ember-vite-hmr 0.6.2 → 0.6.4
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/babel-plugin.d.ts +4 -5
- package/dist/lib/babel-plugin.js +16 -28
- package/dist/lib/hmr.d.ts +1 -0
- package/dist/lib/hmr.js +24 -13
- package/package.json +3 -1
|
@@ -9,17 +9,16 @@ declare class HotAstProcessor {
|
|
|
9
9
|
};
|
|
10
10
|
counter: number;
|
|
11
11
|
meta: {
|
|
12
|
-
usedImports:
|
|
12
|
+
usedImports: Set<unknown>;
|
|
13
13
|
importVar: any;
|
|
14
14
|
};
|
|
15
|
+
private usedImports;
|
|
15
16
|
transform(env: ASTPluginEnvironment): {
|
|
16
17
|
visitor: glimmer.NodeVisitor;
|
|
17
18
|
};
|
|
18
|
-
buildVisitor({ importVar, imports,
|
|
19
|
+
buildVisitor({ importVar, imports, usedImports }: {
|
|
19
20
|
importVar: any;
|
|
20
21
|
imports: any;
|
|
21
|
-
changes: any;
|
|
22
|
-
hotReplaced: any;
|
|
23
22
|
usedImports: any;
|
|
24
23
|
}): glimmer.NodeVisitor;
|
|
25
24
|
replaceInAst(ast: glimmer.ASTv1.Template, importVar?: string, imports?: string[]): Set<unknown>;
|
|
@@ -28,5 +27,5 @@ declare class HotAstProcessor {
|
|
|
28
27
|
export declare const hotAstProcessor: HotAstProcessor;
|
|
29
28
|
export default function hotReplaceAst({ types: t }: {
|
|
30
29
|
types: BabelTypes;
|
|
31
|
-
}
|
|
30
|
+
}): PluginObj<import("@babel/core").PluginPass>;
|
|
32
31
|
export {};
|
package/dist/lib/babel-plugin.js
CHANGED
|
@@ -84,7 +84,7 @@ class HotAstProcessor {
|
|
|
84
84
|
};
|
|
85
85
|
this.counter = 0;
|
|
86
86
|
this.meta = {
|
|
87
|
-
usedImports:
|
|
87
|
+
usedImports: new Set(),
|
|
88
88
|
importVar: null,
|
|
89
89
|
};
|
|
90
90
|
}
|
|
@@ -109,12 +109,11 @@ class HotAstProcessor {
|
|
|
109
109
|
visitor: this.buildVisitor({
|
|
110
110
|
importVar,
|
|
111
111
|
imports,
|
|
112
|
-
changes: [],
|
|
113
112
|
usedImports,
|
|
114
113
|
}),
|
|
115
114
|
};
|
|
116
115
|
}
|
|
117
|
-
buildVisitor({ importVar, imports,
|
|
116
|
+
buildVisitor({ importVar, imports, usedImports }) {
|
|
118
117
|
const findBlockParams = function (expression, p) {
|
|
119
118
|
if (p.node &&
|
|
120
119
|
p.node.type === 'BlockStatement' &&
|
|
@@ -136,15 +135,16 @@ class HotAstProcessor {
|
|
|
136
135
|
p.parentNode.params.includes(node)) {
|
|
137
136
|
return;
|
|
138
137
|
}
|
|
139
|
-
|
|
138
|
+
const original = node.original.split('.')[0];
|
|
139
|
+
if (original === 'this')
|
|
140
140
|
return;
|
|
141
|
-
if (
|
|
141
|
+
if (original.startsWith('@'))
|
|
142
142
|
return;
|
|
143
|
-
if (
|
|
143
|
+
if (original === 'block')
|
|
144
144
|
return;
|
|
145
|
-
if (
|
|
145
|
+
if (original.startsWith('this.'))
|
|
146
146
|
return;
|
|
147
|
-
if (findBlockParams(
|
|
147
|
+
if (findBlockParams(original, p))
|
|
148
148
|
return;
|
|
149
149
|
const params = [];
|
|
150
150
|
const blockParams = [];
|
|
@@ -152,14 +152,14 @@ class HotAstProcessor {
|
|
|
152
152
|
if (node.original === 'helper' ||
|
|
153
153
|
node.original === 'component' ||
|
|
154
154
|
node.original === 'modifier') {
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
const original = p.parentNode.params[0].original.split('.')[0];
|
|
156
|
+
if (original &&
|
|
157
|
+
findBlockParams(original, p))
|
|
157
158
|
return;
|
|
158
|
-
if (
|
|
159
|
+
if (original?.includes('.'))
|
|
159
160
|
return;
|
|
160
|
-
if (!
|
|
161
|
+
if (!original)
|
|
161
162
|
return;
|
|
162
|
-
const original = p.parentNode.params[0].original;
|
|
163
163
|
const param = glimmer.builders.path(`${importVar}.${original}`);
|
|
164
164
|
p.parentNode.params.splice(0, 1);
|
|
165
165
|
p.parentNode.params.push(param);
|
|
@@ -169,7 +169,7 @@ class HotAstProcessor {
|
|
|
169
169
|
if (importVar) {
|
|
170
170
|
if (imports.includes(node.original)) {
|
|
171
171
|
usedImports.add(node.original);
|
|
172
|
-
node.original = `${importVar}.${node.original
|
|
172
|
+
node.original = `${importVar}.${original}` + node.original.split('.').slice(1).join('.');
|
|
173
173
|
node.parts = node.original.split('.');
|
|
174
174
|
}
|
|
175
175
|
return;
|
|
@@ -205,23 +205,12 @@ class HotAstProcessor {
|
|
|
205
205
|
modifiers: {},
|
|
206
206
|
},
|
|
207
207
|
};
|
|
208
|
-
const changes = [];
|
|
209
208
|
const visitor = this.buildVisitor({
|
|
210
209
|
importVar,
|
|
211
210
|
imports,
|
|
212
|
-
changes,
|
|
213
|
-
hotReplaced,
|
|
214
211
|
usedImports,
|
|
215
212
|
});
|
|
216
213
|
glimmer.traverse(ast, visitor);
|
|
217
|
-
const program = ast;
|
|
218
|
-
let body = [...program.body];
|
|
219
|
-
for (const letBlock of changes) {
|
|
220
|
-
letBlock.program.body = body;
|
|
221
|
-
body = [letBlock];
|
|
222
|
-
}
|
|
223
|
-
program.body.length = 0;
|
|
224
|
-
program.body.push(...body);
|
|
225
214
|
return usedImports;
|
|
226
215
|
}
|
|
227
216
|
processAst(contents, importVar, imports) {
|
|
@@ -232,7 +221,7 @@ class HotAstProcessor {
|
|
|
232
221
|
}
|
|
233
222
|
}
|
|
234
223
|
exports.hotAstProcessor = new HotAstProcessor();
|
|
235
|
-
function hotReplaceAst({ types: t }
|
|
224
|
+
function hotReplaceAst({ types: t }) {
|
|
236
225
|
let imports = [];
|
|
237
226
|
let importMap = {};
|
|
238
227
|
let tracked;
|
|
@@ -325,8 +314,6 @@ function hotReplaceAst({ types: t }, options) {
|
|
|
325
314
|
const hotAccepts = [];
|
|
326
315
|
for (const imp of [...usedImports]) {
|
|
327
316
|
const { source, specifiers } = importMap[imp];
|
|
328
|
-
const i = t.importDeclaration([...specifiers], t.stringLiteral(source));
|
|
329
|
-
node.body.splice(0, 0, i);
|
|
330
317
|
const specifier = specifiers.find((s) => s.local.name === imp);
|
|
331
318
|
const specifierName = specifier.imported?.name ||
|
|
332
319
|
specifier.imported?.value ||
|
|
@@ -377,6 +364,7 @@ function hotReplaceAst({ types: t }, options) {
|
|
|
377
364
|
const specifierName = specifier.imported?.name ||
|
|
378
365
|
specifier.imported?.value ||
|
|
379
366
|
'default';
|
|
367
|
+
state.importUtil.import(path, source, specifierName);
|
|
380
368
|
const ast = (0, core_1.parse)(`import.meta.hot.accept('${source}', (module) => (${importVar.name}.${imp}=module['${specifierName}']))`);
|
|
381
369
|
const impHot = ast?.program.body[0];
|
|
382
370
|
hotAccepts.push(impHot);
|
package/dist/lib/hmr.d.ts
CHANGED
package/dist/lib/hmr.js
CHANGED
|
@@ -10,6 +10,9 @@ function hmr() {
|
|
|
10
10
|
name: 'hmr-plugin',
|
|
11
11
|
enforce: 'post',
|
|
12
12
|
resolveId(id) {
|
|
13
|
+
if (id.startsWith('/@id/embroider_virtual:')) {
|
|
14
|
+
return this.resolve(id.replace('/@id/', ''), process.cwd());
|
|
15
|
+
}
|
|
13
16
|
if (id === '/ember-vite-hmr/services/webpack-hot-reload') {
|
|
14
17
|
return this.resolve('ember-vite-hmr/services/webpack-hot-reload', process.cwd());
|
|
15
18
|
}
|
|
@@ -18,6 +21,23 @@ function hmr() {
|
|
|
18
21
|
return (`<script type="module" src="/ember-vite-hmr/services/webpack-hot-reload" />` +
|
|
19
22
|
html);
|
|
20
23
|
},
|
|
24
|
+
handleHotUpdate(ctx) {
|
|
25
|
+
if (!ctx.file.split('?')[0].endsWith('.hbs')) {
|
|
26
|
+
return ctx.modules;
|
|
27
|
+
}
|
|
28
|
+
const otherModules = [];
|
|
29
|
+
const pairedModule = ctx.modules.find(m => [...m.importers].find(i => i.id.startsWith('embroider_virtual') && i.id.endsWith('-embroider-pair-component')));
|
|
30
|
+
if (pairedModule) {
|
|
31
|
+
const pairComponent = [...pairedModule.importers].find(i => i.id.startsWith('embroider_virtual') && i.id.endsWith('-embroider-pair-component'));
|
|
32
|
+
if (pairComponent) {
|
|
33
|
+
const componentModule = [...pairComponent.clientImportedModules].find(cim => cim.id.split('?')[0].match(/\/component\.(js|ts|gjs|gts)/));
|
|
34
|
+
if (componentModule) {
|
|
35
|
+
otherModules.push(componentModule);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return [...ctx.modules, ...otherModules];
|
|
40
|
+
},
|
|
21
41
|
async transform(source, id) {
|
|
22
42
|
const resourcePath = id.replace(/\\/g, '/').split('?')[0];
|
|
23
43
|
const supportedPaths = ['routers', 'controllers', 'routes'];
|
|
@@ -32,18 +52,6 @@ function hmr() {
|
|
|
32
52
|
if (resourcePath.includes('/-components/')) {
|
|
33
53
|
return source;
|
|
34
54
|
}
|
|
35
|
-
const name = require(`${process.cwd()}/package.json`).name;
|
|
36
|
-
if (resourcePath.includes(`/assets/${name}.js`)) {
|
|
37
|
-
const result = [
|
|
38
|
-
...source.matchAll(/d\("([^"]+)"/g),
|
|
39
|
-
];
|
|
40
|
-
for (const resultElement of result) {
|
|
41
|
-
const dep = resultElement[1];
|
|
42
|
-
if (!dep.includes('-components'))
|
|
43
|
-
continue;
|
|
44
|
-
source += `\nimport.meta.hot.accept("${dep}", () => void);`;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
55
|
if (resourcePath.endsWith('.hbs') ||
|
|
48
56
|
resourcePath.endsWith('.gjs') ||
|
|
49
57
|
resourcePath.endsWith('.gts')) {
|
|
@@ -54,9 +62,12 @@ function hmr() {
|
|
|
54
62
|
const dep = resultElement[1];
|
|
55
63
|
const resolved = await this.resolve(dep, resourcePath, {});
|
|
56
64
|
let id = resolved.id;
|
|
57
|
-
if (id.includes('rewritten-app')) {
|
|
65
|
+
if (id.includes('rewritten-app') && !id.startsWith('embroider_virtual:')) {
|
|
58
66
|
id = id.split('rewritten-app')[1];
|
|
59
67
|
}
|
|
68
|
+
if (id.startsWith('embroider_virtual:')) {
|
|
69
|
+
id = '/@id/' + id;
|
|
70
|
+
}
|
|
60
71
|
if (path_1.default.resolve(id).replace(/\\/g, '/') === id &&
|
|
61
72
|
path_1.default.isAbsolute(id)) {
|
|
62
73
|
if (!id.startsWith('/')) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-vite-hmr",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"ember-addon"
|
|
6
6
|
],
|
|
@@ -38,6 +38,8 @@
|
|
|
38
38
|
"prepack": "pnpm build || echo 'its okay'"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
+
"@babel/types": "^7.24.0",
|
|
42
|
+
"babel-import-util": "^2.0.1",
|
|
41
43
|
"@glimmer/syntax": "^0.88.1",
|
|
42
44
|
"@babel/core": "^7.23.2",
|
|
43
45
|
"@babel/plugin-transform-typescript": "^7.22.15",
|