Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Convert to ESM + switch to meow
Browse files Browse the repository at this point in the history
And swap `micromatch` for `picomatch`(which was the only part of `micromatch` which we used)
  • Loading branch information
voxpelli committed Jun 27, 2022
1 parent 9a83eb6 commit 620c0c2
Show file tree
Hide file tree
Showing 23 changed files with 312 additions and 384 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "@voxpelli",
"root": true,
"rules": {
"semi": ["error", "never"]
"semi": ["error", "never"],
"func-style": ["warn", "declaration", { "allowArrowFunctions": true }]
}
}
8 changes: 1 addition & 7 deletions .github/workflows/exit-silently-on-unsupported.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
env: {}

# FILE GENERATED WITH: npx ghat voxpelli/ghatemplates/exit-silently-on-unsupported
# SOURCE: https://github.com/voxpelli/ghatemplates
# OPTIONS: {"set":["jobs.test.strategy.matrix.node_version=[0.10.48,12]"]}

name: Exit silently on unsupported
on:
push:
Expand All @@ -29,7 +23,7 @@ jobs:
os:
- ubuntu-latest
files:
- ./cli.js
- ./cli.cjs
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node_version }}
Expand Down
12 changes: 5 additions & 7 deletions cli.js → cli.cjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env node
/* eslint-disable no-var, no-console, unicorn/prefer-number-properties */
/* eslint-disable no-var, no-console, promise/prefer-await-to-then, unicorn/prefer-number-properties, unicorn/no-process-exit */

'use strict'

if (require('./package.json').engines.node !== '^14.17.0 || >=16.0.0') {
if (require('./package.json').engines.node !== '^14.18.0 || >=16.0.0') {
console.error('dependency-check: Mismatch between package.json node engine and cli engine check')
process.exit(1)
}
Expand All @@ -12,9 +10,9 @@ var match = process.version.match(/v(\d+)\.(\d+)/) || []
var major = parseInt(match[1] || '', 10)
var minor = parseInt(match[2] || '', 10)

if (major > 14 || (major === 14 && minor >= 17)) {
require('./lib/cli-engine')
if (major > 14 || (major === 14 && minor >= 18)) {
require('./lib/cli-engine-import.cjs')
} else {
console.error('dependency-check: Node 14.17.0 or greater is required. `dependency-check` did not run.')
console.error('dependency-check: Node 14.18.0 or greater is required. `dependency-check` did not run.')
process.exit(0)
}
15 changes: 5 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
'use strict'

const { check } = require('./lib/check')
const { extra, missing } = require('./lib/compare')

module.exports = {
check,
extra,
missing,
}
export { check } from './lib/check.js'
export {
findUnused as extra,
findMissing as missing
} from './lib/compare.js'
18 changes: 5 additions & 13 deletions lib/check.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
'use strict'

const { getExtensions } = require('./extensions')
const { parse } = require('./parse')
import { getExtensions } from './extensions.js'
import { parse } from './parse.js'

const {
resolveEntryTarget,
resolveModuleTarget
} = require('./resolve-target')
import { resolveEntryTarget, resolveModuleTarget } from './resolve-target.js'

/**
* @typedef CheckOptions
Expand All @@ -23,7 +19,7 @@ const {
* @param {CheckOptions} opts
* @returns {Promise<import('./parse').ParseResult>}
*/
const check = async function (opts) {
export async function check (opts) {
if (!opts) throw new Error('Requires an opts argument to be set')

const {
Expand Down Expand Up @@ -52,14 +48,10 @@ const check = async function (opts) {
return parse({
builtins,
entries: [...(targetEntries || []), ...(entries || [])],
extensions: getExtensions(extensions, detective),
extensions: await getExtensions(extensions, detective),
ignoreUnknownExtensions,
noDefaultEntries: noDefaultEntries || (targetEntries && targetEntries.length !== 0),
'package': pkg,
path: pkgPath
})
}

module.exports = {
check
}
13 changes: 13 additions & 0 deletions lib/cli-engine-import.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable no-console, promise/prefer-await-to-then, unicorn/no-process-exit */

'use strict'

// This file purely exists because "import" is a reserved word in old node.js and
// thus can't be included directly in the cli.cjs file without error

import('./cli-engine.js').catch(err => {
console.error('unexpected error:', err)
process.exit(1)
})

module.exports = {}
Loading

0 comments on commit 620c0c2

Please sign in to comment.