@shapeshift-labs/frontier-lang-compiler 0.2.150 → 0.2.151
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 +315 -9
- package/bench/real-repo-corpus-checkout-identity.mjs +134 -0
- package/bench/real-repo-corpus-checkout-proof.mjs +263 -0
- package/bench/real-repo-corpus-command-execution.mjs +314 -0
- package/bench/real-repo-corpus-evidence.mjs +165 -0
- package/bench/real-repo-corpus-suite.mjs +273 -0
- package/bench/smoke.mjs +109 -7
- package/dist/declarations/import-adapter-core.d.ts +4 -3
- package/dist/declarations/import-adapter-options-native.d.ts +21 -0
- package/dist/declarations/js-ts-project-merge-admission-routes.d.ts +35 -0
- package/dist/declarations/js-ts-project-merge-commonjs-interop.d.ts +29 -0
- package/dist/declarations/js-ts-project-merge-confidence.d.ts +64 -0
- package/dist/declarations/js-ts-project-merge-declaration-emit-parity.d.ts +37 -0
- package/dist/declarations/js-ts-project-merge-declarations.d.ts +65 -0
- package/dist/declarations/js-ts-project-merge-diagnostics.d.ts +97 -0
- package/dist/declarations/js-ts-project-merge-global-augmentation.d.ts +30 -0
- package/dist/declarations/js-ts-project-merge-jsx-render-branch.d.ts +48 -0
- package/dist/declarations/js-ts-project-merge-proof-levels.d.ts +109 -0
- package/dist/declarations/js-ts-project-merge-quality-gates.d.ts +38 -0
- package/dist/declarations/js-ts-project-merge-semantic-equivalence-proof.d.ts +45 -0
- package/dist/declarations/js-ts-project-merge-tsconfig.d.ts +43 -0
- package/dist/declarations/js-ts-safe-merge.d.ts +47 -0
- package/dist/declarations/js-ts-safe-project-merge.d.ts +120 -38
- package/dist/declarations/native-project-compiler-assignability-oracle.d.ts +41 -0
- package/dist/declarations/native-project-compiler-callable-signatures.d.ts +31 -0
- package/dist/declarations/native-project-compiler-class-member-runtime-proof.d.ts +87 -0
- package/dist/declarations/native-project-compiler-composite-types.d.ts +23 -0
- package/dist/declarations/native-project-compiler-enum-proof.d.ts +58 -0
- package/dist/declarations/native-project-compiler-index-signature.d.ts +7 -0
- package/dist/declarations/native-project-compiler-public-api-source-binding.d.ts +8 -0
- package/dist/declarations/native-project-compiler-scope.d.ts +37 -0
- package/dist/declarations/native-project-compiler-type-reference-targets.d.ts +38 -0
- package/dist/declarations/native-project-css-modules.d.ts +90 -0
- package/dist/declarations/native-project-decorator-metadata.d.ts +126 -0
- package/dist/declarations/native-project-jsx-graph.d.ts +313 -0
- package/dist/declarations/native-project-module-declarations.d.ts +52 -0
- package/dist/declarations/native-project-module-resolution.d.ts +76 -1
- package/dist/declarations/native-project-runtime-effect-target.d.ts +29 -0
- package/dist/declarations/native-project-runtime-executable-effect-evidence.d.ts +107 -0
- package/dist/declarations/native-project-runtime-mutation-target.d.ts +33 -0
- package/dist/declarations/native-project-runtime-promise-chain.d.ts +30 -0
- package/dist/declarations/native-project-runtime-promise-combinator.d.ts +22 -0
- package/dist/declarations/native-project-runtime-reachability.d.ts +30 -0
- package/dist/declarations/native-project-runtime-resource-management.d.ts +27 -0
- package/dist/declarations/native-project-runtime-yield-delegation.d.ts +10 -0
- package/dist/declarations/native-project-scope-template-reference.d.ts +13 -0
- package/dist/declarations/native-project-source-evidence.d.ts +8 -0
- package/dist/declarations/native-project.d.ts +40 -39
- package/dist/declarations/semantic-edit-script.d.ts +10 -8
- package/dist/declarations/semantic-graph-layers.d.ts +79 -0
- package/dist/declarations/semantic-sidecar.d.ts +3 -2
- package/dist/declarations/semantic-structural-diff.d.ts +94 -0
- package/dist/declarations/source-preservation.d.ts +32 -1
- package/dist/declarations/target-adapters.d.ts +22 -2
- package/dist/index.d.ts +31 -0
- package/dist/index.js +5 -0
- package/dist/internal/index-impl/compileNativeSource.js +53 -5
- package/dist/internal/index-impl/createLightweightNativeImport.js +58 -4
- package/dist/internal/index-impl/createNativeImportFromSyntaxAst.js +17 -1
- package/dist/internal/index-impl/createNativeImportFromTypeScriptAst.js +28 -4
- package/dist/internal/index-impl/createNativeProjectImportResult.js +31 -27
- package/dist/internal/index-impl/createNativeProjectModuleResolutionFromPackageManifests.js +145 -0
- package/dist/internal/index-impl/createNativeSourcePreservation.js +34 -7
- package/dist/internal/index-impl/createSemanticImportSidecar.js +27 -1
- package/dist/internal/index-impl/createTypeScriptCompilerNativeImporterAdapter.js +16 -5
- package/dist/internal/index-impl/dynamicImportExpressionMetadata.js +80 -0
- package/dist/internal/index-impl/importMetaUrlDependencyMetadata.js +176 -0
- package/dist/internal/index-impl/importNativeSource.js +2 -3
- package/dist/internal/index-impl/moduleImportAttributeMetadata.js +232 -0
- package/dist/internal/index-impl/projectSemanticEditScriptToSource.js +8 -1
- package/dist/internal/index-impl/projectSymbolGraphClassStaticBlocks.js +148 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerAdvancedTypeMetadata.js +45 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerCallableSignatureEquivalence.js +107 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerClassPrivateAccessorRuntimeProof.js +280 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerClassShapeEquivalence.js +103 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerConditionalTypeEquivalence.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerDecoratorRuntimeProof.js +197 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerEnumEquivalence.js +188 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerFacts.js +244 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerIndexSignatureEquivalence.js +58 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerMetadata.js +168 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalence.js +199 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalenceProof.js +204 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeReferenceTargetEquivalence.js +99 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleRecords.js +264 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleScanners.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleUtils.js +152 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModules.js +82 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentImports.js +170 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentProviderLookup.js +167 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentWrappers.js +150 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxContextTargets.js +71 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxContextValues.js +212 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxEventHandlers.js +172 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxHookEffects.js +124 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxHooks.js +281 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxMemberComponents.js +139 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxPropFlows.js +320 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxPropValues.js +145 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxProviderFlows.js +133 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRecords.js +315 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderCollections.js +155 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderReturns.js +291 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderRisk.js +279 -0
- package/dist/internal/index-impl/projectSymbolGraphModuleDeclarationShapes.js +138 -0
- package/dist/internal/index-impl/projectSymbolGraphModuleResolution.js +89 -87
- package/dist/internal/index-impl/projectSymbolGraphPackageConditions.js +314 -0
- package/dist/internal/index-impl/projectSymbolGraphReExportImportTargets.js +43 -0
- package/dist/internal/index-impl/projectSymbolGraphReExports.js +55 -1
- package/dist/internal/index-impl/projectSymbolGraphRuntimeRegions.js +108 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefAliases.js +307 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefLexical.js +320 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefOwners.js +50 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecordBuilders.js +112 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecords.js +238 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructural.js +104 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructuralNormalize.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefUseHashes.js +107 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceMapGeneratedBoundary.js +111 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceRecords.js +268 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceRecordsOwnership.js +309 -0
- package/dist/internal/index-impl/replaySemanticEditProjection.js +53 -39
- package/dist/internal/index-impl/runtimeOrderEvidenceBinding.js +151 -0
- package/dist/internal/index-impl/runtimeOrderProofSurfaces.js +253 -0
- package/dist/internal/index-impl/semanticEditCallsiteArgumentMerge.js +319 -0
- package/dist/internal/index-impl/semanticEditExplicitSourceReplacement.js +7 -2
- package/dist/internal/index-impl/semanticEditProjectionRecord.js +8 -0
- package/dist/internal/index-impl/semanticEditReplayDiagnostics.js +7 -2
- package/dist/internal/index-impl/semanticEditReplayOutputBinding.js +61 -0
- package/dist/internal/index-impl/semanticEditReplayRerunRoute.js +27 -0
- package/dist/internal/index-impl/semanticEditReplaySourceReplacement.js +6 -1
- package/dist/internal/index-impl/semanticEditRuntimeOrderReasons.js +320 -0
- package/dist/internal/index-impl/semanticEditScriptClassification.js +90 -5
- package/dist/internal/index-impl/semanticEditScripts.js +42 -5
- package/dist/internal/index-impl/semanticEditTypeSyntaxReasons.js +134 -0
- package/dist/internal/index-impl/semanticIndexFromNativeDeclarations.js +11 -5
- package/dist/internal/index-impl/semanticStructuralDiffRecords.js +150 -0
- package/dist/internal/index-impl/sourceMapGeneratedBoundaryGate.js +185 -0
- package/dist/internal/index-impl/staticMemberLiteral.js +31 -0
- package/dist/internal/index-impl/staticOptionalMemberReference.js +22 -0
- package/dist/internal/index-impl/syntaxAstSourcePreservation.js +273 -0
- package/dist/internal/index-impl/syntaxCommonJsModuleDeclarationEntries.js +297 -0
- package/dist/internal/index-impl/syntaxModuleDeclarationEntries.js +56 -132
- package/dist/internal/index-impl/syntaxModuleEntryRecords.js +160 -0
- package/dist/internal/index-impl/typeScriptCompilerAdvancedTypeShapes.js +160 -0
- package/dist/internal/index-impl/typeScriptCompilerAssignabilityOracle.js +97 -0
- package/dist/internal/index-impl/typeScriptCompilerClassApi.js +238 -0
- package/dist/internal/index-impl/typeScriptCompilerDecoratorMetadata.js +290 -0
- package/dist/internal/index-impl/typeScriptCompilerEnumShape.js +279 -0
- package/dist/internal/index-impl/typeScriptCompilerFacts.js +294 -0
- package/dist/internal/index-impl/typeScriptCompilerInferenceSyntax.js +170 -0
- package/dist/internal/index-impl/typeScriptCompilerReferenceGraph.js +186 -0
- package/dist/internal/index-impl/typeScriptCompilerSymbolIdentity.js +294 -0
- package/dist/internal/index-impl/typeScriptCompilerTypeReferenceTargets.js +142 -0
- package/dist/internal/index-impl/typeScriptDeclaration.js +10 -38
- package/dist/internal/index-impl/typeScriptModuleDeclarationEntries.js +52 -15
- package/dist/internal/index-impl/typeScriptSourceFilePreservation.js +296 -0
- package/dist/js-ts-safe-member-class-invariants.js +247 -0
- package/dist/js-ts-safe-member-merge-result.js +23 -3
- package/dist/js-ts-safe-member-merge.js +28 -4
- package/dist/js-ts-safe-merge-binding-patterns.js +170 -0
- package/dist/js-ts-safe-merge-jsx-attribute-fallback.js +151 -157
- package/dist/js-ts-safe-merge-jsx-attribute-parser.js +277 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-fallback.js +161 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-merge.js +319 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-parser.js +300 -0
- package/dist/js-ts-safe-merge-parse-declarations.js +46 -2
- package/dist/js-ts-safe-merge-parse-statements.js +8 -0
- package/dist/js-ts-safe-merge-semantic-edit-fallback.js +13 -5
- package/dist/js-ts-safe-merge-source-shape-fallbacks.js +3 -1
- package/dist/js-ts-safe-merge-top-level-rename-fallback.js +31 -5
- package/dist/js-ts-safe-merge-top-level-rename-result.js +7 -2
- package/dist/js-ts-safe-merge-variable-declarator-fallback.js +124 -6
- package/dist/js-ts-safe-merge-variable-declarator-parser.js +34 -4
- package/dist/js-ts-safe-merge.js +136 -0
- package/dist/js-ts-safe-project-merge-admission-routes.js +216 -0
- package/dist/js-ts-safe-project-merge-admission.js +161 -0
- package/dist/js-ts-safe-project-merge-ambient.js +110 -0
- package/dist/js-ts-safe-project-merge-core.js +85 -0
- package/dist/js-ts-safe-project-merge-css-module-conflicts.js +60 -0
- package/dist/js-ts-safe-project-merge-declaration-emit-parity.js +186 -0
- package/dist/js-ts-safe-project-merge-declarations.js +227 -0
- package/dist/js-ts-safe-project-merge-diagnostics-metadata.js +42 -0
- package/dist/js-ts-safe-project-merge-diagnostics-ts.js +73 -0
- package/dist/js-ts-safe-project-merge-diagnostics.js +283 -0
- package/dist/js-ts-safe-project-merge-evidence-routing.js +38 -0
- package/dist/js-ts-safe-project-merge-files.js +70 -0
- package/dist/js-ts-safe-project-merge-global-augmentation-compatibility.js +99 -0
- package/dist/js-ts-safe-project-merge-graph-conflicts.js +90 -2
- package/dist/js-ts-safe-project-merge-graph-delta-commonjs-interop.js +108 -0
- package/dist/js-ts-safe-project-merge-graph-delta-compiler-conflicts.js +179 -0
- package/dist/js-ts-safe-project-merge-graph-delta-compiler-details.js +189 -0
- package/dist/js-ts-safe-project-merge-graph-delta-conflicts.js +51 -184
- package/dist/js-ts-safe-project-merge-graph-delta-identity-conflicts.js +202 -0
- package/dist/js-ts-safe-project-merge-graph-delta-inference-syntax.js +80 -0
- package/dist/js-ts-safe-project-merge-graph-delta-module-declarations.js +155 -0
- package/dist/js-ts-safe-project-merge-graph-limits.js +16 -1
- package/dist/js-ts-safe-project-merge-graph.js +37 -5
- package/dist/js-ts-safe-project-merge-import-removal.js +292 -0
- package/dist/js-ts-safe-project-merge-jsx-graph-conflict-details.js +235 -0
- package/dist/js-ts-safe-project-merge-jsx-graph-conflicts.js +173 -0
- package/dist/js-ts-safe-project-merge-jsx-prop-contracts.js +86 -0
- package/dist/js-ts-safe-project-merge-jsx-render-branch-proof.js +189 -0
- package/dist/js-ts-safe-project-merge-missing-evidence.js +310 -0
- package/dist/js-ts-safe-project-merge-move-rename.js +209 -0
- package/dist/js-ts-safe-project-merge-proof-conflicts.js +44 -0
- package/dist/js-ts-safe-project-merge-proof-levels.js +320 -0
- package/dist/js-ts-safe-project-merge-quality-gates.js +140 -0
- package/dist/js-ts-safe-project-merge-routing-calibration.js +125 -0
- package/dist/js-ts-safe-project-merge-runtime-region-conflicts.js +156 -0
- package/dist/js-ts-safe-project-merge-scope-use-def-conflicts.js +292 -0
- package/dist/js-ts-safe-project-merge-semantic-equivalence-proof.js +175 -0
- package/dist/js-ts-safe-project-merge-semantic-replay-proof.js +311 -0
- package/dist/js-ts-safe-project-merge-semantic-replay-routes.js +179 -0
- package/dist/js-ts-safe-project-merge-source-span-conflicts.js +310 -0
- package/dist/js-ts-safe-project-merge-source-span-roundtrip-proof.js +172 -0
- package/dist/js-ts-safe-project-merge-split-merge-admission.js +96 -0
- package/dist/js-ts-safe-project-merge-split-merge-records.js +320 -0
- package/dist/js-ts-safe-project-merge-split-merge-shapes.js +234 -0
- package/dist/js-ts-safe-project-merge-split-merge.js +218 -0
- package/dist/js-ts-safe-project-merge-summary.js +320 -0
- package/dist/js-ts-safe-project-merge-symbol-move-admission.js +63 -0
- package/dist/js-ts-safe-project-merge-symbol-move-default-admission.js +143 -0
- package/dist/js-ts-safe-project-merge-symbol-move-risks.js +213 -0
- package/dist/js-ts-safe-project-merge-symbol-move.js +316 -0
- package/dist/js-ts-safe-project-merge-symbol-rename-admission.js +59 -0
- package/dist/js-ts-safe-project-merge-symbol-rename-default-admission.js +111 -0
- package/dist/js-ts-safe-project-merge-symbol-rename.js +319 -0
- package/dist/js-ts-safe-project-merge-ts-options.js +205 -0
- package/dist/js-ts-safe-project-merge-ts-program.js +268 -0
- package/dist/js-ts-safe-project-merge-typed-property-rename-rebase-utils.js +69 -0
- package/dist/js-ts-safe-project-merge-typed-property-rename-rebase.js +317 -0
- package/dist/js-ts-safe-project-merge-unsupported-surfaces.js +319 -0
- package/dist/js-ts-safe-project-merge.js +170 -171
- package/dist/js-ts-semantic-scope-use-def-bindings.js +287 -0
- package/dist/js-ts-semantic-scope-use-def-scan.js +241 -0
- package/dist/js-ts-semantic-scope-use-def-utils.js +132 -0
- package/dist/js-ts-semantic-scope-use-def.js +217 -0
- package/dist/lightweight-dependency-effects.js +28 -4
- package/dist/lightweight-dependency-relations.js +13 -7
- package/dist/lightweight-dependency-top-level.js +63 -0
- package/dist/native-import-language-profiles.js +27 -1
- package/dist/native-js-ts-importers.js +9 -5
- package/dist/native-parser-ast-format-profiles.js +12 -0
- package/dist/native-parser-html-css-format-profiles.js +85 -0
- package/dist/native-region-scanner-core.js +5 -3
- package/dist/native-region-scanner-js-commonjs.js +155 -0
- package/dist/native-region-scanner-js-imports.js +51 -13
- package/dist/native-region-scanner-js-reexports.js +79 -0
- package/dist/native-region-scanner-js-ts-helpers.js +23 -0
- package/dist/native-source-ledger-helpers.js +1 -1
- package/dist/native-source-ledger.js +24 -10
- package/dist/native-source-maps-ecma426.js +316 -0
- package/dist/native-source-maps.js +36 -6
- package/dist/native-source-preservation-ownership.js +292 -0
- package/dist/native-source-preservation-scanner.js +63 -25
- package/dist/native-source-preservation-types.d.ts +3 -0
- package/dist/semantic-import-effect-occurrences.js +242 -0
- package/dist/semantic-import-effect-regions.js +95 -58
- package/dist/semantic-import-graph-layers.js +224 -0
- package/dist/semantic-import-runtime-conditional-evidence.js +135 -0
- package/dist/semantic-import-runtime-effect-target-evidence.js +145 -0
- package/dist/semantic-import-runtime-exit-evidence.js +32 -0
- package/dist/semantic-import-runtime-import-meta-evidence.js +33 -0
- package/dist/semantic-import-runtime-mutation-evidence.js +155 -0
- package/dist/semantic-import-runtime-order-evidence.js +318 -0
- package/dist/semantic-import-runtime-promise-chain-evidence.js +103 -0
- package/dist/semantic-import-runtime-promise-combinator-evidence.js +166 -0
- package/dist/semantic-import-runtime-reachability-evidence.js +269 -0
- package/dist/semantic-import-runtime-resource-management-evidence.js +293 -0
- package/dist/semantic-import-runtime-switch-evidence.js +304 -0
- package/dist/semantic-import-runtime-throw-evidence.js +44 -0
- package/dist/semantic-import-runtime-try-finally-evidence.js +172 -0
- package/dist/semantic-import-sidecar-entry.js +4 -0
- package/dist/semantic-import-source-preservation.js +6 -2
- package/package.json +1 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { idFragment } from '../../native-import-utils.js';
|
|
3
|
+
|
|
4
|
+
function createProjectModuleDeclarationShapeRecords(semanticIndex, exportEdges = []) {
|
|
5
|
+
const documentsByPath = new Map((semanticIndex?.documents ?? []).filter((document) => document.path).map((document) => [document.path, document]));
|
|
6
|
+
return {
|
|
7
|
+
moduleDeclarationRecords: uniqueRecords((semanticIndex?.symbols ?? []).filter(isModuleDeclarationSymbol).map((symbol) => moduleDeclarationShapeRecord(symbol, documentsByPath))),
|
|
8
|
+
exportAssignmentRecords: uniqueRecords((exportEdges ?? []).filter(isExportAssignmentEdge).map(exportAssignmentShapeRecord))
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function moduleDeclarationShapeRecord(symbol, documentsByPath) {
|
|
13
|
+
const metadata = objectValue(symbol.metadata);
|
|
14
|
+
const sourcePath = symbol.definitionSpan?.path;
|
|
15
|
+
const moduleName = firstString(metadata.moduleName, metadata.namespace, symbol.name);
|
|
16
|
+
const surfaceKind = moduleDeclarationSurfaceKind(moduleName);
|
|
17
|
+
const document = documentsByPath.get(sourcePath);
|
|
18
|
+
const shapeInput = { sourcePath, sourceHash: document?.sourceHash, sourceSpan: symbol.definitionSpan, moduleName, surfaceKind, symbolKind: symbol.kind, signatureHash: symbol.signatureHash };
|
|
19
|
+
const shapeHash = hashSemanticValue({ kind: 'frontier.lang.moduleDeclarationShape', ...shapeInput });
|
|
20
|
+
return compactRecord({
|
|
21
|
+
kind: 'frontier.lang.projectModuleDeclarationShape',
|
|
22
|
+
version: 1,
|
|
23
|
+
id: `module_declaration_shape_${idFragment(symbol.id)}`,
|
|
24
|
+
symbolId: symbol.id,
|
|
25
|
+
language: symbol.language,
|
|
26
|
+
sourcePath,
|
|
27
|
+
sourceHash: document?.sourceHash,
|
|
28
|
+
moduleName,
|
|
29
|
+
namespace: firstString(metadata.namespace, moduleName),
|
|
30
|
+
surfaceKind,
|
|
31
|
+
declarationOnly: surfaceKind !== 'namespace-declaration',
|
|
32
|
+
runtimeNamespace: surfaceKind === 'namespace-declaration',
|
|
33
|
+
ambient: surfaceKind === 'ambient-module-declaration' || surfaceKind === 'global-augmentation',
|
|
34
|
+
nativeAstNodeId: symbol.nativeAstNodeId,
|
|
35
|
+
sourceSpan: symbol.definitionSpan,
|
|
36
|
+
signatureHash: symbol.signatureHash,
|
|
37
|
+
shapeHash,
|
|
38
|
+
shapeProof: moduleDeclarationShapeProof(surfaceKind, shapeHash)
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function exportAssignmentShapeRecord(edge) {
|
|
43
|
+
const shapeInput = { sourcePath: edge.sourcePath, exportedName: edge.exportedName, localName: edge.localName, exportKind: edge.exportKind };
|
|
44
|
+
const shapeHash = hashSemanticValue({ kind: 'frontier.lang.exportAssignmentShape', ...shapeInput });
|
|
45
|
+
return compactRecord({
|
|
46
|
+
kind: 'frontier.lang.projectExportAssignmentShape',
|
|
47
|
+
version: 1,
|
|
48
|
+
id: `export_assignment_shape_${idFragment(edge.id)}`,
|
|
49
|
+
edgeId: edge.id,
|
|
50
|
+
sourcePath: edge.sourcePath,
|
|
51
|
+
sourceHash: edge.sourceHash,
|
|
52
|
+
exportedName: edge.exportedName,
|
|
53
|
+
localName: edge.localName,
|
|
54
|
+
exportKind: edge.exportKind,
|
|
55
|
+
publicContract: edge.publicContract,
|
|
56
|
+
commonJsShape: true,
|
|
57
|
+
shapeHash,
|
|
58
|
+
shapeProof: exportAssignmentShapeProof(shapeHash)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function moduleDeclarationShapeProof(surfaceKind, shapeHash) {
|
|
63
|
+
return {
|
|
64
|
+
kind: 'frontier.lang.projectModuleDeclarationShapeProof',
|
|
65
|
+
version: 1,
|
|
66
|
+
status: 'static-shape-evidence',
|
|
67
|
+
proofLevel: 'module-declaration-static-shape',
|
|
68
|
+
shapeHash,
|
|
69
|
+
requiredSignals: ['parser-module-declaration-symbol', 'source-span', 'static-shape-hash'],
|
|
70
|
+
providedSignals: ['parser-module-declaration-symbol', 'source-span', 'static-shape-hash'],
|
|
71
|
+
unsupportedSignals: moduleDeclarationUnsupportedSignals(surfaceKind),
|
|
72
|
+
runtimeEquivalenceClaim: false,
|
|
73
|
+
semanticEquivalenceClaim: false
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function exportAssignmentShapeProof(shapeHash) {
|
|
78
|
+
return {
|
|
79
|
+
kind: 'frontier.lang.projectExportAssignmentShapeProof',
|
|
80
|
+
version: 1,
|
|
81
|
+
status: 'static-shape-evidence',
|
|
82
|
+
proofLevel: 'export-assignment-static-shape',
|
|
83
|
+
shapeHash,
|
|
84
|
+
requiredSignals: ['parser-export-assignment-edge', 'source-span', 'static-shape-hash'],
|
|
85
|
+
providedSignals: ['parser-export-assignment-edge', 'source-span', 'static-shape-hash'],
|
|
86
|
+
unsupportedSignals: ['commonjs-runtime-interop-equivalence-unproven', 'module-export-assignment-side-effects-unproven'],
|
|
87
|
+
runtimeInteropEquivalenceClaim: false,
|
|
88
|
+
semanticEquivalenceClaim: false
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function moduleDeclarationUnsupportedSignals(surfaceKind) {
|
|
93
|
+
if (surfaceKind === 'global-augmentation') return ['global-augmentation-compatibility-unproven'];
|
|
94
|
+
if (surfaceKind === 'ambient-module-declaration') return ['ambient-module-consumer-compatibility-unproven'];
|
|
95
|
+
return ['namespace-runtime-evaluation-order-unproven'];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function isModuleDeclarationSymbol(symbol) {
|
|
99
|
+
return symbol?.kind === 'module' && String(symbol.metadata?.scan ?? '').includes('module-declaration');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function isExportAssignmentEdge(edge) {
|
|
103
|
+
return edge?.exportKind === 'assignment' || edge?.exportedName === 'module.exports';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function moduleDeclarationSurfaceKind(moduleName) {
|
|
107
|
+
const name = String(moduleName ?? '');
|
|
108
|
+
if (name === 'global') return 'global-augmentation';
|
|
109
|
+
if (/^(?:\.|\.\.|@|#|[A-Za-z0-9_-]+\/)/.test(name)) return 'ambient-module-declaration';
|
|
110
|
+
return 'namespace-declaration';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function compactRecord(record) {
|
|
114
|
+
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function objectValue(value) {
|
|
118
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function firstString(...values) {
|
|
122
|
+
for (const value of values) {
|
|
123
|
+
if (value !== undefined && value !== null && String(value)) return String(value);
|
|
124
|
+
}
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function uniqueRecords(records) {
|
|
129
|
+
const seen = new Set();
|
|
130
|
+
return records.filter((record) => {
|
|
131
|
+
const key = record?.id ?? hashSemanticValue(record);
|
|
132
|
+
if (!key || seen.has(key)) return false;
|
|
133
|
+
seen.add(key);
|
|
134
|
+
return true;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { createProjectModuleDeclarationShapeRecords };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { modulePathCandidates } from './projectSymbolGraphModulePathCandidates.js';
|
|
2
|
+
import { exportMapMatch, exportTargetsForValue, packageEnvironmentConditionAmbiguity, packageEnvironmentConditionEvidence, packageConditions, packageRuntimeConditionAmbiguity, packageRuntimeConditionEvidence } from './projectSymbolGraphPackageConditions.js';
|
|
3
|
+
|
|
4
|
+
const UNKNOWN_DYNAMIC_IMPORT_MODULE_SPECIFIER = '<dynamic-import>';
|
|
5
|
+
const UNKNOWN_HOST_DEPENDENCY_MODULE_SPECIFIER = '<host-dependency>';
|
|
2
6
|
|
|
3
7
|
export function resolveRelativeProjectModule(sourcePath, moduleSpecifier, documentsByPath) {
|
|
4
8
|
if (!sourcePath || !moduleSpecifier || !moduleSpecifier.startsWith('.')) return undefined;
|
|
@@ -13,11 +17,13 @@ export function resolveRelativeProjectModule(sourcePath, moduleSpecifier, docume
|
|
|
13
17
|
};
|
|
14
18
|
}
|
|
15
19
|
|
|
16
|
-
export function resolveProjectModule(sourcePath, moduleSpecifier, documentsByPath, moduleResolution) {
|
|
20
|
+
export function resolveProjectModule(sourcePath, moduleSpecifier, documentsByPath, moduleResolution, edgeMetadata) {
|
|
17
21
|
if (!sourcePath || !moduleSpecifier) return undefined;
|
|
22
|
+
if (moduleSpecifier === UNKNOWN_DYNAMIC_IMPORT_MODULE_SPECIFIER) return { kind: 'dynamic-import-non-literal-missing' };
|
|
23
|
+
if (moduleSpecifier === UNKNOWN_HOST_DEPENDENCY_MODULE_SPECIFIER) return { kind: 'host-dependency-non-literal-missing' };
|
|
18
24
|
if (String(moduleSpecifier).startsWith('.')) return resolveRelativeProjectModule(sourcePath, moduleSpecifier, documentsByPath);
|
|
19
|
-
if (String(moduleSpecifier).startsWith('#')) return resolvePackageImportProjectModule(sourcePath, moduleSpecifier, documentsByPath, moduleResolution);
|
|
20
|
-
return resolveConfiguredProjectModule(moduleSpecifier, documentsByPath, moduleResolution);
|
|
25
|
+
if (String(moduleSpecifier).startsWith('#')) return resolvePackageImportProjectModule(sourcePath, moduleSpecifier, documentsByPath, moduleResolution, edgeMetadata);
|
|
26
|
+
return resolveConfiguredProjectModule(sourcePath, moduleSpecifier, documentsByPath, moduleResolution, edgeMetadata);
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
export function createProjectModuleSymbolResolver(symbols, documents) {
|
|
@@ -26,7 +32,15 @@ export function createProjectModuleSymbolResolver(symbols, documents) {
|
|
|
26
32
|
if (!edge?.targetDocumentId) return undefined;
|
|
27
33
|
const targetName = targetExportName(edge);
|
|
28
34
|
if (!targetName) return undefined;
|
|
29
|
-
|
|
35
|
+
if (edge.importKind === 'commonjs-require' && targetName === 'default') {
|
|
36
|
+
return exportedByDocumentAndName.get(symbolKey(edge.targetDocumentId, 'module.exports'))?.id;
|
|
37
|
+
}
|
|
38
|
+
const directExport = exportedByDocumentAndName.get(symbolKey(edge.targetDocumentId, targetName));
|
|
39
|
+
if (directExport) return directExport.id;
|
|
40
|
+
if (targetName === 'default') {
|
|
41
|
+
return exportedByDocumentAndName.get(symbolKey(edge.targetDocumentId, 'module.exports'))?.id;
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
30
44
|
};
|
|
31
45
|
}
|
|
32
46
|
|
|
@@ -68,28 +82,51 @@ function projectExportSymbolMap(symbols, documents) {
|
|
|
68
82
|
function symbolDocumentId(symbol, documentsByPath) {
|
|
69
83
|
return symbol?.metadata?.moduleEdge?.sourceDocumentId ?? documentsByPath.get(symbol.definitionSpan?.path)?.id;
|
|
70
84
|
}
|
|
71
|
-
|
|
72
|
-
function resolveConfiguredProjectModule(moduleSpecifier, documentsByPath, moduleResolution) {
|
|
85
|
+
function resolveConfiguredProjectModule(sourcePath, moduleSpecifier, documentsByPath, moduleResolution, edgeMetadata) {
|
|
73
86
|
const packageInfo = packageSpecifierInfo(moduleSpecifier);
|
|
74
|
-
const candidates = configuredModuleCandidates(moduleSpecifier, moduleResolution, packageInfo);
|
|
87
|
+
const candidates = configuredModuleCandidates(sourcePath, moduleSpecifier, moduleResolution, packageInfo, edgeMetadata);
|
|
75
88
|
let firstMissing;
|
|
76
89
|
for (const candidate of candidates) {
|
|
77
|
-
const target = moduleTargetDocument(candidate.path, documentsByPath);
|
|
78
90
|
const packageFields = packageResolutionFields(candidate, packageInfo);
|
|
91
|
+
if (candidate.failClosedKind) {
|
|
92
|
+
firstMissing ??= { path: candidate.path, kind: candidate.failClosedKind, ...packageFields };
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const target = moduleTargetDocument(candidate.path, documentsByPath);
|
|
79
96
|
if (target) return { path: target.path, documentId: target.id, resolutionPathVariant: target.resolutionPathVariant, kind: `${candidate.kind}-source`, ...packageFields };
|
|
80
97
|
firstMissing ??= { path: candidate.path, kind: `${candidate.kind}-missing`, ...packageFields };
|
|
81
98
|
}
|
|
82
99
|
return firstMissing ?? (packageInfo ? { kind: 'package-external', ...packageInfo } : undefined);
|
|
83
100
|
}
|
|
84
101
|
|
|
85
|
-
function resolvePackageImportProjectModule(sourcePath, moduleSpecifier, documentsByPath, moduleResolution = {}) {
|
|
102
|
+
function resolvePackageImportProjectModule(sourcePath, moduleSpecifier, documentsByPath, moduleResolution = {}, edgeMetadata) {
|
|
86
103
|
const packageContext = packageImportContext(sourcePath, moduleResolution);
|
|
104
|
+
if (packageContext.packageWorkspaceRootAmbiguous) return { kind: 'package-workspace-root-ambiguous-missing', packageImportKey: moduleSpecifier, packageName: packageContext.packageName, ...packageWorkspaceRootAmbiguityFields(packageContext) };
|
|
105
|
+
if (packageContext.packageImportScopeMismatch) return { kind: 'package-import-scope-missing', packageImportKey: moduleSpecifier };
|
|
87
106
|
const importsValue = packageContext.imports;
|
|
88
107
|
if (!importsValue) return { kind: 'package-import-external', packageImportKey: moduleSpecifier };
|
|
89
108
|
const match = packageImportMapValue(importsValue, moduleSpecifier);
|
|
90
109
|
if (!match) return { kind: 'package-import-external', packageImportKey: moduleSpecifier };
|
|
110
|
+
const runtimeEvidence = packageRuntimeConditionEvidence(moduleResolution, sourcePath, packageContext, edgeMetadata);
|
|
111
|
+
if (runtimeEvidence.packageRuntimeConditionConflict) return {
|
|
112
|
+
kind: 'package-runtime-condition-conflict-missing',
|
|
113
|
+
packageImportKey: match.key,
|
|
114
|
+
packageName: packageContext.packageName,
|
|
115
|
+
...runtimeEvidence
|
|
116
|
+
};
|
|
117
|
+
if (match.value === null) return { kind: 'package-import-null-target-missing', packageImportKey: match.key, packageName: packageContext.packageName, ...runtimeEvidence };
|
|
118
|
+
const runtimeAmbiguity = packageRuntimeConditionAmbiguity(match.value, moduleResolution, sourcePath, packageContext, edgeMetadata);
|
|
119
|
+
if (runtimeAmbiguity) return { kind: 'package-import-runtime-ambiguous-missing', packageImportKey: match.key, packageImportCondition: runtimeAmbiguity, packageName: packageContext.packageName, ...runtimeEvidence };
|
|
120
|
+
const environmentEvidence = packageEnvironmentConditionEvidence(moduleResolution, edgeMetadata);
|
|
121
|
+
const environmentAmbiguity = packageEnvironmentConditionAmbiguity(match.value, moduleResolution, sourcePath, packageContext, edgeMetadata);
|
|
122
|
+
if (environmentAmbiguity) return { kind: 'package-import-environment-ambiguous-missing', packageImportKey: match.key, packageImportCondition: environmentAmbiguity, packageName: packageContext.packageName, ...environmentAmbiguityFields(environmentAmbiguity), ...runtimeEvidence, ...environmentEvidence };
|
|
123
|
+
const conditions = packageConditions(moduleResolution, sourcePath, packageContext, edgeMetadata);
|
|
124
|
+
const targets = exportTargetsForValue(match.value, conditions);
|
|
125
|
+
if (!targets.length && isRecord(match.value)) {
|
|
126
|
+
return { kind: 'package-import-condition-missing', packageImportKey: match.key, packageName: packageContext.packageName, ...runtimeEvidence };
|
|
127
|
+
}
|
|
91
128
|
let firstMissing;
|
|
92
|
-
for (const target of
|
|
129
|
+
for (const target of targets) {
|
|
93
130
|
const packageImportTarget = target.path;
|
|
94
131
|
if (!packageImportTarget || !String(packageImportTarget).startsWith('.')) {
|
|
95
132
|
return { kind: 'package-import-external', packageImportKey: match.key, packageImportCondition: target.condition, packageImportTarget };
|
|
@@ -100,7 +137,9 @@ function resolvePackageImportProjectModule(sourcePath, moduleSpecifier, document
|
|
|
100
137
|
packageImportKey: match.key,
|
|
101
138
|
packageImportCondition: target.condition,
|
|
102
139
|
packageImportTarget,
|
|
103
|
-
packageName: packageContext.packageName
|
|
140
|
+
packageName: packageContext.packageName,
|
|
141
|
+
...runtimeEvidence,
|
|
142
|
+
...environmentEvidence
|
|
104
143
|
};
|
|
105
144
|
if (resolved) return { path: resolved.path, documentId: resolved.id, resolutionPathVariant: resolved.resolutionPathVariant, kind: 'package-import-source', ...record };
|
|
106
145
|
firstMissing ??= { path: candidatePath, kind: 'package-import-missing', ...record };
|
|
@@ -108,17 +147,16 @@ function resolvePackageImportProjectModule(sourcePath, moduleSpecifier, document
|
|
|
108
147
|
return firstMissing ?? { kind: 'package-import-external', packageImportKey: match.key };
|
|
109
148
|
}
|
|
110
149
|
|
|
111
|
-
function configuredModuleCandidates(moduleSpecifier, moduleResolution = {}, packageInfo) {
|
|
150
|
+
function configuredModuleCandidates(sourcePath, moduleSpecifier, moduleResolution = {}, packageInfo, edgeMetadata) {
|
|
112
151
|
const compilerOptions = moduleResolution.compilerOptions ?? {};
|
|
113
152
|
const baseUrl = normalizeProjectPath(moduleResolution.baseUrl ?? compilerOptions.baseUrl ?? '');
|
|
114
153
|
return uniquePaths([
|
|
115
154
|
...aliasCandidates(moduleSpecifier, moduleResolution.aliases, 'alias', baseUrl),
|
|
116
155
|
...aliasCandidates(moduleSpecifier, moduleResolution.paths ?? compilerOptions.paths, 'path-alias', baseUrl),
|
|
117
|
-
...packageCandidates(packageInfo, moduleResolution),
|
|
156
|
+
...packageCandidates(sourcePath, packageInfo, moduleResolution, edgeMetadata),
|
|
118
157
|
...baseUrlCandidates(moduleSpecifier, baseUrl)
|
|
119
158
|
]);
|
|
120
159
|
}
|
|
121
|
-
|
|
122
160
|
function aliasCandidates(moduleSpecifier, aliases, kind, baseUrl) {
|
|
123
161
|
return Object.entries(aliases ?? {}).flatMap(([pattern, targetPatterns]) => {
|
|
124
162
|
const capture = patternCapture(moduleSpecifier, pattern);
|
|
@@ -135,41 +173,31 @@ function baseUrlCandidates(moduleSpecifier, baseUrl) {
|
|
|
135
173
|
if (!baseUrl || String(moduleSpecifier).startsWith('@')) return [];
|
|
136
174
|
return [{ kind: 'base-url', path: normalizeProjectPath(joinProjectPath(baseUrl, moduleSpecifier)) }];
|
|
137
175
|
}
|
|
138
|
-
|
|
139
|
-
function packageCandidates(packageInfo, moduleResolution = {}) {
|
|
176
|
+
function packageCandidates(sourcePath, packageInfo, moduleResolution = {}, edgeMetadata) {
|
|
140
177
|
if (!packageInfo) return [];
|
|
141
178
|
const options = moduleResolution.packages?.[packageInfo.packageName];
|
|
142
179
|
if (!options) return [];
|
|
180
|
+
const rootAmbiguity = packageWorkspaceRootAmbiguity(options, packageInfo); if (rootAmbiguity) return [rootAmbiguity];
|
|
143
181
|
const root = normalizeProjectPath(options.root ?? '');
|
|
144
182
|
const subpath = packageInfo.packageSubpath === '.' ? '' : packageInfo.packageSubpath.slice(2);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
path: target.path,
|
|
163
|
-
packageExportCondition: target.condition,
|
|
164
|
-
...packageInfo
|
|
165
|
-
}));
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function packageExportTargets(exportsValue, subpath, conditions) {
|
|
169
|
-
if (!exportsValue) return [];
|
|
170
|
-
return exportTargetsForValue(exportMapValue(exportsValue, subpath), conditions);
|
|
183
|
+
const exportMatch = exportMapMatch(options.exports, packageInfo.packageSubpath);
|
|
184
|
+
const exportValue = exportMatch?.value;
|
|
185
|
+
const runtimeEvidence = packageRuntimeConditionEvidence(moduleResolution, sourcePath, undefined, edgeMetadata);
|
|
186
|
+
const environmentEvidence = packageEnvironmentConditionEvidence(moduleResolution, edgeMetadata);
|
|
187
|
+
if (Object.prototype.hasOwnProperty.call(options, 'exports')) {
|
|
188
|
+
const fallbackPath = normalizeProjectPath(joinProjectPath(root, subpath || '.'));
|
|
189
|
+
if (runtimeEvidence.packageRuntimeConditionConflict) return [{ kind: 'package', failClosedKind: 'package-runtime-condition-conflict-missing', path: fallbackPath, packageExportKey: exportMatch?.key, ...runtimeEvidence, ...packageInfo }];
|
|
190
|
+
if (exportValue === undefined || exportValue === null) return [{ kind: 'package', failClosedKind: exportValue === null ? 'package-export-null-target-missing' : 'package-subpath-not-exported-missing', path: fallbackPath, packageExportKey: exportMatch?.key, ...runtimeEvidence, ...packageInfo }];
|
|
191
|
+
const runtimeAmbiguity = packageRuntimeConditionAmbiguity(exportValue, moduleResolution, sourcePath, undefined, edgeMetadata);
|
|
192
|
+
if (runtimeAmbiguity) return [{ kind: 'package', failClosedKind: 'package-export-runtime-ambiguous-missing', path: fallbackPath, packageExportKey: exportMatch?.key, packageExportCondition: runtimeAmbiguity, ...runtimeEvidence, ...packageInfo }];
|
|
193
|
+
const environmentAmbiguity = packageEnvironmentConditionAmbiguity(exportValue, moduleResolution, sourcePath, undefined, edgeMetadata);
|
|
194
|
+
if (environmentAmbiguity) return [{ kind: 'package', failClosedKind: 'package-export-environment-ambiguous-missing', path: fallbackPath, packageExportKey: exportMatch?.key, packageExportCondition: environmentAmbiguity, ...environmentAmbiguityFields(environmentAmbiguity), ...runtimeEvidence, ...environmentEvidence, ...packageInfo }];
|
|
195
|
+
const exportTargets = exportTargetsForValue(exportValue, packageConditions(moduleResolution, sourcePath, undefined, edgeMetadata));
|
|
196
|
+
if (!exportTargets.length) return [{ kind: 'package', failClosedKind: 'package-export-condition-missing', path: fallbackPath, packageExportKey: exportMatch?.key, ...runtimeEvidence, ...packageInfo }];
|
|
197
|
+
return uniquePaths(exportTargets.map((target) => ({ kind: 'package', path: normalizeProjectPath(joinProjectPath(root, target.path)), packageExportKey: exportMatch?.key, packageExportCondition: target.condition, packageExportTarget: target.path, ...runtimeEvidence, ...environmentEvidence, ...packageInfo })));
|
|
198
|
+
}
|
|
199
|
+
return uniquePaths(packageFallbackTargets(options, subpath).map((path) => ({ kind: 'package', path: normalizeProjectPath(joinProjectPath(root, path)), ...packageInfo })));
|
|
171
200
|
}
|
|
172
|
-
|
|
173
201
|
function packageImportMapValue(importsValue, moduleSpecifier) {
|
|
174
202
|
if (!isRecord(importsValue)) return undefined;
|
|
175
203
|
if (Object.prototype.hasOwnProperty.call(importsValue, moduleSpecifier)) return { key: moduleSpecifier, value: importsValue[moduleSpecifier] };
|
|
@@ -185,29 +213,19 @@ function packageImportContext(sourcePath, moduleResolution = {}) {
|
|
|
185
213
|
.map(([packageName, options]) => ({
|
|
186
214
|
packageName,
|
|
187
215
|
root: normalizeProjectPath(options.root ?? ''),
|
|
188
|
-
|
|
216
|
+
packageType: options.packageType ?? options.type,
|
|
217
|
+
imports: options.imports,
|
|
218
|
+
...packageWorkspaceRootAmbiguityFields(options)
|
|
189
219
|
}))
|
|
190
|
-
.filter((entry) => entry.imports &&
|
|
220
|
+
.filter((entry) => entry.imports && packageRootContainsSource(sourcePath, entry))
|
|
191
221
|
.sort((left, right) => right.root.length - left.root.length);
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
222
|
+
if (packages[0]) return packages[0];
|
|
223
|
+
const root = normalizeProjectPath(moduleResolution.packageRoot ?? moduleResolution.root ?? '');
|
|
224
|
+
const imports = moduleResolution.imports ?? moduleResolution.packageImports;
|
|
225
|
+
return imports && root && !pathInsideRoot(sourcePath, root)
|
|
226
|
+
? { root, imports, packageImportScopeMismatch: true }
|
|
227
|
+
: { root, imports };
|
|
196
228
|
}
|
|
197
|
-
|
|
198
|
-
function exportMapValue(exportsValue, subpath) {
|
|
199
|
-
if (!isRecord(exportsValue) || !Object.keys(exportsValue).some((key) => key.startsWith('.'))) return subpath === '.' ? exportsValue : undefined;
|
|
200
|
-
return exportsValue[subpath] ?? patternExportMapValue(exportsValue, subpath);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function patternExportMapValue(exportsValue, subpath) {
|
|
204
|
-
for (const [pattern, target] of Object.entries(exportsValue)) {
|
|
205
|
-
const capture = patternCapture(subpath, pattern);
|
|
206
|
-
if (capture !== undefined) return replaceExportTargetCapture(target, capture);
|
|
207
|
-
}
|
|
208
|
-
return undefined;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
229
|
function replaceExportTargetCapture(target, capture) {
|
|
212
230
|
if (typeof target === 'string') return target.replace('*', capture);
|
|
213
231
|
if (Array.isArray(target)) return target.map((entry) => replaceExportTargetCapture(entry, capture));
|
|
@@ -215,19 +233,15 @@ function replaceExportTargetCapture(target, capture) {
|
|
|
215
233
|
return Object.fromEntries(Object.entries(target).map(([key, value]) => [key, replaceExportTargetCapture(value, capture)]));
|
|
216
234
|
}
|
|
217
235
|
|
|
218
|
-
function exportTargetsForValue(value, conditions, condition) {
|
|
219
|
-
if (!value) return [];
|
|
220
|
-
if (typeof value === 'string') return [{ path: value, condition }];
|
|
221
|
-
if (Array.isArray(value)) return value.flatMap((entry) => exportTargetsForValue(entry, conditions, condition));
|
|
222
|
-
if (!isRecord(value)) return [];
|
|
223
|
-
return conditions.flatMap((key) => exportTargetsForValue(value[key], conditions, key));
|
|
224
|
-
}
|
|
225
|
-
|
|
226
236
|
function packageFallbackTargets(options, subpath) {
|
|
227
237
|
const sourceRoot = normalizeProjectPath(options.sourceRoot ?? 'src');
|
|
228
238
|
if (subpath) return [joinProjectPath(sourceRoot, subpath), subpath];
|
|
229
239
|
return [options.types, options.main, joinProjectPath(sourceRoot, 'index')].filter(Boolean);
|
|
230
240
|
}
|
|
241
|
+
function packageWorkspaceRootAmbiguity(options, packageInfo) { const fields = packageWorkspaceRootAmbiguityFields(options); return fields.packageWorkspaceRootAmbiguous ? { kind: 'package', failClosedKind: 'package-workspace-root-ambiguous-missing', path: packageSpecifierPath(packageInfo), ...fields, ...packageInfo } : undefined; }
|
|
242
|
+
function packageWorkspaceRootAmbiguityFields(options = {}) { const roots = uniquePaths([...(Array.isArray(options.packageWorkspaceRoots) ? options.packageWorkspaceRoots.map((path) => ({ path: normalizeProjectPath(path) })) : []), { path: normalizeProjectPath(options.root ?? '') }]).map((entry) => entry.path); return options.packageWorkspaceRootAmbiguous || roots.length > 1 ? { packageWorkspaceRootAmbiguous: true, packageWorkspaceRoots: roots, packageResolutionReasonCode: 'package-workspace-root-ambiguous-missing' } : {}; }
|
|
243
|
+
function packageRootContainsSource(sourcePath, entry) { return (entry.packageWorkspaceRootAmbiguous ? entry.packageWorkspaceRoots : [entry.root]).some((root) => pathInsideRoot(sourcePath, root)); }
|
|
244
|
+
function packageSpecifierPath(packageInfo) { return packageInfo.packageSubpath === '.' ? packageInfo.packageName : `${packageInfo.packageName}/${packageInfo.packageSubpath.slice(2)}`; }
|
|
231
245
|
|
|
232
246
|
function moduleTargetDocument(path, documentsByPath) {
|
|
233
247
|
for (const candidate of modulePathCandidates(path)) {
|
|
@@ -281,30 +295,18 @@ function packageSpecifierInfo(moduleSpecifier) {
|
|
|
281
295
|
|
|
282
296
|
function packageResolutionFields(candidate, packageInfo) {
|
|
283
297
|
if (!candidate.packageName && candidate.kind !== 'package') return {};
|
|
284
|
-
return {
|
|
285
|
-
packageName: candidate.packageName ?? packageInfo?.packageName,
|
|
286
|
-
packageSubpath: candidate.packageSubpath ?? packageInfo?.packageSubpath,
|
|
287
|
-
packageExportCondition: candidate.packageExportCondition,
|
|
288
|
-
packageImportKey: candidate.packageImportKey,
|
|
289
|
-
packageImportCondition: candidate.packageImportCondition,
|
|
290
|
-
packageImportTarget: candidate.packageImportTarget
|
|
291
|
-
};
|
|
298
|
+
return { packageName: candidate.packageName ?? packageInfo?.packageName, packageSubpath: candidate.packageSubpath ?? packageInfo?.packageSubpath, packageExportKey: candidate.packageExportKey, packageExportCondition: candidate.packageExportCondition, packageExportTarget: candidate.packageExportTarget, packageImportKey: candidate.packageImportKey, packageImportCondition: candidate.packageImportCondition, packageImportTarget: candidate.packageImportTarget, packageRuntimeCondition: candidate.packageRuntimeCondition, packageRuntimeConditionEvidenceSource: candidate.packageRuntimeConditionEvidenceSource, packageRuntimeConditionEdgeKind: candidate.packageRuntimeConditionEdgeKind, packageRuntimeConditionCandidates: candidate.packageRuntimeConditionCandidates, packageRuntimeConditionReasonCode: candidate.packageRuntimeConditionReasonCode, packageEnvironmentCondition: candidate.packageEnvironmentCondition, packageEnvironmentConditionEvidenceSource: candidate.packageEnvironmentConditionEvidenceSource, packageEnvironmentConditionCandidates: candidate.packageEnvironmentConditionCandidates, packageEnvironmentConditionReasonCode: candidate.packageEnvironmentConditionReasonCode, packageType: candidate.packageType, packageWorkspaceRootAmbiguous: candidate.packageWorkspaceRootAmbiguous, packageWorkspaceRoots: candidate.packageWorkspaceRoots, packageResolutionReasonCode: candidate.packageResolutionReasonCode };
|
|
292
299
|
}
|
|
293
300
|
|
|
294
|
-
function
|
|
295
|
-
return moduleResolution.packageExportConditions ?? moduleResolution.conditions ?? ['types', 'import', 'module', 'require', 'default'];
|
|
296
|
-
}
|
|
301
|
+
function environmentAmbiguityFields(ambiguity) { return { packageEnvironmentConditionCandidates: ambiguity.split('|'), packageEnvironmentConditionReasonCode: 'package-environment-condition-ambiguous-missing' }; }
|
|
297
302
|
|
|
298
|
-
function isRecord(value) {
|
|
299
|
-
return value && typeof value === 'object' && !Array.isArray(value);
|
|
300
|
-
}
|
|
303
|
+
function isRecord(value) { return value && typeof value === 'object' && !Array.isArray(value); }
|
|
301
304
|
|
|
302
305
|
function normalizeProjectPath(path) {
|
|
303
306
|
const parts = [];
|
|
304
307
|
for (const part of String(path).split('/')) {
|
|
305
308
|
if (!part || part === '.') continue;
|
|
306
|
-
if (part === '..') parts.pop();
|
|
307
|
-
else parts.push(part);
|
|
309
|
+
if (part === '..') parts.pop(); else parts.push(part);
|
|
308
310
|
}
|
|
309
311
|
return parts.join('/');
|
|
310
312
|
}
|