Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(create-config): updated script for latest Yarn version #969

Merged
merged 3 commits into from
Mar 7, 2025

Conversation

GauBen
Copy link
Contributor

@GauBen GauBen commented Mar 6, 2025

Hi! I'm trying out knip but I failed to make it work. This PR should make the error readable:

Error: Command failed: yarn add -W -D knip typescript @types/node
    at genericNodeError (node:internal/errors:983:15)
    at wrappedFn (node:internal/errors:537:14)
    at checkExecSyncError (node:child_process:882:11)
    at execSync (node:child_process:954:15)
    at main (file:///private/var/folders/nq/5sbqxy457yj6_x1_28c_x2sr0000gp/T/xfs-c03b4532/dlx-61726/node_modules/@knip/create-config/index.js:49:3)
    at file:///private/var/folders/nq/5sbqxy457yj6_x1_28c_x2sr0000gp/T/xfs-c03b4532/dlx-61726/node_modules/@knip/create-config/index.js:58:1
    at ModuleJob.run (node:internal/modules/esm/module_job:273:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:600:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
  status: 1,
  signal: null,
  output: [
    null,
    Buffer(246) [Uint8Array] [
       27,  91,  51,  49, 109,  27,  91,  49, 109,  85, 110, 107,
      110, 111, 119, 110,  32,  83, 121, 110, 116,  97, 120,  32,
       69, 114, 114, 111, 114,  27,  91,  50,  50, 109,  27,  91,
       51,  57, 109,  58,  32,  85, 110, 115, 117, 112, 112, 111,
      114, 116, 101, 100,  32, 111, 112, 116, 105, 111, 110,  32,
      110,  97, 109, 101,  32,  40,  34,  45,  87,  34,  41,  46,
       10,  10,  36,  32, 121,  97, 114, 110,  32,  97, 100, 100,
       32,  91,  45,  45, 106, 115, 111, 110,  93,  32,  91,  45,
       70,  44,  45,  45,
      ... 146 more items
    ],
    Buffer(0) [Uint8Array] []
  ],
  pid: 61736,
  stdout: Buffer(246) [Uint8Array] [
     27,  91,  51,  49, 109,  27,  91,  49, 109,  85, 110, 107,
    110, 111, 119, 110,  32,  83, 121, 110, 116,  97, 120,  32,
     69, 114, 114, 111, 114,  27,  91,  50,  50, 109,  27,  91,
     51,  57, 109,  58,  32,  85, 110, 115, 117, 112, 112, 111,
    114, 116, 101, 100,  32, 111, 112, 116, 105, 111, 110,  32,
    110,  97, 109, 101,  32,  40,  34,  45,  87,  34,  41,  46,
     10,  10,  36,  32, 121,  97, 114, 110,  32,  97, 100, 100,
     32,  91,  45,  45, 106, 115, 111, 110,  93,  32,  91,  45,
     70,  44,  45,  45,
    ... 146 more items
  ],
  stderr: Buffer(0) [Uint8Array] []
}

Should make the error readable:

```
Error: Command failed: yarn add -W -D knip typescript @types/node
    at genericNodeError (node:internal/errors:983:15)
    at wrappedFn (node:internal/errors:537:14)
    at checkExecSyncError (node:child_process:882:11)
    at execSync (node:child_process:954:15)
    at main (file:///private/var/folders/nq/5sbqxy457yj6_x1_28c_x2sr0000gp/T/xfs-c03b4532/dlx-61726/node_modules/@knip/create-config/index.js:49:3)
    at file:///private/var/folders/nq/5sbqxy457yj6_x1_28c_x2sr0000gp/T/xfs-c03b4532/dlx-61726/node_modules/@knip/create-config/index.js:58:1
    at ModuleJob.run (node:internal/modules/esm/module_job:273:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:600:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
  status: 1,
  signal: null,
  output: [
    null,
    Buffer(246) [Uint8Array] [
       27,  91,  51,  49, 109,  27,  91,  49, 109,  85, 110, 107,
      110, 111, 119, 110,  32,  83, 121, 110, 116,  97, 120,  32,
       69, 114, 114, 111, 114,  27,  91,  50,  50, 109,  27,  91,
       51,  57, 109,  58,  32,  85, 110, 115, 117, 112, 112, 111,
      114, 116, 101, 100,  32, 111, 112, 116, 105, 111, 110,  32,
      110,  97, 109, 101,  32,  40,  34,  45,  87,  34,  41,  46,
       10,  10,  36,  32, 121,  97, 114, 110,  32,  97, 100, 100,
       32,  91,  45,  45, 106, 115, 111, 110,  93,  32,  91,  45,
       70,  44,  45,  45,
      ... 146 more items
    ],
    Buffer(0) [Uint8Array] []
  ],
  pid: 61736,
  stdout: Buffer(246) [Uint8Array] [
     27,  91,  51,  49, 109,  27,  91,  49, 109,  85, 110, 107,
    110, 111, 119, 110,  32,  83, 121, 110, 116,  97, 120,  32,
     69, 114, 114, 111, 114,  27,  91,  50,  50, 109,  27,  91,
     51,  57, 109,  58,  32,  85, 110, 115, 117, 112, 112, 111,
    114, 116, 101, 100,  32, 111, 112, 116, 105, 111, 110,  32,
    110,  97, 109, 101,  32,  40,  34,  45,  87,  34,  41,  46,
     10,  10,  36,  32, 121,  97, 114, 110,  32,  97, 100, 100,
     32,  91,  45,  45, 106, 115, 111, 110,  93,  32,  91,  45,
     70,  44,  45,  45,
    ... 146 more items
  ],
  stderr: Buffer(0) [Uint8Array] []
}
```
@GauBen
Copy link
Contributor Author

GauBen commented Mar 6, 2025

The error is Unknown Syntax Error: Unsupported option name ("-W").

Indeed latest yarn does not have it https://yarnpkg.com/cli/add#options

I updated this PR to fix the error. I confirm it works once the -W flag is removed: knip is added to package.json scripts.

@GauBen GauBen changed the title fix(create-config): forward stdio when running commands fix(create-config): updated script for latest Yarn version Mar 6, 2025
@webpro
Copy link
Member

webpro commented Mar 6, 2025

Hi @GauBen! Thanks for the PR.

Looks like we need the -W flag for classic Yarn in workspaces: https://classic.yarnpkg.com/en/docs/cli/add

I do like to use the stdio option. But perhaps we need something to verify we're not using Yarn classic, so we know not to add the -W flag?

@GauBen
Copy link
Contributor Author

GauBen commented Mar 6, 2025

What about looking for yarn lockfile v1 in the first few bytes of yarn.lock?

@webpro
Copy link
Member

webpro commented Mar 6, 2025

Sounds OK, but isn't there an easier/faster way e.g. see if the .yarn directory exists or something?

@GauBen
Copy link
Contributor Author

GauBen commented Mar 6, 2025

You could have yarn v1 saved in .yarn/releases, not sure what could be done in that matter

@webpro
Copy link
Member

webpro commented Mar 6, 2025

Oh sorry, I'm not familiar with the implementation details of Yarn. Let's go with your idea, thanks in advance!

@GauBen
Copy link
Contributor Author

GauBen commented Mar 6, 2025

What do you think of this?

Copy link

pkg-pr-new bot commented Mar 7, 2025

Open in Stackblitz

npm i https://pkg.pr.new/knip@969

commit: 7cf7227

@webpro
Copy link
Member

webpro commented Mar 7, 2025

That reads the whole file, which can be pretty large. Also it keeps things simple, so let's just roll with for now. Thanks! I'll release it shortly.

@webpro webpro merged commit 2419174 into webpro-nl:main Mar 7, 2025
22 of 23 checks passed
@webpro
Copy link
Member

webpro commented Mar 7, 2025

Released as https://www.npmjs.com/package/@knip/create-config v1.0.5 :)

@GauBen GauBen deleted the patch-1 branch March 7, 2025 08:36
@webpro
Copy link
Member

webpro commented Mar 13, 2025

🚀 This pull request is included in v5.46.0. See Release 5.46.0 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants