rip-lang 3.13.6 → 3.13.7
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 +5 -18
package/package.json
CHANGED
package/rip-loader.js
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
// Bun loader for .rip files
|
|
2
2
|
|
|
3
3
|
import { plugin } from "bun";
|
|
4
|
-
import { dirname, join } from "path";
|
|
5
4
|
import { fileURLToPath } from "url";
|
|
6
5
|
import { compileToJS } from "./src/compiler.js";
|
|
7
6
|
|
|
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
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
7
|
await plugin({
|
|
22
8
|
name: "rip-loader",
|
|
23
9
|
async setup(build) {
|
|
@@ -29,12 +15,13 @@ await plugin({
|
|
|
29
15
|
const source = readFileSync(args.path, "utf-8");
|
|
30
16
|
let js = compileToJS(source);
|
|
31
17
|
|
|
32
|
-
// Rewrite @rip-lang/* imports to absolute paths. Bun
|
|
33
|
-
//
|
|
34
|
-
//
|
|
18
|
+
// Rewrite @rip-lang/* imports to absolute paths. Bun workers ignore
|
|
19
|
+
// NODE_PATH, onResolve skips compiled source, and require.resolve({ paths })
|
|
20
|
+
// is broken in plugin handlers — so we use import.meta.resolve, which
|
|
21
|
+
// resolves from this file's location (inside the global node_modules tree).
|
|
35
22
|
js = js.replace(/(from\s+|import\s*\()(['"])(@rip-lang\/[^'"]+)\2/g, (match, prefix, quote, specifier) => {
|
|
36
23
|
try {
|
|
37
|
-
return `${prefix}${quote}${
|
|
24
|
+
return `${prefix}${quote}${fileURLToPath(import.meta.resolve(specifier))}${quote}`;
|
|
38
25
|
} catch {
|
|
39
26
|
return match;
|
|
40
27
|
}
|