From 397c0225152d8eb326ab33781863e7a6c6fa2cda Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Wed, 5 May 2021 20:09:53 -0500 Subject: [PATCH] Change pull.js to work in older versions of node --- src/addons/pull.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/addons/pull.js b/src/addons/pull.js index 106dc2f1c..80d42877f 100644 --- a/src/addons/pull.js +++ b/src/addons/pull.js @@ -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);