Skip to content

Commit

Permalink
fix when rc file not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
YieldRay committed Jun 11, 2024
1 parent 6cc8a09 commit 9032e57
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
11 changes: 4 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@

## [0.1.3](https://github.com/YieldRay/nrm-lite/compare/v0.1.2...v0.1.3) (2024-03-12)


### Bug Fixes

* fix the --version flag ([9e059ef](https://github.com/YieldRay/nrm-lite/commit/9e059efaf24198123e01307a71e59dfdad09bba2))
- fix the --version flag ([9e059ef](https://github.com/YieldRay/nrm-lite/commit/9e059efaf24198123e01307a71e59dfdad09bba2))

## [0.1.2](https://github.com/YieldRay/nrm-lite/compare/v0.1.1...v0.1.2) (2024-03-11)


### Features

* support timeout for test command ([d14c87d](https://github.com/YieldRay/nrm-lite/commit/d14c87d70a5990dc60c855f5c42883d1d9e8da3e))
- support timeout for test command ([d14c87d](https://github.com/YieldRay/nrm-lite/commit/d14c87d70a5990dc60c855f5c42883d1d9e8da3e))

## 0.1.1 (2024-03-11)


### Features

* add test command ([432f29d](https://github.com/YieldRay/nrm-lite/commit/432f29db4524f64951056970ab44b0917302efa2))
* initial commit ([ff2c04b](https://github.com/YieldRay/nrm-lite/commit/ff2c04b774b81b849c60a46c18dde2555c51b61e))
- add test command ([432f29d](https://github.com/YieldRay/nrm-lite/commit/432f29db4524f64951056970ab44b0917302efa2))
- initial commit ([ff2c04b](https://github.com/YieldRay/nrm-lite/commit/ff2c04b774b81b849c60a46c18dde2555c51b61e))
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![node-current](https://img.shields.io/node/v/nrm-lite)](https://nodejs.dev/)
[![install size](https://packagephobia.com/badge?p=nrm-lite)](https://packagephobia.com/result?p=nrm-lite)

Fast and lightweight NpmRegistryManager, for the minimalists.
Fast and lightweight Npm [Registry](https://docs.npmjs.com/cli/using-npm/registry) Manager, for the minimalists.
Like [dnrm](https://github.com/markthree/dnrm), but in pure Node.js.

[![asciicast](https://asciinema.org/a/646571.svg)](https://asciinema.org/a/646571)
Expand Down
8 changes: 4 additions & 4 deletions cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ ${c.bold('Usage:')}
nrml ls List registries
nrml use ${c.gray('<name>')} Use registry
nrml test ${c.gray(
'[<timeout>]'
'[<timeout>]',
)} Test registry speed, optional timeout in second (default: 2)
nrml rc Open .npmrc file
nrml help Show this help
Expand Down Expand Up @@ -137,7 +137,7 @@ async function test(timeoutLimit) {
name,
url,
timeSpent: await speedTest(url, timeoutLimit),
}))
})),
)

const currentRegistry = await getRegistry(local)
Expand All @@ -152,8 +152,8 @@ async function rc() {
} catch {
console.error(
`You do not have vscode installed!\nPlease open ${c.gray(
filePath
)} manually.`
filePath,
)} manually.`,
)
process.exit(-1)
}
Expand Down
11 changes: 8 additions & 3 deletions config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ export async function setRegistry(local, registryUrl) {
*/
export async function getRegistry(local) {
const filePath = await getConfigPath(local)
const fileStream = fs.createReadStream(filePath)
const { registry } = await findRegistryFromStream(fileStream)
return registry || REGISTRIES['npm']
try {
const fileStream = fs.createReadStream(filePath) // the file may not exists
const { registry } = await findRegistryFromStream(fileStream)
return registry || REGISTRIES['npm']
} catch {
// when rc file not found, fallback registry to default
return REGISTRIES['npm']
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nrm-lite",
"version": "0.1.3",
"version": "0.1.4",
"type": "module",
"description": "Fast and lightweight NpmRegistryManager, for the minimalists.",
"main": "index.mjs",
Expand All @@ -22,8 +22,8 @@
"nrml": "cli.mjs"
},
"devDependencies": {
"@types/node": "^20.11.26",
"typescript": "^5.4.2"
"@types/node": "^20.14.2",
"typescript": "^5.4.5"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
Expand Down
1 change: 0 additions & 1 deletion registry.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const REGISTRIES = {
}

/**
*
* Note that `registryLineNumber` is index + 1
*
* @param {NodeJS.ReadableStream} stream
Expand Down
6 changes: 3 additions & 3 deletions tty.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export function printRegistries(
name,
url,
})),
timeoutLimit
timeoutLimit,
) {
const maxNameLength = Math.max(
...registriesInfo.map(({ name }) => name.length)
...registriesInfo.map(({ name }) => name.length),
)
/**
* @type {number=}
Expand All @@ -57,7 +57,7 @@ export function printRegistries(
// lazy compute
if (!maxUrlLength)
maxUrlLength = Math.max(
...registriesInfo.map(({ url }) => url.length)
...registriesInfo.map(({ url }) => url.length),
)
}

Expand Down

0 comments on commit 9032e57

Please sign in to comment.