Skip to content
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

fix npm root issues on Next.js deploy #6372

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Changes from 2 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
15 changes: 13 additions & 2 deletions src/frameworks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@

// Use "true &&"" to keep typescript from compiling this file and rewriting
// the import statement into a require
const { dynamicImport } = require(true && "../dynamicImport");

Check warning on line 25 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value

Check warning on line 25 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Require statement not part of import statement

const NPM_ROOT_TIMEOUT_MILLIES = 2_000;
const NPM_ROOT_TIMEOUT_MILLIES = 5_000;
const NPM_ROOT_MEMO = new Map<string, string>();

/**
* Whether the given string starts with http:// or https://
Expand All @@ -36,7 +37,7 @@
/**
* add type to readJSON
*/
export function readJSON<JsonType = any>(

Check warning on line 40 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected any. Specify a different type
file: string,
options?: ReadOptions | BufferEncoding | string
): Promise<JsonType> {
Expand All @@ -53,10 +54,10 @@
defaultBuildScripts: string[]
): Promise<void> {
const packageJsonBuffer = await readFile(join(dir, "package.json"));
const packageJson = JSON.parse(packageJsonBuffer.toString());

Check warning on line 57 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value
const buildScript = packageJson.scripts?.build;

Check warning on line 58 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value

Check warning on line 58 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .scripts on an `any` value

if (buildScript && !defaultBuildScripts.includes(buildScript)) {

Check warning on line 60 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe argument of type `any` assigned to a parameter of type `string`
console.warn(
`\nWARNING: Your package.json contains a custom build that is being ignored. Only the ${framework} default build script (e.g, "${defaultBuildScripts[0]}") is respected. If you have a more advanced build process you should build a custom integration https://firebase.google.com/docs/hosting/express\n`
);
Expand Down Expand Up @@ -145,7 +146,7 @@
next();
} else {
for (const [fn, args] of buffer) {
(res as any)[fn](...args);

Check warning on line 149 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access [fn] on an `any` value

Check warning on line 149 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe call of an `any` typed value

Check warning on line 149 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected any. Specify a different type
}
res.end(...args);
buffer.length = 0;
Expand Down Expand Up @@ -222,9 +223,19 @@
}

export function getNpmRoot(cwd: string) {
return spawnSync("npm", ["root"], { cwd, timeout: NPM_ROOT_TIMEOUT_MILLIES })
let npmRoot = NPM_ROOT_MEMO.get(cwd);
if (npmRoot) return npmRoot;

npmRoot = spawnSync("npm", ["root"], {
cwd,
timeout: NPM_ROOT_TIMEOUT_MILLIES,
})
.stdout?.toString()
.trim();

NPM_ROOT_MEMO.set(cwd, npmRoot);

return npmRoot;
}

export function getNodeModuleBin(name: string, cwd: string) {
Expand Down
Loading