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

Support pnpm for single run detection #3811

Closed
3 tasks done
cherryblossom000 opened this issue Aug 29, 2021 · 1 comment · Fixed by #8702
Closed
3 tasks done

Support pnpm for single run detection #3811

cherryblossom000 opened this issue Aug 29, 2021 · 1 comment · Fixed by #8702
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement New feature or request good first issue Good for newcomers package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@cherryblossom000
Copy link
Contributor

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

.eslintrc.yml

root: true
parser: '@typescript-eslint/parser'
parserOptions:
  project: tsconfig.json
  allowAutomaticSingleRunInference: true

tsconfig.json

{
  "files": ["index.ts"]
}

index.ts

// nothing
pnpm install

DEBUG=typescript-eslint:* pnpm eslint index.ts
# or
DEBUG=typescript-eslint:* ./node_modules/.bin/eslint index.ts

https://github.com/cherryblossom000/typescript-eslint-single-run-pnpm

Expected Result

typescript-estree should detect that this is a single run of ESLint.

$ TSESTREE_SINGLE_RUN=true DEBUG=typescript-eslint:* pnpm eslint index.ts
  typescript-eslint:typescript-estree:parser parserOptions.project (excluding ignored) matched projects: Set(1) {
  '/path/to/typescript-eslint-single-run-pnpm/tsconfig.json'
} +0ms
  typescript-eslint:typescript-estree:useProvidedProgram Retrieving ast for /path/to/typescript-eslint-single-run-pnpm/index.ts from provided program instance(s) +0ms
  typescript-eslint:typescript-estree:parser Detected single-run/CLI usage, creating Program once ahead of time for project: /path/to/typescript-eslint-single-run-pnpm/tsconfig.json +2ms
  typescript-eslint:parser:parser Resolved libs from program: [ 'lib' ] +0ms

Actual Result

typescript-estree did not detect that this was a single run.

$ DEBUG=typescript-eslint:* pnpm eslint index.ts
  typescript-eslint:typescript-estree:parser parserOptions.project (excluding ignored) matched projects: Set(1) {
  '/path/to/typescript-eslint-single-run-pnpm/tsconfig.json'
} +0ms
  typescript-eslint:typescript-estree:createProjectProgram Creating project program for: /path/to/typescript-eslint-single-run-pnpm/index.ts +0ms
  typescript-eslint:typescript-estree:createWatchProgram File did not belong to any existing programs, moving to create/update. /path/to/typescript-eslint-single-run-pnpm/index.ts +0ms
  typescript-eslint:typescript-estree:createWatchProgram Creating watch program for /path/to/typescript-eslint-single-run-pnpm/tsconfig.json. +0ms
  typescript-eslint:typescript-estree:createWatchProgram Found program for file. /path/to/typescript-eslint-single-run-pnpm/index.ts +573ms
  typescript-eslint:parser:parser Resolved libs from program: [ 'lib' ] +0ms

Additional Info

Instead of copying the Node.js CLI script, pnpm creates a shell script that invokes the direct path to the script (e.g. node node_modules/eslint/bin/eslint.js) in node_modules/.bin/eslint:

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -z "$NODE_PATH" ]; then
  export NODE_PATH="/path/to/typescript-eslint-single-run-pnpm/node_modules/.pnpm/eslint@7.32.0/node_modules/eslint/bin/node_modules:/path/to/typescript-eslint-single-run-pnpm/node_modules/.pnpm/eslint@7.32.0/node_modules/eslint/node_modules:/path/to/typescript-eslint-single-run-pnpm/node_modules/.pnpm/eslint@7.32.0/node_modules:/path/to/typescript-eslint-single-run-pnpm/node_modules/.pnpm/node_modules:/path/to/typescript-eslint-single-run-pnpm/node_modules:/path/to/node_modules:/path/node_modules:/node_modules:/path/to/typescript-eslint-single-run-pnpm/node_modules/eslint/bin/node_modules:/path/to/typescript-eslint-single-run-pnpm/node_modules/eslint/node_modules"
else
  export NODE_PATH="$NODE_PATH:/path/to/typescript-eslint-single-run-pnpm/node_modules/.pnpm/eslint@7.32.0/node_modules/eslint/bin/node_modules:/path/to/typescript-eslint-single-run-pnpm/node_modules/.pnpm/eslint@7.32.0/node_modules/eslint/node_modules:/path/to/typescript-eslint-single-run-pnpm/node_modules/.pnpm/eslint@7.32.0/node_modules:/path/to/typescript-eslint-single-run-pnpm/node_modules/.pnpm/node_modules:/path/to/typescript-eslint-single-run-pnpm/node_modules:/path/to/node_modules:/path/node_modules:/node_modules:/path/to/typescript-eslint-single-run-pnpm/node_modules/eslint/bin/node_modules:/path/to/typescript-eslint-single-run-pnpm/node_modules/eslint/node_modules"
fi
if [ -x "$basedir/node" ]; then
  exec "$basedir/node"  "$basedir/../eslint/bin/eslint.js" "$@"
else
  exec node  "$basedir/../eslint/bin/eslint.js" "$@"
fi

This means that process.argv[1] ends with node_modules/eslint/bin/eslint.js instead of node_modules/.bin/eslint.

I know that I can just use TSESTREE_SINGLE_RUN=true, that ESLint could change the path to the bin file at any time, and that pnpm isn't as popular as npm and yarn, so I understand if this isn't actionable.

Versions

package version
@typescript-eslint/typescript-estree 4.29.3
TypeScript 4.3.5
node 16.8.0
@cherryblossom000 cherryblossom000 added package: typescript-estree Issues related to @typescript-eslint/typescript-estree triage Waiting for maintainers to take a look labels Aug 29, 2021
@bradzacher bradzacher added enhancement New feature or request good first issue Good for newcomers and removed triage Waiting for maintainers to take a look labels Aug 29, 2021
@JoshuaKGoldberg JoshuaKGoldberg added the accepting prs Go ahead, send a pull request that resolves this issue label Oct 25, 2021
@Jack-Works
Copy link

I'm using Windows + pnpm, and using npx to start the command. My command is npx eslint packages --debug and my argv is:

['C:\Program Files\nodejs\node.exe', 'C:\Users\Jack\workspace\project_name\node_modules\eslint\bin\eslint.js', 'packages', '--debug']

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement New feature or request good first issue Good for newcomers package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
4 participants