pnpm-settings-migrator 0.0.1
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/LICENSE +21 -0
- package/README.md +30 -0
- package/bin.mjs +4 -0
- package/dist/cli.d.mts +2 -0
- package/dist/cli.mjs +38 -0
- package/dist/index.d.mts +29 -0
- package/dist/index.mjs +8 -0
- package/dist/shared/pnpm-settings-migrator.BiiS7DGq.mjs +85 -0
- package/package.json +84 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-PRESENT ntnyq <https://github.com/ntnyq>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# pnpm-settings-migrator
|
|
2
|
+
|
|
3
|
+
[](https://github.com/ntnyq/pnpm-settings-migrator/actions)
|
|
4
|
+
[](https://www.npmjs.com/package/pnpm-settings-migrator)
|
|
5
|
+
[](https://www.npmjs.com/package/pnpm-settings-migrator)
|
|
6
|
+
[](https://github.com/ntnyq/pnpm-settings-migrator/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Move pnpm settings from `pnpm` field in `package.json` and `.npmrc` file to `pnpm-workspace.yaml`.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
Run in your workspace root:
|
|
13
|
+
|
|
14
|
+
```shell
|
|
15
|
+
pnpm dlx pnpm-settings-migrator
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## CLI Options
|
|
19
|
+
|
|
20
|
+
| Option | Type | Default | Description |
|
|
21
|
+
| :----: | :------: | :-------------: | :-----------------------: |
|
|
22
|
+
| `cwd` | `string` | `process.cwd()` | Current working directory |
|
|
23
|
+
|
|
24
|
+
## Context
|
|
25
|
+
|
|
26
|
+
- [Moving settings to pnpm-workspace.yaml](https://github.com/orgs/pnpm/discussions/9037)
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
[MIT](./LICENSE) License © 2025-PRESENT [ntnyq](https://github.com/ntnyq)
|
package/bin.mjs
ADDED
package/dist/cli.d.mts
ADDED
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { cac } from 'cac';
|
|
3
|
+
import { consola } from 'consola';
|
|
4
|
+
import { getColor } from 'consola/utils';
|
|
5
|
+
import { m as migratePnpmSettings } from './shared/pnpm-settings-migrator.BiiS7DGq.mjs';
|
|
6
|
+
import '@ntnyq/utils';
|
|
7
|
+
import 'pathe';
|
|
8
|
+
import 'node:fs/promises';
|
|
9
|
+
import 'js-yaml';
|
|
10
|
+
import 'camelcase-keys';
|
|
11
|
+
import 'read-ini-file';
|
|
12
|
+
|
|
13
|
+
const name = "pnpm-settings-migrator";
|
|
14
|
+
const version = "0.0.1";
|
|
15
|
+
|
|
16
|
+
const dim = getColor("dim");
|
|
17
|
+
const green = getColor("green");
|
|
18
|
+
const red = getColor("red");
|
|
19
|
+
const bold = getColor("bold");
|
|
20
|
+
const magenta = getColor("magenta");
|
|
21
|
+
const cli = cac(name);
|
|
22
|
+
cli.version(version).option("--cwd [cwd]", "Current working directory").help();
|
|
23
|
+
cli.command("").action(async (options) => {
|
|
24
|
+
try {
|
|
25
|
+
consola.log(`
|
|
26
|
+
${bold(magenta(name))} ${dim(`v${version}`)}`);
|
|
27
|
+
consola.log(dim("\n--------------\n"));
|
|
28
|
+
await migratePnpmSettings(options);
|
|
29
|
+
consola.success(green("pnpm settings migrate successfully!"));
|
|
30
|
+
} catch (err) {
|
|
31
|
+
consola.fail(red(String(err)));
|
|
32
|
+
if (err instanceof Error && err.stack) {
|
|
33
|
+
consola.fail(dim(err.stack?.split("\n").slice(1).join("\n")));
|
|
34
|
+
}
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
cli.parse();
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
/**
|
|
3
|
+
* Whether to remove `.npmrc` file
|
|
4
|
+
*
|
|
5
|
+
* @default true
|
|
6
|
+
*/
|
|
7
|
+
cleanNpmrc?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Whether to remove `pnpm` field in `package.json`
|
|
10
|
+
*
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
cleanPackageJson?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Current working directory
|
|
16
|
+
*
|
|
17
|
+
* @default process.cwd()
|
|
18
|
+
*/
|
|
19
|
+
cwd?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Strategy to handle conflicts
|
|
22
|
+
*/
|
|
23
|
+
strategy?: 'discard' | 'merge' | 'overwrite';
|
|
24
|
+
}
|
|
25
|
+
declare function resolveOptions(options?: Options): Required<Options>;
|
|
26
|
+
|
|
27
|
+
declare function migratePnpmSettings(rawOptions?: Options): Promise<void>;
|
|
28
|
+
|
|
29
|
+
export { type Options, migratePnpmSettings, resolveOptions };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { m as migratePnpmSettings, r as resolveOptions } from './shared/pnpm-settings-migrator.BiiS7DGq.mjs';
|
|
2
|
+
import '@ntnyq/utils';
|
|
3
|
+
import 'pathe';
|
|
4
|
+
import 'node:process';
|
|
5
|
+
import 'node:fs/promises';
|
|
6
|
+
import 'js-yaml';
|
|
7
|
+
import 'camelcase-keys';
|
|
8
|
+
import 'read-ini-file';
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { pick } from '@ntnyq/utils';
|
|
2
|
+
import { resolve } from 'pathe';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
import { access, readFile, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { load, dump } from 'js-yaml';
|
|
6
|
+
import camelcaseKeys from 'camelcase-keys';
|
|
7
|
+
import { readIniFile } from 'read-ini-file';
|
|
8
|
+
|
|
9
|
+
const NPMRC = ".npmrc";
|
|
10
|
+
const PACKAGE_JSON = "package.json";
|
|
11
|
+
const PNPM_WORKSPACE_YAML = "pnpm-workspace.yaml";
|
|
12
|
+
const PNPM_SETTINGS_FIELDS = [
|
|
13
|
+
"allowedDeprecatedVersions",
|
|
14
|
+
"allowNonAppliedPatches",
|
|
15
|
+
"auditConfig",
|
|
16
|
+
"configDependencies",
|
|
17
|
+
"executionEnv",
|
|
18
|
+
"ignoredBuiltDependencies",
|
|
19
|
+
"ignoredOptionalDependencies",
|
|
20
|
+
"neverBuiltDependencies",
|
|
21
|
+
"onlyBuiltDependencies",
|
|
22
|
+
"onlyBuiltDependenciesFile",
|
|
23
|
+
"overrides",
|
|
24
|
+
"packageExtensions",
|
|
25
|
+
"patchedDependencies",
|
|
26
|
+
"peerDependencyRules",
|
|
27
|
+
"requiredScripts",
|
|
28
|
+
"supportedArchitectures",
|
|
29
|
+
"updateConfig"
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
function resolveOptions(options = {}) {
|
|
33
|
+
return {
|
|
34
|
+
cleanNpmrc: options.cleanNpmrc ?? true,
|
|
35
|
+
cleanPackageJson: options.cleanPackageJson ?? true,
|
|
36
|
+
cwd: options.cwd ?? process.cwd(),
|
|
37
|
+
strategy: options.strategy ?? "merge"
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function fsExists(path) {
|
|
42
|
+
return access(path).then(() => true).catch(() => false);
|
|
43
|
+
}
|
|
44
|
+
async function fsReadFile(path) {
|
|
45
|
+
return await readFile(path, "utf-8");
|
|
46
|
+
}
|
|
47
|
+
async function fsWriteFile(path, content) {
|
|
48
|
+
await writeFile(path, content, "utf-8");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function readNpmrc(path) {
|
|
52
|
+
const content = await readIniFile(path);
|
|
53
|
+
return camelcaseKeys(content);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function readPackageJson(path) {
|
|
57
|
+
const content = await fsReadFile(path);
|
|
58
|
+
return JSON.parse(content);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function readPnpmWorkspace(path) {
|
|
62
|
+
const content = await fsReadFile(path);
|
|
63
|
+
return load(content);
|
|
64
|
+
}
|
|
65
|
+
async function writePnpmWorkspace(path, pnpmWorkspace) {
|
|
66
|
+
await fsWriteFile(path, dump(pnpmWorkspace));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function migratePnpmSettings(rawOptions = {}) {
|
|
70
|
+
const options = resolveOptions(rawOptions);
|
|
71
|
+
const npmrcPath = resolve(options.cwd, NPMRC);
|
|
72
|
+
const packageJsonPath = resolve(options.cwd, PACKAGE_JSON);
|
|
73
|
+
const pnpmWorkspaceYamlPath = resolve(options.cwd, PNPM_WORKSPACE_YAML);
|
|
74
|
+
const isNpmrcExist = await fsExists(npmrcPath);
|
|
75
|
+
const isPackageJsonExist = await fsExists(packageJsonPath);
|
|
76
|
+
const isPnpmWorkspaceExist = await fsExists(pnpmWorkspaceYamlPath);
|
|
77
|
+
const pnpmWorkspaceContent = {
|
|
78
|
+
...isNpmrcExist ? pick(await readNpmrc(npmrcPath), PNPM_SETTINGS_FIELDS) : {},
|
|
79
|
+
...isPackageJsonExist ? (await readPackageJson(packageJsonPath)).pnpm : {},
|
|
80
|
+
...isPnpmWorkspaceExist ? await readPnpmWorkspace(pnpmWorkspaceYamlPath) : {}
|
|
81
|
+
};
|
|
82
|
+
await writePnpmWorkspace(pnpmWorkspaceYamlPath, pnpmWorkspaceContent);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { migratePnpmSettings as m, resolveOptions as r };
|
package/package.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pnpm-settings-migrator",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "Move pnpm settings from `pnpm` field in `package.json` and `.npmrc` file to `pnpm-workspace.yaml`",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"migrator",
|
|
8
|
+
"pnpm",
|
|
9
|
+
"settings"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": {
|
|
13
|
+
"name": "ntnyq",
|
|
14
|
+
"email": "ntnyq13@gmail.com"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/ntnyq/pnpm-settings-migrator#readme",
|
|
17
|
+
"repository": "ntnyq/pnpm-settings-migrator",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/ntnyq/pnpm-settings-migrator/issues"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
"./package.json": "./package.json",
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.mts",
|
|
25
|
+
"default": "./dist/index.mjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/index.mjs",
|
|
29
|
+
"types": "./dist/index.d.mts",
|
|
30
|
+
"bin": "./bin.mjs",
|
|
31
|
+
"files": [
|
|
32
|
+
"bin.mjs",
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"sideEffects": false,
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@ntnyq/utils": "^0.6.1",
|
|
41
|
+
"@pnpm/types": "^1000.2.1",
|
|
42
|
+
"cac": "^6.7.14",
|
|
43
|
+
"camelcase-keys": "^9.1.3",
|
|
44
|
+
"consola": "^3.4.0",
|
|
45
|
+
"js-yaml": "^4.1.0",
|
|
46
|
+
"pathe": "^2.0.3",
|
|
47
|
+
"read-ini-file": "^4.0.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@ntnyq/eslint-config": "^4.0.0-beta.11",
|
|
51
|
+
"@ntnyq/prettier-config": "^2.0.0",
|
|
52
|
+
"@types/js-yaml": "^4.0.9",
|
|
53
|
+
"@types/node": "^22.13.9",
|
|
54
|
+
"bumpp": "^10.0.3",
|
|
55
|
+
"eslint": "^9.21.0",
|
|
56
|
+
"husky": "^9.1.7",
|
|
57
|
+
"nano-staged": "^0.8.0",
|
|
58
|
+
"npm-run-all2": "^7.0.2",
|
|
59
|
+
"prettier": "^3.5.3",
|
|
60
|
+
"tsx": "^4.19.3",
|
|
61
|
+
"typescript": "^5.8.2",
|
|
62
|
+
"unbuild": "^3.5.0",
|
|
63
|
+
"vitest": "^3.0.8"
|
|
64
|
+
},
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": ">=18.18.0"
|
|
67
|
+
},
|
|
68
|
+
"nano-staged": {
|
|
69
|
+
"*.{js,ts,mjs,cjs,md,vue,yml,yaml,toml,json}": "eslint --fix",
|
|
70
|
+
"*.{css,scss,html}": "prettier -uw"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "unbuild",
|
|
74
|
+
"dev": "unbuild --watch",
|
|
75
|
+
"lint": "eslint",
|
|
76
|
+
"release": "run-s release:check release:version release:publish",
|
|
77
|
+
"release:check": "run-s lint typecheck test",
|
|
78
|
+
"release:publish": "pnpm publish",
|
|
79
|
+
"release:version": "bumpp",
|
|
80
|
+
"start": "tsx src/cli.ts",
|
|
81
|
+
"test": "vitest",
|
|
82
|
+
"typecheck": "tsc --noEmit"
|
|
83
|
+
}
|
|
84
|
+
}
|