This repository has been archived by the owner on Feb 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
7,481 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": "8" | ||
}, | ||
"loose": true | ||
} | ||
] | ||
], | ||
"plugins": ["@babel/plugin-proposal-class-properties"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"root": true, | ||
"extends": ["smooth", "smooth/project"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
package.json | ||
CHANGELOG.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"semi": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- 8 | ||
- 10 | ||
- 12 | ||
|
||
script: | ||
- yarn ci | ||
|
||
notifications: | ||
email: false | ||
|
||
cache: | ||
yarn: true | ||
directories: | ||
- 'node_modules' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Bundle analyzer JS clients | ||
|
||
This repository contains all JavaScript clients for [Bundle Analyzer](https://www.bundle-analyzer.com). | ||
|
||
## Complete documentation | ||
|
||
👉 [See full documentation](https://docs.bundle-analyzer.com/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const path = require('path') | ||
const fs = require('fs') | ||
|
||
const config = fs.readFileSync(path.join(__dirname, '.babelrc')) | ||
|
||
module.exports = JSON.parse(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"lerna": "3.3.0", | ||
"packages": ["packages/*"], | ||
"version": "1.0.0", | ||
"npmClient": "yarn", | ||
"useWorkspaces": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"private": true, | ||
"workspaces": [ | ||
"packages/*" | ||
], | ||
"scripts": { | ||
"build": "lerna run build", | ||
"ci": "yarn build && yarn lint", | ||
"format": "prettier --write \"**/*.{js,json,md}\"", | ||
"lint": "eslint .", | ||
"release": "lerna publish --conventional-commits && conventional-github-releaser --preset angular" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.4.4", | ||
"@babel/core": "^7.4.5", | ||
"@babel/plugin-proposal-class-properties": "^7.4.4", | ||
"@babel/preset-env": "^7.4.5", | ||
"babel-eslint": "^10.0.1", | ||
"conventional-github-releaser": "^3.1.3", | ||
"eslint": "^6.0.1", | ||
"eslint-config-airbnb": "^18.0.1", | ||
"eslint-config-prettier": "^6.2.0", | ||
"eslint-config-smooth": "^2.1.1", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-jsx-a11y": "^6.2.3", | ||
"eslint-plugin-react": "^7.14.3", | ||
"eslint-plugin-react-hooks": "^2.0.1", | ||
"lerna": "^3.14.1", | ||
"prettier": "^1.18.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* | ||
!/lib/**/*.js | ||
*.test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# @bundle-analyzer/webpack-plugin | ||
|
||
Official webpack plugin compatible with [Bundle Analyzer service](https://www.bundle-analyzer.com). | ||
|
||
## Install | ||
|
||
``` | ||
npm install --save-dev @bundle-analyzer/webpack-plugin | ||
``` | ||
|
||
## Usage | ||
|
||
**webpack.config.js** | ||
|
||
```js | ||
const BundleAnalyzerPlugin = require('@bundle-analyzer/webpack-plugin') | ||
|
||
module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
path: __dirname + '/dist', | ||
filename: 'index_bundle.js', | ||
}, | ||
plugins: [new BundleAnalyzerPlugin()], | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
### token | ||
|
||
You can specify the token using options or environment variable `BUNDLE_ANALYZER_TOKEN`. | ||
|
||
```js | ||
const BundleAnalyzerPlugin = require('@bundle-analyzer/webpack-plugin') | ||
|
||
module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
path: __dirname + '/dist', | ||
filename: 'index_bundle.js', | ||
}, | ||
plugins: [new BundleAnalyzerPlugin({ token: 'Your repository token' })], | ||
} | ||
``` | ||
|
||
## Complete documentation | ||
|
||
👉 [See full documentation](https://docs.bundle-analyzer.com/) | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@bundle-analyzer/webpack-plugin", | ||
"description": "Bundle Analyzer webpack plugin.", | ||
"version": "1.0.0", | ||
"main": "lib/index.js", | ||
"repository": "https://github.com/smooth-code/bundle-analyzer-javascript/tree/master/packages/webpack-plugin", | ||
"author": "Greg Bergé <berge.greg@gmail.com>", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"keywords": [ | ||
"webpack", | ||
"plugin", | ||
"bundle-analyzer", | ||
"bundlesize" | ||
], | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"prebuild": "rm -rf lib/", | ||
"build": "babel --config-file ../../babel.config.js -d lib --ignore \"**/*.test.js\" src", | ||
"prepublishOnly": "yarn run build" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.19.0", | ||
"brotli-size": "^4.0.0", | ||
"gzip-size": "^5.1.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function getToken(configToken) { | ||
const token = configToken || process.env.BUNDLE_ANALYZER_TOKEN | ||
if (!token) { | ||
throw new Error( | ||
`Token not found, please specify a token using BUNDLE_ANALYZER_TOKEN env variable`, | ||
) | ||
} | ||
return token | ||
} | ||
|
||
export function getApiUrl() { | ||
return ( | ||
process.env.BUNDLE_ANALYZER_API_URL || 'https://api.bundle-analyzer.com' | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { execSync } from 'child_process' | ||
|
||
export function branch() { | ||
return execSync('git rev-parse --abbrev-ref HEAD || hg branch') | ||
.toString() | ||
.trim() | ||
} | ||
|
||
export function head() { | ||
return execSync("git log -1 --pretty=%H || hg id -i --debug | tr -d '+'") | ||
.toString() | ||
.trim() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { gzipSync } from 'zlib' | ||
import { promisify } from 'util' | ||
import fs from 'fs' | ||
import path from 'path' | ||
import axios from 'axios' | ||
import gzipSize from 'gzip-size' | ||
import brotliSize from 'brotli-size' | ||
import { detectProvider } from './provider' | ||
import { getToken, getApiUrl } from './config' | ||
|
||
const readFile = promisify(fs.readFile) | ||
|
||
async function sizeAssets(stats) { | ||
return Promise.all( | ||
stats.assets.map(async asset => { | ||
const fullPath = path.join(stats.outputPath, asset.name) | ||
const buffer = await readFile(fullPath) | ||
return { | ||
...asset, | ||
gzipSize: await gzipSize(buffer), | ||
brotliSize: await brotliSize(buffer), | ||
} | ||
}), | ||
) | ||
} | ||
|
||
class BundleAnalyzer { | ||
constructor({ token } = {}) { | ||
this.token = getToken(token) | ||
this.metadata = detectProvider() | ||
} | ||
|
||
apply(compiler) { | ||
const isProductionLikeMode = | ||
compiler.options.mode === 'production' || !compiler.options.mode | ||
if (!isProductionLikeMode) { | ||
return | ||
} | ||
const { token, metadata } = this | ||
compiler.hooks.afterEmit.tapAsync( | ||
'@bundle-analyzer/webpack-plugin', | ||
(hookCompiler, callback) => { | ||
const apiUrl = getApiUrl() | ||
const stats = hookCompiler.getStats().toJson({ | ||
maxModules: Infinity, | ||
source: false, | ||
}) | ||
|
||
async function sendBuild() { | ||
const assets = await sizeAssets(stats) | ||
|
||
const { data: build } = await axios.post(`${apiUrl}/builds`, { | ||
token, | ||
branch: metadata.branch, | ||
commit: metadata.commit, | ||
providerMetadata: metadata, | ||
stats: { | ||
assets, | ||
chunksNumber: stats.chunks.length, | ||
modulesNumber: stats.modules.length, | ||
assetsNumber: stats.assets.length, | ||
}, | ||
}) | ||
|
||
await axios.request({ | ||
method: 'put', | ||
url: build.webpackStatsPutUrl, | ||
data: gzipSync(Buffer.from(JSON.stringify(stats))), | ||
headers: { | ||
'content-encoding': 'gzip', | ||
}, | ||
maxContentLength: 30 * 1024 * 1024, | ||
}) | ||
|
||
await axios.post(`${apiUrl}/builds/${build.id}/start`, { | ||
token, | ||
}) | ||
} | ||
|
||
sendBuild() | ||
.then(() => callback()) | ||
.catch(error => { | ||
function getMessage() { | ||
if ( | ||
error.response && | ||
error.response.data && | ||
error.response.data.error && | ||
error.response.data.error.message | ||
) { | ||
return error.response.data.error.message | ||
} | ||
return error.message | ||
} | ||
callback(new Error(`Bundle Analyzer - ${getMessage()}`)) | ||
}) | ||
}, | ||
) | ||
} | ||
} | ||
|
||
module.exports = BundleAnalyzer | ||
module.exports.default = BundleAnalyzer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* eslint-disable no-console */ | ||
import services from './services' | ||
import * as localGit from './services/localGit' | ||
|
||
export function detectProvider() { | ||
const service = services.find(service => service.detect()) | ||
if (service) { | ||
const config = service.config() | ||
// console.log(`${config.name} detected`) | ||
return config | ||
} | ||
|
||
// console.log(`No CI service detected, use local git`) | ||
const config = localGit.config() | ||
if (!config) { | ||
throw new Error('Unknown CI service provider. Unable to upload stats.') | ||
} | ||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export function detect() { | ||
return !!process.env.APPVEYOR | ||
} | ||
|
||
export function config() { | ||
return { | ||
name: 'App Veyor', | ||
service: 'appveyor', | ||
commit: process.env.APPVEYOR_REPO_COMMIT, | ||
branch: process.env.APPVEYOR_REPO_BRANCH, | ||
pr: process.env.APPVEYOR_PULL_REQUEST_NUMBER, | ||
job: `${process.env.APPVEYOR_ACCOUNT_NAME}/${process.env.APPVEYOR_PROJECT_SLUG}/${process.env.APPVEYOR_BUILD_VERSION}`, | ||
build: process.env.APPVEYOR_JOB_ID, | ||
slug: process.env.APPVEYOR_REPO_NAME, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export function detect() { | ||
return !!process.env.TF_BUILD | ||
} | ||
|
||
export function config() { | ||
return { | ||
name: 'Azure Pipelines', | ||
service: 'azure_pipelines', | ||
commit: process.env.BUILD_SOURCEVERSION, | ||
branch: process.env.BUILD_SOURCEBRANCH, | ||
pr: process.env.SYSTEM_PULLREQUEST_PULLREQUESTNUMBER, | ||
job: process.env.SYSTEM_JOBID, | ||
build: process.env.BUILD_BUILDID, | ||
build_url: `${process.env.SYSTEM_TEAMFOUNDATIONSERVERURI + | ||
process.env.SYSTEM_TEAMPROJECT}/_build/results?buildId=${ | ||
process.env.BUILD_BUILDID | ||
}`, | ||
slug: process.env.BUILD_REPOSITORY_ID, | ||
} | ||
} |
Oops, something went wrong.