From 9fd7830938a0978c556a99b23c1f1d99912f9822 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Tue, 26 Oct 2021 23:35:57 +0200 Subject: [PATCH] ci: use minification in production builds --- .gitlab-ci.yml | 133 ++++++++++++++++++++-------------------- package.json | 6 +- rollup.config.js | 4 ++ yarn.lock | 155 ++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 227 insertions(+), 71 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b810293..8457ab3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,85 +6,86 @@ image: node:lts stages: - - test - - build - - release - -before_script: - - yarn install --immutable + - test + - build + - release cache: &global_cache - paths: - - .yarn/cache + paths: + - .yarn/cache lint: - stage: test - script: - - yarn lint - cache: - <<: *global_cache + stage: test + before_script: + - yarn install --immutable + script: + - yarn lint + cache: + <<: *global_cache reuse: - stage: test - image: - name: fsfe/reuse:latest - entrypoint: [""] - before_script: [] - script: - - reuse lint + stage: test + image: + name: fsfe/reuse:latest + entrypoint: [''] + script: + - reuse lint build: - stage: build - script: - - yarn build - - mv dist darkness-dependent-vision - cache: - <<: *global_cache - artifacts: - paths: - - darkness-dependent-vision - expire_in: 1 week + stage: build + before_script: + - yarn install --immutable + - if [[ ! -z ${CI_COMMIT_TAG+x} ]]; then export NODE_ENV=production; fi + script: + - yarn build + - mv dist darkness-dependent-vision + cache: + <<: *global_cache + artifacts: + paths: + - darkness-dependent-vision + expire_in: 1 week .release-template: &release-template - stage: release - before_script: - - yarn install - - apt update - - apt install --yes jq - - REPOSITORY_URL=$(echo "${CI_REPOSITORY_URL}" | sed -e "s|gitlab-ci-token:.*@|${RELEASE_TOKEN}:${RELEASE_TOKEN_SECRET}@|g") - - git remote set-url origin $REPOSITORY_URL - - git config user.name $GITLAB_USER_LOGIN - - git config user.email $GITLAB_USER_EMAIL - - git branch -D ci-processing || true - - git checkout -b ci-processing - cache: - <<: *global_cache - script: | - yarn bump-version --release=${RELEASE_TYPE} - RELEASE_VERSION=$(jq -r '.version' < package.json) - git add package.json src/module.json - git --no-pager diff - git commit -m "release version ${RELEASE_VERSION}" - git tag -f latest - git tag -f ${RELEASE_VERSION} - git push origin ci-processing:${CI_BUILD_REF_NAME} - git push origin latest -f - git push origin ${RELEASE_VERSION} - only: - - master - when: manual + stage: release + before_script: + - yarn install --immutable + - apt update + - apt install --yes jq + - REPOSITORY_URL=$(echo "${CI_REPOSITORY_URL}" | sed -e "s|gitlab-ci-token:.*@|${RELEASE_TOKEN}:${RELEASE_TOKEN_SECRET}@|g") + - git remote set-url origin $REPOSITORY_URL + - git config user.name $GITLAB_USER_LOGIN + - git config user.email $GITLAB_USER_EMAIL + - git branch -D ci-processing || true + - git checkout -b ci-processing + cache: + <<: *global_cache + script: | + yarn bump-version --release=${RELEASE_TYPE} + RELEASE_VERSION=$(jq -r '.version' < package.json) + git add package.json src/module.json + git --no-pager diff + git commit -m "release version ${RELEASE_VERSION}" + git tag -f latest + git tag -f ${RELEASE_VERSION} + git push origin ci-processing:${CI_BUILD_REF_NAME} + git push origin latest -f + git push origin ${RELEASE_VERSION} + only: + - master + when: manual release-patch: - variables: - RELEASE_TYPE: patch - <<: *release-template + variables: + RELEASE_TYPE: patch + <<: *release-template release-minor: - variables: - RELEASE_TYPE: minor - <<: *release-template + variables: + RELEASE_TYPE: minor + <<: *release-template release-major: - variables: - RELEASE_TYPE: major - <<: *release-template + variables: + RELEASE_TYPE: major + <<: *release-template diff --git a/package.json b/package.json index 340a58e..c82ea51 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "bump-version": "gulp bumpVersion", "lint": "eslint --ext .js .", "lint:fix": "eslint --ext .js --fix .", - "format": "prettier --write \"./**/*.(js|json|css)\"", + "format": "prettier --write \"./**/*.(js|json|css|yml)\"", "postinstall": "husky install" }, "devDependencies": { @@ -42,11 +42,13 @@ "lint-staged": "11.2.6", "prettier": "2.4.1", "rollup": "2.58.3", + "rollup-plugin-sourcemaps": "^0.6.3", + "rollup-plugin-terser": "^7.0.2", "semver": "7.3.5", "yargs": "17.2.1" }, "lint-staged": { "*.(js)": "eslint --fix", - "*.(json|css)": "prettier --write" + "*.(json|css|yml)": "prettier --write" } } diff --git a/rollup.config.js b/rollup.config.js index 41c50c6..ca01e81 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: MIT +const sourcemaps = require('rollup-plugin-sourcemaps'); +const { terser } = require('rollup-plugin-terser'); + module.exports = { input: 'src/module/darkness-dependent-vision.js', output: { @@ -9,4 +12,5 @@ module.exports = { format: 'es', sourcemap: true, }, + plugins: [sourcemaps(), process.env.NODE_ENV === 'production' && terser()], }; diff --git a/yarn.lock b/yarn.lock index 826b226..75967b9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5,7 +5,7 @@ __metadata: version: 4 cacheKey: 7 -"@babel/code-frame@npm:^7.0.0": +"@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.10.4": version: 7.15.8 resolution: "@babel/code-frame@npm:7.15.8" dependencies: @@ -77,6 +77,19 @@ __metadata: languageName: node linkType: hard +"@rollup/pluginutils@npm:^3.0.9": + version: 3.1.0 + resolution: "@rollup/pluginutils@npm:3.1.0" + dependencies: + "@types/estree": 0.0.39 + estree-walker: ^1.0.1 + picomatch: ^2.2.2 + peerDependencies: + rollup: ^1.20.0||^2.0.0 + checksum: 45da6411e045d1b034242a8144f4a5e8c02ff1b68a2e0857807f5bb4b091c416f2015e075057f0f0dec200e7b35efe6ed4e301b43e365cedea09192f01a6839b + languageName: node + linkType: hard + "@tootallnate/once@npm:1": version: 1.1.2 resolution: "@tootallnate/once@npm:1.1.2" @@ -84,6 +97,20 @@ __metadata: languageName: node linkType: hard +"@types/estree@npm:0.0.39": + version: 0.0.39 + resolution: "@types/estree@npm:0.0.39" + checksum: 43e5361de39969def145f32f4599391ab13055ec94841f1633a7cfe10f0e8a940ebf0e9a4b2770454a6bddd034b57e7e0d51a4d565cb2714ee2accf10a7718be + languageName: node + linkType: hard + +"@types/node@npm:*": + version: 16.11.6 + resolution: "@types/node@npm:16.11.6" + checksum: 52890a089f89ca9f20d6022c65aa747954040835436f1ceca62bdba1e2e604a86f8a2bbc4a5d54c975834092bb22f8e23832cd6b2d1b0abc0249e9f5035d86b4 + languageName: node + linkType: hard + "@types/parse-json@npm:^4.0.0": version: 4.0.0 resolution: "@types/parse-json@npm:4.0.0" @@ -846,6 +873,13 @@ __metadata: languageName: node linkType: hard +"commander@npm:^2.20.0": + version: 2.20.3 + resolution: "commander@npm:2.20.3" + checksum: b73428e97de7624323f81ba13f8ed9271de487017432d18b4da3f07cfc528ad754bbd199004bd5d14e0ccd67d1fdfe0ec8dbbd4c438b401df3c4cc387bfd1daa + languageName: node + linkType: hard + "commander@npm:^8.2.0": version: 8.2.0 resolution: "commander@npm:8.2.0" @@ -968,6 +1002,8 @@ __metadata: lint-staged: 11.2.6 prettier: 2.4.1 rollup: 2.58.3 + rollup-plugin-sourcemaps: ^0.6.3 + rollup-plugin-terser: ^7.0.2 semver: 7.3.5 yargs: 17.2.1 languageName: unknown @@ -1397,6 +1433,13 @@ __metadata: languageName: node linkType: hard +"estree-walker@npm:^1.0.1": + version: 1.0.1 + resolution: "estree-walker@npm:1.0.1" + checksum: 85e7cee763e9125a7d8a947b3a06a8b9282873936df220dd0d791d9b3315e45e40ab096b43ba71bdc99140c11a6d23fdcf686642dc119a7b2d6181004fdb24d2 + languageName: node + linkType: hard + "esutils@npm:^2.0.2": version: 2.0.3 resolution: "esutils@npm:2.0.3" @@ -2556,6 +2599,17 @@ fsevents@~2.3.2: languageName: node linkType: hard +"jest-worker@npm:^26.2.1": + version: 26.6.2 + resolution: "jest-worker@npm:26.6.2" + dependencies: + "@types/node": "*" + merge-stream: ^2.0.0 + supports-color: ^7.0.0 + checksum: 5eb349833b5e9750ce8700388961dfd5d5e207c913122221e418e48b9cda3c17b0fb418f6a90f1614cfdc3ca836158b720c5dc1de82cb1e708266b4d76e31a38 + languageName: node + linkType: hard + "js-tokens@npm:^4.0.0": version: 4.0.0 resolution: "js-tokens@npm:4.0.0" @@ -3459,7 +3513,7 @@ fsevents@~2.3.2: languageName: node linkType: hard -"picomatch@npm:^2.2.3": +"picomatch@npm:^2.2.2, picomatch@npm:^2.2.3": version: 2.3.0 resolution: "picomatch@npm:2.3.0" checksum: 80113a0fb70cfa62730d5aa3fd3d45b76bf3985f8494080ab2de1cc1fa3ba96d77990c7553a81401e16c51c0eb19c27cf5bc94f2196155090f26c8a167968001 @@ -3596,6 +3650,15 @@ fsevents@~2.3.2: languageName: node linkType: hard +"randombytes@npm:^2.1.0": + version: 2.1.0 + resolution: "randombytes@npm:2.1.0" + dependencies: + safe-buffer: ^5.1.0 + checksum: ede2693af09732ceab1c273dd70db787f34a7b8d95bab13f1aca763483c0113452a78e53d61ff18d393dcea586d388e01f198a5132a4a85cebba31ec54164b75 + languageName: node + linkType: hard + "read-pkg-up@npm:^1.0.1": version: 1.0.1 resolution: "read-pkg-up@npm:1.0.1" @@ -3831,6 +3894,36 @@ fsevents@~2.3.2: languageName: node linkType: hard +"rollup-plugin-sourcemaps@npm:^0.6.3": + version: 0.6.3 + resolution: "rollup-plugin-sourcemaps@npm:0.6.3" + dependencies: + "@rollup/pluginutils": ^3.0.9 + source-map-resolve: ^0.6.0 + peerDependencies: + "@types/node": ">=10.0.0" + rollup: ">=0.31.2" + peerDependenciesMeta: + "@types/node": + optional: true + checksum: 73e8d02fa8ade508fb0b9c74ec273aad557d1e7f32a71c156df85337cc277834922734601233103f7a6e398fbddd53bc9105288f7b54d5e3b6dd88c2a882079e + languageName: node + linkType: hard + +"rollup-plugin-terser@npm:^7.0.2": + version: 7.0.2 + resolution: "rollup-plugin-terser@npm:7.0.2" + dependencies: + "@babel/code-frame": ^7.10.4 + jest-worker: ^26.2.1 + serialize-javascript: ^4.0.0 + terser: ^5.0.0 + peerDependencies: + rollup: ^2.0.0 + checksum: 553cc21efcea3e4d46c61fbd41cb4a82a3ab8e02ae4ce7c03f9248dea93e5a91c3624e2271490ee05b2bb481568305733b496d968d3ac9c99b777a588a336f01 + languageName: node + linkType: hard + "rollup@npm:2.58.3": version: 2.58.3 resolution: "rollup@npm:2.58.3" @@ -3920,6 +4013,15 @@ fsevents@~2.3.2: languageName: node linkType: hard +"serialize-javascript@npm:^4.0.0": + version: 4.0.0 + resolution: "serialize-javascript@npm:4.0.0" + dependencies: + randombytes: ^2.1.0 + checksum: f17305aaabab9ae443505d1bf477c13b09adb7031c397d18400bec16f43f788febdd3311ca6043fdebd1d446cfa70a5804ef7268da54351dec51080f56d52fa9 + languageName: node + linkType: hard + "set-blocking@npm:^2.0.0, set-blocking@npm:~2.0.0": version: 2.0.0 resolution: "set-blocking@npm:2.0.0" @@ -4061,6 +4163,26 @@ fsevents@~2.3.2: languageName: node linkType: hard +"source-map-resolve@npm:^0.6.0": + version: 0.6.0 + resolution: "source-map-resolve@npm:0.6.0" + dependencies: + atob: ^2.1.2 + decode-uri-component: ^0.2.0 + checksum: 9bbd2656937ce422f1526026638a91dacba0822f1ab954ac34728c9b4f2960dbfc22a8463af9fbf74f28f3722263444df79b2b5ffa07de07dbcda2ec5a8c7513 + languageName: node + linkType: hard + +"source-map-support@npm:~0.5.20": + version: 0.5.20 + resolution: "source-map-support@npm:0.5.20" + dependencies: + buffer-from: ^1.0.0 + source-map: ^0.6.0 + checksum: 2c5821ee94732b2ddbb1e1d9e61ed76ef00f72415fa686ab96d5f5c711789d55424866fa7d6c493beea380e44418053d86ec490b82c101008eac311463da84a9 + languageName: node + linkType: hard + "source-map-url@npm:^0.4.0": version: 0.4.1 resolution: "source-map-url@npm:0.4.1" @@ -4075,6 +4197,20 @@ fsevents@~2.3.2: languageName: node linkType: hard +"source-map@npm:^0.6.0": + version: 0.6.1 + resolution: "source-map@npm:0.6.1" + checksum: 8647829a0611724114022be455ca1c8a2c8ae61df81c5b3667d9b398207226a1e21174fb7bbf0b4dbeb27ac358222afb5a14f1c74a62a62b8883b012e5eb1270 + languageName: node + linkType: hard + +"source-map@npm:~0.7.2": + version: 0.7.3 + resolution: "source-map@npm:0.7.3" + checksum: 351ce26ffa1ebf203660c0d70d7566c81e65d2d994d1c2d94da140808e02da34961673ce12ecea9b40797b96fbeb8c70bf71a4ad9f779f1a4fdbba75530bb386 + languageName: node + linkType: hard + "sparkles@npm:^1.0.0": version: 1.0.1 resolution: "sparkles@npm:1.0.1" @@ -4299,7 +4435,7 @@ fsevents@~2.3.2: languageName: node linkType: hard -"supports-color@npm:^7.1.0": +"supports-color@npm:^7.0.0, supports-color@npm:^7.1.0": version: 7.2.0 resolution: "supports-color@npm:7.2.0" dependencies: @@ -4332,6 +4468,19 @@ fsevents@~2.3.2: languageName: node linkType: hard +"terser@npm:^5.0.0": + version: 5.9.0 + resolution: "terser@npm:5.9.0" + dependencies: + commander: ^2.20.0 + source-map: ~0.7.2 + source-map-support: ~0.5.20 + bin: + terser: bin/terser + checksum: 7603e5a3dc0317cc4b3251e855aa90ef397b03780a1d0d747b20b832d857b50d4c017b1342007f562e20e3e538044daa71e5addd5ab6aad64ee926c5d4b0c88f + languageName: node + linkType: hard + "text-table@npm:^0.2.0": version: 0.2.0 resolution: "text-table@npm:0.2.0"