diff --git a/.eslintignore b/.eslintignore index 9c62828..450ea1c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,4 @@ node_modules coverage dist +vendor diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e8c6141..71f78ac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,5 +21,6 @@ jobs: - run: pnpm install - run: pnpm lint - run: pnpm build - - run: pnpm vitest --coverage + - run: pnpm test --coverage + - run: pnpm test:build - uses: codecov/codecov-action@v3 diff --git a/.gitignore b/.gitignore index bb9eace..bace84d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ types *.env* .idea .history +vendor diff --git a/build.config.ts b/build.config.ts index f5c4377..e1bd1f1 100644 --- a/build.config.ts +++ b/build.config.ts @@ -1,3 +1,4 @@ +import { resolve } from "node:path"; import { defineBuildConfig } from "unbuild"; export default defineBuildConfig({ @@ -6,5 +7,26 @@ export default defineBuildConfig({ declaration: true, rollup: { emitCJS: true, + inlineDependencies: true, + dts: { + respectExternal: true, + } }, + alias: { + 'source-map': 'source-map-js', + // eslint-disable-next-line unicorn/prefer-module + assert: resolve(__dirname, 'stubs/assert/index.js'), + // eslint-disable-next-line unicorn/prefer-module + recast: resolve(__dirname, 'vendor/recast/main.ts'), + // eslint-disable-next-line unicorn/prefer-module + 'ast-types': resolve(__dirname, 'vendor/ast-types/src/main.ts'), + }, + hooks: { + 'rollup:dts:options': (ctx, options) => { + // @ts-expect-error filter out commonjs plugin in dts build + options.plugins = options.plugins.filter((plugin) => { + return plugin && plugin.name !== 'commonjs' + }) + } + } }); diff --git a/helpers.d.ts b/helpers.d.ts index 3de006d..fbac79a 100644 --- a/helpers.d.ts +++ b/helpers.d.ts @@ -1 +1 @@ -export * from "./dist/helpers.d.ts"; +export * from "./dist/helpers.js"; diff --git a/package.json b/package.json index 3c0ca26..42f2086 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ ], "scripts": { "build": "unbuild", + "prepare": "esno ./scripts/vendor.ts", "dev": "vitest dev", "dev:ui": "vitest dev --ui", "lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src test", @@ -34,27 +35,38 @@ "prepack": "pnpm run build", "typecheck": "tsc --noEmit", "release": "pnpm run test run && changelogen --release && npm publish && git push --follow-tags", - "test": "vitest" + "test": "vitest", + "test:build": "TEST_BUILD=true vitest", + "test:full": "pnpm run test && pnpm run build && pnpm run test:build" }, "dependencies": { "@babel/parser": "^7.22.15", "@babel/types": "^7.22.15", - "recast": "^0.23.4" + "source-map-js": "^1.0.2" }, "devDependencies": { "@types/node": "^20.5.9", "@vitest/coverage-v8": "^0.34.3", "@vitest/ui": "^0.34.3", + "ast-types": "^0.16.1", "changelogen": "^0.5.5", - "eslint": "^8.48.0", "eslint-config-unjs": "^0.2.1", + "eslint": "^8.48.0", + "execa": "^8.0.1", "lint-staged": "^14.0.1", + "magicast": "workspace:*", "prettier": "^3.0.3", + "recast": "^0.23.4", "simple-git-hooks": "^2.9.0", + "source-map": "npm:source-map-js@latest", + "tiged": "^2.12.5", "typescript": "^5.2.2", "unbuild": "^2.0.0", "vitest": "^0.34.3" }, + "resolutions": { + "source-map": "npm:source-map-js@latest" + }, "simple-git-hooks": { "pre-commit": "pnpm lint-staged" }, @@ -64,5 +76,24 @@ "prettier -w" ] }, - "packageManager": "pnpm@8.7.4" + "packageManager": "pnpm@8.7.4", + "pnpm": { + "overrides": { + "array-includes": "npm:@nolyfill/array-includes@latest", + "array.prototype.flat": "npm:@nolyfill/array.prototype.flat@latest", + "array.prototype.flatmap": "npm:@nolyfill/array.prototype.flatmap@latest", + "available-typed-arrays": "npm:@nolyfill/available-typed-arrays@latest", + "define-properties": "npm:@nolyfill/define-properties@latest", + "function-bind": "npm:@nolyfill/function-bind@latest", + "gopd": "npm:@nolyfill/gopd@latest", + "has": "npm:@nolyfill/has@latest", + "has-symbols": "npm:@nolyfill/has-symbols@latest", + "has-tostringtag": "npm:@nolyfill/has-tostringtag@latest", + "is-arguments": "npm:@nolyfill/is-arguments@latest", + "is-generator-function": "npm:@nolyfill/is-generator-function@latest", + "object-is": "npm:@nolyfill/object-is@latest", + "object.values": "npm:@nolyfill/object.values@latest", + "which-typed-array": "npm:@nolyfill/which-typed-array@latest" + } + } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d1c0946..b78e881 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,54 +4,91 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false -dependencies: - '@babel/parser': - specifier: ^7.22.15 - version: 7.22.15 - '@babel/types': - specifier: ^7.22.15 - version: 7.22.15 - recast: - specifier: ^0.23.4 - version: 0.23.4 - -devDependencies: - '@types/node': - specifier: ^20.5.9 - version: 20.5.9 - '@vitest/coverage-v8': - specifier: ^0.34.3 - version: 0.34.3(vitest@0.34.3) - '@vitest/ui': - specifier: ^0.34.3 - version: 0.34.3(vitest@0.34.3) - changelogen: - specifier: ^0.5.5 - version: 0.5.5 - eslint: - specifier: ^8.48.0 - version: 8.48.0 - eslint-config-unjs: - specifier: ^0.2.1 - version: 0.2.1(eslint@8.48.0)(typescript@5.2.2) - lint-staged: - specifier: ^14.0.1 - version: 14.0.1 - prettier: - specifier: ^3.0.3 - version: 3.0.3 - simple-git-hooks: - specifier: ^2.9.0 - version: 2.9.0 - typescript: - specifier: ^5.2.2 - version: 5.2.2 - unbuild: - specifier: ^2.0.0 - version: 2.0.0(typescript@5.2.2) - vitest: - specifier: ^0.34.3 - version: 0.34.3(@vitest/ui@0.34.3) +overrides: + array-includes: npm:@nolyfill/array-includes@latest + array.prototype.flat: npm:@nolyfill/array.prototype.flat@latest + array.prototype.flatmap: npm:@nolyfill/array.prototype.flatmap@latest + available-typed-arrays: npm:@nolyfill/available-typed-arrays@latest + define-properties: npm:@nolyfill/define-properties@latest + function-bind: npm:@nolyfill/function-bind@latest + gopd: npm:@nolyfill/gopd@latest + has: npm:@nolyfill/has@latest + has-symbols: npm:@nolyfill/has-symbols@latest + has-tostringtag: npm:@nolyfill/has-tostringtag@latest + is-arguments: npm:@nolyfill/is-arguments@latest + is-generator-function: npm:@nolyfill/is-generator-function@latest + object-is: npm:@nolyfill/object-is@latest + object.values: npm:@nolyfill/object.values@latest + which-typed-array: npm:@nolyfill/which-typed-array@latest + +importers: + + .: + dependencies: + '@babel/parser': + specifier: ^7.22.15 + version: 7.22.15 + '@babel/types': + specifier: ^7.22.15 + version: 7.22.15 + source-map-js: + specifier: ^1.0.2 + version: 1.0.2 + devDependencies: + '@types/node': + specifier: ^20.5.9 + version: 20.5.9 + '@vitest/coverage-v8': + specifier: ^0.34.3 + version: 0.34.3(vitest@0.34.3) + '@vitest/ui': + specifier: ^0.34.3 + version: 0.34.3(vitest@0.34.3) + ast-types: + specifier: ^0.16.1 + version: 0.16.1 + changelogen: + specifier: ^0.5.5 + version: 0.5.5 + eslint: + specifier: ^8.48.0 + version: 8.48.0 + eslint-config-unjs: + specifier: ^0.2.1 + version: 0.2.1(eslint@8.48.0)(typescript@5.2.2) + execa: + specifier: ^8.0.1 + version: 8.0.1 + lint-staged: + specifier: ^14.0.1 + version: 14.0.1 + magicast: + specifier: workspace:* + version: 'link:' + prettier: + specifier: ^3.0.3 + version: 3.0.3 + recast: + specifier: ^0.23.4 + version: 0.23.4 + simple-git-hooks: + specifier: ^2.9.0 + version: 2.9.0 + source-map: + specifier: npm:source-map-js@latest + version: /source-map-js@1.0.2 + tiged: + specifier: ^2.12.5 + version: 2.12.5 + typescript: + specifier: ^5.2.2 + version: 5.2.2 + unbuild: + specifier: ^2.0.0 + version: 2.0.0(typescript@5.2.2) + vitest: + specifier: ^0.34.3 + version: 0.34.3(@vitest/ui@0.34.3) packages: @@ -1006,6 +1043,101 @@ packages: fastq: 1.15.0 dev: true + /@nolyfill/array-includes@1.0.21: + resolution: {integrity: sha512-P+SLU5wuJmHnuo1Nhy/3l4yneHm6M+WmISz5tCVGLc0rytUBRfACmneLTryh4nlobAhUulDkBL+VoldU1g3zoA==} + engines: {node: '>=12.4.0'} + dependencies: + '@nolyfill/shared': 1.0.21 + dev: true + + /@nolyfill/array.prototype.flat@1.0.21: + resolution: {integrity: sha512-RoyB6qmcOSuflZH+XcZAkE1aBrYIV/3qdIGk6EG1afCdZSkUUCz0PAT8h3lHdtgVh+ge82hMK2SdCur2YeNj8A==} + engines: {node: '>=12.4.0'} + dependencies: + '@nolyfill/shared': 1.0.21 + dev: true + + /@nolyfill/array.prototype.flatmap@1.0.21: + resolution: {integrity: sha512-VWUiJBWk4qDgktkeQRzrtYlQdBRnEU3vfjoQxcBmdn3vSnq7ujKCBox4cdpZe9LZK9FU9Y1L4UteyW5THat2CQ==} + engines: {node: '>=12.4.0'} + dependencies: + '@nolyfill/shared': 1.0.21 + dev: true + + /@nolyfill/available-typed-arrays@1.0.21: + resolution: {integrity: sha512-JhNt/GI0AlGLhfpeh4H9eo71zvWbG6oRMzGaZiubR+9muc8vtACsoGD/Yv+dIx1D9ab2aXqxhP3A7Wc8Mu4u5w==} + engines: {node: '>=12.4.0'} + dev: true + + /@nolyfill/define-properties@1.0.21: + resolution: {integrity: sha512-q1xDIx9cYp6N1BjT8Kdq4GJwiJWxG1LV9jWDvz3hw/Q24m/DYSGXv+RTpB3rNZoorn4xweF2jklmxFFhhyKimA==} + engines: {node: '>=12.4.0'} + dependencies: + '@nolyfill/shared': 1.0.21 + dev: true + + /@nolyfill/function-bind@1.0.21: + resolution: {integrity: sha512-0Jsaoxp/9HJqCa3GzEzJcoi4+VfupD/o+1pBG0qJ0X3d+sKbbfSej2Faiyp0fTHH36mhsdAKi2TahEx9JV08ZA==} + engines: {node: '>=12.4.0'} + dev: true + + /@nolyfill/gopd@1.0.21: + resolution: {integrity: sha512-zSg1OEGXGcIfBWkq83frp/1LQD4NPxnNh8ECO05mcZtHjeSAtgq726gOOq3tsdlR8d696Gjq3Hw8wiaPmgafyg==} + engines: {node: '>=12.4.0'} + dev: true + + /@nolyfill/has-symbols@1.0.21: + resolution: {integrity: sha512-fx+nNcrPdXoPH+nKNlqRfeOOxCu7IqFAh6KqzVbuHdu5QHpPT74TmobOQzruTYq+nHeSsw3+9uc32aSa4jrkNw==} + engines: {node: '>=12.4.0'} + dev: true + + /@nolyfill/has-tostringtag@1.0.21: + resolution: {integrity: sha512-vcSJnah+I19svbYbOIQF/NK0S42rQLGDEWc67OEPXsZSy+VFlpsE42kVNZSykIecmZGuZ8iMlB0cpFii6Lfwhw==} + engines: {node: '>=12.4.0'} + dev: true + + /@nolyfill/has@1.0.21: + resolution: {integrity: sha512-Sf8iFaegjGp29hQVQjIc+nDR0uWqGkHsFC3jsUigFwGjpafgMaBtL++DpTU9jYAKDJEvslR1szl8qJjNGlhgcw==} + engines: {node: '>=12.4.0'} + dependencies: + '@nolyfill/shared': 1.0.21 + dev: true + + /@nolyfill/is-arguments@1.0.21: + resolution: {integrity: sha512-HRZGXP4Khz2W/Oma5TD0w2PMUNjFFCwc+GDQxX1/DfWFCewnVhdudjlUDH4/XOikYhGkxcG+YVJAXXsmcVWW7A==} + engines: {node: '>=12.4.0'} + dev: true + + /@nolyfill/is-generator-function@1.0.21: + resolution: {integrity: sha512-rxHlkx7kHiu7/nNgn/SV5cbuncZv52RzRJ+weVQsjj5xpLxsH298NGRLcHW48yYwPOdGvd3BnbpZe1kCo9QWaw==} + engines: {node: '>=12.4.0'} + dev: true + + /@nolyfill/object-is@1.0.21: + resolution: {integrity: sha512-iUQXK1Qvh6UjkcOd+xLY6ji/xBG6oSiStbc5Q73luWK3wNmwpIaO/FvZjE8OQFQzarSj6vI4EMUM8JKpwnZosg==} + engines: {node: '>=12.4.0'} + dependencies: + '@nolyfill/shared': 1.0.21 + dev: true + + /@nolyfill/object.values@1.0.21: + resolution: {integrity: sha512-5RPPiaknXoCnpwXZTy99Oo/sNega0wf5DsYQU6YOFa1kLhvwgc4x2/Np1F8zT7WwGE9C1POH3ZIuSMelpd79Ew==} + engines: {node: '>=12.4.0'} + dependencies: + '@nolyfill/shared': 1.0.21 + dev: true + + /@nolyfill/shared@1.0.21: + resolution: {integrity: sha512-qDc/NoaFU23E0hhiDPeUrvWzTXIPE+RbvRQtRWSeHHNmCIgYI9HS1jKzNYNJxv4jvZ/1VmM3L6rNVxbj+LBMNA==} + dev: true + + /@nolyfill/which-typed-array@1.0.21: + resolution: {integrity: sha512-/AqIVAAGLI6KH9idsre3pvup5H48fhtd2z4G2ACxEPCZVI1JycBMnuX6bcQTdOuYBm5ZzewZ1LNf/oGMiD9Jrg==} + engines: {node: '>=12.4.0'} + dependencies: + '@nolyfill/shared': 1.0.21 + dev: true + /@pkgr/utils@2.3.1: resolution: {integrity: sha512-wfzX8kc1PMyUILA+1Z/EqoE4UCXGy0iRGMhPwdfae1+f0OXlLqCk+By+aMzgJBzR9AzS4CDizioG6Ss1gvAFJw==} engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0} @@ -1400,6 +1532,11 @@ packages: uri-js: 4.4.1 dev: true + /ansi-colors@4.1.3: + resolution: {integrity: sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==} + engines: {node: '>=6'} + dev: true + /ansi-escapes@5.0.0: resolution: {integrity: sha512-5GFMVX8HqE/TB+FuBJGuO5XG0WrsA6ptUqoODaT/n9mmUaZFkqnBueB4leqGBCmrUHnCnC4PCZTCd0E7QQ83bA==} engines: {node: '>=12'} @@ -1454,50 +1591,19 @@ packages: resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==} dev: true - /array-includes@3.1.6: - resolution: {integrity: sha512-sgTbLvL6cNnw24FnbaDyjmvddQ2ML8arZsgaJhoABMoplz/4QRhtrYS+alr1BUM1Bwp6dhx8vVCBSLG+StwOFw==} - engines: {node: '>= 0.4'} - dependencies: - call-bind: 1.0.2 - define-properties: 1.2.0 - es-abstract: 1.21.1 - get-intrinsic: 1.2.0 - is-string: 1.0.7 - dev: true - /array-union@2.1.0: resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==} engines: {node: '>=8'} dev: true - /array.prototype.flat@1.3.1: - resolution: {integrity: sha512-roTU0KWIOmJ4DRLmwKd19Otg0/mT3qPNt0Qb3GWW8iObuZXxrjB/pzn0R3hqpRSWg4HCwqx+0vwOnWnvlOyeIA==} - engines: {node: '>= 0.4'} - dependencies: - call-bind: 1.0.2 - define-properties: 1.2.0 - es-abstract: 1.21.1 - es-shim-unscopables: 1.0.0 - dev: true - - /array.prototype.flatmap@1.3.1: - resolution: {integrity: sha512-8UGn9O1FDVvMNB0UlLv4voxRMze7+FpHyF5mSMRjWHUMlpoDViniy05870VlxhfgTnLbpuwTzvD76MTtWxB/mQ==} - engines: {node: '>= 0.4'} - dependencies: - call-bind: 1.0.2 - define-properties: 1.2.0 - es-abstract: 1.21.1 - es-shim-unscopables: 1.0.0 - dev: true - /assert@2.0.0: resolution: {integrity: sha512-se5Cd+js9dXJnu6Ag2JFc00t+HmHOen+8Q+L7O9zI0PqQXr20uk2J0XQqMxZEeo5U50o8Nvmmx7dZrl+Ufr35A==} dependencies: es6-object-assign: 1.1.0 is-nan: 1.3.2 - object-is: 1.1.5 + object-is: /@nolyfill/object-is@1.0.21 util: 0.12.5 - dev: false + dev: true /assertion-error@1.1.0: resolution: {integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==} @@ -1508,11 +1614,7 @@ packages: engines: {node: '>=4'} dependencies: tslib: 2.5.0 - dev: false - - /available-typed-arrays@1.0.5: - resolution: {integrity: sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==} - engines: {node: '>= 0.4'} + dev: true /balanced-match@1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} @@ -1610,8 +1712,9 @@ packages: /call-bind@1.0.2: resolution: {integrity: sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==} dependencies: - function-bind: 1.1.1 + function-bind: /@nolyfill/function-bind@1.0.21 get-intrinsic: 1.2.0 + dev: true /callsites@3.1.0: resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==} @@ -1761,6 +1864,10 @@ packages: resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} dev: true + /colorette@1.2.1: + resolution: {integrity: sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==} + dev: true + /colorette@2.0.20: resolution: {integrity: sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==} dev: true @@ -1867,13 +1974,6 @@ packages: engines: {node: '>=12'} dev: true - /define-properties@1.2.0: - resolution: {integrity: sha512-xvqAVKGfT1+UAvPwKTVw/njhdQ8ZhXK4lI0bCIuCMrp2up9nPnaDftrLtmpTazqd1o+UY4zgzU+avtMbDP+ldA==} - engines: {node: '>= 0.4'} - dependencies: - has-property-descriptors: 1.0.0 - object-keys: 1.1.1 - /defu@6.1.2: resolution: {integrity: sha512-+uO4+qr7msjNNWKYPHqN/3+Dx3NFkmIzayk2L1MyZQlvgZb/J1A0fo410dpKrN2SnqFjt8n4JL8fDJE0wIgjFQ==} dev: true @@ -1933,78 +2033,22 @@ packages: tapable: 2.2.1 dev: true - /error-ex@1.3.2: - resolution: {integrity: sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==} - dependencies: - is-arrayish: 0.2.1 - dev: true - - /es-abstract@1.21.1: - resolution: {integrity: sha512-QudMsPOz86xYz/1dG1OuGBKOELjCh99IIWHLzy5znUB6j8xG2yMA7bfTV86VSqKF+Y/H08vQPR+9jyXpuC6hfg==} - engines: {node: '>= 0.4'} - dependencies: - available-typed-arrays: 1.0.5 - call-bind: 1.0.2 - es-set-tostringtag: 2.0.1 - es-to-primitive: 1.2.1 - function-bind: 1.1.1 - function.prototype.name: 1.1.5 - get-intrinsic: 1.2.0 - get-symbol-description: 1.0.0 - globalthis: 1.0.3 - gopd: 1.0.1 - has: 1.0.3 - has-property-descriptors: 1.0.0 - has-proto: 1.0.1 - has-symbols: 1.0.3 - internal-slot: 1.0.5 - is-array-buffer: 3.0.1 - is-callable: 1.2.7 - is-negative-zero: 2.0.2 - is-regex: 1.1.4 - is-shared-array-buffer: 1.0.2 - is-string: 1.0.7 - is-typed-array: 1.1.10 - is-weakref: 1.0.2 - object-inspect: 1.12.3 - object-keys: 1.1.1 - object.assign: 4.1.4 - regexp.prototype.flags: 1.4.3 - safe-regex-test: 1.0.0 - string.prototype.trimend: 1.0.6 - string.prototype.trimstart: 1.0.6 - typed-array-length: 1.0.4 - unbox-primitive: 1.0.2 - which-typed-array: 1.1.9 - dev: true - - /es-set-tostringtag@2.0.1: - resolution: {integrity: sha512-g3OMbtlwY3QewlqAiMLI47KywjWZoEytKr8pf6iTC8uJq5bIAH52Z9pnQ8pVL6whrCto53JZDuUIsifGeLorTg==} - engines: {node: '>= 0.4'} - dependencies: - get-intrinsic: 1.2.0 - has: 1.0.3 - has-tostringtag: 1.0.0 - dev: true - - /es-shim-unscopables@1.0.0: - resolution: {integrity: sha512-Jm6GPcCdC30eMLbZ2x8z2WuRwAws3zTBBKuusffYVUrNj/GVSUAZ+xKMaUpfNDR5IbyNA5LJbaecoUVbmUcB1w==} + /enquirer@2.3.6: + resolution: {integrity: sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==} + engines: {node: '>=8.6'} dependencies: - has: 1.0.3 + ansi-colors: 4.1.3 dev: true - /es-to-primitive@1.2.1: - resolution: {integrity: sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==} - engines: {node: '>= 0.4'} + /error-ex@1.3.2: + resolution: {integrity: sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==} dependencies: - is-callable: 1.2.7 - is-date-object: 1.0.5 - is-symbol: 1.0.4 + is-arrayish: 0.2.1 dev: true /es6-object-assign@1.1.0: resolution: {integrity: sha512-MEl9uirslVwqQU369iHNWZXsI8yaZYGg/D65aOgZkeyFJwHYSxilf7rQzXKI7DdDuBPrBXbfk3sl9hJhmd5AUw==} - dev: false + dev: true /esbuild@0.16.17: resolution: {integrity: sha512-G8LEkV0XzDMNwXKgM0Jwu3nY3lSTwSGY6XbxM9cr9+s0T/qSV1q1JVPBGzm3dcjhCic9+emZDmMffkwgPeOeLg==} @@ -2163,7 +2207,7 @@ packages: resolution: {integrity: sha512-gozW2blMLJCeFpBwugLTGyvVjNoeo1knonXAcatC6bjPBZitotxdWf7Gimr25N4c0AAOo4eOUfaG82IJPDpqCA==} dependencies: debug: 3.2.7 - is-core-module: 2.12.1 + is-core-module: 2.13.0 resolve: 1.22.2 transitivePeerDependencies: - supports-color @@ -2183,7 +2227,7 @@ packages: eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.62.0)(eslint-import-resolver-typescript@3.5.5)(eslint@8.48.0) get-tsconfig: 4.6.0 globby: 13.1.4 - is-core-module: 2.12.1 + is-core-module: 2.13.0 is-glob: 4.0.3 synckit: 0.8.5 transitivePeerDependencies: @@ -2256,19 +2300,19 @@ packages: optional: true dependencies: '@typescript-eslint/parser': 5.62.0(eslint@8.48.0)(typescript@5.2.2) - array-includes: 3.1.6 - array.prototype.flat: 1.3.1 - array.prototype.flatmap: 1.3.1 + array-includes: /@nolyfill/array-includes@1.0.21 + array.prototype.flat: /@nolyfill/array.prototype.flat@1.0.21 + array.prototype.flatmap: /@nolyfill/array.prototype.flatmap@1.0.21 debug: 3.2.7 doctrine: 2.1.0 eslint: 8.48.0 eslint-import-resolver-node: 0.3.7 eslint-module-utils: 2.7.4(@typescript-eslint/parser@5.62.0)(eslint-import-resolver-node@0.3.7)(eslint-import-resolver-typescript@3.5.5)(eslint@8.48.0) - has: 1.0.3 - is-core-module: 2.12.1 + has: /@nolyfill/has@1.0.21 + is-core-module: 2.13.0 is-glob: 4.0.3 minimatch: 3.1.2 - object.values: 1.1.6 + object.values: /@nolyfill/object.values@1.0.21 resolve: 1.22.2 semver: 6.3.0 tsconfig-paths: 3.14.1 @@ -2289,7 +2333,7 @@ packages: eslint: 8.48.0 eslint-plugin-es-x: 7.2.0(eslint@8.48.0) ignore: 5.2.4 - is-core-module: 2.12.1 + is-core-module: 2.13.0 minimatch: 3.1.2 resolve: 1.22.2 semver: 7.5.4 @@ -2436,7 +2480,7 @@ packages: resolution: {integrity: sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==} engines: {node: '>=4'} hasBin: true - dev: false + dev: true /esquery@1.5.0: resolution: {integrity: sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==} @@ -2604,6 +2648,16 @@ packages: resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==} dependencies: is-callable: 1.2.7 + dev: true + + /fs-extra@10.1.0: + resolution: {integrity: sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==} + engines: {node: '>=12'} + dependencies: + graceful-fs: 4.2.10 + jsonfile: 6.1.0 + universalify: 2.0.0 + dev: true /fs-extra@11.1.1: resolution: {integrity: sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==} @@ -2633,21 +2687,8 @@ packages: dev: true optional: true - /function-bind@1.1.1: - resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==} - - /function.prototype.name@1.1.5: - resolution: {integrity: sha512-uN7m/BzVKQnCUF/iW8jYea67v++2u7m5UgENbHRtdDVclOUP+FMPlCNdmk0h/ysGyo2tavMJEDqJAkJdRa1vMA==} - engines: {node: '>= 0.4'} - dependencies: - call-bind: 1.0.2 - define-properties: 1.2.0 - es-abstract: 1.21.1 - functions-have-names: 1.2.3 - dev: true - - /functions-have-names@1.2.3: - resolution: {integrity: sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==} + /fuzzysearch@1.0.3: + resolution: {integrity: sha512-s+kNWQuI3mo9OALw0HJ6YGmMbLqEufCh2nX/zzV5CrICQ/y4AwPxM+6TIiF9ItFCHXFCyM/BfCCmN57NTIJuPg==} dev: true /gensync@1.0.0-beta.2: @@ -2662,9 +2703,10 @@ packages: /get-intrinsic@1.2.0: resolution: {integrity: sha512-L049y6nFOuom5wGyRc3/gdTLO94dySVKRACj1RmJZBQXlbTMhtNIgkWkUHq+jYmZvKf14EW1EoJnnjbmoHij0Q==} dependencies: - function-bind: 1.1.1 - has: 1.0.3 - has-symbols: 1.0.3 + function-bind: /@nolyfill/function-bind@1.0.21 + has: /@nolyfill/has@1.0.21 + has-symbols: /@nolyfill/has-symbols@1.0.21 + dev: true /get-stream@6.0.1: resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==} @@ -2676,14 +2718,6 @@ packages: engines: {node: '>=16'} dev: true - /get-symbol-description@1.0.0: - resolution: {integrity: sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw==} - engines: {node: '>= 0.4'} - dependencies: - call-bind: 1.0.2 - get-intrinsic: 1.2.0 - dev: true - /get-tsconfig@4.6.0: resolution: {integrity: sha512-lgbo68hHTQnFddybKbbs/RDRJnJT5YyGy2kQzVwbq+g67X73i+5MVTval34QxGkOe9X5Ujf1UYpCaphLyltjEg==} dependencies: @@ -2753,13 +2787,6 @@ packages: type-fest: 0.20.2 dev: true - /globalthis@1.0.3: - resolution: {integrity: sha512-sFdI5LyBiNTHjRd7cGPWapiHWMOXKyuBNX/cWJ3NfzrZQVa8GI/8cofCl74AOVqq9W5kNmguTIzJ/1s2gyI9wA==} - engines: {node: '>= 0.4'} - dependencies: - define-properties: 1.2.0 - dev: true - /globalyzer@0.1.0: resolution: {integrity: sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q==} dev: true @@ -2802,11 +2829,6 @@ packages: resolution: {integrity: sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==} dev: true - /gopd@1.0.1: - resolution: {integrity: sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==} - dependencies: - get-intrinsic: 1.2.0 - /graceful-fs@4.2.10: resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==} dev: true @@ -2815,10 +2837,6 @@ packages: resolution: {integrity: sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==} dev: true - /has-bigints@1.0.2: - resolution: {integrity: sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==} - dev: true - /has-flag@3.0.0: resolution: {integrity: sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==} engines: {node: '>=4'} @@ -2830,32 +2848,6 @@ packages: engines: {node: '>=8'} dev: true - /has-property-descriptors@1.0.0: - resolution: {integrity: sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==} - dependencies: - get-intrinsic: 1.2.0 - - /has-proto@1.0.1: - resolution: {integrity: sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==} - engines: {node: '>= 0.4'} - dev: true - - /has-symbols@1.0.3: - resolution: {integrity: sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==} - engines: {node: '>= 0.4'} - - /has-tostringtag@1.0.0: - resolution: {integrity: sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==} - engines: {node: '>= 0.4'} - dependencies: - has-symbols: 1.0.3 - - /has@1.0.3: - resolution: {integrity: sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==} - engines: {node: '>= 0.4.0'} - dependencies: - function-bind: 1.1.1 - /hookable@5.5.3: resolution: {integrity: sha512-Yc+BQe8SvoXH1643Qez1zqLRmbA5rCL+sSmk6TVos0LWVfNIB7PGncdlId77WzLGSIB5KaWgTaNTs2lNVEI6VQ==} dev: true @@ -2868,6 +2860,16 @@ packages: resolution: {integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==} dev: true + /https-proxy-agent@5.0.0: + resolution: {integrity: sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==} + engines: {node: '>= 6'} + dependencies: + agent-base: 6.0.2 + debug: 4.3.4 + transitivePeerDependencies: + - supports-color + dev: true + /https-proxy-agent@5.0.1: resolution: {integrity: sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==} engines: {node: '>= 6'} @@ -2925,42 +2927,12 @@ packages: /inherits@2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} - - /internal-slot@1.0.5: - resolution: {integrity: sha512-Y+R5hJrzs52QCG2laLn4udYVnxsfny9CpOhNhUvk/SSSVyF6T27FzRbF0sroPidSu3X8oEAkOn2K804mjpt6UQ==} - engines: {node: '>= 0.4'} - dependencies: - get-intrinsic: 1.2.0 - has: 1.0.3 - side-channel: 1.0.4 - dev: true - - /is-arguments@1.1.1: - resolution: {integrity: sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==} - engines: {node: '>= 0.4'} - dependencies: - call-bind: 1.0.2 - has-tostringtag: 1.0.0 - dev: false - - /is-array-buffer@3.0.1: - resolution: {integrity: sha512-ASfLknmY8Xa2XtB4wmbz13Wu202baeA18cJBCeCy0wXUHZF0IPyVEXqKEcd+t2fNSLLL1vC6k7lxZEojNbISXQ==} - dependencies: - call-bind: 1.0.2 - get-intrinsic: 1.2.0 - is-typed-array: 1.1.10 dev: true /is-arrayish@0.2.1: resolution: {integrity: sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==} dev: true - /is-bigint@1.0.4: - resolution: {integrity: sha512-zB9CruMamjym81i2JZ3UMn54PKGsQzsJeo6xvN3HJJ4CAsQNB6iRutp2To77OfCNuoxspsIhzaPoO1zyCEhFOg==} - dependencies: - has-bigints: 1.0.2 - dev: true - /is-binary-path@2.1.0: resolution: {integrity: sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==} engines: {node: '>=8'} @@ -2968,14 +2940,6 @@ packages: binary-extensions: 2.2.0 dev: true - /is-boolean-object@1.1.2: - resolution: {integrity: sha512-gDYaKHJmnj4aWxyj6YHyXVpdQawtVLHU5cb+eztPGczf6cjuTdwve5ZIEfgXqH4e57An1D1AKf8CZ3kYrQRqYA==} - engines: {node: '>= 0.4'} - dependencies: - call-bind: 1.0.2 - has-tostringtag: 1.0.0 - dev: true - /is-builtin-module@3.2.1: resolution: {integrity: sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==} engines: {node: '>=6'} @@ -2986,18 +2950,12 @@ packages: /is-callable@1.2.7: resolution: {integrity: sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==} engines: {node: '>= 0.4'} - - /is-core-module@2.12.1: - resolution: {integrity: sha512-Q4ZuBAe2FUsKtyQJoQHlvP8OvBERxO3jEmy1I7hcRXcJBGGHFh/aJBswbXuS9sgrDH2QUO8ilkwNPHvHMd8clg==} - dependencies: - has: 1.0.3 dev: true - /is-date-object@1.0.5: - resolution: {integrity: sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==} - engines: {node: '>= 0.4'} + /is-core-module@2.13.0: + resolution: {integrity: sha512-Z7dk6Qo8pOCp3l4tsX2C5ZVas4V+UxwQodwZhLopL91TX8UyyHEXafPcyoeeWuLrwzHcr3igO78wNLwHJHsMCQ==} dependencies: - has-tostringtag: 1.0.0 + has: /@nolyfill/has@1.0.21 dev: true /is-docker@2.2.1: @@ -3022,13 +2980,6 @@ packages: engines: {node: '>=12'} dev: true - /is-generator-function@1.0.10: - resolution: {integrity: sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==} - engines: {node: '>= 0.4'} - dependencies: - has-tostringtag: 1.0.0 - dev: false - /is-glob@4.0.3: resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==} engines: {node: '>=0.10.0'} @@ -3053,19 +3004,7 @@ packages: engines: {node: '>= 0.4'} dependencies: call-bind: 1.0.2 - define-properties: 1.2.0 - dev: false - - /is-negative-zero@2.0.2: - resolution: {integrity: sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA==} - engines: {node: '>= 0.4'} - dev: true - - /is-number-object@1.0.7: - resolution: {integrity: sha512-k1U0IRzLMo7ZlYIfzRu23Oh6MiIFasgpb9X76eqfFZAqwH44UI4KTBvBYIZ1dSL9ZzChTB9ShHfLkR4pdW5krQ==} - engines: {node: '>= 0.4'} - dependencies: - has-tostringtag: 1.0.0 + define-properties: /@nolyfill/define-properties@1.0.21 dev: true /is-number@7.0.0: @@ -3084,20 +3023,6 @@ packages: '@types/estree': 1.0.0 dev: true - /is-regex@1.1.4: - resolution: {integrity: sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==} - engines: {node: '>= 0.4'} - dependencies: - call-bind: 1.0.2 - has-tostringtag: 1.0.0 - dev: true - - /is-shared-array-buffer@1.0.2: - resolution: {integrity: sha512-sqN2UDu1/0y6uvXyStCOzyhAjCSlHceFoMKJW8W9EU9cvic/QdsZ0kEU93HEy3IUEFZIiH/3w+AH/UQbPHNdhA==} - dependencies: - call-bind: 1.0.2 - dev: true - /is-stream@2.0.1: resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==} engines: {node: '>=8'} @@ -3108,34 +3033,15 @@ packages: engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} dev: true - /is-string@1.0.7: - resolution: {integrity: sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==} - engines: {node: '>= 0.4'} - dependencies: - has-tostringtag: 1.0.0 - dev: true - - /is-symbol@1.0.4: - resolution: {integrity: sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==} - engines: {node: '>= 0.4'} - dependencies: - has-symbols: 1.0.3 - dev: true - /is-typed-array@1.1.10: resolution: {integrity: sha512-PJqgEHiWZvMpaFZ3uTc8kHPM4+4ADTlDniuQL7cU/UDA0Ql7F70yGfHph3cLNe+c9toaigv+DFzTJKhc2CtO6A==} engines: {node: '>= 0.4'} dependencies: - available-typed-arrays: 1.0.5 + available-typed-arrays: /@nolyfill/available-typed-arrays@1.0.21 call-bind: 1.0.2 for-each: 0.3.3 - gopd: 1.0.1 - has-tostringtag: 1.0.0 - - /is-weakref@1.0.2: - resolution: {integrity: sha512-qctsuLZmIQ0+vSSMfoVvyFe2+GSEvnmZ2ezTup1SBse9+twCCeial6EEi3Nc2KFcf6+qz2FBPnjXsk8xhKSaPQ==} - dependencies: - call-bind: 1.0.2 + gopd: /@nolyfill/gopd@1.0.21 + has-tostringtag: /@nolyfill/has-tostringtag@1.0.21 dev: true /is-wsl@2.2.0: @@ -3505,6 +3411,11 @@ packages: ufo: 1.1.2 dev: true + /mri@1.1.6: + resolution: {integrity: sha512-oi1b3MfbyGa7FJMP9GmLTttni5JoICpYBRlq+x5V16fZbLsnL9N3wFqqIm/nIG43FjUFkFh9Epzp/kzUGUnJxQ==} + engines: {node: '>=4'} + dev: true + /mri@1.2.0: resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} engines: {node: '>=4'} @@ -3573,41 +3484,6 @@ packages: path-key: 4.0.0 dev: true - /object-inspect@1.12.3: - resolution: {integrity: sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==} - dev: true - - /object-is@1.1.5: - resolution: {integrity: sha512-3cyDsyHgtmi7I7DfSSI2LDp6SK2lwvtbg0p0R1e0RvTqF5ceGx+K2dfSjm1bKDMVCFEDAQvy+o8c6a7VujOddw==} - engines: {node: '>= 0.4'} - dependencies: - call-bind: 1.0.2 - define-properties: 1.2.0 - dev: false - - /object-keys@1.1.1: - resolution: {integrity: sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==} - engines: {node: '>= 0.4'} - - /object.assign@4.1.4: - resolution: {integrity: sha512-1mxKf0e58bvyjSCtKYY4sRe9itRk3PJpquJOjeIkz885CczcI4IvJJDLPS72oowuSh+pBxUFROpX+TU++hxhZQ==} - engines: {node: '>= 0.4'} - dependencies: - call-bind: 1.0.2 - define-properties: 1.2.0 - has-symbols: 1.0.3 - object-keys: 1.1.1 - dev: true - - /object.values@1.1.6: - resolution: {integrity: sha512-FVVTkD1vENCsAcwNs9k6jea2uHC/X0+JcjG8YA60FN5CMaJmG95wT9jek/xX9nornqGRrBkKtzuAu2wuHpKqvw==} - engines: {node: '>= 0.4'} - dependencies: - call-bind: 1.0.2 - define-properties: 1.2.0 - es-abstract: 1.21.1 - dev: true - /ofetch@1.1.1: resolution: {integrity: sha512-SSMoktrp9SNLi20BWfB/BnnKcL0RDigXThD/mZBeQxkIRv1xrd9183MtLdsqRYLYSqW0eTr5t8w8MqjNhvoOQQ==} dependencies: @@ -3887,22 +3763,13 @@ packages: esprima: 4.0.1 source-map: 0.6.1 tslib: 2.5.0 - dev: false + dev: true /regexp-tree@0.1.24: resolution: {integrity: sha512-s2aEVuLhvnVJW6s/iPgEGK6R+/xngd2jNQ+xy4bXNDKxZKJH6jpPHY6kVeVv1IeLCHgswRj+Kl3ELaDjG6V1iw==} hasBin: true dev: true - /regexp.prototype.flags@1.4.3: - resolution: {integrity: sha512-fjggEOO3slI6Wvgjwflkc4NFRCTZAu5CnNfBd5qOMYhWdn67nJBBu34/TkD++eeFmd8C9r9jfXJ27+nSiRkSUA==} - engines: {node: '>= 0.4'} - dependencies: - call-bind: 1.0.2 - define-properties: 1.2.0 - functions-have-names: 1.2.3 - dev: true - /regexpp@3.2.0: resolution: {integrity: sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==} engines: {node: '>=8'} @@ -3928,7 +3795,7 @@ packages: resolution: {integrity: sha512-Sb+mjNHOULsBv818T40qSPeRiuWLyaGMa5ewydRLFimneixmVy2zdivRl+AF6jaYPC8ERxGDmFSiqui6SfPd+g==} hasBin: true dependencies: - is-core-module: 2.12.1 + is-core-module: 2.13.0 path-parse: 1.0.7 supports-preserve-symlinks-flag: 1.0.0 dev: true @@ -4000,14 +3867,6 @@ packages: queue-microtask: 1.2.3 dev: true - /safe-regex-test@1.0.0: - resolution: {integrity: sha512-JBUUzyOgEwXQY1NuPtvcj/qcBDbDmEvWufhlnXZIm75DEHp+afM1r1ujJpJsV/gSM4t59tpDyPi1sd6ZaPFfsA==} - dependencies: - call-bind: 1.0.2 - get-intrinsic: 1.2.0 - is-regex: 1.1.4 - dev: true - /safe-regex@2.1.1: resolution: {integrity: sha512-rx+x8AMzKb5Q5lQ95Zoi6ZbJqwCLkqi3XuJXp5P3rT8OEc6sZCJG5AE5dU3lsgRr/F4Bs31jSlVN+j5KrsGu9A==} dependencies: @@ -4053,14 +3912,6 @@ packages: engines: {node: '>=8'} dev: true - /side-channel@1.0.4: - resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==} - dependencies: - call-bind: 1.0.2 - get-intrinsic: 1.2.0 - object-inspect: 1.12.3 - dev: true - /siginfo@2.0.0: resolution: {integrity: sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==} dev: true @@ -4110,11 +3961,11 @@ packages: /source-map-js@1.0.2: resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==} engines: {node: '>=0.10.0'} - dev: true /source-map@0.6.1: resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} engines: {node: '>=0.10.0'} + dev: true /spdx-correct@3.1.1: resolution: {integrity: sha512-cOYcUWwhCuHCXi49RhFRCyJEK3iPj1Ziz9DpViV3tbZOwXD49QzIN3MpOLJNxh2qwq2lJJZaKMVw9qNi4jTC0w==} @@ -4164,22 +4015,6 @@ packages: strip-ansi: 7.0.1 dev: true - /string.prototype.trimend@1.0.6: - resolution: {integrity: sha512-JySq+4mrPf9EsDBEDYMOb/lM7XQLulwg5R/m1r0PXEFqrV0qHvl58sdTilSXtKOflCsK2E8jxf+GKC0T07RWwQ==} - dependencies: - call-bind: 1.0.2 - define-properties: 1.2.0 - es-abstract: 1.21.1 - dev: true - - /string.prototype.trimstart@1.0.6: - resolution: {integrity: sha512-omqjMDaY92pbn5HOX7f9IccLA+U1tA9GvtU4JrodiXFfYB7jPzzHpRzpglLAjtUV6bB557zwClJezTqnAiYnQA==} - dependencies: - call-bind: 1.0.2 - define-properties: 1.2.0 - es-abstract: 1.21.1 - dev: true - /strip-ansi@6.0.1: resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==} engines: {node: '>=8'} @@ -4285,6 +4120,31 @@ packages: resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==} dev: true + /tiged@2.12.5: + resolution: {integrity: sha512-divl34KaEXBUO8N2m5UcMdQZjqLZRzEq+ychP5bNYSGF0JQq1j6m4uF7WuQOCRomlBeu5vJfjkXtyYumijX+bA==} + engines: {node: '>=8.0.0'} + hasBin: true + dependencies: + colorette: 1.2.1 + enquirer: 2.3.6 + fs-extra: 10.1.0 + fuzzysearch: 1.0.3 + https-proxy-agent: 5.0.0 + mri: 1.1.6 + rimraf: 3.0.2 + tar: 6.1.13 + tiny-glob: 0.2.8 + transitivePeerDependencies: + - supports-color + dev: true + + /tiny-glob@0.2.8: + resolution: {integrity: sha512-vkQP7qOslq63XRX9kMswlby99kyO5OvKptw7AMwBVMjXEI7Tb61eoI5DydyEMOseyGS5anDN1VPoVxEvH01q8w==} + dependencies: + globalyzer: 0.1.0 + globrex: 0.1.2 + dev: true + /tiny-glob@0.2.9: resolution: {integrity: sha512-g/55ssRPUjShh+xkfx9UPDXqhckHEsHr4Vd9zX55oSdGZc/MD0m3sferOkwWtp98bv+kcVfEHtRJgBVJzelrzg==} dependencies: @@ -4342,6 +4202,7 @@ packages: /tslib@2.5.0: resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==} + dev: true /tsutils@3.21.0(typescript@5.2.2): resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} @@ -4385,14 +4246,6 @@ packages: engines: {node: '>=10'} dev: true - /typed-array-length@1.0.4: - resolution: {integrity: sha512-KjZypGq+I/H7HI5HlOoGHkWUUGq+Q0TPhQurLbyrVrvnKTBgzLhIJ7j6J/XTQOi0d1RjyZ0wdas8bKs2p0x3Ng==} - dependencies: - call-bind: 1.0.2 - for-each: 0.3.3 - is-typed-array: 1.1.10 - dev: true - /typescript@5.2.2: resolution: {integrity: sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==} engines: {node: '>=14.17'} @@ -4403,15 +4256,6 @@ packages: resolution: {integrity: sha512-TrY6DsjTQQgyS3E3dBaOXf0TpPD8u9FVrVYmKVegJuFw51n/YB9XPt+U6ydzFG5ZIN7+DIjPbNmXoBj9esYhgQ==} dev: true - /unbox-primitive@1.0.2: - resolution: {integrity: sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==} - dependencies: - call-bind: 1.0.2 - has-bigints: 1.0.2 - has-symbols: 1.0.3 - which-boxed-primitive: 1.0.2 - dev: true - /unbuild@2.0.0(typescript@5.2.2): resolution: {integrity: sha512-JWCUYx3Oxdzvw2J9kTAp+DKE8df/BnH/JTSj6JyA4SH40ECdFu7FoJJcrm8G92B7TjofQ6GZGjJs50TRxoH6Wg==} hasBin: true @@ -4497,11 +4341,11 @@ packages: resolution: {integrity: sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==} dependencies: inherits: 2.0.4 - is-arguments: 1.1.1 - is-generator-function: 1.0.10 + is-arguments: /@nolyfill/is-arguments@1.0.21 + is-generator-function: /@nolyfill/is-generator-function@1.0.21 is-typed-array: 1.1.10 - which-typed-array: 1.1.9 - dev: false + which-typed-array: /@nolyfill/which-typed-array@1.0.21 + dev: true /v8-to-istanbul@9.1.0: resolution: {integrity: sha512-6z3GW9x8G1gd+JIIgQQQxXuiJtCXeAjp6RaPEPLv62mH3iPHPxV6W3robxtCzNErRo6ZwTmzWhsbNvjyEBKzKA==} @@ -4639,27 +4483,6 @@ packages: - terser dev: true - /which-boxed-primitive@1.0.2: - resolution: {integrity: sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==} - dependencies: - is-bigint: 1.0.4 - is-boolean-object: 1.1.2 - is-number-object: 1.0.7 - is-string: 1.0.7 - is-symbol: 1.0.4 - dev: true - - /which-typed-array@1.1.9: - resolution: {integrity: sha512-w9c4xkx6mPidwp7180ckYWfMmvxpjlZuIudNtDf4N/tTAUB8VJbX25qZoAsrtGuYNnGw3pa0AXgbGKRB8/EceA==} - engines: {node: '>= 0.4'} - dependencies: - available-typed-arrays: 1.0.5 - call-bind: 1.0.2 - for-each: 0.3.3 - gopd: 1.0.1 - has-tostringtag: 1.0.0 - is-typed-array: 1.1.10 - /which@2.0.2: resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} engines: {node: '>= 8'} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..d50ce2a --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - stubs/* diff --git a/scripts/vendor.ts b/scripts/vendor.ts new file mode 100644 index 0000000..b4ba6c2 --- /dev/null +++ b/scripts/vendor.ts @@ -0,0 +1,96 @@ +/* eslint-disable unicorn/prefer-top-level-await */ +import fs from 'node:fs' +import fsp from 'node:fs/promises' +import { execa } from 'execa' + +// This script clones recast and patches, and then re-bundle it so we get rid of the unnecessary polyfills + +async function cloneRecast() { + if (fs.existsSync('vendor/recast')) { + console.log('vendor/recast already exists') + } + else { + // Clone recast + await execa('npx', ['tiged', 'benjamn/recast#v0.23.4', 'vendor/recast'], { stdio: 'inherit' }) + + // Remove the tsconfig.json so it's targeting newer node versions + await fsp.rm('vendor/recast/tsconfig.json') + + // Remove the assert import and usage + await filterLines('vendor/recast/lib/patcher.ts', (line) => { + if (line.startsWith('import assert from')) { + return false + } + if (/^\s*assert\./.test(line)) { + return `false && ` + line + } + return line + }) + await filterLines('vendor/recast/lib/patcher.ts', (line) => { + if (line.startsWith('import assert from')) { + return false + } + if (/^\s*assert\./.test(line)) { + return `false && ` + line + } + return line + }) + + // Remove the require(), and since we are providing our own parser anyway + await filterLines('vendor/recast/lib/options.ts', (line) => { + if (line.includes('parser: require("../parsers/esprima")')) { + return false + } + return line + }) + + await filterLines('vendor/recast/lib/util.ts', (line) => { + if (line.includes('isBrowser() ? "\\n"')) { return 'return "\\n"' } + return line + }) + + console.log('vendor/recast cloned') + } +} + + +async function cloneAstTypes() { + if (fs.existsSync('vendor/ast-types')) { + console.log('vendor/ast-types already exists') + } + else { + // Clone recast + await execa('npx', ['tiged', 'benjamn/ast-types#v0.16.1', 'vendor/ast-types'], { stdio: 'inherit' }) + + // Remove the tsconfig.json so it's targeting newer node versions + await fsp.rm('vendor/ast-types/tsconfig.json') + + // Add import type + await filterLines('vendor/ast-types/src/main.ts', (line) => { + if (/^import\s*{\s*(ASTNode|Visitor)/.test(line)) { + return line.replace(/^import /, 'import type ') + } + return line + }) + + console.log('vendor/ast-types cloned') + } +} + +async function filterLines(file: string, filter: (line: string, index: number) => boolean | string) { + const content = await fsp.readFile(file, 'utf8') + const lines = content.split('\n') + const newContent = lines + .map((i, idx) => filter(i, idx)) + .filter(i => i !== false) + .join('\n') + if (newContent !== content) { + await fsp.writeFile(file, newContent) + } +} + + +await Promise.all([ + cloneRecast(), + cloneAstTypes(), +]) diff --git a/src/builders.ts b/src/builders.ts index 2349958..a072610 100644 --- a/src/builders.ts +++ b/src/builders.ts @@ -14,7 +14,7 @@ export const builders = { functionCall(callee: string, ...args: any[]): Proxified { const node = b.callExpression( b.identifier(callee), - args.map((i) => literalToAst(i) as any) + args.map((i) => literalToAst(i) as any), ); return proxifyFunctionCall(node as any); }, @@ -24,7 +24,7 @@ export const builders = { newExpression(callee: string, ...args: any[]): Proxified { const node = b.newExpression( b.identifier(callee), - args.map((i) => literalToAst(i) as any) + args.map((i) => literalToAst(i) as any), ); return proxifyNewExpression(node as any); }, diff --git a/src/code.ts b/src/code.ts index 51c1b02..e030d7a 100644 --- a/src/code.ts +++ b/src/code.ts @@ -14,7 +14,7 @@ import { proxify } from "./proxy/proxify"; export function parseModule( code: string, - options?: ParseOptions + options?: ParseOptions, ): ProxifiedModule { const node: ParsedFileNode = parse(code, { parser: options?.parser || getBabelParser(), @@ -25,7 +25,7 @@ export function parseModule( export function parseExpression( code: string, - options?: ParseOptions + options?: ParseOptions, ): Proxified { const root: ParsedFileNode = parse("(" + code + ")", { parser: options?.parser || getBabelParser(), @@ -50,7 +50,7 @@ export function parseExpression( export function generateCode( node: { $ast: ASTNode } | ASTNode | ProxifiedModule, - options: GenerateOptions = {} + options: GenerateOptions = {}, ): { code: string; map?: any } { const ast = (node as Proxified).$ast || node; @@ -69,7 +69,7 @@ export function generateCode( export async function loadFile( filename: string, - options: ParseOptions = {} + options: ParseOptions = {}, ): Promise> { const contents = await fsp.readFile(filename, "utf8"); options.sourceFileName = options.sourceFileName ?? filename; @@ -79,7 +79,7 @@ export async function loadFile( export async function writeFile( node: { ast: ASTNode } | ASTNode, filename?: string, - options?: ParseOptions + options?: ParseOptions, ): Promise { const ast = "ast" in node ? node.ast : node; const { code, map } = generateCode(ast, options); diff --git a/src/format.ts b/src/format.ts index a71760d..669f3d0 100644 --- a/src/format.ts +++ b/src/format.ts @@ -13,7 +13,7 @@ export interface CodeFormatOptions { export function detectCodeFormat( code: string, - userStyles: CodeFormatOptions = {} + userStyles: CodeFormatOptions = {}, ): CodeFormatOptions { // Detect features only user not specified const detect = { diff --git a/src/helpers/config.ts b/src/helpers/config.ts index 2a9a347..71be36a 100644 --- a/src/helpers/config.ts +++ b/src/helpers/config.ts @@ -25,14 +25,14 @@ export function getDefaultExportOptions(magicast: ProxifiedModule) { * If no config declaration is found, undefined is returned. */ export function getConfigFromVariableDeclaration( - magicast: ProxifiedModule + magicast: ProxifiedModule, ): { declaration: VariableDeclarator; config: ProxifiedObject | undefined; } { if (magicast.exports.default.$type !== "identifier") { throw new MagicastError( - `Not supported: Cannot modify this kind of default export (${magicast.exports.default.$type})` + `Not supported: Cannot modify this kind of default export (${magicast.exports.default.$type})`, ); } diff --git a/src/helpers/nuxt.ts b/src/helpers/nuxt.ts index 61afa94..ccc5cfe 100644 --- a/src/helpers/nuxt.ts +++ b/src/helpers/nuxt.ts @@ -6,7 +6,7 @@ export function addNuxtModule( magicast: ProxifiedModule, name: string, optionsKey?: string, - options?: any + options?: any, ) { const config = getDefaultExportOptions(magicast); diff --git a/src/helpers/vite.ts b/src/helpers/vite.ts index 657b5c3..1b51eb8 100644 --- a/src/helpers/vite.ts +++ b/src/helpers/vite.ts @@ -51,7 +51,7 @@ export interface UpdateVitePluginConfigOptions { export function addVitePlugin( magicast: ProxifiedModule, - plugin: AddVitePluginOptions + plugin: AddVitePluginOptions, ) { const config: Proxified | undefined = getDefaultExportOptions(magicast); @@ -72,7 +72,7 @@ export function addVitePlugin( export function findVitePluginCall( magicast: ProxifiedModule, - plugin: UpdateVitePluginConfigOptions | string + plugin: UpdateVitePluginConfigOptions | string, ): ProxifiedFunctionCall | undefined { const _plugin = typeof plugin === "string" ? { from: plugin, imported: "default" } : plugin; @@ -81,18 +81,18 @@ export function findVitePluginCall( const constructor = magicast.imports.$items.find( (i) => - i.from === _plugin.from && i.imported === (_plugin.imported || "default") + i.from === _plugin.from && i.imported === (_plugin.imported || "default"), )?.local; return config.plugins?.find( - (p: any) => p && p.$type === "function-call" && p.$callee === constructor + (p: any) => p && p.$type === "function-call" && p.$callee === constructor, ); } export function updateVitePluginConfig( magicast: ProxifiedModule, plugin: UpdateVitePluginConfigOptions | string, - handler: Record | ((args: any[]) => any[]) + handler: Record | ((args: any[]) => any[]), ) { const item = findVitePluginCall(magicast, plugin); if (!item) { @@ -116,7 +116,7 @@ export function updateVitePluginConfig( */ function insertPluginIntoVariableDeclarationConfig( magicast: ProxifiedModule, - plugin: AddVitePluginOptions + plugin: AddVitePluginOptions, ) { const { config: configObject, declaration } = getConfigFromVariableDeclaration(magicast); @@ -133,7 +133,7 @@ function insertPluginIntoVariableDeclarationConfig( ) { // @ts-ignore this works despite the type error because of recast declaration.init = generateCode( - builders.functionCall(declaration.init.callee.name, configObject) + builders.functionCall(declaration.init.callee.name, configObject), ).code; } } @@ -149,6 +149,6 @@ function insertPluginIntoConfig(plugin: AddVitePluginOptions, config: any) { 0, plugin.options ? builders.functionCall(plugin.constructor, plugin.options) - : builders.functionCall(plugin.constructor) + : builders.functionCall(plugin.constructor), ); } diff --git a/src/proxy/_utils.ts b/src/proxy/_utils.ts index c65c800..6d63cd9 100644 --- a/src/proxy/_utils.ts +++ b/src/proxy/_utils.ts @@ -74,13 +74,13 @@ export function literalToAst(value: any, seen = new Set()): ASTNode { literalToAst(key, seen) as any, literalToAst(value, seen) as any, ]) as any; - }) as any + }) as any, ), ]) as any; } if (Array.isArray(value)) { return b.arrayExpression( - value.map((n) => literalToAst(n, seen)) as any + value.map((n) => literalToAst(n, seen)) as any, ) as any; } if (typeof value === "object") { @@ -89,9 +89,9 @@ export function literalToAst(value: any, seen = new Set()): ASTNode { return b.property( "init", /^[$A-Z_a-z][\w$]*$/g.test(key) ? b.identifier(key) : b.literal(key), - literalToAst(value, seen) as any + literalToAst(value, seen) as any, ) as any; - }) + }), ) as any; } return b.literal(value) as any; @@ -99,7 +99,7 @@ export function literalToAst(value: any, seen = new Set()): ASTNode { export function makeProxyUtils( node: ASTNode, - extend: T = {} as T + extend: T = {} as T, ): Record { const obj = extend as any; obj[PROXY_KEY] = true; @@ -116,7 +116,7 @@ const propertyDescriptor = { export function createProxy( node: ASTNode, extend: any, - handler: ProxyHandler + handler: ProxyHandler, ): T { const utils = makeProxyUtils(node, extend); return new Proxy( @@ -124,7 +124,7 @@ export function createProxy( { ownKeys() { return Object.keys(utils).filter( - (i) => i !== PROXY_KEY && !i.startsWith("$") + (i) => i !== PROXY_KEY && !i.startsWith("$"), ); }, getOwnPropertyDescriptor() { @@ -155,6 +155,6 @@ export function createProxy( } return false; }, - } + }, ) as T; } diff --git a/src/proxy/array.ts b/src/proxy/array.ts index ff91783..e13cb8c 100644 --- a/src/proxy/array.ts +++ b/src/proxy/array.ts @@ -6,7 +6,7 @@ import { proxify } from "./proxify"; export function proxifyArrayElements( node: ASTNode, elements: ASTNode[], - mod?: ProxifiedModule + mod?: ProxifiedModule, ): ProxifiedArray { const getItem = (key: number) => { return elements[key]; @@ -36,7 +36,7 @@ export function proxifyArrayElements( const deleted = elements.splice( start, deleteCount, - ...items.map((n) => literalToAst(n)) + ...items.map((n) => literalToAst(n)), ); return deleted.map((n) => proxify(n as any, mod)); }, @@ -104,13 +104,13 @@ export function proxifyArrayElements( ownKeys() { return ["length", ...elements.map((_, i) => i.toString())]; }, - } + }, ); } export function proxifyArray( node: ASTNode, - mod?: ProxifiedModule + mod?: ProxifiedModule, ): ProxifiedArray { if (!("elements" in node)) { return undefined as any; diff --git a/src/proxy/exports.ts b/src/proxy/exports.ts index af16c16..a6000b0 100644 --- a/src/proxy/exports.ts +++ b/src/proxy/exports.ts @@ -53,8 +53,8 @@ export function createExportsProxy(root: Program, mod: ProxifiedModule) { : (b.exportNamedDeclaration( b.variableDeclaration("const", [ b.variableDeclarator(b.identifier(key), node), - ]) - ) as any) + ]), + ) as any), ); }; @@ -86,7 +86,7 @@ export function createExportsProxy(root: Program, mod: ProxifiedModule) { "declarations" in i.declaration ) { return i.declaration.declarations.map((d) => - "name" in d.id ? d.id.name : "" + "name" in d.id ? d.id.name : "", ); } return []; @@ -117,6 +117,6 @@ export function createExportsProxy(root: Program, mod: ProxifiedModule) { } return false; }, - } + }, ); } diff --git a/src/proxy/function-call.ts b/src/proxy/function-call.ts index 55c94fb..1eb020a 100644 --- a/src/proxy/function-call.ts +++ b/src/proxy/function-call.ts @@ -6,7 +6,7 @@ import { proxifyArrayElements } from "./array"; export function proxifyFunctionCall( node: ASTNode, - mod?: ProxifiedModule + mod?: ProxifiedModule, ): ProxifiedFunctionCall { if (node.type !== "CallExpression") { throw new MagicastError("Not a function call"); @@ -18,7 +18,7 @@ export function proxifyFunctionCall( } if (node.type === "MemberExpression") { return `${stringifyExpression(node.object)}.${stringifyExpression( - node.property + node.property, )}`; } throw new MagicastError("Not implemented"); @@ -33,6 +33,6 @@ export function proxifyFunctionCall( $callee: stringifyExpression(node.callee as any), $args: argumentsProxy, }, - {} + {}, ) as ProxifiedFunctionCall; } diff --git a/src/proxy/identifier.ts b/src/proxy/identifier.ts index 4b2de5f..4d7cde5 100644 --- a/src/proxy/identifier.ts +++ b/src/proxy/identifier.ts @@ -13,6 +13,6 @@ export function proxifyIdentifier(node: ASTNode): ProxifiedIdentifier { $type: "identifier", $name: node.name, }, - {} + {}, ) as ProxifiedIdentifier; } diff --git a/src/proxy/imports.ts b/src/proxy/imports.ts index 57108b6..e033b56 100644 --- a/src/proxy/imports.ts +++ b/src/proxy/imports.ts @@ -25,7 +25,7 @@ export function creatImportProxy( | ImportSpecifier | ImportNamespaceSpecifier | ImportDefaultSpecifier, - root: Program + root: Program, ): ProxifiedImportItem { if (_importProxyCache.has(specifier)) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -52,7 +52,7 @@ export function creatImportProxy( set imported(value) { if (specifier.type !== "ImportSpecifier") { throw new MagicastError( - "Changing import name is not yet implemented" + "Changing import name is not yet implemented", ); } if (specifier.imported.type === "Identifier") { @@ -81,7 +81,7 @@ export function creatImportProxy( } const declaration = root.body.find( - (i) => i.type === "ImportDeclaration" && i.source.value === value + (i) => i.type === "ImportDeclaration" && i.source.value === value, ) as ImportDeclaration | undefined; if (declaration) { // TODO: insert after the last import maybe? @@ -90,8 +90,8 @@ export function creatImportProxy( root.body.unshift( b.importDeclaration( [specifier as any], - b.stringLiteral(value) - ) as any + b.stringLiteral(value), + ) as any, ); } }, @@ -107,7 +107,7 @@ export function creatImportProxy( ownKeys() { return ["imported", "local", "from", "toJSON"]; }, - } + }, ) as ProxifiedImportItem; _importProxyCache.set(specifier, proxy); return proxy; @@ -116,7 +116,7 @@ export function creatImportProxy( export function createImportsProxy( root: Program, // eslint-disable-next-line @typescript-eslint/no-unused-vars - mod: ProxifiedModule + mod: ProxifiedModule, ): ProxifiedImportsMap { // TODO: cache const getAllImports = () => { @@ -149,15 +149,14 @@ export function createImportsProxy( ? b.importNamespaceSpecifier(b.identifier(local)) : b.importSpecifier(b.identifier(value.imported), b.identifier(local)); - const declaration = imports.find( - (i) => i.from === value.from - )?.$declaration; + const declaration = imports.find((i) => i.from === value.from) + ?.$declaration; if (declaration) { // TODO: insert after the last import maybe? declaration.specifiers.push(specifier as any); } else { root.body.unshift( - b.importDeclaration([specifier], b.stringLiteral(value.from)) as any + b.importDeclaration([specifier], b.stringLiteral(value.from)) as any, ); } return true; @@ -211,7 +210,7 @@ export function createImportsProxy( has(_, prop) { return getAllImports().some((i) => i.local === prop); }, - } + }, ) as any as ProxifiedImportsMap; return proxy; diff --git a/src/proxy/module.ts b/src/proxy/module.ts index b529523..b9318f8 100644 --- a/src/proxy/module.ts +++ b/src/proxy/module.ts @@ -9,7 +9,7 @@ import { createProxy } from "./_utils"; export function proxifyModule( ast: ParsedFileNode, - code: string + code: string, ): ProxifiedModule { const root = ast.program; if (root.type !== "Program") { diff --git a/src/proxy/new-expression.ts b/src/proxy/new-expression.ts index 04718ad..08e8265 100644 --- a/src/proxy/new-expression.ts +++ b/src/proxy/new-expression.ts @@ -6,7 +6,7 @@ import { proxifyArrayElements } from "./array"; export function proxifyNewExpression( node: ASTNode, - mod?: ProxifiedModule + mod?: ProxifiedModule, ): ProxifiedNewExpression { if (node.type !== "NewExpression") { throw new MagicastError("Not a new expression"); @@ -18,7 +18,7 @@ export function proxifyNewExpression( } if (node.type === "MemberExpression") { return `${stringifyExpression(node.object)}.${stringifyExpression( - node.property + node.property, )}`; } throw new MagicastError("Not implemented"); @@ -33,6 +33,6 @@ export function proxifyNewExpression( $callee: stringifyExpression(node.callee as any), $args: argumentsProxy, }, - {} + {}, ) as ProxifiedNewExpression; } diff --git a/src/proxy/object.ts b/src/proxy/object.ts index 62aec08..9285b1f 100644 --- a/src/proxy/object.ts +++ b/src/proxy/object.ts @@ -9,7 +9,7 @@ const b = recast.types.builders; export function proxifyObject( node: ASTNode, - mod?: ProxifiedModule + mod?: ProxifiedModule, ): ProxifiedObject { if (!("properties" in node)) { return undefined as any; @@ -35,7 +35,7 @@ export function proxifyObject( const getPropName = ( prop: (typeof node.properties)[0], - throwError = false + throwError = false, ) => { if ("key" in prop && "name" in prop.key) { return prop.key.name; @@ -58,7 +58,7 @@ export function proxifyObject( const replaceOrAddProp = (key: string, value: ASTNode) => { const prop = (node.properties as any[]).find( - (prop: any) => getPropName(prop) === key + (prop: any) => getPropName(prop) === key, ); if (prop) { prop.value = value; @@ -114,7 +114,8 @@ export function proxifyObject( key = String(key); } const index = node.properties.findIndex( - (prop) => "key" in prop && "name" in prop.key && prop.key.name === key + (prop) => + "key" in prop && "name" in prop.key && prop.key.name === key, ); if (index !== -1) { node.properties.splice(index, 1); @@ -126,6 +127,6 @@ export function proxifyObject( .map((prop) => getPropName(prop, true)) .filter(Boolean) as string[]; }, - } + }, ) as ProxifiedObject; } diff --git a/test/_utils.ts b/test/_utils.ts index 043643b..5b27f61 100644 --- a/test/_utils.ts +++ b/test/_utils.ts @@ -2,5 +2,7 @@ import { format } from "prettier"; import { generateCode } from "../src"; export function generate(mod: any) { - return format(generateCode(mod).code, { parser: "babel-ts" }).trim(); + return format(generateCode(mod).code, { parser: "babel-ts" }).then((code) => + code.trim(), + ); } diff --git a/test/array.test.ts b/test/array.test.ts index 0cc1871..5e20804 100644 --- a/test/array.test.ts +++ b/test/array.test.ts @@ -1,11 +1,11 @@ import { describe, expect, it } from "vitest"; -import { parseModule } from "../src"; +import { parseModule } from "magicast"; import { generate } from "./_utils"; describe("array", () => { - it("array operations", () => { + it("array operations", async () => { const mod = parseModule<{ default: (number | any | string)[] }>( - `export default [1, 2, 3, 4, 5]` + `export default [1, 2, 3, 4, 5]`, ); expect(mod.exports.default.length).toBe(5); @@ -16,7 +16,7 @@ describe("array", () => { expect(deleted).toEqual([2, 3, 4]); - expect(generate(mod)).toMatchInlineSnapshot( + expect(await generate(mod)).toMatchInlineSnapshot( ` "export default [ 1, @@ -26,11 +26,11 @@ describe("array", () => { \\"bar\\", 5, ];" - ` + `, ); const foundIndex = mod.exports.default.findIndex( - (item) => item.foo === "bar" + (item) => item.foo === "bar", ); const found = mod.exports.default.find((item) => item.foo === "bar"); diff --git a/test/builders/expression.test.ts b/test/builders/expression.test.ts index 9d6977f..9f24089 100644 --- a/test/builders/expression.test.ts +++ b/test/builders/expression.test.ts @@ -1,9 +1,9 @@ import { describe, expect, it } from "vitest"; -import { builders, parseModule } from "../../src"; +import { builders, parseModule } from "magicast"; import { generate } from "../_utils"; describe("builders/expression", () => { - it("new expression", () => { + it("new expression", async () => { const call = builders.newExpression("Foo", 1, "bar", { foo: "bar", }); @@ -22,7 +22,7 @@ describe("builders/expression", () => { const mod = parseModule(""); mod.exports.a = call; - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export const a = new Foo(1, \\"bar\\", { foo: \\"bar\\", });" diff --git a/test/builders/function-call.test.ts b/test/builders/function-call.test.ts index 07f6a99..3f83b7f 100644 --- a/test/builders/function-call.test.ts +++ b/test/builders/function-call.test.ts @@ -1,9 +1,9 @@ import { describe, expect, it } from "vitest"; -import { builders, parseModule } from "../../src"; +import { builders, parseModule } from "magicast"; import { generate } from "../_utils"; describe("builders/functionCall", () => { - it("new", () => { + it("new", async () => { const call = builders.functionCall("functionName", 1, "bar", { foo: "bar", }); @@ -22,7 +22,7 @@ describe("builders/functionCall", () => { const mod = parseModule(""); mod.exports.a = call; - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export const a = functionName(1, \\"bar\\", { foo: \\"bar\\", });" diff --git a/test/builders/raw.test.ts b/test/builders/raw.test.ts index ae8b859..5f3d25f 100644 --- a/test/builders/raw.test.ts +++ b/test/builders/raw.test.ts @@ -1,40 +1,40 @@ import { describe, expect, it } from "vitest"; -import { builders, parseModule } from "../../src"; +import { builders, parseModule } from "magicast"; import { generate } from "../_utils"; describe("builders/raw", () => { - it("object", () => { + it("object", async () => { const expression = builders.raw("{ foo: 1 }"); expect(expression.$type).toBe("object"); expect(expression.foo).toBe(1); const mod = parseModule(""); mod.exports.a = expression; - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export const a = { foo: 1, };" `); }); - it("identifier", () => { + it("identifier", async () => { const expression = builders.raw("foo"); expect(expression.$type).toBe("identifier"); expect(expression.$name).toBe("foo"); const mod = parseModule(""); mod.exports.a = expression; - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export const a = foo;" `); }); - it("identifier as property", () => { + it("identifier as property", async () => { const mod = parseModule(""); mod.exports.default ||= {}; mod.exports.default.foo = builders.raw("foo"); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default { foo: foo, };" diff --git a/test/errors.test.ts b/test/errors.test.ts index e9c9d78..1e865da 100644 --- a/test/errors.test.ts +++ b/test/errors.test.ts @@ -1,5 +1,5 @@ import { expect, describe, it } from "vitest"; -import { parseExpression, parseModule } from "../src"; +import { parseExpression, parseModule } from "magicast"; import { generate } from "./_utils"; describe("errors", () => { @@ -11,7 +11,7 @@ export default { ? 1 : 2 } - `.trim() + `.trim(), ); expect(() => mod.exports.default.a).toThrowErrorMatchingInlineSnapshot( @@ -25,7 +25,7 @@ export default { 4 | : 2 5 | } " - ` + `, ); }); @@ -35,7 +35,7 @@ export default { export default { a: 1 + 1 } - `.trim() + `.trim(), ); expect(() => mod.exports.default.a).toThrowErrorMatchingInlineSnapshot( @@ -47,11 +47,11 @@ export default { ^ 3 | } " - ` + `, ); }); - it("array destructuring", () => { + it("array destructuring", async () => { const mod = parseModule( ` export default { @@ -61,12 +61,12 @@ export default { ...foo ] } - `.trim() + `.trim(), ); // Adding an item should work mod.exports.default.foo.push("foo"); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default { foo: [1, 2, ...foo, \\"foo\\"], };" @@ -86,11 +86,11 @@ export default { 6 | ] 7 | } " - ` + `, ); }); - it("object destructuring", () => { + it("object destructuring", async () => { const mod = parseModule( ` export default { @@ -99,12 +99,12 @@ export default { ...bar } } - `.trim() + `.trim(), ); // Adding a property should work mod.exports.default.foo.extra = "foo"; - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default { foo: { a: 1, @@ -128,7 +128,7 @@ export default { 5 | } 6 | } " - ` + `, ); }); diff --git a/test/exports.test.ts b/test/exports.test.ts index 8e916ee..69d8ae8 100644 --- a/test/exports.test.ts +++ b/test/exports.test.ts @@ -1,18 +1,18 @@ import { expect, it, describe } from "vitest"; -import { parseModule } from "../src"; +import { parseModule } from "magicast"; import { generate } from "./_utils"; describe("exports", () => { - it("manipulate exports", () => { + it("manipulate exports", async () => { const mod = parseModule(""); expect(Object.keys(mod.exports)).toEqual([]); expect(mod.exports).toMatchInlineSnapshot(`{}`); - expect(generate(mod)).toMatchInlineSnapshot('""'); + expect(await generate(mod)).toMatchInlineSnapshot('""'); mod.exports.default = { foo: "1" }; - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default { foo: \\"1\\", };" @@ -20,7 +20,7 @@ describe("exports", () => { mod.exports.default.foo = 2; - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default { foo: 2, };" @@ -31,7 +31,7 @@ describe("exports", () => { expect(Object.keys(mod.exports)).toEqual(["default", "named"]); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default { foo: 2, }; @@ -57,14 +57,14 @@ describe("exports", () => { // delete delete mod.exports.default; - expect(generate(mod)).toMatchInlineSnapshot( - '"export const named = [\\"a\\"];"' + expect(await generate(mod)).toMatchInlineSnapshot( + '"export const named = [\\"a\\"];"', ); delete mod.exports.named; expect(Object.keys(mod.exports)).toEqual([]); - expect(generate(mod)).toMatchInlineSnapshot('""'); + expect(await generate(mod)).toMatchInlineSnapshot('""'); }); }); diff --git a/test/format.test.ts b/test/format.test.ts index b818adf..41f841e 100644 --- a/test/format.test.ts +++ b/test/format.test.ts @@ -1,5 +1,5 @@ import { expect, it, describe } from "vitest"; -import { CodeFormatOptions, detectCodeFormat } from "../src"; +import { CodeFormatOptions, detectCodeFormat } from "magicast"; describe("format", () => { const cases: Array<{ diff --git a/test/function-call.test.ts b/test/function-call.test.ts index 25a636a..fa467d4 100644 --- a/test/function-call.test.ts +++ b/test/function-call.test.ts @@ -1,9 +1,9 @@ import { describe, expect, it } from "vitest"; -import { builders, parseModule, ProxifiedModule } from "../src"; +import { builders, parseModule, ProxifiedModule } from "magicast"; import { generate } from "./_utils"; describe("function-calls", () => { - it("function wrapper", () => { + it("function wrapper", async () => { const mod = parseModule(` export const a: any = { foo: 1} export default defineConfig({ @@ -30,7 +30,7 @@ describe("function-calls", () => { options.modules ||= []; options.modules.push("b"); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export const a: any = { foo: 1 }; export default defineConfig({ // Modules @@ -39,7 +39,7 @@ describe("function-calls", () => { `); }); - it("construct function call", () => { + it("construct function call", async () => { // eslint-disable-next-line unicorn/consistent-function-scoping const installVuePlugin = (mod: ProxifiedModule) => { // Inject export default if not exists @@ -69,7 +69,7 @@ describe("function-calls", () => { config.plugins.push( builders.functionCall("vuePlugin", { jsx: true, - }) + }), ); }; @@ -83,7 +83,7 @@ describe("function-calls", () => { installVuePlugin(mod1); installVuePlugin(mod2); - expect(generate(mod1)).toMatchInlineSnapshot(` + expect(await generate(mod1)).toMatchInlineSnapshot(` "import vuePlugin from \\"@vitejs/plugin-vue\\"; import { defineConfig } from \\"vite\\"; @@ -96,6 +96,6 @@ describe("function-calls", () => { });" `); - expect(generate(mod2)).toEqual(generate(mod1)); + expect(await generate(mod2)).toEqual(await generate(mod1)); }); }); diff --git a/test/general.test.ts b/test/general.test.ts index 146cc20..8aa5af5 100644 --- a/test/general.test.ts +++ b/test/general.test.ts @@ -1,20 +1,20 @@ import { expect, it, describe } from "vitest"; -import { generateCode, parseModule, parseExpression } from "../src"; +import { generateCode, parseModule, parseExpression } from "magicast"; import { generate } from "./_utils"; describe("general", () => { - it("basic object and array", () => { + it("basic object and array", async () => { const mod = parseModule(`export default { a: 1, b: { c: {} } }`); mod.exports.default.a = 2; - expect(generate(mod)).toMatchInlineSnapshot( - '"export default { a: 2, b: { c: {} } };"' + expect(await generate(mod)).toMatchInlineSnapshot( + '"export default { a: 2, b: { c: {} } };"', ); mod.exports.default.b.c = { d: 3 }; - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default { a: 2, b: { @@ -31,7 +31,7 @@ describe("general", () => { expect(mod.exports.default.modules.$ast).toBeDefined(); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default { a: 2, @@ -48,7 +48,7 @@ describe("general", () => { mod.exports.default.modules.push("a"); mod.exports.default.modules.unshift({ foo: "bar" }); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default { a: 2, @@ -88,13 +88,13 @@ describe("general", () => { expect(mod.exports.default.modules[0].$type).toBe("object"); }); - it("mix two configs", () => { + it("mix two configs", async () => { const mod1 = parseModule(`export default { a: 1 }`); const mod2 = parseModule(`export default { b: 2 }`); mod1.exports.default.b = mod2.exports.default; - expect(generate(mod1)).toMatchInlineSnapshot( + expect(await generate(mod1)).toMatchInlineSnapshot( ` "export default { a: 1, @@ -103,90 +103,90 @@ describe("general", () => { b: 2, }, };" - ` + `, ); }); - it("delete property", () => { + it("delete property", async () => { const mod = parseModule(`export default { a: 1, b: [1, { foo: 'bar' }] }`); delete mod.exports.default.b[1].foo; - expect(generate(mod)).toMatchInlineSnapshot( - '"export default { a: 1, b: [1, {}] };"' + expect(await generate(mod)).toMatchInlineSnapshot( + '"export default { a: 1, b: [1, {}] };"', ); delete mod.exports.default.b[0]; - expect(generate(mod)).toMatchInlineSnapshot( - '"export default { a: 1, b: [undefined, {}] };"' + expect(await generate(mod)).toMatchInlineSnapshot( + '"export default { a: 1, b: [undefined, {}] };"', ); delete mod.exports.default.a; - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default { b: [undefined, {}], };" `); }); - it("should preserve code styles", () => { + it("should preserve code styles", async () => { const mod = parseModule( ` export const config = { array: ['a'] } - `.trim() + `.trim(), ); mod.exports.config.array.push("b"); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export const config = { array: [\\"a\\", \\"b\\"], };" `); }); - it("satisfies", () => { + it("satisfies", async () => { const mod = parseModule( - `export const obj = { foo: 42 } satisfies Record;` + `export const obj = { foo: 42 } satisfies Record;`, ); mod.exports.obj.foo = 100; - expect(generate(mod)).toMatchInlineSnapshot( - '"export const obj = { foo: 100 } satisfies Record;"' + expect(await generate(mod)).toMatchInlineSnapshot( + '"export const obj = { foo: 100 } satisfies Record;"', ); }); - it("satisfies 2", () => { + it("satisfies 2", async () => { const mod = parseModule(`export default {} satisfies {}`); mod.exports.default.foo = 100; - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default { foo: 100, } satisfies {};" `); }); - it("as", () => { + it("as", async () => { const mod = parseModule( - `export const obj = { foo: 42 } as Record;` + `export const obj = { foo: 42 } as Record;`, ); mod.exports.obj.foo = 100; - expect(generate(mod)).toMatchInlineSnapshot( - '"export const obj = { foo: 100 } as Record;"' + expect(await generate(mod)).toMatchInlineSnapshot( + '"export const obj = { foo: 100 } as Record;"', ); }); - it("as 2", () => { + it("as 2", async () => { const mod = parseModule(`export default {} as {}`); mod.exports.default.foo = 100; - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default { foo: 100, } as {};" @@ -224,7 +224,7 @@ export const config = { exp[2] = "foo"; expect(generateCode(exp).code).toMatchInlineSnapshot( - '"[1, { foo: 2 }, \\"foo\\"]"' + '"[1, { foo: 2 }, \\"foo\\"]"', ); }); }); diff --git a/test/helpers/nuxt.test.ts b/test/helpers/nuxt.test.ts index 5a74913..810614a 100644 --- a/test/helpers/nuxt.test.ts +++ b/test/helpers/nuxt.test.ts @@ -1,16 +1,17 @@ import { it, describe, expect } from "vitest"; -import { parseModule } from "../../src"; -import { addNuxtModule } from "../../src/helpers"; +import { parseModule } from "magicast"; import { generate } from "../_utils"; +import { addNuxtModule } from "magicast/helpers"; describe("helpers > nuxt", () => { - it("add module", () => { + it("add module", async () => { const code = `export default defineNuxtConfig({})`; const mod = parseModule(code); + addNuxtModule(mod, "@vueuse/nuxt", "vueuse", { hello: "world" }); addNuxtModule(mod, "@unocss/nuxt", "unocss", { another: "config" }); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default defineNuxtConfig({ modules: [\\"@vueuse/nuxt\\", \\"@unocss/nuxt\\"], diff --git a/test/helpers/vite.test.ts b/test/helpers/vite.test.ts index a38e3b8..d0a13bf 100644 --- a/test/helpers/vite.test.ts +++ b/test/helpers/vite.test.ts @@ -1,10 +1,10 @@ import { it, describe, expect } from "vitest"; -import { parseModule } from "../../src"; -import { addVitePlugin, updateVitePluginConfig } from "../../src/helpers"; +import { parseModule } from "magicast"; import { generate } from "../_utils"; +import { addVitePlugin, updateVitePluginConfig } from "magicast/helpers"; describe("helpers > vite", () => { - it("add plugin", () => { + it("add plugin", async () => { const code = ` import { defineConfig } from 'vite' @@ -36,7 +36,7 @@ export default defineConfig({}) updateVitePluginConfig(mod, "vite-plugin-inspect", { dev: false }); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "import { VitePWA } from \\"vite-plugin-pwa\\"; import Inspect from \\"vite-plugin-inspect\\"; import vuePlugin from \\"@vitejs/plugin-vue\\"; @@ -57,7 +57,7 @@ export default defineConfig({}) `); }); - it("add plugin at index", () => { + it("add plugin at index", async () => { const code = ` import { defineConfig } from 'vite' import { somePlugin1, somePlugin2 } from 'some-module' @@ -94,7 +94,7 @@ export default defineConfig({ index: 5, // at the end, out of bounds on purpose }); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "import { VitePWA } from \\"vite-plugin-pwa\\"; import Inspect from \\"vite-plugin-inspect\\"; import vuePlugin from \\"@vitejs/plugin-vue\\"; @@ -117,7 +117,7 @@ export default defineConfig({ `); }); - it("handles default export from identifier (fn call)", () => { + it("handles default export from identifier (fn call)", async () => { const code = ` import { defineConfig } from 'vite'; import { somePlugin1, somePlugin2 } from 'some-module' @@ -137,7 +137,7 @@ export default defineConfig({ constructor: "VitePWA", }); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "import { VitePWA } from \\"vite-plugin-pwa\\"; import { defineConfig } from \\"vite\\"; import { somePlugin1, somePlugin2 } from \\"some-module\\"; @@ -145,12 +145,12 @@ export default defineConfig({ const config = defineConfig({ plugins: [somePlugin1(), somePlugin2(), VitePWA()], }); - + export default config;" `); }); - it("handles default export from identifier (object)", () => { + it("handles default export from identifier (object)", async () => { const code = ` import { somePlugin1, somePlugin2 } from 'some-module' @@ -170,14 +170,14 @@ export default defineConfig({ constructor: "VitePWA", }); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "import { VitePWA } from \\"vite-plugin-pwa\\"; import { somePlugin1, somePlugin2 } from \\"some-module\\"; const myConfig = { plugins: [somePlugin1(), VitePWA(), somePlugin2()], }; - + export default myConfig;" `); }); diff --git a/test/imports.test.ts b/test/imports.test.ts index 3392115..caef742 100644 --- a/test/imports.test.ts +++ b/test/imports.test.ts @@ -1,9 +1,9 @@ import { expect, it, describe } from "vitest"; -import { parseModule } from "../src"; +import { parseModule } from "magicast"; import { generate } from "./_utils"; describe("imports", () => { - it("manipulate imports", () => { + it("manipulate imports", async () => { const mod = parseModule(` import { defineConfig, Plugin } from 'vite' import Vue from '@vitejs/plugin-vue' @@ -64,7 +64,7 @@ foo: [] delete mod.imports.Plugin; - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "import { defineConfig } from \\"vite\\"; import VuePlugin from \\"@vitejs/plugin-vue\\"; import * as path2 from \\"path\\"; @@ -74,7 +74,7 @@ foo: [] });" `); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "import { defineConfig } from \\"vite\\"; import VuePlugin from \\"@vitejs/plugin-vue\\"; import * as path2 from \\"path\\"; @@ -99,7 +99,7 @@ foo: [] imported: "Good", }); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "import * as Star from \\"star\\"; import Foo from \\"foo\\"; import { defineConfig, Good } from \\"vite\\"; @@ -113,7 +113,7 @@ foo: [] mod.imports.defineConfig.from = "vitest/config"; - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "import { defineConfig } from \\"vitest/config\\"; import * as Star from \\"star\\"; import Foo from \\"foo\\"; diff --git a/test/object.test.ts b/test/object.test.ts index 7abc09b..d91552a 100644 --- a/test/object.test.ts +++ b/test/object.test.ts @@ -4,7 +4,7 @@ import { deepMergeObject } from "../src/helpers/deep-merge"; import { generate } from "./_utils"; describe("object", () => { - it("object property", () => { + it("object property", async () => { const mod = parseModule( ` export default { @@ -14,7 +14,7 @@ export default { foo() {} } } - `.trim() + `.trim(), ); expect(mod.exports.default.foo.a).toBe(1); @@ -40,7 +40,7 @@ export default { mod.exports.default.foo["a-b"] = "updated"; - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default { foo: { [\\"a\\"]: 1, @@ -52,14 +52,14 @@ export default { `); }); - it("recursively create objects", () => { + it("recursively create objects", async () => { const mod = parseModule( ` export default { foo: { } } - `.trim() + `.trim(), ); // Update existing object keys @@ -72,7 +72,7 @@ export default { mod.exports.default.bar.testValue = {}; mod.exports.default.bar.testValue.value = "a"; - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default { foo: { value: 1, @@ -87,7 +87,7 @@ export default { `); }); - it("recursively merge objects", () => { + it("recursively merge objects", async () => { const mod = parseModule( ` export default { @@ -96,7 +96,7 @@ export default { 100: 10, true: 10 } - `.trim() + `.trim(), ); const obj = { @@ -118,7 +118,7 @@ export default { // Recursively merge existing object with `obj` deepMergeObject(mod.exports.default, obj); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default { foo: { value: 1, @@ -136,7 +136,7 @@ export default { `); }); - it("object keys camelCase style", () => { + it("object keys camelCase style", async () => { const mod = parseModule(`export default defineAppConfig({ test: { foo: 1, @@ -152,7 +152,7 @@ export default { deepMergeObject(config, obj1); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default defineAppConfig({ test: { foo: 1, @@ -166,7 +166,7 @@ export default { deepMergeObject(config, obj2); - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default defineAppConfig({ test: { foo: 1, @@ -181,7 +181,7 @@ export default { `); }); - it("object keys kebab-case style", () => { + it("object keys kebab-case style", async () => { const mod = parseModule(`export default defineAppConfig({ test: { foo: 1, @@ -198,7 +198,7 @@ export default { deepMergeObject(config, obj1); // Valid - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default defineAppConfig({ test: { foo: 1, @@ -213,7 +213,7 @@ export default { deepMergeObject(config, obj2); // TODO: Should be valid - expect(generate(mod)).toMatchInlineSnapshot(` + expect(await generate(mod)).toMatchInlineSnapshot(` "export default defineAppConfig({ test: { foo: 1, diff --git a/test/utils.test.ts b/test/utils.test.ts index f22f78a..eaa2206 100644 --- a/test/utils.test.ts +++ b/test/utils.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from "vitest"; import { print } from "recast"; -import { parseModule, builders } from "../src"; +import { parseModule, builders } from "magicast"; describe("literalToAst", () => { // eslint-disable-next-line unicorn/consistent-function-scoping @@ -23,18 +23,18 @@ describe("literalToAst", () => { it("built-in objects", () => { expect(run(new Set(["foo", 1]))).toMatchInlineSnapshot( - '"new Set([\\"foo\\", 1])"' + '"new Set([\\"foo\\", 1])"', ); expect(run(new Date("2010-01-01"))).toMatchInlineSnapshot( - '"new Date(\\"2010-01-01T00:00:00.000Z\\")"' + '"new Date(\\"2010-01-01T00:00:00.000Z\\")"', ); const map = new Map(); map.set(1, "foo"); map.set(2, "bar"); expect(run(map)).toMatchInlineSnapshot( - '"new Map([[1, \\"foo\\"], [2, \\"bar\\"]])"' + '"new Map([[1, \\"foo\\"], [2, \\"bar\\"]])"', ); }); diff --git a/tsconfig.json b/tsconfig.json index d079baa..ea8204f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,19 @@ { "compilerOptions": { + "rootDir": ".", "target": "ESNext", "module": "ESNext", - "moduleResolution": "Node", + "moduleResolution": "Bundler", "esModuleInterop": true, - "strict": true + "strict": true, + "paths": { + "magicast": [ + "./src/index.ts" + ] + } }, - "include": [ - "src" + "exclude": [ + "dist", + "vendor" ] } diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..5eb5c44 --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,21 @@ +import { fileURLToPath } from 'node:url' +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + resolve: { + alias: { + recast: fileURLToPath(new URL('vendor/recast/main.ts', import.meta.url)), + 'ast-types': fileURLToPath(new URL('vendor/ast-types/src/main.ts', import.meta.url)), + ...(process.env.TEST_BUILD === 'true' + ? {} + : { + 'magicast/helpers': fileURLToPath(new URL('src/helpers/index.ts', import.meta.url)), + magicast: fileURLToPath(new URL('src/index.ts', import.meta.url)), + } + ) + } + }, + test: { + name: (process.env.TEST_BUILD === 'true' ? 'build' : 'src'), + } +})