Skip to content

Commit

Permalink
fix(dynamic-import-vars): allow ./${var}.suffix.js (#834)
Browse files Browse the repository at this point in the history
Allow dynamically importing files in the same directory with an extra suffix before the extension.
  • Loading branch information
lennyburdette authored and shellscape committed Jul 15, 2021
1 parent e32a9e9 commit c33e948
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/release.yml
Expand Up @@ -19,6 +19,7 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: 14
registry-url: https://registry.npmjs.org/

- name: Checkout Master
run: |
Expand All @@ -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;
Expand All @@ -39,12 +45,10 @@ jobs:
run: |
git config --global user.email "release-workflow@rollup.dev"
git config --global user.name "Release Workflow"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git remote set-url origin https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/${{ github.repository }}
- name: pnpm install
run: pnpm install
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Build Packages
run: pnpm build --recursive
Expand All @@ -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.GH_TOKEN}}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 2 additions & 0 deletions .npmrc
@@ -1,3 +1,5 @@
registry=https://registry.npmjs.org/

enable-pre-post-scripts = true
link-workspace-packages = false
shamefully-hoist = true
Expand Down
2 changes: 1 addition & 1 deletion packages/dynamic-import-vars/package.json
@@ -1,6 +1,6 @@
{
"name": "@rollup/plugin-dynamic-import-vars",
"version": "1.1.1",
"version": "1.1.5",
"publishConfig": {
"access": "public"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/dynamic-import-vars/src/dynamic-import-to-glob.js
Expand Up @@ -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, ` +
Expand Down
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions scripts/release.ts
Expand Up @@ -123,6 +123,8 @@ 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']);
await execa('git', ['rebase']);
};
Expand Down

0 comments on commit c33e948

Please sign in to comment.