Skip to content

Commit 615863f

Browse files
committed
refactor(utils): refactor code to use async await
1 parent 1519ad0 commit 615863f

File tree

1 file changed

+47
-53
lines changed

1 file changed

+47
-53
lines changed

@packages/utils/pkg-check.js

+47-53
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const cli = yargs
6262
.help()
6363
.version();
6464

65-
function main(flags) {
65+
async function main(flags) {
6666
if (!Proxy) {
6767
console
6868
.warn('Skipping pkg-check, detected missing Proxy support')
@@ -73,59 +73,53 @@ function main(flags) {
7373
const skipImport =
7474
typeof flags.skipImport === 'boolean' ? flags.skipImport : false;
7575

76-
return readPkg({cwd}).then(pkg => {
77-
return getTarballFiles(cwd, {write: !skipImport}).then(tarball => {
78-
return getPackageFiles(cwd).then(pkgFiles => {
79-
let problems = [];
80-
81-
if (!flags.skipBin) {
82-
problems = problems.concat(
83-
pkgFiles.bin
84-
.filter(binFile => tarball.files.indexOf(binFile) === -1)
85-
.map(binFile => ({
86-
type: 'bin',
87-
file: binFile,
88-
message: `Required bin file ${binFile} not found for ${
89-
pkg.name
90-
}`
91-
}))
92-
);
93-
}
94-
95-
if (!flags.skipMain && tarball.files.indexOf(pkgFiles.main) === -1) {
96-
problems.push({
97-
type: 'main',
98-
file: pkgFiles.main,
99-
message: `Required main file ${pkgFiles.main} not found for ${
100-
pkg.name
101-
}`
102-
});
103-
}
104-
105-
if (!flags.skipImport && !flags.skipMain) {
106-
const importable = fileImportable(
107-
path.join(tarball.dirname, pkgFiles.main)
108-
);
109-
if (!importable[1]) {
110-
problems.push({
111-
type: 'import',
112-
file: pkgFiles.main,
113-
message: `Error while importing ${pkgFiles.main}: ${
114-
importable[0].message
115-
}`
116-
});
117-
}
118-
}
119-
120-
return {
121-
pkg: pkg,
122-
pkgFiles: pkgFiles,
123-
files: tarball.files,
124-
problems: problems
125-
};
126-
});
76+
const pkg = await readPkg({cwd});
77+
const tarball = await getTarballFiles(cwd, {write: !skipImport});
78+
const pkgFiles = await getPackageFiles(cwd);
79+
80+
let problems = [];
81+
82+
if (!flags.skipBin) {
83+
problems = problems.concat(
84+
pkgFiles.bin
85+
.filter(binFile => tarball.files.indexOf(binFile) === -1)
86+
.map(binFile => ({
87+
type: 'bin',
88+
file: binFile,
89+
message: `Required bin file ${binFile} not found for ${pkg.name}`
90+
}))
91+
);
92+
}
93+
94+
if (!flags.skipMain && tarball.files.indexOf(pkgFiles.main) === -1) {
95+
problems.push({
96+
type: 'main',
97+
file: pkgFiles.main,
98+
message: `Required main file ${pkgFiles.main} not found for ${pkg.name}`
12799
});
128-
});
100+
}
101+
102+
if (!flags.skipImport && !flags.skipMain) {
103+
const importable = fileImportable(
104+
path.join(tarball.dirname, pkgFiles.main)
105+
);
106+
if (!importable[1]) {
107+
problems.push({
108+
type: 'import',
109+
file: pkgFiles.main,
110+
message: `Error while importing ${pkgFiles.main}: ${
111+
importable[0].message
112+
}`
113+
});
114+
}
115+
}
116+
117+
return {
118+
pkg: pkg,
119+
pkgFiles: pkgFiles,
120+
files: tarball.files,
121+
problems: problems
122+
};
129123
}
130124

131125
main(cli.argv)

0 commit comments

Comments
 (0)