rip-lang 3.13.5 → 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 +13 -10
package/package.json
CHANGED
package/rip-loader.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
// Bun loader for .rip files
|
|
2
2
|
|
|
3
3
|
import { plugin } from "bun";
|
|
4
|
-
import { dirname } from "path";
|
|
5
4
|
import { fileURLToPath } from "url";
|
|
6
5
|
import { compileToJS } from "./src/compiler.js";
|
|
7
6
|
|
|
8
|
-
// Ensure NODE_PATH includes the node_modules where rip-lang is installed, so workers
|
|
9
|
-
// (and any code running through this loader) can resolve @rip-lang/* packages even
|
|
10
|
-
// when the script lives in a directory without its own node_modules.
|
|
11
|
-
const _nodeModules = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
12
|
-
if (!process.env.NODE_PATH?.split(':').includes(_nodeModules)) {
|
|
13
|
-
process.env.NODE_PATH = [_nodeModules, process.env.NODE_PATH].filter(Boolean).join(':');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
7
|
await plugin({
|
|
17
8
|
name: "rip-loader",
|
|
18
9
|
async setup(build) {
|
|
@@ -22,7 +13,19 @@ await plugin({
|
|
|
22
13
|
build.onLoad({ filter: /\.rip$/ }, async (args) => {
|
|
23
14
|
try {
|
|
24
15
|
const source = readFileSync(args.path, "utf-8");
|
|
25
|
-
|
|
16
|
+
let js = compileToJS(source);
|
|
17
|
+
|
|
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).
|
|
22
|
+
js = js.replace(/(from\s+|import\s*\()(['"])(@rip-lang\/[^'"]+)\2/g, (match, prefix, quote, specifier) => {
|
|
23
|
+
try {
|
|
24
|
+
return `${prefix}${quote}${fileURLToPath(import.meta.resolve(specifier))}${quote}`;
|
|
25
|
+
} catch {
|
|
26
|
+
return match;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
26
29
|
|
|
27
30
|
return {
|
|
28
31
|
contents: js,
|