Skip to content

Commit

Permalink
Reformat code using prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
soilSpoon committed Dec 24, 2020
1 parent e12f713 commit 34d5529
Show file tree
Hide file tree
Showing 45 changed files with 137 additions and 251 deletions.
50 changes: 25 additions & 25 deletions .github/workflows/node.js.yml
Expand Up @@ -4,31 +4,31 @@
name: Node.js CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
name: Build and test for ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
PLAYWRIGHT_BROWSERS_PATH: 0

strategy:
fail-fast: false
matrix:
node-version: [12.x, 13.x, 14.x]
os: [ubuntu-latest, windows-latest]
build:
name: Build and test for ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
PLAYWRIGHT_BROWSERS_PATH: 0

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm install
- name: Run Tests
run: npm test
strategy:
fail-fast: false
matrix:
node-version: [12.x, 13.x, 14.x]
os: [ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm install
- name: Run Tests
run: npm test
3 changes: 1 addition & 2 deletions src/BabelConfig.js
Expand Up @@ -17,8 +17,7 @@ class BabelConfig {
mixBabelConfig
],
{
arrayMerge: (destinationArray, sourceArray, options) =>
sourceArray
arrayMerge: (destinationArray, sourceArray, options) => sourceArray
}
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/File.js
Expand Up @@ -168,7 +168,9 @@ class File {
pathWithoutQueryString() {
const queryStringIndex = this.path().indexOf('?');

return queryStringIndex < 0 ? this.path() : this.path().substr(0, queryStringIndex);
return queryStringIndex < 0
? this.path()
: this.path().substr(0, queryStringIndex);
}

/**
Expand Down
18 changes: 7 additions & 11 deletions src/FileCollection.js
Expand Up @@ -30,15 +30,13 @@ class FileCollection {
* @param {object} wantsBabel
*/
merge(output, wantsBabel = false) {
return concat(this.files, output.makeDirectories().path()).then(
contents => {
if (this.shouldCompileWithBabel(wantsBabel, output)) {
output.write(this.babelify(contents));
}

return new File(output.makeDirectories().path());
return concat(this.files, output.makeDirectories().path()).then(contents => {
if (this.shouldCompileWithBabel(wantsBabel, output)) {
output.write(this.babelify(contents));
}
);

return new File(output.makeDirectories().path());
});
}

/**
Expand Down Expand Up @@ -95,9 +93,7 @@ class FileCollection {
let files = glob.sync(src.path(), { nodir: true });

if (!files.length) {
Log.feedback(
`Notice: The ${src.path()} search produced no matches.`
);
Log.feedback(`Notice: The ${src.path()} search produced no matches.`);
}

return this.copyTo(destination, files);
Expand Down
12 changes: 3 additions & 9 deletions src/Manifest.js
Expand Up @@ -24,9 +24,7 @@ class Manifest {
);
}

return collect(this.manifest)
.sortKeys()
.all();
return collect(this.manifest).sortKeys().all();
}

/**
Expand Down Expand Up @@ -74,9 +72,7 @@ class Manifest {
* Refresh the mix-manifest.js file.
*/
refresh() {
File.find(this.path())
.makeDirectories()
.write(this.manifest);
File.find(this.path()).makeDirectories().write(this.manifest);
}

/**
Expand All @@ -103,9 +99,7 @@ class Manifest {

// If there's a temporary mix.js chunk, we can safely remove it.
if (assets.mix) {
assets.mix = collect(assets.mix)
.except('mix.js')
.all();
assets.mix = collect(assets.mix).except('mix.js').all();
}

return (
Expand Down
14 changes: 3 additions & 11 deletions src/PostCssPluginsFactory.js
Expand Up @@ -54,14 +54,8 @@ class PostCssPluginsFactory {
* Load any postcss plugins that were passed to the Mix command.
*/
loadLocalPlugins() {
if (
this.preprocessor.postCssPlugins &&
this.preprocessor.postCssPlugins.length
) {
this.plugins = [
...this.plugins,
...this.preprocessor.postCssPlugins
];
if (this.preprocessor.postCssPlugins && this.preprocessor.postCssPlugins.length) {
this.plugins = [...this.plugins, ...this.preprocessor.postCssPlugins];
}

return this;
Expand All @@ -72,9 +66,7 @@ class PostCssPluginsFactory {
*/
loadAutoprefixer() {
if (this.Config.autoprefixer) {
this.plugins.push(
require('autoprefixer')(this.Config.autoprefixer)
);
this.plugins.push(require('autoprefixer')(this.Config.autoprefixer));
}

return this;
Expand Down
18 changes: 4 additions & 14 deletions src/builder/Entry.js
Expand Up @@ -53,16 +53,11 @@ class Entry {
* Add a default entry script to the structure.
*/
addDefault() {
this.add(
'mix',
new File(path.resolve(__dirname, 'mock-entry.js')).path()
);
this.add('mix', new File(path.resolve(__dirname, 'mock-entry.js')).path());
}

hasDefault() {
return (this.structure.mix || []).some(path =>
path.includes('mock-entry.js')
);
return (this.structure.mix || []).some(path => path.includes('mock-entry.js'));
}

/**
Expand Down Expand Up @@ -94,18 +89,13 @@ class Entry {
!pathFromPublicDir.startsWith('/' + Config.publicPath) &&
!pathFromPublicDir.startsWith('\\' + Config.publicPath)
) {
output = new File(
path.join(Config.publicPath, output.pathFromPublic())
);
output = new File(path.join(Config.publicPath, output.pathFromPublic()));
}

// If the output points to a directory, we'll grab a file name from the fallback src.
if (output.isDirectory()) {
output = new File(
path.join(
output.filePath,
fallback.nameWithoutExtension() + '.js'
)
path.join(output.filePath, fallback.nameWithoutExtension() + '.js')
);
}

Expand Down
38 changes: 10 additions & 28 deletions src/builder/MergeSmart.js
Expand Up @@ -15,8 +15,7 @@ const isArray = Array.isArray;
function uniteRules(rules, key, newRule, rule) {
if (
String(rule.test) !== String(newRule.test) ||
((newRule.enforce || rule.enforce) &&
rule.enforce !== newRule.enforce) ||
((newRule.enforce || rule.enforce) && rule.enforce !== newRule.enforce) ||
(newRule.include && !isSameValue(rule.include, newRule.include)) ||
(newRule.exclude && !isSameValue(rule.exclude, newRule.exclude))
) {
Expand All @@ -30,10 +29,7 @@ function uniteRules(rules, key, newRule, rule) {
) {
// Don't merge the rule if there isn't any identifying fields and the loaders don't match
return false;
} else if (
(rule.include || rule.exclude) &&
(!newRule.include && !newRule.exclude)
) {
} else if ((rule.include || rule.exclude) && !newRule.include && !newRule.exclude) {
// Don't merge child without include/exclude to parent that has either
return false;
}
Expand All @@ -51,9 +47,7 @@ function uniteRules(rules, key, newRule, rule) {

// newRule.loader should always override use, loaders and oneOf
if (newRule.loader) {
const optionsKey = newRule.options
? 'options'
: newRule.query && 'query';
const optionsKey = newRule.options ? 'options' : newRule.query && 'query';

delete rule.use;
delete rule.loaders;
Expand All @@ -74,8 +68,7 @@ function uniteRules(rules, key, newRule, rule) {
(rule.use || rule.loaders || rule.loader) &&
(newRule.use || newRule.loaders)
) {
const expandEntry = loader =>
typeof loader === 'string' ? { loader } : loader;
const expandEntry = loader => (typeof loader === 'string' ? { loader } : loader);
// this is only here to avoid breaking existing tests
const unwrapEntry = entry =>
!entry.options && !entry.query ? entry.loader : entry;
Expand All @@ -97,9 +90,7 @@ function uniteRules(rules, key, newRule, rule) {
} else {
entries = [].concat(rule.use || rule.loaders).map(expandEntry);
}
const newEntries = []
.concat(newRule.use || newRule.loaders)
.map(expandEntry);
const newEntries = [].concat(newRule.use || newRule.loaders).map(expandEntry);

const loadersKey = rule.use || newRule.use ? 'use' : 'loaders';
const resolvedKey = `${key}.${loadersKey}`;
Expand All @@ -115,9 +106,7 @@ function uniteRules(rules, key, newRule, rule) {
rule[loadersKey] = newRule.use || newRule.loaders;
break;
default:
rule[loadersKey] = combineEntries(newEntries, entries).map(
unwrapEntry
);
rule[loadersKey] = combineEntries(newEntries, entries).map(unwrapEntry);
}
}

Expand Down Expand Up @@ -185,8 +174,7 @@ function combineEntries(newEntries, existingEntries) {
areEqualEntries,
existingEntriesIteratorIndex
);
const hasEquivalentEntryInExistingEntries =
indexInExistingEntries !== -1;
const hasEquivalentEntryInExistingEntries = indexInExistingEntries !== -1;

if (hasEquivalentEntryInExistingEntries) {
// If the same entry exists in existing entries, we should add all of the entries that
Expand Down Expand Up @@ -215,10 +203,7 @@ function combineEntries(newEntries, existingEntries) {
existingEntriesIteratorIndex -= 1;
}

uniteEntries(
currentEntry,
existingEntries[existingEntriesIteratorIndex]
);
uniteEntries(currentEntry, existingEntries[existingEntriesIteratorIndex]);
// uniteEntries mutates the second parameter to be a merged version, so that's what's pushed
resultSet.unshift(existingEntries[existingEntriesIteratorIndex]);

Expand All @@ -245,11 +230,8 @@ function combineEntries(newEntries, existingEntries) {
) {
const existingEntry = existingEntries[existingEntriesIteratorIndex];
const alreadyHasMatchingEntryInResultSet =
findLastIndexUsingComparinator(
resultSet,
existingEntry,
areEqualEntries
) !== -1;
findLastIndexUsingComparinator(resultSet, existingEntry, areEqualEntries) !==
-1;

if (!alreadyHasMatchingEntryInResultSet) {
resultSet.unshift(existingEntry);
Expand Down
2 changes: 1 addition & 1 deletion src/builder/WebpackConfig.js
Expand Up @@ -129,7 +129,7 @@ class WebpackConfig {
* @param {{app: import("express").Application}} param0
*/
onBeforeSetupMiddleware({ app }) {
app.use(function(req, _, next) {
app.use(function (req, _, next) {
// Something causes hot update chunks (except for the JSON payload)
// to start with a double slash
// e.g. GET http://localhost:8080//js/app.[hash].hot-update.js
Expand Down
2 changes: 1 addition & 1 deletion src/builder/webpack-default.js
@@ -1,7 +1,7 @@
let path = require('path');
let TerserPlugin = require('terser-webpack-plugin');

module.exports = function() {
module.exports = function () {
return {
context: Mix.paths.root(),

Expand Down
2 changes: 1 addition & 1 deletion src/builder/webpack-plugins.js
Expand Up @@ -5,7 +5,7 @@ let ManifestPlugin = require('../webpackPlugins/ManifestPlugin');
let MockEntryPlugin = require('../webpackPlugins/MockEntryPlugin');
let BuildOutputPlugin = require('../webpackPlugins/BuildOutputPlugin');

module.exports = function() {
module.exports = function () {
let plugins = [];

// If the user didn't declare any JS compilation, we still need to
Expand Down
2 changes: 1 addition & 1 deletion src/builder/webpack-rules.js
@@ -1,4 +1,4 @@
module.exports = function() {
module.exports = function () {
let rules = [];

// Add support for loading HTML files.
Expand Down
4 changes: 1 addition & 3 deletions src/components/Autoload.js
Expand Up @@ -10,9 +10,7 @@ class Autoload {

Object.keys(libs).forEach(library => {
[].concat(libs[library]).forEach(alias => {
aliases[alias] = library.includes('.')
? library.split('.')
: library;
aliases[alias] = library.includes('.') ? library.split('.') : library;
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/BrowserSync.js
Expand Up @@ -52,7 +52,7 @@ class BrowserSync {
snippetOptions: {
rule: {
match: this.regex(),
fn: function(snippet, match) {
fn: function (snippet, match) {
return snippet + match;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/DumpWebpackConfig.js
Expand Up @@ -13,7 +13,7 @@ class DumpWebpackConfig {
*/
register() {
Mix.listen('configReadyForUser', config => {
RegExp.prototype.toJSON = function() {
RegExp.prototype.toJSON = function () {
return this.toString();
};

Expand Down
8 changes: 1 addition & 7 deletions src/components/Less.js
Expand Up @@ -17,13 +17,7 @@ class Less extends Preprocessor {
* @param {Array} postCssPlugins
*/
register(src, output, pluginOptions = {}, postCssPlugins = []) {
return this.preprocess(
'less',
src,
output,
pluginOptions,
postCssPlugins
);
return this.preprocess('less', src, output, pluginOptions, postCssPlugins);
}

chunkRegex() {
Expand Down

0 comments on commit 34d5529

Please sign in to comment.