Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@rollup/plugin-dynamic-import-vars] Allow path.relative #1831

Open
rtritto opened this issue Dec 27, 2024 · 0 comments
Open

[@rollup/plugin-dynamic-import-vars] Allow path.relative #1831

rtritto opened this issue Dec 27, 2024 · 0 comments

Comments

@rtritto
Copy link

rtritto commented Dec 27, 2024

  • Rollup Plugin Name: @rollup/plugin-dynamic-import-vars
  • Rollup Plugin Version: 2.1.5

Feature Use Case

Load API routes using filesystem.

Feature Proposal

Ignore path.relative:

  • as parameter
    import fs from 'node:fs'
    import path from 'node:path'
    
    const files = fs.globSync(pattern, { cwd: entryDir })
    for (const file of sortRoutesByParams(files)) {
      // Fix Windows slashes
      const filepath = file.replaceAll('\\', '/')
      await import(path.relative(entryDir, filepath))
      // ...
    }
  • as resolved
    import fs from 'node:fs'
    import path from 'node:path'
    
    const files = fs.globSync(pattern, { cwd: entryDir })
    for (const file of sortRoutesByParams(files)) {
      // Fix Windows slashes
      const filepath = file.replaceAll('\\', '/')
      const resolved = path.relative(entryDir, filepath)
      await import(resolved)
      // ...
    }

Current

VariableDynamicImportError: invalid import "import(path.relative(entryDir, filepath))". It cannot be statically analyzed. Variable dynamic imports must start with ./ and be limited to a specific directory. For example: import(`./foo/${bar}.js`).
    at dynamicImportToGlob (C:\project\.yarn\__virtual__\@rollup-plugin-dynamic-import-vars-virtual-469ce0e48e\5\Users\USER\AppData\Local\Yarn\Berry\cache\@rollup-plugin-dynamic-import-vars-npm-2.1.5-a03e1726af-10c0.zip\node_modules\@rollup\plugin-dynamic-import-vars\dist\cjs\index.js:99:11)
    at Object.enter (C:\project\.yarn\__virtual__\@rollup-plugin-dynamic-import-vars-virtual-469ce0e48e\5\Users\USER\AppData\Local\Yarn\Berry\cache\@rollup-plugin-dynamic-import-vars-npm-2.1.5-a03e1726af-10c0.zip\node_modules\@rollup\plugin-dynamic-import-vars\dist\cjs\index.js:169:26)
    at SyncWalker.visit (C:\Users\USER\AppData\Local\Yarn\Berry\cache\estree-walker-npm-2.0.2-dfab42f65c-10c0.zip\node_modules\estree-walker\dist\umd\estree-walker.js:116:17)      
    at SyncWalker.visit (C:\Users\USER\AppData\Local\Yarn\Berry\cache\estree-walker-npm-2.0.2-dfab42f65c-10c0.zip\node_modules\estree-walker\dist\umd\estree-walker.js:153:12)      
    at SyncWalker.visit (C:\Users\USER\AppData\Local\Yarn\Berry\cache\estree-walker-npm-2.0.2-dfab42f65c-10c0.zip\node_modules\estree-walker\dist\umd\estree-walker.js:153:12)      
    at SyncWalker.visit (C:\Users\USER\AppData\Local\Yarn\Berry\cache\estree-walker-npm-2.0.2-dfab42f65c-10c0.zip\node_modules\estree-walker\dist\umd\estree-walker.js:153:12)      
    at SyncWalker.visit (C:\Users\USER\AppData\Local\Yarn\Berry\cache\estree-walker-npm-2.0.2-dfab42f65c-10c0.zip\node_modules\estree-walker\dist\umd\estree-walker.js:146:19)      
    at SyncWalker.visit (C:\Users\USER\AppData\Local\Yarn\Berry\cache\estree-walker-npm-2.0.2-dfab42f65c-10c0.zip\node_modules\estree-walker\dist\umd\estree-walker.js:146:19)      
    at SyncWalker.visit (C:\Users\USER\AppData\Local\Yarn\Berry\cache\estree-walker-npm-2.0.2-dfab42f65c-10c0.zip\node_modules\estree-walker\dist\umd\estree-walker.js:153:12)      
    at SyncWalker.visit (C:\Users\USER\AppData\Local\Yarn\Berry\cache\estree-walker-npm-2.0.2-dfab42f65c-10c0.zip\node_modules\estree-walker\dist\umd\estree-walker.js:146:19) {    
  id: 'C:\\project\\src\\index.ts',
  hook: 'transform',
  code: 'PLUGIN_ERROR',
  plugin: 'rollup-plugin-dynamic-import-variables',
  watchFiles: [
    'C:\\project\\src\\index.ts'
  ]
}

Expected

No error

@rtritto rtritto changed the title [@rollup/plugin-dynamic-import-vars] Ignore path.relative [@rollup/plugin-dynamic-import-vars] Allow path.relative Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant