From 4ee78eb3f194d6015af145060d9b61794d1ea477 Mon Sep 17 00:00:00 2001 From: Mickey Rose Date: Fri, 2 Jul 2021 15:12:19 +0200 Subject: [PATCH] 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 --- .../babel-helpers/scripts/generate-helpers.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/babel-helpers/scripts/generate-helpers.js b/packages/babel-helpers/scripts/generate-helpers.js index 0552619d9b8a..cdc02f206411 100644 --- a/packages/babel-helpers/scripts/generate-helpers.js +++ b/packages/babel-helpers/scripts/generate-helpers.js @@ -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+(?\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