Compare commits

...

12 Commits

Author SHA1 Message Date
Chris Barber
b325ff79f9 Merge branch 'main' into chrisbarber/debug-normalize-test 2022-09-20 14:12:23 -05:00
Chris Barber
65531307f7 Added a timeout 2022-09-20 14:01:11 -05:00
Chris Barber
a07798f9f9 Disable getSpawnOption tests on windows 2022-09-20 13:29:04 -05:00
Chris Barber
fe6cc437b1 Restored getSpawnOptions and locked next to latest 2022-09-20 13:07:00 -05:00
Chris Barber
8c51431bcc Renabled node path, bypass getSpawnOptions 2022-09-20 10:15:19 -05:00
Chris Barber
2ee1880796 Disabling path scrubbing, forcing normalize test only 2022-09-20 09:57:46 -05:00
Chris Barber
9cb5c3274f Debugging build 2022-09-20 01:33:03 -05:00
Chris Barber
95c03d655c Testing vercel-build 2022-09-20 01:04:52 -05:00
Chris Barber
9d1bdb370e more debug logging 2022-09-20 00:21:09 -05:00
Chris Barber
c34a6af8cf more debug 2022-09-19 23:01:58 -05:00
Chris Barber
65cb097131 more debug 2022-09-19 22:38:05 -05:00
Chris Barber
a5e242a1a5 debug 2022-09-19 16:54:57 -05:00
4 changed files with 151 additions and 108 deletions

View File

@@ -184,6 +184,7 @@ export async function getNodeBinPath({
cwd: string;
}): Promise<string> {
const { lockfilePath } = await scanParentDirs(cwd);
console.log({ cwd, lockfilePath });
const dir = path.dirname(lockfilePath || cwd);
return path.join(dir, 'node_modules', '.bin');
}
@@ -221,7 +222,7 @@ export function getSpawnOptions(
env: cloneEnv(process.env),
};
if (!meta.isDev) {
if (!meta.isDev && process.platform !== 'win32') {
let found = false;
const oldPath = opts.env.PATH || process.env.PATH || '';
@@ -430,6 +431,9 @@ export async function runNpmInstall(
destPath
);
console.log('!'.repeat(100));
console.log({ destPath });
// Only allow `runNpmInstall()` to run once per `package.json`
// when doing a default install (no additional args)
if (meta && packageJsonPath && args.length === 0) {
@@ -548,6 +552,8 @@ export function getEnvForPackageManager({
}
}
console.log('getEnvForPackageManager()', newEnv);
return newEnv;
}
@@ -598,6 +604,16 @@ export async function runPackageJsonScript(
debug('Running user script...');
const runScriptTime = Date.now();
console.log('runPackageJsonScript()');
console.log({
destPath,
scriptNames,
packageJson,
cliType,
lockfileVersion,
scriptName,
});
const opts: SpawnOptionsExtended = {
cwd: destPath,
...spawnOpts,
@@ -618,6 +634,8 @@ export async function runPackageJsonScript(
}
console.log(`Running "${opts.prettyCommand}"`);
console.log(opts);
await new Promise<void>(resolve => setTimeout(() => resolve(), 3000));
await spawnAsync(cliType, ['run', scriptName], opts);
debug(`Script complete [${Date.now() - runScriptTime}ms]`);

View File

@@ -1,111 +1,114 @@
import { delimiter } from 'path';
import { getSpawnOptions } from '../src';
describe('Test `getSpawnOptions()`', () => {
const origProcessEnvPath = process.env.PATH;
(process.platform === 'win32' ? describe.skip : describe)(
'Test `getSpawnOptions()`',
() => {
const origProcessEnvPath = process.env.PATH;
beforeEach(() => {
process.env.PATH = undefined;
});
afterEach(() => {
process.env.PATH = origProcessEnvPath;
});
const cases: Array<{
name: string;
args: Parameters<typeof getSpawnOptions>;
envPath: string | undefined;
want: string | undefined;
}> = [
{
name: 'should do nothing when isDev and node14',
args: [
{ isDev: true },
{ major: 14, range: '14.x', runtime: 'nodejs14.x' },
],
envPath: '/foo',
want: '/foo',
},
{
name: 'should do nothing when isDev and node16',
args: [
{ isDev: true },
{ major: 16, range: '16.x', runtime: 'nodejs16.x' },
],
envPath: '/foo',
want: '/foo',
},
{
name: 'should replace 14 with 16 when only path',
args: [
{ isDev: false },
{ major: 16, range: '16.x', runtime: 'nodejs16.x' },
],
envPath: '/node14/bin',
want: '/node16/bin',
},
{
name: 'should replace 14 with 16 at beginning',
args: [
{ isDev: false },
{ major: 16, range: '16.x', runtime: 'nodejs16.x' },
],
envPath: `/node14/bin${delimiter}/foo`,
want: `/node16/bin${delimiter}/foo`,
},
{
name: 'should replace 14 with 16 at end',
args: [
{ isDev: false },
{ major: 16, range: '16.x', runtime: 'nodejs16.x' },
],
envPath: `/foo${delimiter}/node14/bin`,
want: `/foo${delimiter}/node16/bin`,
},
{
name: 'should replace 14 with 16 in middle',
args: [
{ isDev: false },
{ major: 16, range: '16.x', runtime: 'nodejs16.x' },
],
envPath: `/foo${delimiter}/node14/bin${delimiter}/bar`,
want: `/foo${delimiter}/node16/bin${delimiter}/bar`,
},
{
name: 'should prepend 16 at beginning when nothing to replace',
args: [
{ isDev: false },
{ major: 16, range: '16.x', runtime: 'nodejs16.x' },
],
envPath: `/foo`,
want: `/node16/bin${delimiter}/foo`,
},
{
name: 'should prepend 16 at beginning no path input',
args: [
{ isDev: false },
{ major: 16, range: '16.x', runtime: 'nodejs16.x' },
],
envPath: '',
want: `/node16/bin`,
},
{
name: 'should replace 12 with 14 when only path',
args: [
{ isDev: false },
{ major: 14, range: '14.x', runtime: 'nodejs14.x' },
],
envPath: '/node12/bin',
want: '/node14/bin',
},
];
for (const { name, args, envPath, want } of cases) {
it(name, () => {
process.env.PATH = envPath;
const opts = getSpawnOptions(...args);
expect(opts.env?.PATH).toBe(want);
beforeEach(() => {
process.env.PATH = undefined;
});
afterEach(() => {
process.env.PATH = origProcessEnvPath;
});
const cases: Array<{
name: string;
args: Parameters<typeof getSpawnOptions>;
envPath: string | undefined;
want: string | undefined;
}> = [
{
name: 'should do nothing when isDev and node14',
args: [
{ isDev: true },
{ major: 14, range: '14.x', runtime: 'nodejs14.x' },
],
envPath: '/foo',
want: '/foo',
},
{
name: 'should do nothing when isDev and node16',
args: [
{ isDev: true },
{ major: 16, range: '16.x', runtime: 'nodejs16.x' },
],
envPath: '/foo',
want: '/foo',
},
{
name: 'should replace 14 with 16 when only path',
args: [
{ isDev: false },
{ major: 16, range: '16.x', runtime: 'nodejs16.x' },
],
envPath: '/node14/bin',
want: '/node16/bin',
},
{
name: 'should replace 14 with 16 at beginning',
args: [
{ isDev: false },
{ major: 16, range: '16.x', runtime: 'nodejs16.x' },
],
envPath: `/node14/bin${delimiter}/foo`,
want: `/node16/bin${delimiter}/foo`,
},
{
name: 'should replace 14 with 16 at end',
args: [
{ isDev: false },
{ major: 16, range: '16.x', runtime: 'nodejs16.x' },
],
envPath: `/foo${delimiter}/node14/bin`,
want: `/foo${delimiter}/node16/bin`,
},
{
name: 'should replace 14 with 16 in middle',
args: [
{ isDev: false },
{ major: 16, range: '16.x', runtime: 'nodejs16.x' },
],
envPath: `/foo${delimiter}/node14/bin${delimiter}/bar`,
want: `/foo${delimiter}/node16/bin${delimiter}/bar`,
},
{
name: 'should prepend 16 at beginning when nothing to replace',
args: [
{ isDev: false },
{ major: 16, range: '16.x', runtime: 'nodejs16.x' },
],
envPath: `/foo`,
want: `/node16/bin${delimiter}/foo`,
},
{
name: 'should prepend 16 at beginning no path input',
args: [
{ isDev: false },
{ major: 16, range: '16.x', runtime: 'nodejs16.x' },
],
envPath: '',
want: `/node16/bin`,
},
{
name: 'should replace 12 with 14 when only path',
args: [
{ isDev: false },
{ major: 14, range: '14.x', runtime: 'nodejs14.x' },
],
envPath: '/node12/bin',
want: '/node14/bin',
},
];
for (const { name, args, envPath, want } of cases) {
it(name, () => {
process.env.PATH = envPath;
const opts = getSpawnOptions(...args);
expect(opts.env?.PATH).toBe(want);
});
}
}
});
);

View File

@@ -8,7 +8,8 @@
"build": "node build.js",
"build-dev": "node build.js --dev",
"test": "jest --env node --verbose --bail --runInBand",
"test-unit": "yarn test test/unit/",
"test-unit": "yarn test test/unit/fixtures/01-normalize-routes",
"test-unit2": "yarn test test/unit/",
"test-next-local": "jest --env node --verbose --bail --forceExit --testTimeout=360000 test/integration/*.test.js test/integration/*.test.ts",
"test-next-local:middleware": "jest --env node --verbose --bail --useStderr --testTimeout=360000 test/integration/middleware.test.ts",
"test-integration-once": "rm test/builder-info.json; jest --env node --verbose --runInBand --bail test/fixtures/**/*.test.js"

View File

@@ -36,7 +36,7 @@ import { Sema } from 'async-sema';
// escape-string-regexp version must match Next.js version
import escapeStringRegexp from 'escape-string-regexp';
import findUp from 'find-up';
import {
import fs, {
lstat,
pathExists,
readFile,
@@ -335,6 +335,21 @@ export const build: BuildV2 = async ({
}
} else {
await runNpmInstall(entryPath, [], spawnOpts, meta, nodeVersion);
console.log('npm install finished');
try {
console.log(fs.readdirSync(path.join(entryPath, 'node_modules')));
} catch (e) {
console.log(
`Failed to read dir: ${path.join(entryPath, 'node_modules')}`
);
}
try {
console.log(fs.readdirSync(path.join(entryPath, 'node_modules', '.bin')));
} catch (e) {
console.log(
`Failed to read dir: ${path.join(entryPath, 'node_modules', '.bin')}`
);
}
}
// Refetch Next version now that dependencies are installed.
@@ -424,8 +439,12 @@ export const build: BuildV2 = async ({
env.NODE_ENV = 'production';
}
console.log('?'.repeat(100));
console.log({ buildCommand, buildScriptName, entryPath });
if (buildCommand) {
// Add `node_modules/.bin` to PATH
const nodeBinPath = await getNodeBinPath({ cwd: entryPath });
env.PATH = `${nodeBinPath}${path.delimiter}${env.PATH}`;
@@ -434,6 +453,8 @@ export const build: BuildV2 = async ({
env.YARN_NODE_LINKER = 'node-modules';
}
console.log({ nodeBinPath });
debug(
`Added "${nodeBinPath}" to PATH env because a build command was used.`
);