Skip to content

Commit

Permalink
Merge pull request mozilla#16667 from Snuffleupagus/esm-cmaps
Browse files Browse the repository at this point in the history
[ESM] Convert the "cmaps"-task to use `import()` syntax
  • Loading branch information
timvandermeij authored Jul 9, 2023
2 parents c0cc7f3 + f012fc5 commit 1972b73
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
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

0 comments on commit 1972b73

Please sign in to comment.