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

chore: cleanup paths example #132

Merged
merged 1 commit into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ swc_register_toolchains(
swc_version = "v1.3.25",
)

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "register_jq_toolchains")

aspect_bazel_lib_dependencies(override_local_config_platform = True)

register_jq_toolchains()

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_outs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ load("@bazel_skylib//rules:write_file.bzl", "write_file")
# Note, --config is documented on swcx CLI but isn't functional. See
# https://github.com/swc-project/swc/issues/4017#issuecomment-1374141572
# In the call to swc_compile below, we ought to be able to use
# `args = ["--config", "module.format=" + format]`
# `args = ["--config", "module.type=" + format]`
# As a workaround, write our config to an rc file. Can be changed back when swcx supports --config.
[
write_file(
Expand Down
2 changes: 1 addition & 1 deletion examples/paths/.swcrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"target": "es2021",
"baseUrl": "examples/paths",
"paths": {
"@modules/*": ["src/modules/*"]
"@modules/*": ["./src/modules/*"]
}
},
"module": {
Expand Down
8 changes: 8 additions & 0 deletions examples/paths/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ Note that this example also depends on the setup in /WORKSPACE at the root of th
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
load("@aspect_rules_swc//swc:defs.bzl", "swc")

# buildifier: disable=bzl-visibility
load("@aspect_rules_swc//swc/private:testing.bzl", "matching_paths_test")

swc(
name = "compile",
swcrc = ".swcrc",
)

# Verify that the "paths" entry is agreed between swc and TS language service (in the editor)
matching_paths_test(
name = "check_paths",
)

write_source_files(
name = "test",
files = {
Expand Down
10 changes: 3 additions & 7 deletions examples/paths/expected.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/*
Note: your editor/ide might be complaining about this import path as
it probably does not interpret .swcrc like it normally would a tsconfig.json,
you should safely be able to ignore this
*/ "use strict";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const _moduleX = require("./modules/moduleX");
(0, _moduleX.moduleA)(); //# sourceMappingURL=index.js.map
const _moduleA = require("./modules/moduleA");
(0, _moduleA.moduleA)(); //# sourceMappingURL=index.js.map
7 changes: 1 addition & 6 deletions examples/paths/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/*
Note: your editor/ide might be complaining about this import path as
it probably does not interpret .swcrc like it normally would a tsconfig.json,
you should safely be able to ignore this
*/
import { moduleA } from "@modules/moduleX";
import { moduleA } from "@modules/moduleA";

moduleA();

Expand Down
5 changes: 0 additions & 5 deletions examples/paths/src/modules/moduleA/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
Note: your editor/ide might be complaining about this import path as
it probably does not interpret .swcrc like it normally would a tsconfig.json,
you should safely be able to ignore this
*/
import { moduleB } from "@modules/moduleB";

export const moduleA = () => {
Expand Down
7 changes: 7 additions & 0 deletions examples/paths/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"paths": {
"@modules/*": ["./src/modules/*"]
}
}
}
27 changes: 27 additions & 0 deletions swc/private/testing.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Utilities for writing tests

TODO: promote to public API.
"""

load("@aspect_bazel_lib//lib:jq.bzl", "jq")
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")

def matching_paths_test(name, tsconfig = "tsconfig.json", swcrc = ".swcrc"):
jq(
name = "_ts_" + name,
srcs = [tsconfig],
filter = ".compilerOptions.paths",
)

jq(
name = "_swc_" + name,
srcs = [swcrc],
filter = ".jsc.paths",
)

diff_test(
name = name,
file1 = "_ts_" + name,
file2 = "_swc_" + name,
failure_message = "tsconfig compilerOptions.paths don't match swcrc jsc.paths",
)