Skip to content

fix: handle paths with spaces in getGlobalEsbuildVersion function #7571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/frameworks/next/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ describe("Next.js utils", () => {
.withArgs("npx which esbuild", { encoding: "utf8" })
.returns(mockBinaryPath + "\n");
execSyncStub
.withArgs(`${mockBinaryPath} --version`, { encoding: "utf8" })
.withArgs(`"${mockBinaryPath}" --version`, { encoding: "utf8" })
.returns(`${mockGlobalVersion}\n`);

const consoleWarnStub = sinon.stub(console, "warn");
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/next/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import { execSync } from "child_process";
import { FirebaseError } from "../../error";

export const I18N_SOURCE = /\/:nextInternalLocale(\([^\)]+\))?/;

Check warning on line 41 in src/frameworks/next/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unnecessary escape character: \)

/**
* Remove escaping from characters used for Regex patch matching that Next.js
Expand All @@ -65,13 +65,13 @@
return path.replace(I18N_SOURCE, "");
}

export function cleanI18n<T = any>(it: T & { source: string; [key: string]: any }): T {

Check warning on line 68 in src/frameworks/next/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment

Check warning on line 68 in src/frameworks/next/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 68 in src/frameworks/next/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
const [, localesRegex] = it.source.match(I18N_SOURCE) || [undefined, undefined];

Check warning on line 69 in src/frameworks/next/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Use the `RegExp#exec()` method instead
const source = localesRegex ? cleanCustomRouteI18n(it.source) : it.source;
const destination =

Check warning on line 71 in src/frameworks/next/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
"destination" in it && localesRegex ? cleanCustomRouteI18n(it.destination) : it.destination;

Check warning on line 72 in src/frameworks/next/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `string`
const regex =

Check warning on line 73 in src/frameworks/next/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
"regex" in it && localesRegex ? it.regex.replace(`(?:/${localesRegex})`, "") : it.regex;

Check warning on line 74 in src/frameworks/next/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .replace on an `any` value

Check warning on line 74 in src/frameworks/next/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value
return {
...it,
source,
Expand Down Expand Up @@ -521,7 +521,7 @@
*/
export function getGlobalEsbuildVersion(binPath: string): string | null {
try {
const versionOutput = execSync(`${binPath} --version`, { encoding: "utf8" })?.trim();
const versionOutput = execSync(`"${binPath}" --version`, { encoding: "utf8" })?.trim();
if (!versionOutput) {
return null;
}
Expand Down
Loading