Skip to content

Commit

Permalink
upgrade svelte-hmr (preservation of local state, reactive blocks, acc…
Browse files Browse the repository at this point in the history
…essors, & named exports)
  • Loading branch information
rixo committed Feb 27, 2020
1 parent 472668f commit 0c1ccaa
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ module.exports = function(source, map) {
if (options.hotReload && !isProduction && !isServer) {
const hotOptions = Object.assign({}, options.hotOptions);
const id = JSON.stringify(relative(process.cwd(), compileOptions.filename));
js.code = makeHot(id, js.code, hotOptions, compiled);
js.code = makeHot(id, js.code, hotOptions, compiled, source, compileOptions);
}

if (options.emitCss && css.code) {
Expand Down
14 changes: 8 additions & 6 deletions lib/resolve-svelte.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ const { version } = req(`${base}/package.json`);

const major_version = +version[0];

const { compile, preprocess } =
major_version >= 3 ? req(`${base}/compiler`) : req(`${base}`);

const makeHot =
major_version >= 3 ? require('./svelte3/make-hot') : require('./make-hot');
const { compile, preprocess, walk } =
major_version >= 3 ? req(`${base}/compiler`) : req(`${base}`);

module.exports = {
major_version,
compile,
preprocess,
makeHot,
walk,
};

// NOTE svelte3/make-hot requires this module to get the walk function, so we
// need to have walk available on module.exports before requiring it from here
module.exports.makeHot =
major_version >= 3 ? require('./svelte3/make-hot') : require('./make-hot');
2 changes: 2 additions & 0 deletions lib/svelte3/make-hot.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const { walk } = require('../resolve-svelte');
const { createMakeHot } = require('svelte-hmr');

const hotApi = require.resolve('./hot-api.js');

const makeHot = createMakeHot(hotApi, {
meta: 'module',
walk,
});

module.exports = makeHot;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dependencies": {
"loader-utils": "^1.1.0",
"svelte-dev-helper": "^1.1.9",
"svelte-hmr": "^0.1.4"
"svelte-hmr": "^0.3.1"
},
"devDependencies": {
"chai": "^4.1.2",
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,9 @@ svelte-dev-helper@^1.1.9:
version "1.1.9"
resolved "https://registry.yarnpkg.com/svelte-dev-helper/-/svelte-dev-helper-1.1.9.tgz#7d187db5c6cdbbd64d75a32f91b8998bde3273c3"

svelte-hmr@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/svelte-hmr/-/svelte-hmr-0.1.4.tgz#dfcdfe7ef8099c832e43794c362c86dbab62f01f"
svelte-hmr@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/svelte-hmr/-/svelte-hmr-0.3.1.tgz#a4092afe0e0b993869dbaaabac5722ef9e2967db"

svelte@3.12:
version "3.12.1"
Expand Down

0 comments on commit 0c1ccaa

Please sign in to comment.