ember-vite-hmr 0.6.4 → 0.6.8

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/addon-main.cjs CHANGED
@@ -34,8 +34,8 @@ Object.assign(module.exports, {
34
34
  );
35
35
  const CompatAppBuilder = require(compatAppBuilder).CompatAppBuilder;
36
36
  const etcOptions = CompatAppBuilder.prototype.etcOptions;
37
- CompatAppBuilder.prototype.etcOptions = function (...args) {
38
- const opts = etcOptions.call(this, ...args);
37
+ CompatAppBuilder.prototype.etcOptions = async function (...args) {
38
+ const opts = await etcOptions.call(this, ...args);
39
39
  opts.transforms.push(astPlugin);
40
40
  return opts;
41
41
  };
@@ -43,7 +43,6 @@ Object.assign(module.exports, {
43
43
  },
44
44
 
45
45
  _buildPlugin() {
46
- const hotAstProcessor = require('./dist/lib/babel-plugin').hotAstProcessor;
47
- return hotAstProcessor.transform.bind(hotAstProcessor);
46
+ return require('./dist/lib/babel-plugin').hotAstProcessor;
48
47
  },
49
48
  });
@@ -1,18 +1,21 @@
1
1
  import { PluginObj } from '@babel/core';
2
2
  import type * as BabelTypesNamespace from '@babel/types';
3
3
  import * as glimmer from '@glimmer/syntax';
4
- import { ASTPluginEnvironment } from '@glimmer/syntax';
5
4
  export type BabelTypes = typeof BabelTypesNamespace;
5
+ interface ASTPluginEnvironment {
6
+ locals: string[];
7
+ }
6
8
  declare class HotAstProcessor {
7
9
  options: {
8
10
  itsStatic: boolean;
9
11
  };
10
12
  counter: number;
11
13
  meta: {
12
- usedImports: Set<unknown>;
14
+ usedImports: Set<string>;
13
15
  importVar: any;
14
16
  };
15
- private usedImports;
17
+ usedImports: Set<any>;
18
+ constructor();
16
19
  transform(env: ASTPluginEnvironment): {
17
20
  visitor: glimmer.NodeVisitor;
18
21
  };
@@ -87,6 +87,7 @@ class HotAstProcessor {
87
87
  usedImports: new Set(),
88
88
  importVar: null,
89
89
  };
90
+ this.transform = this.transform.bind(this);
90
91
  }
91
92
  transform(env) {
92
93
  if (!this.meta.importVar)
@@ -146,13 +147,11 @@ class HotAstProcessor {
146
147
  return;
147
148
  if (findBlockParams(original, p))
148
149
  return;
149
- const params = [];
150
- const blockParams = [];
151
- const letBlock = glimmer.builders.path('let');
152
150
  if (node.original === 'helper' ||
153
151
  node.original === 'component' ||
154
152
  node.original === 'modifier') {
155
- const original = p.parentNode.params[0].original.split('.')[0];
153
+ const parent = p.parentNode;
154
+ const original = parent.params[0].original.split('.')[0];
156
155
  if (original &&
157
156
  findBlockParams(original, p))
158
157
  return;
@@ -161,8 +160,8 @@ class HotAstProcessor {
161
160
  if (!original)
162
161
  return;
163
162
  const param = glimmer.builders.path(`${importVar}.${original}`);
164
- p.parentNode.params.splice(0, 1);
165
- p.parentNode.params.push(param);
163
+ parent.params.splice(0, 1);
164
+ parent.params.push(param);
166
165
  usedImports.add(original);
167
166
  return;
168
167
  }
@@ -228,8 +227,23 @@ function hotReplaceAst({ types: t }) {
228
227
  let importVar;
229
228
  let importsKlass;
230
229
  let templateImportSpecifier = '';
230
+ importMap = {};
231
+ imports = [];
231
232
  return {
232
233
  name: 'hot-reload-imports',
234
+ pre(file) {
235
+ for (let statement of file.ast.program.body) {
236
+ if (statement.type === 'ImportDeclaration') {
237
+ for (let specifier of statement.specifiers) {
238
+ imports.push(specifier.local.name);
239
+ importMap[specifier.local.name] = {
240
+ source: statement.source.value,
241
+ specifiers: statement.specifiers,
242
+ };
243
+ }
244
+ }
245
+ }
246
+ },
233
247
  visitor: {
234
248
  Program: {
235
249
  enter(path, state) {
@@ -237,8 +251,6 @@ function hotReplaceAst({ types: t }) {
237
251
  templateImportSpecifier = '';
238
252
  importVar = null;
239
253
  tracked = null;
240
- importMap = {};
241
- imports = [];
242
254
  exports.hotAstProcessor.meta.usedImports = [];
243
255
  exports.hotAstProcessor.meta.importVar = null;
244
256
  const filename = path.hub.file.opts.filename.split('?')[0];
@@ -253,25 +265,16 @@ function hotReplaceAst({ types: t }) {
253
265
  const node = path.node;
254
266
  const templateImport = node.body.find((i) => i.type === 'ImportDeclaration' &&
255
267
  i.source.value === '@ember/template-compiler');
256
- if (templateImport) {
268
+ if (templateImport && templateImport.type === 'ImportDeclaration') {
257
269
  const def = templateImport.specifiers[0];
258
270
  templateImportSpecifier = def.local.name;
259
271
  }
260
272
  tracked = path.scope.generateUidIdentifier('tracked');
261
- importVar = path.scope.generateUidIdentifier('__imports__');
273
+ importVar = t.identifier('imports_templates__');
262
274
  exports.hotAstProcessor.meta.importVar = importVar;
263
275
  node.body.splice(0, 0, t.importDeclaration([t.importSpecifier(tracked, t.identifier('tracked'))], t.stringLiteral('@glimmer/tracking')));
264
276
  let usedImports = new Set();
265
277
  path.traverse({
266
- ImportDeclaration: function (path) {
267
- path.node.specifiers.forEach(function (s) {
268
- imports.push(s.local.name);
269
- importMap[s.local.name] = {
270
- source: path.node.source.value,
271
- specifiers: path.node.specifiers,
272
- };
273
- });
274
- },
275
278
  CallExpression(path) {
276
279
  const call = path.node;
277
280
  if (templateImportSpecifier &&
@@ -331,9 +334,7 @@ function hotReplaceAst({ types: t }) {
331
334
  if (!filename.includes('rewritten-app')) {
332
335
  return;
333
336
  }
334
- if (!filename.endsWith('.hbs') &&
335
- !filename.endsWith('.gts') &&
336
- !filename.endsWith('.gjs')) {
337
+ if (!filename.endsWith('.hbs')) {
337
338
  return;
338
339
  }
339
340
  path.traverse({
@@ -354,16 +355,21 @@ function hotReplaceAst({ types: t }) {
354
355
  .reverse()
355
356
  .find((x) => x.type === 'ImportDeclaration');
356
357
  const idx = node.body.indexOf(lastImport);
357
- const assignment = node.body.at(-1);
358
+ const assignment = node.body.slice(-1)[0];
358
359
  node.body.splice(-1, 1);
359
360
  node.body.splice(idx, 0, assignment);
360
361
  const hotAccepts = [];
362
+ const handled = new Set();
361
363
  for (const imp of [...usedImports, ...exports.hotAstProcessor.meta.usedImports]) {
362
364
  const { source, specifiers } = importMap[imp];
363
365
  const specifier = specifiers.find((s) => s.local.name === imp);
364
366
  const specifierName = specifier.imported?.name ||
365
367
  specifier.imported?.value ||
366
368
  'default';
369
+ if (handled.has(imp)) {
370
+ continue;
371
+ }
372
+ handled.add(imp);
367
373
  state.importUtil.import(path, source, specifierName);
368
374
  const ast = (0, core_1.parse)(`import.meta.hot.accept('${source}', (module) => (${importVar.name}.${imp}=module['${specifierName}']))`);
369
375
  const impHot = ast?.program.body[0];
package/dist/lib/hmr.js CHANGED
@@ -52,6 +52,10 @@ function hmr() {
52
52
  if (resourcePath.includes('/-components/')) {
53
53
  return source;
54
54
  }
55
+ const name = require(`${process.cwd()}/package.json`).name;
56
+ if (resourcePath.includes(`/assets/${name}.js`)) {
57
+ source += `\nimport.meta.hot.accept();`;
58
+ }
55
59
  if (resourcePath.endsWith('.hbs') ||
56
60
  resourcePath.endsWith('.gjs') ||
57
61
  resourcePath.endsWith('.gts')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-vite-hmr",
3
- "version": "0.6.4",
3
+ "version": "0.6.8",
4
4
  "keywords": [
5
5
  "ember-addon"
6
6
  ],
@@ -34,50 +34,41 @@
34
34
  "start": "concurrently 'npm:start:*'",
35
35
  "start:js": "rollup --config --watch --no-watch.clearScreen",
36
36
  "start:types": "glint --declaration --watch",
37
- "test": "vitest",
37
+ "test": "vitest --run",
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",
43
- "@glimmer/syntax": "^0.88.1",
44
41
  "@babel/core": "^7.23.2",
45
42
  "@babel/plugin-transform-typescript": "^7.22.15",
43
+ "@babel/traverse": "^7.23.2",
44
+ "@babel/types": "^7.24.0",
46
45
  "@embroider/addon-shim": "^1.0.0",
47
- "@embroider/babel-loader-9": "^3.1.0",
48
- "@embroider/hbs-loader": "^3.0.2",
49
- "@embroider/shared-internals": "^2.5.0",
46
+ "@glimmer/syntax": "^0.88.1",
50
47
  "@types/supports-color": "^8.1.0",
51
- "assert-never": "^1.2.1",
48
+ "babel-import-util": "^2.0.1",
52
49
  "babel-loader": "^8.2.2",
53
50
  "babel-preset-env": "^1.7.0",
54
- "css-loader": "^5.2.6",
55
- "csso": "^4.2.0",
56
- "debug": "^4.3.4",
57
- "escape-string-regexp": "^4.0.0",
58
- "fs-extra": "^9.1.0",
59
- "html-webpack-plugin": "^5.5.3",
60
- "vite": "^5.0.12",
61
- "vitest": "^1.2.2",
62
- "jsdom": "^16.6.0",
63
- "lodash": "^4.17.21",
64
- "mini-css-extract-plugin": "^2.5.3",
65
- "semver": "^7.3.5",
51
+ "semver": "^7.3.5"
52
+ },
53
+ "devDependencies": {
54
+ "assert-never": "^1.2.1",
55
+ "content-tag": "^2.0.1",
66
56
  "source-map-url": "^0.4.1",
67
57
  "style-loader": "^2.0.0",
68
58
  "supports-color": "^8.1.0",
69
59
  "terser": "^5.7.0",
70
60
  "thread-loader": "^3.0.4",
71
- "webpack-dev-server": "^4.15.1"
72
- },
73
- "devDependencies": {
61
+ "vite": "^5.0.12",
62
+ "vitest": "^1.2.2",
63
+ "ember-cli-htmlbars": "^6.3.0",
74
64
  "@babel/eslint-parser": "^7.19.1",
75
65
  "@babel/plugin-proposal-class-properties": "^7.16.7",
76
- "@babel/plugin-proposal-decorators": "^7.20.13",
66
+ "@babel/plugin-proposal-decorators": "^7.23.2",
77
67
  "@babel/plugin-transform-class-static-block": "^7.20.0",
78
68
  "@babel/runtime": "^7.17.0",
79
- "@embroider/addon-dev": "^4.1.0",
80
- "@embroider/core": "^3.3.0",
69
+ "@embroider/addon-dev": "^4.2.1",
70
+ "@embroider/compat": "^3.4.6",
71
+ "@embroider/core": "^3.4.6",
81
72
  "@glint/core": "^1.2.0",
82
73
  "@glint/environment-ember-loose": "^1.2.0",
83
74
  "@glint/environment-ember-template-imports": "^1.2.0",
@@ -93,7 +84,7 @@
93
84
  "@types/mini-css-extract-plugin": "^1.4.3",
94
85
  "@types/node": "^15.12.2",
95
86
  "@types/semver": "^7.3.6",
96
- "babel-plugin-ember-template-compilation": "^2.2.0",
87
+ "babel-plugin-ember-template-compilation": "^2.2.1",
97
88
  "concurrently": "^8.0.1",
98
89
  "ember-resolver": "^11.0.1",
99
90
  "ember-source": "^5.3.0",