pnpm-settings-migrator 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -17,9 +17,26 @@ pnpm dlx pnpm-settings-migrator
|
|
|
17
17
|
|
|
18
18
|
## CLI Options
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
### `--cwd`
|
|
21
|
+
|
|
22
|
+
- **Type**: `string`
|
|
23
|
+
- **Default**: `process.cwd()`
|
|
24
|
+
|
|
25
|
+
Current working directory.
|
|
26
|
+
|
|
27
|
+
### `--no-clean-npmrc`
|
|
28
|
+
|
|
29
|
+
- **Type**: `boolean`
|
|
30
|
+
- **Default**: `false`
|
|
31
|
+
|
|
32
|
+
Disable removing pnpm settings in `.npmrc` file.
|
|
33
|
+
|
|
34
|
+
### `---no-clean-package-json`
|
|
35
|
+
|
|
36
|
+
- **Type**: `boolean`
|
|
37
|
+
- **Default**: `false`
|
|
38
|
+
|
|
39
|
+
Disable removing `pnpm` field in `package.json`.
|
|
23
40
|
|
|
24
41
|
## Context
|
|
25
42
|
|
package/dist/cli.mjs
CHANGED
|
@@ -2,16 +2,18 @@ import process from 'node:process';
|
|
|
2
2
|
import { cac } from 'cac';
|
|
3
3
|
import { consola } from 'consola';
|
|
4
4
|
import { getColor } from 'consola/utils';
|
|
5
|
-
import { m as migratePnpmSettings } from './shared/pnpm-settings-migrator.
|
|
5
|
+
import { m as migratePnpmSettings } from './shared/pnpm-settings-migrator.UmbLs3tK.mjs';
|
|
6
6
|
import '@ntnyq/utils';
|
|
7
7
|
import 'pathe';
|
|
8
8
|
import 'node:fs/promises';
|
|
9
|
+
import 'detect-indent';
|
|
9
10
|
import 'js-yaml';
|
|
10
11
|
import 'camelcase-keys';
|
|
11
12
|
import 'read-ini-file';
|
|
13
|
+
import 'uncase';
|
|
12
14
|
|
|
13
15
|
const name = "pnpm-settings-migrator";
|
|
14
|
-
const version = "0.0.
|
|
16
|
+
const version = "0.0.2";
|
|
15
17
|
|
|
16
18
|
const dim = getColor("dim");
|
|
17
19
|
const green = getColor("green");
|
|
@@ -19,7 +21,10 @@ const red = getColor("red");
|
|
|
19
21
|
const bold = getColor("bold");
|
|
20
22
|
const magenta = getColor("magenta");
|
|
21
23
|
const cli = cac(name);
|
|
22
|
-
cli.version(version).option("--cwd [cwd]", "Current working directory").
|
|
24
|
+
cli.version(version).option("--cwd [cwd]", "Current working directory").option("--no-clean-npmrc", "Disable removing pnpm settings in .npmrc file").option(
|
|
25
|
+
"--no-clean-package-json",
|
|
26
|
+
"Disable removing pnpm field in package.json"
|
|
27
|
+
).help();
|
|
23
28
|
cli.command("").action(async (options) => {
|
|
24
29
|
try {
|
|
25
30
|
consola.log(`
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { PnpmSettings } from '@pnpm/types';
|
|
2
|
+
|
|
1
3
|
interface Options {
|
|
2
4
|
/**
|
|
3
|
-
* Whether to remove `.npmrc` file
|
|
5
|
+
* Whether to remove pnpm settings in `.npmrc` file
|
|
4
6
|
*
|
|
5
7
|
* @default true
|
|
6
8
|
*/
|
|
@@ -26,4 +28,30 @@ declare function resolveOptions(options?: Options): Required<Options>;
|
|
|
26
28
|
|
|
27
29
|
declare function migratePnpmSettings(rawOptions?: Options): Promise<void>;
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
/**
|
|
32
|
+
* legacy `pnpm-workspace` types
|
|
33
|
+
*/
|
|
34
|
+
type PnpmWorkspaceLegacy = {
|
|
35
|
+
catalog?: Record<string, string>;
|
|
36
|
+
catalogs?: Record<string, Record<string, string>>;
|
|
37
|
+
packages?: string[];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* `package-json`
|
|
41
|
+
* @pg
|
|
42
|
+
*/
|
|
43
|
+
interface PackageJson {
|
|
44
|
+
pnpm?: PnpmSettings;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* `.npmrc`
|
|
48
|
+
* @pg
|
|
49
|
+
*/
|
|
50
|
+
type NpmRC = Record<string, any>;
|
|
51
|
+
/**
|
|
52
|
+
* `pnpm-workspace` types
|
|
53
|
+
* @pg
|
|
54
|
+
*/
|
|
55
|
+
type PnpmWorkspace = PnpmSettings & PnpmWorkspaceLegacy;
|
|
56
|
+
|
|
57
|
+
export { type NpmRC, type Options, type PackageJson, type PnpmWorkspace, type PnpmWorkspaceLegacy, migratePnpmSettings, resolveOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
export { m as migratePnpmSettings, r as resolveOptions } from './shared/pnpm-settings-migrator.
|
|
1
|
+
export { m as migratePnpmSettings, r as resolveOptions } from './shared/pnpm-settings-migrator.UmbLs3tK.mjs';
|
|
2
2
|
import '@ntnyq/utils';
|
|
3
3
|
import 'pathe';
|
|
4
4
|
import 'node:process';
|
|
5
5
|
import 'node:fs/promises';
|
|
6
|
+
import 'detect-indent';
|
|
6
7
|
import 'js-yaml';
|
|
7
8
|
import 'camelcase-keys';
|
|
8
9
|
import 'read-ini-file';
|
|
10
|
+
import 'uncase';
|
package/dist/shared/{pnpm-settings-migrator.BiiS7DGq.mjs → pnpm-settings-migrator.UmbLs3tK.mjs}
RENAMED
|
@@ -2,9 +2,11 @@ import { pick } from '@ntnyq/utils';
|
|
|
2
2
|
import { resolve } from 'pathe';
|
|
3
3
|
import process from 'node:process';
|
|
4
4
|
import { access, readFile, writeFile } from 'node:fs/promises';
|
|
5
|
+
import detectIndent from 'detect-indent';
|
|
5
6
|
import { load, dump } from 'js-yaml';
|
|
6
7
|
import camelcaseKeys from 'camelcase-keys';
|
|
7
8
|
import { readIniFile } from 'read-ini-file';
|
|
9
|
+
import { kebabCase } from 'uncase';
|
|
8
10
|
|
|
9
11
|
const NPMRC = ".npmrc";
|
|
10
12
|
const PACKAGE_JSON = "package.json";
|
|
@@ -45,14 +47,34 @@ async function fsReadFile(path) {
|
|
|
45
47
|
return await readFile(path, "utf-8");
|
|
46
48
|
}
|
|
47
49
|
async function fsWriteFile(path, content) {
|
|
48
|
-
await writeFile(path, content
|
|
50
|
+
await writeFile(path, `${content.trimEnd()}
|
|
51
|
+
`, "utf-8");
|
|
49
52
|
}
|
|
50
53
|
|
|
54
|
+
async function pruneNpmrc(path) {
|
|
55
|
+
const pnpmSettingsFields = PNPM_SETTINGS_FIELDS.map((v) => kebabCase(v));
|
|
56
|
+
const content = await fsReadFile(path);
|
|
57
|
+
const lines = content.split(/\r?\n/).filter((line) => {
|
|
58
|
+
const trimedLine = line.trim();
|
|
59
|
+
if (!trimedLine.length || pnpmSettingsFields.some((v) => trimedLine.startsWith(v))) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
});
|
|
64
|
+
await fsWriteFile(path, lines.join("\n"));
|
|
65
|
+
}
|
|
51
66
|
async function readNpmrc(path) {
|
|
52
67
|
const content = await readIniFile(path);
|
|
53
68
|
return camelcaseKeys(content);
|
|
54
69
|
}
|
|
55
70
|
|
|
71
|
+
async function prunePackageJson(path) {
|
|
72
|
+
const content = await fsReadFile(path);
|
|
73
|
+
const indent = detectIndent(content);
|
|
74
|
+
const packageJson = JSON.parse(content);
|
|
75
|
+
delete packageJson.pnpm;
|
|
76
|
+
await fsWriteFile(path, JSON.stringify(packageJson, null, indent.indent || 2));
|
|
77
|
+
}
|
|
56
78
|
async function readPackageJson(path) {
|
|
57
79
|
const content = await fsReadFile(path);
|
|
58
80
|
return JSON.parse(content);
|
|
@@ -63,7 +85,9 @@ async function readPnpmWorkspace(path) {
|
|
|
63
85
|
return load(content);
|
|
64
86
|
}
|
|
65
87
|
async function writePnpmWorkspace(path, pnpmWorkspace) {
|
|
66
|
-
await
|
|
88
|
+
const content = await fsReadFile(path);
|
|
89
|
+
const indent = detectIndent(content);
|
|
90
|
+
await fsWriteFile(path, dump(pnpmWorkspace, { indent: indent.amount || 2 }));
|
|
67
91
|
}
|
|
68
92
|
|
|
69
93
|
async function migratePnpmSettings(rawOptions = {}) {
|
|
@@ -80,6 +104,12 @@ async function migratePnpmSettings(rawOptions = {}) {
|
|
|
80
104
|
...isPnpmWorkspaceExist ? await readPnpmWorkspace(pnpmWorkspaceYamlPath) : {}
|
|
81
105
|
};
|
|
82
106
|
await writePnpmWorkspace(pnpmWorkspaceYamlPath, pnpmWorkspaceContent);
|
|
107
|
+
if (isNpmrcExist && options.cleanNpmrc) {
|
|
108
|
+
await pruneNpmrc(npmrcPath);
|
|
109
|
+
}
|
|
110
|
+
if (isPackageJsonExist && options.cleanNpmrc) {
|
|
111
|
+
await prunePackageJson(packageJsonPath);
|
|
112
|
+
}
|
|
83
113
|
}
|
|
84
114
|
|
|
85
115
|
export { migratePnpmSettings as m, resolveOptions as r };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pnpm-settings-migrator",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"description": "Move pnpm settings from `pnpm` field in `package.json` and `.npmrc` file to `pnpm-workspace.yaml`",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"migrator",
|
|
@@ -42,9 +42,11 @@
|
|
|
42
42
|
"cac": "^6.7.14",
|
|
43
43
|
"camelcase-keys": "^9.1.3",
|
|
44
44
|
"consola": "^3.4.0",
|
|
45
|
+
"detect-indent": "^7.0.1",
|
|
45
46
|
"js-yaml": "^4.1.0",
|
|
46
47
|
"pathe": "^2.0.3",
|
|
47
|
-
"read-ini-file": "^4.0.0"
|
|
48
|
+
"read-ini-file": "^4.0.0",
|
|
49
|
+
"uncase": "^0.0.4"
|
|
48
50
|
},
|
|
49
51
|
"devDependencies": {
|
|
50
52
|
"@ntnyq/eslint-config": "^4.0.0-beta.11",
|