ember-vite-hmr 0.1.0

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/README.md ADDED
@@ -0,0 +1,38 @@
1
+ ember-vite-hmr
2
+
3
+ Ember Vite Hmr plugin.
4
+
5
+ this can hot reload
6
+
7
+ - helpers
8
+ - modifiers
9
+ - components + templates, fcct components and its deps
10
+ - routes/controllers/route-templates (although it refreshes the whole route and thus looses all state)
11
+
12
+ it cannot hot reload local properties that turn out to be helpers/modifiers/components.
13
+
14
+ ## Installation
15
+
16
+ ```
17
+ ember install ember-vite-hmr
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ update your `vite.config.mjs` with
23
+
24
+ ```js
25
+ import { hmr } from 'ember-vite-hmr';
26
+ ...hmr
27
+ plugins: [
28
+ ...hmr(resolver())
29
+ ]
30
+ ```
31
+
32
+ ## Contributing
33
+
34
+ See the [Contributing](CONTRIBUTING.md) guide for details.
35
+
36
+ ## License
37
+
38
+ This project is licensed under the [MIT License](LICENSE.md).
package/addon-main.cjs ADDED
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ const { addonV1Shim } = require('@embroider/addon-shim');
4
+ const path = require('path');
5
+ module.exports = addonV1Shim(__dirname);
6
+ const included = module.exports.included;
7
+
8
+ Object.assign(module.exports, {
9
+ _getBabelOptions() {
10
+ const parentOptions = this.parent && this.parent.options;
11
+ const appOptions = this.app && this.app.options;
12
+ const addonOptions = parentOptions || appOptions || {};
13
+
14
+ addonOptions.babel = addonOptions.babel || {};
15
+ addonOptions.babel.plugins = addonOptions.babel.plugins || [];
16
+ return addonOptions.babel;
17
+ },
18
+ included(...args) {
19
+ this._getBabelOptions().plugins.push([require.resolve('./dist/lib/babel-plugin.js'), { v: 4, appName: this.app.name }]);
20
+ this._super.included; // need to access this somehow? otherwise it fails later on...
21
+
22
+ let astPlugin = this._buildPlugin();
23
+ astPlugin.parallelBabel = {
24
+ requireFile: __filename,
25
+ buildUsing: '_buildPlugin',
26
+ params: {}
27
+ };
28
+ const compatAppBuilder = require.resolve('@embroider/compat/src/compat-app-builder', { paths: [process.cwd()] });
29
+ const CompatAppBuilder = require(compatAppBuilder).CompatAppBuilder;
30
+ const etcOptions = CompatAppBuilder.prototype.etcOptions;
31
+ CompatAppBuilder.prototype.etcOptions = function (...args) {
32
+ const opts = etcOptions.call(this, ...args);
33
+ opts.transforms.push(astPlugin);
34
+ return opts;
35
+ }
36
+ included.call(this, ...args);
37
+ },
38
+
39
+ _buildPlugin() {
40
+ const hotAstProcessor = require('./dist/lib/babel-plugin').hotAstProcessor;
41
+ return hotAstProcessor.transform.bind(hotAstProcessor);
42
+ },
43
+ })
44
+
@@ -0,0 +1 @@
1
+ export { default } from "ember-vite-hmr/initializers/webpack-hot-reload";
@@ -0,0 +1 @@
1
+ export { default } from "ember-vite-hmr/services/webpack-hot-reload";
@@ -0,0 +1,15 @@
1
+ function initialize(application) {
2
+ application.__container__.lookup('service:webpack-hot-reload');
3
+ const resolver = application.__registry__.resolver._fallback || application.__registry__.resolver;
4
+ const resolverResolve = resolver.resolve;
5
+ resolver.resolve = function (name) {
6
+ name = name.replace(/--hot-version--.*$/, '');
7
+ return resolverResolve.call(this, name);
8
+ };
9
+ }
10
+ var webpackHotReload = {
11
+ initialize
12
+ };
13
+
14
+ export { webpackHotReload as default, initialize };
15
+ //# sourceMappingURL=webpack-hot-reload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack-hot-reload.js","sources":["../../src/initializers/webpack-hot-reload.ts"],"sourcesContent":["export function initialize(application) {\n application.__container__.lookup('service:webpack-hot-reload');\n const resolver =\n application.__registry__.resolver._fallback ||\n application.__registry__.resolver;\n const resolverResolve = resolver.resolve;\n resolver.resolve = function (name) {\n name = name.replace(/--hot-version--.*$/, '');\n return resolverResolve.call(this, name);\n };\n}\n\nexport default {\n initialize,\n};\n"],"names":["initialize","application","__container__","lookup","resolver","__registry__","_fallback","resolverResolve","resolve","name","replace","call"],"mappings":"AAAO,SAASA,UAAUA,CAACC,WAAW,EAAE;AACtCA,EAAAA,WAAW,CAACC,aAAa,CAACC,MAAM,CAAC,4BAA4B,CAAC,CAAA;AAC9D,EAAA,MAAMC,QAAQ,GACZH,WAAW,CAACI,YAAY,CAACD,QAAQ,CAACE,SAAS,IAC3CL,WAAW,CAACI,YAAY,CAACD,QAAQ,CAAA;AACnC,EAAA,MAAMG,eAAe,GAAGH,QAAQ,CAACI,OAAO,CAAA;AACxCJ,EAAAA,QAAQ,CAACI,OAAO,GAAG,UAAUC,IAAI,EAAE;IACjCA,IAAI,GAAGA,IAAI,CAACC,OAAO,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAA;AAC7C,IAAA,OAAOH,eAAe,CAACI,IAAI,CAAC,IAAI,EAAEF,IAAI,CAAC,CAAA;GACxC,CAAA;AACH,CAAA;AAEA,uBAAe;AACbT,EAAAA,UAAAA;AACF,CAAC;;;;"}
@@ -0,0 +1,32 @@
1
+ import { PluginObj } from '@babel/core';
2
+ import type * as BabelTypesNamespace from '@babel/types';
3
+ import * as glimmer from '@glimmer/syntax';
4
+ import { ASTPluginEnvironment } from '@glimmer/syntax';
5
+ export type BabelTypes = typeof BabelTypesNamespace;
6
+ declare class HotAstProcessor {
7
+ options: {
8
+ itsStatic: boolean;
9
+ };
10
+ counter: number;
11
+ meta: {
12
+ usedImports: any[];
13
+ importVar: any;
14
+ };
15
+ transform(env: ASTPluginEnvironment): {
16
+ visitor: glimmer.NodeVisitor;
17
+ };
18
+ buildVisitor({ importVar, imports, changes, hotReplaced, usedImports }: {
19
+ importVar: any;
20
+ imports: any;
21
+ changes: any;
22
+ hotReplaced: any;
23
+ usedImports: any;
24
+ }): glimmer.NodeVisitor;
25
+ replaceInAst(ast: glimmer.ASTv1.Template, importVar?: string, imports?: string[]): Set<unknown>;
26
+ processAst(contents: string, importVar?: string, imports?: string[]): string;
27
+ }
28
+ export declare const hotAstProcessor: HotAstProcessor;
29
+ export default function hotReplaceAst({ types: t }: {
30
+ types: BabelTypes;
31
+ }, options: any): PluginObj<import("@babel/core").PluginPass>;
32
+ export {};
@@ -0,0 +1,502 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.hotAstProcessor = void 0;
27
+ const core_1 = require("@babel/core");
28
+ const glimmer = __importStar(require("@glimmer/syntax"));
29
+ const builtInComponents = ['LinkTo'];
30
+ const builtInHelpers = [
31
+ '-get-dynamic-var',
32
+ '-element',
33
+ '-lf-get-outlet-state',
34
+ '-in-element',
35
+ 'in-element',
36
+ '-with-dynamic-vars',
37
+ 'action',
38
+ 'array',
39
+ 'component',
40
+ 'concat',
41
+ 'debugger',
42
+ 'each',
43
+ 'each-in',
44
+ 'fn',
45
+ 'get',
46
+ 'has-block',
47
+ 'has-block-params',
48
+ 'hasBlock',
49
+ 'hasBlockParams',
50
+ 'hash',
51
+ 'if',
52
+ 'input',
53
+ 'let',
54
+ 'link-to',
55
+ 'loc',
56
+ 'log',
57
+ 'mount',
58
+ 'mut',
59
+ 'on',
60
+ 'outlet',
61
+ 'partial',
62
+ 'query-params',
63
+ 'readonly',
64
+ 'textarea',
65
+ 'unbound',
66
+ 'unless',
67
+ 'with',
68
+ 'yield',
69
+ 'modifier',
70
+ 'helper',
71
+ ];
72
+ function dasherize(str) {
73
+ return str
74
+ .trim()
75
+ .split(/\.?(?=[A-Z])/)
76
+ .join('-')
77
+ .toLowerCase();
78
+ }
79
+ class HotAstProcessor {
80
+ constructor() {
81
+ this.options = {
82
+ itsStatic: false,
83
+ };
84
+ this.counter = 0;
85
+ this.meta = {
86
+ usedImports: [],
87
+ importVar: null,
88
+ };
89
+ }
90
+ transform(env) {
91
+ if (!this.meta.importVar)
92
+ return {
93
+ visitor: {},
94
+ };
95
+ const meta = this.meta;
96
+ meta.usedImports = new Set();
97
+ const usedImports = this.meta.usedImports;
98
+ const imports = [...env.locals];
99
+ if (!meta.importVar) {
100
+ return {
101
+ visitor: {},
102
+ };
103
+ }
104
+ const importVar = meta.importVar.name;
105
+ env.locals.length = 0;
106
+ env.locals.push(importVar);
107
+ return {
108
+ visitor: this.buildVisitor({
109
+ importVar,
110
+ imports,
111
+ changes: [],
112
+ usedImports,
113
+ }),
114
+ };
115
+ }
116
+ buildVisitor({ importVar, imports, changes, hotReplaced, usedImports }) {
117
+ const findBlockParams = function (expression, p) {
118
+ if (p.node &&
119
+ p.node.type === 'BlockStatement' &&
120
+ p.node.program.blockParams.includes(expression)) {
121
+ return true;
122
+ }
123
+ const node = p.node;
124
+ if (node && node.blockParams && node.blockParams.includes(expression)) {
125
+ return true;
126
+ }
127
+ if (!p.parent)
128
+ return false;
129
+ return findBlockParams(expression, p.parent);
130
+ };
131
+ const visitor = {
132
+ PathExpression: (node, p) => {
133
+ if ((p.parentNode?.type === 'SubExpression' ||
134
+ p.parentNode?.type === 'MustacheStatement') &&
135
+ p.parentNode.params.includes(node)) {
136
+ return;
137
+ }
138
+ if (node.original === 'this')
139
+ return;
140
+ if (node.original.startsWith('@'))
141
+ return;
142
+ if (node.original === 'block')
143
+ return;
144
+ if (node.original.startsWith('this.'))
145
+ return;
146
+ if (findBlockParams(node.original.split('.')[0], p))
147
+ return;
148
+ if (importVar) {
149
+ if (imports.includes(node.original)) {
150
+ usedImports.add(node.original);
151
+ node.original = `${importVar}.${node.original}`;
152
+ node.parts = node.original.split('.');
153
+ }
154
+ return;
155
+ }
156
+ const params = [];
157
+ const blockParams = [];
158
+ const letBlock = glimmer.builders.path('let');
159
+ if (node.original === 'helper' ||
160
+ node.original === 'component' ||
161
+ node.original === 'modifier') {
162
+ if (p.parentNode.params[0].original &&
163
+ findBlockParams(p.parentNode.params[0].original.split('.')[0], p))
164
+ return;
165
+ if (p.parentNode.params[0].original?.includes('.'))
166
+ return;
167
+ const sub = glimmer.builders.sexpr(node.original, [p.parentNode.params[0]], glimmer.builders.hash([]));
168
+ const param = glimmer.builders.sexpr('webpack-hot-reload', [sub], glimmer.builders.hash([
169
+ glimmer.builders.pair('type', glimmer.builders.string(node.original)),
170
+ ]));
171
+ p.parentNode.params.splice(0, 1);
172
+ params.push(param);
173
+ const name = node.original + '_' + this.counter;
174
+ blockParams.push(name);
175
+ node.type = 'PathExpression';
176
+ node.original = name;
177
+ const block = glimmer.builders.blockItself([], blockParams);
178
+ const b = glimmer.builders.block(letBlock, params, null, block);
179
+ changes.push(b);
180
+ this.counter++;
181
+ return;
182
+ }
183
+ if (builtInHelpers.includes(node.original)) {
184
+ return;
185
+ }
186
+ if (!builtInHelpers.includes(node.original)) {
187
+ if (p.parentNode?.type === 'ElementModifierStatement')
188
+ return;
189
+ }
190
+ const firstLetter = node.original.split('.').slice(-1)[0][0];
191
+ let type = 'helper';
192
+ if ((this.options.itsStatic &&
193
+ p.parentNode?.type === 'MustacheStatement') ||
194
+ firstLetter === firstLetter.toUpperCase()) {
195
+ type = 'component';
196
+ }
197
+ const sub = glimmer.builders.sexpr(type, [
198
+ glimmer.builders.string(node.original),
199
+ ...(p.parentNode.type === 'SubExpression' ? p.parentNode.params : []),
200
+ ]);
201
+ const param = glimmer.builders.sexpr('webpack-hot-reload', [sub], glimmer.builders.hash([
202
+ glimmer.builders.pair('type', glimmer.builders.string(type)),
203
+ ]));
204
+ params.push(param);
205
+ const name = type + '_' + this.counter;
206
+ blockParams.push(name);
207
+ node.type = 'PathExpression';
208
+ node.original = name;
209
+ if (!params.length)
210
+ return;
211
+ const block = glimmer.builders.blockItself([], blockParams);
212
+ const b = glimmer.builders.block(letBlock, params, null, block);
213
+ changes.push(b);
214
+ this.counter++;
215
+ },
216
+ ElementNode: (element, p) => {
217
+ const params = [];
218
+ const blockParams = [];
219
+ const letBlock = glimmer.builders.path('let');
220
+ element.modifiers.forEach((modifier) => {
221
+ if (importVar) {
222
+ return;
223
+ }
224
+ if (!modifier.path.original)
225
+ return;
226
+ if (modifier.path.original && modifier.path.original.includes('.'))
227
+ return;
228
+ if (builtInHelpers.includes(modifier.path.original)) {
229
+ return;
230
+ }
231
+ const sub = glimmer.builders.sexpr('modifier', [
232
+ {
233
+ ...((modifier.path.original &&
234
+ glimmer.builders.string(modifier.path.original)) ||
235
+ modifier.path),
236
+ },
237
+ ]);
238
+ const param = glimmer.builders.sexpr('webpack-hot-reload', [sub], glimmer.builders.hash([
239
+ glimmer.builders.pair('type', glimmer.builders.string('modifier')),
240
+ ]));
241
+ params.push(param);
242
+ const name = 'modifier_' + this.counter;
243
+ blockParams.push(name);
244
+ modifier.path.type = 'PathExpression';
245
+ modifier.path.original = 'modifier_' + this.counter;
246
+ this.counter++;
247
+ });
248
+ if (findBlockParams(element.tag.split('.')[0], p))
249
+ return;
250
+ if (importVar) {
251
+ if (imports.includes(element.tag)) {
252
+ usedImports.add(element.tag);
253
+ element.tag = `${importVar}.${element.tag}`;
254
+ }
255
+ return;
256
+ }
257
+ if (builtInComponents.includes(element.tag)) {
258
+ return;
259
+ }
260
+ if (element.tag[0] === element.tag[0].toUpperCase()) {
261
+ const sub = glimmer.builders.sexpr('component', [
262
+ glimmer.builders.string(dasherize(element.tag)),
263
+ ]);
264
+ const param = glimmer.builders.sexpr('webpack-hot-reload', [sub], glimmer.builders.hash([
265
+ glimmer.builders.pair('type', glimmer.builders.string('component')),
266
+ ]));
267
+ params.push(param);
268
+ const name = 'Component_' + this.counter;
269
+ blockParams.push(name);
270
+ element.tag = name;
271
+ }
272
+ const block = glimmer.builders.blockItself([], blockParams);
273
+ if (!params.length)
274
+ return;
275
+ const b = glimmer.builders.block(letBlock, params, null, block);
276
+ changes.push(b);
277
+ this.counter++;
278
+ },
279
+ Program: {
280
+ exit(program) { },
281
+ },
282
+ };
283
+ return visitor;
284
+ }
285
+ replaceInAst(ast, importVar, imports) {
286
+ const usedImports = new Set();
287
+ const hotReplaced = {
288
+ components: new Set(),
289
+ helpers: new Set(),
290
+ modifiers: new Set(),
291
+ others: new Set(),
292
+ info: {
293
+ components: {},
294
+ helpers: {},
295
+ modifiers: {},
296
+ },
297
+ };
298
+ const changes = [];
299
+ const visitor = this.buildVisitor({
300
+ importVar,
301
+ imports,
302
+ changes,
303
+ hotReplaced,
304
+ usedImports,
305
+ });
306
+ glimmer.traverse(ast, visitor);
307
+ const program = ast;
308
+ let body = [...program.body];
309
+ for (const letBlock of changes) {
310
+ letBlock.program.body = body;
311
+ body = [letBlock];
312
+ }
313
+ program.body.length = 0;
314
+ program.body.push(...body);
315
+ return usedImports;
316
+ }
317
+ processAst(contents, importVar, imports) {
318
+ const ast = glimmer.preprocess(contents);
319
+ this.counter = 0;
320
+ this.usedImports = this.replaceInAst(ast, importVar, imports);
321
+ return glimmer.print(ast);
322
+ }
323
+ }
324
+ exports.hotAstProcessor = new HotAstProcessor();
325
+ function hotReplaceAst({ types: t }, options) {
326
+ let imports = [];
327
+ let importMap = {};
328
+ let tracked;
329
+ let importVar;
330
+ let importsKlass;
331
+ let templateImportSpecifier = '';
332
+ return {
333
+ name: 'hot-reload-imports',
334
+ visitor: {
335
+ Program: {
336
+ enter(path) {
337
+ templateImportSpecifier = '';
338
+ importVar = null;
339
+ tracked = null;
340
+ importMap = {};
341
+ imports = [];
342
+ exports.hotAstProcessor.meta.usedImports = [];
343
+ exports.hotAstProcessor.meta.importVar = null;
344
+ const filename = path.hub.file.opts.filename.split('?')[0];
345
+ if (!filename.endsWith('.hbs') &&
346
+ !filename.endsWith('.gts') &&
347
+ !filename.endsWith('.gjs')) {
348
+ return;
349
+ }
350
+ if (!filename.includes('rewritten-app')) {
351
+ return;
352
+ }
353
+ const node = path.node;
354
+ const templateImport = node.body.find((i) => i.type === 'ImportDeclaration' &&
355
+ i.source.value === '@ember/template-compiler');
356
+ if (templateImport) {
357
+ const def = templateImport.specifiers[0];
358
+ templateImportSpecifier = def.local.name;
359
+ }
360
+ tracked = path.scope.generateUidIdentifier('tracked');
361
+ importVar = path.scope.generateUidIdentifier('__imports__');
362
+ exports.hotAstProcessor.meta.importVar = importVar;
363
+ node.body.splice(0, 0, t.importDeclaration([t.importSpecifier(tracked, t.identifier('tracked'))], t.stringLiteral('@glimmer/tracking')));
364
+ let usedImports = new Set();
365
+ const addedIds = new Set();
366
+ path.traverse({
367
+ ImportDeclaration: function (path) {
368
+ path.node.specifiers.forEach(function (s) {
369
+ imports.push(s.local.name);
370
+ importMap[s.local.name] = {
371
+ source: path.node.source.value,
372
+ specifiers: path.node.specifiers,
373
+ };
374
+ });
375
+ },
376
+ Identifier(path) {
377
+ if (addedIds.has(path.node)) {
378
+ path.scope
379
+ .getBinding(path.node.name)
380
+ ?.referencePaths.push(path);
381
+ }
382
+ },
383
+ CallExpression(path) {
384
+ const call = path.node;
385
+ if (templateImportSpecifier &&
386
+ call.callee.name ===
387
+ templateImportSpecifier &&
388
+ (call.arguments[0]?.type === 'StringLiteral' ||
389
+ call.arguments[0]?.type === 'TemplateLiteral')) {
390
+ if (call.arguments[0].type === 'StringLiteral') {
391
+ call.arguments[0].value = exports.hotAstProcessor.processAst(call.arguments[0].value, importVar.name, imports);
392
+ exports.hotAstProcessor.usedImports.forEach(usedImports.add, usedImports);
393
+ }
394
+ if (call.arguments[0].type === 'TemplateLiteral' &&
395
+ call.arguments[0].quasis[0]) {
396
+ call.arguments[0].quasis[0].value.raw =
397
+ exports.hotAstProcessor.processAst(call.arguments[0].quasis[0].value.raw, importVar.name, imports);
398
+ exports.hotAstProcessor.usedImports.forEach(usedImports.add, usedImports);
399
+ }
400
+ }
401
+ },
402
+ });
403
+ const lastImport = [...node.body]
404
+ .reverse()
405
+ .find((x) => x.type === 'ImportDeclaration');
406
+ const idx = node.body.indexOf(lastImport);
407
+ const importsVar = t.variableDeclaration('let', [
408
+ t.variableDeclarator(importVar),
409
+ ]);
410
+ importsKlass = t.classExpression(path.scope.generateUidIdentifier('Imports'), null, t.classBody([...usedImports].map((i) => {
411
+ const x = t.identifier(i);
412
+ addedIds.add(x);
413
+ return t.classProperty(t.identifier(i), x, null, [
414
+ t.decorator(tracked),
415
+ ]);
416
+ })));
417
+ const assignment = t.expressionStatement(t.assignmentExpression('=', importVar, t.newExpression(importsKlass, [])));
418
+ const hotAccepts = [];
419
+ for (const imp of [...usedImports]) {
420
+ const { source, specifiers } = importMap[imp];
421
+ const specifier = specifiers.find((s) => s.local.name === imp);
422
+ const specifierName = specifier.imported?.name ||
423
+ specifier.imported?.value ||
424
+ 'default';
425
+ const ast = (0, core_1.parse)(`import.meta.hot.accept('${source}', (module) => (${importVar.name}.${imp}=module['${specifierName}']))`);
426
+ const impHot = ast?.program.body[0];
427
+ hotAccepts.push(impHot);
428
+ }
429
+ const ifHot = t.ifStatement(t.memberExpression(t.metaProperty(t.identifier('import'), t.identifier('meta')), t.identifier('hot')), t.blockStatement([assignment, ...hotAccepts]));
430
+ node.body.splice(idx, 0, importsVar);
431
+ node.body.push(ifHot);
432
+ },
433
+ exit(path, state) {
434
+ const filename = path.hub.file.opts.filename.split('?')[0];
435
+ if (!filename.includes('rewritten-app')) {
436
+ return;
437
+ }
438
+ if (!filename.endsWith('.hbs') &&
439
+ !filename.endsWith('.gts') &&
440
+ !filename.endsWith('.gjs')) {
441
+ return;
442
+ }
443
+ path.traverse({
444
+ ImportDeclaration: function (path) {
445
+ path.node.specifiers.forEach(function (s) {
446
+ imports.push(s.local.name);
447
+ importMap[s.local.name] = {
448
+ source: path.node.source.value,
449
+ specifiers: path.node.specifiers,
450
+ };
451
+ });
452
+ },
453
+ });
454
+ const node = path.node;
455
+ const usedImports = exports.hotAstProcessor.meta.usedImports;
456
+ if (usedImports) {
457
+ const lastImport = [...node.body]
458
+ .reverse()
459
+ .find((x) => x.type === 'ImportDeclaration');
460
+ const idx = node.body.indexOf(lastImport);
461
+ const assignment = node.body.at(-1);
462
+ node.body.splice(-1, 1);
463
+ node.body.splice(idx, 0, assignment);
464
+ const hotAccepts = [];
465
+ for (const imp of [...usedImports]) {
466
+ const { source, specifiers } = importMap[imp];
467
+ const specifier = specifiers.find((s) => s.local.name === imp);
468
+ const specifierName = specifier.imported?.name ||
469
+ specifier.imported?.value ||
470
+ 'default';
471
+ const ast = (0, core_1.parse)(`import.meta.hot.accept('${source}', (module) => (${importVar.name}.${imp}=module['${specifierName}']))`);
472
+ const impHot = ast?.program.body[0];
473
+ hotAccepts.push(impHot);
474
+ }
475
+ const ifHot = t.ifStatement(t.memberExpression(t.metaProperty(t.identifier('import'), t.identifier('meta')), t.identifier('hot')), t.blockStatement([...hotAccepts]));
476
+ node.body.push(ifHot);
477
+ importsKlass.body.body.length = 0;
478
+ }
479
+ },
480
+ },
481
+ CallExpression: {
482
+ exit(path, state) {
483
+ const filename = path.hub.file.opts.filename.split('?')[0];
484
+ if (filename.endsWith('.hbs')) {
485
+ const usedImports = exports.hotAstProcessor.meta.usedImports;
486
+ [...usedImports].map((i) => {
487
+ if (importsKlass.body.body.find((b) => b.key.name === i)) {
488
+ return;
489
+ }
490
+ const x = t.identifier(i);
491
+ const klassProp = t.classProperty(t.identifier(i), x, null, [
492
+ t.decorator(tracked),
493
+ ]);
494
+ importsKlass.body.body.push(klassProp);
495
+ });
496
+ }
497
+ },
498
+ },
499
+ },
500
+ };
501
+ }
502
+ exports.default = hotReplaceAst;
@@ -0,0 +1,5 @@
1
+ export default function (resolver: any): {
2
+ name: string;
3
+ enforce: string;
4
+ transform(source: any, id: any): any;
5
+ };
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function transform({ resolver, resourcePath, plugin }) {
4
+ const resourcePath = resourcePath.replace(/\\/g, '/').split('?')[0];
5
+ const supportedPaths = ['routers', 'controllers', 'routes'];
6
+ const supportedFileNames = [
7
+ 'router.js',
8
+ 'router.ts',
9
+ 'router.gts',
10
+ 'router.gjs',
11
+ 'controller.js',
12
+ 'controller.ts',
13
+ ];
14
+ if (resourcePath.endsWith('.hbs') ||
15
+ resourcePath.endsWith('.gjs') ||
16
+ resourcePath.endsWith('.gts')) {
17
+ const result = [...source.matchAll(/import.meta.hot.accept\(\'([^']+)\'/g)];
18
+ for (const resultElement of result) {
19
+ const dep = resultElement[1];
20
+ const resolved = await resolver.resolveId.call(plugin, dep, resourcePath, {});
21
+ let id = resolved.id;
22
+ if (id.includes('rewritten-app')) {
23
+ id = id.split('rewritten-app')[1];
24
+ }
25
+ if (path.resolve(id).replace(/\\/g, '/') === id && path.isAbsolute(id)) {
26
+ if (!id.startsWith('/')) {
27
+ id = '/' + id;
28
+ }
29
+ id = '/@fs' + id;
30
+ }
31
+ source = source.replace(`import.meta.hot.accept('${dep}'`, `import.meta.hot.accept('${id}'`);
32
+ }
33
+ return source;
34
+ }
35
+ if (!supportedPaths.some((s) => resourcePath.includes(`/${s}/`)) &&
36
+ !supportedFileNames.some((s) => resourcePath.endsWith(s))) {
37
+ return source;
38
+ }
39
+ return `${source}
40
+ if (import.meta.hot && window.emberHotReloadPlugin) {
41
+ const result = window.emberHotReloadPlugin.canAcceptNew(import.meta.url);
42
+ result.then(() => {
43
+ if (!result) {
44
+ import.meta.hot.decline();
45
+ } else {
46
+ import.meta.hot.accept()
47
+ }
48
+ });
49
+ }
50
+ `;
51
+ }
52
+ function default_1(resolver) {
53
+ return {
54
+ name: 'hmr-plugin',
55
+ enforce: 'post',
56
+ transform(source, id) {
57
+ const options = {
58
+ resolver,
59
+ plugin: this,
60
+ source,
61
+ resourcePath: id,
62
+ };
63
+ return transform.call(options);
64
+ },
65
+ };
66
+ }
67
+ exports.default = default_1;
@@ -0,0 +1,199 @@
1
+ import Service, { service } from '@ember/service';
2
+ import { getOwner } from '@ember/owner';
3
+ import Router from '@ember/routing/route';
4
+ import Controller from '@ember/controller';
5
+
6
+ function _initializerDefineProperty(target, property, descriptor, context) {
7
+ if (!descriptor) return;
8
+ Object.defineProperty(target, property, {
9
+ enumerable: descriptor.enumerable,
10
+ configurable: descriptor.configurable,
11
+ writable: descriptor.writable,
12
+ value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
13
+ });
14
+ }
15
+ function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
16
+ var desc = {};
17
+ Object.keys(descriptor).forEach(function (key) {
18
+ desc[key] = descriptor[key];
19
+ });
20
+ desc.enumerable = !!desc.enumerable;
21
+ desc.configurable = !!desc.configurable;
22
+ if ('value' in desc || desc.initializer) {
23
+ desc.writable = true;
24
+ }
25
+ desc = decorators.slice().reverse().reduce(function (desc, decorator) {
26
+ return decorator(target, property, desc) || desc;
27
+ }, desc);
28
+ if (context && desc.initializer !== void 0) {
29
+ desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
30
+ desc.initializer = undefined;
31
+ }
32
+ if (desc.initializer === void 0) {
33
+ Object.defineProperty(target, property, desc);
34
+ desc = null;
35
+ }
36
+ return desc;
37
+ }
38
+
39
+ var _dec, _class, _descriptor;
40
+ const ChangeMap = new WeakMap();
41
+ function getLatestChange(obj) {
42
+ while (ChangeMap.has(obj)) {
43
+ obj = ChangeMap.get(obj);
44
+ }
45
+ return obj;
46
+ }
47
+ let modulePrefix;
48
+ let podModulePrefix;
49
+ if (import.meta.hot) {
50
+ const ModuleMap = new Map();
51
+ window.emberHotReloadPlugin = {
52
+ _accepting: 0,
53
+ changed: {},
54
+ subscribers: [],
55
+ version: 1,
56
+ moduleDepCallbacks: {},
57
+ versionMap: {},
58
+ clear(module) {
59
+ this.moduleDepCallbacks[module.id] = {};
60
+ },
61
+ register(module, dep, callback) {
62
+ dep = dep.replace(new RegExp(`^${modulePrefix}/`), './');
63
+ this.moduleDepCallbacks[module.id][dep] = this.moduleDepCallbacks[module.id][dep] || [];
64
+ this.moduleDepCallbacks[module.id][dep].push(callback);
65
+ },
66
+ loadNew(oldModule, newModule) {
67
+ this.versionMap[newModule.id] = newModule.version;
68
+ const entry = Object.values(requirejs.entries).find(module => module.module.exports.default === oldModule.exports.default);
69
+ entry.module = {
70
+ exports: newModule.exports
71
+ };
72
+ },
73
+ __import(moduleUrl) {
74
+ return import( /* @vite-ignore */moduleUrl);
75
+ },
76
+ async canAcceptNew(moduleUrl) {
77
+ this._accepting += 1;
78
+ const m = await this.__import(moduleUrl);
79
+ const module = {
80
+ exports: m,
81
+ id: moduleUrl.split('?')[0]
82
+ };
83
+ this._accepting -= 1;
84
+ if (this._accepting === 0) {
85
+ setTimeout(() => this.notifyNew(), 0);
86
+ }
87
+ let ok = module.id.includes('/routes/') || module.id.includes('/routers/') || module.id.includes('/controllers/') || module.id.match(/controller\.(js|ts)$/) || module.id.match(/route\.(js|ts|gts)$/);
88
+ if (!ok) {
89
+ return false;
90
+ }
91
+ if (ModuleMap.get(module.id)) {
92
+ this.changed[module.id] = {
93
+ old: ModuleMap.get(module.id),
94
+ new: module
95
+ };
96
+ }
97
+ module.version = this.version;
98
+ ModuleMap.set(module.id, module);
99
+ return true;
100
+ },
101
+ notifyNew() {
102
+ this.version += 1;
103
+ Object.values(this.changed).forEach(change => {
104
+ this.loadNew(change.old, change.new);
105
+ this.subscribers.forEach(fn => fn(change.old, change.new));
106
+ });
107
+ this.changed = {};
108
+ },
109
+ subscribe(fn) {
110
+ this.subscribers.push(fn);
111
+ },
112
+ unsubscribe(fn) {
113
+ const idx = this.subscribers.indexOf(fn);
114
+ if (idx >= 0) {
115
+ this.subscribers.splice(idx, 1);
116
+ }
117
+ }
118
+ };
119
+ }
120
+ let WebpackHotReloadService = (_dec = service(), (_class = class WebpackHotReloadService extends Service {
121
+ constructor(...args) {
122
+ super(...args);
123
+ _initializerDefineProperty(this, "router", _descriptor, this);
124
+ }
125
+ init() {
126
+ super.init();
127
+ if (!window.emberHotReloadPlugin) return;
128
+ modulePrefix = getOwner(this).application.modulePrefix;
129
+ podModulePrefix = getOwner(this).application.podModulePrefix;
130
+ this.router._router;
131
+ Object.defineProperty(this.router._router, '_routerMicrolib', {
132
+ set(v) {
133
+ const getRoute = v.getRoute;
134
+ v.getRoute = function (name) {
135
+ return getRoute.call(this, `${name}--hot-version--${window.emberHotReloadPlugin.version}`);
136
+ };
137
+ this.___routerMicrolib = v;
138
+ },
139
+ get() {
140
+ return this.___routerMicrolib;
141
+ }
142
+ });
143
+ this.container = getOwner(this)?.__container__;
144
+ window.emberHotReloadPlugin.subscribe((oldModule, newModule) => {
145
+ const types = ['route', 'controller', 'template', 'modifier', 'helper', 'component'];
146
+ Object.keys(this.container.cache).forEach(k => {
147
+ if (types.some(t => k.startsWith(`${t}:`))) {
148
+ delete this.container.cache[k];
149
+ }
150
+ });
151
+ Object.keys(this.container.factoryManagerCache).forEach(k => {
152
+ if (types.some(t => k.startsWith(`${t}:`))) {
153
+ delete this.container.factoryManagerCache[k];
154
+ }
155
+ });
156
+ Object.keys(this.container.registry._resolveCache).forEach(k => {
157
+ if (types.some(t => k.startsWith(`${t}:`))) {
158
+ delete this.container.registry._resolveCache[k];
159
+ }
160
+ });
161
+ Object.keys(this.container.validationCache).forEach(k => {
162
+ if (types.some(t => k.startsWith(`${t}:`))) {
163
+ delete this.container.validationCache[k];
164
+ }
165
+ });
166
+ Object.keys(this.container.registry.registrations).forEach(k => {
167
+ if (types.some(t => k.startsWith(`${t}:`))) {
168
+ delete this.container.registry.registrations[k];
169
+ }
170
+ });
171
+ if (oldModule.exports.default?.prototype && oldModule.exports.default.prototype instanceof Router) {
172
+ this.router.refresh();
173
+ }
174
+ if (oldModule.exports.default?.prototype && oldModule.exports.default.prototype instanceof Controller) {
175
+ this.router.refresh();
176
+ }
177
+ if (oldModule.id.startsWith('./templates/') && !oldModule.id.startsWith('./templates/components/')) {
178
+ this.router.refresh();
179
+ }
180
+ if (oldModule.id.startsWith(`./${podModulePrefix}/`)) {
181
+ this.router.refresh();
182
+ }
183
+ });
184
+ }
185
+ getLatestChange(obj) {
186
+ return getLatestChange(obj);
187
+ }
188
+ }, (_descriptor = _applyDecoratedDescriptor(_class.prototype, "router", [_dec], {
189
+ configurable: true,
190
+ enumerable: true,
191
+ writable: true,
192
+ initializer: null
193
+ })), _class));
194
+ // this service using `Owner.lookup('service:hot-reload')`, as well
195
+ // as to check when you pass the service name as an argument to the decorator,
196
+ // like `@service('hot-reload') declare altName: HotReloadService;`.
197
+
198
+ export { WebpackHotReloadService as default };
199
+ //# sourceMappingURL=webpack-hot-reload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack-hot-reload.js","sources":["../../src/services/webpack-hot-reload.ts"],"sourcesContent":["import Service, { service } from '@ember/service';\nimport { getOwner } from '@ember/owner';\nimport RouterService from '@ember/routing/router-service';\nimport Router from '@ember/routing/route';\nimport Controller from '@ember/controller';\n\nconst ChangeMap = new WeakMap();\n\nfunction getLatestChange(obj) {\n while (ChangeMap.has(obj)) {\n obj = ChangeMap.get(obj);\n }\n return obj;\n}\n\nlet modulePrefix!: string;\nlet podModulePrefix!: string;\nif (import.meta.hot) {\n const ModuleMap = new Map();\n\n window.emberHotReloadPlugin = {\n _accepting: 0,\n changed: {},\n subscribers: [],\n version: 1,\n moduleDepCallbacks: {},\n versionMap: {},\n clear(module) {\n this.moduleDepCallbacks[module.id] = {};\n },\n register(module, dep, callback) {\n dep = dep.replace(new RegExp(`^${modulePrefix}/`), './');\n this.moduleDepCallbacks[module.id][dep] =\n this.moduleDepCallbacks[module.id][dep] || [];\n this.moduleDepCallbacks[module.id][dep].push(callback);\n },\n loadNew(oldModule, newModule) {\n this.versionMap[newModule.id] = newModule.version;\n const entry = Object.values(requirejs.entries).find(\n (module) => module.module.exports.default === oldModule.exports.default,\n );\n entry.module = {\n exports: newModule.exports,\n };\n },\n\n __import(moduleUrl) {\n return import(/* @vite-ignore */ moduleUrl);\n },\n\n async canAcceptNew(moduleUrl) {\n this._accepting += 1;\n const m = await this.__import(moduleUrl);\n const module = {\n exports: m,\n id: moduleUrl.split('?')[0],\n };\n this._accepting -= 1;\n if (this._accepting === 0) {\n setTimeout(() => this.notifyNew(), 0);\n }\n let ok =\n module.id.includes('/routes/') ||\n module.id.includes('/routers/') ||\n module.id.includes('/controllers/') ||\n module.id.match(/controller\\.(js|ts)$/) ||\n module.id.match(/route\\.(js|ts|gts)$/);\n if (!ok) {\n return false;\n }\n\n if (ModuleMap.get(module.id)) {\n this.changed[module.id] = {\n old: ModuleMap.get(module.id),\n new: module,\n };\n }\n module.version = this.version;\n ModuleMap.set(module.id, module);\n return true;\n },\n notifyNew() {\n this.version += 1;\n Object.values(this.changed).forEach((change) => {\n this.loadNew(change.old, change.new);\n this.subscribers.forEach((fn) => fn(change.old, change.new));\n });\n this.changed = {};\n },\n subscribe(fn) {\n this.subscribers.push(fn);\n },\n unsubscribe(fn) {\n const idx = this.subscribers.indexOf(fn);\n if (idx >= 0) {\n this.subscribers.splice(idx, 1);\n }\n },\n };\n}\n\nexport default class WebpackHotReloadService extends Service {\n declare container: any;\n @service() router!: RouterService;\n\n init() {\n super.init();\n if (!window.emberHotReloadPlugin) return;\n modulePrefix = getOwner(this)!.application.modulePrefix;\n podModulePrefix = getOwner(this)!.application.podModulePrefix;\n this.router._router;\n Object.defineProperty(this.router._router, '_routerMicrolib', {\n set(v) {\n const getRoute = v.getRoute;\n v.getRoute = function (name) {\n return getRoute.call(\n this,\n `${name}--hot-version--${window.emberHotReloadPlugin.version}`,\n );\n };\n this.___routerMicrolib = v;\n },\n get() {\n return this.___routerMicrolib;\n },\n });\n this.container = getOwner(this)?.__container__;\n window.emberHotReloadPlugin.subscribe((oldModule, newModule) => {\n const types = [\n 'route',\n 'controller',\n 'template',\n 'modifier',\n 'helper',\n 'component',\n ];\n Object.keys(this.container.cache).forEach((k) => {\n if (types.some((t) => k.startsWith(`${t}:`))) {\n delete this.container.cache[k];\n }\n });\n Object.keys(this.container.factoryManagerCache).forEach((k) => {\n if (types.some((t) => k.startsWith(`${t}:`))) {\n delete this.container.factoryManagerCache[k];\n }\n });\n Object.keys(this.container.registry._resolveCache).forEach((k) => {\n if (types.some((t) => k.startsWith(`${t}:`))) {\n delete this.container.registry._resolveCache[k];\n }\n });\n Object.keys(this.container.validationCache).forEach((k) => {\n if (types.some((t) => k.startsWith(`${t}:`))) {\n delete this.container.validationCache[k];\n }\n });\n Object.keys(this.container.registry.registrations).forEach((k) => {\n if (types.some((t) => k.startsWith(`${t}:`))) {\n delete this.container.registry.registrations[k];\n }\n });\n if (\n oldModule.exports.default?.prototype &&\n oldModule.exports.default.prototype instanceof Router\n ) {\n this.router.refresh();\n }\n if (\n oldModule.exports.default?.prototype &&\n oldModule.exports.default.prototype instanceof Controller\n ) {\n this.router.refresh();\n }\n if (\n oldModule.id.startsWith('./templates/') &&\n !oldModule.id.startsWith('./templates/components/')\n ) {\n this.router.refresh();\n }\n if (oldModule.id.startsWith(`./${podModulePrefix}/`)) {\n this.router.refresh();\n }\n });\n }\n getLatestChange(obj) {\n return getLatestChange(obj);\n }\n}\n\n// Don't remove this declaration: this is what enables TypeScript to resolve\n// this service using `Owner.lookup('service:hot-reload')`, as well\n// as to check when you pass the service name as an argument to the decorator,\n// like `@service('hot-reload') declare altName: HotReloadService;`.\ndeclare module '@ember/service' {\n interface Registry {\n 'hot-reload': WebpackHotReloadService;\n }\n}\n"],"names":["ChangeMap","WeakMap","getLatestChange","obj","has","get","modulePrefix","podModulePrefix","import","meta","hot","ModuleMap","Map","window","emberHotReloadPlugin","_accepting","changed","subscribers","version","moduleDepCallbacks","versionMap","clear","module","id","register","dep","callback","replace","RegExp","push","loadNew","oldModule","newModule","entry","Object","values","requirejs","entries","find","exports","default","__import","moduleUrl","canAcceptNew","m","split","setTimeout","notifyNew","ok","includes","match","old","new","set","forEach","change","fn","subscribe","unsubscribe","idx","indexOf","splice","WebpackHotReloadService","_dec","service","_class","Service","constructor","args","_initializerDefineProperty","_descriptor","init","getOwner","application","router","_router","defineProperty","v","getRoute","name","call","___routerMicrolib","container","__container__","types","keys","cache","k","some","t","startsWith","factoryManagerCache","registry","_resolveCache","validationCache","registrations","prototype","Router","refresh","Controller","_applyDecoratedDescriptor","configurable","enumerable","writable","initializer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAMA,SAAS,GAAG,IAAIC,OAAO,EAAE,CAAA;AAE/B,SAASC,eAAeA,CAACC,GAAG,EAAE;AAC5B,EAAA,OAAOH,SAAS,CAACI,GAAG,CAACD,GAAG,CAAC,EAAE;AACzBA,IAAAA,GAAG,GAAGH,SAAS,CAACK,GAAG,CAACF,GAAG,CAAC,CAAA;AAC1B,GAAA;AACA,EAAA,OAAOA,GAAG,CAAA;AACZ,CAAA;AAEA,IAAIG,YAAqB,CAAA;AACzB,IAAIC,eAAwB,CAAA;AAC5B,IAAIC,MAAM,CAACC,IAAI,CAACC,GAAG,EAAE;AACnB,EAAA,MAAMC,SAAS,GAAG,IAAIC,GAAG,EAAE,CAAA;EAE3BC,MAAM,CAACC,oBAAoB,GAAG;AAC5BC,IAAAA,UAAU,EAAE,CAAC;IACbC,OAAO,EAAE,EAAE;AACXC,IAAAA,WAAW,EAAE,EAAE;AACfC,IAAAA,OAAO,EAAE,CAAC;IACVC,kBAAkB,EAAE,EAAE;IACtBC,UAAU,EAAE,EAAE;IACdC,KAAKA,CAACC,MAAM,EAAE;MACZ,IAAI,CAACH,kBAAkB,CAACG,MAAM,CAACC,EAAE,CAAC,GAAG,EAAE,C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A;AAC7B,GAAA;AACF,CAAC,GAAAmE,WAAA,GAAA8B,yBAAA,CAAAnC,MAAA,CAAA+B,SAAA,EAAA,QAAA,EAAA,CAAAjC,IAAA,CAAA,EAAA;EAAAsC,YAAA,EAAA,IAAA;EAAAC,UAAA,EAAA,IAAA;EAAAC,QAAA,EAAA,IAAA;EAAAC,WAAA,EAAA,IAAA;AAAA,CAAA,CAAA,GAAAvC,MAAA,CAAA,EAAA;AAGD;AACA;AACA;;;;"}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=template-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-registry.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,144 @@
1
+ {
2
+ "name": "ember-vite-hmr",
3
+ "version": "0.1.0",
4
+ "keywords": [
5
+ "ember-addon"
6
+ ],
7
+ "private": false,
8
+ "description": "Builds EmberJS apps with Webpack Dev Server and Hot Reload",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/patricklx/ember-webpack-hot-reload"
12
+ },
13
+ "license": "MIT",
14
+ "author": "Patrick Pircher",
15
+ "main": "dist/lib/ember-webpack.js",
16
+ "files": [
17
+ "addon-main.cjs",
18
+ "dist"
19
+ ],
20
+ "scripts": {
21
+ "build": "concurrently 'pnpm:build:*'",
22
+ "build:js": "rollup --config",
23
+ "build:lib": "tsc --p tsconfig.lib.json",
24
+ "build:types": "glint --declaration",
25
+ "lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
26
+ "lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
27
+ "lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
28
+ "lint:js": "eslint . --cache",
29
+ "lint:prettier": "prettier --check .",
30
+ "lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
31
+ "lint:js:fix": "eslint . --fix",
32
+ "lint:prettier:fix": "prettier --w .",
33
+ "lint:types": "glint",
34
+ "start": "concurrently 'npm:start:*'",
35
+ "start:js": "rollup --config --watch --no-watch.clearScreen",
36
+ "start:types": "glint --declaration --watch",
37
+ "test": "vitest",
38
+ "prepack": "pnpm build || echo 'its okay'"
39
+ },
40
+ "dependencies": {
41
+ "@glimmer/syntax": "^0.88.1",
42
+ "@babel/core": "^7.23.2",
43
+ "@babel/plugin-transform-typescript": "^7.22.15",
44
+ "@embroider/addon-shim": "^1.0.0",
45
+ "@embroider/babel-loader-9": "^3.1.0",
46
+ "@embroider/hbs-loader": "^3.0.2",
47
+ "@embroider/shared-internals": "^2.5.0",
48
+ "@types/supports-color": "^8.1.0",
49
+ "assert-never": "^1.2.1",
50
+ "babel-loader": "^8.2.2",
51
+ "babel-preset-env": "^1.7.0",
52
+ "css-loader": "^5.2.6",
53
+ "csso": "^4.2.0",
54
+ "debug": "^4.3.4",
55
+ "escape-string-regexp": "^4.0.0",
56
+ "fs-extra": "^9.1.0",
57
+ "html-webpack-plugin": "^5.5.3",
58
+ "vite": "^5.0.12",
59
+ "vitest": "^1.2.2",
60
+ "jsdom": "^16.6.0",
61
+ "lodash": "^4.17.21",
62
+ "mini-css-extract-plugin": "^2.5.3",
63
+ "semver": "^7.3.5",
64
+ "source-map-url": "^0.4.1",
65
+ "style-loader": "^2.0.0",
66
+ "supports-color": "^8.1.0",
67
+ "terser": "^5.7.0",
68
+ "thread-loader": "^3.0.4",
69
+ "webpack-dev-server": "^4.15.1"
70
+ },
71
+ "devDependencies": {
72
+ "@babel/eslint-parser": "^7.19.1",
73
+ "@babel/plugin-proposal-class-properties": "^7.16.7",
74
+ "@babel/plugin-proposal-decorators": "^7.20.13",
75
+ "@babel/plugin-transform-class-static-block": "^7.20.0",
76
+ "@babel/runtime": "^7.17.0",
77
+ "@embroider/addon-dev": "^4.1.0",
78
+ "@embroider/core": "^3.3.0",
79
+ "@glint/core": "^1.2.0",
80
+ "@glint/environment-ember-loose": "^1.2.0",
81
+ "@glint/environment-ember-template-imports": "^1.2.0",
82
+ "@glint/template": "^1.2.0",
83
+ "@rollup/plugin-babel": "^6.0.3",
84
+ "@tsconfig/ember": "^2.0.0",
85
+ "@types/babel__core": "^7.20.3",
86
+ "@types/babel__traverse": "^7.20.3",
87
+ "@types/csso": "^3.5.1",
88
+ "@types/debug": "^4.1.5",
89
+ "@types/fs-extra": "^9.0.12",
90
+ "@types/lodash": "^4.14.170",
91
+ "@types/mini-css-extract-plugin": "^1.4.3",
92
+ "@types/node": "^15.12.2",
93
+ "@types/semver": "^7.3.6",
94
+ "babel-plugin-ember-template-compilation": "^2.2.0",
95
+ "concurrently": "^8.0.1",
96
+ "ember-resolver": "^11.0.1",
97
+ "ember-source": "^5.3.0",
98
+ "ember-template-lint": "^5.11.2",
99
+ "eslint": "^8.33.0",
100
+ "eslint-config-prettier": "^9.0.0",
101
+ "eslint-plugin-ember": "^11.11.1",
102
+ "eslint-plugin-n": "^16.0.0",
103
+ "eslint-plugin-prettier": "^5.0.0",
104
+ "prettier": "^3.0.3",
105
+ "prettier-plugin-ember-template-tag": "^1.1.0",
106
+ "rollup": "^3.21.8",
107
+ "typescript": "^5.1.6"
108
+ },
109
+ "peerDependencies": {
110
+ "@embroider/compat": "^3.3.0"
111
+ },
112
+ "engines": {
113
+ "node": "12.* || 14.* || >= 16"
114
+ },
115
+ "ember": {
116
+ "edition": "octane"
117
+ },
118
+ "ember-addon": {
119
+ "version": 2,
120
+ "type": "addon",
121
+ "main": "addon-main.cjs",
122
+ "app-js": {
123
+ "./initializers/webpack-hot-reload.js": "./dist/_app_/initializers/webpack-hot-reload.js",
124
+ "./services/webpack-hot-reload.js": "./dist/_app_/services/webpack-hot-reload.js"
125
+ }
126
+ },
127
+ "exports": {
128
+ ".": {
129
+ "default": "./dist/lib/ember-webpack.js"
130
+ },
131
+ "./*": {
132
+ "types": "./declarations/*.d.ts",
133
+ "default": "./dist/*.js"
134
+ },
135
+ "./addon-main.js": "./addon-main.cjs"
136
+ },
137
+ "typesVersions": {
138
+ "*": {
139
+ "*": [
140
+ "declarations/*"
141
+ ]
142
+ }
143
+ }
144
+ }