Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/namespace-object
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/RuntimeTemplate.js
  • Loading branch information
sokra committed May 28, 2018
2 parents d4a04b8 + 1f2584e commit 7708471
Show file tree
Hide file tree
Showing 250 changed files with 3,849 additions and 1,467 deletions.
19 changes: 9 additions & 10 deletions .github/PULL_REQUEST_TEMPLATE.md
@@ -1,4 +1,9 @@
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. -->
<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->
<!-- Try to link to an open issue for more information. -->


<!-- In addition to that please answer these questions: -->

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

Expand All @@ -8,17 +13,11 @@

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

**If relevant, link to documentation update:**

<!-- Link PR from webpack/webpack.js.org here, or N/A -->

**Summary**

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->
<!-- Try to link to an open issue for more information. -->

**Does this PR introduce a breaking change?**

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

**Other information**
**What needs to be documented once your changes are merged?**

<!-- List all the information that needs to be added to the documentation after merge -->
<!-- When your changes are merged you will be asked to contribute this to the documentation -->
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,4 +10,5 @@
*.log
.idea
.vscode
.eslintcache
package-lock.json
14 changes: 14 additions & 0 deletions .prettierignore
@@ -0,0 +1,14 @@
# Ignore all paths.
**/*.*

# Enable prettier for the following paths.
!setup/**/*.js
!lib/**/*.js
!bin/*.js
!hot/*.js
!buildin/*.js
!test/*.js
!test/**/webpack.config.js
!examples/**/webpack.config.js
!schemas/**/*.js
!declarations.d.ts
40 changes: 27 additions & 13 deletions .travis.yml
Expand Up @@ -9,42 +9,56 @@ branches:

cache:
yarn: true
directories:
- ".jest-cache"
- ".eslintcache"

stages:
- basic
- advanced
- versions

matrix:
include:
- os: linux
node_js: "10"
env: NO_WATCH_TESTS=1 JOB_PART=lint
env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=basic
stage: basic
- os: linux
node_js: "10"
env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration
- os: linux
node_js: "8"
env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration
env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=lint-unit
stage: advanced
- os: linux
node_js: "10"
env: NO_WATCH_TESTS=1 JOB_PART=unit
- os: linux
node_js: "6"
env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration
env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=integration
stage: advanced
- os: osx
node_js: "10"
env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration
env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=integration
stage: versions
- os: linux
node_js: "8"
env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=integration
stage: versions
- os: linux
node_js: "6"
env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=integration
stage: versions
fast_finish: true
allow_failures:
- os: osx
fast_finish: true

install:
- yarn --frozen-lockfile
- yarn link --frozen-lockfile || true
- yarn link webpack --frozen-lockfile

script: npm run travis:$JOB_PART
script: yarn travis:$JOB_PART

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

notifications:
slack:
Expand Down
147 changes: 95 additions & 52 deletions README.md

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions appveyor.yml
Expand Up @@ -9,24 +9,28 @@ branches:
init:
- git config --global core.autocrlf input

cache:
- "..\\.yarn-cache"
- ".jest-cache"

# what combinations to test
environment:
matrix:
- nodejs_version: 8
- nodejs_version: 10
job_part: unit
- nodejs_version: 8
jest: --maxWorkers=2 --cacheDirectory .jest-cache
- nodejs_version: 10
job_part: integration
jest: --maxWorkers=2
jest: --maxWorkers=2 --cacheDirectory .jest-cache
- nodejs_version: 6
job_part: integration
jest: --maxWorkers=2
jest: --maxWorkers=2 --cacheDirectory .jest-cache

install:
- ps: Install-Product node $env:nodejs_version x64
- npm install yarn -g
- yarn install --frozen-lockfile
- yarn link --frozen-lockfile || yarn link --frozen-lockfile
- yarn link webpack --frozen-lockfile
- yarn --frozen-lockfile --preferred-cache-folder ..\\.yarn-cache
- yarn link --frozen-lockfile --preferred-cache-folder ..\\.yarn-cache || yarn link --frozen-lockfile --preferred-cache-folder ..\\.yarn-cache
- yarn link webpack --frozen-lockfile --preferred-cache-folder ..\\.yarn-cache

build: off

Expand All @@ -38,5 +42,7 @@ test_script:
- yarn --version
- cmd: set JEST=%jest%
- cmd: yarn appveyor:%job_part%
- cmd: yarn istanbul report --report lcovonly
- cmd: yarn unlink webpack
- cmd: yarn global add codecov && codecov -F %job_part% --disable=gcov
- cmd: del /F /Q .jest-cache\\haste-map* .jest-cache\\perf-cache* 2> null || Ver > null
171 changes: 128 additions & 43 deletions bin/webpack.js
@@ -1,8 +1,16 @@
#!/usr/bin/env node
function runCommand(command, options) {

process.exitCode = 0;

/**
* @param {string} command process to run
* @param {string[]} args commandline arguments
* @returns {Promise<void>} promise
*/
const runCommand = (command, args) => {
const cp = require("child_process");
return new Promise((resolve, reject) => {
const executedCommand = cp.spawn(command, options, {
const executedCommand = cp.spawn(command, args, {
stdio: "inherit",
shell: true
});
Expand All @@ -13,69 +21,146 @@ function runCommand(command, options) {

executedCommand.on("exit", code => {
if (code === 0) {
resolve(true);
resolve();
} else {
reject();
}
});
});
}
};

let webpackCliInstalled = false;
try {
require.resolve("webpack-cli");
webpackCliInstalled = true;
} catch (err) {
webpackCliInstalled = false;
}
/**
* @param {string} packageName name of the package
* @returns {boolean} is the package installed?
*/
const isInstalled = packageName => {
try {
require.resolve(packageName);

if (!webpackCliInstalled) {
return true;
} catch (err) {
return false;
}
};

/**
* @typedef {Object} CliOption
* @property {string} name display name
* @property {string} package npm package name
* @property {string} alias shortcut for choice
* @property {boolean} installed currently installed?
* @property {string} url homepage
* @property {string} description description
*/

/** @type {CliOption[]} */
const CLIs = [
{
name: "webpack-cli",
package: "webpack-cli",
alias: "cli",
installed: isInstalled("webpack-cli"),
url: "https://github.com/webpack/webpack-cli",
description: "The original webpack full-featured CLI."
},
{
name: "webpack-command",
package: "webpack-command",
alias: "command",
installed: isInstalled("webpack-command"),
url: "https://github.com/webpack-contrib/webpack-command",
description: "A lightweight, opinionated webpack CLI."
}
];

const installedClis = CLIs.filter(cli => cli.installed);

if (installedClis.length === 0) {
const path = require("path");
const fs = require("fs");
const readLine = require("readline");
const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock"));

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

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

const commandToBeRun = `${packageManager} ${options.join(" ")}`;
console.error(notify);

const question = `Would you like to install webpack-cli? (That will run ${commandToBeRun}) (yes/NO)`;
const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock"));

const packageManager = isYarn ? "yarn" : "npm";
const installOptions = [isYarn ? "add" : "install", "-D"];

console.error(
`We will use "${packageManager}" to install the CLI via "${packageManager} ${installOptions.join(
" "
)}".`
);

let question = `Which one do you like to install (${CLIs.map(
item => item.name
).join("/")}):\n`;

console.error("The CLI moved into a separate package: webpack-cli");
const questionInterface = readLine.createInterface({
input: process.stdin,
output: process.stdout
output: process.stderr
});
questionInterface.question(question, answer => {
questionInterface.close();
switch (answer.toLowerCase()) {
case "y":
case "yes":
case "1": {
runCommand(packageManager, options)
.then(result => {
return require("webpack-cli"); //eslint-disable-line
})
.catch(error => {
console.error(error);
process.exitCode = 1;
});
break;
}
default: {
console.error(
"It needs to be installed alongside webpack to use the CLI"
);
process.exitCode = 1;
break;
}

const normalizedAnswer = answer.toLowerCase();
const selectedPackage = CLIs.find(item => {
return item.name === normalizedAnswer || item.alias === normalizedAnswer;
});

if (!normalizedAnswer) {
console.error(
"One CLI needs to be installed alongside webpack to use the CLI."
);
process.exitCode = 1;

return;
} else if (!selectedPackage) {
console.error(
"No matching choice.\n" +
"One CLI needs to be installed alongside webpack to use the CLI.\n" +
"Try to installing your CLI of choice manually."
);
process.exitCode = 1;

return;
}

const packageName = selectedPackage.package;

console.log(
`Installing '${
selectedPackage.name
}' (running '${packageManager} ${installOptions.join(
" "
)} ${packageName}')...`
);

runCommand(packageManager, installOptions.concat(packageName))
.then(() => {
require(packageName); //eslint-disable-line
})
.catch(error => {
console.error(error);
process.exitCode = 1;
});
});
} else if (installedClis.length === 1) {
require(installedClis[0].package); // eslint-disable-line
} else {
require("webpack-cli"); // eslint-disable-line
console.warn(
`You have installed ${installedClis
.map(item => item.name)
.join(
" and "
)} 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.`
);
}

0 comments on commit 7708471

Please sign in to comment.