vite-plugin-dynamic-import
Advanced tools
Comparing version 0.7.0 to 0.7.1
@@ -27,4 +27,4 @@ "use strict"; | ||
var _a, _b; | ||
const pureId = (0, utils_1.cleanUrl)(id); | ||
const extensions = utils_1.JS_EXTENSIONS.concat(utils_1.KNOWN_SFC_EXTENSIONS); | ||
const pureId = (0, vite_plugin_utils_1.cleanUrl)(id); | ||
const extensions = vite_plugin_utils_1.JS_EXTENSIONS.concat(vite_plugin_utils_1.KNOWN_SFC_EXTENSIONS); | ||
const globExtensions = ((_a = config.resolve) === null || _a === void 0 ? void 0 : _a.extensions) || extensions; | ||
@@ -31,0 +31,0 @@ const { ext } = path_1.default.parse(pureId); |
import type { AcornNode } from 'rollup'; | ||
export declare const JS_EXTENSIONS: string[]; | ||
export declare const KNOWN_SFC_EXTENSIONS: string[]; | ||
export declare const singleCommentsRegex: RegExp; | ||
export declare const multilineCommentsRegex: RegExp; | ||
export declare const dynamicImportRegex: RegExp; | ||
@@ -10,8 +6,5 @@ export declare const normallyImporteeRegex: RegExp; | ||
export declare const viteIgnoreRegex: RegExp; | ||
export declare const queryRE: RegExp; | ||
export declare const hashRE: RegExp; | ||
export declare function hasDynamicImport(code: string): boolean; | ||
export declare const cleanUrl: (url: string) => string; | ||
export declare function simpleWalk(ast: AcornNode, visitors: { | ||
[type: string]: (node: AcornNode) => void | Promise<void>; | ||
}): Promise<void>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.simpleWalk = exports.cleanUrl = exports.hasDynamicImport = exports.hashRE = exports.queryRE = exports.viteIgnoreRegex = exports.importeeRawRegex = exports.normallyImporteeRegex = exports.dynamicImportRegex = exports.multilineCommentsRegex = exports.singleCommentsRegex = exports.KNOWN_SFC_EXTENSIONS = exports.JS_EXTENSIONS = void 0; | ||
exports.JS_EXTENSIONS = [ | ||
'.mjs', | ||
'.js', | ||
'.ts', | ||
'.jsx', | ||
'.tsx', | ||
'.cjs' | ||
]; | ||
exports.KNOWN_SFC_EXTENSIONS = [ | ||
'.vue', | ||
'.svelte', | ||
]; | ||
exports.singleCommentsRegex = /([^\:])\/\/.*/g; | ||
exports.multilineCommentsRegex = /\/\*(.|[\r\n])*?\*\//gm; | ||
exports.simpleWalk = exports.hasDynamicImport = exports.viteIgnoreRegex = exports.importeeRawRegex = exports.normallyImporteeRegex = exports.dynamicImportRegex = void 0; | ||
const vite_plugin_utils_1 = require("vite-plugin-utils"); | ||
exports.dynamicImportRegex = /\bimport[\s\r\n]*?\(/; | ||
@@ -24,13 +11,9 @@ // this is probably less accurate | ||
exports.viteIgnoreRegex = /\/\*\s*@vite-ignore\s*\*\//; | ||
exports.queryRE = /\?.*$/s; | ||
exports.hashRE = /#.*$/s; | ||
function hasDynamicImport(code) { | ||
code = code | ||
.replace(exports.singleCommentsRegex, '') | ||
.replace(exports.multilineCommentsRegex, ''); | ||
.replace(vite_plugin_utils_1.singlelineCommentsRE, '') | ||
.replace(vite_plugin_utils_1.multilineCommentsRE, ''); | ||
return exports.dynamicImportRegex.test(code); | ||
} | ||
exports.hasDynamicImport = hasDynamicImport; | ||
const cleanUrl = (url) => url.replace(exports.hashRE, '').replace(exports.queryRE, ''); | ||
exports.cleanUrl = cleanUrl; | ||
async function simpleWalk(ast, visitors) { | ||
@@ -37,0 +20,0 @@ var _a; |
{ | ||
"name": "vite-plugin-dynamic-import", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"description": "Enhance Vite builtin dynamic import", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import path from 'path' | ||
import type { Plugin, ResolvedConfig } from 'vite' | ||
import fastGlob from 'fast-glob' | ||
import { sortPlugin, OfficialPlugins } from 'vite-plugin-utils' | ||
import { | ||
hasDynamicImport, | ||
sortPlugin, | ||
OfficialPlugins, | ||
cleanUrl, | ||
JS_EXTENSIONS, | ||
KNOWN_SFC_EXTENSIONS, | ||
} from 'vite-plugin-utils' | ||
import { | ||
hasDynamicImport, | ||
normallyImporteeRegex, | ||
@@ -11,0 +14,0 @@ viteIgnoreRegex, |
import type { AcornNode } from 'rollup' | ||
import { | ||
singlelineCommentsRE, | ||
multilineCommentsRE, | ||
} from 'vite-plugin-utils' | ||
export const JS_EXTENSIONS = [ | ||
'.mjs', | ||
'.js', | ||
'.ts', | ||
'.jsx', | ||
'.tsx', | ||
'.cjs' | ||
] | ||
export const KNOWN_SFC_EXTENSIONS = [ | ||
'.vue', | ||
'.svelte', | ||
] | ||
export const singleCommentsRegex = /([^\:])\/\/.*/g | ||
export const multilineCommentsRegex = /\/\*(.|[\r\n])*?\*\//gm | ||
export const dynamicImportRegex = /\bimport[\s\r\n]*?\(/ | ||
@@ -24,15 +13,10 @@ // this is probably less accurate | ||
export const viteIgnoreRegex = /\/\*\s*@vite-ignore\s*\*\// | ||
export const queryRE = /\?.*$/s | ||
export const hashRE = /#.*$/s | ||
export function hasDynamicImport(code: string) { | ||
code = code | ||
.replace(singleCommentsRegex, '') | ||
.replace(multilineCommentsRegex, '') | ||
.replace(singlelineCommentsRE, '') | ||
.replace(multilineCommentsRE, '') | ||
return dynamicImportRegex.test(code) | ||
} | ||
export const cleanUrl = (url: string): string => | ||
url.replace(hashRE, '').replace(queryRE, '') | ||
export async function simpleWalk( | ||
@@ -39,0 +23,0 @@ ast: AcornNode, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
53164
1215