mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-11 04:22:13 +00:00
[remix] Reinstall dependencies during prepareCache() (#10922)
https://github.com/vercel/vercel/pull/10819 introduced a bug causing the `prepareCache()` function to fail (due to `@remix-run/dev` no longer being require-able). Even if it were not failing, the deps installed are not a valid representation of the user's `package.json` / lockfile. So to have more truthful cache contents, run `npm install` once again during `prepareCache()` to fix both issues at the same time.
This commit is contained in:
5
.changeset/neat-turkeys-relate.md
Normal file
5
.changeset/neat-turkeys-relate.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@vercel/remix-builder': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Reinstall dependencies during `prepareCache()`
|
||||||
@@ -104,15 +104,17 @@ export const build: BuildV2 = async ({
|
|||||||
meta
|
meta
|
||||||
);
|
);
|
||||||
|
|
||||||
const { cliType, packageJsonPath, lockfileVersion } = await scanParentDirs(
|
const { cliType, packageJsonPath, lockfileVersion, lockfilePath } =
|
||||||
entrypointFsDirname
|
await scanParentDirs(entrypointFsDirname);
|
||||||
);
|
|
||||||
|
|
||||||
if (!packageJsonPath) {
|
if (!packageJsonPath) {
|
||||||
throw new Error('Failed to locate `package.json` file in your project');
|
throw new Error('Failed to locate `package.json` file in your project');
|
||||||
}
|
}
|
||||||
|
|
||||||
const pkgRaw = await fs.readFile(packageJsonPath, 'utf8');
|
const [lockfileRaw, pkgRaw] = await Promise.all([
|
||||||
|
lockfilePath ? fs.readFile(lockfilePath) : null,
|
||||||
|
fs.readFile(packageJsonPath, 'utf8'),
|
||||||
|
]);
|
||||||
const pkg = JSON.parse(pkgRaw);
|
const pkg = JSON.parse(pkgRaw);
|
||||||
|
|
||||||
const spawnOpts = getSpawnOptions(meta, nodeVersion);
|
const spawnOpts = getSpawnOptions(meta, nodeVersion);
|
||||||
@@ -423,9 +425,7 @@ module.exports = config;`;
|
|||||||
cleanupOps.push(
|
cleanupOps.push(
|
||||||
fs
|
fs
|
||||||
.rename(renamedRemixConfigPath, remixConfigPath)
|
.rename(renamedRemixConfigPath, remixConfigPath)
|
||||||
.then(() =>
|
.then(() => debug(`Restored original "${remixConfigPath}" file`))
|
||||||
debug(`Restored original "${basename(remixConfigPath)}" file`)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Restore original server entrypoint if it was modified (for Hydrogen v2)
|
// Restore original server entrypoint if it was modified (for Hydrogen v2)
|
||||||
@@ -433,11 +433,24 @@ module.exports = config;`;
|
|||||||
cleanupOps.push(
|
cleanupOps.push(
|
||||||
fs
|
fs
|
||||||
.writeFile(serverEntryPointAbs, originalServerEntryPoint)
|
.writeFile(serverEntryPointAbs, originalServerEntryPoint)
|
||||||
.then(() =>
|
.then(() => debug(`Restored original "${serverEntryPointAbs}" file`))
|
||||||
debug(`Restored original "${basename(serverEntryPointAbs!)}" file`)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// Restore original `package.json` file and lockfile
|
||||||
|
if (depsModified) {
|
||||||
|
cleanupOps.push(
|
||||||
|
fs
|
||||||
|
.writeFile(packageJsonPath, pkgRaw)
|
||||||
|
.then(() => debug(`Restored original "${packageJsonPath}" file`))
|
||||||
|
);
|
||||||
|
if (lockfilePath && lockfileRaw) {
|
||||||
|
cleanupOps.push(
|
||||||
|
fs
|
||||||
|
.writeFile(lockfilePath, lockfileRaw)
|
||||||
|
.then(() => debug(`Restored original "${lockfilePath}" file`))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
await Promise.all(cleanupOps);
|
await Promise.all(cleanupOps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
import { glob } from '@vercel/build-utils';
|
import {
|
||||||
|
getNodeVersion,
|
||||||
|
getSpawnOptions,
|
||||||
|
glob,
|
||||||
|
runNpmInstall,
|
||||||
|
} from '@vercel/build-utils';
|
||||||
import { dirname, join, relative } from 'path';
|
import { dirname, join, relative } from 'path';
|
||||||
import { require_, chdirAndReadConfig } from './utils';
|
import { require_, chdirAndReadConfig } from './utils';
|
||||||
import type { PrepareCache } from '@vercel/build-utils';
|
import type { PrepareCache } from '@vercel/build-utils';
|
||||||
@@ -7,10 +12,32 @@ export const prepareCache: PrepareCache = async ({
|
|||||||
entrypoint,
|
entrypoint,
|
||||||
repoRootPath,
|
repoRootPath,
|
||||||
workPath,
|
workPath,
|
||||||
|
config,
|
||||||
}) => {
|
}) => {
|
||||||
const root = repoRootPath || workPath;
|
const root = repoRootPath || workPath;
|
||||||
const mountpoint = dirname(entrypoint);
|
const mountpoint = dirname(entrypoint);
|
||||||
const entrypointFsDirname = join(workPath, mountpoint);
|
const entrypointFsDirname = join(workPath, mountpoint);
|
||||||
|
|
||||||
|
// Because the `node_modules` directory was modified to install
|
||||||
|
// the forked Remix compiler, re-install to the "fresh" dependencies
|
||||||
|
// state before the cache gets created.
|
||||||
|
const nodeVersion = await getNodeVersion(
|
||||||
|
entrypointFsDirname,
|
||||||
|
undefined,
|
||||||
|
config
|
||||||
|
);
|
||||||
|
const spawnOpts = getSpawnOptions({}, nodeVersion);
|
||||||
|
await runNpmInstall(
|
||||||
|
entrypointFsDirname,
|
||||||
|
[],
|
||||||
|
{
|
||||||
|
...spawnOpts,
|
||||||
|
stdio: 'ignore',
|
||||||
|
},
|
||||||
|
undefined,
|
||||||
|
nodeVersion
|
||||||
|
);
|
||||||
|
|
||||||
const packageJsonPath = join(entrypointFsDirname, 'package.json');
|
const packageJsonPath = join(entrypointFsDirname, 'package.json');
|
||||||
const remixRunDevPath = dirname(
|
const remixRunDevPath = dirname(
|
||||||
require_.resolve('@remix-run/dev/package.json', {
|
require_.resolve('@remix-run/dev/package.json', {
|
||||||
|
|||||||
Reference in New Issue
Block a user