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