diff --git a/.gitattributes b/.gitattributes
index 1a0ca3aa71..f2db881a76 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -2,5 +2,4 @@ docs/Built-ins.md linguist-generated=true
docs/Jasmine.md linguist-generated=true
docs/Providers.md linguist-generated=true
docs/Rollup.md linguist-generated=true
-docs/Terser.md linguist-generated=true
docs/TypeScript.md linguist-generated=true
diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel
index fe52a7237c..2aaece8cf9 100644
--- a/docs/BUILD.bazel
+++ b/docs/BUILD.bazel
@@ -65,7 +65,6 @@ _READMES = {
"Jasmine": "//packages/jasmine:README.md",
"Providers": "//docs:providers.md_",
"Rollup": "//packages/rollup:README.md",
- "Terser": "//packages/terser:README.md",
}
[
diff --git a/docs/Terser.md b/docs/Terser.md
deleted file mode 100755
index edbbe945e5..0000000000
--- a/docs/Terser.md
+++ /dev/null
@@ -1,143 +0,0 @@
-
-
-# Terser rules for Bazel
-
-The Terser rules run the Terser JS minifier with Bazel.
-
-Wraps the Terser CLI documented at https://github.com/terser-js/terser#command-line-usage
-
-## Installation
-
-Add the `@bazel/terser` npm package to your `devDependencies` in `package.json`.
-
-## Installing with user-managed dependencies
-
-If you didn't use the `yarn_install` or `npm_install` rule, you'll have to declare a rule in your root `BUILD.bazel` file to execute terser:
-
-```python
-# Create a terser rule to use in terser_minified#terser_bin
-# attribute when using user-managed dependencies
-nodejs_binary(
- name = "terser_bin",
- entry_point = "//:node_modules/terser/bin/uglifyjs",
- # Point bazel to your node_modules to find the entry point
- data = ["//:node_modules"],
-)
-```
-
-
-## terser_minified
-
-**USAGE**
-
-
-terser_minified(name, args, config_file, debug, sourcemap, src, terser_bin)
-
-
-Run the terser minifier.
-
-Typical example:
-```python
-load("@npm//@bazel/terser:index.bzl", "terser_minified")
-
-terser_minified(
- name = "out.min",
- src = "input.js",
- config_file = "terser_config.json",
-)
-```
-
-Note that the `name` attribute determines what the resulting files will be called.
-So the example above will output `out.min.js` and `out.min.js.map` (since `sourcemap` defaults to `true`).
-If the input is a directory, then the output will also be a directory, named after the `name` attribute.
-Note that this rule is **NOT** recursive. It assumes a flat file structure. Passing in a folder with nested folder
-will result in an empty output directory.
-
-
-**ATTRIBUTES**
-
-
-name
-
-(*Name, mandatory*): A unique name for this target.
-
-
-args
-
-(*List of strings*): Additional command line arguments to pass to terser.
-
-Terser only parses minify() args from the config file so additional arguments such as `--comments` may
-be passed to the rule using this attribute. See https://github.com/terser/terser#command-line-usage for the
-full list of terser CLI options.
-
-Defaults to `[]`
-
-config_file
-
-(*Label*): A JSON file containing Terser minify() options.
-
-This is the file you would pass to the --config-file argument in terser's CLI.
-https://github.com/terser-js/terser#minify-options documents the content of the file.
-
-Bazel will make a copy of your config file, treating it as a template.
-
-Run bazel with `--subcommands` to see the path to the copied file.
-
-If you use the magic strings `"bazel_debug"` or `"bazel_no_debug"`, these will be
-replaced with `true` and `false` respecting the value of the `debug` attribute
-or the `--compilation_mode=dbg` bazel flag.
-
-For example
-
-```
-{
- "compress": {
- "arrows": "bazel_no_debug"
- }
-}
-```
-
-Will disable the `arrows` compression setting when debugging.
-
-If `config_file` isn't supplied, Bazel will use a default config file.
-
-Defaults to `@npm//@bazel/terser:terser_config.default.json`
-
-debug
-
-(*Boolean*): Configure terser to produce more readable output.
-
-Instead of setting this attribute, consider using debugging compilation mode instead
-bazel build --compilation_mode=dbg //my/terser:target
-so that it only affects the current build.
-
-Defaults to `False`
-
-sourcemap
-
-(*Boolean*): Whether to produce a .js.map output
-
-Defaults to `True`
-
-src
-
-(*Label, mandatory*): File(s) to minify.
-
-Can be a .js file, a rule producing .js files as its default output, or a rule producing a directory of .js files.
-
-Note that you can pass multiple files to terser, which it will bundle together.
-If you want to do this, you can pass a filegroup here.
-
-
-terser_bin
-
-(*Label*): An executable target that runs Terser
-
-Defaults to `@npm//@bazel/terser/bin:terser`
-
-
diff --git a/e2e/BUILD.bazel b/e2e/BUILD.bazel
index 3d1007440e..80e419d0e5 100644
--- a/e2e/BUILD.bazel
+++ b/e2e/BUILD.bazel
@@ -120,12 +120,6 @@ e2e_integration_test(
tags = ["no-bazelci-windows"],
)
-# terser rules are tested in the e2e_webapp
-test_suite(
- name = "e2e_terser",
- tests = ["e2e_webapp"],
-)
-
# rollup rules are tested in the e2e_webapp
test_suite(
name = "e2e_rollup",
@@ -136,7 +130,6 @@ e2e_integration_test(
name = "e2e_webapp",
npm_packages = {
"//packages/rollup:npm_package": "@bazel/rollup",
- "//packages/terser:npm_package": "@bazel/terser",
},
)
diff --git a/e2e/webapp/BUILD.bazel b/e2e/webapp/BUILD.bazel
index af96a1e97f..b78a56b339 100644
--- a/e2e/webapp/BUILD.bazel
+++ b/e2e/webapp/BUILD.bazel
@@ -1,6 +1,5 @@
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
-load("@npm//@bazel/terser:index.bzl", "terser_minified")
rollup_bundle(
name = "app",
@@ -12,13 +11,8 @@ rollup_bundle(
# supports_workers = True,
)
-terser_minified(
- name = "out.min",
- src = "app",
-)
-
nodejs_test(
name = "test",
- data = ["out.min"],
+ data = ["app"],
entry_point = ":test.js",
)
diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel
index eecdb030bd..9a8807b28f 100644
--- a/examples/BUILD.bazel
+++ b/examples/BUILD.bazel
@@ -19,7 +19,6 @@ example_integration_test(
timeout = "long",
npm_packages = {
"//packages/rollup:npm_package": "@bazel/rollup",
- "//packages/terser:npm_package": "@bazel/terser",
"//packages/typescript:npm_package": "@bazel/typescript",
},
owners = [
@@ -66,7 +65,6 @@ example_integration_test(
name = "examples_app",
npm_packages = {
"//packages/rollup:npm_package": "@bazel/rollup",
- "//packages/terser:npm_package": "@bazel/terser",
"//packages/typescript:npm_package": "@bazel/typescript",
},
)
@@ -112,7 +110,6 @@ example_integration_test(
npm_packages = {
"//packages/jasmine:npm_package": "@bazel/jasmine",
"//packages/rollup:npm_package": "@bazel/rollup",
- "//packages/terser:npm_package": "@bazel/terser",
},
tags = [
# Bintray was removed from the internet, and the version of
@@ -148,7 +145,6 @@ example_integration_test(
],
npm_packages = {
"//packages/rollup:npm_package": "@bazel/rollup",
- "//packages/terser:npm_package": "@bazel/terser",
"//packages/typescript:npm_package": "@bazel/typescript",
},
)
diff --git a/examples/angular/src/BUILD.bazel b/examples/angular/src/BUILD.bazel
index b63af3f07f..001317540c 100644
--- a/examples/angular/src/BUILD.bazel
+++ b/examples/angular/src/BUILD.bazel
@@ -4,7 +4,6 @@ load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
load("@npm//@babel/cli:index.bzl", "babel")
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
-load("@npm//@bazel/terser:index.bzl", "terser_minified")
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@npm//history-server:index.bzl", "history_server")
load("@npm//html-insert-assets:index.bzl", "html_insert_assets")
@@ -150,16 +149,6 @@ history_server(
templated_args = ["-a $$(rlocation $(rootpath :devapp))"],
)
-terser_minified(
- name = "bundle-es2015.min",
- src = ":bundle-es2015",
-)
-
-terser_minified(
- name = "bundle-es5.min",
- src = ":bundle-es5",
-)
-
html_insert_assets(
name = "inject_scripts_for_prod",
# we can't output "src/example/index.html" since that collides with the devmode file.
@@ -173,21 +162,21 @@ html_insert_assets(
"--roots=. $(RULEDIR)",
"--assets",
] + ["$(execpath %s)" % s for s in _ASSETS] + [
- "--scripts --module $(execpath :bundle-es2015.min)/index.prod.js",
- "--scripts --nomodule $(execpath :bundle-es5.min)/index.prod.js",
+ "--scripts --module $(execpath :bundle-es2015)/index.prod.js",
+ "--scripts --nomodule $(execpath :bundle-es5)/index.prod.js",
],
data = [
"//src:example/index.html",
- ":bundle-es2015.min",
- ":bundle-es5.min",
+ ":bundle-es2015",
+ ":bundle-es5",
] + _ASSETS,
)
pkg_web(
name = "prodapp",
srcs = _ASSETS + [
- ":bundle-es2015.min",
- ":bundle-es5.min",
+ ":bundle-es2015",
+ ":bundle-es5",
# each injected index file should be listed here
":inject_scripts_for_prod",
"//src/assets",
diff --git a/examples/app/BUILD.bazel b/examples/app/BUILD.bazel
index d94a60f322..4dcccf2e21 100644
--- a/examples/app/BUILD.bazel
+++ b/examples/app/BUILD.bazel
@@ -1,7 +1,6 @@
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
load("@npm//@bazel/protractor:index.bzl", "protractor_web_test_suite")
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
-load("@npm//@bazel/terser:index.bzl", "terser_minified")
load("@npm//@bazel/typescript:index.bzl", "ts_project")
load("@npm//html-insert-assets:index.bzl", "html_insert_assets")
load("@npm//http-server:index.bzl", "http_server")
@@ -19,13 +18,8 @@ rollup_bundle(
deps = [":app"],
)
-terser_minified(
- name = "bundle.min",
- src = ":bundle",
-)
-
_ASSETS = [
- ":bundle.min",
+ ":bundle",
"//styles:base.css",
"//styles:test.css",
]
diff --git a/examples/kotlin/BUILD.bazel b/examples/kotlin/BUILD.bazel
index bac6c9b57e..50ef918014 100644
--- a/examples/kotlin/BUILD.bazel
+++ b/examples/kotlin/BUILD.bazel
@@ -5,7 +5,6 @@ load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin", "pkg_web")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_import", "kt_js_library")
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
-load("@npm//@bazel/terser:index.bzl", "terser_minified")
load("@npm//http-server:index.bzl", "http_server")
# Grab a Maven dependency
@@ -46,16 +45,10 @@ rollup_bundle(
],
)
-terser_minified(
- # This will output bundle.min directory since rollup produces a directory
- name = "bundle.min",
- src = ":bundle",
-)
-
pkg_web(
name = "package",
srcs = [
- "bundle.min",
+ "bundle",
"index.html",
],
)
diff --git a/examples/webapp/differential_loading.bzl b/examples/webapp/differential_loading.bzl
index 1d602609ad..78a432ab52 100644
--- a/examples/webapp/differential_loading.bzl
+++ b/examples/webapp/differential_loading.bzl
@@ -3,7 +3,6 @@
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
load("@npm_deps//@babel/cli:index.bzl", "babel")
load("@npm_deps//@bazel/rollup:index.bzl", "rollup_bundle")
-load("@npm_deps//@bazel/terser:index.bzl", "terser_minified")
load("@npm_deps//@bazel/typescript:index.bzl", "ts_project")
def differential_loading(name, entry_point, srcs):
@@ -42,23 +41,11 @@ def differential_loading(name, entry_point, srcs):
],
)
- # Run terser against both modern and legacy browser chunks
- terser_minified(
- name = name + "_chunks_es5.min",
- src = name + "_chunks_es5",
- )
-
- terser_minified(
- name = name + "_chunks.min",
- src = name + "_chunks",
- )
-
pkg_web(
name = name,
srcs = [
"index.html",
"favicon.png",
- name + "_chunks.min",
- name + "_chunks_es5.min",
+ name + "_chunks",
],
)
diff --git a/internal/pkg_web/test/BUILD.bazel b/internal/pkg_web/test/BUILD.bazel
index b3bc9426d5..6852f42b26 100644
--- a/internal/pkg_web/test/BUILD.bazel
+++ b/internal/pkg_web/test/BUILD.bazel
@@ -2,7 +2,6 @@ load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
load("@npm//@babel/cli:index.bzl", "babel")
load("//packages/jasmine:index.bzl", "jasmine_node_test")
load("//packages/rollup:index.bzl", "rollup_bundle")
-load("//packages/terser:index.bzl", "terser_minified")
load("//packages/typescript:index.bzl", "ts_project")
package(default_visibility = ["//visibility:public"])
@@ -41,38 +40,12 @@ babel(
],
)
-terser_minified(
- name = "bundle.min",
- src = ":bundle",
-)
-
-terser_minified(
- name = "bundle.min_debug",
- src = ":bundle",
- debug = True,
-)
-
-terser_minified(
- name = "bundle.min.es2015",
- src = ":bundle.es2015.js",
-)
-
-terser_minified(
- name = "bundle.min_debug.es2015",
- src = ":bundle.es2015.js",
- debug = True,
-)
-
pkg_web(
name = "pkg",
srcs = [
"index.html",
":bundle",
":bundle.es2015",
- ":bundle.min",
- ":bundle.min.es2015",
- ":bundle.min_debug",
- ":bundle.min_debug.es2015",
],
stamp = "@rules_nodejs//nodejs/stamp:always",
substitutions = {
diff --git a/internal/pkg_web/test/spec.js b/internal/pkg_web/test/spec.js
index 4b5a2c3a9d..de5894f5e7 100644
--- a/internal/pkg_web/test/spec.js
+++ b/internal/pkg_web/test/spec.js
@@ -11,14 +11,6 @@ describe('pkg_web', () => {
'bundle.es2015.js.map',
'bundle.js',
'bundle.js.map',
- 'bundle.min.es2015.js',
- 'bundle.min.es2015.js.map',
- 'bundle.min.js',
- 'bundle.min.js.map',
- 'bundle.min_debug.es2015.js',
- 'bundle.min_debug.es2015.js.map',
- 'bundle.min_debug.js',
- 'bundle.min_debug.js.map',
'index.html',
]);
});
diff --git a/internal/pkg_web/test2/BUILD.bazel b/internal/pkg_web/test2/BUILD.bazel
index 8a7a75e0f2..bfad0f5c73 100644
--- a/internal/pkg_web/test2/BUILD.bazel
+++ b/internal/pkg_web/test2/BUILD.bazel
@@ -2,7 +2,6 @@ load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
load("@npm//@babel/cli:index.bzl", "babel")
load("//packages/jasmine:index.bzl", "jasmine_node_test")
load("//packages/rollup:index.bzl", "rollup_bundle")
-load("//packages/terser:index.bzl", "terser_minified")
rollup_bundle(
name = "local_bundle",
@@ -31,27 +30,6 @@ babel(
],
)
-terser_minified(
- name = "local_bundle.min",
- src = ":local_bundle",
-)
-
-terser_minified(
- name = "local_bundle.min_debug",
- src = ":local_bundle",
- debug = True,
-)
-
-terser_minified(
- name = "local_bundle.min.es2015",
- src = ":local_bundle.es2015.js",
-)
-
-terser_minified(
- name = "local_bundle.min_debug.es2015",
- src = ":local_bundle.es2015.js",
- debug = True,
-)
# Same exts as //internal/pkg_web/test-exports, //internal/pkg_web/test2/rel-exports
EXTS = [
@@ -65,18 +43,10 @@ pkg_web(
"index.html",
# bundles from a different directory
"//internal/pkg_web/test:bundle.es2015",
- "//internal/pkg_web/test:bundle.min.es2015",
- "//internal/pkg_web/test:bundle.min_debug.es2015",
"//internal/pkg_web/test:bundle",
- "//internal/pkg_web/test:bundle.min",
- "//internal/pkg_web/test:bundle.min_debug",
# bundles in the current path
":local_bundle.es2015",
- ":local_bundle.min.es2015",
- ":local_bundle.min_debug.es2015",
":local_bundle",
- ":local_bundle.min",
- ":local_bundle.min_debug",
] +
# bin + gen + exported files from a different directory
["//internal/pkg_web/test-exports:bin-" + e for e in EXTS] +
diff --git a/packages/index.bzl b/packages/index.bzl
index 632c435d98..addc673afe 100644
--- a/packages/index.bzl
+++ b/packages/index.bzl
@@ -20,7 +20,6 @@ NPM_PACKAGES = ["@bazel/%s" % pkg for pkg in [
"jasmine",
"rollup",
"runfiles",
- "terser",
"typescript",
"worker",
]]
diff --git a/packages/terser/BUILD.bazel b/packages/terser/BUILD.bazel
deleted file mode 100644
index 51ddbd97fc..0000000000
--- a/packages/terser/BUILD.bazel
+++ /dev/null
@@ -1,70 +0,0 @@
-# Copyright 2017 The Bazel Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
-load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "pkg_npm")
-load("@build_bazel_rules_nodejs//tools/stardoc:index.bzl", "stardoc")
-load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file")
-
-package(default_visibility = ["//visibility:public"])
-
-exports_files(["terser_config.default.json"])
-
-exports_files(
- ["index.js"],
- visibility = ["//packages/terser:__subpackages__"],
-)
-
-bzl_library(
- name = "bzl",
- srcs = glob(["*.bzl"]),
- deps = [
- "@bazel_skylib//lib:types",
- "@build_bazel_rules_nodejs//:bzl",
- "@build_bazel_rules_nodejs//internal/common:bzl",
- "@rules_nodejs//nodejs:bzl",
- ],
-)
-
-stardoc(
- name = "docs",
- testonly = True,
- out = "README.md",
- input = "index.bzl",
- tags = ["fix-windows"],
- deps = [":bzl"],
-)
-
-copy_file(
- name = "npm_version_check",
- src = "//internal:npm_version_check.js",
- out = ":npm_version_check.js",
-)
-
-pkg_npm(
- name = "npm_package",
- package_name = "@bazel/terser",
- srcs = [
- "index.bzl",
- "index.js",
- "package.json",
- "terser_config.default.json",
- "terser_minified.bzl",
- ],
- build_file_content = """exports_files(["terser_config.default.json"])""",
- deps = [
- ":README.md",
- ":npm_version_check",
- ],
-)
diff --git a/packages/terser/bin/BUILD.bazel b/packages/terser/bin/BUILD.bazel
deleted file mode 100644
index fb1e0dc850..0000000000
--- a/packages/terser/bin/BUILD.bazel
+++ /dev/null
@@ -1,14 +0,0 @@
-"""The default binaries used in our local builds
-
-Note that in the npm distribution, this file is absent, and will be generated on-the-fly when
-the package is installed (possibly with different attribute values).
-"""
-
-load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
-
-nodejs_binary(
- name = "terser",
- data = ["@npm//terser"],
- entry_point = "//packages/terser:index.js",
- visibility = ["//:__subpackages__"],
-)
diff --git a/packages/terser/index.bzl b/packages/terser/index.bzl
deleted file mode 100644
index e9fedd5380..0000000000
--- a/packages/terser/index.bzl
+++ /dev/null
@@ -1,44 +0,0 @@
-# Copyright 2019 The Bazel Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""
-# Terser rules for Bazel
-
-The Terser rules run the Terser JS minifier with Bazel.
-
-Wraps the Terser CLI documented at https://github.com/terser-js/terser#command-line-usage
-
-## Installation
-
-Add the `@bazel/terser` npm package to your `devDependencies` in `package.json`.
-
-## Installing with user-managed dependencies
-
-If you didn't use the `yarn_install` or `npm_install` rule, you'll have to declare a rule in your root `BUILD.bazel` file to execute terser:
-
-```python
-# Create a terser rule to use in terser_minified#terser_bin
-# attribute when using user-managed dependencies
-nodejs_binary(
- name = "terser_bin",
- entry_point = "//:node_modules/terser/bin/uglifyjs",
- # Point bazel to your node_modules to find the entry point
- data = ["//:node_modules"],
-)
-```
-"""
-
-load(":terser_minified.bzl", _terser_minified = "terser_minified")
-
-terser_minified = _terser_minified
diff --git a/packages/terser/index.js b/packages/terser/index.js
deleted file mode 100644
index 3819a1523d..0000000000
--- a/packages/terser/index.js
+++ /dev/null
@@ -1,255 +0,0 @@
-#!/usr/bin/env node
-/**
- * @fileoverview wraps the terser CLI to support minifying a directory
- * Terser doesn't support it; see https://github.com/terser/terser/issues/75
- * TODO: maybe we should generalize this to a package which would be useful outside
- * bazel; however we would have to support the full terser CLI and not make
- * assumptions about how the argv looks.
- */
-const fs = require('fs');
-const path = require('path');
-const child_process = require('child_process');
-const os = require('os')
-
-// Run Bazel with --define=VERBOSE_LOGS=1 to enable this logging
-const VERBOSE_LOGS = !!process.env['VERBOSE_LOGS'];
-
-function log_verbose(...m) {
- if (VERBOSE_LOGS) console.error('[terser/index.js]', ...m);
-}
-
-function log_error(...m) {
- console.error('[terser/index.js]', ...m);
-}
-
-function isDirectory(input) {
- return fs.lstatSync(path.join(process.cwd(), input)).isDirectory();
-}
-
-// Returns a single quotes version of str
-function singleQuotes(str) {
- return `'${str.replace(/'/g, '').replace(/"/g, '')}'`;
-}
-
-// Ensures that args are well formed.
-// Work-around for an issue on Windows when exec bin path is not quoted.
-// In --source-map, base=bazel-out/x64_windows-opt-exec-2B5CBBC6/bin must
-// be quoted such as base='bazel-out/x64_windows-opt-exec-2B5CBBC6/bin' pr
-// terser fails with
-// ERROR: `includeSources,base=bazel-out/x64_windows-opt-exec-2B5CBBC6/bin,content=inline,url=bundle.min.js.map` is not a supported option
-function fixArgs(args) {
- const sourceMapIndex = args.indexOf('--source-map');
- if (sourceMapIndex === -1) {
- return args;
- }
- let sourceMapOptions = args[sourceMapIndex + 1].split(',');
- sourceMapOptions = sourceMapOptions.map(o => {
- const s = o.split('=');
- if (s.length == 1) {
- return o;
- }
- switch (s[0]) {
- case 'base':
- case 'content':
- case 'url':
- return `${s[0]}=${singleQuotes(s[1])}`;
- default:
- return o;
- }
- });
-
- return [
- ...args.slice(0, sourceMapIndex + 1),
- sourceMapOptions.join(','),
- ...args.slice(sourceMapIndex + 2),
- ];
-}
-
-/**
- * Replaces directory url with the outputFile name in the url option of source-map argument
- */
-function directoryArgs(residualArgs, inputFile, outputFile) {
- const sourceMapIndex = residualArgs.indexOf('--source-map');
- if (sourceMapIndex === -1) {
- return residualArgs;
- }
-
- let sourceMapOptions = residualArgs[sourceMapIndex + 1].split(',');
-
- // set the correct sourcemap url for this output file
- sourceMapOptions = sourceMapOptions.map(
- o => o.startsWith('url=') ? `url='${path.basename(outputFile)}.map'` : o);
-
- // if an input .map file exists then set the correct sourcemap content option
- if (fs.existsSync(`${inputFile}.map`)) {
- // even on Windows terser expects '/' path separators so we normalize these in the sourcemap
- // content file path below
- sourceMapOptions = sourceMapOptions.map(
- o => o.startsWith('content=') ? `content='${inputFile.replace(/\\/g, '/')}.map'` : o);
- }
-
- return [
- ...residualArgs.slice(0, sourceMapIndex + 1),
- sourceMapOptions.join(','),
- ...residualArgs.slice(sourceMapIndex + 2),
- ];
-}
-
-function terserDirectory(input, output, residual, terserBinary) {
- if (!fs.existsSync(output)) {
- fs.mkdirSync(output);
- }
-
- const TERSER_CONCURENCY = (process.env.TERSER_CONCURRENCY || os.cpus().length - 1) || 1
-
- let work = [];
- let active = 0;
- let errors = [];
-
- function exec([inputFile, outputFile]) {
- active++;
- let args = [
- terserBinary, inputFile, '--output', outputFile,
- ...directoryArgs(residual, inputFile, outputFile)
- ];
-
- spawn(process.execPath, [...process.execArgv, ...args])
- .then(
- (data) => {
- if (data.code) {
- errors.push(inputFile)
- // NOTE: Even though a terser process has errored we continue here to collect all of
- // the errors. this behavior is another candidate for user configuration because
- // there is value in stopping at the first error in some use cases.
-
- log_error(`errored: ${inputFile}\nOUT: ${data.out}\nERR: ${data.err}\ncode: ${
- data.code}`);
- } else {
- log_verbose('finished: ', inputFile);
- }
- --active;
- next();
- },
- (err) => {
- --active;
- log_error('errored: [spawn exception]', inputFile, '\n' + err)
- errors.push(inputFile)
- next();
- })
- }
-
- function next() {
- if (work.length) {
- exec(work.shift());
- } else if (!active) {
- if (errors.length) {
- log_error('terser errored processing javascript in directory.')
- process.exitCode = 2;
- }
- // NOTE: work is done at this point and node should exit here.
- }
- }
-
- fs.readdirSync(input).forEach(f => {
- if (path.extname(f) === '.js' || path.extname(f) === '.mjs') {
- const inputFile = path.join(input, path.basename(f));
- const outputFile = path.join(output, path.basename(f));
-
- if (active < TERSER_CONCURENCY) {
- exec([inputFile, outputFile]);
- } else {
- work.push([inputFile, outputFile])
- }
- }
- });
-}
-
-function spawn(cmd, args) {
- return new Promise((resolve, reject) => {
- const err = [];
- const out = [];
- // this may throw syncronously if the process cannot be created.
- let proc = child_process.spawn(cmd, args);
-
- proc.stdout.on('data', (buf) => {
- out.push(buf);
- });
- proc.stderr.on('data', (buf) => {err.push(buf)})
- proc.on('exit', (code) => {
- // we never reject here based on exit code because an error is a valid result of running a
- // process.
- resolve({out: Buffer.concat(out), err: err.length ? Buffer.concat(err) : false, code});
- });
- })
-}
-
-function main() {
- process.argv = fixArgs(process.argv)
-
- // Peek at the arguments to find any directories declared as inputs
- let argv = process.argv.slice(2);
- // terser_minified.bzl always passes the inputs first,
- // then --output [out], then remaining args
- // We want to keep those remaining ones to pass to terser
- // Avoid a dependency on a library like minimist; keep it simple.
- const outputArgIndex = argv.findIndex((arg) => arg.startsWith('--'));
-
- // We don't want to implement a command-line parser for terser
- // so we invoke its CLI as child processes when a directory is provided, just altering the
- // input/output arguments. See discussion: https://github.com/bazelbuild/rules_nodejs/issues/822
-
- const inputs = argv.slice(0, outputArgIndex);
- const output = argv[outputArgIndex + 1];
- const residual = argv.slice(outputArgIndex + 2);
-
- // Allow for user to override terser binary via TERSER_BINARY for testing
- let terserBinary = process.env.TERSER_BINARY;
- if (!terserBinary) {
- try {
- // Node 12 and above will respect exports field in package.json, Terser 5 added these
- // but did not add ./bin/terser as an export so we instead resolve to terser/package.json
- // and strip the /package.json and add /bin/terser in its place. This has now been
- // fixed upstream in https://github.com/terser/terser/pull/971 but this code should remain
- // so we support all versions of terser.
- // NB: slice(0,-13) trims the '/pacakge.json' from the end of the resolved path.
- const terserNpmPath = require.resolve('terser/package.json').slice(0,-13);
- terserBinary = `${terserNpmPath}/bin/terser`;
- if (!fs.existsSync(terserBinary)) {
- // Try the old `uglifyjs` binary from <4.3.0
- terserBinary = `${terserNpmPath}/bin/uglify`;
- }
- } catch (_) {
- // fall through here; will check for valid terserBinary below
- }
- }
- if (!terserBinary || !fs.existsSync(terserBinary)) {
- throw new Error('terser binary not found. Maybe you need to set the terser_bin attribute?')
- }
-
- // choose a default concurrency of the number of cores -1 but at least 1.
-
- log_verbose(`Running terser/index.js
- inputs: ${inputs}
- output: ${output}
- residual: ${residual}`);
-
- if (!inputs.find(isDirectory) && inputs.length) {
- // Inputs were only files
- // Just use terser CLI exactly as it works outside bazel
- require(terserBinary);
-
- } else if (inputs.length > 1) {
- // We don't know how to merge multiple input dirs to one output dir
- throw new Error('terser_minified only allows a single input when minifying a directory');
-
- } else if (inputs[0]) {
- terserDirectory(inputs[0], output, residual, terserBinary);
- }
-}
-
-// export this for unit testing purposes
-exports.directoryArgs = directoryArgs;
-
-if (require.main === module) {
- main();
-}
diff --git a/packages/terser/package.json b/packages/terser/package.json
deleted file mode 100644
index c4c13c0579..0000000000
--- a/packages/terser/package.json
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- "name": "@bazel/terser",
- "peerDependencies": {
- "terser": ">=4.0.0 <5.9.0"
- },
- "description": "Run Terser JS optimizer under Bazel",
- "license": "Apache-2.0",
- "version": "0.0.0-PLACEHOLDER",
- "repository": {
- "type" : "git",
- "url" : "https://github.com/bazelbuild/rules_nodejs.git",
- "directory": "packages/terser"
- },
- "bugs": {
- "url": "https://github.com/bazelbuild/rules_nodejs/issues"
- },
- "keywords": [
- "terser",
- "bazel"
- ],
- "bin": {
- "terser": "index.js"
- },
- "scripts": {
- "postinstall": "node npm_version_check.js"
- }
-}
diff --git a/packages/terser/terser_config.default.json b/packages/terser/terser_config.default.json
deleted file mode 100644
index 1caeb4e88f..0000000000
--- a/packages/terser/terser_config.default.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "compress": {
- "keep_fnames": "bazel_no_debug",
- "passes": 3,
- "pure_getters": true,
- "reduce_funcs": "bazel_no_debug",
- "reduce_vars": "bazel_no_debug",
- "sequences": "bazel_no_debug"
- },
- "mangle": "bazel_no_debug"
-}
\ No newline at end of file
diff --git a/packages/terser/terser_minified.bzl b/packages/terser/terser_minified.bzl
deleted file mode 100644
index 850bbd28e3..0000000000
--- a/packages/terser/terser_minified.bzl
+++ /dev/null
@@ -1,205 +0,0 @@
-# Copyright 2019 The Bazel Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"Rule to run the terser binary under bazel"
-
-load("@rules_nodejs//nodejs:providers.bzl", "JSModuleInfo")
-load("@build_bazel_rules_nodejs//:providers.bzl", "run_node")
-
-_DOC = """Run the terser minifier.
-
-Typical example:
-```python
-load("@npm//@bazel/terser:index.bzl", "terser_minified")
-
-terser_minified(
- name = "out.min",
- src = "input.js",
- config_file = "terser_config.json",
-)
-```
-
-Note that the `name` attribute determines what the resulting files will be called.
-So the example above will output `out.min.js` and `out.min.js.map` (since `sourcemap` defaults to `true`).
-If the input is a directory, then the output will also be a directory, named after the `name` attribute.
-Note that this rule is **NOT** recursive. It assumes a flat file structure. Passing in a folder with nested folder
-will result in an empty output directory.
-"""
-
-_TERSER_ATTRS = {
- "args": attr.string_list(
- doc = """Additional command line arguments to pass to terser.
-
-Terser only parses minify() args from the config file so additional arguments such as `--comments` may
-be passed to the rule using this attribute. See https://github.com/terser/terser#command-line-usage for the
-full list of terser CLI options.""",
- ),
- "config_file": attr.label(
- doc = """A JSON file containing Terser minify() options.
-
-This is the file you would pass to the --config-file argument in terser's CLI.
-https://github.com/terser-js/terser#minify-options documents the content of the file.
-
-Bazel will make a copy of your config file, treating it as a template.
-
-Run bazel with `--subcommands` to see the path to the copied file.
-
-If you use the magic strings `"bazel_debug"` or `"bazel_no_debug"`, these will be
-replaced with `true` and `false` respecting the value of the `debug` attribute
-or the `--compilation_mode=dbg` bazel flag.
-
-For example
-
-```
-{
- "compress": {
- "arrows": "bazel_no_debug"
- }
-}
-```
-
-Will disable the `arrows` compression setting when debugging.
-
-If `config_file` isn't supplied, Bazel will use a default config file.
-""",
- allow_single_file = True,
- # These defaults match how terser was run in the legacy built-in rollup_bundle rule.
- # We keep them the same so it's easier for users to migrate.
- default = Label("//packages/terser:terser_config.default.json"),
- ),
- "debug": attr.bool(
- doc = """Configure terser to produce more readable output.
-
-Instead of setting this attribute, consider using debugging compilation mode instead
-bazel build --compilation_mode=dbg //my/terser:target
-so that it only affects the current build.
-""",
- ),
- "sourcemap": attr.bool(
- doc = "Whether to produce a .js.map output",
- default = True,
- ),
- "src": attr.label(
- doc = """File(s) to minify.
-
-Can be a .js file, a rule producing .js files as its default output, or a rule producing a directory of .js files.
-
-Note that you can pass multiple files to terser, which it will bundle together.
-If you want to do this, you can pass a filegroup here.""",
- allow_files = [".js", ".map", ".mjs"],
- mandatory = True,
- ),
- "terser_bin": attr.label(
- doc = "An executable target that runs Terser",
- default = Label("//packages/terser/bin:terser"),
- executable = True,
- cfg = "exec",
- ),
-}
-
-def _filter_js(files):
- return [f for f in files if f.is_directory or f.extension == "js" or f.extension == "mjs"]
-
-def _terser(ctx):
- "Generate actions to create terser config run terser"
-
- # CLI arguments; see https://www.npmjs.com/package/terser#command-line-usage
- args = ctx.actions.args()
-
- inputs = []
- outputs = []
-
- # If src has a JSModuleInfo provider than use that otherwise use DefaultInfo files
- if JSModuleInfo in ctx.attr.src:
- inputs.extend(ctx.attr.src[JSModuleInfo].sources.to_list())
- else:
- inputs.extend(ctx.files.src[:])
-
- sources = _filter_js(inputs)
- sourcemaps = [f for f in inputs if f.extension == "map"]
- directory_srcs = [s for s in sources if s.is_directory]
- if len(directory_srcs) > 0:
- if len(sources) > 1:
- fail("When directories are passed to terser_minified, there should be only one input")
- outputs.append(ctx.actions.declare_directory(ctx.label.name))
- else:
- outputs.append(ctx.actions.declare_file("%s.js" % ctx.label.name))
- if ctx.attr.sourcemap:
- outputs.append(ctx.actions.declare_file("%s.js.map" % ctx.label.name))
-
- args.add_all([s.path for s in sources])
- args.add_all(["--output", outputs[0].path])
-
- debug = ctx.attr.debug or ctx.var["COMPILATION_MODE"] == "dbg"
- if debug:
- args.add("--debug")
- args.add("--beautify")
-
- if ctx.attr.sourcemap:
- # Source mapping options are comma-packed into one argv
- # see https://github.com/terser-js/terser#command-line-usage
- source_map_opts = ["includeSources", "base='%s'" % ctx.bin_dir.path]
-
- if len(sourcemaps) == 0:
- source_map_opts.append("content=inline")
- elif len(sourcemaps) == 1:
- source_map_opts.append("content='%s'" % sourcemaps[0].path)
- else:
- fail("When sourcemap is True, there should only be one or none input sourcemaps")
-
- # Add a comment at the end of the js output so DevTools knows where to find the sourcemap
- source_map_opts.append("url='%s.js.map'" % ctx.label.name)
-
- # This option doesn't work in the config file, only on the CLI
- args.add_all(["--source-map", ",".join(source_map_opts)])
-
- opts = ctx.actions.declare_file("_%s.minify_options.json" % ctx.label.name)
- inputs.append(opts)
- ctx.actions.expand_template(
- template = ctx.file.config_file,
- output = opts,
- substitutions = {
- "\"bazel_debug\"": str(debug).lower(),
- "\"bazel_no_debug\"": str(not debug).lower(),
- },
- )
-
- args.add_all(["--config-file", opts.path])
- args.add_all(ctx.attr.args)
-
- run_node(
- ctx,
- inputs = inputs,
- outputs = outputs,
- executable = "terser_bin",
- arguments = [args],
- env = {"COMPILATION_MODE": ctx.var["COMPILATION_MODE"]},
- progress_message = "Minifying JavaScript %s [terser]" % (outputs[0].short_path),
- )
-
- outputs_depset = depset(outputs)
-
- return [
- DefaultInfo(files = outputs_depset),
- JSModuleInfo(
- direct_sources = outputs_depset,
- sources = outputs_depset,
- ),
- ]
-
-terser_minified = rule(
- doc = _DOC,
- implementation = _terser,
- attrs = _TERSER_ATTRS,
-)
diff --git a/packages/terser/test/BUILD.bazel b/packages/terser/test/BUILD.bazel
deleted file mode 100644
index e2ef4a9d0f..0000000000
--- a/packages/terser/test/BUILD.bazel
+++ /dev/null
@@ -1,10 +0,0 @@
-load("//packages/jasmine:index.bzl", "jasmine_node_test")
-
-jasmine_node_test(
- name = "test",
- srcs = ["directory-args.spec.js"],
- deps = [
- "//packages/terser:index.js",
- "@npm//tmp",
- ],
-)
diff --git a/packages/terser/test/args/BUILD.bazel b/packages/terser/test/args/BUILD.bazel
deleted file mode 100644
index 8dcfd75454..0000000000
--- a/packages/terser/test/args/BUILD.bazel
+++ /dev/null
@@ -1,16 +0,0 @@
-load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test")
-load("//packages/terser:index.bzl", "terser_minified")
-
-terser_minified(
- name = "out.min",
- src = "input.js",
- args = ["--comments"],
- sourcemap = False,
-)
-
-generated_file_test(
- name = "test",
- src = "output.golden.js_",
- generated = "out.min",
- src_dbg = "output.debug.golden.js_",
-)
diff --git a/packages/terser/test/args/input.js b/packages/terser/test/args/input.js
deleted file mode 100644
index 63e0c071e7..0000000000
--- a/packages/terser/test/args/input.js
+++ /dev/null
@@ -1,12 +0,0 @@
-/**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
-class A {
- doThing() {
- console.error('thing');
- }
-}
diff --git a/packages/terser/test/args/output.debug.golden.js_ b/packages/terser/test/args/output.debug.golden.js_
deleted file mode 100644
index daf2c758a6..0000000000
--- a/packages/terser/test/args/output.debug.golden.js_
+++ /dev/null
@@ -1,12 +0,0 @@
-/**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
-class A {
- doThing() {
- console.error("thing");
- }
-}
\ No newline at end of file
diff --git a/packages/terser/test/args/output.golden.js_ b/packages/terser/test/args/output.golden.js_
deleted file mode 100644
index fb0400fbc3..0000000000
--- a/packages/terser/test/args/output.golden.js_
+++ /dev/null
@@ -1,8 +0,0 @@
-/**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
-class A{doThing(){console.error("thing")}}
\ No newline at end of file
diff --git a/packages/terser/test/debug/BUILD.bazel b/packages/terser/test/debug/BUILD.bazel
deleted file mode 100644
index d3f533001a..0000000000
--- a/packages/terser/test/debug/BUILD.bazel
+++ /dev/null
@@ -1,31 +0,0 @@
-load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test")
-load("//packages/terser:index.bzl", "terser_minified")
-
-terser_minified(
- name = "out.min",
- src = "input.js",
- debug = True,
- # Turn off sourcemap so we get only one output
- sourcemap = False,
-)
-
-generated_file_test(
- name = "test",
- src = "output.debug.golden.js_",
- generated = "out.min",
-)
-
-terser_minified(
- name = "debug_from_env",
- src = "input.js",
- sourcemap = False,
- # Don't specify debug = True
- # Instead we'll run the test with --compilation_mode=dbg
-)
-
-generated_file_test(
- name = "test_define_DEBUG",
- src = "output.golden.js_",
- generated = "debug_from_env",
- src_dbg = "output.debug.golden.js_",
-)
diff --git a/packages/terser/test/debug/input.js b/packages/terser/test/debug/input.js
deleted file mode 100644
index 450575665e..0000000000
--- a/packages/terser/test/debug/input.js
+++ /dev/null
@@ -1,6 +0,0 @@
-// This will be pretty printed since we run terser with debug settings
-class A {
- doThing() {
- console.error('thing');
- }
-}
diff --git a/packages/terser/test/debug/output.debug.golden.js_ b/packages/terser/test/debug/output.debug.golden.js_
deleted file mode 100644
index 7fb6b25267..0000000000
--- a/packages/terser/test/debug/output.debug.golden.js_
+++ /dev/null
@@ -1,5 +0,0 @@
-class A {
- doThing() {
- console.error("thing");
- }
-}
\ No newline at end of file
diff --git a/packages/terser/test/debug/output.golden.js_ b/packages/terser/test/debug/output.golden.js_
deleted file mode 100644
index 8e71c23365..0000000000
--- a/packages/terser/test/debug/output.golden.js_
+++ /dev/null
@@ -1 +0,0 @@
-class A{doThing(){console.error("thing")}}
\ No newline at end of file
diff --git a/packages/terser/test/directory-args.spec.js b/packages/terser/test/directory-args.spec.js
deleted file mode 100644
index fff58edf60..0000000000
--- a/packages/terser/test/directory-args.spec.js
+++ /dev/null
@@ -1,48 +0,0 @@
-const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']);
-const {directoryArgs} =
- require(runfiles.resolve('build_bazel_rules_nodejs/packages/terser/index.js'));
-const fs = require('fs');
-const path = require('path');
-const tmp = require('tmp');
-
-describe('directoryArgs', () => {
- it('return a new array ref', () => {
- const args = ['--source-map', '', ''];
- expect(directoryArgs(args, '')).not.toBe(args);
- });
-
- it('should not return a new array ref with source-maps arg ', () => {
- const args = [];
- expect(directoryArgs(args)).toBe(args);
- });
-
- it('should set the correct file url and souremap content', () => {
- const out = tmp.dirSync().name;
- const input = path.join(out, 'file.js');
- const output = '/test/file.js';
- const args = [
- '--ie8',
- '--source-map',
- `root='http://foo.com/src',url='some_wrong_name',content=inline`,
- '--keep-fnames',
- ];
- // if no corresponding map file exists then sourcemap content should
- // be left as inline
- expect(directoryArgs(args, input, output)).toEqual([
- '--ie8',
- '--source-map',
- `root='http://foo.com/src',url='${path.basename(output)}.map',content=inline`,
- '--keep-fnames',
- ]);
- // if a corresponding map file exists then sourcemap content should be set
- // to the map file
- fs.writeFileSync(`${input}.map`, '');
- expect(directoryArgs(args, input, output)).toEqual([
- '--ie8',
- '--source-map',
- `root='http://foo.com/src',url='${path.basename(output)}.map',content='${
- input.replace(/\\/g, '/')}.map'`,
- '--keep-fnames',
- ]);
- });
-})
diff --git a/packages/terser/test/directory_input/BUILD.bazel b/packages/terser/test/directory_input/BUILD.bazel
deleted file mode 100644
index d35f18dfdb..0000000000
--- a/packages/terser/test/directory_input/BUILD.bazel
+++ /dev/null
@@ -1,19 +0,0 @@
-load("@build_bazel_rules_nodejs//:tools/declare_directory.bzl", "declare_directory")
-load("//packages/jasmine:index.bzl", "jasmine_node_test")
-load("//packages/terser:index.bzl", "terser_minified")
-
-declare_directory(
- name = "dir",
- srcs = glob(["input*.js"]),
-)
-
-terser_minified(
- name = "out.min",
- src = "dir",
-)
-
-jasmine_node_test(
- name = "test",
- srcs = ["spec.js"],
- data = [":out.min"],
-)
diff --git a/packages/terser/test/directory_input/input1.js b/packages/terser/test/directory_input/input1.js
deleted file mode 100644
index c186f0365a..0000000000
--- a/packages/terser/test/directory_input/input1.js
+++ /dev/null
@@ -1,4 +0,0 @@
-function a() {
- var somelongname = 'a';
- console.log(somelongname);
-}
diff --git a/packages/terser/test/directory_input/input2.js b/packages/terser/test/directory_input/input2.js
deleted file mode 100644
index 5d48a06ef8..0000000000
--- a/packages/terser/test/directory_input/input2.js
+++ /dev/null
@@ -1,4 +0,0 @@
-function b() {
- var someotherlongname = 'b';
- console.log(someotherlongname);
-}
diff --git a/packages/terser/test/directory_input/spec.js b/packages/terser/test/directory_input/spec.js
deleted file mode 100644
index eea0a7f676..0000000000
--- a/packages/terser/test/directory_input/spec.js
+++ /dev/null
@@ -1,24 +0,0 @@
-const fs = require('fs');
-const path = require('path');
-const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']);
-
-describe('terser on a directory', () => {
- it('should produce an output for each input', () => {
- const out = runfiles.resolvePackageRelative('out.min');
- expect(fs.existsSync(out + '/input1.js')).toBeTruthy();
- expect(fs.existsSync(out + '/input2.js')).toBeTruthy();
- });
-
- it('should link the source to the source map', () => {
- const minFile = runfiles.resolvePackageRelative('out.min') + '/input1.js';
- const expectedSourceMapUrl = runfiles.resolvePackageRelative('out.min') + '/input1.js.map';
- const content = fs.readFileSync(minFile, 'utf8');
- const sourceMapLine = content.split(/r?\n/).find(l => l.startsWith('//#'));
-
- expect(sourceMapLine).toBeDefined();
-
- const [_, sourceMapUrl] = sourceMapLine.split('=');
-
- expect(sourceMapUrl).toEqual(path.basename(expectedSourceMapUrl));
- })
-});
diff --git a/packages/terser/test/exec/BUILD.bazel b/packages/terser/test/exec/BUILD.bazel
deleted file mode 100644
index cc4ec2145f..0000000000
--- a/packages/terser/test/exec/BUILD.bazel
+++ /dev/null
@@ -1,10 +0,0 @@
-load("//packages/jasmine:index.bzl", "jasmine_node_test")
-
-jasmine_node_test(
- name = "test",
- srcs = ["spec.js"],
- data = [
- "//packages/terser:index.js",
- ],
- tags = ["exclusive"],
-)
diff --git a/packages/terser/test/exec/spec.js b/packages/terser/test/exec/spec.js
deleted file mode 100644
index 3d4ca63974..0000000000
--- a/packages/terser/test/exec/spec.js
+++ /dev/null
@@ -1,143 +0,0 @@
-const fs = require('fs');
-const cp = require('child_process');
-const util = require('util');
-const assert = require('assert');
-const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']);
-const terserWrap = runfiles.resolve('build_bazel_rules_nodejs/packages/terser/index.js');
-
-if (!fs.existsSync(terserWrap)) {
- throw new Error(
- 'expected to find terserwrap javascript file at \n' + terserWrap + '\nbut it does not exist!')
-}
-
-if (process.platform === 'win32' && process.versions.node.split('.')[0] < 12) {
- // skip this test if we're on node10.
- // TODO: remove this when node 12 is the default
- console.error(
- 'this test is only run on windows with nodejs >= 12 because there is an issue with spawning processes and ENOMEM errors.')
- process.exit(0)
-}
-
-function terser(inputFile, outputFile, opts, attempts = 0) {
- return cp.execFileSync(
- process.execPath, [terserWrap, inputFile, '--output', outputFile], opts || {env: []})
-}
-
-describe('run terser', () => {
- it('should fail', () => {
- let thrown = false
- try {
- terser('loop.js', 'boop.js')
- } catch (e) {
- console.error(e, e + '')
- assert.strictEqual(e.status, 1, 'exit code should be 1');
- thrown = true;
- }
- assert.ok(thrown, 'should have thrown on missing input file.')
-
- fs.writeFileSync('soup.js', 'omg soup!');
-
- let stderr = '';
- try {
- terser('soup.js', 'boop.js')
- } catch (e) {
- assert.ok(e.status, 'exit code');
- stderr = e.stderr + ''
- }
-
- assert.ok(
- stderr.indexOf('Parse error at') > -1, 'should have parse error in output from terser.')
- })
-
- it('errors when cannot locate user defined terser binary', () => {
- fs.writeFileSync('soup.js', '"valid";');
-
- try {
- terser('soup.js', 'boop.js', {env: {TERSER_BINARY: 'DOES_NOT_EXIST'}})
- } catch (e) {
- console.error(e, e + '')
- assert.ok(e.status, 'exit code');
- stderr = e.stderr + ''
- }
- })
-
- // terser's default behavior waits for javascript from stdin if no arguments are provided.
- // this doesnt match with how we can use it in bazel so we disable this feature.
- it('exits when no arguments are provided.', async () => {
- await util.promisify(cp.execFile)(process.execPath, [terserWrap], {env: []});
- })
-
- it('errors when any file in a directory fails', () => {
- // retries are not run in clean directories
- try {
- fs.mkdirSync('fruit')
- fs.mkdirSync('frout')
- } catch (e) {
- }
-
- fs.writeFileSync('fruit/apples.js', 'yay apple!');
- fs.writeFileSync('fruit/orange.js', '"orange.js"');
- stderr = '';
- try {
- terser('fruit', 'frout')
- } catch (e) {
- console.log(e + '', e.status, e.stderr + '', e.stdout + '')
-
- assert.strictEqual(e.status, 2, 'exit code 2');
- stderr = e.stderr + ''
- }
-
- assert.ok(
- stderr.indexOf('Parse error at') > -1, 'should have parse error in output from terser.');
-
- assert.ok(
- fs.existsSync('frout/orange.js'),
- 'even if one script has a parse error all other scripts should be processed.')
- });
-
- // always uses concurrency >= to the number of items to process
- // this excercies a code path where the pending work queue is never used.
- it('processes all files in a directory', () => {
- // retries are not run in clean directories.
- try {
- fs.mkdirSync('fruit2');
- fs.mkdirSync('frout2');
- } catch (e) {
- }
-
- fs.writeFileSync('fruit2/apples.js', '"apple";');
- fs.writeFileSync('fruit2/orange.js', '"orange!";');
-
- try {
- terser('fruit2', 'frout2', {env: {TERSER_CONCURRENCY: 2}})
- } catch (e) {
- assert.fail('should not have failed to process any javascript.')
- }
-
- assert.ok(fs.existsSync('frout2/orange.js'), 'minified js should have been created')
- assert.ok(fs.existsSync('frout2/apples.js'), 'minified js should have been created')
- });
-
- // this excercies the code path where work has to be queued an dequeued based on exhausting the
- // avaiable concurrency.
- it('processes all files in a directory with single concurrency', () => {
- // retries are not run in clean directories
- try {
- fs.mkdirSync('fruit3');
- fs.mkdirSync('frout3');
- } catch (e) {
- }
-
- fs.writeFileSync('fruit3/apples.js', '"apple";');
- fs.writeFileSync('fruit3/orange.js', '"orange!";');
-
- try {
- terser('fruit3', 'frout3', {env: {TERSER_CONCURRENCY: 1}})
- } catch (e) {
- assert.fail('should not have failed to process any javascript.')
- }
-
- assert.ok(fs.existsSync('frout3/orange.js'), 'minified js should have been created')
- assert.ok(fs.existsSync('frout3/apples.js'), 'minified js should have been created')
- });
-});
diff --git a/packages/terser/test/inline_sourcemap/BUILD.bazel b/packages/terser/test/inline_sourcemap/BUILD.bazel
deleted file mode 100644
index c988c82de4..0000000000
--- a/packages/terser/test/inline_sourcemap/BUILD.bazel
+++ /dev/null
@@ -1,20 +0,0 @@
-load("//packages/jasmine:index.bzl", "jasmine_node_test")
-load("//packages/terser:index.bzl", "terser_minified")
-
-# Check that filegroups work
-filegroup(
- name = "srcs",
- srcs = ["input.js"],
-)
-
-terser_minified(
- name = "out.min",
- src = ":srcs",
-)
-
-jasmine_node_test(
- name = "test",
- srcs = ["spec.js"],
- data = ["@npm//source-map"],
- deps = [":out.min"],
-)
diff --git a/packages/terser/test/inline_sourcemap/input.js b/packages/terser/test/inline_sourcemap/input.js
deleted file mode 100644
index 22d226368a..0000000000
--- a/packages/terser/test/inline_sourcemap/input.js
+++ /dev/null
@@ -1,11 +0,0 @@
-'use strict';
-exports.__esModule = true;
-// clang-format off
-var MyClass = /** @class */ (function () {
- function MyClass(something) {
- console.log(something);
- }
- return MyClass;
-}());
-exports.MyClass = MyClass;
-//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbnB1dC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLG1CQUFtQjtBQUNuQjtJQUNFLGlCQUFZLFNBQWlCO1FBQzNCLE9BQU8sQ0FBQyxHQUFHLENBQUMsU0FBUyxDQUFDLENBQUM7SUFDekIsQ0FBQztJQUVILGNBQUM7QUFBRCxDQUFDLEFBTEQsSUFLQztBQUxZLDBCQUFPIn0=
\ No newline at end of file
diff --git a/packages/terser/test/inline_sourcemap/input.ts b/packages/terser/test/inline_sourcemap/input.ts
deleted file mode 100644
index b65b2f698e..0000000000
--- a/packages/terser/test/inline_sourcemap/input.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-// clang-format off
-export class MyClass {
- constructor(something: string) {
- console.log(something);
- }
- field: string|undefined;
-}
diff --git a/packages/terser/test/inline_sourcemap/spec.js b/packages/terser/test/inline_sourcemap/spec.js
deleted file mode 100644
index d4338de434..0000000000
--- a/packages/terser/test/inline_sourcemap/spec.js
+++ /dev/null
@@ -1,33 +0,0 @@
-const fs = require('fs');
-const path = require('path');
-const sm = require('source-map');
-const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']);
-
-describe('terser sourcemap handling', () => {
- it('should produce a sourcemap output', async () => {
- const file = runfiles.resolvePackageRelative('out.min.js.map');
- const debugBuild = /\/bazel-out\/[^/\s]*-dbg\//.test(file);
- const rawSourceMap = JSON.parse(fs.readFileSync(file, 'utf-8'));
- await sm.SourceMapConsumer.with(rawSourceMap, null, consumer => {
- // terser will produce different output based on DEBUG flag
- const pos =
- consumer.originalPositionFor(!debugBuild ? {line: 1, column: 89} : {line: 6, column: 22});
- expect(pos.name).toBe('something');
- expect(pos.line).toBe(3);
- expect(pos.column).toBe(14);
- });
- });
-
- it('should link the source to the source map', () => {
- const minFile = runfiles.resolvePackageRelative('out.min.js');
- const expectedSourceMapUrl = runfiles.resolvePackageRelative('out.min.js.map');
- const content = fs.readFileSync(minFile, 'utf8');
- const sourceMapLine = content.split(/r?\n/).find(l => l.startsWith('//#'));
-
- expect(sourceMapLine).toBeDefined();
-
- const [_, sourceMapUrl] = sourceMapLine.split('=');
-
- expect(sourceMapUrl).toEqual(path.basename(expectedSourceMapUrl));
- })
-});
diff --git a/packages/terser/test/js_srcs/BUILD.bazel b/packages/terser/test/js_srcs/BUILD.bazel
deleted file mode 100644
index d87414d79a..0000000000
--- a/packages/terser/test/js_srcs/BUILD.bazel
+++ /dev/null
@@ -1,41 +0,0 @@
-load("//packages/jasmine:index.bzl", "jasmine_node_test")
-load("//packages/terser:index.bzl", "terser_minified")
-
-# Case 2: get the JS file from DefaultInfo of a dep
-load(":produces_js_as_defaultinfo.bzl", "produces_js_as_defaultinfo")
-
-filegroup(
- name = "src1_in",
- srcs = [
- "src1.js",
- "src1b.js",
- ],
-)
-
-terser_minified(
- name = "case1",
- src = ":src1_in",
- sourcemap = False,
-)
-
-produces_js_as_defaultinfo(
- name = "src2_in",
- srcs = ["src2.js"],
-)
-
-terser_minified(
- name = "case2",
- src = ":src2_in",
- sourcemap = False,
-)
-
-jasmine_node_test(
- name = "test",
- srcs = [
- "terser_spec.js",
- ],
- deps = [
- ":case1",
- ":case2",
- ],
-)
diff --git a/packages/terser/test/js_srcs/produces_js_as_defaultinfo.bzl b/packages/terser/test/js_srcs/produces_js_as_defaultinfo.bzl
deleted file mode 100644
index 374309c129..0000000000
--- a/packages/terser/test/js_srcs/produces_js_as_defaultinfo.bzl
+++ /dev/null
@@ -1,9 +0,0 @@
-"test fixture"
-
-def _produces_js_as_defaultinfo(ctx):
- return DefaultInfo(files = depset(ctx.files.srcs))
-
-produces_js_as_defaultinfo = rule(
- _produces_js_as_defaultinfo,
- attrs = {"srcs": attr.label_list(allow_files = True)},
-)
diff --git a/packages/terser/test/js_srcs/src1.js b/packages/terser/test/js_srcs/src1.js
deleted file mode 100644
index 65f48d4b33..0000000000
--- a/packages/terser/test/js_srcs/src1.js
+++ /dev/null
@@ -1,5 +0,0 @@
-/**
- * @fileoverview Description of this file.
- */
-
-console.error('here is non-optimized JS');
diff --git a/packages/terser/test/js_srcs/src1b.js b/packages/terser/test/js_srcs/src1b.js
deleted file mode 100644
index cc798ff50d..0000000000
--- a/packages/terser/test/js_srcs/src1b.js
+++ /dev/null
@@ -1 +0,0 @@
-export const a = 1;
diff --git a/packages/terser/test/js_srcs/src2.js b/packages/terser/test/js_srcs/src2.js
deleted file mode 100644
index 05b07f0095..0000000000
--- a/packages/terser/test/js_srcs/src2.js
+++ /dev/null
@@ -1 +0,0 @@
-console.log('src2');
diff --git a/packages/terser/test/js_srcs/terser_spec.js b/packages/terser/test/js_srcs/terser_spec.js
deleted file mode 100644
index f82dc295ec..0000000000
--- a/packages/terser/test/js_srcs/terser_spec.js
+++ /dev/null
@@ -1,17 +0,0 @@
-const fs = require('fs');
-const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']);
-
-describe('terser rule', () => {
- it('should accept InputArtifact (file in project)', () => {
- const file = runfiles.resolvePackageRelative('case1.js');
- const debugBuild = /\/bazel-out\/[^/\s]*-dbg\//.test(file);
- const expected = debugBuild ?
- 'console.error("here is non-optimized JS");\n\nexport const a = 1;' :
- 'console.error("here is non-optimized JS");export const a=1;';
- expect(fs.readFileSync(file, 'utf-8')).toBe(expected);
- });
- it('should accept a rule that produces JS files in DefaultInfo', () => {
- const file = runfiles.resolvePackageRelative('case2.js');
- expect(fs.readFileSync(file, 'utf-8')).toBe('console.log("src2");');
- });
-});
diff --git a/packages/terser/test/sourcemap/BUILD.bazel b/packages/terser/test/sourcemap/BUILD.bazel
deleted file mode 100644
index d09fba1819..0000000000
--- a/packages/terser/test/sourcemap/BUILD.bazel
+++ /dev/null
@@ -1,51 +0,0 @@
-load("@build_bazel_rules_nodejs//:tools/declare_directory.bzl", "declare_directory")
-load("//packages/jasmine:index.bzl", "jasmine_node_test")
-load("//packages/terser:index.bzl", "terser_minified")
-
-filegroup(
- name = "src1_and_map",
- srcs = [
- "src1.js",
- "src1.js.map",
- ],
-)
-
-terser_minified(
- name = "src1.min",
- src = ":src1_and_map",
-)
-
-jasmine_node_test(
- name = "test",
- srcs = [
- "terser_spec.js",
- ],
- data = ["@npm//source-map"],
- deps = [
- ":src1.min",
- ],
-)
-
-declare_directory(
- name = "dir",
- srcs = [
- "src1.js",
- "src1.js.map",
- ],
-)
-
-terser_minified(
- name = "dir.min",
- src = "dir",
-)
-
-jasmine_node_test(
- name = "directory_test",
- srcs = [
- "directory_spec.js",
- ],
- data = ["@npm//source-map"],
- deps = [
- ":dir.min",
- ],
-)
diff --git a/packages/terser/test/sourcemap/README.md b/packages/terser/test/sourcemap/README.md
deleted file mode 100644
index 3f25b35417..0000000000
--- a/packages/terser/test/sourcemap/README.md
+++ /dev/null
@@ -1 +0,0 @@
-The src1.js{,.map} files were generated from running `tsc --lib es2015,dom --sourcemap --noImplicitUseStrict src1.ts`.
diff --git a/packages/terser/test/sourcemap/directory_spec.js b/packages/terser/test/sourcemap/directory_spec.js
deleted file mode 100644
index 6562868f4d..0000000000
--- a/packages/terser/test/sourcemap/directory_spec.js
+++ /dev/null
@@ -1,27 +0,0 @@
-const fs = require('fs');
-const sm = require('source-map');
-const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']);
-
-describe('terser on a directory with map files', () => {
- it('should produce an output for each input', () => {
- const out = runfiles.resolvePackageRelative('dir.min');
- expect(fs.existsSync(out + '/src1.js')).toBeTruthy();
- });
-
- it('should produce a sourcemap output', async () => {
- const out = runfiles.resolvePackageRelative('dir.min');
- const file = require.resolve(out + '/src1.js.map');
- const debugBuild = /\/bazel-out\/[^/\s]*-dbg\//.test(file);
- const rawSourceMap = JSON.parse(fs.readFileSync(file, 'utf-8'));
- await sm.SourceMapConsumer.with(rawSourceMap, null, consumer => {
- const pos = consumer.originalPositionFor(
- // position of MyClass in terser_minified output src1.min.js
- // depends on COMPILATION_MODE
- !debugBuild ? {line: 1, column: 18} : {line: 3, column: 5});
- expect(pos.source).toBe('src1.ts');
- expect(pos.line).toBe(2);
- expect(pos.column).toBe(14);
- expect(pos.name).toBe('MyClass');
- });
- });
-});
\ No newline at end of file
diff --git a/packages/terser/test/sourcemap/src1.js b/packages/terser/test/sourcemap/src1.js
deleted file mode 100644
index ad3902e964..0000000000
--- a/packages/terser/test/sourcemap/src1.js
+++ /dev/null
@@ -1,10 +0,0 @@
-exports.__esModule = true;
-// clang-format off
-/*a comment*/ var MyClass = /** @class */ (function () {
- function MyClass(s) {
- console.log(s);
- }
- return MyClass;
-}());
-exports.MyClass = MyClass;
-//# sourceMappingURL=src1.js.map
\ No newline at end of file
diff --git a/packages/terser/test/sourcemap/src1.js.map b/packages/terser/test/sourcemap/src1.js.map
deleted file mode 100644
index 8d7b122ca0..0000000000
--- a/packages/terser/test/sourcemap/src1.js.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"src1.js","sourceRoot":"","sources":["src1.ts"],"names":[],"mappings":";AAAA,mBAAmB;AACnB,aAAa,CAAC;IACZ,iBAAY,CAAS;QACnB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;IAEH,cAAC;AAAD,CAAC,AALa,IAKb;AAL0B,0BAAO"}
\ No newline at end of file
diff --git a/packages/terser/test/sourcemap/src1.ts b/packages/terser/test/sourcemap/src1.ts
deleted file mode 100644
index f60f2b78bd..0000000000
--- a/packages/terser/test/sourcemap/src1.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-// clang-format off
-/*a comment*/ export class MyClass {
- constructor(s: string) {
- console.log(s);
- }
- field: string|undefined;
-}
diff --git a/packages/terser/test/sourcemap/terser_spec.js b/packages/terser/test/sourcemap/terser_spec.js
deleted file mode 100644
index 4aa41135b2..0000000000
--- a/packages/terser/test/sourcemap/terser_spec.js
+++ /dev/null
@@ -1,22 +0,0 @@
-const fs = require('fs');
-const sm = require('source-map');
-const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']);
-const DIR = 'build_bazel_rules_nodejs/packages/terser/test/sourcemap';
-
-describe('terser sourcemap handling', () => {
- it('should produce a sourcemap output', async () => {
- const file = runfiles.resolve(DIR + '/src1.min.js.map');
- const debugBuild = /\/bazel-out\/[^/\s]*-dbg\//.test(file);
- const rawSourceMap = JSON.parse(fs.readFileSync(file, 'utf-8'));
- await sm.SourceMapConsumer.with(rawSourceMap, null, consumer => {
- const pos = consumer.originalPositionFor(
- // position of MyClass in terser_minified output src1.min.js
- // depends on DEBUG flag
- !debugBuild ? {line: 1, column: 18} : {line: 3, column: 5});
- expect(pos.source).toBe('src1.ts');
- expect(pos.line).toBe(2);
- expect(pos.column).toBe(14);
- expect(pos.name).toBe('MyClass');
- });
- });
-});
diff --git a/packages/terser/test/user_config/BUILD.bazel b/packages/terser/test/user_config/BUILD.bazel
deleted file mode 100644
index 8b4ee61c09..0000000000
--- a/packages/terser/test/user_config/BUILD.bazel
+++ /dev/null
@@ -1,16 +0,0 @@
-load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test")
-load("//packages/terser:index.bzl", "terser_minified")
-
-terser_minified(
- name = "out.min",
- src = "input.js",
- config_file = "terser_config.json",
- sourcemap = False,
-)
-
-generated_file_test(
- name = "test",
- src = "output.golden.js_",
- generated = "out.min",
- src_dbg = "output.debug.golden.js_",
-)
diff --git a/packages/terser/test/user_config/input.js b/packages/terser/test/user_config/input.js
deleted file mode 100644
index 8bfa41bb4e..0000000000
--- a/packages/terser/test/user_config/input.js
+++ /dev/null
@@ -1,6 +0,0 @@
-// Assert that the terser_config.json was used. It disables the arrows setting:
-// arrows (default: true) -- Converts ()=>{return x} to ()=>x.
-// The output.golden.js_ has the braces and return keyword still present
-const a = () => {
- return 'hello'
-};
diff --git a/packages/terser/test/user_config/output.debug.golden.js_ b/packages/terser/test/user_config/output.debug.golden.js_
deleted file mode 100644
index 283f499b00..0000000000
--- a/packages/terser/test/user_config/output.debug.golden.js_
+++ /dev/null
@@ -1,3 +0,0 @@
-const a = () => {
- return "hello";
-};
\ No newline at end of file
diff --git a/packages/terser/test/user_config/output.golden.js_ b/packages/terser/test/user_config/output.golden.js_
deleted file mode 100644
index 0538cefa6c..0000000000
--- a/packages/terser/test/user_config/output.golden.js_
+++ /dev/null
@@ -1 +0,0 @@
-const a=()=>{return"hello"};
\ No newline at end of file
diff --git a/packages/terser/test/user_config/terser_config.json b/packages/terser/test/user_config/terser_config.json
deleted file mode 100644
index 0723f9cd31..0000000000
--- a/packages/terser/test/user_config/terser_config.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "compress": {
- "arrows": false
- }
-}
\ No newline at end of file