ember-native 1.2.1 → 2.0.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.
Files changed (100) hide show
  1. package/declarations/components/InspectorSupport.d.ts +0 -1
  2. package/declarations/components/ListView.d.ts +0 -1
  3. package/declarations/components/RadListView.d.ts +1 -1
  4. package/declarations/components/index.d.ts +0 -1
  5. package/declarations/dom/element-registry.d.ts +0 -1
  6. package/declarations/dom/native/FrameElement.d.ts +0 -1
  7. package/declarations/dom/native/NativeElementNode.d.ts +8 -1
  8. package/declarations/dom/native/PageElement.d.ts +0 -1
  9. package/declarations/dom/native-elements-tag-name-map.d.ts +31 -6
  10. package/declarations/dom/nodes/CommentNode.d.ts +0 -1
  11. package/declarations/dom/nodes/DocumentNode.d.ts +6 -3
  12. package/declarations/dom/nodes/ElementNode.d.ts +6 -2
  13. package/declarations/dom/nodes/PropertyNode.d.ts +2 -4
  14. package/declarations/dom/nodes/TextNode.d.ts +0 -1
  15. package/declarations/dom/nodes/ViewNode.d.ts +1 -1
  16. package/declarations/dom/setup-registry.d.ts +0 -1
  17. package/declarations/index.d.ts +1 -2
  18. package/declarations/instance-initializers/history.d.ts +0 -1
  19. package/declarations/instance-initializers/webpack-hot-reload.d.ts +6 -0
  20. package/declarations/services/history.d.ts +3 -1
  21. package/declarations/services/native-router.d.ts +0 -1
  22. package/declarations/services/webpack-hot-reload.d.ts +13 -0
  23. package/declarations/setup-inspector-support.d.ts +0 -1
  24. package/declarations/setup.d.ts +0 -1
  25. package/declarations/types/glint.d.ts +22 -2
  26. package/declarations/types/globals.d.ts +28 -31
  27. package/dist/_app_/instance-initializers/ember-native/webpack-hot-reload.js +1 -0
  28. package/dist/_app_/services/ember-native/webpack-hot-reload.js +1 -0
  29. package/dist/{_rollupPluginBabelHelpers-DZQzmiRH.js → _rollupPluginBabelHelpers-apNPIsxw.js} +6 -6
  30. package/dist/_rollupPluginBabelHelpers-apNPIsxw.js.map +1 -0
  31. package/dist/components/InspectorSupport.js +1 -5
  32. package/dist/components/InspectorSupport.js.map +1 -1
  33. package/dist/components/ListView.js +4 -3
  34. package/dist/components/ListView.js.map +1 -1
  35. package/dist/components/RadListView.js +17 -3
  36. package/dist/components/RadListView.js.map +1 -1
  37. package/dist/dom/native/FrameElement.js +1 -1
  38. package/dist/dom/native/FrameElement.js.map +1 -1
  39. package/dist/dom/native/NativeElementNode.js +18 -3
  40. package/dist/dom/native/NativeElementNode.js.map +1 -1
  41. package/dist/dom/nodes/CommentNode.js +1 -1
  42. package/dist/dom/nodes/CommentNode.js.map +1 -1
  43. package/dist/dom/nodes/DocumentNode.js +18 -6
  44. package/dist/dom/nodes/DocumentNode.js.map +1 -1
  45. package/dist/dom/nodes/ElementNode.js +22 -6
  46. package/dist/dom/nodes/ElementNode.js.map +1 -1
  47. package/dist/dom/nodes/PropertyNode.js +7 -10
  48. package/dist/dom/nodes/PropertyNode.js.map +1 -1
  49. package/dist/dom/nodes/TextNode.js +1 -1
  50. package/dist/dom/nodes/TextNode.js.map +1 -1
  51. package/dist/dom/nodes/ViewNode.js +9 -2
  52. package/dist/dom/nodes/ViewNode.js.map +1 -1
  53. package/dist/dom/setup-registry.js +1 -2
  54. package/dist/dom/setup-registry.js.map +1 -1
  55. package/dist/instance-initializers/webpack-hot-reload.js +18 -0
  56. package/dist/instance-initializers/webpack-hot-reload.js.map +1 -0
  57. package/dist/services/history.js +9 -6
  58. package/dist/services/history.js.map +1 -1
  59. package/dist/services/native-router.js +1 -1
  60. package/dist/services/webpack-hot-reload.js +192 -0
  61. package/dist/services/webpack-hot-reload.js.map +1 -0
  62. package/dist/setup-inspector-support.js +1 -1
  63. package/dist/setup-inspector-support.js.map +1 -1
  64. package/dist/setup.js +38 -0
  65. package/dist/setup.js.map +1 -1
  66. package/dist/utils/babel-plugin.js +207 -0
  67. package/dist/utils/babel-plugin.ts +293 -0
  68. package/dist/utils/content-tag-loader.js +1 -1
  69. package/dist/utils/ember-native.js +2 -0
  70. package/dist/utils/eslint/ember-native.js +2 -0
  71. package/dist/utils/hmr-loader.js +53 -0
  72. package/dist/utils/tsconfig.json +15 -0
  73. package/dist/utils/webpack.config.js +0 -1
  74. package/package.json +49 -41
  75. package/declarations/components/InspectorSupport.d.ts.map +0 -1
  76. package/declarations/components/ListView.d.ts.map +0 -1
  77. package/declarations/components/RadListView.d.ts.map +0 -1
  78. package/declarations/components/index.d.ts.map +0 -1
  79. package/declarations/dom/element-registry.d.ts.map +0 -1
  80. package/declarations/dom/native/FrameElement.d.ts.map +0 -1
  81. package/declarations/dom/native/NativeElementNode.d.ts.map +0 -1
  82. package/declarations/dom/native/PageElement.d.ts.map +0 -1
  83. package/declarations/dom/native-elements-tag-name-map.d.ts.map +0 -1
  84. package/declarations/dom/nodes/CommentNode.d.ts.map +0 -1
  85. package/declarations/dom/nodes/DocumentNode.d.ts.map +0 -1
  86. package/declarations/dom/nodes/ElementNode.d.ts.map +0 -1
  87. package/declarations/dom/nodes/PropertyNode.d.ts.map +0 -1
  88. package/declarations/dom/nodes/TextNode.d.ts.map +0 -1
  89. package/declarations/dom/nodes/ViewNode.d.ts.map +0 -1
  90. package/declarations/dom/setup-registry.d.ts.map +0 -1
  91. package/declarations/index.d.ts.map +0 -1
  92. package/declarations/instance-initializers/history.d.ts.map +0 -1
  93. package/declarations/services/history.d.ts.map +0 -1
  94. package/declarations/services/native-router.d.ts.map +0 -1
  95. package/declarations/setup-inspector-support.d.ts.map +0 -1
  96. package/declarations/setup.d.ts.map +0 -1
  97. package/declarations/types/glint.d.ts.map +0 -1
  98. package/declarations/types/globals.d.ts.map +0 -1
  99. package/dist/_rollupPluginBabelHelpers-DZQzmiRH.js.map +0 -1
  100. package/dist/utils/fix-glimmer-content-owner.js +0 -13
package/dist/setup.js CHANGED
@@ -1,16 +1,20 @@
1
+ import { _ as _defineProperty } from './_rollupPluginBabelHelpers-apNPIsxw.js';
1
2
  import * as loader from 'loader.js';
2
3
  import { registerElements } from './dom/setup-registry.js';
3
4
  import { SimpleDynamicAttribute } from '@glimmer/runtime';
4
5
  import ElementNode from './dom/nodes/ElementNode.js';
5
6
  import { _backburner } from '@ember/runloop';
7
+ import DocumentNode from './dom/nodes/DocumentNode.js';
6
8
 
7
9
  function setup() {
8
10
  globalThis.requireModule = loader.require;
9
11
  globalThis.requirejs = loader.require;
10
12
  globalThis.define = loader.define;
13
+ globalThis.document = new DocumentNode();
11
14
  globalThis.Element = ElementNode;
12
15
  globalThis.Node = ElementNode;
13
16
  globalThis.HTMLElement = ElementNode;
17
+ globalThis.NodeList = Array;
14
18
  function handleBackburnerErrors() {
15
19
  const next = _backburner['_platform'].next;
16
20
  _backburner['_platform'].next = function (...args) {
@@ -39,6 +43,40 @@ function setup() {
39
43
  element.setAttribute(name, normalizedValue);
40
44
  }
41
45
  };
46
+ class Window {}
47
+ class MouseEvent {
48
+ constructor(type, eventOpts) {
49
+ _defineProperty(this, "type", void 0);
50
+ _defineProperty(this, "eventOpts", void 0);
51
+ if (type === 'click') {
52
+ type = 'tap';
53
+ }
54
+ this.type = type;
55
+ this.eventOpts = eventOpts;
56
+ }
57
+ }
58
+ const g = globalThis;
59
+ g.Window = Window;
60
+ g.MouseEvent = MouseEvent;
61
+ g.window = globalThis;
62
+ g.window.location = {
63
+ href: '',
64
+ host: '',
65
+ hostname: '',
66
+ pathname: '',
67
+ search: '',
68
+ origin: '',
69
+ protocol: 'none'
70
+ };
71
+ const document = new DocumentNode();
72
+ document.location = globalThis.window.location;
73
+ g.__emberNative = {
74
+ installGlobal() {
75
+ globalThis.window = globalThis;
76
+ globalThis.document = document;
77
+ }
78
+ };
79
+ g.__emberNative.installGlobal();
42
80
  registerElements();
43
81
  }
44
82
 
package/dist/setup.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"setup.js","sources":["../src/setup.ts"],"sourcesContent":["import * as loader from 'loader.js';\nimport { registerElements } from './dom/setup-registry.ts';\nimport { SimpleDynamicAttribute } from '@glimmer/runtime';\nimport ElementNode from './dom/nodes/ElementNode.ts';\nimport { _backburner } from '@ember/runloop';\n\nexport function setup() {\n globalThis.requireModule = loader.require;\n globalThis.requirejs = loader.require;\n globalThis.define = loader.define;\n\n globalThis.Element = ElementNode as any;\n globalThis.Node = ElementNode as any;\n globalThis.HTMLElement = ElementNode as any;\n\n function handleBackburnerErrors() {\n const next = _backburner['_platform'].next;\n _backburner['_platform'].next = function (...args: any) {\n const p = next.call(this, ...args);\n p.catch(console.error);\n return p;\n };\n }\n handleBackburnerErrors();\n\n SimpleDynamicAttribute.prototype.set = function (dom, value, _env) {\n const { name, namespace } = this.attribute;\n dom.__setAttribute(name, value as any, namespace);\n };\n\n SimpleDynamicAttribute.prototype.update = function (value, _env) {\n const normalizedValue = value;\n const { element: element, name: name } = this.attribute;\n if (null === normalizedValue) {\n element.removeAttribute(name);\n } else {\n element.setAttribute(name, normalizedValue as string);\n }\n };\n\n registerElements();\n}\n"],"names":["setup","globalThis","requireModule","loader","require","requirejs","define","Element","ElementNode","Node","HTMLElement","handleBackburnerErrors","next","_backburner","args","p","call","catch","console","error","SimpleDynamicAttribute","prototype","set","dom","value","_env","name","namespace","attribute","__setAttribute","update","normalizedValue","element","removeAttribute","setAttribute","registerElements"],"mappings":";;;;;;AAMO,SAASA,KAAKA,GAAG;AACtBC,EAAAA,UAAU,CAACC,aAAa,GAAGC,MAAM,CAACC,OAAO;AACzCH,EAAAA,UAAU,CAACI,SAAS,GAAGF,MAAM,CAACC,OAAO;AACrCH,EAAAA,UAAU,CAACK,MAAM,GAAGH,MAAM,CAACG,MAAM;EAEjCL,UAAU,CAACM,OAAO,GAAGC,WAAkB;EACvCP,UAAU,CAACQ,IAAI,GAAGD,WAAkB;EACpCP,UAAU,CAACS,WAAW,GAAGF,WAAkB;EAE3C,SAASG,sBAAsBA,GAAG;AAChC,IAAA,MAAMC,IAAI,GAAGC,WAAW,CAAC,WAAW,CAAC,CAACD,IAAI;IAC1CC,WAAW,CAAC,WAAW,CAAC,CAACD,IAAI,GAAG,UAAU,GAAGE,IAAS,EAAE;MACtD,MAAMC,CAAC,GAAGH,IAAI,CAACI,IAAI,CAAC,IAAI,EAAE,GAAGF,IAAI,CAAC;AAClCC,MAAAA,CAAC,CAACE,KAAK,CAACC,OAAO,CAACC,KAAK,CAAC;AACtB,MAAA,OAAOJ,CAAC;KACT;AACH;AACAJ,EAAAA,sBAAsB,EAAE;EAExBS,sBAAsB,CAACC,SAAS,CAACC,GAAG,GAAG,UAAUC,GAAG,EAAEC,KAAK,EAAEC,IAAI,EAAE;IACjE,MAAM;MAAEC,IAAI;AAAEC,MAAAA;KAAW,GAAG,IAAI,CAACC,SAAS;IAC1CL,GAAG,CAACM,cAAc,CAACH,IAAI,EAAEF,KAAK,EAASG,SAAS,CAAC;GAClD;EAEDP,sBAAsB,CAACC,SAAS,CAACS,MAAM,GAAG,UAAUN,KAAK,EAAEC,IAAI,EAAE;IAC/D,MAAMM,eAAe,GAAGP,KAAK;IAC7B,MAAM;AAAEQ,MAAAA,OAAO,EAAEA,OAAO;AAAEN,MAAAA,IAAI,EAAEA;KAAM,GAAG,IAAI,CAACE,SAAS;IACvD,IAAI,IAAI,KAAKG,eAAe,EAAE;AAC5BC,MAAAA,OAAO,CAACC,eAAe,CAACP,IAAI,CAAC;AAC/B,KAAC,MAAM;AACLM,MAAAA,OAAO,CAACE,YAAY,CAACR,IAAI,EAAEK,eAAyB,CAAC;AACvD;GACD;AAEDI,EAAAA,gBAAgB,EAAE;AACpB;;;;"}
1
+ {"version":3,"file":"setup.js","sources":["../src/setup.ts"],"sourcesContent":["import * as loader from 'loader.js';\nimport { registerElements } from './dom/setup-registry.ts';\nimport { SimpleDynamicAttribute } from '@glimmer/runtime';\nimport ElementNode from './dom/nodes/ElementNode.ts';\nimport { _backburner } from '@ember/runloop';\nimport DocumentNode from './dom/nodes/DocumentNode.ts';\n\nexport function setup() {\n globalThis.requireModule = loader.require;\n globalThis.requirejs = loader.require;\n globalThis.define = loader.define;\n\n globalThis.document = new DocumentNode() as unknown as Document;\n globalThis.Element = ElementNode as any;\n globalThis.Node = ElementNode as any;\n globalThis.HTMLElement = ElementNode as any;\n globalThis.NodeList = Array as any;\n\n function handleBackburnerErrors() {\n const next = _backburner['_platform'].next;\n _backburner['_platform'].next = function (...args: any) {\n const p = next.call(this, ...args);\n p.catch(console.error);\n return p;\n };\n }\n handleBackburnerErrors();\n\n SimpleDynamicAttribute.prototype.set = function (dom, value, _env) {\n const { name, namespace } = this.attribute;\n dom.__setAttribute(name, value as any, namespace);\n };\n\n SimpleDynamicAttribute.prototype.update = function (value, _env) {\n const normalizedValue = value;\n const { element: element, name: name } = this.attribute;\n if (null === normalizedValue) {\n element.removeAttribute(name);\n } else {\n element.setAttribute(name, normalizedValue as string);\n }\n };\n\n class Window {}\n\n class MouseEvent {\n type: any;\n eventOpts: any;\n constructor(type: string, eventOpts: any) {\n if (type === 'click') {\n type = 'tap';\n }\n this.type = type;\n this.eventOpts = eventOpts;\n }\n }\n\n const g = globalThis as any;\n g.Window = Window;\n g.MouseEvent = MouseEvent;\n g.window = globalThis;\n g.window.location = {\n href: '',\n host: '',\n hostname: '',\n pathname: '',\n search: '',\n origin: '',\n protocol: 'none',\n } as any;\n const document = new DocumentNode() as unknown as Document;\n (document as unknown as any).location = globalThis.window.location;\n\n g.__emberNative = {\n installGlobal() {\n (globalThis as any).window = globalThis;\n (globalThis as any).document = document;\n },\n };\n g.__emberNative.installGlobal();\n\n registerElements();\n}\n"],"names":["setup","globalThis","requireModule","loader","require","requirejs","define","document","DocumentNode","Element","ElementNode","Node","HTMLElement","NodeList","Array","handleBackburnerErrors","next","_backburner","args","p","call","catch","console","error","SimpleDynamicAttribute","prototype","set","dom","value","_env","name","namespace","attribute","__setAttribute","update","normalizedValue","element","removeAttribute","setAttribute","Window","MouseEvent","constructor","type","eventOpts","_defineProperty","g","window","location","href","host","hostname","pathname","search","origin","protocol","__emberNative","installGlobal","registerElements"],"mappings":";;;;;;;;AAOO,SAASA,KAAKA,GAAG;AACtBC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A,UAAU,CAASM,QAAQ,GAAGA,QAAQ;AACzC;GACD;AACDsC,EAAAA,CAAC,CAACU,aAAa,CAACC,aAAa,EAAE;AAE/BC,EAAAA,gBAAgB,EAAE;AACpB;;;;"}
@@ -0,0 +1,207 @@
1
+ import { parse } from '@babel/core';
2
+ import * as glimmer from '@glimmer/syntax';
3
+ import { ImportUtil } from 'babel-import-util';
4
+ class HotAstProcessor {
5
+ constructor() {
6
+ this.options = {
7
+ itsStatic: false,
8
+ };
9
+ this.counter = 0;
10
+ this.meta = {
11
+ locals: new Set(),
12
+ importVar: null,
13
+ babelProgram: undefined,
14
+ importBindings: new Set(),
15
+ };
16
+ this.didCreateImportClass = false;
17
+ this.transform = this.transform.bind(this);
18
+ }
19
+ reset() {
20
+ this.meta.importVar = null;
21
+ this.meta.babelProgram = undefined;
22
+ this.meta.importBindings = new Set();
23
+ }
24
+ transform(env) {
25
+ var _a;
26
+ if (process.env['EMBER_HMR_ENABLED'] !== 'true') {
27
+ return {
28
+ visitor: {},
29
+ };
30
+ }
31
+ if (!this.meta.babelProgram) {
32
+ return {
33
+ visitor: {},
34
+ };
35
+ }
36
+ if ((_a = env.filename) === null || _a === void 0 ? void 0 : _a.includes('node_modules')) {
37
+ return {
38
+ visitor: {},
39
+ };
40
+ }
41
+ const meta = this.meta;
42
+ const importVar = env.meta.jsutils.bindExpression(meta.importVar || 'null', null, {
43
+ nameHint: 'template__imports__',
44
+ });
45
+ meta.importVar = meta.importVar || importVar;
46
+ return {
47
+ visitor: Object.assign({}, this.buildVisitor({
48
+ importVar,
49
+ importBindings: meta.importBindings,
50
+ babelProgram: meta.babelProgram,
51
+ })),
52
+ };
53
+ }
54
+ buildVisitor({ importVar, importBindings, babelProgram, }) {
55
+ const findImport = function findImport(specifier) {
56
+ return babelProgram.body.find((b) => b.type === 'ImportDeclaration' &&
57
+ b.specifiers.some((s) => s.local.name === specifier));
58
+ };
59
+ const findBlockParams = function (expression, p) {
60
+ if (p.node.type === 'Template') {
61
+ return false;
62
+ }
63
+ if (p.node &&
64
+ p.node.type === 'BlockStatement' &&
65
+ p.node.program.blockParams.includes(expression)) {
66
+ return true;
67
+ }
68
+ const node = p.node;
69
+ if (node && node.blockParams && node.blockParams.includes(expression)) {
70
+ return true;
71
+ }
72
+ if (!p.parent)
73
+ return false;
74
+ return findBlockParams(expression, p.parent);
75
+ };
76
+ const visitor = {
77
+ PathExpression: (node, p) => {
78
+ var _a, _b;
79
+ if ((((_a = p.parentNode) === null || _a === void 0 ? void 0 : _a.type) === 'SubExpression' ||
80
+ ((_b = p.parentNode) === null || _b === void 0 ? void 0 : _b.type) === 'MustacheStatement') &&
81
+ p.parentNode.params.includes(node)) {
82
+ return;
83
+ }
84
+ const original = node.original.split('.')[0];
85
+ if (original === 'this')
86
+ return;
87
+ if (original.startsWith('@'))
88
+ return;
89
+ if (original === 'block')
90
+ return;
91
+ if (original.startsWith('this.'))
92
+ return;
93
+ if (findBlockParams(original, p))
94
+ return;
95
+ if (node.original === 'helper' ||
96
+ node.original === 'component' ||
97
+ node.original === 'modifier') {
98
+ const parent = p.parentNode;
99
+ if (typeof parent.params[0].original !==
100
+ 'string') {
101
+ return;
102
+ }
103
+ const original = parent.params[0].original.split('.')[0];
104
+ if (original && findBlockParams(original, p))
105
+ return;
106
+ if (original === null || original === void 0 ? void 0 : original.includes('.'))
107
+ return;
108
+ if (!original)
109
+ return;
110
+ if (findImport(original)) {
111
+ const param = glimmer.builders.path(`${importVar}.${original}`);
112
+ parent.params.splice(0, 1, param);
113
+ importBindings.add(original);
114
+ }
115
+ return;
116
+ }
117
+ if (importVar) {
118
+ if (findImport(node.original)) {
119
+ node.original = `${importVar}.${node.original}`;
120
+ node.parts = node.original.split('.');
121
+ importBindings.add(original);
122
+ }
123
+ return;
124
+ }
125
+ },
126
+ ElementNode: (element, p) => {
127
+ const original = element.tag.split('.')[0];
128
+ if (findBlockParams(original, p))
129
+ return;
130
+ if (importVar) {
131
+ if (findImport(original)) {
132
+ element.tag = `${importVar}.${original}`;
133
+ p.node.tag = element.tag;
134
+ importBindings.add(original);
135
+ }
136
+ return;
137
+ }
138
+ },
139
+ };
140
+ return visitor;
141
+ }
142
+ }
143
+ export const hotAstProcessor = new HotAstProcessor();
144
+ export default function hotReplaceAst(babel) {
145
+ const t = babel.types;
146
+ return {
147
+ name: 'a-hot-reload-imports',
148
+ pre(file) {
149
+ hotAstProcessor.reset();
150
+ hotAstProcessor.meta.babelProgram = file.ast.program;
151
+ },
152
+ visitor: {
153
+ Program(path, state) {
154
+ var _a;
155
+ if (!hotAstProcessor.meta.importVar) {
156
+ return;
157
+ }
158
+ if (process.env['EMBER_HMR_ENABLED'] !== 'true') {
159
+ return;
160
+ }
161
+ if ((_a = state.filename) === null || _a === void 0 ? void 0 : _a.includes('node_modules')) {
162
+ return;
163
+ }
164
+ const util = new ImportUtil(babel, path);
165
+ const tracked = util.import(path, '@glimmer/tracking', 'tracked');
166
+ const klass = t.classExpression(path.scope.generateUidIdentifier('Imports'), null, t.classBody([]));
167
+ const bindings = [...hotAstProcessor.meta.importBindings].sort();
168
+ for (const local of bindings) {
169
+ klass.body.body.push(t.classProperty(t.identifier(local), t.identifier(local), null, [
170
+ t.decorator(tracked),
171
+ ]));
172
+ }
173
+ const newExp = t.newExpression(klass, []);
174
+ const assign = t.assignmentExpression('=', t.identifier(hotAstProcessor.meta.importVar), newExp);
175
+ const varDeclaration = path.node.body.findIndex((e) => e.type === 'VariableDeclaration' &&
176
+ e.declarations[0].id.name ===
177
+ hotAstProcessor.meta.importVar) + 1;
178
+ const lastImportIndex = [...path.node.body].findLastIndex((e) => e.type === 'ImportDeclaration') + 1;
179
+ path.node.body.splice(Math.max(varDeclaration, lastImportIndex), 0, assign);
180
+ const findImport = function findImport(specifier) {
181
+ return path.node.body.find((b) => b.type === 'ImportDeclaration' &&
182
+ b.specifiers.some((s) => s.local.name === specifier));
183
+ };
184
+ const ifHotStatements = [];
185
+ for (const imp of bindings) {
186
+ const importDeclaration = findImport(imp);
187
+ if (!importDeclaration) {
188
+ console.log('could not find import for ', imp);
189
+ continue;
190
+ }
191
+ const source = importDeclaration.source.value;
192
+ // const timestamp = Date.now();
193
+ const ast = parse(`
194
+ import.meta.webpackHot.accept('${source}', function () {
195
+ ${hotAstProcessor.meta.importVar}.${imp} = ${imp};
196
+ });
197
+ `);
198
+ const accept = ast.program.body;
199
+ ifHotStatements.push(...accept);
200
+ }
201
+ const ifHot = t.ifStatement(t.memberExpression(t.metaProperty(t.identifier('import'), t.identifier('meta')), t.identifier('webpackHot')), t.blockStatement([...ifHotStatements]));
202
+ path.node.body.push(ifHot);
203
+ path.scope.crawl();
204
+ },
205
+ },
206
+ };
207
+ }
@@ -0,0 +1,293 @@
1
+ import { parse, type PluginObj } from '@babel/core';
2
+ import type * as BabelTypesNamespace from '@babel/types';
3
+ import type { Program, Statement } from '@babel/types';
4
+ import type * as Babel from '@babel/core';
5
+ import * as glimmer from '@glimmer/syntax';
6
+ import { ASTv1, type NodeVisitor, WalkerPath } from '@glimmer/syntax';
7
+ import { ImportUtil } from 'babel-import-util';
8
+
9
+ interface ASTPluginEnvironment {
10
+ locals: string[];
11
+ filename: string;
12
+ }
13
+
14
+ class HotAstProcessor {
15
+ options = {
16
+ itsStatic: false,
17
+ };
18
+ counter = 0;
19
+ meta = {
20
+ locals: new Set<string>(),
21
+ importVar: null,
22
+ babelProgram: undefined,
23
+ importBindings: new Set<string>(),
24
+ } as {
25
+ locals: Set<string>;
26
+ importVar: any;
27
+ importBindings: Set<string>;
28
+ babelProgram?: Program;
29
+ };
30
+ didCreateImportClass: boolean = false;
31
+
32
+ constructor() {
33
+ this.transform = this.transform.bind(this);
34
+ }
35
+
36
+ reset() {
37
+ this.meta.importVar = null;
38
+ this.meta.babelProgram = undefined;
39
+ this.meta.importBindings = new Set<string>();
40
+ }
41
+
42
+ transform(env: ASTPluginEnvironment): any {
43
+ if (process.env['EMBER_HMR_ENABLED'] !== 'true') {
44
+ return {
45
+ visitor: {},
46
+ };
47
+ }
48
+ if (!this.meta.babelProgram) {
49
+ return {
50
+ visitor: {},
51
+ };
52
+ }
53
+ if (env.filename?.includes('node_modules')) {
54
+ return {
55
+ visitor: {},
56
+ };
57
+ }
58
+ const meta = this.meta as Required<typeof this.meta>;
59
+ const importVar = (env as any).meta.jsutils.bindExpression(
60
+ meta.importVar || 'null',
61
+ null,
62
+ {
63
+ nameHint: 'template__imports__',
64
+ },
65
+ );
66
+ meta.importVar = meta.importVar || importVar;
67
+ return {
68
+ visitor: {
69
+ ...this.buildVisitor({
70
+ importVar,
71
+ importBindings: meta.importBindings,
72
+ babelProgram: meta.babelProgram,
73
+ }),
74
+ },
75
+ };
76
+ }
77
+
78
+ buildVisitor({
79
+ importVar,
80
+ importBindings,
81
+ babelProgram,
82
+ }: {
83
+ importVar: string;
84
+ importBindings: Set<string>;
85
+ babelProgram: Program;
86
+ }) {
87
+ const findImport = function findImport(specifier: string) {
88
+ return babelProgram.body.find(
89
+ (b) =>
90
+ b.type === 'ImportDeclaration' &&
91
+ b.specifiers.some((s) => s.local.name === specifier),
92
+ );
93
+ };
94
+
95
+ const findBlockParams = function (
96
+ expression: string,
97
+ p: WalkerPath<
98
+ | ASTv1.BlockStatement
99
+ | ASTv1.Block
100
+ | ASTv1.ElementNode
101
+ | ASTv1.PathExpression
102
+ >,
103
+ ): boolean {
104
+ if ((p.node as any).type === 'Template') {
105
+ return false;
106
+ }
107
+ if (
108
+ p.node &&
109
+ p.node.type === 'BlockStatement' &&
110
+ p.node.program.blockParams.includes(expression)
111
+ ) {
112
+ return true;
113
+ }
114
+ const node = p.node as any;
115
+ if (node && node.blockParams && node.blockParams.includes(expression)) {
116
+ return true;
117
+ }
118
+ if (!p.parent) return false;
119
+ return findBlockParams(expression, p.parent as any);
120
+ };
121
+ const visitor: NodeVisitor = {
122
+ PathExpression: (node, p) => {
123
+ if (
124
+ (p.parentNode?.type === 'SubExpression' ||
125
+ p.parentNode?.type === 'MustacheStatement') &&
126
+ p.parentNode.params.includes(node)
127
+ ) {
128
+ return;
129
+ }
130
+ const original = node.original.split('.')[0]!;
131
+ if (original === 'this') return;
132
+ if (original.startsWith('@')) return;
133
+ if (original === 'block') return;
134
+ if (original.startsWith('this.')) return;
135
+ if (findBlockParams(original, p)) return;
136
+ if (
137
+ node.original === 'helper' ||
138
+ node.original === 'component' ||
139
+ node.original === 'modifier'
140
+ ) {
141
+ const parent = p.parentNode as ASTv1.MustacheStatement;
142
+ if (
143
+ typeof (parent.params[0] as ASTv1.StringLiteral).original !==
144
+ 'string'
145
+ ) {
146
+ return;
147
+ }
148
+ const original = (
149
+ parent.params[0] as ASTv1.StringLiteral
150
+ ).original.split('.')[0];
151
+ if (original && findBlockParams(original, p)) return;
152
+ if (original?.includes('.')) return;
153
+ if (!original) return;
154
+ if (findImport(original)) {
155
+ const param = glimmer.builders.path(`${importVar}.${original}`);
156
+ parent.params.splice(0, 1, param);
157
+ importBindings.add(original);
158
+ }
159
+ return;
160
+ }
161
+ if (importVar) {
162
+ if (findImport(node.original)) {
163
+ node.original = `${importVar}.${node.original}`;
164
+ node.parts = node.original.split('.');
165
+ importBindings.add(original);
166
+ }
167
+ return;
168
+ }
169
+ },
170
+ ElementNode: (
171
+ element: ASTv1.ElementNode,
172
+ p: WalkerPath<ASTv1.ElementNode>,
173
+ ) => {
174
+ const original = element.tag.split('.')[0]!;
175
+ if (findBlockParams(original, p)) return;
176
+ if (importVar) {
177
+ if (findImport(original)) {
178
+ element.tag = `${importVar}.${original}`;
179
+ p.node.tag = element.tag;
180
+ importBindings.add(original);
181
+ }
182
+ return;
183
+ }
184
+ },
185
+ };
186
+ return visitor;
187
+ }
188
+ }
189
+
190
+ export const hotAstProcessor = new HotAstProcessor();
191
+
192
+ export default function hotReplaceAst(babel: typeof Babel) {
193
+ const t = babel.types;
194
+ return {
195
+ name: 'a-hot-reload-imports',
196
+ pre(file) {
197
+ hotAstProcessor.reset();
198
+ hotAstProcessor.meta.babelProgram = file.ast.program;
199
+ },
200
+ visitor: {
201
+ Program(path, state) {
202
+ if (!hotAstProcessor.meta.importVar) {
203
+ return;
204
+ }
205
+ if (process.env['EMBER_HMR_ENABLED'] !== 'true') {
206
+ return;
207
+ }
208
+ if (state.filename?.includes('node_modules')) {
209
+ return;
210
+ }
211
+ const util = new ImportUtil(babel, path);
212
+ const tracked = util.import(path, '@glimmer/tracking', 'tracked');
213
+ const klass = t.classExpression(
214
+ path.scope.generateUidIdentifier('Imports'),
215
+ null,
216
+ t.classBody([]),
217
+ );
218
+ const bindings = [...hotAstProcessor.meta.importBindings].sort();
219
+ for (const local of bindings) {
220
+ klass.body.body.push(
221
+ t.classProperty(t.identifier(local), t.identifier(local), null, [
222
+ t.decorator(tracked),
223
+ ]),
224
+ );
225
+ }
226
+
227
+ const newExp = t.newExpression(klass, []);
228
+ const assign = t.assignmentExpression(
229
+ '=',
230
+ t.identifier(hotAstProcessor.meta.importVar),
231
+ newExp,
232
+ );
233
+
234
+ const varDeclaration =
235
+ path.node.body.findIndex(
236
+ (e: BabelTypesNamespace.Statement) =>
237
+ e.type === 'VariableDeclaration' &&
238
+ (e.declarations[0]!.id as BabelTypesNamespace.Identifier).name ===
239
+ hotAstProcessor.meta.importVar,
240
+ ) + 1;
241
+
242
+ const lastImportIndex =
243
+ [...path.node.body].findLastIndex(
244
+ (e: BabelTypesNamespace.Statement) =>
245
+ e.type === 'ImportDeclaration',
246
+ ) + 1;
247
+
248
+ path.node.body.splice(
249
+ Math.max(varDeclaration, lastImportIndex),
250
+ 0,
251
+ assign as unknown as Statement,
252
+ );
253
+
254
+ const findImport = function findImport(specifier: string) {
255
+ return path.node.body.find(
256
+ (b) =>
257
+ b.type === 'ImportDeclaration' &&
258
+ b.specifiers.some((s) => s.local.name === specifier),
259
+ );
260
+ };
261
+
262
+ const ifHotStatements = [];
263
+ for (const imp of bindings) {
264
+ const importDeclaration = findImport(
265
+ imp,
266
+ ) as BabelTypesNamespace.ImportDeclaration;
267
+ if (!importDeclaration) {
268
+ console.log('could not find import for ', imp);
269
+ continue;
270
+ }
271
+ const source = importDeclaration.source.value;
272
+ // const timestamp = Date.now();
273
+ const ast = parse(`
274
+ import.meta.webpackHot.accept('${source}', function () {
275
+ ${hotAstProcessor.meta.importVar}.${imp} = ${imp};
276
+ });
277
+ `);
278
+ const accept = ast!.program.body;
279
+ ifHotStatements.push(...accept);
280
+ }
281
+ const ifHot = t.ifStatement(
282
+ t.memberExpression(
283
+ t.metaProperty(t.identifier('import'), t.identifier('meta')),
284
+ t.identifier('webpackHot'),
285
+ ),
286
+ t.blockStatement([...ifHotStatements]),
287
+ );
288
+ path.node.body.push(ifHot);
289
+ path.scope.crawl();
290
+ },
291
+ },
292
+ } as PluginObj;
293
+ }
@@ -5,5 +5,5 @@ const Preprocessor = new ContentTag.Preprocessor();
5
5
  module.exports = function (source) {
6
6
  return Preprocessor.process(source, {
7
7
  inline_source_map: true,
8
- });
8
+ }).code;
9
9
  };
@@ -6,4 +6,6 @@ module.exports.emberNativeGlobals = {
6
6
  'rad-list-view': true,
7
7
  'list-view': true,
8
8
  frame: true,
9
+ require: true,
10
+ module: true,
9
11
  };
@@ -6,4 +6,6 @@ module.exports.emberNativeGlobals = {
6
6
  'rad-list-view': true,
7
7
  'list-view': true,
8
8
  frame: true,
9
+ require: true,
10
+ module: true,
9
11
  };
@@ -0,0 +1,53 @@
1
+ function hmr() {
2
+ return {
3
+ name: 'hmr-plugin',
4
+
5
+ transform(source, resourcePath) {
6
+ if (process.env['EMBER_HMR_ENABLED'] !== 'true') {
7
+ return source;
8
+ }
9
+ const supportedPaths = ['routers', 'controllers', 'routes', 'templates'];
10
+ const supportedFileNames = [
11
+ 'route.js',
12
+ 'route.ts',
13
+ 'route.gts',
14
+ 'route.gjs',
15
+ 'controller.js',
16
+ 'controller.ts',
17
+ ];
18
+ if (resourcePath.includes('/-components/')) {
19
+ return source;
20
+ }
21
+ if (
22
+ !supportedPaths.some((s) => resourcePath.includes(`/${s}/`)) &&
23
+ !supportedFileNames.some((s) => resourcePath.endsWith(s))
24
+ ) {
25
+ return source;
26
+ }
27
+ if (
28
+ supportedPaths.includes('templates') &&
29
+ supportedPaths.includes('components')
30
+ ) {
31
+ return source;
32
+ }
33
+ return `${source}
34
+ if (import.meta.hot && window.emberHotReloadPlugin) {
35
+ const result = window.emberHotReloadPlugin.canAcceptNew(import.meta.url);
36
+ result.then(() => {
37
+ if (!result) {
38
+ import.meta.hot.decline();
39
+ } else {
40
+ import.meta.hot.accept()
41
+ }
42
+ });
43
+ }
44
+ `;
45
+ },
46
+ };
47
+ }
48
+
49
+ const hmrPlugin = hmr();
50
+
51
+ module.exports = function (source) {
52
+ return hmrPlugin.transform(source, this.resourcePath);
53
+ };
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": ".",
4
+ "emitDeclarationOnly": false,
5
+ "outDir": "../dist/utils",
6
+ "target": "ES6",
7
+ "module": "es2020",
8
+ "lib": ["es2023", "dom"],
9
+ "moduleResolution": "bundler",
10
+ "noEmitOnError": false
11
+ },
12
+ "include": [
13
+ "./babel-plugin.ts"
14
+ ]
15
+ }
@@ -10,7 +10,6 @@ module.exports = (webpack) => {
10
10
  ),
11
11
  );
12
12
  for (const glimmerDir of glimmerDirs) {
13
- console.log(glimmerDir);
14
13
  config.resolve.alias.set(
15
14
  `@glimmer/${glimmerDir}`,
16
15
  `ember-source/dist/packages/@glimmer/${glimmerDir}`,