@h-rig/core 0.0.6-alpha.140 → 0.0.6-alpha.141
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/dist/src/load-config.js +30 -14
- package/package.json +2 -2
package/dist/src/load-config.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/core/src/load-config.ts
|
|
3
|
-
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync } from "fs";
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync } from "fs";
|
|
4
4
|
import { isBuiltin } from "module";
|
|
5
|
-
import { tmpdir } from "os";
|
|
6
5
|
import { dirname, isAbsolute, join, relative, resolve } from "path";
|
|
7
6
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
8
7
|
import { Schema as Schema2 } from "effect";
|
|
@@ -95,17 +94,28 @@ function resolvePackageDirFromBunStore(packageName, nodeModulesDir) {
|
|
|
95
94
|
return null;
|
|
96
95
|
const encoded = packageName.replace("/", "+");
|
|
97
96
|
try {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
const candidates = readdirSync(storeDir).filter((entry) => entry.startsWith(`${encoded}@`)).map((entry) => {
|
|
98
|
+
const candidateDir = join(storeDir, entry, "node_modules", packageName);
|
|
99
|
+
const packageJsonPath = join(candidateDir, "package.json");
|
|
100
|
+
if (!existsSync(packageJsonPath))
|
|
101
|
+
return null;
|
|
102
|
+
try {
|
|
103
|
+
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
104
|
+
return {
|
|
105
|
+
dir: candidateDir,
|
|
106
|
+
sortKey: pkg.version?.trim() || entry
|
|
107
|
+
};
|
|
108
|
+
} catch {
|
|
109
|
+
return {
|
|
110
|
+
dir: candidateDir,
|
|
111
|
+
sortKey: entry
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}).filter((candidate) => candidate !== null).sort((a, b) => b.sortKey.localeCompare(a.sortKey, undefined, { numeric: true, sensitivity: "base" }));
|
|
115
|
+
return candidates[0]?.dir ?? null;
|
|
105
116
|
} catch {
|
|
106
117
|
return null;
|
|
107
118
|
}
|
|
108
|
-
return null;
|
|
109
119
|
}
|
|
110
120
|
function resolveDirectoryModulePath(directoryPath) {
|
|
111
121
|
const packageJsonPath = join(directoryPath, "package.json");
|
|
@@ -225,6 +235,10 @@ function resolvedFilePath(path, rootPath) {
|
|
|
225
235
|
return null;
|
|
226
236
|
return rootPath && !isWithinDir(resolved, rootPath) ? null : resolved;
|
|
227
237
|
}
|
|
238
|
+
var RUNTIME_BUNDLE_EXTERNALS = [];
|
|
239
|
+
function shouldDeferToRuntimeExternal(specifier) {
|
|
240
|
+
return RUNTIME_BUNDLE_EXTERNALS.includes(specifier);
|
|
241
|
+
}
|
|
228
242
|
async function importConfigViaRuntimeBundleUnserialized(configPath) {
|
|
229
243
|
const bun = globalThis.Bun;
|
|
230
244
|
if (!bun?.build) {
|
|
@@ -262,9 +276,9 @@ async function importConfigViaRuntimeBundleUnserialized(configPath) {
|
|
|
262
276
|
return;
|
|
263
277
|
});
|
|
264
278
|
build.onResolve({ filter: /.*/ }, (args) => {
|
|
265
|
-
if (/^(?:node|bun):/.test(args.path) || isBuiltin(args.path))
|
|
266
|
-
return;
|
|
267
279
|
const parent = args.importer ? dirname(args.importer) : configDir;
|
|
280
|
+
if (/^(?:node|bun):/.test(args.path) || isBuiltin(args.path) || shouldDeferToRuntimeExternal(args.path))
|
|
281
|
+
return;
|
|
268
282
|
const projectScoped = isWithinDir(parent, configDir);
|
|
269
283
|
try {
|
|
270
284
|
const resolved = bun.resolveSync?.(args.path, parent) ?? resolveBarePackageExport(args.path, parent, projectScoped ? configDir : undefined);
|
|
@@ -294,7 +308,7 @@ throw new Error(${JSON.stringify(`Failed to bundle ${configPath}: Could not reso
|
|
|
294
308
|
target: "bun",
|
|
295
309
|
format: "esm",
|
|
296
310
|
throw: false,
|
|
297
|
-
external: [
|
|
311
|
+
external: [...RUNTIME_BUNDLE_EXTERNALS],
|
|
298
312
|
plugins: [hostResolverPlugin]
|
|
299
313
|
});
|
|
300
314
|
if (!result.success || !result.outputs[0]) {
|
|
@@ -302,7 +316,9 @@ throw new Error(${JSON.stringify(`Failed to bundle ${configPath}: Could not reso
|
|
|
302
316
|
`);
|
|
303
317
|
throw new Error(`Failed to bundle ${configPath}: ${detail || "unknown bundler error"}`);
|
|
304
318
|
}
|
|
305
|
-
const
|
|
319
|
+
const bundleParentDir = join(configDir, ".rig", "tmp");
|
|
320
|
+
mkdirSync(bundleParentDir, { recursive: true });
|
|
321
|
+
const dir = mkdtempSync(join(bundleParentDir, "rig-config-bundle-"));
|
|
306
322
|
try {
|
|
307
323
|
const bundledPath = join(dir, "rig.config.bundled.js");
|
|
308
324
|
await bun.write(bundledPath, await result.outputs[0].text());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h-rig/core",
|
|
3
|
-
"version": "0.0.6-alpha.
|
|
3
|
+
"version": "0.0.6-alpha.141",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Config and plugin composition library for Rig's OMP extension ecosystem; not a product host/runtime.",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"module": "./dist/src/index.js",
|
|
46
46
|
"types": "./dist/src/index.d.ts",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.
|
|
48
|
+
"@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.141",
|
|
49
49
|
"effect": "4.0.0-beta.90"
|
|
50
50
|
}
|
|
51
51
|
}
|