Skip to content

Commit 581d0dc

Browse files
authored
chore(node): drop Node 10 support (#136)
This also converts the project to pure ESM as it is fully supported in Node 12.20 and beyond. BREAKING CHANGE: This removes support for Node v10 and makes the new minimum runtime Node v12.20, as v10 is EOL. Please upgrade your Node.js environment to at least version 12.20, or continue using the latest v9 release of `pwned` if you are unable to upgrade your environment.
1 parent a5f7e85 commit 581d0dc

25 files changed

+140
-91
lines changed

.babelrc.cjs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const isTest = process.env.NODE_ENV === 'test';
2+
3+
module.exports = {
4+
plugins: [
5+
isTest && 'babel-plugin-transform-import-meta',
6+
!isTest && 'babel-plugin-add-import-extension',
7+
].filter(Boolean),
8+
presets: [
9+
[
10+
'@babel/preset-env',
11+
{
12+
// needed for jest.mock() until they have a way to mock ES modules
13+
modules: isTest ? 'commonjs' : false,
14+
targets: {
15+
node: '12.20',
16+
},
17+
},
18+
],
19+
'@babel/preset-typescript',
20+
],
21+
};

.babelrc.js

-13
This file was deleted.

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
- checkout
1616
- node/install-packages:
1717
pkg-manager: yarn
18+
- run: yarn build
1819
- run: yarn validate
1920
- run: yarn test --coverage --no-cache --maxWorkers 4
2021
- run: yarn codecov
21-
- run: yarn build
2222
- persist_to_workspace:
2323
root: ~/
2424
paths:

.eslintrc.js .eslintrc.cjs

File renamed without changes.

bin/pwned.js

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
#!/usr/bin/env node
2-
require('source-map-support/register');
3-
const path = require('path');
4-
const yargs = require('yargs');
2+
import sourceMapSupport from 'source-map-support';
3+
import yargs from 'yargs';
4+
import { hideBin } from 'yargs/helpers';
5+
6+
/* eslint-disable import/extensions */
7+
import * as apiKey from '../lib/commands/apiKey.js';
8+
import * as ba from '../lib/commands/ba.js';
9+
import * as breach from '../lib/commands/breach.js';
10+
import * as breaches from '../lib/commands/breaches.js';
11+
import * as dc from '../lib/commands/dc.js';
12+
import * as pa from '../lib/commands/pa.js';
13+
import * as pw from '../lib/commands/pw.js';
14+
import * as search from '../lib/commands/search.js';
15+
16+
sourceMapSupport.install();
517

618
// eslint-disable-next-line no-unused-expressions
7-
yargs
8-
.commandDir(path.join(__dirname, '..', 'lib', 'commands'))
19+
yargs(hideBin(process.argv))
20+
.command(apiKey)
21+
.command(ba)
22+
.command(breach)
23+
.command(breaches)
24+
.command(dc)
25+
.command(pa)
26+
.command(pw)
27+
.command(search)
928
.demandCommand()
1029
.recommendCommands()
1130
.strict()
12-
.wrap(Math.min(100, yargs.terminalWidth()))
31+
.wrap(Math.min(100, yargs().terminalWidth()))
1332
.alias('h', 'help')
1433
.alias('v', 'version').argv;
File renamed without changes.

jest.config.js jest.config.cjs

File renamed without changes.
File renamed without changes.

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
},
2020
"contributors": [],
2121
"license": "MIT",
22+
"type": "module",
2223
"main": "bin/pwned.js",
2324
"bin": "bin/pwned.js",
2425
"directories": {
@@ -61,7 +62,7 @@
6162
},
6263
"homepage": "https://wkovacs64.github.io/pwned",
6364
"engines": {
64-
"node": ">= 10"
65+
"node": ">= 12.20"
6566
},
6667
"dependencies": {
6768
"common-tags": "^1.8.0",
@@ -80,6 +81,7 @@
8081
"@babel/preset-typescript": "7.13.0",
8182
"@commitlint/cli": "12.1.1",
8283
"@commitlint/config-conventional": "12.1.1",
84+
"@jest/globals": "26.6.2",
8385
"@types/common-tags": "1.8.0",
8486
"@types/jest": "26.0.23",
8587
"@types/node": "12.20.11",
@@ -88,6 +90,8 @@
8890
"@types/yargs": "16.0.1",
8991
"@wkovacs64/prettier-config": "3.0.0",
9092
"babel-jest": "26.6.3",
93+
"babel-plugin-add-import-extension": "1.5.1",
94+
"babel-plugin-transform-import-meta": "2.0.0",
9195
"codecov": "3.8.1",
9296
"commitizen": "4.2.3",
9397
"cross-env": "7.0.3",
File renamed without changes.
File renamed without changes.

src/commands/__tests__/ba.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { jest } from '@jest/globals';
12
import * as hibp from 'hibp';
23
import {
34
spinnerFns,

src/commands/__tests__/breach.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { jest } from '@jest/globals';
12
import * as hibp from 'hibp';
23
import {
34
spinnerFns,

src/commands/__tests__/breaches.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { jest } from '@jest/globals';
12
import * as hibp from 'hibp';
23
import {
34
spinnerFns,

src/commands/__tests__/dc.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { jest } from '@jest/globals';
12
import * as hibp from 'hibp';
23
import {
34
spinnerFns,

src/commands/__tests__/pa.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { jest } from '@jest/globals';
12
import * as hibp from 'hibp';
23
import {
34
spinnerFns,

src/commands/__tests__/pw.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { jest } from '@jest/globals';
12
import * as hibp from 'hibp';
23
import {
34
spinnerFns,

src/commands/__tests__/search.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { jest } from '@jest/globals';
12
import * as hibp from 'hibp';
23
import {
34
spinnerFns,

src/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Conf from 'conf';
2-
import * as pkg from '../package.json';
2+
import { pkg } from './utils';
33

44
export const config = new Conf<{ apiKey: string }>({
55
projectName: pkg.name,

src/utils/__tests__/logger.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-console */
2+
import { jest } from '@jest/globals';
23
import { loggerFns } from '../../../test/fixtures';
34
import { logger, Logger, LoggerFunction } from '../logger';
45

src/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './logger';
2+
export * from './pkg';
23
export * from './spinner';
34
export * from './translate-api-error';
45
export * from './user-agent';

src/utils/pkg.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import url from 'url';
4+
5+
const dirname = path.dirname(url.fileURLToPath(import.meta.url));
6+
7+
export const pkg = JSON.parse(
8+
fs.readFileSync(path.join(dirname, '..', '..', 'package.json'), 'utf8'),
9+
);

src/utils/user-agent.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import * as pkg from '../../package.json';
1+
import { pkg } from './pkg';
22

33
export const userAgent = `${pkg.name} ${pkg.version}`;

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"compilerOptions": {
33
"lib": ["esnext"],
4-
"target": "esnext",
4+
"target": "es2019", // Node 12
5+
"module": "es2020",
56
"moduleResolution": "node",
6-
"resolveJsonModule": true,
77
"esModuleInterop": true,
88
"noEmit": true,
99
"strict": true,

0 commit comments

Comments
 (0)