Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit e165a7f

Browse files
fix: builds gavel using rollup
1 parent 93aa5f9 commit e165a7f

File tree

8 files changed

+189
-37
lines changed

8 files changed

+189
-37
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ cov.*
88
.nyc_output
99

1010
# List specific to .gitignore
11+
build
1112
node_modules
1213
.idea/

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ cov.*
1010
# List specific to .npmignore
1111
.travis.yml
1212
.npmignore
13+
lib
1314
docs/
1415
img/
1516
test/

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ install:
1414
- 'npm install --no-save'
1515
script:
1616
- 'npm run ci:lint'
17+
- 'npm run ci:build'
1718
- 'npm run ci:test'
1819
after_success:
1920
- 'npm run ci:release'

appveyor.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
environment:
2-
nodejs_version: "10"
2+
nodejs_version: '10'
33
cache:
4-
- "node_modules"
4+
- 'node_modules'
55
install:
66
- ps: Install-Product node 10
7-
- "npm -g install npm@6"
7+
- 'npm -g install npm@6'
88
- "set PATH=%APPDATA%\\npm;%PATH%"
9-
- "npm install"
9+
- 'npm install'
1010
build: off
1111
test_script:
12-
- "node --version"
13-
- "npm --version"
14-
- "npm test"
12+
- 'node --version'
13+
- 'npm --version'
14+
- 'npm run build'
15+
- 'npm test'

package-lock.json

Lines changed: 128 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
"name": "gavel",
33
"version": "0.0.0-semantically-released",
44
"description": "Validator of HTTP transactions (JavaScript implementation)",
5-
"main": "lib/index.js",
5+
"main": "build/index.js",
66
"engines": {
77
"node": ">= 8"
88
},
99
"bin": {
1010
"gavel": "bin/gavel"
1111
},
1212
"scripts": {
13+
"start": "npm run build -- --watch",
14+
"build": "rollup -c=rollup.config.js",
1315
"lint": "eslint lib/**/*.js test/**/*.js",
1416
"test": "npm run test:server && npm run test:browser && npm run test:features",
1517
"test:server": "mocha \"test/**/*.test.js\"",
@@ -19,6 +21,7 @@
1921
"coveralls": "nyc --reporter=text-lcov npm run test:server | coveralls",
2022
"ci:lint": "npm run lint",
2123
"ci:test": "npm run coveralls && npm run test:browser && npm run test:features",
24+
"ci:build": "npm run build",
2225
"ci:release": "semantic-release"
2326
},
2427
"husky": {

rollup.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const resolve = require('rollup-plugin-node-resolve');
2+
const commonjs = require('rollup-plugin-commonjs');
3+
const packageJson = require('./package.json');
4+
5+
const buildUmd = {
6+
input: 'lib/index.js',
7+
output: {
8+
file: packageJson.main,
9+
format: 'umd',
10+
name: 'gavel',
11+
exports: 'named',
12+
sourcemap: true
13+
},
14+
plugins: [
15+
resolve({
16+
browser: true,
17+
18+
// Forbid bundling of NodeJS built-ins (i.e. "fs", "path").
19+
// Throw when such modules are present in the bundle.
20+
preferBuiltins: false
21+
}),
22+
commonjs()
23+
]
24+
};
25+
26+
module.exports = [buildUmd];

test/cucumber/support/world.js

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
/*
2-
* decaffeinate suggestions:
3-
* DS101: Remove unnecessary use of Array.from
4-
* DS102: Remove unnecessary code created because of implicit returns
5-
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
6-
*/
7-
/* eslint-disable */
8-
const vm = require('vm');
9-
const util = require('util');
101
const { assert } = require('chai');
112
const { exec } = require('child_process');
12-
const gavel = require('../../../lib');
3+
const gavel = require('../../../build');
134

145
const HTTP_LINE_DELIMITER = '\n';
156

@@ -28,12 +19,10 @@ class World {
2819

2920
executeCommands(commands) {
3021
const commandsBuffer = commands.join(';');
31-
const cmd =
32-
`PATH=$PATH:${process.cwd()}/bin:${process.cwd()}/node_modules/.bin; cd /tmp/gavel-* ;` +
33-
commandsBuffer;
22+
const cmd = `PATH=$PATH:${process.cwd()}/bin:${process.cwd()}/node_modules/.bin; cd /tmp/gavel-* ;${commandsBuffer}`;
3423

3524
return new Promise((resolve) => {
36-
const child = exec(cmd, function(error, stdout, stderr) {
25+
const child = exec(cmd, function(error) {
3726
if (error) {
3827
resolve(error.code);
3928
}
@@ -78,7 +67,8 @@ Make sure it's in the "Header-Name: value" format.
7867
`
7968
);
8069

81-
const [_, key, value] = match;
70+
const key = match[1];
71+
const value = match[2];
8272

8373
return Object.assign({}, acc, {
8474
[key.toLowerCase()]: value.trim()
@@ -117,17 +107,17 @@ Make sure it's in the "Header-Name: value" format.
117107
const headersLines = [];
118108
let bodyEntered = false;
119109

120-
for (let line of Array.from(lines)) {
110+
/* eslint-disable no-restricted-syntax */
111+
for (const line of Array.from(lines)) {
121112
if (line === '') {
122113
bodyEntered = true;
114+
} else if (bodyEntered) {
115+
bodyLines.push(line);
123116
} else {
124-
if (bodyEntered) {
125-
bodyLines.push(line);
126-
} else {
127-
headersLines.push(line);
128-
}
117+
headersLines.push(line);
129118
}
130119
}
120+
/* eslint-enable no-restricted-syntax */
131121

132122
parsed.headers = this.parseHeaders(headersLines.join(HTTP_LINE_DELIMITER));
133123
parsed.body = bodyLines.join(HTTP_LINE_DELIMITER);
@@ -154,20 +144,21 @@ Make sure it's in the "Header-Name: value" format.
154144
}
155145

156146
toPascalCase(string) {
157-
let result = string.replace(
158-
/(\w)(\w*)/g,
159-
(g0, g1, g2) => g1.toUpperCase() + g2.toLowerCase()
160-
);
161-
return (result = result.replace(' ', ''));
147+
return string
148+
.replace(
149+
/(\w)(\w*)/g,
150+
(g0, g1, g2) => g1.toUpperCase() + g2.toLowerCase()
151+
)
152+
.replace(' ', '');
162153
}
163154

164155
// Debugging helper
165156
inspect(data) {
166157
if (data !== null && typeof data === 'object') {
167158
return JSON.stringify(data, null, 2);
168-
} else {
169-
return data;
170159
}
160+
161+
return data;
171162
}
172163

173164
// Debugging helper
@@ -177,5 +168,5 @@ Make sure it's in the "Header-Name: value" format.
177168
}
178169

179170
module.exports = function() {
180-
return (this.World = World);
171+
this.World = World;
181172
};

0 commit comments

Comments
 (0)