@akanjs/devkit 3.3.0-rc.5 → 3.3.0-rc.50
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 +650 -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 +70 -10
- package/akanConfig/akanConfig.ts +57 -206
- package/akanConfig/akanWorkers.test.ts +39 -0
- package/akanConfig/akanWorkers.ts +32 -0
- package/akanConfig/desktopServerConfig.ts +96 -0
- package/akanConfig/dockerImage.ts +39 -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 +49 -0
- package/app/applicationBuildReporter.ts +5 -0
- package/app/applicationBuildRunner.test.ts +275 -0
- package/app/applicationBuildRunner.ts +149 -12
- package/app/dictionarySizes.ts +91 -0
- package/app/routeFilesReport.test.ts +59 -0
- package/app/routeFilesReport.ts +46 -0
- package/app/routeJsBudget.ts +18 -4
- 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 +64 -8
- package/biome.base.json +6 -2
- 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 +34 -26
- 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 +10 -11
- 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/csrE2e/devHmrLatency.e2e.test.ts +1 -1
- package/docs/apiReference.test.ts +9 -0
- package/docs/apiReference.ts +14 -0
- package/executors/appExecutor.ts +3 -1
- package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
- package/executors/clientRuntimeKeys.fixture.json +393 -0
- package/executors/clientRuntimeKeys.test.ts +1690 -0
- package/executors/executor.ts +12 -4
- package/executors/executors.test.ts +2 -0
- package/executors/sysExecutor.ts +70 -4
- package/executors/workspaceExecutor.ts +7 -4
- package/frontendBuild/allRoutesBuilder.ts +99 -7
- package/frontendBuild/autoImportSync.ts +3 -2
- package/frontendBuild/buildRouteClient.test.ts +686 -13
- package/frontendBuild/clientBuildTypes.ts +26 -0
- package/frontendBuild/clientEntriesBundler.ts +49 -1
- package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
- package/frontendBuild/clientEntryDiscovery.ts +136 -14
- package/frontendBuild/clientEntryGroups.test.ts +77 -0
- package/frontendBuild/clientEntryGroups.ts +61 -0
- package/frontendBuild/csrDevArtifactWriter.ts +2 -2
- package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
- package/frontendBuild/csrDevModuleCompiler.ts +44 -8
- package/frontendBuild/csrDevPatcher.test.ts +1 -1
- package/frontendBuild/csrDevPatcher.ts +33 -7
- package/frontendBuild/csrDevTypes.ts +9 -0
- package/frontendBuild/devBarrelImports.test.ts +154 -0
- package/frontendBuild/devBarrelImports.ts +83 -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 +329 -0
- package/frontendBuild/dictionaryAssetBuilder.ts +165 -16
- package/frontendBuild/dictionaryConstants.ts +136 -0
- package/frontendBuild/dictionaryPacking.test.ts +142 -0
- package/frontendBuild/dictionaryPacking.ts +135 -0
- package/frontendBuild/dictionaryRoutes.test.ts +251 -0
- package/frontendBuild/dictionaryRoutes.ts +227 -0
- package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
- package/frontendBuild/pagesBundleBuilder.ts +81 -3
- package/frontendBuild/precompressArtifacts.test.ts +22 -0
- package/frontendBuild/precompressArtifacts.ts +22 -8
- package/frontendBuild/registryMetadataFingerprint.ts +3 -3
- package/frontendBuild/renderedEntries.ts +144 -0
- package/frontendBuild/routeClientBuilder.ts +407 -43
- package/frontendBuild/routeHandoffs.test.ts +155 -0
- package/frontendBuild/routeHandoffs.ts +117 -0
- package/frontendBuild/routeModulePreloads.test.ts +32 -0
- package/frontendBuild/routeModulePreloads.ts +20 -11
- package/frontendBuild/routeRuntimeCheck.test.ts +280 -0
- package/frontendBuild/routeRuntimeCheck.ts +248 -0
- package/frontendBuild/routeRuntimePays.test.ts +143 -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/biomeBase.test.ts +21 -2
- package/lint/biomeBase.ts +1 -1
- package/lint/biomeCheck.test.ts +162 -0
- package/lint/biomeCheck.ts +131 -0
- package/lint/linter.test.ts +16 -11
- 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.test.ts +9 -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/nativePublicEnv.ts +1 -1
- package/mobile/serverBundleSecrets.ts +43 -0
- package/package.json +15 -169
- package/packageExports.test.ts +38 -24
- package/quality/dictionaryKeys.test.ts +356 -0
- package/quality/dictionaryKeys.ts +488 -0
- package/quality/objectImportReport.test.ts +36 -0
- package/quality/objectImportReport.ts +105 -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/quality/translatorBindings.ts +187 -0
- package/test/secretEnvFixture.ts +134 -0
- package/test/testHelpers.ts +11 -0
- package/transforms/barrelAnalyzer.ts +26 -4
- package/transforms/barrelImportsPlugin.ts +121 -32
- package/transforms/exportReach.test.ts +162 -0
- package/transforms/exportReach.ts +308 -0
- 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/moduleParts.test.ts +225 -0
- package/transforms/moduleParts.ts +418 -0
- package/transforms/objectImportEdits.ts +150 -0
- package/transforms/objectMemberImports.test.ts +633 -0
- package/transforms/objectMemberImports.ts +571 -0
- package/transforms/objectMemberLookup.ts +150 -0
- package/transforms/objectModule.test.ts +307 -0
- package/transforms/objectModule.ts +482 -0
- package/transforms/objectModuleAnalyzer.ts +104 -0
- package/transforms/partImports.test.ts +76 -0
- package/transforms/partImports.ts +110 -0
- package/transforms/partModules.test.ts +187 -0
- package/transforms/partModules.ts +90 -0
- package/transforms/partPurity.ts +124 -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.test.ts +39 -0
- package/workspace/scanInfo.ts +48 -5
- package/workspace/slicePlanner.ts +1 -1
- package/workspace/workspaceLayout.ts +1 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { BarrelAnalyzer } from "./barrelAnalyzer";
|
|
2
|
+
import type { ObjectKeepReason, ObjectMemberImportsOptions } from "./objectMemberImports";
|
|
3
|
+
import type { ObjectMemberImport, ObjectModuleFacts, ObjectShape } from "./objectModule";
|
|
4
|
+
import type { ObjectModuleAnalyzer } from "./objectModuleAnalyzer";
|
|
5
|
+
|
|
6
|
+
export interface ObjectBarrels {
|
|
7
|
+
names: readonly string[];
|
|
8
|
+
analyzer: BarrelAnalyzer;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ObjectSource {
|
|
12
|
+
file: string;
|
|
13
|
+
object: string;
|
|
14
|
+
facts: ObjectModuleFacts;
|
|
15
|
+
shape: ObjectShape;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ObjectMemberOwner {
|
|
19
|
+
/** The object module that lists the member, which the member's specifier is relative to. */
|
|
20
|
+
file: string;
|
|
21
|
+
member: ObjectMemberImport;
|
|
22
|
+
nested: boolean;
|
|
23
|
+
/** Whether the object module the importer names, the one that lists the member or one between is `"use client"`. */
|
|
24
|
+
useClient: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ObjectLookupRead {
|
|
28
|
+
files: Set<string>;
|
|
29
|
+
barrels: Set<string>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type ObjectCopyLink = [module: string, specifier: string, imported: string, file: string | null, object: string | null];
|
|
33
|
+
|
|
34
|
+
export interface ObjectCopyReach {
|
|
35
|
+
modules: string[];
|
|
36
|
+
barrelFiles: string[];
|
|
37
|
+
links: ObjectCopyLink[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const MAX_COPY_DEPTH = 4;
|
|
41
|
+
|
|
42
|
+
const keyOf = ({ file, object }: Pick<ObjectSource, "file" | "object">) => `${file}#${object}`;
|
|
43
|
+
|
|
44
|
+
//* Finds the object module that lists a member an importer names. A member the object's own shape does not list may
|
|
45
|
+
//* come from an imported object `Object.assign` copied in (`Object.assign(Section, Field, { Rich })`), read from that
|
|
46
|
+
//* object's module, last copy first as the later source wins.
|
|
47
|
+
export class ObjectMemberLookup {
|
|
48
|
+
readonly #modules: ObjectModuleAnalyzer;
|
|
49
|
+
readonly #resolve: ObjectMemberImportsOptions["resolve"];
|
|
50
|
+
readonly #barrels: ObjectBarrels | null;
|
|
51
|
+
|
|
52
|
+
constructor(
|
|
53
|
+
modules: ObjectModuleAnalyzer,
|
|
54
|
+
resolve: ObjectMemberImportsOptions["resolve"],
|
|
55
|
+
barrels: ObjectBarrels | null = null,
|
|
56
|
+
) {
|
|
57
|
+
this.#modules = modules;
|
|
58
|
+
this.#resolve = resolve;
|
|
59
|
+
this.#barrels = barrels;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async find(
|
|
63
|
+
source: ObjectSource,
|
|
64
|
+
memberPath: string[],
|
|
65
|
+
read: ObjectLookupRead,
|
|
66
|
+
): Promise<ObjectMemberOwner | ObjectKeepReason> {
|
|
67
|
+
return (await this.#find(source, memberPath, read, [])) ?? "unresolved-member";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async namesFile(source: ObjectSource, read: ObjectLookupRead, above: string[] = []): Promise<boolean> {
|
|
71
|
+
if ([...source.shape.members.values()].some(Boolean)) return true;
|
|
72
|
+
const path = [...above, keyOf(source)];
|
|
73
|
+
if (source.shape.open || path.length > MAX_COPY_DEPTH) return false;
|
|
74
|
+
for (const copied of source.shape.copied) {
|
|
75
|
+
const from = await this.#copiedSource(source.file, copied, read);
|
|
76
|
+
if (from && !path.includes(keyOf(from)) && (await this.namesFile(from, read, path))) return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async reach(file: string): Promise<ObjectCopyReach> {
|
|
82
|
+
const read: ObjectLookupRead = { files: new Set([file]), barrels: new Set() };
|
|
83
|
+
const links: ObjectCopyLink[] = [];
|
|
84
|
+
for (const module of read.files) {
|
|
85
|
+
const facts = await this.#modules.facts(module);
|
|
86
|
+
for (const shape of facts?.objects.values() ?? [])
|
|
87
|
+
for (const copied of shape.copied) {
|
|
88
|
+
const declared = await this.#declarationOf(copied, read);
|
|
89
|
+
const from = declared && (await this.#resolve(declared.specifier, module));
|
|
90
|
+
if (from) read.files.add(from);
|
|
91
|
+
links.push([module, copied.specifier, copied.imported, from ?? null, declared?.imported ?? null]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const barrelFiles = await Promise.all([...read.barrels].map((barrel) => this.#barrels?.analyzer.filesOf(barrel)));
|
|
95
|
+
return { modules: [...read.files], barrelFiles: barrelFiles.flatMap((files) => files ?? []), links };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//? null: the object holds no such member, so an object copied in before it may.
|
|
99
|
+
async #find(
|
|
100
|
+
source: ObjectSource,
|
|
101
|
+
memberPath: string[],
|
|
102
|
+
read: ObjectLookupRead,
|
|
103
|
+
above: string[],
|
|
104
|
+
): Promise<ObjectMemberOwner | ObjectKeepReason | null> {
|
|
105
|
+
const { file, facts, shape } = source;
|
|
106
|
+
const [name, inner] = memberPath;
|
|
107
|
+
if (name === undefined) return "unresolved-member";
|
|
108
|
+
const nestedKey = inner === undefined ? null : `${name}.${inner}`;
|
|
109
|
+
if (shape.members.has(name) || (nestedKey !== null && shape.members.has(nestedKey))) {
|
|
110
|
+
const nested = nestedKey === null ? null : shape.members.get(nestedKey);
|
|
111
|
+
const member = nested ?? shape.members.get(name);
|
|
112
|
+
return member ? { file, member, nested: !!nested, useClient: facts.useClient } : "unresolved-member";
|
|
113
|
+
}
|
|
114
|
+
if (shape.open) return "unresolved-member";
|
|
115
|
+
const path = [...above, keyOf(source)];
|
|
116
|
+
for (const copied of [...shape.copied].reverse()) {
|
|
117
|
+
const from = await this.#copiedSource(file, copied, read);
|
|
118
|
+
if (!from || path.includes(keyOf(from)) || path.length > MAX_COPY_DEPTH) return "unresolved-member";
|
|
119
|
+
//? Naming the member's file skips this module as well as the one that copies from it.
|
|
120
|
+
if (from.facts.failed) return from.facts.failed.clause;
|
|
121
|
+
const found = await this.#find(from, memberPath, read, path);
|
|
122
|
+
if (found === null) continue;
|
|
123
|
+
return typeof found === "string" ? found : { ...found, useClient: found.useClient || facts.useClient };
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async #copiedSource(
|
|
129
|
+
importer: string,
|
|
130
|
+
copied: ObjectMemberImport,
|
|
131
|
+
read: ObjectLookupRead,
|
|
132
|
+
): Promise<ObjectSource | null> {
|
|
133
|
+
const declared = await this.#declarationOf(copied, read);
|
|
134
|
+
const file = declared && (await this.#resolve(declared.specifier, importer));
|
|
135
|
+
if (!declared || !file) return null;
|
|
136
|
+
read.files.add(file);
|
|
137
|
+
const facts = await this.#modules.facts(file);
|
|
138
|
+
const shape = facts?.objects.get(declared.imported);
|
|
139
|
+
return facts && shape ? { file, object: declared.imported, facts, shape } : null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
//? Followed as `rewriteBarrelImports` rewrites an importer's own import, so every caller finds the object at one file.
|
|
143
|
+
async #declarationOf(copied: ObjectMemberImport, read: ObjectLookupRead): Promise<ObjectMemberImport | null> {
|
|
144
|
+
if (!this.#barrels?.names.includes(copied.specifier) || copied.imported === "default") return copied;
|
|
145
|
+
read.barrels.add(copied.specifier);
|
|
146
|
+
const target = (await this.#barrels.analyzer.analyze(copied.specifier))?.get(copied.imported);
|
|
147
|
+
if (!target) return copied;
|
|
148
|
+
return target.namespace ? null : { specifier: target.subpath, imported: target.originalName };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { ObjectModule } from "./objectModule";
|
|
3
|
+
|
|
4
|
+
const read = (lines: string[], file = "index.tsx") => ObjectModule.read(lines.join("\n"), file);
|
|
5
|
+
const membersOf = (lines: string[], object: string) =>
|
|
6
|
+
Object.fromEntries(read(lines).objects.get(object)?.members ?? []);
|
|
7
|
+
|
|
8
|
+
describe("ObjectModule: a module an importer may skip for the members it names", () => {
|
|
9
|
+
test("passes the model index akan sync writes", () => {
|
|
10
|
+
const facts = read([
|
|
11
|
+
'import * as Template from "./Memo.Template";',
|
|
12
|
+
'import * as Unit from "./Memo.Unit";',
|
|
13
|
+
'import * as Zone from "./Memo.Zone";',
|
|
14
|
+
"export const Memo = { Template, Unit, Zone };",
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
expect(facts.failed).toBeNull();
|
|
18
|
+
expect(Object.fromEntries(facts.objects.get("Memo")?.members ?? [])).toEqual({
|
|
19
|
+
Template: { specifier: "./Memo.Template", imported: "*" },
|
|
20
|
+
Unit: { specifier: "./Memo.Unit", imported: "*" },
|
|
21
|
+
Zone: { specifier: "./Memo.Zone", imported: "*" },
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("passes declarations that bind names: types, directives, functions, const values, export lists", () => {
|
|
26
|
+
const facts = read([
|
|
27
|
+
'"use client";',
|
|
28
|
+
'import type { Props } from "./types";',
|
|
29
|
+
'import { Text } from "./Text";',
|
|
30
|
+
'import Default from "./Default";',
|
|
31
|
+
"interface Local { a: string }",
|
|
32
|
+
"type Alias = Local;",
|
|
33
|
+
"declare const injected: string;",
|
|
34
|
+
"const enum Size { Small }",
|
|
35
|
+
"function helper(props: Props) { return props; }",
|
|
36
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: the fixture module's own source holds a template literal
|
|
37
|
+
"const label = `size ${Size.Small}`;",
|
|
38
|
+
"const options = [1, ...[2]];",
|
|
39
|
+
"const pick = typeof label === 'string' ? !label : void 0;",
|
|
40
|
+
"const Wrapper = () => null;",
|
|
41
|
+
"const Fields = { Text, Default, Wrapper, helper, label, options, pick };",
|
|
42
|
+
"export { Fields as Field };",
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
expect(facts.failed).toBeNull();
|
|
46
|
+
expect(facts.useClient).toBe(true);
|
|
47
|
+
expect([...facts.objects.keys()]).toEqual(["Field"]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("passes members put on an object the module declares, with `X.m = …` or `Object.assign`", () => {
|
|
51
|
+
const lines = [
|
|
52
|
+
'import { Navigator } from "./Navigator";',
|
|
53
|
+
'import { Slide } from "./Slide";',
|
|
54
|
+
'import * as parts from "./parts";',
|
|
55
|
+
"export const Scroll = () => null;",
|
|
56
|
+
"Scroll.Navigator = Navigator;",
|
|
57
|
+
"export const Dialog = Object.assign(() => null, { Slide, Part: parts.Part });",
|
|
58
|
+
"const Base = { Slide };",
|
|
59
|
+
"Object.assign(Base, { Navigator });",
|
|
60
|
+
"export { Base };",
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
expect(read(lines).failed).toBeNull();
|
|
64
|
+
expect(membersOf(lines, "Scroll")).toEqual({ Navigator: { specifier: "./Navigator", imported: "Navigator" } });
|
|
65
|
+
expect(membersOf(lines, "Dialog")).toEqual({
|
|
66
|
+
Slide: { specifier: "./Slide", imported: "Slide" },
|
|
67
|
+
Part: { specifier: "./parts", imported: "Part" },
|
|
68
|
+
});
|
|
69
|
+
expect(Object.keys(membersOf(lines, "Base"))).toEqual(["Slide", "Navigator"]);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("fails an import that runs a module for its effect (bare-import)", () => {
|
|
73
|
+
expect(read(['import "./register";', 'import { A } from "./A";', "export const X = { A };"]).failed).toEqual({
|
|
74
|
+
clause: "bare-import",
|
|
75
|
+
line: 1,
|
|
76
|
+
});
|
|
77
|
+
const tail = ['import { A } from "./A";', "export const X = { A };"];
|
|
78
|
+
expect(read(['import {} from "./register";', ...tail]).failed).toEqual({ clause: "bare-import", line: 1 });
|
|
79
|
+
expect(read(['import { type T } from "./types";', ...tail]).failed).toBeNull();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("fails a re-export, which runs a module no member of the object loads (reexport)", () => {
|
|
83
|
+
const tail = ['import { A } from "./A";', "export const X = { A };"];
|
|
84
|
+
for (const line of [
|
|
85
|
+
'export * from "./register";',
|
|
86
|
+
'export * as parts from "./register";',
|
|
87
|
+
'export { helper } from "./register";',
|
|
88
|
+
'export { type T, helper } from "./register";',
|
|
89
|
+
'export {} from "./register";',
|
|
90
|
+
])
|
|
91
|
+
expect(read([line, ...tail]).failed).toEqual({ clause: "reexport", line: 1 });
|
|
92
|
+
for (const line of [
|
|
93
|
+
'export type { T } from "./types";',
|
|
94
|
+
'export type * from "./types";',
|
|
95
|
+
'export { type T } from "./types";',
|
|
96
|
+
])
|
|
97
|
+
expect(read([line, ...tail]).failed).toBeNull();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("fails a statement with an effect, a `let`, or a member put on a name the module does not declare (effect-statement)", () => {
|
|
101
|
+
const exported = 'import { A } from "./A";\nexport const X = { A };';
|
|
102
|
+
for (const line of [
|
|
103
|
+
"register(X);",
|
|
104
|
+
"let count = 0;",
|
|
105
|
+
"if (X) X.b = A;",
|
|
106
|
+
"class Holder { static { register(); } }",
|
|
107
|
+
"enum Size { Small }",
|
|
108
|
+
"globalThis.X = X;",
|
|
109
|
+
"window.X = X;",
|
|
110
|
+
])
|
|
111
|
+
expect(read([exported, line]).failed?.clause).toBe("effect-statement");
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("fails a call or construction evaluated at load (call)", () => {
|
|
115
|
+
const head = 'import { wrap } from "./wrap";\nimport { A } from "./A";';
|
|
116
|
+
for (const value of ["wrap(A)", "new Map()", "tag`x`", "{ Text: wrap(A) }", "Object.assign({}, { A: wrap(A) })"])
|
|
117
|
+
expect(read([head, `export const X = ${value};`]).failed).toEqual({ clause: "call", line: 3 });
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("passes a call of React's memo, forwardRef, lazy or createContext, whose arguments are values like any other", () => {
|
|
121
|
+
const failedOn = (head: string, value: string, ...rest: string[]) =>
|
|
122
|
+
read([head, 'import { A } from "./A";', `const Wrapped = ${value};`, "export const X = { A, Wrapped };", ...rest])
|
|
123
|
+
.failed;
|
|
124
|
+
|
|
125
|
+
for (const name of ["memo", "forwardRef", "lazy", "createContext"])
|
|
126
|
+
expect(failedOn(`import { ${name} } from "react";`, `${name}(A)`)).toBeNull();
|
|
127
|
+
expect(failedOn('import { memo as wrap } from "react";', "wrap(A)")).toBeNull();
|
|
128
|
+
expect(failedOn('import React from "react";', "React.memo(A)")).toBeNull();
|
|
129
|
+
expect(failedOn('import * as React from "react";', "React.forwardRef<HTMLDivElement>(() => null)")).toBeNull();
|
|
130
|
+
expect(
|
|
131
|
+
failedOn('import React, { memo } from "react";', "memo(React.lazy(() => import('./A')), ...[A])"),
|
|
132
|
+
).toBeNull();
|
|
133
|
+
|
|
134
|
+
const call = { clause: "call" as const, line: 3 };
|
|
135
|
+
expect(failedOn('import { memo } from "./memo";', "memo(A)")).toEqual(call);
|
|
136
|
+
expect(failedOn('import { memo } from "preact/compat";', "memo(A)")).toEqual(call);
|
|
137
|
+
expect(failedOn('import * as React from "./react";', "React.memo(A)")).toEqual(call);
|
|
138
|
+
expect(failedOn("const memo = (value: unknown) => value;", "memo(A)")).toEqual(call);
|
|
139
|
+
expect(failedOn('import { useMemo } from "react";', "useMemo(A)")).toEqual(call);
|
|
140
|
+
expect(failedOn('import React from "react";', "React.createElement(A)")).toEqual(call);
|
|
141
|
+
expect(failedOn('import { memo } from "react";', "new memo(A)")).toEqual(call);
|
|
142
|
+
expect(failedOn('import { memo, version } from "react";', "memo(version.trim())")).toEqual(call);
|
|
143
|
+
expect(failedOn('import { memo } from "react";', "memo((globalThis.seen = A))")?.clause).toBe("effect-value");
|
|
144
|
+
expect(failedOn('import { memo } from "react";', "memo(A)", 'Wrapped.displayName = "Wrapped";')).toEqual({
|
|
145
|
+
clause: "effect-statement",
|
|
146
|
+
line: 5,
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test("fails a value that assigns or awaits while it is evaluated (effect-value)", () => {
|
|
151
|
+
const head = 'import { A } from "./A";\nconst state = { n: 0 };';
|
|
152
|
+
for (const value of ["{ A, n: (state.n = 1) }", "{ A, n: ++state.n }", "await A", "Object.assign(window, { A })"])
|
|
153
|
+
expect(read([head, `export const X = ${value};`]).failed?.clause).toBe("effect-value");
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("fails a module that puts a member on an import (mutated-import)", () => {
|
|
157
|
+
const head = 'import { Field } from "./Field";\nimport { A } from "./A";';
|
|
158
|
+
expect(read([head, "Field.A = A;", "export const X = { A };"]).failed?.clause).toBe("mutated-import");
|
|
159
|
+
expect(read([head, "Object.assign(Field, { A });", "export const X = { A };"]).failed?.clause).toBe(
|
|
160
|
+
"mutated-import",
|
|
161
|
+
);
|
|
162
|
+
expect(read([head, "export const X = Object.assign(Field, { A });"]).failed?.clause).toBe("mutated-import");
|
|
163
|
+
expect(read([head, "export const X = Object.assign(Field.Sub, { A });"]).failed?.clause).toBe("mutated-import");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("fails a member put on anything but an object the module created above it, which the object would not record", () => {
|
|
167
|
+
const head = 'import { Base } from "./Base";\nimport { A } from "./A";\nimport { B } from "./B";';
|
|
168
|
+
const failedOn = (...lines: string[]) => read([head, ...lines]).failed;
|
|
169
|
+
|
|
170
|
+
expect(failedOn("const Alias = Base;", "Alias.Extra = B;", "export const X = { A };")).toEqual({
|
|
171
|
+
clause: "effect-statement",
|
|
172
|
+
line: 5,
|
|
173
|
+
});
|
|
174
|
+
expect(failedOn("const Alias = Base;", "Object.assign(Alias, { B });", "export const X = { A };")?.clause).toBe(
|
|
175
|
+
"effect-statement",
|
|
176
|
+
);
|
|
177
|
+
expect(failedOn("X.A = B;", "export const X = { A };")).toEqual({ clause: "effect-statement", line: 4 });
|
|
178
|
+
expect(failedOn("const Own = { A };", "export const X = { Sub: Object.assign(Own, { B }) };")?.clause).toBe(
|
|
179
|
+
"effect-value",
|
|
180
|
+
);
|
|
181
|
+
const shadowed = ['import { Object } from "./Object";', 'import { A } from "./A";'];
|
|
182
|
+
expect(read([...shadowed, "export const X = Object.assign({}, { A });"]).failed?.clause).toBe("call");
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("records a member put on an object under every name bound to it, in the order the module runs", () => {
|
|
186
|
+
const lines = [
|
|
187
|
+
'import { A } from "./A";',
|
|
188
|
+
'import { B } from "./B";',
|
|
189
|
+
'import { C } from "./C";',
|
|
190
|
+
"export function Root() { return null; }",
|
|
191
|
+
"export const Toast = Object.assign(Root, { A });",
|
|
192
|
+
"Root.B = B;",
|
|
193
|
+
"Toast.A = C;",
|
|
194
|
+
];
|
|
195
|
+
|
|
196
|
+
expect(read(lines).failed).toBeNull();
|
|
197
|
+
for (const object of ["Root", "Toast"])
|
|
198
|
+
expect(membersOf(lines, object)).toEqual({
|
|
199
|
+
A: { specifier: "./C", imported: "C" },
|
|
200
|
+
B: { specifier: "./B", imported: "B" },
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("names no file for a member a function with members of its own may replace when it is copied in", () => {
|
|
205
|
+
const head = ['import { A } from "./A";', 'import { B } from "./B";', "export const X = { A };"];
|
|
206
|
+
const merged = [...head, "const Base = () => null;", "Base.A = B;", "Object.assign(X, Base);"];
|
|
207
|
+
|
|
208
|
+
expect(membersOf(merged, "X")).toEqual({ A: null });
|
|
209
|
+
expect(read(merged).objects.get("X")?.open).toBe(true);
|
|
210
|
+
expect(membersOf([...head, "const Plain = () => null;", "Object.assign(X, Plain);"], "X")).toEqual({
|
|
211
|
+
A: { specifier: "./A", imported: "A" },
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("records an imported object `Object.assign` copies in, and names no file for a member it may replace", () => {
|
|
216
|
+
const head = [
|
|
217
|
+
'import { Field } from "./Field";',
|
|
218
|
+
'import Base from "./Base";',
|
|
219
|
+
'import * as parts from "./parts";',
|
|
220
|
+
'import { A } from "./A";',
|
|
221
|
+
'import { B } from "./B";',
|
|
222
|
+
];
|
|
223
|
+
const shapeOf = (...lines: string[]) => {
|
|
224
|
+
const shape = read([...head, ...lines]).objects.get("X");
|
|
225
|
+
return { members: Object.fromEntries(shape?.members ?? []), open: shape?.open, copied: shape?.copied };
|
|
226
|
+
};
|
|
227
|
+
const field = { specifier: "./Field", imported: "Field" };
|
|
228
|
+
const b = { specifier: "./B", imported: "B" };
|
|
229
|
+
|
|
230
|
+
expect(read([...head, "export const X = Object.assign(() => null, Field, { A });"]).failed).toBeNull();
|
|
231
|
+
expect(shapeOf("export const X = Object.assign(() => null, { A }, Field, { B });")).toEqual({
|
|
232
|
+
members: { A: null, B: b },
|
|
233
|
+
open: false,
|
|
234
|
+
copied: [field],
|
|
235
|
+
});
|
|
236
|
+
expect(shapeOf("export const X = Object.assign({}, Field, { A }, Base as object, { B });")).toEqual({
|
|
237
|
+
members: { A: null, B: b },
|
|
238
|
+
open: false,
|
|
239
|
+
copied: [field, { specifier: "./Base", imported: "default" }],
|
|
240
|
+
});
|
|
241
|
+
expect(shapeOf("export const X = { A };", "Object.assign(X, Field);", "X.B = B;")).toEqual({
|
|
242
|
+
members: { A: null, B: b },
|
|
243
|
+
open: false,
|
|
244
|
+
copied: [field],
|
|
245
|
+
});
|
|
246
|
+
expect(shapeOf("export const X = Object.assign({ A }, parts, { B });")).toEqual({
|
|
247
|
+
members: { A: null, B: b },
|
|
248
|
+
open: true,
|
|
249
|
+
copied: [],
|
|
250
|
+
});
|
|
251
|
+
expect(shapeOf("export const X = Object.assign({ A }, Field.Sub, { B });").open).toBe(true);
|
|
252
|
+
expect(shapeOf("export const X = Object.assign({}, Field, { ...parts, B });").open).toBe(true);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test("points a member written one level down at its file, and no deeper", () => {
|
|
256
|
+
const lines = [
|
|
257
|
+
'import { Zone } from "./Doc";',
|
|
258
|
+
'import { Graph } from "./Graph";',
|
|
259
|
+
'import { Leaf } from "./Leaf";',
|
|
260
|
+
"export const Constant = { Doc: { Zone, Deep: { Leaf } }, Graph };",
|
|
261
|
+
];
|
|
262
|
+
|
|
263
|
+
expect(membersOf(lines, "Constant")).toEqual({
|
|
264
|
+
Doc: null,
|
|
265
|
+
"Doc.Zone": { specifier: "./Doc", imported: "Zone" },
|
|
266
|
+
"Doc.Deep": null,
|
|
267
|
+
Graph: { specifier: "./Graph", imported: "Graph" },
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test("names no file for a member a later spread, computed key or source may replace", () => {
|
|
272
|
+
const head = ['import { A } from "./A";', 'import { B } from "./B";', 'import { Other } from "./Other";'];
|
|
273
|
+
|
|
274
|
+
expect(membersOf([...head, "export const X = { A, ...Other, B };"], "X")).toEqual({
|
|
275
|
+
A: null,
|
|
276
|
+
B: { specifier: "./B", imported: "B" },
|
|
277
|
+
});
|
|
278
|
+
expect(membersOf([...head, 'export const X = { A, ["k"]: B };'], "X")).toEqual({ A: null });
|
|
279
|
+
expect(membersOf([...head, "export const X = Object.assign({ A }, Other, { B });"], "X")).toEqual({
|
|
280
|
+
A: null,
|
|
281
|
+
B: { specifier: "./B", imported: "B" },
|
|
282
|
+
});
|
|
283
|
+
expect(membersOf([...head, "export const X = { Doc: { A, ...Other }, B };"], "X")).toEqual({
|
|
284
|
+
Doc: null,
|
|
285
|
+
"Doc.A": null,
|
|
286
|
+
B: { specifier: "./B", imported: "B" },
|
|
287
|
+
});
|
|
288
|
+
expect(membersOf([...head, "export const X = { Doc: { A } };", "X.Doc = Other;"], "X")).toEqual({
|
|
289
|
+
Doc: { specifier: "./Other", imported: "Other" },
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test("names no file for a member declared in the object's own file or keyed with a dot", () => {
|
|
294
|
+
const lines = [
|
|
295
|
+
'import { A } from "./A";',
|
|
296
|
+
"const Local = () => null;",
|
|
297
|
+
'export const X = { A, Local, "Doc.A": A, method() { return A; } };',
|
|
298
|
+
];
|
|
299
|
+
|
|
300
|
+
expect(membersOf(lines, "X")).toEqual({
|
|
301
|
+
A: { specifier: "./A", imported: "A" },
|
|
302
|
+
Local: null,
|
|
303
|
+
"Doc.A": null,
|
|
304
|
+
method: null,
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
});
|