@cyclonedx/cdxgen 12.1.5 → 12.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -40
- package/bin/cdxgen.js +194 -97
- package/bin/evinse.js +4 -4
- package/bin/repl.js +1 -1
- package/bin/sign.js +102 -0
- package/bin/validate.js +233 -0
- package/bin/verify.js +69 -28
- package/data/queries.json +1 -1
- package/data/rules/ci-permissions.yaml +186 -0
- package/data/rules/dependency-sources.yaml +123 -0
- package/data/rules/package-integrity.yaml +135 -0
- package/data/rules/vscode-extensions.yaml +228 -0
- package/lib/cli/index.js +449 -429
- package/lib/cli/index.poku.js +117 -0
- package/lib/evinser/db.js +137 -0
- package/lib/{helpers → evinser}/db.poku.js +2 -6
- package/lib/evinser/evinser.js +2 -14
- package/lib/helpers/analyzer.js +606 -3
- package/lib/helpers/analyzer.poku.js +230 -0
- package/lib/helpers/bomSigner.js +312 -0
- package/lib/helpers/bomSigner.poku.js +156 -0
- package/lib/helpers/ciParsers/azurePipelines.js +295 -0
- package/lib/helpers/ciParsers/azurePipelines.poku.js +253 -0
- package/lib/helpers/ciParsers/circleCi.js +286 -0
- package/lib/helpers/ciParsers/circleCi.poku.js +230 -0
- package/lib/helpers/ciParsers/common.js +24 -0
- package/lib/helpers/ciParsers/githubActions.js +636 -0
- package/lib/helpers/ciParsers/githubActions.poku.js +802 -0
- package/lib/helpers/ciParsers/gitlabCi.js +213 -0
- package/lib/helpers/ciParsers/gitlabCi.poku.js +247 -0
- package/lib/helpers/ciParsers/jenkins.js +181 -0
- package/lib/helpers/ciParsers/jenkins.poku.js +197 -0
- package/lib/helpers/depsUtils.js +219 -0
- package/lib/helpers/depsUtils.poku.js +207 -0
- package/lib/helpers/display.js +426 -5
- package/lib/helpers/envcontext.js +18 -3
- package/lib/helpers/formulationParsers.js +351 -0
- package/lib/helpers/logger.js +14 -0
- package/lib/helpers/protobom.js +9 -9
- package/lib/helpers/pythonutils.js +9 -0
- package/lib/helpers/remote/dependency-track.js +84 -0
- package/lib/helpers/remote/dependency-track.poku.js +119 -0
- package/lib/helpers/table.js +384 -0
- package/lib/helpers/table.poku.js +186 -0
- package/lib/helpers/utils.js +865 -416
- package/lib/helpers/utils.poku.js +172 -265
- package/lib/helpers/versutils.js +202 -0
- package/lib/helpers/versutils.poku.js +315 -0
- package/lib/helpers/vsixutils.js +1061 -0
- package/lib/helpers/vsixutils.poku.js +2247 -0
- package/lib/managers/binary.js +19 -19
- package/lib/managers/docker.js +108 -1
- package/lib/managers/oci.js +10 -0
- package/lib/managers/piptree.js +3 -9
- package/lib/parsers/npmrc.js +17 -13
- package/lib/parsers/npmrc.poku.js +41 -5
- package/lib/server/openapi.yaml +34 -1
- package/lib/server/server.js +50 -13
- package/lib/server/server.poku.js +332 -144
- package/lib/stages/postgen/annotator.js +1 -1
- package/lib/stages/postgen/auditBom.js +196 -0
- package/lib/stages/postgen/auditBom.poku.js +378 -0
- package/lib/stages/postgen/postgen.js +54 -1
- package/lib/stages/postgen/postgen.poku.js +90 -1
- package/lib/stages/postgen/ruleEngine.js +369 -0
- package/lib/stages/pregen/envAudit.js +299 -0
- package/lib/stages/pregen/envAudit.poku.js +572 -0
- package/lib/stages/pregen/pregen.js +12 -8
- package/lib/{helpers/validator.js → validator/bomValidator.js} +107 -47
- package/lib/validator/complianceEngine.js +241 -0
- package/lib/validator/complianceEngine.poku.js +168 -0
- package/lib/validator/complianceRules.js +1610 -0
- package/lib/validator/complianceRules.poku.js +328 -0
- package/lib/validator/index.js +222 -0
- package/lib/validator/index.poku.js +144 -0
- package/lib/validator/reporters/annotations.js +121 -0
- package/lib/validator/reporters/console.js +149 -0
- package/lib/validator/reporters/index.js +41 -0
- package/lib/validator/reporters/json.js +37 -0
- package/lib/validator/reporters/sarif.js +184 -0
- package/lib/validator/reporters.poku.js +150 -0
- package/package.json +8 -9
- package/types/bin/sign.d.ts +3 -0
- package/types/bin/sign.d.ts.map +1 -0
- package/types/bin/validate.d.ts +3 -0
- package/types/bin/validate.d.ts.map +1 -0
- package/types/helpers/utils.d.ts +0 -1
- package/types/lib/cli/index.d.ts +49 -52
- package/types/lib/cli/index.d.ts.map +1 -1
- package/types/lib/evinser/db.d.ts +34 -0
- package/types/lib/evinser/db.d.ts.map +1 -0
- package/types/lib/evinser/evinser.d.ts +63 -16
- package/types/lib/evinser/evinser.d.ts.map +1 -1
- package/types/lib/helpers/analyzer.d.ts.map +1 -1
- package/types/lib/helpers/bomSigner.d.ts +27 -0
- package/types/lib/helpers/bomSigner.d.ts.map +1 -0
- package/types/lib/helpers/ciParsers/azurePipelines.d.ts +17 -0
- package/types/lib/helpers/ciParsers/azurePipelines.d.ts.map +1 -0
- package/types/lib/helpers/ciParsers/circleCi.d.ts +17 -0
- package/types/lib/helpers/ciParsers/circleCi.d.ts.map +1 -0
- package/types/lib/helpers/ciParsers/common.d.ts +11 -0
- package/types/lib/helpers/ciParsers/common.d.ts.map +1 -0
- package/types/lib/helpers/ciParsers/githubActions.d.ts +34 -0
- package/types/lib/helpers/ciParsers/githubActions.d.ts.map +1 -0
- package/types/lib/helpers/ciParsers/gitlabCi.d.ts +17 -0
- package/types/lib/helpers/ciParsers/gitlabCi.d.ts.map +1 -0
- package/types/lib/helpers/ciParsers/jenkins.d.ts +17 -0
- package/types/lib/helpers/ciParsers/jenkins.d.ts.map +1 -0
- package/types/lib/helpers/depsUtils.d.ts +21 -0
- package/types/lib/helpers/depsUtils.d.ts.map +1 -0
- package/types/lib/helpers/display.d.ts +111 -11
- package/types/lib/helpers/display.d.ts.map +1 -1
- package/types/lib/helpers/envcontext.d.ts +19 -7
- package/types/lib/helpers/envcontext.d.ts.map +1 -1
- package/types/lib/helpers/formulationParsers.d.ts +50 -0
- package/types/lib/helpers/formulationParsers.d.ts.map +1 -0
- package/types/lib/helpers/logger.d.ts +15 -1
- package/types/lib/helpers/logger.d.ts.map +1 -1
- package/types/lib/helpers/protobom.d.ts +2 -2
- package/types/lib/helpers/pythonutils.d.ts +10 -1
- package/types/lib/helpers/pythonutils.d.ts.map +1 -1
- package/types/lib/helpers/remote/dependency-track.d.ts +16 -0
- package/types/lib/helpers/remote/dependency-track.d.ts.map +1 -0
- package/types/lib/helpers/table.d.ts +6 -0
- package/types/lib/helpers/table.d.ts.map +1 -0
- package/types/lib/helpers/utils.d.ts +533 -128
- package/types/lib/helpers/utils.d.ts.map +1 -1
- package/types/lib/helpers/versutils.d.ts +8 -0
- package/types/lib/helpers/versutils.d.ts.map +1 -0
- package/types/lib/helpers/vsixutils.d.ts +130 -0
- package/types/lib/helpers/vsixutils.d.ts.map +1 -0
- package/types/lib/managers/docker.d.ts +12 -31
- package/types/lib/managers/docker.d.ts.map +1 -1
- package/types/lib/managers/oci.d.ts +11 -1
- package/types/lib/managers/oci.d.ts.map +1 -1
- package/types/lib/managers/piptree.d.ts.map +1 -1
- package/types/lib/parsers/npmrc.d.ts +4 -1
- package/types/lib/parsers/npmrc.d.ts.map +1 -1
- package/types/lib/server/server.d.ts +22 -2
- package/types/lib/server/server.d.ts.map +1 -1
- package/types/lib/stages/postgen/auditBom.d.ts +20 -0
- package/types/lib/stages/postgen/auditBom.d.ts.map +1 -0
- package/types/lib/stages/postgen/postgen.d.ts +8 -1
- package/types/lib/stages/postgen/postgen.d.ts.map +1 -1
- package/types/lib/stages/postgen/ruleEngine.d.ts +18 -0
- package/types/lib/stages/postgen/ruleEngine.d.ts.map +1 -0
- package/types/lib/stages/pregen/envAudit.d.ts +8 -0
- package/types/lib/stages/pregen/envAudit.d.ts.map +1 -0
- package/types/lib/stages/pregen/pregen.d.ts.map +1 -1
- package/types/lib/{helpers/validator.d.ts → validator/bomValidator.d.ts} +1 -1
- package/types/lib/validator/bomValidator.d.ts.map +1 -0
- package/types/lib/validator/complianceEngine.d.ts +66 -0
- package/types/lib/validator/complianceEngine.d.ts.map +1 -0
- package/types/lib/validator/complianceRules.d.ts +70 -0
- package/types/lib/validator/complianceRules.d.ts.map +1 -0
- package/types/lib/validator/index.d.ts +70 -0
- package/types/lib/validator/index.d.ts.map +1 -0
- package/types/lib/validator/reporters/annotations.d.ts +31 -0
- package/types/lib/validator/reporters/annotations.d.ts.map +1 -0
- package/types/lib/validator/reporters/console.d.ts +30 -0
- package/types/lib/validator/reporters/console.d.ts.map +1 -0
- package/types/lib/validator/reporters/index.d.ts +21 -0
- package/types/lib/validator/reporters/index.d.ts.map +1 -0
- package/types/lib/validator/reporters/json.d.ts +11 -0
- package/types/lib/validator/reporters/json.d.ts.map +1 -0
- package/types/lib/validator/reporters/sarif.d.ts +16 -0
- package/types/lib/validator/reporters/sarif.d.ts.map +1 -0
- package/lib/helpers/db.js +0 -162
- package/lib/stages/pregen/env-audit.js +0 -34
- package/lib/stages/pregen/env-audit.poku.js +0 -290
- package/types/helpers/db.d.ts +0 -35
- package/types/helpers/db.d.ts.map +0 -1
- package/types/lib/helpers/db.d.ts +0 -35
- package/types/lib/helpers/db.d.ts.map +0 -1
- package/types/lib/helpers/validator.d.ts.map +0 -1
- package/types/lib/stages/pregen/env-audit.d.ts +0 -2
- package/types/lib/stages/pregen/env-audit.d.ts.map +0 -1
- package/types/managers/binary.d.ts +0 -37
- package/types/managers/binary.d.ts.map +0 -1
- package/types/managers/docker.d.ts +0 -56
- package/types/managers/docker.d.ts.map +0 -1
- package/types/managers/oci.d.ts +0 -2
- package/types/managers/oci.d.ts.map +0 -1
- package/types/managers/piptree.d.ts +0 -2
- package/types/managers/piptree.d.ts.map +0 -1
- package/types/server/server.d.ts +0 -34
- package/types/server/server.d.ts.map +0 -1
- package/types/stages/postgen/annotator.d.ts +0 -27
- package/types/stages/postgen/annotator.d.ts.map +0 -1
- package/types/stages/postgen/postgen.d.ts +0 -51
- package/types/stages/postgen/postgen.d.ts.map +0 -1
- package/types/stages/pregen/pregen.d.ts +0 -59
- package/types/stages/pregen/pregen.d.ts.map +0 -1
package/lib/helpers/analyzer.js
CHANGED
|
@@ -145,8 +145,8 @@ const setFileRef = (
|
|
|
145
145
|
exportedModules,
|
|
146
146
|
isExternal: true,
|
|
147
147
|
fileName: fileRelativeLoc,
|
|
148
|
-
lineNumber: sourceLoc?.line
|
|
149
|
-
columnNumber: sourceLoc?.column
|
|
148
|
+
lineNumber: sourceLoc?.line ?? undefined,
|
|
149
|
+
columnNumber: sourceLoc?.column ?? undefined,
|
|
150
150
|
};
|
|
151
151
|
// replace relative imports with full path
|
|
152
152
|
let moduleFullPath = pathway;
|
|
@@ -186,7 +186,7 @@ const setFileRef = (
|
|
|
186
186
|
const vueCleaningRegex = /<\/*script.*>|<style[\s\S]*style>|<\/*br>/gi;
|
|
187
187
|
const vueTemplateRegex = /(<template.*>)([\s\S]*)(<\/template>)/gi;
|
|
188
188
|
const vueCommentRegex = /<!--[\s\S]*?-->/gi;
|
|
189
|
-
const vueBindRegex = /(:\[)([\s\S]*?)(
|
|
189
|
+
const vueBindRegex = /(:\[)([\s\S]*?)(])/gi;
|
|
190
190
|
const vuePropRegex = /\s([.:@])([a-zA-Z]*?=)/gi;
|
|
191
191
|
|
|
192
192
|
const fileToParseableCode = (file) => {
|
|
@@ -216,12 +216,252 @@ const fileToParseableCode = (file) => {
|
|
|
216
216
|
return code;
|
|
217
217
|
};
|
|
218
218
|
|
|
219
|
+
const isWasmPath = (modulePath) =>
|
|
220
|
+
typeof modulePath === "string" && /\.wasm([?#].*)?$/i.test(modulePath);
|
|
221
|
+
|
|
222
|
+
const getStringValue = (astNode) => {
|
|
223
|
+
if (!astNode) {
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
if (astNode.type === "StringLiteral") {
|
|
227
|
+
return astNode.value;
|
|
228
|
+
}
|
|
229
|
+
if (
|
|
230
|
+
astNode.type === "TemplateLiteral" &&
|
|
231
|
+
astNode.expressions.length === 0 &&
|
|
232
|
+
astNode.quasis.length === 1
|
|
233
|
+
) {
|
|
234
|
+
return astNode.quasis[0].value.cooked;
|
|
235
|
+
}
|
|
236
|
+
return undefined;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const unwrapAwait = (astNode) =>
|
|
240
|
+
astNode?.type === "AwaitExpression" ? astNode.argument : astNode;
|
|
241
|
+
|
|
242
|
+
const isImportMetaUrl = (astNode) =>
|
|
243
|
+
astNode?.type === "MemberExpression" &&
|
|
244
|
+
astNode.object?.type === "MetaProperty" &&
|
|
245
|
+
astNode.object.meta?.name === "import" &&
|
|
246
|
+
astNode.object.property?.name === "meta" &&
|
|
247
|
+
astNode.property?.type === "Identifier" &&
|
|
248
|
+
astNode.property.name === "url";
|
|
249
|
+
|
|
250
|
+
const getMemberExpressionPropertyName = (propertyNode) => {
|
|
251
|
+
if (!propertyNode) {
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
if (propertyNode.type === "Identifier") {
|
|
255
|
+
return propertyNode.name;
|
|
256
|
+
}
|
|
257
|
+
if (propertyNode.type === "StringLiteral") {
|
|
258
|
+
return propertyNode.value;
|
|
259
|
+
}
|
|
260
|
+
return undefined;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const resolveWasmLiteralFromNode = (astNode, wasmBufferByVarName) => {
|
|
264
|
+
const normalizedNode = unwrapAwait(astNode);
|
|
265
|
+
const directLiteral = getStringValue(normalizedNode);
|
|
266
|
+
if (isWasmPath(directLiteral)) {
|
|
267
|
+
return directLiteral;
|
|
268
|
+
}
|
|
269
|
+
if (normalizedNode?.type === "Identifier") {
|
|
270
|
+
return wasmBufferByVarName.get(normalizedNode.name);
|
|
271
|
+
}
|
|
272
|
+
if (normalizedNode?.type === "CallExpression") {
|
|
273
|
+
if (
|
|
274
|
+
normalizedNode.callee?.type === "Identifier" &&
|
|
275
|
+
normalizedNode.callee.name === "fetch" &&
|
|
276
|
+
normalizedNode.arguments?.length
|
|
277
|
+
) {
|
|
278
|
+
return resolveWasmLiteralFromNode(
|
|
279
|
+
normalizedNode.arguments[0],
|
|
280
|
+
wasmBufferByVarName,
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (normalizedNode?.type === "NewExpression") {
|
|
285
|
+
if (
|
|
286
|
+
normalizedNode.callee?.type === "Identifier" &&
|
|
287
|
+
normalizedNode.callee.name === "URL" &&
|
|
288
|
+
normalizedNode.arguments?.length
|
|
289
|
+
) {
|
|
290
|
+
const urlLiteral = getStringValue(normalizedNode.arguments[0]);
|
|
291
|
+
const baseArg = normalizedNode.arguments[1];
|
|
292
|
+
if (isWasmPath(urlLiteral) && (!baseArg || isImportMetaUrl(baseArg))) {
|
|
293
|
+
return urlLiteral;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return undefined;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const getWasmSourceFromInstantiateCall = (callNode, wasmBufferByVarName) => {
|
|
301
|
+
if (!callNode?.callee || callNode.callee.type !== "MemberExpression") {
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
const objectNode = callNode.callee.object;
|
|
305
|
+
const propertyNode = callNode.callee.property;
|
|
306
|
+
const calleeObjectName = getMemberExpressionPropertyName(objectNode);
|
|
307
|
+
const calleePropertyName = getMemberExpressionPropertyName(propertyNode);
|
|
308
|
+
if (calleeObjectName !== "WebAssembly") {
|
|
309
|
+
return undefined;
|
|
310
|
+
}
|
|
311
|
+
if (
|
|
312
|
+
calleePropertyName !== "instantiate" &&
|
|
313
|
+
calleePropertyName !== "instantiateStreaming" &&
|
|
314
|
+
calleePropertyName !== "compile" &&
|
|
315
|
+
calleePropertyName !== "compileStreaming"
|
|
316
|
+
) {
|
|
317
|
+
return undefined;
|
|
318
|
+
}
|
|
319
|
+
if (!callNode.arguments?.length) {
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
return resolveWasmLiteralFromNode(callNode.arguments[0], wasmBufferByVarName);
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const getWasmSourceFromCallExpression = (callNode, wasmBufferByVarName) => {
|
|
326
|
+
const wasmSourceFromInstantiate = getWasmSourceFromInstantiateCall(
|
|
327
|
+
callNode,
|
|
328
|
+
wasmBufferByVarName,
|
|
329
|
+
);
|
|
330
|
+
if (wasmSourceFromInstantiate) {
|
|
331
|
+
return wasmSourceFromInstantiate;
|
|
332
|
+
}
|
|
333
|
+
if (
|
|
334
|
+
callNode?.callee?.type === "Identifier" &&
|
|
335
|
+
["fetch", "locateFile"].includes(callNode.callee.name) &&
|
|
336
|
+
callNode.arguments?.length
|
|
337
|
+
) {
|
|
338
|
+
return resolveWasmLiteralFromNode(
|
|
339
|
+
callNode.arguments[0],
|
|
340
|
+
wasmBufferByVarName,
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
return undefined;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
const getNamedImportsFromObjectPattern = (idNode) => {
|
|
347
|
+
const namedImports = [];
|
|
348
|
+
if (!idNode || idNode.type !== "ObjectPattern") {
|
|
349
|
+
return namedImports;
|
|
350
|
+
}
|
|
351
|
+
for (const prop of idNode.properties || []) {
|
|
352
|
+
if (prop.type !== "ObjectProperty") {
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
const keyName = getMemberExpressionPropertyName(prop.key);
|
|
356
|
+
if (keyName) {
|
|
357
|
+
namedImports.push(keyName);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return namedImports;
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const setSyntheticImportRef = (
|
|
364
|
+
allImports,
|
|
365
|
+
allExports,
|
|
366
|
+
src,
|
|
367
|
+
file,
|
|
368
|
+
importPath,
|
|
369
|
+
modules,
|
|
370
|
+
sourceLoc,
|
|
371
|
+
) => {
|
|
372
|
+
if (!importPath) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
const safeModules = modules || [];
|
|
376
|
+
const syntheticSpecifiers = safeModules.map((moduleName) => ({
|
|
377
|
+
imported: { name: moduleName },
|
|
378
|
+
}));
|
|
379
|
+
setFileRef(
|
|
380
|
+
allImports,
|
|
381
|
+
allExports,
|
|
382
|
+
src,
|
|
383
|
+
file,
|
|
384
|
+
{ value: importPath, loc: sourceLoc ? { start: sourceLoc } : undefined },
|
|
385
|
+
syntheticSpecifiers,
|
|
386
|
+
);
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
const setSyntheticExportRef = (
|
|
390
|
+
allImports,
|
|
391
|
+
allExports,
|
|
392
|
+
src,
|
|
393
|
+
file,
|
|
394
|
+
importPath,
|
|
395
|
+
modules,
|
|
396
|
+
sourceLoc,
|
|
397
|
+
) => {
|
|
398
|
+
if (!importPath) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const safeModules = modules || [];
|
|
402
|
+
const syntheticSpecifiers = safeModules.map((moduleName) => ({
|
|
403
|
+
exported: { name: moduleName },
|
|
404
|
+
}));
|
|
405
|
+
setFileRef(
|
|
406
|
+
allImports,
|
|
407
|
+
allExports,
|
|
408
|
+
src,
|
|
409
|
+
file,
|
|
410
|
+
{ value: importPath, loc: sourceLoc ? { start: sourceLoc } : undefined },
|
|
411
|
+
syntheticSpecifiers,
|
|
412
|
+
);
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
const getWasmExportMemberInfo = (astNode) => {
|
|
416
|
+
if (!astNode) {
|
|
417
|
+
return undefined;
|
|
418
|
+
}
|
|
419
|
+
if (astNode.type === "AssignmentExpression") {
|
|
420
|
+
return getWasmExportMemberInfo(astNode.right);
|
|
421
|
+
}
|
|
422
|
+
if (
|
|
423
|
+
astNode.type !== "MemberExpression" ||
|
|
424
|
+
astNode.object?.type !== "Identifier"
|
|
425
|
+
) {
|
|
426
|
+
return undefined;
|
|
427
|
+
}
|
|
428
|
+
return {
|
|
429
|
+
aliasName: astNode.object.name,
|
|
430
|
+
exportName: getMemberExpressionPropertyName(astNode.property),
|
|
431
|
+
};
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const getAssignmentTargetName = (astNode) => {
|
|
435
|
+
if (!astNode) {
|
|
436
|
+
return undefined;
|
|
437
|
+
}
|
|
438
|
+
if (astNode.type === "Identifier") {
|
|
439
|
+
return astNode.name;
|
|
440
|
+
}
|
|
441
|
+
if (
|
|
442
|
+
astNode.type === "MemberExpression" &&
|
|
443
|
+
astNode.object?.type === "Identifier" &&
|
|
444
|
+
astNode.object.name === "Module"
|
|
445
|
+
) {
|
|
446
|
+
return getMemberExpressionPropertyName(astNode.property);
|
|
447
|
+
}
|
|
448
|
+
return undefined;
|
|
449
|
+
};
|
|
450
|
+
|
|
219
451
|
/**
|
|
220
452
|
* Check AST tree for any (j|tsx?) files and set a file
|
|
221
453
|
* references for any import, require or dynamic import files.
|
|
222
454
|
*/
|
|
223
455
|
const parseFileASTTree = (src, file, allImports, allExports) => {
|
|
224
456
|
const ast = parse(fileToParseableCode(file), babelParserOptions);
|
|
457
|
+
const wasmBufferByVarName = new Map();
|
|
458
|
+
const wasmResultByVarName = new Map();
|
|
459
|
+
const wasmInstanceByVarName = new Map();
|
|
460
|
+
const wasiConstructorAliases = new Set(["WASI"]);
|
|
461
|
+
const wasiNamespaceAliases = new Set();
|
|
462
|
+
const wasiInstanceAliases = new Set();
|
|
463
|
+
const wasmPathLiterals = new Set();
|
|
464
|
+
const wasmExportAliases = new Set(["wasmExports"]);
|
|
225
465
|
traverse.default(ast, {
|
|
226
466
|
ImportDeclaration: (path) => {
|
|
227
467
|
if (path?.node) {
|
|
@@ -233,6 +473,20 @@ const parseFileASTTree = (src, file, allImports, allExports) => {
|
|
|
233
473
|
path.node.source,
|
|
234
474
|
path.node.specifiers,
|
|
235
475
|
);
|
|
476
|
+
const sourceValue = path.node.source?.value;
|
|
477
|
+
if (sourceValue === "node:wasi" || sourceValue === "wasi") {
|
|
478
|
+
for (const specifier of path.node.specifiers || []) {
|
|
479
|
+
if (
|
|
480
|
+
specifier.type === "ImportSpecifier" &&
|
|
481
|
+
specifier.imported?.name === "WASI"
|
|
482
|
+
) {
|
|
483
|
+
wasiConstructorAliases.add(specifier.local?.name || "WASI");
|
|
484
|
+
}
|
|
485
|
+
if (specifier.type === "ImportNamespaceSpecifier") {
|
|
486
|
+
wasiNamespaceAliases.add(specifier.local?.name);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
236
490
|
}
|
|
237
491
|
},
|
|
238
492
|
// For require('') statements
|
|
@@ -250,6 +504,355 @@ const parseFileASTTree = (src, file, allImports, allExports) => {
|
|
|
250
504
|
if (path?.node && path.node.callee.type === "Import") {
|
|
251
505
|
setFileRef(allImports, allExports, src, file, path.node.arguments[0]);
|
|
252
506
|
}
|
|
507
|
+
const wasmSourceLiteral = getWasmSourceFromCallExpression(
|
|
508
|
+
path?.node,
|
|
509
|
+
wasmBufferByVarName,
|
|
510
|
+
);
|
|
511
|
+
if (wasmSourceLiteral) {
|
|
512
|
+
wasmPathLiterals.add(wasmSourceLiteral);
|
|
513
|
+
setSyntheticImportRef(
|
|
514
|
+
allImports,
|
|
515
|
+
allExports,
|
|
516
|
+
src,
|
|
517
|
+
file,
|
|
518
|
+
wasmSourceLiteral,
|
|
519
|
+
[],
|
|
520
|
+
path.node.loc?.start,
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
if (
|
|
524
|
+
path?.node?.callee?.type === "MemberExpression" &&
|
|
525
|
+
path.node.callee.object?.type === "Identifier" &&
|
|
526
|
+
wasiInstanceAliases.has(path.node.callee.object.name)
|
|
527
|
+
) {
|
|
528
|
+
const methodName = getMemberExpressionPropertyName(
|
|
529
|
+
path.node.callee.property,
|
|
530
|
+
);
|
|
531
|
+
if (methodName === "start" || methodName === "initialize") {
|
|
532
|
+
setSyntheticImportRef(
|
|
533
|
+
allImports,
|
|
534
|
+
allExports,
|
|
535
|
+
src,
|
|
536
|
+
file,
|
|
537
|
+
"node:wasi",
|
|
538
|
+
[methodName],
|
|
539
|
+
path.node.loc?.start,
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
ImportExpression: (path) => {
|
|
545
|
+
if (path?.node?.source) {
|
|
546
|
+
setFileRef(allImports, allExports, src, file, path.node.source);
|
|
547
|
+
}
|
|
548
|
+
},
|
|
549
|
+
VariableDeclarator: (path) => {
|
|
550
|
+
const idNode = path?.node?.id;
|
|
551
|
+
const initNode = unwrapAwait(path?.node?.init);
|
|
552
|
+
if (!idNode || !initNode) {
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
if (
|
|
556
|
+
idNode.type === "Identifier" &&
|
|
557
|
+
initNode.type === "CallExpression" &&
|
|
558
|
+
initNode.callee?.type === "MemberExpression"
|
|
559
|
+
) {
|
|
560
|
+
const calleePropertyName = getMemberExpressionPropertyName(
|
|
561
|
+
initNode.callee.property,
|
|
562
|
+
);
|
|
563
|
+
if (
|
|
564
|
+
calleePropertyName === "readFile" ||
|
|
565
|
+
calleePropertyName === "readFileSync"
|
|
566
|
+
) {
|
|
567
|
+
const pathArg = initNode.arguments?.[0];
|
|
568
|
+
const wasmPath = getStringValue(pathArg);
|
|
569
|
+
if (isWasmPath(wasmPath)) {
|
|
570
|
+
wasmBufferByVarName.set(idNode.name, wasmPath);
|
|
571
|
+
wasmPathLiterals.add(wasmPath);
|
|
572
|
+
setSyntheticImportRef(
|
|
573
|
+
allImports,
|
|
574
|
+
allExports,
|
|
575
|
+
src,
|
|
576
|
+
file,
|
|
577
|
+
wasmPath,
|
|
578
|
+
[],
|
|
579
|
+
path.node.loc?.start,
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
const wasmSource = getWasmSourceFromInstantiateCall(
|
|
584
|
+
initNode,
|
|
585
|
+
wasmBufferByVarName,
|
|
586
|
+
);
|
|
587
|
+
if (wasmSource) {
|
|
588
|
+
wasmResultByVarName.set(idNode.name, wasmSource);
|
|
589
|
+
wasmPathLiterals.add(wasmSource);
|
|
590
|
+
setSyntheticImportRef(
|
|
591
|
+
allImports,
|
|
592
|
+
allExports,
|
|
593
|
+
src,
|
|
594
|
+
file,
|
|
595
|
+
wasmSource,
|
|
596
|
+
[],
|
|
597
|
+
path.node.loc?.start,
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
if (
|
|
601
|
+
initNode.callee?.type === "MemberExpression" &&
|
|
602
|
+
initNode.callee.object?.type === "Identifier" &&
|
|
603
|
+
wasiNamespaceAliases.has(initNode.callee.object.name) &&
|
|
604
|
+
getMemberExpressionPropertyName(initNode.callee.property) === "WASI"
|
|
605
|
+
) {
|
|
606
|
+
wasiInstanceAliases.add(idNode.name);
|
|
607
|
+
setSyntheticImportRef(
|
|
608
|
+
allImports,
|
|
609
|
+
allExports,
|
|
610
|
+
src,
|
|
611
|
+
file,
|
|
612
|
+
"node:wasi",
|
|
613
|
+
["WASI"],
|
|
614
|
+
path.node.loc?.start,
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
if (
|
|
619
|
+
idNode.type === "Identifier" &&
|
|
620
|
+
initNode.type === "CallExpression" &&
|
|
621
|
+
initNode.callee?.type === "Identifier" &&
|
|
622
|
+
wasiConstructorAliases.has(initNode.callee.name)
|
|
623
|
+
) {
|
|
624
|
+
wasiInstanceAliases.add(idNode.name);
|
|
625
|
+
setSyntheticImportRef(
|
|
626
|
+
allImports,
|
|
627
|
+
allExports,
|
|
628
|
+
src,
|
|
629
|
+
file,
|
|
630
|
+
"node:wasi",
|
|
631
|
+
["WASI"],
|
|
632
|
+
path.node.loc?.start,
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
if (idNode.type === "Identifier" && initNode.type === "NewExpression") {
|
|
636
|
+
if (
|
|
637
|
+
initNode.callee?.type === "Identifier" &&
|
|
638
|
+
wasiConstructorAliases.has(initNode.callee.name)
|
|
639
|
+
) {
|
|
640
|
+
wasiInstanceAliases.add(idNode.name);
|
|
641
|
+
setSyntheticImportRef(
|
|
642
|
+
allImports,
|
|
643
|
+
allExports,
|
|
644
|
+
src,
|
|
645
|
+
file,
|
|
646
|
+
"node:wasi",
|
|
647
|
+
["WASI"],
|
|
648
|
+
path.node.loc?.start,
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
if (
|
|
652
|
+
initNode.callee?.type === "MemberExpression" &&
|
|
653
|
+
initNode.callee.object?.type === "Identifier" &&
|
|
654
|
+
wasiNamespaceAliases.has(initNode.callee.object.name) &&
|
|
655
|
+
getMemberExpressionPropertyName(initNode.callee.property) === "WASI"
|
|
656
|
+
) {
|
|
657
|
+
wasiInstanceAliases.add(idNode.name);
|
|
658
|
+
setSyntheticImportRef(
|
|
659
|
+
allImports,
|
|
660
|
+
allExports,
|
|
661
|
+
src,
|
|
662
|
+
file,
|
|
663
|
+
"node:wasi",
|
|
664
|
+
["WASI"],
|
|
665
|
+
path.node.loc?.start,
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
if (idNode.type === "ObjectPattern") {
|
|
670
|
+
if (initNode.type === "CallExpression") {
|
|
671
|
+
const wasmSource = getWasmSourceFromInstantiateCall(
|
|
672
|
+
initNode,
|
|
673
|
+
wasmBufferByVarName,
|
|
674
|
+
);
|
|
675
|
+
if (wasmSource) {
|
|
676
|
+
wasmPathLiterals.add(wasmSource);
|
|
677
|
+
for (const prop of idNode.properties || []) {
|
|
678
|
+
if (
|
|
679
|
+
prop.type === "ObjectProperty" &&
|
|
680
|
+
getMemberExpressionPropertyName(prop.key) === "instance" &&
|
|
681
|
+
prop.value?.type === "Identifier"
|
|
682
|
+
) {
|
|
683
|
+
wasmInstanceByVarName.set(prop.value.name, wasmSource);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
setSyntheticImportRef(
|
|
687
|
+
allImports,
|
|
688
|
+
allExports,
|
|
689
|
+
src,
|
|
690
|
+
file,
|
|
691
|
+
wasmSource,
|
|
692
|
+
[],
|
|
693
|
+
path.node.loc?.start,
|
|
694
|
+
);
|
|
695
|
+
}
|
|
696
|
+
if (
|
|
697
|
+
initNode.callee?.type === "Identifier" &&
|
|
698
|
+
initNode.callee.name === "require"
|
|
699
|
+
) {
|
|
700
|
+
const requiredModule = getStringValue(initNode.arguments?.[0]);
|
|
701
|
+
if (requiredModule === "node:wasi" || requiredModule === "wasi") {
|
|
702
|
+
for (const prop of idNode.properties || []) {
|
|
703
|
+
if (
|
|
704
|
+
prop.type === "ObjectProperty" &&
|
|
705
|
+
getMemberExpressionPropertyName(prop.key) === "WASI" &&
|
|
706
|
+
prop.value?.type === "Identifier"
|
|
707
|
+
) {
|
|
708
|
+
wasiConstructorAliases.add(prop.value.name);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
if (initNode.type === "MemberExpression") {
|
|
715
|
+
const exportNames = getNamedImportsFromObjectPattern(idNode);
|
|
716
|
+
if (!exportNames.length) {
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
if (
|
|
720
|
+
initNode.object?.type === "MemberExpression" &&
|
|
721
|
+
initNode.object.object?.type === "Identifier" &&
|
|
722
|
+
getMemberExpressionPropertyName(initNode.object.property) ===
|
|
723
|
+
"instance" &&
|
|
724
|
+
getMemberExpressionPropertyName(initNode.property) === "exports"
|
|
725
|
+
) {
|
|
726
|
+
const wasmSource = wasmResultByVarName.get(
|
|
727
|
+
initNode.object.object.name,
|
|
728
|
+
);
|
|
729
|
+
if (wasmSource) {
|
|
730
|
+
setSyntheticImportRef(
|
|
731
|
+
allImports,
|
|
732
|
+
allExports,
|
|
733
|
+
src,
|
|
734
|
+
file,
|
|
735
|
+
wasmSource,
|
|
736
|
+
exportNames,
|
|
737
|
+
path.node.loc?.start,
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
if (
|
|
742
|
+
initNode.object?.type === "Identifier" &&
|
|
743
|
+
getMemberExpressionPropertyName(initNode.property) === "exports"
|
|
744
|
+
) {
|
|
745
|
+
const wasmSource = wasmInstanceByVarName.get(initNode.object.name);
|
|
746
|
+
if (wasmSource) {
|
|
747
|
+
setSyntheticImportRef(
|
|
748
|
+
allImports,
|
|
749
|
+
allExports,
|
|
750
|
+
src,
|
|
751
|
+
file,
|
|
752
|
+
wasmSource,
|
|
753
|
+
exportNames,
|
|
754
|
+
path.node.loc?.start,
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
if (
|
|
761
|
+
idNode.type === "Identifier" &&
|
|
762
|
+
initNode.type === "MemberExpression" &&
|
|
763
|
+
initNode.object?.type === "Identifier" &&
|
|
764
|
+
getMemberExpressionPropertyName(initNode.property) === "instance"
|
|
765
|
+
) {
|
|
766
|
+
const wasmSource = wasmResultByVarName.get(initNode.object.name);
|
|
767
|
+
if (wasmSource) {
|
|
768
|
+
wasmInstanceByVarName.set(idNode.name, wasmSource);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
if (
|
|
772
|
+
idNode.type === "Identifier" &&
|
|
773
|
+
initNode.type === "CallExpression" &&
|
|
774
|
+
initNode.callee?.type === "MemberExpression" &&
|
|
775
|
+
initNode.callee.object?.type === "Identifier" &&
|
|
776
|
+
initNode.callee.object.name === "WebAssembly"
|
|
777
|
+
) {
|
|
778
|
+
const wasmSource = getWasmSourceFromInstantiateCall(
|
|
779
|
+
initNode,
|
|
780
|
+
wasmBufferByVarName,
|
|
781
|
+
);
|
|
782
|
+
if (wasmSource) {
|
|
783
|
+
wasmResultByVarName.set(idNode.name, wasmSource);
|
|
784
|
+
wasmPathLiterals.add(wasmSource);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
AssignmentExpression: (path) => {
|
|
789
|
+
const wasmExportMemberInfo = getWasmExportMemberInfo(path?.node?.right);
|
|
790
|
+
if (!wasmExportMemberInfo?.exportName) {
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
if (!wasmExportAliases.has(wasmExportMemberInfo.aliasName)) {
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
if (!wasmPathLiterals.size) {
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
for (const wasmPath of wasmPathLiterals) {
|
|
800
|
+
setSyntheticImportRef(
|
|
801
|
+
allImports,
|
|
802
|
+
allExports,
|
|
803
|
+
src,
|
|
804
|
+
file,
|
|
805
|
+
wasmPath,
|
|
806
|
+
[wasmExportMemberInfo.exportName],
|
|
807
|
+
path.node.loc?.start,
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
const targetName = getAssignmentTargetName(path?.node?.left);
|
|
811
|
+
if (!targetName) {
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
for (const wasmPath of wasmPathLiterals) {
|
|
815
|
+
setSyntheticExportRef(
|
|
816
|
+
allImports,
|
|
817
|
+
allExports,
|
|
818
|
+
src,
|
|
819
|
+
file,
|
|
820
|
+
wasmPath,
|
|
821
|
+
[targetName],
|
|
822
|
+
path.node.loc?.start,
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
},
|
|
826
|
+
NewExpression: (path) => {
|
|
827
|
+
if (path?.node?.callee?.type === "Identifier") {
|
|
828
|
+
if (wasiConstructorAliases.has(path.node.callee.name)) {
|
|
829
|
+
setSyntheticImportRef(
|
|
830
|
+
allImports,
|
|
831
|
+
allExports,
|
|
832
|
+
src,
|
|
833
|
+
file,
|
|
834
|
+
"node:wasi",
|
|
835
|
+
["WASI"],
|
|
836
|
+
path.node.loc?.start,
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
if (
|
|
841
|
+
path?.node?.callee?.type === "MemberExpression" &&
|
|
842
|
+
path.node.callee.object?.type === "Identifier" &&
|
|
843
|
+
wasiNamespaceAliases.has(path.node.callee.object.name) &&
|
|
844
|
+
getMemberExpressionPropertyName(path.node.callee.property) === "WASI"
|
|
845
|
+
) {
|
|
846
|
+
setSyntheticImportRef(
|
|
847
|
+
allImports,
|
|
848
|
+
allExports,
|
|
849
|
+
src,
|
|
850
|
+
file,
|
|
851
|
+
"node:wasi",
|
|
852
|
+
["WASI"],
|
|
853
|
+
path.node.loc?.start,
|
|
854
|
+
);
|
|
855
|
+
}
|
|
253
856
|
},
|
|
254
857
|
// Use for export barrells
|
|
255
858
|
ExportAllDeclaration: (path) => {
|