Skip to content

Commit 891c7f5

Browse files
committed
chore(utils): use yargs instead of meow
1 parent eec247e commit 891c7f5

File tree

3 files changed

+62
-42
lines changed

3 files changed

+62
-42
lines changed

@packages/utils/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@
3838
"dependencies": {
3939
"execa": "0.11.0",
4040
"is-builtin-module": "3.0.0",
41-
"meow": "4.0.1",
4241
"read-pkg": "5.2.0",
4342
"require-from-string": "2.0.2",
44-
"tar-fs": "2.0.0"
43+
"tar-fs": "2.0.0",
44+
"tmp": "0.1.0",
45+
"yargs": "^15.1.0"
46+
},
47+
"devDependencies": {
48+
"@types/yargs": "^15.0.3",
49+
"@types/tmp": "^0.1.0"
4550
}
4651
}

@packages/utils/pkg-check.js

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const fs = require('fs');
44
const zlib = require('zlib');
55

66
const execa = require('execa');
7-
const meow = require('meow');
7+
const yargs = require('yargs');
88
const readPkg = require('read-pkg');
99
const requireFromString = require('require-from-string');
1010
const tar = require('tar-fs');
@@ -33,23 +33,52 @@ require = function(id) {
3333
};
3434
`;
3535

36-
function main(cli) {
36+
const cliYargs = yargs
37+
.options({
38+
cwd: {
39+
description: 'directory to execute in',
40+
type: 'string'
41+
},
42+
skipMain: {
43+
default: false,
44+
type: 'boolean',
45+
description: 'Skip main checks'
46+
},
47+
skipBin: {
48+
default: false,
49+
type: 'boolean',
50+
description: 'Skip bin checks'
51+
},
52+
skipImport: {
53+
default: false,
54+
type: 'boolean',
55+
description: 'Skip import smoke test'
56+
}
57+
})
58+
.scriptName('pkg-check')
59+
.usage('pkg-check\n')
60+
.usage('Check if a package creates valid tarballs')
61+
.example('$0', '')
62+
.help()
63+
.version();
64+
65+
function main(flags) {
3766
if (!Proxy) {
3867
console
3968
.warn('Skipping pkg-check, detected missing Proxy support')
4069
.process.exit(0);
4170
}
4271

43-
const cwd = cli.flags.cwd || process.cwd();
72+
const cwd = flags.cwd || process.cwd();
4473
const skipImport =
45-
typeof cli.flags.skipImport === 'boolean' ? cli.flags.skipImport : false;
74+
typeof flags.skipImport === 'boolean' ? flags.skipImport : false;
4675

4776
return readPkg({cwd}).then(pkg => {
4877
return getTarballFiles(cwd, {write: !skipImport}).then(tarball => {
4978
return getPackageFiles(cwd).then(pkgFiles => {
5079
let problems = [];
5180

52-
if (!cli.flags.skipBin) {
81+
if (!flags.skipBin) {
5382
problems = problems.concat(
5483
pkgFiles.bin
5584
.filter(binFile => tarball.files.indexOf(binFile) === -1)
@@ -64,7 +93,7 @@ function main(cli) {
6493
}
6594

6695
if (
67-
!cli.flags.skipMain &&
96+
!flags.skipMain &&
6897
tarball.files.indexOf(pkgFiles.main) === -1
6998
) {
7099
problems.push({
@@ -76,7 +105,7 @@ function main(cli) {
76105
});
77106
}
78107

79-
if (!cli.flags.skipImport && !cli.flags.skipMain) {
108+
if (!flags.skipImport && !flags.skipMain) {
80109
const importable = fileImportable(
81110
path.join(tarball.dirname, pkgFiles.main)
82111
);
@@ -102,21 +131,7 @@ function main(cli) {
102131
});
103132
}
104133

105-
main(
106-
meow(`
107-
pkg-check
108-
109-
Check if a package creates valid tarballs
110-
111-
Options
112-
--skip-main Skip main checks
113-
--skip-bin Skip bin checks
114-
--skip-import Skip import smoke test
115-
116-
Examples
117-
$ pkg-check
118-
`)
119-
)
134+
main(cliYargs.argv)
120135
.then(report => {
121136
if (report.problems.length > 0) {
122137
console.log(
@@ -135,7 +150,7 @@ main(
135150
.catch(err => {
136151
setTimeout(() => {
137152
throw err;
138-
});
153+
}, 0);
139154
});
140155

141156
async function getTarballFiles(source, options) {

yarn.lock

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,7 +2003,7 @@
20032003
resolved "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-13.1.0.tgz#c563aa192f39350a1d18da36c5a8da382bbd8228"
20042004
integrity sha512-gCubfBUZ6KxzoibJ+SCUc/57Ms1jz5NjHe4+dI2krNmU5zCPAphyLJYyTOg06ueIyfj+SaCUqmzun7ImlxDcKg==
20052005

2006-
"@types/yargs@^15.0.0":
2006+
"@types/yargs@^15.0.0", "@types/yargs@^15.0.3":
20072007
version "15.0.3"
20082008
resolved "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.3.tgz#41453a0bc7ab393e995d1f5451455638edbd2baf"
20092009
integrity sha512-XCMQRK6kfpNBixHLyHUsGmXrpEmFFxzMrcnSXFMziHd8CoNJo8l16FkHyQq4x+xbM7E2XL83/O78OD8u+iZTdQ==
@@ -6949,21 +6949,6 @@ mem@^1.1.0:
69496949
dependencies:
69506950
mimic-fn "^1.0.0"
69516951

6952-
meow@4.0.1, meow@^4.0.0:
6953-
version "4.0.1"
6954-
resolved "https://registry.npmjs.org/meow/-/meow-4.0.1.tgz#d48598f6f4b1472f35bf6317a95945ace347f975"
6955-
integrity sha512-xcSBHD5Z86zaOc+781KrupuHAzeGXSLtiAOmBsiLDiPSaYSB6hdew2ng9EBAnZ62jagG9MHAOdxpDi/lWBFJ/A==
6956-
dependencies:
6957-
camelcase-keys "^4.0.0"
6958-
decamelize-keys "^1.0.0"
6959-
loud-rejection "^1.0.0"
6960-
minimist "^1.1.3"
6961-
minimist-options "^3.0.1"
6962-
normalize-package-data "^2.3.4"
6963-
read-pkg-up "^3.0.0"
6964-
redent "^2.0.0"
6965-
trim-newlines "^2.0.0"
6966-
69676952
meow@5.0.0, meow@^5.0.0:
69686953
version "5.0.0"
69696954
resolved "https://registry.npmjs.org/meow/-/meow-5.0.0.tgz#dfc73d63a9afc714a5e371760eb5c88b91078aa4"
@@ -6995,6 +6980,21 @@ meow@^3.3.0:
69956980
redent "^1.0.0"
69966981
trim-newlines "^1.0.0"
69976982

6983+
meow@^4.0.0:
6984+
version "4.0.1"
6985+
resolved "https://registry.npmjs.org/meow/-/meow-4.0.1.tgz#d48598f6f4b1472f35bf6317a95945ace347f975"
6986+
integrity sha512-xcSBHD5Z86zaOc+781KrupuHAzeGXSLtiAOmBsiLDiPSaYSB6hdew2ng9EBAnZ62jagG9MHAOdxpDi/lWBFJ/A==
6987+
dependencies:
6988+
camelcase-keys "^4.0.0"
6989+
decamelize-keys "^1.0.0"
6990+
loud-rejection "^1.0.0"
6991+
minimist "^1.1.3"
6992+
minimist-options "^3.0.1"
6993+
normalize-package-data "^2.3.4"
6994+
read-pkg-up "^3.0.0"
6995+
redent "^2.0.0"
6996+
trim-newlines "^2.0.0"
6997+
69986998
merge-stream@^2.0.0:
69996999
version "2.0.0"
70007000
resolved "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
@@ -10366,7 +10366,7 @@ yargs@^14.2.0, yargs@^14.2.2:
1036610366
y18n "^4.0.0"
1036710367
yargs-parser "^15.0.0"
1036810368

10369-
yargs@^15.0.0:
10369+
yargs@^15.0.0, yargs@^15.1.0:
1037010370
version "15.1.0"
1037110371
resolved "https://registry.npmjs.org/yargs/-/yargs-15.1.0.tgz#e111381f5830e863a89550bd4b136bb6a5f37219"
1037210372
integrity sha512-T39FNN1b6hCW4SOIk1XyTOWxtXdcen0t+XYrysQmChzSipvhBO8Bj0nK1ozAasdk24dNWuMZvr4k24nz+8HHLg==

0 commit comments

Comments
 (0)