Change pull.js to work in older versions of node

This commit is contained in:
Thomas Weber committed 2021-05-05 20:09:53 -05:00
1 parent f44e3919f8
commit 397c022515
1 file changed
+10 -1
+10 -1
View File
@@ -60,11 +60,20 @@ const commitHash = childProcess.execSync('git rev-parse --short HEAD')
.toString()
.trim();
const matchAll = (str, regex) => {
const matches = [];
let match;
while ((match = regex.exec(str)) !== null) {
matches.push(match);
}
return matches;
};
const includeImportedLibraries = contents => {
// Parse things like:
// import { normalizeHex, getHexRegex } from "../../libraries/normalize-color.js";
// import RateLimiter from "../../libraries/rate-limiter.js";
const matches = [...contents.matchAll(/import +(?:{.*}|.*) +from +["']\.\.\/\.\.\/libraries\/([\w\d_\/-]+(?:\.esm)?\.js)["'];/g)];
const matches = matchAll(contents, /import +(?:{.*}|.*) +from +["']\.\.\/\.\.\/libraries\/([\w\d_\/-]+(?:\.esm)?\.js)["'];/g);
for (const match of matches) {
const libraryFile = match[1];
const oldLibraryPath = pathUtil.resolve(__dirname, 'ScratchAddons', 'libraries', libraryFile);