Skip to content

Commit

Permalink
WIP: Add rollup to transpile percy-agent.js
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 3, 2019
1 parent 7509765 commit 20d8b51
Show file tree
Hide file tree
Showing 7 changed files with 1,233 additions and 2 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,178 changes: 1,178 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"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 Down Expand Up @@ -67,6 +72,10 @@
"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",
Expand Down Expand Up @@ -98,7 +107,7 @@
"agent"
],
"license": "MIT",
"main": "dist/index.js",
"main": "dist/public/percy-agent.js",
"oclif": {
"commands": "./dist/commands",
"bin": "percy",
Expand All @@ -110,6 +119,7 @@
"repository": "percy/percy-agent",
"scripts": {
"build": "npm run clean && rm -rf dist && tsc && npm run build-client",
"build-client:new": "rollup -c",
"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-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",
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: "percy-agent",
file: pkg.main,
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 20d8b51

Please sign in to comment.