@akanjs/devkit 3.3.0-rc.3 → 3.3.0-rc.30
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/CHANGELOG.md +547 -0
- package/DEV_RUNTIME_KNOBS.md +1 -1
- package/README.ko.md +3 -2
- package/README.md +3 -3
- package/akanApp/akanApp.host.test.ts +1 -1
- package/akanApp/akanApp.host.ts +11 -0
- package/akanConfig/akanBin.ts +4 -0
- package/akanConfig/akanConfig.test.ts +66 -7
- package/akanConfig/akanConfig.ts +53 -204
- package/akanConfig/akanWorkers.test.ts +39 -0
- package/akanConfig/akanWorkers.ts +32 -0
- package/akanConfig/desktopServerConfig.ts +96 -0
- package/akanConfig/dockerImage.ts +37 -0
- package/akanConfig/nativeKeys.ts +52 -0
- package/akanConfig/types.ts +1 -0
- package/app/appBin.test.ts +63 -0
- package/app/appBin.ts +50 -0
- package/app/applicationBuildReporter.test.ts +32 -0
- package/app/applicationBuildReporter.ts +4 -0
- package/app/applicationBuildRunner.test.ts +275 -0
- package/app/applicationBuildRunner.ts +126 -5
- package/app/dictionarySizes.ts +94 -0
- package/artifact/implicitRootLayout.test.ts +19 -0
- package/artifact/implicitRootLayout.ts +16 -2
- package/artifact/implicitRootLayoutRender.test.tsx +4 -1
- package/artifact/storeBootstrap.test.ts +28 -0
- package/artifact/storeBootstrap.ts +60 -8
- package/biome.base.json +5 -1
- package/codeAgent/agent/CodeAgent.ts +36 -16
- package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
- package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
- package/codeAgent/agent/CodeAgentGate.ts +23 -4
- package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +62 -0
- package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
- package/codeAgent/agent/codeAgentContract.test.ts +117 -5
- package/codeAgent/skills/akan-agent/SKILL.md +8 -1
- package/codeAgent/skills/akan-code/SKILL.md +38 -3
- package/codeAgent/skills/akan-deps/SKILL.md +3 -2
- package/codeAgent/skills/akan-err/SKILL.md +13 -8
- package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
- package/codeAgent/skills/akan-module/SKILL.md +2 -2
- package/codeAgent/skills/akan-page/SKILL.md +4 -14
- package/codeAgent/skills/akan-query/SKILL.md +13 -20
- package/codeAgent/skills/akan-runtime/SKILL.md +20 -0
- package/codeAgent/skills/akan-service/SKILL.md +2 -5
- package/codeAgent/skills/akan-transport/SKILL.md +5 -14
- package/codeAgent/skills/akan-ui/SKILL.md +2 -5
- package/context/akanContext.ts +2 -0
- package/docs/apiReference.test.ts +9 -0
- package/docs/apiReference.ts +14 -0
- package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
- package/executors/clientRuntimeKeys.fixture.json +393 -0
- package/executors/clientRuntimeKeys.test.ts +1591 -0
- package/executors/executors.test.ts +2 -0
- package/executors/sysExecutor.ts +66 -3
- package/executors/workspaceExecutor.ts +7 -4
- package/frontendBuild/allRoutesBuilder.ts +72 -3
- package/frontendBuild/autoImportSync.ts +3 -2
- package/frontendBuild/buildRouteClient.test.ts +515 -12
- package/frontendBuild/clientBuildTypes.ts +15 -0
- package/frontendBuild/clientEntriesBundler.ts +38 -0
- package/frontendBuild/clientEntryDiscovery.test.ts +95 -1
- package/frontendBuild/clientEntryDiscovery.ts +88 -7
- package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
- package/frontendBuild/csrDevModuleCompiler.ts +44 -8
- package/frontendBuild/csrDevPatcher.ts +33 -7
- package/frontendBuild/csrDevTypes.ts +9 -0
- package/frontendBuild/devBarrelImports.test.ts +100 -0
- package/frontendBuild/devBarrelImports.ts +82 -23
- package/frontendBuild/devRegistryBundler.ts +4 -2
- package/frontendBuild/devRouteRuntime.test.ts +492 -0
- package/frontendBuild/devRouteRuntime.ts +167 -0
- package/frontendBuild/dictionaryAssetBuilder.test.ts +316 -0
- package/frontendBuild/dictionaryAssetBuilder.ts +152 -16
- package/frontendBuild/dictionaryConstants.ts +82 -0
- package/frontendBuild/dictionaryPacking.test.ts +84 -0
- package/frontendBuild/dictionaryPacking.ts +92 -0
- package/frontendBuild/dictionaryRoutes.test.ts +186 -0
- package/frontendBuild/dictionaryRoutes.ts +225 -0
- package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
- package/frontendBuild/pagesBundleBuilder.ts +81 -3
- package/frontendBuild/precompressArtifacts.ts +7 -0
- package/frontendBuild/registryMetadataFingerprint.ts +3 -3
- package/frontendBuild/routeClientBuilder.ts +288 -15
- package/frontendBuild/routeHandoffs.test.ts +145 -0
- package/frontendBuild/routeHandoffs.ts +115 -0
- package/frontendBuild/routeRuntimeCheck.test.ts +257 -0
- package/frontendBuild/routeRuntimeCheck.ts +241 -0
- package/frontendBuild/routeRuntimePays.test.ts +137 -0
- package/frontendBuild/routeRuntimePays.ts +117 -0
- package/frontendBuild/rscServerRendererGuard.test.ts +60 -0
- package/frontendBuild/rscServerRendererGuard.ts +68 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +24 -34
- package/frontendBuild/ssrDevBundler.test.ts +150 -1
- package/frontendBuild/ssrDevBundler.ts +66 -11
- package/frontendBuild/vendorFileImports.test.ts +254 -0
- package/frontendBuild/vendorFileImports.ts +163 -0
- package/frontendBuild/vendorNarrowing.ts +28 -0
- package/frontendBuild/vendorSpecifiers.ts +2 -0
- package/incrementalBuilder/buildBatch.proc.ts +9 -9
- package/incrementalBuilder/buildBatchProtocol.ts +1 -1
- package/incrementalBuilder/builderBoot.ts +5 -5
- package/incrementalBuilder/builderGraphPayloads.ts +4 -4
- package/incrementalBuilder/builderLanes.ts +2 -2
- package/incrementalBuilder/builderWatch.ts +8 -8
- package/incrementalBuilder/csrRegistry.ts +4 -4
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +79 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +27 -8
- package/incrementalBuilder/ssrRegistry.ts +6 -6
- package/index.ts +1 -1
- package/integration/renderAdmissionSoak.test.ts +99 -0
- package/integration/renderAdmissionSoak.ts +609 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
- package/lint/biomeCheck.test.ts +145 -0
- package/lint/biomeCheck.ts +131 -0
- package/lint/no-arbitrary-color.grit +5 -0
- package/lint/no-conditional-st-hook.grit +5 -1
- package/lint/no-daisyui-legacy-class.grit +8 -0
- package/lint/no-document-cookie.grit +3 -0
- package/lint/no-inline-color.grit +10 -2
- package/lint/no-oversized-list-limit.grit +2 -0
- package/lint/no-raw-palette-class.grit +7 -0
- package/lint/no-unpublished-form-setter.grit +2 -0
- package/lint/no-web-only-api-outside-webkit.grit +5 -0
- package/lint/no-web-storage.grit +3 -0
- package/lint/withheldEnvFile.ts +17 -0
- package/mobile/desktopBin.ts +2 -2
- package/mobile/desktopServerStage.ts +1 -0
- package/mobile/nativeApp.test.ts +7 -5
- package/mobile/nativeApp.ts +2 -2
- package/mobile/nativeConfig.test.ts +96 -1
- package/mobile/nativeConfig.ts +46 -12
- package/mobile/serverBundleSecrets.ts +43 -0
- package/package.json +15 -169
- package/packageExports.test.ts +38 -24
- package/quality/dictionaryKeys.test.ts +173 -0
- package/quality/dictionaryKeys.ts +415 -0
- package/quality/objectImportReport.test.ts +36 -0
- package/quality/objectImportReport.ts +102 -0
- package/quality/qualityScanner.ts +1 -1
- package/quality/routeRuntimeReport.test.ts +91 -0
- package/quality/routeRuntimeReport.ts +121 -0
- package/quality/runtimeConstantFacts.ts +71 -0
- package/quality/runtimeConstantGraph.ts +123 -0
- package/quality/runtimeConstantReads.ts +116 -0
- package/quality/runtimeImports.test.ts +190 -0
- package/quality/runtimeImports.ts +233 -0
- package/quality/runtimeKeyNames.ts +46 -0
- package/quality/runtimeLexicalScope.ts +132 -0
- package/quality/runtimeMarkerReach.test.ts +84 -0
- package/quality/runtimeMarkerReach.ts +255 -0
- package/quality/runtimeModuleFacts.ts +290 -0
- package/quality/runtimeNameTable.test.ts +172 -0
- package/quality/runtimeNameTable.ts +477 -0
- package/quality/runtimeScopeReport.test.ts +123 -0
- package/quality/runtimeScopeReport.ts +167 -0
- package/quality/runtimeSliceKey.ts +269 -0
- package/quality/runtimeSyntax.ts +133 -0
- package/quality/runtimeTable.fixture.ts +189 -0
- package/quality/runtimeUse.test.ts +737 -0
- package/quality/runtimeUse.ts +696 -0
- package/quality/runtimeUseReadable.test.ts +393 -0
- package/quality/ssrScanner.test.ts +13 -0
- package/quality/ssrScanner.ts +1 -1
- package/test/secretEnvFixture.ts +134 -0
- package/test/testHelpers.ts +11 -0
- package/transforms/barrelAnalyzer.ts +26 -4
- package/transforms/barrelImportsPlugin.ts +82 -14
- package/transforms/frameworkObjects.fixture.tsx +58 -0
- package/transforms/frameworkObjects.test.ts +54 -0
- package/transforms/modelReference.test.ts +196 -0
- package/transforms/modelReference.ts +39 -0
- package/transforms/objectImportEdits.ts +150 -0
- package/transforms/objectMemberImports.test.ts +347 -0
- package/transforms/objectMemberImports.ts +537 -0
- package/transforms/objectModule.test.ts +237 -0
- package/transforms/objectModule.ts +458 -0
- package/transforms/objectModuleAnalyzer.ts +104 -0
- package/transforms/reactIconImports.test.ts +231 -0
- package/transforms/reactIconImports.ts +325 -0
- package/transforms/routeConstants.ts +122 -0
- package/transforms/routeRuntime.test.ts +835 -0
- package/transforms/routeRuntime.ts +703 -0
- package/transforms/routeRuntimeEdits.ts +92 -0
- package/transforms/routeRuntimeGraph.ts +66 -0
- package/transforms/routeRuntimePlan.ts +244 -0
- package/transforms/secretEnvDeclaration.test.ts +208 -0
- package/transforms/secretEnvDeclaration.ts +213 -0
- package/transforms/secretEnvFile.test.ts +117 -0
- package/transforms/secretEnvFile.ts +113 -0
- package/transforms/secretEnvName.test.ts +54 -0
- package/transforms/secretEnvName.ts +29 -0
- package/transforms/secretEnvSource.test.ts +148 -0
- package/transforms/secretEnvSource.ts +166 -0
- package/transforms/serverEnvEvaluationError.ts +11 -0
- package/transforms/serverEnvPlugin.test.ts +2 -1
- package/transforms/serverEnvPlugin.ts +13 -0
- package/transforms/serverEnvProfile.test.ts +115 -2
- package/transforms/serverEnvProfile.ts +117 -40
- package/transforms/serverEnvSecrets.test.ts +292 -0
- package/transforms/signalDescriptors.test.ts +280 -0
- package/transforms/signalDescriptors.ts +227 -0
- package/transforms/thisFreeExports.ts +87 -0
- package/transforms/transforms.test.ts +180 -3
- package/transforms/tsconfigPackageResolver.test.ts +1 -0
- package/tunnel/createTunnel.test.ts +29 -8
- package/tunnel/createTunnel.ts +18 -11
- package/typecheck/projectTypecheck.test.ts +29 -0
- package/typecheck/typeChecker.test.ts +49 -0
- package/typecheck/typeChecker.ts +9 -7
- package/typecheck/withheldDiagnostics.ts +41 -0
- package/util/fileEditor.ts +1 -0
- package/util/selectModel.ts +1 -0
- package/workflow/executor.ts +6 -2
- package/workflow/index.ts +1 -0
- package/workflow/plan.ts +36 -7
- package/workflow/types.ts +1 -1
- package/workflow/uiTarget.ts +50 -0
- package/workspace/getRelatedCnsts.ts +7 -0
- package/workspace/scanInfo.ts +1 -1
- package/workspace/workspaceLayout.ts +1 -0
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { hasUseClientDirective } from "./rscUseClientTransform";
|
|
3
|
+
|
|
4
|
+
export type ObjectModuleClause =
|
|
5
|
+
| "bare-import"
|
|
6
|
+
| "reexport"
|
|
7
|
+
| "effect-statement"
|
|
8
|
+
| "call"
|
|
9
|
+
| "effect-value"
|
|
10
|
+
| "mutated-import";
|
|
11
|
+
|
|
12
|
+
export interface ObjectMemberImport {
|
|
13
|
+
specifier: string;
|
|
14
|
+
/** `*` for a namespace import, `default` for a default import. */
|
|
15
|
+
imported: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ObjectShape {
|
|
19
|
+
/**
|
|
20
|
+
* null: a member the analysis cannot point at a file (declared in the object's own file, or computed there).
|
|
21
|
+
* `Doc.Zone` keys a member of an object literal written one level down (`{ Doc: { Zone } }`).
|
|
22
|
+
*/
|
|
23
|
+
members: Map<string, ObjectMemberImport | null>;
|
|
24
|
+
/** Members the analysis cannot list (a spread, a computed key, an object copied in by name). */
|
|
25
|
+
open: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ObjectModuleFacts {
|
|
29
|
+
useClient: boolean;
|
|
30
|
+
failed: { clause: ObjectModuleClause; line: number } | null;
|
|
31
|
+
objects: Map<string, ObjectShape>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ModuleExports {
|
|
35
|
+
names: Set<string>;
|
|
36
|
+
star: boolean;
|
|
37
|
+
useClient: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//? `Object.assign` returns its target, so `const X = Object.assign(Base, …)` and `Base.m = …` change one object.
|
|
41
|
+
interface ObjectRoot {
|
|
42
|
+
literal: ts.ObjectLiteralExpression | null;
|
|
43
|
+
edits: { member: string | null; value: ts.Expression }[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface Collected {
|
|
47
|
+
imports: Map<string, ObjectMemberImport>;
|
|
48
|
+
roots: Map<string, ObjectRoot>;
|
|
49
|
+
exported: Map<string, string>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const STAR_EXPORT_RE = /(?:^|\n)\s*export\s*\*\s*from\b/;
|
|
53
|
+
const ASSIGN_OPERATORS = new Set([
|
|
54
|
+
ts.SyntaxKind.EqualsToken,
|
|
55
|
+
ts.SyntaxKind.PlusEqualsToken,
|
|
56
|
+
ts.SyntaxKind.MinusEqualsToken,
|
|
57
|
+
ts.SyntaxKind.AsteriskEqualsToken,
|
|
58
|
+
ts.SyntaxKind.SlashEqualsToken,
|
|
59
|
+
ts.SyntaxKind.PercentEqualsToken,
|
|
60
|
+
ts.SyntaxKind.AmpersandAmpersandEqualsToken,
|
|
61
|
+
ts.SyntaxKind.BarBarEqualsToken,
|
|
62
|
+
ts.SyntaxKind.QuestionQuestionEqualsToken,
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
//* The rule a module meets before an importer may skip it and import the object's members instead. Every top-level
|
|
66
|
+
//* statement is a declaration (an import that binds names, a type, a directive, a `const` or `function`, an `export`
|
|
67
|
+
//* list) or puts a member on an object the module created above it (`X.m = v`, `Object.assign(X, …)`), and every
|
|
68
|
+
//* value evaluated at load is effect-free (no call but `Object.assign` onto the module's own object). Such a module
|
|
69
|
+
//* only binds names, so an importer that never reaches the object loses nothing by not running it. A re-export fails:
|
|
70
|
+
//* skipping the module would skip the module it re-exports from, which nothing else loads.
|
|
71
|
+
export class ObjectModule {
|
|
72
|
+
static scriptKindOf(file: string): ts.ScriptKind {
|
|
73
|
+
if (file.endsWith(".tsx")) return ts.ScriptKind.TSX;
|
|
74
|
+
if (file.endsWith(".jsx")) return ts.ScriptKind.JSX;
|
|
75
|
+
if (/\.[cm]?js$/.test(file)) return ts.ScriptKind.JS;
|
|
76
|
+
return ts.ScriptKind.TS;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static read(source: string, file: string): ObjectModuleFacts {
|
|
80
|
+
const sourceFile = ts.createSourceFile(
|
|
81
|
+
file,
|
|
82
|
+
source,
|
|
83
|
+
ts.ScriptTarget.Latest,
|
|
84
|
+
false,
|
|
85
|
+
ObjectModule.scriptKindOf(file),
|
|
86
|
+
);
|
|
87
|
+
const reader = new ObjectModule(sourceFile);
|
|
88
|
+
return reader.#facts(hasUseClientDirective(source));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static readonly #tsTranspiler = new Bun.Transpiler({ loader: "ts" });
|
|
92
|
+
static readonly #tsxTranspiler = new Bun.Transpiler({ loader: "tsx" });
|
|
93
|
+
|
|
94
|
+
static exportsOf(source: string, file: string): ModuleExports {
|
|
95
|
+
const jsx = [ts.ScriptKind.TSX, ts.ScriptKind.JSX].includes(ObjectModule.scriptKindOf(file));
|
|
96
|
+
let names: string[] = [];
|
|
97
|
+
try {
|
|
98
|
+
names = (jsx ? ObjectModule.#tsxTranspiler : ObjectModule.#tsTranspiler).scan(source).exports;
|
|
99
|
+
} catch {
|
|
100
|
+
return { names: new Set(), star: true, useClient: hasUseClientDirective(source) };
|
|
101
|
+
}
|
|
102
|
+
return { names: new Set(names), star: STAR_EXPORT_RE.test(source), useClient: hasUseClientDirective(source) };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
readonly #sourceFile: ts.SourceFile;
|
|
106
|
+
readonly #collected: Collected = { imports: new Map(), roots: new Map(), exported: new Map() };
|
|
107
|
+
readonly #objectShadowed: boolean;
|
|
108
|
+
#failed: ObjectModuleFacts["failed"] = null;
|
|
109
|
+
|
|
110
|
+
constructor(sourceFile: ts.SourceFile) {
|
|
111
|
+
this.#sourceFile = sourceFile;
|
|
112
|
+
this.#objectShadowed = ObjectModule.#bindsObject(sourceFile);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
#facts(useClient: boolean): ObjectModuleFacts {
|
|
116
|
+
for (const statement of this.#sourceFile.statements)
|
|
117
|
+
if (ts.isFunctionDeclaration(statement) && statement.body)
|
|
118
|
+
this.#collected.roots.set(statement.name?.text ?? "default", { literal: null, edits: [] });
|
|
119
|
+
for (const statement of this.#sourceFile.statements) this.#collect(statement);
|
|
120
|
+
const objects = new Map<string, ObjectShape>();
|
|
121
|
+
for (const [name, local] of this.#collected.exported) {
|
|
122
|
+
const shape = this.#shapeOf(local);
|
|
123
|
+
if (shape) objects.set(name, shape);
|
|
124
|
+
}
|
|
125
|
+
return { useClient, failed: this.#failed, objects };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
#fail(clause: ObjectModuleClause, node: ts.Node) {
|
|
129
|
+
if (this.#failed) return;
|
|
130
|
+
const line = this.#sourceFile.getLineAndCharacterOfPosition(node.getStart(this.#sourceFile)).line + 1;
|
|
131
|
+
this.#failed = { clause, line };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#collect(statement: ts.Statement) {
|
|
135
|
+
if (ts.isImportDeclaration(statement)) return this.#collectImport(statement);
|
|
136
|
+
if (ts.isExportDeclaration(statement)) return this.#collectExportList(statement);
|
|
137
|
+
if (ObjectModule.#isTypeOnly(statement)) return;
|
|
138
|
+
if (ts.isExpressionStatement(statement)) return this.#collectExpression(statement);
|
|
139
|
+
if (ts.isFunctionDeclaration(statement)) {
|
|
140
|
+
const name = statement.name?.text ?? "default";
|
|
141
|
+
if (ObjectModule.#hasModifier(statement, ts.SyntaxKind.DefaultKeyword))
|
|
142
|
+
this.#collected.exported.set("default", name);
|
|
143
|
+
else if (ObjectModule.#hasModifier(statement, ts.SyntaxKind.ExportKeyword))
|
|
144
|
+
this.#collected.exported.set(name, name);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (ts.isVariableStatement(statement)) return this.#collectVariables(statement);
|
|
148
|
+
if (ts.isExportAssignment(statement) && !statement.isExportEquals) return this.#checkValue(statement.expression);
|
|
149
|
+
this.#fail("effect-statement", statement);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
#collectImport(statement: ts.ImportDeclaration) {
|
|
153
|
+
const clause = statement.importClause;
|
|
154
|
+
if (!clause) return this.#fail("bare-import", statement);
|
|
155
|
+
if (clause.phaseModifier === ts.SyntaxKind.TypeKeyword || !ts.isStringLiteral(statement.moduleSpecifier)) return;
|
|
156
|
+
const bindings = clause.namedBindings;
|
|
157
|
+
if (!clause.name && bindings && ts.isNamedImports(bindings) && bindings.elements.length === 0)
|
|
158
|
+
return this.#fail("bare-import", statement);
|
|
159
|
+
const specifier = statement.moduleSpecifier.text;
|
|
160
|
+
const { imports } = this.#collected;
|
|
161
|
+
if (clause.name) imports.set(clause.name.text, { specifier, imported: "default" });
|
|
162
|
+
if (!bindings) return;
|
|
163
|
+
if (ts.isNamespaceImport(bindings)) {
|
|
164
|
+
imports.set(bindings.name.text, { specifier, imported: "*" });
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
for (const element of bindings.elements) {
|
|
168
|
+
if (element.isTypeOnly) continue;
|
|
169
|
+
imports.set(element.name.text, { specifier, imported: (element.propertyName ?? element.name).text });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
#collectExportList(statement: ts.ExportDeclaration) {
|
|
174
|
+
if (statement.isTypeOnly) return;
|
|
175
|
+
const clause = statement.exportClause;
|
|
176
|
+
if (statement.moduleSpecifier) {
|
|
177
|
+
const named = clause && ts.isNamedExports(clause) ? clause.elements : [];
|
|
178
|
+
if (named.length === 0 || named.some((element) => !element.isTypeOnly)) this.#fail("reexport", statement);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (!clause || !ts.isNamedExports(clause)) return;
|
|
182
|
+
for (const element of clause.elements) {
|
|
183
|
+
if (element.isTypeOnly) continue;
|
|
184
|
+
this.#collected.exported.set(element.name.text, (element.propertyName ?? element.name).text);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
#collectExpression(statement: ts.ExpressionStatement) {
|
|
189
|
+
const expression = ObjectModule.#unwrap(statement.expression);
|
|
190
|
+
if (ts.isStringLiteral(expression)) return;
|
|
191
|
+
if (
|
|
192
|
+
ts.isBinaryExpression(expression) &&
|
|
193
|
+
expression.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
194
|
+
ts.isPropertyAccessExpression(expression.left) &&
|
|
195
|
+
ts.isIdentifier(expression.left.expression)
|
|
196
|
+
) {
|
|
197
|
+
const root = this.#rootNamed(expression.left.expression, "effect-statement");
|
|
198
|
+
this.#checkValue(expression.right);
|
|
199
|
+
root?.edits.push({ member: expression.left.name.text, value: expression.right });
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const assign = this.#objectAssignOf(expression);
|
|
203
|
+
const target = assign?.[0];
|
|
204
|
+
if (assign && target) {
|
|
205
|
+
const root = this.#rootNamed(target, "effect-statement");
|
|
206
|
+
for (const source of assign.slice(1)) {
|
|
207
|
+
this.#checkValue(source);
|
|
208
|
+
root?.edits.push({ member: null, value: source });
|
|
209
|
+
}
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
this.#fail("effect-statement", statement);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
#collectVariables(statement: ts.VariableStatement) {
|
|
216
|
+
if (ObjectModule.#hasModifier(statement, ts.SyntaxKind.DeclareKeyword)) return;
|
|
217
|
+
if (!(statement.declarationList.flags & ts.NodeFlags.Const)) return this.#fail("effect-statement", statement);
|
|
218
|
+
const exported = ObjectModule.#hasModifier(statement, ts.SyntaxKind.ExportKeyword);
|
|
219
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
220
|
+
if (!ts.isIdentifier(declaration.name) || !declaration.initializer) {
|
|
221
|
+
this.#fail("effect-statement", declaration);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const root = this.#rootOf(declaration.initializer);
|
|
225
|
+
if (root) this.#collected.roots.set(declaration.name.text, root);
|
|
226
|
+
if (exported) this.#collected.exported.set(declaration.name.text, declaration.name.text);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
#rootOf(node: ts.Expression): ObjectRoot | null {
|
|
231
|
+
const value = ObjectModule.#unwrap(node);
|
|
232
|
+
const assign = this.#objectAssignOf(value);
|
|
233
|
+
if (!assign) {
|
|
234
|
+
this.#checkValue(value);
|
|
235
|
+
if (ts.isObjectLiteralExpression(value)) return { literal: value, edits: [] };
|
|
236
|
+
return ObjectModule.#isFunction(value) ? { literal: null, edits: [] } : null;
|
|
237
|
+
}
|
|
238
|
+
const [target, ...sources] = assign;
|
|
239
|
+
if (!target) {
|
|
240
|
+
this.#fail("call", value);
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
const unwrapped = ObjectModule.#unwrap(target);
|
|
244
|
+
const fresh = ts.isObjectLiteralExpression(unwrapped) || ObjectModule.#isFunction(unwrapped);
|
|
245
|
+
if (!fresh) this.#checkValue(unwrapped);
|
|
246
|
+
const root = fresh ? this.#rootOf(unwrapped) : this.#rootNamed(unwrapped, "effect-value");
|
|
247
|
+
for (const source of sources) {
|
|
248
|
+
this.#checkValue(source);
|
|
249
|
+
root?.edits.push({ member: null, value: source });
|
|
250
|
+
}
|
|
251
|
+
return root;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
#rootNamed(node: ts.Expression, otherwise: ObjectModuleClause): ObjectRoot | null {
|
|
255
|
+
const target = ObjectModule.#unwrap(node);
|
|
256
|
+
const root = ts.isIdentifier(target) ? this.#collected.roots.get(target.text) : undefined;
|
|
257
|
+
if (root) return root;
|
|
258
|
+
this.#fail(this.#isImportBased(target) ? "mutated-import" : otherwise, node);
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
#isImportBased(node: ts.Expression) {
|
|
263
|
+
let current = ObjectModule.#unwrap(node);
|
|
264
|
+
while (ts.isPropertyAccessExpression(current) || ts.isElementAccessExpression(current))
|
|
265
|
+
current = ObjectModule.#unwrap(current.expression);
|
|
266
|
+
return ts.isIdentifier(current) && this.#collected.imports.has(current.text);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
#checkValue(node: ts.Expression): void {
|
|
270
|
+
const value = ObjectModule.#unwrap(node);
|
|
271
|
+
const assign = this.#objectAssignOf(value);
|
|
272
|
+
if (assign) this.#checkObjectAssign(assign, value);
|
|
273
|
+
else if (ts.isObjectLiteralExpression(value)) this.#checkObjectLiteral(value);
|
|
274
|
+
else {
|
|
275
|
+
const parts = ObjectModule.#partsOf(value);
|
|
276
|
+
if (typeof parts === "string") this.#fail(parts, value);
|
|
277
|
+
else for (const part of parts) this.#checkValue(part);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
static #partsOf(value: ts.Expression): ts.Expression[] | ObjectModuleClause {
|
|
282
|
+
if (
|
|
283
|
+
ts.isIdentifier(value) ||
|
|
284
|
+
ts.isLiteralExpression(value) ||
|
|
285
|
+
ts.isArrowFunction(value) ||
|
|
286
|
+
ts.isFunctionExpression(value) ||
|
|
287
|
+
[ts.SyntaxKind.TrueKeyword, ts.SyntaxKind.FalseKeyword, ts.SyntaxKind.NullKeyword].includes(value.kind)
|
|
288
|
+
)
|
|
289
|
+
return [];
|
|
290
|
+
if (ts.isTemplateExpression(value)) return value.templateSpans.map((span) => span.expression);
|
|
291
|
+
if (ts.isArrayLiteralExpression(value))
|
|
292
|
+
return value.elements
|
|
293
|
+
.filter((element) => !ts.isOmittedExpression(element))
|
|
294
|
+
.map((element) => (ts.isSpreadElement(element) ? element.expression : element));
|
|
295
|
+
if (ts.isPropertyAccessExpression(value)) return [value.expression];
|
|
296
|
+
if (ts.isElementAccessExpression(value)) return [value.expression, value.argumentExpression];
|
|
297
|
+
if (ts.isConditionalExpression(value)) return [value.condition, value.whenTrue, value.whenFalse];
|
|
298
|
+
if (ts.isBinaryExpression(value))
|
|
299
|
+
return ASSIGN_OPERATORS.has(value.operatorToken.kind) ? "effect-value" : [value.left, value.right];
|
|
300
|
+
if (ts.isPrefixUnaryExpression(value))
|
|
301
|
+
return [ts.SyntaxKind.PlusPlusToken, ts.SyntaxKind.MinusMinusToken].includes(value.operator)
|
|
302
|
+
? "effect-value"
|
|
303
|
+
: [value.operand];
|
|
304
|
+
if (ts.isTypeOfExpression(value) || ts.isVoidExpression(value)) return [value.expression];
|
|
305
|
+
if (ts.isCallExpression(value) || ts.isNewExpression(value) || ts.isTaggedTemplateExpression(value)) return "call";
|
|
306
|
+
return "effect-value";
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
#checkObjectLiteral(value: ts.ObjectLiteralExpression): void {
|
|
310
|
+
for (const property of value.properties) {
|
|
311
|
+
if (property.name && ts.isComputedPropertyName(property.name)) this.#checkValue(property.name.expression);
|
|
312
|
+
if (ts.isPropertyAssignment(property)) this.#checkValue(property.initializer);
|
|
313
|
+
else if (ts.isSpreadAssignment(property)) this.#checkValue(property.expression);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
//? Below a `const`, `Object.assign` may only fill a fresh object: one of the module's own would change unrecorded.
|
|
318
|
+
#checkObjectAssign(args: ts.Expression[], node: ts.Node): void {
|
|
319
|
+
const [target, ...sources] = args;
|
|
320
|
+
if (!target) {
|
|
321
|
+
this.#fail("call", node);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const unwrapped = ObjectModule.#unwrap(target);
|
|
325
|
+
this.#checkValue(unwrapped);
|
|
326
|
+
if (!ts.isObjectLiteralExpression(unwrapped) && !ObjectModule.#isFunction(unwrapped))
|
|
327
|
+
this.#fail(this.#isImportBased(unwrapped) ? "mutated-import" : "effect-value", node);
|
|
328
|
+
for (const source of sources) this.#checkValue(source);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
#shapeOf(local: string): ObjectShape | null {
|
|
332
|
+
const root = this.#collected.roots.get(local);
|
|
333
|
+
if (!root || (!root.literal && root.edits.length === 0)) return null;
|
|
334
|
+
const shape: ObjectShape = { members: new Map(), open: false };
|
|
335
|
+
if (root.literal) this.#addLiteral(shape, root.literal);
|
|
336
|
+
for (const { member, value } of root.edits) {
|
|
337
|
+
if (member === null) this.#addSource(shape, value);
|
|
338
|
+
else ObjectModule.#setMember(shape, member, this.#memberOf(value));
|
|
339
|
+
}
|
|
340
|
+
return shape;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
static #setMember(shape: ObjectShape, key: string, member: ObjectMemberImport | null) {
|
|
344
|
+
for (const known of shape.members.keys()) if (known.startsWith(`${key}.`)) shape.members.delete(known);
|
|
345
|
+
shape.members.set(key, member);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
//? A spread or computed key may overwrite any member listed before it, so none of those still names a file.
|
|
349
|
+
static #cover(shape: ObjectShape, prefix: string) {
|
|
350
|
+
if (!prefix) shape.open = true;
|
|
351
|
+
for (const key of shape.members.keys()) if (key.startsWith(prefix)) shape.members.set(key, null);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
//? `Object.assign` copies a source's own enumerable members: none from a function nothing put a member on.
|
|
355
|
+
#addSource(shape: ObjectShape, node: ts.Expression) {
|
|
356
|
+
const value = ObjectModule.#unwrap(node);
|
|
357
|
+
if (ts.isObjectLiteralExpression(value)) return this.#addLiteral(shape, value);
|
|
358
|
+
if (ObjectModule.#isFunction(value)) return;
|
|
359
|
+
const root = ts.isIdentifier(value) ? this.#collected.roots.get(value.text) : undefined;
|
|
360
|
+
if (!root || root.literal || root.edits.length > 0) ObjectModule.#cover(shape, "");
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
static #isFunction(value: ts.Expression) {
|
|
364
|
+
return ts.isArrowFunction(value) || ts.isFunctionExpression(value);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
#addLiteral(shape: ObjectShape, literal: ts.ObjectLiteralExpression, prefix = "") {
|
|
368
|
+
for (const property of literal.properties) {
|
|
369
|
+
const name = ts.isSpreadAssignment(property) ? null : ObjectModule.#keyOf(property.name);
|
|
370
|
+
if (name === null) {
|
|
371
|
+
ObjectModule.#cover(shape, prefix);
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
const key = `${prefix}${name}`;
|
|
375
|
+
const value = ts.isPropertyAssignment(property) ? ObjectModule.#unwrap(property.initializer) : null;
|
|
376
|
+
if (name.includes(".")) ObjectModule.#setMember(shape, key, null);
|
|
377
|
+
else if (value && ts.isObjectLiteralExpression(value) && !prefix) {
|
|
378
|
+
ObjectModule.#setMember(shape, key, null);
|
|
379
|
+
this.#addLiteral(shape, value, `${key}.`);
|
|
380
|
+
} else if (value) ObjectModule.#setMember(shape, key, this.#memberOf(value));
|
|
381
|
+
else if (ts.isShorthandPropertyAssignment(property))
|
|
382
|
+
ObjectModule.#setMember(shape, key, this.#memberOf(property.name));
|
|
383
|
+
else ObjectModule.#setMember(shape, key, null);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
#memberOf(node: ts.Expression): ObjectMemberImport | null {
|
|
388
|
+
const value = ObjectModule.#unwrap(node);
|
|
389
|
+
if (ts.isIdentifier(value)) return this.#collected.imports.get(value.text) ?? null;
|
|
390
|
+
if (ts.isPropertyAccessExpression(value) && ts.isIdentifier(value.expression)) {
|
|
391
|
+
const namespace = this.#collected.imports.get(value.expression.text);
|
|
392
|
+
if (namespace?.imported === "*") return { specifier: namespace.specifier, imported: value.name.text };
|
|
393
|
+
}
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
static #keyOf(name: ts.PropertyName | undefined): string | null {
|
|
398
|
+
if (!name) return null;
|
|
399
|
+
if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name)) return name.text;
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
#objectAssignOf(node: ts.Expression): ts.Expression[] | null {
|
|
404
|
+
if (this.#objectShadowed || !ts.isCallExpression(node)) return null;
|
|
405
|
+
const callee = node.expression;
|
|
406
|
+
if (!ts.isPropertyAccessExpression(callee) || callee.name.text !== "assign") return null;
|
|
407
|
+
if (!ts.isIdentifier(callee.expression) || callee.expression.text !== "Object") return null;
|
|
408
|
+
if (node.arguments.some((arg) => ts.isSpreadElement(arg))) return null;
|
|
409
|
+
return [...node.arguments];
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
static #unwrap(node: ts.Expression): ts.Expression {
|
|
413
|
+
let current = node;
|
|
414
|
+
while (
|
|
415
|
+
ts.isParenthesizedExpression(current) ||
|
|
416
|
+
ts.isAsExpression(current) ||
|
|
417
|
+
ts.isSatisfiesExpression(current) ||
|
|
418
|
+
ts.isNonNullExpression(current) ||
|
|
419
|
+
ts.isTypeAssertionExpression(current)
|
|
420
|
+
)
|
|
421
|
+
current = current.expression;
|
|
422
|
+
return current;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
static #hasModifier(node: ts.Node, kind: ts.SyntaxKind) {
|
|
426
|
+
return ts.canHaveModifiers(node) && (ts.getModifiers(node) ?? []).some((modifier) => modifier.kind === kind);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
static #bindsObject(sourceFile: ts.SourceFile) {
|
|
430
|
+
const names: (ts.Node | undefined)[] = [];
|
|
431
|
+
for (const statement of sourceFile.statements) {
|
|
432
|
+
if (ts.isImportDeclaration(statement)) {
|
|
433
|
+
const bindings = statement.importClause?.namedBindings;
|
|
434
|
+
names.push(statement.importClause?.name);
|
|
435
|
+
if (bindings && ts.isNamespaceImport(bindings)) names.push(bindings.name);
|
|
436
|
+
else if (bindings) names.push(...bindings.elements.map((element) => element.name));
|
|
437
|
+
} else if (ts.isVariableStatement(statement))
|
|
438
|
+
names.push(...statement.declarationList.declarations.map((declaration) => declaration.name));
|
|
439
|
+
else if (
|
|
440
|
+
ts.isFunctionDeclaration(statement) ||
|
|
441
|
+
ts.isClassDeclaration(statement) ||
|
|
442
|
+
ts.isEnumDeclaration(statement) ||
|
|
443
|
+
ts.isModuleDeclaration(statement) ||
|
|
444
|
+
ts.isImportEqualsDeclaration(statement)
|
|
445
|
+
)
|
|
446
|
+
names.push(statement.name);
|
|
447
|
+
}
|
|
448
|
+
return names.some((name) => name !== undefined && ts.isIdentifier(name) && name.text === "Object");
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
static #isTypeOnly(statement: ts.Statement) {
|
|
452
|
+
if (ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement)) return true;
|
|
453
|
+
if (ObjectModule.#hasModifier(statement, ts.SyntaxKind.DeclareKeyword)) return true;
|
|
454
|
+
if (ts.isEnumDeclaration(statement)) return ObjectModule.#hasModifier(statement, ts.SyntaxKind.ConstKeyword);
|
|
455
|
+
if (ts.isFunctionDeclaration(statement)) return !statement.body;
|
|
456
|
+
return ts.isEmptyStatement(statement);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { stat } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { type ModuleExports, ObjectModule, type ObjectModuleFacts } from "./objectModule";
|
|
5
|
+
import { ThisFreeExports } from "./thisFreeExports";
|
|
6
|
+
|
|
7
|
+
const MODULE_EXTS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"];
|
|
8
|
+
|
|
9
|
+
const isFile = async (file: string) => {
|
|
10
|
+
try {
|
|
11
|
+
return (await stat(file)).isFile();
|
|
12
|
+
} catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//? A part file's name has a dot of its own (`./Memo.Zone`), so a specifier with an extension is tried bare and with one.
|
|
18
|
+
export const resolveModuleFile = async (fromFile: string, specifier: string): Promise<string | null> => {
|
|
19
|
+
const joined = path.resolve(path.dirname(fromFile), specifier);
|
|
20
|
+
const candidates = [
|
|
21
|
+
joined,
|
|
22
|
+
...MODULE_EXTS.map((ext) => `${joined}${ext}`),
|
|
23
|
+
...MODULE_EXTS.map((ext) => path.join(joined, `index${ext}`)),
|
|
24
|
+
];
|
|
25
|
+
for (const candidate of candidates) if (await isFile(candidate)) return candidate;
|
|
26
|
+
return null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export class ObjectModuleAnalyzer {
|
|
30
|
+
readonly #facts = new Map<string, Promise<ObjectModuleFacts | null>>();
|
|
31
|
+
readonly #exports = new Map<string, Promise<ModuleExports | null>>();
|
|
32
|
+
readonly #thisFree = new Map<string, Promise<Set<string>>>();
|
|
33
|
+
|
|
34
|
+
facts(file: string): Promise<ObjectModuleFacts | null> {
|
|
35
|
+
const key = ObjectModuleAnalyzer.#keyOf(file);
|
|
36
|
+
let facts = this.#facts.get(key);
|
|
37
|
+
if (!facts) {
|
|
38
|
+
facts = ObjectModuleAnalyzer.#text(file).then((source) => {
|
|
39
|
+
if (source === null || !/\bexport\b/.test(source)) return null;
|
|
40
|
+
try {
|
|
41
|
+
return ObjectModule.read(source, file);
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
this.#facts.set(key, facts);
|
|
47
|
+
}
|
|
48
|
+
return facts;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
exportsOf(file: string): Promise<ModuleExports | null> {
|
|
52
|
+
const key = ObjectModuleAnalyzer.#keyOf(file);
|
|
53
|
+
let exports = this.#exports.get(key);
|
|
54
|
+
if (!exports) {
|
|
55
|
+
exports = ObjectModuleAnalyzer.#text(file).then((source) =>
|
|
56
|
+
source === null ? null : ObjectModule.exportsOf(source, file),
|
|
57
|
+
);
|
|
58
|
+
this.#exports.set(key, exports);
|
|
59
|
+
}
|
|
60
|
+
return exports;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
thisFreeOf(file: string): Promise<Set<string>> {
|
|
64
|
+
const key = ObjectModuleAnalyzer.#keyOf(file);
|
|
65
|
+
let names = this.#thisFree.get(key);
|
|
66
|
+
if (!names) {
|
|
67
|
+
names = ObjectModuleAnalyzer.#text(file).then((source) => {
|
|
68
|
+
if (source === null) return new Set<string>();
|
|
69
|
+
try {
|
|
70
|
+
return ThisFreeExports.read(source, file);
|
|
71
|
+
} catch {
|
|
72
|
+
return new Set<string>();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
this.#thisFree.set(key, names);
|
|
76
|
+
}
|
|
77
|
+
return names;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
forget(files: Iterable<string>) {
|
|
81
|
+
for (const file of files) {
|
|
82
|
+
const key = ObjectModuleAnalyzer.#keyOf(file);
|
|
83
|
+
this.#facts.delete(key);
|
|
84
|
+
this.#exports.delete(key);
|
|
85
|
+
this.#thisFree.delete(key);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static #keyOf(file: string) {
|
|
90
|
+
try {
|
|
91
|
+
return fs.realpathSync.native(file);
|
|
92
|
+
} catch {
|
|
93
|
+
return file;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static async #text(file: string): Promise<string | null> {
|
|
98
|
+
try {
|
|
99
|
+
return await Bun.file(file).text();
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|