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:
parent
9bad558d13
commit
4ee78eb3f1
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user