Skip to content

Commit 291903b

Browse files
author
Chris Brody
authored
add package engines & use please-upgrade-node (#295)
to enforce minimum Node.js version in CLI
1 parent c390e6d commit 291903b

File tree

7 files changed

+48
-1
lines changed

7 files changed

+48
-1
lines changed

lib/cli-program.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
const pkg = require('./../package.json');
2+
require('please-upgrade-node')(pkg);
3+
14
const program = require('commander');
5+
26
const updateNotifier = require('update-notifier');
37

48
const command = require('./cli-command');
5-
const pkg = require('./../package.json');
69

710
updateNotifier({ pkg }).notify();
811

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"description": "Tool to create a React Native library module or view module with a single command",
55
"bin": "bin/cli.js",
66
"main": "lib/lib.js",
7+
"engines": {
8+
"node": ">= 8"
9+
},
710
"scripts": {
811
"jest": "jest",
912
"lint": "eslint .",
@@ -48,6 +51,7 @@
4851
"node-emoji": "^1.10.0",
4952
"param-case": "^2.1.1",
5053
"pascal-case": "^2.0.1",
54+
"please-upgrade-node": "^3.2.0",
5155
"update-notifier": "^4.1.0"
5256
},
5357
"devDependencies": {

tests/with-mocks/cli/program/with-defaults/for-android/__snapshots__/cli-program-with-defaults-for-android.test.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
exports[`mocked cli-program.js runs correctly defaults 1`] = `
44
Array [
5+
Object {
6+
"please-upgrade-node": Object {
7+
"engines": Object {
8+
"node": ">= 8",
9+
},
10+
"name": "create-react-native-module",
11+
},
12+
},
513
Object {
614
"notify": Object {},
715
},

tests/with-mocks/cli/program/with-defaults/for-android/cli-program-with-defaults-for-android.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// special compact mocks for this test:
22
const mysnap = [];
33
const mockpushit = x => mysnap.push(x);
4+
jest.mock('please-upgrade-node', () => ({ name, engines }) => {
5+
// only snapshot a limited number of fields
6+
expect(name).toBeDefined();
7+
expect(engines).toBeDefined();
8+
mockpushit({ 'please-upgrade-node': { name, engines } });
9+
});
410
jest.mock('update-notifier', () => ({ pkg }) => {
511
// only check a limited number of fields in pkg
612
expect(pkg.name).toBeDefined();

tests/with-mocks/cli/program/with-missing-args/__snapshots__/cli-program-with-missing-args.test.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
exports[`mocked cli-program.js shows help in case of missing args 1`] = `
44
Array [
5+
Object {
6+
"please-upgrade-node": Object {
7+
"engines": Object {
8+
"node": ">= 8",
9+
},
10+
"name": "create-react-native-module",
11+
},
12+
},
513
Object {
614
"notify": Object {},
715
},

tests/with-mocks/cli/program/with-missing-args/cli-program-with-missing-args.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// special compact mocks for this test:
22
const mysnap = [];
33
const mockpushit = x => mysnap.push(x);
4+
jest.mock('please-upgrade-node', () => ({ name, engines }) => {
5+
// only snapshot a limited number of fields
6+
expect(name).toBeDefined();
7+
expect(engines).toBeDefined();
8+
mockpushit({ 'please-upgrade-node': { name, engines } });
9+
});
410
jest.mock('update-notifier', () => ({ pkg }) => {
511
// only check a limited number of fields in pkg
612
expect(pkg.name).toBeDefined();

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3864,6 +3864,13 @@ pkg-dir@^3.0.0:
38643864
dependencies:
38653865
find-up "^3.0.0"
38663866

3867+
please-upgrade-node@^3.2.0:
3868+
version "3.2.0"
3869+
resolved "https://registry.yarnpkg.com/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz#aeddd3f994c933e4ad98b99d9a556efa0e2fe942"
3870+
integrity sha512-gQR3WpIgNIKwBMVLkpMUeR3e1/E1y42bqDQZfql+kDeXd8COYfM8PQA4X6y7a8u9Ua9FHmsrrmirW2vHs45hWg==
3871+
dependencies:
3872+
semver-compare "^1.0.0"
3873+
38673874
pn@^1.1.0:
38683875
version "1.1.0"
38693876
resolved "https://registry.yarnpkg.com/pn/-/pn-1.1.0.tgz#e2f4cef0e219f463c179ab37463e4e1ecdccbafb"
@@ -4262,6 +4269,11 @@ sax@^1.2.4:
42624269
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
42634270
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
42644271

4272+
semver-compare@^1.0.0:
4273+
version "1.0.0"
4274+
resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc"
4275+
integrity sha1-De4hahyUGrN+nvsXiPavxf9VN/w=
4276+
42654277
semver-diff@^3.1.1:
42664278
version "3.1.1"
42674279
resolved "https://registry.yarnpkg.com/semver-diff/-/semver-diff-3.1.1.tgz#05f77ce59f325e00e2706afd67bb506ddb1ca32b"

0 commit comments

Comments
 (0)