mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 06:21:12 +00:00
refactor(javascript): share bundler registration retention (#16026)
This commit is contained in:
1 parent
8393d3bf07
commit
552fc7149a
1 file changed
+28
-35
@@ -38,6 +38,26 @@ import type {
|
||||
import { JAVASCRIPT_AST_FINGERPRINT_ALGORITHM } from "./javascriptStaticAnalysisTypes.js";
|
||||
import { sha256Hex } from "../../kernel/sha256Hex.js";
|
||||
|
||||
const retainRegistration = (
|
||||
accumulator: AnalysisAccumulator,
|
||||
call: t.CallExpression,
|
||||
modules: JavaScriptBundlerModule[],
|
||||
facts: Omit<JavaScriptBundlerRegistration, "modules" | "location">,
|
||||
): void => {
|
||||
const registration: JavaScriptBundlerRegistration = {
|
||||
...facts,
|
||||
modules: modules.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.module_key, right.module_key),
|
||||
),
|
||||
location: range(call),
|
||||
};
|
||||
addFindingOnce(
|
||||
accumulator,
|
||||
`registration\0${registrationKey(registration)}`,
|
||||
() => accumulator.registrations.push(registration),
|
||||
);
|
||||
};
|
||||
|
||||
/** Inspect a bundler registration call and recover its module table. */
|
||||
export const inspectBundlerRegistration = (
|
||||
source: string,
|
||||
@@ -91,7 +111,7 @@ export const inspectBundlerRegistration = (
|
||||
...runtimeValue.asyncChunkKeys,
|
||||
...recovered.asyncChunkKeys,
|
||||
]);
|
||||
const registration: JavaScriptBundlerRegistration = {
|
||||
retainRegistration(accumulator, call, recovered.modules, {
|
||||
bundler: runtime.toLowerCase().includes("rspack")
|
||||
? ("rspack" as const)
|
||||
: ("webpack" as const),
|
||||
@@ -108,16 +128,7 @@ export const inspectBundlerRegistration = (
|
||||
async_chunk_keys: asyncChunkKeys.values,
|
||||
unknown_async_chunk_keys:
|
||||
runtimeValue.unknownAsyncChunkKeys + recovered.unknownAsyncChunkKeys,
|
||||
modules: recovered.modules.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.module_key, right.module_key),
|
||||
),
|
||||
location: range(call),
|
||||
};
|
||||
addFindingOnce(
|
||||
accumulator,
|
||||
`registration\0${registrationKey(registration)}`,
|
||||
() => accumulator.registrations.push(registration),
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
/** Recover standalone Webpack tables whose factories are called by a local loader. */
|
||||
@@ -153,7 +164,9 @@ export const inspectBundlerBootstrap = (
|
||||
else entries.push(value);
|
||||
},
|
||||
});
|
||||
const registration: JavaScriptBundlerRegistration = {
|
||||
accumulator.unknownFindings +=
|
||||
unknownEntries + recovered.unknownAsyncChunkKeys;
|
||||
retainRegistration(accumulator, call, recovered.modules, {
|
||||
bundler: "webpack",
|
||||
runtime,
|
||||
chunk_keys: [`bootstrap@${String(call.start ?? 0)}`],
|
||||
@@ -164,18 +177,7 @@ export const inspectBundlerBootstrap = (
|
||||
unknown_entry_module_keys: unknownEntries,
|
||||
async_chunk_keys: recovered.asyncChunkKeys,
|
||||
unknown_async_chunk_keys: recovered.unknownAsyncChunkKeys,
|
||||
modules: recovered.modules.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.module_key, right.module_key),
|
||||
),
|
||||
location: range(call),
|
||||
};
|
||||
accumulator.unknownFindings +=
|
||||
unknownEntries + recovered.unknownAsyncChunkKeys;
|
||||
addFindingOnce(
|
||||
accumulator,
|
||||
`registration\0${registrationKey(registration)}`,
|
||||
() => accumulator.registrations.push(registration),
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
/** Inspect esbuild helper wrappers and recover their literal module tables. */
|
||||
@@ -203,7 +205,7 @@ export const inspectEsbuildWrapper = (
|
||||
);
|
||||
if (recovered.modules.length === 0) return;
|
||||
accumulator.unknownFindings += recovered.unknownAsyncChunkKeys;
|
||||
const registration: JavaScriptBundlerRegistration = {
|
||||
retainRegistration(accumulator, call, recovered.modules, {
|
||||
bundler: "esbuild",
|
||||
runtime,
|
||||
chunk_keys: [`${wrapperKind}@${String(call.start ?? 0)}`],
|
||||
@@ -214,16 +216,7 @@ export const inspectEsbuildWrapper = (
|
||||
unknown_entry_module_keys: 0,
|
||||
async_chunk_keys: recovered.asyncChunkKeys,
|
||||
unknown_async_chunk_keys: recovered.unknownAsyncChunkKeys,
|
||||
modules: recovered.modules.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.module_key, right.module_key),
|
||||
),
|
||||
location: range(call),
|
||||
};
|
||||
addFindingOnce(
|
||||
accumulator,
|
||||
`registration\0${registrationKey(registration)}`,
|
||||
() => accumulator.registrations.push(registration),
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
interface RecoveredBundlerModules {
|
||||
|
||||
Reference in new issue
Block a user