@h-rig/core 0.0.6-alpha.60 → 0.0.6-alpha.61

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.
@@ -31,7 +31,17 @@ function isModuleResolutionError(error) {
31
31
  function runningFromCompiledBinary() {
32
32
  return import.meta.url.includes("$bunfs");
33
33
  }
34
- async function importConfigViaRuntimeBundle(configPath) {
34
+ var runtimeBundleQueue = Promise.resolve();
35
+ function enqueueRuntimeBundle(operation) {
36
+ const next = runtimeBundleQueue.then(operation, operation);
37
+ runtimeBundleQueue = next.then(() => {
38
+ return;
39
+ }, () => {
40
+ return;
41
+ });
42
+ return next;
43
+ }
44
+ async function importConfigViaRuntimeBundleUnserialized(configPath) {
35
45
  const bun = globalThis.Bun;
36
46
  if (!bun?.build) {
37
47
  throw new Error(`Failed to import ${configPath}: bare imports could not be resolved and no Bun.build runtime bundler is available.`);
@@ -44,6 +54,7 @@ async function importConfigViaRuntimeBundle(configPath) {
44
54
  }
45
55
  })();
46
56
  const configDir = dirname(configPath);
57
+ const UNRESOLVED_NAMESPACE = "rig-config-unresolved";
47
58
  const hostResolverPlugin = {
48
59
  name: "rig-host-package-resolver",
49
60
  setup(build) {
@@ -62,6 +73,25 @@ async function importConfigViaRuntimeBundle(configPath) {
62
73
  }
63
74
  return;
64
75
  });
76
+ build.onResolve({ filter: /.*/ }, (args) => {
77
+ if (/^(?:node|bun):/.test(args.path))
78
+ return;
79
+ const parent = args.importer ? dirname(args.importer) : configDir;
80
+ try {
81
+ const resolved = bun.resolveSync?.(args.path, parent);
82
+ if (resolved)
83
+ return { path: resolved };
84
+ } catch {
85
+ return { path: args.path, namespace: UNRESOLVED_NAMESPACE };
86
+ }
87
+ return;
88
+ });
89
+ build.onLoad({ filter: /.*/, namespace: UNRESOLVED_NAMESPACE }, (args) => ({
90
+ loader: "js",
91
+ contents: `module.exports = {};
92
+ throw new Error(${JSON.stringify(`Failed to bundle ${configPath}: Could not resolve: "${args.path}". Maybe you need to "bun install"?`)});
93
+ `
94
+ }));
65
95
  }
66
96
  };
67
97
  const result = await bun.build({
@@ -91,18 +121,18 @@ async function loadConfig(cwd) {
91
121
  for (const name of TS_NAMES) {
92
122
  const p = join(cwd, name);
93
123
  if (existsSync(p)) {
94
- let mod;
95
- if (runningFromCompiledBinary()) {
96
- mod = await importConfigViaRuntimeBundle(p);
97
- } else {
124
+ const mod = await enqueueRuntimeBundle(async () => {
125
+ if (runningFromCompiledBinary()) {
126
+ return importConfigViaRuntimeBundleUnserialized(p);
127
+ }
98
128
  try {
99
- mod = await import(pathToFileURL(p).href);
129
+ return await import(pathToFileURL(p).href);
100
130
  } catch (error) {
101
131
  if (!isModuleResolutionError(error))
102
132
  throw error;
103
- mod = await importConfigViaRuntimeBundle(p);
133
+ return importConfigViaRuntimeBundleUnserialized(p);
104
134
  }
105
- }
135
+ });
106
136
  const raw = mod.default ?? mod.config;
107
137
  return decodePreservingRuntime(raw);
108
138
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h-rig/core",
3
- "version": "0.0.6-alpha.60",
3
+ "version": "0.0.6-alpha.61",
4
4
  "type": "module",
5
5
  "description": "Rig package",
6
6
  "license": "UNLICENSED",
@@ -31,7 +31,7 @@
31
31
  "main": "./dist/src/index.js",
32
32
  "module": "./dist/src/index.js",
33
33
  "dependencies": {
34
- "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.60",
34
+ "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.61",
35
35
  "effect": "4.0.0-beta.78"
36
36
  }
37
37
  }