Skip to content

Support pnpm for single run detection #3811

Closed
@cherryblossom000

Description

@cherryblossom000
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestgood first issueGood for newcomerslocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: typescript-estreeIssues related to @typescript-eslint/typescript-estree

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions