From cc53f0f192a6a810ded137e1c4f960022cc4725b Mon Sep 17 00:00:00 2001 From: Lenny Burdette Date: Thu, 15 Jul 2021 15:10:07 -0400 Subject: [PATCH] fix(dynamic-import-vars): allow ./${var}.suffix.js (#834) Allow dynamically importing files in the same directory with an extra suffix before the extension. --- .github/workflows/release.yml | 11 ++++++++--- .npmrc | 2 ++ packages/dynamic-import-vars/package.json | 2 +- .../dynamic-import-vars/src/dynamic-import-to-glob.js | 4 +++- .../test/src/dynamic-import-to-glob.test.js | 9 +++++++++ scripts/release.ts | 4 ++++ 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 38ac5fbef..834fc97cc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,6 +19,7 @@ jobs: uses: actions/setup-node@v1 with: node-version: 14 + registry-url: https://registry.npmjs.org/ - name: Checkout Master run: | @@ -30,6 +31,11 @@ jobs: echo branch `git branch --show-current`; echo node `node -v`; + - name: Initliaze .npmrc + run: > + echo -e "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}\n$(cat .npmrc)" > .npmrc + && cat -n .npmrc + - name: Install pnpm run: | npm install pnpm -g; @@ -43,8 +49,6 @@ jobs: - name: pnpm install run: pnpm install - env: - NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} - name: Build Packages run: pnpm build --recursive @@ -58,4 +62,5 @@ jobs: - name: Release and Publish Packages run: pnpm release --filter [HEAD^] env: - NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.npmrc b/.npmrc index a4dc4a3e9..b500e9003 100644 --- a/.npmrc +++ b/.npmrc @@ -1,3 +1,5 @@ +registry=https://registry.npmjs.org/ + enable-pre-post-scripts = true link-workspace-packages = false shamefully-hoist = true diff --git a/packages/dynamic-import-vars/package.json b/packages/dynamic-import-vars/package.json index f601e9314..0ea028425 100644 --- a/packages/dynamic-import-vars/package.json +++ b/packages/dynamic-import-vars/package.json @@ -1,6 +1,6 @@ { "name": "@rollup/plugin-dynamic-import-vars", - "version": "1.1.1", + "version": "1.1.3", "publishConfig": { "access": "public" }, diff --git a/packages/dynamic-import-vars/src/dynamic-import-to-glob.js b/packages/dynamic-import-vars/src/dynamic-import-to-glob.js index d3e1f18a1..c814b123b 100644 --- a/packages/dynamic-import-vars/src/dynamic-import-to-glob.js +++ b/packages/dynamic-import-vars/src/dynamic-import-to-glob.js @@ -86,7 +86,9 @@ export function dynamicImportToGlob(node, sourceString) { ); } - if (glob.startsWith('./*.')) { + // Disallow ./*.ext + const ownDirectoryStarExtension = /^\.\/\*\.[\w]+$/; + if (ownDirectoryStarExtension.test(glob)) { throw new VariableDynamicImportError( `${ `invalid import "${sourceString}". Variable imports cannot import their own directory, ` + diff --git a/packages/dynamic-import-vars/test/src/dynamic-import-to-glob.test.js b/packages/dynamic-import-vars/test/src/dynamic-import-to-glob.test.js index bbd350e40..5d0508ec8 100644 --- a/packages/dynamic-import-vars/test/src/dynamic-import-to-glob.test.js +++ b/packages/dynamic-import-vars/test/src/dynamic-import-to-glob.test.js @@ -17,6 +17,15 @@ test('template literal with variable filename', (t) => { t.is(glob, './foo/*.js'); }); +test('template literal with dot-prefixed suffix', (t) => { + const ast = CustomParser.parse('import(`./${bar}.entry.js`);', { + sourceType: 'module' + }); + + const glob = dynamicImportToGlob(ast.body[0].expression.arguments[0]); + t.is(glob, './*.entry.js'); +}); + test('template literal with variable directory', (t) => { const ast = CustomParser.parse('import(`./foo/${bar}/x.js`);', { sourceType: 'module' diff --git a/scripts/release.ts b/scripts/release.ts index d224bfb7a..40c8c843e 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -123,7 +123,11 @@ const publish = async (cwd: string) => { const pull = async (main: string) => { log(chalk`{blue Pulling Latest Changes from Remote and Rebasing}`); + + await execa('git', ['checkout', '.npmrc']); await execa('git', ['pull', 'origin', main, '--no-edit']); + const { stdout } = await execa('git', ['status']); + console.log({ stdout }); await execa('git', ['rebase']); };