Skip to content

Commit 83b99b9

Browse files
committed
add setup script and update package scripts
1 parent 1958784 commit 83b99b9

File tree

4 files changed

+138
-20
lines changed

4 files changed

+138
-20
lines changed

_SETUP.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Setup
22

3-
Setup your local webpack repository
3+
At webpack we use `yarn` to execute commands.
4+
5+
If you already have `yarn` installed, do: `yarn setup`. This will complete all required steps.
6+
7+
If not, do: `npm run setup`, the setup will also install `yarn` for you.
8+
9+
That's all.
10+
11+
## Setup manually
12+
13+
Setup your local webpack repository
414

515
```bash
616
git clone https://github.com/webpack/webpack.git
@@ -15,4 +25,4 @@ To run the entire test suite use:
1525

1626
```bash
1727
yarn test
18-
```
28+
```

package.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,33 +88,34 @@
8888
"schemas/"
8989
],
9090
"scripts": {
91+
"setup": "node ./setup/setup.js",
9192
"test": "mocha test/*.test.js test/*.unittest.js --max-old-space-size=4096 --harmony --trace-deprecation",
9293
"test:integration": "mocha test/*.test.js --max-old-space-size=4096 --harmony --trace-deprecation",
9394
"test:unit": "mocha test/*.unittest.js --max-old-space-size=4096 --harmony --trace-deprecation",
94-
"travis:integration": "npm run cover:init && npm run cover:integration && npm run cover:report-min",
95-
"travis:unit": "npm run cover:init && npm run cover:unit && npm run cover:report-min",
96-
"travis:lint": "npm run lint-files",
97-
"travis:benchmark": "npm run benchmark",
98-
"appveyor:integration": "npm run cover:init && npm run cover:integration && npm run cover:report-min",
99-
"appveyor:unit": "npm run cover:init && npm run cover:unit && npm run cover:report-min",
100-
"appveyor:benchmark": "npm run benchmark",
95+
"travis:integration": "yarn cover:init && yarn cover:integration && yarn cover:report-min",
96+
"travis:unit": "yarn cover:init && yarn cover:unit && yarn cover:report-min",
97+
"travis:lint": "yarn lint",
98+
"travis:benchmark": "yarn benchmark",
99+
"appveyor:integration": "yarn cover:init && yarn cover:integration && yarn cover:report-min",
100+
"appveyor:unit": "yarn cover:init && yarn cover:unit && yarn cover:report-min",
101+
"appveyor:benchmark": "yarn benchmark",
101102
"circleci:test": "node node_modules/mocha/bin/mocha --max-old-space-size=4096 --harmony --trace-deprecation test/*.test.js test/*.unittest.js",
102-
"circleci:lint": "npm run lint-files",
103+
"circleci:lint": "yarn lint",
103104
"build:examples": "cd examples && node buildAll.js",
104-
"pretest": "npm run lint-files",
105-
"lint-files": "npm run lint && npm run schema-lint",
106-
"lint": "eslint lib bin hot buildin \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\"",
107-
"fix": "npm run lint -- --fix",
108-
"pretty-files": "prettier \"lib/**/*.js\" \"bin/*.js\" \"hot/*.js\" \"buildin/*.js\" \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\" --write",
105+
"pretest": "yarn lint",
106+
"prelint": "yarn setup",
107+
"lint": "yarn code-lint && yarn schema-lint",
108+
"code-lint": "eslint setup lib bin hot buildin \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\"",
109+
"fix": "yarn code-lint --fix",
110+
"pretty": "prettier \"setup/**/*.js\" \"lib/**/*.js\" \"bin/*.js\" \"hot/*.js\" \"buildin/*.js\" \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\" --write",
109111
"schema-lint": "mocha test/*.lint.js --opts test/lint-mocha.opts",
110112
"benchmark": "mocha --max-old-space-size=4096 --harmony --trace-deprecation test/*.benchmark.js -R spec",
111-
"cover": "npm run cover:init && npm run cover:all && npm run cover:report",
113+
"cover": "yarn cover:init && yarn cover:all && yarn cover:report",
112114
"cover:init": "rimraf coverage",
113115
"cover:all": "node --max-old-space-size=4096 --harmony --trace-deprecation ./node_modules/istanbul/lib/cli.js cover --report none node_modules/mocha/bin/_mocha -- test/*.test.js test/*.unittest.js",
114116
"cover:integration": "node --max-old-space-size=4096 --harmony --trace-deprecation ./node_modules/istanbul/lib/cli.js cover --report none node_modules/mocha/bin/_mocha -- test/*.test.js",
115117
"cover:unit": "node --max-old-space-size=4096 --harmony --trace-deprecation ./node_modules/istanbul/lib/cli.js cover --report none node_modules/mocha/bin/_mocha -- test/*.unittest.js",
116118
"cover:report": "istanbul report",
117-
"cover:report-min": "istanbul report --report lcovonly",
118-
"publish-patch": "npm run lint && mocha && npm version patch && git push && git push --tags && npm publish"
119+
"cover:report-min": "istanbul report --report lcovonly"
119120
}
120121
}

setup/setup.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
"use strict";
2+
3+
const fs = require("fs");
4+
const path = require("path");
5+
const root = process.cwd();
6+
const node_modulesFolder = path.resolve(root, "node_modules");
7+
const webpackDependencyFolder = path.resolve(root, "node_modules/webpack");
8+
9+
function setup() {
10+
return checkSymlinkExistsAsync()
11+
.then(hasSymlink => {
12+
if (!hasSymlink) {
13+
return ensureYarnInstalledAsync().then(() => {
14+
return runSetupAsync().then(() => {
15+
return checkSymlinkExistsAsync();
16+
});
17+
});
18+
}
19+
})
20+
.then(message => {
21+
process.exitCode = 0;
22+
})
23+
.catch(e => {
24+
console.error(e);
25+
process.exitCode = 1;
26+
});
27+
}
28+
29+
function runSetupAsync() {
30+
return exec("yarn", ["install"], "Install dependencies")
31+
.then(() => exec("yarn", ["link"], "Create webpack symlink"))
32+
.then(() => exec("yarn", ["link", "webpack"], "Link webpack into itself"));
33+
}
34+
35+
function checkSymlinkExistsAsync() {
36+
return new Promise((resolve, reject) => {
37+
if (
38+
fs.existsSync(node_modulesFolder) &&
39+
fs.existsSync(webpackDependencyFolder) &&
40+
fs.lstatSync(webpackDependencyFolder).isSymbolicLink()
41+
) {
42+
resolve(true);
43+
} else {
44+
resolve(false);
45+
}
46+
});
47+
}
48+
49+
function ensureYarnInstalledAsync() {
50+
var semverPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$/;
51+
return execGetOutput("yarn", ["-v"], "Check yarn version")
52+
.then(stdout => semverPattern.test(stdout), () => false)
53+
.then(hasYarn => hasYarn || installYarnAsync());
54+
}
55+
56+
function installYarnAsync() {
57+
return exec("npm", ["install", "-g", "yarn"], "Install yarn");
58+
}
59+
60+
function exec(command, args, description) {
61+
console.log(`Setup: ${description}`);
62+
return new Promise((resolve, reject) => {
63+
let cp = require("child_process").spawn(command, args, {
64+
cwd: root,
65+
stdio: "inherit",
66+
shell: true
67+
});
68+
cp.on("error", error => {
69+
reject(new Error(`${description} failed with ${error}`));
70+
});
71+
cp.on("exit", exitCode => {
72+
if (exitCode) {
73+
reject(`${description} failed with exitcode ${exitCode}`);
74+
} else {
75+
resolve();
76+
}
77+
});
78+
});
79+
}
80+
81+
function execGetOutput(command, args, description) {
82+
console.log(`Setup: ${description}`);
83+
return new Promise((resolve, reject) => {
84+
let cp = require("child_process").spawn(command, args, {
85+
cwd: root,
86+
stdio: [process.stdin, "pipe", process.stderr],
87+
shell: true
88+
});
89+
cp.on("error", error => {
90+
reject(new Error(`${description} failed with ${error}`));
91+
});
92+
cp.on("exit", exitCode => {
93+
if (exitCode) {
94+
reject(`${description} failed with exitcode ${exitCode}`);
95+
} else {
96+
resolve(
97+
Buffer.concat(buffers)
98+
.toString("utf-8")
99+
.trim()
100+
);
101+
}
102+
});
103+
const buffers = [];
104+
cp.stdout.on("data", data => buffers.push(data));
105+
});
106+
}
107+
108+
setup();

test/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ But don't give up hope!!! Although our tests may appear complex and overwhelming
55

66
## tl;dr
77
* Clone repo
8-
* install and link deps
9-
* `yarn install && yarn link && yarn link webpack`
8+
* Run tests (this automatically runs the setup)
109
* `yarn test`
1110

1211
* To run an individual suite: (recommended during development for easier isolated diffs)

0 commit comments

Comments
 (0)