ember-vite-hmr 1.3.0 → 1.4.1
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 +34 -0
- package/dist/lib/babel-plugin.js +6 -7
- package/dist/lib/hmr.js +57 -46
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PluginObj } from '@babel/core';
|
|
2
|
+
import type * as BabelTypesNamespace from '@babel/types';
|
|
3
|
+
import { Program } from '@babel/types';
|
|
4
|
+
import * as glimmer from '@glimmer/syntax';
|
|
5
|
+
export type BabelTypes = typeof BabelTypesNamespace;
|
|
6
|
+
interface ASTPluginEnvironment {
|
|
7
|
+
locals: string[];
|
|
8
|
+
}
|
|
9
|
+
declare class HotAstProcessor {
|
|
10
|
+
options: {
|
|
11
|
+
itsStatic: boolean;
|
|
12
|
+
};
|
|
13
|
+
counter: number;
|
|
14
|
+
meta: {
|
|
15
|
+
locals: Set<string>;
|
|
16
|
+
importVar: any;
|
|
17
|
+
importBindings: Set<string>;
|
|
18
|
+
babelProgram: Program;
|
|
19
|
+
};
|
|
20
|
+
didCreateImportClass: boolean;
|
|
21
|
+
constructor();
|
|
22
|
+
reset(): void;
|
|
23
|
+
transform(env: ASTPluginEnvironment): any;
|
|
24
|
+
buildVisitor({ importVar, importBindings, babelProgram }: {
|
|
25
|
+
importVar: string;
|
|
26
|
+
importBindings: Set<string>;
|
|
27
|
+
babelProgram: Program;
|
|
28
|
+
}): glimmer.NodeVisitor;
|
|
29
|
+
}
|
|
30
|
+
export declare const hotAstProcessor: HotAstProcessor;
|
|
31
|
+
export default function hotReplaceAst({ types: t }: {
|
|
32
|
+
types: BabelTypes;
|
|
33
|
+
}): PluginObj<import("@babel/core").PluginPass>;
|
|
34
|
+
export {};
|
package/dist/lib/babel-plugin.js
CHANGED
|
@@ -110,13 +110,11 @@ class HotAstProcessor {
|
|
|
110
110
|
return meta.babelProgram.body.find(b => b.type === 'ImportDeclaration' && b.specifiers.some(s => s.local.name === specifier));
|
|
111
111
|
};
|
|
112
112
|
return {
|
|
113
|
-
visitor: {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}),
|
|
119
|
-
},
|
|
113
|
+
visitor: Object.assign({}, this.buildVisitor({
|
|
114
|
+
importVar,
|
|
115
|
+
importBindings: meta.importBindings,
|
|
116
|
+
babelProgram: meta.babelProgram
|
|
117
|
+
})),
|
|
120
118
|
};
|
|
121
119
|
}
|
|
122
120
|
buildVisitor({ importVar, importBindings, babelProgram }) {
|
|
@@ -248,6 +246,7 @@ function hotReplaceAst({ types: t }) {
|
|
|
248
246
|
}
|
|
249
247
|
const ifHot = t.ifStatement(t.memberExpression(t.metaProperty(t.identifier('import'), t.identifier('meta')), t.identifier('hot')), t.blockStatement([...hotAccepts]));
|
|
250
248
|
path.node.body.push(ifHot);
|
|
249
|
+
path.scope.crawl();
|
|
251
250
|
}
|
|
252
251
|
},
|
|
253
252
|
};
|
package/dist/lib/hmr.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -41,56 +50,57 @@ function hmr(enableViteHmrForModes = ['development']) {
|
|
|
41
50
|
}
|
|
42
51
|
return [...ctx.modules, ...otherModules];
|
|
43
52
|
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (resourcePath.includes('/-components/')) {
|
|
56
|
-
return source;
|
|
57
|
-
}
|
|
58
|
-
const name = require(`${process.cwd()}/package.json`).name;
|
|
59
|
-
if (resourcePath.includes(`/assets/${name}.js`)) {
|
|
60
|
-
source += `\nimport.meta.hot.accept();`;
|
|
61
|
-
}
|
|
62
|
-
if (resourcePath.endsWith('.hbs') ||
|
|
63
|
-
resourcePath.endsWith('.gjs') ||
|
|
64
|
-
resourcePath.endsWith('.gts')) {
|
|
65
|
-
const result = [
|
|
66
|
-
...source.matchAll(/import.meta.hot.accept\(\'([^']+)\'/g),
|
|
53
|
+
transform(source, id) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const resourcePath = id.replace(/\\/g, '/').split('?')[0];
|
|
56
|
+
const supportedPaths = ['routers', 'controllers', 'routes'];
|
|
57
|
+
const supportedFileNames = [
|
|
58
|
+
'router.js',
|
|
59
|
+
'router.ts',
|
|
60
|
+
'router.gts',
|
|
61
|
+
'router.gjs',
|
|
62
|
+
'controller.js',
|
|
63
|
+
'controller.ts',
|
|
67
64
|
];
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
65
|
+
if (resourcePath.includes('/-components/')) {
|
|
66
|
+
return source;
|
|
67
|
+
}
|
|
68
|
+
const name = require(`${process.cwd()}/package.json`).name;
|
|
69
|
+
if (resourcePath.includes(`/assets/${name}.js`)) {
|
|
70
|
+
source += `\nimport.meta.hot.accept();`;
|
|
71
|
+
}
|
|
72
|
+
if (resourcePath.endsWith('.hbs') ||
|
|
73
|
+
resourcePath.endsWith('.gjs') ||
|
|
74
|
+
resourcePath.endsWith('.gts')) {
|
|
75
|
+
const result = [
|
|
76
|
+
...source.matchAll(/import.meta.hot.accept\(\'([^']+)\'/g),
|
|
77
|
+
];
|
|
78
|
+
for (const resultElement of result) {
|
|
79
|
+
const dep = resultElement[1];
|
|
80
|
+
const resolved = yield this.resolve(dep, resourcePath, {});
|
|
81
|
+
let id = resolved.id;
|
|
82
|
+
if (id.includes('rewritten-app') && !id.startsWith('embroider_virtual:')) {
|
|
83
|
+
id = id.split('rewritten-app')[1];
|
|
84
|
+
}
|
|
85
|
+
if (id.startsWith('embroider_virtual:')) {
|
|
86
|
+
id = '/@id/' + id;
|
|
87
|
+
}
|
|
88
|
+
if (path_1.default.resolve(id).replace(/\\/g, '/') === id &&
|
|
89
|
+
path_1.default.isAbsolute(id)) {
|
|
90
|
+
if (!id.startsWith('/')) {
|
|
91
|
+
id = '/' + id;
|
|
92
|
+
}
|
|
93
|
+
id = '/@fs' + id;
|
|
82
94
|
}
|
|
83
|
-
|
|
95
|
+
source = source.replace(`import.meta.hot.accept('${dep}'`, `import.meta.hot.accept('${id}'`);
|
|
84
96
|
}
|
|
85
|
-
|
|
97
|
+
return source;
|
|
86
98
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return source
|
|
92
|
-
}
|
|
93
|
-
return `${source}
|
|
99
|
+
if (!supportedPaths.some((s) => resourcePath.includes(`/${s}/`)) &&
|
|
100
|
+
!supportedFileNames.some((s) => resourcePath.endsWith(s))) {
|
|
101
|
+
return source;
|
|
102
|
+
}
|
|
103
|
+
return `${source}
|
|
94
104
|
if (import.meta.hot && window.emberHotReloadPlugin) {
|
|
95
105
|
const result = window.emberHotReloadPlugin.canAcceptNew(import.meta.url);
|
|
96
106
|
result.then(() => {
|
|
@@ -102,6 +112,7 @@ function hmr(enableViteHmrForModes = ['development']) {
|
|
|
102
112
|
});
|
|
103
113
|
}
|
|
104
114
|
`;
|
|
115
|
+
});
|
|
105
116
|
},
|
|
106
117
|
};
|
|
107
118
|
}
|