-
-
Notifications
You must be signed in to change notification settings - Fork 215
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
chore: use package-manager-detector
#227
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,6 @@ | ||
function npmRun(agent: string) { | ||
return (args: string[]) => { | ||
if (args.length > 1) | ||
return `${agent} run ${args[0]} -- ${args.slice(1).join(' ')}` | ||
else return `${agent} run ${args[0]}` | ||
} | ||
} | ||
import type { Agent, Command } from 'package-manager-detector/agents' | ||
import { AGENTS, COMMANDS, INSTALL_PAGE, LOCKS } from 'package-manager-detector/agents' | ||
|
||
const yarn = { | ||
'agent': 'yarn {0}', | ||
'run': 'yarn run {0}', | ||
'install': 'yarn install {0}', | ||
'frozen': 'yarn install --frozen-lockfile', | ||
'global': 'yarn global add {0}', | ||
'add': 'yarn add {0}', | ||
'upgrade': 'yarn upgrade {0}', | ||
'upgrade-interactive': 'yarn upgrade-interactive {0}', | ||
'execute': 'npx {0}', | ||
'uninstall': 'yarn remove {0}', | ||
'global_uninstall': 'yarn global remove {0}', | ||
} | ||
const pnpm = { | ||
'agent': 'pnpm {0}', | ||
'run': 'pnpm run {0}', | ||
'install': 'pnpm i {0}', | ||
'frozen': 'pnpm i --frozen-lockfile', | ||
'global': 'pnpm add -g {0}', | ||
'add': 'pnpm add {0}', | ||
'upgrade': 'pnpm update {0}', | ||
'upgrade-interactive': 'pnpm update -i {0}', | ||
'execute': 'pnpm dlx {0}', | ||
'uninstall': 'pnpm remove {0}', | ||
'global_uninstall': 'pnpm remove --global {0}', | ||
} | ||
const bun = { | ||
'agent': 'bun {0}', | ||
'run': 'bun run {0}', | ||
'install': 'bun install {0}', | ||
'frozen': 'bun install --frozen-lockfile', | ||
'global': 'bun add -g {0}', | ||
'add': 'bun add {0}', | ||
'upgrade': 'bun update {0}', | ||
'upgrade-interactive': 'bun update {0}', | ||
'execute': 'bun x {0}', | ||
'uninstall': 'bun remove {0}', | ||
'global_uninstall': 'bun remove -g {0}', | ||
} | ||
export { AGENTS, COMMANDS, INSTALL_PAGE, LOCKS } | ||
|
||
export const AGENTS = { | ||
'npm': { | ||
'agent': 'npm {0}', | ||
'run': npmRun('npm'), | ||
'install': 'npm i {0}', | ||
'frozen': 'npm ci', | ||
'global': 'npm i -g {0}', | ||
'add': 'npm i {0}', | ||
'upgrade': 'npm update {0}', | ||
'upgrade-interactive': null, | ||
'execute': 'npx {0}', | ||
'uninstall': 'npm uninstall {0}', | ||
'global_uninstall': 'npm uninstall -g {0}', | ||
}, | ||
'yarn': yarn, | ||
'yarn@berry': { | ||
...yarn, | ||
'frozen': 'yarn install --immutable', | ||
'upgrade': 'yarn up {0}', | ||
'upgrade-interactive': 'yarn up -i {0}', | ||
'execute': 'yarn dlx {0}', | ||
// Yarn 2+ removed 'global', see https://github.com/yarnpkg/berry/issues/821 | ||
'global': 'npm i -g {0}', | ||
'global_uninstall': 'npm uninstall -g {0}', | ||
}, | ||
'pnpm': pnpm, | ||
// pnpm v6.x or below | ||
'pnpm@6': { | ||
...pnpm, | ||
run: npmRun('pnpm'), | ||
}, | ||
'bun': bun, | ||
} | ||
|
||
export type Agent = keyof typeof AGENTS | ||
export type Command = keyof typeof AGENTS.npm | ||
|
||
export const agents = Object.keys(AGENTS) as Agent[] | ||
|
||
// the order here matters, more specific one comes first | ||
export const LOCKS: Record<string, Agent> = { | ||
'bun.lockb': 'bun', | ||
'pnpm-lock.yaml': 'pnpm', | ||
'yarn.lock': 'yarn', | ||
'package-lock.json': 'npm', | ||
'npm-shrinkwrap.json': 'npm', | ||
} | ||
|
||
export const INSTALL_PAGE: Record<Agent, string> = { | ||
'bun': 'https://bun.sh', | ||
'pnpm': 'https://pnpm.io/installation', | ||
'pnpm@6': 'https://pnpm.io/6.x/installation', | ||
'yarn': 'https://classic.yarnpkg.com/en/docs/install', | ||
'yarn@berry': 'https://yarnpkg.com/getting-started/install', | ||
'npm': 'https://docs.npmjs.com/cli/v8/configuring-npm/install', | ||
} | ||
export type { Agent, Command } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove the types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we don't need it:
d.mts
,d.cts
andd.ts
generated, we can omit the types entry (if we include the types entry, CJS being masquerading, check https://publint.dev/@antfu/[email protected] or https://arethetypeswrong.github.io/?p=%40antfu%2Fni%400.22.4):publint
arethetypeswrong