ember-vite-hmr 2.0.4 → 2.0.6

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.
@@ -1,4 +1,3 @@
1
-
2
1
  import Route from '@ember/routing/route';
3
2
  import Component from '@glimmer/component';
4
3
  import { getInternalComponentManager } from '@glimmer/manager';
@@ -1 +1 @@
1
- {"version":3,"file":"setup-hmr-manager.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
1
+ {"version":3,"file":"setup-hmr-manager.js","sources":["../../src/instance-initializers/setup-hmr-manager.ts"],"sourcesContent":["import Route from '@ember/routing/route';\nimport Controller from '@ember/controller';\nimport Component from '@glimmer/component';\n// @ts-ignore\nimport { getInternalComponentManager } from '@glimmer/manager';\n\ninterface HotComponent extends Component<{ __hot__?: any }> {\n __get_hot_state__?: () => Record<string, any>;\n}\n\ntype Mutable<T> = {\n -readonly [P in keyof T]: any;\n};\n\nfunction findPropertyDescriptor(component: Object, key: string) {\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, any> = {};\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 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 if (instance.args.__hot__) {\n const state =\n instance.__get_hot_state__?.() || instance.args.__hot__.getState?.();\n for (const k in state) {\n instance[k as keyof HotComponent] = state[k];\n }\n instance.args.__hot__.getState = () => getState(instance, ['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: any[]) {\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, any> = {};\n\n Route.prototype.setupController = function (...args: any[]) {\n const controller = args[0];\n // @ts-ignore\n const r = setupController.call(this, ...args);\n const fullRouteName = this.fullRouteName;\n const state = StateCache[fullRouteName] || {};\n const skip = ['_qpDelegate', 'target', 'queryParams'];\n const routerState = getState(state.router, skip);\n const controllerState = getState(state.controller, skip);\n for (const k in routerState) {\n (this as any)[k] = routerState[k];\n }\n for (const k in controllerState) {\n controller[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","writable","prototype","toString","call","value","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,CAACC,SAAiB,EAAEC,GAAW,EAAE;EAC9D,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,KAA0B,GAAG,EAAE;EACrC,IAAI,CAACT,SAAS,EAAE;AACd,IAAA,OAAOS,KAAK;AACd,EAAA;AACA,EAAA,KAAK,MAAMR,GAAG,IAAID,SAAS,EAAE;AAC3B,IAAA,IAAIQ,IAAI,CAACE,QAA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,MAAAA,KAAK,EAAE,IAAI;AACXN,MAAAA;KACD;AACD,IAAA,OAAOC,CAAC;EACV,CAAC;AACH;AAEA,sBAAe;AACbT,EAAAA;AACF,CAAC;;;;"}
@@ -1,6 +1,7 @@
1
-
2
1
  import { debounce, next } from '@ember/runloop';
3
2
 
3
+ /// <reference types="../../types/global" />
4
+
4
5
  function patchResolver(application) {
5
6
  application.__container__.lookup('service:vite-hot-reload');
6
7
  const resolver = application.__registry__.resolver?._fallback || (application.__registry__.fallback?.resolver)._fallback || application.__registry__.fallback?.resolver || application.__registry__.resolver;
@@ -11,7 +12,7 @@ function patchResolver(application) {
11
12
  };
12
13
  }
13
14
  function supportErrorRecovery(appInstance) {
14
- const bodyHtml = window.document.body.cloneNode(true);
15
+ const bodyHtml = globalThis.document.body.cloneNode(true);
15
16
  const renderer = appInstance.__container__.lookup('renderer:-dom');
16
17
  const router = appInstance.__container__.lookup('service:router');
17
18
  const warn = console.warn;
@@ -23,13 +24,15 @@ function supportErrorRecovery(appInstance) {
23
24
  applicationRouter._router._toplevelView.destroy();
24
25
  applicationRouter._router._toplevelView = null;
25
26
  renderer._clearAllRoots();
26
- window.document.body = bodyHtml.cloneNode(true);
27
+ globalThis.document.body = bodyHtml.cloneNode(true);
27
28
  next(() => {
28
29
  const transition = router.refresh();
29
30
  applicationRouter.setup(applicationRouter.context, transition);
30
31
  });
31
32
  }
32
- import.meta.hot?.on('vite:beforeUpdate', () => debounce(rerender, 100));
33
+ if (import.meta.hot) {
34
+ import.meta.hot.on('vite:beforeUpdate', () => debounce(rerender, 100));
35
+ }
33
36
  console.warn = function (...args) {
34
37
  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.')) {
35
38
  scheduleRerender = true;
@@ -1 +1 @@
1
- {"version":3,"file":"vite-hot-reload.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
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 any)?._fallback ||\n (application.__registry__.fallback?.resolver as any)._fallback ||\n (application.__registry__.fallback?.resolver as any) ||\n application.__registry__.resolver;\n const resolverResolve = resolver.resolve;\n resolver.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 = 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 any;\n applicationRouter._router._toplevelView.destroy();\n applicationRouter._router._toplevelView = null;\n (renderer as any)._clearAllRoots();\n globalThis.document.body = bodyHtml.cloneNode(true) as any;\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 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(console, ...args);\n };\n}\n\nexport function initialize(application: ApplicationInstance) {\n patchResolver(application);\n supportErrorRecovery(application);\n}\n\nexport default {\n initialize,\n};"],"names":["patchResolver","application","__container__","lookup","resolver","__registry__","_fallback","fallback","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,EAAUE,SAAS,IACrD,CAACL,WAAW,CAACI,YAAY,CAACE,QAAQ,EAAEH,QAAQ,EAASE,SAAS,IAC7DL,WAAW,CAACI,YAAY,CAACE,QAAQ,EAAEH,QAAgB,IACpDH,WAAW,CAACI,YAAY,CAACD,QAAQ;AACnC,EAAA,MAAMI,eAAe,GAAGJ,QAAQ,CAACK,OAAO;AACxCL,EAAAA,QAAQ,CAACK,OAAO,GAAG,UAAUC,IAAY,EAAE;IACzCA,IAAI,GAAGA,IAAI,CAACC,OAAO,CAAC,oBAAoB,EAAE,EAAE,CAAC;AAC7C,IAAA,OAAOH,eAAe,CAACI,IAAI,CAAC,IAAI,EAAEF,IAAI,CAAC;EACzC,CAAC;AACH;AAEA,SAASG,oBAAoBA,CAACC,WAAgC,EAAE;EAC9D,MAAMC,QAAQ,GAAGC,UAAU,CAACC,QAAQ,CAACC,IAAI,CAACC,SAAS,CAAC,IAAI,CAAC;EACzD,MAAMC,QAAQ,GAAGN,WAAW,CAACZ,aAAa,CAACC,MAAM,CAC/C,eACF,CAAa;EACb,MAAMkB,MAAM,GAAGP,WAAW,CAACZ,aAAa,CAACC,MAAM,CAC7C,gBACF,CAAkB;AAClB,EAAA,MAAMmB,IAAI,GAAGC,OAAO,CAACD,IAAI;EACzB,IAAIE,gBAAgB,GAAG,KAAK;EAC5B,eAAeC,QAAQA,GAAG;IACxB,IAAI,CAACD,gBAAgB,EAAE;AACvBA,IAAAA,gBAAgB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
267
  const lastImportIndex = // @ts-ignore
268
268
  path.node.body.findLastIndex((e) => e.type === 'ImportDeclaration') + 1;
269
- path.node.body.splice(Math.max(varDeclaration, lastImportIndex), 0, assign);
269
+ path.node.body.splice(Math.max(varDeclaration, lastImportIndex), 0, t.expressionStatement(assign));
270
270
  // Export metadata about tracked imports for hmr.ts to use
271
271
  const importMetadata = t.variableDeclaration('const', [
272
272
  t.variableDeclarator(t.identifier('__hmr_import_metadata__'), t.objectExpression([
package/dist/lib/hmr.js CHANGED
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.hmr = hmr;
16
16
  const path_1 = __importDefault(require("path"));
17
17
  const core_1 = require("@babel/core");
18
- const fs_1 = require("fs");
18
+ const promises_1 = require("fs/promises");
19
19
  function generateContent(yields) {
20
20
  if (!yields.includes('default')) {
21
21
  yields.push('default');
@@ -124,6 +124,9 @@ function hmr(enableViteHmrForModes = ['development']) {
124
124
  },
125
125
  resolveId(id, importer, meta) {
126
126
  return __awaiter(this, void 0, void 0, function* () {
127
+ if (id.includes('@ember-vite-hmr/setup-ember-hmr.js')) {
128
+ return id;
129
+ }
127
130
  if (importer === null || importer === void 0 ? void 0 : importer.startsWith(virtualPrefix)) {
128
131
  importer = path_1.default.join(process.cwd(), 'package.json');
129
132
  return this.resolve(id, importer, meta);
@@ -146,6 +149,9 @@ function hmr(enableViteHmrForModes = ['development']) {
146
149
  },
147
150
  load(id) {
148
151
  return __awaiter(this, void 0, void 0, function* () {
152
+ if (id.includes('@ember-vite-hmr/setup-ember-hmr.js')) {
153
+ return yield (0, promises_1.readFile)(path_1.default.resolve(__dirname, '..', 'setup-ember-hmr.js'), 'utf8');
154
+ }
149
155
  if (id.startsWith(virtualPrefix)) {
150
156
  if (!server) {
151
157
  // During build, server is not available
@@ -175,8 +181,14 @@ function hmr(enableViteHmrForModes = ['development']) {
175
181
  if (process.env['EMBER_VITE_HMR_ENABLED'] !== 'true') {
176
182
  return html;
177
183
  }
178
- return (`<script type="module" src="/ember-vite-hmr/services/vite-hot-reload" />` +
179
- html);
184
+ const fullPath = '/@ember-vite-hmr/setup-ember-hmr.js';
185
+ return [
186
+ {
187
+ tag: 'script',
188
+ attrs: { type: 'module' },
189
+ children: `import "${fullPath}"`,
190
+ },
191
+ ];
180
192
  },
181
193
  handleHotUpdate(ctx) {
182
194
  if (!ctx.file.split('?')[0].endsWith('.hbs')) {
@@ -201,7 +213,7 @@ function hmr(enableViteHmrForModes = ['development']) {
201
213
  return __awaiter(this, void 0, void 0, function* () {
202
214
  if (options.type === 'update' || options.type === 'create') {
203
215
  const id = options.file;
204
- const source = (0, fs_1.readFileSync)(id).toString();
216
+ const source = (yield (0, promises_1.readFile)(id)).toString();
205
217
  if (cachedYields[id] &&
206
218
  difference(cachedYields[id].yields, getYieldsFromFile(id, source, true).yields).length) {
207
219
  for (const y of getYieldsFromFile(id, source).yields) {
@@ -237,7 +249,7 @@ function hmr(enableViteHmrForModes = ['development']) {
237
249
  import.meta.hot.accept('@embroider/virtual/compat-modules', (m) => {
238
250
  for (const [name, module] of Object.entries(m.default)) {
239
251
  if (name.includes('initializers') && prevCompatModules[name]?.default !== module.default) {
240
- window.location.reload();
252
+ globalThis.location.reload();
241
253
  }
242
254
  }
243
255
  prevCompatModules = m.default;
@@ -382,8 +394,8 @@ ${hotReloadStatements.join('\n')}
382
394
  return source;
383
395
  }
384
396
  return `${source}
385
- if (import.meta.hot && window.emberHotReloadPlugin) {
386
- const result = window.emberHotReloadPlugin.canAcceptNew(import.meta.url);
397
+ if (import.meta.hot && globalThis.emberHotReloadPlugin) {
398
+ const result = globalThis.emberHotReloadPlugin.canAcceptNew(import.meta.url);
387
399
  result.then(() => {
388
400
  if (!result) {
389
401
  import.meta.hot.decline();
@@ -1,4 +1,3 @@
1
-
2
1
  import Service, { service } from '@ember/service';
3
2
  import { getOwner } from '@ember/owner';
4
3
  import Route from '@ember/routing/route';
@@ -29,86 +28,6 @@ function getLatestChange(obj) {
29
28
  }
30
29
  return obj;
31
30
  }
32
- let modulePrefix;
33
- let podModulePrefix;
34
- if (import.meta.hot) {
35
- const ModuleMap = new Map();
36
- window.emberHotReloadPlugin = {
37
- Resolver: null,
38
- _accepting: 0,
39
- changed: {},
40
- subscribers: [],
41
- version: 1,
42
- routerVersion: 1,
43
- moduleDepCallbacks: {},
44
- versionMap: {},
45
- clear(module) {
46
- this.moduleDepCallbacks[module.id] = {};
47
- },
48
- register(module, dep, callback) {
49
- dep = dep.replace(new RegExp(`^${modulePrefix}/`), './');
50
- this.moduleDepCallbacks[module.id][dep] = this.moduleDepCallbacks[module.id][dep] || [];
51
- this.moduleDepCallbacks[module.id][dep].push(callback);
52
- },
53
- loadNew(oldModule, newModule) {
54
- ModuleMap.set(newModule.id, newModule);
55
- this.versionMap[newModule.id] = newModule.version;
56
- const entry = Object.entries(this.Resolver.explicitModules).find(([name, module]) => module.default === oldModule.exports.default);
57
- if (!entry) return;
58
- this.Resolver.explicitModules[entry[0]] = newModule.exports;
59
- },
60
- __import(moduleUrl) {
61
- return import(/* @vite-ignore */moduleUrl);
62
- },
63
- async canAcceptNew(moduleUrl) {
64
- this._accepting += 1;
65
- const m = await this.__import(moduleUrl);
66
- const module = {
67
- exports: m,
68
- id: moduleUrl.split('?')[0].replace(/http:\/\/.*:[^\/]*\//, ''),
69
- version: 0
70
- };
71
- this._accepting -= 1;
72
- if (this._accepting === 0) {
73
- setTimeout(() => this.notifyNew(), 0);
74
- }
75
- 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)$/);
76
- if (!ok) {
77
- return false;
78
- }
79
- if (module.id.includes('templates') && module.id.includes('components')) {
80
- return false;
81
- }
82
- if (ModuleMap.get(module.id)) {
83
- this.changed[module.id] = {
84
- old: ModuleMap.get(module.id),
85
- new: module
86
- };
87
- } else {
88
- ModuleMap.set(module.id, module);
89
- }
90
- module.version = this.version;
91
- return true;
92
- },
93
- notifyNew() {
94
- this.version += 1;
95
- Object.values(this.changed).forEach(change => {
96
- this.loadNew(change.old, change.new);
97
- this.subscribers.forEach(fn => fn(change.old, change.new));
98
- });
99
- this.changed = {};
100
- },
101
- subscribe(fn) {
102
- this.subscribers.push(fn);
103
- },
104
- unsubscribe(fn) {
105
- const idx = this.subscribers.indexOf(fn);
106
- if (idx >= 0) {
107
- this.subscribers.splice(idx, 1);
108
- }
109
- }
110
- };
111
- }
112
31
  let ViteHotReloadService = (_dec = service(), _class = class ViteHotReloadService extends Service {
113
32
  constructor(...args) {
114
33
  super(...args);
@@ -116,17 +35,17 @@ let ViteHotReloadService = (_dec = service(), _class = class ViteHotReloadServic
116
35
  }
117
36
  init(args) {
118
37
  super.init(args);
119
- if (!window.emberHotReloadPlugin) return;
38
+ if (!globalThis.emberHotReloadPlugin) return;
120
39
  const app = getOwner(this).application;
121
- window.emberHotReloadPlugin.Resolver = app.Resolver;
122
- modulePrefix = app.modulePrefix;
123
- podModulePrefix = app.podModulePrefix;
40
+ globalThis.emberHotReloadPlugin.Resolver = app.Resolver;
41
+ globalThis.emberHotReloadPlugin.modulePrefix = app.modulePrefix;
42
+ globalThis.emberHotReloadPlugin.podModulePrefix = app.podModulePrefix;
124
43
  this.router._router;
125
44
  Object.defineProperty(this.router._router, '_routerMicrolib', {
126
45
  set(v) {
127
46
  const getRoute = v.getRoute;
128
47
  v.getRoute = function (name) {
129
- const route = getRoute.call(this, `${name}--hot-version--${window.emberHotReloadPlugin.routerVersion}`);
48
+ const route = getRoute.call(this, `${name}--hot-version--${globalThis.emberHotReloadPlugin.routerVersion}`);
130
49
  route.fullRouteName = `${name}`.replace(/--hot-version--.*$/, '');
131
50
  return route;
132
51
  };
@@ -137,7 +56,7 @@ let ViteHotReloadService = (_dec = service(), _class = class ViteHotReloadServic
137
56
  }
138
57
  });
139
58
  this.container = getOwner(this)?.__container__;
140
- window.emberHotReloadPlugin.subscribe((oldModule, newModule) => {
59
+ globalThis.emberHotReloadPlugin.subscribe((oldModule, newModule) => {
141
60
  let changed = false;
142
61
  if (oldModule.exports.default?.prototype && oldModule.exports.default.prototype instanceof Route) {
143
62
  changed = true;
@@ -148,33 +67,33 @@ let ViteHotReloadService = (_dec = service(), _class = class ViteHotReloadServic
148
67
  if (oldModule.id.startsWith('app/templates/') && !oldModule.id.startsWith('app/templates/components/')) {
149
68
  changed = true;
150
69
  }
151
- if (oldModule.id.startsWith(`./${podModulePrefix}/`)) {
70
+ if (oldModule.id.startsWith(`./${globalThis.emberHotReloadPlugin.podModulePrefix}/`)) {
152
71
  changed = true;
153
72
  }
154
73
  if (!changed) return;
155
- window.emberHotReloadPlugin.routerVersion += 1;
74
+ globalThis.emberHotReloadPlugin.routerVersion += 1;
156
75
  const types = ['route', 'controller', 'template', 'modifier', 'helper', 'component'];
157
76
  Object.keys(this.container.cache).forEach(k => {
158
77
  if (types.some(t => k.startsWith(`${t}:`))) {
159
78
  delete this.container.cache[k];
160
79
  }
161
80
  });
162
- Object.keys(this.container.factoryManagerCache).forEach(k => {
81
+ Object.keys(this.container.factoryManagerCache || {}).forEach(k => {
163
82
  if (types.some(t => k.startsWith(`${t}:`))) {
164
83
  delete this.container.factoryManagerCache[k];
165
84
  }
166
85
  });
167
- Object.keys(this.container.registry._resolveCache).forEach(k => {
86
+ Object.keys(this.container.registry._resolveCache || {}).forEach(k => {
168
87
  if (types.some(t => k.startsWith(`${t}:`))) {
169
88
  delete this.container.registry._resolveCache[k];
170
89
  }
171
90
  });
172
- Object.keys(this.container.validationCache).forEach(k => {
91
+ Object.keys(this.container.validationCache || {}).forEach(k => {
173
92
  if (types.some(t => k.startsWith(`${t}:`))) {
174
93
  delete this.container.validationCache[k];
175
94
  }
176
95
  });
177
- Object.keys(this.container.registry.registrations).forEach(k => {
96
+ Object.keys(this.container.registry.registrations || {}).forEach(k => {
178
97
  if (types.some(t => k.startsWith(`${t}:`))) {
179
98
  delete this.container.registry.registrations[k];
180
99
  }
@@ -188,7 +107,7 @@ let ViteHotReloadService = (_dec = service(), _class = class ViteHotReloadServic
188
107
  if (oldModule.id.startsWith('app/templates/') && !oldModule.id.startsWith('app/templates/components/')) {
189
108
  this.router.refresh();
190
109
  }
191
- if (oldModule.id.startsWith(`./${podModulePrefix}/`)) {
110
+ if (oldModule.id.startsWith(`./${globalThis.emberHotReloadPlugin.podModulePrefix}/`)) {
192
111
  this.router.refresh();
193
112
  }
194
113
  });
@@ -1 +1 @@
1
- {"version":3,"file":"vite-hot-reload.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
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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BAAA,CAAAvD,MAAA,CAAAqC,SAAA,EAAA,QAAA,EAAA,CAAAvC,IAAA,CAAA,EAAA;EAAA0D,YAAA,EAAA,IAAA;EAAAC,UAAA,EAAA,IAAA;EAAAC,QAAA,EAAA,IAAA;EAAAC,WAAA,EAAA;AAAA,CAAA,CAAA,EAAA3D,MAAA;AAGD;AACA;AACA;;;;"}
@@ -0,0 +1,83 @@
1
+ /// <reference types="../types/global" />
2
+
3
+ if (import.meta.hot) {
4
+ const ModuleMap = new Map();
5
+ globalThis.emberHotReloadPlugin = {
6
+ modulePrefix: '',
7
+ podModulePrefix: '',
8
+ Resolver: null,
9
+ _accepting: 0,
10
+ changed: {},
11
+ subscribers: [],
12
+ version: 1,
13
+ routerVersion: 1,
14
+ moduleDepCallbacks: {},
15
+ versionMap: {},
16
+ clear(module) {
17
+ this.moduleDepCallbacks[module.id] = {};
18
+ },
19
+ register(module, dep, callback) {
20
+ dep = dep.replace(new RegExp(`^${globalThis.emberHotReloadPlugin.modulePrefix}/`), './');
21
+ this.moduleDepCallbacks[module.id][dep] = this.moduleDepCallbacks[module.id][dep] || [];
22
+ this.moduleDepCallbacks[module.id][dep].push(callback);
23
+ },
24
+ loadNew(oldModule, newModule) {
25
+ ModuleMap.set(newModule.id, newModule);
26
+ this.versionMap[newModule.id] = newModule.version;
27
+ const entry = Object.entries(this.Resolver.explicitModules).find(([name, module]) => module.default === oldModule.exports.default);
28
+ if (!entry) return;
29
+ this.Resolver.explicitModules[entry[0]] = newModule.exports;
30
+ },
31
+ __import(moduleUrl) {
32
+ return import(/* @vite-ignore */moduleUrl);
33
+ },
34
+ async canAcceptNew(moduleUrl) {
35
+ this._accepting += 1;
36
+ const m = await this.__import(moduleUrl);
37
+ const module = {
38
+ exports: m,
39
+ id: moduleUrl.split('?')[0].replace(/http:\/\/.*:[^\/]*\//, ''),
40
+ version: 0
41
+ };
42
+ this._accepting -= 1;
43
+ if (this._accepting === 0) {
44
+ setTimeout(() => this.notifyNew(), 0);
45
+ }
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)$/);
47
+ if (!ok) {
48
+ return false;
49
+ }
50
+ if (module.id.includes('templates') && module.id.includes('components')) {
51
+ return false;
52
+ }
53
+ if (ModuleMap.get(module.id)) {
54
+ this.changed[module.id] = {
55
+ old: ModuleMap.get(module.id),
56
+ new: module
57
+ };
58
+ } else {
59
+ ModuleMap.set(module.id, module);
60
+ }
61
+ module.version = this.version;
62
+ return true;
63
+ },
64
+ notifyNew() {
65
+ this.version += 1;
66
+ Object.values(this.changed).forEach(change => {
67
+ this.loadNew(change.old, change.new);
68
+ this.subscribers.forEach(fn => fn(change.old, change.new));
69
+ });
70
+ this.changed = {};
71
+ },
72
+ subscribe(fn) {
73
+ this.subscribers.push(fn);
74
+ },
75
+ unsubscribe(fn) {
76
+ const idx = this.subscribers.indexOf(fn);
77
+ if (idx >= 0) {
78
+ this.subscribers.splice(idx, 1);
79
+ }
80
+ }
81
+ };
82
+ }
83
+ //# sourceMappingURL=setup-ember-hmr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup-ember-hmr.js","sources":["../src/setup-ember-hmr.ts"],"sourcesContent":["/// <reference types=\"../types/global\" />\n\nimport 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: Function) {\n dep = dep.replace(new RegExp(`^${globalThis.emberHotReloadPlugin.modulePrefix}/`), './');\n this.moduleDepCallbacks[module.id]![dep] =\n this.moduleDepCallbacks[module.id]![dep] || ([] as Function[]);\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, any>,\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 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.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 (Object.values(this.changed) as Array<{ old: Module; new: Module }>).forEach((change) => {\n this.loadNew(change.old, change.new);\n this.subscribers.forEach((fn: any) => fn(change.old, change.new));\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":"AAAA;;AAIA,IAAIA,MAAM,CAACC,IAAI,CAACC,GAAG,EAAE;AACjB,EAAA,MAAMC,SAAS,GAAG,IAAIC,GAAG,EAAE;EAE3BC,UAAU,CAACC,oBAAoB,GAAG;AAC9BC,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;MAClB,IAAI,CAACH,kBAAkB,CAACG,MAAM,CAACC,EAAE,CAAC,GAAG,EAAE;IAC3C,CAAC;AACDC,IAAAA,QAAQA,CAACF,MAAc,EAAEG,GAAW,EAAEC,QAAkB,EAAE;AACtDD,MAAAA,GAAG,GAAGA,GAAG,CAACE,OAAO,CAAC,IAAIC,MAAM,CAAC,CAAA,CAAA,EAAInB,UAAU,CAACC,oBAAoB,CAACC,YAAY,GAAG,CAAC,EAAE,IAAI,CAAC;MACxF,IAAI,CAACQ,kBAAkB,CAACG,MAAM,CAACC,EAAE,CAAC,CAAEE,GAAG,CAAC,GACpC,IAAI,CAACN,kBAAkB,CAACG,MAAM,CAACC,EAAE,CAAC,CAAEE,GAAG,CAAC,IAAK,EAAiB;AAClE,MAAA,IAAI,CAACN,kBAAkB,CAACG,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,CAAC,IAAI,CAACxC,OAAO,CAAC,CAAyCyC,OAAO,CAAEC,MAAM,IAAK;QACrF,IAAI,CAAC3B,OAAO,CAAC2B,MAAM,CAACJ,GAAG,EAAEI,MAAM,CAACH,GAAG,CAAC;AACpC,QAAA,IAAI,CAACtC,WAAW,CAACwC,OAAO,CAAEE,EAAO,IAAKA,EAAE,CAACD,MAAM,CAACJ,GAAG,EAAEI,MAAM,CAACH,GAAG,CAAC,CAAC;AACrE,MAAA,CAAC,CAAC;AACF,MAAA,IAAI,CAACvC,OAAO,GAAG,EAAE;IACrB,CAAC;IACD4C,SAASA,CAACD,EAAkD,EAAE;AAC1D,MAAA,IAAI,CAAC1C,WAAW,CAACa,IAAI,CAAC6B,EAAE,CAAC;IAC7B,CAAC;IACDE,WAAWA,CAACF,EAAkD,EAAE;MAC5D,MAAMG,GAAG,GAAG,IAAI,CAAC7C,WAAW,CAAC8C,OAAO,CAACJ,EAAE,CAAC;MACxC,IAAIG,GAAG,IAAI,CAAC,EAAE;QACV,IAAI,CAAC7C,WAAW,CAAC+C,MAAM,CAACF,GAAG,EAAE,CAAC,CAAC;AACnC,MAAA;AACJ,IAAA;GACH;AACL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-vite-hmr",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "keywords": [
5
5
  "ember-addon"
6
6
  ],
@@ -39,15 +39,15 @@
39
39
  "prepack": "pnpm build || echo 'its okay'"
40
40
  },
41
41
  "dependencies": {
42
- "@babel/core": "^7.28.0",
42
+ "@babel/core": "^7.28.5",
43
43
  "@babel/plugin-transform-typescript": "^7.28.5",
44
44
  "@babel/traverse": "^7.28.5",
45
45
  "@babel/types": "^7.28.5",
46
- "@embroider/addon-shim": "^1.10.0",
46
+ "@embroider/addon-shim": "^1.10.2",
47
47
  "@glimmer/syntax": "^0.95.0",
48
48
  "@types/supports-color": "^10.0.0",
49
49
  "babel-import-util": "^3.0.0",
50
- "babel-loader": "^10.0.0",
50
+ "babel-loader": "^10.1.1",
51
51
  "babel-preset-env": "^1.7.0",
52
52
  "semver": "^7.7.3"
53
53
  },
@@ -57,56 +57,56 @@
57
57
  "@babel/plugin-proposal-decorators": "^7.28.0",
58
58
  "@babel/plugin-transform-class-static-block": "^7.28.3",
59
59
  "@babel/runtime": "^7.28.4",
60
- "@embroider/addon-dev": "^8.1.0",
61
- "@embroider/compat": "^4.1.8",
62
- "@embroider/core": "^4.2.5",
60
+ "@embroider/addon-dev": "^8.3.0",
61
+ "@embroider/compat": "^4.1.17",
62
+ "@embroider/core": "^4.4.7",
63
63
  "@glint/core": "^1.2.0",
64
64
  "@glint/environment-ember-loose": "^1.5.2",
65
65
  "@glint/environment-ember-template-imports": "^1.5.2",
66
- "@glint/template": "^1.7.0",
67
- "@rollup/plugin-babel": "^6.1.0",
68
- "@tsconfig/ember": "^3.0.11",
66
+ "@glint/template": "^1.7.3",
67
+ "@rollup/plugin-babel": "^7.0.0",
68
+ "@tsconfig/ember": "^3.0.12",
69
69
  "@types/babel__core": "^7.20.3",
70
70
  "@types/babel__traverse": "^7.28.0",
71
71
  "@types/csso": "^5.0.4",
72
72
  "@types/debug": "^4.1.5",
73
73
  "@types/fs-extra": "^11.0.4",
74
- "@types/lodash": "^4.17.20",
74
+ "@types/lodash": "^4.17.21",
75
75
  "@types/mini-css-extract-plugin": "^2.5.1",
76
- "@types/node": "^24.10.0",
76
+ "@types/node": "^24.10.1",
77
77
  "@types/rsvp": "^4.0.9",
78
78
  "@types/semver": "^7.7.1",
79
79
  "assert-never": "^1.4.0",
80
80
  "babel-import-util": "^3.0.0",
81
81
  "babel-plugin-ember-template-compilation": "^3.0.1",
82
82
  "concurrently": "^9.2.1",
83
- "content-tag": "^2.0.1",
83
+ "content-tag": "^4.0.0",
84
84
  "ember-cli-htmlbars": "^6.3.0",
85
85
  "ember-resolver": "^13.1.1",
86
- "ember-source": "^6.8.1",
86
+ "ember-source": "^6.12.0",
87
87
  "@glimmer/component": "^2.0.0",
88
88
  "ember-template-lint": "^7.9.3",
89
89
  "eslint": "^9.38.0",
90
90
  "eslint-config-prettier": "^10.1.8",
91
- "eslint-plugin-ember": "^12.7.4",
91
+ "eslint-plugin-ember": "^12.7.5",
92
92
  "eslint-plugin-n": "^17.23.1",
93
- "eslint-plugin-prettier": "^5.5.4",
94
- "execa": "^9.6.0",
93
+ "eslint-plugin-prettier": "^5.5.5",
94
+ "execa": "^9.6.1",
95
95
  "fs-extra": "^11.3.2",
96
- "playwright-chromium": "^1.56.1",
97
- "prettier": "^3.6.2",
98
- "prettier-plugin-ember-template-tag": "^2.1.0",
96
+ "playwright-chromium": "^1.59.1",
97
+ "prettier": "^3.8.1",
98
+ "prettier-plugin-ember-template-tag": "^2.1.2",
99
99
  "puppeteer-chromium-resolver": "^24.0.2",
100
- "rollup": "^4.52.5",
100
+ "rollup": "^4.53.3",
101
101
  "source-map-url": "^0.4.1",
102
102
  "strip-ansi": "^7.1.2",
103
103
  "style-loader": "^4.0.0",
104
104
  "supports-color": "^10.2.2",
105
- "terser": "^5.44.0",
105
+ "terser": "^5.46.1",
106
106
  "thread-loader": "^4.0.2",
107
107
  "typescript": "^5.9.3",
108
- "vite": "^7.2.0",
109
- "vitest": "^4.0.7"
108
+ "vite": "^7.2.6",
109
+ "vitest": "^4.1.2"
110
110
  },
111
111
  "peerDependencies": {
112
112
  "@embroider/compat": "*",