@stream44.studio/encapsulate 0.4.0-rc.21 → 0.4.0-rc.22
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/package.json
CHANGED
|
@@ -33,7 +33,8 @@ async function constructCacheFilePath(moduleFilepath: string, importStackLine: n
|
|
|
33
33
|
const absoluteFilepath = join(spineFilesystemRoot, moduleFilepath)
|
|
34
34
|
const npmUri = await constructNpmUriForCache(absoluteFilepath, spineFilesystemRoot)
|
|
35
35
|
if (npmUri) {
|
|
36
|
-
|
|
36
|
+
// Prefix with o/npmjs.com/node_modules/ for external modules
|
|
37
|
+
return `o/npmjs.com/node_modules/${npmUri}:${importStackLine}`
|
|
37
38
|
}
|
|
38
39
|
// Fallback to normalized path
|
|
39
40
|
return `${normalize(moduleFilepath).replace(/^\.\.\//, '').replace(/\.\.\//g, '')}:${importStackLine}`
|
|
@@ -43,10 +44,20 @@ async function constructCacheFilePath(moduleFilepath: string, importStackLine: n
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
/**
|
|
46
|
-
* Finds the nearest package.json and constructs an npm URI for cache files
|
|
47
|
+
* Finds the nearest package.json and constructs an npm URI for cache files.
|
|
48
|
+
* First checks if the path contains /node_modules/ and if so, extracts the portion
|
|
49
|
+
* after the last /node_modules/ occurrence for consistent paths in dev and installed mode.
|
|
47
50
|
* This matches the logic from static-analyzer.v0.ts
|
|
48
51
|
*/
|
|
49
52
|
async function constructNpmUriForCache(absoluteFilepath: string, spineRoot: string): Promise<string | null> {
|
|
53
|
+
// Check for /node_modules/ in the path — use the last occurrence to handle nested node_modules
|
|
54
|
+
const nodeModulesMarker = '/node_modules/'
|
|
55
|
+
const lastIdx = absoluteFilepath.lastIndexOf(nodeModulesMarker)
|
|
56
|
+
if (lastIdx !== -1) {
|
|
57
|
+
// Extract everything after the last /node_modules/
|
|
58
|
+
return absoluteFilepath.substring(lastIdx + nodeModulesMarker.length)
|
|
59
|
+
}
|
|
60
|
+
|
|
50
61
|
let currentDir = dirname(absoluteFilepath)
|
|
51
62
|
const maxDepth = 20 // Prevent infinite loops
|
|
52
63
|
|
|
@@ -14,12 +14,22 @@ const ENCAPSULATE_MODULE_EXPORTS = new Set([
|
|
|
14
14
|
])
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Finds the nearest package.json and constructs an npm URI for the given filepath
|
|
17
|
+
* Finds the nearest package.json and constructs an npm URI for the given filepath.
|
|
18
|
+
* First checks if the path contains /node_modules/ and if so, extracts the portion
|
|
19
|
+
* after the last /node_modules/ occurrence for consistent paths in dev and installed mode.
|
|
18
20
|
* @param absoluteFilepath - The absolute path to the file
|
|
19
21
|
* @param spineRoot - The spine filesystem root
|
|
20
22
|
* @returns The npm URI (e.g., '@scope/package/path/to/file.ts') or null if not found
|
|
21
23
|
*/
|
|
22
24
|
async function constructNpmUri(absoluteFilepath: string, spineRoot: string): Promise<string | null> {
|
|
25
|
+
// Check for /node_modules/ in the path — use the last occurrence to handle nested node_modules
|
|
26
|
+
const nodeModulesMarker = '/node_modules/'
|
|
27
|
+
const lastIdx = absoluteFilepath.lastIndexOf(nodeModulesMarker)
|
|
28
|
+
if (lastIdx !== -1) {
|
|
29
|
+
// Extract everything after the last /node_modules/
|
|
30
|
+
return absoluteFilepath.substring(lastIdx + nodeModulesMarker.length)
|
|
31
|
+
}
|
|
32
|
+
|
|
23
33
|
let currentDir = dirname(absoluteFilepath)
|
|
24
34
|
const maxDepth = 20 // Prevent infinite loops
|
|
25
35
|
|
|
@@ -57,6 +67,13 @@ async function constructNpmUri(absoluteFilepath: string, spineRoot: string): Pro
|
|
|
57
67
|
return null
|
|
58
68
|
}
|
|
59
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Checks if a filepath was resolved via node_modules
|
|
72
|
+
*/
|
|
73
|
+
function isFromNodeModules(absoluteFilepath: string): boolean {
|
|
74
|
+
return absoluteFilepath.includes('/node_modules/')
|
|
75
|
+
}
|
|
76
|
+
|
|
60
77
|
// Native JavaScript APIs that don't require explicit ambient reference declaration
|
|
61
78
|
// These are module-global builtins available in all JavaScript runtimes
|
|
62
79
|
const MODULE_GLOBAL_BUILTINS = new Set([
|
|
@@ -228,7 +245,8 @@ export function StaticAnalyzer({
|
|
|
228
245
|
// External module - construct npm URI
|
|
229
246
|
const npmUri = await constructNpmUri(moduleFilepath, spineOptions.spineFilesystemRoot)
|
|
230
247
|
if (npmUri) {
|
|
231
|
-
|
|
248
|
+
// Prefix with o/npmjs.com/node_modules/ for external modules
|
|
249
|
+
cacheFilePath = `o/npmjs.com/node_modules/${npmUri}`
|
|
232
250
|
} else {
|
|
233
251
|
// Fallback to normalized path if npm URI construction fails
|
|
234
252
|
cacheFilePath = normalize(encapsulateOptions.moduleFilepath).replace(/^\.\.\//, '').replace(/\.\.\//g, '')
|