Skip to content

Commit

Permalink
refactor: rename to magicast
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 15, 2023
1 parent 1f9f67b commit 7cebb25
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 43 deletions.
56 changes: 17 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,36 @@
# 🧀 Paneer
# 🧀 Magicast

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Github Actions][github-actions-src]][github-actions-href]
[![Codecov][codecov-src]][codecov-href]

Paneer allows you to programmatically modify JavaScript and Typescript source codes with a simplified, elegant and familiar syntax built on top of the [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree) parsed by [recast](https://github.com/benjamn/recast) and [babel](https://babeljs.io/).
Magicast allows you to programmatically modify JavaScript and Typescript source codes with a simplified, elegant and familiar syntax built on top of the [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree) parsed by [recast](https://github.com/benjamn/recast) and [babel](https://babeljs.io/).

**Roadmap:**

🚧 Paneer is currently in the proof of concept state. While underlying parsers are stable, you might need to directly modify underlying AST for unsupported operations in the meantime.

- Generic API
- [x] Working parser and code generation with TS support
- [x] Create node from any value
- [ ] Access to comments
- ESM
- [x] Basic syntax support
- [x] Access to the named exports
- [ ] Access to imports
- Typescript
- [x] Basic syntax support
- [ ] Allow access to type nodes with shortcuts
- Objects
- [x] Iterate over properties
- [ ] Assign new properties
- Arrays
- [x] Push literal values
- [ ] Iterate and modify elements individually
- Functions
- [x] Access to call expression arguments
- [ ] Access to function body
- [ ] Access to function return
🚧 Magicast is currently in the proof of concept state. While underlying parsers are stable, you might need to directly modify underlying AST for unsupported operations in the meantime.

## Usage

Install npm package:

```sh
# using yarn
yarn add --dev paneer
yarn add --dev magicast

# using npm
npm install -D paneer
npm install -D magicast

# using pnpm
pnpm add -D paneer
pnpm add -D magicast
```

Import utilities:

```js
// ESM / Bundler
import { parseCode, generateCode, builders, createNode } from "paneer";
import { parseCode, generateCode, builders, createNode } from "magicast";

// CommonJS
const { parseCode, generateCode, builders, createNode } = require("panner");
Expand All @@ -71,7 +49,7 @@ export default {
Code to modify and append `b` to `foo` prop of defaultExport:

```js
import { loadFile, writeFile } from "paneer";
import { loadFile, writeFile } from "magicast";

const _module = await loadFile("config.js");

Expand All @@ -91,7 +69,7 @@ export default {
**Example:** Directly use AST utils:

```js
import { parseCode, generateCode } from "paneer";
import { parseCode, generateCode } from "magicast";

// Parse to AST
const _module = parseCode(`export default { foo: ['a'] }`);
Expand Down Expand Up @@ -119,11 +97,11 @@ Published under [MIT License](./LICENSE).

<!-- Badges -->

[npm-version-src]: https://img.shields.io/npm/v/paneer?style=flat-square
[npm-version-href]: https://npmjs.com/package/paneer
[npm-downloads-src]: https://img.shields.io/npm/dm/paneer?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/paneer
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/paneer/ci/main?style=flat-square
[github-actions-href]: https://github.com/unjs/paneer/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/paneer/main?style=flat-square
[codecov-href]: https://codecov.io/gh/unjs/paneer
[npm-version-src]: https://img.shields.io/npm/v/magicast?style=flat-square
[npm-version-href]: https://npmjs.com/package/magicast
[npm-downloads-src]: https://img.shields.io/npm/dm/magicast?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/magicast
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/magicast/ci/main?style=flat-square
[github-actions-href]: https://github.com/unjs/magicast/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/magicast/main?style=flat-square
[codecov-href]: https://codecov.io/gh/unjs/magicast
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "paneer",
"name": "magicast",
"version": "0.1.0",
"description": "",
"repository": "unjs/paneer",
"repository": "unjs/magicast",
"license": "MIT",
"sideEffects": false,
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as recast from "recast";
import { ProxyUtils } from "./proxy/types";
import type { ESNode } from "./types";

const PROXY_KEY = "__paneer_proxy";
const PROXY_KEY = "__magicast_proxy";

export function literalToAst(value: any): ESNode {
if (value[PROXY_KEY]) {
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function generate(mod: any) {
return format(generateCode(mod).code, { parser: "babel-ts" }).trim();
}

describe("paneer", () => {
describe("magicast", () => {
it("basic object and array", () => {
const mod = parseCode(`export default { a: 1, b: { c: {} } }`);

Expand Down

0 comments on commit 7cebb25

Please sign in to comment.