Skip to content

Commit

Permalink
minor improvement to gulp generate-runtime-helpers error message (bab…
Browse files Browse the repository at this point in the history
…el#13522)

* improve gulp generate-runtime-helpers error message

If you had some garbage in packages/babel-runtime-helpers/src/helpers/,
gulp generate-runtime-helpers would blow up with an unhelpful message:

    TypeError: Cannot read property 'groups' of null

* ignore files starting with a dot when generating runtime helpers
  • Loading branch information
lightmare authored and nicolo-ribaudo committed Jul 30, 2021
1 parent 9d1415e commit 092cc0d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/babel-helpers/scripts/generate-helpers.js
Expand Up @@ -17,18 +17,21 @@ import template from "@babel/template";

for (const file of (await fs.promises.readdir(HELPERS_FOLDER)).sort()) {
if (IGNORED_FILES.has(file)) continue;
if (file.startsWith(".")) continue; // ignore e.g. vim swap files

const [helperName] = file.split(".");
const isValidId = isValidBindingIdentifier(helperName);
const varName = isValidId ? helperName : `_${helperName}`;

const fileContents = await fs.promises.readFile(
join(fileURLToPath(HELPERS_FOLDER), file),
"utf8"
);
const { minVersion } = fileContents.match(
const filePath = join(fileURLToPath(HELPERS_FOLDER), file);
const fileContents = await fs.promises.readFile(filePath, "utf8");
const minVersionMatch = fileContents.match(
/^\s*\/\*\s*@minVersion\s+(?<minVersion>\S+)\s*\*\/\s*$/m
).groups;
);
if (!minVersionMatch) {
throw new Error(`@minVersion number missing in ${filePath}`);
}
const { minVersion } = minVersionMatch.groups;

// TODO: We can minify the helpers in production
const source = fileContents
Expand Down

0 comments on commit 092cc0d

Please sign in to comment.