minor improvement to gulp generate-runtime-helpers error message (#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
This commit is contained in:
Mickey Rose 2021-07-02 15:12:19 +02:00 committed by GitHub
parent 9bad558d13
commit 4ee78eb3f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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