Skip to content

[ESM] Convert the "cmaps"-task to use import() syntax #16667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
});
Expand All @@ -489,4 +489,6 @@ exports.compressCmaps = function (src, dest, verify) {
"%"
);
});
};
}

export { compressCmaps };
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -206,7 +206,7 @@ exports.optimizeCMap = function (data) {
}
i++;
}
};
}

function incHex(a) {
let c = 1,
Expand All @@ -223,3 +223,5 @@ function incHex(a) {
}
return s;
}

export { optimizeCMap };
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -100,4 +100,6 @@ exports.parseAdobeCMap = function (content) {
}

return result;
};
}

export { parseAdobeCMap };
8 changes: 4 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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) {
Expand Down