Skip to content

Commit

Permalink
fix generate-helpers failing in URL-encoded path (#13404)
Browse files Browse the repository at this point in the history
HELPERS_FOLDER.pathname may be URL-encoded, if the working tree's
absolute path contains spaces, some reserved characters, or anything
beyond ASCII.

readFile accepts a plain String or URL for the path, but does not
automatically decode URL-encoded Strings.
  • Loading branch information
lightmare committed May 31, 2021
1 parent 08772e2 commit b397aca
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/babel-helpers/scripts/generate-helpers.js
@@ -1,6 +1,6 @@
import fs from "fs";
import { join } from "path";
import { URL } from "url";
import { URL, fileURLToPath } from "url";

const HELPERS_FOLDER = new URL("../src/helpers", import.meta.url);
const IGNORED_FILES = new Set(["package.json"]);
Expand All @@ -23,7 +23,7 @@ import template from "@babel/template";
const varName = isValidId ? helperName : `_${helperName}`;

const fileContents = await fs.promises.readFile(
join(HELPERS_FOLDER.pathname, file),
join(fileURLToPath(HELPERS_FOLDER), file),
"utf8"
);
const { minVersion } = fileContents.match(
Expand Down

0 comments on commit b397aca

Please sign in to comment.