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

prevent future post-1.60 deprecation warnings #48

Merged
merged 2 commits into from
Apr 2, 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
27 changes: 20 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ function capitalize(str) {
return str[0].toUpperCase() + str.slice(1);
}

function normalize(compiled) {
// svelte.compile signature changed in 1.60 — this avoids
// future deprecation warnings while preserving backwards
// compatibility
const js = compiled.js || { code: compiled.code, map: compiled.map };

const css = compiled.css && typeof compiled.css === 'object'
? compiled.css
: { code: compiled.css, map: compiled.cssMap };

return { js, css, ast: compiled.ast };
}

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

Expand All @@ -72,27 +85,27 @@ module.exports = function(source, map) {
if (!options.onwarn) options.onwarn = warning => this.emitWarning(new Error(warning));

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

if (options.emitCss && css) {
if (options.emitCss && css.code) {
const posixTmpdir = posixify(tmpdir());
const tmpFile = posix.join(posixTmpdir, 'svelte-' + ast.hash + '.css');

css += '\n/*# sourceMappingURL=' + cssMap.toUrl() + '*/';
code = code + `\nrequire('${tmpFile}');\n`;
css.code += '\n/*# sourceMappingURL=' + css.map.toUrl() + '*/';
js.code = js.code + `\nrequire('${tmpFile}');\n`;

writeFileSync(tmpFile, css);
writeFileSync(tmpFile, css.code);
const { atime, mtime } = statSync(tmpFile);
utimesSync(tmpFile, new Date(atime.getTime() - 99999), new Date(mtime.getTime() - 99999));
}

if (options.hotReload && !isProduction && !isServer) {
const hotOptions = Object.assign({}, options.hotOptions);
const id = JSON.stringify(relative(process.cwd(), options.filename));
code = makeHot(id, code, hotOptions);
js.code = makeHot(id, js.code, hotOptions);
}

callback(null, code, map);
callback(null, js.code, js.map);
}, err => callback(err)).catch(err => {
// wrap error to provide correct
// context when logging to console
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"mocha": "^3.2.0",
"sinon": "^1.17.6",
"sinon-chai": "^2.8.0",
"svelte": "^1.56.0"
"svelte": "^1.60.0"
},
"peerDependencies": {
"svelte": "^1.44.0"
Expand Down