From 3cf154b9d75aad4ba39a374b296589ed63d52302 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 23 Dec 2022 16:37:24 +0200 Subject: [PATCH 01/18] feat: implement the config commands --- config/plugin-commands-config/README.md | 15 ++++ config/plugin-commands-config/jest.config.js | 3 + config/plugin-commands-config/package.json | 44 +++++++++++ .../src/ConfigCommandOptions.ts | 7 ++ config/plugin-commands-config/src/config.ts | 77 +++++++++++++++++++ .../plugin-commands-config/src/configSet.ts | 6 ++ config/plugin-commands-config/src/index.ts | 4 + config/plugin-commands-config/tsconfig.json | 40 ++++++++++ .../plugin-commands-config/tsconfig.lint.json | 8 ++ pnpm-lock.yaml | 16 ++++ 10 files changed, 220 insertions(+) create mode 100644 config/plugin-commands-config/README.md create mode 100644 config/plugin-commands-config/jest.config.js create mode 100644 config/plugin-commands-config/package.json create mode 100644 config/plugin-commands-config/src/ConfigCommandOptions.ts create mode 100644 config/plugin-commands-config/src/config.ts create mode 100644 config/plugin-commands-config/src/configSet.ts create mode 100644 config/plugin-commands-config/src/index.ts create mode 100644 config/plugin-commands-config/tsconfig.json create mode 100644 config/plugin-commands-config/tsconfig.lint.json diff --git a/config/plugin-commands-config/README.md b/config/plugin-commands-config/README.md new file mode 100644 index 00000000000..a02fa4c6edd --- /dev/null +++ b/config/plugin-commands-config/README.md @@ -0,0 +1,15 @@ +# @pnpm/plugin-commands-config + +> Commands for reading and writing settings to/from config files + +[![npm version](https://img.shields.io/npm/v/@pnpm/plugin-commands-config.svg)](https://www.npmjs.com/package/@pnpm/plugin-commands-config) + +## Installation + +```sh +pnpm add @pnpm/plugin-commands-config +``` + +## License + +MIT diff --git a/config/plugin-commands-config/jest.config.js b/config/plugin-commands-config/jest.config.js new file mode 100644 index 00000000000..95f86a21281 --- /dev/null +++ b/config/plugin-commands-config/jest.config.js @@ -0,0 +1,3 @@ +const config = require('../../jest.config.js') + +module.exports = config diff --git a/config/plugin-commands-config/package.json b/config/plugin-commands-config/package.json new file mode 100644 index 00000000000..a454e83cc8b --- /dev/null +++ b/config/plugin-commands-config/package.json @@ -0,0 +1,44 @@ +{ + "name": "@pnpm/plugin-commands-config", + "version": "0.0.0", + "description": "Commands for reading and writing settings to/from config files", + "main": "lib/index.js", + "types": "lib/index.d.ts", + "files": [ + "lib", + "!*.map" + ], + "engines": { + "node": ">=14.6" + }, + "scripts": { + "lint": "eslint src/**/*.ts test/**/*.ts", + "_test": "jest", + "test": "pnpm run compile && pnpm run _test", + "prepublishOnly": "pnpm run compile", + "compile": "tsc --build && pnpm run lint --fix" + }, + "repository": "https://github.com/pnpm/pnpm/blob/main/config/plugin-commands-config", + "keywords": [ + "pnpm7", + "pnpm", + "config" + ], + "license": "MIT", + "bugs": { + "url": "https://github.com/pnpm/pnpm/issues" + }, + "homepage": "https://github.com/pnpm/pnpm/blob/main/config/plugin-commands-config#readme", + "dependencies": { + "@pnpm/config": "workspace:*", + "@pnpm/error": "workspace:*" + }, + "funding": "https://opencollective.com/pnpm", + "devDependencies": { + "@pnpm/logger": "^5.0.0", + "@pnpm/plugin-commands-config": "workspace:*" + }, + "exports": { + ".": "./lib/index.js" + } +} diff --git a/config/plugin-commands-config/src/ConfigCommandOptions.ts b/config/plugin-commands-config/src/ConfigCommandOptions.ts new file mode 100644 index 00000000000..defda75daed --- /dev/null +++ b/config/plugin-commands-config/src/ConfigCommandOptions.ts @@ -0,0 +1,7 @@ +import { Config } from '@pnpm/config' + +export type ConfigCommandOptions = Pick diff --git a/config/plugin-commands-config/src/config.ts b/config/plugin-commands-config/src/config.ts new file mode 100644 index 00000000000..02fa5ba4ce5 --- /dev/null +++ b/config/plugin-commands-config/src/config.ts @@ -0,0 +1,77 @@ +import { docsUrl } from '@pnpm/cli-utils' +import { PnpmError } from '@pnpm/error' +import renderHelp from 'render-help' +import { configSet } from './configSet' +import { ConfigCommandOptions } from './ConfigCommandOptions' + +export function rcOptionsTypes () { + return {} +} + +export function cliOptionsTypes () { + return { + global: Boolean, + remote: Boolean, + } +} + +export const commandNames = ['env'] + +export function help () { + return renderHelp({ + description: 'Manage Node.js versions.', + descriptionLists: [ + { + title: 'Commands', + list: [ + { + description: 'Installs the specified version of Node.js. The npm CLI bundled with the given Node.js version gets installed as well.', + name: 'use', + }, + { + description: 'Removes the specified version of Node.js.', + name: 'remove', + shortAlias: 'rm', + }, + { + description: 'List Node.js versions available locally or remotely', + name: 'list', + shortAlias: 'ls', + }, + ], + }, + { + title: 'Options', + list: [ + { + description: 'Manages Node.js versions globally', + name: '--global', + shortAlias: '-g', + }, + { + description: 'List the remote versions of Node.js', + name: '--remote', + }, + ], + }, + ], + url: docsUrl('env'), + usages: [ + 'pnpm config set ', + ], + }) +} + +export async function handler (opts: ConfigCommandOptions, params: string[]) { + if (params.length === 0) { + throw new PnpmError('ENV_NO_SUBCOMMAND', 'Please specify the subcommand') + } + switch (params[0]) { + case 'set': { + return configSet(opts, params.slice(1)) + } + default: { + throw new PnpmError('ENV_UNKNOWN_SUBCOMMAND', 'This subcommand is not known') + } + } +} diff --git a/config/plugin-commands-config/src/configSet.ts b/config/plugin-commands-config/src/configSet.ts new file mode 100644 index 00000000000..9728b350fd4 --- /dev/null +++ b/config/plugin-commands-config/src/configSet.ts @@ -0,0 +1,6 @@ +import { ConfigCommandOptions } from './ConfigCommandOptions' + +export function configSet (opts: ConfigCommandOptions, key: string, value: string) { + if (opts.global) { + } +} diff --git a/config/plugin-commands-config/src/index.ts b/config/plugin-commands-config/src/index.ts new file mode 100644 index 00000000000..98cc86c99c2 --- /dev/null +++ b/config/plugin-commands-config/src/index.ts @@ -0,0 +1,4 @@ +import * as env from './env' +import * as node from './node' + +export { env, node } diff --git a/config/plugin-commands-config/tsconfig.json b/config/plugin-commands-config/tsconfig.json new file mode 100644 index 00000000000..5a909aea982 --- /dev/null +++ b/config/plugin-commands-config/tsconfig.json @@ -0,0 +1,40 @@ +{ + "extends": "@pnpm/tsconfig", + "compilerOptions": { + "outDir": "lib", + "rootDir": "src" + }, + "include": [ + "src/**/*.ts", + "../../__typings__/**/*.d.ts" + ], + "references": [ + { + "path": "../../__utils__/prepare" + }, + { + "path": "../../cli/cli-utils" + }, + { + "path": "../../config/config" + }, + { + "path": "../../network/fetch" + }, + { + "path": "../../packages/error" + }, + { + "path": "../../pkg-manager/remove-bins" + }, + { + "path": "../../store/store-path" + }, + { + "path": "../node.fetcher" + }, + { + "path": "../node.resolver" + } + ] +} diff --git a/config/plugin-commands-config/tsconfig.lint.json b/config/plugin-commands-config/tsconfig.lint.json new file mode 100644 index 00000000000..1bbe711971a --- /dev/null +++ b/config/plugin-commands-config/tsconfig.lint.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "include": [ + "src/**/*.ts", + "test/**/*.ts", + "../../__typings__/**/*.d.ts" + ] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 95eb63b3ca2..8f0a91d880a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -697,6 +697,22 @@ importers: specifier: workspace:* version: 'link:' + config/plugin-commands-config: + dependencies: + '@pnpm/config': + specifier: workspace:* + version: link:../config + '@pnpm/error': + specifier: workspace:* + version: link:../../packages/error + devDependencies: + '@pnpm/logger': + specifier: ^5.0.0 + version: 5.0.0 + '@pnpm/plugin-commands-config': + specifier: workspace:* + version: 'link:' + env/node.fetcher: dependencies: '@pnpm/create-cafs-store': From 0392b1718711973a83d873ca50dd6fb141fb01bd Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 23 Dec 2022 16:52:41 +0200 Subject: [PATCH 02/18] feat: implement the config commands --- __typings__/local.d.ts | 5 ++++ config/plugin-commands-config/package.json | 6 +++- .../src/ConfigCommandOptions.ts | 1 + config/plugin-commands-config/src/config.ts | 6 ++-- .../plugin-commands-config/src/configSet.ts | 11 +++++-- config/plugin-commands-config/src/index.ts | 5 ++-- config/plugin-commands-config/tsconfig.json | 20 +------------ pnpm-lock.yaml | 30 +++++++++++++++++++ pnpm/package.json | 1 + pnpm/src/cmd/index.ts | 2 ++ pnpm/src/pnpm.ts | 2 -- pnpm/tsconfig.json | 3 ++ 12 files changed, 61 insertions(+), 31 deletions(-) diff --git a/__typings__/local.d.ts b/__typings__/local.d.ts index 2ac66fa0a99..f143741241c 100644 --- a/__typings__/local.d.ts +++ b/__typings__/local.d.ts @@ -151,6 +151,11 @@ declare module 'string.prototype.replaceall' { export = anything } +declare module 'write-ini-file' { + const anything: any + export = anything +} + declare module 'ramda/src/map' { function map (fn: (x: V) => U, obj: Record): Record export = map diff --git a/config/plugin-commands-config/package.json b/config/plugin-commands-config/package.json index a454e83cc8b..6921f802217 100644 --- a/config/plugin-commands-config/package.json +++ b/config/plugin-commands-config/package.json @@ -30,8 +30,12 @@ }, "homepage": "https://github.com/pnpm/pnpm/blob/main/config/plugin-commands-config#readme", "dependencies": { + "@pnpm/cli-utils": "workspace:*", "@pnpm/config": "workspace:*", - "@pnpm/error": "workspace:*" + "@pnpm/error": "workspace:*", + "read-ini-file": "^3.1.0", + "render-help": "^1.0.2", + "write-ini-file": "4.0.0" }, "funding": "https://opencollective.com/pnpm", "devDependencies": { diff --git a/config/plugin-commands-config/src/ConfigCommandOptions.ts b/config/plugin-commands-config/src/ConfigCommandOptions.ts index defda75daed..570c3d2d35d 100644 --- a/config/plugin-commands-config/src/ConfigCommandOptions.ts +++ b/config/plugin-commands-config/src/ConfigCommandOptions.ts @@ -2,6 +2,7 @@ import { Config } from '@pnpm/config' export type ConfigCommandOptions = Pick diff --git a/config/plugin-commands-config/src/config.ts b/config/plugin-commands-config/src/config.ts index 02fa5ba4ce5..256b9750c9f 100644 --- a/config/plugin-commands-config/src/config.ts +++ b/config/plugin-commands-config/src/config.ts @@ -15,11 +15,11 @@ export function cliOptionsTypes () { } } -export const commandNames = ['env'] +export const commandNames = ['c'] export function help () { return renderHelp({ - description: 'Manage Node.js versions.', + description: 'Manage the pnpm configuration files.', descriptionLists: [ { title: 'Commands', @@ -68,7 +68,7 @@ export async function handler (opts: ConfigCommandOptions, params: string[]) { } switch (params[0]) { case 'set': { - return configSet(opts, params.slice(1)) + return configSet(opts, params[1], params[2]) } default: { throw new PnpmError('ENV_UNKNOWN_SUBCOMMAND', 'This subcommand is not known') diff --git a/config/plugin-commands-config/src/configSet.ts b/config/plugin-commands-config/src/configSet.ts index 9728b350fd4..472c093c089 100644 --- a/config/plugin-commands-config/src/configSet.ts +++ b/config/plugin-commands-config/src/configSet.ts @@ -1,6 +1,11 @@ +import path from 'path' +import readIniFile from 'read-ini-file' +import writeIniFile from 'write-ini-file' import { ConfigCommandOptions } from './ConfigCommandOptions' -export function configSet (opts: ConfigCommandOptions, key: string, value: string) { - if (opts.global) { - } +export async function configSet (opts: ConfigCommandOptions, key: string, value: string) { + const configPath = opts.global ? path.join(opts.configDir, 'rc') : path.join(opts.dir, '.npmrc') + const settings = await readIniFile(configPath) + settings[key] = value + await writeIniFile(configPath, settings) } diff --git a/config/plugin-commands-config/src/index.ts b/config/plugin-commands-config/src/index.ts index 98cc86c99c2..3ece161e58d 100644 --- a/config/plugin-commands-config/src/index.ts +++ b/config/plugin-commands-config/src/index.ts @@ -1,4 +1,3 @@ -import * as env from './env' -import * as node from './node' +import * as config from './config' -export { env, node } +export { config } diff --git a/config/plugin-commands-config/tsconfig.json b/config/plugin-commands-config/tsconfig.json index 5a909aea982..4b1ec9020f6 100644 --- a/config/plugin-commands-config/tsconfig.json +++ b/config/plugin-commands-config/tsconfig.json @@ -9,32 +9,14 @@ "../../__typings__/**/*.d.ts" ], "references": [ - { - "path": "../../__utils__/prepare" - }, { "path": "../../cli/cli-utils" }, - { - "path": "../../config/config" - }, - { - "path": "../../network/fetch" - }, { "path": "../../packages/error" }, { - "path": "../../pkg-manager/remove-bins" - }, - { - "path": "../../store/store-path" - }, - { - "path": "../node.fetcher" - }, - { - "path": "../node.resolver" + "path": "../config" } ] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8f0a91d880a..8edbea1127c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -699,12 +699,24 @@ importers: config/plugin-commands-config: dependencies: + '@pnpm/cli-utils': + specifier: workspace:* + version: link:../../cli/cli-utils '@pnpm/config': specifier: workspace:* version: link:../config '@pnpm/error': specifier: workspace:* version: link:../../packages/error + read-ini-file: + specifier: ^3.1.0 + version: 3.1.0 + render-help: + specifier: ^1.0.2 + version: 1.0.2 + write-ini-file: + specifier: 4.0.0 + version: 4.0.0 devDependencies: '@pnpm/logger': specifier: ^5.0.0 @@ -3972,6 +3984,9 @@ importers: '@pnpm/plugin-commands-audit': specifier: workspace:* version: link:../lockfile/plugin-commands-audit + '@pnpm/plugin-commands-config': + specifier: workspace:* + version: link:../config/plugin-commands-config '@pnpm/plugin-commands-deploy': specifier: workspace:* version: link:../releasing/plugin-commands-deploy @@ -12374,6 +12389,11 @@ packages: resolution: {integrity: sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA==} engines: {node: '>=10'} + /ini/3.0.1: + resolution: {integrity: sha512-it4HyVAUTKBc6m8e1iXWvXSTdndF7HbdN713+kvLrymxTaU4AUBWrJ4vEooP+V7fexnVD3LKcBshjGGPefSMUQ==} + engines: {node: ^12.13.0 || ^14.15.0 || >=16.0.0} + dev: false + /inquirer/6.5.2: resolution: {integrity: sha512-cntlB5ghuB0iuO65Ovoi8ogLHiWGs/5yNrtUcKjFhSSiVeAIVpD7koaSU9RM8mpXw5YDi9RdYXGQMaOURB7ycQ==} engines: {node: '>=6.0.0'} @@ -17210,6 +17230,15 @@ packages: imurmurhash: 0.1.4 signal-exit: 3.0.7 + /write-ini-file/4.0.0: + resolution: {integrity: sha512-o43++IKaOeIxjxflvFH4BQvkpDsiqqH2I6qsz8Az2uyWAq0Gw6Mrc2JYSmGKoARE9j7jz/X/hTmPZi6B1XKT8g==} + engines: {node: '>=14.6'} + dependencies: + ini: 3.0.1 + make-dir: 3.1.0 + write-file-atomic: 5.0.0 + dev: false + /write-json-file/3.2.0: resolution: {integrity: sha512-3xZqT7Byc2uORAatYiP3DHUUAVEkNOswEWNs9H5KXiicRTvzYzYqKjYc4G7p+8pltvAw641lVByKVtMpf+4sYQ==} engines: {node: '>=6'} @@ -17646,6 +17675,7 @@ time: /which/3.0.0: '2022-11-01T19:20:24.475Z' /wrap-ansi/7.0.0: '2020-04-22T16:53:23.889Z' /write-file-atomic/5.0.0: '2022-10-14T05:22:38.937Z' + /write-ini-file/4.0.0: '2022-12-23T13:45:29.905Z' /write-json-file/4.3.0: '2020-02-07T08:54:49.528Z' /write-json5-file/3.1.0: '2021-02-11T22:54:24.439Z' /write-pkg/4.0.0: '2019-04-29T10:37:09.855Z' diff --git a/pnpm/package.json b/pnpm/package.json index b46e7b2da5d..492e1934479 100644 --- a/pnpm/package.json +++ b/pnpm/package.json @@ -41,6 +41,7 @@ "@pnpm/parse-cli-args": "workspace:*", "@pnpm/pick-registry-for-package": "workspace:*", "@pnpm/plugin-commands-audit": "workspace:*", + "@pnpm/plugin-commands-config": "workspace:*", "@pnpm/plugin-commands-deploy": "workspace:*", "@pnpm/plugin-commands-doctor": "workspace:*", "@pnpm/plugin-commands-env": "workspace:*", diff --git a/pnpm/src/cmd/index.ts b/pnpm/src/cmd/index.ts index f56eab94494..fd931d39708 100644 --- a/pnpm/src/cmd/index.ts +++ b/pnpm/src/cmd/index.ts @@ -1,6 +1,7 @@ import { CompletionFunc } from '@pnpm/command' import { types as allTypes } from '@pnpm/config' import { audit } from '@pnpm/plugin-commands-audit' +import { config } from '@pnpm/plugin-commands-config' import { doctor } from '@pnpm/plugin-commands-doctor' import { env } from '@pnpm/plugin-commands-env' import { deploy } from '@pnpm/plugin-commands-deploy' @@ -99,6 +100,7 @@ const commands: CommandDefinition[] = [ add, audit, bin, + config, create, deploy, dlx, diff --git a/pnpm/src/pnpm.ts b/pnpm/src/pnpm.ts index 85b7af63012..13e74b324a0 100644 --- a/pnpm/src/pnpm.ts +++ b/pnpm/src/pnpm.ts @@ -28,8 +28,6 @@ const argv = process.argv.slice(2) case 'access': case 'adduser': case 'bugs': - case 'c': - case 'config': case 'deprecate': case 'dist-tag': case 'docs': diff --git a/pnpm/tsconfig.json b/pnpm/tsconfig.json index 01d07a54334..cb864ce2790 100644 --- a/pnpm/tsconfig.json +++ b/pnpm/tsconfig.json @@ -45,6 +45,9 @@ { "path": "../config/pick-registry-for-package" }, + { + "path": "../config/plugin-commands-config" + }, { "path": "../env/plugin-commands-env" }, From e9a871254e78f84e2b89040ac3587e892d02fef2 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 23 Dec 2022 16:59:10 +0200 Subject: [PATCH 03/18] feat: implement the config commands --- config/plugin-commands-config/src/config.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/config/plugin-commands-config/src/config.ts b/config/plugin-commands-config/src/config.ts index 256b9750c9f..6433180f1e9 100644 --- a/config/plugin-commands-config/src/config.ts +++ b/config/plugin-commands-config/src/config.ts @@ -11,11 +11,10 @@ export function rcOptionsTypes () { export function cliOptionsTypes () { return { global: Boolean, - remote: Boolean, } } -export const commandNames = ['c'] +export const commandNames = ['config', 'c'] export function help () { return renderHelp({ @@ -64,7 +63,9 @@ export function help () { export async function handler (opts: ConfigCommandOptions, params: string[]) { if (params.length === 0) { - throw new PnpmError('ENV_NO_SUBCOMMAND', 'Please specify the subcommand') + throw new PnpmError('ENV_NO_SUBCOMMAND', 'Please specify the subcommand', { + hint: help(), + }) } switch (params[0]) { case 'set': { From 4b70f2a4d62fc097527e9d43f533c8363e68a7b4 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 23 Dec 2022 17:16:03 +0200 Subject: [PATCH 04/18] test: config set --- config/plugin-commands-config/package.json | 3 ++- .../plugin-commands-config/src/configSet.ts | 11 +++++++++- .../test/configSet.test.ts | 22 +++++++++++++++++++ config/plugin-commands-config/tsconfig.json | 3 +++ pnpm-lock.yaml | 3 +++ 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 config/plugin-commands-config/test/configSet.test.ts diff --git a/config/plugin-commands-config/package.json b/config/plugin-commands-config/package.json index 6921f802217..f9f2cc44493 100644 --- a/config/plugin-commands-config/package.json +++ b/config/plugin-commands-config/package.json @@ -40,7 +40,8 @@ "funding": "https://opencollective.com/pnpm", "devDependencies": { "@pnpm/logger": "^5.0.0", - "@pnpm/plugin-commands-config": "workspace:*" + "@pnpm/plugin-commands-config": "workspace:*", + "@pnpm/prepare": "workspace:*" }, "exports": { ".": "./lib/index.js" diff --git a/config/plugin-commands-config/src/configSet.ts b/config/plugin-commands-config/src/configSet.ts index 472c093c089..5b317757611 100644 --- a/config/plugin-commands-config/src/configSet.ts +++ b/config/plugin-commands-config/src/configSet.ts @@ -5,7 +5,16 @@ import { ConfigCommandOptions } from './ConfigCommandOptions' export async function configSet (opts: ConfigCommandOptions, key: string, value: string) { const configPath = opts.global ? path.join(opts.configDir, 'rc') : path.join(opts.dir, '.npmrc') - const settings = await readIniFile(configPath) + const settings = await safeReadIniFile(configPath) settings[key] = value await writeIniFile(configPath, settings) } + +async function safeReadIniFile (configPath: string) { + try { + return await readIniFile(configPath) + } catch (err: any) { // eslint-disable-line @typescript-eslint/no-explicit-any + if (err.code === 'ENOENT') return {} + throw err + } +} diff --git a/config/plugin-commands-config/test/configSet.test.ts b/config/plugin-commands-config/test/configSet.test.ts new file mode 100644 index 00000000000..f4f2f6dcea3 --- /dev/null +++ b/config/plugin-commands-config/test/configSet.test.ts @@ -0,0 +1,22 @@ +import fs from 'fs' +import path from 'path' +import { tempDir } from '@pnpm/prepare' +import { config } from '@pnpm/plugin-commands-config' + +test('install Node (and npm, npx) by exact version of Node.js', async () => { + const tmp = tempDir() + const configDir = path.join(tmp, 'global-config') + fs.mkdirSync(configDir, { recursive: true }) + fs.writeFileSync(path.join(configDir, 'rc'), 'store-dir=~/store') + + await config.handler({ + dir: process.cwd(), + configDir, + global: true, + rawConfig: {}, + }, ['set', 'fetch-retries', '1']) + + expect(fs.readFileSync(path.join(configDir, 'rc'), 'utf8')).toBe(`store-dir=~/store +fetch-retries=1 +`) +}) diff --git a/config/plugin-commands-config/tsconfig.json b/config/plugin-commands-config/tsconfig.json index 4b1ec9020f6..1da7d909ef4 100644 --- a/config/plugin-commands-config/tsconfig.json +++ b/config/plugin-commands-config/tsconfig.json @@ -9,6 +9,9 @@ "../../__typings__/**/*.d.ts" ], "references": [ + { + "path": "../../__utils__/prepare" + }, { "path": "../../cli/cli-utils" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8edbea1127c..dddef07d029 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -724,6 +724,9 @@ importers: '@pnpm/plugin-commands-config': specifier: workspace:* version: 'link:' + '@pnpm/prepare': + specifier: workspace:* + version: link:../../__utils__/prepare env/node.fetcher: dependencies: From 37605cdc6b114ea7450996e8f2e425b8bd0d9f81 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 23 Dec 2022 17:31:36 +0200 Subject: [PATCH 05/18] feat: implement the config commands --- config/plugin-commands-config/src/config.ts | 31 ++++++++----------- .../plugin-commands-config/src/configGet.ts | 5 +++ 2 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 config/plugin-commands-config/src/configGet.ts diff --git a/config/plugin-commands-config/src/config.ts b/config/plugin-commands-config/src/config.ts index 6433180f1e9..0f831122aad 100644 --- a/config/plugin-commands-config/src/config.ts +++ b/config/plugin-commands-config/src/config.ts @@ -1,6 +1,7 @@ import { docsUrl } from '@pnpm/cli-utils' import { PnpmError } from '@pnpm/error' import renderHelp from 'render-help' +import { configGet } from './configGet' import { configSet } from './configSet' import { ConfigCommandOptions } from './ConfigCommandOptions' @@ -24,18 +25,12 @@ export function help () { title: 'Commands', list: [ { - description: 'Installs the specified version of Node.js. The npm CLI bundled with the given Node.js version gets installed as well.', - name: 'use', + description: 'Sets the config key to the value provided', + name: 'set', }, { - description: 'Removes the specified version of Node.js.', - name: 'remove', - shortAlias: 'rm', - }, - { - description: 'List Node.js versions available locally or remotely', - name: 'list', - shortAlias: 'ls', + description: 'Print the config value for the provided key', + name: 'get', }, ], }, @@ -43,27 +38,24 @@ export function help () { title: 'Options', list: [ { - description: 'Manages Node.js versions globally', + description: 'Sets the configuration in the global config file', name: '--global', shortAlias: '-g', }, - { - description: 'List the remote versions of Node.js', - name: '--remote', - }, ], }, ], - url: docsUrl('env'), + url: docsUrl('config'), usages: [ 'pnpm config set ', + 'pnpm config get ', ], }) } export async function handler (opts: ConfigCommandOptions, params: string[]) { if (params.length === 0) { - throw new PnpmError('ENV_NO_SUBCOMMAND', 'Please specify the subcommand', { + throw new PnpmError('CONFIG_NO_SUBCOMMAND', 'Please specify the subcommand', { hint: help(), }) } @@ -71,8 +63,11 @@ export async function handler (opts: ConfigCommandOptions, params: string[]) { case 'set': { return configSet(opts, params[1], params[2]) } + case 'get': { + return configGet(opts, params[1]) + } default: { - throw new PnpmError('ENV_UNKNOWN_SUBCOMMAND', 'This subcommand is not known') + throw new PnpmError('CONFIG_UNKNOWN_SUBCOMMAND', 'This subcommand is not known') } } } diff --git a/config/plugin-commands-config/src/configGet.ts b/config/plugin-commands-config/src/configGet.ts new file mode 100644 index 00000000000..552686da00f --- /dev/null +++ b/config/plugin-commands-config/src/configGet.ts @@ -0,0 +1,5 @@ +import { ConfigCommandOptions } from './ConfigCommandOptions' + +export function configGet (opts: ConfigCommandOptions, key: string) { + return opts.rawConfig[key] +} From dad035749a3528be3eccd2524b4ea040d5bc258a Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 23 Dec 2022 18:38:17 +0200 Subject: [PATCH 06/18] feat: implement the config commands --- config/config/package.json | 2 +- config/config/src/index.ts | 7 ++++--- .../src/ConfigCommandOptions.ts | 1 + config/plugin-commands-config/src/configGet.ts | 5 ++++- pnpm-lock.yaml | 16 +++++++++++++--- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/config/config/package.json b/config/config/package.json index 7ee84bf9cd0..e4c6f33dbcd 100644 --- a/config/config/package.json +++ b/config/config/package.json @@ -37,7 +37,7 @@ "@pnpm/error": "workspace:*", "@pnpm/git-utils": "workspace:*", "@pnpm/matcher": "workspace:*", - "@pnpm/npm-conf": "2.0.4", + "@pnpm/npm-conf": "2.1.0", "@pnpm/pnpmfile": "workspace:*", "@pnpm/read-project-manifest": "workspace:*", "@pnpm/types": "workspace:*", diff --git a/config/config/src/index.ts b/config/config/src/index.ts index 4543c04bb36..fb284c475d2 100644 --- a/config/config/src/index.ts +++ b/config/config/src/index.ts @@ -175,6 +175,10 @@ export async function getConfig ( cliOptions.dir = await realpathMissing(cliOptions.dir) cliOptions['prefix'] = cliOptions.dir // the npm config system still expects `prefix` } + if (!cliOptions.configDir) { + cliOptions.configDir = getConfigDir(process) + } + cliOptions['globalPnpmConfig'] = path.join(cliOptions.configDir as string, 'rc') const rcOptionsTypes = { ...types, ...opts.rcOptionsTypes } const { config: npmConfig, warnings, failedToLoadBuiltInConfig } = loadNpmConf(cliOptions, rcOptionsTypes, { 'auto-install-peers': false, @@ -428,9 +432,6 @@ export async function getConfig ( if (!pnpmConfig.stateDir) { pnpmConfig.stateDir = getStateDir(process) } - if (!pnpmConfig.configDir) { - pnpmConfig.configDir = getConfigDir(process) - } if (pnpmConfig['hoist'] === false) { delete pnpmConfig.hoistPattern } diff --git a/config/plugin-commands-config/src/ConfigCommandOptions.ts b/config/plugin-commands-config/src/ConfigCommandOptions.ts index 570c3d2d35d..247f0e1baee 100644 --- a/config/plugin-commands-config/src/ConfigCommandOptions.ts +++ b/config/plugin-commands-config/src/ConfigCommandOptions.ts @@ -5,4 +5,5 @@ export type ConfigCommandOptions = Pick diff --git a/config/plugin-commands-config/src/configGet.ts b/config/plugin-commands-config/src/configGet.ts index 552686da00f..80608fc12ec 100644 --- a/config/plugin-commands-config/src/configGet.ts +++ b/config/plugin-commands-config/src/configGet.ts @@ -1,5 +1,8 @@ import { ConfigCommandOptions } from './ConfigCommandOptions' export function configGet (opts: ConfigCommandOptions, key: string) { - return opts.rawConfig[key] + if (opts.global) { + return opts.rawConfig[key] + } + return opts.rawLocalConfig[key] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dddef07d029..1c3033052f5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -541,8 +541,8 @@ importers: specifier: workspace:* version: link:../matcher '@pnpm/npm-conf': - specifier: 2.0.4 - version: 2.0.4 + specifier: 2.1.0 + version: 2.1.0 '@pnpm/pnpmfile': specifier: workspace:* version: link:../../hooks/pnpmfile @@ -7923,6 +7923,16 @@ packages: '@pnpm/config.env-replace': 1.0.0 '@pnpm/network.ca-file': 1.0.2 config-chain: 1.1.13 + dev: true + + /@pnpm/npm-conf/2.1.0: + resolution: {integrity: sha512-Oe6ntvgsMTE3hDIqy6sajqHF+MnzJrOF06qC2QSiUEybLL7cp6tjoKUa32gpd9+KPVl4QyMs3E3nsXrx/Vdnlw==} + engines: {node: '>=12'} + dependencies: + '@pnpm/config.env-replace': 1.0.0 + '@pnpm/network.ca-file': 1.0.2 + config-chain: 1.1.13 + dev: false /@pnpm/npm-lifecycle/2.0.0_typanion@3.12.1: resolution: {integrity: sha512-613qs9UwSFFVhXPv94Rt3tpJGv/D6mkHkZsByhHgBJII9gJXQ+bq4uru8y5q5g/kggS0raNH+18YGd9eu0Nawg==} @@ -17457,7 +17467,7 @@ time: /@pnpm/meta-updater/0.2.2: '2022-11-18T12:00:42.706Z' /@pnpm/network.agent/0.0.4: '2022-11-21T01:38:39.074Z' /@pnpm/nopt/0.2.1: '2021-06-01T19:45:54.552Z' - /@pnpm/npm-conf/2.0.4: '2022-11-11T20:26:48.028Z' + /@pnpm/npm-conf/2.1.0: '2022-12-23T16:08:03.626Z' /@pnpm/npm-lifecycle/2.0.0: '2022-11-30T19:58:42.868Z' /@pnpm/npm-package-arg/1.0.0: '2022-06-28T12:48:31.287Z' /@pnpm/os.env.path-extender/0.2.8: '2022-11-21T01:38:43.315Z' From 67c238dc51f5be05e859f57e68f6fe090f0d31e2 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 23 Dec 2022 18:46:11 +0200 Subject: [PATCH 07/18] feat: implement the config commands --- config/plugin-commands-config/src/config.ts | 12 ++++++++++-- config/plugin-commands-config/src/configSet.ts | 9 +++++++-- config/plugin-commands-config/test/configSet.test.ts | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/config/plugin-commands-config/src/config.ts b/config/plugin-commands-config/src/config.ts index 0f831122aad..5b982f5f072 100644 --- a/config/plugin-commands-config/src/config.ts +++ b/config/plugin-commands-config/src/config.ts @@ -25,13 +25,17 @@ export function help () { title: 'Commands', list: [ { - description: 'Sets the config key to the value provided', + description: 'Set the config key to the value provided', name: 'set', }, { description: 'Print the config value for the provided key', name: 'get', }, + { + description: 'Remove the config key from the config file', + name: 'delete', + }, ], }, { @@ -49,6 +53,7 @@ export function help () { usages: [ 'pnpm config set ', 'pnpm config get ', + 'pnpm config delete ', ], }) } @@ -61,11 +66,14 @@ export async function handler (opts: ConfigCommandOptions, params: string[]) { } switch (params[0]) { case 'set': { - return configSet(opts, params[1], params[2]) + return configSet(opts, params[1], params[2] ?? '') } case 'get': { return configGet(opts, params[1]) } + case 'delete': { + return configSet(opts, params[1], null) + } default: { throw new PnpmError('CONFIG_UNKNOWN_SUBCOMMAND', 'This subcommand is not known') } diff --git a/config/plugin-commands-config/src/configSet.ts b/config/plugin-commands-config/src/configSet.ts index 5b317757611..a5b6db430a8 100644 --- a/config/plugin-commands-config/src/configSet.ts +++ b/config/plugin-commands-config/src/configSet.ts @@ -3,10 +3,15 @@ import readIniFile from 'read-ini-file' import writeIniFile from 'write-ini-file' import { ConfigCommandOptions } from './ConfigCommandOptions' -export async function configSet (opts: ConfigCommandOptions, key: string, value: string) { +export async function configSet (opts: ConfigCommandOptions, key: string, value: string | null) { const configPath = opts.global ? path.join(opts.configDir, 'rc') : path.join(opts.dir, '.npmrc') const settings = await safeReadIniFile(configPath) - settings[key] = value + if (value == null) { + if (settings[key] == null) return + delete settings[key] + } else { + settings[key] = value + } await writeIniFile(configPath, settings) } diff --git a/config/plugin-commands-config/test/configSet.test.ts b/config/plugin-commands-config/test/configSet.test.ts index f4f2f6dcea3..0a53d1b055a 100644 --- a/config/plugin-commands-config/test/configSet.test.ts +++ b/config/plugin-commands-config/test/configSet.test.ts @@ -14,6 +14,7 @@ test('install Node (and npm, npx) by exact version of Node.js', async () => { configDir, global: true, rawConfig: {}, + rawLocalConfig: {}, }, ['set', 'fetch-retries', '1']) expect(fs.readFileSync(path.join(configDir, 'rc'), 'utf8')).toBe(`store-dir=~/store From b57f14970e816c321edf8911635ea85e84065806 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 23 Dec 2022 20:53:00 +0200 Subject: [PATCH 08/18] test: fix --- pnpm/test/cli.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pnpm/test/cli.ts b/pnpm/test/cli.ts index fdd0ef0e446..89fc4c957d0 100644 --- a/pnpm/test/cli.ts +++ b/pnpm/test/cli.ts @@ -50,13 +50,6 @@ test('pnpm import does not move modules created by npm', async () => { expect(packageManifestInodeBefore).toBe(packageManifestInodeAfter) }) -test('pass through to npm CLI for commands that are not supported by npm', () => { - const result = execPnpmSync(['config', 'get', 'user-agent']) - - expect(result.status).toBe(0) - expect(result.stdout.toString()).toMatch(/npm\//) // command returned correct result -}) - test('pass through to npm with all the args', async () => { prepare() await rimraf('package.json') From 4e771b901c9b372e048f58b39131d95db9648ae3 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 23 Dec 2022 22:25:33 +0200 Subject: [PATCH 09/18] test: fix --- __typings__/local.d.ts | 5 ---- __typings__/typed.d.ts | 5 ---- config/config/package.json | 2 +- config/config/src/readLocalConfig.ts | 2 +- config/plugin-commands-config/package.json | 4 +-- .../plugin-commands-config/src/configSet.ts | 4 +-- .../test/configSet.test.ts | 8 +++-- pnpm-lock.yaml | 30 ++++++++++++------- 8 files changed, 31 insertions(+), 29 deletions(-) diff --git a/__typings__/local.d.ts b/__typings__/local.d.ts index f143741241c..2ac66fa0a99 100644 --- a/__typings__/local.d.ts +++ b/__typings__/local.d.ts @@ -151,11 +151,6 @@ declare module 'string.prototype.replaceall' { export = anything } -declare module 'write-ini-file' { - const anything: any - export = anything -} - declare module 'ramda/src/map' { function map (fn: (x: V) => U, obj: Record): Record export = map diff --git a/__typings__/typed.d.ts b/__typings__/typed.d.ts index c033485b80b..84390303f75 100644 --- a/__typings__/typed.d.ts +++ b/__typings__/typed.d.ts @@ -20,11 +20,6 @@ declare module 'path-name' { export = pathname; } -declare module 'read-ini-file' { - function readIniFile (filename: string): Promise; - export = readIniFile; -} - declare module 'right-pad' { function rightPad (txt: string, size: number): string; export = rightPad; diff --git a/config/config/package.json b/config/config/package.json index e4c6f33dbcd..5a22e2b8d9a 100644 --- a/config/config/package.json +++ b/config/config/package.json @@ -50,7 +50,7 @@ "path-absolute": "^1.0.1", "path-name": "^1.0.0", "ramda": "npm:@pnpm/ramda@0.28.1", - "read-ini-file": "^3.1.0", + "read-ini-file": "4.0.0", "realpath-missing": "^1.1.0", "which": "^3.0.0" }, diff --git a/config/config/src/readLocalConfig.ts b/config/config/src/readLocalConfig.ts index 1965cb81367..611ec377032 100644 --- a/config/config/src/readLocalConfig.ts +++ b/config/config/src/readLocalConfig.ts @@ -1,7 +1,7 @@ import path from 'path' import camelcaseKeys from 'camelcase-keys' import { envReplace } from '@pnpm/config.env-replace' -import readIniFile from 'read-ini-file' +import { readIniFile } from 'read-ini-file' export async function readLocalConfig (prefix: string) { try { diff --git a/config/plugin-commands-config/package.json b/config/plugin-commands-config/package.json index f9f2cc44493..8bb068dbcf7 100644 --- a/config/plugin-commands-config/package.json +++ b/config/plugin-commands-config/package.json @@ -33,9 +33,9 @@ "@pnpm/cli-utils": "workspace:*", "@pnpm/config": "workspace:*", "@pnpm/error": "workspace:*", - "read-ini-file": "^3.1.0", + "read-ini-file": "4.0.0", "render-help": "^1.0.2", - "write-ini-file": "4.0.0" + "write-ini-file": "4.0.1" }, "funding": "https://opencollective.com/pnpm", "devDependencies": { diff --git a/config/plugin-commands-config/src/configSet.ts b/config/plugin-commands-config/src/configSet.ts index a5b6db430a8..9451411be9c 100644 --- a/config/plugin-commands-config/src/configSet.ts +++ b/config/plugin-commands-config/src/configSet.ts @@ -1,6 +1,6 @@ import path from 'path' -import readIniFile from 'read-ini-file' -import writeIniFile from 'write-ini-file' +import { readIniFile } from 'read-ini-file' +import { writeIniFile } from 'write-ini-file' import { ConfigCommandOptions } from './ConfigCommandOptions' export async function configSet (opts: ConfigCommandOptions, key: string, value: string | null) { diff --git a/config/plugin-commands-config/test/configSet.test.ts b/config/plugin-commands-config/test/configSet.test.ts index 0a53d1b055a..1b62c8a4b2b 100644 --- a/config/plugin-commands-config/test/configSet.test.ts +++ b/config/plugin-commands-config/test/configSet.test.ts @@ -2,6 +2,7 @@ import fs from 'fs' import path from 'path' import { tempDir } from '@pnpm/prepare' import { config } from '@pnpm/plugin-commands-config' +import { readIniFileSync } from 'read-ini-file' test('install Node (and npm, npx) by exact version of Node.js', async () => { const tmp = tempDir() @@ -17,7 +18,8 @@ test('install Node (and npm, npx) by exact version of Node.js', async () => { rawLocalConfig: {}, }, ['set', 'fetch-retries', '1']) - expect(fs.readFileSync(path.join(configDir, 'rc'), 'utf8')).toBe(`store-dir=~/store -fetch-retries=1 -`) + expect(readIniFileSync(path.join(configDir, 'rc'))).toEqual({ + 'store-dir': '~/store', + 'fetch-retries': '1', + }) }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1c3033052f5..7c26fe10c37 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -580,8 +580,8 @@ importers: specifier: npm:@pnpm/ramda@0.28.1 version: /@pnpm/ramda/0.28.1 read-ini-file: - specifier: ^3.1.0 - version: 3.1.0 + specifier: 4.0.0 + version: 4.0.0 realpath-missing: specifier: ^1.1.0 version: 1.1.0 @@ -709,14 +709,14 @@ importers: specifier: workspace:* version: link:../../packages/error read-ini-file: - specifier: ^3.1.0 - version: 3.1.0 + specifier: 4.0.0 + version: 4.0.0 render-help: specifier: ^1.0.2 version: 1.0.2 write-ini-file: - specifier: 4.0.0 - version: 4.0.0 + specifier: 4.0.1 + version: 4.0.1 devDependencies: '@pnpm/logger': specifier: ^5.0.0 @@ -12401,6 +12401,7 @@ packages: /ini/2.0.0: resolution: {integrity: sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA==} engines: {node: '>=10'} + dev: true /ini/3.0.1: resolution: {integrity: sha512-it4HyVAUTKBc6m8e1iXWvXSTdndF7HbdN713+kvLrymxTaU4AUBWrJ4vEooP+V7fexnVD3LKcBshjGGPefSMUQ==} @@ -15258,6 +15259,15 @@ packages: dependencies: ini: 2.0.0 strip-bom: 4.0.0 + dev: true + + /read-ini-file/4.0.0: + resolution: {integrity: sha512-zz4qv/sKETv7nAkATqSJ9YMbKD8NXRPuA8d17VdYCuNYrVstB1S6UAMU6aytf5vRa9MESbZN7jLZdcmrOxz4gg==} + engines: {node: '>=14.6'} + dependencies: + ini: 3.0.1 + strip-bom: 4.0.0 + dev: false /read-pkg-up/7.0.1: resolution: {integrity: sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg==} @@ -17243,8 +17253,8 @@ packages: imurmurhash: 0.1.4 signal-exit: 3.0.7 - /write-ini-file/4.0.0: - resolution: {integrity: sha512-o43++IKaOeIxjxflvFH4BQvkpDsiqqH2I6qsz8Az2uyWAq0Gw6Mrc2JYSmGKoARE9j7jz/X/hTmPZi6B1XKT8g==} + /write-ini-file/4.0.1: + resolution: {integrity: sha512-8XPBFS/EqPls2V4vYSc8kPVXjLg2b0GgVVC52w2WEH4sVDXew9rgch60ckXLiTfiYQKmkxezRaRctbGQr7oj5Q==} engines: {node: '>=14.6'} dependencies: ini: 3.0.1 @@ -17636,7 +17646,7 @@ time: /proxyquire/2.1.3: '2019-08-12T13:54:46.049Z' /ps-list/7.2.0: '2020-06-17T09:02:36.119Z' /publish-packed/4.1.1: '2022-01-04T09:56:54.476Z' - /read-ini-file/3.1.0: '2021-02-11T22:53:37.619Z' + /read-ini-file/4.0.0: '2022-12-23T20:19:57.971Z' /read-yaml-file/2.1.0: '2021-02-11T22:53:46.064Z' /realpath-missing/1.1.0: '2021-02-11T22:53:50.718Z' /remark-parse/9.0.0: '2020-10-14T08:48:35.392Z' @@ -17688,7 +17698,7 @@ time: /which/3.0.0: '2022-11-01T19:20:24.475Z' /wrap-ansi/7.0.0: '2020-04-22T16:53:23.889Z' /write-file-atomic/5.0.0: '2022-10-14T05:22:38.937Z' - /write-ini-file/4.0.0: '2022-12-23T13:45:29.905Z' + /write-ini-file/4.0.1: '2022-12-23T20:19:59.977Z' /write-json-file/4.3.0: '2020-02-07T08:54:49.528Z' /write-json5-file/3.1.0: '2021-02-11T22:54:24.439Z' /write-pkg/4.0.0: '2019-04-29T10:37:09.855Z' From 3078f5e565a40beff8e478713b153b6cddbf0ba7 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 24 Dec 2022 01:45:41 +0200 Subject: [PATCH 10/18] test: config --- .../test/configDelete.test.ts | 25 +++++++++++++++++ .../test/configGet.test.ts | 28 +++++++++++++++++++ .../test/configSet.test.ts | 2 +- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 config/plugin-commands-config/test/configDelete.test.ts create mode 100644 config/plugin-commands-config/test/configGet.test.ts diff --git a/config/plugin-commands-config/test/configDelete.test.ts b/config/plugin-commands-config/test/configDelete.test.ts new file mode 100644 index 00000000000..5364d90ec8a --- /dev/null +++ b/config/plugin-commands-config/test/configDelete.test.ts @@ -0,0 +1,25 @@ +import fs from 'fs' +import path from 'path' +import { tempDir } from '@pnpm/prepare' +import { config } from '@pnpm/plugin-commands-config' +import { readIniFileSync } from 'read-ini-file' + +test('config delete', async () => { + const tmp = tempDir() + const configDir = path.join(tmp, 'global-config') + fs.mkdirSync(configDir, { recursive: true }) + fs.writeFileSync(path.join(configDir, 'rc'), `store-dir=~/store +cache-dir=~/cache`) + + await config.handler({ + dir: process.cwd(), + configDir, + global: true, + rawConfig: {}, + rawLocalConfig: {}, + }, ['delete', 'store-dir']) + + expect(readIniFileSync(path.join(configDir, 'rc'))).toEqual({ + 'cache-dir': '~/cache', + }) +}) diff --git a/config/plugin-commands-config/test/configGet.test.ts b/config/plugin-commands-config/test/configGet.test.ts new file mode 100644 index 00000000000..c5fcee397a0 --- /dev/null +++ b/config/plugin-commands-config/test/configGet.test.ts @@ -0,0 +1,28 @@ +import { config } from '@pnpm/plugin-commands-config' + +test('config get --global', async () => { + const configKey = await config.handler({ + dir: process.cwd(), + configDir: process.cwd(), + global: true, + rawConfig: { + 'store-dir': '~/store', + }, + rawLocalConfig: {}, + }, ['get', 'store-dir']) + + expect(configKey).toEqual('~/store') +}) + +test('config get', async () => { + const configKey = await config.handler({ + dir: process.cwd(), + configDir: process.cwd(), + rawConfig: {}, + rawLocalConfig: { + 'fetch-retries': '2', + }, + }, ['get', 'fetch-retries']) + + expect(configKey).toEqual('2') +}) diff --git a/config/plugin-commands-config/test/configSet.test.ts b/config/plugin-commands-config/test/configSet.test.ts index 1b62c8a4b2b..6905c764af3 100644 --- a/config/plugin-commands-config/test/configSet.test.ts +++ b/config/plugin-commands-config/test/configSet.test.ts @@ -4,7 +4,7 @@ import { tempDir } from '@pnpm/prepare' import { config } from '@pnpm/plugin-commands-config' import { readIniFileSync } from 'read-ini-file' -test('install Node (and npm, npx) by exact version of Node.js', async () => { +test('config set', async () => { const tmp = tempDir() const configDir = path.join(tmp, 'global-config') fs.mkdirSync(configDir, { recursive: true }) From 25c6379127ea683d0ce10589deeb8f77df4016fd Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 24 Dec 2022 02:19:17 +0200 Subject: [PATCH 11/18] feat: config list --- config/plugin-commands-config/package.json | 5 ++- .../src/ConfigCommandOptions.ts | 2 +- config/plugin-commands-config/src/config.ts | 10 ++++++ .../plugin-commands-config/src/configList.ts | 11 ++++++ .../test/configList.test.ts | 35 +++++++++++++++++++ pnpm-lock.yaml | 15 ++++++++ 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 config/plugin-commands-config/src/configList.ts create mode 100644 config/plugin-commands-config/test/configList.test.ts diff --git a/config/plugin-commands-config/package.json b/config/plugin-commands-config/package.json index 8bb068dbcf7..fb920aa38a1 100644 --- a/config/plugin-commands-config/package.json +++ b/config/plugin-commands-config/package.json @@ -33,15 +33,18 @@ "@pnpm/cli-utils": "workspace:*", "@pnpm/config": "workspace:*", "@pnpm/error": "workspace:*", + "ini": "3.0.1", "read-ini-file": "4.0.0", "render-help": "^1.0.2", + "sort-keys": "^4.2.0", "write-ini-file": "4.0.1" }, "funding": "https://opencollective.com/pnpm", "devDependencies": { "@pnpm/logger": "^5.0.0", "@pnpm/plugin-commands-config": "workspace:*", - "@pnpm/prepare": "workspace:*" + "@pnpm/prepare": "workspace:*", + "@types/ini": "1.3.31" }, "exports": { ".": "./lib/index.js" diff --git a/config/plugin-commands-config/src/ConfigCommandOptions.ts b/config/plugin-commands-config/src/ConfigCommandOptions.ts index 247f0e1baee..5d2945e74fb 100644 --- a/config/plugin-commands-config/src/ConfigCommandOptions.ts +++ b/config/plugin-commands-config/src/ConfigCommandOptions.ts @@ -6,4 +6,4 @@ export type ConfigCommandOptions = Pick +> & { json?: boolean } diff --git a/config/plugin-commands-config/src/config.ts b/config/plugin-commands-config/src/config.ts index 5b982f5f072..8a72533c071 100644 --- a/config/plugin-commands-config/src/config.ts +++ b/config/plugin-commands-config/src/config.ts @@ -3,6 +3,7 @@ import { PnpmError } from '@pnpm/error' import renderHelp from 'render-help' import { configGet } from './configGet' import { configSet } from './configSet' +import { configList } from './configList' import { ConfigCommandOptions } from './ConfigCommandOptions' export function rcOptionsTypes () { @@ -12,6 +13,7 @@ export function rcOptionsTypes () { export function cliOptionsTypes () { return { global: Boolean, + json: Boolean, } } @@ -36,6 +38,10 @@ export function help () { description: 'Remove the config key from the config file', name: 'delete', }, + { + description: 'Show all the config settings', + name: 'list', + }, ], }, { @@ -54,6 +60,7 @@ export function help () { 'pnpm config set ', 'pnpm config get ', 'pnpm config delete ', + 'pnpm config list', ], }) } @@ -74,6 +81,9 @@ export async function handler (opts: ConfigCommandOptions, params: string[]) { case 'delete': { return configSet(opts, params[1], null) } + case 'list': { + return configList(opts) + } default: { throw new PnpmError('CONFIG_UNKNOWN_SUBCOMMAND', 'This subcommand is not known') } diff --git a/config/plugin-commands-config/src/configList.ts b/config/plugin-commands-config/src/configList.ts new file mode 100644 index 00000000000..8d808e90ad0 --- /dev/null +++ b/config/plugin-commands-config/src/configList.ts @@ -0,0 +1,11 @@ +import { encode } from 'ini' +import sortKeys from 'sort-keys' +import { ConfigCommandOptions } from './ConfigCommandOptions' + +export async function configList (opts: ConfigCommandOptions) { + const sortedConfig = sortKeys(opts.rawConfig) + if (opts.json) { + return JSON.stringify(sortedConfig, null, 2) + } + return encode(sortedConfig) +} diff --git a/config/plugin-commands-config/test/configList.test.ts b/config/plugin-commands-config/test/configList.test.ts new file mode 100644 index 00000000000..9ac5e74555d --- /dev/null +++ b/config/plugin-commands-config/test/configList.test.ts @@ -0,0 +1,35 @@ +import { config } from '@pnpm/plugin-commands-config' + +test('config list', async () => { + const output = await config.handler({ + dir: process.cwd(), + configDir: process.cwd(), + rawConfig: { + 'store-dir': '~/store', + 'fetch-retries': '2', + }, + rawLocalConfig: {}, + }, ['list']) + + expect(output).toEqual(`fetch-retries=2 +store-dir=~/store +`) +}) + +test('config list --json', async () => { + const output = await config.handler({ + dir: process.cwd(), + configDir: process.cwd(), + json: true, + rawConfig: { + 'store-dir': '~/store', + 'fetch-retries': '2', + }, + rawLocalConfig: {}, + }, ['list']) + + expect(output).toEqual(JSON.stringify({ + 'fetch-retries': '2', + 'store-dir': '~/store', + }, null, 2)) +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7c26fe10c37..eed90c024a8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -708,12 +708,18 @@ importers: '@pnpm/error': specifier: workspace:* version: link:../../packages/error + ini: + specifier: 3.0.1 + version: 3.0.1 read-ini-file: specifier: 4.0.0 version: 4.0.0 render-help: specifier: ^1.0.2 version: 1.0.2 + sort-keys: + specifier: ^4.2.0 + version: 4.2.0 write-ini-file: specifier: 4.0.1 version: 4.0.1 @@ -727,6 +733,9 @@ importers: '@pnpm/prepare': specifier: workspace:* version: link:../../__utils__/prepare + '@types/ini': + specifier: 1.3.31 + version: 1.3.31 env/node.fetcher: dependencies: @@ -8567,6 +8576,10 @@ packages: /@types/http-cache-semantics/4.0.1: resolution: {integrity: sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==} + /@types/ini/1.3.31: + resolution: {integrity: sha512-8ecxxaG4AlVEM1k9+BsziMw8UsX0qy3jYI1ad/71RrDZ+rdL6aZB0wLfAuflQiDhkD5o4yJ0uPK3OSUic3fG0w==} + dev: true + /@types/is-ci/3.0.0: resolution: {integrity: sha512-Q0Op0hdWbYd1iahB+IFNQcWXFq4O0Q5MwQP7uN0souuQ4rPg1vEYcnIOfr1gY+M+6rc8FGoRaBO1mOOvL29sEQ==} dependencies: @@ -17495,6 +17508,7 @@ time: /@types/fs-extra/9.0.13: '2021-09-21T19:02:27.512Z' /@types/graceful-fs/4.1.5: '2021-02-11T21:49:02.172Z' /@types/hosted-git-info/3.0.2: '2021-07-06T21:35:19.353Z' + /@types/ini/1.3.31: '2021-10-07T21:01:49.672Z' /@types/is-ci/3.0.0: '2021-03-07T11:49:37.729Z' /@types/is-windows/1.0.0: '2019-11-19T19:37:55.992Z' /@types/isexe/2.0.1: '2021-07-06T21:42:29.330Z' @@ -17592,6 +17606,7 @@ time: /graceful-git/3.1.2: '2021-09-16T00:23:26.185Z' /husky/8.0.2: '2022-11-08T03:41:05.629Z' /hyperdrive-schemas/2.0.0: '2020-07-14T11:16:33.671Z' + /ini/3.0.1: '2022-08-22T17:22:43.830Z' /is-ci/3.0.1: '2021-10-26T04:02:03.835Z' /is-inner-link/4.0.0: '2021-02-11T22:54:33.386Z' /is-port-reachable/3.0.0: '2019-11-12T09:49:42.096Z' From 9d877abf1082342429d5140dbac77a76575d740a Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 24 Dec 2022 03:16:46 +0200 Subject: [PATCH 12/18] feat: short aliases for get/set config --- config/plugin-commands-config/src/get.ts | 12 ++++++++++++ config/plugin-commands-config/src/index.ts | 4 +++- config/plugin-commands-config/src/set.ts | 12 ++++++++++++ pnpm/src/cmd/index.ts | 4 +++- pnpm/src/pnpm.ts | 2 -- 5 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 config/plugin-commands-config/src/get.ts create mode 100644 config/plugin-commands-config/src/set.ts diff --git a/config/plugin-commands-config/src/get.ts b/config/plugin-commands-config/src/get.ts new file mode 100644 index 00000000000..98759472227 --- /dev/null +++ b/config/plugin-commands-config/src/get.ts @@ -0,0 +1,12 @@ +import * as configCmd from './config' +import { ConfigCommandOptions } from './ConfigCommandOptions' + +export const rcOptionsTypes = configCmd.rcOptionsTypes +export const cliOptionsTypes = configCmd.cliOptionsTypes +export const help = configCmd.help + +export const commandNames = ['get'] + +export async function handler (opts: ConfigCommandOptions, params: string[]) { + return configCmd.handler(opts, ['get', ...params]) +} diff --git a/config/plugin-commands-config/src/index.ts b/config/plugin-commands-config/src/index.ts index 3ece161e58d..be79d4cc973 100644 --- a/config/plugin-commands-config/src/index.ts +++ b/config/plugin-commands-config/src/index.ts @@ -1,3 +1,5 @@ import * as config from './config' +import * as getCommand from './get' +import * as setCommand from './set' -export { config } +export { config, getCommand, setCommand } diff --git a/config/plugin-commands-config/src/set.ts b/config/plugin-commands-config/src/set.ts new file mode 100644 index 00000000000..fc360d66321 --- /dev/null +++ b/config/plugin-commands-config/src/set.ts @@ -0,0 +1,12 @@ +import * as configCmd from './config' +import { ConfigCommandOptions } from './ConfigCommandOptions' + +export const rcOptionsTypes = configCmd.rcOptionsTypes +export const cliOptionsTypes = configCmd.cliOptionsTypes +export const help = configCmd.help + +export const commandNames = ['set'] + +export async function handler (opts: ConfigCommandOptions, params: string[]) { + return configCmd.handler(opts, ['set', ...params]) +} diff --git a/pnpm/src/cmd/index.ts b/pnpm/src/cmd/index.ts index fd931d39708..d143740dd87 100644 --- a/pnpm/src/cmd/index.ts +++ b/pnpm/src/cmd/index.ts @@ -1,7 +1,7 @@ import { CompletionFunc } from '@pnpm/command' import { types as allTypes } from '@pnpm/config' import { audit } from '@pnpm/plugin-commands-audit' -import { config } from '@pnpm/plugin-commands-config' +import { config, getCommand, setCommand } from '@pnpm/plugin-commands-config' import { doctor } from '@pnpm/plugin-commands-doctor' import { env } from '@pnpm/plugin-commands-env' import { deploy } from '@pnpm/plugin-commands-deploy' @@ -101,6 +101,8 @@ const commands: CommandDefinition[] = [ audit, bin, config, + getCommand, + setCommand, create, deploy, dlx, diff --git a/pnpm/src/pnpm.ts b/pnpm/src/pnpm.ts index 13e74b324a0..2fc9d6d1e6b 100644 --- a/pnpm/src/pnpm.ts +++ b/pnpm/src/pnpm.ts @@ -32,7 +32,6 @@ const argv = process.argv.slice(2) case 'dist-tag': case 'docs': case 'edit': - case 'get': case 'info': case 'login': case 'logout': @@ -45,7 +44,6 @@ const argv = process.argv.slice(2) case 's': case 'se': case 'search': - case 'set': case 'set-script': case 'star': case 'stars': From e7b5a50d1a11a6c7751e09e3975b0ccfc68d222d Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 24 Dec 2022 03:43:03 +0200 Subject: [PATCH 13/18] fix: global get --- .../src/ConfigCommandOptions.ts | 1 - config/plugin-commands-config/src/configGet.ts | 5 +---- .../plugin-commands-config/test/configGet.test.ts | 15 +-------------- 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/config/plugin-commands-config/src/ConfigCommandOptions.ts b/config/plugin-commands-config/src/ConfigCommandOptions.ts index 5d2945e74fb..661b0815d53 100644 --- a/config/plugin-commands-config/src/ConfigCommandOptions.ts +++ b/config/plugin-commands-config/src/ConfigCommandOptions.ts @@ -5,5 +5,4 @@ export type ConfigCommandOptions = Pick & { json?: boolean } diff --git a/config/plugin-commands-config/src/configGet.ts b/config/plugin-commands-config/src/configGet.ts index 80608fc12ec..552686da00f 100644 --- a/config/plugin-commands-config/src/configGet.ts +++ b/config/plugin-commands-config/src/configGet.ts @@ -1,8 +1,5 @@ import { ConfigCommandOptions } from './ConfigCommandOptions' export function configGet (opts: ConfigCommandOptions, key: string) { - if (opts.global) { - return opts.rawConfig[key] - } - return opts.rawLocalConfig[key] + return opts.rawConfig[key] } diff --git a/config/plugin-commands-config/test/configGet.test.ts b/config/plugin-commands-config/test/configGet.test.ts index c5fcee397a0..d9303d1bbef 100644 --- a/config/plugin-commands-config/test/configGet.test.ts +++ b/config/plugin-commands-config/test/configGet.test.ts @@ -1,6 +1,6 @@ import { config } from '@pnpm/plugin-commands-config' -test('config get --global', async () => { +test('config get', async () => { const configKey = await config.handler({ dir: process.cwd(), configDir: process.cwd(), @@ -13,16 +13,3 @@ test('config get --global', async () => { expect(configKey).toEqual('~/store') }) - -test('config get', async () => { - const configKey = await config.handler({ - dir: process.cwd(), - configDir: process.cwd(), - rawConfig: {}, - rawLocalConfig: { - 'fetch-retries': '2', - }, - }, ['get', 'fetch-retries']) - - expect(configKey).toEqual('2') -}) From 3cd1726c62c0b5070239bd9bdb25a2ff19025a2f Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 24 Dec 2022 04:10:13 +0200 Subject: [PATCH 14/18] docs: add changesets --- .changeset/perfect-squids-count.md | 16 ++++++++++++++++ .changeset/tiny-chicken-train.md | 6 ++++++ config/config/package.json | 2 +- config/config/src/index.ts | 15 ++++++++++----- pnpm-lock.yaml | 19 +++++++++---------- 5 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 .changeset/perfect-squids-count.md create mode 100644 .changeset/tiny-chicken-train.md diff --git a/.changeset/perfect-squids-count.md b/.changeset/perfect-squids-count.md new file mode 100644 index 00000000000..ae1a4be4bf3 --- /dev/null +++ b/.changeset/perfect-squids-count.md @@ -0,0 +1,16 @@ +--- +"@pnpm/plugin-commands-config": major +"pnpm": minor +--- + +pnpm gets its own implementation of the following commands: + +* `pnpm config get` +* `pnpm config set` +* `pnpm config delete` +* `pnpm config list` + +In previous versions these commands were passing through to npm CLI. + +PR: [#5829](https://github.com/pnpm/pnpm/pull/5829) +Related issue: [#5621](https://github.com/pnpm/pnpm/issues/5621) diff --git a/.changeset/tiny-chicken-train.md b/.changeset/tiny-chicken-train.md new file mode 100644 index 00000000000..c121d6142ce --- /dev/null +++ b/.changeset/tiny-chicken-train.md @@ -0,0 +1,6 @@ +--- +"@pnpm/config": minor +"pnpm": minor +--- + +pnpm reads settings from its own global configuration file at `$XDG_CONFIG_HOME/pnpm/rc` [#5829](https://github.com/pnpm/pnpm/pull/5829). diff --git a/config/config/package.json b/config/config/package.json index 5a22e2b8d9a..4cac3c857f9 100644 --- a/config/config/package.json +++ b/config/config/package.json @@ -37,7 +37,7 @@ "@pnpm/error": "workspace:*", "@pnpm/git-utils": "workspace:*", "@pnpm/matcher": "workspace:*", - "@pnpm/npm-conf": "2.1.0", + "@pnpm/npm-conf": "2.0.0", "@pnpm/pnpmfile": "workspace:*", "@pnpm/read-project-manifest": "workspace:*", "@pnpm/types": "workspace:*", diff --git a/config/config/src/index.ts b/config/config/src/index.ts index fb284c475d2..5ebc1dfe2cd 100644 --- a/config/config/src/index.ts +++ b/config/config/src/index.ts @@ -175,10 +175,6 @@ export async function getConfig ( cliOptions.dir = await realpathMissing(cliOptions.dir) cliOptions['prefix'] = cliOptions.dir // the npm config system still expects `prefix` } - if (!cliOptions.configDir) { - cliOptions.configDir = getConfigDir(process) - } - cliOptions['globalPnpmConfig'] = path.join(cliOptions.configDir as string, 'rc') const rcOptionsTypes = { ...types, ...opts.rcOptionsTypes } const { config: npmConfig, warnings, failedToLoadBuiltInConfig } = loadNpmConf(cliOptions, rcOptionsTypes, { 'auto-install-peers': false, @@ -239,7 +235,15 @@ export async function getConfig ( 'registry-supports-time-field': false, }) - npmConfig.addFile(path.resolve(path.join(__dirname, 'pnpmrc')), 'pnpm-builtin') + const configDir = getConfigDir(process) + { + const warn = npmConfig.addFile(path.join(configDir as string, 'rc'), 'pnpm-global') + if (warn) warnings.push(warn) + } + { + const warn = npmConfig.addFile(path.resolve(path.join(__dirname, 'pnpmrc')), 'pnpm-builtin') + if (warn) warnings.push(warn) + } delete cliOptions.prefix @@ -256,6 +260,7 @@ export async function getConfig ( pnpmConfig.maxSockets = npmConfig.maxsockets delete pnpmConfig['maxsockets'] + pnpmConfig.configDir = configDir pnpmConfig.workspaceDir = opts.workspaceDir pnpmConfig.workspaceRoot = cliOptions['workspace-root'] as boolean // This is needed to prevent pnpm reading workspaceRoot from env variables pnpmConfig.rawLocalConfig = Object.assign.apply(Object, [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eed90c024a8..11ef68e3782 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -541,8 +541,8 @@ importers: specifier: workspace:* version: link:../matcher '@pnpm/npm-conf': - specifier: 2.1.0 - version: 2.1.0 + specifier: 2.0.0 + version: 2.0.0 '@pnpm/pnpmfile': specifier: workspace:* version: link:../../hooks/pnpmfile @@ -7925,23 +7925,22 @@ packages: normalize-registry-url: 2.0.0 dev: true - /@pnpm/npm-conf/2.0.4: - resolution: {integrity: sha512-xWjBhnntYvAjYt1alEoFJiThMe0ZhSY7iZuxBUR+DH3tH2RyGrP2KU75NZfo/jhc3dSBUqZrd1DnIIgkQ0WyKw==} + /@pnpm/npm-conf/2.0.0: + resolution: {integrity: sha512-Ot3xJvdbRQ3fwtDeRYMik/97BbCKij9ZupSgY1tJLCzPPgYRTIIjwdOBHQX2qGbwqNeKd6EneMyKAAsUMO09Bw==} engines: {node: '>=12'} dependencies: - '@pnpm/config.env-replace': 1.0.0 '@pnpm/network.ca-file': 1.0.2 config-chain: 1.1.13 - dev: true + dev: false - /@pnpm/npm-conf/2.1.0: - resolution: {integrity: sha512-Oe6ntvgsMTE3hDIqy6sajqHF+MnzJrOF06qC2QSiUEybLL7cp6tjoKUa32gpd9+KPVl4QyMs3E3nsXrx/Vdnlw==} + /@pnpm/npm-conf/2.0.4: + resolution: {integrity: sha512-xWjBhnntYvAjYt1alEoFJiThMe0ZhSY7iZuxBUR+DH3tH2RyGrP2KU75NZfo/jhc3dSBUqZrd1DnIIgkQ0WyKw==} engines: {node: '>=12'} dependencies: '@pnpm/config.env-replace': 1.0.0 '@pnpm/network.ca-file': 1.0.2 config-chain: 1.1.13 - dev: false + dev: true /@pnpm/npm-lifecycle/2.0.0_typanion@3.12.1: resolution: {integrity: sha512-613qs9UwSFFVhXPv94Rt3tpJGv/D6mkHkZsByhHgBJII9gJXQ+bq4uru8y5q5g/kggS0raNH+18YGd9eu0Nawg==} @@ -17490,7 +17489,7 @@ time: /@pnpm/meta-updater/0.2.2: '2022-11-18T12:00:42.706Z' /@pnpm/network.agent/0.0.4: '2022-11-21T01:38:39.074Z' /@pnpm/nopt/0.2.1: '2021-06-01T19:45:54.552Z' - /@pnpm/npm-conf/2.1.0: '2022-12-23T16:08:03.626Z' + /@pnpm/npm-conf/2.0.0: '2022-07-31T00:06:52.248Z' /@pnpm/npm-lifecycle/2.0.0: '2022-11-30T19:58:42.868Z' /@pnpm/npm-package-arg/1.0.0: '2022-06-28T12:48:31.287Z' /@pnpm/os.env.path-extender/0.2.8: '2022-11-21T01:38:43.315Z' From 335523b86dec988003c5109452e9b29afc02aa41 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 24 Dec 2022 04:14:48 +0200 Subject: [PATCH 15/18] test: fix --- config/plugin-commands-config/test/configDelete.test.ts | 1 - config/plugin-commands-config/test/configGet.test.ts | 1 - config/plugin-commands-config/test/configList.test.ts | 2 -- config/plugin-commands-config/test/configSet.test.ts | 1 - 4 files changed, 5 deletions(-) diff --git a/config/plugin-commands-config/test/configDelete.test.ts b/config/plugin-commands-config/test/configDelete.test.ts index 5364d90ec8a..fb7ad0b64df 100644 --- a/config/plugin-commands-config/test/configDelete.test.ts +++ b/config/plugin-commands-config/test/configDelete.test.ts @@ -16,7 +16,6 @@ cache-dir=~/cache`) configDir, global: true, rawConfig: {}, - rawLocalConfig: {}, }, ['delete', 'store-dir']) expect(readIniFileSync(path.join(configDir, 'rc'))).toEqual({ diff --git a/config/plugin-commands-config/test/configGet.test.ts b/config/plugin-commands-config/test/configGet.test.ts index d9303d1bbef..91cf3a4140a 100644 --- a/config/plugin-commands-config/test/configGet.test.ts +++ b/config/plugin-commands-config/test/configGet.test.ts @@ -8,7 +8,6 @@ test('config get', async () => { rawConfig: { 'store-dir': '~/store', }, - rawLocalConfig: {}, }, ['get', 'store-dir']) expect(configKey).toEqual('~/store') diff --git a/config/plugin-commands-config/test/configList.test.ts b/config/plugin-commands-config/test/configList.test.ts index 9ac5e74555d..74883c9783f 100644 --- a/config/plugin-commands-config/test/configList.test.ts +++ b/config/plugin-commands-config/test/configList.test.ts @@ -8,7 +8,6 @@ test('config list', async () => { 'store-dir': '~/store', 'fetch-retries': '2', }, - rawLocalConfig: {}, }, ['list']) expect(output).toEqual(`fetch-retries=2 @@ -25,7 +24,6 @@ test('config list --json', async () => { 'store-dir': '~/store', 'fetch-retries': '2', }, - rawLocalConfig: {}, }, ['list']) expect(output).toEqual(JSON.stringify({ diff --git a/config/plugin-commands-config/test/configSet.test.ts b/config/plugin-commands-config/test/configSet.test.ts index 6905c764af3..feeb471a48a 100644 --- a/config/plugin-commands-config/test/configSet.test.ts +++ b/config/plugin-commands-config/test/configSet.test.ts @@ -15,7 +15,6 @@ test('config set', async () => { configDir, global: true, rawConfig: {}, - rawLocalConfig: {}, }, ['set', 'fetch-retries', '1']) expect(readIniFileSync(path.join(configDir, 'rc'))).toEqual({ From 3067643119f0c3d8d1a08389448581e4ff7d02f5 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 24 Dec 2022 13:25:46 +0200 Subject: [PATCH 16/18] test: fix --- config/plugin-commands-config/test/configList.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/plugin-commands-config/test/configList.test.ts b/config/plugin-commands-config/test/configList.test.ts index 74883c9783f..cc22cf1f54a 100644 --- a/config/plugin-commands-config/test/configList.test.ts +++ b/config/plugin-commands-config/test/configList.test.ts @@ -10,7 +10,7 @@ test('config list', async () => { }, }, ['list']) - expect(output).toEqual(`fetch-retries=2 + expect(output.replace(/\/r\/n/g, '\n')).toEqual(`fetch-retries=2 store-dir=~/store `) }) From 3a888262b4b47c658ba1214ca4b6f396c04baaca Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 24 Dec 2022 13:38:59 +0200 Subject: [PATCH 17/18] test: fix --- config/config/package.json | 2 +- pnpm-lock.yaml | 15 +++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/config/config/package.json b/config/config/package.json index 4cac3c857f9..42cf8f7729a 100644 --- a/config/config/package.json +++ b/config/config/package.json @@ -37,7 +37,7 @@ "@pnpm/error": "workspace:*", "@pnpm/git-utils": "workspace:*", "@pnpm/matcher": "workspace:*", - "@pnpm/npm-conf": "2.0.0", + "@pnpm/npm-conf": "2.0.4", "@pnpm/pnpmfile": "workspace:*", "@pnpm/read-project-manifest": "workspace:*", "@pnpm/types": "workspace:*", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 11ef68e3782..76652c511d6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -541,8 +541,8 @@ importers: specifier: workspace:* version: link:../matcher '@pnpm/npm-conf': - specifier: 2.0.0 - version: 2.0.0 + specifier: 2.0.4 + version: 2.0.4 '@pnpm/pnpmfile': specifier: workspace:* version: link:../../hooks/pnpmfile @@ -7925,14 +7925,6 @@ packages: normalize-registry-url: 2.0.0 dev: true - /@pnpm/npm-conf/2.0.0: - resolution: {integrity: sha512-Ot3xJvdbRQ3fwtDeRYMik/97BbCKij9ZupSgY1tJLCzPPgYRTIIjwdOBHQX2qGbwqNeKd6EneMyKAAsUMO09Bw==} - engines: {node: '>=12'} - dependencies: - '@pnpm/network.ca-file': 1.0.2 - config-chain: 1.1.13 - dev: false - /@pnpm/npm-conf/2.0.4: resolution: {integrity: sha512-xWjBhnntYvAjYt1alEoFJiThMe0ZhSY7iZuxBUR+DH3tH2RyGrP2KU75NZfo/jhc3dSBUqZrd1DnIIgkQ0WyKw==} engines: {node: '>=12'} @@ -7940,7 +7932,6 @@ packages: '@pnpm/config.env-replace': 1.0.0 '@pnpm/network.ca-file': 1.0.2 config-chain: 1.1.13 - dev: true /@pnpm/npm-lifecycle/2.0.0_typanion@3.12.1: resolution: {integrity: sha512-613qs9UwSFFVhXPv94Rt3tpJGv/D6mkHkZsByhHgBJII9gJXQ+bq4uru8y5q5g/kggS0raNH+18YGd9eu0Nawg==} @@ -17489,7 +17480,7 @@ time: /@pnpm/meta-updater/0.2.2: '2022-11-18T12:00:42.706Z' /@pnpm/network.agent/0.0.4: '2022-11-21T01:38:39.074Z' /@pnpm/nopt/0.2.1: '2021-06-01T19:45:54.552Z' - /@pnpm/npm-conf/2.0.0: '2022-07-31T00:06:52.248Z' + /@pnpm/npm-conf/2.0.4: '2022-11-11T20:26:48.028Z' /@pnpm/npm-lifecycle/2.0.0: '2022-11-30T19:58:42.868Z' /@pnpm/npm-package-arg/1.0.0: '2022-06-28T12:48:31.287Z' /@pnpm/os.env.path-extender/0.2.8: '2022-11-21T01:38:43.315Z' From c8bf1af46f5962c497d53b0693fb5aab3fc5c2a7 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 24 Dec 2022 14:59:20 +0200 Subject: [PATCH 18/18] test: fix --- config/plugin-commands-config/test/configList.test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/config/plugin-commands-config/test/configList.test.ts b/config/plugin-commands-config/test/configList.test.ts index cc22cf1f54a..48f3b318537 100644 --- a/config/plugin-commands-config/test/configList.test.ts +++ b/config/plugin-commands-config/test/configList.test.ts @@ -1,5 +1,11 @@ import { config } from '@pnpm/plugin-commands-config' +const CRLF = '\r\n' + +function normalizeNewlines (str: string) { + return str.replace(new RegExp(CRLF, 'g'), '\n') +} + test('config list', async () => { const output = await config.handler({ dir: process.cwd(), @@ -10,7 +16,7 @@ test('config list', async () => { }, }, ['list']) - expect(output.replace(/\/r\/n/g, '\n')).toEqual(`fetch-retries=2 + expect(normalizeNewlines(output)).toEqual(`fetch-retries=2 store-dir=~/store `) })