Skip to content

Commit

Permalink
ci(tools): validate bundle names packages
Browse files Browse the repository at this point in the history
This script is now part of the ci.sh script which
ensures that there is no human error when defining
the webpack bundle names in the package.json files
for each package in the project.

The idea is to reduce the manual review burden on the
maintainers who can also miss these type of issues.

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Aug 4, 2021
1 parent dd5c3f1 commit e6aea32
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/cactus-cmd-api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dist/*"
],
"main": "dist/lib/main/typescript/index.js",
"mainMinified": "dist/cactus-cmd-api-server.node.umd.js",
"mainMinified": "dist/cactus-cmd-api-server.node.umd.min.js",
"browser": "dist/cactus-cmd-api-server.web.umd.js",
"browserMinified": "dist/cactus-cmd-api-server.web.umd.min.js",
"module": "dist/lib/main/typescript/index.js",
Expand Down
1 change: 1 addition & 0 deletions tools/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function mainTask()
yarn run configure

yarn run custom-checks
node ./tools/validate-bundle-names.js

# Tests are still flaky (on weak hardware such as the CI env) despite our best
# efforts so here comes the mighty hammer of brute force. 3 times the charm...
Expand Down
16 changes: 12 additions & 4 deletions tools/validate-bundle-names.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
#!/usr/bin/env node

const fs = require("fs-extra");
const { getPackageInfoList } = require("./get-package-info-list");

const main = async () => {
const packageInfoList = await getPackageInfoList([]);

const errors = [];

packageInfoList.forEach((pi) => {
const checksDone = packageInfoList.map(async (pi) => {
const nameNoScope = pi.name.replace("@hyperledger/", "");

const targetMain = `dist/${nameNoScope}.node.umd.js`;
const targetMain = `dist/lib/main/typescript/index.js`;
const targetMainMinified = `dist/${nameNoScope}.node.umd.min.js`;
const targetBrowser = `dist/${nameNoScope}.web.umd.js`;
const targetBrowserMinified = `dist/${nameNoScope}.web.umd.min.js`;

const { main, mainMinified, browser, browserMinified } = pi.packageObject;

const pkgJsonPath = `${pi.location}/package.json`;
const pkgJson = await fs.readJson(pkgJsonPath);

if (!pkgJson.scripts.webpack) {
console.log(`Skipping ${pi.name} due to lack of webpack npm script`);
return;
}

if (targetMain !== main) {
errors.push(`${pkgJsonPath}: \n\t${targetMain}\n\t${main}\n`);
}
if (targetMainMinified !== mainMinified) {
errors.push(
`${pkgJsonPath}: \n\t${targetMainMinified}\n\t${mainMinified}\n`
`${pkgJsonPath}: \n\t${targetMainMinified}\n\t${mainMinified}\n`,
);
}
if (targetBrowser !== browser) {
Expand All @@ -37,6 +43,8 @@ const main = async () => {
}
});

await Promise.all(checksDone);

if (errors.length === 0) {
console.log(`No errors found. All OK.`);
process.exit(0);
Expand Down

0 comments on commit e6aea32

Please sign in to comment.