From ddc5cbac2361f0b9c9a90e8f905ee53b9dfa7477 Mon Sep 17 00:00:00 2001 From: Austin Merrick Date: Fri, 10 May 2024 09:38:33 -0700 Subject: [PATCH] feat: support import assertions (#417) `acorn-import-attributes` [did not support import assertions before](https://github.com/vercel/nft/pull/377#issuecomment-1849719137), but now it does! This is important because `acorn` is failing to parse `runner.js` in [this issue](https://github.com/vercel/vercel/issues/11533) due to an import assertion. --- package-lock.json | 8 ++++---- package.json | 2 +- src/analyze.ts | 2 +- test/unit/import-assertions/foo.js | 0 test/unit/import-assertions/info.json | 3 +++ test/unit/import-assertions/input.js | 4 ++++ test/unit/import-assertions/output.js | 6 ++++++ 7 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 test/unit/import-assertions/foo.js create mode 100644 test/unit/import-assertions/info.json create mode 100644 test/unit/import-assertions/input.js create mode 100644 test/unit/import-assertions/output.js diff --git a/package-lock.json b/package-lock.json index 101c6a5f..2adf5272 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@mapbox/node-pre-gyp": "^1.0.5", "@rollup/pluginutils": "^4.0.0", "acorn": "^8.6.0", - "acorn-import-attributes": "^1.9.2", + "acorn-import-attributes": "^1.9.5", "async-sema": "^3.1.1", "bindings": "^1.4.0", "estree-walker": "2.0.2", @@ -5766,9 +5766,9 @@ } }, "node_modules/acorn-import-attributes": { - "version": "1.9.2", - "resolved": "https://registry.npmjs.org/acorn-import-attributes/-/acorn-import-attributes-1.9.2.tgz", - "integrity": "sha512-O+nfJwNolEA771IYJaiLWK1UAwjNsQmZbTRqqwBYxCgVQTmpFEMvBw6LOIQV0Me339L5UMVYFyRohGnGlQDdIQ==", + "version": "1.9.5", + "resolved": "https://registry.npmjs.org/acorn-import-attributes/-/acorn-import-attributes-1.9.5.tgz", + "integrity": "sha512-n02Vykv5uA3eHGM/Z2dQrcD56kL8TyDb2p1+0P83PClMnC/nc+anbQRhIOWnSq4Ke/KvDPrY3C9hDtC/A3eHnQ==", "peerDependencies": { "acorn": "^8" } diff --git a/package.json b/package.json index d8c1b8f7..d3cc9433 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "@mapbox/node-pre-gyp": "^1.0.5", "@rollup/pluginutils": "^4.0.0", "acorn": "^8.6.0", - "acorn-import-attributes": "^1.9.2", + "acorn-import-attributes": "^1.9.5", "async-sema": "^3.1.1", "bindings": "^1.4.0", "estree-walker": "2.0.2", diff --git a/src/analyze.ts b/src/analyze.ts index 39150d14..4af46c71 100644 --- a/src/analyze.ts +++ b/src/analyze.ts @@ -33,7 +33,7 @@ const acorn = Parser.extend( //require("acorn-class-fields"), //require("acorn-static-class-features"), //require("acorn-private-class-elements") - require('acorn-import-attributes').importAttributes, + require('acorn-import-attributes').importAttributesOrAssertions, ); import os from 'os'; diff --git a/test/unit/import-assertions/foo.js b/test/unit/import-assertions/foo.js new file mode 100644 index 00000000..e69de29b diff --git a/test/unit/import-assertions/info.json b/test/unit/import-assertions/info.json new file mode 100644 index 00000000..b42f309e --- /dev/null +++ b/test/unit/import-assertions/info.json @@ -0,0 +1,3 @@ +{ + "foo": "bar" +} \ No newline at end of file diff --git a/test/unit/import-assertions/input.js b/test/unit/import-assertions/input.js new file mode 100644 index 00000000..63895fd5 --- /dev/null +++ b/test/unit/import-assertions/input.js @@ -0,0 +1,4 @@ +import foo from "./foo" +import info from "./info.json" assert { type: "json" } + +export default info \ No newline at end of file diff --git a/test/unit/import-assertions/output.js b/test/unit/import-assertions/output.js new file mode 100644 index 00000000..31bc9583 --- /dev/null +++ b/test/unit/import-assertions/output.js @@ -0,0 +1,6 @@ +[ + "package.json", + "test/unit/import-assertions/foo.js", + "test/unit/import-assertions/info.json", + "test/unit/import-assertions/input.js" +]