Skip to content

Commit 4633da5

Browse files
authored
Merge pull request #48 from sveltejs/1.60-compatibility
prevent future post-1.60 deprecation warnings
2 parents 69c637d + 97dcefa commit 4633da5

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

index.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ function capitalize(str) {
4848
return str[0].toUpperCase() + str.slice(1);
4949
}
5050

51+
function normalize(compiled) {
52+
// svelte.compile signature changed in 1.60 — this avoids
53+
// future deprecation warnings while preserving backwards
54+
// compatibility
55+
const js = compiled.js || { code: compiled.code, map: compiled.map };
56+
57+
const css = compiled.css && typeof compiled.css === 'object'
58+
? compiled.css
59+
: { code: compiled.css, map: compiled.cssMap };
60+
61+
return { js, css, ast: compiled.ast };
62+
}
63+
5164
module.exports = function(source, map) {
5265
this.cacheable();
5366

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

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

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

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

84-
writeFileSync(tmpFile, css);
97+
writeFileSync(tmpFile, css.code);
8598
const { atime, mtime } = statSync(tmpFile);
8699
utimesSync(tmpFile, new Date(atime.getTime() - 99999), new Date(mtime.getTime() - 99999));
87100
}
88101

89102
if (options.hotReload && !isProduction && !isServer) {
90103
const hotOptions = Object.assign({}, options.hotOptions);
91104
const id = JSON.stringify(relative(process.cwd(), options.filename));
92-
code = makeHot(id, code, hotOptions);
105+
js.code = makeHot(id, js.code, hotOptions);
93106
}
94107

95-
callback(null, code, map);
108+
callback(null, js.code, js.map);
96109
}, err => callback(err)).catch(err => {
97110
// wrap error to provide correct
98111
// context when logging to console

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"mocha": "^3.2.0",
2727
"sinon": "^1.17.6",
2828
"sinon-chai": "^2.8.0",
29-
"svelte": "^1.56.0"
29+
"svelte": "^1.60.0"
3030
},
3131
"peerDependencies": {
3232
"svelte": "^1.44.0"

0 commit comments

Comments
 (0)