GeezerVison is showing github.com — add setup script and update package scripts · webpack/webpack@83b99b9
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: _SETUP.md +12-2Lines changed: 12 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | # Setup | 2 | 2 |
| 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 | 4 | 14 |
| 5 | 15 | ```bash | 6 | 16 | git clone https://github.com/webpack/webpack.git | @@ -15,4 +25,4 @@ To run the entire test suite use: | 15 | 25 |
| 16 | 26 | ```bash | 17 | 27 | yarn test | 18 | | -``` | | 28 | +``` |
Collapse file Copy file name to clipboardExpand all lines: package.json +17-16Lines changed: 17 additions & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 88 | 88 | "schemas/" | 89 | 89 | ], | 90 | 90 | "scripts": { | | 91 | + "setup": "node ./setup/setup.js", | 91 | 92 | "test": "mocha test/*.test.js test/*.unittest.js --max-old-space-size=4096 --harmony --trace-deprecation", | 92 | 93 | "test:integration": "mocha test/*.test.js --max-old-space-size=4096 --harmony --trace-deprecation", | 93 | 94 | "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", | 101 | 102 | "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", | 103 | 104 | "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", | 109 | 111 | "schema-lint": "mocha test/*.lint.js --opts test/lint-mocha.opts", | 110 | 112 | "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", | 112 | 114 | "cover:init": "rimraf coverage", | 113 | 115 | "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", | 114 | 116 | "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", | 115 | 117 | "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", | 116 | 118 | "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" | 119 | 120 | } | 120 | 121 | } |
Collapse file Copy file name to clipboard +108Lines changed: 108 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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(); |
Collapse file Copy file name to clipboardExpand all lines: test/README.md +1-2Lines changed: 1 addition & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -5,8 +5,7 @@ But don't give up hope!!! Although our tests may appear complex and overwhelming | 5 | 5 |
| 6 | 6 | ## tl;dr | 7 | 7 | * Clone repo | 8 | | -* install and link deps | 9 | | - * `yarn install && yarn link && yarn link webpack` | | 8 | +* Run tests (this automatically runs the setup) | 10 | 9 | * `yarn test` | 11 | 10 |
| 12 | 11 | * To run an individual suite: (recommended during development for easier isolated diffs) | |
|