@ecopages/core 0.2.0-alpha.45 → 0.2.0-alpha.47
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/core",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.47",
|
|
4
4
|
"description": "Core package for Ecopages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecopages",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"directory": "packages/core"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@ecopages/file-system": "0.2.0-alpha.
|
|
20
|
+
"@ecopages/file-system": "0.2.0-alpha.47",
|
|
21
21
|
"@ecopages/logger": "^0.2.3",
|
|
22
22
|
"@ecopages/scripts-injector": "^0.1.5",
|
|
23
23
|
"@worker-tools/html-rewriter": "0.1.0-pre.19",
|
|
@@ -46,6 +46,70 @@ function resolveRuntimePackageRoot(specifier, resolvedPath, parentPath) {
|
|
|
46
46
|
const packageName = getPackageNameFromSpecifier(specifier);
|
|
47
47
|
return findInstalledPackageDir(packageName, parentPath) ?? findPackageRoot(resolvedPath);
|
|
48
48
|
}
|
|
49
|
+
function isPackageExportedSubpath(specifier, resolvedPath, parentPath) {
|
|
50
|
+
const packageName = getPackageNameFromSpecifier(specifier);
|
|
51
|
+
if (specifier === packageName) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
const packageRoot = resolveRuntimePackageRoot(specifier, resolvedPath, parentPath);
|
|
55
|
+
const manifest = readPackageManifest(packageRoot);
|
|
56
|
+
if (!manifest?.exports || typeof manifest.exports !== "object" || Array.isArray(manifest.exports)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const subpath = `.${specifier.slice(packageName.length)}`;
|
|
60
|
+
return subpath in manifest.exports;
|
|
61
|
+
}
|
|
62
|
+
function getNodeExternalSpecifier(specifier, resolvedPath, parentPath) {
|
|
63
|
+
const packageName = getPackageNameFromSpecifier(specifier);
|
|
64
|
+
if (specifier === packageName) {
|
|
65
|
+
return specifier;
|
|
66
|
+
}
|
|
67
|
+
if (path.extname(specifier)) {
|
|
68
|
+
return specifier;
|
|
69
|
+
}
|
|
70
|
+
if (isPackageExportedSubpath(specifier, resolvedPath, parentPath)) {
|
|
71
|
+
return specifier;
|
|
72
|
+
}
|
|
73
|
+
for (const extension of [".js", ".mjs", ".cjs", ".json"]) {
|
|
74
|
+
const candidateSpecifier = `${specifier}${extension}`;
|
|
75
|
+
try {
|
|
76
|
+
const candidateResolvedPath = resolveSpecifier(candidateSpecifier, parentPath);
|
|
77
|
+
if (existsSync(candidateResolvedPath)) {
|
|
78
|
+
return candidateSpecifier;
|
|
79
|
+
}
|
|
80
|
+
} catch {
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
for (const candidatePath of [
|
|
84
|
+
resolvedPath,
|
|
85
|
+
...[".js", ".mjs", ".cjs", ".json"].map((extension) => `${specifier}${extension}`)
|
|
86
|
+
]) {
|
|
87
|
+
const candidateResolvedPath = candidatePath === resolvedPath ? resolvedPath : (() => {
|
|
88
|
+
try {
|
|
89
|
+
return resolveSpecifier(candidatePath, parentPath);
|
|
90
|
+
} catch {
|
|
91
|
+
return void 0;
|
|
92
|
+
}
|
|
93
|
+
})();
|
|
94
|
+
if (!candidateResolvedPath) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (!existsSync(candidateResolvedPath)) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const resolvedExtension = path.extname(candidateResolvedPath);
|
|
101
|
+
if (![".js", ".mjs", ".cjs", ".json"].includes(resolvedExtension)) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const packageRoot = resolveRuntimePackageRoot(specifier, candidateResolvedPath, parentPath);
|
|
105
|
+
const requestedSubpath = specifier.slice(packageName.length + 1);
|
|
106
|
+
const resolvedSubpath = path.relative(packageRoot, candidateResolvedPath);
|
|
107
|
+
if (resolvedSubpath === `${requestedSubpath}${resolvedExtension}`) {
|
|
108
|
+
return `${specifier}${resolvedExtension}`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return specifier;
|
|
112
|
+
}
|
|
49
113
|
function ensureRuntimePackageLink(nodeModulesDir, specifier, resolvedPath, parentPath) {
|
|
50
114
|
const packageName = getPackageNameFromSpecifier(specifier);
|
|
51
115
|
const packageRoot = resolveRuntimePackageRoot(specifier, resolvedPath, parentPath);
|
|
@@ -256,7 +320,7 @@ function resolveNodeBootstrapDependency(args, options) {
|
|
|
256
320
|
const resolvedPath = resolveSpecifier(args.path, resolveParent);
|
|
257
321
|
ensureRuntimePackageLink(options.runtimeNodeModulesDir, args.path, resolvedPath, resolveParent);
|
|
258
322
|
return {
|
|
259
|
-
path: args.path,
|
|
323
|
+
path: getNodeExternalSpecifier(args.path, resolvedPath, resolveParent),
|
|
260
324
|
external: true
|
|
261
325
|
};
|
|
262
326
|
}
|