@h-rig/core 0.0.6-alpha.89 → 0.0.6-alpha.90
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 +6 -130
- package/package.json +2 -2
package/dist/src/load-config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/core/src/load-config.ts
|
|
3
|
-
import { existsSync, mkdtempSync, readFileSync,
|
|
3
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync } from "fs";
|
|
4
4
|
import { tmpdir } from "os";
|
|
5
5
|
import { dirname, join } from "path";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
@@ -38,118 +38,6 @@ function isModuleResolutionError(error) {
|
|
|
38
38
|
function runningFromCompiledBinary() {
|
|
39
39
|
return import.meta.url.includes("$bunfs");
|
|
40
40
|
}
|
|
41
|
-
function packageNameAndSubpath(specifier) {
|
|
42
|
-
if (specifier.startsWith(".") || specifier.startsWith("/") || /^[a-zA-Z]+:/.test(specifier))
|
|
43
|
-
return null;
|
|
44
|
-
const parts = specifier.split("/");
|
|
45
|
-
const packageName = specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
46
|
-
if (!packageName)
|
|
47
|
-
return null;
|
|
48
|
-
const rest = parts.slice(specifier.startsWith("@") ? 2 : 1).join("/");
|
|
49
|
-
return { packageName, subpath: rest ? `./${rest}` : "." };
|
|
50
|
-
}
|
|
51
|
-
function exportTargetFromEntry(entry) {
|
|
52
|
-
if (typeof entry === "string")
|
|
53
|
-
return entry;
|
|
54
|
-
if (entry && typeof entry === "object" && !Array.isArray(entry)) {
|
|
55
|
-
const conditions = entry;
|
|
56
|
-
for (const key of ["bun", "import", "default", "require"]) {
|
|
57
|
-
if (typeof conditions[key] === "string")
|
|
58
|
-
return conditions[key];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
function patternExportTarget(record, subpath) {
|
|
64
|
-
for (const [pattern, entry] of Object.entries(record)) {
|
|
65
|
-
if (!pattern.includes("*"))
|
|
66
|
-
continue;
|
|
67
|
-
const [prefix = "", suffix = ""] = pattern.split("*");
|
|
68
|
-
if (!subpath.startsWith(prefix) || !subpath.endsWith(suffix))
|
|
69
|
-
continue;
|
|
70
|
-
const replacement = subpath.slice(prefix.length, subpath.length - suffix.length);
|
|
71
|
-
const target = exportTargetFromEntry(entry);
|
|
72
|
-
if (target)
|
|
73
|
-
return target.replace("*", replacement);
|
|
74
|
-
}
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
function exportTargetFromPackageJson(pkg, subpath) {
|
|
78
|
-
const exportsField = pkg.exports;
|
|
79
|
-
const target = (() => {
|
|
80
|
-
if (typeof exportsField === "string" && subpath === ".")
|
|
81
|
-
return exportsField;
|
|
82
|
-
if (!exportsField || typeof exportsField !== "object" || Array.isArray(exportsField))
|
|
83
|
-
return null;
|
|
84
|
-
const record = exportsField;
|
|
85
|
-
return exportTargetFromEntry(record[subpath] ?? (subpath === "." ? record["."] : undefined)) ?? patternExportTarget(record, subpath);
|
|
86
|
-
})();
|
|
87
|
-
if (target)
|
|
88
|
-
return target;
|
|
89
|
-
return subpath === "." && typeof pkg.module === "string" ? pkg.module : subpath === "." && typeof pkg.main === "string" ? pkg.main : null;
|
|
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
|
-
for (const entry of readdirSync(storeDir).sort()) {
|
|
98
|
-
if (!entry.startsWith(`${encoded}@`))
|
|
99
|
-
continue;
|
|
100
|
-
const candidate = join(storeDir, entry, "node_modules", packageName);
|
|
101
|
-
if (existsSync(join(candidate, "package.json")))
|
|
102
|
-
return candidate;
|
|
103
|
-
}
|
|
104
|
-
} catch {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
function resolvePackageExportFromDir(packageDir, subpath) {
|
|
110
|
-
const packageJsonPath = join(packageDir, "package.json");
|
|
111
|
-
if (!existsSync(packageJsonPath))
|
|
112
|
-
return null;
|
|
113
|
-
try {
|
|
114
|
-
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
115
|
-
const target = exportTargetFromPackageJson(pkg, subpath);
|
|
116
|
-
if (target) {
|
|
117
|
-
const resolved = join(packageDir, target);
|
|
118
|
-
if (existsSync(resolved))
|
|
119
|
-
return resolved;
|
|
120
|
-
}
|
|
121
|
-
} catch {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
function resolveBarePackageExport(specifier, parentDir) {
|
|
127
|
-
const parsed = packageNameAndSubpath(specifier);
|
|
128
|
-
if (!parsed)
|
|
129
|
-
return null;
|
|
130
|
-
const packageNames = parsed.packageName.startsWith("@rig/") ? [parsed.packageName, parsed.packageName.replace(/^@rig\//, "@h-rig/")] : [parsed.packageName];
|
|
131
|
-
let current = parentDir;
|
|
132
|
-
while (true) {
|
|
133
|
-
const nodeModulesDir = join(current, "node_modules");
|
|
134
|
-
for (const packageName of packageNames) {
|
|
135
|
-
const directPackageDir = join(nodeModulesDir, packageName);
|
|
136
|
-
const resolvedDirect = resolvePackageExportFromDir(directPackageDir, parsed.subpath);
|
|
137
|
-
if (resolvedDirect)
|
|
138
|
-
return resolvedDirect;
|
|
139
|
-
const bunStorePackageDir = resolvePackageDirFromBunStore(packageName, nodeModulesDir);
|
|
140
|
-
if (bunStorePackageDir) {
|
|
141
|
-
const resolvedFromStore = resolvePackageExportFromDir(bunStorePackageDir, parsed.subpath);
|
|
142
|
-
if (resolvedFromStore)
|
|
143
|
-
return resolvedFromStore;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
const next = dirname(current);
|
|
147
|
-
if (next === current)
|
|
148
|
-
break;
|
|
149
|
-
current = next;
|
|
150
|
-
}
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
41
|
var runtimeBundleQueue = Promise.resolve();
|
|
154
42
|
function enqueueRuntimeBundle(operation) {
|
|
155
43
|
const next = runtimeBundleQueue.then(operation, operation);
|
|
@@ -179,20 +67,16 @@ async function importConfigViaRuntimeBundleUnserialized(configPath) {
|
|
|
179
67
|
setup(build) {
|
|
180
68
|
build.onResolve({ filter: /^@rig\// }, (args) => {
|
|
181
69
|
const candidates = [
|
|
70
|
+
[args.path, configDir],
|
|
182
71
|
[args.path, hostDir],
|
|
183
|
-
[args.path.replace(/^@rig\//, "@h-rig/"), hostDir]
|
|
184
|
-
[args.path, configDir]
|
|
72
|
+
[args.path.replace(/^@rig\//, "@h-rig/"), hostDir]
|
|
185
73
|
];
|
|
186
74
|
for (const [specifier, parent] of candidates) {
|
|
187
75
|
try {
|
|
188
|
-
const resolved = bun.resolveSync?.(specifier, parent)
|
|
76
|
+
const resolved = bun.resolveSync?.(specifier, parent);
|
|
189
77
|
if (resolved)
|
|
190
78
|
return { path: resolved };
|
|
191
|
-
} catch {
|
|
192
|
-
const resolved = resolveBarePackageExport(specifier, parent);
|
|
193
|
-
if (resolved)
|
|
194
|
-
return { path: resolved };
|
|
195
|
-
}
|
|
79
|
+
} catch {}
|
|
196
80
|
}
|
|
197
81
|
return;
|
|
198
82
|
});
|
|
@@ -201,13 +85,10 @@ async function importConfigViaRuntimeBundleUnserialized(configPath) {
|
|
|
201
85
|
return;
|
|
202
86
|
const parent = args.importer ? dirname(args.importer) : configDir;
|
|
203
87
|
try {
|
|
204
|
-
const resolved = bun.resolveSync?.(args.path, parent)
|
|
88
|
+
const resolved = bun.resolveSync?.(args.path, parent);
|
|
205
89
|
if (resolved)
|
|
206
90
|
return { path: resolved };
|
|
207
91
|
} catch {
|
|
208
|
-
const resolved = resolveBarePackageExport(args.path, parent);
|
|
209
|
-
if (resolved)
|
|
210
|
-
return { path: resolved };
|
|
211
92
|
return { path: args.path, namespace: UNRESOLVED_NAMESPACE };
|
|
212
93
|
}
|
|
213
94
|
return;
|
|
@@ -251,11 +132,6 @@ async function loadConfig(cwd) {
|
|
|
251
132
|
if (runningFromCompiledBinary()) {
|
|
252
133
|
return importConfigViaRuntimeBundleUnserialized(p);
|
|
253
134
|
}
|
|
254
|
-
const source = readFileSync(p, "utf8");
|
|
255
|
-
const importsRigHostPackages = /(?:import\s+[^;]*?from\s*|import\s*\()\s*["']@rig\//.test(source);
|
|
256
|
-
if (importsRigHostPackages) {
|
|
257
|
-
return importConfigViaRuntimeBundleUnserialized(p);
|
|
258
|
-
}
|
|
259
135
|
try {
|
|
260
136
|
return await import(pathToFileURL(p).href);
|
|
261
137
|
} catch (error) {
|
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.90",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Rig package",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"module": "./dist/src/index.js",
|
|
38
38
|
"types": "./dist/src/index.d.ts",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.
|
|
40
|
+
"@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.90",
|
|
41
41
|
"effect": "4.0.0-beta.78"
|
|
42
42
|
}
|
|
43
43
|
}
|