vite-plugin-fast-external
Advanced tools
Comparing version
35
index.js
@@ -34,5 +34,8 @@ const fs = require('fs') | ||
function node_modules(root, count = 0) { | ||
if (node_modules.p) { | ||
return node_modules.p | ||
} | ||
const p = path.join(root, 'node_modules') | ||
if (fs.existsSync(p)) { | ||
return p | ||
return node_modules.p = p | ||
} | ||
@@ -57,20 +60,16 @@ if (count >= 19) { | ||
for (const [module, strOrFn] of Object.entries(externals)) { | ||
const modFilename = path.join(node_modules(root), directory, `${module}.js`) | ||
if (!fs.existsSync(modFilename)) { | ||
// for '@scope/name' package | ||
ensureDir(path.parse(modFilename).dir) | ||
const moduleId = path.join(node_modules(root), directory, `${module}.js`) | ||
let moduleContent | ||
if (typeof strOrFn === 'string') { | ||
const iifeName = strOrFn | ||
moduleContent = format === 'cjs' | ||
? `const ${iifeName} = window['${iifeName}']; module.exports = ${iifeName};` | ||
: `const ${iifeName} = window['${iifeName}']; export { ${iifeName} as default }` | ||
} else { | ||
moduleContent = strOrFn() | ||
} | ||
let moduleContent | ||
if (typeof strOrFn === 'string') { | ||
const iifeName = strOrFn | ||
moduleContent = format === 'cjs' | ||
? `const ${iifeName} = window['${iifeName}']; module.exports = ${iifeName};` | ||
: `const ${iifeName} = window['${iifeName}']; export { ${iifeName} as default }` | ||
} else { | ||
moduleContent = strOrFn() | ||
} | ||
fs.writeFileSync(modFilename, moduleContent) | ||
} | ||
// for '@scope/name' package | ||
ensureDir(path.parse(moduleId).dir) | ||
fs.writeFileSync(moduleId, moduleContent) | ||
} | ||
@@ -77,0 +76,0 @@ } |
{ | ||
"name": "vite-plugin-fast-external", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "An tiny and fast external plugin for vite.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
110
0.92%0
-100%5560
-0.16%