summaryrefslogtreecommitdiff
path: root/dev/build-libs.js
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-11-04 18:45:57 +0900
committerDarius Jahandarie <djahandarie@gmail.com>2023-11-04 18:45:57 +0900
commitef79eab44bfd000792c610b968b5ceefd41e76a0 (patch)
tree48b04f30f6248caedbd880801aa49402a9e8066a /dev/build-libs.js
parent376151096431d4362e4baaacf0cef4a534e169f7 (diff)
Modernize codebase
- Use ES modules - Remove vendored libs and build them from npm using esbuild - Switch from JSZip to zip.js
Diffstat (limited to 'dev/build-libs.js')
-rw-r--r--dev/build-libs.js60
1 files changed, 23 insertions, 37 deletions
diff --git a/dev/build-libs.js b/dev/build-libs.js
index 36c07edd..497206c9 100644
--- a/dev/build-libs.js
+++ b/dev/build-libs.js
@@ -18,49 +18,35 @@
const fs = require('fs');
const path = require('path');
-const browserify = require('browserify');
+const esbuild = require('esbuild');
-async function buildParse5() {
- const parse5Path = require.resolve('parse5');
- const cwd = process.cwd();
- try {
- const baseDir = path.dirname(parse5Path);
- process.chdir(baseDir); // This is necessary to ensure relative source map file names are consistent
- return await new Promise((resolve, reject) => {
- browserify({
- entries: [parse5Path],
- standalone: 'parse5',
- debug: true,
- baseDir
- }).bundle((error, result) => {
- if (error) {
- reject(error);
- } else {
- resolve(result);
- }
- });
- });
- } finally {
- process.chdir(cwd);
- }
-}
-
-function getBuildTargets() {
- const extLibPath = path.join(__dirname, '..', 'ext', 'lib');
- return [
- {path: path.join(extLibPath, 'parse5.js'), build: buildParse5}
- ];
+async function buildLib(p) {
+ await esbuild.build({
+ entryPoints: [p],
+ bundle: true,
+ minify: false,
+ sourcemap: true,
+ target: 'es2020',
+ format: 'esm',
+ outfile: path.join(__dirname, '..', 'ext', 'lib', path.basename(p)),
+ external: ['fs']
+ });
}
-async function main() {
- for (const {path: path2, build} of getBuildTargets()) {
- const content = await build();
- fs.writeFileSync(path2, content);
+async function buildLibs() {
+ const devLibPath = path.join(__dirname, 'lib');
+ const files = await fs.promises.readdir(devLibPath, {
+ withFileTypes: true
+ });
+ for (const f of files) {
+ if (f.isFile()) {
+ await buildLib(path.join(devLibPath, f.name));
+ }
}
}
-if (require.main === module) { main(); }
+if (require.main === module) { buildLibs(); }
module.exports = {
- getBuildTargets
+ buildLibs
};