sindresorhus / np

A better `npm publish`
MIT License
7.56k stars 299 forks source link

np with npm 10.5.1: Failed to parse output of npm pack #740

Closed karlhorky closed 7 months ago

karlhorky commented 7 months ago

Description

Using npm@10.5.1 (latest as of 3 Apr 2024), the following error message is thrown during publish:

➜  preflight git:(main) np --yolo

✖ Error: Failed to parse output of npm pack
    at Module.getFilesToBePacked (file:///Users/k/Library/pnpm/global/5/.pnpm/np@10.0.2/node_modules/np/source/npm/util.js:147:9)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Module.getNewFiles (file:///Users/k/Library/pnpm/global/5/.pnpm/np@10.0.2/node_modules/np/source/util.js:107:27)
    at async checkNewFilesAndDependencies (file:///Users/k/Library/pnpm/global/5/.pnpm/np@10.0.2/node_modules/np/source/ui.js:82:19)
    at async ui (file:///Users/k/Library/pnpm/global/5/.pnpm/np@10.0.2/node_modules/np/source/ui.js:138:30)
    at async getOptions (file:///Users/k/Library/pnpm/global/5/.pnpm/np@10.0.2/node_modules/np/source/cli-implementation.js:146:18)
    at async file:///Users/k/Library/pnpm/global/5/.pnpm/np@10.0.2/node_modules/np/source/cli-implementation.js:163:45

This is probably because npm pack with the flags that np uses also returns output with npm v10:

npm pack --dry-run --json --silent

> @upleveled/preflight@6.1.1 build /Users/k/p/preflight
> tsdx build --format esm --target node --tsconfig tsconfig.src.json "--silent"

✓ Building modules 585 ms
[
  {
    "id": "@upleveled/preflight@6.1.1",
    ...

Steps to reproduce

  1. Use a package with a prepare script that generates output
  2. Use npm v10.5.1
  3. Run np

Expected behavior

Package should be published, like it is with npm v9

Environment

np - 10.0.2 Node.js - 20.12.0 npm - 10.5.1 Git - 2.39.2 OS - macOS Sonoma 14.4.1 (23E224)

karlhorky commented 7 months ago

@transitive-bullshit @sindresorhus Thanks for the #743 PR and review 🙌

Will this be released in the next minor or patch version of np? eg:

sindresorhus commented 7 months ago

https://github.com/sindresorhus/np/releases/tag/v10.0.4

karlhorky commented 7 months ago

Thanks!

Tried to confirm the fix with np@10.0.4 + npm@10.5.2, but still encountering the error:

➜  preflight git:(main) pnpm i -g np@10.0.4
Packages: +1 -1
+-
Progress: resolved 510, reused 509, downloaded 1, added 1, done

/Users/k/Library/pnpm/global/5:
- np 10.0.3
+ np 10.0.4

Done in 6.4s
➜  preflight git:(main) npm --version
10.5.2
➜  preflight git:(main) np --version
10.0.4
➜  preflight git:(main) np

✖ Error: Failed to parse output of npm pack
    at Module.getFilesToBePacked (file:///Users/k/Library/pnpm/global/5/.pnpm/np@10.0.4/node_modules/np/source/npm/util.js:149:9)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Module.getNewFiles (file:///Users/k/Library/pnpm/global/5/.pnpm/np@10.0.4/node_modules/np/source/util.js:107:27)
    at async checkNewFilesAndDependencies (file:///Users/k/Library/pnpm/global/5/.pnpm/np@10.0.4/node_modules/np/source/ui.js:82:19)
    at async ui (file:///Users/k/Library/pnpm/global/5/.pnpm/np@10.0.4/node_modules/np/source/ui.js:138:30)
    at async getOptions (file:///Users/k/Library/pnpm/global/5/.pnpm/np@10.0.4/node_modules/np/source/cli-implementation.js:146:18)
    at async file:///Users/k/Library/pnpm/global/5/.pnpm/np@10.0.4/node_modules/np/source/cli-implementation.js:163:45

More context (output of npm pack):

➜  preflight git:(main) npm pack

> @upleveled/preflight@7.0.3 prepare
> pnpm build

> @upleveled/preflight@7.0.3 build /Users/k/p/preflight
> tsdx build --format esm --target node --tsconfig tsconfig.src.json

✓ Building modules 507 ms
npm notice
npm notice 📦  @upleveled/preflight@7.0.3
npm notice === Tarball Contents ===
npm notice 1.1kB  LICENSE
npm notice 1.3kB  README.md
npm notice 56B    bin/preflight.js
npm notice 128B   dist/checks/allChangesCommittedToGit.d.ts
npm notice 93B    dist/checks/eslint.d.ts
npm notice 126B   dist/checks/eslintConfigIsValid.d.ts
npm notice 142B   dist/checks/linkOnGithubAbout.d.ts
npm notice 136B   dist/checks/nodeModulesIgnoredFromGit.d.ts
npm notice 132B   dist/checks/noDependencyProblems/nextJsProjectHasSharpInstalled.d.ts
npm notice 131B   dist/checks/noDependencyProblems/noDependenciesWithoutTypes.d.ts
npm notice 128B   dist/checks/noDependencyProblems/noUnusedDependencies.d.ts
npm notice 143B   dist/checks/noExtraneousFilesCommittedToGit.d.ts
npm notice 126B   dist/checks/noSecretsCommittedToGit.d.ts
npm notice 127B   dist/checks/preflightIsLatestVersion.d.ts
npm notice 97B    dist/checks/prettier.d.ts
npm notice 146B   dist/checks/projectFolderNameMatchesCorrectFormat.d.ts
npm notice 164B   dist/checks/stylelint.d.ts
npm notice 132B   dist/checks/stylelintConfigIsValid.d.ts
npm notice 125B   dist/checks/useSinglePackageManager.d.ts
npm notice 11B    dist/index.d.ts
npm notice 27.1kB dist/preflight.esm.js
npm notice 51.7kB dist/preflight.esm.js.map
npm notice 76B    dist/types/CtxParam.d.ts
npm notice 156B   dist/types/TaskParam.d.ts
npm notice 65B    dist/util/commandExample.d.ts
npm notice 66B    dist/util/crossPlatform.d.ts
npm notice 53B    dist/util/drone.d.ts
npm notice 1.3kB  dist/util/packageJson.d.ts
npm notice 47B    dist/util/preflightBinPath.d.ts
npm notice 51B    dist/util/randomUserAgent.d.ts
npm notice 2.9kB  package.json
npm notice 1.2kB  src/checks/allChangesCommittedToGit.ts
npm notice 1.8kB  src/checks/eslint.ts
npm notice 2.8kB  src/checks/eslintConfigIsValid.ts
npm notice 1.6kB  src/checks/linkOnGithubAbout.ts
npm notice 997B   src/checks/nodeModulesIgnoredFromGit.ts
npm notice 636B   src/checks/noDependencyProblems/nextJsProjectHasSharpInstalled.ts
npm notice 3.9kB  src/checks/noDependencyProblems/noDependenciesWithoutTypes.ts
npm notice 3.2kB  src/checks/noDependencyProblems/noUnusedDependencies.ts
npm notice 743B   src/checks/noExtraneousFilesCommittedToGit.ts
npm notice 1.0kB  src/checks/noSecretsCommittedToGit.ts
npm notice 851B   src/checks/preflightIsLatestVersion.ts
npm notice 901B   src/checks/prettier.ts
npm notice 963B   src/checks/projectFolderNameMatchesCorrectFormat.ts
npm notice 1.8kB  src/checks/stylelint.ts
npm notice 3.0kB  src/checks/stylelintConfigIsValid.ts
npm notice 949B   src/checks/useSinglePackageManager.ts
npm notice 3.6kB  src/index.ts
npm notice 77B    src/types/CtxParam.ts
npm notice 165B   src/types/TaskParam.ts
npm notice 90B    src/types/top-user-agents.d.ts
npm notice 345B   src/util/commandExample.ts
npm notice 243B   src/util/crossPlatform.ts
npm notice 203B   src/util/drone.ts
npm notice 1.4kB  src/util/packageJson.ts
npm notice 247B   src/util/preflightBinPath.ts
npm notice 191B   src/util/randomUserAgent.ts
npm notice === Tarball Details ===
npm notice name:          @upleveled/preflight
npm notice version:       7.0.3
npm notice filename:      upleveled-preflight-7.0.3.tgz
npm notice package size:  33.0 kB
npm notice unpacked size: 120.9 kB
npm notice shasum:        4873f8be9307c7581b9909e6c5aee2deeaae1cbf
npm notice integrity:     sha512-MIomTY1lT9ufk[...]oPAJzQkN6okhA==
npm notice total files:   57
npm notice
upleveled-preflight-7.0.3.tgz

This is tsdx, so it shows an animated spinner + progress bar thing during build too:

Screenshot 2024-04-17 at 18 01 34

Or maybe I'm doing something wrong?

cc @transitive-bullshit

karlhorky commented 7 months ago

I guess an alternative workaround implementation in np could potentially use npm pack --foreground-scripts=false

karlhorky commented 7 months ago

Eg. maybe something like this PR:

karlhorky commented 7 months ago

@sindresorhus thanks for the review and merge of my PR and publish of np@10.0.5 👍

I can confirm that np@10.0.5 is no longer failing with npm@^10 🎉