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

esm #1358

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft

esm #1358

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.
161 changes: 12 additions & 149 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@
"node": "^18.18.0 || >=20.0.0",
"npm": ">=8.12.1"
},
"exports": {
".": {
"import": "./build/index.js",
"require": "./build/index.js"
}
},
"type": "module",
"main": "build/index.js",
"types": "build/index.d.ts",
"scripts": {
"build": "rimraf build && npm run build:options && vite build",
"build:options": "vite-node src/scripts/build-options.ts",
"lint": "cross-env FORCE_COLOR=1 npm-run-all --parallel --aggregate-output lint:*",
"lint:lockfile": "lockfile-lint",
"lint:markdown": "markdownlint \"**/*.md\" --ignore node_modules --ignore build --config .markdownlint.js",
"lint:markdown": "markdownlint \"**/*.md\" --ignore node_modules --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 && test/bun-setup.sh",
"prepublishOnly": "npm run build",
Expand Down Expand Up @@ -64,7 +71,7 @@
"@types/js-yaml": "^4.0.9",
"@types/json-parse-helpfulerror": "^1.0.3",
"@types/jsonlines": "^0.1.5",
"@types/lodash": "^4.17.0",
"@types/lodash-es": "^4.17.12",
"@types/make-fetch-happen": "^10.0.4",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.30",
Expand Down Expand Up @@ -105,7 +112,7 @@
"json-parse-helpfulerror": "^1.0.3",
"jsonlines": "^0.1.1",
"lockfile-lint": "^4.13.2",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"make-fetch-happen": "^13.0.0",
"markdownlint-cli": "^0.39.0",
"mocha": "^10.4.0",
Expand All @@ -124,7 +131,6 @@
"semver": "^7.6.0",
"semver-utils": "^1.1.4",
"should": "^13.2.3",
"sinon": "^17.0.1",
"source-map-support": "^0.5.21",
"spawn-please": "^3.0.0",
"strip-ansi": "^7.1.0",
Expand Down Expand Up @@ -160,7 +166,11 @@
"mocha": {
"check-leaks": true,
"extension": [
"test.ts"
"ts"
],
"node-option": [
"experimental-specifier-resolution=node",
"loader=ts-node/esm"
],
"require": [
"source-map-support/register",
Expand Down
18 changes: 11 additions & 7 deletions src/bin/cli.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#!/usr/bin/env node
import { Help, Option, program } from 'commander'
import cloneDeep from 'lodash/cloneDeep'
import pickBy from 'lodash/pickBy'
import { cloneDeep, pickBy } from 'lodash-es'
import fs from 'node:fs/promises'
import path from 'node:path'
import semver from 'semver'
import pkg from '../../package.json'
import cliOptions, { renderExtendedHelp } from '../cli-options'
import ncu from '../index'
import { chalkInit } from '../lib/chalk'
import cliOptions, { renderExtendedHelp } from '../cli-options.js'
import ncu from '../index.js'
import { chalkInit } from '../lib/chalk.js'
// async global contexts are only available in esm modules -> function
import getNcuRc from '../lib/getNcuRc'
import getNcuRc from '../lib/getNcuRc.js'

const __dirname = path.dirname(new URL(import.meta.url).pathname)

const optionVersionDescription = 'Output the version number of npm-check-updates.'

Expand All @@ -19,6 +21,8 @@ const uncode = (s: string) => s.replace(/`/g, '')
// importing update-notifier dynamically as esm modules are only allowed to be dynamically imported inside of cjs modules
const { default: updateNotifier } = await import('update-notifier')

const pkg = JSON.parse(await fs.readFile(path.join(__dirname, '../../../package.json'), 'utf-8'))

// check if a new version of ncu is available and print an update notification
//
// For testing from specific versions, use:
Expand Down
16 changes: 8 additions & 8 deletions src/cli-options.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import sortBy from 'lodash/sortBy'
import path from 'path'
import { defaultCacheFile } from './lib/cache'
import chalk from './lib/chalk'
import table from './lib/table'
import CLIOption from './types/CLIOption'
import ExtendedHelp from './types/ExtendedHelp'
import { Index } from './types/IndexType'
import { sortBy } from 'lodash-es'
import path from 'node:path'
import { defaultCacheFile } from './lib/cache.js'
import chalk from './lib/chalk.js'
import table from './lib/table.js'
import CLIOption from './types/CLIOption.js'
import ExtendedHelp from './types/ExtendedHelp.js'
import { Index } from './types/IndexType.js'

/** Valid strings for the --target option. Indicates the desired version to upgrade to. */
const supportedVersionTargets = ['latest', 'newest', 'greatest', 'minor', 'patch', 'semver']
Expand Down
46 changes: 23 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import isString from 'lodash/isString'
import path from 'path'
import { isString } from 'lodash-es'
import path from 'node:path'
import prompts from 'prompts-ncu'
import spawn from 'spawn-please'
import { cliOptionsMap } from './cli-options'
import { cacheClear } from './lib/cache'
import chalk, { chalkInit } from './lib/chalk'
import determinePackageManager from './lib/determinePackageManager'
import doctor from './lib/doctor'
import exists from './lib/exists'
import findPackage from './lib/findPackage'
import getAllPackages from './lib/getAllPackages'
import getNcuRc from './lib/getNcuRc'
import initOptions from './lib/initOptions'
import { print, printJson } from './lib/logging'
import mergeOptions from './lib/mergeOptions'
import programError from './lib/programError'
import runGlobal from './lib/runGlobal'
import runLocal from './lib/runLocal'
import { Index } from './types/IndexType'
import { Options } from './types/Options'
import { PackageFile } from './types/PackageFile'
import { PackageInfo } from './types/PackageInfo'
import { RunOptions } from './types/RunOptions'
import { VersionSpec } from './types/VersionSpec'
import { cliOptionsMap } from './cli-options.js'
import { cacheClear } from './lib/cache.js'
import chalk, { chalkInit } from './lib/chalk.js'
import determinePackageManager from './lib/determinePackageManager.js'
import doctor from './lib/doctor.js'
import exists from './lib/exists.js'
import findPackage from './lib/findPackage.js'
import getAllPackages from './lib/getAllPackages.js'
import getNcuRc from './lib/getNcuRc.js'
import initOptions from './lib/initOptions.js'
import { print, printJson } from './lib/logging.js'
import mergeOptions from './lib/mergeOptions.js'
import programError from './lib/programError.js'
import runGlobal from './lib/runGlobal.js'
import runLocal from './lib/runLocal.js'
import { Index } from './types/IndexType.js'
import { Options } from './types/Options.js'
import { PackageFile } from './types/PackageFile.js'
import { PackageInfo } from './types/PackageInfo.js'
import { RunOptions } from './types/RunOptions.js'
import { VersionSpec } from './types/VersionSpec.js'

// allow prompt injection from environment variable for testing purposes
if (process.env.INJECT_PROMPTS) {
Expand Down