ecopages 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.
@@ -77,6 +77,50 @@ function ensureRuntimePackageLink(nodeModulesDir, specifier, resolvedPath) {
77
77
  }
78
78
  symlinkSync(packageRoot, linkPath, "dir");
79
79
  }
80
+ function readPackageManifest(packageDir) {
81
+ const packageJsonPath = path.join(packageDir, "package.json");
82
+ try {
83
+ return JSON.parse(readFileSync(packageJsonPath, "utf8"));
84
+ } catch {
85
+ return void 0;
86
+ }
87
+ }
88
+ function isPackageExportedSubpath(specifier, resolvedPath) {
89
+ const packageName = getPackageNameFromSpecifier(specifier);
90
+ if (specifier === packageName) {
91
+ return false;
92
+ }
93
+ const packageRoot = findPackageRoot(resolvedPath);
94
+ const manifest = readPackageManifest(packageRoot);
95
+ if (!manifest?.exports || typeof manifest.exports !== "object" || Array.isArray(manifest.exports)) {
96
+ return false;
97
+ }
98
+ const subpath = `.${specifier.slice(packageName.length)}`;
99
+ return subpath in manifest.exports;
100
+ }
101
+ function getNodeExternalSpecifier(specifier, resolvedPath) {
102
+ const packageName = getPackageNameFromSpecifier(specifier);
103
+ if (specifier === packageName) {
104
+ return specifier;
105
+ }
106
+ if (path.extname(specifier)) {
107
+ return specifier;
108
+ }
109
+ if (isPackageExportedSubpath(specifier, resolvedPath)) {
110
+ return specifier;
111
+ }
112
+ const resolvedExtension = path.extname(resolvedPath);
113
+ if (![".js", ".mjs", ".cjs", ".json"].includes(resolvedExtension)) {
114
+ return specifier;
115
+ }
116
+ const packageRoot = findPackageRoot(resolvedPath);
117
+ const requestedSubpath = specifier.slice(packageName.length + 1);
118
+ const resolvedSubpath = path.relative(packageRoot, resolvedPath);
119
+ if (resolvedSubpath === `${requestedSubpath}${resolvedExtension}`) {
120
+ return `${specifier}${resolvedExtension}`;
121
+ }
122
+ return specifier;
123
+ }
80
124
  function createNodeEntryBridgePlugin({ rootDir, entryFile, runtimeNodeModulesDir }) {
81
125
  return {
82
126
  name: "ecopages-node-entry-bridge",
@@ -97,7 +141,7 @@ function createNodeEntryBridgePlugin({ rootDir, entryFile, runtimeNodeModulesDir
97
141
  }
98
142
  if (!args.path.startsWith("@ecopages/")) {
99
143
  return {
100
- path: args.path,
144
+ path: getNodeExternalSpecifier(args.path, resolvedPath),
101
145
  external: true
102
146
  };
103
147
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecopages",
3
- "version": "0.2.0-alpha.45",
3
+ "version": "0.2.0-alpha.47",
4
4
  "description": "CLI utilities for Ecopages",
5
5
  "type": "module",
6
6
  "engines": {
@@ -32,7 +32,7 @@
32
32
  "ecopages": "bin/cli.js"
33
33
  },
34
34
  "dependencies": {
35
- "@ecopages/core": "0.2.0-alpha.45",
35
+ "@ecopages/core": "0.2.0-alpha.47",
36
36
  "@ecopages/logger": "^0.2.3",
37
37
  "esbuild": "^0.28.0",
38
38
  "giget": "^2.0.0"