Skip to content

Commit 584a961

Browse files
committed
better filename & explose hotApi on makeHot
1 parent fe09a0e commit 584a961

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

lib/make-hot.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const defaultHotOptions = {
3232
absoluteImports: false,
3333
}
3434

35+
const defaultHotApi = 'svelte-hmr/runtime/hot-api-esm.js'
36+
3537
const nativeAdapter = require.resolve(
3638
'../runtime/svelte-native/proxy-adapter-native.js'
3739
)
@@ -148,10 +150,10 @@ const parseCssId = (code, parseHash) => {
148150
}
149151

150152
// meta can be 'import.meta' or 'module'
151-
const createMakeHot = (_hotApi, options) => {
152-
if (typeof _hotApi !== 'string') {
153-
options = _hotApi
154-
_hotApi = null
153+
const createMakeHot = (hotApi = defaultHotApi, options) => {
154+
if (typeof hotApi !== 'string') {
155+
options = hotApi
156+
hotApi = defaultHotApi
155157
}
156158
const { meta = 'import.meta', walk } = options || {}
157159

@@ -171,7 +173,7 @@ const createMakeHot = (_hotApi, options) => {
171173
return accessors
172174
}
173175

174-
return function makeHot(
176+
function makeHot(
175177
id,
176178
compiledCode,
177179
hotOptionsArg,
@@ -181,9 +183,6 @@ const createMakeHot = (_hotApi, options) => {
181183
) {
182184
const hotOptions = Object.assign({}, defaultHotOptions, hotOptionsArg)
183185

184-
const hotApi =
185-
_hotApi || (hotOptions.compatVite && 'svelte-hmr/runtime/esm.js')
186-
187186
const noPreserveState =
188187
hotOptions.noPreserveState ||
189188
(hotOptions.noPreserveStateKey &&
@@ -221,6 +220,11 @@ const createMakeHot = (_hotApi, options) => {
221220

222221
return compiledCode.replace(/(\n?export default ([^;]*);)/, replacement)
223222
}
223+
224+
// rollup-plugin-svelte-hot needs hotApi path (for tests)
225+
makeHot.hotApi = hotApi
226+
227+
return makeHot
224228
}
225229

226230
module.exports = createMakeHot
File renamed without changes.

0 commit comments

Comments
 (0)