From 7cebb25224725b87665935d7f21fa54712f5922f Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 15 Feb 2023 12:47:13 +0100 Subject: [PATCH] refactor: rename to magicast --- README.md | 56 ++++++++++++++-------------------------------- package.json | 4 ++-- src/utils.ts | 2 +- test/index.test.ts | 2 +- 4 files changed, 21 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index b555cbd..6dbf288 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,15 @@ -# 🧀 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 @@ -39,20 +17,20 @@ 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"); @@ -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"); @@ -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'] }`); @@ -119,11 +97,11 @@ Published under [MIT License](./LICENSE). -[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 diff --git a/package.json b/package.json index 93ca70b..56470bd 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/utils.ts b/src/utils.ts index e233138..c616677 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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]) { diff --git a/test/index.test.ts b/test/index.test.ts index aaf4e9d..badb85a 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -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: {} } }`);