@shapeshift-labs/frontier-lang-compiler 0.2.107 → 0.2.108

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.
@@ -78,8 +78,6 @@ export interface ImportNativeProjectOptions {
78
78
  }
79
79
 
80
80
  export type NativeProjectSymbolGraphRemainingField =
81
- | 'moduleEdges[].resolvedModulePath'
82
- | 'moduleEdges[].targetDocumentId'
83
81
  | 'moduleEdges[].resolvedTargetSymbolId'
84
82
  | 'moduleEdges[].resolutionKind'
85
83
  | 'moduleEdges[].packageName'
@@ -112,6 +110,9 @@ export interface NativeProjectSymbolGraphModuleEdgeRecord {
112
110
  readonly sourcePath?: string;
113
111
  readonly sourceHash?: string;
114
112
  readonly moduleSpecifier?: string;
113
+ readonly resolvedModulePath?: string;
114
+ readonly targetDocumentId?: string;
115
+ readonly resolutionKind?: 'relative-source' | 'relative-missing' | string;
115
116
  readonly importKind?: string;
116
117
  readonly exportKind?: string;
117
118
  readonly importedName?: string;
@@ -1,5 +1,6 @@
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{resolveRelativeProjectModule}from'./projectSymbolGraphModuleResolution.js';
3
4
  export function createNativeProjectImportResult(input, imports) {
4
5
  const idPart = idFragment(input.id ?? input.projectRoot ?? 'native_project');
5
6
  const nodes = {};
@@ -140,8 +141,6 @@ export function createNativeProjectImportResult(input, imports) {
140
141
  }
141
142
 
142
143
  const PROJECT_SYMBOL_GRAPH_REMAINING_FIELDS = Object.freeze([
143
- 'moduleEdges[].resolvedModulePath',
144
- 'moduleEdges[].targetDocumentId',
145
144
  'moduleEdges[].resolvedTargetSymbolId',
146
145
  'moduleEdges[].resolutionKind',
147
146
  'moduleEdges[].packageName',
@@ -158,16 +157,17 @@ function createProjectSymbolGraphSummary(semanticIndex, imports, input) {
158
157
  const documents = semanticIndex?.documents ?? [];
159
158
  const symbolsById = new Map((semanticIndex?.symbols ?? []).map((symbol) => [symbol.id, symbol]));
160
159
  const documentsById = new Map(documents.map((document) => [document.id, document]));
160
+ const documentsByPath = new Map(documents.filter((document) => document.path).map((document) => [document.path, document]));
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]));
164
164
  const relations = semanticIndex?.relations ?? [];
165
165
  const importEdges = relations
166
166
  .filter((relation) => relation.predicate === 'imports')
167
- .map((relation) => moduleEdgeRecord(relation, moduleEdgeByRelation, symbolsById, documentsById));
167
+ .map((relation) => moduleEdgeRecord(relation, moduleEdgeByRelation, symbolsById, documentsById, documentsByPath));
168
168
  const exportEdges = relations
169
169
  .filter((relation) => relation.predicate === 'exports')
170
- .map((relation) => moduleEdgeRecord(relation, moduleEdgeByRelation, symbolsById, documentsById));
170
+ .map((relation) => moduleEdgeRecord(relation, moduleEdgeByRelation, symbolsById, documentsById, documentsByPath));
171
171
  const reExportIdentities = uniqueRecords([
172
172
  ...facts
173
173
  .filter((fact) => fact.predicate === 'reExportIdentity' && fact.value)
@@ -213,7 +213,7 @@ function createProjectSymbolGraphSummary(semanticIndex, imports, input) {
213
213
  };
214
214
  }
215
215
 
216
- function moduleEdgeRecord(relation, moduleEdgeByRelation, symbolsById, documentsById) {
216
+ function moduleEdgeRecord(relation, moduleEdgeByRelation, symbolsById, documentsById, documentsByPath) {
217
217
  const fact = moduleEdgeByRelation.get(relation.id);
218
218
  const value = objectValue(fact?.value);
219
219
  const metadata = objectValue(relation.metadata);
@@ -228,6 +228,7 @@ function moduleEdgeRecord(relation, moduleEdgeByRelation, symbolsById, documents
228
228
  symbolMetadata.moduleSpecifier,
229
229
  symbol?.kind === 'module' ? symbol.name : undefined
230
230
  );
231
+ const resolution = resolveRelativeProjectModule(document?.path, moduleSpecifier, documentsByPath);
231
232
  return compactRecord({
232
233
  id: relation.id,
233
234
  sourceDocumentId: relation.sourceId,
@@ -237,6 +238,9 @@ function moduleEdgeRecord(relation, moduleEdgeByRelation, symbolsById, documents
237
238
  sourcePath: document?.path,
238
239
  sourceHash: document?.sourceHash,
239
240
  moduleSpecifier,
241
+ resolvedModulePath: resolution?.path,
242
+ targetDocumentId: resolution?.documentId,
243
+ resolutionKind: resolution?.kind,
240
244
  importKind: firstString(moduleEdge.importKind, value.importKind),
241
245
  exportKind: firstString(moduleEdge.exportKind, value.exportKind),
242
246
  importedName: firstString(moduleEdge.importedName, value.importedName),
@@ -0,0 +1,33 @@
1
+ export function resolveRelativeProjectModule(sourcePath, moduleSpecifier, documentsByPath) {
2
+ if (!sourcePath || !moduleSpecifier || !moduleSpecifier.startsWith('.')) return undefined;
3
+ const base = sourcePath.includes('/') ? sourcePath.slice(0, sourcePath.lastIndexOf('/')) : '';
4
+ const unresolvedPath = normalizeProjectPath(`${base}/${moduleSpecifier}`);
5
+ const target = moduleTargetDocument(unresolvedPath, documentsByPath);
6
+ return {
7
+ path: target?.path ?? unresolvedPath,
8
+ documentId: target?.id,
9
+ kind: target ? 'relative-source' : 'relative-missing'
10
+ };
11
+ }
12
+
13
+ function moduleTargetDocument(path, documentsByPath) {
14
+ for (const candidate of modulePathCandidates(path)) {
15
+ const document = documentsByPath.get(candidate);
16
+ if (document) return document;
17
+ }
18
+ return undefined;
19
+ }
20
+
21
+ function modulePathCandidates(path) {
22
+ return [path, `${path}.js`, `${path}.ts`, `${path}.tsx`, `${path}.jsx`, `${path}/index.js`, `${path}/index.ts`];
23
+ }
24
+
25
+ function normalizeProjectPath(path) {
26
+ const parts = [];
27
+ for (const part of String(path).split('/')) {
28
+ if (!part || part === '.') continue;
29
+ if (part === '..') parts.pop();
30
+ else parts.push(part);
31
+ }
32
+ return parts.join('/');
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshift-labs/frontier-lang-compiler",
3
- "version": "0.2.107",
3
+ "version": "0.2.108",
4
4
  "description": "Compiler facade for Frontier Lang source documents and language projection adapters.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",