@h-rig/core 0.0.6-alpha.140 → 0.0.6-alpha.142

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.
@@ -1,10 +1,9 @@
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
- import { fileURLToPath, pathToFileURL } from "url";
6
+ import { pathToFileURL } from "url";
8
7
  import { Schema as Schema2 } from "effect";
9
8
  import { RigConfig as RigConfig2 } from "@rig/contracts";
10
9
 
@@ -89,24 +88,6 @@ function exportTargetFromPackageJson(pkg, subpath) {
89
88
  return target;
90
89
  return subpath === "." && typeof pkg.module === "string" ? pkg.module : subpath === "." && typeof pkg.main === "string" ? pkg.main : null;
91
90
  }
92
- function resolvePackageDirFromBunStore(packageName, nodeModulesDir) {
93
- const storeDir = join(nodeModulesDir, ".bun");
94
- if (!existsSync(storeDir))
95
- return null;
96
- const encoded = packageName.replace("/", "+");
97
- try {
98
- for (const entry of readdirSync(storeDir).sort()) {
99
- if (!entry.startsWith(`${encoded}@`))
100
- continue;
101
- const candidate = join(storeDir, entry, "node_modules", packageName);
102
- if (existsSync(join(candidate, "package.json")))
103
- return candidate;
104
- }
105
- } catch {
106
- return null;
107
- }
108
- return null;
109
- }
110
91
  function resolveDirectoryModulePath(directoryPath) {
111
92
  const packageJsonPath = join(directoryPath, "package.json");
112
93
  if (existsSync(packageJsonPath)) {
@@ -141,68 +122,6 @@ function resolveModulePath(candidatePath) {
141
122
  }
142
123
  return null;
143
124
  }
144
- function resolvePackageExportFromDir(packageDir, subpath) {
145
- const packageJsonPath = join(packageDir, "package.json");
146
- if (existsSync(packageJsonPath)) {
147
- try {
148
- const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
149
- const target = exportTargetFromPackageJson(pkg, subpath);
150
- if (target) {
151
- const resolved = resolveModulePath(join(packageDir, target));
152
- if (resolved)
153
- return resolved;
154
- }
155
- } catch {
156
- return null;
157
- }
158
- }
159
- if (subpath !== ".") {
160
- const legacySubpath = subpath.replace(/^\.\//, "");
161
- for (const candidate of [
162
- join(packageDir, legacySubpath),
163
- join(packageDir, `${legacySubpath}.js`),
164
- join(packageDir, `${legacySubpath}.mjs`),
165
- join(packageDir, `${legacySubpath}.cjs`),
166
- join(packageDir, `${legacySubpath}.ts`),
167
- join(packageDir, `${legacySubpath}.json`)
168
- ]) {
169
- const resolved = resolveModulePath(candidate);
170
- if (resolved)
171
- return resolved;
172
- }
173
- }
174
- return subpath === "." ? resolveDirectoryModulePath(packageDir) : null;
175
- }
176
- function resolveBarePackageExport(specifier, parentDir, ceilingDir) {
177
- const parsed = packageNameAndSubpath(specifier);
178
- if (!parsed)
179
- return null;
180
- const packageNames = parsed.packageName.startsWith("@rig/") ? [parsed.packageName, parsed.packageName.replace(/^@rig\//, "@h-rig/")] : [parsed.packageName];
181
- const ceiling = ceilingDir ? resolve(ceilingDir) : null;
182
- let current = resolve(parentDir);
183
- while (true) {
184
- const nodeModulesDir = join(current, "node_modules");
185
- for (const packageName of packageNames) {
186
- const directPackageDir = join(nodeModulesDir, packageName);
187
- const resolvedDirect = resolvePackageExportFromDir(directPackageDir, parsed.subpath);
188
- if (resolvedDirect)
189
- return resolvedDirect;
190
- const bunStorePackageDir = resolvePackageDirFromBunStore(packageName, nodeModulesDir);
191
- if (bunStorePackageDir) {
192
- const resolvedFromStore = resolvePackageExportFromDir(bunStorePackageDir, parsed.subpath);
193
- if (resolvedFromStore)
194
- return resolvedFromStore;
195
- }
196
- }
197
- if (ceiling && current === ceiling)
198
- break;
199
- const next = dirname(current);
200
- if (next === current)
201
- break;
202
- current = next;
203
- }
204
- return null;
205
- }
206
125
  var runtimeBundleQueue = Promise.resolve();
207
126
  function enqueueRuntimeBundle(operation) {
208
127
  const next = runtimeBundleQueue.then(operation, operation);
@@ -230,61 +149,31 @@ async function importConfigViaRuntimeBundleUnserialized(configPath) {
230
149
  if (!bun?.build) {
231
150
  throw new Error(`Failed to import ${configPath}: bare imports could not be resolved and no Bun.build runtime bundler is available.`);
232
151
  }
233
- const hostDir = (() => {
234
- try {
235
- return dirname(fileURLToPath(import.meta.url));
236
- } catch {
237
- return process.cwd();
238
- }
239
- })();
240
152
  const configDir = dirname(configPath);
241
153
  const UNRESOLVED_NAMESPACE = "rig-config-unresolved";
242
- const hostResolverPlugin = {
243
- name: "rig-host-package-resolver",
154
+ const unresolvedLocalPlugin = {
155
+ name: "rig-config-unresolved-local",
244
156
  setup(build) {
245
- build.onResolve({ filter: /^@rig\// }, (args) => {
246
- const candidates = [
247
- { specifier: args.path, parent: hostDir },
248
- { specifier: args.path.replace(/^@rig\//, "@h-rig/"), parent: hostDir },
249
- { specifier: args.path, parent: configDir, root: configDir }
250
- ];
251
- for (const candidate of candidates) {
252
- try {
253
- const resolved = resolvedFilePath(bun.resolveSync?.(candidate.specifier, candidate.parent) ?? resolveBarePackageExport(candidate.specifier, candidate.parent, candidate.root), candidate.root);
254
- if (resolved)
255
- return { path: resolved };
256
- } catch {
257
- const resolved = resolvedFilePath(resolveBarePackageExport(candidate.specifier, candidate.parent, candidate.root), candidate.root);
258
- if (resolved)
259
- return { path: resolved };
260
- }
261
- }
262
- return;
263
- });
264
157
  build.onResolve({ filter: /.*/ }, (args) => {
265
- if (/^(?:node|bun):/.test(args.path) || isBuiltin(args.path))
158
+ if (/^(?:node|bun):/.test(args.path) || isBuiltin(args.path) || packageNameAndSubpath(args.path))
266
159
  return;
267
160
  const parent = args.importer ? dirname(args.importer) : configDir;
268
- const projectScoped = isWithinDir(parent, configDir);
269
161
  try {
270
- const resolved = bun.resolveSync?.(args.path, parent) ?? resolveBarePackageExport(args.path, parent, projectScoped ? configDir : undefined);
271
- const filePath = resolvedFilePath(resolved, projectScoped ? configDir : undefined);
162
+ const resolved = bun.resolveSync?.(args.path, parent) ?? resolve(parent, args.path);
163
+ const filePath = resolvedFilePath(resolved, configDir);
272
164
  if (filePath)
273
165
  return { path: filePath };
274
- if (resolved)
275
- return { path: args.path, namespace: UNRESOLVED_NAMESPACE };
276
166
  } catch {
277
- const resolved = resolvedFilePath(resolveBarePackageExport(args.path, parent, projectScoped ? configDir : undefined), projectScoped ? configDir : undefined);
278
- if (resolved)
279
- return { path: resolved };
280
- return { path: args.path, namespace: UNRESOLVED_NAMESPACE };
167
+ const filePath = resolvedFilePath(resolve(parent, args.path), configDir);
168
+ if (filePath)
169
+ return { path: filePath };
281
170
  }
282
- return;
171
+ return { path: args.path, namespace: UNRESOLVED_NAMESPACE };
283
172
  });
284
173
  build.onLoad({ filter: /.*/, namespace: UNRESOLVED_NAMESPACE }, (args) => ({
285
174
  loader: "js",
286
175
  contents: `module.exports = {};
287
- throw new Error(${JSON.stringify(`Failed to bundle ${configPath}: Could not resolve: "${args.path}". Maybe you need to "bun install"?`)});
176
+ throw new Error(${JSON.stringify(`Failed to bundle ${configPath}: Could not resolve local import "${args.path}". Maybe you need to fix a relative import in rig.config.ts or install project deps.`)});
288
177
  `
289
178
  }));
290
179
  }
@@ -294,15 +183,17 @@ throw new Error(${JSON.stringify(`Failed to bundle ${configPath}: Could not reso
294
183
  target: "bun",
295
184
  format: "esm",
296
185
  throw: false,
297
- external: ["fastembed", "onnxruntime-node", "mupdf", "markit-ai"],
298
- plugins: [hostResolverPlugin]
186
+ packages: "external",
187
+ plugins: [unresolvedLocalPlugin]
299
188
  });
300
189
  if (!result.success || !result.outputs[0]) {
301
190
  const detail = result.logs.map((log) => String(log)).join(`
302
191
  `);
303
192
  throw new Error(`Failed to bundle ${configPath}: ${detail || "unknown bundler error"}`);
304
193
  }
305
- const dir = mkdtempSync(join(tmpdir(), "rig-config-bundle-"));
194
+ const bundleParentDir = join(configDir, ".rig", "tmp");
195
+ mkdirSync(bundleParentDir, { recursive: true });
196
+ const dir = mkdtempSync(join(bundleParentDir, "rig-config-bundle-"));
306
197
  try {
307
198
  const bundledPath = join(dir, "rig.config.bundled.js");
308
199
  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.140",
3
+ "version": "0.0.6-alpha.142",
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.140",
48
+ "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.142",
49
49
  "effect": "4.0.0-beta.90"
50
50
  }
51
51
  }