ember-vite-hmr 2.0.4 → 2.0.5
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/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
|
|
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
|
-
|
|
179
|
-
|
|
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,
|
|
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) {
|
|
@@ -29,86 +29,6 @@ function getLatestChange(obj) {
|
|
|
29
29
|
}
|
|
30
30
|
return obj;
|
|
31
31
|
}
|
|
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
32
|
let ViteHotReloadService = (_dec = service(), _class = class ViteHotReloadService extends Service {
|
|
113
33
|
constructor(...args) {
|
|
114
34
|
super(...args);
|
|
@@ -119,8 +39,8 @@ let ViteHotReloadService = (_dec = service(), _class = class ViteHotReloadServic
|
|
|
119
39
|
if (!window.emberHotReloadPlugin) return;
|
|
120
40
|
const app = getOwner(this).application;
|
|
121
41
|
window.emberHotReloadPlugin.Resolver = app.Resolver;
|
|
122
|
-
modulePrefix = app.modulePrefix;
|
|
123
|
-
podModulePrefix = app.podModulePrefix;
|
|
42
|
+
window.emberHotReloadPlugin.modulePrefix = app.modulePrefix;
|
|
43
|
+
window.emberHotReloadPlugin.podModulePrefix = app.podModulePrefix;
|
|
124
44
|
this.router._router;
|
|
125
45
|
Object.defineProperty(this.router._router, '_routerMicrolib', {
|
|
126
46
|
set(v) {
|
|
@@ -148,7 +68,7 @@ let ViteHotReloadService = (_dec = service(), _class = class ViteHotReloadServic
|
|
|
148
68
|
if (oldModule.id.startsWith('app/templates/') && !oldModule.id.startsWith('app/templates/components/')) {
|
|
149
69
|
changed = true;
|
|
150
70
|
}
|
|
151
|
-
if (oldModule.id.startsWith(`./${podModulePrefix}/`)) {
|
|
71
|
+
if (oldModule.id.startsWith(`./${window.emberHotReloadPlugin.podModulePrefix}/`)) {
|
|
152
72
|
changed = true;
|
|
153
73
|
}
|
|
154
74
|
if (!changed) return;
|
|
@@ -188,7 +108,7 @@ let ViteHotReloadService = (_dec = service(), _class = class ViteHotReloadServic
|
|
|
188
108
|
if (oldModule.id.startsWith('app/templates/') && !oldModule.id.startsWith('app/templates/components/')) {
|
|
189
109
|
this.router.refresh();
|
|
190
110
|
}
|
|
191
|
-
if (oldModule.id.startsWith(`./${podModulePrefix}/`)) {
|
|
111
|
+
if (oldModule.id.startsWith(`./${window.emberHotReloadPlugin.podModulePrefix}/`)) {
|
|
192
112
|
this.router.refresh();
|
|
193
113
|
}
|
|
194
114
|
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
|
|
2
|
+
if (import.meta.hot) {
|
|
3
|
+
const ModuleMap = new Map();
|
|
4
|
+
window.emberHotReloadPlugin = {
|
|
5
|
+
modulePrefix: '',
|
|
6
|
+
podModulePrefix: '',
|
|
7
|
+
Resolver: null,
|
|
8
|
+
_accepting: 0,
|
|
9
|
+
changed: {},
|
|
10
|
+
subscribers: [],
|
|
11
|
+
version: 1,
|
|
12
|
+
routerVersion: 1,
|
|
13
|
+
moduleDepCallbacks: {},
|
|
14
|
+
versionMap: {},
|
|
15
|
+
clear(module) {
|
|
16
|
+
this.moduleDepCallbacks[module.id] = {};
|
|
17
|
+
},
|
|
18
|
+
register(module, dep, callback) {
|
|
19
|
+
dep = dep.replace(new RegExp(`^${window.emberHotReloadPlugin.modulePrefix}/`), './');
|
|
20
|
+
this.moduleDepCallbacks[module.id][dep] = this.moduleDepCallbacks[module.id][dep] || [];
|
|
21
|
+
this.moduleDepCallbacks[module.id][dep].push(callback);
|
|
22
|
+
},
|
|
23
|
+
loadNew(oldModule, newModule) {
|
|
24
|
+
ModuleMap.set(newModule.id, newModule);
|
|
25
|
+
this.versionMap[newModule.id] = newModule.version;
|
|
26
|
+
const entry = Object.entries(this.Resolver.explicitModules).find(([name, module]) => module.default === oldModule.exports.default);
|
|
27
|
+
if (!entry) return;
|
|
28
|
+
this.Resolver.explicitModules[entry[0]] = newModule.exports;
|
|
29
|
+
},
|
|
30
|
+
__import(moduleUrl) {
|
|
31
|
+
return import(/* @vite-ignore */moduleUrl);
|
|
32
|
+
},
|
|
33
|
+
async canAcceptNew(moduleUrl) {
|
|
34
|
+
this._accepting += 1;
|
|
35
|
+
const m = await this.__import(moduleUrl);
|
|
36
|
+
const module = {
|
|
37
|
+
exports: m,
|
|
38
|
+
id: moduleUrl.split('?')[0].replace(/http:\/\/.*:[^\/]*\//, ''),
|
|
39
|
+
version: 0
|
|
40
|
+
};
|
|
41
|
+
this._accepting -= 1;
|
|
42
|
+
if (this._accepting === 0) {
|
|
43
|
+
setTimeout(() => this.notifyNew(), 0);
|
|
44
|
+
}
|
|
45
|
+
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)$/);
|
|
46
|
+
if (!ok) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (module.id.includes('templates') && module.id.includes('components')) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (ModuleMap.get(module.id)) {
|
|
53
|
+
this.changed[module.id] = {
|
|
54
|
+
old: ModuleMap.get(module.id),
|
|
55
|
+
new: module
|
|
56
|
+
};
|
|
57
|
+
} else {
|
|
58
|
+
ModuleMap.set(module.id, module);
|
|
59
|
+
}
|
|
60
|
+
module.version = this.version;
|
|
61
|
+
return true;
|
|
62
|
+
},
|
|
63
|
+
notifyNew() {
|
|
64
|
+
this.version += 1;
|
|
65
|
+
Object.values(this.changed).forEach(change => {
|
|
66
|
+
this.loadNew(change.old, change.new);
|
|
67
|
+
this.subscribers.forEach(fn => fn(change.old, change.new));
|
|
68
|
+
});
|
|
69
|
+
this.changed = {};
|
|
70
|
+
},
|
|
71
|
+
subscribe(fn) {
|
|
72
|
+
this.subscribers.push(fn);
|
|
73
|
+
},
|
|
74
|
+
unsubscribe(fn) {
|
|
75
|
+
const idx = this.subscribers.indexOf(fn);
|
|
76
|
+
if (idx >= 0) {
|
|
77
|
+
this.subscribers.splice(idx, 1);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=setup-ember-hmr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-ember-hmr.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-vite-hmr",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"ember-addon"
|
|
6
6
|
],
|
|
@@ -43,7 +43,7 @@
|
|
|
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.
|
|
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",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@babel/runtime": "^7.28.4",
|
|
60
60
|
"@embroider/addon-dev": "^8.1.0",
|
|
61
61
|
"@embroider/compat": "^4.1.8",
|
|
62
|
-
"@embroider/core": "^4.2.
|
|
62
|
+
"@embroider/core": "^4.2.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",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"@types/fs-extra": "^11.0.4",
|
|
74
74
|
"@types/lodash": "^4.17.20",
|
|
75
75
|
"@types/mini-css-extract-plugin": "^2.5.1",
|
|
76
|
-
"@types/node": "^24.10.
|
|
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",
|
|
@@ -97,16 +97,16 @@
|
|
|
97
97
|
"prettier": "^3.6.2",
|
|
98
98
|
"prettier-plugin-ember-template-tag": "^2.1.0",
|
|
99
99
|
"puppeteer-chromium-resolver": "^24.0.2",
|
|
100
|
-
"rollup": "^4.
|
|
100
|
+
"rollup": "^4.53.2",
|
|
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.
|
|
105
|
+
"terser": "^5.44.1",
|
|
106
106
|
"thread-loader": "^4.0.2",
|
|
107
107
|
"typescript": "^5.9.3",
|
|
108
|
-
"vite": "^7.2.
|
|
109
|
-
"vitest": "^4.0.
|
|
108
|
+
"vite": "^7.2.2",
|
|
109
|
+
"vitest": "^4.0.8"
|
|
110
110
|
},
|
|
111
111
|
"peerDependencies": {
|
|
112
112
|
"@embroider/compat": "*",
|