* * @param {object} param0 * @param {import('@next/telemetry').Span} param0.parentSpan * @param {object} [param0.dependencies] * @param {object | null} [param0.resolutions] * @param { ((ctx: { dependencies: { [key: string]: string } }) => string) | string | null} [param0.installCommand] * @par
({
parentSpan,
dependencies = {},
resolutions = null,
installCommand = null,
packageJson = {},
subDir = '',
keepRepoDir = false,
beforeInstall,
})
| 46 | * @returns {Promise<{installDir: string, pkgPaths: Map<string, string>, tmpRepoDir: string | undefined}>} |
| 47 | */ |
| 48 | async function createNextInstall({ |
| 49 | parentSpan, |
| 50 | dependencies = {}, |
| 51 | resolutions = null, |
| 52 | installCommand = null, |
| 53 | packageJson = {}, |
| 54 | subDir = '', |
| 55 | keepRepoDir = false, |
| 56 | beforeInstall, |
| 57 | }) { |
| 58 | const tmpDir = await fs.realpath(process.env.NEXT_TEST_DIR || os.tmpdir()) |
| 59 | |
| 60 | return await parentSpan |
| 61 | .traceChild('createNextInstall') |
| 62 | .traceAsyncFn(async (rootSpan) => { |
| 63 | const origRepoDir = path.join(__dirname, '../../') |
| 64 | const installDir = path.join( |
| 65 | tmpDir, |
| 66 | `next-install-${randomBytes(32).toString('hex')}`, |
| 67 | subDir |
| 68 | ) |
| 69 | let tmpRepoDir |
| 70 | require('console').log('Creating next instance in:') |
| 71 | require('console').log(installDir) |
| 72 | |
| 73 | const pkgPathsEnv = process.env.NEXT_TEST_PKG_PATHS |
| 74 | let pkgPaths |
| 75 | |
| 76 | if (pkgPathsEnv) { |
| 77 | pkgPaths = new Map(JSON.parse(pkgPathsEnv)) |
| 78 | require('console').log('using provided pkg paths') |
| 79 | } else { |
| 80 | tmpRepoDir = path.join( |
| 81 | tmpDir, |
| 82 | `next-repo-${randomBytes(32).toString('hex')}`, |
| 83 | subDir |
| 84 | ) |
| 85 | require('console').log('Creating temp repo dir', tmpRepoDir) |
| 86 | |
| 87 | for (const item of [ |
| 88 | 'package.json', |
| 89 | 'packages', |
| 90 | // Otherwise pnpm will not recognize workspaces |
| 91 | 'pnpm-workspace.yaml', |
| 92 | ]) { |
| 93 | await rootSpan |
| 94 | .traceChild(`copy ${item} to temp dir`) |
| 95 | .traceAsyncFn(() => |
| 96 | fs.copy( |
| 97 | path.join(origRepoDir, item), |
| 98 | path.join(tmpRepoDir, item), |
| 99 | { |
| 100 | filter: (item) => { |
| 101 | return ( |
| 102 | !item.includes('node_modules') && |
| 103 | !item.includes('pnpm-lock.yaml') && |
| 104 | !item.includes('.DS_Store') && |
| 105 | // Exclude Rust compilation files |
no test coverage detected