diff --git a/.appveyor.yml b/.appveyor.yml deleted file mode 100644 index e2dc3c6d4d6..00000000000 --- a/.appveyor.yml +++ /dev/null @@ -1,30 +0,0 @@ -clone_depth: 10 - -version: "{build}" - -environment: - fast_finish: true - matrix: - - nodejs_version: "8" - platform: x86 - -build: off - -install: - - ps: Install-Product node $env:nodejs_version $env:platform - - npm i -g npm - - npm i - - npm ci - - npm install --global codecov - - npm install eslint-plugin-node@latest --save-dev - -test_script: - - node --version - - npm --version - - which npm - - npm run appveyor:build - - npm run appveyor:lint - - npm run appveyor:test - -cache: - - node_modules -> appveyor.yml,package.json,package-lock.json diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000000..e095cab0376 --- /dev/null +++ b/.babelrc @@ -0,0 +1,12 @@ +{ + "presets": [[ + "@babel/preset-env", + { + "targets": { + "node": "current" + } + } + ], + "jest" + ] +} \ No newline at end of file diff --git a/.cz-config.js b/.cz-config.js index a9187cd8af8..b9895b88383 100644 --- a/.cz-config.js +++ b/.cz-config.js @@ -19,13 +19,13 @@ module.exports = { // sort type values in asc types: [ { value: "ast", name: "ast: init, migrate, add, etc" }, - { value: "break", name: "break: changes that break the behaviour of the cli" }, + { value: "break", name: "break: Changes that break the behaviour of the cli" }, { value: "chore", name: "chore: Updating deps, docs, linting, etc" }, { value: "cli", name: "cli: Core CLI things" }, { value: "docs", name: "docs: Documentation" }, { value: "feat", name: "feat: A new feature" }, { value: "fix", name: "fix: Bugs, typos, etc" }, { value: "misc", name: "misc: Other formats like tweaks and such" }, - { value: "tests", name: "tests: Tests, jest, binTestCases, etc" } + { value: "tests", name: "tests: Tests, jest, binTestCases, etc" }, ] }; diff --git a/.eslintignore b/.eslintignore index 999cb2bddc8..f6c8e2019eb 100644 --- a/.eslintignore +++ b/.eslintignore @@ -9,3 +9,5 @@ test/**/null.js test/**/main.js test/**/cliEntry.js test/**/foo.js +test/binCases/config-location/webpack-babel-config/bin/es6.js +packages/utils/validate-identifier.ts \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js index b584e0b742f..1aa1b65f720 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,31 +1,30 @@ module.exports = { - "root": true, - "plugins": ["node"], - "extends": ["eslint:recommended", "plugin:node/recommended"], - "env": { - "node": true, - "es6": true, - "jest": true + extends: ["eslint:recommended", "plugin:prettier/recommended"], + plugins: ["prettier"], + env: { + node: true, + es6: true, + jest: true }, - "parserOptions": { "ecmaVersion": 2017, "sourceType": "module"}, - "rules": { + parserOptions: { ecmaVersion: 2017, sourceType: "module" }, + rules: { "no-useless-escape": "off", "quote-props": ["error", "as-needed"], "no-dupe-keys": "error", - "quotes": ["error", "double"], + quotes: ["error", "double"], "no-undef": "error", "no-extra-semi": "error", - "semi": "error", + semi: "error", "no-template-curly-in-string": "error", "no-caller": "error", - "yoda": "error", - "eqeqeq": "error", + yoda: "error", + eqeqeq: "error", "global-require": "off", "brace-style": "error", "key-spacing": "error", "space-in-parens": ["error", "never"], "space-infix-ops": "error", - "indent": ["error", "tab", { "SwitchCase": 1 }], + indent: ["error", "tab", { SwitchCase: 1 }], "no-extra-bind": "warn", "no-empty": "off", "no-multiple-empty-lines": "error", @@ -33,78 +32,31 @@ module.exports = { "no-process-exit": "off", "no-trailing-spaces": "error", "no-use-before-define": "off", - "no-unused-vars": ["error", { "args": "none" }], + "no-unused-vars": ["error", { args: "none" }], "no-unsafe-negation": "error", "no-loop-func": "warn", "space-before-function-paren": ["error", "never"], "space-before-blocks": "error", "object-curly-spacing": ["error", "always"], - "object-curly-newline": ["error", { "consistent": true }], - "keyword-spacing": ["error", { - "after": true, - "overrides": { - "const": { "after": true }, - "try": { "after": true }, - "throw": { "after": true }, - "case": { "after": true }, - "return": { "after": true }, - "finally": { "after": true }, - "do": { "after": true } - } - }], - "no-console": "off", - "valid-jsdoc": "error", - "node/no-unsupported-features": ["error", { "version": 6 }], - "node/no-deprecated-api": "error", - "node/no-missing-import": "error", - "node/no-missing-require": [ - "error", - { - "resolvePaths": ["./packages"], - "allowModules": [ - "webpack", - "@webpack-cli/generators", - "@webpack-cli/init", - "@webpack-cli/migrate", - "@webpack-cli/utils", - "@webpack-cli/generate-loader", - "@webpack-cli/generate-plugin", - "@webpack-cli/webpack-scaffold" - ] - } - ], - "node/no-unpublished-bin": "error", - "node/no-unpublished-require": [ + "object-curly-newline": ["error", { consistent: true }], + "keyword-spacing": [ "error", { - "allowModules": [ - "webpack", - "webpack-dev-server", - "@webpack-cli/generators", - "@webpack-cli/init", - "@webpack-cli/migrate", - "@webpack-cli/utils", - "@webpack-cli/generate-loader", - "@webpack-cli/generate-plugin", - "@webpack-cli/webpack-scaffold" - ] - } - ], - "node/no-extraneous-require": [ - "error", - { - "allowModules": [ - "@webpack-cli/migrate", - "@webpack-cli/generators", - "@webpack-cli/utils", - "@webpack-cli/generate-loader", - "@webpack-cli/generate-plugin", - "@webpack-cli/webpack-scaffold" - ] + after: true, + overrides: { + const: { after: true }, + try: { after: true }, + throw: { after: true }, + case: { after: true }, + return: { after: true }, + finally: { after: true }, + do: { after: true } + } } ], + "no-console": "off", + "valid-jsdoc": "error", "eol-last": ["error", "always"], - "newline-per-chained-call": "off", - "node/process-exit-as-throw": "error" + "newline-per-chained-call": "off" } }; diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000000..1632a73dd4c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.js text eol=lf +*.ts text eol=lf diff --git a/CONTRIBUTING.md b/.github/CONTRIBUTING.md similarity index 57% rename from CONTRIBUTING.md rename to .github/CONTRIBUTING.md index 5c635b7302c..9fe2bc4fa62 100644 --- a/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -2,9 +2,33 @@ From opening a bug report to creating a pull request: every contribution is appreciated and welcomed. If you're planning a new feature or changing -the api, please create an issue first. This way we can ensure that your precious +the API, please create an issue first. This way we can ensure that your precious work is not in vain. +Table of Contents + +- [Issues](#issues) +- [Your first Contribution](#your-first-contribution) +- [Setup](#setup) +- [Running Tests](#running-tests) +- [Editor Config](#editor-config) +- [Dependencies](#dependencies) +- [Branching Model](#branching-model) +- [Naming a branch](#naming-a-branch) + - [Features](#features) + - [Fixes](#fixes) +- [Testing](#testing) +- [Pull Requests](#pull-requests) +- [Submitting a good Pull Request](#submitting-a-good-pull-request) +- [Commit message](#commit-message) + - [Commit Message Format](#commit-message-format) +- [Migrate with the CLI](#migrate-with-the-cli) + - [How it's being done](#how-its-being-done) + - [Structure of a transform](#structure-of-a-transform) + - [Further Work](#further-work) +- [Contributor License Agreement](#contributor-license-agreement) +- [Documentation](#documentation) + ## Issues Most of the time, when webpack does not work correctly, it might be a configuration issue. @@ -17,9 +41,9 @@ that include your `webpack.config.js` and relevant files. This way you help othe ## Your first Contribution -First of all you will need to create an issue in github for the feature or bugfix that you want to work on. When you open a new issue, there will be a template that will be automatically added to the text of the issue, which you would need to fill in. Doing this will help us to understand better what the ticket is about. +First of all, you will need to create an issue in Github for the feature or bugfix that you want to work on. When you open a new issue, there will be a template that will be automatically added to the text of the issue, which you would need to fill in. Doing this will help us to understand better what the ticket is about. -After you've created the issue, we will have a look, and provide feedback to your ticket. +After you've created the issue, we will have a look, and provide feedback to your ticket. In case it is a bug that you want to fix, we might help you with background information about the issue, so you can make an informed fix. @@ -27,30 +51,121 @@ In case you are suggesting a new feature, we will match your idea with our curre ## Setup -* Install [Node.js](https://nodejs.org/) if you don't have it already. - *Note: Node 6 or greater would be better for "best results".* -* Fork the **webpack-cli** repo at [https://github.com/webpack/webpack-cli](https://github.com/webpack/webpack-cli). -* `git clone && cd webpack-cli` +- Install [Node.js](https://nodejs.org/) if you don't have it already. + _Note: Node 6 or greater would be better for "best results"._ +- Fork the **webpack-cli** repo at [https://github.com/webpack/webpack-cli](https://github.com/webpack/webpack-cli). +- `git clone && cd webpack-cli` + +- If you decide to use [yarn](https://yarnpkg.com/lang/en/): + ```bash + npm install -g yarn + ``` + +> Using yarn is not a requirement, [npm](https://www.npmjs.com/) is included in node. + +- Install the dependencies and link them: + + ```bash + #npm + npm install + npm link + npm link webpack-cli + --------------------------- + #yarn + yarn + yarn link + yarn link webpack-cli + ``` + +- Bootstrap all the submodules before building for the first time + + ```bash + #npm + npm run bootstrap + npm run build + --------------------------- + #yarn + yarn bootstrap + yarn build + ``` + +## Running Tests + +### Using npm + +- Run all the tests with: + + ```bash + #npm + npm run test + --------------------------- + #yarn + yarn test + ``` + +- Run CLI tests with: + + ```bash + #npm + npm run test:cli + --------------------------- + #yarn + yarn test:cli` + ``` + +- Run tests of all packages: + + ```bash + #npm + npm run test:packages + --------------------------- + #yarn + yarn test:packages + ``` + +- Test a single CLI test case: + + > Must run from root of the poject + + ```bash + #npm + npx jest path/to/my-test.js + --------------------------- + #yarn + yarn jest path/to/my-test.js + ``` + +- You can also install jest globally and run tests without npx: + + ```bash + #npm + npm i -g jest + jest path/to/my-test.js + --------------------------- + #yarn + yarn global add jest + jest path/to/my-test.js + ``` + +- You can run the linters: + + ```bash + #npm + npm run lint + --------------------------- + #yarn + yarn lint + ``` -### Setup with npm -* Install the dependencies: `npm install` -* Run the tests with: `npm test` +## Editor Config -### Setup with yarn -* If you don't have yarn yet: `npm install -g yarn` -* Install the dependencies and link them +The [.editorconfig](https://github.com/webpack/webpack-cli/blob/master/.editorconfig) in the root should ensure consistent formatting. Please make sure you've [installed the plugin](http://editorconfig.org/#download) if your text editor needs one. -```bash -yarn install -yarn link -yarn link webpack-cli -``` +## Dependencies -* To run the entire test suite use: `yarn test` +This is a multi-package repository and dependencies are managed using [lerna](https://lerna.js.org/) -## Editor Config - -The [.editorconfig](https://github.com/webpack/webpack-cli/blob/master/.editorconfig) in the root should ensure consistent formatting. Please make sure you've [installed the plugin](http://editorconfig.org/#download) if your text editor needs one. +> If you are adding or updating any dependency, please commit the updated `package-lock.json` file. ## Branching Model @@ -60,19 +175,19 @@ We base our branching model on [git flow](http://nvie.com/posts/a-successful-git Making a branch in your fork for your contribution is helpful in the following ways: -* It allows you to submit more than one contribution in a single PR. -* It allows us to identify what your contribution is about from the branch name. +- It allows you to submit more than one contribution in a single PR. +- It allows us to identify what your contribution is about from the branch name. You will want to checkout the `master` branch locally before creating your new branch. There are two types of branches: -* Feature -* Bugfix +- Feature +- Bugfix ### Features -If your contribution is something new, like a option for the cli, you can create a branch with the following prefix: +If your contribution is something new, like an option for the cli, you can create a branch with the following prefix: `feature/` @@ -84,7 +199,7 @@ If you are fixing an existing bug, you can create a branch with the following pr ## Testing -Every bugfix or feature that you submit, needs to be tested. Writing tests for code is very important to prevent future bugs, and help to discover possible new bugs promptly. +Every bugfix or feature that you submit, needs to be tested. Writing tests for the code is very important to prevent future bugs, and help to discover possible new bugs promptly. It is important that you test the logic of the code you're writing, and that your tests really go through all your lines, branches and statements. This is the only way to ensure that the code coverage is high enough to ensure the users of the cli, that they are using a solid tool. @@ -95,42 +210,47 @@ In case you need a hand or pointers on to how to write your tests, do not hesita After getting some feedback, push to your fork and submit a pull request. We may suggest some changes, improvements or implementation alternatives. -In case you've got a small change in most of the cases your pull request would be accepted quicker. +In case you've got a small change in most of the cases, your pull request would be accepted quicker. ## Submitting a good Pull Request -* Write tests -* Follow the existing coding style -* Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) +- Write tests +- Follow the existing coding style +- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) -## Commit message format +## Commit message Our commit messages format follows the [angular.js commits format](https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#commit-message-format). +You can use `npm run commit` script to have an interactive way of making commits that follow our guidelines. + We don't use the scope. The template of a commit would look like this: ### Commit Message Format -Each commit message consists of a **header**, a **body** and a **footer**. The header has a special + +Each commit message consists of a **header**, a **body** and a **footer**. The header has a special format that includes a **type** and a **subject**: -``` +```md : +