ember-vite-hmr 2.2.2 → 2.2.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.
Files changed (2) hide show
  1. package/dist/lib/hmr.js +41 -14
  2. package/package.json +6 -6
package/dist/lib/hmr.js CHANGED
@@ -15,26 +15,51 @@ const traverse = traverseModule.default || traverseModule;
15
15
  import { readFile } from 'fs/promises';
16
16
  const __filename = fileURLToPath(import.meta.url);
17
17
  const __dirname = path.dirname(__filename);
18
+ // Above this many distinct named blocks, fall back to forwarding all of them
19
+ // unconditionally rather than generating an exponential number of branches
20
+ // (see generateInvocations below for why branching is needed at all).
21
+ const MAX_COMBINATORIAL_YIELDS = 8;
22
+ function blockTag(y) {
23
+ return `<:${y} as |a b c d e f g h i j k l|>{{yield a b c d e f g h i j k l to='${y}'}}</:${y}>`;
24
+ }
25
+ function invocation(selected) {
26
+ if (!selected.length) {
27
+ return `<this.curried @__hot__={{this.hot}} ...attributes />`;
28
+ }
29
+ return `<this.curried @__hot__={{this.hot}} ...attributes>${selected.map(blockTag).join('\n')}</this.curried>`;
30
+ }
31
+ // Glimmer determines a target component's `(has-block "y")` purely from
32
+ // whether a `<:y>` named block tag is structurally present on the
33
+ // invocation, not from whether that block's content renders anything, and
34
+ // named block tags cannot be nested inside `{{#if}}` (a "named block nested
35
+ // in a normal block" compile error). So a per-block `{{#if (has-block 'y')}}
36
+ // <:y>...</:y>{{/if}}` inside a single invocation can't work — instead this
37
+ // recursively branches on `(has-block y)` for each known named block to
38
+ // build one fully static invocation per combination of blocks the caller
39
+ // actually passed, so blocks not passed are truly absent rather than merely
40
+ // empty (see #531).
41
+ function generateInvocations(remaining, selected) {
42
+ if (!remaining.length) {
43
+ return invocation(selected);
44
+ }
45
+ const [y, ...rest] = remaining;
46
+ return `{{#if (has-block '${y}')}}${generateInvocations(rest, [...selected, y])}{{else}}${generateInvocations(rest, selected)}{{/if}}`;
47
+ }
18
48
  function generateContent(yields) {
19
49
  if (!yields.includes('default')) {
20
50
  yields.push('default');
21
51
  }
22
- let all = yields.map((y) => `(has-block '${y}')`).join(' ');
23
- let str = '';
24
- for (const y of yields) {
25
- str += `
26
- <:${y} as |a b c d e f g h i j k l|>{{yield a b c d e f g h i j k l to='${y}'}}</:${y}>
27
- `;
28
- }
29
- return `
52
+ if (yields.length > MAX_COMBINATORIAL_YIELDS) {
53
+ let all = yields.map((y) => `(has-block '${y}')`).join(' ');
54
+ return `
30
55
  {{#if (notAny ${all})}}
31
56
  <this.curried @__hot__={{this.hot}} ...attributes />
32
57
  {{else}}
33
- <this.curried @__hot__={{this.hot}} ...attributes >
34
- ${str}
35
- </this.curried>
58
+ ${invocation(yields)}
36
59
  {{/if}}
37
60
  `;
61
+ }
62
+ return generateInvocations(yields, []);
38
63
  }
39
64
  const getHotComponent = (imp, specifier, yields) => `
40
65
  import { ${specifier} as TargetComponent } from "${imp}";
@@ -199,9 +224,11 @@ export function hmr(enableViteHmrForModes = ['development']) {
199
224
  },
200
225
  configResolved(config) {
201
226
  base = config.base;
202
- process.env.EMBER_VITE_HMR_ENABLED = enableViteHmrForModes
203
- .includes(config.mode)
204
- .toString();
227
+ // `import.meta.hot` is never truthy without a dev server, so a `vite
228
+ // build` that resolves mode to 'development' would inject permanently
229
+ // dead HMR scaffolding and leave imported components bound to undefined.
230
+ process.env.EMBER_VITE_HMR_ENABLED = (config.command === 'serve' &&
231
+ enableViteHmrForModes.includes(config.mode)).toString();
205
232
  },
206
233
  resolveId(id, importer, meta) {
207
234
  return __awaiter(this, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-vite-hmr",
3
- "version": "2.2.2",
3
+ "version": "2.2.4",
4
4
  "private": false,
5
5
  "description": "provides hmr support for ember apps",
6
6
  "keywords": [
@@ -38,7 +38,7 @@
38
38
  "@babel/core": "^7.29.0",
39
39
  "@babel/plugin-transform-typescript": "^7.28.6",
40
40
  "@babel/traverse": "^7.29.0",
41
- "@babel/types": "^7.28.5",
41
+ "@babel/types": "^8.0.4",
42
42
  "@embroider/addon-shim": "^1.10.3",
43
43
  "@glimmer/syntax": "^0.95.0",
44
44
  "@types/supports-color": "^10.0.0",
@@ -61,7 +61,7 @@
61
61
  "@glint/core": "^1.2.0",
62
62
  "@glint/environment-ember-loose": "^1.5.2",
63
63
  "@glint/environment-ember-template-imports": "^1.5.2",
64
- "@glint/template": "^1.7.3",
64
+ "@glint/template": "^1.7.10",
65
65
  "@rollup/plugin-babel": "^7.0.0",
66
66
  "@tsconfig/ember": "^3.0.12",
67
67
  "@types/babel__core": "^7.20.3",
@@ -74,7 +74,7 @@
74
74
  "@types/node": "^26.1.1",
75
75
  "@types/rsvp": "^4.0.9",
76
76
  "@types/semver": "^7.7.1",
77
- "@typescript-eslint/eslint-plugin": "^8.61.1",
77
+ "@typescript-eslint/eslint-plugin": "^8.65.0",
78
78
  "@typescript-eslint/parser": "^8.65.0",
79
79
  "assert-never": "^1.4.0",
80
80
  "babel-import-util": "^3.0.0",
@@ -91,7 +91,7 @@
91
91
  "eslint-plugin-n": "^18.2.2",
92
92
  "eslint-plugin-prettier": "^5.5.5",
93
93
  "execa": "^9.6.1",
94
- "fs-extra": "^11.3.6",
94
+ "fs-extra": "^11.4.0",
95
95
  "globals": "^17.7.0",
96
96
  "playwright-chromium": "^1.59.1",
97
97
  "prettier": "^3.8.4",
@@ -103,7 +103,7 @@
103
103
  "strip-ansi": "^7.2.0",
104
104
  "style-loader": "^4.0.0",
105
105
  "supports-color": "^10.2.2",
106
- "terser": "^5.46.1",
106
+ "terser": "^5.49.0",
107
107
  "thread-loader": "^4.0.2",
108
108
  "typescript": "^5.9.3",
109
109
  "vite": "^8.0.16",