rip-lang 3.13.5 → 3.13.6
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/package.json +1 -1
- package/rip-loader.js +24 -8
package/package.json
CHANGED
package/rip-loader.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
// Bun loader for .rip files
|
|
2
2
|
|
|
3
3
|
import { plugin } from "bun";
|
|
4
|
-
import { dirname } from "path";
|
|
4
|
+
import { dirname, join } from "path";
|
|
5
5
|
import { fileURLToPath } from "url";
|
|
6
6
|
import { compileToJS } from "./src/compiler.js";
|
|
7
7
|
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
// Resolution paths for @rip-lang/* packages: the loader's own node_modules tree,
|
|
9
|
+
// plus the global bun install as a fallback (covers dev repo running outside workspace).
|
|
10
|
+
const _loaderModules = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
11
|
+
const _globalModules = join(process.env.HOME || '', '.bun', 'install', 'global', 'node_modules');
|
|
12
|
+
const _resolvePaths = [...new Set([_loaderModules, _globalModules])];
|
|
13
|
+
|
|
14
|
+
// Set NODE_PATH so child processes can also resolve @rip-lang/* packages.
|
|
15
|
+
for (const p of _resolvePaths) {
|
|
16
|
+
if (!process.env.NODE_PATH?.split(':').includes(p)) {
|
|
17
|
+
process.env.NODE_PATH = [p, process.env.NODE_PATH].filter(Boolean).join(':');
|
|
18
|
+
}
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
await plugin({
|
|
@@ -22,7 +27,18 @@ await plugin({
|
|
|
22
27
|
build.onLoad({ filter: /\.rip$/ }, async (args) => {
|
|
23
28
|
try {
|
|
24
29
|
const source = readFileSync(args.path, "utf-8");
|
|
25
|
-
|
|
30
|
+
let js = compileToJS(source);
|
|
31
|
+
|
|
32
|
+
// Rewrite @rip-lang/* imports to absolute paths. Bun's worker threads
|
|
33
|
+
// don't respect NODE_PATH, and onResolve doesn't fire for imports in
|
|
34
|
+
// compiled source, so we resolve them here during compilation.
|
|
35
|
+
js = js.replace(/(from\s+|import\s*\()(['"])(@rip-lang\/[^'"]+)\2/g, (match, prefix, quote, specifier) => {
|
|
36
|
+
try {
|
|
37
|
+
return `${prefix}${quote}${require.resolve(specifier, { paths: _resolvePaths })}${quote}`;
|
|
38
|
+
} catch {
|
|
39
|
+
return match;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
26
42
|
|
|
27
43
|
return {
|
|
28
44
|
contents: js,
|