@h-rig/core 0.0.6-alpha.141 → 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.
@@ -3,7 +3,7 @@
3
3
  import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync } from "fs";
4
4
  import { isBuiltin } from "module";
5
5
  import { dirname, isAbsolute, join, relative, resolve } from "path";
6
- import { fileURLToPath, pathToFileURL } from "url";
6
+ import { pathToFileURL } from "url";
7
7
  import { Schema as Schema2 } from "effect";
8
8
  import { RigConfig as RigConfig2 } from "@rig/contracts";
9
9
 
@@ -88,35 +88,6 @@ function exportTargetFromPackageJson(pkg, subpath) {
88
88
  return target;
89
89
  return subpath === "." && typeof pkg.module === "string" ? pkg.module : subpath === "." && typeof pkg.main === "string" ? pkg.main : null;
90
90
  }
91
- function resolvePackageDirFromBunStore(packageName, nodeModulesDir) {
92
- const storeDir = join(nodeModulesDir, ".bun");
93
- if (!existsSync(storeDir))
94
- return null;
95
- const encoded = packageName.replace("/", "+");
96
- try {
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;
116
- } catch {
117
- return null;
118
- }
119
- }
120
91
  function resolveDirectoryModulePath(directoryPath) {
121
92
  const packageJsonPath = join(directoryPath, "package.json");
122
93
  if (existsSync(packageJsonPath)) {
@@ -151,68 +122,6 @@ function resolveModulePath(candidatePath) {
151
122
  }
152
123
  return null;
153
124
  }
154
- function resolvePackageExportFromDir(packageDir, subpath) {
155
- const packageJsonPath = join(packageDir, "package.json");
156
- if (existsSync(packageJsonPath)) {
157
- try {
158
- const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
159
- const target = exportTargetFromPackageJson(pkg, subpath);
160
- if (target) {
161
- const resolved = resolveModulePath(join(packageDir, target));
162
- if (resolved)
163
- return resolved;
164
- }
165
- } catch {
166
- return null;
167
- }
168
- }
169
- if (subpath !== ".") {
170
- const legacySubpath = subpath.replace(/^\.\//, "");
171
- for (const candidate of [
172
- join(packageDir, legacySubpath),
173
- join(packageDir, `${legacySubpath}.js`),
174
- join(packageDir, `${legacySubpath}.mjs`),
175
- join(packageDir, `${legacySubpath}.cjs`),
176
- join(packageDir, `${legacySubpath}.ts`),
177
- join(packageDir, `${legacySubpath}.json`)
178
- ]) {
179
- const resolved = resolveModulePath(candidate);
180
- if (resolved)
181
- return resolved;
182
- }
183
- }
184
- return subpath === "." ? resolveDirectoryModulePath(packageDir) : null;
185
- }
186
- function resolveBarePackageExport(specifier, parentDir, ceilingDir) {
187
- const parsed = packageNameAndSubpath(specifier);
188
- if (!parsed)
189
- return null;
190
- const packageNames = parsed.packageName.startsWith("@rig/") ? [parsed.packageName, parsed.packageName.replace(/^@rig\//, "@h-rig/")] : [parsed.packageName];
191
- const ceiling = ceilingDir ? resolve(ceilingDir) : null;
192
- let current = resolve(parentDir);
193
- while (true) {
194
- const nodeModulesDir = join(current, "node_modules");
195
- for (const packageName of packageNames) {
196
- const directPackageDir = join(nodeModulesDir, packageName);
197
- const resolvedDirect = resolvePackageExportFromDir(directPackageDir, parsed.subpath);
198
- if (resolvedDirect)
199
- return resolvedDirect;
200
- const bunStorePackageDir = resolvePackageDirFromBunStore(packageName, nodeModulesDir);
201
- if (bunStorePackageDir) {
202
- const resolvedFromStore = resolvePackageExportFromDir(bunStorePackageDir, parsed.subpath);
203
- if (resolvedFromStore)
204
- return resolvedFromStore;
205
- }
206
- }
207
- if (ceiling && current === ceiling)
208
- break;
209
- const next = dirname(current);
210
- if (next === current)
211
- break;
212
- current = next;
213
- }
214
- return null;
215
- }
216
125
  var runtimeBundleQueue = Promise.resolve();
217
126
  function enqueueRuntimeBundle(operation) {
218
127
  const next = runtimeBundleQueue.then(operation, operation);
@@ -235,70 +144,36 @@ function resolvedFilePath(path, rootPath) {
235
144
  return null;
236
145
  return rootPath && !isWithinDir(resolved, rootPath) ? null : resolved;
237
146
  }
238
- var RUNTIME_BUNDLE_EXTERNALS = [];
239
- function shouldDeferToRuntimeExternal(specifier) {
240
- return RUNTIME_BUNDLE_EXTERNALS.includes(specifier);
241
- }
242
147
  async function importConfigViaRuntimeBundleUnserialized(configPath) {
243
148
  const bun = globalThis.Bun;
244
149
  if (!bun?.build) {
245
150
  throw new Error(`Failed to import ${configPath}: bare imports could not be resolved and no Bun.build runtime bundler is available.`);
246
151
  }
247
- const hostDir = (() => {
248
- try {
249
- return dirname(fileURLToPath(import.meta.url));
250
- } catch {
251
- return process.cwd();
252
- }
253
- })();
254
152
  const configDir = dirname(configPath);
255
153
  const UNRESOLVED_NAMESPACE = "rig-config-unresolved";
256
- const hostResolverPlugin = {
257
- name: "rig-host-package-resolver",
154
+ const unresolvedLocalPlugin = {
155
+ name: "rig-config-unresolved-local",
258
156
  setup(build) {
259
- build.onResolve({ filter: /^@rig\// }, (args) => {
260
- const candidates = [
261
- { specifier: args.path, parent: hostDir },
262
- { specifier: args.path.replace(/^@rig\//, "@h-rig/"), parent: hostDir },
263
- { specifier: args.path, parent: configDir, root: configDir }
264
- ];
265
- for (const candidate of candidates) {
266
- try {
267
- const resolved = resolvedFilePath(bun.resolveSync?.(candidate.specifier, candidate.parent) ?? resolveBarePackageExport(candidate.specifier, candidate.parent, candidate.root), candidate.root);
268
- if (resolved)
269
- return { path: resolved };
270
- } catch {
271
- const resolved = resolvedFilePath(resolveBarePackageExport(candidate.specifier, candidate.parent, candidate.root), candidate.root);
272
- if (resolved)
273
- return { path: resolved };
274
- }
275
- }
276
- return;
277
- });
278
157
  build.onResolve({ filter: /.*/ }, (args) => {
279
- const parent = args.importer ? dirname(args.importer) : configDir;
280
- if (/^(?:node|bun):/.test(args.path) || isBuiltin(args.path) || shouldDeferToRuntimeExternal(args.path))
158
+ if (/^(?:node|bun):/.test(args.path) || isBuiltin(args.path) || packageNameAndSubpath(args.path))
281
159
  return;
282
- const projectScoped = isWithinDir(parent, configDir);
160
+ const parent = args.importer ? dirname(args.importer) : configDir;
283
161
  try {
284
- const resolved = bun.resolveSync?.(args.path, parent) ?? resolveBarePackageExport(args.path, parent, projectScoped ? configDir : undefined);
285
- 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);
286
164
  if (filePath)
287
165
  return { path: filePath };
288
- if (resolved)
289
- return { path: args.path, namespace: UNRESOLVED_NAMESPACE };
290
166
  } catch {
291
- const resolved = resolvedFilePath(resolveBarePackageExport(args.path, parent, projectScoped ? configDir : undefined), projectScoped ? configDir : undefined);
292
- if (resolved)
293
- return { path: resolved };
294
- return { path: args.path, namespace: UNRESOLVED_NAMESPACE };
167
+ const filePath = resolvedFilePath(resolve(parent, args.path), configDir);
168
+ if (filePath)
169
+ return { path: filePath };
295
170
  }
296
- return;
171
+ return { path: args.path, namespace: UNRESOLVED_NAMESPACE };
297
172
  });
298
173
  build.onLoad({ filter: /.*/, namespace: UNRESOLVED_NAMESPACE }, (args) => ({
299
174
  loader: "js",
300
175
  contents: `module.exports = {};
301
- 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.`)});
302
177
  `
303
178
  }));
304
179
  }
@@ -308,8 +183,8 @@ throw new Error(${JSON.stringify(`Failed to bundle ${configPath}: Could not reso
308
183
  target: "bun",
309
184
  format: "esm",
310
185
  throw: false,
311
- external: [...RUNTIME_BUNDLE_EXTERNALS],
312
- plugins: [hostResolverPlugin]
186
+ packages: "external",
187
+ plugins: [unresolvedLocalPlugin]
313
188
  });
314
189
  if (!result.success || !result.outputs[0]) {
315
190
  const detail = result.logs.map((log) => String(log)).join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h-rig/core",
3
- "version": "0.0.6-alpha.141",
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.141",
48
+ "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.142",
49
49
  "effect": "4.0.0-beta.90"
50
50
  }
51
51
  }