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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/rip-loader.js +24 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rip-lang",
3
- "version": "3.13.5",
3
+ "version": "3.13.6",
4
4
  "description": "A modern language that compiles to JavaScript",
5
5
  "type": "module",
6
6
  "main": "src/compiler.js",
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
- // 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(':');
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
- const js = compileToJS(source);
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,