Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

Commit

Permalink
refactor: rename the name option (#261)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the `name` option was renamed to the `filename` option
  • Loading branch information
evilebottnawi authored Jul 28, 2020
1 parent e0d9887 commit 8d7cae0
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 31 deletions.
15 changes: 6 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,19 @@ FetchCompileWasmPlugin =
export default function loader() {}

export function pitch(request) {
this.cacheable(false);

const options = loaderUtils.getOptions(this);

validateOptions(schema, options, {
name: 'Worker Loader',
baseDataPath: 'options',
});

this.cacheable(false);

const cb = this.async();

const filename = loaderUtils.interpolateName(
this,
options.name || '[hash].worker.js',
{
context: options.context || this.rootContext || this.options.context,
regExp: options.regExp,
}
options.filename || '[hash].worker.js',
{ context: this.rootContext }
);

const worker = {};
Expand Down Expand Up @@ -91,6 +86,8 @@ export function pitch(request) {
worker.compiler
);

const cb = this.async();

if (
worker.compiler.cache &&
typeof worker.compiler.cache.get === 'function'
Expand Down
9 changes: 5 additions & 4 deletions src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
}
]
},
"name": {
"filename": {
"type": "string",
"minLength": 1
},
"publicPath": {
"type": "string"
},
"inline": {
Expand All @@ -33,9 +37,6 @@
"fallback": {
"type": "boolean"
},
"publicPath": {
"type": "string"
},
"esModule": {
"type": "boolean"
}
Expand Down
14 changes: 14 additions & 0 deletions test/__snapshots__/filename-options.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`"filename" option should work: errors 1`] = `Array []`;

exports[`"filename" option should work: module 1`] = `
"export default function() {
return new Worker(__webpack_public_path__ + \\"my-custom-name.js\\");
};
"
`;

exports[`"filename" option should work: result 1`] = `"{\\"postMessage\\":true,\\"onmessage\\":true}"`;

exports[`"filename" option should work: warnings 1`] = `Array []`;
14 changes: 0 additions & 14 deletions test/__snapshots__/name-options.test.js.snap

This file was deleted.

4 changes: 2 additions & 2 deletions test/name-options.test.js → test/filename-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
getWarnings,
} from './helpers';

describe('"name" option', () => {
describe('"filename" option', () => {
it('should work', async () => {
const compiler = getCompiler('./basic/entry.js', {
name: 'my-custom-name.js',
filename: 'my-custom-name.js',
});
const stats = await compile(compiler);
const result = await getResultFromBrowser(stats);
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/query/entry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Worker from '!../../../src?name=test.worker.js!./my-worker-name.js';
import Worker from '!../../../src?filename=test.worker.js!./my-worker-name.js';

const worker = new Worker();

Expand Down
2 changes: 1 addition & 1 deletion test/helpers/getCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default (fixture, loaderOptions = {}, config = {}) => {
rules: [
{
loader: path.resolve(__dirname, '../../src'),
options: { name: 'test.worker.js', ...loaderOptions },
options: { filename: 'test.worker.js', ...loaderOptions },
},
],
},
Expand Down

0 comments on commit 8d7cae0

Please sign in to comment.