-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support --output-dir flag (#7)
- Loading branch information
Showing
6 changed files
with
158 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Directory use case for swc: minifying a folder of code-split files | ||
This has to be a directory-in, directory-out pattern since the codesplitter produces unpredictable filenames. | ||
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") | ||
load(":mocks.bzl", "mock_codesplit") | ||
|
||
mock_codesplit( | ||
name = "split_app", | ||
) | ||
|
||
# Runs `swc path/to/split_app --out-dir ../../bazel-bin/examples/directory/minify` | ||
# You can run `bazel build --subcommands //examples/directory:minify` | ||
# to see the exact command line Bazel runs. | ||
# Note that by default, sources are found by glob(["**/*.ts"]) | ||
swc( | ||
name = "minify", | ||
srcs = ["split_app"], | ||
output_dir = True, | ||
) | ||
|
||
sh_test( | ||
name = "test", | ||
srcs = ["test.sh"], | ||
# Workaround https://github.com/swc-project/swc/issues/3028 | ||
# The test will need to know this folder to make the assertion | ||
args = ["$(TARGET_CPU)-$(COMPILATION_MODE)"], | ||
data = ["minify"], | ||
deps = ["@bazel_tools//tools/bash/runfiles"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"Placeholder for a rule like webpack which may produce an unpredictable number of JS chunks" | ||
|
||
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory") | ||
load("@bazel_skylib//rules:write_file.bzl", "write_file") | ||
|
||
def mock_codesplit(name): | ||
write_file( | ||
name = "write1", | ||
out = "file1.js", | ||
content = ["const a = 1"], | ||
) | ||
|
||
write_file( | ||
name = "write2", | ||
out = "file2.js", | ||
content = ["const a = 2"], | ||
) | ||
|
||
copy_to_directory( | ||
name = name, | ||
srcs = ["file1.js", "file2.js"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
|
||
# --- begin runfiles.bash initialization v2 --- | ||
# Copy-pasted from the Bazel Bash runfiles library v2. | ||
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash | ||
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ | ||
source "$0.runfiles/$f" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e | ||
# --- end runfiles.bash initialization v2 --- | ||
|
||
set -o errexit | ||
|
||
ARCH=$1 | ||
readonly in_folder=$(rlocation $TEST_WORKSPACE/$(dirname $TEST_BINARY)/minify) | ||
|
||
# Due to https://github.com/swc-project/swc/issues/3028 the path is longer than we'd like | ||
# It should really just contain $in_folder/file1.js | ||
if ! [[ -e $in_folder/$ARCH/bin/examples/directory/split_app/file1.js ]]; then | ||
echo >&2 "Missing expected output file in directory" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters