From 6c23a8a288f358cc78283d8ae45e46bfe9c08685 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Fri, 2 Dec 2022 13:26:17 -0600 Subject: [PATCH 1/4] Use standard rollup resolution --- src/import-assert.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/import-assert.ts b/src/import-assert.ts index 182e457..b664efc 100644 --- a/src/import-assert.ts +++ b/src/import-assert.ts @@ -1,4 +1,3 @@ -import path from 'path'; import { Plugin } from 'rollup'; import convert from 'string-to-template-literal'; @@ -29,12 +28,10 @@ type Assertion = { type: 'css'|'json' }; const assertionMap = new Map(); const filePattern = /\.(js|ts|jsx|tsx)$/; -const getImportPath = (id: string, source: string): string => path.resolve(path.dirname(id), source); - export function importAssertionsPlugin(): Plugin { return { name: 'rollup-plugin-import-assert', - transform(data: string, id: string) { + async transform(data: string, id: string) { let code = data; /** If the file is a JS-like file, continue */ if (filePattern.exec(id)) { @@ -46,16 +43,16 @@ export function importAssertionsPlugin(): Plugin { const importDeclarations = getObjects(body, 'type', 'ImportDeclaration'); const importExpressions = getObjects(body, 'type', 'ImportExpression'); - importDeclarations.forEach(node => { + for (const node of importDeclarations) { if (node.assertions) { const [ assertion ] = node.assertions as any; const assert: Assertion = { type: assertion.value.value }; - const importPath = getImportPath(id, node.source.value); + const importPath = await this.resolve(node.source.value, id).id assertionMap.set(importPath, assert); } - }); + }; - importExpressions.forEach(node => { + for (const node of importExpressions) { // Skip dynamic imports with expressions // @example: import(`./foo/${bar}.js`); // NOK // @example: import(`./foo/bar.js`); // OK @@ -67,7 +64,7 @@ export function importAssertionsPlugin(): Plugin { if(!node.source.value) return; const source = node.source.value || node.source.quasis[0].value.raw; - const importPath = getImportPath(id, source); + const importPath = await this.resolve(source, id).id; // TODO: We can still make this better if (node.hasOwnProperty('arguments') && getObjects(node, 'name', 'assert')) { @@ -89,7 +86,7 @@ export function importAssertionsPlugin(): Plugin { }); } } - }); + } } const assertion = assertionMap.get(id); From eb60c16141d906113acb3017afa38fe43ef9a110 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Fri, 2 Dec 2022 13:37:02 -0600 Subject: [PATCH 2/4] remove obsolete deps/settings for `fs` --- package-lock.json | 69 +++++++++++++++++++++++++++++++---------------- package.json | 1 - rollup.config.js | 6 ++--- 3 files changed, 48 insertions(+), 28 deletions(-) diff --git a/package-lock.json b/package-lock.json index b7370eb..dbb4d96 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,6 @@ "devDependencies": { "@rollup/plugin-commonjs": "^21.0.1", "@rollup/plugin-node-resolve": "^13.1.2", - "@types/node": "^16.0.0", "acorn-import-assertions": "^1.7.1", "ava": "^3.15.0", "rollup": "^2.52.7", @@ -210,15 +209,15 @@ } }, "node_modules/@rollup/plugin-node-resolve": { - "version": "13.1.3", - "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.1.3.tgz", - "integrity": "sha512-BdxNk+LtmElRo5d06MGY4zoepyrXX1tkzX2hrnPEZ53k78GuOMWLqmJDGIIOPwVRIFZrLQOo+Yr6KtCuLIA0AQ==", + "version": "13.3.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.3.0.tgz", + "integrity": "sha512-Lus8rbUo1eEcnS4yTFKLZrVumLPY+YayBdWXgFSHYhTT2iJbMhoaaBL3xl5NCdeRytErGr8tZ0L71BMRmnlwSw==", "dev": true, "dependencies": { "@rollup/pluginutils": "^3.1.0", "@types/resolve": "1.17.1", - "builtin-modules": "^3.1.0", "deepmerge": "^4.2.2", + "is-builtin-module": "^3.1.0", "is-module": "^1.0.0", "resolve": "^1.19.0" }, @@ -286,9 +285,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "16.0.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.0.0.tgz", - "integrity": "sha512-TmCW5HoZ2o2/z2EYi109jLqIaPIi9y/lc2LmDCWzuCi35bcaQ+OtUh6nwBiFK7SOu25FAU5+YKdqFZUwtqGSdg==", + "version": "18.11.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.10.tgz", + "integrity": "sha512-juG3RWMBOqcOuXC643OAdSA525V44cVgGV6dUDuiFtss+8Fk5x1hI93Rsld43VeJVIeqlP9I7Fn9/qaVqoEAuQ==", "dev": true }, "node_modules/@types/normalize-package-data": { @@ -717,9 +716,9 @@ "dev": true }, "node_modules/builtin-modules": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.2.0.tgz", - "integrity": "sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz", + "integrity": "sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==", "dev": true, "engines": { "node": ">=6" @@ -2523,6 +2522,21 @@ "node": ">=8" } }, + "node_modules/is-builtin-module": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.2.0.tgz", + "integrity": "sha512-phDA4oSGt7vl1n5tJvTWooWWAsXLY+2xCnxNqvKhGEzujg+A43wPlPOyDg3C8XQHN+6k/JTQWJ/j0dQh/qr+Hw==", + "dev": true, + "dependencies": { + "builtin-modules": "^3.3.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-ci": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-2.0.0.tgz", @@ -2611,7 +2625,7 @@ "node_modules/is-module": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", - "integrity": "sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=", + "integrity": "sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==", "dev": true }, "node_modules/is-npm": { @@ -5154,15 +5168,15 @@ } }, "@rollup/plugin-node-resolve": { - "version": "13.1.3", - "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.1.3.tgz", - "integrity": "sha512-BdxNk+LtmElRo5d06MGY4zoepyrXX1tkzX2hrnPEZ53k78GuOMWLqmJDGIIOPwVRIFZrLQOo+Yr6KtCuLIA0AQ==", + "version": "13.3.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.3.0.tgz", + "integrity": "sha512-Lus8rbUo1eEcnS4yTFKLZrVumLPY+YayBdWXgFSHYhTT2iJbMhoaaBL3xl5NCdeRytErGr8tZ0L71BMRmnlwSw==", "dev": true, "requires": { "@rollup/pluginutils": "^3.1.0", "@types/resolve": "1.17.1", - "builtin-modules": "^3.1.0", "deepmerge": "^4.2.2", + "is-builtin-module": "^3.1.0", "is-module": "^1.0.0", "resolve": "^1.19.0" } @@ -5214,9 +5228,9 @@ "dev": true }, "@types/node": { - "version": "16.0.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.0.0.tgz", - "integrity": "sha512-TmCW5HoZ2o2/z2EYi109jLqIaPIi9y/lc2LmDCWzuCi35bcaQ+OtUh6nwBiFK7SOu25FAU5+YKdqFZUwtqGSdg==", + "version": "18.11.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.10.tgz", + "integrity": "sha512-juG3RWMBOqcOuXC643OAdSA525V44cVgGV6dUDuiFtss+8Fk5x1hI93Rsld43VeJVIeqlP9I7Fn9/qaVqoEAuQ==", "dev": true }, "@types/normalize-package-data": { @@ -5544,9 +5558,9 @@ "dev": true }, "builtin-modules": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.2.0.tgz", - "integrity": "sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz", + "integrity": "sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==", "dev": true }, "cacheable-request": { @@ -6916,6 +6930,15 @@ "binary-extensions": "^2.0.0" } }, + "is-builtin-module": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.2.0.tgz", + "integrity": "sha512-phDA4oSGt7vl1n5tJvTWooWWAsXLY+2xCnxNqvKhGEzujg+A43wPlPOyDg3C8XQHN+6k/JTQWJ/j0dQh/qr+Hw==", + "dev": true, + "requires": { + "builtin-modules": "^3.3.0" + } + }, "is-ci": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-2.0.0.tgz", @@ -6980,7 +7003,7 @@ "is-module": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", - "integrity": "sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=", + "integrity": "sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==", "dev": true }, "is-npm": { diff --git a/package.json b/package.json index 27c4f8b..91c9720 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "devDependencies": { "@rollup/plugin-commonjs": "^21.0.1", "@rollup/plugin-node-resolve": "^13.1.2", - "@types/node": "^16.0.0", "acorn-import-assertions": "^1.7.1", "ava": "^3.15.0", "rollup": "^2.52.7", diff --git a/rollup.config.js b/rollup.config.js index 17bd8ac..0d1a1e7 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -8,10 +8,8 @@ export default { file: 'dist/import-assert.cjs' }, plugins: [ - nodeResolve({ - preferBuiltins: true - }), + nodeResolve(), commonjs() - + ] } From 13e0c7ccbf48c81e4f30fa88847b6394457115f7 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Fri, 2 Dec 2022 13:59:13 -0600 Subject: [PATCH 3/4] chore(release): 2.1.4 --- CHANGELOG.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c039113..cb05b34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [2.1.4](https://github.com/calebdwilliams/rollup-plugin-import-assert/compare/v2.1.3...v2.1.4) (2022-12-02) + ### [2.1.3](https://github.com/calebdwilliams/rollup-plugin-import-assert/compare/v2.1.2...v2.1.3) (2022-11-08) ### [2.1.2](https://github.com/calebdwilliams/rollup-plugin-import-assert/compare/v2.1.0...v2.1.2) (2022-10-27) diff --git a/package-lock.json b/package-lock.json index dbb4d96..cca5b7e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rollup-plugin-import-assert", - "version": "2.1.3", + "version": "2.1.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "rollup-plugin-import-assert", - "version": "2.1.3", + "version": "2.1.4", "license": "MIT", "dependencies": { "string-to-template-literal": "^0.2.2" diff --git a/package.json b/package.json index 91c9720..990a6ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup-plugin-import-assert", - "version": "2.1.3", + "version": "2.1.4", "description": "A Rollup plugin to add import assertion behavior and syntax support", "main": "dist/import-assert.js", "module": "dist/import-assert.js", From 7ff332dd93a4a015d8ca6b40a290cb794f32fe37 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Fri, 2 Dec 2022 14:03:12 -0600 Subject: [PATCH 4/4] misplaced await --- src/import-assert.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/import-assert.ts b/src/import-assert.ts index b664efc..f01dd2a 100644 --- a/src/import-assert.ts +++ b/src/import-assert.ts @@ -47,7 +47,7 @@ export function importAssertionsPlugin(): Plugin { if (node.assertions) { const [ assertion ] = node.assertions as any; const assert: Assertion = { type: assertion.value.value }; - const importPath = await this.resolve(node.source.value, id).id + const importPath = (await this.resolve(node.source.value, id)).id assertionMap.set(importPath, assert); } }; @@ -64,7 +64,7 @@ export function importAssertionsPlugin(): Plugin { if(!node.source.value) return; const source = node.source.value || node.source.quasis[0].value.raw; - const importPath = await this.resolve(source, id).id; + const importPath = (await this.resolve(source, id)).id; // TODO: We can still make this better if (node.hasOwnProperty('arguments') && getObjects(node, 'name', 'assert')) {