Skip to content

Commit 2fe00e6

Browse files
authored
Merge pull request #223 from HomyeeKing/patch-1
chore: remove home field from npmrc
2 parents f99eb89 + 0424253 commit 2fe00e6

File tree

5 files changed

+109
-87
lines changed

5 files changed

+109
-87
lines changed

.changeset/silly-shirts-confess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"nrm": minor
3+
---
4+
5+
fix: Remove invalid home field from .npmrc.

biome.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"recommended": true,
2424
"suspicious": {
2525
"noExplicitAny": "off"
26+
},
27+
"performance": {
28+
"noDelete": "off"
2629
}
2730
}
2831
},

src/actions.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ import {
2727
writeFile,
2828
} from './helpers';
2929

30+
export async function cleanInvalidNpmConfig() {
31+
const npmrc = await readFile(NPMRC);
32+
if (!npmrc) return;
33+
delete npmrc.home;
34+
await writeFile(NPMRC, npmrc);
35+
}
36+
3037
export async function onList() {
3138
const currentRegistry = await getCurrentRegistry();
3239
const registries = await getRegistries();
@@ -88,8 +95,8 @@ export async function onUse(name: string) {
8895
if (await isRegistryNotFound(alias)) {
8996
return;
9097
}
91-
92-
const registry = registries[alias];
98+
// https://github.com/Pana/nrm/pull/223#issuecomment-3057092705
99+
const { home: _, ...registry } = registries[alias];
93100
const npmrc = await readFile(NPMRC);
94101
await writeFile(NPMRC, Object.assign(npmrc, registry));
95102

src/index.ts

Lines changed: 92 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { Command } from 'commander';
44
import packageJson from '../package.json';
55
import {
6+
cleanInvalidNpmConfig,
67
onAdd,
78
onCurrent,
89
onDelete,
@@ -18,88 +19,95 @@ import {
1819
onUse,
1920
} from './actions.js';
2021

21-
const program = new Command();
22-
23-
const { name, version, description } = packageJson;
24-
program.name(name).description(description).version(version);
25-
26-
program.command('ls').description('List all the registries').action(onList);
27-
28-
program
29-
.command('current')
30-
.option('-u, --show-url', 'Show the registry URL instead of the name')
31-
.description('Show current registry name or URL')
32-
.action(onCurrent);
33-
34-
program
35-
.command('use [name]')
36-
.description('Change current registry')
37-
.action(onUse);
38-
39-
program
40-
.command('add <name> <url> [home]')
41-
.description('Add custom registry')
42-
.action(onAdd);
43-
44-
program
45-
.command('login <name> [base64]')
46-
.option('-a, --always-auth', 'Set is always auth')
47-
.option('-u, --username <username>', 'Your user name for this registry')
48-
.option('-p, --password <password>', 'Your password for this registry')
49-
.option('-e, --email <email>', 'Your email for this registry')
50-
.description(
51-
'Set authorize information for a custom registry with a base64 encoded string or username and password',
52-
)
53-
.action(onLogin);
54-
55-
program
56-
.command('set-hosted-repo <name> <repo>')
57-
.description(
58-
'Set hosted npm repository for a custom registry to publish package',
59-
)
60-
.action(onSetRepository);
61-
62-
program
63-
.command('set-scope <scopeName> <url>')
64-
.description('Associating a scope with a registry')
65-
.action(onSetScope);
66-
67-
program
68-
.command('del-scope <scopeName>')
69-
.description('Remove a scope')
70-
.action(onDeleteScope);
71-
72-
program
73-
.command('set <name>')
74-
.requiredOption('-a,--attr <attr>', 'Set a custom registry attribute')
75-
.requiredOption('-v,--value <value>', 'Set a custom registry value')
76-
.description('Set a custom registry attribute')
77-
.action(onSetAttribute);
78-
79-
program
80-
.command('rename <name> <newName>')
81-
.description('Change custom registry name')
82-
.action(onRename);
83-
84-
program
85-
.command('del [name]')
86-
.description('Delete custom registry')
87-
.action(onDelete);
88-
89-
program
90-
.command('home <name> [browser]')
91-
.description('Open the homepage of registry with optional browser')
92-
.action(onHome);
93-
94-
program
95-
.command('test [registry]')
96-
.description('Show response time for specific or all registries')
97-
.action(() => {
98-
onTest();
99-
}); // ignore return value to pass typescript check
100-
101-
program.parse(process.argv);
102-
103-
if (process.argv.length === 2) {
104-
program.outputHelp();
22+
async function main() {
23+
const program = new Command();
24+
25+
// make sure the invalid npm config is cleaned up
26+
await cleanInvalidNpmConfig();
27+
28+
const { name, version, description } = packageJson;
29+
program.name(name).description(description).version(version);
30+
31+
program.command('ls').description('List all the registries').action(onList);
32+
33+
program
34+
.command('current')
35+
.option('-u, --show-url', 'Show the registry URL instead of the name')
36+
.description('Show current registry name or URL')
37+
.action(onCurrent);
38+
39+
program
40+
.command('use [name]')
41+
.description('Change current registry')
42+
.action(onUse);
43+
44+
program
45+
.command('add <name> <url> [home]')
46+
.description('Add custom registry')
47+
.action(onAdd);
48+
49+
program
50+
.command('login <name> [base64]')
51+
.option('-a, --always-auth', 'Set is always auth')
52+
.option('-u, --username <username>', 'Your user name for this registry')
53+
.option('-p, --password <password>', 'Your password for this registry')
54+
.option('-e, --email <email>', 'Your email for this registry')
55+
.description(
56+
'Set authorize information for a custom registry with a base64 encoded string or username and password',
57+
)
58+
.action(onLogin);
59+
60+
program
61+
.command('set-hosted-repo <name> <repo>')
62+
.description(
63+
'Set hosted npm repository for a custom registry to publish package',
64+
)
65+
.action(onSetRepository);
66+
67+
program
68+
.command('set-scope <scopeName> <url>')
69+
.description('Associating a scope with a registry')
70+
.action(onSetScope);
71+
72+
program
73+
.command('del-scope <scopeName>')
74+
.description('Remove a scope')
75+
.action(onDeleteScope);
76+
77+
program
78+
.command('set <name>')
79+
.requiredOption('-a,--attr <attr>', 'Set a custom registry attribute')
80+
.requiredOption('-v,--value <value>', 'Set a custom registry value')
81+
.description('Set a custom registry attribute')
82+
.action(onSetAttribute);
83+
84+
program
85+
.command('rename <name> <newName>')
86+
.description('Change custom registry name')
87+
.action(onRename);
88+
89+
program
90+
.command('del [name]')
91+
.description('Delete custom registry')
92+
.action(onDelete);
93+
94+
program
95+
.command('home <name> [browser]')
96+
.description('Open the homepage of registry with optional browser')
97+
.action(onHome);
98+
99+
program
100+
.command('test [registry]')
101+
.description('Show response time for specific or all registries')
102+
.action(() => {
103+
onTest();
104+
}); // ignore return value to pass typescript check
105+
106+
await program.parseAsync(process.argv);
107+
108+
if (process.argv.length === 2) {
109+
program.outputHelp();
110+
}
105111
}
112+
113+
main();

tests/cli.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { onHome, onTest } from '../src/actions';
1919
import { NPMRC, NRMRC, REGISTRIES } from '../src/constants';
2020
import { isUnicodeSupported, readFile, writeFile } from '../src/helpers';
2121

22-
2322
const isWin = process.platform === 'win32';
2423

2524
const shouldUseMain = isUnicodeSupported();

0 commit comments

Comments
 (0)