From f012fc5e70d8723846d3e05d28bbd08311c4a3fa Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 8 Jul 2023 14:35:15 +0200 Subject: [PATCH] [ESM] Convert the "cmaps"-task to use `import()` syntax --- .../cmapscompress/{compress.js => compress.mjs} | 14 ++++++++------ .../cmapscompress/{optimize.js => optimize.mjs} | 6 ++++-- external/cmapscompress/{parse.js => parse.mjs} | 6 ++++-- gulpfile.js | 8 ++++---- 4 files changed, 20 insertions(+), 14 deletions(-) rename external/cmapscompress/{compress.js => compress.mjs} (98%) rename external/cmapscompress/{optimize.js => optimize.mjs} (99%) rename external/cmapscompress/{parse.js => parse.mjs} (97%) diff --git a/external/cmapscompress/compress.js b/external/cmapscompress/compress.mjs similarity index 98% rename from external/cmapscompress/compress.js rename to external/cmapscompress/compress.mjs index a0bf221bf243c..06a46c499a806 100644 --- a/external/cmapscompress/compress.js +++ b/external/cmapscompress/compress.mjs @@ -13,10 +13,10 @@ * limitations under the License. */ -const fs = require("fs"); -const path = require("path"); -const parseAdobeCMap = require("./parse.js").parseAdobeCMap; -const optimizeCMap = require("./optimize.js").optimizeCMap; +import fs from "fs"; +import { optimizeCMap } from "./optimize.mjs"; +import { parseAdobeCMap } from "./parse.mjs"; +import path from "path"; function compressCmap(srcPath, destPath, verify) { const content = fs.readFileSync(srcPath).toString(); @@ -469,7 +469,7 @@ function incHex(a) { return s; } -exports.compressCmaps = function (src, dest, verify) { +function compressCmaps(src, dest, verify) { const files = fs.readdirSync(src).filter(function (fn) { return !fn.includes("."); // skipping files with the extension }); @@ -489,4 +489,6 @@ exports.compressCmaps = function (src, dest, verify) { "%" ); }); -}; +} + +export { compressCmaps }; diff --git a/external/cmapscompress/optimize.js b/external/cmapscompress/optimize.mjs similarity index 99% rename from external/cmapscompress/optimize.js rename to external/cmapscompress/optimize.mjs index 75716059ccdf5..97b2c1a6bbfad 100644 --- a/external/cmapscompress/optimize.js +++ b/external/cmapscompress/optimize.mjs @@ -13,7 +13,7 @@ * limitations under the License. */ -exports.optimizeCMap = function (data) { +function optimizeCMap(data) { let i = 1; while (i < data.body.length) { if (data.body[i - 1].type === data.body[i].type) { @@ -206,7 +206,7 @@ exports.optimizeCMap = function (data) { } i++; } -}; +} function incHex(a) { let c = 1, @@ -223,3 +223,5 @@ function incHex(a) { } return s; } + +export { optimizeCMap }; diff --git a/external/cmapscompress/parse.js b/external/cmapscompress/parse.mjs similarity index 97% rename from external/cmapscompress/parse.js rename to external/cmapscompress/parse.mjs index edb5ab3cac003..47ec49c01533f 100644 --- a/external/cmapscompress/parse.js +++ b/external/cmapscompress/parse.mjs @@ -13,7 +13,7 @@ * limitations under the License. */ -exports.parseAdobeCMap = function (content) { +function parseAdobeCMap(content) { let m = /(\bbegincmap\b[\s\S]*?)\bendcmap\b/.exec(content); if (!m) { throw new Error("cmap was not found"); @@ -100,4 +100,6 @@ exports.parseAdobeCMap = function (content) { } return result; -}; +} + +export { parseAdobeCMap }; diff --git a/gulpfile.js b/gulpfile.js index 20b37a092abfc..021be167d11e7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -848,7 +848,7 @@ gulp.task("locale", function () { ]); }); -gulp.task("cmaps", function (done) { +gulp.task("cmaps", async function () { const CMAP_INPUT = "external/cmaps"; const VIEWER_CMAP_OUTPUT = "external/bcmaps"; @@ -869,10 +869,10 @@ gulp.task("cmaps", function (done) { } }); - const compressCmaps = - require("./external/cmapscompress/compress.js").compressCmaps; + const { compressCmaps } = await import( + "./external/cmapscompress/compress.mjs" + ); compressCmaps(CMAP_INPUT, VIEWER_CMAP_OUTPUT, true); - done(); }); function preprocessCSS(source, defines) {