@vercel/nft
Advanced tools
Comparing version 0.26.4 to 0.26.5
@@ -29,3 +29,3 @@ "use strict"; | ||
//require("acorn-private-class-elements") | ||
require("acorn-import-attributes").importAttributes); | ||
require('acorn-import-attributes').importAttributes); | ||
const os_1 = __importDefault(require("os")); | ||
@@ -40,5 +40,5 @@ const wrappers_1 = require("./utils/wrappers"); | ||
NODE_ENV: static_eval_1.UNKNOWN, | ||
[static_eval_1.UNKNOWN]: true | ||
[static_eval_1.UNKNOWN]: true, | ||
}, | ||
[static_eval_1.UNKNOWN]: true | ||
[static_eval_1.UNKNOWN]: true, | ||
}; | ||
@@ -71,3 +71,3 @@ // unique symbol value to identify express instance in static analysis | ||
stat: FS_FN, | ||
statSync: FS_FN | ||
statSync: FS_FN, | ||
}; | ||
@@ -85,3 +85,3 @@ const fsExtraSymbols = { | ||
bindings: { | ||
default: BINDINGS | ||
default: BINDINGS, | ||
}, | ||
@@ -93,33 +93,33 @@ express: { | ||
set: EXPRESS_SET, | ||
engine: EXPRESS_ENGINE | ||
engine: EXPRESS_ENGINE, | ||
}; | ||
} | ||
}, | ||
}, | ||
fs: { | ||
default: fsSymbols, | ||
...fsSymbols | ||
...fsSymbols, | ||
}, | ||
'fs-extra': { | ||
default: fsExtraSymbols, | ||
...fsExtraSymbols | ||
...fsExtraSymbols, | ||
}, | ||
'graceful-fs': { | ||
default: fsSymbols, | ||
...fsSymbols | ||
...fsSymbols, | ||
}, | ||
process: { | ||
default: staticProcess, | ||
...staticProcess | ||
...staticProcess, | ||
}, | ||
// populated below | ||
path: { | ||
default: {} | ||
default: {}, | ||
}, | ||
os: { | ||
default: os_1.default, | ||
...os_1.default | ||
...os_1.default, | ||
}, | ||
'@mapbox/node-pre-gyp': { | ||
default: node_pre_gyp_1.default, | ||
...node_pre_gyp_1.default | ||
...node_pre_gyp_1.default, | ||
}, | ||
@@ -130,25 +130,25 @@ 'node-pre-gyp': binary_locators_1.pregyp, | ||
'node-gyp-build': { | ||
default: NODE_GYP_BUILD | ||
default: NODE_GYP_BUILD, | ||
}, | ||
'@aminya/node-gyp-build': { | ||
default: NODE_GYP_BUILD | ||
default: NODE_GYP_BUILD, | ||
}, | ||
'nbind': { | ||
nbind: { | ||
init: NBIND_INIT, | ||
default: { | ||
init: NBIND_INIT | ||
} | ||
init: NBIND_INIT, | ||
}, | ||
}, | ||
'resolve-from': { | ||
default: resolve_from_1.default | ||
default: resolve_from_1.default, | ||
}, | ||
'strong-globalize': { | ||
default: { | ||
SetRootDir: SET_ROOT_DIR | ||
SetRootDir: SET_ROOT_DIR, | ||
}, | ||
SetRootDir: SET_ROOT_DIR | ||
SetRootDir: SET_ROOT_DIR, | ||
}, | ||
'pkginfo': { | ||
default: PKG_INFO | ||
} | ||
pkginfo: { | ||
default: PKG_INFO, | ||
}, | ||
}); | ||
@@ -165,6 +165,9 @@ const globalBindings = { | ||
Object: { | ||
assign: Object.assign | ||
} | ||
assign: Object.assign, | ||
}, | ||
}; | ||
globalBindings.global = globalBindings.GLOBAL = globalBindings.globalThis = globalBindings; | ||
globalBindings.global = | ||
globalBindings.GLOBAL = | ||
globalBindings.globalThis = | ||
globalBindings; | ||
// call expression triggers | ||
@@ -174,3 +177,3 @@ const TRIGGER = Symbol(); | ||
const staticPath = staticModules.path; | ||
Object.keys(path_1.default).forEach(name => { | ||
Object.keys(path_1.default).forEach((name) => { | ||
const pathFn = path_1.default[name]; | ||
@@ -194,3 +197,8 @@ if (typeof pathFn === 'function') { | ||
const excludeAssetExtensions = new Set(['.h', '.cmake', '.c', '.cpp']); | ||
const excludeAssetFiles = new Set(['CHANGELOG.md', 'README.md', 'readme.md', 'changelog.md']); | ||
const excludeAssetFiles = new Set([ | ||
'CHANGELOG.md', | ||
'README.md', | ||
'readme.md', | ||
'changelog.md', | ||
]); | ||
let cwd; | ||
@@ -217,3 +225,2 @@ const absoluteRegEx = /^\/[^\/]+|^[a-z]:[\\/][^\\/]+/i; | ||
const repeatGlobRegEx = /([\/\\]\*\*[\/\\]\*)+/g; | ||
; | ||
async function analyze(id, code, job) { | ||
@@ -232,8 +239,12 @@ const assets = new Set(); | ||
const wildcardIndex = wildcardPath.indexOf(static_eval_1.WILDCARD); | ||
const dirIndex = wildcardIndex === -1 ? wildcardPath.length : wildcardPath.lastIndexOf(path_1.default.sep, wildcardIndex); | ||
const dirIndex = wildcardIndex === -1 | ||
? wildcardPath.length | ||
: wildcardPath.lastIndexOf(path_1.default.sep, wildcardIndex); | ||
const assetDirPath = wildcardPath.substring(0, dirIndex); | ||
const patternPath = wildcardPath.slice(dirIndex); | ||
const wildcardPattern = patternPath.replace(static_eval_1.wildcardRegEx, (_match, index) => { | ||
const wildcardPattern = patternPath | ||
.replace(static_eval_1.wildcardRegEx, (_match, index) => { | ||
return patternPath[index - 1] === path_1.default.sep ? '**/*' : '*'; | ||
}).replace(repeatGlobRegEx, '/**/*') || '/**/*'; | ||
}) | ||
.replace(repeatGlobRegEx, '/**/*') || '/**/*'; | ||
if (job.ignoreFn(path_1.default.relative(job.base, assetDirPath + wildcardPattern))) | ||
@@ -244,8 +255,12 @@ return; | ||
console.log('Globbing ' + assetDirPath + wildcardPattern); | ||
const files = (await new Promise((resolve, reject) => (0, glob_1.default)(assetDirPath + wildcardPattern, { mark: true, ignore: assetDirPath + '/**/node_modules/**/*', dot: true }, (err, files) => err ? reject(err) : resolve(files)))); | ||
const files = await new Promise((resolve, reject) => (0, glob_1.default)(assetDirPath + wildcardPattern, { | ||
mark: true, | ||
ignore: assetDirPath + '/**/node_modules/**/*', | ||
dot: true, | ||
}, (err, files) => (err ? reject(err) : resolve(files)))); | ||
files | ||
.filter(name => !excludeAssetExtensions.has(path_1.default.extname(name)) && | ||
.filter((name) => !excludeAssetExtensions.has(path_1.default.extname(name)) && | ||
!excludeAssetFiles.has(path_1.default.basename(name)) && | ||
!name.endsWith('/')) | ||
.forEach(file => assets.add(file)); | ||
.forEach((file) => assets.add(file)); | ||
}); | ||
@@ -259,3 +274,6 @@ }; | ||
try { | ||
ast = acorn.parse(code, { ecmaVersion: 'latest', allowReturnOutsideFunction: true }); | ||
ast = acorn.parse(code, { | ||
ecmaVersion: 'latest', | ||
allowReturnOutsideFunction: true, | ||
}); | ||
isESM = false; | ||
@@ -272,3 +290,7 @@ } | ||
try { | ||
ast = acorn.parse(code, { ecmaVersion: 'latest', sourceType: 'module', allowAwaitOutsideFunction: true }); | ||
ast = acorn.parse(code, { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
allowAwaitOutsideFunction: true, | ||
}); | ||
isESM = true; | ||
@@ -286,12 +308,12 @@ } | ||
shadowDepth: 0, | ||
value: { value: path_1.default.resolve(id, '..') } | ||
value: { value: path_1.default.resolve(id, '..') }, | ||
}, | ||
__filename: { | ||
shadowDepth: 0, | ||
value: { value: id } | ||
value: { value: id }, | ||
}, | ||
process: { | ||
shadowDepth: 0, | ||
value: { value: staticProcess } | ||
} | ||
value: { value: staticProcess }, | ||
}, | ||
}); | ||
@@ -310,5 +332,5 @@ if (!isESM || job.mixedModules) { | ||
return (0, resolve_dependency_js_1.default)(specifier, id, job); | ||
} | ||
} | ||
} | ||
}, | ||
}, | ||
}, | ||
}; | ||
@@ -324,3 +346,3 @@ knownBindings.require.value.value.resolve[TRIGGER] = true; | ||
shadowDepth: 0, | ||
value: value | ||
value: value, | ||
}; | ||
@@ -351,10 +373,15 @@ } | ||
setKnownBinding(impt.local.name, { value: staticModule }); | ||
else if (impt.type === 'ImportDefaultSpecifier' && 'default' in staticModule) | ||
else if (impt.type === 'ImportDefaultSpecifier' && | ||
'default' in staticModule) | ||
setKnownBinding(impt.local.name, { value: staticModule.default }); | ||
else if (impt.type === 'ImportSpecifier' && impt.imported.name in staticModule) | ||
setKnownBinding(impt.local.name, { value: staticModule[impt.imported.name] }); | ||
else if (impt.type === 'ImportSpecifier' && | ||
impt.imported.name in staticModule) | ||
setKnownBinding(impt.local.name, { | ||
value: staticModule[impt.imported.name], | ||
}); | ||
} | ||
} | ||
} | ||
else if (decl.type === 'ExportNamedDeclaration' || decl.type === 'ExportAllDeclaration') { | ||
else if (decl.type === 'ExportNamedDeclaration' || | ||
decl.type === 'ExportAllDeclaration') { | ||
if (decl.source) | ||
@@ -367,6 +394,6 @@ deps.add(String(decl.source.value)); | ||
const vars = Object.create(null); | ||
Object.keys(globalBindings).forEach(name => { | ||
Object.keys(globalBindings).forEach((name) => { | ||
vars[name] = { value: globalBindings[name] }; | ||
}); | ||
Object.keys(knownBindings).forEach(name => { | ||
Object.keys(knownBindings).forEach((name) => { | ||
vars[name] = getKnownBinding(name); | ||
@@ -386,7 +413,10 @@ }); | ||
function emitWildcardRequire(wildcardRequire) { | ||
if (!job.analysis.emitGlobs || !wildcardRequire.startsWith('./') && !wildcardRequire.startsWith('../')) | ||
if (!job.analysis.emitGlobs || | ||
(!wildcardRequire.startsWith('./') && !wildcardRequire.startsWith('../'))) | ||
return; | ||
wildcardRequire = path_1.default.resolve(dir, wildcardRequire); | ||
const wildcardIndex = wildcardRequire.indexOf(static_eval_1.WILDCARD); | ||
const dirIndex = wildcardIndex === -1 ? wildcardRequire.length : wildcardRequire.lastIndexOf(path_1.default.sep, wildcardIndex); | ||
const dirIndex = wildcardIndex === -1 | ||
? wildcardRequire.length | ||
: wildcardRequire.lastIndexOf(path_1.default.sep, wildcardIndex); | ||
const wildcardDirPath = wildcardRequire.substring(0, dirIndex); | ||
@@ -398,3 +428,4 @@ const patternPath = wildcardRequire.slice(dirIndex); | ||
if (!wildcardPattern.endsWith('*')) | ||
wildcardPattern += '?(' + (job.ts ? '.ts|.tsx|' : '') + '.js|.json|.node)'; | ||
wildcardPattern += | ||
'?(' + (job.ts ? '.ts|.tsx|' : '') + '.js|.json|.node)'; | ||
if (job.ignoreFn(path_1.default.relative(job.base, wildcardDirPath + wildcardPattern))) | ||
@@ -405,8 +436,8 @@ return; | ||
console.log('Globbing ' + wildcardDirPath + wildcardPattern); | ||
const files = (await new Promise((resolve, reject) => (0, glob_1.default)(wildcardDirPath + wildcardPattern, { mark: true, ignore: wildcardDirPath + '/**/node_modules/**/*' }, (err, files) => err ? reject(err) : resolve(files)))); | ||
const files = await new Promise((resolve, reject) => (0, glob_1.default)(wildcardDirPath + wildcardPattern, { mark: true, ignore: wildcardDirPath + '/**/node_modules/**/*' }, (err, files) => (err ? reject(err) : resolve(files)))); | ||
files | ||
.filter(name => !excludeAssetExtensions.has(path_1.default.extname(name)) && | ||
.filter((name) => !excludeAssetExtensions.has(path_1.default.extname(name)) && | ||
!excludeAssetFiles.has(path_1.default.basename(name)) && | ||
!name.endsWith('/')) | ||
.forEach(file => deps.add(file)); | ||
.forEach((file) => deps.add(file)); | ||
}); | ||
@@ -444,3 +475,10 @@ } | ||
(0, wrappers_1.handleWrappers)(ast); | ||
await (0, special_cases_1.default)({ id, ast, emitDependency: path => deps.add(path), emitAsset: path => assets.add(path), emitAssetDirectory, job }); | ||
await (0, special_cases_1.default)({ | ||
id, | ||
ast, | ||
emitDependency: (path) => deps.add(path), | ||
emitAsset: (path) => assets.add(path), | ||
emitAssetDirectory, | ||
job, | ||
}); | ||
} | ||
@@ -455,4 +493,7 @@ async function backtrack(parent, context) { | ||
if (curStaticValue) { | ||
if ('value' in curStaticValue && typeof curStaticValue.value !== 'symbol' || | ||
'then' in curStaticValue && typeof curStaticValue.then !== 'symbol' && typeof curStaticValue.else !== 'symbol') { | ||
if (('value' in curStaticValue && | ||
typeof curStaticValue.value !== 'symbol') || | ||
('then' in curStaticValue && | ||
typeof curStaticValue.then !== 'symbol' && | ||
typeof curStaticValue.else !== 'symbol')) { | ||
staticChildValue = curStaticValue; | ||
@@ -485,9 +526,15 @@ staticChildNode = parent; | ||
if (node.type === 'Identifier') { | ||
if ((0, ast_helpers_1.isIdentifierRead)(node, parent) && job.analysis.computeFileReferences) { | ||
if ((0, ast_helpers_1.isIdentifierRead)(node, parent) && | ||
job.analysis.computeFileReferences) { | ||
let binding; | ||
// detect asset leaf expression triggers (if not already) | ||
// __dirname, __filename | ||
if (typeof (binding = getKnownBinding(node.name)?.value) === 'string' && binding.match(absoluteRegEx) || | ||
binding && (typeof binding === 'function' || typeof binding === 'object') && binding[TRIGGER]) { | ||
staticChildValue = { value: typeof binding === 'string' ? binding : undefined }; | ||
if ((typeof (binding = getKnownBinding(node.name)?.value) === 'string' && | ||
binding.match(absoluteRegEx)) || | ||
(binding && | ||
(typeof binding === 'function' || typeof binding === 'object') && | ||
binding[TRIGGER])) { | ||
staticChildValue = { | ||
value: typeof binding === 'string' ? binding : undefined, | ||
}; | ||
staticChildNode = node; | ||
@@ -498,3 +545,9 @@ await backtrack(parent, this); | ||
} | ||
else if (job.analysis.computeFileReferences && node.type === 'MemberExpression' && node.object.type === 'MetaProperty' && node.object.meta.name === 'import' && node.object.property.name === 'meta' && (node.property.computed ? node.property.value : node.property.name) === 'url') { | ||
else if (job.analysis.computeFileReferences && | ||
node.type === 'MemberExpression' && | ||
node.object.type === 'MetaProperty' && | ||
node.object.meta.name === 'import' && | ||
node.object.property.name === 'meta' && | ||
(node.property.computed ? node.property.value : node.property.name) === | ||
'url') { | ||
// import.meta.url leaf trigger | ||
@@ -516,4 +569,7 @@ staticChildValue = { value: importMetaUrl }; | ||
else if (node.type === 'CallExpression') { | ||
if ((!isESM || job.mixedModules) && node.callee.type === 'Identifier' && node.arguments.length) { | ||
if (node.callee.name === 'require' && knownBindings.require.shadowDepth === 0) { | ||
if ((!isESM || job.mixedModules) && | ||
node.callee.type === 'Identifier' && | ||
node.arguments.length) { | ||
if (node.callee.name === 'require' && | ||
knownBindings.require.shadowDepth === 0) { | ||
await processRequireArg(node.arguments[0]); | ||
@@ -547,6 +603,11 @@ return; | ||
} | ||
const calleeValue = job.analysis.evaluatePureExpressions && await computePureStaticValue(node.callee, false); | ||
const calleeValue = job.analysis.evaluatePureExpressions && | ||
(await computePureStaticValue(node.callee, false)); | ||
// if we have a direct pure static function, | ||
// and that function has a [TRIGGER] symbol -> trigger asset emission from it | ||
if (calleeValue && 'value' in calleeValue && typeof calleeValue.value === 'function' && calleeValue.value[TRIGGER] && job.analysis.computeFileReferences) { | ||
if (calleeValue && | ||
'value' in calleeValue && | ||
typeof calleeValue.value === 'function' && | ||
calleeValue.value[TRIGGER] && | ||
job.analysis.computeFileReferences) { | ||
staticChildValue = await computePureStaticValue(node, true); | ||
@@ -560,3 +621,5 @@ // if it computes, then we start backtracking | ||
// handle well-known function symbol cases | ||
else if (calleeValue && 'value' in calleeValue && typeof calleeValue.value === 'symbol') { | ||
else if (calleeValue && | ||
'value' in calleeValue && | ||
typeof calleeValue.value === 'symbol') { | ||
switch (calleeValue.value) { | ||
@@ -612,3 +675,4 @@ // customRequireWrapper('...') | ||
node.arguments[0].arguments[1].type === 'Literal'; | ||
if (knownBindings.__dirname.shadowDepth === 0 && (withDirname || withPathJoinDirname)) { | ||
if (knownBindings.__dirname.shadowDepth === 0 && | ||
(withDirname || withPathJoinDirname)) { | ||
const pathJoinedDir = withPathJoinDirname | ||
@@ -643,3 +707,6 @@ ? path_1.default.join(dir, node.arguments[0].arguments[1].value) | ||
const arg = await computePureStaticValue(node.arguments[0], false); | ||
if (arg && 'value' in arg && (typeof arg.value === 'string' || typeof arg.value === 'undefined')) { | ||
if (arg && | ||
'value' in arg && | ||
(typeof arg.value === 'string' || | ||
typeof arg.value === 'undefined')) { | ||
const bindingInfo = (0, binary_locators_1.nbind)(arg.value); | ||
@@ -675,3 +742,5 @@ if (bindingInfo && bindingInfo.path) { | ||
staticChildNode = node.arguments[0]; | ||
if (calleeValue.value === FS_DIR_FN && node.arguments[0].type === 'Identifier' && node.arguments[0].name === '__dirname') { | ||
if (calleeValue.value === FS_DIR_FN && | ||
node.arguments[0].type === 'Identifier' && | ||
node.arguments[0].name === '__dirname') { | ||
// Special case `fs.readdirSync(__dirname)` to emit right away | ||
@@ -700,3 +769,4 @@ emitAssetDirectory(dir); | ||
const rootPjson = path_1.default.resolve('/package.json'); | ||
while (pjsonPath !== rootPjson && (await job.stat(pjsonPath) === null)) | ||
while (pjsonPath !== rootPjson && | ||
(await job.stat(pjsonPath)) === null) | ||
pjsonPath = path_1.default.resolve(pjsonPath, '../../package.json'); | ||
@@ -709,3 +779,6 @@ if (pjsonPath !== rootPjson) | ||
} | ||
else if (node.type === 'VariableDeclaration' && parent && !(0, ast_helpers_1.isVarLoop)(parent) && job.analysis.evaluatePureExpressions) { | ||
else if (node.type === 'VariableDeclaration' && | ||
parent && | ||
!(0, ast_helpers_1.isVarLoop)(parent) && | ||
job.analysis.evaluatePureExpressions) { | ||
for (const decl of node.declarations) { | ||
@@ -730,6 +803,10 @@ if (!decl.init) | ||
continue; | ||
setKnownBinding(prop.value.name, { value: computed.value[prop.key.name] }); | ||
setKnownBinding(prop.value.name, { | ||
value: computed.value[prop.key.name], | ||
}); | ||
} | ||
} | ||
if (!('value' in computed) && isAbsolutePathOrUrl(computed.then) && isAbsolutePathOrUrl(computed.else)) { | ||
if (!('value' in computed) && | ||
isAbsolutePathOrUrl(computed.then) && | ||
isAbsolutePathOrUrl(computed.else)) { | ||
staticChildValue = computed; | ||
@@ -742,3 +819,6 @@ staticChildNode = decl.init; | ||
} | ||
else if (node.type === 'AssignmentExpression' && parent && !(0, ast_helpers_1.isLoop)(parent) && job.analysis.evaluatePureExpressions) { | ||
else if (node.type === 'AssignmentExpression' && | ||
parent && | ||
!(0, ast_helpers_1.isLoop)(parent) && | ||
job.analysis.evaluatePureExpressions) { | ||
if (!hasKnownBindingValue(node.left.name)) { | ||
@@ -761,3 +841,5 @@ const computed = await computePureStaticValue(node.right, false); | ||
continue; | ||
setKnownBinding(prop.value.name, { value: computed.value[prop.key.name] }); | ||
setKnownBinding(prop.value.name, { | ||
value: computed.value[prop.key.name], | ||
}); | ||
} | ||
@@ -775,7 +857,11 @@ } | ||
else if ((!isESM || job.mixedModules) && | ||
(node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') && | ||
(node.arguments || node.params)[0] && (node.arguments || node.params)[0].type === 'Identifier') { | ||
(node.type === 'FunctionDeclaration' || | ||
node.type === 'FunctionExpression' || | ||
node.type === 'ArrowFunctionExpression') && | ||
(node.arguments || node.params)[0] && | ||
(node.arguments || node.params)[0].type === 'Identifier') { | ||
let fnName; | ||
let args; | ||
if ((node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression') && | ||
if ((node.type === 'ArrowFunctionExpression' || | ||
node.type === 'FunctionExpression') && | ||
parent && | ||
@@ -794,3 +880,4 @@ parent.type === 'VariableDeclarator' && | ||
for (let i = 0; i < node.body.body.length; i++) { | ||
if (node.body.body[i].type === 'VariableDeclaration' && !requireDecl) { | ||
if (node.body.body[i].type === 'VariableDeclaration' && | ||
!requireDecl) { | ||
requireDecl = node.body.body[i].declarations.find((decl) => decl && | ||
@@ -840,3 +927,3 @@ decl.id && | ||
await backtrack(parent, this); | ||
} | ||
}, | ||
}); | ||
@@ -848,3 +935,5 @@ await assetEmissionPromises; | ||
const wildcardIndex = assetPath.indexOf(static_eval_1.WILDCARD); | ||
const dirIndex = wildcardIndex === -1 ? assetPath.length : assetPath.lastIndexOf(path_1.default.sep, wildcardIndex); | ||
const dirIndex = wildcardIndex === -1 | ||
? assetPath.length | ||
: assetPath.lastIndexOf(path_1.default.sep, wildcardIndex); | ||
const basePath = assetPath.substring(0, dirIndex); | ||
@@ -892,6 +981,14 @@ try { | ||
if (pkgBase) { | ||
const nodeModulesBase = id.substring(0, id.indexOf(path_1.default.sep + 'node_modules')) + path_1.default.sep + 'node_modules' + path_1.default.sep; | ||
const nodeModulesBase = id.substring(0, id.indexOf(path_1.default.sep + 'node_modules')) + | ||
path_1.default.sep + | ||
'node_modules' + | ||
path_1.default.sep; | ||
if (!assetPath.startsWith(nodeModulesBase)) { | ||
if (job.log) | ||
console.log('Skipping asset emission of ' + assetPath.replace(static_eval_1.wildcardRegEx, '*') + ' for ' + id + ' as it is outside the package base ' + pkgBase); | ||
console.log('Skipping asset emission of ' + | ||
assetPath.replace(static_eval_1.wildcardRegEx, '*') + | ||
' for ' + | ||
id + | ||
' as it is outside the package base ' + | ||
pkgBase); | ||
return false; | ||
@@ -903,3 +1000,7 @@ } | ||
function resolveAbsolutePathOrUrl(value) { | ||
return value instanceof url_1.URL ? (0, url_1.fileURLToPath)(value) : value.startsWith('file:') ? (0, url_1.fileURLToPath)(new url_1.URL(value)) : path_1.default.resolve(value); | ||
return value instanceof url_1.URL | ||
? (0, url_1.fileURLToPath)(value) | ||
: value.startsWith('file:') | ||
? (0, url_1.fileURLToPath)(new url_1.URL(value)) | ||
: path_1.default.resolve(value); | ||
} | ||
@@ -910,3 +1011,4 @@ async function emitStaticChildAsset() { | ||
} | ||
if ('value' in staticChildValue && isAbsolutePathOrUrl(staticChildValue.value)) { | ||
if ('value' in staticChildValue && | ||
isAbsolutePathOrUrl(staticChildValue.value)) { | ||
try { | ||
@@ -918,3 +1020,6 @@ const resolved = resolveAbsolutePathOrUrl(staticChildValue.value); | ||
} | ||
else if ('then' in staticChildValue && 'else' in staticChildValue && isAbsolutePathOrUrl(staticChildValue.then) && isAbsolutePathOrUrl(staticChildValue.else)) { | ||
else if ('then' in staticChildValue && | ||
'else' in staticChildValue && | ||
isAbsolutePathOrUrl(staticChildValue.then) && | ||
isAbsolutePathOrUrl(staticChildValue.else)) { | ||
let resolvedThen; | ||
@@ -935,3 +1040,6 @@ try { | ||
} | ||
else if (staticChildNode && staticChildNode.type === 'ArrayExpression' && 'value' in staticChildValue && staticChildValue.value instanceof Array) { | ||
else if (staticChildNode && | ||
staticChildNode.type === 'ArrayExpression' && | ||
'value' in staticChildValue && | ||
staticChildValue.value instanceof Array) { | ||
for (const value of staticChildValue.value) { | ||
@@ -949,5 +1057,4 @@ try { | ||
exports.default = analyze; | ||
; | ||
function isAst(ast) { | ||
return 'body' in ast; | ||
} |
@@ -14,3 +14,5 @@ #!/usr/bin/env node | ||
!reason.parents || | ||
(reason.type.length === 1 && reason.type.includes('initial') && reason.parents.size === 0)) { | ||
(reason.type.length === 1 && | ||
reason.type.includes('initial') && | ||
reason.parents.size === 0)) { | ||
return; | ||
@@ -72,5 +74,3 @@ } | ||
} | ||
const normalizedExitPoint = ((0, path_1.isAbsolute)(exitpoint) | ||
? (0, path_1.relative)(cwd, exitpoint) | ||
: exitpoint).replace(/[/\\]/g, path_1.sep); | ||
const normalizedExitPoint = ((0, path_1.isAbsolute)(exitpoint) ? (0, path_1.relative)(cwd, exitpoint) : exitpoint).replace(/[/\\]/g, path_1.sep); | ||
printStack(normalizedExitPoint, reasons, stdout, cwd); | ||
@@ -77,0 +77,0 @@ } |
/// <reference types="node" /> | ||
import type { Stats } from "fs"; | ||
import type { Stats } from 'fs'; | ||
export declare class CachedFileSystem { | ||
@@ -4,0 +4,0 @@ private fileCache; |
@@ -65,3 +65,3 @@ "use strict"; | ||
catch (e) { | ||
if (e.code !== "EINVAL" && e.code !== "ENOENT" && e.code !== "UNKNOWN") | ||
if (e.code !== 'EINVAL' && e.code !== 'ENOENT' && e.code !== 'UNKNOWN') | ||
throw e; | ||
@@ -76,3 +76,3 @@ return null; | ||
catch (e) { | ||
if (e.code === "ENOENT" || e.code === "EISDIR") { | ||
if (e.code === 'ENOENT' || e.code === 'EISDIR') { | ||
return null; | ||
@@ -88,3 +88,3 @@ } | ||
catch (e) { | ||
if (e.code === "ENOENT") { | ||
if (e.code === 'ENOENT') { | ||
return null; | ||
@@ -91,0 +91,0 @@ } |
@@ -61,3 +61,3 @@ "use strict"; | ||
reasons: job.reasons, | ||
warnings: job.warnings | ||
warnings: job.warnings, | ||
}; | ||
@@ -67,3 +67,2 @@ return result; | ||
exports.nodeFileTrace = nodeFileTrace; | ||
; | ||
class Job { | ||
@@ -136,3 +135,3 @@ constructor({ base = process.cwd(), processCwd, exports, conditions = exports || ['node'], exportsOnly = false, paths = {}, ignore, log = false, mixedModules = false, ts = true, analysis = {}, cache, | ||
else if (Array.isArray(ignore)) { | ||
const resolvedIgnores = ignore.map(ignore => (0, path_1.relative)(base, (0, path_1.resolve)(base || process.cwd(), ignore))); | ||
const resolvedIgnores = ignore.map((ignore) => (0, path_1.relative)(base, (0, path_1.resolve)(base || process.cwd(), ignore))); | ||
this.ignoreFn = (path) => { | ||
@@ -173,3 +172,3 @@ if (path.startsWith('..' + path_1.sep)) | ||
} | ||
this.analysisCache = cache && cache.analysisCache || new Map(); | ||
this.analysisCache = (cache && cache.analysisCache) || new Map(); | ||
if (cache) { | ||
@@ -239,3 +238,3 @@ cache.analysisCache = this.analysisCache; | ||
ignored: false, | ||
parents: new Set() | ||
parents: new Set(), | ||
}; | ||
@@ -276,3 +275,2 @@ this.reasons.set(path, reasonEntry); | ||
} | ||
; | ||
this.processed.add(path); | ||
@@ -317,4 +315,12 @@ const emitted = await this.emitFile(path, 'dependency', parent); | ||
const ext = (0, path_1.extname)(asset); | ||
if (ext === '.js' || ext === '.mjs' || ext === '.node' || ext === '' || | ||
this.ts && (ext === '.ts' || ext === '.tsx') && asset.startsWith(this.base) && asset.slice(this.base.length).indexOf(path_1.sep + 'node_modules' + path_1.sep) === -1) | ||
if (ext === '.js' || | ||
ext === '.mjs' || | ||
ext === '.node' || | ||
ext === '' || | ||
(this.ts && | ||
(ext === '.ts' || ext === '.tsx') && | ||
asset.startsWith(this.base) && | ||
asset | ||
.slice(this.base.length) | ||
.indexOf(path_1.sep + 'node_modules' + path_1.sep) === -1)) | ||
await this.emitDependency(asset, path); | ||
@@ -321,0 +327,0 @@ else |
@@ -11,3 +11,7 @@ "use strict"; | ||
let resolved; | ||
if ((0, path_1.isAbsolute)(specifier) || specifier === '.' || specifier === '..' || specifier.startsWith('./') || specifier.startsWith('../')) { | ||
if ((0, path_1.isAbsolute)(specifier) || | ||
specifier === '.' || | ||
specifier === '..' || | ||
specifier.startsWith('./') || | ||
specifier.startsWith('../')) { | ||
const trailingSlash = specifier.endsWith('/'); | ||
@@ -23,3 +27,3 @@ resolved = await resolvePath((0, path_1.resolve)(parent, '..', specifier) + (trailingSlash ? '/' : ''), parent, job); | ||
if (Array.isArray(resolved)) { | ||
return Promise.all(resolved.map(resolved => job.realpath(resolved, parent))); | ||
return Promise.all(resolved.map((resolved) => job.realpath(resolved, parent))); | ||
} | ||
@@ -34,5 +38,5 @@ else if (resolved.startsWith('node:')) { | ||
exports.default = resolveDependency; | ||
; | ||
async function resolvePath(path, parent, job) { | ||
const result = await resolveFile(path, parent, job) || await resolveDir(path, parent, job); | ||
const result = (await resolveFile(path, parent, job)) || | ||
(await resolveDir(path, parent, job)); | ||
if (!result) { | ||
@@ -49,5 +53,11 @@ throw new NotFoundError(path, parent); | ||
return path; | ||
if (job.ts && path.startsWith(job.base) && path.slice(job.base.length).indexOf(path_1.sep + 'node_modules' + path_1.sep) === -1 && await job.isFile(path + '.ts')) | ||
if (job.ts && | ||
path.startsWith(job.base) && | ||
path.slice(job.base.length).indexOf(path_1.sep + 'node_modules' + path_1.sep) === -1 && | ||
(await job.isFile(path + '.ts'))) | ||
return path + '.ts'; | ||
if (job.ts && path.startsWith(job.base) && path.slice(job.base.length).indexOf(path_1.sep + 'node_modules' + path_1.sep) === -1 && await job.isFile(path + '.tsx')) | ||
if (job.ts && | ||
path.startsWith(job.base) && | ||
path.slice(job.base.length).indexOf(path_1.sep + 'node_modules' + path_1.sep) === -1 && | ||
(await job.isFile(path + '.tsx'))) | ||
return path + '.tsx'; | ||
@@ -65,7 +75,8 @@ if (await job.isFile(path + '.js')) | ||
path = path.slice(0, -1); | ||
if (!await job.isDir(path)) | ||
if (!(await job.isDir(path))) | ||
return; | ||
const pkgCfg = await getPkgCfg(path, job); | ||
if (pkgCfg && typeof pkgCfg.main === 'string') { | ||
const resolved = await resolveFile((0, path_1.resolve)(path, pkgCfg.main), parent, job) || await resolveFile((0, path_1.resolve)(path, pkgCfg.main, 'index'), parent, job); | ||
const resolved = (await resolveFile((0, path_1.resolve)(path, pkgCfg.main), parent, job)) || | ||
(await resolveFile((0, path_1.resolve)(path, pkgCfg.main, 'index'), parent, job)); | ||
if (resolved) { | ||
@@ -112,3 +123,4 @@ await job.emitFile(path + path_1.sep + 'package.json', 'resolve', parent); | ||
const target = getExportsTarget(item, conditions, cjsResolve); | ||
if (target === null || typeof target === 'string' && target.startsWith('./')) | ||
if (target === null || | ||
(typeof target === 'string' && target.startsWith('./'))) | ||
return target; | ||
@@ -120,4 +132,4 @@ } | ||
if (condition === 'default' || | ||
condition === 'require' && cjsResolve || | ||
condition === 'import' && !cjsResolve || | ||
(condition === 'require' && cjsResolve) || | ||
(condition === 'import' && !cjsResolve) || | ||
conditions.includes(condition)) { | ||
@@ -139,4 +151,8 @@ const target = getExportsTarget(exports[condition], conditions, cjsResolve); | ||
} | ||
else if (typeof obj === 'string' || Array.isArray(obj) || obj === null || | ||
typeof obj === 'object' && Object.keys(obj).length && Object.keys(obj)[0][0] !== '.') { | ||
else if (typeof obj === 'string' || | ||
Array.isArray(obj) || | ||
obj === null || | ||
(typeof obj === 'object' && | ||
Object.keys(obj).length && | ||
Object.keys(obj)[0][0] !== '.')) { | ||
matchObj = { '.': obj }; | ||
@@ -156,3 +172,4 @@ } | ||
if (typeof target === 'string' && target.startsWith('./')) | ||
return pkgPath + target.slice(1).replace(/\*/g, subpath.slice(match.length - 1)); | ||
return (pkgPath + | ||
target.slice(1).replace(/\*/g, subpath.slice(match.length - 1))); | ||
} | ||
@@ -163,3 +180,5 @@ if (!match.endsWith('/')) | ||
const target = getExportsTarget(matchObj[match], job.conditions, cjsResolve); | ||
if (typeof target === 'string' && target.endsWith('/') && target.startsWith('./')) | ||
if (typeof target === 'string' && | ||
target.endsWith('/') && | ||
target.startsWith('./')) | ||
return pkgPath + target.slice(1) + subpath.slice(match.length); | ||
@@ -180,4 +199,6 @@ } | ||
if (cjsResolve) | ||
importsResolved = await resolveFile(importsResolved, parent, job) || await resolveDir(importsResolved, parent, job); | ||
else if (!await job.isFile(importsResolved)) | ||
importsResolved = | ||
(await resolveFile(importsResolved, parent, job)) || | ||
(await resolveDir(importsResolved, parent, job)); | ||
else if (!(await job.isFile(importsResolved))) | ||
throw new NotFoundError(importsResolved, parent); | ||
@@ -208,8 +229,14 @@ if (importsResolved) { | ||
const { exports: pkgExports } = pkgCfg || {}; | ||
if (pkgCfg && pkgCfg.name && pkgCfg.name === pkgName && pkgExports !== null && pkgExports !== undefined) { | ||
if (pkgCfg && | ||
pkgCfg.name && | ||
pkgCfg.name === pkgName && | ||
pkgExports !== null && | ||
pkgExports !== undefined) { | ||
selfResolved = resolveExportsImports(pjsonBoundary, pkgExports, '.' + name.slice(pkgName.length), job, false, cjsResolve); | ||
if (selfResolved) { | ||
if (cjsResolve) | ||
selfResolved = await resolveFile(selfResolved, parent, job) || await resolveDir(selfResolved, parent, job); | ||
else if (!await job.isFile(selfResolved)) | ||
selfResolved = | ||
(await resolveFile(selfResolved, parent, job)) || | ||
(await resolveDir(selfResolved, parent, job)); | ||
else if (!(await job.isFile(selfResolved))) | ||
throw new NotFoundError(selfResolved, parent); | ||
@@ -232,11 +259,18 @@ } | ||
const { exports: pkgExports } = pkgCfg || {}; | ||
if (job.conditions && pkgExports !== undefined && pkgExports !== null && !selfResolved) { | ||
if (job.conditions && | ||
pkgExports !== undefined && | ||
pkgExports !== null && | ||
!selfResolved) { | ||
let legacyResolved; | ||
if (!job.exportsOnly) | ||
legacyResolved = await resolveFile(nodeModulesDir + path_1.sep + name, parent, job) || await resolveDir(nodeModulesDir + path_1.sep + name, parent, job); | ||
legacyResolved = | ||
(await resolveFile(nodeModulesDir + path_1.sep + name, parent, job)) || | ||
(await resolveDir(nodeModulesDir + path_1.sep + name, parent, job)); | ||
let resolved = resolveExportsImports(nodeModulesDir + path_1.sep + pkgName, pkgExports, '.' + name.slice(pkgName.length), job, false, cjsResolve); | ||
if (resolved) { | ||
if (cjsResolve) | ||
resolved = await resolveFile(resolved, parent, job) || await resolveDir(resolved, parent, job); | ||
else if (!await job.isFile(resolved)) | ||
resolved = | ||
(await resolveFile(resolved, parent, job)) || | ||
(await resolveDir(resolved, parent, job)); | ||
else if (!(await job.isFile(resolved))) | ||
throw new NotFoundError(resolved, parent); | ||
@@ -254,3 +288,4 @@ } | ||
else { | ||
const resolved = await resolveFile(nodeModulesDir + path_1.sep + name, parent, job) || await resolveDir(nodeModulesDir + path_1.sep + name, parent, job); | ||
const resolved = (await resolveFile(nodeModulesDir + path_1.sep + name, parent, job)) || | ||
(await resolveDir(nodeModulesDir + path_1.sep + name, parent, job)); | ||
if (resolved) { | ||
@@ -271,3 +306,4 @@ if (selfResolved && selfResolved !== resolved) | ||
const pathTarget = job.paths[path] + name.slice(path.length); | ||
const resolved = await resolveFile(pathTarget, parent, job) || await resolveDir(pathTarget, parent, job); | ||
const resolved = (await resolveFile(pathTarget, parent, job)) || | ||
(await resolveDir(pathTarget, parent, job)); | ||
if (!resolved) { | ||
@@ -274,0 +310,0 @@ throw new NotFoundError(name, parent); |
@@ -38,8 +38,14 @@ "use strict"; | ||
function isVarLoop(node) { | ||
return node.type === 'ForStatement' || node.type === 'ForInStatement' || node.type === 'ForOfStatement'; | ||
return (node.type === 'ForStatement' || | ||
node.type === 'ForInStatement' || | ||
node.type === 'ForOfStatement'); | ||
} | ||
exports.isVarLoop = isVarLoop; | ||
function isLoop(node) { | ||
return node.type === 'ForStatement' || node.type === 'ForInStatement' || node.type === 'ForOfStatement' || node.type === 'WhileStatement' || node.type === 'DoWhileStatement'; | ||
return (node.type === 'ForStatement' || | ||
node.type === 'ForInStatement' || | ||
node.type === 'ForOfStatement' || | ||
node.type === 'WhileStatement' || | ||
node.type === 'DoWhileStatement'); | ||
} | ||
exports.isLoop = isLoop; |
@@ -10,4 +10,4 @@ "use strict"; | ||
// pregyp | ||
const versioning = require("@mapbox/node-pre-gyp/lib/util/versioning.js"); | ||
const napi = require("@mapbox/node-pre-gyp/lib/util/napi.js"); | ||
const versioning = require('@mapbox/node-pre-gyp/lib/util/versioning.js'); | ||
const napi = require('@mapbox/node-pre-gyp/lib/util/napi.js'); | ||
const pregypFind = (package_json_path, opts) => { | ||
@@ -30,21 +30,21 @@ const package_json = JSON.parse(graceful_fs_1.default.readFileSync(package_json_path).toString()); | ||
function makeModulePathList(root, name) { | ||
return ([ | ||
return [ | ||
[root, name], | ||
[root, "build", name], | ||
[root, "build", "Debug", name], | ||
[root, "build", "Release", name], | ||
[root, "out", "Debug", name], | ||
[root, "Debug", name], | ||
[root, "out", "Release", name], | ||
[root, "Release", name], | ||
[root, "build", "default", name], | ||
[root, 'build', name], | ||
[root, 'build', 'Debug', name], | ||
[root, 'build', 'Release', name], | ||
[root, 'out', 'Debug', name], | ||
[root, 'Debug', name], | ||
[root, 'out', 'Release', name], | ||
[root, 'Release', name], | ||
[root, 'build', 'default', name], | ||
[ | ||
root, | ||
process.env["NODE_BINDINGS_COMPILED_DIR"] || "compiled", | ||
process.env['NODE_BINDINGS_COMPILED_DIR'] || 'compiled', | ||
process.versions.node, | ||
process.platform, | ||
process.arch, | ||
name | ||
] | ||
]); | ||
name, | ||
], | ||
]; | ||
} | ||
@@ -58,3 +58,3 @@ function findCompiledModule(basePath, specList) { | ||
try { | ||
spec.path = eval("require.resolve(basePath)"); | ||
spec.path = eval('require.resolve(basePath)'); | ||
return spec; | ||
@@ -73,3 +73,3 @@ } | ||
try { | ||
spec.path = eval("require.resolve(resolvedPath)"); | ||
spec.path = eval('require.resolve(resolvedPath)'); | ||
} | ||
@@ -87,4 +87,4 @@ catch (err) { | ||
const found = findCompiledModule(basePath, [ | ||
{ ext: ".node", name: "nbind.node", type: "node" }, | ||
{ ext: ".js", name: "nbind.js", type: "emcc" } | ||
{ ext: '.node', name: 'nbind.node', type: 'node' }, | ||
{ ext: '.js', name: 'nbind.js', type: 'emcc' }, | ||
]); | ||
@@ -91,0 +91,0 @@ return found; |
@@ -32,2 +32,1 @@ "use strict"; | ||
exports.getPackageName = getPackageName; | ||
; |
@@ -27,6 +27,5 @@ "use strict"; | ||
return; | ||
const files = await new Promise((resolve, reject) => (0, glob_1.default)(pkgPath + sharedlibGlob, { ignore: pkgPath + '/**/node_modules/**/*', dot: true }, (err, files) => err ? reject(err) : resolve(files))); | ||
await Promise.all(files.map(file => job.emitFile(file, 'sharedlib', path))); | ||
const files = await new Promise((resolve, reject) => (0, glob_1.default)(pkgPath + sharedlibGlob, { ignore: pkgPath + '/**/node_modules/**/*', dot: true }, (err, files) => (err ? reject(err) : resolve(files)))); | ||
await Promise.all(files.map((file) => job.emitFile(file, 'sharedlib', path))); | ||
} | ||
exports.sharedLibEmit = sharedLibEmit; | ||
; |
@@ -16,3 +16,9 @@ "use strict"; | ||
}, | ||
'argon2'({ id, emitAssetDirectory }) { | ||
'@serialport/bindings-cpp'({ id, emitAssetDirectory }) { | ||
if (id.endsWith('@serialport/bindings-cpp/dist/index.js')) { | ||
emitAssetDirectory((0, path_1.resolve)((0, path_1.dirname)(id), '..', 'build', 'Release')); | ||
emitAssetDirectory((0, path_1.resolve)((0, path_1.dirname)(id), '..', 'prebuilds')); | ||
} | ||
}, | ||
argon2({ id, emitAssetDirectory }) { | ||
if (id.endsWith('argon2/argon2.js')) { | ||
@@ -24,3 +30,3 @@ emitAssetDirectory((0, path_1.resolve)((0, path_1.dirname)(id), 'build', 'Release')); | ||
}, | ||
'bull'({ id, emitAssetDirectory }) { | ||
bull({ id, emitAssetDirectory }) { | ||
if (id.endsWith('bull/lib/commands/index.js')) { | ||
@@ -30,3 +36,3 @@ emitAssetDirectory((0, path_1.resolve)((0, path_1.dirname)(id))); | ||
}, | ||
'camaro'({ id, emitAsset }) { | ||
camaro({ id, emitAsset }) { | ||
if (id.endsWith('camaro/dist/camaro.js')) { | ||
@@ -36,3 +42,3 @@ emitAsset((0, path_1.resolve)((0, path_1.dirname)(id), 'camaro.wasm')); | ||
}, | ||
'esbuild'({ id, emitAssetDirectory }) { | ||
esbuild({ id, emitAssetDirectory }) { | ||
if (id.endsWith('esbuild/lib/main.js')) { | ||
@@ -61,3 +67,3 @@ const file = (0, path_1.resolve)(id, '..', '..', 'package.json'); | ||
}, | ||
'oracledb'({ id, ast, emitAsset }) { | ||
oracledb({ id, ast, emitAsset }) { | ||
if (id.endsWith('oracledb/lib/oracledb.js')) { | ||
@@ -73,20 +79,43 @@ for (const statement of ast.body) { | ||
statement.body.body[0].block.body[0].type === 'ExpressionStatement' && | ||
statement.body.body[0].block.body[0].expression.type === 'AssignmentExpression' && | ||
statement.body.body[0].block.body[0].expression.type === | ||
'AssignmentExpression' && | ||
statement.body.body[0].block.body[0].expression.operator === '=' && | ||
statement.body.body[0].block.body[0].expression.left.type === 'Identifier' && | ||
statement.body.body[0].block.body[0].expression.left.name === 'oracledbCLib' && | ||
statement.body.body[0].block.body[0].expression.right.type === 'CallExpression' && | ||
statement.body.body[0].block.body[0].expression.right.callee.type === 'Identifier' && | ||
statement.body.body[0].block.body[0].expression.right.callee.name === 'require' && | ||
statement.body.body[0].block.body[0].expression.right.arguments.length === 1 && | ||
statement.body.body[0].block.body[0].expression.right.arguments[0].type === 'MemberExpression' && | ||
statement.body.body[0].block.body[0].expression.right.arguments[0].computed === true && | ||
statement.body.body[0].block.body[0].expression.right.arguments[0].object.type === 'Identifier' && | ||
statement.body.body[0].block.body[0].expression.right.arguments[0].object.name === 'binaryLocations' && | ||
statement.body.body[0].block.body[0].expression.right.arguments[0].property.type === 'Identifier' && | ||
statement.body.body[0].block.body[0].expression.right.arguments[0].property.name === 'i') { | ||
statement.body.body[0].block.body[0].expression.right.arguments = [{ type: 'Literal', value: '_' }]; | ||
const version = global._unit ? '3.0.0' : JSON.parse((0, graceful_fs_1.readFileSync)(id.slice(0, -15) + 'package.json', 'utf8')).version; | ||
statement.body.body[0].block.body[0].expression.left.type === | ||
'Identifier' && | ||
statement.body.body[0].block.body[0].expression.left.name === | ||
'oracledbCLib' && | ||
statement.body.body[0].block.body[0].expression.right.type === | ||
'CallExpression' && | ||
statement.body.body[0].block.body[0].expression.right.callee.type === | ||
'Identifier' && | ||
statement.body.body[0].block.body[0].expression.right.callee.name === | ||
'require' && | ||
statement.body.body[0].block.body[0].expression.right.arguments | ||
.length === 1 && | ||
statement.body.body[0].block.body[0].expression.right.arguments[0] | ||
.type === 'MemberExpression' && | ||
statement.body.body[0].block.body[0].expression.right.arguments[0] | ||
.computed === true && | ||
statement.body.body[0].block.body[0].expression.right.arguments[0] | ||
.object.type === 'Identifier' && | ||
statement.body.body[0].block.body[0].expression.right.arguments[0] | ||
.object.name === 'binaryLocations' && | ||
statement.body.body[0].block.body[0].expression.right.arguments[0] | ||
.property.type === 'Identifier' && | ||
statement.body.body[0].block.body[0].expression.right.arguments[0] | ||
.property.name === 'i') { | ||
statement.body.body[0].block.body[0].expression.right.arguments = [ | ||
{ type: 'Literal', value: '_' }, | ||
]; | ||
const version = global._unit | ||
? '3.0.0' | ||
: JSON.parse((0, graceful_fs_1.readFileSync)(id.slice(0, -15) + 'package.json', 'utf8')).version; | ||
const useVersion = Number(version.slice(0, version.indexOf('.'))) >= 4; | ||
const binaryName = 'oracledb-' + (useVersion ? version : 'abi' + process.versions.modules) + '-' + process.platform + '-' + process.arch + '.node'; | ||
const binaryName = 'oracledb-' + | ||
(useVersion ? version : 'abi' + process.versions.modules) + | ||
'-' + | ||
process.platform + | ||
'-' + | ||
process.arch + | ||
'.node'; | ||
emitAsset((0, path_1.resolve)(id, '../../build/Release/' + binaryName)); | ||
@@ -114,3 +143,3 @@ } | ||
}, | ||
'semver'({ id, emitAsset }) { | ||
semver({ id, emitAsset }) { | ||
if (id.endsWith('semver/index.js')) { | ||
@@ -121,3 +150,3 @@ // See https://github.com/npm/node-semver/blob/master/CHANGELOG.md#710 | ||
}, | ||
'sharp': async ({ id, emitAssetDirectory, job }) => { | ||
sharp: async ({ id, emitAssetDirectory, job }) => { | ||
if (id.endsWith('sharp/lib/index.js')) { | ||
@@ -146,3 +175,3 @@ const file = (0, path_1.resolve)(id, '..', '..', 'package.json'); | ||
}, | ||
'shiki'({ id, emitAssetDirectory }) { | ||
shiki({ id, emitAssetDirectory }) { | ||
if (id.endsWith('/dist/index.js')) { | ||
@@ -164,6 +193,9 @@ emitAssetDirectory((0, path_1.resolve)((0, path_1.dirname)(id), '..', 'languages')); | ||
statement.expression.right.arguments[0].type === 'CallExpression' && | ||
statement.expression.right.arguments[0].callee.type === 'Identifier' && | ||
statement.expression.right.arguments[0].callee.name === 'resolvePath' && | ||
statement.expression.right.arguments[0].callee.type === | ||
'Identifier' && | ||
statement.expression.right.arguments[0].callee.name === | ||
'resolvePath' && | ||
statement.expression.right.arguments[0].arguments.length === 1 && | ||
statement.expression.right.arguments[0].arguments[0].type === 'Literal') { | ||
statement.expression.right.arguments[0].arguments[0].type === | ||
'Literal') { | ||
const arg = statement.expression.right.arguments[0].arguments[0].value; | ||
@@ -194,3 +226,3 @@ let resolved; | ||
type: 'Identifier', | ||
name: '__dirname' | ||
name: '__dirname', | ||
}, | ||
@@ -200,4 +232,4 @@ right: { | ||
value: relResolved, | ||
raw: JSON.stringify(relResolved) | ||
} | ||
raw: JSON.stringify(relResolved), | ||
}, | ||
}; | ||
@@ -221,10 +253,20 @@ } | ||
for (const node of statement.expression.right.body.body) { | ||
if (node.type === 'IfStatement' && node.consequent && 'body' in node.consequent && node.consequent.body) { | ||
if (node.type === 'IfStatement' && | ||
node.consequent && | ||
'body' in node.consequent && | ||
node.consequent.body) { | ||
const ifBody = node.consequent.body; | ||
let replaced = false; | ||
if (Array.isArray(ifBody) && ifBody[0] && ifBody[0].type === 'ExpressionStatement') { | ||
if (Array.isArray(ifBody) && | ||
ifBody[0] && | ||
ifBody[0].type === 'ExpressionStatement') { | ||
replaced = await replaceResolvePathStatement(ifBody[0]); | ||
} | ||
if (Array.isArray(ifBody) && ifBody[1] && ifBody[1].type === 'TryStatement' && ifBody[1].block.body && ifBody[1].block.body[0]) { | ||
replaced = await replaceResolvePathStatement(ifBody[1].block.body[0]) || replaced; | ||
if (Array.isArray(ifBody) && | ||
ifBody[1] && | ||
ifBody[1].type === 'TryStatement' && | ||
ifBody[1].block.body && | ||
ifBody[1].block.body[0]) { | ||
replaced = | ||
(await replaceResolvePathStatement(ifBody[1].block.body[0])) || replaced; | ||
} | ||
@@ -238,3 +280,3 @@ return; | ||
}, | ||
'typescript'({ id, emitAssetDirectory }) { | ||
typescript({ id, emitAssetDirectory }) { | ||
if (id.endsWith('typescript/lib/tsc.js')) { | ||
@@ -276,9 +318,9 @@ emitAssetDirectory((0, path_1.resolve)(id, '../')); | ||
}, | ||
'pixelmatch'({ id, emitDependency }) { | ||
pixelmatch({ id, emitDependency }) { | ||
if (id.endsWith('pixelmatch/index.js')) { | ||
emitDependency((0, path_1.resolve)((0, path_1.dirname)(id), 'bin/pixelmatch')); | ||
} | ||
} | ||
}, | ||
}; | ||
async function handleSpecialCases({ id, ast, emitDependency, emitAsset, emitAssetDirectory, job }) { | ||
async function handleSpecialCases({ id, ast, emitDependency, emitAsset, emitAssetDirectory, job, }) { | ||
const pkgName = (0, get_package_base_1.getPackageName)(id); | ||
@@ -288,5 +330,11 @@ const specialCase = specialCases[pkgName || '']; | ||
if (specialCase) | ||
await specialCase({ id, ast, emitDependency, emitAsset, emitAssetDirectory, job }); | ||
await specialCase({ | ||
id, | ||
ast, | ||
emitDependency, | ||
emitAsset, | ||
emitAssetDirectory, | ||
job, | ||
}); | ||
} | ||
exports.default = handleSpecialCases; | ||
; |
@@ -8,3 +8,3 @@ "use strict"; | ||
computeBranches, | ||
vars | ||
vars, | ||
}; | ||
@@ -25,3 +25,2 @@ return walk(ast); | ||
exports.evaluate = evaluate; | ||
; | ||
exports.UNKNOWN = Symbol(); | ||
@@ -39,3 +38,3 @@ exports.FUNCTION = Symbol(); | ||
const visitors = { | ||
'ArrayExpression': async function ArrayExpression(node, walk) { | ||
ArrayExpression: async function ArrayExpression(node, walk) { | ||
const arr = []; | ||
@@ -56,5 +55,8 @@ for (let i = 0, l = node.elements.length; i < l; i++) { | ||
}, | ||
'ArrowFunctionExpression': async function (node, walk) { | ||
ArrowFunctionExpression: async function (node, walk) { | ||
// () => val support only | ||
if (node.params.length === 0 && !node.generator && !node.async && node.expression) { | ||
if (node.params.length === 0 && | ||
!node.generator && | ||
!node.async && | ||
node.expression) { | ||
const innerValue = await walk(node.body); | ||
@@ -65,4 +67,4 @@ if (!innerValue || !('value' in innerValue)) | ||
value: { | ||
[exports.FUNCTION]: () => innerValue.value | ||
} | ||
[exports.FUNCTION]: () => innerValue.value, | ||
}, | ||
}; | ||
@@ -72,3 +74,3 @@ } | ||
}, | ||
'BinaryExpression': async function BinaryExpression(node, walk) { | ||
BinaryExpression: async function BinaryExpression(node, walk) { | ||
const op = node.operator; | ||
@@ -83,4 +85,10 @@ let l = await walk(node.left); | ||
// UNKNOWN + 'str' -> wildcard string value | ||
if (this.computeBranches && r && 'value' in r && typeof r.value === 'string') | ||
return { value: exports.WILDCARD + r.value, wildcards: [node.left, ...r.wildcards || []] }; | ||
if (this.computeBranches && | ||
r && | ||
'value' in r && | ||
typeof r.value === 'string') | ||
return { | ||
value: exports.WILDCARD + r.value, | ||
wildcards: [node.left, ...(r.wildcards || [])], | ||
}; | ||
return; | ||
@@ -92,3 +100,6 @@ } | ||
if (l && 'value' in l && typeof l.value === 'string') | ||
return { value: l.value + exports.WILDCARD, wildcards: [...l.wildcards || [], node.right] }; | ||
return { | ||
value: l.value + exports.WILDCARD, | ||
wildcards: [...(l.wildcards || []), node.right], | ||
}; | ||
} | ||
@@ -230,3 +241,3 @@ // A || UNKNOWN -> A if A is truthy | ||
}, | ||
'CallExpression': async function CallExpression(node, walk) { | ||
CallExpression: async function CallExpression(node, walk) { | ||
const callee = await walk(node.callee); | ||
@@ -256,3 +267,3 @@ if (!callee || 'test' in callee) | ||
if ('value' in x && typeof x.value === 'string' && x.wildcards) | ||
x.wildcards.forEach(w => wildcards.push(w)); | ||
x.wildcards.forEach((w) => wildcards.push(w)); | ||
} | ||
@@ -291,3 +302,4 @@ else { | ||
if (wildcards.length) { | ||
if (typeof result !== 'string' || countWildcards(result) !== wildcards.length) | ||
if (typeof result !== 'string' || | ||
countWildcards(result) !== wildcards.length) | ||
return; | ||
@@ -307,3 +319,3 @@ return { value: result, wildcards }; | ||
}, | ||
'ConditionalExpression': async function ConditionalExpression(node, walk) { | ||
ConditionalExpression: async function ConditionalExpression(node, walk) { | ||
const val = await walk(node.test); | ||
@@ -323,9 +335,9 @@ if (val && 'value' in val) | ||
then: thenValue.value, | ||
else: elseValue.value | ||
else: elseValue.value, | ||
}; | ||
}, | ||
'ExpressionStatement': async function ExpressionStatement(node, walk) { | ||
ExpressionStatement: async function ExpressionStatement(node, walk) { | ||
return walk(node.expression); | ||
}, | ||
'Identifier': async function Identifier(node, _walk) { | ||
Identifier: async function Identifier(node, _walk) { | ||
if (Object.hasOwnProperty.call(this.vars, node.name)) | ||
@@ -335,6 +347,6 @@ return this.vars[node.name]; | ||
}, | ||
'Literal': async function Literal(node, _walk) { | ||
Literal: async function Literal(node, _walk) { | ||
return { value: node.value }; | ||
}, | ||
'MemberExpression': async function MemberExpression(node, walk) { | ||
MemberExpression: async function MemberExpression(node, walk) { | ||
const obj = await walk(node.object); | ||
@@ -348,4 +360,4 @@ if (!obj || 'test' in obj || typeof obj.value === 'function') { | ||
value: { | ||
[exports.FUNCTION]: (...args) => obj.value.concat(args) | ||
} | ||
[exports.FUNCTION]: (...args) => obj.value.concat(args), | ||
}, | ||
}; | ||
@@ -404,3 +416,3 @@ } | ||
}, | ||
'MetaProperty': async function MetaProperty(node) { | ||
MetaProperty: async function MetaProperty(node) { | ||
if (node.meta.name === 'import' && node.property.name === 'meta') | ||
@@ -410,3 +422,3 @@ return { value: this.vars['import.meta'] }; | ||
}, | ||
'NewExpression': async function NewExpression(node, walk) { | ||
NewExpression: async function NewExpression(node, walk) { | ||
// new URL('./local', parent) | ||
@@ -447,3 +459,3 @@ const cls = await walk(node.callee); | ||
then: new url_1.URL(arg.then, parent.value), | ||
else: new url_1.URL(arg.else, parent.value) | ||
else: new url_1.URL(arg.else, parent.value), | ||
}; | ||
@@ -459,3 +471,3 @@ } | ||
then: new url_1.URL(arg.then), | ||
else: new url_1.URL(arg.else) | ||
else: new url_1.URL(arg.else), | ||
}; | ||
@@ -470,7 +482,9 @@ } | ||
}, | ||
'ObjectExpression': async function ObjectExpression(node, walk) { | ||
ObjectExpression: async function ObjectExpression(node, walk) { | ||
const obj = {}; | ||
for (let i = 0; i < node.properties.length; i++) { | ||
const prop = node.properties[i]; | ||
const keyValue = prop.computed ? walk(prop.key) : prop.key && { value: prop.key.name || prop.key.value }; | ||
const keyValue = prop.computed | ||
? walk(prop.key) | ||
: prop.key && { value: prop.key.name || prop.key.value }; | ||
if (!keyValue || 'test' in keyValue) | ||
@@ -489,4 +503,8 @@ return; | ||
}, | ||
'SequenceExpression': async function SequenceExpression(node, walk) { | ||
if ('expressions' in node && node.expressions.length === 2 && node.expressions[0].type === 'Literal' && node.expressions[0].value === 0 && node.expressions[1].type === 'MemberExpression') { | ||
SequenceExpression: async function SequenceExpression(node, walk) { | ||
if ('expressions' in node && | ||
node.expressions.length === 2 && | ||
node.expressions[0].type === 'Literal' && | ||
node.expressions[0].value === 0 && | ||
node.expressions[1].type === 'MemberExpression') { | ||
const arg = await walk(node.expressions[1]); | ||
@@ -497,3 +515,3 @@ return arg; | ||
}, | ||
'TemplateLiteral': async function TemplateLiteral(node, walk) { | ||
TemplateLiteral: async function TemplateLiteral(node, walk) { | ||
let val = { value: '' }; | ||
@@ -518,3 +536,3 @@ for (var i = 0; i < node.expressions.length; i++) { | ||
if (exprValue.wildcards) | ||
val.wildcards = [...val.wildcards || [], ...exprValue.wildcards]; | ||
val.wildcards = [...(val.wildcards || []), ...exprValue.wildcards]; | ||
} | ||
@@ -536,3 +554,3 @@ else { | ||
then: val.value + exprValue.then, | ||
else: val.value + exprValue.else | ||
else: val.value + exprValue.else, | ||
}; | ||
@@ -554,3 +572,3 @@ } | ||
}, | ||
'ThisExpression': async function ThisExpression(_node, _walk) { | ||
ThisExpression: async function ThisExpression(_node, _walk) { | ||
if (Object.hasOwnProperty.call(this.vars, 'this')) | ||
@@ -560,3 +578,3 @@ return this.vars['this']; | ||
}, | ||
'UnaryExpression': async function UnaryExpression(node, walk) { | ||
UnaryExpression: async function UnaryExpression(node, walk) { | ||
const val = await walk(node.argument); | ||
@@ -586,4 +604,4 @@ if (!val) | ||
return undefined; | ||
} | ||
}, | ||
}; | ||
visitors.LogicalExpression = visitors.BinaryExpression; |
@@ -6,3 +6,7 @@ "use strict"; | ||
function isUndefinedOrVoid(node) { | ||
return node.type === 'Identifier' && node.name === 'undefined' || node.type === 'UnaryExpression' && node.operator === 'void' && node.argument.type === 'Literal' && node.argument.value === 0; | ||
return ((node.type === 'Identifier' && node.name === 'undefined') || | ||
(node.type === 'UnaryExpression' && | ||
node.operator === 'void' && | ||
node.argument.type === 'Literal' && | ||
node.argument.value === 0)); | ||
} | ||
@@ -25,3 +29,4 @@ // Wrapper detection pretransforms to enable static analysis | ||
ast.body[0].expression.callee.type === 'FunctionExpression' && | ||
(ast.body[0].expression.arguments.length === 1 || ast.body[0].expression.arguments.length === 0)) | ||
(ast.body[0].expression.arguments.length === 1 || | ||
ast.body[0].expression.arguments.length === 0)) | ||
wrapper = ast.body[0].expression; | ||
@@ -49,3 +54,4 @@ else if (ast.body.length === 1 && | ||
// (typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }) | ||
if (wrapper.arguments[0] && wrapper.arguments[0].type === 'ConditionalExpression' && | ||
if (wrapper.arguments[0] && | ||
wrapper.arguments[0].type === 'ConditionalExpression' && | ||
wrapper.arguments[0].test.type === 'LogicalExpression' && | ||
@@ -70,19 +76,33 @@ wrapper.arguments[0].test.operator === '&&' && | ||
wrapper.arguments[0].alternate.body.body.length === 1 && | ||
wrapper.arguments[0].alternate.body.body[0].type === 'ExpressionStatement' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.type === 'AssignmentExpression' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.left.type === 'MemberExpression' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.left.object.type === 'Identifier' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.left.object.name === 'module' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.left.property.type === 'Identifier' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.left.property.name === 'exports' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.left.computed === false && | ||
wrapper.arguments[0].alternate.body.body[0].expression.right.type === 'CallExpression' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.right.callee.type === 'Identifier' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.right.callee.name === wrapper.arguments[0].alternate.params[0].name && | ||
wrapper.arguments[0].alternate.body.body[0].type === | ||
'ExpressionStatement' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.type === | ||
'AssignmentExpression' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.left.type === | ||
'MemberExpression' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.left.object | ||
.type === 'Identifier' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.left.object | ||
.name === 'module' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.left.property | ||
.type === 'Identifier' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.left.property | ||
.name === 'exports' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.left.computed === | ||
false && | ||
wrapper.arguments[0].alternate.body.body[0].expression.right.type === | ||
'CallExpression' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.right.callee | ||
.type === 'Identifier' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.right.callee | ||
.name === wrapper.arguments[0].alternate.params[0].name && | ||
'body' in wrapper.callee && | ||
'body' in wrapper.callee.body && | ||
Array.isArray(wrapper.callee.body.body) && | ||
wrapper.arguments[0].alternate.body.body[0].expression.right.arguments.length === 1 && | ||
wrapper.arguments[0].alternate.body.body[0].expression.right.arguments[0].type === 'Identifier' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.right.arguments[0].name === 'require') { | ||
wrapper.arguments[0].alternate.body.body[0].expression.right.arguments | ||
.length === 1 && | ||
wrapper.arguments[0].alternate.body.body[0].expression.right.arguments[0] | ||
.type === 'Identifier' && | ||
wrapper.arguments[0].alternate.body.body[0].expression.right.arguments[0] | ||
.name === 'require') { | ||
let body = wrapper.callee.body.body; | ||
@@ -98,3 +118,4 @@ if (body[0].type === 'ExpressionStatement' && | ||
body[0].expression.callee.type === 'Identifier' && | ||
body[0].expression.callee.name === wrapper.arguments[0].test.right.object.name && | ||
body[0].expression.callee.name === | ||
wrapper.arguments[0].test.right.object.name && | ||
body[0].expression.arguments.length === 1 && | ||
@@ -108,3 +129,3 @@ body[0].expression.arguments[0].type === 'FunctionExpression' && | ||
try { | ||
// @ts-ignore If it doesn't exist thats ok | ||
// @ts-ignore If it doesn't exist that's ok | ||
delete arg.scope.declarations.require; | ||
@@ -131,23 +152,28 @@ } | ||
// }); | ||
else if (wrapper.arguments[0] && wrapper.arguments[0].type === 'FunctionExpression' && | ||
else if (wrapper.arguments[0] && | ||
wrapper.arguments[0].type === 'FunctionExpression' && | ||
wrapper.arguments[0].params.length === 0 && | ||
(wrapper.arguments[0].body.body.length === 1 || | ||
wrapper.arguments[0].body.body.length === 2 && | ||
(wrapper.arguments[0].body.body.length === 2 && | ||
wrapper.arguments[0].body.body[0].type === 'VariableDeclaration' && | ||
wrapper.arguments[0].body.body[0].declarations.length === 3 && | ||
wrapper.arguments[0].body.body[0].declarations.every(decl => decl.init === null && decl.id.type === 'Identifier')) && | ||
wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1].type === 'ReturnStatement' && | ||
wrapper.arguments[0].body.body[0].declarations.every((decl) => decl.init === null && decl.id.type === 'Identifier'))) && | ||
wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1] | ||
.type === 'ReturnStatement' && | ||
(browserifyReturn = wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1]) && | ||
browserifyReturn.argument?.type === 'CallExpression' && | ||
browserifyReturn.argument.arguments.length && | ||
browserifyReturn.argument.arguments.every(arg => arg && arg.type === 'Literal' && typeof arg.value === 'number') && | ||
browserifyReturn.argument.arguments.every((arg) => arg && arg.type === 'Literal' && typeof arg.value === 'number') && | ||
browserifyReturn.argument.callee.type === 'CallExpression' && | ||
(browserifyReturn.argument.callee.callee.type === 'FunctionExpression' || | ||
browserifyReturn.argument.callee.callee.type === 'CallExpression' && | ||
browserifyReturn.argument.callee.callee.callee.type === 'FunctionExpression' && | ||
browserifyReturn.argument.callee.callee.arguments.length === 0) && | ||
(browserifyReturn.argument.callee.callee.type === 'CallExpression' && | ||
browserifyReturn.argument.callee.callee.callee.type === | ||
'FunctionExpression' && | ||
browserifyReturn.argument.callee.callee.arguments.length === 0)) && | ||
// (dont go deeper into browserify loader internals than this) | ||
browserifyReturn.argument.callee.arguments.length === 3 && | ||
browserifyReturn.argument.callee.arguments[0].type === 'ObjectExpression' && | ||
browserifyReturn.argument.callee.arguments[1].type === 'ObjectExpression' && | ||
browserifyReturn.argument.callee.arguments[0].type === | ||
'ObjectExpression' && | ||
browserifyReturn.argument.callee.arguments[1].type === | ||
'ObjectExpression' && | ||
browserifyReturn.argument.callee.arguments[2].type === 'ArrayExpression') { | ||
@@ -158,3 +184,3 @@ const modules = browserifyReturn.argument.callee.arguments[0].properties; | ||
const externals = {}; | ||
if (modules.every(m => { | ||
if (modules.every((m) => { | ||
if (m.type !== 'Property' || | ||
@@ -176,4 +202,7 @@ m.computed !== false || | ||
if (prop.type !== 'Property' || | ||
(prop.value.type !== 'Identifier' && prop.value.type !== 'Literal' && !isUndefinedOrVoid(prop.value)) || | ||
!(prop.key.type === 'Literal' && typeof prop.key.value === 'string' || | ||
(prop.value.type !== 'Identifier' && | ||
prop.value.type !== 'Literal' && | ||
!isUndefinedOrVoid(prop.value)) || | ||
!((prop.key.type === 'Literal' && | ||
typeof prop.key.value === 'string') || | ||
prop.key.type === 'Identifier') || | ||
@@ -192,3 +221,3 @@ prop.computed) { | ||
value: prop.key.name, | ||
raw: JSON.stringify(prop.key.name) | ||
raw: JSON.stringify(prop.key.name), | ||
}; | ||
@@ -206,3 +235,3 @@ } | ||
const cache = browserifyReturn.argument.callee.arguments[1]; | ||
cache.properties = externalIds.map(ext => { | ||
cache.properties = externalIds.map((ext) => { | ||
return { | ||
@@ -217,3 +246,4 @@ type: 'Property', | ||
type: 'ObjectExpression', | ||
properties: [{ | ||
properties: [ | ||
{ | ||
type: 'Property', | ||
@@ -226,3 +256,3 @@ kind: 'init', | ||
type: 'Identifier', | ||
name: 'exports' | ||
name: 'exports', | ||
}, | ||
@@ -234,8 +264,9 @@ value: { | ||
type: 'Identifier', | ||
name: 'require' | ||
name: 'require', | ||
}, | ||
arguments: [externals[ext]] | ||
} | ||
}] | ||
} | ||
arguments: [externals[ext]], | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
@@ -269,3 +300,4 @@ }); | ||
// } | ||
else if (wrapper.arguments[0] && wrapper.arguments[0].type === 'FunctionExpression' && | ||
else if (wrapper.arguments[0] && | ||
wrapper.arguments[0].type === 'FunctionExpression' && | ||
wrapper.arguments[0].params.length === 2 && | ||
@@ -304,3 +336,4 @@ wrapper.arguments[0].params[0].type === 'Identifier' && | ||
statement.consequent.body[0].declarations[0].init && | ||
statement.consequent.body[0].declarations[0].init.type === 'CallExpression') | ||
statement.consequent.body[0].declarations[0].init.type === | ||
'CallExpression') | ||
callSite = statement.consequent.body[0].declarations[0].init; | ||
@@ -311,5 +344,7 @@ else if (statement.consequent.body[0].type === 'ExpressionStatement' && | ||
else if (statement.consequent.body[0].type === 'ExpressionStatement' && | ||
statement.consequent.body[0].expression.type === 'AssignmentExpression' && | ||
statement.consequent.body[0].expression.type === | ||
'AssignmentExpression' && | ||
statement.consequent.body[0].expression.operator === '=' && | ||
statement.consequent.body[0].expression.right.type === 'CallExpression') | ||
statement.consequent.body[0].expression.right.type === | ||
'CallExpression') | ||
callSite = statement.consequent.body[0].expression.right; | ||
@@ -330,3 +365,3 @@ if (callSite && | ||
try { | ||
// @ts-ignore If scope doesn't exist thats ok | ||
// @ts-ignore If scope doesn't exist that's ok | ||
const scope = funcExpression.scope; | ||
@@ -341,3 +376,3 @@ delete scope.declarations.require; | ||
// Webpack wrapper | ||
// | ||
// | ||
// module.exports = (function(e) { | ||
@@ -373,3 +408,3 @@ // var t = {}; | ||
// OR Webpack 5 non-runtime variant: | ||
// | ||
// | ||
// (function() { | ||
@@ -384,29 +419,45 @@ // var exports = {}; | ||
// | ||
else if (wrapper.callee.type === 'FunctionExpression' && | ||
else if ((wrapper.callee.type === 'FunctionExpression' && | ||
wrapper.callee.body.body.length > 2 && | ||
wrapper.callee.body.body[0].type === 'VariableDeclaration' && | ||
wrapper.callee.body.body[0].declarations.length === 1 && | ||
wrapper.callee.body.body[0].declarations[0].type === 'VariableDeclarator' && | ||
wrapper.callee.body.body[0].declarations[0].type === | ||
'VariableDeclarator' && | ||
wrapper.callee.body.body[0].declarations[0].id.type === 'Identifier' && | ||
wrapper.callee.body.body[0].declarations[0].init && (wrapper.callee.body.body[0].declarations[0].init.type === 'ObjectExpression' && | ||
wrapper.callee.body.body[0].declarations[0].init.properties.length === 0 || | ||
wrapper.callee.body.body[0].declarations[0].init.type === 'CallExpression' && | ||
wrapper.callee.body.body[0].declarations[0].init.arguments.length === 1) && | ||
(wrapper.callee.body.body[1] && | ||
wrapper.callee.body.body[0].declarations[0].init && | ||
((wrapper.callee.body.body[0].declarations[0].init.type === | ||
'ObjectExpression' && | ||
wrapper.callee.body.body[0].declarations[0].init.properties.length === | ||
0) || | ||
(wrapper.callee.body.body[0].declarations[0].init.type === | ||
'CallExpression' && | ||
wrapper.callee.body.body[0].declarations[0].init.arguments | ||
.length === 1)) && | ||
((wrapper.callee.body.body[1] && | ||
wrapper.callee.body.body[1].type === 'FunctionDeclaration' && | ||
wrapper.callee.body.body[1].params.length === 1 && | ||
wrapper.callee.body.body[1].body.body.length >= 3 || | ||
wrapper.callee.body.body[2] && | ||
wrapper.callee.body.body[1].body.body.length >= 3) || | ||
(wrapper.callee.body.body[2] && | ||
wrapper.callee.body.body[2].type === 'FunctionDeclaration' && | ||
wrapper.callee.body.body[2].params.length === 1 && | ||
wrapper.callee.body.body[2].body.body.length >= 3) && (wrapper.arguments[0] && (wrapper.arguments[0].type === 'ArrayExpression' && | ||
(webpackModuleObj = wrapper.arguments[0]) && | ||
wrapper.arguments[0].elements.length > 0 && | ||
wrapper.arguments[0].elements.every(el => el && el.type === 'FunctionExpression') || | ||
wrapper.arguments[0].type === 'ObjectExpression' && | ||
wrapper.callee.body.body[2].body.body.length >= 3)) && | ||
wrapper.arguments[0] && | ||
((wrapper.arguments[0].type === 'ArrayExpression' && | ||
(webpackModuleObj = wrapper.arguments[0]) && | ||
wrapper.arguments[0].properties && | ||
wrapper.arguments[0].properties.length > 0 && | ||
wrapper.arguments[0].properties.every(prop => prop && prop.type === 'Property' && !prop.computed && prop.key && prop.key.type === 'Literal' && (typeof prop.key.value === 'string' || typeof prop.key.value === 'number') && prop.value && prop.value.type === 'FunctionExpression'))) || | ||
wrapper.arguments.length === 0 && | ||
wrapper.arguments[0].elements.length > 0 && | ||
wrapper.arguments[0].elements.every((el) => el && el.type === 'FunctionExpression')) || | ||
(wrapper.arguments[0].type === 'ObjectExpression' && | ||
(webpackModuleObj = wrapper.arguments[0]) && | ||
wrapper.arguments[0].properties && | ||
wrapper.arguments[0].properties.length > 0 && | ||
wrapper.arguments[0].properties.every((prop) => prop && | ||
prop.type === 'Property' && | ||
!prop.computed && | ||
prop.key && | ||
prop.key.type === 'Literal' && | ||
(typeof prop.key.value === 'string' || | ||
typeof prop.key.value === 'number') && | ||
prop.value && | ||
prop.value.type === 'FunctionExpression')))) || | ||
(wrapper.arguments.length === 0 && | ||
wrapper.callee.type === 'FunctionExpression' && | ||
@@ -420,41 +471,71 @@ wrapper.callee.params.length === 0 && | ||
wrapper.callee.body.body[1].type === 'ExpressionStatement' && | ||
wrapper.callee.body.body[1].expression.type === 'AssignmentExpression' && | ||
wrapper.callee.body.body[1].expression.type === | ||
'AssignmentExpression' && | ||
wrapper.callee.body.body[2].type === 'ExpressionStatement' && | ||
wrapper.callee.body.body[2].expression.type === 'AssignmentExpression' && | ||
wrapper.callee.body.body[2].expression.type === | ||
'AssignmentExpression' && | ||
wrapper.callee.body.body[3].type === 'ExpressionStatement' && | ||
wrapper.callee.body.body[3].expression.type === 'AssignmentExpression' && | ||
wrapper.callee.body.body[3].expression.left.type === 'MemberExpression' && | ||
wrapper.callee.body.body[3].expression.left.object.type === 'Identifier' && | ||
wrapper.callee.body.body[3].expression.left.object.name === wrapper.callee.body.body[0].declarations[0].id.name && | ||
wrapper.callee.body.body[3].expression.left.property.type === 'Identifier' && | ||
wrapper.callee.body.body[3].expression.left.property.name === 'modules' && | ||
wrapper.callee.body.body[3].expression.right.type === 'ObjectExpression' && | ||
wrapper.callee.body.body[3].expression.right.properties.every(prop => prop && prop.type === 'Property' && !prop.computed && prop.key && prop.key.type === 'Literal' && (typeof prop.key.value === 'string' || typeof prop.key.value === 'number') && prop.value && prop.value.type === 'FunctionExpression') && | ||
wrapper.callee.body.body[3].expression.type === | ||
'AssignmentExpression' && | ||
wrapper.callee.body.body[3].expression.left.type === | ||
'MemberExpression' && | ||
wrapper.callee.body.body[3].expression.left.object.type === | ||
'Identifier' && | ||
wrapper.callee.body.body[3].expression.left.object.name === | ||
wrapper.callee.body.body[0].declarations[0].id.name && | ||
wrapper.callee.body.body[3].expression.left.property.type === | ||
'Identifier' && | ||
wrapper.callee.body.body[3].expression.left.property.name === | ||
'modules' && | ||
wrapper.callee.body.body[3].expression.right.type === | ||
'ObjectExpression' && | ||
wrapper.callee.body.body[3].expression.right.properties.every((prop) => prop && | ||
prop.type === 'Property' && | ||
!prop.computed && | ||
prop.key && | ||
prop.key.type === 'Literal' && | ||
(typeof prop.key.value === 'string' || | ||
typeof prop.key.value === 'number') && | ||
prop.value && | ||
prop.value.type === 'FunctionExpression') && | ||
(webpackModuleObj = wrapper.callee.body.body[3].expression.right) && | ||
(wrapper.callee.body.body[4].type === 'VariableDeclaration' && | ||
((wrapper.callee.body.body[4].type === 'VariableDeclaration' && | ||
wrapper.callee.body.body[4].declarations.length === 1 && | ||
wrapper.callee.body.body[4].declarations[0].init && | ||
wrapper.callee.body.body[4].declarations[0].init.type === 'CallExpression' && | ||
wrapper.callee.body.body[4].declarations[0].init.callee.type === 'Identifier' && | ||
wrapper.callee.body.body[4].declarations[0].init.callee.name === 'require' || | ||
wrapper.callee.body.body[5].type === 'VariableDeclaration' && | ||
wrapper.callee.body.body[4].declarations[0].init.type === | ||
'CallExpression' && | ||
wrapper.callee.body.body[4].declarations[0].init.callee.type === | ||
'Identifier' && | ||
wrapper.callee.body.body[4].declarations[0].init.callee.name === | ||
'require') || | ||
(wrapper.callee.body.body[5].type === 'VariableDeclaration' && | ||
wrapper.callee.body.body[5].declarations.length === 1 && | ||
wrapper.callee.body.body[5].declarations[0].init && | ||
wrapper.callee.body.body[5].declarations[0].init.type === 'CallExpression' && | ||
wrapper.callee.body.body[5].declarations[0].init.callee.type === 'Identifier' && | ||
wrapper.callee.body.body[5].declarations[0].init.callee.name === 'require')) { | ||
wrapper.callee.body.body[5].declarations[0].init.type === | ||
'CallExpression' && | ||
wrapper.callee.body.body[5].declarations[0].init.callee.type === | ||
'Identifier' && | ||
wrapper.callee.body.body[5].declarations[0].init.callee.name === | ||
'require')))) { | ||
const externalMap = new Map(); | ||
let modules; | ||
if (webpackModuleObj.type === 'ArrayExpression') | ||
modules = webpackModuleObj.elements.filter(el => el?.type === 'FunctionExpression').map((el, i) => [String(i), el]); | ||
modules = webpackModuleObj.elements.filter((el) => el?.type === 'FunctionExpression').map((el, i) => [String(i), el]); | ||
// Structure already checked in conditional above | ||
else | ||
modules = webpackModuleObj.properties.map(prop => [String(prop.key.value), prop.value]); | ||
modules = webpackModuleObj.properties.map((prop) => [ | ||
String(prop.key.value), | ||
prop.value, | ||
]); | ||
for (const [k, m] of modules) { | ||
const statement = m.body.body.length === 1 ? m.body.body[0] : | ||
(m.body.body.length === 2 || m.body.body.length === 3 && m.body.body[2].type === 'EmptyStatement') && | ||
const statement = m.body.body.length === 1 | ||
? m.body.body[0] | ||
: (m.body.body.length === 2 || | ||
(m.body.body.length === 3 && | ||
m.body.body[2].type === 'EmptyStatement')) && | ||
m.body.body[0].type === 'ExpressionStatement' && | ||
m.body.body[0].expression.type === 'Literal' && | ||
m.body.body[0].expression.value === 'use strict' | ||
? m.body.body[1] : null; | ||
? m.body.body[1] | ||
: null; | ||
if (statement && | ||
@@ -481,3 +562,5 @@ statement.type === 'ExpressionStatement' && | ||
for (const [, m] of modules) { | ||
if ('params' in m && m.params.length === 3 && m.params[2].type === 'Identifier') { | ||
if ('params' in m && | ||
m.params.length === 3 && | ||
m.params[2].type === 'Identifier') { | ||
const assignedVars = new Map(); | ||
@@ -501,8 +584,10 @@ (0, estree_walker_1.walk)(m.body, { | ||
type: 'Identifier', | ||
name: 'require' | ||
name: 'require', | ||
}, | ||
arguments: [{ | ||
arguments: [ | ||
{ | ||
type: 'Literal', | ||
value: externalId | ||
}] | ||
value: externalId, | ||
}, | ||
], | ||
}; | ||
@@ -522,7 +607,9 @@ const parent = maybeParent; | ||
} | ||
else if ('arguments' in parent && parent.arguments.some(arg => arg === node)) { | ||
parent.arguments = parent.arguments.map(arg => arg === node ? replacement : arg); | ||
else if ('arguments' in parent && | ||
parent.arguments.some((arg) => arg === node)) { | ||
parent.arguments = parent.arguments.map((arg) => arg === node ? replacement : arg); | ||
} | ||
else if ('init' in parent && parent.init === node) { | ||
if (parent.type === 'VariableDeclarator' && parent.id.type === 'Identifier') | ||
if (parent.type === 'VariableDeclarator' && | ||
parent.id.type === 'Identifier') | ||
assignedVars.set(parent.id.name, externalId); | ||
@@ -542,3 +629,5 @@ parent.init = replacement; | ||
node.arguments[0].type === 'Identifier') { | ||
if (maybeParent && 'init' in maybeParent && maybeParent.init === node) { | ||
if (maybeParent && | ||
'init' in maybeParent && | ||
maybeParent.init === node) { | ||
const req = node.arguments[0]; | ||
@@ -554,8 +643,8 @@ const callExpression = { | ||
type: 'Identifier', | ||
name: 'Object' | ||
name: 'Object', | ||
}, | ||
property: { | ||
type: 'Identifier', | ||
name: 'assign' | ||
} | ||
name: 'assign', | ||
}, | ||
}, | ||
@@ -567,7 +656,8 @@ arguments: [ | ||
params: [], | ||
body: req | ||
body: req, | ||
}, | ||
{ | ||
type: 'ObjectExpression', | ||
properties: [{ | ||
properties: [ | ||
{ | ||
type: 'Property', | ||
@@ -580,8 +670,9 @@ kind: 'init', | ||
type: 'Identifier', | ||
name: 'a' | ||
name: 'a', | ||
}, | ||
value: req | ||
}] | ||
} | ||
] | ||
value: req, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
@@ -591,3 +682,3 @@ maybeParent.init = callExpression; | ||
} | ||
} | ||
}, | ||
}); | ||
@@ -594,0 +685,0 @@ } |
{ | ||
"name": "@vercel/nft", | ||
"version": "0.26.4", | ||
"version": "0.26.5", | ||
"repository": "vercel/nft", | ||
@@ -11,11 +11,15 @@ "license": "MIT", | ||
}, | ||
"files": [ | ||
"out" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"git-pre-commit": "prettier --write . && git add -A", | ||
"prepublishOnly": "tsc && rm out/utils/*.d.ts && rm out/tsconfig.tsbuildinfo", | ||
"prettier-check": "prettier --check .", | ||
"prettier-fix": "prettier --write .", | ||
"test": "jest --verbose", | ||
"test-verbose": "tsc --sourceMap && jest --verbose --coverage --globals \"{\\\"coverage\\\":true}\"" | ||
}, | ||
"files": [ | ||
"out" | ||
], | ||
"prettier": "@vercel/style-guide/prettier", | ||
"dependencies": { | ||
@@ -40,3 +44,3 @@ "@mapbox/node-pre-gyp": "^1.0.5", | ||
"@google-cloud/bigquery": "^4.1.4", | ||
"@google-cloud/firestore": "^6.2.0", | ||
"@google-cloud/firestore": "^7.6.0", | ||
"@sentry/node": "^5.5.0", | ||
@@ -50,2 +54,4 @@ "@tpluscode/sparql-builder": "^0.3.12", | ||
"@types/node": "^14.14.37", | ||
"@vercel/git-hooks": "^1.0.0", | ||
"@vercel/style-guide": "^5.2.0", | ||
"analytics-node": "^3.4.0-beta.1", | ||
@@ -69,7 +75,7 @@ "apollo-server-express": "^2.14.2", | ||
"esm": "^3.2.25", | ||
"express": "^4.17.3", | ||
"express": "^4.19.2", | ||
"fast-glob": "^3.1.1", | ||
"fetch-h2": "^2.2.0", | ||
"firebase": "^7", | ||
"firebase-admin": "^11.4.1", | ||
"firebase-admin": "^12.0.0", | ||
"fluent-ffmpeg": "^2.1.2", | ||
@@ -95,3 +101,2 @@ "geo-tz": "^7.0.1", | ||
"mysql": "^2.17.1", | ||
"npm": "^6.14.6", | ||
"oracledb": "^6.2.0", | ||
@@ -110,2 +115,3 @@ "paraphrase": "1.8.0", | ||
"polyfill-library": "3.93.0", | ||
"prettier": "^3.2.5", | ||
"prismjs": "^1.27.0", | ||
@@ -123,2 +129,3 @@ "pug": "^3.0.1", | ||
"sequelize": "^6.29.0", | ||
"serialport": "^12.0.0", | ||
"sharp": "^0.33.1", | ||
@@ -141,6 +148,6 @@ "shiki": "^0.14.5", | ||
}, | ||
"packageManager": "npm@10.2.5", | ||
"engines": { | ||
"node": ">=16" | ||
}, | ||
"packageManager": "npm@10.2.5", | ||
"publishConfig": { | ||
@@ -147,0 +154,0 @@ "access": "public" |
@@ -12,2 +12,3 @@ # Node File Trace | ||
### Installation | ||
```bash | ||
@@ -39,4 +40,4 @@ npm i @vercel/nft | ||
const { fileList } = await nodeFileTrace(files, { | ||
base: process.cwd() | ||
} | ||
base: process.cwd(), | ||
}); | ||
``` | ||
@@ -55,4 +56,4 @@ | ||
const { fileList } = await nodeFileTrace(files, { | ||
processCwd: path.resolve(__dirname) | ||
} | ||
processCwd: path.resolve(__dirname), | ||
}); | ||
``` | ||
@@ -70,3 +71,3 @@ | ||
const { fileList } = await nodeFileTrace(files, { | ||
conditions: ['node', 'production'] | ||
conditions: ['node', 'production'], | ||
}); | ||
@@ -85,3 +86,3 @@ ``` | ||
const { fileList } = await nodeFileTrace(files, { | ||
exportsOnly: true | ||
exportsOnly: true, | ||
}); | ||
@@ -101,4 +102,4 @@ ``` | ||
paths: { | ||
'utils/': '/path/to/utils/' | ||
} | ||
'utils/': '/path/to/utils/', | ||
}, | ||
}); | ||
@@ -113,6 +114,6 @@ ``` | ||
* `readFile(path): Promise<string>` | ||
* `stat(path): Promise<FS.Stats>` | ||
* `readlink(path): Promise<string>` | ||
* `resolve(id: string, parent: string): Promise<string | string[]>` | ||
- `readFile(path): Promise<string>` | ||
- `stat(path): Promise<FS.Stats>` | ||
- `readlink(path): Promise<string>` | ||
- `resolve(id: string, parent: string): Promise<string | string[]>` | ||
@@ -123,15 +124,18 @@ ##### Advanced Resolving | ||
* `resolve(id: string, parent: string, job: Job, isCjs: boolean): Promise<string | string[]>` | ||
- `resolve(id: string, parent: string, job: Job, isCjs: boolean): Promise<string | string[]>` | ||
Here is an example showing one id being resolved to a bespoke path while all other paths being resolved by the built-in resolver | ||
```js | ||
const { nodeFileTrace, resolve } = require('@vercel/nft'); | ||
const files = ['./src/main.js', './src/second.js']; | ||
const { fileList } = await nodeFileTrace(files, { resolve: async (id, parent, job, isCjs) => { | ||
if (id === './src/main.js') { | ||
return '/path/to/some/resolved/main/file.js' | ||
} else { | ||
return resolve(id, parent, job, isCjs) | ||
} | ||
}}); | ||
const { fileList } = await nodeFileTrace(files, { | ||
resolve: async (id, parent, job, isCjs) => { | ||
if (id === './src/main.js') { | ||
return '/path/to/some/resolved/main/file.js'; | ||
} else { | ||
return resolve(id, parent, job, isCjs); | ||
} | ||
}, | ||
}); | ||
``` | ||
@@ -179,3 +183,3 @@ | ||
evaluatePureExpressions: true, | ||
} | ||
}, | ||
}); | ||
@@ -190,3 +194,3 @@ ``` | ||
const { fileList } = await nodeFileTrace(files, { | ||
ignore: ['./node_modules/pkg/file.js'] | ||
ignore: ['./node_modules/pkg/file.js'], | ||
}); | ||
@@ -193,0 +197,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
318288
3809
231
101