Skip to content

Commit

Permalink
Introduce rollup config
Browse files Browse the repository at this point in the history
This is to resolve the error where winston was being being included in
various webpack bundles. We change the `main` entry point of the
`@percy/agent` package so only the file that's ready for a browser is
bundled. Then we transpile that file fully with babel and rollup so
their webpack config isn't looking to compile it too.

This solves percy/percy-cypress#58 fully.
  • Loading branch information
Robdel12 committed Apr 5, 2019
1 parent 57381a1 commit 757ebcc
Show file tree
Hide file tree
Showing 7 changed files with 1,298 additions and 53 deletions.
10 changes: 10 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
"@babel/env",
"@babel/typescript"
],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread"
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
.percy.pid
/tmp/*
/dist-test
/.rpt2_cache
1,290 changes: 1,241 additions & 49 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"delay": 1000
}
},
"browser": "dist/public/percy-agent.js",
"bugs": "https://github.com/percy/percy-agent/issues",
"dependencies": {
"@oclif/command": "^1",
Expand All @@ -26,7 +27,6 @@
"@types/express": "^4.16.0",
"@types/js-yaml": "^3.11.2",
"@types/puppeteer": "^1.6.0",
"@types/sinon": "^7.0.11",
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"colors": "^1.3.2",
Expand All @@ -36,10 +36,14 @@
"percy-client": "^3.0.3",
"puppeteer": "^1.13.0",
"retry-axios": "^0.4.1",
"sinon": "7.3.1",
"winston": "^2.0.0"
},
"devDependencies": {
"@babel/core": "^7.4.0",
"@babel/plugin-proposal-class-properties": "^7.4.0",
"@babel/plugin-proposal-object-rest-spread": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"@babel/preset-typescript": "^7.3.3",
"@oclif/dev-cli": "^1",
"@oclif/errors": "^1",
"@oclif/test": "^1",
Expand All @@ -53,6 +57,7 @@
"@types/mocha": "^5.2.5",
"@types/nock": "^9.3.0",
"@types/node": "^10.7.1",
"@types/sinon": "^5.0.1",
"@types/sinon-chai": "^3.2.0",
"browserify": "^16.2.3",
"chai": "^4.1.2",
Expand All @@ -67,6 +72,11 @@
"prettier": "1.14.2",
"pryjs": "^1.0.3",
"semantic-release": "^15.13.3",
"rollup": "^1.8.0",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^9.2.3",
"rollup-plugin-node-resolve": "^4.0.1",
"sinon": "7.2.3",
"sinon-chai": "^3.2.0",
"stdout-stderr": "^0.1.9",
"testem": "^2.9.3",
Expand Down Expand Up @@ -109,7 +119,7 @@
"repository": "percy/percy-agent",
"scripts": {
"build": "npm run clean && rm -rf dist && tsc && npm run build-client",
"build-client": "mkdir -p dist/public && browserify src/percy-agent-client/index.ts -p [ tsify --noImplicitAny ] --standalone PercyAgent > dist/public/percy-agent.js",
"build-client": "rollup -c",
"build-client-test": "npm run build-client && browserify test/percy-agent-client/*.ts -p [ tsify --noImplicitAny ] > dist-test/browserified-tests.js",
"clean": "rm -f .oclif.manifest.json",
"lint": "tsc -p test --noEmit && tslint -p test -t stylish --fix",
Expand Down
26 changes: 26 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import commonjs from "rollup-plugin-commonjs";
import resolve from "rollup-plugin-node-resolve";
import babel from "rollup-plugin-babel";
import pkg from "./package.json";

export default {
input: "src/percy-agent-client/index.ts",
output: {
name: "PercyAgent",
file: pkg.browser,
format: "umd"
},
plugins: [
// Allows node_modules resolution
resolve({ extensions: [".ts"] }),

// Allow bundling cjs modules. Rollup doesn't understand cjs
commonjs(),

// Compile TypeScript/JavaScript files
babel({
extensions: [".ts"],
include: ["src/**"]
})
]
};
4 changes: 3 additions & 1 deletion src/percy-agent-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
// and then simply use `var percyAgent = new PercyAgent()` to create a new client instance.

// tslint:disable-next-line:no-var-requires
module.exports = require('./percy-agent').default
import PercyAgent from './percy-agent'

export default PercyAgent
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@
},
"include": [
"./src/**/*"
],
"exclude": [
"node_modules",
"dist"
]
}

0 comments on commit 757ebcc

Please sign in to comment.