Skip to content

Commit

Permalink
refactor(utils): refactor code to use async await
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Feb 10, 2020
1 parent 1519ad0 commit 615863f
Showing 1 changed file with 47 additions and 53 deletions.
100 changes: 47 additions & 53 deletions @packages/utils/pkg-check.js
Expand Up @@ -62,7 +62,7 @@ const cli = yargs
.help()
.version();

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

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

if (!flags.skipBin) {
problems = problems.concat(
pkgFiles.bin
.filter(binFile => tarball.files.indexOf(binFile) === -1)
.map(binFile => ({
type: 'bin',
file: binFile,
message: `Required bin file ${binFile} not found for ${
pkg.name
}`
}))
);
}

if (!flags.skipMain && tarball.files.indexOf(pkgFiles.main) === -1) {
problems.push({
type: 'main',
file: pkgFiles.main,
message: `Required main file ${pkgFiles.main} not found for ${
pkg.name
}`
});
}

if (!flags.skipImport && !flags.skipMain) {
const importable = fileImportable(
path.join(tarball.dirname, pkgFiles.main)
);
if (!importable[1]) {
problems.push({
type: 'import',
file: pkgFiles.main,
message: `Error while importing ${pkgFiles.main}: ${
importable[0].message
}`
});
}
}

return {
pkg: pkg,
pkgFiles: pkgFiles,
files: tarball.files,
problems: problems
};
});
const pkg = await readPkg({cwd});
const tarball = await getTarballFiles(cwd, {write: !skipImport});
const pkgFiles = await getPackageFiles(cwd);

let problems = [];

if (!flags.skipBin) {
problems = problems.concat(
pkgFiles.bin
.filter(binFile => tarball.files.indexOf(binFile) === -1)
.map(binFile => ({
type: 'bin',
file: binFile,
message: `Required bin file ${binFile} not found for ${pkg.name}`
}))
);
}

if (!flags.skipMain && tarball.files.indexOf(pkgFiles.main) === -1) {
problems.push({
type: 'main',
file: pkgFiles.main,
message: `Required main file ${pkgFiles.main} not found for ${pkg.name}`
});
});
}

if (!flags.skipImport && !flags.skipMain) {
const importable = fileImportable(
path.join(tarball.dirname, pkgFiles.main)
);
if (!importable[1]) {
problems.push({
type: 'import',
file: pkgFiles.main,
message: `Error while importing ${pkgFiles.main}: ${
importable[0].message
}`
});
}
}

return {
pkg: pkg,
pkgFiles: pkgFiles,
files: tarball.files,
problems: problems
};
}

main(cli.argv)
Expand Down

0 comments on commit 615863f

Please sign in to comment.