GitXplorerGitXplorer
j

bazel-swc-paths-bug-repo

public
0 stars
0 forks
0 issues

Commits

List of commits on branch main.
Unverified
eab6d6da0eafcf9c108aa0f1dae10bed3f5919f7

add rules_swc only repro

jjackvincentnz committed a year ago
Unverified
0d391fb155de3be556fab11f4c0a79608de8eb85

upgrade to swc@v1.3.100 in Bazel WORKSPACE and add symlink repro

jjackvincentnz committed a year ago
Unverified
49f29ec5def61a8aaaed4c233f944f6efb42ca2b

bazelify and show not working in bazel

jjackvincentnz committed a year ago
Unverified
55b2805756cb82efd2f17206dce62a8a47d5716d

working swc jsc.paths resolution with nested modules

jjackvincentnz committed a year ago

README

The README file for this repository.

Bazel + SWC + paths resolution issue

Summary

Demonstrates that SWC correctly resolves jsc.paths when running outside of Bazel, and then within Bazel resolves these paths to include sandboxs paths.

Reproduction

  1. Build to dist/tsc with tsc: pnpm build-tsc.
  2. Build to dist/swc with swc: pnpm build-pnpm.
  3. Build to bazel-bin/ with Bazel and rules_ts: pnpm build-bazel.
  4. Download swc@v1.3.100, and build in symlinked tmp dir: ./repro.sh
  5. Build to bazel-bin/ with Bazel and rules_swc: pnpm build-bazel-swc.

Issue

When built with Bazel and rules_swc (5), the resolved paths include the sandbox directory:

# bazel-bin/src/parent/out/index.js

import { name } from "../../../../../../../private/var/tmp/_bazel_jack.vincent/04548c3a2779b70cbf6368fff2f77038/sandbox/darwin-sandbox/43/execroot/__main__/bazel-out/darwin-fastbuild/bin/src/parent/child";
export const parentName = name + "'s parent";

When built with Bazel (3) and rules_ts, the resolved paths include the sandbox directory:

# bazel-bin/src/parent/index.js

import { name } from "../../../../../../../private/var/tmp/_bazel_jack.vincent/04548c3a2779b70cbf6368fff2f77038/sandbox/darwin-sandbox/12/execroot/__main__/src/parent/child";
export const parentName = name + "'s parent";

Outside Bazel, swc resolves the configured path to the relative path:

# dist/swc/parent/index.js

import { name } from "./child";
export const parentName = name + "'s parent";

Tsc does nothing with these imports, as they don't modify pure JS:

# dist/tsc/parent/index.js

import { name } from "@myorg/parent/child";
export const parentName = name + "'s parent";

Building with the swc cli in a symlinked tmp directory also works outside Bazel:

╰─❯ ./repro.sh
total 0
drwx------    4 jack.vincent  999066206   128 22 Dec 11:03 .
drwx------@ 244 jack.vincent  999066206  7808 22 Dec 11:03 ..
lrwxr-xr-x    1 jack.vincent  999066206    45 22 Dec 11:03 .swcrc -> /Users/jack.vincent/code/dump/swc_test/.swcrc
drwxr-xr-x    4 jack.vincent  999066206   128 22 Dec 11:03 src

./src:
total 0
drwxr-xr-x  4 jack.vincent  999066206  128 22 Dec 11:03 .
drwx------  4 jack.vincent  999066206  128 22 Dec 11:03 ..
lrwxr-xr-x  1 jack.vincent  999066206   51 22 Dec 11:03 index.ts -> /Users/jack.vincent/code/dump/swc_test/src/index.ts
drwxr-xr-x  4 jack.vincent  999066206  128 22 Dec 11:03 parent

./src/parent:
total 0
drwxr-xr-x  4 jack.vincent  999066206  128 22 Dec 11:03 .
drwxr-xr-x  4 jack.vincent  999066206  128 22 Dec 11:03 ..
drwxr-xr-x  3 jack.vincent  999066206   96 22 Dec 11:03 child
lrwxr-xr-x  1 jack.vincent  999066206   58 22 Dec 11:03 index.ts -> /Users/jack.vincent/code/dump/swc_test/src/parent/index.ts

./src/parent/child:
total 0
drwxr-xr-x  3 jack.vincent  999066206   96 22 Dec 11:03 .
drwxr-xr-x  4 jack.vincent  999066206  128 22 Dec 11:03 ..
lrwxr-xr-x  1 jack.vincent  999066206   64 22 Dec 11:03 index.ts -> /Users/jack.vincent/code/dump/swc_test/src/parent/child/index.ts
import { parentName } from "./parent";
import { name } from "./child";