Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Mar 4, 2024
1 parent 29a9dfa commit b0bf749
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/babel-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ export default function hotReplaceAst(
),
t.blockStatement([assignment, ...hotAccepts]),
);
node.body.splice(idx, 0, importsVar);
node.body.splice(0, 0, importsVar);
node.body.push(ifHot);
},
exit(path, state) {
Expand Down Expand Up @@ -435,7 +435,7 @@ export default function hotReplaceAst(
});
const node = path.node;
const usedImports = hotAstProcessor.meta.usedImports;
if (usedImports) {
if (usedImports || exports.hotAstProcessor.usedImports) {
const lastImport = [...node.body]
.reverse()
.find((x) => x.type === 'ImportDeclaration');
Expand All @@ -444,7 +444,7 @@ export default function hotReplaceAst(
node.body.splice(-1, 1);
node.body.splice(idx, 0, assignment);
const hotAccepts = [];
for (const imp of [...usedImports]) {
for (const imp of [...usedImports, ...exports.hotAstProcessor.meta.usedImports]) {
const { source, specifiers } = importMap[imp];
const specifier = specifiers.find((s) => s.local.name === imp);
const specifierName =
Expand Down
14 changes: 14 additions & 0 deletions lib/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ export function hmr() {
'controller.js',
'controller.ts',
];
if (resourcePath.includes('/-components/')) {
return source;
}
const name = require(`${process.cwd()}/package.json`).name;
if (resourcePath.includes(`/assets/${name}.js`)) {
const result = [
...source.matchAll(/d\("([^"]+)"/g),
];
for (const resultElement of result) {
const dep = resultElement[1];
if (!dep.includes('-components')) continue;
source += `\nimport.meta.hot.accept("${dep}", () => void);`
}
}
if (
resourcePath.endsWith('.hbs') ||
resourcePath.endsWith('.gjs') ||
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-vite-hmr",
"version": "0.6.1",
"version": "0.6.2",
"keywords": [
"ember-addon"
],
Expand Down

0 comments on commit b0bf749

Please sign in to comment.