From 5d7dcef9b05370d99eb2ff29bda3e0b41563488d Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 3 May 2022 10:53:56 +0200 Subject: [PATCH 1/2] feat: add paths repro/example --- examples/paths/.swcrc | 15 +++++++++++++++ examples/paths/BUILD.bazel | 15 +++++++++++++++ examples/paths/src/index.ts | 8 ++++++++ examples/paths/src/modules/moduleA/index.ts | 11 +++++++++++ examples/paths/src/modules/moduleB/index.ts | 1 + 5 files changed, 50 insertions(+) create mode 100644 examples/paths/.swcrc create mode 100644 examples/paths/BUILD.bazel create mode 100644 examples/paths/src/index.ts create mode 100644 examples/paths/src/modules/moduleA/index.ts create mode 100644 examples/paths/src/modules/moduleB/index.ts diff --git a/examples/paths/.swcrc b/examples/paths/.swcrc new file mode 100644 index 0000000..1083822 --- /dev/null +++ b/examples/paths/.swcrc @@ -0,0 +1,15 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript" + }, + "target": "es2021", + "baseUrl": ".", + "paths": { + "@modules/*": ["./src/modules/*"] + } + }, + "module": { + "type": "commonjs" + } +} diff --git a/examples/paths/BUILD.bazel b/examples/paths/BUILD.bazel new file mode 100644 index 0000000..876cae7 --- /dev/null +++ b/examples/paths/BUILD.bazel @@ -0,0 +1,15 @@ +"""Path-alias use case for swc: specifying the paths options in .swcrc + +Note that this example also depends on the setup in /WORKSPACE at the root of this repository. +""" + +load("@aspect_rules_swc//swc:swc.bzl", "swc") + +# Runs `swc src/index.ts > ../../bazel-bin/examples/paths/src/index.js` +# You can run `bazel build --subcommands //examples/paths:transpile` +# to see the exact command line Bazel runs. +# Note that by default, sources are found by glob(["**/*.ts"]) +swc( + name = "transpile", + swcrc = ".swcrc", +) diff --git a/examples/paths/src/index.ts b/examples/paths/src/index.ts new file mode 100644 index 0000000..c63b92e --- /dev/null +++ b/examples/paths/src/index.ts @@ -0,0 +1,8 @@ +/* + 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/moduleA"; + +moduleA(); diff --git a/examples/paths/src/modules/moduleA/index.ts b/examples/paths/src/modules/moduleA/index.ts new file mode 100644 index 0000000..00ebf8c --- /dev/null +++ b/examples/paths/src/modules/moduleA/index.ts @@ -0,0 +1,11 @@ +/* + 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 = () => { + console.log("This is module A"); + moduleB; +}; diff --git a/examples/paths/src/modules/moduleB/index.ts b/examples/paths/src/modules/moduleB/index.ts new file mode 100644 index 0000000..2e97749 --- /dev/null +++ b/examples/paths/src/modules/moduleB/index.ts @@ -0,0 +1 @@ +export const moduleB = () => console.log("This is module B!"); From 22799fcec64651ea9469666ed4cc2929dd6cde20 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 3 May 2022 11:00:14 +0200 Subject: [PATCH 2/2] fix: syntax error in moduleA --- examples/paths/src/modules/moduleA/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/paths/src/modules/moduleA/index.ts b/examples/paths/src/modules/moduleA/index.ts index 00ebf8c..0eb984a 100644 --- a/examples/paths/src/modules/moduleA/index.ts +++ b/examples/paths/src/modules/moduleA/index.ts @@ -7,5 +7,5 @@ import { moduleB } from "@modules/moduleB"; export const moduleA = () => { console.log("This is module A"); - moduleB; + moduleB(); };