Skip to content

Commit 0b4926b

Browse files
committed
minor #159 Replace "resolve_url_loader" by "resolveUrlLoader" (Lyrkan)
This PR was squashed before being merged into the master branch (closes #159). Discussion ---------- Replace "resolve_url_loader" by "resolveUrlLoader" This PR deprecates the `resolve_url_loader` option used by the `enableSassLoader` and replaces it by `resolveUrlLoader`. This is done to be consistent with other methods that use camel-case instead of snake-case (see [#152](#152 (comment))). `resolve_url_loader` will still work for now but will display the following deprecation message: ![2017-09-13_23-38-56](https://user-images.githubusercontent.com/850046/30402523-4c736d86-98de-11e7-97c1-81a216912fb7.png) Commits ------- ff442a6 Add a logger.deprecation(message) method 9dac153 Replace sass option 'resolve_url_loader' by 'resolveUrlLoader'
2 parents 2e216a4 + ff442a6 commit 0b4926b

File tree

7 files changed

+29
-14
lines changed

7 files changed

+29
-14
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,11 @@ const publicApi = {
429429
* // options.includePaths = [...]
430430
* }, {
431431
* // set optional Encore-specific options
432-
* // resolve_url_loader: true
432+
* // resolveUrlLoader: true
433433
* });
434434
*
435435
* Supported options:
436-
* * {bool} resolve_url_loader (default=true)
436+
* * {bool} resolveUrlLoader (default=true)
437437
* Whether or not to use the resolve-url-loader.
438438
* Setting to false can increase performance in some
439439
* cases, especially when using bootstrap_sass. But,

lib/WebpackConfig.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ class WebpackConfig {
5757
this.useSassLoader = false;
5858
this.useReact = false;
5959
this.usePreact = false;
60-
this.preactOptions = {
61-
preactCompat: false
62-
};
6360
this.useVueLoader = false;
6461
this.useTypeScriptLoader = false;
6562
this.useForkedTypeScriptTypeChecking = false;
6663

6764
// Features/Loaders options
6865
this.sassOptions = {
69-
resolve_url_loader: true
66+
resolveUrlLoader: true
67+
};
68+
this.preactOptions = {
69+
preactCompat: false
7070
};
7171

7272
// Features/Loaders options callbacks
@@ -311,11 +311,17 @@ class WebpackConfig {
311311
this.sassLoaderOptionsCallback = sassLoaderOptionsCallback;
312312

313313
for (const optionKey of Object.keys(options)) {
314-
if (!(optionKey in this.sassOptions)) {
315-
throw new Error(`Invalid option "${optionKey}" passed to enableSassLoader(). Valid keys are ${Object.keys(this.sassOptions).join(', ')}`);
314+
let normalizedOptionKey = optionKey;
315+
if (optionKey === 'resolve_url_loader') {
316+
logger.deprecation('enableSassLoader: "resolve_url_loader" is deprecated. Please use "resolveUrlLoader" instead.');
317+
normalizedOptionKey = 'resolveUrlLoader';
318+
}
319+
320+
if (!(normalizedOptionKey in this.sassOptions)) {
321+
throw new Error(`Invalid option "${normalizedOptionKey}" passed to enableSassLoader(). Valid keys are ${Object.keys(this.sassOptions).join(', ')}`);
316322
}
317323

318-
this.sassOptions[optionKey] = options[optionKey];
324+
this.sassOptions[normalizedOptionKey] = options[optionKey];
319325
}
320326
}
321327

lib/loaders/sass.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = {
2323
loaderFeatures.ensurePackagesExist('sass');
2424

2525
const sassLoaders = [...cssLoader.getLoaders(webpackConfig, ignorePostCssLoader)];
26-
if (true === webpackConfig.sassOptions.resolve_url_loader) {
26+
if (true === webpackConfig.sassOptions.resolveUrlLoader) {
2727
// responsible for resolving SASS url() paths
2828
// without this, all url() paths must be relative to the
2929
// entry file, not the file that contains the url()
@@ -37,7 +37,7 @@ module.exports = {
3737

3838
let config = Object.assign({}, sassOptions, {
3939
// needed by the resolve-url-loader
40-
sourceMap: (true === webpackConfig.sassOptions.resolve_url_loader) || webpackConfig.useSourceMaps
40+
sourceMap: (true === webpackConfig.sassOptions.resolveUrlLoader) || webpackConfig.useSourceMaps
4141
});
4242

4343
// allow options to be configured

lib/logger.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const messagesKeys = [
1515
'debug',
1616
'recommendation',
1717
'warning',
18+
'deprecation',
1819
];
1920
const defaultConfig = {
2021
isVerbose: false,
@@ -62,6 +63,12 @@ module.exports = {
6263
log(`${chalk.bgYellow.black(' WARNING ')} ${chalk.yellow(message)}`);
6364
},
6465

66+
deprecation(message) {
67+
messages.deprecation.push(message);
68+
69+
log(`${chalk.bgYellow.black('DEPRECATION')} ${chalk.yellow(message)}`);
70+
},
71+
6572
getMessages() {
6673
return messages;
6774
},

test/WebpackConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,10 @@ describe('WebpackConfig object', () => {
471471

472472
it('Pass valid config', () => {
473473
const config = createConfig();
474-
config.enableSassLoader(() => {}, { resolve_url_loader: false });
474+
config.enableSassLoader(() => {}, { resolveUrlLoader: false });
475475

476476
expect(config.useSassLoader).to.be.true;
477-
expect(config.sassOptions.resolve_url_loader).to.be.false;
477+
expect(config.sassOptions.resolveUrlLoader).to.be.false;
478478
});
479479

480480
it('Pass invalid config', () => {

test/loaders/sass.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('loaders/sass', () => {
6767
it('getLoaders() without resolve-url-loader', () => {
6868
const config = createConfig();
6969
config.enableSassLoader(() => {}, {
70-
resolve_url_loader: false,
70+
resolveUrlLoader: false,
7171
});
7272
config.enableSourceMaps(false);
7373

test/logger.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ describe('logger', () => {
2828
'debug',
2929
'recommendation',
3030
'warning',
31+
'deprecation',
3132
];
3233
const testString = 'TEST MESSAGE';
3334
const expectedMessages = {
3435
debug: [testString],
3536
recommendation: [testString],
3637
warning: [testString],
38+
deprecation: [testString],
3739
};
3840

3941
logger.quiet();

0 commit comments

Comments
 (0)