summaryrefslogtreecommitdiff
path: root/dev/build-libs.js
diff options
context:
space:
mode:
Diffstat (limited to 'dev/build-libs.js')
-rw-r--r--dev/build-libs.js79
1 files changed, 38 insertions, 41 deletions
diff --git a/dev/build-libs.js b/dev/build-libs.js
index 36c07edd..8320a947 100644
--- a/dev/build-libs.js
+++ b/dev/build-libs.js
@@ -16,51 +16,48 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-const fs = require('fs');
-const path = require('path');
-const browserify = require('browserify');
+import Ajv from 'ajv';
+import standaloneCode from 'ajv/dist/standalone/index.js';
+import esbuild from 'esbuild';
+import fs from 'fs';
+import path from 'path';
+import {fileURLToPath} from 'url';
-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);
- }
-}
+const dirname = path.dirname(fileURLToPath(import.meta.url));
+const extDir = path.join(dirname, '..', 'ext');
-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(extDir, 'lib', path.basename(p)),
+ external: ['fs']
+ });
}
-async function main() {
- for (const {path: path2, build} of getBuildTargets()) {
- const content = await build();
- fs.writeFileSync(path2, content);
+export 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(); }
+ const schemaDir = path.join(extDir, 'data/schemas/');
+ const schemaFileNames = fs.readdirSync(schemaDir);
+ const schemas = schemaFileNames.map((schemaFileName) => JSON.parse(fs.readFileSync(path.join(schemaDir, schemaFileName))));
+ const ajv = new Ajv({schemas: schemas, code: {source: true, esm: true}});
+ const moduleCode = standaloneCode(ajv);
-module.exports = {
- getBuildTargets
-};
+ // https://github.com/ajv-validator/ajv/issues/2209
+ const patchedModuleCode = "import {ucs2length} from './ucs2length.js';" + moduleCode.replaceAll('require("ajv/dist/runtime/ucs2length").default', 'ucs2length');
+
+ fs.writeFileSync(path.join(extDir, 'lib/validate-schemas.js'), patchedModuleCode);
+}