Skip to content

Commit b680d76

Browse files
committed
Rollup gopherage typescript bundle with make rule
This is an example from reverse engineering rollup_bundle bazel target. Gopherage typescript bundle is already source code controlled, verify-gopherage script is meant to ensure that the bundled js file is correct, however https://github.com/kubernetes/test-infra/blob/26e57a2169f9f24d8980bdf63c6bb268b3522ea1/hack/verify-gopherage.sh#L36 doesn't really catch error when the generated file doesn't exist, which doesn't really work.
1 parent 16e3d7b commit b680d76

File tree

7 files changed

+131
-6
lines changed

7 files changed

+131
-6
lines changed

gopherage/Makefile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2022 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
include ../Makefile.base.mk
16+
# Makefile.base.mk requires REPO_ROOT to be set
17+
REPO_ROOT:=${CURDIR}/..
18+
19+
rollup-js:
20+
./rollup-js.sh
21+
22+
.PHONY: rollup-js

gopherage/cmd/html/static/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_output

gopherage/cmd/html/static/tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{
55
"extends": "../../../../tsconfig.json",
66
"compilerOptions": {
7-
"target": "es2015"
8-
}
7+
"target": "es2015",
8+
"outDir": "_output"
9+
},
910
}

gopherage/rollup-js.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2021 The Kubernetes Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o errexit
17+
set -o nounset
18+
set -o pipefail
19+
20+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
21+
cd "${REPO_ROOT}"
22+
23+
# ensure deps are installed
24+
hack/build/ensure-node_modules.sh
25+
26+
hack/run-in-node-container.sh \
27+
node_modules/.bin/rimraf dist
28+
29+
trap "rm -rf gopherage/cmd/html/static/_output" EXIT
30+
31+
hack/run-in-node-container.sh \
32+
node_modules/.bin/tsc -p gopherage/cmd/html/static/tsconfig.json
33+
34+
hack/run-in-node-container.sh \
35+
node_modules/.bin/rollup -c gopherage/rollup.config.js

gopherage/rollup.config.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { nodeResolve } from '@rollup/plugin-node-resolve';
2+
import commonjs from '@rollup/plugin-commonjs';
3+
import { terser } from "rollup-plugin-terser";
4+
5+
export default {
6+
context: "window",
7+
input: './gopherage/cmd/html/static/_output/browser.js',
8+
output: [
9+
{
10+
file: 'bundle.js',
11+
format: 'esm',
12+
},
13+
{
14+
file: 'bundle.min.js',
15+
format: 'esm',
16+
plugins: [terser()]
17+
}
18+
],
19+
plugins: [nodeResolve(), commonjs()]
20+
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@rollup/plugin-commonjs": "14.0.0",
1919
"@rollup/plugin-json": "4.1.0",
2020
"@rollup/plugin-node-resolve": "8.4.0",
21+
"rollup-plugin-terser": "5.1.3",
2122
"@types/color": "^3.0.0",
2223
"@types/google.visualization": "^0.0.43",
2324
"@types/gtag.js": "^0.0.0",

yarn.lock

+49-4
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,14 @@ jasmine@~3.4.0:
719719
glob "^7.1.3"
720720
jasmine-core "~3.4.0"
721721

722+
jest-worker@^24.6.0:
723+
version "24.9.0"
724+
resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-24.9.0.tgz#5dbfdb5b2d322e98567898238a9697bcce67b3e5"
725+
integrity sha512-51PE4haMSXcHohnSMdM42anbvZANYTqMrr52tVKPqqsPJMzoP6FYYDVqahX/HrAoKEKz3uUPzSvKs9A3qR4iVw==
726+
dependencies:
727+
merge-stream "^2.0.0"
728+
supports-color "^6.1.0"
729+
722730
js-tokens@^4.0.0:
723731
version "4.0.0"
724732
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
@@ -758,6 +766,11 @@ make-dir@^3.0.0:
758766
dependencies:
759767
semver "^6.0.0"
760768

769+
merge-stream@^2.0.0:
770+
version "2.0.0"
771+
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
772+
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==
773+
761774
minimatch@^3.0.4:
762775
version "3.0.4"
763776
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
@@ -907,7 +920,18 @@ [email protected]:
907920
"@buxlabs/amd-to-es6" "^0.13.3"
908921
rollup-pluginutils "^2.3.3"
909922

910-
rollup-pluginutils@^2.3.3:
923+
924+
version "5.1.3"
925+
resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-5.1.3.tgz#5f4c4603b12b4f8d093f4b6f31c9aa5eba98a223"
926+
integrity sha512-FuFuXE5QUJ7snyxHLPp/0LFXJhdomKlIx/aK7Tg88Yubsx/UU/lmInoJafXJ4jwVVNcORJ1wRUC5T9cy5yk0wA==
927+
dependencies:
928+
"@babel/code-frame" "^7.0.0"
929+
jest-worker "^24.6.0"
930+
rollup-pluginutils "^2.8.1"
931+
serialize-javascript "^2.1.2"
932+
terser "^4.1.0"
933+
934+
rollup-pluginutils@^2.3.3, rollup-pluginutils@^2.8.1:
911935
version "2.8.2"
912936
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz#72f2af0748b592364dbd3389e600e5a9444a351e"
913937
integrity sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==
@@ -941,6 +965,11 @@ semver@^6.0.0:
941965
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
942966
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
943967

968+
serialize-javascript@^2.1.2:
969+
version "2.1.2"
970+
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-2.1.2.tgz#ecec53b0e0317bdc95ef76ab7074b7384785fa61"
971+
integrity sha512-rs9OggEUF0V4jUSecXazOYsLfu7OGK2qIn3c7IPBiffz32XniEp/TX9Xmc9LQfK2nQ2QKHvZ2oygKUGU0lG4jQ==
972+
944973
set-blocking@^2.0.0:
945974
version "2.0.0"
946975
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
@@ -1029,6 +1058,13 @@ supports-color@^5.3.0:
10291058
dependencies:
10301059
has-flag "^3.0.0"
10311060

1061+
supports-color@^6.1.0:
1062+
version "6.1.0"
1063+
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.1.0.tgz#0764abc69c63d5ac842dd4867e8d025e880df8f3"
1064+
integrity sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==
1065+
dependencies:
1066+
has-flag "^3.0.0"
1067+
10321068
supports-color@^7.1.0:
10331069
version "7.2.0"
10341070
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da"
@@ -1045,6 +1081,15 @@ [email protected]:
10451081
source-map "~0.6.1"
10461082
source-map-support "~0.5.12"
10471083

1084+
terser@^4.1.0:
1085+
version "4.8.0"
1086+
resolved "https://registry.yarnpkg.com/terser/-/terser-4.8.0.tgz#63056343d7c70bb29f3af665865a46fe03a0df17"
1087+
integrity sha512-EAPipTNeWsb/3wLPeup1tVPaXfIaU68xMnVdPafIL1TV05OhASArYyIfFvnvJCNrR2NIOvDVNNTFRa+Re2MWyw==
1088+
dependencies:
1089+
commander "^2.20.0"
1090+
source-map "~0.6.1"
1091+
source-map-support "~0.5.12"
1092+
10481093
test-exclude@^6.0.0:
10491094
version "6.0.0"
10501095
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-6.0.0.tgz#04a8698661d805ea6fa293b6cb9e63ac044ef15e"
@@ -1101,9 +1146,9 @@ tsutils@^2.29.0:
11011146
tslib "^1.8.1"
11021147

11031148
typescript@^3.7.5:
1104-
version "3.9.7"
1105-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
1106-
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==
1149+
version "3.9.10"
1150+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.10.tgz#70f3910ac7a51ed6bef79da7800690b19bf778b8"
1151+
integrity sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==
11071152

11081153
v8-to-istanbul@^4.1.2:
11091154
version "4.1.4"

0 commit comments

Comments
 (0)