Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full file path not being fed to SWC CLI #11

Closed
riyavsinha opened this issue Dec 20, 2021 · 9 comments · Fixed by #12
Closed

Full file path not being fed to SWC CLI #11

riyavsinha opened this issue Dec 20, 2021 · 9 comments · Fixed by #12

Comments

@riyavsinha
Copy link

riyavsinha commented Dec 20, 2021

I have a file packages/xpackage/server/src/tests/y-test.ts, which I am trying to compile with the swc_rule.

Problem
The compiled output file is empty.

Configuration

swc(
  name = "y_test_swc",
  srcs = ["y-test.ts"],
  source_maps = True,
  swcrc = "//packages/xpackage:.swcrc",
)

Possible Cause
Current subcommand being run by swc_rule:

SUBCOMMAND: # //packages/xpackage/server/src/tests:y_test_swc [action 'Transpiling with swc //packages/xpackage/server/src/tests:y_test_swc [swc packages/xpackage/server/src/tests/y-test.ts]', configuration: 2dbb605ac0825292323b7a4585cb36cd7762af7e47ba3ff3f3e09310b3ca4246, execution platform: @local_config_platform//:host]
(cd /private/var/tmp/_bazel_riyavsinha/903eebc477abc3a7df81d5ec7291fe86/execroot/workspace_name && \
  exec env - \
    SWC_BINARY_PATH=external/swc_darwin-x64/swc.darwin-x64.node \
  bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/aspect_rules_swc/swc/_cli_launcher.sh --source-maps true --config-file packages/xpackage/.swcrc server/src/tests/y-test.ts --out-file bazel-out/darwin-fastbuild/bin/packages/xpackage/server/src/tests/y-test.js --no-swcrc -q)

Because the input file is being given as server/src/tests/y-test.ts instead of packages/xpackage/server/src/tests/y-test.ts (the packages/xpackage stripped away), maybe the file is not being recognized/input to swc in the first place, and so it outputs a blank file?

(There is also no error thrown for this, and only by opening the compiled file can you see that it is blank, though this may be an issue with swc?)

@alexeagle
Copy link
Member

--out-file bazel-out/darwin-fastbuild/bin/packages/xpackage/server/src/tests/y-test.js looks right.

What's in your .swcrc?

@riyavsinha
Copy link
Author

SWCRC:

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false,
      "decorators": true,
      "dynamicImport": false
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true
    },
    "target": "es2016"
  },
  "module": {
    "type": "commonjs",
    "strict": false,
    "strictMode": true,
    "lazy": false,
    "noInterop": false
  },
  "sourceMaps": true
}

@riyavsinha
Copy link
Author

riyavsinha commented Dec 20, 2021

Oh interesting, removing the swcrc attribute makes it compile with the correct input file:

Config:

swc(
  name = "cron_test_swc",
  srcs = ["cron-test.ts"],
  source_maps = True,
)

Subcommand run:

SUBCOMMAND: # //packages/xpackage/server/src/tests:y_test_swc [action 'Transpiling with swc //packages/xpackage/server/src/tests:y_test_swc [swc packages/xpackage/server/src/tests/y-test.ts]', configuration: 2dbb605ac0825292323b7a4585cb36cd7762af7e47ba3ff3f3e09310b3ca4246, execution platform: @local_config_platform//:host]
(cd /private/var/tmp/_bazel_riyavsinha/903eebc477abc3a7df81d5ec7291fe86/execroot/workspace_name && \
  exec env - \
    SWC_BINARY_PATH=external/swc_darwin-x64/swc.darwin-x64.node \
  bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/aspect_rules_swc/swc/_cli_launcher.sh --source-maps true packages/xpackage/server/src/tests/y-test.ts --out-file bazel-out/darwin-fastbuild/bin/packages/xpackage/server/src/tests/y-test.js --no-swcrc -q)

Not fully sure what part of the swcrc is contributing to this yet

@riyavsinha
Copy link
Author

I tried moving my .swcrc to the workspace root, which produced this command, which looks more correct:

SUBCOMMAND: # //packages/xpackage/server/src/tests:y_test_swc [action 'Transpiling with swc //packages/xpackage/server/src/tests:y_test_swc [swc packages/xpackage/server/src/tests/y-test.ts]', configuration: 2dbb605ac0825292323b7a4585cb36cd7762af7e47ba3ff3f3e09310b3ca4246, execution platform: @local_config_platform//:host]
(cd /private/var/tmp/_bazel_riyavsinha/903eebc477abc3a7df81d5ec7291fe86/execroot/workspace_name && \
  exec env - \
    SWC_BINARY_PATH=external/swc_darwin-x64/swc.darwin-x64.node \
  bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/aspect_rules_swc/swc/_cli_launcher.sh --source-maps true --config-file .swcrc packages/xpackage/server/src/tests/y-test.ts --out-file bazel-out/darwin-fastbuild/bin/packages/xpackage/server/src/tests/y-test.js --no-swcrc -q)

ERROR: /Users/riyavsinha/Projects/workspace_name/packages/xpackage/server/src/tests/BUILD:20:4: Transpiling with swc //packages/xpackage/server/src/tests:y_test_swc [swc packages/xpackage/server/src/tests/y-test.ts] failed: (Exit 1): _cli_launcher.sh failed: error executing command bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/aspect_rules_swc/swc/_cli_launcher.sh --source-maps true --config-file .swcrc packages/xpackage/server/src/tests/y-test.ts --out-file ... (remaining 3 argument(s) skipped)

So, because the .swcrc is now in the root, it looks like it passes the correct full path to the CLI packages/xpackage/server/src/tests/y-test.ts.

(The error comes from //:.swcrc being passed to the CLI as .swcrc, which it doesn't like for some reason)

@riyavsinha
Copy link
Author

This is probably happening because of the "relativizing" of paths:
https://github.com/aspect-build/rules_swc/blob/main/swc/private/swc.bzl#L83

@alexeagle
Copy link
Member

Yeah I agree, swc behavior changes based on the config file path. I'm not sure if that's actually desirable or if it ought to change upstream.

@riyavsinha
Copy link
Author

Hm, so the path relativizing in this repo's rule is not the cause?

In my initial custom swc rule I believe it worked without modifying paths in the rule implementation:

args.add("--config-file", ctx.file.swcrc.path)
args.add_all([src.path for src in ctx.files.srcs])

alexeagle added a commit that referenced this issue Dec 21, 2021
maybe something changed upstream since that code was written?
The newly added example shows it working without that.

Fixes #11
alexeagle added a commit that referenced this issue Dec 21, 2021
maybe something changed upstream since that code was written?
The newly added example shows it working without that.

Fixes #11
@alexeagle
Copy link
Member

@gregmagolan added that comment

# Pass in the swcrc config if it is set; if it is
# then source paths are expected to be relative to the swcrc directory

But yeah, it seems broken to me as-is.

@gregmagolan
Copy link
Member

Odd, I had trouble with it initially with the full path when passing an swcrc file and had to make it relative to work. Something change upstream?

gregmagolan pushed a commit that referenced this issue Dec 21, 2021
maybe something changed upstream since that code was written?
The newly added example shows it working without that.

Fixes #11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants