@stream44.studio/encapsulate 0.4.0-rc.21 → 0.4.0-rc.23
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
|
@@ -28,12 +28,16 @@ function safeCapsuleName(name: string) {
|
|
|
28
28
|
* @returns The cache file path to use
|
|
29
29
|
*/
|
|
30
30
|
async function constructCacheFilePath(moduleFilepath: string, importStackLine: number, spineFilesystemRoot: string): Promise<string> {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const isExternal = moduleFilepath.startsWith('../')
|
|
32
|
+
const hasNodeModules = moduleFilepath.includes('node_modules/')
|
|
33
|
+
|
|
34
|
+
if (isExternal || hasNodeModules) {
|
|
35
|
+
// External module or node_modules path - construct npm URI
|
|
33
36
|
const absoluteFilepath = join(spineFilesystemRoot, moduleFilepath)
|
|
34
37
|
const npmUri = await constructNpmUriForCache(absoluteFilepath, spineFilesystemRoot)
|
|
35
38
|
if (npmUri) {
|
|
36
|
-
|
|
39
|
+
// Prefix with o/npmjs.com/node_modules/ for external modules
|
|
40
|
+
return `o/npmjs.com/node_modules/${npmUri}:${importStackLine}`
|
|
37
41
|
}
|
|
38
42
|
// Fallback to normalized path
|
|
39
43
|
return `${normalize(moduleFilepath).replace(/^\.\.\//, '').replace(/\.\.\//g, '')}:${importStackLine}`
|
|
@@ -43,10 +47,20 @@ async function constructCacheFilePath(moduleFilepath: string, importStackLine: n
|
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
/**
|
|
46
|
-
* Finds the nearest package.json and constructs an npm URI for cache files
|
|
50
|
+
* Finds the nearest package.json and constructs an npm URI for cache files.
|
|
51
|
+
* First checks if the path contains /node_modules/ and if so, extracts the portion
|
|
52
|
+
* after the last /node_modules/ occurrence for consistent paths in dev and installed mode.
|
|
47
53
|
* This matches the logic from static-analyzer.v0.ts
|
|
48
54
|
*/
|
|
49
55
|
async function constructNpmUriForCache(absoluteFilepath: string, spineRoot: string): Promise<string | null> {
|
|
56
|
+
// Check for /node_modules/ in the path — use the last occurrence to handle nested node_modules
|
|
57
|
+
const nodeModulesMarker = '/node_modules/'
|
|
58
|
+
const lastIdx = absoluteFilepath.lastIndexOf(nodeModulesMarker)
|
|
59
|
+
if (lastIdx !== -1) {
|
|
60
|
+
// Extract everything after the last /node_modules/
|
|
61
|
+
return absoluteFilepath.substring(lastIdx + nodeModulesMarker.length)
|
|
62
|
+
}
|
|
63
|
+
|
|
50
64
|
let currentDir = dirname(absoluteFilepath)
|
|
51
65
|
const maxDepth = 20 // Prevent infinite loops
|
|
52
66
|
|
|
@@ -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([
|
|
@@ -224,11 +241,15 @@ export function StaticAnalyzer({
|
|
|
224
241
|
|
|
225
242
|
// Determine the cache file path based on whether the module is external or internal
|
|
226
243
|
let cacheFilePath: string
|
|
227
|
-
|
|
228
|
-
|
|
244
|
+
const isExternal = encapsulateOptions.moduleFilepath.startsWith('../')
|
|
245
|
+
const hasNodeModules = encapsulateOptions.moduleFilepath.includes('node_modules/')
|
|
246
|
+
|
|
247
|
+
if (isExternal || hasNodeModules) {
|
|
248
|
+
// External module or node_modules path - construct npm URI
|
|
229
249
|
const npmUri = await constructNpmUri(moduleFilepath, spineOptions.spineFilesystemRoot)
|
|
230
250
|
if (npmUri) {
|
|
231
|
-
|
|
251
|
+
// Prefix with o/npmjs.com/node_modules/ for external modules
|
|
252
|
+
cacheFilePath = `o/npmjs.com/node_modules/${npmUri}`
|
|
232
253
|
} else {
|
|
233
254
|
// Fallback to normalized path if npm URI construction fails
|
|
234
255
|
cacheFilePath = normalize(encapsulateOptions.moduleFilepath).replace(/^\.\.\//, '').replace(/\.\.\//g, '')
|