Skip to content

Commit

Permalink
Bump prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencookdev committed Jan 23, 2021
1 parent 502488b commit ab9c484
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 107 deletions.
50 changes: 21 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<div><sup><em>(for webpack)</em></sup></div>
</h1>

<a href="https://travis-ci.org/stephencookdev/speed-measure-webpack-plugin"><img src="https://travis-ci.org/stephencookdev/speed-measure-webpack-plugin.svg?branch=master" /></a>
<a href="https://npmjs.com/package/speed-measure-webpack-plugin"><img src="https://img.shields.io/npm/dw/speed-measure-webpack-plugin.svg" /></a>
<a href="https://npmjs.com/package/speed-measure-webpack-plugin"><img src="https://img.shields.io/node/v/speed-measure-webpack-plugin.svg" /></a>
<a href="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/prettier/prettier"><img src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg" /></a>
<a href="https://travis-ci.org/stephencookdev/speed-measure-webpack-plugin"><img src="https://travis-ci.org/stephencookdev/speed-measure-webpack-plugin.svg?branch=master" /></a>
<a href="https://npmjs.com/package/speed-measure-webpack-plugin"><img src="https://img.shields.io/npm/dw/speed-measure-webpack-plugin.svg" /></a>
<a href="https://npmjs.com/package/speed-measure-webpack-plugin"><img src="https://img.shields.io/node/v/speed-measure-webpack-plugin.svg" /></a>
<a href="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/prettier/prettier"><img src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg" /></a>

</div>
<br>

Expand Down Expand Up @@ -40,11 +41,8 @@ Change your webpack config from

```javascript
const webpackConfig = {
plugins: [
new MyPlugin(),
new MyOtherPlugin()
]
}
plugins: [new MyPlugin(), new MyOtherPlugin()],
};
```

to
Expand All @@ -55,10 +53,7 @@ const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
const smp = new SpeedMeasurePlugin();

const webpackConfig = smp.wrap({
plugins: [
new MyPlugin(),
new MyOtherPlugin()
]
plugins: [new MyPlugin(), new MyOtherPlugin()],
});
```

Expand Down Expand Up @@ -90,18 +85,18 @@ Default: `"human"`

Determines in what format this plugin prints its measurements

* `"json"` - produces a JSON blob
* `"human"` - produces a human readable output
* `"humanVerbose"` - produces a more verbose version of the human readable output
* If a function, it will call the function with the JSON blob, and output the response
- `"json"` - produces a JSON blob
- `"human"` - produces a human readable output
- `"humanVerbose"` - produces a more verbose version of the human readable output
- If a function, it will call the function with the JSON blob, and output the response

### `options.outputTarget`

Type: `String|Function`<br>
Default: `console.log`

* If a string, it specifies the path to a file to output to.
* If a function, it will call the function with the output as the first parameter
- If a string, it specifies the path to a file to output to.
- If a function, it will call the function with the output as the first parameter

### `options.pluginNames`

Expand All @@ -116,14 +111,12 @@ takes an object of `pluginName: PluginConstructor`, e.g.
const uglify = new UglifyJSPlugin();
const smp = new SpeedMeasurePlugin({
pluginNames: {
customUglifyName: uglify
}
customUglifyName: uglify,
},
});

const webpackConfig = smp.wrap({
plugins: [
uglify
]
plugins: [uglify],
});
```

Expand All @@ -136,12 +129,11 @@ You can configure SMP to include the files that take the most time per loader, w

```javascript
const smp = new SpeedMeasurePlugin({
outputFormat: 'humanVerbose',
loaderTopFiles: 10
outputFormat: "humanVerbose",
loaderTopFiles: 10,
});
```


### `options.granularLoaderData` _(experimental)_

Type: `Boolean`<br>
Expand All @@ -151,8 +143,8 @@ By default, SMP measures loaders in groups. If truthy, this plugin will give per

This flag is _experimental_. Some loaders will have inaccurate results:

* loaders using separate processes (e.g. `thread-loader`)
* loaders emitting file output (e.g. `file-loader`)
- loaders using separate processes (e.g. `thread-loader`)
- loaders emitting file output (e.g. `file-loader`)

We will find solutions to these issues before removing the _(experimental)_ flag on this option.

Expand Down
2 changes: 1 addition & 1 deletion colours.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ module.exports.fg = (text, time) => {
return textModifier(text);
};

module.exports.bg = text => chalk.bgBlack.green.bold(text);
module.exports.bg = (text) => chalk.bgBlack.green.bold(text);
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ module.exports = class SpeedMeasurePlugin {
if (typeof config === "function")
return (...args) => this.wrap(config(...args));

config.plugins = (config.plugins || []).map(plugin => {
config.plugins = (config.plugins || []).map((plugin) => {
const pluginName =
Object.keys(this.options.pluginNames || {}).find(
pluginName => plugin === this.options.pluginNames[pluginName]
(pluginName) => plugin === this.options.pluginNames[pluginName]
) ||
(plugin.constructor && plugin.constructor.name) ||
"(unable to deduce plugin name)";
Expand All @@ -50,7 +50,7 @@ module.exports = class SpeedMeasurePlugin {

if (config.optimization && config.optimization.minimizer) {
config.optimization.minimizer = config.optimization.minimizer.map(
plugin => {
(plugin) => {
return new WrappedPlugin(plugin, plugin.constructor.name, this);
}
);
Expand Down Expand Up @@ -101,15 +101,15 @@ module.exports = class SpeedMeasurePlugin {
data.start = curTime;
eventList.push(data);
} else if (eventType === "end") {
const matchingEvent = eventList.find(e => {
const matchingEvent = eventList.find((e) => {
const allowOverwrite = !e.end || !data.fillLast;
const idMatch = e.id !== undefined && e.id === data.id;
const nameMatch =
!data.id && e.name !== undefined && e.name === data.name;
return allowOverwrite && (idMatch || nameMatch);
});
const eventToModify =
matchingEvent || (data.fillLast && eventList.find(e => !e.end));
matchingEvent || (data.fillLast && eventList.find((e) => !e.end));
if (!eventToModify) {
console.error(
"Could not find a matching event to end",
Expand Down Expand Up @@ -155,12 +155,12 @@ module.exports = class SpeedMeasurePlugin {
this.timeEventData = {};
});

tap(compiler, "compilation", compilation => {
tap(compilation, "normal-module-loader", loaderContext => {
tap(compiler, "compilation", (compilation) => {
tap(compilation, "normal-module-loader", (loaderContext) => {
loaderContext[NS] = this.provideLoaderTiming;
});

tap(compilation, "build-module", module => {
tap(compilation, "build-module", (module) => {
const name = getModuleName(module);
if (name) {
this.addTimeEvent("loaders", "build", "start", {
Expand All @@ -171,7 +171,7 @@ module.exports = class SpeedMeasurePlugin {
}
});

tap(compilation, "succeed-module", module => {
tap(compilation, "succeed-module", (module) => {
const name = getModuleName(module);
if (name) {
this.addTimeEvent("loaders", "build", "end", {
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
testPathIgnorePatterns: ["__tests__"],
testURL: "https://localhost",
}
};
4 changes: 1 addition & 3 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"lerna": "2.9.0",
"packages": [
"__tests__/setups/*"
],
"packages": ["__tests__/setups/*"],
"version": "0.0.0"
}
16 changes: 8 additions & 8 deletions loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ let id = 0;

const NS = path.dirname(fs.realpathSync(__filename));

const getLoaderName = path => {
const getLoaderName = (path) => {
const standardPath = path.replace(/\\/g, "/");
const nodeModuleName = /\/node_modules\/([^\/]+)/.exec(standardPath);
return (nodeModuleName && nodeModuleName[1]) || "";
};

module.exports.pitch = function() {
module.exports.pitch = function () {
const callback = this[NS];
const module = this.resourcePath;
const loaderPaths = this.loaders
.map(l => l.path)
.filter(l => !l.includes("speed-measure-webpack-plugin"));
.map((l) => l.path)
.filter((l) => !l.includes("speed-measure-webpack-plugin"));

// Hack ourselves to overwrite the `require` method so we can override the
// loadLoaders
hackWrapLoaders(loaderPaths, (loader, path) => {
const loaderName = getLoaderName(path);
const wrapFunc = func =>
function() {
const wrapFunc = (func) =>
function () {
const loaderId = id++;
const almostThis = Object.assign({}, this, {
async: function() {
async: function () {
const asyncCallback = this.async.apply(this, arguments);

return function() {
return function () {
callback({
id: loaderId,
type: "end",
Expand Down
35 changes: 19 additions & 16 deletions migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,38 @@ SMP follows [semver](https://semver.org/). This guide should help with upgrading

### If Using Static Constructor

If you're using the `SpeedMeasurePlugin.wrapPlugins(plugins, options)` static method, then
If you're using the `SpeedMeasurePlugin.wrapPlugins(plugins, options)` static method, then

* remove all `.wrapPlugins` calls
* instantiate an `smp`
* call `smp.wrap` on your entire config
- remove all `.wrapPlugins` calls
- instantiate an `smp`
- call `smp.wrap` on your entire config

e.g.

```javascript
// v0
const webpackConfig = {
plugins: SpeedMeasurePlugin.wrapPlugins({
FooPlugin: new FooPlugin()
}, smpOptions)
plugins: SpeedMeasurePlugin.wrapPlugins(
{
FooPlugin: new FooPlugin(),
},
smpOptions
),
};

// v1
const smp = new SpeedMeasurePlugin(smpOptions);
const webpackConfig = smp.wrap({
plugins: [new FooPlugin()]
plugins: [new FooPlugin()],
});
```

### If Using `smp` Instance

If you're using the `smp.wrapPlugins(plugins)` method, then

* remove all `.wrapPlugins` calls
* call `smp.wrap` on your entire config
- remove all `.wrapPlugins` calls
- call `smp.wrap` on your entire config

e.g.

Expand All @@ -43,14 +46,14 @@ e.g.
const smp = new SpeedMeasurePlugin(smpOptions);
const webpackConfig = {
plugins: smp.wrapPlugins({
FooPlugin: new FooPlugin()
})
FooPlugin: new FooPlugin(),
}),
};

// v1
const smp = new SpeedMeasurePlugin(smpOptions);
const webpackConfig = smp.wrap({
plugins: [new FooPlugin()]
plugins: [new FooPlugin()],
});
```

Expand All @@ -62,10 +65,10 @@ v1 no longer requires you to manually enter each plugin name. If you want to kee
const fooPlugin = new FooPlugin();
const smp = new SpeedMeasurePlugin({
pluginNames: {
customFooPluginName: fooPlugin
}
customFooPluginName: fooPlugin,
},
});
const webpackConfig = smp.wrap({
plugins: [fooPlugin]
plugins: [fooPlugin],
});
```
2 changes: 1 addition & 1 deletion neutrino.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const SpeedMeasurePlugin = require(".");
const smp = new SpeedMeasurePlugin();

module.exports = neutrino => {
module.exports = (neutrino) => {
const origConfig = neutrino.config;
const wrappedConfig = smp.wrap(origConfig.toConfig());
neutrino.config = new Proxy(origConfig, {
Expand Down
Loading

0 comments on commit ab9c484

Please sign in to comment.