Skip to content

Commit 7967d92

Browse files
authored
fix(deps): update dependencies & Node 16 supports (#18)
* fix(deps): update dependencies * style: format * fix: support npm 7 & Node.js 16 * remove volta
1 parent f12811e commit 7967d92

File tree

11 files changed

+1147
-706
lines changed

11 files changed

+1147
-706
lines changed

Diff for: .githooks/pre-commit

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
npx --no-install lint-staged

Diff for: .github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
node-version: [10, 12, 14]
11+
node-version: [ 12, 14, 16 ]
1212
steps:
1313
- name: checkout
1414
uses: actions/checkout@v2

Diff for: .mocharc.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"timeout": "5000"
3+
}

Diff for: bin/cmd.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ canNpmPublish(cli.input[0], {
3636
.then(() => {
3737
process.exit(0);
3838
})
39-
.catch(error => {
39+
.catch((error) => {
4040
if (cli.flags.verbose) {
4141
console.error(error.message);
4242
}

Diff for: lib/can-npm-publish.js

+29-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
// MIT © 2018 azu
22
"use strict";
3+
const path = require("path");
34
const spawn = require("cross-spawn");
45
const readPkg = require("read-pkg");
56
const validatePkgName = require("validate-npm-package-name");
7+
/**
8+
* @param {string} [filePathOrDirPath]
9+
* @returns {Promise<readPkg.NormalizedPackageJson>}
10+
*/
11+
const readPkgWithPath = (filePathOrDirPath) => {
12+
if (filePathOrDirPath) {
13+
const isJSON = path.extname(filePathOrDirPath) === ".json";
14+
if (isJSON) {
15+
return Promise.resolve(require(filePathOrDirPath));
16+
}
17+
return readPkg({ cwd: filePathOrDirPath });
18+
} else {
19+
return readPkg();
20+
}
21+
};
622
/**
723
* Return rejected promise if the package name is invalid
824
* @param {string} packagePath
925
* @param {{verbose:boolean}} options
1026
* @returns {Promise}
1127
*/
1228
const checkPkgName = (packagePath, options) => {
13-
return readPkg(packagePath).then(pkg => {
29+
return readPkgWithPath(packagePath).then((pkg) => {
1430
const name = pkg["name"];
1531
const result = validatePkgName(name);
1632
// Treat Legacy Names as valid
@@ -34,8 +50,8 @@ const checkPkgName = (packagePath, options) => {
3450
* @param {string} packagePath
3551
* @returns {Promise}
3652
*/
37-
const checkPrivateField = packagePath => {
38-
return readPkg(packagePath).then(pkg => {
53+
const checkPrivateField = (packagePath) => {
54+
return readPkgWithPath(packagePath).then((pkg) => {
3955
if (pkg["private"] === true) {
4056
return Promise.reject(new Error("This package is private."));
4157
}
@@ -56,15 +72,18 @@ const viewPackage = (packageName, registry) => {
5672
let result = "";
5773
let errorResult = "";
5874

59-
view.stdout.on("data", data => {
75+
view.stdout.on("data", (data) => {
6076
result += data.toString();
6177
});
6278

63-
view.stderr.on("data", err => {
79+
view.stderr.on("data", (err) => {
6480
errorResult += err.toString();
6581
});
6682

67-
view.on("close", code => {
83+
view.on("close", (code) => {
84+
if (code !== 0) {
85+
return reject(new Error(errorResult));
86+
}
6887
const resultJSON = JSON.parse(result);
6988
if (resultJSON && resultJSON.error) {
7089
// the package is not in the npm registry => can publish
@@ -75,13 +94,13 @@ const viewPackage = (packageName, registry) => {
7594
return reject(new Error(errorResult));
7695
}
7796
}
78-
resolve(JSON.parse(result));
97+
resolve(resultJSON);
7998
});
8099
});
81100
};
82101

83-
const checkAlreadyPublish = packagePath => {
84-
return readPkg(packagePath).then(pkg => {
102+
const checkAlreadyPublish = (packagePath) => {
103+
return readPkgWithPath(packagePath).then((pkg) => {
85104
const name = pkg["name"];
86105
const version = pkg["version"];
87106
const publishConfig = pkg["publishConfig"];
@@ -92,7 +111,7 @@ const checkAlreadyPublish = packagePath => {
92111
if (version === undefined) {
93112
return Promise.reject(new Error("This package has no `version`."));
94113
}
95-
return viewPackage(name, registry).then(versions => {
114+
return viewPackage(name, registry).then((versions) => {
96115
if (versions.includes(version)) {
97116
return Promise.reject(new Error(`${name}@${version} is already published`));
98117
}

Diff for: package.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,31 @@
3232
},
3333
"scripts": {
3434
"test": "mocha test",
35-
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
3635
"precommit": "lint-staged",
37-
"postcommit": "git reset"
36+
"postcommit": "git reset",
37+
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
38+
"prepare": "git config --local core.hooksPath .githooks"
3839
},
3940
"dependencies": {
40-
"cross-spawn": "^6.0.5",
41-
"meow": "^4.0.0",
42-
"read-pkg": "^3.0.0",
41+
"cross-spawn": "^7.0.3",
42+
"meow": "^9.0.0",
43+
"read-pkg": "^5.0.0",
4344
"validate-npm-package-name": "^3.0.0"
4445
},
4546
"devDependencies": {
46-
"husky": "^0.14.3",
47-
"lint-staged": "^6.0.1",
48-
"mocha": "^5.0.0",
49-
"prettier": "^1.10.2"
47+
"lint-staged": "^11.0.0",
48+
"mocha": "^9.0.0",
49+
"prettier": "^2.3.1"
5050
},
5151
"prettier": {
5252
"singleQuote": false,
5353
"printWidth": 120,
54-
"tabWidth": 4
54+
"tabWidth": 4,
55+
"trailingComma": "none"
5556
},
5657
"lint-staged": {
5758
"*.{js,jsx,ts,tsx,css}": [
58-
"prettier --write",
59-
"git add"
59+
"prettier --write"
6060
]
6161
}
6262
}

Diff for: test/can-npm-publish-bin-test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ const shouldNotCalled = () => {
1010
};
1111

1212
describe("can-npm-publish bin", () => {
13-
it("should return 0, it can publish", done => {
13+
it("should return 0, it can publish", (done) => {
1414
const bin = spawn("node", [binPath, path.join(__dirname, "fixtures/not-published-yet.json")]);
1515

1616
// Finish the test when the executable finishes and returns 0
17-
bin.on("close", exit_code => {
17+
bin.on("close", (exit_code) => {
1818
assert.ok(exit_code === 0);
1919
done();
2020
});
2121
});
22-
it("should return 1, it can't publish", done => {
22+
it("should return 1, it can't publish", (done) => {
2323
const bin = spawn("node", [binPath, path.join(__dirname, "fixtures/already-published.json")]);
2424

2525
// Finish the test when the executable finishes and returns 1
26-
bin.on("close", exit_code => {
26+
bin.on("close", (exit_code) => {
2727
assert.ok(exit_code === 1);
2828
done();
2929
});
3030
});
31-
it("should send errors to stderr when verbose, it can't publish", done => {
31+
it("should send errors to stderr when verbose, it can't publish", (done) => {
3232
const bin = spawn("node", [binPath, path.join(__dirname, "fixtures/already-published.json"), "--verbose"]);
3333

3434
// Finish the test and stop the executable when it outputs to stderr
35-
bin.stderr.on("data", data => {
35+
bin.stderr.on("data", (data) => {
3636
assert.ok(/almin@0.15.2 is already published/.test(data));
3737
bin.kill();
3838
done();

Diff for: test/can-npm-publish-test.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ const shouldNotCalled = () => {
77
};
88
describe("can-npm-publish", () => {
99
it("should be rejected, it is invalid name", () => {
10-
return canNpmPublish(path.join(__dirname, "fixtures/invalid-name.json")).then(shouldNotCalled, error => {
11-
assert.ok(/Invalid name/s.test(error.message));
10+
return canNpmPublish(path.join(__dirname, "fixtures/invalid-name.json")).then(shouldNotCalled, (error) => {
11+
assert.ok(/name can only contain URL-friendly characters/s.test(error.message));
1212
});
1313
});
1414
it("should be rejected, it is private:true", () => {
15-
return canNpmPublish(path.join(__dirname, "fixtures/private.json")).then(shouldNotCalled, error => {
15+
return canNpmPublish(path.join(__dirname, "fixtures/private.json")).then(shouldNotCalled, (error) => {
1616
assert.ok(/This package is private/.test(error.message));
1717
});
1818
});
1919
it("should be rejected, it is already published", () => {
20-
return canNpmPublish(path.join(__dirname, "fixtures/already-published.json")).then(shouldNotCalled, error => {
20+
return canNpmPublish(path.join(__dirname, "fixtures/already-published.json")).then(shouldNotCalled, (error) => {
2121
assert.ok(/is already published/.test(error.message));
2222
});
2323
});
2424
it("should be rejected, it is already published to yarnpkg registry", () => {
2525
return canNpmPublish(path.join(__dirname, "fixtures/already-published-registry.json")).then(
2626
shouldNotCalled,
27-
error => {
27+
(error) => {
2828
assert.ok(/is already published/.test(error.message));
2929
}
3030
);
3131
});
3232
it("should be rejected, it is already published scoped package", () => {
33-
return canNpmPublish(path.join(__dirname, "fixtures/scoped-package.json")).then(shouldNotCalled, error => {
33+
return canNpmPublish(path.join(__dirname, "fixtures/scoped-package.json")).then(shouldNotCalled, (error) => {
3434
assert.ok(/is already published/.test(error.message));
3535
});
3636
});
@@ -51,11 +51,16 @@ describe("can-npm-publish", () => {
5151
}
5252
};
5353

54-
return canNpmPublish(path.join(__dirname, "fixtures/legacy-name.json"), { verbose: true }).then(() => {
55-
// Restore stderr to normal
56-
process.stderr.write = stderrWrite;
57-
58-
assert.ok(/name can no longer contain capital letters/.test(stderrOutput));
59-
}, shouldNotCalled);
54+
return canNpmPublish(path.join(__dirname, "fixtures/legacy-name.json"), { verbose: true }).then(
55+
() => {
56+
// Restore stderr to normal
57+
process.stderr.write = stderrWrite;
58+
assert.ok(/name can no longer contain capital letters/.test(stderrOutput));
59+
},
60+
(error) => {
61+
console.log(error);
62+
shouldNotCalled();
63+
}
64+
);
6065
});
6166
});

Diff for: test/fixtures/legacy-name.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"private": false,
3-
"name": "lEgAcY-nAmE",
3+
"name": "JSONStream",
44
"version": "1.0.0"
55
}

Diff for: test/mocha.opts

-1
This file was deleted.

0 commit comments

Comments
 (0)