Skip to content

Commit

Permalink
build.js: esbuild-wasm, build duration, fix sourcemap
Browse files Browse the repository at this point in the history
  • Loading branch information
subhoghoshX authored and martinpitt committed Apr 14, 2023
1 parent 0d7ee14 commit 00f191f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
41 changes: 28 additions & 13 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';

import fs from 'node:fs';
import path from 'node:path';
import os from 'node:os';

import copy from 'esbuild-plugin-copy';
import esbuild from "esbuild";
import { replace } from 'esbuild-plugin-replace';

import { cockpitCompressPlugin } from './pkg/lib/esbuild-compress-plugin.js';
import { cockpitPoEsbuildPlugin } from './pkg/lib/cockpit-po-plugin.js';
import { cockpitRsyncEsbuildPlugin } from './pkg/lib/cockpit-rsync-plugin.js';
import { cleanPlugin } from './pkg/lib/esbuild-cleanup-plugin.js';
import { eslintPlugin } from './pkg/lib/esbuild-eslint-plugin.js';
import { stylelintPlugin } from './pkg/lib/esbuild-stylelint-plugin.js';
import { replace } from 'esbuild-plugin-replace';
import { esbuildStylesPlugins } from './pkg/lib/esbuild-common.js';

const useWasm = os.arch() !== 'x64';
const esbuild = (await import(useWasm ? 'esbuild-wasm' : 'esbuild'));

const production = process.env.NODE_ENV === 'production';
const watchMode = process.env.ESBUILD_WATCH === "true" || false;
// linters dominate the build time, so disable them for production builds by default, but enable in watch mode
Expand All @@ -25,8 +29,24 @@ const outdir = 'dist';
// Obtain package name from package.json
const packageJson = JSON.parse(fs.readFileSync('package.json'));

const getTime = () => new Date().toTimeString()
.split(' ')[0];
function notifyEndPlugin() {
return {
name: 'notify-end',
setup(build) {
let startTime;

build.onStart(() => {
startTime = new Date();
});

build.onEnd(() => {
const endTime = new Date();
const timeStamp = endTime.toTimeString().split(' ')[0];
console.log(`${timeStamp}: Build finished in ${endTime - startTime} ms`);
});
}
};
}

const cwd = process.cwd();

Expand Down Expand Up @@ -54,7 +74,7 @@ function watch_dirs(dir, on_change) {
}

const context = await esbuild.context({
...!production ? { sourcemap: "external" } : {},
...!production ? { sourcemap: "linked" } : {},
bundle: true,
entryPoints: ["./src/index.js"],
external: ['*.woff', '*.woff2', '*.jpg', '*.svg', '../../assets*'], // Allow external font files which live in ../../static/fonts
Expand Down Expand Up @@ -98,12 +118,7 @@ const context = await esbuild.context({
...production ? [cockpitCompressPlugin()] : [],
cockpitRsyncEsbuildPlugin({ dest: packageJson.name }),

{
name: 'notify-end',
setup(build) {
build.onEnd(() => console.log(`${getTime()}: Build finished`));
}
},
notifyEndPlugin(),
]
});

Expand Down
2 changes: 1 addition & 1 deletion node_modules
Submodule node_modules updated 88 files
+70 −55 .package-lock.json
+2 −1 .package.json
+ @esbuild/linux-x64/bin/esbuild
+1 −1 @esbuild/linux-x64/package.json
+56 −0 builtins/node_modules/semver/README.md
+8 −2 builtins/node_modules/semver/bin/semver.js
+37 −33 builtins/node_modules/semver/classes/comparator.js
+6 −2 builtins/node_modules/semver/classes/range.js
+10 −9 builtins/node_modules/semver/classes/semver.js
+24 −8 builtins/node_modules/semver/functions/diff.js
+3 −2 builtins/node_modules/semver/functions/inc.js
+0 −10 builtins/node_modules/semver/functions/parse.js
+1 −0 builtins/node_modules/semver/index.js
+15 −2 builtins/node_modules/semver/internal/constants.js
+14 −10 builtins/node_modules/semver/internal/parse-options.js
+7 −6 builtins/node_modules/semver/package.json
+1 −1 builtins/node_modules/semver/ranges/intersects.js
+6 −3 builtins/node_modules/semver/ranges/subset.js
+1 −1 caniuse-lite/data/features/webgpu.js
+1 −1 caniuse-lite/package.json
+1 −1 chrome-remote-interface/chrome-remote-interface.js
+11 −0 chrome-remote-interface/lib/chrome.js
+1 −1 chrome-remote-interface/package.json
+19 −3 electron-to-chromium/full-chromium-versions.js
+1 −1 electron-to-chromium/full-chromium-versions.json
+11 −1 electron-to-chromium/full-versions.js
+1 −1 electron-to-chromium/full-versions.json
+1 −1 electron-to-chromium/package.json
+1 −0 electron-to-chromium/versions.js
+1 −1 electron-to-chromium/versions.json
+21 −0 esbuild-wasm/LICENSE.md
+3 −0 esbuild-wasm/README.md
+101 −0 esbuild-wasm/bin/esbuild
+ esbuild-wasm/esbuild.wasm
+642 −0 esbuild-wasm/esm/browser.d.ts
+2,489 −0 esbuild-wasm/esm/browser.js
+20 −0 esbuild-wasm/esm/browser.min.js
+642 −0 esbuild-wasm/lib/browser.d.ts
+2,535 −0 esbuild-wasm/lib/browser.js
+22 −0 esbuild-wasm/lib/browser.min.js
+642 −0 esbuild-wasm/lib/main.d.ts
+2,186 −0 esbuild-wasm/lib/main.js
+16 −0 esbuild-wasm/package.json
+554 −0 esbuild-wasm/wasm_exec.js
+49 −0 esbuild-wasm/wasm_exec_node.js
+1 −1 esbuild/bin/esbuild
+5 −4 esbuild/install.js
+8 −8 esbuild/lib/main.js
+23 −23 esbuild/package.json
+56 −0 eslint-plugin-n/node_modules/semver/README.md
+8 −2 eslint-plugin-n/node_modules/semver/bin/semver.js
+37 −33 eslint-plugin-n/node_modules/semver/classes/comparator.js
+6 −2 eslint-plugin-n/node_modules/semver/classes/range.js
+10 −9 eslint-plugin-n/node_modules/semver/classes/semver.js
+24 −8 eslint-plugin-n/node_modules/semver/functions/diff.js
+3 −2 eslint-plugin-n/node_modules/semver/functions/inc.js
+0 −10 eslint-plugin-n/node_modules/semver/functions/parse.js
+1 −0 eslint-plugin-n/node_modules/semver/index.js
+15 −2 eslint-plugin-n/node_modules/semver/internal/constants.js
+14 −10 eslint-plugin-n/node_modules/semver/internal/parse-options.js
+7 −6 eslint-plugin-n/node_modules/semver/package.json
+1 −1 eslint-plugin-n/node_modules/semver/ranges/intersects.js
+6 −3 eslint-plugin-n/node_modules/semver/ranges/subset.js
+4 −0 eslint-scope/README.md
+3 −3 eslint-scope/dist/eslint-scope.cjs
+1 −1 eslint-scope/lib/referencer.js
+1 −1 eslint-scope/lib/scope-manager.js
+1 −1 eslint-scope/lib/version.js
+2 −1 eslint-scope/package.json
+9 −0 is-core-module/CHANGELOG.md
+4 −1 is-core-module/core.json
+5 −4 is-core-module/package.json
+56 −0 normalize-package-data/node_modules/semver/README.md
+8 −2 normalize-package-data/node_modules/semver/bin/semver.js
+37 −33 normalize-package-data/node_modules/semver/classes/comparator.js
+6 −2 normalize-package-data/node_modules/semver/classes/range.js
+10 −9 normalize-package-data/node_modules/semver/classes/semver.js
+24 −8 normalize-package-data/node_modules/semver/functions/diff.js
+3 −2 normalize-package-data/node_modules/semver/functions/inc.js
+0 −10 normalize-package-data/node_modules/semver/functions/parse.js
+1 −0 normalize-package-data/node_modules/semver/index.js
+15 −2 normalize-package-data/node_modules/semver/internal/constants.js
+14 −10 normalize-package-data/node_modules/semver/internal/parse-options.js
+7 −6 normalize-package-data/node_modules/semver/package.json
+1 −1 normalize-package-data/node_modules/semver/ranges/intersects.js
+6 −3 normalize-package-data/node_modules/semver/ranges/subset.js
+1 −1 sass/package.json
+194 −48 sass/sass.dart.js
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
"argparse": "^2.0.1",
"buffer": "^6.0.3",
"chrome-remote-interface": "^0.32.1",
"esbuild": "0.17.10",
"esbuild": "^0.17.16",
"esbuild-plugin-copy": "^2.0.2",
"esbuild-plugin-replace": "^1.3.0",
"esbuild-sass-plugin": "2.6.0",
"esbuild-wasm": "^0.17.16",
"eslint": "^8.29.0",
"eslint-config-standard": "^17.0.0",
"eslint-config-standard-jsx": "^11.0.0",
Expand Down

0 comments on commit 00f191f

Please sign in to comment.