Skip to content

Commit

Permalink
Chore: Validate size of VS Code extension bundle
Browse files Browse the repository at this point in the history
Fix #2955
Close #2983
  • Loading branch information
antross authored and molant committed Sep 17, 2019
1 parent 0d3a13c commit 488fa03
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/extension-vscode/package.json
Expand Up @@ -16,6 +16,7 @@
],
"timeout": "1m"
},
"bundleSize": 75000,
"categories": [
"Linters"
],
Expand Down Expand Up @@ -61,6 +62,7 @@
"rimraf": "^3.0.0",
"sinon": "^7.4.2",
"typescript": "^3.6.3",
"vsce": "^1.66.0",
"vscode-languageclient": "^5.2.1",
"vscode-languageserver": "^5.2.1",
"webpack": "^4.39.3",
Expand Down Expand Up @@ -95,8 +97,9 @@
"lint:dependencies": "node ../../scripts/lint-dependencies.js",
"lint:md": "node ../../scripts/lint-markdown.js",
"test": "npm run lint && npm run build && npm run test-only",
"test-only": "nyc ava",
"test-release": "npm run lint && npm run build-release && ava",
"test-only": "nyc ava && npm run build-release && vsce package && npm run validate-bundle-size",
"test-release": "npm run lint && npm run build-release && ava && vsce package && npm run validate-bundle-size",
"validate-bundle-size": "node ./scripts/bundle-size.js",
"vscode:prepublish": "npm run build-release",
"watch": "npm run build && npm-run-all --parallel -c watch:*",
"watch:assets": "npm run build:assets -- -w --no-initial",
Expand Down
20 changes: 20 additions & 0 deletions packages/extension-vscode/scripts/bundle-size.js
@@ -0,0 +1,20 @@
const fs = require('fs');
const path = require('path');
const packageJSON = require('../package.json');

const filename = `${path.resolve(__dirname, '..')}/vscode-webhint-${packageJSON.version}.vsix`;

fs.stat(filename, (err, stats) => {
if (err) {
throw new Error(`Reading bundle failed: ${err}`);
}

const sizeKB = Math.round(stats.size / 1000);
const limitKB = Math.round(packageJSON.bundleSize / 1000);

if (sizeKB > limitKB) {
throw new Error(`Bundle size of ${sizeKB}KB exceeds limit of ${limitKB}KB defined in package.json for ${filename}.`);
} else {
console.log(`Bundle size of ${sizeKB}KB is within limit of ${limitKB}KB defined in package.json for ${filename}.`);
}
});
15 changes: 15 additions & 0 deletions packages/extension-vscode/scripts/tsconfig.json
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"allowJs": true,
"alwaysStrict": true,
"checkJs": true,
"moduleResolution": "node",
"noUnusedLocals": true,
"resolveJsonModule": true,
"strict": true,
"target": "esnext"
},
"include": [
"**/*.js"
]
}

0 comments on commit 488fa03

Please sign in to comment.