From 483384af686de923dcd5908b5ec95f864704f18a Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Tue, 11 Feb 2025 18:30:11 +0800 Subject: [PATCH] feat: `init` command create file add `packageManager` field (#9069) close #9068 --------- Co-authored-by: Zoltan Kochan --- .changeset/sweet-tomatoes-own.md | 6 ++++++ packages/plugin-commands-init/package.json | 1 + packages/plugin-commands-init/src/init.ts | 2 ++ packages/plugin-commands-init/tsconfig.json | 3 +++ pnpm-lock.yaml | 3 +++ 5 files changed, 15 insertions(+) create mode 100644 .changeset/sweet-tomatoes-own.md diff --git a/.changeset/sweet-tomatoes-own.md b/.changeset/sweet-tomatoes-own.md new file mode 100644 index 0000000000..3154992ee2 --- /dev/null +++ b/.changeset/sweet-tomatoes-own.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-init": minor +"pnpm": patch +--- + +`pnpm init` command adds a `packageManager` field with the current version of pnpm CLI [#9069](https://github.com/pnpm/pnpm/pull/9069). diff --git a/packages/plugin-commands-init/package.json b/packages/plugin-commands-init/package.json index 7f85b83bbb..7af5550570 100644 --- a/packages/plugin-commands-init/package.json +++ b/packages/plugin-commands-init/package.json @@ -37,6 +37,7 @@ "load-json-file": "catalog:" }, "dependencies": { + "@pnpm/cli-meta": "workspace:*", "@pnpm/cli-utils": "workspace:*", "@pnpm/config": "workspace:*", "@pnpm/error": "workspace:*", diff --git a/packages/plugin-commands-init/src/init.ts b/packages/plugin-commands-init/src/init.ts index 48ea7ad8b6..5d2fc76bd4 100644 --- a/packages/plugin-commands-init/src/init.ts +++ b/packages/plugin-commands-init/src/init.ts @@ -1,6 +1,7 @@ import fs from 'fs' import path from 'path' import { docsUrl } from '@pnpm/cli-utils' +import { packageManager } from '@pnpm/cli-meta' import { type CliOptions, type UniversalOptions } from '@pnpm/config' import { PnpmError } from '@pnpm/error' import { writeProjectManifest } from '@pnpm/write-project-manifest' @@ -45,6 +46,7 @@ export async function handler ( version: '1.0.0', description: '', main: 'index.js', + packageManager: `pnpm@${packageManager.version}`, scripts: { test: 'echo "Error: no test specified" && exit 1', }, diff --git a/packages/plugin-commands-init/tsconfig.json b/packages/plugin-commands-init/tsconfig.json index e15badd158..7fb987fe16 100644 --- a/packages/plugin-commands-init/tsconfig.json +++ b/packages/plugin-commands-init/tsconfig.json @@ -15,6 +15,9 @@ { "path": "../../__utils__/test-fixtures" }, + { + "path": "../../cli/cli-meta" + }, { "path": "../../cli/cli-utils" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a41d9b4102..efe01368a4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3940,6 +3940,9 @@ importers: packages/plugin-commands-init: dependencies: + '@pnpm/cli-meta': + specifier: workspace:* + version: link:../../cli/cli-meta '@pnpm/cli-utils': specifier: workspace:* version: link:../../cli/cli-utils