@shapeshift-labs/frontier-lang-compiler 0.2.112 → 0.2.114
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 +29 -0
- package/dist/declarations/native-project-module-resolution.d.ts +17 -0
- package/dist/declarations/native-project.d.ts +8 -8
- package/dist/internal/index-impl/createNativeProjectImportResult.js +12 -14
- package/dist/internal/index-impl/projectSymbolGraphModuleResolution.js +125 -14
- package/dist/internal/index-impl/projectSymbolGraphReExports.js +43 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -213,6 +213,35 @@ When `includeOutputProjectSymbolGraph` is enabled, the same
|
|
|
213
213
|
`moduleResolution` shape is used for output graph artifacts. Resolution is
|
|
214
214
|
runtime-neutral: `baseUrl`, `paths`, `aliases`, and `compilerOptions.paths`
|
|
215
215
|
are matched against the supplied project files, not the host filesystem.
|
|
216
|
+
Bare package imports also get explicit package identity. If `packages` is
|
|
217
|
+
provided, package export maps can resolve back to supplied workspace sources
|
|
218
|
+
and record the selected export condition:
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
const project = safeMergeJsTsProject({
|
|
222
|
+
includeOutputProjectSymbolGraph: true,
|
|
223
|
+
moduleResolution: {
|
|
224
|
+
packages: {
|
|
225
|
+
'@pkg/core': {
|
|
226
|
+
root: 'packages/core',
|
|
227
|
+
exports: { './utils': { import: './src/utils.ts', default: './dist/utils.js' } }
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
packageExportConditions: ['import', 'default']
|
|
231
|
+
},
|
|
232
|
+
baseFiles,
|
|
233
|
+
workerFiles,
|
|
234
|
+
headFiles
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
console.log(project.outputProjectSymbolGraph.importEdges[0].packageName); // "@pkg/core"
|
|
238
|
+
console.log(project.outputProjectSymbolGraph.importEdges[0].packageExportCondition); // "import"
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Named re-export identities also include symbol links when the project graph has
|
|
242
|
+
enough evidence. For `export { thing as renamedThing } from './thing.js'`,
|
|
243
|
+
`reExportIdentities[]` records the source module, imported/exported names,
|
|
244
|
+
`originSymbolId`, `exportedSymbolId`, and `localSymbolId`.
|
|
216
245
|
|
|
217
246
|
High-risk native features also have explicit evidence policies. These policies are advisory in this package: they tell a swarm or admission queue what evidence is missing without silently changing the existing readiness classification.
|
|
218
247
|
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
export type NativeProjectModuleResolutionPaths = Readonly<Record<string, readonly string[] | string>>;
|
|
2
|
+
export type NativeProjectPackageExportTarget = string | readonly string[] | NativeProjectPackageConditionalExports;
|
|
3
|
+
export type NativeProjectPackageExports = NativeProjectPackageExportTarget | Readonly<Record<string, NativeProjectPackageExportTarget>>;
|
|
4
|
+
|
|
5
|
+
export interface NativeProjectPackageConditionalExports {
|
|
6
|
+
readonly [condition: string]: NativeProjectPackageExportTarget;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface NativeProjectPackageResolutionOptions {
|
|
10
|
+
readonly root?: string;
|
|
11
|
+
readonly sourceRoot?: string;
|
|
12
|
+
readonly main?: string;
|
|
13
|
+
readonly types?: string;
|
|
14
|
+
readonly exports?: NativeProjectPackageExports;
|
|
15
|
+
}
|
|
2
16
|
|
|
3
17
|
export interface NativeProjectModuleResolutionOptions {
|
|
4
18
|
readonly baseUrl?: string;
|
|
5
19
|
readonly paths?: NativeProjectModuleResolutionPaths;
|
|
6
20
|
readonly aliases?: NativeProjectModuleResolutionPaths;
|
|
21
|
+
readonly packages?: Readonly<Record<string, NativeProjectPackageResolutionOptions>>;
|
|
22
|
+
readonly conditions?: readonly string[];
|
|
23
|
+
readonly packageExportConditions?: readonly string[];
|
|
7
24
|
readonly compilerOptions?: {
|
|
8
25
|
readonly baseUrl?: string;
|
|
9
26
|
readonly paths?: NativeProjectModuleResolutionPaths;
|
|
@@ -79,8 +79,6 @@ export interface ImportNativeProjectOptions {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
export type NativeProjectSymbolGraphRemainingField =
|
|
82
|
-
| 'moduleEdges[].packageName'
|
|
83
|
-
| 'moduleEdges[].packageExportCondition'
|
|
84
82
|
| 'reExportIdentities[].originSymbolId'
|
|
85
83
|
| 'reExportIdentities[].exportedSymbolId'
|
|
86
84
|
| 'reExportIdentities[].localSymbolId'
|
|
@@ -112,13 +110,15 @@ export interface NativeProjectSymbolGraphModuleEdgeRecord {
|
|
|
112
110
|
readonly resolvedModulePath?: string;
|
|
113
111
|
readonly targetDocumentId?: string;
|
|
114
112
|
readonly resolvedTargetSymbolId?: string;
|
|
115
|
-
readonly resolutionKind?: 'relative-source' | 'relative-missing' | 'alias-source' | 'alias-missing' | 'path-alias-source' | 'path-alias-missing' | 'base-url-source' | 'base-url-missing' | string;
|
|
113
|
+
readonly resolutionKind?: 'relative-source' | 'relative-missing' | 'alias-source' | 'alias-missing' | 'path-alias-source' | 'path-alias-missing' | 'base-url-source' | 'base-url-missing' | 'package-source' | 'package-missing' | 'package-external' | string;
|
|
114
|
+
readonly packageName?: string;
|
|
115
|
+
readonly packageSubpath?: string;
|
|
116
|
+
readonly packageExportCondition?: string;
|
|
116
117
|
readonly importKind?: string;
|
|
117
118
|
readonly exportKind?: string;
|
|
118
119
|
readonly importedName?: string;
|
|
119
120
|
readonly exportedName?: string;
|
|
120
|
-
readonly localName?: string;
|
|
121
|
-
readonly namespace?: string;
|
|
121
|
+
readonly localName?: string; readonly namespace?: string;
|
|
122
122
|
readonly isTypeOnly?: boolean;
|
|
123
123
|
readonly isReExport?: boolean;
|
|
124
124
|
readonly publicContract?: boolean;
|
|
@@ -138,10 +138,10 @@ export interface NativeProjectSymbolGraphReExportIdentityRecord {
|
|
|
138
138
|
readonly localName?: string;
|
|
139
139
|
readonly namespace?: string;
|
|
140
140
|
readonly isTypeOnly?: boolean;
|
|
141
|
-
readonly symbolId?: string;
|
|
141
|
+
readonly symbolId?: string; readonly originSymbolId?: string;
|
|
142
|
+
readonly exportedSymbolId?: string; readonly localSymbolId?: string;
|
|
142
143
|
readonly relationId?: string;
|
|
143
|
-
readonly ownershipRegionId?: string;
|
|
144
|
-
readonly ownershipRegionKey?: string;
|
|
144
|
+
readonly ownershipRegionId?: string; readonly ownershipRegionKey?: string;
|
|
145
145
|
readonly publicContract?: boolean;
|
|
146
146
|
readonly factId?: string;
|
|
147
147
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import{idFragment,uniqueByEvidenceId,uniqueByLossId,uniqueStrings}from'../../native-import-utils.js';import{createDocument,createPatch,createUniversalAstEnvelope}from'@shapeshift-labs/frontier-lang-kernel';
|
|
2
2
|
import{createNativeImportResultContract}from'./createNativeImportResultContract.js';import{createProjectImportAdmissionRecord}from'./createProjectImportAdmissionRecord.js';import{mergeSemanticIndexes}from'./mergeSemanticIndexes.js';import{summarizeNativeImportLosses}from'./summarizeNativeImportLosses.js';import{summarizeProjectSourcePreservation}from'./summarizeProjectSourcePreservation.js';
|
|
3
|
-
import{createProjectModuleSymbolResolver,resolveProjectModule}from'./projectSymbolGraphModuleResolution.js';
|
|
3
|
+
import{createProjectDocumentExportSymbolResolver,createProjectModuleSymbolResolver,resolveProjectModule}from'./projectSymbolGraphModuleResolution.js';
|
|
4
|
+
import{isReExportImportEdge,reExportIdentityInputFromEdge,reExportIdentityRecord}from'./projectSymbolGraphReExports.js';
|
|
4
5
|
export function createNativeProjectImportResult(input, imports) {
|
|
5
6
|
const idPart = idFragment(input.id ?? input.projectRoot ?? 'native_project');
|
|
6
7
|
const nodes = {};
|
|
@@ -141,8 +142,6 @@ export function createNativeProjectImportResult(input, imports) {
|
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
const PROJECT_SYMBOL_GRAPH_REMAINING_FIELDS = Object.freeze([
|
|
144
|
-
'moduleEdges[].packageName',
|
|
145
|
-
'moduleEdges[].packageExportCondition',
|
|
146
145
|
'reExportIdentities[].originSymbolId',
|
|
147
146
|
'reExportIdentities[].exportedSymbolId',
|
|
148
147
|
'reExportIdentities[].localSymbolId',
|
|
@@ -158,6 +157,7 @@ function createProjectSymbolGraphSummary(semanticIndex, imports, input) {
|
|
|
158
157
|
const documentsByPath = new Map(documents.filter((document) => document.path).map((document) => [document.path, document]));
|
|
159
158
|
const moduleResolution = input.moduleResolution ?? input.tsconfig;
|
|
160
159
|
const resolveTargetSymbolId = createProjectModuleSymbolResolver(semanticIndex?.symbols ?? [], documents);
|
|
160
|
+
const resolveDocumentExportSymbolId = createProjectDocumentExportSymbolResolver(semanticIndex?.symbols ?? [], documents);
|
|
161
161
|
const facts = semanticIndex?.facts ?? [];
|
|
162
162
|
const moduleEdgeFacts = facts.filter((fact) => fact.predicate === 'moduleEdge');
|
|
163
163
|
const moduleEdgeByRelation = new Map(moduleEdgeFacts.map((fact) => [fact.subjectId, fact]));
|
|
@@ -168,22 +168,17 @@ function createProjectSymbolGraphSummary(semanticIndex, imports, input) {
|
|
|
168
168
|
const exportEdges = relations
|
|
169
169
|
.filter((relation) => relation.predicate === 'exports')
|
|
170
170
|
.map((relation) => moduleEdgeRecord(relation, moduleEdgeByRelation, symbolsById, documentsById, documentsByPath, moduleResolution, resolveTargetSymbolId));
|
|
171
|
+
const moduleEdgeById = new Map([...importEdges, ...exportEdges].map((edge) => [edge.id, edge]));
|
|
171
172
|
const reExportIdentities = uniqueRecords([
|
|
172
173
|
...facts
|
|
173
174
|
.filter((fact) => fact.predicate === 'reExportIdentity' && fact.value)
|
|
174
|
-
.map((fact) => (
|
|
175
|
+
.map((fact) => reExportIdentityRecord(objectValue(fact.value), moduleEdgeById.get(objectValue(fact.value).relationId ?? fact.objectId), resolveDocumentExportSymbolId, { factId: fact.id })),
|
|
175
176
|
...exportEdges
|
|
176
177
|
.filter((edge) => edge.isReExport)
|
|
177
|
-
.map((edge) =>
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
sourceHash: edge.sourceHash,
|
|
182
|
-
moduleSpecifier: edge.moduleSpecifier,
|
|
183
|
-
symbolId: edge.targetSymbolId,
|
|
184
|
-
relationId: edge.id,
|
|
185
|
-
publicContract: edge.publicContract
|
|
186
|
-
}))
|
|
178
|
+
.map((edge) => reExportIdentityRecord(reExportIdentityInputFromEdge(edge, `reexport_${idFragment(edge.id)}`), edge, resolveDocumentExportSymbolId)),
|
|
179
|
+
...importEdges
|
|
180
|
+
.filter((edge) => isReExportImportEdge(edge))
|
|
181
|
+
.map((edge) => reExportIdentityRecord(reExportIdentityInputFromEdge(edge, `reexport_${idFragment(edge.id)}`), edge, resolveDocumentExportSymbolId))
|
|
187
182
|
]);
|
|
188
183
|
const publicContractRegions = uniqueRecords(facts
|
|
189
184
|
.filter((fact) => fact.predicate === 'publicContractRegion' && fact.value)
|
|
@@ -244,6 +239,9 @@ function moduleEdgeRecord(relation, moduleEdgeByRelation, symbolsById, documents
|
|
|
244
239
|
resolvedModulePath: resolution?.path,
|
|
245
240
|
targetDocumentId: resolution?.documentId,
|
|
246
241
|
resolutionKind: resolution?.kind,
|
|
242
|
+
packageName: resolution?.packageName,
|
|
243
|
+
packageSubpath: resolution?.packageSubpath,
|
|
244
|
+
packageExportCondition: resolution?.packageExportCondition,
|
|
247
245
|
importKind: firstString(moduleEdge.importKind, value.importKind, symbolMetadata.importKind),
|
|
248
246
|
exportKind: firstString(moduleEdge.exportKind, value.exportKind, symbolMetadata.exportKind),
|
|
249
247
|
importedName: firstString(moduleEdge.importedName, value.importedName, symbolMetadata.importedName),
|
|
@@ -17,14 +17,7 @@ export function resolveProjectModule(sourcePath, moduleSpecifier, documentsByPat
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function createProjectModuleSymbolResolver(symbols, documents) {
|
|
20
|
-
const
|
|
21
|
-
const exportedByDocumentAndName = new Map();
|
|
22
|
-
for (const symbol of symbols ?? []) {
|
|
23
|
-
if (symbol?.kind !== 'export' || !symbol.name) continue;
|
|
24
|
-
const document = documentsByPath.get(symbol.definitionSpan?.path);
|
|
25
|
-
if (!document) continue;
|
|
26
|
-
exportedByDocumentAndName.set(symbolKey(document.id, symbol.name), symbol);
|
|
27
|
-
}
|
|
20
|
+
const exportedByDocumentAndName = projectExportSymbolMap(symbols, documents);
|
|
28
21
|
return function resolveProjectModuleSymbol(edge) {
|
|
29
22
|
if (!edge?.targetDocumentId) return undefined;
|
|
30
23
|
const targetName = targetExportName(edge);
|
|
@@ -33,23 +26,45 @@ export function createProjectModuleSymbolResolver(symbols, documents) {
|
|
|
33
26
|
};
|
|
34
27
|
}
|
|
35
28
|
|
|
29
|
+
export function createProjectDocumentExportSymbolResolver(symbols, documents) {
|
|
30
|
+
const exportedByDocumentAndName = projectExportSymbolMap(symbols, documents);
|
|
31
|
+
return function resolveDocumentExportSymbol(documentId, name) {
|
|
32
|
+
if (!documentId || !name) return undefined;
|
|
33
|
+
return exportedByDocumentAndName.get(symbolKey(documentId, name))?.id;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function projectExportSymbolMap(symbols, documents) {
|
|
38
|
+
const documentsByPath = new Map(documents.filter((document) => document.path).map((document) => [document.path, document]));
|
|
39
|
+
const exportedByDocumentAndName = new Map();
|
|
40
|
+
for (const symbol of symbols ?? []) {
|
|
41
|
+
if (symbol?.kind !== 'export' || !symbol.name) continue;
|
|
42
|
+
const document = documentsByPath.get(symbol.definitionSpan?.path);
|
|
43
|
+
if (document) exportedByDocumentAndName.set(symbolKey(document.id, symbol.name), symbol);
|
|
44
|
+
}
|
|
45
|
+
return exportedByDocumentAndName;
|
|
46
|
+
}
|
|
47
|
+
|
|
36
48
|
function resolveConfiguredProjectModule(moduleSpecifier, documentsByPath, moduleResolution) {
|
|
37
|
-
const
|
|
49
|
+
const packageInfo = packageSpecifierInfo(moduleSpecifier);
|
|
50
|
+
const candidates = configuredModuleCandidates(moduleSpecifier, moduleResolution, packageInfo);
|
|
38
51
|
let firstMissing;
|
|
39
52
|
for (const candidate of candidates) {
|
|
40
53
|
const target = moduleTargetDocument(candidate.path, documentsByPath);
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
const packageFields = packageResolutionFields(candidate, packageInfo);
|
|
55
|
+
if (target) return { path: target.path, documentId: target.id, kind: `${candidate.kind}-source`, ...packageFields };
|
|
56
|
+
firstMissing ??= { path: candidate.path, kind: `${candidate.kind}-missing`, ...packageFields };
|
|
43
57
|
}
|
|
44
|
-
return firstMissing;
|
|
58
|
+
return firstMissing ?? (packageInfo ? { kind: 'package-external', ...packageInfo } : undefined);
|
|
45
59
|
}
|
|
46
60
|
|
|
47
|
-
function configuredModuleCandidates(moduleSpecifier, moduleResolution = {}) {
|
|
61
|
+
function configuredModuleCandidates(moduleSpecifier, moduleResolution = {}, packageInfo) {
|
|
48
62
|
const compilerOptions = moduleResolution.compilerOptions ?? {};
|
|
49
63
|
const baseUrl = normalizeProjectPath(moduleResolution.baseUrl ?? compilerOptions.baseUrl ?? '');
|
|
50
64
|
return uniquePaths([
|
|
51
65
|
...aliasCandidates(moduleSpecifier, moduleResolution.aliases, 'alias', baseUrl),
|
|
52
66
|
...aliasCandidates(moduleSpecifier, moduleResolution.paths ?? compilerOptions.paths, 'path-alias', baseUrl),
|
|
67
|
+
...packageCandidates(packageInfo, moduleResolution),
|
|
53
68
|
...baseUrlCandidates(moduleSpecifier, baseUrl)
|
|
54
69
|
]);
|
|
55
70
|
}
|
|
@@ -71,6 +86,74 @@ function baseUrlCandidates(moduleSpecifier, baseUrl) {
|
|
|
71
86
|
return [{ kind: 'base-url', path: normalizeProjectPath(joinProjectPath(baseUrl, moduleSpecifier)) }];
|
|
72
87
|
}
|
|
73
88
|
|
|
89
|
+
function packageCandidates(packageInfo, moduleResolution = {}) {
|
|
90
|
+
if (!packageInfo) return [];
|
|
91
|
+
const options = moduleResolution.packages?.[packageInfo.packageName];
|
|
92
|
+
if (!options) return [];
|
|
93
|
+
const root = normalizeProjectPath(options.root ?? '');
|
|
94
|
+
const subpath = packageInfo.packageSubpath === '.' ? '' : packageInfo.packageSubpath.slice(2);
|
|
95
|
+
return uniquePaths([
|
|
96
|
+
...packageExportCandidates(packageInfo, options, moduleResolution).map((candidate) => ({
|
|
97
|
+
...candidate,
|
|
98
|
+
path: normalizeProjectPath(joinProjectPath(root, candidate.path))
|
|
99
|
+
})),
|
|
100
|
+
...packageFallbackTargets(options, subpath).map((path) => ({
|
|
101
|
+
kind: 'package',
|
|
102
|
+
path: normalizeProjectPath(joinProjectPath(root, path)),
|
|
103
|
+
...packageInfo
|
|
104
|
+
}))
|
|
105
|
+
]);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function packageExportCandidates(packageInfo, options, moduleResolution) {
|
|
109
|
+
const targets = packageExportTargets(options.exports, packageInfo.packageSubpath, packageConditions(moduleResolution));
|
|
110
|
+
return targets.map((target) => ({
|
|
111
|
+
kind: 'package',
|
|
112
|
+
path: target.path,
|
|
113
|
+
packageExportCondition: target.condition,
|
|
114
|
+
...packageInfo
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function packageExportTargets(exportsValue, subpath, conditions) {
|
|
119
|
+
if (!exportsValue) return [];
|
|
120
|
+
return exportTargetsForValue(exportMapValue(exportsValue, subpath), conditions);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function exportMapValue(exportsValue, subpath) {
|
|
124
|
+
if (!isRecord(exportsValue) || !Object.keys(exportsValue).some((key) => key.startsWith('.'))) return subpath === '.' ? exportsValue : undefined;
|
|
125
|
+
return exportsValue[subpath] ?? patternExportMapValue(exportsValue, subpath);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function patternExportMapValue(exportsValue, subpath) {
|
|
129
|
+
for (const [pattern, target] of Object.entries(exportsValue)) {
|
|
130
|
+
const capture = patternCapture(subpath, pattern);
|
|
131
|
+
if (capture !== undefined) return replaceExportTargetCapture(target, capture);
|
|
132
|
+
}
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function replaceExportTargetCapture(target, capture) {
|
|
137
|
+
if (typeof target === 'string') return target.replace('*', capture);
|
|
138
|
+
if (Array.isArray(target)) return target.map((entry) => replaceExportTargetCapture(entry, capture));
|
|
139
|
+
if (!isRecord(target)) return target;
|
|
140
|
+
return Object.fromEntries(Object.entries(target).map(([key, value]) => [key, replaceExportTargetCapture(value, capture)]));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function exportTargetsForValue(value, conditions, condition) {
|
|
144
|
+
if (!value) return [];
|
|
145
|
+
if (typeof value === 'string') return [{ path: value, condition }];
|
|
146
|
+
if (Array.isArray(value)) return value.flatMap((entry) => exportTargetsForValue(entry, conditions, condition));
|
|
147
|
+
if (!isRecord(value)) return [];
|
|
148
|
+
return conditions.flatMap((key) => exportTargetsForValue(value[key], conditions, key));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function packageFallbackTargets(options, subpath) {
|
|
152
|
+
const sourceRoot = normalizeProjectPath(options.sourceRoot ?? 'src');
|
|
153
|
+
if (subpath) return [joinProjectPath(sourceRoot, subpath), subpath];
|
|
154
|
+
return [options.types, options.main, joinProjectPath(sourceRoot, 'index')].filter(Boolean);
|
|
155
|
+
}
|
|
156
|
+
|
|
74
157
|
function moduleTargetDocument(path, documentsByPath) {
|
|
75
158
|
for (const candidate of modulePathCandidates(path)) {
|
|
76
159
|
const document = documentsByPath.get(candidate);
|
|
@@ -80,7 +163,7 @@ function moduleTargetDocument(path, documentsByPath) {
|
|
|
80
163
|
}
|
|
81
164
|
|
|
82
165
|
function modulePathCandidates(path) {
|
|
83
|
-
return [path, `${path}.js`, `${path}.ts`, `${path}.tsx`, `${path}.jsx`, `${path}/index.js`, `${path}/index.ts`];
|
|
166
|
+
return [path, `${path}.js`, `${path}.ts`, `${path}.tsx`, `${path}.jsx`, `${path}.d.ts`, `${path}/index.js`, `${path}/index.ts`, `${path}/index.d.ts`];
|
|
84
167
|
}
|
|
85
168
|
|
|
86
169
|
function targetExportName(edge) {
|
|
@@ -114,6 +197,34 @@ function joinProjectPath(left, right) {
|
|
|
114
197
|
return left ? `${left}/${right}` : String(right);
|
|
115
198
|
}
|
|
116
199
|
|
|
200
|
+
function packageSpecifierInfo(moduleSpecifier) {
|
|
201
|
+
if (!moduleSpecifier || String(moduleSpecifier).startsWith('#')) return undefined;
|
|
202
|
+
const parts = String(moduleSpecifier).split('/');
|
|
203
|
+
if (!parts[0] || parts[0] === '.' || parts[0] === '..') return undefined;
|
|
204
|
+
const scoped = parts[0].startsWith('@');
|
|
205
|
+
if (scoped && parts.length < 2) return undefined;
|
|
206
|
+
const packageName = scoped ? `${parts[0]}/${parts[1]}` : parts[0];
|
|
207
|
+
const rest = parts.slice(scoped ? 2 : 1).join('/');
|
|
208
|
+
return { packageName, packageSubpath: rest ? `./${rest}` : '.' };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function packageResolutionFields(candidate, packageInfo) {
|
|
212
|
+
if (!candidate.packageName && candidate.kind !== 'package') return {};
|
|
213
|
+
return {
|
|
214
|
+
packageName: candidate.packageName ?? packageInfo?.packageName,
|
|
215
|
+
packageSubpath: candidate.packageSubpath ?? packageInfo?.packageSubpath,
|
|
216
|
+
packageExportCondition: candidate.packageExportCondition
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function packageConditions(moduleResolution = {}) {
|
|
221
|
+
return moduleResolution.packageExportConditions ?? moduleResolution.conditions ?? ['types', 'import', 'module', 'require', 'default'];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function isRecord(value) {
|
|
225
|
+
return value && typeof value === 'object' && !Array.isArray(value);
|
|
226
|
+
}
|
|
227
|
+
|
|
117
228
|
function normalizeProjectPath(path) {
|
|
118
229
|
const parts = [];
|
|
119
230
|
for (const part of String(path).split('/')) {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export function reExportIdentityRecord(identity, edge, resolveDocumentExportSymbolId, extra = {}) {
|
|
2
|
+
const exportedName = firstString(identity.exportedName, edge?.exportedName, edge?.importedName === '*' ? undefined : (edge?.exportedName ?? edge?.importedName));
|
|
3
|
+
const importedName = firstString(identity.importedName, edge?.importedName);
|
|
4
|
+
const localName = firstString(identity.localName, edge?.localName, exportedName);
|
|
5
|
+
return compactRecord({
|
|
6
|
+
...identity,
|
|
7
|
+
exportedName,
|
|
8
|
+
importedName,
|
|
9
|
+
localName,
|
|
10
|
+
originSymbolId: firstString(identity.originSymbolId, edge?.resolvedTargetSymbolId),
|
|
11
|
+
exportedSymbolId: firstString(identity.exportedSymbolId, resolveDocumentExportSymbolId(edge?.sourceDocumentId, exportedName), edge?.predicate === 'exports' ? edge?.targetSymbolId : undefined),
|
|
12
|
+
localSymbolId: firstString(identity.localSymbolId, edge?.targetSymbolId),
|
|
13
|
+
...extra
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function isReExportImportEdge(edge) {
|
|
18
|
+
return edge.importKind === 'reexport' || edge.importKind === 'namespace-reexport';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function reExportIdentityInputFromEdge(edge, id) {
|
|
22
|
+
return compactRecord({
|
|
23
|
+
id,
|
|
24
|
+
sourceDocumentId: edge.sourceDocumentId,
|
|
25
|
+
sourcePath: edge.sourcePath,
|
|
26
|
+
sourceHash: edge.sourceHash,
|
|
27
|
+
moduleSpecifier: edge.moduleSpecifier,
|
|
28
|
+
symbolId: edge.targetSymbolId,
|
|
29
|
+
relationId: edge.id,
|
|
30
|
+
publicContract: edge.publicContract
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function compactRecord(record) {
|
|
35
|
+
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function firstString(...values) {
|
|
39
|
+
for (const value of values) {
|
|
40
|
+
if (value !== undefined && value !== null && String(value)) return String(value);
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
package/package.json
CHANGED