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()) {
|
for (const file of (await fs.promises.readdir(HELPERS_FOLDER)).sort()) {
|
||||||
if (IGNORED_FILES.has(file)) continue;
|
if (IGNORED_FILES.has(file)) continue;
|
||||||
|
if (file.startsWith(".")) continue; // ignore e.g. vim swap files
|
||||||
|
|
||||||
const [helperName] = file.split(".");
|
const [helperName] = file.split(".");
|
||||||
const isValidId = isValidBindingIdentifier(helperName);
|
const isValidId = isValidBindingIdentifier(helperName);
|
||||||
const varName = isValidId ? helperName : `_${helperName}`;
|
const varName = isValidId ? helperName : `_${helperName}`;
|
||||||
|
|
||||||
const fileContents = await fs.promises.readFile(
|
const filePath = join(fileURLToPath(HELPERS_FOLDER), file);
|
||||||
join(fileURLToPath(HELPERS_FOLDER), file),
|
const fileContents = await fs.promises.readFile(filePath, "utf8");
|
||||||
"utf8"
|
const minVersionMatch = fileContents.match(
|
||||||
);
|
|
||||||
const { minVersion } = fileContents.match(
|
|
||||||
/^\s*\/\*\s*@minVersion\s+(?<minVersion>\S+)\s*\*\/\s*$/m
|
/^\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
|
// TODO: We can minify the helpers in production
|
||||||
const source = fileContents
|
const source = fileContents
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user