Skip to content

Commit 7708471

Browse files
committed
Merge branch 'master' into bugfix/namespace-object
# Conflicts: # lib/RuntimeTemplate.js
2 parents d4a04b8 + 1f2584e commit 7708471

File tree

250 files changed

+3849
-1467
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+3849
-1467
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. -->
2+
<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->
3+
<!-- Try to link to an open issue for more information. -->
4+
5+
6+
<!-- In addition to that please answer these questions: -->
27

38
**What kind of change does this PR introduce?**
49

@@ -8,17 +13,11 @@
813

914
<!-- Note that we won't merge your changes if you don't add tests -->
1015

11-
**If relevant, link to documentation update:**
12-
13-
<!-- Link PR from webpack/webpack.js.org here, or N/A -->
14-
15-
**Summary**
16-
17-
<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->
18-
<!-- Try to link to an open issue for more information. -->
19-
2016
**Does this PR introduce a breaking change?**
2117

2218
<!-- If this PR introduces a breaking change, please describe the impact and a migration path for existing applications. -->
2319

24-
**Other information**
20+
**What needs to be documented once your changes are merged?**
21+
22+
<!-- List all the information that needs to be added to the documentation after merge -->
23+
<!-- When your changes are merged you will be asked to contribute this to the documentation -->

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
*.log
1111
.idea
1212
.vscode
13+
.eslintcache
1314
package-lock.json

.prettierignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Ignore all paths.
2+
**/*.*
3+
4+
# Enable prettier for the following paths.
5+
!setup/**/*.js
6+
!lib/**/*.js
7+
!bin/*.js
8+
!hot/*.js
9+
!buildin/*.js
10+
!test/*.js
11+
!test/**/webpack.config.js
12+
!examples/**/webpack.config.js
13+
!schemas/**/*.js
14+
!declarations.d.ts

.travis.yml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,56 @@ branches:
99

1010
cache:
1111
yarn: true
12+
directories:
13+
- ".jest-cache"
14+
- ".eslintcache"
15+
16+
stages:
17+
- basic
18+
- advanced
19+
- versions
1220

1321
matrix:
1422
include:
1523
- os: linux
1624
node_js: "10"
17-
env: NO_WATCH_TESTS=1 JOB_PART=lint
25+
env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=basic
26+
stage: basic
1827
- os: linux
1928
node_js: "10"
20-
env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration
21-
- os: linux
22-
node_js: "8"
23-
env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration
29+
env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=lint-unit
30+
stage: advanced
2431
- os: linux
2532
node_js: "10"
26-
env: NO_WATCH_TESTS=1 JOB_PART=unit
27-
- os: linux
28-
node_js: "6"
29-
env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration
33+
env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=integration
34+
stage: advanced
3035
- os: osx
3136
node_js: "10"
32-
env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration
37+
env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=integration
38+
stage: versions
39+
- os: linux
40+
node_js: "8"
41+
env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=integration
42+
stage: versions
43+
- os: linux
44+
node_js: "6"
45+
env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=integration
46+
stage: versions
47+
fast_finish: true
3348
allow_failures:
3449
- os: osx
35-
fast_finish: true
3650

3751
install:
3852
- yarn --frozen-lockfile
3953
- yarn link --frozen-lockfile || true
4054
- yarn link webpack --frozen-lockfile
4155

42-
script: npm run travis:$JOB_PART
56+
script: yarn travis:$JOB_PART
4357

4458
after_success:
4559
- cat ./coverage/lcov.info | node_modules/.bin/coveralls --verbose
4660
- bash <(curl -s https://codecov.io/bash) -F $JOB_PART -X gcov
47-
- rm -rf ./coverage
61+
- rm -f .jest-cache/haste-map* .jest-cache/perf-cache*
4862

4963
notifications:
5064
slack:

README.md

Lines changed: 95 additions & 52 deletions
Large diffs are not rendered by default.

appveyor.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,28 @@ branches:
99
init:
1010
- git config --global core.autocrlf input
1111

12+
cache:
13+
- "..\\.yarn-cache"
14+
- ".jest-cache"
15+
1216
# what combinations to test
1317
environment:
1418
matrix:
15-
- nodejs_version: 8
19+
- nodejs_version: 10
1620
job_part: unit
17-
- nodejs_version: 8
21+
jest: --maxWorkers=2 --cacheDirectory .jest-cache
22+
- nodejs_version: 10
1823
job_part: integration
19-
jest: --maxWorkers=2
24+
jest: --maxWorkers=2 --cacheDirectory .jest-cache
2025
- nodejs_version: 6
2126
job_part: integration
22-
jest: --maxWorkers=2
27+
jest: --maxWorkers=2 --cacheDirectory .jest-cache
2328

2429
install:
2530
- ps: Install-Product node $env:nodejs_version x64
26-
- npm install yarn -g
27-
- yarn install --frozen-lockfile
28-
- yarn link --frozen-lockfile || yarn link --frozen-lockfile
29-
- yarn link webpack --frozen-lockfile
31+
- yarn --frozen-lockfile --preferred-cache-folder ..\\.yarn-cache
32+
- yarn link --frozen-lockfile --preferred-cache-folder ..\\.yarn-cache || yarn link --frozen-lockfile --preferred-cache-folder ..\\.yarn-cache
33+
- yarn link webpack --frozen-lockfile --preferred-cache-folder ..\\.yarn-cache
3034

3135
build: off
3236

@@ -38,5 +42,7 @@ test_script:
3842
- yarn --version
3943
- cmd: set JEST=%jest%
4044
- cmd: yarn appveyor:%job_part%
45+
- cmd: yarn istanbul report --report lcovonly
4146
- cmd: yarn unlink webpack
4247
- cmd: yarn global add codecov && codecov -F %job_part% --disable=gcov
48+
- cmd: del /F /Q .jest-cache\\haste-map* .jest-cache\\perf-cache* 2> null || Ver > null

bin/webpack.js

Lines changed: 128 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
#!/usr/bin/env node
2-
function runCommand(command, options) {
2+
3+
process.exitCode = 0;
4+
5+
/**
6+
* @param {string} command process to run
7+
* @param {string[]} args commandline arguments
8+
* @returns {Promise<void>} promise
9+
*/
10+
const runCommand = (command, args) => {
311
const cp = require("child_process");
412
return new Promise((resolve, reject) => {
5-
const executedCommand = cp.spawn(command, options, {
13+
const executedCommand = cp.spawn(command, args, {
614
stdio: "inherit",
715
shell: true
816
});
@@ -13,69 +21,146 @@ function runCommand(command, options) {
1321

1422
executedCommand.on("exit", code => {
1523
if (code === 0) {
16-
resolve(true);
24+
resolve();
1725
} else {
1826
reject();
1927
}
2028
});
2129
});
22-
}
30+
};
2331

24-
let webpackCliInstalled = false;
25-
try {
26-
require.resolve("webpack-cli");
27-
webpackCliInstalled = true;
28-
} catch (err) {
29-
webpackCliInstalled = false;
30-
}
32+
/**
33+
* @param {string} packageName name of the package
34+
* @returns {boolean} is the package installed?
35+
*/
36+
const isInstalled = packageName => {
37+
try {
38+
require.resolve(packageName);
3139

32-
if (!webpackCliInstalled) {
40+
return true;
41+
} catch (err) {
42+
return false;
43+
}
44+
};
45+
46+
/**
47+
* @typedef {Object} CliOption
48+
* @property {string} name display name
49+
* @property {string} package npm package name
50+
* @property {string} alias shortcut for choice
51+
* @property {boolean} installed currently installed?
52+
* @property {string} url homepage
53+
* @property {string} description description
54+
*/
55+
56+
/** @type {CliOption[]} */
57+
const CLIs = [
58+
{
59+
name: "webpack-cli",
60+
package: "webpack-cli",
61+
alias: "cli",
62+
installed: isInstalled("webpack-cli"),
63+
url: "https://github.com/webpack/webpack-cli",
64+
description: "The original webpack full-featured CLI."
65+
},
66+
{
67+
name: "webpack-command",
68+
package: "webpack-command",
69+
alias: "command",
70+
installed: isInstalled("webpack-command"),
71+
url: "https://github.com/webpack-contrib/webpack-command",
72+
description: "A lightweight, opinionated webpack CLI."
73+
}
74+
];
75+
76+
const installedClis = CLIs.filter(cli => cli.installed);
77+
78+
if (installedClis.length === 0) {
3379
const path = require("path");
3480
const fs = require("fs");
3581
const readLine = require("readline");
36-
const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock"));
3782

38-
const packageManager = isYarn ? "yarn" : "npm";
39-
const options = ["install", "-D", "webpack-cli"];
83+
let notify =
84+
"One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:";
4085

41-
if (isYarn) {
42-
options[0] = "add";
86+
for (const item of CLIs) {
87+
notify += `\n - ${item.name} (${item.url})\n ${item.description}`;
4388
}
4489

45-
const commandToBeRun = `${packageManager} ${options.join(" ")}`;
90+
console.error(notify);
4691

47-
const question = `Would you like to install webpack-cli? (That will run ${commandToBeRun}) (yes/NO)`;
92+
const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock"));
93+
94+
const packageManager = isYarn ? "yarn" : "npm";
95+
const installOptions = [isYarn ? "add" : "install", "-D"];
96+
97+
console.error(
98+
`We will use "${packageManager}" to install the CLI via "${packageManager} ${installOptions.join(
99+
" "
100+
)}".`
101+
);
102+
103+
let question = `Which one do you like to install (${CLIs.map(
104+
item => item.name
105+
).join("/")}):\n`;
48106

49-
console.error("The CLI moved into a separate package: webpack-cli");
50107
const questionInterface = readLine.createInterface({
51108
input: process.stdin,
52-
output: process.stdout
109+
output: process.stderr
53110
});
54111
questionInterface.question(question, answer => {
55112
questionInterface.close();
56-
switch (answer.toLowerCase()) {
57-
case "y":
58-
case "yes":
59-
case "1": {
60-
runCommand(packageManager, options)
61-
.then(result => {
62-
return require("webpack-cli"); //eslint-disable-line
63-
})
64-
.catch(error => {
65-
console.error(error);
66-
process.exitCode = 1;
67-
});
68-
break;
69-
}
70-
default: {
71-
console.error(
72-
"It needs to be installed alongside webpack to use the CLI"
73-
);
74-
process.exitCode = 1;
75-
break;
76-
}
113+
114+
const normalizedAnswer = answer.toLowerCase();
115+
const selectedPackage = CLIs.find(item => {
116+
return item.name === normalizedAnswer || item.alias === normalizedAnswer;
117+
});
118+
119+
if (!normalizedAnswer) {
120+
console.error(
121+
"One CLI needs to be installed alongside webpack to use the CLI."
122+
);
123+
process.exitCode = 1;
124+
125+
return;
126+
} else if (!selectedPackage) {
127+
console.error(
128+
"No matching choice.\n" +
129+
"One CLI needs to be installed alongside webpack to use the CLI.\n" +
130+
"Try to installing your CLI of choice manually."
131+
);
132+
process.exitCode = 1;
133+
134+
return;
77135
}
136+
137+
const packageName = selectedPackage.package;
138+
139+
console.log(
140+
`Installing '${
141+
selectedPackage.name
142+
}' (running '${packageManager} ${installOptions.join(
143+
" "
144+
)} ${packageName}')...`
145+
);
146+
147+
runCommand(packageManager, installOptions.concat(packageName))
148+
.then(() => {
149+
require(packageName); //eslint-disable-line
150+
})
151+
.catch(error => {
152+
console.error(error);
153+
process.exitCode = 1;
154+
});
78155
});
156+
} else if (installedClis.length === 1) {
157+
require(installedClis[0].package); // eslint-disable-line
79158
} else {
80-
require("webpack-cli"); // eslint-disable-line
159+
console.warn(
160+
`You have installed ${installedClis
161+
.map(item => item.name)
162+
.join(
163+
" and "
164+
)} together. To work with the "webpack" command you need only one CLI package, please remove one of them or use them directly via their binary.`
165+
);
81166
}

0 commit comments

Comments
 (0)