Skip to content

Commit

Permalink
chore: better args name
Browse files Browse the repository at this point in the history
  • Loading branch information
caoxiemeihao committed Apr 30, 2023
1 parent da70ede commit 9fbefa5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/dynamic-import-to-glob.ts
Expand Up @@ -68,8 +68,8 @@ function expressionToGlob(node: AcornNode): string {
* @see https://github.com/rollup/plugins/blob/master/packages/dynamic-import-vars/src/dynamic-import-to-glob.js
*/
export async function dynamicImportToGlob(
node: AcornNode,
sourceString: string,
importeeNode: AcornNode,
importeeCode: string,
/**
* The `resolver` for processing alias or bare(node_modules),
* and try to add extension for compatible restrict of '@rollup/plugin-dynamic-import-vars'
Expand All @@ -87,7 +87,7 @@ export async function dynamicImportToGlob(
*/
resolver?: (glob: string) => string | Promise<string>,
): Promise<string | null> {
let glob = expressionToGlob(node)
let glob = expressionToGlob(importeeNode)
glob = await resolver?.(glob) ?? glob
if (!glob.includes('*') || glob.startsWith('data:')) {
return null
Expand All @@ -96,33 +96,33 @@ export async function dynamicImportToGlob(

if (glob.startsWith('*')) {
throw new Error(
`invalid import "${sourceString}". It cannot be statically analyzed. Variable dynamic imports must start with ./ and be limited to a specific directory. ${example}`
`invalid import "${importeeCode}". It cannot be statically analyzed. Variable dynamic imports must start with ./ and be limited to a specific directory. ${example}`
)
}

if (glob.startsWith('/')) {
throw new Error(
`invalid import "${sourceString}". Variable absolute imports are not supported, imports must start with ./ in the static part of the import. ${example}`
`invalid import "${importeeCode}". Variable absolute imports are not supported, imports must start with ./ in the static part of the import. ${example}`
)
}

if (!glob.startsWith('./') && !glob.startsWith('../')) {
throw new Error(
`invalid import "${sourceString}". Variable bare imports are not supported, imports must start with ./ in the static part of the import. ${example}`
`invalid import "${importeeCode}". Variable bare imports are not supported, imports must start with ./ in the static part of the import. ${example}`
)
}

// Disallow ./*.ext
const ownDirectoryStarExtension = /^\.\/\*\.[\w]+$/
if (ownDirectoryStarExtension.test(glob)) {
throw new Error(
`invalid import "${sourceString}". Variable imports cannot import their own directory, place imports in a separate directory or make the import filename more specific. ${example}`
`invalid import "${importeeCode}". Variable imports cannot import their own directory, place imports in a separate directory or make the import filename more specific. ${example}`
)
}

if (path.extname(glob) === '') {
throw new Error(
`invalid import "${sourceString}". A file extension must be included in the static part of the import. ${example}`
`invalid import "${importeeCode}". A file extension must be included in the static part of the import. ${example}`
)
}

Expand Down

0 comments on commit 9fbefa5

Please sign in to comment.