ember-vite-hmr 2.0.6 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/instance-initializers/setup-hmr-manager.js +19 -4
- package/dist/instance-initializers/setup-hmr-manager.js.map +1 -1
- package/dist/instance-initializers/vite-hot-reload.js +8 -6
- package/dist/instance-initializers/vite-hot-reload.js.map +1 -1
- package/dist/lib/babel-plugin.d.ts +6 -4
- package/dist/lib/babel-plugin.js +199 -64
- package/dist/lib/hmr.js +26 -16
- package/dist/services/vite-hot-reload.js +9 -4
- package/dist/services/vite-hot-reload.js.map +1 -1
- package/dist/setup-ember-hmr.js +3 -5
- package/dist/setup-ember-hmr.js.map +1 -1
- package/package.json +13 -9
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Route from '@ember/routing/route';
|
|
2
|
+
import Service from '@ember/service';
|
|
2
3
|
import Component from '@glimmer/component';
|
|
3
4
|
import { getInternalComponentManager } from '@glimmer/manager';
|
|
4
5
|
|
|
@@ -18,6 +19,17 @@ function getState(component, skip) {
|
|
|
18
19
|
for (const key in component) {
|
|
19
20
|
if (skip.includes(key)) continue;
|
|
20
21
|
const entry = findPropertyDescriptor(component, key);
|
|
22
|
+
const value = component[key];
|
|
23
|
+
|
|
24
|
+
// Skip Service instances - they should not be synced
|
|
25
|
+
if (value instanceof Service) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Skip Function properties - they should not be synced
|
|
30
|
+
if (typeof value === 'function') {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
21
33
|
if (entry) {
|
|
22
34
|
if (entry.writable && !Object.prototype.toString.call(entry.value).includes('Function')) {
|
|
23
35
|
state[key] = component[key];
|
|
@@ -30,12 +42,16 @@ function getState(component, skip) {
|
|
|
30
42
|
return state;
|
|
31
43
|
}
|
|
32
44
|
function syncState(instance) {
|
|
33
|
-
|
|
34
|
-
|
|
45
|
+
const args = instance.args;
|
|
46
|
+
if (args.__hot__) {
|
|
47
|
+
const state = instance.__get_hot_state__?.() || args.__hot__.getState?.();
|
|
35
48
|
for (const k in state) {
|
|
49
|
+
if (instance[k] instanceof Service) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
36
52
|
instance[k] = state[k];
|
|
37
53
|
}
|
|
38
|
-
|
|
54
|
+
args.__hot__.getState = () => getState(instance, ['args']);
|
|
39
55
|
}
|
|
40
56
|
}
|
|
41
57
|
function initialize() {
|
|
@@ -51,7 +67,6 @@ function initialize() {
|
|
|
51
67
|
const StateCache = {};
|
|
52
68
|
Route.prototype.setupController = function (...args) {
|
|
53
69
|
const controller = args[0];
|
|
54
|
-
// @ts-ignore
|
|
55
70
|
const r = setupController.call(this, ...args);
|
|
56
71
|
const fullRouteName = this.fullRouteName;
|
|
57
72
|
const state = StateCache[fullRouteName] || {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-hmr-manager.js","sources":["../../src/instance-initializers/setup-hmr-manager.ts"],"sourcesContent":["import Route from '@ember/routing/route';\nimport
|
|
1
|
+
{"version":3,"file":"setup-hmr-manager.js","sources":["../../src/instance-initializers/setup-hmr-manager.ts"],"sourcesContent":["import Route from '@ember/routing/route';\nimport Service from '@ember/service';\nimport Component from '@glimmer/component';\nimport { getInternalComponentManager } from '@glimmer/manager';\n\ninterface HotComponent extends Component<{ __hot__?: unknown }> {\n __get_hot_state__?: () => Record<string, unknown>;\n [key: string]: unknown;\n}\n\ntype Mutable<T> = {\n -readonly [P in keyof T]: unknown;\n};\n\nfunction findPropertyDescriptor(\n component: HotComponent | Record<string, unknown>,\n key: string,\n) {\n let proto = component;\n while (proto) {\n const desc = Object.getOwnPropertyDescriptor(proto, key);\n if (desc) return desc;\n proto = Object.getPrototypeOf(proto);\n }\n}\n\nfunction getState(component: HotComponent, skip: string[]) {\n const state: Record<string, unknown> = {};\n if (!component) {\n return state;\n }\n for (const key in component) {\n if (skip.includes(key)) continue;\n const entry = findPropertyDescriptor(component, key);\n const value = component[key as keyof Component];\n \n // Skip Service instances - they should not be synced\n if (value instanceof Service) {\n continue;\n }\n \n // Skip Function properties - they should not be synced\n if (typeof value === 'function') {\n continue;\n }\n \n if (entry) {\n if (\n entry.writable &&\n !Object.prototype.toString.call(entry.value).includes('Function')\n ) {\n state[key] = component[key as keyof Component];\n }\n if (entry.set) {\n state[key] = component[key as keyof Component];\n }\n }\n }\n return state;\n}\n\nfunction syncState(instance: Mutable<HotComponent>) {\n const args = instance.args as { __hot__?: { getState?: () => Record<string, unknown> } };\n if (args.__hot__) {\n const state =\n (instance.__get_hot_state__ as (() => Record<string, unknown>) | undefined)?.() || args.__hot__.getState?.();\n for (const k in state) {\n if (instance[k as keyof HotComponent] instanceof Service) {\n continue;\n }\n instance[k as keyof HotComponent] = state[k];\n }\n args.__hot__.getState = () => getState(instance as HotComponent, ['args']);\n }\n}\n\nexport function initialize() {\n const ComponentManager = getInternalComponentManager(Component);\n const proto = Object.getPrototypeOf(ComponentManager);\n const create = proto.create;\n proto.create = function (...args: unknown[]) {\n const instance = create.call(this, ...args);\n syncState(instance.component);\n return instance;\n };\n\n const setupController = Route.prototype.setupController;\n\n const StateCache: Record<string, unknown> = {};\n\n Route.prototype.setupController = function (...args: Parameters<typeof setupController>) {\n const controller = args[0] as unknown as Record<string, unknown>;\n const r = setupController.call(this, ...args);\n const fullRouteName = this.fullRouteName;\n const state = StateCache[fullRouteName] as { router?: Record<string, unknown>; controller?: Record<string, unknown> } || {};\n const skip = ['_qpDelegate', 'target', 'queryParams'];\n const routerState = getState(state.router as HotComponent, skip);\n const controllerState = getState(state.controller as HotComponent, skip);\n for (const k in routerState) {\n (this as unknown as Record<string, unknown>)[k] = routerState[k];\n }\n for (const k in controllerState) {\n (controller as Record<string, unknown>)[k] = controllerState[k];\n }\n StateCache[fullRouteName] = {\n route: this,\n controller,\n };\n return r;\n };\n}\n\nexport default {\n initialize,\n};\n"],"names":["findPropertyDescriptor","component","key","proto","desc","Object","getOwnPropertyDescriptor","getPrototypeOf","getState","skip","state","includes","entry","value","Service","writable","prototype","toString","call","set","syncState","instance","args","__hot__","__get_hot_state__","k","initialize","ComponentManager","getInternalComponentManager","Component","create","setupController","Route","StateCache","controller","r","fullRouteName","routerState","router","controllerState","route"],"mappings":";;;;;AAcA,SAASA,sBAAsBA,CAC7BC,SAAiD,EACjDC,GAAW,EACX;EACA,IAAIC,KAAK,GAAGF,SAAS;AACrB,EAAA,OAAOE,KAAK,EAAE;IACZ,MAAMC,IAAI,GAAGC,MAAM,CAACC,wBAAwB,CAACH,KAAK,EAAED,GAAG,CAAC;IACxD,IAAIE,IAAI,EAAE,OAAOA,IAAI;AACrBD,IAAAA,KAAK,GAAGE,MAAM,CAACE,cAAc,CAACJ,KAAK,CAAC;AACtC,EAAA;AACF;AAEA,SAASK,QAAQA,CAACP,SAAuB,EAAEQ,IAAc,EAAE;EACzD,MAAMC,KAA8B,GAAG,EAAE;EACzC,IAAI,CAACT,SAAS,EAAE;AACd,IAAA,OAAOS,KAAK;AACd,EAAA;AACA,EAAA,KAAK,MAAMR,GAAG,IAAID,SAAS,EAAE;AAC3B,IAAA,IAAIQ,IAAI,CAACE,QAAQ,CAACT,GAAG,CAAC,EAAE;AACxB,IAAA,MAAMU,KAAK,GAAGZ,sBAAsB,CAACC,SAAS,EAAEC,GAAG,CAAC;AACpD,IAAA,MAAMW,KAAK,GAAGZ,SAAS,CAACC,GAAG,CAAoB;;AAE/C;IACA,IAAIW,KAAK,YAAYC,OAAO,EAAE;AAC5B,MAAA;AACF,IAAA;;AAEA;AACA,IAAA,IAAI,OAAOD,KAAK,KAAK,UAAU,EAAE;AAC/B,MAAA;AACF,IAAA;AAEA,IAAA,IAAID,KAAK,EAAE;MACT,IACEA,KAAK,CAACG,QAAQ,IACd,CAACV,MAAM,CAACW,SAAS,CAACC,QAAQ,CAACC,IAAI,CAACN,KAAK,CAACC,KAAK,CAAC,CAACF,QAAQ,CAAC,UAAU,CAAC,EACjE;AACA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5
|
function patchResolver(application) {
|
|
6
6
|
application.__container__.lookup('service:vite-hot-reload');
|
|
7
7
|
const resolver = application.__registry__.resolver?._fallback || (application.__registry__.fallback?.resolver)._fallback || application.__registry__.fallback?.resolver || application.__registry__.resolver;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
if (!resolver) return;
|
|
9
|
+
const resolverWithResolve = resolver;
|
|
10
|
+
const resolverResolve = resolverWithResolve.resolve;
|
|
11
|
+
resolverWithResolve.resolve = function (name) {
|
|
10
12
|
name = name.replace(/--hot-version--.*$/, '');
|
|
11
13
|
return resolverResolve.call(this, name);
|
|
12
14
|
};
|
|
@@ -15,13 +17,13 @@ function supportErrorRecovery(appInstance) {
|
|
|
15
17
|
const bodyHtml = globalThis.document.body.cloneNode(true);
|
|
16
18
|
const renderer = appInstance.__container__.lookup('renderer:-dom');
|
|
17
19
|
const router = appInstance.__container__.lookup('service:router');
|
|
18
|
-
const warn = console.warn;
|
|
20
|
+
const warn = globalThis.console.warn;
|
|
19
21
|
let scheduleRerender = false;
|
|
20
22
|
async function rerender() {
|
|
21
23
|
if (!scheduleRerender) return;
|
|
22
24
|
scheduleRerender = false;
|
|
23
25
|
const applicationRouter = appInstance.__container__.lookup('route:application');
|
|
24
|
-
applicationRouter._router._toplevelView
|
|
26
|
+
applicationRouter._router._toplevelView?.destroy();
|
|
25
27
|
applicationRouter._router._toplevelView = null;
|
|
26
28
|
renderer._clearAllRoots();
|
|
27
29
|
globalThis.document.body = bodyHtml.cloneNode(true);
|
|
@@ -33,11 +35,11 @@ function supportErrorRecovery(appInstance) {
|
|
|
33
35
|
if (import.meta.hot) {
|
|
34
36
|
import.meta.hot.on('vite:beforeUpdate', () => debounce(rerender, 100));
|
|
35
37
|
}
|
|
36
|
-
console.warn = function (...args) {
|
|
38
|
+
globalThis.console.warn = function (...args) {
|
|
37
39
|
if (args[0].includes('Attempted to rerender, but the Ember application has had an unrecoverable error occur during render. You should reload the application after fixing the cause of the error.')) {
|
|
38
40
|
scheduleRerender = true;
|
|
39
41
|
}
|
|
40
|
-
warn.call(console, ...args);
|
|
42
|
+
warn.call(globalThis.console, ...args);
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
45
|
function initialize(application) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-hot-reload.js","sources":["../../src/instance-initializers/vite-hot-reload.ts"],"sourcesContent":["/// <reference types=\"../../types/global\" />\n\nimport ApplicationInstance from '@ember/application/instance';\nimport { debounce, next } from '@ember/runloop';\nimport RouterService from '@ember/routing/router-service';\nimport { Renderer } from '@ember/-internals/glimmer/lib/renderer';\n\nfunction patchResolver(application: ApplicationInstance) {\n application.__container__.lookup('service:vite-hot-reload');\n const resolver =\n (application.__registry__.resolver as
|
|
1
|
+
{"version":3,"file":"vite-hot-reload.js","sources":["../../src/instance-initializers/vite-hot-reload.ts"],"sourcesContent":["/// <reference types=\"../../types/global\" />\n\nimport ApplicationInstance from '@ember/application/instance';\nimport { debounce, next } from '@ember/runloop';\nimport RouterService from '@ember/routing/router-service';\nimport { Renderer } from '@ember/-internals/glimmer/lib/renderer';\n\nfunction patchResolver(application: ApplicationInstance) {\n application.__container__.lookup('service:vite-hot-reload');\n const resolver =\n (application.__registry__.resolver as { _fallback?: unknown })?._fallback ||\n (application.__registry__.fallback?.resolver as { _fallback?: unknown })\n ._fallback ||\n (application.__registry__.fallback?.resolver as unknown) ||\n application.__registry__.resolver;\n \n if (!resolver) return;\n \n const resolverWithResolve = resolver as { resolve: (name: string) => unknown };\n const resolverResolve = resolverWithResolve.resolve;\n resolverWithResolve.resolve = function (name: string) {\n name = name.replace(/--hot-version--.*$/, '');\n return resolverResolve.call(this, name);\n };\n}\n\nfunction supportErrorRecovery(appInstance: ApplicationInstance) {\n const bodyHtml = globalThis.document.body.cloneNode(true);\n const renderer = appInstance.__container__.lookup(\n 'renderer:-dom',\n ) as Renderer;\n const router = appInstance.__container__.lookup(\n 'service:router',\n ) as RouterService;\n const warn = globalThis.console.warn;\n let scheduleRerender = false;\n async function rerender() {\n if (!scheduleRerender) return;\n scheduleRerender = false;\n const applicationRouter = appInstance.__container__.lookup(\n 'route:application',\n ) as {\n _router: { _toplevelView: { destroy: () => void } | null };\n context: unknown;\n setup: (context: unknown, transition: unknown) => void;\n };\n applicationRouter._router._toplevelView?.destroy();\n applicationRouter._router._toplevelView = null;\n (renderer as unknown as { _clearAllRoots: () => void })._clearAllRoots();\n globalThis.document.body = bodyHtml.cloneNode(true) as HTMLBodyElement;\n next(() => {\n const transition = router.refresh();\n applicationRouter.setup(applicationRouter.context, transition);\n });\n }\n if (import.meta.hot) {\n import.meta.hot.on('vite:beforeUpdate', () => debounce(rerender, 100));\n }\n globalThis.console.warn = function (...args) {\n if (\n args[0].includes(\n 'Attempted to rerender, but the Ember application has had an unrecoverable error occur during render. You should reload the application after fixing the cause of the error.',\n )\n ) {\n scheduleRerender = true;\n }\n warn.call(globalThis.console, ...args);\n };\n}\n\nexport function initialize(application: ApplicationInstance) {\n patchResolver(application);\n supportErrorRecovery(application);\n}\n\nexport default {\n initialize,\n};\n"],"names":["patchResolver","application","__container__","lookup","resolver","__registry__","_fallback","fallback","resolverWithResolve","resolverResolve","resolve","name","replace","call","supportErrorRecovery","appInstance","bodyHtml","globalThis","document","body","cloneNode","renderer","router","warn","console","scheduleRerender","rerender","applicationRouter","_router","_toplevelView","destroy","_clearAllRoots","next","transition","refresh","setup","context","import","meta","hot","on","debounce","args","includes","initialize"],"mappings":";;AAAA;;AAOA,SAASA,aAAaA,CAACC,WAAgC,EAAE;AACvDA,EAAAA,WAAW,CAACC,aAAa,CAACC,MAAM,CAAC,yBAAyB,CAAC;AAC3D,EAAA,MAAMC,QAAQ,GACXH,WAAW,CAACI,YAAY,CAACD,QAAQ,EAA8BE,SAAS,IACzE,CAACL,WAAW,CAACI,YAAY,CAACE,QAAQ,EAAEH,QAAQ,EACzCE,SAAS,IACXL,WAAW,CAACI,YAAY,CAACE,QAAQ,EAAEH,QAAoB,IACxDH,W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X,MAAM,CAACY,OAAO,EAAE;MACnCP,iBAAiB,CAACQ,KAAK,CAACR,iBAAiB,CAACS,OAAO,EAAEH,UAAU,CAAC;AAChE,IAAA,CAAC,CAAC;AACJ,EAAA;AACA,EAAA,IAAII,MAAM,CAACC,IAAI,CAACC,GAAG,EAAE;AACnBF,IAAAA,MAAM,CAACC,IAAI,CAACC,GAAG,CAACC,EAAE,CAAC,mBAAmB,EAAE,MAAMC,QAAQ,CAACf,QAAQ,EAAE,GAAG,CAAC,CAAC;AACxE,EAAA;EACAT,UAAU,CAACO,OAAO,CAACD,IAAI,GAAG,UAAU,GAAGmB,IAAI,EAAE;IAC3C,IACEA,IAAI,CAAC,CAAC,CAAC,CAACC,QAAQ,CACd,6KACF,CAAC,EACD;AACAlB,MAAAA,gBAAgB,GAAG,IAAI;AACzB,IAAA;IACAF,IAAI,CAACV,IAAI,CAACI,UAAU,CAACO,OAAO,EAAE,GAAGkB,IAAI,CAAC;EACxC,CAAC;AACH;AAEO,SAASE,UAAUA,CAAC3C,WAAgC,EAAE;EAC3DD,aAAa,CAACC,WAAW,CAAC;EAC1Ba,oBAAoB,CAACb,WAAW,CAAC;AACnC;AAEA,oBAAe;AACb2C,EAAAA;AACF,CAAC;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginObj } from '@babel/core';
|
|
2
2
|
import { Program } from '@babel/types';
|
|
3
3
|
import type * as Babel from '@babel/core';
|
|
4
|
-
import
|
|
4
|
+
import { NodeVisitor } from '@glimmer/syntax';
|
|
5
5
|
interface ASTPluginEnvironment {
|
|
6
6
|
locals: string[];
|
|
7
7
|
filename: string;
|
|
@@ -13,19 +13,21 @@ declare class HotAstProcessor {
|
|
|
13
13
|
counter: number;
|
|
14
14
|
meta: {
|
|
15
15
|
locals: Set<string>;
|
|
16
|
-
importVar:
|
|
16
|
+
importVar: string | null;
|
|
17
17
|
importBindings: Set<string>;
|
|
18
18
|
babelProgram?: Program;
|
|
19
19
|
};
|
|
20
20
|
didCreateImportClass: boolean;
|
|
21
21
|
constructor();
|
|
22
22
|
reset(): void;
|
|
23
|
-
transform(env: ASTPluginEnvironment):
|
|
23
|
+
transform(env: ASTPluginEnvironment): {
|
|
24
|
+
visitor: Record<string, unknown>;
|
|
25
|
+
};
|
|
24
26
|
buildVisitor({ importVar, importBindings, babelProgram, }: {
|
|
25
27
|
importVar: string;
|
|
26
28
|
importBindings: Set<string>;
|
|
27
29
|
babelProgram: Program;
|
|
28
|
-
}):
|
|
30
|
+
}): NodeVisitor;
|
|
29
31
|
}
|
|
30
32
|
export declare const hotAstProcessor: HotAstProcessor;
|
|
31
33
|
export default function hotReplaceAst(babel: typeof Babel): PluginObj;
|
package/dist/lib/babel-plugin.js
CHANGED
|
@@ -37,56 +37,6 @@ exports.hotAstProcessor = void 0;
|
|
|
37
37
|
exports.default = hotReplaceAst;
|
|
38
38
|
const glimmer = __importStar(require("@glimmer/syntax"));
|
|
39
39
|
const babel_import_util_1 = require("babel-import-util");
|
|
40
|
-
const builtInComponents = ['LinkTo'];
|
|
41
|
-
const builtInHelpers = [
|
|
42
|
-
'-get-dynamic-var',
|
|
43
|
-
'-element',
|
|
44
|
-
'-lf-get-outlet-state',
|
|
45
|
-
'-in-element',
|
|
46
|
-
'in-element',
|
|
47
|
-
'-with-dynamic-vars',
|
|
48
|
-
'action',
|
|
49
|
-
'array',
|
|
50
|
-
'component',
|
|
51
|
-
'concat',
|
|
52
|
-
'debugger',
|
|
53
|
-
'each',
|
|
54
|
-
'each-in',
|
|
55
|
-
'fn',
|
|
56
|
-
'get',
|
|
57
|
-
'has-block',
|
|
58
|
-
'has-block-params',
|
|
59
|
-
'hasBlock',
|
|
60
|
-
'hasBlockParams',
|
|
61
|
-
'hash',
|
|
62
|
-
'if',
|
|
63
|
-
'input',
|
|
64
|
-
'let',
|
|
65
|
-
'link-to',
|
|
66
|
-
'loc',
|
|
67
|
-
'log',
|
|
68
|
-
'mount',
|
|
69
|
-
'mut',
|
|
70
|
-
'on',
|
|
71
|
-
'outlet',
|
|
72
|
-
'partial',
|
|
73
|
-
'query-params',
|
|
74
|
-
'readonly',
|
|
75
|
-
'textarea',
|
|
76
|
-
'unbound',
|
|
77
|
-
'unless',
|
|
78
|
-
'with',
|
|
79
|
-
'yield',
|
|
80
|
-
'modifier',
|
|
81
|
-
'helper',
|
|
82
|
-
];
|
|
83
|
-
function dasherize(str) {
|
|
84
|
-
return str
|
|
85
|
-
.trim()
|
|
86
|
-
.split(/\.?(?=[A-Z])/)
|
|
87
|
-
.join('-')
|
|
88
|
-
.toLowerCase();
|
|
89
|
-
}
|
|
90
40
|
class HotAstProcessor {
|
|
91
41
|
constructor() {
|
|
92
42
|
this.options = {
|
|
@@ -109,7 +59,7 @@ class HotAstProcessor {
|
|
|
109
59
|
}
|
|
110
60
|
transform(env) {
|
|
111
61
|
var _a;
|
|
112
|
-
if (process.env
|
|
62
|
+
if (process.env.EMBER_VITE_HMR_ENABLED !== 'true') {
|
|
113
63
|
return {
|
|
114
64
|
visitor: {},
|
|
115
65
|
};
|
|
@@ -124,10 +74,6 @@ class HotAstProcessor {
|
|
|
124
74
|
nameHint: 'template__imports__',
|
|
125
75
|
});
|
|
126
76
|
meta.importVar = meta.importVar || importVar;
|
|
127
|
-
const findImport = function findImport(specifier) {
|
|
128
|
-
return meta.babelProgram.body.find((b) => b.type === 'ImportDeclaration' &&
|
|
129
|
-
b.specifiers.some((s) => s.local.name === specifier));
|
|
130
|
-
};
|
|
131
77
|
return {
|
|
132
78
|
visitor: Object.assign({}, this.buildVisitor({
|
|
133
79
|
importVar,
|
|
@@ -180,7 +126,7 @@ class HotAstProcessor {
|
|
|
180
126
|
if (node.original === 'helper' ||
|
|
181
127
|
node.original === 'component' ||
|
|
182
128
|
node.original === 'modifier') {
|
|
183
|
-
node.original;
|
|
129
|
+
// node.original;
|
|
184
130
|
const parent = p.parentNode;
|
|
185
131
|
if (typeof parent.params[0].original !==
|
|
186
132
|
'string') {
|
|
@@ -228,9 +174,7 @@ class HotAstProcessor {
|
|
|
228
174
|
}
|
|
229
175
|
exports.hotAstProcessor = new HotAstProcessor();
|
|
230
176
|
function hotReplaceAst(babel) {
|
|
231
|
-
|
|
232
|
-
let imports = [];
|
|
233
|
-
let importMap = {};
|
|
177
|
+
const t = babel.types;
|
|
234
178
|
return {
|
|
235
179
|
name: 'a-hot-reload-imports',
|
|
236
180
|
pre(file) {
|
|
@@ -238,20 +182,212 @@ function hotReplaceAst(babel) {
|
|
|
238
182
|
exports.hotAstProcessor.meta.babelProgram = file.ast.program;
|
|
239
183
|
},
|
|
240
184
|
visitor: {
|
|
185
|
+
ExportDefaultDeclaration(path, state) {
|
|
186
|
+
var _a, _b;
|
|
187
|
+
if (process.env.EMBER_VITE_HMR_ENABLED !== 'true') {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if ((_a = state.filename) === null || _a === void 0 ? void 0 : _a.includes('node_modules')) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
// Check if this is a service file (normalize path for cross-platform compatibility)
|
|
194
|
+
const normalizedFilename = (_b = state.filename) === null || _b === void 0 ? void 0 : _b.replace(/\\/g, '/');
|
|
195
|
+
if (!(normalizedFilename === null || normalizedFilename === void 0 ? void 0 : normalizedFilename.includes('/services/'))) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const declaration = path.node.declaration;
|
|
199
|
+
// Handle both inline class declaration and identifier reference
|
|
200
|
+
let classDeclaration = null;
|
|
201
|
+
let classIdentifier = null;
|
|
202
|
+
if (declaration.type === 'ClassDeclaration' && declaration.id) {
|
|
203
|
+
// Case 1: export default class MyService extends Service { ... }
|
|
204
|
+
classDeclaration = declaration;
|
|
205
|
+
classIdentifier = declaration.id;
|
|
206
|
+
}
|
|
207
|
+
else if (declaration.type === 'Identifier') {
|
|
208
|
+
// Case 2: class MyService extends Service { ... } \n export default MyService;
|
|
209
|
+
const binding = path.scope.getBinding(declaration.name);
|
|
210
|
+
if (binding && binding.path.isClassDeclaration()) {
|
|
211
|
+
classDeclaration = binding.path
|
|
212
|
+
.node;
|
|
213
|
+
classIdentifier = classDeclaration.id;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (!classDeclaration || !classIdentifier) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (classIdentifier.name.endsWith('HmrProxy')) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
// Check if it extends Service
|
|
223
|
+
const superClass = classDeclaration.superClass;
|
|
224
|
+
if (!superClass ||
|
|
225
|
+
((superClass.type !== 'Identifier' ||
|
|
226
|
+
superClass.name !== 'Service') &&
|
|
227
|
+
superClass.type !== 'MemberExpression')) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
// Get the program path for ImportUtil
|
|
231
|
+
const programPath = path.findParent((p) => p.isProgram());
|
|
232
|
+
if (!programPath) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const util = new babel_import_util_1.ImportUtil(babel, programPath);
|
|
236
|
+
const tracked = util.import(programPath, '@glimmer/tracking', 'tracked');
|
|
237
|
+
const Service = util.import(programPath, '@ember/service', 'default');
|
|
238
|
+
const originalClassName = classIdentifier.name;
|
|
239
|
+
const proxyClassName = `${originalClassName}HmrProxy`;
|
|
240
|
+
const implVarName = `_${originalClassName}Impl`;
|
|
241
|
+
const proxyVarName = `_${originalClassName}Proxy`;
|
|
242
|
+
// Keep the original class as-is, just remove it from export
|
|
243
|
+
// We'll add it back as a non-exported class
|
|
244
|
+
// Create the HMR proxy service class
|
|
245
|
+
const proxyClass = t.classDeclaration(t.identifier(proxyClassName), Service, t.classBody([
|
|
246
|
+
// static Impl = OriginalService (reference to the original class)
|
|
247
|
+
t.classProperty(t.identifier('Impl'), t.identifier(originalClassName), null, null, false, true),
|
|
248
|
+
// @tracked _delegate = new _OriginalServiceImpl()
|
|
249
|
+
t.classProperty(t.identifier('_delegate'), t.newExpression(t.identifier(implVarName), []), null, [t.decorator(tracked)], false, false),
|
|
250
|
+
// constructor
|
|
251
|
+
t.classMethod('constructor', t.identifier('constructor'), [t.restElement(t.identifier('args'))], t.blockStatement([
|
|
252
|
+
t.expressionStatement(t.callExpression(t.super(), [
|
|
253
|
+
t.spreadElement(t.identifier('args')),
|
|
254
|
+
])),
|
|
255
|
+
t.ifStatement(t.unaryExpression('!', t.identifier(proxyVarName)), t.blockStatement([
|
|
256
|
+
t.expressionStatement(t.assignmentExpression('=', t.identifier(proxyVarName), t.thisExpression())),
|
|
257
|
+
])),
|
|
258
|
+
t.returnStatement(t.newExpression(t.identifier('Proxy'), [
|
|
259
|
+
t.thisExpression(),
|
|
260
|
+
t.objectExpression([
|
|
261
|
+
t.objectMethod('method', t.identifier('get'), [t.identifier('target'), t.identifier('prop')], t.blockStatement([
|
|
262
|
+
t.ifStatement(t.binaryExpression('===', t.identifier('prop'), t.stringLiteral('_delegate')), t.returnStatement(t.memberExpression(t.identifier('target'), t.identifier('_delegate')))),
|
|
263
|
+
t.returnStatement(t.memberExpression(t.memberExpression(t.identifier('target'), t.identifier('_delegate')), t.identifier('prop'), true)),
|
|
264
|
+
])),
|
|
265
|
+
t.objectMethod('method', t.identifier('set'), [
|
|
266
|
+
t.identifier('target'),
|
|
267
|
+
t.identifier('prop'),
|
|
268
|
+
t.identifier('value'),
|
|
269
|
+
], t.blockStatement([
|
|
270
|
+
t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.memberExpression(t.identifier('target'), t.identifier('_delegate')), t.identifier('prop'), true), t.identifier('value'))),
|
|
271
|
+
t.returnStatement(t.booleanLiteral(true)),
|
|
272
|
+
])),
|
|
273
|
+
]),
|
|
274
|
+
])),
|
|
275
|
+
])),
|
|
276
|
+
// willDestroy
|
|
277
|
+
t.classMethod('method', t.identifier('willDestroy'), [], t.blockStatement([
|
|
278
|
+
t.expressionStatement(t.callExpression(t.memberExpression(t.super(), t.identifier('willDestroy')), [])),
|
|
279
|
+
t.expressionStatement(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('_delegate')), t.identifier('willDestroy')), [])),
|
|
280
|
+
])),
|
|
281
|
+
]));
|
|
282
|
+
// Create variable declarations with unique names to avoid conflicts
|
|
283
|
+
const currentImplDeclaration = t.variableDeclaration('let', [
|
|
284
|
+
t.variableDeclarator(t.identifier(implVarName), t.identifier(originalClassName)),
|
|
285
|
+
]);
|
|
286
|
+
const currentProxyDeclaration = t.variableDeclaration('let', [
|
|
287
|
+
t.variableDeclarator(t.identifier(proxyVarName), t.nullLiteral()),
|
|
288
|
+
]);
|
|
289
|
+
// For Case 1 (inline class), we need to keep the class as non-exported
|
|
290
|
+
// For Case 2 (separate declaration), the class already exists, so we don't recreate it
|
|
291
|
+
if (declaration.type === 'ClassDeclaration') {
|
|
292
|
+
// Case 1: Inline class export - create a non-exported version
|
|
293
|
+
const originalClass = t.classDeclaration(classIdentifier, classDeclaration.superClass, classDeclaration.body, classDeclaration.decorators || []);
|
|
294
|
+
// Replace the export with all the necessary declarations
|
|
295
|
+
// IMPORTANT: Class must be declared BEFORE the variables that reference it
|
|
296
|
+
path.replaceWithMultiple([
|
|
297
|
+
originalClass, // The original class (no longer exported) - MUST BE FIRST
|
|
298
|
+
currentImplDeclaration,
|
|
299
|
+
currentProxyDeclaration,
|
|
300
|
+
t.exportDefaultDeclaration(proxyClass), // Export the proxy class
|
|
301
|
+
]);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
// Case 2: Separate declaration - class already exists, just replace the export
|
|
305
|
+
path.replaceWithMultiple([
|
|
306
|
+
currentImplDeclaration,
|
|
307
|
+
currentProxyDeclaration,
|
|
308
|
+
t.exportDefaultDeclaration(proxyClass), // Export the proxy class
|
|
309
|
+
]);
|
|
310
|
+
}
|
|
311
|
+
// Add HMR code after the export using babel template
|
|
312
|
+
if (programPath) {
|
|
313
|
+
const hmrCode = `
|
|
314
|
+
if (import.meta.hot) {
|
|
315
|
+
import.meta.hot.accept((newModule) => {
|
|
316
|
+
if (import.meta.hot.data._hotReload && newModule?.default?.Impl) {
|
|
317
|
+
import.meta.hot.data._hotReload(newModule.default.Impl);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
import.meta.hot.data._hotReload = import.meta.hot.data._hotReload || function(NewImpl) {
|
|
322
|
+
// Skip reload if no instance has been created yet
|
|
323
|
+
if (!${proxyVarName}) {
|
|
324
|
+
${implVarName} = NewImpl;
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const oldDelegate = ${proxyVarName}._delegate;
|
|
329
|
+
${implVarName} = NewImpl;
|
|
330
|
+
const newDelegate = new ${implVarName}();
|
|
331
|
+
${proxyVarName}._delegate = newDelegate;
|
|
332
|
+
|
|
333
|
+
// Sync state from old to new while keeping new implementation defaults
|
|
334
|
+
for (const key in oldDelegate) {
|
|
335
|
+
const descriptor =
|
|
336
|
+
Object.getOwnPropertyDescriptor(oldDelegate, key) ||
|
|
337
|
+
Object.getOwnPropertyDescriptor(Object.getPrototypeOf(oldDelegate), key);
|
|
338
|
+
const hasOwnDefault = Object.prototype.hasOwnProperty.call(newDelegate, key);
|
|
339
|
+
const currentValue = newDelegate[key];
|
|
340
|
+
const previousValue = oldDelegate[key];
|
|
341
|
+
|
|
342
|
+
// Skip Service instances - they should not be synced
|
|
343
|
+
if (previousValue instanceof Service) {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Skip Function properties - they should not be synced
|
|
348
|
+
if (typeof previousValue === 'function') {
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const shouldSync =
|
|
353
|
+
!!descriptor &&
|
|
354
|
+
(descriptor.writable || descriptor.set || Object.prototype.hasOwnProperty.call(oldDelegate, key)) &&
|
|
355
|
+
(!hasOwnDefault || currentValue === previousValue);
|
|
356
|
+
|
|
357
|
+
if (shouldSync) {
|
|
358
|
+
try {
|
|
359
|
+
newDelegate[key] = previousValue;
|
|
360
|
+
} catch (e) {
|
|
361
|
+
// Skip non-writable properties
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (oldDelegate.willDestroy) {
|
|
367
|
+
oldDelegate.willDestroy();
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
`;
|
|
372
|
+
const template = babel.template.statements(hmrCode);
|
|
373
|
+
programPath.pushContainer('body', template());
|
|
374
|
+
}
|
|
375
|
+
},
|
|
241
376
|
Program(path, state) {
|
|
242
377
|
var _a;
|
|
243
|
-
if (process.env
|
|
378
|
+
if (process.env.EMBER_VITE_HMR_ENABLED !== 'true') {
|
|
244
379
|
return;
|
|
245
380
|
}
|
|
246
381
|
if ((_a = state.filename) === null || _a === void 0 ? void 0 : _a.includes('node_modules')) {
|
|
247
382
|
return;
|
|
248
383
|
}
|
|
249
|
-
if (!exports.hotAstProcessor.meta.importVar ||
|
|
384
|
+
if (!exports.hotAstProcessor.meta.importVar ||
|
|
385
|
+
exports.hotAstProcessor.meta.importBindings.size === 0) {
|
|
250
386
|
return;
|
|
251
387
|
}
|
|
252
388
|
const util = new babel_import_util_1.ImportUtil(babel, path);
|
|
253
389
|
const tracked = util.import(path, '@glimmer/tracking', 'tracked');
|
|
254
|
-
|
|
390
|
+
util.import(path, '@glimmer/component', 'default');
|
|
255
391
|
const klass = t.classExpression(path.scope.generateUidIdentifier('Imports'), null, t.classBody([]));
|
|
256
392
|
const bindings = [...exports.hotAstProcessor.meta.importBindings].sort();
|
|
257
393
|
for (const local of bindings) {
|
|
@@ -264,8 +400,7 @@ function hotReplaceAst(babel) {
|
|
|
264
400
|
const varDeclaration = path.node.body.findIndex((e) => e.type === 'VariableDeclaration' &&
|
|
265
401
|
e.declarations[0].id.name ===
|
|
266
402
|
exports.hotAstProcessor.meta.importVar) + 1;
|
|
267
|
-
const lastImportIndex =
|
|
268
|
-
path.node.body.findLastIndex((e) => e.type === 'ImportDeclaration') + 1;
|
|
403
|
+
const lastImportIndex = path.node.body.findLastIndex((e) => e.type === 'ImportDeclaration') + 1;
|
|
269
404
|
path.node.body.splice(Math.max(varDeclaration, lastImportIndex), 0, t.expressionStatement(assign));
|
|
270
405
|
// Export metadata about tracked imports for hmr.ts to use
|
|
271
406
|
const importMetadata = t.variableDeclaration('const', [
|
package/dist/lib/hmr.js
CHANGED
|
@@ -108,7 +108,7 @@ function normalizePath(inputPath) {
|
|
|
108
108
|
}
|
|
109
109
|
const virtualPrefix = '/ember-vite-hmr/virtual/component:';
|
|
110
110
|
function hmr(enableViteHmrForModes = ['development']) {
|
|
111
|
-
let conf;
|
|
111
|
+
// let conf: any;
|
|
112
112
|
let server;
|
|
113
113
|
return {
|
|
114
114
|
name: 'hmr-plugin',
|
|
@@ -117,8 +117,8 @@ function hmr(enableViteHmrForModes = ['development']) {
|
|
|
117
117
|
server = s;
|
|
118
118
|
},
|
|
119
119
|
configResolved(config) {
|
|
120
|
-
conf = config;
|
|
121
|
-
process.env
|
|
120
|
+
// conf = config;
|
|
121
|
+
process.env.EMBER_VITE_HMR_ENABLED = enableViteHmrForModes
|
|
122
122
|
.includes(config.mode)
|
|
123
123
|
.toString();
|
|
124
124
|
},
|
|
@@ -128,7 +128,8 @@ function hmr(enableViteHmrForModes = ['development']) {
|
|
|
128
128
|
return id;
|
|
129
129
|
}
|
|
130
130
|
if (importer === null || importer === void 0 ? void 0 : importer.startsWith(virtualPrefix)) {
|
|
131
|
-
|
|
131
|
+
const newImporter = path_1.default.join(process.cwd(), 'package.json');
|
|
132
|
+
importer = newImporter;
|
|
132
133
|
return this.resolve(id, importer, meta);
|
|
133
134
|
}
|
|
134
135
|
if (id.startsWith(virtualPrefix)) {
|
|
@@ -143,7 +144,7 @@ function hmr(enableViteHmrForModes = ['development']) {
|
|
|
143
144
|
return id;
|
|
144
145
|
}
|
|
145
146
|
if (id === '/ember-vite-hmr/services/vite-hot-reload') {
|
|
146
|
-
return this.resolve('ember-vite-hmr/services/vite-hot-reload', path_1.default.
|
|
147
|
+
return this.resolve('ember-vite-hmr/services/vite-hot-reload', path_1.default.resolve(process.cwd(), 'package.json'), meta);
|
|
147
148
|
}
|
|
148
149
|
});
|
|
149
150
|
},
|
|
@@ -166,7 +167,6 @@ function hmr(enableViteHmrForModes = ['development']) {
|
|
|
166
167
|
if (filename.includes('__vpc__')) {
|
|
167
168
|
filename = filename.split('__vpc__')[0];
|
|
168
169
|
}
|
|
169
|
-
// @ts-ignore
|
|
170
170
|
const res = yield server.transformRequest(filename);
|
|
171
171
|
const content = res === null || res === void 0 ? void 0 : res.code;
|
|
172
172
|
const resId = yield this.resolve(filename, path_1.default.resolve(process.cwd(), 'package.json'));
|
|
@@ -178,7 +178,7 @@ function hmr(enableViteHmrForModes = ['development']) {
|
|
|
178
178
|
});
|
|
179
179
|
},
|
|
180
180
|
transformIndexHtml(html) {
|
|
181
|
-
if (process.env
|
|
181
|
+
if (process.env.EMBER_VITE_HMR_ENABLED !== 'true') {
|
|
182
182
|
return html;
|
|
183
183
|
}
|
|
184
184
|
const fullPath = '/@ember-vite-hmr/setup-ember-hmr.js';
|
|
@@ -234,20 +234,23 @@ function hmr(enableViteHmrForModes = ['development']) {
|
|
|
234
234
|
},
|
|
235
235
|
transform(source, id) {
|
|
236
236
|
return __awaiter(this, void 0, void 0, function* () {
|
|
237
|
-
if (process.env
|
|
237
|
+
if (process.env.EMBER_VITE_HMR_ENABLED !== 'true') {
|
|
238
238
|
return source;
|
|
239
239
|
}
|
|
240
240
|
const resourcePath = normalizePath(id.split('?')[0]);
|
|
241
241
|
const supportedExt = ['.hbs', '.gjs', 'gts', '.js', '.ts'];
|
|
242
|
-
if (!supportedExt.some(x => resourcePath.endsWith(x))) {
|
|
242
|
+
if (!supportedExt.some((x) => resourcePath.endsWith(x))) {
|
|
243
243
|
return source;
|
|
244
244
|
}
|
|
245
|
-
const
|
|
245
|
+
const pkgPath = path_1.default.resolve(process.cwd(), 'package.json');
|
|
246
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
247
|
+
const name = require(pkgPath).name;
|
|
246
248
|
if (resourcePath.includes(`${name}/app/app.js`)) {
|
|
247
249
|
source += `\n
|
|
248
250
|
let prevCompatModules = Object.assign({}, compatModules);
|
|
249
251
|
import.meta.hot.accept('@embroider/virtual/compat-modules', (m) => {
|
|
250
252
|
for (const [name, module] of Object.entries(m.default)) {
|
|
253
|
+
compatModules[name] = module;
|
|
251
254
|
if (name.includes('initializers') && prevCompatModules[name]?.default !== module.default) {
|
|
252
255
|
globalThis.location.reload();
|
|
253
256
|
}
|
|
@@ -278,6 +281,7 @@ function hmr(enableViteHmrForModes = ['development']) {
|
|
|
278
281
|
let importVar = null;
|
|
279
282
|
let bindings = [];
|
|
280
283
|
const importStatements = [];
|
|
284
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
281
285
|
const traverse = require('@babel/traverse').default;
|
|
282
286
|
// First pass: Extract metadata
|
|
283
287
|
traverse(result, {
|
|
@@ -286,16 +290,20 @@ function hmr(enableViteHmrForModes = ['development']) {
|
|
|
286
290
|
const declaration = path.node.declaration;
|
|
287
291
|
// Check if this is: export const __hmr_import_metadata__ = {...}
|
|
288
292
|
if ((declaration === null || declaration === void 0 ? void 0 : declaration.type) === 'VariableDeclaration' &&
|
|
289
|
-
((_c = (_b = (_a = declaration.declarations) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.name) ===
|
|
293
|
+
((_c = (_b = (_a = declaration.declarations) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.name) ===
|
|
294
|
+
'__hmr_import_metadata__') {
|
|
290
295
|
const init = declaration.declarations[0].init;
|
|
291
296
|
if ((init === null || init === void 0 ? void 0 : init.type) === 'ObjectExpression') {
|
|
292
297
|
// Extract importVar and bindings from the object
|
|
293
298
|
for (const prop of init.properties) {
|
|
294
|
-
if (prop.type === 'ObjectProperty' &&
|
|
295
|
-
|
|
299
|
+
if (prop.type === 'ObjectProperty' &&
|
|
300
|
+
prop.key.type === 'Identifier') {
|
|
301
|
+
if (prop.key.name === 'importVar' &&
|
|
302
|
+
prop.value.type === 'StringLiteral') {
|
|
296
303
|
importVar = prop.value.value;
|
|
297
304
|
}
|
|
298
|
-
else if (prop.key.name === 'bindings' &&
|
|
305
|
+
else if (prop.key.name === 'bindings' &&
|
|
306
|
+
prop.value.type === 'ArrayExpression') {
|
|
299
307
|
bindings = prop.value.elements
|
|
300
308
|
.filter((el) => (el === null || el === void 0 ? void 0 : el.type) === 'StringLiteral')
|
|
301
309
|
.map((el) => el.value);
|
|
@@ -310,6 +318,7 @@ function hmr(enableViteHmrForModes = ['development']) {
|
|
|
310
318
|
if (importVar && bindings.length > 0) {
|
|
311
319
|
traverse(result, {
|
|
312
320
|
ImportDeclaration(path) {
|
|
321
|
+
var _a;
|
|
313
322
|
const importSource = path.node.source.value;
|
|
314
323
|
for (const specifier of path.node.specifiers) {
|
|
315
324
|
const local = specifier.local.name;
|
|
@@ -320,7 +329,7 @@ function hmr(enableViteHmrForModes = ['development']) {
|
|
|
320
329
|
}
|
|
321
330
|
else if (specifier.type === 'ImportSpecifier') {
|
|
322
331
|
// For named imports, use the imported name
|
|
323
|
-
specifierName = specifier.imported.name;
|
|
332
|
+
specifierName = ((_a = specifier.imported) === null || _a === void 0 ? void 0 : _a.name) || 'default';
|
|
324
333
|
}
|
|
325
334
|
else if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
326
335
|
specifierName = '*';
|
|
@@ -342,7 +351,8 @@ function hmr(enableViteHmrForModes = ['development']) {
|
|
|
342
351
|
for (const imp of importStatements) {
|
|
343
352
|
// Resolve the import to check if it's from node_modules
|
|
344
353
|
const resolved = yield this.resolve(imp.source, resourcePath, {});
|
|
345
|
-
if ((resolved === null || resolved === void 0 ? void 0 : resolved.id) &&
|
|
354
|
+
if ((resolved === null || resolved === void 0 ? void 0 : resolved.id) &&
|
|
355
|
+
normalizePath(resolved.id).includes('node_modules')) {
|
|
346
356
|
// Skip node_modules imports
|
|
347
357
|
continue;
|
|
348
358
|
}
|
|
@@ -23,7 +23,7 @@ function _initializerDefineProperty(e, i, r, l) {
|
|
|
23
23
|
var _dec, _class, _descriptor;
|
|
24
24
|
const ChangeMap = new WeakMap();
|
|
25
25
|
function getLatestChange(obj) {
|
|
26
|
-
while (ChangeMap.has(obj)) {
|
|
26
|
+
while (obj && typeof obj === 'object' && ChangeMap.has(obj)) {
|
|
27
27
|
obj = ChangeMap.get(obj);
|
|
28
28
|
}
|
|
29
29
|
return obj;
|
|
@@ -40,7 +40,8 @@ let ViteHotReloadService = (_dec = service(), _class = class ViteHotReloadServic
|
|
|
40
40
|
globalThis.emberHotReloadPlugin.Resolver = app.Resolver;
|
|
41
41
|
globalThis.emberHotReloadPlugin.modulePrefix = app.modulePrefix;
|
|
42
42
|
globalThis.emberHotReloadPlugin.podModulePrefix = app.podModulePrefix;
|
|
43
|
-
|
|
43
|
+
// Ensure router is initialized
|
|
44
|
+
void this.router._router;
|
|
44
45
|
Object.defineProperty(this.router._router, '_routerMicrolib', {
|
|
45
46
|
set(v) {
|
|
46
47
|
const getRoute = v.getRoute;
|
|
@@ -55,8 +56,9 @@ let ViteHotReloadService = (_dec = service(), _class = class ViteHotReloadServic
|
|
|
55
56
|
return this.___routerMicrolib;
|
|
56
57
|
}
|
|
57
58
|
});
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
const owner = getOwner(this);
|
|
60
|
+
this.container = owner?.__container__;
|
|
61
|
+
globalThis.emberHotReloadPlugin.subscribe((oldModule, _newModule) => {
|
|
60
62
|
let changed = false;
|
|
61
63
|
if (oldModule.exports.default?.prototype && oldModule.exports.default.prototype instanceof Route) {
|
|
62
64
|
changed = true;
|
|
@@ -64,6 +66,9 @@ let ViteHotReloadService = (_dec = service(), _class = class ViteHotReloadServic
|
|
|
64
66
|
if (oldModule.exports.default?.prototype && oldModule.exports.default.prototype instanceof Controller) {
|
|
65
67
|
changed = true;
|
|
66
68
|
}
|
|
69
|
+
if (oldModule.exports.default?.prototype && oldModule.exports.default.prototype instanceof Service) {
|
|
70
|
+
changed = true;
|
|
71
|
+
}
|
|
67
72
|
if (oldModule.id.startsWith('app/templates/') && !oldModule.id.startsWith('app/templates/components/')) {
|
|
68
73
|
changed = true;
|
|
69
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-hot-reload.js","sources":["../../src/services/vite-hot-reload.ts"],"sourcesContent":["import Service, { service } from '@ember/service';\nimport { getOwner } from '@ember/owner';\nimport RouterService from '@ember/routing/router-service';\nimport Router from '@ember/routing/route';\nimport Controller from '@ember/controller';\nimport ApplicationInstance from '@ember/application/instance';\n\nconst ChangeMap = new WeakMap();\n\nfunction getLatestChange(obj: any) {\n while (ChangeMap.has(obj)) {\n obj = ChangeMap.get(obj);\n }\n return obj;\n}\n\nexport default class ViteHotReloadService extends Service {\n declare container: any;\n @service() router!: RouterService;\n\n init(args: any) {\n super.init(args);\n if (!globalThis.emberHotReloadPlugin) return;\n const app = (getOwner(this) as ApplicationInstance)!.application as any;\n globalThis.emberHotReloadPlugin.Resolver = app.Resolver;\n globalThis.emberHotReloadPlugin.modulePrefix = app.modulePrefix;\n globalThis.emberHotReloadPlugin.podModulePrefix = app.podModulePrefix;\n this.router._router;\n Object.defineProperty(this.router._router, '_routerMicrolib', {\n set(v) {\n const getRoute = v.getRoute;\n v.getRoute = function (name: string) {\n const route = getRoute.call(\n this,\n `${name}--hot-version--${globalThis.emberHotReloadPlugin.routerVersion}`,\n );\n route.fullRouteName = `${name}`.replace(\n /--hot-version--.*$/,\n '',\n );\n return route;\n };\n this.___routerMicrolib = v;\n },\n get() {\n return this.___routerMicrolib;\n },\n });\n this.container = (getOwner(this) as any)?.__container__;\n globalThis.emberHotReloadPlugin.subscribe((oldModule: any, newModule: any) => {\n let changed = false;\n if (\n oldModule.exports.default?.prototype &&\n oldModule.exports.default.prototype instanceof Router\n ) {\n changed = true;\n }\n if (\n oldModule.exports.default?.prototype &&\n oldModule.exports.default.prototype instanceof Controller\n ) {\n changed = true;\n }\n if (\n oldModule.id.startsWith('app/templates/') &&\n !oldModule.id.startsWith('app/templates/components/')\n ) {\n changed = true;\n }\n if (oldModule.id.startsWith(`./${globalThis.emberHotReloadPlugin.podModulePrefix}/`)) {\n changed = true;\n }\n if (!changed) return;\n globalThis.emberHotReloadPlugin.routerVersion += 1;\n const types = [\n 'route',\n 'controller',\n 'template',\n 'modifier',\n 'helper',\n 'component',\n ];\n Object.keys(this.container.cache).forEach((k) => {\n if (types.some((t) => k.startsWith(`${t}:`))) {\n delete this.container.cache[k];\n }\n });\n Object.keys(this.container.factoryManagerCache || {}).forEach((k) => {\n if (types.some((t) => k.startsWith(`${t}:`))) {\n delete this.container.factoryManagerCache[k];\n }\n });\n Object.keys(this.container.registry._resolveCache || {}).forEach((k) => {\n if (types.some((t) => k.startsWith(`${t}:`))) {\n delete this.container.registry._resolveCache[k];\n }\n });\n Object.keys(this.container.validationCache || {}).forEach((k) => {\n if (types.some((t) => k.startsWith(`${t}:`))) {\n delete this.container.validationCache[k];\n }\n });\n Object.keys(this.container.registry.registrations || {}).forEach((k) => {\n if (types.some((t) => k.startsWith(`${t}:`))) {\n delete this.container.registry.registrations[k];\n }\n });\n if (\n oldModule.exports.default?.prototype &&\n oldModule.exports.default.prototype instanceof Router\n ) {\n this.router.refresh();\n }\n if (\n oldModule.exports.default?.prototype &&\n oldModule.exports.default.prototype instanceof Controller\n ) {\n this.router.refresh();\n }\n if (\n oldModule.id.startsWith('app/templates/') &&\n !oldModule.id.startsWith('app/templates/components/')\n ) {\n this.router.refresh();\n }\n if (oldModule.id.startsWith(`./${globalThis.emberHotReloadPlugin.podModulePrefix}/`)) {\n this.router.refresh();\n }\n });\n }\n getLatestChange(obj: any) {\n return getLatestChange(obj);\n }\n}\n\n// Don't remove this declaration: this is what enables TypeScript to resolve\n// this service using `Owner.lookup('service:hot-reload')`, as well\n// as to check when you pass the service name as an argument to the decorator,\n// like `@service('hot-reload') declare altName: HotReloadService;`.\ndeclare module '@ember/service' {\n interface Registry {\n 'hot-reload': ViteHotReloadService;\n }\n}\n"],"names":["ChangeMap","WeakMap","getLatestChange","obj","has","get","ViteHotReloadService","_dec","service","_class","Service","constructor","args","_initializerDefineProperty","_descriptor","init","globalThis","emberHotReloadPlugin","app","getOwner","application","Resolver","modulePrefix","podModulePrefix","router","_router","Object","defineProperty","set","v","getRoute","name","route","call","routerVersion","fullRouteName","replace","___routerMicrolib","container","__container__","subscribe","oldModule","newModule","changed","exports","default","prototype","Router","Controller","id","startsWith","types","keys","cache","forEach","k","some","t","factoryManagerCache","registry","_resolveCache","validationCache","registrations","refresh","_applyDecoratedDescriptor","configurable","enumerable","writable","initializer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAMA,SAAS,GAAG,IAAIC,OAAO,EAAE;AAE/B,SAASC,eAAeA,CAACC,GAAQ,EAAE;AACjC,EAAA,OAAOH,SAAS,CAACI,GAAG,CAACD,GAAG,CAAC,EAAE;AACzBA,IAAAA,GAAG,GAAGH,SAAS,CAACK,GAAG,CAACF,GAAG,CAAC;AAC1B,EAAA;AACA,EAAA,OAAOA,GAAG;AACZ;AAAC,IAEoBG,oBAAoB,IAAAC,IAAA,GAEtCC,OAAO,EAAE,EAAAC,MAAA,GAFG,MAAMH,oBAAoB,SAASI,OAAO,CAAC;AAAAC,EAAAA,WAAAA,CAAA,GAAAC,IAAA,EAAA;AAAA,IAAA,KAAA,CAAA,GAAAA,IAAA,CAAA;AAAAC,IAAAA,0BAAA,iBAAAC,WAAA,EAAA,IAAA,CAAA;AAAA,EAAA;EAIxDC,IAAIA,CAACH,IAAS,EAAE;AACd,IAAA,KAAK,CAACG,IAAI,CAACH,IAAI,CAAC;AAChB,IAAA,IAAI,CAACI,UAAU,CAACC,oBAAoB,EAAE;AACtC,IAAA,MAAMC,GAAG,GAAIC,QAAQ,CAAC,IA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EAAA,IAAA;EAAAC,UAAA,EAAA,IAAA;EAAAC,QAAA,EAAA,IAAA;EAAAC,WAAA,EAAA;AAAA,CAAA,CAAA,EAAA3D,MAAA;AAGD;AACA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"vite-hot-reload.js","sources":["../../src/services/vite-hot-reload.ts"],"sourcesContent":["import Service, { service } from '@ember/service';\nimport { getOwner } from '@ember/owner';\nimport RouterService from '@ember/routing/router-service';\nimport Router from '@ember/routing/route';\nimport Controller from '@ember/controller';\nimport ApplicationInstance from '@ember/application/instance';\n\nconst ChangeMap = new WeakMap<object, unknown>();\n\nfunction getLatestChange(obj: unknown) {\n while (obj && typeof obj === 'object' && ChangeMap.has(obj)) {\n obj = ChangeMap.get(obj);\n }\n return obj;\n}\n\nexport default class ViteHotReloadService extends Service {\n declare container: {\n cache: Record<string, unknown>;\n factoryManagerCache: Record<string, unknown>;\n registry: {\n _resolveCache: Record<string, unknown>;\n registrations: Record<string, unknown>;\n };\n validationCache: Record<string, unknown>;\n };\n @service() router!: RouterService;\n\n init(args?: object) {\n super.init(args);\n if (!globalThis.emberHotReloadPlugin) return;\n const app = (getOwner(this) as ApplicationInstance)!.application as unknown as {\n Resolver: unknown;\n modulePrefix: string;\n podModulePrefix: string;\n };\n globalThis.emberHotReloadPlugin.Resolver = app.Resolver;\n globalThis.emberHotReloadPlugin.modulePrefix = app.modulePrefix;\n globalThis.emberHotReloadPlugin.podModulePrefix = app.podModulePrefix;\n // Ensure router is initialized\n void this.router._router;\n Object.defineProperty(this.router._router, '_routerMicrolib', {\n set(v) {\n const getRoute = v.getRoute;\n v.getRoute = function (name: string) {\n const route = getRoute.call(\n this,\n `${name}--hot-version--${globalThis.emberHotReloadPlugin.routerVersion}`,\n );\n route.fullRouteName = `${name}`.replace(/--hot-version--.*$/, '');\n return route;\n };\n this.___routerMicrolib = v;\n },\n get() {\n return this.___routerMicrolib;\n },\n });\n const owner = getOwner(this) as unknown as { __container__: ViteHotReloadService['container'] };\n this.container = owner?.__container__;\n globalThis.emberHotReloadPlugin.subscribe(\n (\n oldModule: {\n exports: { default?: { prototype?: unknown } };\n id: string;\n },\n _newModule: unknown,\n ) => {\n let changed = false;\n if (\n oldModule.exports.default?.prototype &&\n oldModule.exports.default.prototype instanceof Router\n ) {\n changed = true;\n }\n if (\n oldModule.exports.default?.prototype &&\n oldModule.exports.default.prototype instanceof Controller\n ) {\n changed = true;\n }\n if (\n oldModule.exports.default?.prototype &&\n oldModule.exports.default.prototype instanceof Service\n ) {\n changed = true;\n }\n if (\n oldModule.id.startsWith('app/templates/') &&\n !oldModule.id.startsWith('app/templates/components/')\n ) {\n changed = true;\n }\n if (\n oldModule.id.startsWith(\n `./${globalThis.emberHotReloadPlugin.podModulePrefix}/`,\n )\n ) {\n changed = true;\n }\n if (!changed) return;\n globalThis.emberHotReloadPlugin.routerVersion += 1;\n const types = [\n 'route',\n 'controller',\n 'template',\n 'modifier',\n 'helper',\n 'component',\n ];\n Object.keys(this.container.cache).forEach((k) => {\n if (types.some((t) => k.startsWith(`${t}:`))) {\n delete this.container.cache[k];\n }\n });\n Object.keys(this.container.factoryManagerCache || {}).forEach((k) => {\n if (types.some((t) => k.startsWith(`${t}:`))) {\n delete this.container.factoryManagerCache[k];\n }\n });\n Object.keys(this.container.registry._resolveCache || {}).forEach(\n (k) => {\n if (types.some((t) => k.startsWith(`${t}:`))) {\n delete this.container.registry._resolveCache[k];\n }\n },\n );\n Object.keys(this.container.validationCache || {}).forEach((k) => {\n if (types.some((t) => k.startsWith(`${t}:`))) {\n delete this.container.validationCache[k];\n }\n });\n Object.keys(this.container.registry.registrations || {}).forEach(\n (k) => {\n if (types.some((t) => k.startsWith(`${t}:`))) {\n delete this.container.registry.registrations[k];\n }\n },\n );\n if (\n oldModule.exports.default?.prototype &&\n oldModule.exports.default.prototype instanceof Router\n ) {\n this.router.refresh();\n }\n if (\n oldModule.exports.default?.prototype &&\n oldModule.exports.default.prototype instanceof Controller\n ) {\n this.router.refresh();\n }\n if (\n oldModule.id.startsWith('app/templates/') &&\n !oldModule.id.startsWith('app/templates/components/')\n ) {\n this.router.refresh();\n }\n if (\n oldModule.id.startsWith(\n `./${globalThis.emberHotReloadPlugin.podModulePrefix}/`,\n )\n ) {\n this.router.refresh();\n }\n },\n );\n }\n getLatestChange(obj: unknown) {\n return getLatestChange(obj);\n }\n}\n\n// Don't remove this declaration: this is what enables TypeScript to resolve\n// this service using `Owner.lookup('service:hot-reload')`, as well\n// as to check when you pass the service name as an argument to the decorator,\n// like `@service('hot-reload') declare altName: HotReloadService;`.\ndeclare module '@ember/service' {\n interface Registry {\n 'hot-reload': ViteHotReloadService;\n }\n}\n"],"names":["ChangeMap","WeakMap","getLatestChange","obj","has","get","ViteHotReloadService","_dec","service","_class","Service","constructor","args","_initializerDefineProperty","_descriptor","init","globalThis","emberHotReloadPlugin","app","getOwner","application","Resolver","modulePrefix","podModulePrefix","router","_router","Object","defineProperty","set","v","getRoute","name","route","call","routerVersion","fullRouteName","replace","___routerMicrolib","owner","container","__container__","subscribe","oldModule","_newModule","changed","exports","default","prototype","Router","Controller","id","startsWith","types","keys","cache","forEach","k","some","t","factoryManagerCache","registry","_resolveCache","validationCache","registrations","refresh","_applyDecoratedDescriptor","configurable","enumerable","writable","initializer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAMA,SAAS,GAAG,IAAIC,OAAO,EAAmB;AAEhD,SAASC,eAAeA,CAACC,GAAY,EAAE;AACrC,EAAA,OAAOA,GAAG,IAAI,OAAOA,GAAG,KAAK,QAAQ,IAAIH,SAAS,CAACI,GAAG,CAACD,GAAG,CAAC,EAAE;AAC3DA,IAAAA,GAAG,GAAGH,SAAS,CAACK,GAAG,CAACF,GAAG,CAAC;AAC1B,EAAA;AACA,EAAA,OAAOA,GAAG;AACZ;AAAC,IAEoBG,oBAAoB,IAAAC,IAAA,GAUtCC,OAAO,EAAE,EAAAC,MAAA,GAVG,MAAMH,oBAAoB,SAASI,OAAO,CAAC;AA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SAAS,CAACQ,EAAE,CAACC,UAAU,CAAC,2BAA2B,CAAC,EACrD;AACA,QAAA,IAAI,CAAC3B,MAAM,CAACwC,OAAO,EAAE;AACvB,MAAA;AACA,MAAA,IACEtB,SAAS,CAACQ,EAAE,CAACC,UAAU,CACrB,CAAA,EAAA,EAAKnC,UAAU,CAACC,oBAAoB,CAACM,eAAe,CAAA,CAAA,CACtD,CAAC,EACD;AACA,QAAA,IAAI,CAACC,MAAM,CAACwC,OAAO,EAAE;AACvB,MAAA;AACF,IAAA,CACF,CAAC;AACH,EAAA;EACA9D,eAAeA,CAACC,GAAY,EAAE;IAC5B,OAAOD,eAAe,CAACC,GAAG,CAAC;AAC7B,EAAA;AACF,CAAC,EAAAW,WAAA,GAAAmD,yBAAA,CAAAxD,MAAA,CAAAsC,SAAA,EAAA,QAAA,EAAA,CAAAxC,IAAA,CAAA,EAAA;EAAA2D,YAAA,EAAA,IAAA;EAAAC,UAAA,EAAA,IAAA;EAAAC,QAAA,EAAA,IAAA;EAAAC,WAAA,EAAA;AAAA,CAAA,CAAA,EAAA5D,MAAA;AAGD;AACA;AACA;;;;"}
|
package/dist/setup-ember-hmr.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="../types/global" />
|
|
2
|
-
|
|
3
1
|
if (import.meta.hot) {
|
|
4
2
|
const ModuleMap = new Map();
|
|
5
3
|
globalThis.emberHotReloadPlugin = {
|
|
@@ -24,7 +22,7 @@ if (import.meta.hot) {
|
|
|
24
22
|
loadNew(oldModule, newModule) {
|
|
25
23
|
ModuleMap.set(newModule.id, newModule);
|
|
26
24
|
this.versionMap[newModule.id] = newModule.version;
|
|
27
|
-
const entry = Object.entries(this.Resolver.explicitModules).find(([
|
|
25
|
+
const entry = Object.entries(this.Resolver.explicitModules).find(([_name, module]) => module.default === oldModule.exports.default);
|
|
28
26
|
if (!entry) return;
|
|
29
27
|
this.Resolver.explicitModules[entry[0]] = newModule.exports;
|
|
30
28
|
},
|
|
@@ -41,9 +39,9 @@ if (import.meta.hot) {
|
|
|
41
39
|
};
|
|
42
40
|
this._accepting -= 1;
|
|
43
41
|
if (this._accepting === 0) {
|
|
44
|
-
setTimeout(() => this.notifyNew(), 0);
|
|
42
|
+
globalThis.setTimeout(() => this.notifyNew(), 0);
|
|
45
43
|
}
|
|
46
|
-
let ok = module.id.includes('/routes/') || module.id.includes('/routers/') || module.id.includes('/controllers/') || module.id.includes('/templates/') || module.id.match(/controller\.(js|ts)$/) || module.id.match(/route\.(js|ts|gts)$/);
|
|
44
|
+
let ok = module.id.includes('/routes/') || module.id.includes('/routers/') || module.id.includes('/controllers/') || module.id.includes('/templates/') || module.id.includes('/services/') || module.id.match(/controller\.(js|ts)$/) || module.id.match(/route\.(js|ts|gts)$/);
|
|
47
45
|
if (!ok) {
|
|
48
46
|
return false;
|
|
49
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-ember-hmr.js","sources":["../src/setup-ember-hmr.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"setup-ember-hmr.js","sources":["../src/setup-ember-hmr.ts"],"sourcesContent":["import type { Module } from '../types/global';\n\nif (import.meta.hot) {\n const ModuleMap = new Map();\n\n globalThis.emberHotReloadPlugin = {\n modulePrefix: '',\n podModulePrefix: '',\n Resolver: null,\n _accepting: 0,\n changed: {} as Record<string, { old: Module; new: Module }>,\n subscribers: [],\n version: 1,\n routerVersion: 1,\n moduleDepCallbacks: {},\n versionMap: {},\n\n clear(module: Module) {\n this.moduleDepCallbacks[module.id] = {};\n },\n register(module: Module, dep: string, callback: () => void) {\n dep = dep.replace(\n new RegExp(`^${globalThis.emberHotReloadPlugin.modulePrefix}/`),\n './',\n );\n this.moduleDepCallbacks[module.id]![dep] =\n this.moduleDepCallbacks[module.id]![dep] || ([] as (() => void)[]);\n this.moduleDepCallbacks[module.id]![dep]!.push(callback);\n },\n loadNew(oldModule: Module, newModule: Module) {\n ModuleMap.set(newModule.id, newModule);\n this.versionMap[newModule.id] = newModule.version;\n const entry = Object.entries(\n this.Resolver.explicitModules as Record<string, { default?: unknown }>,\n ).find(([_name, module]) => module.default === oldModule.exports.default);\n if (!entry) return;\n this.Resolver.explicitModules[entry[0]] = newModule.exports;\n },\n\n __import(moduleUrl: string) {\n return import(/* @vite-ignore */ moduleUrl);\n },\n\n async canAcceptNew(moduleUrl: string) {\n this._accepting += 1;\n const m = await this.__import(moduleUrl);\n const module: Module = {\n exports: m,\n id: moduleUrl.split('?')[0]!.replace(/http:\\/\\/.*:[^\\/]*\\//, ''),\n version: 0,\n };\n this._accepting -= 1;\n if (this._accepting === 0) {\n globalThis.setTimeout(() => this.notifyNew(), 0);\n }\n let ok =\n module.id.includes('/routes/') ||\n module.id.includes('/routers/') ||\n module.id.includes('/controllers/') ||\n module.id.includes('/templates/') ||\n module.id.includes('/services/') ||\n module.id.match(/controller\\.(js|ts)$/) ||\n module.id.match(/route\\.(js|ts|gts)$/);\n if (!ok) {\n return false;\n }\n\n if (module.id.includes('templates') && module.id.includes('components')) {\n return false;\n }\n\n if (ModuleMap.get(module.id)) {\n this.changed[module.id] = {\n old: ModuleMap.get(module.id),\n new: module,\n };\n } else {\n ModuleMap.set(module.id, module);\n }\n module.version = this.version;\n return true;\n },\n notifyNew() {\n this.version += 1;\n (\n Object.values(this.changed) as Array<{ old: Module; new: Module }>\n ).forEach((change) => {\n this.loadNew(change.old, change.new);\n this.subscribers.forEach(\n (fn: (oldModule: Module, newModule: Module) => void) =>\n fn(change.old, change.new),\n );\n });\n this.changed = {};\n },\n subscribe(fn: (oldModule: Module, newModule: Module) => void) {\n this.subscribers.push(fn);\n },\n unsubscribe(fn: (oldModule: Module, newModule: Module) => void) {\n const idx = this.subscribers.indexOf(fn);\n if (idx >= 0) {\n this.subscribers.splice(idx, 1);\n }\n },\n };\n}\n"],"names":["import","meta","hot","ModuleMap","Map","globalThis","emberHotReloadPlugin","modulePrefix","podModulePrefix","Resolver","_accepting","changed","subscribers","version","routerVersion","moduleDepCallbacks","versionMap","clear","module","id","register","dep","callback","replace","RegExp","push","loadNew","oldModule","newModule","set","entry","Object","entries","explicitModules","find","_name","default","exports","__import","moduleUrl","canAcceptNew","m","split","setTimeout","notifyNew","ok","includes","match","get","old","new","values","forEach","change","fn","subscribe","unsubscribe","idx","indexOf","splice"],"mappings":"AAEA,IAAIA,MAAM,CAACC,IAAI,CAACC,GAAG,EAAE;AACnB,EAAA,MAAMC,SAAS,GAAG,IAAIC,GAAG,EAAE;EAE3BC,UAAU,CAACC,oBAAoB,GAAG;AAChCC,IAAAA,YAAY,EAAE,EAAE;AAChBC,IAAAA,eAAe,EAAE,EAAE;AACnBC,IAAAA,QAAQ,EAAE,IAAI;AACdC,IAAAA,UAAU,EAAE,CAAC;IACbC,OAAO,EAAE,EAAkD;AAC3DC,IAAAA,WAAW,EAAE,EAAE;AACfC,IAAAA,OAAO,EAAE,CAAC;AACVC,IAAAA,aAAa,EAAE,CAAC;IAChBC,kBAAkB,EAAE,EAAE;IACtBC,UAAU,EAAE,EAAE;IAEdC,KAAKA,CAACC,MAAc,EAAE;MACpB,IAAI,CAACH,kBAAkB,CAACG,MAAM,CAACC,EAAE,CAAC,GAAG,EAAE;IACzC,CAAC;AACDC,IAAAA,QAAQA,CAACF,MAAc,EAAEG,GAAW,EAAEC,QAAoB,EAAE;AAC1DD,MAAAA,GAAG,GAAGA,GAAG,CAACE,OAAO,CACf,IAAIC,MAAM,CAAC,CAAA,CAAA,EAAInB,UAAU,CAACC,oBAAoB,CAACC,YAAY,GAAG,CAAC,EAC/D,IACF,CAAC;MACD,IAAI,CAACQ,kBAAkB,CAACG,MAAM,CAACC,EAAE,CAAC,CAAEE,GAAG,CAAC,GACtC,IAAI,CAACN,kBAAkB,CAACG,MAAM,CAACC,EAAE,CAAC,CAAEE,GAAG,CAAC,IAAK,EAAqB;AACpE,MAAA,IAAI,CAACN,kBAAkB,CAACG,MAAM,CAACC,EAAE,CAAC,CAAEE,GAAG,CAAC,CAAEI,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MAEfkB,MAAM,CAACoB,MAAM,CAAC,IAAI,CAACxC,OAAO,CAAC,CAC3ByC,OAAO,CAAEC,MAAM,IAAK;QACpB,IAAI,CAAC3B,OAAO,CAAC2B,MAAM,CAACJ,GAAG,EAAEI,MAAM,CAACH,GAAG,CAAC;AACpC,QAAA,IAAI,CAACtC,WAAW,CAACwC,OAAO,CACrBE,EAAkD,IACjDA,EAAE,CAACD,MAAM,CAACJ,GAAG,EAAEI,MAAM,CAACH,GAAG,CAC7B,CAAC;AACH,MAAA,CAAC,CAAC;AACF,MAAA,IAAI,CAACvC,OAAO,GAAG,EAAE;IACnB,CAAC;IACD4C,SAASA,CAACD,EAAkD,EAAE;AAC5D,MAAA,IAAI,CAAC1C,WAAW,CAACa,IAAI,CAAC6B,EAAE,CAAC;IAC3B,CAAC;IACDE,WAAWA,CAACF,EAAkD,EAAE;MAC9D,MAAMG,GAAG,GAAG,IAAI,CAAC7C,WAAW,CAAC8C,OAAO,CAACJ,EAAE,CAAC;MACxC,IAAIG,GAAG,IAAI,CAAC,EAAE;QACZ,IAAI,CAAC7C,WAAW,CAAC+C,MAAM,CAACF,GAAG,EAAE,CAAC,CAAC;AACjC,MAAA;AACF,IAAA;GACD;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-vite-hmr",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"ember-addon"
|
|
6
6
|
],
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "
|
|
21
|
+
"build": "pnpm build:js && pnpm build:lib",
|
|
22
22
|
"build:js": "rollup --config",
|
|
23
23
|
"build:lib": "tsc --p tsconfig.lib.json",
|
|
24
24
|
"watch:lib": "tsc --p tsconfig.lib.json --watch",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@babel/core": "^7.28.5",
|
|
43
43
|
"@babel/plugin-transform-typescript": "^7.28.5",
|
|
44
|
-
"@babel/traverse": "^7.
|
|
44
|
+
"@babel/traverse": "^7.29.0",
|
|
45
45
|
"@babel/types": "^7.28.5",
|
|
46
46
|
"@embroider/addon-shim": "^1.10.2",
|
|
47
47
|
"@glimmer/syntax": "^0.95.0",
|
|
@@ -60,6 +60,8 @@
|
|
|
60
60
|
"@embroider/addon-dev": "^8.3.0",
|
|
61
61
|
"@embroider/compat": "^4.1.17",
|
|
62
62
|
"@embroider/core": "^4.4.7",
|
|
63
|
+
"@eslint/js": "^9.39.4",
|
|
64
|
+
"@glimmer/component": "^2.0.0",
|
|
63
65
|
"@glint/core": "^1.2.0",
|
|
64
66
|
"@glint/environment-ember-loose": "^1.5.2",
|
|
65
67
|
"@glint/environment-ember-template-imports": "^1.5.2",
|
|
@@ -69,13 +71,15 @@
|
|
|
69
71
|
"@types/babel__core": "^7.20.3",
|
|
70
72
|
"@types/babel__traverse": "^7.28.0",
|
|
71
73
|
"@types/csso": "^5.0.4",
|
|
72
|
-
"@types/debug": "^4.1.
|
|
74
|
+
"@types/debug": "^4.1.13",
|
|
73
75
|
"@types/fs-extra": "^11.0.4",
|
|
74
76
|
"@types/lodash": "^4.17.21",
|
|
75
77
|
"@types/mini-css-extract-plugin": "^2.5.1",
|
|
76
78
|
"@types/node": "^24.10.1",
|
|
77
79
|
"@types/rsvp": "^4.0.9",
|
|
78
80
|
"@types/semver": "^7.7.1",
|
|
81
|
+
"@typescript-eslint/eslint-plugin": "^8.58.2",
|
|
82
|
+
"@typescript-eslint/parser": "^8.58.2",
|
|
79
83
|
"assert-never": "^1.4.0",
|
|
80
84
|
"babel-import-util": "^3.0.0",
|
|
81
85
|
"babel-plugin-ember-template-compilation": "^3.0.1",
|
|
@@ -84,22 +88,22 @@
|
|
|
84
88
|
"ember-cli-htmlbars": "^6.3.0",
|
|
85
89
|
"ember-resolver": "^13.1.1",
|
|
86
90
|
"ember-source": "^6.12.0",
|
|
87
|
-
"@glimmer/component": "^2.0.0",
|
|
88
91
|
"ember-template-lint": "^7.9.3",
|
|
89
|
-
"eslint": "^9.
|
|
92
|
+
"eslint": "^9.39.4",
|
|
90
93
|
"eslint-config-prettier": "^10.1.8",
|
|
91
94
|
"eslint-plugin-ember": "^12.7.5",
|
|
92
|
-
"eslint-plugin-n": "^17.
|
|
95
|
+
"eslint-plugin-n": "^17.24.0",
|
|
93
96
|
"eslint-plugin-prettier": "^5.5.5",
|
|
94
97
|
"execa": "^9.6.1",
|
|
95
98
|
"fs-extra": "^11.3.2",
|
|
99
|
+
"globals": "^17.5.0",
|
|
96
100
|
"playwright-chromium": "^1.59.1",
|
|
97
101
|
"prettier": "^3.8.1",
|
|
98
|
-
"prettier-plugin-ember-template-tag": "^2.1.
|
|
102
|
+
"prettier-plugin-ember-template-tag": "^2.1.3",
|
|
99
103
|
"puppeteer-chromium-resolver": "^24.0.2",
|
|
100
104
|
"rollup": "^4.53.3",
|
|
101
105
|
"source-map-url": "^0.4.1",
|
|
102
|
-
"strip-ansi": "^7.
|
|
106
|
+
"strip-ansi": "^7.2.0",
|
|
103
107
|
"style-loader": "^4.0.0",
|
|
104
108
|
"supports-color": "^10.2.2",
|
|
105
109
|
"terser": "^5.46.1",
|