Skip to content

Commit

Permalink
chore(node): drop Node 10 support (#136)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wKovacs64 committed May 3, 2021
1 parent a5f7e85 commit 581d0dc
Show file tree
Hide file tree
Showing 25 changed files with 140 additions and 91 deletions.
21 changes: 21 additions & 0 deletions .babelrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const isTest = process.env.NODE_ENV === 'test';

module.exports = {
plugins: [
isTest && 'babel-plugin-transform-import-meta',
!isTest && 'babel-plugin-add-import-extension',
].filter(Boolean),
presets: [
[
'@babel/preset-env',
{
// needed for jest.mock() until they have a way to mock ES modules
modules: isTest ? 'commonjs' : false,
targets: {
node: '12.20',
},
},
],
'@babel/preset-typescript',
],
};
13 changes: 0 additions & 13 deletions .babelrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
- checkout
- node/install-packages:
pkg-manager: yarn
- run: yarn build
- run: yarn validate
- run: yarn test --coverage --no-cache --maxWorkers 4
- run: yarn codecov
- run: yarn build
- persist_to_workspace:
root: ~/
paths:
Expand Down
File renamed without changes.
31 changes: 25 additions & 6 deletions bin/pwned.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
#!/usr/bin/env node
require('source-map-support/register');
const path = require('path');
const yargs = require('yargs');
import sourceMapSupport from 'source-map-support';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

/* eslint-disable import/extensions */
import * as apiKey from '../lib/commands/apiKey.js';
import * as ba from '../lib/commands/ba.js';
import * as breach from '../lib/commands/breach.js';
import * as breaches from '../lib/commands/breaches.js';
import * as dc from '../lib/commands/dc.js';
import * as pa from '../lib/commands/pa.js';
import * as pw from '../lib/commands/pw.js';
import * as search from '../lib/commands/search.js';

sourceMapSupport.install();

// eslint-disable-next-line no-unused-expressions
yargs
.commandDir(path.join(__dirname, '..', 'lib', 'commands'))
yargs(hideBin(process.argv))
.command(apiKey)
.command(ba)
.command(breach)
.command(breaches)
.command(dc)
.command(pa)
.command(pw)
.command(search)
.demandCommand()
.recommendCommands()
.strict()
.wrap(Math.min(100, yargs.terminalWidth()))
.wrap(Math.min(100, yargs().terminalWidth()))
.alias('h', 'help')
.alias('v', 'version').argv;
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"contributors": [],
"license": "MIT",
"type": "module",
"main": "bin/pwned.js",
"bin": "bin/pwned.js",
"directories": {
Expand Down Expand Up @@ -61,7 +62,7 @@
},
"homepage": "https://wkovacs64.github.io/pwned",
"engines": {
"node": ">= 10"
"node": ">= 12.20"
},
"dependencies": {
"common-tags": "^1.8.0",
Expand All @@ -80,6 +81,7 @@
"@babel/preset-typescript": "7.13.0",
"@commitlint/cli": "12.1.1",
"@commitlint/config-conventional": "12.1.1",
"@jest/globals": "26.6.2",
"@types/common-tags": "1.8.0",
"@types/jest": "26.0.23",
"@types/node": "12.20.11",
Expand All @@ -88,6 +90,8 @@
"@types/yargs": "16.0.1",
"@wkovacs64/prettier-config": "3.0.0",
"babel-jest": "26.6.3",
"babel-plugin-add-import-extension": "1.5.1",
"babel-plugin-transform-import-meta": "2.0.0",
"codecov": "3.8.1",
"commitizen": "4.2.3",
"cross-env": "7.0.3",
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/commands/__tests__/ba.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jest } from '@jest/globals';
import * as hibp from 'hibp';
import {
spinnerFns,
Expand Down
1 change: 1 addition & 0 deletions src/commands/__tests__/breach.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jest } from '@jest/globals';
import * as hibp from 'hibp';
import {
spinnerFns,
Expand Down
1 change: 1 addition & 0 deletions src/commands/__tests__/breaches.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jest } from '@jest/globals';
import * as hibp from 'hibp';
import {
spinnerFns,
Expand Down
1 change: 1 addition & 0 deletions src/commands/__tests__/dc.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jest } from '@jest/globals';
import * as hibp from 'hibp';
import {
spinnerFns,
Expand Down
1 change: 1 addition & 0 deletions src/commands/__tests__/pa.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jest } from '@jest/globals';
import * as hibp from 'hibp';
import {
spinnerFns,
Expand Down
1 change: 1 addition & 0 deletions src/commands/__tests__/pw.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jest } from '@jest/globals';
import * as hibp from 'hibp';
import {
spinnerFns,
Expand Down
1 change: 1 addition & 0 deletions src/commands/__tests__/search.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jest } from '@jest/globals';
import * as hibp from 'hibp';
import {
spinnerFns,
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Conf from 'conf';
import * as pkg from '../package.json';
import { pkg } from './utils';

export const config = new Conf<{ apiKey: string }>({
projectName: pkg.name,
Expand Down
1 change: 1 addition & 0 deletions src/utils/__tests__/logger.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
import { jest } from '@jest/globals';
import { loggerFns } from '../../../test/fixtures';
import { logger, Logger, LoggerFunction } from '../logger';

Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './logger';
export * from './pkg';
export * from './spinner';
export * from './translate-api-error';
export * from './user-agent';
9 changes: 9 additions & 0 deletions src/utils/pkg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import fs from 'fs';
import path from 'path';
import url from 'url';

const dirname = path.dirname(url.fileURLToPath(import.meta.url));

export const pkg = JSON.parse(
fs.readFileSync(path.join(dirname, '..', '..', 'package.json'), 'utf8'),
);
2 changes: 1 addition & 1 deletion src/utils/user-agent.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import * as pkg from '../../package.json';
import { pkg } from './pkg';

export const userAgent = `${pkg.name} ${pkg.version}`;
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"lib": ["esnext"],
"target": "esnext",
"target": "es2019", // Node 12
"module": "es2020",
"moduleResolution": "node",
"resolveJsonModule": true,
"esModuleInterop": true,
"noEmit": true,
"strict": true,
Expand Down

0 comments on commit 581d0dc

Please sign in to comment.