From 4b55a6d8437c95bc251d9490011e1d9bc6ea2557 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 28 Dec 2022 04:34:03 +0200 Subject: [PATCH 01/10] fix: print a better error message on prepare pkg failure close #5845 --- cli/default-reporter/src/reportError.ts | 19 +++++++++++++++++++ exec/prepare-package/src/index.ts | 4 +++- fetching/git-fetcher/src/index.ts | 7 ++++++- .../src/gitHostedTarballFetcher.ts | 8 ++++++-- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/cli/default-reporter/src/reportError.ts b/cli/default-reporter/src/reportError.ts index b2de04208be..5791bac3a97 100644 --- a/cli/default-reporter/src/reportError.ts +++ b/cli/default-reporter/src/reportError.ts @@ -20,6 +20,9 @@ const colorPath = chalk.gray export function reportError (logObj: Log, config?: Config) { const errorInfo = getErrorInfo(logObj, config) let output = formatErrorSummary(errorInfo.title, logObj['err']['code']) + if (errorInfo.prepend) { + output = `${errorInfo.prepend}\n${output}` + } if (logObj['pkgsStack'] != null) { if (logObj['pkgsStack'].length > 0) { output += `\n\n${formatPkgsStack(logObj['pkgsStack'])}` @@ -36,6 +39,7 @@ export function reportError (logObj: Log, config?: Config) { function getErrorInfo (logObj: Log, config?: Config): { title: string body?: string + prepend?: string } { if (logObj['err']) { const err = logObj['err'] as (PnpmError & { stack: object }) @@ -69,6 +73,8 @@ function getErrorInfo (logObj: Log, config?: Config): { case 'ERR_PNPM_FETCH_401': case 'ERR_PNPM_FETCH_403': return reportAuthError(err, logObj as any, config) // eslint-disable-line @typescript-eslint/no-explicit-any + case 'ERR_PNPM_PREPARE_PACKAGE': + return reportPreparePackage(err, logObj as any) // eslint-disable-line @typescript-eslint/no-explicit-any default: { // Errors with unknown error codes are printed with stack trace if (!err.code?.startsWith?.('ERR_PNPM_')) { @@ -386,6 +392,19 @@ ${foundSettings.join('\n')}` } } +function reportPreparePackage ( + err: Error, + msg: { + stderr: string + stdout: string + }, +) { + return { + title: err.message, + prepend: `STDOUT:\n${msg.stdout}\nSTDERR:\n${msg.stderr}`, + } +} + function hideSecureInfo (key: string, value: string) { if (key.endsWith('_password')) return '[hidden]' if (key.endsWith('_auth') || key.endsWith('_authToken')) return `${value.substring(0, 4)}[hidden]` diff --git a/exec/prepare-package/src/index.ts b/exec/prepare-package/src/index.ts index 26fbdd356bf..c460ca00773 100644 --- a/exec/prepare-package/src/index.ts +++ b/exec/prepare-package/src/index.ts @@ -32,7 +32,9 @@ export async function preparePackage (opts: { rawConfig: object }, pkgDir: strin await execa(pm, ['run', scriptName], execOpts) } } catch (err: any) { // eslint-disable-line - throw new PnpmError('PREPARE_PKG_FAILURE', err.shortMessage ?? err.message) + err.code = 'ERR_PNPM_PREPARE_PACKAGE' + err.message = err.shortMessage + throw err } await rimraf(path.join(pkgDir, 'node_modules')) } diff --git a/fetching/git-fetcher/src/index.ts b/fetching/git-fetcher/src/index.ts index 07f79f916c7..220d8c74c59 100644 --- a/fetching/git-fetcher/src/index.ts +++ b/fetching/git-fetcher/src/index.ts @@ -19,7 +19,12 @@ export function createGitFetcher (createOpts: { gitShallowHosts?: string[], rawC await execGit(['clone', resolution.repo, tempLocation]) } await execGit(['checkout', resolution.commit], { cwd: tempLocation }) - await preparePkg(tempLocation) + try { + await preparePkg(tempLocation) + } catch (err: any) { // eslint-disable-line + err.message = `Failed to prepare git-hosted package fetched from "${resolution.repo}": ${err.message}` + throw err + } // removing /.git to make directory integrity calculation faster await rimraf(path.join(tempLocation, '.git')) const filesIndex = await cafs.addFilesFromDir(tempLocation, opts.manifest) diff --git a/fetching/tarball-fetcher/src/gitHostedTarballFetcher.ts b/fetching/tarball-fetcher/src/gitHostedTarballFetcher.ts index ff6ed46a5d8..b08cf076b54 100644 --- a/fetching/tarball-fetcher/src/gitHostedTarballFetcher.ts +++ b/fetching/tarball-fetcher/src/gitHostedTarballFetcher.ts @@ -13,8 +13,12 @@ interface Resolution { export function createGitHostedTarballFetcher (fetchRemoteTarball: FetchFunction, rawConfig: object): FetchFunction { const fetch = async (cafs: Cafs, resolution: Resolution, opts: FetchOptions) => { const { filesIndex } = await fetchRemoteTarball(cafs, resolution, opts) - - return { filesIndex: await prepareGitHostedPkg(filesIndex as FilesIndex, cafs, rawConfig) } + try { + return { filesIndex: await prepareGitHostedPkg(filesIndex as FilesIndex, cafs, rawConfig) } + } catch (err: any) { // eslint-disable-line + err.message = `Failed to prepare git-hosted package fetched from "${resolution.tarball}": ${err.message}` + throw err + } } return fetch as FetchFunction From 7ce4aff3a73e4293301256d5083635a5bad1ab01 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 28 Dec 2022 04:52:00 +0200 Subject: [PATCH 02/10] style: fix --- cli/default-reporter/src/reportError.ts | 2 +- exec/prepare-package/package.json | 1 - exec/prepare-package/src/index.ts | 1 - exec/prepare-package/tsconfig.json | 3 --- fetching/git-fetcher/src/index.ts | 2 +- fetching/tarball-fetcher/src/gitHostedTarballFetcher.ts | 2 +- pnpm-lock.yaml | 3 --- 7 files changed, 3 insertions(+), 11 deletions(-) diff --git a/cli/default-reporter/src/reportError.ts b/cli/default-reporter/src/reportError.ts index 5791bac3a97..36919bc00ad 100644 --- a/cli/default-reporter/src/reportError.ts +++ b/cli/default-reporter/src/reportError.ts @@ -397,7 +397,7 @@ function reportPreparePackage ( msg: { stderr: string stdout: string - }, + } ) { return { title: err.message, diff --git a/exec/prepare-package/package.json b/exec/prepare-package/package.json index f10f68cba19..69bbdd445a4 100644 --- a/exec/prepare-package/package.json +++ b/exec/prepare-package/package.json @@ -29,7 +29,6 @@ }, "homepage": "https://github.com/pnpm/pnpm/blob/main/exec/prepare-package#readme", "dependencies": { - "@pnpm/error": "workspace:*", "@pnpm/npm-lifecycle": "^2.0.0", "@pnpm/read-package-json": "workspace:*", "@zkochan/rimraf": "^2.1.2", diff --git a/exec/prepare-package/src/index.ts b/exec/prepare-package/src/index.ts index c460ca00773..027272458e5 100644 --- a/exec/prepare-package/src/index.ts +++ b/exec/prepare-package/src/index.ts @@ -1,5 +1,4 @@ import path from 'path' -import { PnpmError } from '@pnpm/error' import lifecycle from '@pnpm/npm-lifecycle' import { safeReadPackageJsonFromDir } from '@pnpm/read-package-json' import { PackageScripts } from '@pnpm/types' diff --git a/exec/prepare-package/tsconfig.json b/exec/prepare-package/tsconfig.json index 359055070d7..38adfe8b5ff 100644 --- a/exec/prepare-package/tsconfig.json +++ b/exec/prepare-package/tsconfig.json @@ -15,9 +15,6 @@ { "path": "../../__utils__/test-fixtures" }, - { - "path": "../../packages/error" - }, { "path": "../../packages/types" }, diff --git a/fetching/git-fetcher/src/index.ts b/fetching/git-fetcher/src/index.ts index 220d8c74c59..a86eaeb0b42 100644 --- a/fetching/git-fetcher/src/index.ts +++ b/fetching/git-fetcher/src/index.ts @@ -22,7 +22,7 @@ export function createGitFetcher (createOpts: { gitShallowHosts?: string[], rawC try { await preparePkg(tempLocation) } catch (err: any) { // eslint-disable-line - err.message = `Failed to prepare git-hosted package fetched from "${resolution.repo}": ${err.message}` + err.message = `Failed to prepare git-hosted package fetched from "${resolution.repo}": ${err.message}` // eslint-disable-line throw err } // removing /.git to make directory integrity calculation faster diff --git a/fetching/tarball-fetcher/src/gitHostedTarballFetcher.ts b/fetching/tarball-fetcher/src/gitHostedTarballFetcher.ts index b08cf076b54..27182afcd61 100644 --- a/fetching/tarball-fetcher/src/gitHostedTarballFetcher.ts +++ b/fetching/tarball-fetcher/src/gitHostedTarballFetcher.ts @@ -16,7 +16,7 @@ export function createGitHostedTarballFetcher (fetchRemoteTarball: FetchFunction try { return { filesIndex: await prepareGitHostedPkg(filesIndex as FilesIndex, cafs, rawConfig) } } catch (err: any) { // eslint-disable-line - err.message = `Failed to prepare git-hosted package fetched from "${resolution.tarball}": ${err.message}` + err.message = `Failed to prepare git-hosted package fetched from "${resolution.tarball}": ${err.message}` // eslint-disable-line throw err } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f71fde1c995..e4850c63400 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1224,9 +1224,6 @@ importers: exec/prepare-package: dependencies: - '@pnpm/error': - specifier: workspace:* - version: link:../../packages/error '@pnpm/npm-lifecycle': specifier: ^2.0.0 version: 2.0.0_typanion@3.12.1 From abfd5025d09c7a5224e1007f50d4b5f7779eb6a9 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 31 Dec 2022 04:55:23 +0200 Subject: [PATCH 03/10] test: prepare package error --- cli/default-reporter/test/reportingErrors.ts | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cli/default-reporter/test/reportingErrors.ts b/cli/default-reporter/test/reportingErrors.ts index 4e4783178b3..e3460a79123 100644 --- a/cli/default-reporter/test/reportingErrors.ts +++ b/cli/default-reporter/test/reportingErrors.ts @@ -541,3 +541,29 @@ ${ERROR_PAD}or add the auth tokens manually to the ~/.npmrc file.`) }, }) }) + +test('prints error about git-hosted package preparation', (done) => { + const output$ = toOutput$({ + context: { argv: ['install'], config: { rawConfig: {} } as any }, // eslint-disable-line + streamParser: createStreamParser(), + }) + + const err = new PnpmError('PREPARE_PACKAGE', 'Failed to prepare git-hosted package fetched from "https://codeload.github.com/ethereumjs/ethereumjs-abi/tar.gz/ee3994657fa7a427238e6ba92a84d0b529bbcde0": Command failed with exit code 1: npm install') + err['stdout'] = 'stdout' + err['stderr'] = 'stderr' + logger.error(err, err) + + expect.assertions(1) + + output$.pipe(take(1), map(normalizeNewline)).subscribe({ + complete: () => done(), + error: done, + next: output => { + expect(output).toBe(`STDOUT: +stdout +STDERR: +stderr +${formatError('ERR_PNPM_PREPARE_PACKAGE', 'Failed to prepare git-hosted package fetched from "https://codeload.github.com/ethereumjs/ethereumjs-abi/tar.gz/ee3994657fa7a427238e6ba92a84d0b529bbcde0": Command failed with exit code 1: npm install')}`) + }, + }) +}) From e628d302ff48c9fb0505cc584c2918ed80a49916 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sun, 1 Jan 2023 04:33:00 +0200 Subject: [PATCH 04/10] refactor: show output of githosted pkg build --- cli/default-reporter/src/reportError.ts | 1 + exec/prepare-package/package.json | 1 + exec/prepare-package/src/index.ts | 23 +++++++++++++++-------- exec/prepare-package/tsconfig.json | 3 +++ pnpm-lock.yaml | 3 +++ 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/cli/default-reporter/src/reportError.ts b/cli/default-reporter/src/reportError.ts index 36919bc00ad..e13503f5ffb 100644 --- a/cli/default-reporter/src/reportError.ts +++ b/cli/default-reporter/src/reportError.ts @@ -399,6 +399,7 @@ function reportPreparePackage ( stdout: string } ) { + // maybe prefix it? return { title: err.message, prepend: `STDOUT:\n${msg.stdout}\nSTDERR:\n${msg.stderr}`, diff --git a/exec/prepare-package/package.json b/exec/prepare-package/package.json index 69bbdd445a4..b07a5ce822c 100644 --- a/exec/prepare-package/package.json +++ b/exec/prepare-package/package.json @@ -29,6 +29,7 @@ }, "homepage": "https://github.com/pnpm/pnpm/blob/main/exec/prepare-package#readme", "dependencies": { + "@pnpm/lifecycle": "workspace:*", "@pnpm/npm-lifecycle": "^2.0.0", "@pnpm/read-package-json": "workspace:*", "@zkochan/rimraf": "^2.1.2", diff --git a/exec/prepare-package/src/index.ts b/exec/prepare-package/src/index.ts index 027272458e5..8ef9117a644 100644 --- a/exec/prepare-package/src/index.ts +++ b/exec/prepare-package/src/index.ts @@ -1,9 +1,8 @@ import path from 'path' -import lifecycle from '@pnpm/npm-lifecycle' +import { runLifecycleHook, RunLifecycleHookOptions } from '@pnpm/lifecycle' import { safeReadPackageJsonFromDir } from '@pnpm/read-package-json' import { PackageScripts } from '@pnpm/types' import rimraf from '@zkochan/rimraf' -import execa from 'execa' import preferredPM from 'preferred-pm' import omit from 'ramda/src/omit' @@ -21,18 +20,26 @@ export async function preparePackage (opts: { rawConfig: object }, pkgDir: strin const pm = (await preferredPM(pkgDir))?.name ?? 'npm' // We can't prepare a package without running its lifecycle scripts. // An alternative solution could be to throw an exception. - const config = omit(['ignore-scripts'], opts.rawConfig) - const env = lifecycle.makeEnv(manifest, { config }) - const execOpts = { cwd: pkgDir, env, extendEnv: true } + // const env = lifecycle.makeEnv(manifest, { config }) + const execOpts: RunLifecycleHookOptions = { + depPath: `${manifest.name}@${manifest.version}`, + pkgRoot: pkgDir, + rawConfig: omit(['ignore-scripts'], opts.rawConfig), + rootModulesDir: pkgDir, // We don't need this property but there is currently no way to not set it. + unsafePerm: false, + } try { - await execa(pm, ['install'], execOpts) + manifest.scripts['install'] = `${pm} install` + await runLifecycleHook('install', manifest, execOpts) + // await execa(pm, ['install'], execOpts) for (const scriptName of PREPUBLISH_SCRIPTS) { if (manifest.scripts[scriptName] == null || manifest.scripts[scriptName] === '') continue - await execa(pm, ['run', scriptName], execOpts) + // await execa(pm, ['run', scriptName], execOpts) + await runLifecycleHook(scriptName, manifest, execOpts) } } catch (err: any) { // eslint-disable-line err.code = 'ERR_PNPM_PREPARE_PACKAGE' - err.message = err.shortMessage + // err.message = err.shortMessage throw err } await rimraf(path.join(pkgDir, 'node_modules')) diff --git a/exec/prepare-package/tsconfig.json b/exec/prepare-package/tsconfig.json index 38adfe8b5ff..ccc2d013cc1 100644 --- a/exec/prepare-package/tsconfig.json +++ b/exec/prepare-package/tsconfig.json @@ -20,6 +20,9 @@ }, { "path": "../../pkg-manifest/read-package-json" + }, + { + "path": "../lifecycle" } ] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e4850c63400..ecb173919db 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1224,6 +1224,9 @@ importers: exec/prepare-package: dependencies: + '@pnpm/lifecycle': + specifier: workspace:* + version: link:../lifecycle '@pnpm/npm-lifecycle': specifier: ^2.0.0 version: 2.0.0_typanion@3.12.1 From d088a6eb7d70e77833fbec261de3d7a9b2d0a4a6 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sun, 1 Jan 2023 17:27:31 +0200 Subject: [PATCH 05/10] refactor: show output of githosted pkg build --- cli/default-reporter/src/reportError.ts | 20 ----- .../reportLifecycleScripts.ts | 11 ++- exec/prepare-package/package.json | 1 - exec/prepare-package/src/index.ts | 13 ++-- pnpm-lock.yaml | 76 ++++++++++++++----- 5 files changed, 70 insertions(+), 51 deletions(-) diff --git a/cli/default-reporter/src/reportError.ts b/cli/default-reporter/src/reportError.ts index e13503f5ffb..b2de04208be 100644 --- a/cli/default-reporter/src/reportError.ts +++ b/cli/default-reporter/src/reportError.ts @@ -20,9 +20,6 @@ const colorPath = chalk.gray export function reportError (logObj: Log, config?: Config) { const errorInfo = getErrorInfo(logObj, config) let output = formatErrorSummary(errorInfo.title, logObj['err']['code']) - if (errorInfo.prepend) { - output = `${errorInfo.prepend}\n${output}` - } if (logObj['pkgsStack'] != null) { if (logObj['pkgsStack'].length > 0) { output += `\n\n${formatPkgsStack(logObj['pkgsStack'])}` @@ -39,7 +36,6 @@ export function reportError (logObj: Log, config?: Config) { function getErrorInfo (logObj: Log, config?: Config): { title: string body?: string - prepend?: string } { if (logObj['err']) { const err = logObj['err'] as (PnpmError & { stack: object }) @@ -73,8 +69,6 @@ function getErrorInfo (logObj: Log, config?: Config): { case 'ERR_PNPM_FETCH_401': case 'ERR_PNPM_FETCH_403': return reportAuthError(err, logObj as any, config) // eslint-disable-line @typescript-eslint/no-explicit-any - case 'ERR_PNPM_PREPARE_PACKAGE': - return reportPreparePackage(err, logObj as any) // eslint-disable-line @typescript-eslint/no-explicit-any default: { // Errors with unknown error codes are printed with stack trace if (!err.code?.startsWith?.('ERR_PNPM_')) { @@ -392,20 +386,6 @@ ${foundSettings.join('\n')}` } } -function reportPreparePackage ( - err: Error, - msg: { - stderr: string - stdout: string - } -) { - // maybe prefix it? - return { - title: err.message, - prepend: `STDOUT:\n${msg.stdout}\nSTDERR:\n${msg.stderr}`, - } -} - function hideSecureInfo (key: string, value: string) { if (key.endsWith('_password')) return '[hidden]' if (key.endsWith('_auth') || key.endsWith('_authToken')) return `${value.substring(0, 4)}[hidden]` diff --git a/cli/default-reporter/src/reporterForClient/reportLifecycleScripts.ts b/cli/default-reporter/src/reporterForClient/reportLifecycleScripts.ts index 60396a39d04..b8e0aa3fc71 100644 --- a/cli/default-reporter/src/reporterForClient/reportLifecycleScripts.ts +++ b/cli/default-reporter/src/reporterForClient/reportLifecycleScripts.ts @@ -113,8 +113,13 @@ function renderCollapsedScriptOutput ( maxWidth: number } ) { - messageCache.label = messageCache.label ?? - `${highlightLastFolder(formatPrefixNoTrim(opts.cwd, log.wd))}: Running ${log.stage} script` + if (!messageCache.label) { + messageCache.label = `${highlightLastFolder(formatPrefixNoTrim(opts.cwd, log.wd))}` // : Running ${log.stage} script` + if (!log.wd.includes(log.depPath.replace(/\//g, '+'))) { + messageCache.label += ` [${log.depPath}]`// ${chalk.gray('>')}` + } + messageCache.label += `: Running ${log.stage} script` + } if (!opts.exit) { updateMessageCache(log, messageCache, opts) return `${messageCache.label}...` @@ -191,7 +196,7 @@ function updateMessageCache ( if (log['exitCode'] === 0) { messageCache.status = formatIndentedStatus(chalk.magentaBright(`Done in ${time}`)) } else { - messageCache.status = formatIndentedStatus(chalk.red(`Failed in ${time}`)) + messageCache.status = formatIndentedStatus(chalk.red(`Failed in ${time} at ${log.wd}`)) } } else { messageCache.output.push(formatIndentedOutput(opts.maxWidth, log)) diff --git a/exec/prepare-package/package.json b/exec/prepare-package/package.json index b07a5ce822c..32ae0acd7fc 100644 --- a/exec/prepare-package/package.json +++ b/exec/prepare-package/package.json @@ -30,7 +30,6 @@ "homepage": "https://github.com/pnpm/pnpm/blob/main/exec/prepare-package#readme", "dependencies": { "@pnpm/lifecycle": "workspace:*", - "@pnpm/npm-lifecycle": "^2.0.0", "@pnpm/read-package-json": "workspace:*", "@zkochan/rimraf": "^2.1.2", "execa": "npm:safe-execa@0.1.2", diff --git a/exec/prepare-package/src/index.ts b/exec/prepare-package/src/index.ts index 8ef9117a644..9202c05c3bf 100644 --- a/exec/prepare-package/src/index.ts +++ b/exec/prepare-package/src/index.ts @@ -18,28 +18,25 @@ export async function preparePackage (opts: { rawConfig: object }, pkgDir: strin const manifest = await safeReadPackageJsonFromDir(pkgDir) if (manifest?.scripts == null || !packageShouldBeBuilt(manifest.scripts)) return const pm = (await preferredPM(pkgDir))?.name ?? 'npm' - // We can't prepare a package without running its lifecycle scripts. - // An alternative solution could be to throw an exception. - // const env = lifecycle.makeEnv(manifest, { config }) const execOpts: RunLifecycleHookOptions = { depPath: `${manifest.name}@${manifest.version}`, pkgRoot: pkgDir, + // We can't prepare a package without running its lifecycle scripts. + // An alternative solution could be to throw an exception. rawConfig: omit(['ignore-scripts'], opts.rawConfig), rootModulesDir: pkgDir, // We don't need this property but there is currently no way to not set it. unsafePerm: false, } try { - manifest.scripts['install'] = `${pm} install` - await runLifecycleHook('install', manifest, execOpts) - // await execa(pm, ['install'], execOpts) + const installScriptName = `${pm}-install` + manifest.scripts[installScriptName] = `${pm} install` + await runLifecycleHook(installScriptName, manifest, execOpts) for (const scriptName of PREPUBLISH_SCRIPTS) { if (manifest.scripts[scriptName] == null || manifest.scripts[scriptName] === '') continue - // await execa(pm, ['run', scriptName], execOpts) await runLifecycleHook(scriptName, manifest, execOpts) } } catch (err: any) { // eslint-disable-line err.code = 'ERR_PNPM_PREPARE_PACKAGE' - // err.message = err.shortMessage throw err } await rimraf(path.join(pkgDir, 'node_modules')) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ecb173919db..31c6bf761bb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1227,9 +1227,6 @@ importers: '@pnpm/lifecycle': specifier: workspace:* version: link:../lifecycle - '@pnpm/npm-lifecycle': - specifier: ^2.0.0 - version: 2.0.0_typanion@3.12.1 '@pnpm/read-package-json': specifier: workspace:* version: link:../../pkg-manifest/read-package-json @@ -6780,7 +6777,7 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: '@jest/types': 29.3.1 - '@types/node': 14.18.36 + '@types/node': 18.11.18 chalk: 4.1.2 jest-message-util: 29.3.1 jest-util: 29.3.1 @@ -6801,14 +6798,14 @@ packages: '@jest/test-result': 29.3.1 '@jest/transform': 29.3.1_@babel+types@7.20.7 '@jest/types': 29.3.1 - '@types/node': 14.18.36 + '@types/node': 18.11.18 ansi-escapes: 4.3.2 chalk: 4.1.2 ci-info: 3.7.0 exit: 0.1.2 graceful-fs: 4.2.10 jest-changed-files: 29.2.0 - jest-config: 29.3.1_56nfvjbu5gf7nsgorbtc4ijmhq + jest-config: 29.3.1_7arhz5k5lgu27jr56nuhhcqiee jest-haste-map: 29.3.1 jest-message-util: 29.3.1 jest-regex-util: 29.2.0 @@ -6836,7 +6833,7 @@ packages: dependencies: '@jest/fake-timers': 29.3.1 '@jest/types': 29.3.1 - '@types/node': 14.18.36 + '@types/node': 18.11.18 jest-mock: 29.3.1 dev: true @@ -6863,7 +6860,7 @@ packages: dependencies: '@jest/types': 29.3.1 '@sinonjs/fake-timers': 9.1.2 - '@types/node': 14.18.36 + '@types/node': 18.11.18 jest-message-util: 29.3.1 jest-mock: 29.3.1 jest-util: 29.3.1 @@ -6896,7 +6893,7 @@ packages: '@jest/transform': 29.3.1_@babel+types@7.20.7 '@jest/types': 29.3.1 '@jridgewell/trace-mapping': 0.3.17 - '@types/node': 14.18.36 + '@types/node': 18.11.18 chalk: 4.1.2 collect-v8-coverage: 1.0.1 exit: 0.1.2 @@ -6986,7 +6983,7 @@ packages: '@jest/schemas': 29.0.0 '@types/istanbul-lib-coverage': 2.0.4 '@types/istanbul-reports': 3.0.1 - '@types/node': 14.18.36 + '@types/node': 18.11.18 '@types/yargs': 17.0.17 chalk: 4.1.2 dev: true @@ -12760,7 +12757,7 @@ packages: '@jest/expect': 29.3.1 '@jest/test-result': 29.3.1 '@jest/types': 29.3.1 - '@types/node': 14.18.36 + '@types/node': 18.11.18 chalk: 4.1.2 co: 4.6.0 dedent: 0.7.0 @@ -12850,6 +12847,47 @@ packages: - supports-color dev: true + /jest-config/29.3.1_7arhz5k5lgu27jr56nuhhcqiee: + resolution: {integrity: sha512-y0tFHdj2WnTEhxmGUK1T7fgLen7YK4RtfvpLFBXfQkh2eMJAQq24Vx9472lvn5wg0MAO6B+iPfJfzdR9hJYalg==} + engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + peerDependencies: + '@types/node': '*' + ts-node: '>=9.0.0' + peerDependenciesMeta: + '@types/node': + optional: true + ts-node: + optional: true + dependencies: + '@babel/core': 7.20.7 + '@jest/test-sequencer': 29.3.1 + '@jest/types': 29.3.1 + '@types/node': 18.11.18 + babel-jest: 29.3.1_prjhoemhtbjqo3vlbvwbf3oci4 + chalk: 4.1.2 + ci-info: 3.7.0 + deepmerge: 4.2.2 + glob: 7.2.3 + graceful-fs: 4.2.10 + jest-circus: 29.3.1_@babel+types@7.20.7 + jest-environment-node: 29.3.1 + jest-get-type: 29.2.0 + jest-regex-util: 29.2.0 + jest-resolve: 29.3.1 + jest-runner: 29.3.1_@babel+types@7.20.7 + jest-util: 29.3.1 + jest-validate: 29.3.1 + micromatch: 4.0.5 + parse-json: 5.2.0 + pretty-format: 29.3.1 + slash: 3.0.0 + strip-json-comments: 3.1.1 + ts-node: 10.9.1_xl7wyiapi7jo5c2pfz5vjm55na + transitivePeerDependencies: + - '@babel/types' + - supports-color + dev: true + /jest-diff/29.3.1: resolution: {integrity: sha512-vU8vyiO7568tmin2lA3r2DP8oRvzhvRcD4DjpXc6uGveQodyk7CKLhQlCSiwgx3g0pFaE88/KLZ0yaTWMc4Uiw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -12885,7 +12923,7 @@ packages: '@jest/environment': 29.3.1 '@jest/fake-timers': 29.3.1 '@jest/types': 29.3.1 - '@types/node': 14.18.36 + '@types/node': 18.11.18 jest-mock: 29.3.1 jest-util: 29.3.1 dev: true @@ -12901,7 +12939,7 @@ packages: dependencies: '@jest/types': 29.3.1 '@types/graceful-fs': 4.1.5 - '@types/node': 14.18.36 + '@types/node': 18.11.18 anymatch: 3.1.3 fb-watchman: 2.0.2 graceful-fs: 4.2.10 @@ -12952,7 +12990,7 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: '@jest/types': 29.3.1 - '@types/node': 14.18.36 + '@types/node': 18.11.18 jest-util: 29.3.1 dev: true @@ -13007,7 +13045,7 @@ packages: '@jest/test-result': 29.3.1 '@jest/transform': 29.3.1_@babel+types@7.20.7 '@jest/types': 29.3.1 - '@types/node': 14.18.36 + '@types/node': 18.11.18 chalk: 4.1.2 emittery: 0.13.1 graceful-fs: 4.2.10 @@ -13039,7 +13077,7 @@ packages: '@jest/test-result': 29.3.1 '@jest/transform': 29.3.1_@babel+types@7.20.7 '@jest/types': 29.3.1 - '@types/node': 14.18.36 + '@types/node': 18.11.18 chalk: 4.1.2 cjs-module-lexer: 1.2.2 collect-v8-coverage: 1.0.1 @@ -13096,7 +13134,7 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: '@jest/types': 29.3.1 - '@types/node': 14.18.36 + '@types/node': 18.11.18 chalk: 4.1.2 ci-info: 3.7.0 graceful-fs: 4.2.10 @@ -13121,7 +13159,7 @@ packages: dependencies: '@jest/test-result': 29.3.1 '@jest/types': 29.3.1 - '@types/node': 14.18.36 + '@types/node': 18.11.18 ansi-escapes: 4.3.2 chalk: 4.1.2 emittery: 0.13.1 @@ -13133,7 +13171,7 @@ packages: resolution: {integrity: sha512-lY4AnnmsEWeiXirAIA0c9SDPbuCBq8IYuDVL8PMm0MZ2PEs2yPvRA/J64QBXuZp7CYKrDM/rmNrc9/i3KJQncw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: - '@types/node': 14.18.36 + '@types/node': 18.11.18 jest-util: 29.3.1 merge-stream: 2.0.0 supports-color: 8.1.1 From ad385ba8969f03bf5d98389e4fe115899acea00e Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sun, 1 Jan 2023 20:26:47 +0200 Subject: [PATCH 06/10] test: fix --- .../reportLifecycleScripts.ts | 9 ++++--- cli/default-reporter/test/reportingErrors.ts | 26 ------------------- .../test/reportingLifecycleScripts.ts | 9 ++++--- 3 files changed, 11 insertions(+), 33 deletions(-) diff --git a/cli/default-reporter/src/reporterForClient/reportLifecycleScripts.ts b/cli/default-reporter/src/reporterForClient/reportLifecycleScripts.ts index b8e0aa3fc71..1ee342c9b2d 100644 --- a/cli/default-reporter/src/reporterForClient/reportLifecycleScripts.ts +++ b/cli/default-reporter/src/reporterForClient/reportLifecycleScripts.ts @@ -10,6 +10,7 @@ import { formatPrefix, formatPrefixNoTrim } from './utils/formatPrefix' import { hlValue } from './outputConstants' const NODE_MODULES = `${path.sep}node_modules${path.sep}` +const TMP_DIR_IN_STORE = `tmp${path.sep}_tmp_` // git-hosted dependencies are built in these temporary directories // When streaming processes are spawned, use this color for prefix const colorWheel = ['cyan', 'magenta', 'blue', 'yellow', 'green', 'red'] @@ -65,7 +66,7 @@ export function reportLifecycleScripts ( .forEach((log: LifecycleLog) => { const key = `${log.stage}:${log.depPath}` lifecycleMessages[key] = lifecycleMessages[key] || { - collapsed: log.wd.includes(NODE_MODULES), + collapsed: log.wd.includes(NODE_MODULES) || log.wd.includes(TMP_DIR_IN_STORE), output: [], startTime: process.hrtime(), status: formatIndentedStatus(chalk.magentaBright('Running...')), @@ -114,9 +115,9 @@ function renderCollapsedScriptOutput ( } ) { if (!messageCache.label) { - messageCache.label = `${highlightLastFolder(formatPrefixNoTrim(opts.cwd, log.wd))}` // : Running ${log.stage} script` - if (!log.wd.includes(log.depPath.replace(/\//g, '+'))) { - messageCache.label += ` [${log.depPath}]`// ${chalk.gray('>')}` + messageCache.label = highlightLastFolder(formatPrefixNoTrim(opts.cwd, log.wd)) + if (log.wd.includes(TMP_DIR_IN_STORE)) { + messageCache.label += ` [${log.depPath}]` } messageCache.label += `: Running ${log.stage} script` } diff --git a/cli/default-reporter/test/reportingErrors.ts b/cli/default-reporter/test/reportingErrors.ts index e3460a79123..4e4783178b3 100644 --- a/cli/default-reporter/test/reportingErrors.ts +++ b/cli/default-reporter/test/reportingErrors.ts @@ -541,29 +541,3 @@ ${ERROR_PAD}or add the auth tokens manually to the ~/.npmrc file.`) }, }) }) - -test('prints error about git-hosted package preparation', (done) => { - const output$ = toOutput$({ - context: { argv: ['install'], config: { rawConfig: {} } as any }, // eslint-disable-line - streamParser: createStreamParser(), - }) - - const err = new PnpmError('PREPARE_PACKAGE', 'Failed to prepare git-hosted package fetched from "https://codeload.github.com/ethereumjs/ethereumjs-abi/tar.gz/ee3994657fa7a427238e6ba92a84d0b529bbcde0": Command failed with exit code 1: npm install') - err['stdout'] = 'stdout' - err['stderr'] = 'stderr' - logger.error(err, err) - - expect.assertions(1) - - output$.pipe(take(1), map(normalizeNewline)).subscribe({ - complete: () => done(), - error: done, - next: output => { - expect(output).toBe(`STDOUT: -stdout -STDERR: -stderr -${formatError('ERR_PNPM_PREPARE_PACKAGE', 'Failed to prepare git-hosted package fetched from "https://codeload.github.com/ethereumjs/ethereumjs-abi/tar.gz/ee3994657fa7a427238e6ba92a84d0b529bbcde0": Command failed with exit code 1: npm install')}`) - }, - }) -}) diff --git a/cli/default-reporter/test/reportingLifecycleScripts.ts b/cli/default-reporter/test/reportingLifecycleScripts.ts index 92c9bc7ad8d..69fa9fa9217 100644 --- a/cli/default-reporter/test/reportingLifecycleScripts.ts +++ b/cli/default-reporter/test/reportingLifecycleScripts.ts @@ -17,7 +17,6 @@ const OUTPUT_INDENTATION = chalk.magentaBright('│') const STATUS_INDENTATION = chalk.magentaBright('└─') const STATUS_RUNNING = chalk.magentaBright('Running...') const STATUS_DONE = chalk.magentaBright('Done in 1s') -const STATUS_FAILED = chalk.red('Failed in 1s') const EOL = '\n' function replaceTimeWith1Sec (text: string) { @@ -734,7 +733,7 @@ test('output of failed non-optional dependency is printed', (done) => { ${chalk.gray('node_modules/.registry.npmjs.org/foo/1.0.0/node_modules/')}foo: Running install script, failed in 1s .../foo/1.0.0/node_modules/foo ${INSTALL}$ node foo ${OUTPUT_INDENTATION} foo 0 1 2 3 4 5 6 7 8 9 -${STATUS_INDENTATION} ${STATUS_FAILED}`) +${STATUS_INDENTATION} ${failedAt(wd)}`) }, }) }) @@ -780,7 +779,7 @@ test('do not fail if the debug log has no output', (done) => { ${chalk.gray('node_modules/.registry.npmjs.org/foo/1.0.0/node_modules/')}foo: Running install script, failed in 1s .../foo/1.0.0/node_modules/foo ${INSTALL}$ node foo ${OUTPUT_INDENTATION} -${STATUS_INDENTATION} ${STATUS_FAILED}`) +${STATUS_INDENTATION} ${failedAt(wd)}`) }, }) }) @@ -844,3 +843,7 @@ Running ${POSTINSTALL} for ${hlPkgId('registry.npmjs.org/bar/1.0.0')}: ${childOu }, }) }) + +function failedAt (wd: string) { + return chalk.red(`Failed in 1s at ${wd}`) +} From c86816f216607304bb7e1ed85c4de2a4544ff9d7 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sun, 1 Jan 2023 20:50:39 +0200 Subject: [PATCH 07/10] fix: unsafe-perm --- env/node.fetcher/src/index.ts | 4 +++- exec/prepare-package/src/index.ts | 9 +++++++-- fetching/git-fetcher/src/index.ts | 10 ++++++++-- .../tarball-fetcher/src/gitHostedTarballFetcher.ts | 13 +++++++++---- fetching/tarball-fetcher/src/index.ts | 3 ++- pkg-manager/client/src/index.ts | 3 ++- .../src/recursivePublish.ts | 1 + .../src/createNewStoreController.ts | 2 ++ 8 files changed, 34 insertions(+), 11 deletions(-) diff --git a/env/node.fetcher/src/index.ts b/env/node.fetcher/src/index.ts index 7fdb9673cd5..aa5e12b2520 100644 --- a/env/node.fetcher/src/index.ts +++ b/env/node.fetcher/src/index.ts @@ -34,9 +34,11 @@ export async function fetchNode (fetch: FetchFromRegistry, version: string, targ } const getAuthHeader = () => undefined const fetchers = createTarballFetcher(fetch, getAuthHeader, { - rawConfig: {}, // This is not needed for fetching Node.js retry: opts.retry, timeout: opts.fetchTimeout, + // These are not needed for fetching Node.js + rawConfig: {}, + unsafePerm: false, }) const cafs = createCafsStore(opts.cafsDir) const fetchTarball = pickFetcher(fetchers, { tarball }) diff --git a/exec/prepare-package/src/index.ts b/exec/prepare-package/src/index.ts index 9202c05c3bf..6f4444d35ca 100644 --- a/exec/prepare-package/src/index.ts +++ b/exec/prepare-package/src/index.ts @@ -14,7 +14,12 @@ const PREPUBLISH_SCRIPTS = [ 'postpublish', ] -export async function preparePackage (opts: { rawConfig: object }, pkgDir: string) { +export interface PreparePackageOptions { + rawConfig: object + unsafePerm?: boolean +} + +export async function preparePackage (opts: PreparePackageOptions, pkgDir: string) { const manifest = await safeReadPackageJsonFromDir(pkgDir) if (manifest?.scripts == null || !packageShouldBeBuilt(manifest.scripts)) return const pm = (await preferredPM(pkgDir))?.name ?? 'npm' @@ -25,7 +30,7 @@ export async function preparePackage (opts: { rawConfig: object }, pkgDir: strin // An alternative solution could be to throw an exception. rawConfig: omit(['ignore-scripts'], opts.rawConfig), rootModulesDir: pkgDir, // We don't need this property but there is currently no way to not set it. - unsafePerm: false, + unsafePerm: Boolean(opts.unsafePerm), } try { const installScriptName = `${pm}-install` diff --git a/fetching/git-fetcher/src/index.ts b/fetching/git-fetcher/src/index.ts index a86eaeb0b42..8ee4e5fb946 100644 --- a/fetching/git-fetcher/src/index.ts +++ b/fetching/git-fetcher/src/index.ts @@ -5,9 +5,15 @@ import rimraf from '@zkochan/rimraf' import execa from 'execa' import { URL } from 'url' -export function createGitFetcher (createOpts: { gitShallowHosts?: string[], rawConfig: object }) { +export interface CreateGitFetcherOptions { + gitShallowHosts?: string[] + rawConfig: object + unsafePerm?: boolean +} + +export function createGitFetcher (createOpts: CreateGitFetcherOptions) { const allowedHosts = new Set(createOpts?.gitShallowHosts ?? []) - const preparePkg = preparePackage.bind(null, { rawConfig: createOpts.rawConfig }) + const preparePkg = preparePackage.bind(null, { rawConfig: createOpts.rawConfig, unsafePerm: createOpts.unsafePerm }) const gitFetcher: GitFetcher = async (cafs, resolution, opts) => { const tempLocation = await cafs.tempDir() diff --git a/fetching/tarball-fetcher/src/gitHostedTarballFetcher.ts b/fetching/tarball-fetcher/src/gitHostedTarballFetcher.ts index 27182afcd61..bb88e18d17b 100644 --- a/fetching/tarball-fetcher/src/gitHostedTarballFetcher.ts +++ b/fetching/tarball-fetcher/src/gitHostedTarballFetcher.ts @@ -10,11 +10,16 @@ interface Resolution { tarball: string } -export function createGitHostedTarballFetcher (fetchRemoteTarball: FetchFunction, rawConfig: object): FetchFunction { +export interface CreateGitHostedTarballFetcher { + rawConfig: object + unsafePerm?: boolean +} + +export function createGitHostedTarballFetcher (fetchRemoteTarball: FetchFunction, fetcherOpts: CreateGitHostedTarballFetcher): FetchFunction { const fetch = async (cafs: Cafs, resolution: Resolution, opts: FetchOptions) => { const { filesIndex } = await fetchRemoteTarball(cafs, resolution, opts) try { - return { filesIndex: await prepareGitHostedPkg(filesIndex as FilesIndex, cafs, rawConfig) } + return { filesIndex: await prepareGitHostedPkg(filesIndex as FilesIndex, cafs, fetcherOpts) } } catch (err: any) { // eslint-disable-line err.message = `Failed to prepare git-hosted package fetched from "${resolution.tarball}": ${err.message}` // eslint-disable-line throw err @@ -24,7 +29,7 @@ export function createGitHostedTarballFetcher (fetchRemoteTarball: FetchFunction return fetch as FetchFunction } -async function prepareGitHostedPkg (filesIndex: FilesIndex, cafs: Cafs, rawConfig: object) { +async function prepareGitHostedPkg (filesIndex: FilesIndex, cafs: Cafs, opts: CreateGitHostedTarballFetcher) { const tempLocation = await cafs.tempDir() await cafs.importPackage(tempLocation, { filesResponse: { @@ -33,7 +38,7 @@ async function prepareGitHostedPkg (filesIndex: FilesIndex, cafs: Cafs, rawConfi }, force: true, }) - await preparePackage({ rawConfig }, tempLocation) + await preparePackage(opts, tempLocation) const newFilesIndex = await cafs.addFilesFromDir(tempLocation) // Important! We cannot remove the temp location at this stage. // Even though we have the index of the package, diff --git a/fetching/tarball-fetcher/src/index.ts b/fetching/tarball-fetcher/src/index.ts index 9d87487370f..95d4ebc4494 100644 --- a/fetching/tarball-fetcher/src/index.ts +++ b/fetching/tarball-fetcher/src/index.ts @@ -32,6 +32,7 @@ export function createTarballFetcher ( getAuthHeader: GetAuthHeader, opts: { rawConfig: object + unsafePerm?: boolean timeout?: number retry?: RetryTimeoutOptions offline?: boolean @@ -51,7 +52,7 @@ export function createTarballFetcher ( return { localTarball: createLocalTarballFetcher(), remoteTarball: remoteTarballFetcher, - gitHostedTarball: createGitHostedTarballFetcher(remoteTarballFetcher, opts.rawConfig), + gitHostedTarball: createGitHostedTarballFetcher(remoteTarballFetcher, opts), } } diff --git a/pkg-manager/client/src/index.ts b/pkg-manager/client/src/index.ts index 83625271b0e..562451815d8 100644 --- a/pkg-manager/client/src/index.ts +++ b/pkg-manager/client/src/index.ts @@ -20,6 +20,7 @@ export type ClientOptions = { rawConfig: object retry?: RetryTimeoutOptions timeout?: number + unsafePerm?: boolean userAgent?: string userConfig?: Record gitShallowHosts?: string[] @@ -54,7 +55,7 @@ type Fetchers = { function createFetchers ( fetchFromRegistry: FetchFromRegistry, getAuthHeader: GetAuthHeader, - opts: Pick, + opts: Pick, customFetchers?: CustomFetchers ): Fetchers { const defaultFetchers = { diff --git a/releasing/plugin-commands-publishing/src/recursivePublish.ts b/releasing/plugin-commands-publishing/src/recursivePublish.ts index 59cf2fcc60d..360faa3d00c 100644 --- a/releasing/plugin-commands-publishing/src/recursivePublish.ts +++ b/releasing/plugin-commands-publishing/src/recursivePublish.ts @@ -42,6 +42,7 @@ Partial & { @@ -50,6 +51,7 @@ export async function createNewStoreController ( const { resolve, fetchers } = createClient({ customFetchers: opts.hooks?.fetchers, userConfig: opts.userConfig, + unsafePerm: opts.unsafePerm, authConfig: opts.rawConfig, ca: opts.ca, cacheDir: opts.cacheDir, From 13a44deb46372dfe2ce12398493a55df7c900a13 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sun, 1 Jan 2023 21:54:05 +0200 Subject: [PATCH 08/10] test: collapsed prepare --- .../test/reportingLifecycleScripts.ts | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/cli/default-reporter/test/reportingLifecycleScripts.ts b/cli/default-reporter/test/reportingLifecycleScripts.ts index 69fa9fa9217..6b0a064d9d2 100644 --- a/cli/default-reporter/test/reportingLifecycleScripts.ts +++ b/cli/default-reporter/test/reportingLifecycleScripts.ts @@ -650,6 +650,79 @@ ${chalk.gray('node_modules/.registry.npmjs.org/qar/1.0.0/node_modules/')}qar: Ru }) }) +test('collapses lifecycle output from preparation of a git-hosted dependency', (done) => { + const output$ = toOutput$({ + context: { argv: ['install'] }, + reportingOptions: { outputMaxWidth: 79 }, + streamParser: createStreamParser(), + }) + + const wdOfFoo = path.resolve(process.cwd(), 'tmp/_tmp_01243') + + lifecycleLogger.debug({ + depPath: 'registry.npmjs.org/foo/1.0.0', + optional: false, + script: 'node foo', + stage: 'preinstall', + wd: wdOfFoo, + }) + lifecycleLogger.debug({ + depPath: 'registry.npmjs.org/foo/1.0.0', + line: 'foo 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20', + stage: 'preinstall', + stdio: 'stdout', + wd: wdOfFoo, + }) + lifecycleLogger.debug({ + depPath: 'registry.npmjs.org/foo/1.0.0', + optional: false, + script: 'node foo', + stage: 'postinstall', + stdio: 'stdout', + wd: wdOfFoo, + }) + lifecycleLogger.debug({ + depPath: 'registry.npmjs.org/foo/1.0.0', + line: 'foo I', + stage: 'postinstall', + stdio: 'stdout', + wd: wdOfFoo, + }) + lifecycleLogger.debug({ + depPath: 'registry.npmjs.org/foo/1.0.0', + line: 'foo II', + stage: 'postinstall', + stdio: 'stdout', + wd: wdOfFoo, + }) + lifecycleLogger.debug({ + depPath: 'registry.npmjs.org/foo/1.0.0', + line: 'foo III', + stage: 'postinstall', + stdio: 'stdout', + wd: wdOfFoo, + }) + lifecycleLogger.debug({ + depPath: 'registry.npmjs.org/foo/1.0.0', + exitCode: 0, + optional: false, + stage: 'postinstall', + wd: wdOfFoo, + }) + + expect.assertions(1) + + output$.pipe(skip(2), take(1), map(normalizeNewline)).subscribe({ + complete: () => done(), + error: done, + next: (output: unknown) => { + expect(replaceTimeWith1Sec(output as string)).toBe(`\ +${chalk.gray('tmp')}_tmp_01234: Running preinstall script... +${chalk.gray('tmp')}_tmp_01234: Running postinstall script, done in 1s`) + }, + }) +}) + test('output of failed optional dependency is not shown', (done) => { const output$ = toOutput$({ context: { argv: ['install'] }, From 1af97fc9dbee37722d877bdc22f4e09e58e83a0f Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sun, 1 Jan 2023 22:57:20 +0200 Subject: [PATCH 09/10] test: git prepare failure --- .changeset/sweet-items-scream.md | 7 +++++++ fetching/git-fetcher/test/index.ts | 14 ++++++++++++++ fetching/tarball-fetcher/test/fetch.ts | 10 ++++++++++ 3 files changed, 31 insertions(+) create mode 100644 .changeset/sweet-items-scream.md diff --git a/.changeset/sweet-items-scream.md b/.changeset/sweet-items-scream.md new file mode 100644 index 00000000000..ae984824de6 --- /dev/null +++ b/.changeset/sweet-items-scream.md @@ -0,0 +1,7 @@ +--- +"@pnpm/tarball-fetcher": patch +"@pnpm/git-fetcher": patch +"pnpm": patch +--- + +Print more contextual information when a git-hosted package fails to be prepared for installation [#5847](https://github.com/pnpm/pnpm/pull/5847). diff --git a/fetching/git-fetcher/test/index.ts b/fetching/git-fetcher/test/index.ts index 36cc711c102..c906e746919 100644 --- a/fetching/git-fetcher/test/index.ts +++ b/fetching/git-fetcher/test/index.ts @@ -124,6 +124,20 @@ test('still able to shallow fetch for allowed hosts', async () => { expect(name).toEqual('is-positive') }) +test('fail when preparing a git-hosted package', async () => { + const cafsDir = tempy.directory() + const fetch = createGitFetcher({ rawConfig: {} }).git + const manifest = pDefer() + await expect( + fetch(createCafsStore(cafsDir), + { + commit: 'ba58874aae1210a777eb309dd01a9fdacc7e54e7', + repo: 'https://github.com/pnpm-e2e/prepare-script-fails.git', + type: 'git', + }, { manifest }) + ).rejects.toThrow('Failed to prepare git-hosted package fetched from "https://github.com/pnpm-e2e/prepare-script-fails.git": @pnpm.e2e/prepare-script-fails@1.0.0 npm-install: `npm install`') +}) + function prefixGitArgs (): string[] { return process.platform === 'win32' ? ['-c', 'core.longpaths=true'] : [] } diff --git a/fetching/tarball-fetcher/test/fetch.ts b/fetching/tarball-fetcher/test/fetch.ts index 185605d69f7..9813509eacf 100644 --- a/fetching/tarball-fetcher/test/fetch.ts +++ b/fetching/tarball-fetcher/test/fetch.ts @@ -364,6 +364,16 @@ test('fetch a big repository', async () => { expect(result.filesIndex).toBeTruthy() }) +test('fail when preparing a git-hosted package', async () => { + process.chdir(tempy.directory()) + + const resolution = { tarball: 'https://codeload.github.com/pnpm-e2e/prepare-script-fails/tar.gz/ba58874aae1210a777eb309dd01a9fdacc7e54e7' } + + await expect( + fetch.gitHostedTarball(cafs, resolution, { lockfileDir: process.cwd() }) + ).rejects.toThrow('Failed to prepare git-hosted package fetched from "https://codeload.github.com/pnpm-e2e/prepare-script-fails/tar.gz/ba58874aae1210a777eb309dd01a9fdacc7e54e7": @pnpm.e2e/prepare-script-fails@1.0.0 npm-install: `npm install`') +}) + test('fail when extracting a broken tarball', async () => { const scope = nock(registry) .get('/foo.tgz') From 707fd493c5f0782302ad18a71ec27fe6b8a50ac7 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sun, 1 Jan 2023 23:01:40 +0200 Subject: [PATCH 10/10] docs: add changesets --- .changeset/four-colts-care.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .changeset/four-colts-care.md diff --git a/.changeset/four-colts-care.md b/.changeset/four-colts-care.md new file mode 100644 index 00000000000..5f96beac189 --- /dev/null +++ b/.changeset/four-colts-care.md @@ -0,0 +1,11 @@ +--- +"@pnpm/plugin-commands-publishing": patch +"@pnpm/store-connection-manager": patch +"@pnpm/default-reporter": patch +"@pnpm/prepare-package": patch +"@pnpm/client": patch +"@pnpm/node.fetcher": patch +"pnpm": patch +--- + +Report to the console when a git-hosted dependency is built [#5847](https://github.com/pnpm/pnpm/pull/5847).