ember-repl 3.0.0-beta.8 → 4.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 (88) hide show
  1. package/README.md +1 -1
  2. package/package.json +48 -41
  3. package/src/compile/formats/gjs/babel.ts +7 -0
  4. package/src/{browser/cjs → compile/formats/gjs}/eval.ts +2 -4
  5. package/src/compile/formats/gjs/index.ts +123 -0
  6. package/src/{browser → compile/formats}/hbs.ts +15 -4
  7. package/src/{browser/compile/markdown-to-ember.ts → compile/formats/markdown.ts} +8 -1
  8. package/src/{browser/compile → compile}/formats.ts +14 -13
  9. package/src/{browser/compile → compile}/index.ts +2 -3
  10. package/src/compile/types.ts +26 -0
  11. package/src/index.ts +5 -0
  12. package/src/test-support/index.ts +1 -1
  13. package/declarations/browser/__PRIVATE__.d.ts +0 -2
  14. package/declarations/browser/__PRIVATE__.d.ts.map +0 -1
  15. package/declarations/browser/cjs/eval.d.ts +0 -9
  16. package/declarations/browser/cjs/eval.d.ts.map +0 -1
  17. package/declarations/browser/cjs/index.d.ts +0 -7
  18. package/declarations/browser/cjs/index.d.ts.map +0 -1
  19. package/declarations/browser/compile/formats.d.ts +0 -18
  20. package/declarations/browser/compile/formats.d.ts.map +0 -1
  21. package/declarations/browser/compile/index.d.ts +0 -71
  22. package/declarations/browser/compile/index.d.ts.map +0 -1
  23. package/declarations/browser/compile/markdown-to-ember.d.ts +0 -21
  24. package/declarations/browser/compile/markdown-to-ember.d.ts.map +0 -1
  25. package/declarations/browser/compile/types.d.ts +0 -9
  26. package/declarations/browser/compile/types.d.ts.map +0 -1
  27. package/declarations/browser/esm/index.d.ts +0 -8
  28. package/declarations/browser/esm/index.d.ts.map +0 -1
  29. package/declarations/browser/gjs.d.ts +0 -4
  30. package/declarations/browser/gjs.d.ts.map +0 -1
  31. package/declarations/browser/hbs.d.ts +0 -17
  32. package/declarations/browser/hbs.d.ts.map +0 -1
  33. package/declarations/browser/index.d.ts +0 -7
  34. package/declarations/browser/index.d.ts.map +0 -1
  35. package/declarations/browser/js.d.ts +0 -20
  36. package/declarations/browser/js.d.ts.map +0 -1
  37. package/declarations/browser/known-modules.d.ts +0 -65
  38. package/declarations/browser/known-modules.d.ts.map +0 -1
  39. package/declarations/browser/types.d.ts +0 -21
  40. package/declarations/browser/types.d.ts.map +0 -1
  41. package/declarations/browser/utils.d.ts +0 -19
  42. package/declarations/browser/utils.d.ts.map +0 -1
  43. package/declarations/test-support/index.d.ts +0 -2
  44. package/declarations/test-support/index.d.ts.map +0 -1
  45. package/dist/browser/__PRIVATE__.js +0 -2
  46. package/dist/browser/__PRIVATE__.js.map +0 -1
  47. package/dist/browser/cjs/eval.js +0 -22
  48. package/dist/browser/cjs/eval.js.map +0 -1
  49. package/dist/browser/cjs/index.js +0 -43
  50. package/dist/browser/cjs/index.js.map +0 -1
  51. package/dist/browser/compile/formats.js +0 -171
  52. package/dist/browser/compile/formats.js.map +0 -1
  53. package/dist/browser/compile/index.js +0 -113
  54. package/dist/browser/compile/index.js.map +0 -1
  55. package/dist/browser/compile/markdown-to-ember.js +0 -254
  56. package/dist/browser/compile/markdown-to-ember.js.map +0 -1
  57. package/dist/browser/compile/types.js +0 -2
  58. package/dist/browser/compile/types.js.map +0 -1
  59. package/dist/browser/esm/index.js +0 -67
  60. package/dist/browser/esm/index.js.map +0 -1
  61. package/dist/browser/gjs.js +0 -43
  62. package/dist/browser/gjs.js.map +0 -1
  63. package/dist/browser/hbs.js +0 -94
  64. package/dist/browser/hbs.js.map +0 -1
  65. package/dist/browser/index.js +0 -6
  66. package/dist/browser/index.js.map +0 -1
  67. package/dist/browser/js.js +0 -38
  68. package/dist/browser/js.js.map +0 -1
  69. package/dist/browser/known-modules.js +0 -48
  70. package/dist/browser/known-modules.js.map +0 -1
  71. package/dist/browser/types.js +0 -2
  72. package/dist/browser/types.js.map +0 -1
  73. package/dist/browser/utils.js +0 -46
  74. package/dist/browser/utils.js.map +0 -1
  75. package/dist/build/ember-cli.cjs +0 -36
  76. package/dist/test-support/index.js +0 -8
  77. package/dist/test-support/index.js.map +0 -1
  78. package/src/browser/cjs/index.ts +0 -44
  79. package/src/browser/compile/types.ts +0 -11
  80. package/src/browser/esm/index.ts +0 -80
  81. package/src/browser/gjs.ts +0 -59
  82. package/src/browser/index.ts +0 -8
  83. package/src/browser/js.ts +0 -42
  84. package/src/browser/types.ts +0 -24
  85. package/src/build/ember-cli.cjs +0 -36
  86. /package/src/{browser/__PRIVATE__.ts → __PRIVATE__.ts} +0 -0
  87. /package/src/{browser → compile/formats/gjs}/known-modules.ts +0 -0
  88. /package/src/{browser → compile}/utils.ts +0 -0
package/README.md CHANGED
@@ -198,7 +198,7 @@ resource so that when an error occurs, you could keep rendering the latest succe
198
198
  import Component from '@glimmer/component';
199
199
  import { Compiled } from 'ember-repl';
200
200
  import { use } from 'ember-resources';
201
- import { keepLatest } from 'reactiveweb/keep-latest';
201
+ import { keepLatest } from 'reactiveweb/util/keep-latest';
202
202
 
203
203
  export class Renderer extends Component {
204
204
  @use compile = Compiled(() => this.args.mdText, 'glimdown');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-repl",
3
- "version": "3.0.0-beta.8",
3
+ "version": "4.0.0",
4
4
  "description": "Addon for enabling REPL and Playground creation with Ember/Glimmer",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -18,37 +18,38 @@
18
18
  "declarations/test-support/index.d.ts"
19
19
  ],
20
20
  "markdown/parse": [
21
- "./declarations/browser/compile/markdown-to-ember.d.ts"
21
+ "./declarations/compile/markdown-to-ember.d.ts"
22
22
  ],
23
23
  "*": [
24
- "declarations/browser/*",
25
- "declarations/browser/*/index.d.ts"
24
+ "declarations/*",
25
+ "declarations/*/index.d.ts"
26
26
  ]
27
27
  }
28
28
  },
29
29
  "exports": {
30
30
  ".": {
31
- "types": "./declarations/browser/index.d.ts",
32
- "default": "./dist/browser/index.js"
31
+ "types": "./declarations/index.d.ts",
32
+ "default": "./dist/index.js"
33
33
  },
34
- "./esm": {
35
- "types": "./declarations/browser/esm/index.d.ts",
36
- "default": "./dist/browser/esm/index.js"
34
+ "./formats/markdown": {
35
+ "types": "./declarations/compile/formats/markdown.d.ts",
36
+ "default": "./dist/compile/formats/markdown.js"
37
37
  },
38
- "./markdown/parse": {
39
- "types": "./declarations/browser/compile/markdown-to-ember.d.ts",
40
- "default": "./dist/browser/compile/markdown-to-ember.js"
38
+ "./formats/hbs": {
39
+ "types": "./declarations/compile/formats/hbs.d.ts",
40
+ "default": "./dist/compile/formats/hbs.js"
41
41
  },
42
- "./ember-cli": {
43
- "require": "./src/build/ember-cli.cjs"
42
+ "./formats/gjs": {
43
+ "types": "./declarations/compile/formats/gjs/index.d.ts",
44
+ "default": "./dist/compile/formats/gjs/index.js"
44
45
  },
45
46
  "./test-support": {
46
47
  "types": "./declarations/test-support/index.d.ts",
47
48
  "default": "./dist/test-support/index.js"
48
49
  },
49
50
  "./__PRIVATE__DO_NOT_USE__": {
50
- "types": "./declarations/browser/__PRIVATE__.d.ts",
51
- "default": "./dist/browser/__PRIVATE__.js"
51
+ "types": "./declarations/__PRIVATE__.d.ts",
52
+ "default": "./dist/__PRIVATE__.js"
52
53
  },
53
54
  "./addon-main.js": "./addon-main.cjs"
54
55
  },
@@ -59,24 +60,22 @@
59
60
  "addon-main.cjs"
60
61
  ],
61
62
  "dependencies": {
63
+ "ember-resources": ">= 6.4.2",
62
64
  "@babel/helper-plugin-utils": "^7.22.5",
63
- "@babel/standalone": "^7.23.6",
65
+ "@babel/standalone": "^7.23.10",
64
66
  "@embroider/addon-shim": "1.8.7",
65
67
  "@embroider/macros": "1.13.5",
66
- "@glimmer/compiler": ">= 0.86.0",
67
- "@glimmer/syntax": ">= 0.86.0",
68
68
  "babel-import-util": "^2.0.1",
69
69
  "babel-plugin-ember-template-compilation": "^2.2.1",
70
70
  "broccoli-file-creator": "^2.1.1",
71
- "change-case": "^5.3.0",
71
+ "change-case": "^5.4.2",
72
72
  "common-tags": "^1.8.2",
73
73
  "content-tag": "^1.2.1",
74
74
  "decorator-transforms": "^1.1.0",
75
75
  "line-column": "^1.0.2",
76
- "magic-string": "^0.30.5",
76
+ "magic-string": "^0.30.6",
77
77
  "mdast": "^3.0.0",
78
78
  "parse-static-imports": "^1.1.0",
79
- "reactiveweb": "^1.2.0",
80
79
  "rehype-raw": "^6.1.1",
81
80
  "rehype-stringify": "^9.0.4",
82
81
  "remark-gfm": "^3.0.1",
@@ -88,16 +87,18 @@
88
87
  "vfile": "^6.0.1"
89
88
  },
90
89
  "devDependencies": {
91
- "@babel/core": "^7.23.7",
90
+ "@babel/core": "^7.23.9",
92
91
  "@babel/plugin-transform-typescript": "^7.23.6",
93
92
  "@babel/preset-typescript": "^7.23.3",
94
93
  "@babel/types": "^7.23.9",
95
94
  "@ember/test-helpers": "^3.2.1",
96
95
  "@ember/test-waiters": "^3.1.0",
97
- "@embroider/addon-dev": "4.1.3",
96
+ "@embroider/addon-dev": "4.2.1",
97
+ "@glimmer/compiler": ">= 0.86.0",
98
98
  "@glimmer/component": "^1.1.2",
99
99
  "@glimmer/interfaces": ">= 0.86.0",
100
100
  "@glimmer/reference": ">= 0.86.0",
101
+ "@glimmer/syntax": ">= 0.86.0",
101
102
  "@glimmer/tracking": "^1.1.2",
102
103
  "@glimmer/util": "^0.88.0",
103
104
  "@glint/core": "1.3.0",
@@ -114,26 +115,26 @@
114
115
  "@types/hast": "^3.0.3",
115
116
  "@types/mdast": "^4.0.3",
116
117
  "@types/unist": "^3.0.2",
117
- "@types/uuid": "^9.0.7",
118
+ "@types/uuid": "^9.0.8",
118
119
  "@typescript-eslint/eslint-plugin": "^6.20.0",
119
120
  "@typescript-eslint/parser": "^6.20.0",
120
121
  "concurrently": "^8.2.2",
121
- "ember-resources": "^6.4.2",
122
- "ember-source": "^5.5.0",
122
+ "ember-resources": "^7.0.0",
123
+ "ember-source": "^5.6.0",
123
124
  "ember-template-imports": "^3.4.2",
124
125
  "ember-template-lint": "^5.13.0",
125
126
  "eslint": "^8.55.0",
126
127
  "eslint-plugin-ember": "^12.0.0",
127
128
  "eslint-plugin-node": "^11.1.0",
128
- "eslint-plugin-prettier": "^5.0.1",
129
- "prettier": "^3.1.1",
129
+ "eslint-plugin-prettier": "^5.1.3",
130
+ "execa": "^8.0.1",
131
+ "prettier": "^3.2.5",
130
132
  "prettier-plugin-ember-template-tag": "^2.0.0",
131
133
  "publint": "^0.2.6",
132
- "rollup": "~4.9.0",
134
+ "rollup": "~4.9.6",
133
135
  "rollup-plugin-copy": "^3.5.0",
134
- "rollup-plugin-glimmer-template-tag": "^0.4.1",
135
136
  "typescript": "^5.3.3",
136
- "@nullvoxpopuli/limber-untyped": "0.0.0"
137
+ "@nullvoxpopuli/limber-untyped": "0.0.1"
137
138
  },
138
139
  "volta": {
139
140
  "extends": "../../../package.json"
@@ -148,12 +149,20 @@
148
149
  "app-js": {}
149
150
  },
150
151
  "peerDependencies": {
151
- "@glimmer/compiler": ">= 0.86.0",
152
- "@glimmer/component": "^1.1.2",
153
- "@glimmer/syntax": ">= 0.86.0",
154
152
  "@glint/template": ">= 1.3.0",
155
- "ember-resources": ">= 6.4.2",
156
- "ember-source": ">= 5.5.0"
153
+ "@glimmer/compiler": ">= 0.86.0",
154
+ "@glimmer/syntax": ">= 0.86.0"
155
+ },
156
+ "peerDependenciesMeta": {
157
+ "@glint/template": {
158
+ "optional": true
159
+ },
160
+ "@glimmer/compiler": {
161
+ "optional": true
162
+ },
163
+ "@glimmer/syntax": {
164
+ "optional": true
165
+ }
157
166
  },
158
167
  "engines": {
159
168
  "node": ">= v16",
@@ -161,8 +170,7 @@
161
170
  "yarn": "use pnpm"
162
171
  },
163
172
  "scripts": {
164
- "build": "concurrently 'npm:build:*'",
165
- "build:js": "rollup --config",
173
+ "build": "rollup --config",
166
174
  "lint:types": "tsc --noEmit",
167
175
  "lint:fix": "pnpm -w exec lint fix",
168
176
  "start": "rollup --config --watch",
@@ -173,7 +181,6 @@
173
181
  "lint:hbs": "pnpm -w exec lint hbs",
174
182
  "lint:hbs:fix": "pnpm -w exec lint hbs:fix",
175
183
  "lint:prettier:fix": "pnpm -w exec lint prettier:fix",
176
- "lint:prettier": "pnpm -w exec lint prettier",
177
- "build:types": "tsc --emitDeclarationOnly --noEmit false"
184
+ "lint:prettier": "pnpm -w exec lint prettier"
178
185
  }
179
186
  }
@@ -0,0 +1,7 @@
1
+ import type { availablePlugins, availablePresets, transform } from '@babel/standalone';
2
+
3
+ export interface Babel {
4
+ availablePlugins: typeof availablePlugins;
5
+ availablePresets: typeof availablePresets;
6
+ transform: typeof transform;
7
+ }
@@ -1,12 +1,11 @@
1
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import { modules } from '../known-modules.ts';
2
+ import { modules } from './known-modules.ts';
3
3
 
4
- import type { ExtraModules } from '../types.ts';
5
4
  import type Component from '@glimmer/component';
6
5
 
7
6
  export function evalSnippet(
8
7
  compiled: string,
9
- extraModules: ExtraModules = {}
8
+ extraModules: Record<string, unknown /* imported module */> = {}
10
9
  ): {
11
10
  default: Component;
12
11
  services?: { [key: string]: unknown };
@@ -21,7 +20,6 @@ export function evalSnippet(
21
20
  return preConfigured || window.require(moduleName);
22
21
  }
23
22
 
24
- // https://github.com/glimmerjs/glimmer-experimental/blob/master/packages/examples/playground/src/utils/eval-snippet.ts
25
23
  eval(compiled);
26
24
 
27
25
  return Object.assign(exports, { require }) as {
@@ -0,0 +1,123 @@
1
+ import { importSync } from '@embroider/macros';
2
+
3
+ import babelPluginEmberTemplateCompilation from 'babel-plugin-ember-template-compilation';
4
+
5
+ import { nameFor } from '../../utils.ts';
6
+ import { evalSnippet } from './eval.ts';
7
+
8
+ import type { CompileResult } from '../../types.ts';
9
+ import type { ComponentLike } from '@glint/template';
10
+
11
+ export interface Info {
12
+ code: string;
13
+ name: string;
14
+ }
15
+
16
+ /**
17
+ * @public
18
+ * Transpiles GlimmerJS (*.gjs) formatted text into and evaluates as a JS Module.
19
+ * The returned component can be invoked explicitly in the consuming project.
20
+ *
21
+ * SEE: README for example usage
22
+ *
23
+ * @param {string} code: the code to be compiled
24
+ * @param {Object} extraModules: map of import paths to modules. This isn't needed
25
+ * for classic ember projects, but for strict static ember projects, extraModules
26
+ * will need to be pasesd if compileJS is intended to be used in a styleguide or
27
+ * if there are additional modules that could be imported in the passed `code`.
28
+ *
29
+ * Later on, imports that are not present by default (ember/glimmer) or that
30
+ * are not provided by extraModules will be searched on npm to see if a package
31
+ * needs to be downloaded before running the `code` / invoking the component
32
+ */
33
+ export async function compileJS(
34
+ code: string,
35
+ extraModules?: Record<string, unknown>
36
+ ): Promise<CompileResult> {
37
+ let name = nameFor(code);
38
+ let component: undefined | ComponentLike;
39
+ let error: undefined | Error;
40
+
41
+ try {
42
+ let compiled = await transpile({ code: code, name });
43
+
44
+ if (!compiled) {
45
+ throw new Error(`Compiled output is missing`);
46
+ }
47
+
48
+ component = evalSnippet(compiled, extraModules).default as unknown as ComponentLike;
49
+ } catch (e) {
50
+ error = e as Error | undefined;
51
+ }
52
+
53
+ return { name, component, error };
54
+ }
55
+
56
+ async function transpile({ code: input, name }: Info) {
57
+ let preprocessed = await preprocess(input, name);
58
+ let result = await transform(preprocessed, name);
59
+
60
+ if (!result) {
61
+ return;
62
+ }
63
+
64
+ let { code } = result;
65
+
66
+ return code;
67
+ }
68
+
69
+ import type { Babel } from './babel.ts';
70
+
71
+ const compiler = importSync('ember-source/dist/ember-template-compiler.js');
72
+
73
+ let processor: any;
74
+ let fetchingPromise: Promise<any>;
75
+
76
+ async function preprocess(input: string, name: string): Promise<string> {
77
+ if (!fetchingPromise) {
78
+ fetchingPromise = import('content-tag');
79
+ }
80
+
81
+ if (!processor) {
82
+ let { Preprocessor } = await fetchingPromise;
83
+
84
+ processor = new Preprocessor();
85
+ }
86
+
87
+ return processor.process(input, `${name}.js`);
88
+ }
89
+
90
+ async function transform(
91
+ intermediate: string,
92
+ name: string,
93
+ options: any = {}
94
+ ): Promise<ReturnType<Babel['transform']>> {
95
+ let babel = (await import('@babel/standalone')) as Babel;
96
+
97
+ return babel.transform(intermediate, {
98
+ filename: `${name}.js`,
99
+ plugins: [
100
+ // [babelPluginIntermediateGJS],
101
+ [
102
+ babelPluginEmberTemplateCompilation,
103
+ {
104
+ compiler,
105
+ },
106
+ ],
107
+ [babel.availablePlugins['proposal-decorators'], { legacy: true }],
108
+ [babel.availablePlugins['proposal-class-properties']],
109
+ ],
110
+ presets: [
111
+ [
112
+ babel.availablePresets['env'],
113
+ {
114
+ // false -- keeps ES Modules
115
+ modules: 'cjs',
116
+ targets: { esmodules: true },
117
+ forceAllTransforms: false,
118
+ ...options,
119
+ },
120
+ ],
121
+ ],
122
+ });
123
+ }
@@ -11,9 +11,9 @@ import { on } from '@ember/modifier';
11
11
  import { createTemplateFactory } from '@ember/template-factory';
12
12
  import { importSync } from '@embroider/macros';
13
13
 
14
- import { nameFor } from './utils.ts';
14
+ import { nameFor } from '../utils.ts';
15
15
 
16
- import type { CompileResult } from './types.ts';
16
+ import type { CompileResult } from '../types.ts';
17
17
  import type { ComponentLike } from '@glint/template';
18
18
 
19
19
  // These things are pre-bundled in the old system.
@@ -75,13 +75,24 @@ function compileTemplate(source: string, { moduleName, scope = {} }: CompileTemp
75
75
  // Copied from @glimmer/compiler/lib/compiler#precompile
76
76
  let [block, usedLocals] = precompileJSON(source, options);
77
77
 
78
- let usedScope = usedLocals.map((key: string) => localScope[key]);
78
+ let usedScope = usedLocals.map((key: string) => {
79
+ let value = localScope[key];
80
+
81
+ if (!value) {
82
+ throw new Error(
83
+ `Attempt to use ${key} in compiled hbs, but it was not available in scope. ` +
84
+ `Available scope includes: ${Object.keys(localScope)}`
85
+ );
86
+ }
87
+
88
+ return value;
89
+ });
79
90
 
80
91
  let blockJSON = JSON.stringify(block);
81
92
  let templateJSONObject = {
82
93
  id: moduleName,
83
94
  block: blockJSON,
84
- moduleName: moduleName ?? '(unknown template module)',
95
+ moduleName: moduleName ?? '(dynamically compiled component)',
85
96
  scope: () => usedScope,
86
97
  isStrictMode: true,
87
98
  };
@@ -8,7 +8,7 @@ import { visit } from 'unist-util-visit';
8
8
 
9
9
  import { invocationOf, nameFor } from '../utils.ts';
10
10
 
11
- import type { UnifiedPlugin } from './types.ts';
11
+ import type { UnifiedPlugin } from '../types.ts';
12
12
  import type { Node } from 'hast';
13
13
  import type { Code, Text } from 'mdast';
14
14
  import type { Parent } from 'unist';
@@ -294,6 +294,12 @@ function buildCompiler(options: ParseMarkdownOptions) {
294
294
  });
295
295
  });
296
296
 
297
+ if (options.rehypePlugins) {
298
+ options.rehypePlugins.forEach((plugin) => {
299
+ compiler = compiler.use(plugin) as any;
300
+ });
301
+ }
302
+
297
303
  compiler = compiler.use(rehypeRaw, { passThrough: ['glimmer_raw', 'raw'] }).use(() => (tree) => {
298
304
  visit(tree, 'glimmer_raw', (node: Node) => {
299
305
  node.type = 'raw';
@@ -316,6 +322,7 @@ interface ParseMarkdownOptions {
316
322
  CopyComponent?: string;
317
323
  ShadowComponent?: string;
318
324
  remarkPlugins?: UnifiedPlugin[];
325
+ rehypePlugins?: UnifiedPlugin[];
319
326
  }
320
327
 
321
328
  /**
@@ -1,11 +1,10 @@
1
- import { invocationName } from '../utils.ts';
1
+ import { invocationName } from './utils.ts';
2
2
 
3
- import type { CompileResult } from '../types.ts';
4
- import type { ExtractedCode } from './markdown-to-ember.ts';
5
- import type { UnifiedPlugin } from './types.ts';
3
+ import type { ExtractedCode } from './formats/markdown.ts';
4
+ import type { CompileResult, UnifiedPlugin } from './types.ts';
6
5
  import type { EvalImportMap, ScopeMap } from './types.ts';
7
6
 
8
- async function compileAll(js: { code: string }[], importMap?: EvalImportMap) {
7
+ async function compileGJSArray(js: { code: string }[], importMap?: EvalImportMap) {
9
8
  let modules = await Promise.all(
10
9
  js.map(async ({ code }) => {
11
10
  return await compileGJS(code, importMap);
@@ -20,7 +19,7 @@ export async function compileGJS(
20
19
  importMap?: EvalImportMap
21
20
  ): Promise<CompileResult> {
22
21
  try {
23
- let { compileJS } = await import('../js.ts');
22
+ let { compileJS } = await import('./formats/gjs/index.ts');
24
23
 
25
24
  return await compileJS(gjsInput, importMap);
26
25
  } catch (error) {
@@ -36,7 +35,7 @@ export async function compileHBS(
36
35
  }
37
36
  ): Promise<CompileResult> {
38
37
  try {
39
- let { compileHBS } = await import('../hbs.ts');
38
+ let { compileHBS } = await import('./formats/hbs.ts');
40
39
 
41
40
  return compileHBS(hbsInput, options);
42
41
  } catch (error) {
@@ -46,7 +45,10 @@ export async function compileHBS(
46
45
 
47
46
  async function extractScope(
48
47
  liveCode: ExtractedCode[],
49
- importMap?: EvalImportMap
48
+ options?: {
49
+ importMap?: EvalImportMap;
50
+ topLevelScope?: ScopeMap;
51
+ }
50
52
  ): Promise<CompileResult[]> {
51
53
  let scope: CompileResult[] = [];
52
54
 
@@ -54,7 +56,7 @@ async function extractScope(
54
56
  let js = liveCode.filter((code) => ['js', 'gjs'].includes(code.lang));
55
57
 
56
58
  if (js.length > 0) {
57
- let compiled = await compileAll(js, importMap);
59
+ let compiled = await compileGJSArray(js, options?.importMap);
58
60
 
59
61
  await Promise.all(
60
62
  compiled.map(async (info) => {
@@ -74,7 +76,7 @@ async function extractScope(
74
76
  }
75
77
 
76
78
  for (let { code } of hbs) {
77
- let compiled = await compileHBS(code);
79
+ let compiled = await compileHBS(code, { scope: options?.topLevelScope });
78
80
 
79
81
  scope.push(compiled);
80
82
  }
@@ -92,7 +94,6 @@ export async function compileMD(
92
94
  ShadowComponent?: string;
93
95
  }
94
96
  ): Promise<CompileResult & { rootTemplate?: string }> {
95
- let importMap = options?.importMap;
96
97
  let topLevelScope = options?.topLevelScope ?? {};
97
98
  let rootTemplate: string;
98
99
  let liveCode: ExtractedCode[];
@@ -108,7 +109,7 @@ export async function compileMD(
108
109
  * compiled rootTemplate can invoke them
109
110
  */
110
111
  try {
111
- let { parseMarkdown } = await import('./markdown-to-ember.ts');
112
+ let { parseMarkdown } = await import('./formats/markdown.ts');
112
113
  let { templateOnlyGlimdown, blocks } = await parseMarkdown(glimdownInput, {
113
114
  CopyComponent: options?.CopyComponent,
114
115
  ShadowComponent: options?.ShadowComponent,
@@ -126,7 +127,7 @@ export async function compileMD(
126
127
  */
127
128
  if (liveCode.length > 0) {
128
129
  try {
129
- scope = await extractScope(liveCode, importMap);
130
+ scope = await extractScope(liveCode, options);
130
131
  } catch (error) {
131
132
  console.info({ scope });
132
133
  console.error(error);
@@ -1,14 +1,13 @@
1
1
  import { cell, resource, resourceFactory } from 'ember-resources';
2
2
 
3
- import { nameFor } from '../utils.ts';
4
3
  import {
5
4
  compileGJS as processGJS,
6
5
  compileHBS as processHBS,
7
6
  compileMD as processMD,
8
7
  } from './formats.ts';
8
+ import { nameFor } from './utils.ts';
9
9
 
10
- import type { CompileResult } from '../types.ts';
11
- import type { UnifiedPlugin } from './types.ts';
10
+ import type { CompileResult, UnifiedPlugin } from './types.ts';
12
11
  import type { EvalImportMap, ScopeMap } from './types.ts';
13
12
  import type { ComponentLike } from '@glint/template';
14
13
  type Format = 'glimdown' | 'gjs' | 'hbs';
@@ -0,0 +1,26 @@
1
+ import type { ComponentLike } from '@glint/template';
2
+ import type { Plugin } from 'unified';
3
+
4
+ export interface EvalImportMap {
5
+ [moduleName: string]: ScopeMap;
6
+ }
7
+
8
+ export interface ScopeMap {
9
+ [localName: string]: unknown;
10
+ }
11
+
12
+ export type UnifiedPlugin = Plugin; // Parameters<ReturnType<typeof unified>['use']>[0];
13
+
14
+ export interface CompileResult {
15
+ component?: ComponentLike;
16
+ error?: Error;
17
+ name: string;
18
+ }
19
+
20
+ export type Options = {
21
+ /**
22
+ * @internal
23
+ * @deprecated do not use - not under semver
24
+ */
25
+ skypack?: boolean;
26
+ };
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { compile, Compiled } from './compile/index.ts';
2
+ export { invocationName, invocationOf, nameFor } from './compile/utils.ts';
3
+
4
+ // Public Types
5
+ export type { CompileResult } from './compile/types';
@@ -1,4 +1,4 @@
1
- import { CACHE } from '../browser/compile/index.ts';
1
+ import { CACHE } from '../compile/index.ts';
2
2
 
3
3
  export function clearCompileCache() {
4
4
  CACHE.clear();
@@ -1,2 +0,0 @@
1
- export { CACHE } from './compile/index.ts';
2
- //# sourceMappingURL=__PRIVATE__.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"__PRIVATE__.d.ts","sourceRoot":"","sources":["../../src/browser/__PRIVATE__.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC"}
@@ -1,9 +0,0 @@
1
- import type { ExtraModules } from '../types.ts';
2
- import type Component from '@glimmer/component';
3
- export declare function evalSnippet(compiled: string, extraModules?: ExtraModules): {
4
- default: Component;
5
- services?: {
6
- [key: string]: unknown;
7
- };
8
- };
9
- //# sourceMappingURL=eval.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"eval.d.ts","sourceRoot":"","sources":["../../../src/browser/cjs/eval.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,SAAS,MAAM,oBAAoB,CAAC;AAEhD,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,YAAY,GAAE,YAAiB,GAC9B;IACD,OAAO,EAAE,SAAS,CAAC;IACnB,QAAQ,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;CACvC,CAmBA"}
@@ -1,7 +0,0 @@
1
- import type { CompileResult, ExtraModules } from '../types.ts';
2
- export interface Info {
3
- code: string;
4
- name: string;
5
- }
6
- export declare function compileJS(code: string, extraModules?: ExtraModules): Promise<CompileResult>;
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/browser/cjs/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG/D,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAkBjG"}
@@ -1,18 +0,0 @@
1
- import type { CompileResult } from '../types.ts';
2
- import type { UnifiedPlugin } from './types.ts';
3
- import type { EvalImportMap, ScopeMap } from './types.ts';
4
- export declare function compileGJS(gjsInput: string, importMap?: EvalImportMap): Promise<CompileResult>;
5
- export declare function compileHBS(hbsInput: string, options?: {
6
- moduleName?: string;
7
- scope?: Record<string, unknown>;
8
- }): Promise<CompileResult>;
9
- export declare function compileMD(glimdownInput: string, options?: {
10
- importMap?: EvalImportMap;
11
- topLevelScope?: ScopeMap;
12
- remarkPlugins?: UnifiedPlugin[];
13
- CopyComponent?: string;
14
- ShadowComponent?: string;
15
- }): Promise<CompileResult & {
16
- rootTemplate?: string;
17
- }>;
18
- //# sourceMappingURL=formats.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../../../src/browser/compile/formats.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAY1D,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,aAAa,GACxB,OAAO,CAAC,aAAa,CAAC,CAQxB;AAED,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IACR,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,GACA,OAAO,CAAC,aAAa,CAAC,CAQxB;AAwCD,wBAAsB,SAAS,CAC7B,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE;IACR,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,aAAa,CAAC,EAAE,QAAQ,CAAC;IACzB,aAAa,CAAC,EAAE,aAAa,EAAE,CAAC;IAChC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,GACA,OAAO,CAAC,aAAa,GAAG;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAkFpD"}