Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to ESM #1391

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
File renamed without changes.
File renamed without changes.
1,134 changes: 505 additions & 629 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 4 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"node": "^18.18.0 || >=20.0.0",
"npm": ">=8.12.1"
},
"type": "module",
"main": "build/index.js",
"types": "build/index.d.ts",
"scripts": {
Expand All @@ -28,14 +29,14 @@
"build:analyze": "rimraf build && npm run build:options && ANALYZER=true vite build",
"lint": "cross-env FORCE_COLOR=1 npm-run-all --parallel --aggregate-output lint:*",
"lint:lockfile": "lockfile-lint",
"lint:markdown": "markdownlint \"**/*.md\" --ignore \"**/node_modules/**/*.md\" --ignore build --config .markdownlint.js",
"lint:markdown": "markdownlint \"**/*.md\" --ignore \"**/node_modules/**/*.md\" --ignore build --config .markdownlint.cjs",
"lint:src": "eslint --cache --cache-location node_modules/.cache/.eslintcache --ignore-path .gitignore --report-unused-disable-directives .",
"prepare": "src/scripts/install-hooks",
"prepublishOnly": "npm run build",
"prettier": "prettier . --check",
"test": "npm run test:unit && npm run test:e2e",
"test:bun": "test/bun-install.sh && mocha test/bun",
"test:unit": "mocha test test/package-managers/*",
"test:unit": "vitest test test/package-managers/*",
"test:e2e": "./test/e2e.sh",
"ncu": "node build/cli.js"
},
Expand Down Expand Up @@ -67,7 +68,6 @@
"@types/json-parse-helpfulerror": "^1.0.3",
"@types/jsonlines": "^0.1.5",
"@types/lodash": "^4.17.0",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.30",
"@types/npm-registry-fetch": "^8.0.7",
"@types/parse-github-url": "^1.0.3",
Expand Down Expand Up @@ -110,7 +110,6 @@
"lockfile-lint": "^4.13.2",
"lodash": "^4.17.21",
"markdownlint-cli": "^0.39.0",
"mocha": "^10.4.0",
"npm-registry-fetch": "^16.1.0",
"npm-run-all": "^4.1.5",
"p-map": "^4.0.0",
Expand All @@ -132,7 +131,6 @@
"spawn-please": "^3.0.0",
"strip-ansi": "^7.1.0",
"strip-json-comments": "^5.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.4.3",
"typescript-json-schema": "^0.63.0",
"untildify": "^4.0.0",
Expand All @@ -142,6 +140,7 @@
"vite-bundle-analyzer": "^0.9.3",
"vite-node": "^1.4.0",
"vite-plugin-dts": "^3.8.0",
"vitest": "^1.4.0",
"yarn": "^1.22.22"
},
"files": [
Expand All @@ -160,19 +159,5 @@
"empty-hostname": false,
"type": "npm ",
"path": "package-lock.json"
},
"mocha": {
"check-leaks": true,
"extension": [
"test.ts"
],
"require": [
"source-map-support/register",
"ts-node/register"
],
"timeout": 60000,
"trace-deprecation": true,
"trace-warnings": true,
"use_strict": true
}
}
8 changes: 3 additions & 5 deletions test/bun/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ describe('bun', function () {
version!.should.equal('2.0.0')
})

describe('doctor', function () {
this.timeout(3 * 60 * 1000)

describe('doctor', { timeout: 3 * 60 * 1000 }, function () {
let stub: { restore: () => void }
before(() => (stub = stubVersions(mockNpmVersions, { spawn: true })))
after(() => stub.restore())
beforeEach(() => (stub = stubVersions(mockNpmVersions, { spawn: true })))
afterEach(() => stub.restore())

testPass({ packageManager: 'bun' })
testFail({ packageManager: 'bun' })
Expand Down
20 changes: 10 additions & 10 deletions test/deep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ const setupDeepTest = async () => {
return tempDir
}

describe('--deep', function () {
this.timeout(60000)

describe('--deep', { timeout: 60000 }, function () {
let stub: { restore: () => void }
before(() => (stub = stubVersions('99.9.9', { spawn: true })))
after(() => stub.restore())
beforeEach(() => {
stub = stubVersions('99.9.9', { spawn: true })
})
afterEach(() => stub.restore())

it('do not allow --packageFile and --deep together', async () => {
await ncu({ packageFile: './package.json', deep: true }).should.eventually.be.rejectedWith('Cannot specify both')
Expand Down Expand Up @@ -121,14 +121,14 @@ describe('--deep', function () {
})
})

describe('--deep with nested ncurc files', function () {
describe('--deep with nested ncurc files', { timeout: 60000 }, function () {
const cwd = path.join(__dirname, 'test-data/deep-ncurc')

this.timeout(60000)

let stub: { restore: () => void }
before(() => (stub = stubVersions('99.9.9', { spawn: true })))
after(() => stub.restore())
beforeEach(() => {
stub = stubVersions('99.9.9', { spawn: true })
})
afterEach(() => stub.restore())

it('use ncurc of nested packages', async () => {
const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--deep'], {}, { cwd })
Expand Down
12 changes: 6 additions & 6 deletions test/doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ const ncu = async (
return stdout
}

describe('doctor', function () {
// 3 min timeout
this.timeout(3 * 60 * 1000)

// 3 min timeout
describe('doctor', { timeout: 3 * 60 * 1000 }, function () {
let stub: { restore: () => void }
before(() => (stub = stubVersions(mockNpmVersions, { spawn: true })))
after(() => stub.restore())
beforeEach(() => {
stub = stubVersions(mockNpmVersions, { spawn: true })
})
afterEach(() => stub.restore())

describe('npm', () => {
it('print instructions when -u is not specified', async () => {
Expand Down
49 changes: 21 additions & 28 deletions test/e2e.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash

#!/usr/bin/env bash
cwd=$(pwd)
e2e_dir=$(dirname "$(readlink -f "$0")")
temp_dir=$(mktemp -d)
Expand All @@ -10,26 +9,27 @@ verdaccio_config=$temp_dir/verdaccio-config.yaml

# cleanup on exit
cleanup() {

exit_status=$?

# turn off stop on error
set +e

Comment on lines +14 to +15
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify why this is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this was causing the verdaccio shutdown to fail. Not sure any more :-/

# shut down verdaccio
verdaccio_pid=$(lsof -t -i :$registry_port)
if [ -n "$verdaccio_pid" ]; then
echo Shutting down verdaccio
kill -9 $verdaccio_pid
wait $verdaccio_pid 2>/dev/null
echo "Shutting down verdaccio (PID $verdaccio_pid)"
kill "$verdaccio_pid"
wait "$verdaccio_pid" 2>/dev/null
fi

# delete authToken
# WARNING: The original authToken cannot be restored because it is protected and cannot be read with 'npm config get'.
npm config delete "//localhost:$registry_port/:_authToken"

# remove temp directory
rm -rf $temp_dir
rm -rf "$temp_dir"

# return to working directory
cd $cwd
cd "$cwd"

if [ $exit_status -ne 0 ]; then
echo Error
Expand All @@ -39,6 +39,8 @@ cleanup() {
}

trap cleanup EXIT
# stop at first error
set -e

# create verdaccio config
# - store packages in temp directory so they are deleted on exit
Expand All @@ -55,12 +57,13 @@ packages:
uplinks:
npmjs:
url: https://registry.npmjs.org/
" >$verdaccio_config
" >"$verdaccio_config"

# start verdaccio and wait for it to boot
echo Starting local registry
nohup verdaccio -l $registry_port -c $verdaccio_config &>$registry_log &
grep -q 'http address' <(tail -f $registry_log)
verdaccio -l $registry_port -c "$verdaccio_config" &>"$registry_log" &
verdaccio_pid=$!
grep -q 'http address' <(tail -f "$registry_log")

# set dummy authToken which is required to publish
# https://github.com/verdaccio/verdaccio/issues/212#issuecomment-308578500
Expand All @@ -81,32 +84,22 @@ echo '{
"dependencies": {
"npm-check-updates": "1.0.0"
}
}' >$temp_dir/package.json
}' >"$temp_dir"/package.json

# --configFilePath to avoid reading the repo .ncurc
# --cwd to point to the temp package file
# --pre 1 to ensure that an upgrade is always suggested even if npm-check-updates is on a prerelease version
npx --registry $registry_local npm-check-updates --configFilePath $temp_dir --cwd $temp_dir --pre 1 --registry $registry_local

rm $temp_dir/package.json
cp -r $e2e_dir/e2e $temp_dir

# Test: cjs
echo Test: cjs
cd $temp_dir/e2e/cjs
npx --registry $registry_local npm-check-updates --configFilePath "$temp_dir" --cwd "$temp_dir" --pre 1 --registry $registry_local

echo Installing
npm i npm-check-updates@latest --registry $registry_local

echo Running test
REGISTRY=$registry_local node $temp_dir/e2e/cjs/index.js
rm "$temp_dir"/package.json
cp -r "$e2e_dir"/e2e "$temp_dir"

# Test: esm
echo Test: esm
cd $temp_dir/e2e/esm
cd "$temp_dir"/e2e/esm

echo Installing
npm i npm-check-updates@latest --registry $registry_local

echo Running test
REGISTRY=$registry_local node $temp_dir/e2e/esm/index.js
REGISTRY=$registry_local node "$temp_dir"/e2e/esm/index.js
28 changes: 0 additions & 28 deletions test/e2e/cjs/index.js

This file was deleted.

1 change: 0 additions & 1 deletion test/e2e/cjs/package.json

This file was deleted.

4 changes: 2 additions & 2 deletions test/e2e/esm/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** NOTE: This script is copied into a temp directory by the e2e test and dependencies are installed from the local verdaccio registry. */
import assert from 'assert'
import ncu from 'npm-check-updates'
import { run } from 'npm-check-updates'

const registry = process.env.REGISTRY || 'http://localhost:4873'

Expand All @@ -11,7 +11,7 @@ process.on('unhandledRejection', (reason, p) => {

// test
;(async () => {
const upgraded = await ncu.run({
const upgraded = await run({
// --pre 1 to ensure that an upgrade is always suggested even if npm-check-updates is on a prerelease version
pre: true,
packageData: JSON.stringify({
Expand Down
18 changes: 12 additions & 6 deletions test/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ const bin = path.join(__dirname, '../build/cli.js')
describe('filter', () => {
describe('module', () => {
let stub: { restore: () => void }
before(() => (stub = stubVersions('99.9.9')))
after(() => stub.restore())
beforeEach(() => {
stub = stubVersions('99.9.9')
})
afterEach(() => stub.restore())

it('filter by package name with one arg', async () => {
const upgraded = (await ncu({
Expand Down Expand Up @@ -203,8 +205,10 @@ describe('filter', () => {

describe('cli', () => {
let stub: { restore: () => void }
before(() => (stub = stubVersions('99.9.9', { spawn: true })))
after(() => stub.restore())
beforeEach(() => {
stub = stubVersions('99.9.9', { spawn: true })
})
afterEach(() => stub.restore())

it('filter by package name with --filter', async () => {
const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--stdin', '--filter', 'express'], {
Expand Down Expand Up @@ -296,8 +300,10 @@ describe('filter', () => {
describe('reject', () => {
describe('cli', () => {
let stub: { restore: () => void }
before(() => (stub = stubVersions('99.9.9', { spawn: true })))
after(() => stub.restore())
beforeEach(() => {
stub = stubVersions('99.9.9', { spawn: true })
})
afterEach(() => stub.restore())

it('reject by package name with --reject', async () => {
const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--stdin', '--reject', 'chalk'], {
Expand Down
4 changes: 2 additions & 2 deletions test/filterVersion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ const bin = path.join(__dirname, '../build/cli.js')
describe('filterVersion', () => {
describe('module', () => {
let stub: { restore: () => void }
before(() => {
beforeEach(() => {
stub = stubVersions({
'ncu-test-v2': '2.0.0',
'ncu-test-return-version': '2.0.0',
})
})
after(() => {
afterEach(() => {
stub.restore()
})

Expand Down
4 changes: 2 additions & 2 deletions test/interactive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const bin = path.join(__dirname, '../build/cli.js')

describe('--interactive', () => {
let stub: { restore: () => void }
before(() => {
beforeEach(() => {
stub = stubVersions(
{
'ncu-test-v2': '2.0.0',
Expand All @@ -22,7 +22,7 @@ describe('--interactive', () => {
{ spawn: true },
)
})
after(() => {
afterEach(() => {
stub.restore()
})

Expand Down
6 changes: 4 additions & 2 deletions test/rc-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ const bin = path.join(__dirname, '../build/cli.js')
describe('rc-config', () => {
// before/after must be placed within the describe block, otherwise they will apply to tests in other files
let stub: { restore: () => void }
before(() => (stub = stubVersions('99.9.9', { spawn: true })))
after(() => stub.restore())
beforeEach(() => {
stub = stubVersions('99.9.9', { spawn: true })
})
afterEach(() => stub.restore())

it('print rcConfigPath when there is a non-empty rc config file', async () => {
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))
Expand Down