Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate options.style etc #51

Merged
merged 1 commit into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ function normalize(compiled) {
return { js, css, ast: compiled.ast };
}

const warned = {};
function deprecatePreprocessOptions(options) {
const preprocessOptions = {};

['markup', 'style', 'script'].forEach(kind => {
if (options[kind]) {
if (!warned[kind]) {
console.warn(`[svelte-loader] DEPRECATION: options.${kind} is now options.preprocess.${kind}`);
warned[kind] = true;
}
preprocessOptions[kind] = options[kind];
}
});

options.preprocess = options.preprocess || preprocessOptions;
}

module.exports = function(source, map) {
this.cacheable();

Expand All @@ -86,7 +103,10 @@ module.exports = function(source, map) {

if (!options.onwarn) options.onwarn = warning => this.emitWarning(new Error(warning));

preprocess(source, options).then(processed => {
deprecatePreprocessOptions(options);
options.preprocess.filename = options.filename;

preprocess(source, options.preprocess).then(processed => {
let { js, css, ast } = normalize(compile(processed.toString(), options));

if (options.emitCss && css.code) {
Expand Down
44 changes: 37 additions & 7 deletions test/loader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,12 @@ describe('loader', () => {
});
const callbackSpy = spy(cb);
const options = {
style: ({ content }) => {
return {
code: content.replace(/\$size/gi, '50px'),
};
preprocess: {
style: ({ content }) => {
return {
code: content.replace(/\$size/gi, '50px'),
};
}
},
};

Expand All @@ -321,9 +323,11 @@ describe('loader', () => {
const cacheableSpy = spy(() => {
});
const options = {
style: () => {
throw new Error('Error while preprocessing');
},
preprocess: {
style: () => {
throw new Error('Error while preprocessing');
}
}
};

loader.call(
Expand All @@ -342,6 +346,32 @@ describe('loader', () => {
});
});


describe('deprecations', () => {
it('should warn on options.style', done => {
const { warn } = console;
const warnings = [];

console.warn = (msg) => {
warnings.push(msg);
};

testLoader('test/fixtures/style-valid.html', (err, code, map) => {
expect(code).to.contain('50px');
expect(warnings).to.deep.equal([
'[svelte-loader] DEPRECATION: options.style is now options.preprocess.style'
]);
console.warn = warn;
}, {
style: ({ content }) => {
return {
code: content.replace(/\$size/gi, '50px'),
};
}
})(done);
});
});

describe('hotReload', () => {
it(
'should configure hotReload=false (default)',
Expand Down