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

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,9 +1,9 @@
1
1
  // @bun
2
2
  // packages/core/src/load-config.ts
3
- import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync } from "fs";
3
+ import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync } from "fs";
4
4
  import { isBuiltin } from "module";
5
5
  import { tmpdir } from "os";
6
- import { dirname, isAbsolute, join } from "path";
6
+ import { dirname, isAbsolute, join, relative, resolve } from "path";
7
7
  import { fileURLToPath, pathToFileURL } from "url";
8
8
  import { Schema as Schema2 } from "effect";
9
9
  import { RigConfig as RigConfig2 } from "@rig/contracts";
@@ -107,29 +107,79 @@ function resolvePackageDirFromBunStore(packageName, nodeModulesDir) {
107
107
  }
108
108
  return null;
109
109
  }
110
- function resolvePackageExportFromDir(packageDir, subpath) {
111
- const packageJsonPath = join(packageDir, "package.json");
112
- if (!existsSync(packageJsonPath))
110
+ function resolveDirectoryModulePath(directoryPath) {
111
+ const packageJsonPath = join(directoryPath, "package.json");
112
+ if (existsSync(packageJsonPath)) {
113
+ try {
114
+ const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
115
+ const target = exportTargetFromPackageJson(pkg, ".");
116
+ if (target) {
117
+ const resolved = resolveModulePath(join(directoryPath, target));
118
+ if (resolved)
119
+ return resolved;
120
+ }
121
+ } catch {}
122
+ }
123
+ for (const candidate of ["index.js", "index.mjs", "index.cjs", "index.ts", "index.json"]) {
124
+ const resolved = resolveModulePath(join(directoryPath, candidate));
125
+ if (resolved)
126
+ return resolved;
127
+ }
128
+ return null;
129
+ }
130
+ function resolveModulePath(candidatePath) {
131
+ if (!existsSync(candidatePath))
113
132
  return null;
114
133
  try {
115
- const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
116
- const target = exportTargetFromPackageJson(pkg, subpath);
117
- if (target) {
118
- const resolved = join(packageDir, target);
119
- if (existsSync(resolved))
120
- return resolved;
121
- }
134
+ const stat = statSync(candidatePath);
135
+ if (stat.isFile())
136
+ return candidatePath;
137
+ if (stat.isDirectory())
138
+ return resolveDirectoryModulePath(candidatePath);
122
139
  } catch {
123
140
  return null;
124
141
  }
125
142
  return null;
126
143
  }
127
- function resolveBarePackageExport(specifier, parentDir) {
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) {
128
177
  const parsed = packageNameAndSubpath(specifier);
129
178
  if (!parsed)
130
179
  return null;
131
180
  const packageNames = parsed.packageName.startsWith("@rig/") ? [parsed.packageName, parsed.packageName.replace(/^@rig\//, "@h-rig/")] : [parsed.packageName];
132
- let current = parentDir;
181
+ const ceiling = ceilingDir ? resolve(ceilingDir) : null;
182
+ let current = resolve(parentDir);
133
183
  while (true) {
134
184
  const nodeModulesDir = join(current, "node_modules");
135
185
  for (const packageName of packageNames) {
@@ -144,6 +194,8 @@ function resolveBarePackageExport(specifier, parentDir) {
144
194
  return resolvedFromStore;
145
195
  }
146
196
  }
197
+ if (ceiling && current === ceiling)
198
+ break;
147
199
  const next = dirname(current);
148
200
  if (next === current)
149
201
  break;
@@ -161,8 +213,17 @@ function enqueueRuntimeBundle(operation) {
161
213
  });
162
214
  return next;
163
215
  }
164
- function resolvedFilePath(path) {
165
- return path && isAbsolute(path) ? path : null;
216
+ function isWithinDir(candidatePath, rootPath) {
217
+ const rel = relative(resolve(rootPath), resolve(candidatePath));
218
+ return rel === "" || !rel.startsWith("..") && !isAbsolute(rel);
219
+ }
220
+ function resolvedFilePath(path, rootPath) {
221
+ if (!path || !isAbsolute(path))
222
+ return null;
223
+ const resolved = resolveModulePath(path);
224
+ if (!resolved)
225
+ return null;
226
+ return rootPath && !isWithinDir(resolved, rootPath) ? null : resolved;
166
227
  }
167
228
  async function importConfigViaRuntimeBundleUnserialized(configPath) {
168
229
  const bun = globalThis.Bun;
@@ -183,17 +244,17 @@ async function importConfigViaRuntimeBundleUnserialized(configPath) {
183
244
  setup(build) {
184
245
  build.onResolve({ filter: /^@rig\// }, (args) => {
185
246
  const candidates = [
186
- [args.path, hostDir],
187
- [args.path.replace(/^@rig\//, "@h-rig/"), hostDir],
188
- [args.path, configDir]
247
+ { specifier: args.path, parent: hostDir },
248
+ { specifier: args.path.replace(/^@rig\//, "@h-rig/"), parent: hostDir },
249
+ { specifier: args.path, parent: configDir, root: configDir }
189
250
  ];
190
- for (const [specifier, parent] of candidates) {
251
+ for (const candidate of candidates) {
191
252
  try {
192
- const resolved = resolvedFilePath(bun.resolveSync?.(specifier, parent) ?? resolveBarePackageExport(specifier, parent));
253
+ const resolved = resolvedFilePath(bun.resolveSync?.(candidate.specifier, candidate.parent) ?? resolveBarePackageExport(candidate.specifier, candidate.parent, candidate.root), candidate.root);
193
254
  if (resolved)
194
255
  return { path: resolved };
195
256
  } catch {
196
- const resolved = resolvedFilePath(resolveBarePackageExport(specifier, parent));
257
+ const resolved = resolvedFilePath(resolveBarePackageExport(candidate.specifier, candidate.parent, candidate.root), candidate.root);
197
258
  if (resolved)
198
259
  return { path: resolved };
199
260
  }
@@ -204,15 +265,16 @@ async function importConfigViaRuntimeBundleUnserialized(configPath) {
204
265
  if (/^(?:node|bun):/.test(args.path) || isBuiltin(args.path))
205
266
  return;
206
267
  const parent = args.importer ? dirname(args.importer) : configDir;
268
+ const projectScoped = isWithinDir(parent, configDir);
207
269
  try {
208
- const resolved = bun.resolveSync?.(args.path, parent) ?? resolveBarePackageExport(args.path, parent);
209
- const filePath = resolvedFilePath(resolved);
270
+ const resolved = bun.resolveSync?.(args.path, parent) ?? resolveBarePackageExport(args.path, parent, projectScoped ? configDir : undefined);
271
+ const filePath = resolvedFilePath(resolved, projectScoped ? configDir : undefined);
210
272
  if (filePath)
211
273
  return { path: filePath };
212
274
  if (resolved)
213
275
  return { path: args.path, namespace: UNRESOLVED_NAMESPACE };
214
276
  } catch {
215
- const resolved = resolvedFilePath(resolveBarePackageExport(args.path, parent));
277
+ const resolved = resolvedFilePath(resolveBarePackageExport(args.path, parent, projectScoped ? configDir : undefined), projectScoped ? configDir : undefined);
216
278
  if (resolved)
217
279
  return { path: resolved };
218
280
  return { path: args.path, namespace: UNRESOLVED_NAMESPACE };
@@ -232,6 +294,7 @@ throw new Error(${JSON.stringify(`Failed to bundle ${configPath}: Could not reso
232
294
  target: "bun",
233
295
  format: "esm",
234
296
  throw: false,
297
+ external: ["fastembed", "onnxruntime-node", "mupdf", "markit-ai"],
235
298
  plugins: [hostResolverPlugin]
236
299
  });
237
300
  if (!result.success || !result.outputs[0]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h-rig/core",
3
- "version": "0.0.6-alpha.139",
3
+ "version": "0.0.6-alpha.140",
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.139",
48
+ "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.140",
49
49
  "effect": "4.0.0-beta.90"
50
50
  }
51
51
  }