Skip to content

Commit 7aac621

Browse files
authored
Merge pull request #4 from appcelerator/v3
V3
2 parents cd8fd42 + 412fc0f commit 7aac621

10 files changed

Lines changed: 519 additions & 5493 deletions

File tree

‎.eslintrc‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,64 @@
11
{
2+
"env": {
3+
"es6": true,
4+
"node": true
5+
},
6+
"extends": "eslint:recommended",
7+
"parserOptions": {
8+
"ecmaVersion": "2022",
9+
"sourceType": "module"
10+
},
11+
"plugins": [
12+
"chai-expect",
13+
"mocha",
14+
"promise",
15+
"security"
16+
],
17+
"root": true,
218
"rules": {
3-
"security/detect-non-literal-require": 0
19+
"array-bracket-spacing": [ "warn", "always" ],
20+
"brace-style": [ 2, "1tbs", { "allowSingleLine": true } ],
21+
"camelcase": "off",
22+
"chai-expect/missing-assertion": "error",
23+
"chai-expect/terminating-properties": "warn",
24+
"curly": [ "error", "all" ],
25+
"eol-last": "error",
26+
"indent": [ "error", "tab", { "SwitchCase": 1 } ],
27+
"keyword-spacing": [ "error" ],
28+
"linebreak-style": [ "error", "unix" ],
29+
"max-len": [ "error", 200 ],
30+
"no-case-declarations": "off",
31+
"no-cond-assign": "off",
32+
"no-console": "off",
33+
"no-constant-condition": "off",
34+
"no-control-regex": "off",
35+
"no-empty": "warn",
36+
"no-inner-declarations": "off",
37+
"no-mixed-spaces-and-tabs": "error",
38+
"no-multi-str": "error",
39+
"no-multiple-empty-lines": "error",
40+
"no-trailing-spaces": "error",
41+
"no-unused-vars": "off",
42+
"no-useless-escape": "warn",
43+
"promise/always-return": "error",
44+
"promise/no-return-wrap": "error",
45+
"promise/param-names": "error",
46+
"promise/catch-or-return": "error",
47+
"promise/no-native": "off",
48+
"promise/no-nesting": "warn",
49+
"promise/no-promise-in-callback": "warn",
50+
"promise/no-callback-in-promise": "warn",
51+
"promise/avoid-new": "off",
52+
"promise/no-new-statics": "error",
53+
"promise/no-return-in-finally": "warn",
54+
"promise/valid-params": "warn",
55+
"quotes": [ "error", "single" ],
56+
"semi": [ "error", "always" ],
57+
"space-before-blocks": [ "error", "always" ],
58+
"space-before-function-paren": [ "error", { "anonymous": "always", "named": "ignore", "asyncArrow": "always" }],
59+
"space-in-parens": [ "error", "never" ],
60+
"space-infix-ops": "error",
61+
"space-unary-ops": [ "error", { "nonwords": false, "overrides": {} } ],
62+
"valid-jsdoc": [ "warn", { "requireReturn": false, "requireReturnDescription": false } ]
463
}
564
}

‎.gitattributes‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.js text eol=lf
2+
*.json text eol=lf
3+
*.md text eol=lf

‎.github/workflows/build.yml‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build
2+
on:
3+
- pull_request
4+
- push
5+
6+
jobs:
7+
Lint:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
with:
12+
fetch-depth: 0
13+
- uses: actions/setup-node@v3
14+
with:
15+
node-version: '16.x'
16+
- name: Install dependencies
17+
run: yarn
18+
- name: Lint
19+
run: yarn run lint
20+
21+
Test:
22+
needs: Lint
23+
name: ${{ matrix.os }} ${{ matrix.nodeVersion }} Tests
24+
runs-on: ${{ matrix.os }}
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
nodeVersion: [ '14.19.3', '16.15.1', '18.4.0' ]
29+
os: [ macos-latest, ubuntu-latest, windows-latest ]
30+
steps:
31+
- uses: actions/checkout@v3
32+
with:
33+
fetch-depth: 0
34+
- uses: actions/setup-node@v3
35+
with:
36+
node-version: ${{ matrix.nodeVersion }}
37+
- name: Install dependencies
38+
run: yarn
39+
- name: Run tests
40+
run: yarn run test

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# v3.0.0 (July 5, 2022)
2+
3+
* BREAKING CHANGE: Require Node.js 14.15.0 LTS or newer.
4+
* BREAKING CHANGE: Changed package to a ES module.
5+
* chore: Updated dependencies.
6+
17
# v2.0.0 (Feb 15, 2022)
28

39
* BREAKING CHANGE: Require Node.js 12.13.0 LTS or newer.

‎Jenkinsfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
library 'pipeline-library'
33

44
runNPMPackage {
5-
nodeVersions = [ '12.18.0', '14.4.0' ]
5+
nodeVersions = [ '14.19.3', '16.15.1', '18.4.0' ]
66
}

‎gulpfile.js‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎package.json‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "check-kit",
33
"version": "2.0.0",
44
"description": "Checks if a newer version is available for command line interfaces",
5-
"main": "./dist/index.js",
5+
"type": "module",
6+
"exports": "./src/index.js",
67
"author": "Axway, Inc. <npmjs@appcelerator.com>",
78
"maintainers": [
89
"Chris Barber <cbarber@axway.com>"
@@ -21,26 +22,31 @@
2122
"latest"
2223
],
2324
"scripts": {
24-
"build": "gulp build",
25-
"coverage": "gulp coverage",
26-
"docs": "gulp docs",
27-
"lint": "gulp lint",
28-
"prepare": "gulp build",
29-
"test": "gulp test"
25+
"coverage": "c8 npm run test",
26+
"lint": "eslint --ignore-pattern test/fixtures src test",
27+
"prepublishOnly": "npm run lint",
28+
"test": "npm run lint && mocha test/**/test-*.js --reporter spec"
3029
},
3130
"dependencies": {
32-
"@axway/amplify-request": "^3.0.6",
33-
"babel-plugin-source-map-support": "^2.1.3",
34-
"ci-info": "^3.3.0",
35-
"fs-extra": "^9.1.0",
36-
"registry-auth-token": "4.2.1",
37-
"semver": "^7.3.5",
38-
"snooplogg": "^3.0.2",
31+
"@axway/amplify-request": "^3.0.10",
32+
"ci-info": "^3.3.2",
33+
"fs-extra": "^10.1.0",
34+
"registry-auth-token": "5.0.1",
35+
"semver": "^7.3.7",
36+
"snooplogg": "^5.0.0",
3937
"source-map-support": "^0.5.21",
4038
"tmp": "^0.2.1"
4139
},
4240
"devDependencies": {
43-
"@axway/gulp-tasks": "^4.1.1"
41+
"c8": "^7.11.3",
42+
"chai": "^4.3.6",
43+
"chai-as-promised": "^7.1.1",
44+
"eslint": "^8.19.0",
45+
"eslint-plugin-chai-expect": "^3.0.0",
46+
"eslint-plugin-mocha": "^10.0.5",
47+
"eslint-plugin-promise": "^6.0.0",
48+
"eslint-plugin-security": "^1.5.0",
49+
"mocha": "^10.0.0"
4450
},
4551
"homepage": "https://github.com/appcelerator/check-kit",
4652
"bugs": "https://github.com/appcelerator/check-kit/issues",
@@ -49,6 +55,6 @@
4955
"url": "git://github.com/appcelerator/check-kit.git"
5056
},
5157
"engines": {
52-
"node": ">=12.13.0"
58+
"node": ">=14.15.0"
5359
}
5460
}

‎src/index.js‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
/* istanbul ignore if */
2-
if (!Error.prepareStackTrace) {
3-
require('source-map-support/register');
4-
}
5-
61
import fs from 'fs-extra';
72
import path from 'path';
83
import semver from 'semver';
94
import snooplogg from 'snooplogg';
105
import * as request from '@axway/amplify-request';
116
import { isCI } from 'ci-info';
12-
import { tmpdir } from 'tmp';
13-
import { writeFileSync } from './fsutil';
7+
import tmp from 'tmp';
8+
import { writeFileSync } from './fsutil.js';
149

1510
const { error, log, warn } = snooplogg('check-kit');
1611
const { highlight } = snooplogg.styles;
@@ -56,7 +51,7 @@ export async function check(opts = {}) {
5651

5752
// bail immediately if update notifications have been explicitly disabled or we're running
5853
// within a test
59-
if (!force && (process.env.NO_UPDATE_NOTIFIER || process.env.NODE_ENV === 'test' || isCI)) {
54+
if (!force && !process.env.FORCE_UPDATE_NOTIFIER && (process.env.NO_UPDATE_NOTIFIER || process.env.NODE_ENV === 'test' || isCI)) {
6055
return {};
6156
}
6257

@@ -66,7 +61,7 @@ export async function check(opts = {}) {
6661

6762
// determine the meta directory
6863
if (!metaDir) {
69-
metaDir = process.env.TEST_META_DIR || path.join(tmpdir, 'check-kit');
64+
metaDir = process.env.TEST_META_DIR || path.join(tmp.tmpdir, 'check-kit');
7065
} else if (typeof metaDir !== 'string') {
7166
throw new TypeError('Expected metaDir to be a string');
7267
}
@@ -239,7 +234,7 @@ export async function loadPackageJson(opts = {}) {
239234
*/
240235
async function getLatestVersion(name, distTag, opts) {
241236
const p = name.indexOf('/');
242-
const regUrl = opts.registryUrl || require('registry-auth-token/registry-url')(p !== -1 ? name.substring(0, p) : '');
237+
const regUrl = opts.registryUrl || (await import('registry-auth-token/registry-url.js')).default(p !== -1 ? name.substring(0, p) : '');
243238
const got = request.init(opts);
244239
const reqOpts = {
245240
followRedirect: true,
@@ -248,7 +243,9 @@ async function getLatestVersion(name, distTag, opts) {
248243
},
249244
responseType: 'json',
250245
retry: 0,
251-
timeout: Object.prototype.hasOwnProperty.call(opts, 'timeout') ? opts.timeout : 1000,
246+
timeout: {
247+
request: Object.prototype.hasOwnProperty.call(opts, 'timeout') ? opts.timeout : 1000
248+
},
252249
url: new URL(encodeURIComponent(name).replace(/^%40/, '@'), regUrl)
253250
};
254251
let info;
@@ -279,7 +276,7 @@ async function getLatestVersion(name, distTag, opts) {
279276
}
280277

281278
// package does not exist or we can't access it
282-
const authInfo = require('registry-auth-token')(regUrl, { recursive: true });
279+
const authInfo = (await import('registry-auth-token')).default(regUrl, { recursive: true });
283280
if (!authInfo) {
284281
// no auth info, bail out
285282
return null;

‎test/test-check-kit.js‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
import check, { loadPackageJson } from '../dist/index';
1+
import chai, { expect } from 'chai';
2+
import chaiAsPromised from 'chai-as-promised';
3+
import check, { loadPackageJson } from '../src/index.js';
24
import fs from 'fs-extra';
35
import http from 'http';
46
import path from 'path';
57
import snooplogg from 'snooplogg';
68
import tmp from 'tmp';
9+
import { fileURLToPath } from 'url';
10+
11+
chai.use(chaiAsPromised);
12+
13+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
714

815
const { log } = snooplogg('test:check-kit');
916
const { highlight } = snooplogg.styles;
1017

1118
process.env.TEST_META_DIR = tmp.dirSync({ prefix: 'check-kit-test' }).name;
1219

1320
describe('check-kit', function () {
21+
beforeEach(() => {
22+
process.env.FORCE_UPDATE_NOTIFIER = 1;
23+
});
24+
1425
afterEach(async () => {
1526
await fs.remove(process.env.TEST_META_DIR);
1627
});
@@ -69,6 +80,7 @@ describe('check-kit', function () {
6980
describe('Environment check skip', () => {
7081
it('should skip check if NO_UPDATE_NOTIFIER is set', async () => {
7182
try {
83+
delete process.env.FORCE_UPDATE_NOTIFIER;
7284
process.env.NO_UPDATE_NOTIFIER = 1;
7385
expect(await check()).to.deep.equal({});
7486
} finally {
@@ -78,6 +90,7 @@ describe('check-kit', function () {
7890

7991
it('should skip check if NODE_ENV is set to test', async () => {
8092
try {
93+
delete process.env.FORCE_UPDATE_NOTIFIER;
8194
process.env.NODE_ENV = 'test';
8295
expect(await check()).to.deep.equal({});
8396
} finally {
@@ -126,7 +139,9 @@ describe('check-kit', function () {
126139
expect(result.updateAvailable).to.equal(true);
127140
});
128141

129-
it('should check a valid package.json with scoped name', async () => {
142+
it('should check a valid package.json with scoped name', async function () {
143+
this.timeout(5000);
144+
130145
const result = await check({
131146
pkg: path.resolve(__dirname, 'fixtures/good-scoped/package.json')
132147
});

0 commit comments

Comments
 (0)