Skip to content

Commit 652caf8

Browse files
committed
chore: rebase
2 parents fa658b8 + 530b4f7 commit 652caf8

Some content is hidden

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

42 files changed

+1082
-89
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
[![Issue resolution][issue-resolution]][issue-resolution-url]
2525
[![PR's welcome][pr-welcome]][pr-welcome-url]
2626

27+
## Table of Contents
28+
2729
- [About](#about)
2830
- [How to install](#how-to-install)
2931
- [Packages](#packages)

lib/commands/external.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { prompt } = require('inquirer');
2-
2+
const chalk = require('chalk');
33
class ExternalCommand {
44
static async runCommand(command, args = []) {
55
const cp = require('child_process');
@@ -19,32 +19,25 @@ class ExternalCommand {
1919
}
2020

2121
static validateEnv(extName) {
22-
let packageIsInstalled;
2322
try {
2423
const path = require('path');
2524
const pathForCmd = path.resolve(process.cwd(), 'node_modules', '@webpack-cli', extName);
2625
require.resolve(pathForCmd);
27-
packageIsInstalled = pathForCmd;
26+
return pathForCmd;
2827
} catch (err) {
29-
packageIsInstalled = false;
28+
return false;
3029
}
31-
return packageIsInstalled;
3230
}
3331
static async promptInstallation(scopeName, name) {
3432
const path = require('path');
3533
const fs = require('fs');
3634
const isYarn = fs.existsSync(path.resolve(process.cwd(), 'yarn.lock'));
37-
3835
const packageManager = isYarn ? 'yarn' : 'npm';
39-
const options = ['install', '-D', scopeName];
40-
41-
if (isYarn) {
42-
options[0] = 'add';
43-
}
36+
const options = [isYarn ? 'add': 'install', '-D', scopeName];
4437

4538
const commandToBeRun = `${packageManager} ${options.join(' ')}`;
46-
process.cliLogger.error(`The command moved into a separate package: ${name}`);
47-
const question = `Would you like to install ${name}? (That will run ${commandToBeRun})`;
39+
process.cliLogger.error(`The command moved into a separate package: ${chalk.keyword('orange')(name)}\n`);
40+
const question = `Would you like to install ${name}? (That will run ${chalk.green(commandToBeRun)})`;
4841
const answer = await prompt([
4942
{
5043
type: 'confirm',

lib/groups/advanced.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AdvancedGroup extends GroupHelper {
1414
name = name.substring(0, p);
1515
}
1616
} catch (e) {
17-
console.log('Invalid plugin arguments ' + name + ' (' + e + ').');
17+
process.cliLogger.error('Invalid plugin arguments ' + name + ' (' + e + ').');
1818
process.exit(-1); // eslint-disable-line
1919
}
2020

@@ -23,20 +23,20 @@ class AdvancedGroup extends GroupHelper {
2323
const resolve = require('enhanced-resolve');
2424
path = resolve.sync(process.cwd(), name);
2525
} catch (e) {
26-
console.log('Cannot resolve plugin ' + name + '.');
26+
process.cliLogger.error('Cannot resolve plugin ' + name + '.');
2727
process.exit(-1); // eslint-disable-line
2828
}
2929
let Plugin;
3030
try {
3131
Plugin = require(path);
3232
} catch (e) {
33-
console.log('Cannot load plugin ' + name + '. (' + path + ')');
33+
process.cliLogger.error('Cannot load plugin ' + name + '. (' + path + ')');
3434
throw e;
3535
}
3636
try {
3737
return new Plugin(args);
3838
} catch (e) {
39-
console.log('Cannot instantiate plugin ' + name + '. (' + path + ')');
39+
process.cliLogger.error('Cannot instantiate plugin ' + name + '. (' + path + ')');
4040
throw e;
4141
}
4242
}

lib/groups/config.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ConfigGroup extends GroupHelper {
2626
getConfigExtension(configPath) {
2727
for (let i = this.extensions.length - 1; i >= 0; i--) {
2828
const tmpExt = this.extensions[i];
29-
if (configPath.indexOf(tmpExt, configPath.length - tmpExt.length) > -1) {
29+
if (configPath.includes(tmpExt, configPath.length - tmpExt.length)) {
3030
return tmpExt;
3131
}
3232
}
@@ -41,22 +41,30 @@ class ConfigGroup extends GroupHelper {
4141
};
4242
}
4343

44+
require(path) {
45+
const result = require(path);
46+
if (result && result.__esModule && result.default) {
47+
return result.default;
48+
}
49+
return result;
50+
}
51+
4452
requireConfig(configPath) {
4553
const { register } = this.args;
4654

4755
this.configOptions = (() => {
4856
if (register && register.length) {
4957
module.paths.unshift(resolve(process.cwd(), 'node_modules'));
5058
register.forEach(dep => {
51-
const isRelative = ["./", "../", ".\\", "..\\"].some(start => dep.startsWith(start));
59+
const isRelative = ['./', '../', '.\\', '..\\'].some(start => dep.startsWith(start));
5260
if (isRelative) {
5361
require(resolve(process.cwd(), dep));
5462
} else {
5563
require(dep);
5664
}
5765
});
5866
}
59-
return require(configPath);
67+
return this.require(configPath);
6068
})();
6169
}
6270

@@ -81,7 +89,7 @@ class ConfigGroup extends GroupHelper {
8189
.map(this.mapConfigArg.bind(this));
8290
if (tmpConfigFiles.length) {
8391
if (!config) {
84-
const defaultConfig = tmpConfigFiles.find(p => ~p.path.indexOf(mode));
92+
const defaultConfig = tmpConfigFiles.find(p => p.path.includes(mode));
8593
this.configFiles = defaultConfig || tmpConfigFiles[0];
8694
}
8795
}
@@ -110,7 +118,7 @@ class ConfigGroup extends GroupHelper {
110118
const { merge } = this.args;
111119
if (merge) {
112120
const newConfigPath = this.resolveFilePath(merge, 'webpack.base');
113-
const newConfig = newConfigPath ? require(newConfigPath) : null;
121+
const newConfig = newConfigPath ? this.require(newConfigPath) : null;
114122
this.opts['options'] = require('webpack-merge')(this.opts['options'], newConfig);
115123
}
116124
}

lib/utils/compiler.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,15 @@ const fs = require('fs');
33
const chalk = require('chalk');
44
const Table = require('cli-table3');
55

6-
function showEmojiConditionally(emoji) {
7-
if (process.stdout.isTTY && process.platform === 'darwin') {
8-
return emoji;
9-
} else {
10-
return '';
11-
}
6+
function showEmojiConditionally() {
7+
return (process.stdout.isTTY && process.platform === 'darwin')
128
}
139

1410
function generateOutput(outputOptions, stats, statsErrors) {
1511
const statsObj = stats.toJson(outputOptions);
1612
const { assets, entrypoints, time, builtAt, warnings, outputPath } = statsObj;
1713

18-
const emojies = ['✅', '🌏', '⚒️ ', '⏱ ', '📂'];
19-
const visibleEmojies = emojies.map(e => showEmojiConditionally(e));
14+
const visibleEmojies = showEmojiConditionally() ? ['✅', '🌏', '⚒️ ', '⏱ ', '📂']: new Array(5).fill('');
2015

2116
process.stdout.write('\n');
2217
process.stdout.write(`${visibleEmojies[0]} ${chalk.underline.bold('Compilation Results')}\n`);

lib/utils/group-helper.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ class GroupHelper {
5757
}
5858
mapArgToBoolean(name, optionName) {
5959
ifArg(name, function(bool) {
60-
if (bool === true) options[optionName || name] = true;
61-
else if (bool === false) options[optionName || name] = false;
60+
if ([true, false].includes(bool)) {
61+
options[optionName || name] = bool;
62+
}
6263
});
6364
}
6465

@@ -114,10 +115,10 @@ class GroupHelper {
114115
if (filename && Array.isArray(filename)) {
115116
return filename.map(fp => this.resolveFilePath(fp, defaultValue)).filter(e => e);
116117
}
117-
if (filename && filename.indexOf('.js') < 0) {
118+
if (filename && filename.includes('.js')) {
118119
filename = filename + '.js';
119120
}
120-
if (defaultValue && defaultValue.indexOf('.js') < 0) {
121+
if (defaultValue && defaultValue.includes('.js')) {
121122
defaultValue = defaultValue + '.js';
122123
}
123124
let configPath;

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"test": "nyc jest --maxWorkers=4 --reporters=default --reporters=jest-junit",
4141
"test:cli": "nyc jest test/ --maxWorkers=4 --reporters=default --reporters=jest-junit",
4242
"test:packages": "nyc jest packages/ --maxWorkers=4 --reporters=default --reporters=jest-junit",
43-
"test:ci": "nyc jest --maxWorkers=$(nproc) --reporters=default --reporters=jest-junit",
43+
"test:ci": "nyc jest --maxWorkers=$(nproc) --reporters=default --reporters=jest-junit --colors",
4444
"travis:integration": "npm run build && npm run test && npm run reportCoverage",
4545
"travis:lint": "npm run build && npm run lint",
4646
"watch": "npm run build && tsc -w",

packages/generators/addon-generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const addonGenerator = (
5151
I will create this folder for you.
5252
`);
5353
mkdirp(this.props.name, (err: object): void => {
54-
console.error("Failed to create directory", err);
54+
if (err) console.error("Failed to create directory", err);
5555
});
5656
const pathToProjectDir: string = this.destinationPath(this.props.name);
5757
this.destinationRoot(pathToProjectDir);

packages/info/README.md

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,81 @@ This package returns a set of information related to the local environment.
99
## Installation
1010

1111
```bash
12+
#npm
1213
npm i -D @webpack-cli/info
14+
15+
#yarn
16+
yarn add @webpack-cli/info -D
17+
18+
#npx
19+
npx webpack info [options]
20+
1321
```
1422

1523
## Usage
1624

25+
### Args / Flags
26+
27+
#### Output format
28+
29+
| Flag | Description | Type |
30+
| ------------------- | ----------------------------- | ----------- |
31+
| `--output-json` | To get the output as JSON | [ boolean ] |
32+
| `--output-markdown` | To get the output as markdown | [ boolean ] |
33+
34+
_Not supported for config_
35+
36+
#### Options
37+
38+
| Flag | Description | Type |
39+
| ------------------- | --------------------------------------------------------------- | ----------- |
40+
| `--help` | Show help | [ boolean ] |
41+
| `--version` | Show version number of `webpack-cli` | [ boolean ] |
42+
| `--system` , `-s` | System information ( OS, CPU ) | [ boolean ] |
43+
| `--binaries` , `-b` | Installed binaries (Node, yarn, npm) | [ boolean ] |
44+
| `--browsers` | Installed web browsers | [ boolean ] |
45+
| `--npmg` | Globally installed NPM packages ( webpack & webpack-cli only ) | [ boolean ] |
46+
| `--npmPackages` | Info about packages related to webpack installed in the project | [ boolean ] |
47+
1748
### Node
1849

1950
```js
20-
const envinfo = require("@webpack-cli/info").default;
21-
envinfo();
51+
const info = require('@webpack-cli/info').default;
52+
53+
async function wrapperFunc() {
54+
await info({
55+
/* Custom Config */
56+
});
57+
}
58+
wrapperFunc();
59+
```
60+
61+
#### Custom config
62+
63+
> Config has higher precedence than system flags
64+
65+
```json
66+
// Config's relative path
67+
{
68+
69+
"config": [string]
70+
}
71+
// System info
72+
{
73+
"binaries": [boolean],
74+
"system": [boolean],
75+
"browsers": [boolean],
76+
"npmg": [boolean],
77+
"npmPackages": [boolean],
78+
}
2279
```
2380

81+
The function returns `string` for `system` info, and returns an array of strings (`string[]`) for `config`
82+
2483
### CLI (via `webpack-cli`)
2584

2685
```bash
27-
npx webpack-cli info
86+
webpack-cli info --FLAGS #Flags are optional for custom output
2887
```
2988

3089
[downloads]: https://img.shields.io/npm/dm/@webpack-cli/info.svg

0 commit comments

Comments
 (0)