vite-plugin-dynamic-import
Advanced tools
@@ -7,3 +7,3 @@ /** | ||
| */ | ||
| export declare function dynamicImportToGlob(node: AcornNode, sourceString: string, | ||
| export declare function dynamicImportToGlob(importeeNode: AcornNode, importExpression: string, | ||
| /** | ||
@@ -10,0 +10,0 @@ * The `resolver` for processing alias or bare(node_modules), |
+27
-3
| import type { Plugin } from 'vite'; | ||
| export { dynamicImportToGlob } from './dynamic-import-to-glob'; | ||
| export { type Resolved, Resolve, } from './resolve'; | ||
| export { toLooseGlob, mappingPath, } from './utils'; | ||
| import { hasDynamicImport, normallyImporteeRE, mappingPath, toLooseGlob } from './utils'; | ||
| import { type Resolved, Resolve } from './resolve'; | ||
| import { dynamicImportToGlob } from './dynamic-import-to-glob'; | ||
| export { hasDynamicImport, normallyImporteeRE, mappingPath, toLooseGlob, type Resolved, Resolve, dynamicImportToGlob, globFiles, }; | ||
| export interface Options { | ||
@@ -32,1 +33,24 @@ filter?: (id: string) => boolean | void; | ||
| export default function dynamicImport(options?: Options): Plugin; | ||
| declare function globFiles({ importeeNode, importExpression, importer, resolve, extensions, loose, }: { | ||
| importeeNode: AcornNode; | ||
| importExpression: string; | ||
| /** Used to calculate relative paths */ | ||
| importer: string; | ||
| resolve: Resolve; | ||
| /** Importable file extensions */ | ||
| extensions: string[]; | ||
| /** Match unlimited levels of subdir as much as possible */ | ||
| loose?: boolean; | ||
| }): Promise<{ | ||
| files?: string[]; | ||
| resolved?: Resolved; | ||
| /** | ||
| * 🚧-③ After `expressiontoglob()` processing, it may become a normal path | ||
| * | ||
| * In v2.9.9 Vite has handled internally(2022-06-09) ???? | ||
| * import('@/views/' + 'foo.js') | ||
| * ↓ | ||
| * import('@/viewsfoo.js') | ||
| */ | ||
| normally?: string; | ||
| } | undefined>; |
+32
-15
@@ -20,2 +20,7 @@ "use strict"; | ||
| const singlelineCommentsRE = /\/\/.*/g; | ||
| function cleanUrl(url) { | ||
| const queryRE = /\?.*$/s; | ||
| const hashRE = /#.*$/s; | ||
| return url.replace(hashRE, "").replace(queryRE, ""); | ||
| } | ||
| class MagicString { | ||
@@ -293,4 +298,4 @@ constructor(str) { | ||
| } | ||
| async function dynamicImportToGlob(node, sourceString, resolver) { | ||
| let glob = expressionToGlob(node); | ||
| async function dynamicImportToGlob(importeeNode, importExpression, resolver) { | ||
| let glob = expressionToGlob(importeeNode); | ||
| glob = await (resolver == null ? void 0 : resolver(glob)) ?? glob; | ||
@@ -303,3 +308,3 @@ if (!glob.includes("*") || glob.startsWith("data:")) { | ||
| 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 "${importExpression}". It cannot be statically analyzed. Variable dynamic imports must start with ./ and be limited to a specific directory. ${example}` | ||
| ); | ||
@@ -309,3 +314,3 @@ } | ||
| 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 "${importExpression}". Variable absolute imports are not supported, imports must start with ./ in the static part of the import. ${example}` | ||
| ); | ||
@@ -315,3 +320,3 @@ } | ||
| 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 "${importExpression}". Variable bare imports are not supported, imports must start with ./ in the static part of the import. ${example}` | ||
| ); | ||
@@ -322,3 +327,3 @@ } | ||
| 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 "${importExpression}". Variable imports cannot import their own directory, place imports in a separate directory or make the import filename more specific. ${example}` | ||
| ); | ||
@@ -328,3 +333,3 @@ } | ||
| throw new Error( | ||
| `invalid import "${sourceString}". A file extension must be included in the static part of the import. ${example}` | ||
| `invalid import "${importExpression}". A file extension must be included in the static part of the import. ${example}` | ||
| ); | ||
@@ -372,3 +377,3 @@ } | ||
| }, | ||
| async transform(code, id) { | ||
| transform(code, id) { | ||
| return transformDynamicImport({ | ||
@@ -392,2 +397,4 @@ options, | ||
| var _a, _b; | ||
| if (!(extensions.includes(path.extname(id)) || extensions.includes(path.extname(cleanUrl(id))))) | ||
| return; | ||
| if (!hasDynamicImport(code)) | ||
@@ -445,10 +452,10 @@ return; | ||
| } | ||
| const globResult = await globFiles( | ||
| importExpressionAst, | ||
| const globResult = await globFiles({ | ||
| importeeNode: importExpressionAst.source, | ||
| importExpression, | ||
| id, | ||
| importer: id, | ||
| resolve, | ||
| extensions, | ||
| options.loose !== false | ||
| ); | ||
| loose: options.loose !== false | ||
| }); | ||
| if (!globResult) | ||
@@ -482,3 +489,10 @@ continue; | ||
| } | ||
| async function globFiles(importExpressionAst, importExpression, importer, resolve, extensions, loose = true) { | ||
| async function globFiles({ | ||
| importeeNode, | ||
| importExpression, | ||
| importer, | ||
| resolve, | ||
| extensions, | ||
| loose = true | ||
| }) { | ||
| let files; | ||
@@ -492,3 +506,3 @@ let resolved; | ||
| glob = await dynamicImportToGlob( | ||
| importExpressionAst.source, | ||
| importeeNode, | ||
| importExpression, | ||
@@ -549,3 +563,6 @@ async (raw) => { | ||
| exports.dynamicImportToGlob = dynamicImportToGlob; | ||
| exports.globFiles = globFiles; | ||
| exports.hasDynamicImport = hasDynamicImport; | ||
| exports.mappingPath = mappingPath; | ||
| exports.normallyImporteeRE = normallyImporteeRE; | ||
| exports.toLooseGlob = toLooseGlob; |
+32
-15
@@ -18,2 +18,7 @@ import fs from "node:fs"; | ||
| const singlelineCommentsRE = /\/\/.*/g; | ||
| function cleanUrl(url) { | ||
| const queryRE = /\?.*$/s; | ||
| const hashRE = /#.*$/s; | ||
| return url.replace(hashRE, "").replace(queryRE, ""); | ||
| } | ||
| class MagicString { | ||
@@ -291,4 +296,4 @@ constructor(str) { | ||
| } | ||
| async function dynamicImportToGlob(node, sourceString, resolver) { | ||
| let glob = expressionToGlob(node); | ||
| async function dynamicImportToGlob(importeeNode, importExpression, resolver) { | ||
| let glob = expressionToGlob(importeeNode); | ||
| glob = await (resolver == null ? void 0 : resolver(glob)) ?? glob; | ||
@@ -301,3 +306,3 @@ if (!glob.includes("*") || glob.startsWith("data:")) { | ||
| 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 "${importExpression}". It cannot be statically analyzed. Variable dynamic imports must start with ./ and be limited to a specific directory. ${example}` | ||
| ); | ||
@@ -307,3 +312,3 @@ } | ||
| 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 "${importExpression}". Variable absolute imports are not supported, imports must start with ./ in the static part of the import. ${example}` | ||
| ); | ||
@@ -313,3 +318,3 @@ } | ||
| 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 "${importExpression}". Variable bare imports are not supported, imports must start with ./ in the static part of the import. ${example}` | ||
| ); | ||
@@ -320,3 +325,3 @@ } | ||
| 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 "${importExpression}". Variable imports cannot import their own directory, place imports in a separate directory or make the import filename more specific. ${example}` | ||
| ); | ||
@@ -326,3 +331,3 @@ } | ||
| throw new Error( | ||
| `invalid import "${sourceString}". A file extension must be included in the static part of the import. ${example}` | ||
| `invalid import "${importExpression}". A file extension must be included in the static part of the import. ${example}` | ||
| ); | ||
@@ -370,3 +375,3 @@ } | ||
| }, | ||
| async transform(code, id) { | ||
| transform(code, id) { | ||
| return transformDynamicImport({ | ||
@@ -390,2 +395,4 @@ options, | ||
| var _a, _b; | ||
| if (!(extensions.includes(path.extname(id)) || extensions.includes(path.extname(cleanUrl(id))))) | ||
| return; | ||
| if (!hasDynamicImport(code)) | ||
@@ -443,10 +450,10 @@ return; | ||
| } | ||
| const globResult = await globFiles( | ||
| importExpressionAst, | ||
| const globResult = await globFiles({ | ||
| importeeNode: importExpressionAst.source, | ||
| importExpression, | ||
| id, | ||
| importer: id, | ||
| resolve, | ||
| extensions, | ||
| options.loose !== false | ||
| ); | ||
| loose: options.loose !== false | ||
| }); | ||
| if (!globResult) | ||
@@ -480,3 +487,10 @@ continue; | ||
| } | ||
| async function globFiles(importExpressionAst, importExpression, importer, resolve, extensions, loose = true) { | ||
| async function globFiles({ | ||
| importeeNode, | ||
| importExpression, | ||
| importer, | ||
| resolve, | ||
| extensions, | ||
| loose = true | ||
| }) { | ||
| let files; | ||
@@ -490,3 +504,3 @@ let resolved; | ||
| glob = await dynamicImportToGlob( | ||
| importExpressionAst.source, | ||
| importeeNode, | ||
| importExpression, | ||
@@ -548,4 +562,7 @@ async (raw) => { | ||
| dynamicImportToGlob, | ||
| globFiles, | ||
| hasDynamicImport, | ||
| mappingPath, | ||
| normallyImporteeRE, | ||
| toLooseGlob | ||
| }; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| type AcornNode<T = any> = import('rollup').AcornNode & Record<string, T>; | ||
| type AcornNode<T = any> = import('acorn').Node & Record<string, T>; |
+1
-1
| { | ||
| "name": "vite-plugin-dynamic-import", | ||
| "version": "1.3.0", | ||
| "version": "1.3.1", | ||
| "description": "Enhance Vite builtin dynamic import", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
+1
-1
@@ -43,3 +43,3 @@ # vite-plugin-dynamic-import | ||
| // https://github.com/vite-plugin/vite-plugin-dynamic-import/blob/v1.3.0/src/index.ts#L133-L135 | ||
| if (/node_modules\/(?!\.vite\/)/.test(id)) { | ||
| if (id.includes('/node_modules/foo')) { | ||
| return true | ||
@@ -46,0 +46,0 @@ } |
+1
-1
@@ -43,3 +43,3 @@ # vite-plugin-dynamic-import | ||
| // https://github.com/vite-plugin/vite-plugin-dynamic-import/blob/v1.3.0/src/index.ts#L133-L135 | ||
| if (/node_modules\/(?!\.vite\/)/.test(id)) { | ||
| if (id.includes('/node_modules/foo')) { | ||
| return true | ||
@@ -46,0 +46,0 @@ } |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
48575
3.68%1253
4.85%0
-100%