ember-repl 6.0.0 → 7.0.1
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/LICENSE.md +1 -1
- package/README.md +2 -404
- package/config/.try.mjs +87 -0
- package/config/addon-main.cjs +7 -0
- package/config/attw.json +7 -0
- package/config/babel.publish.config.cjs +29 -0
- package/config/ember-cli-update.json +21 -0
- package/config/rollup.config.mjs +44 -0
- package/config/testem.cjs +35 -0
- package/config/tsconfig.publish.json +15 -0
- package/config/vite.config.mjs +36 -0
- package/declarations/compile/Compiled.d.ts +7 -0
- package/declarations/compile/Compiled.d.ts.map +1 -0
- package/declarations/compile/compile.d.ts +17 -0
- package/declarations/compile/compile.d.ts.map +1 -0
- package/declarations/compile/state.d.ts +43 -0
- package/declarations/compile/state.d.ts.map +1 -0
- package/declarations/compile/types.d.ts +5 -12
- package/declarations/compile/types.d.ts.map +1 -1
- package/declarations/index.d.ts +6 -2
- package/declarations/index.d.ts.map +1 -1
- package/declarations/services/compiler.d.ts +94 -0
- package/declarations/services/compiler.d.ts.map +1 -0
- package/declarations/services/known-modules.d.ts +7 -0
- package/declarations/services/known-modules.d.ts.map +1 -0
- package/declarations/setup.d.ts +7 -0
- package/declarations/setup.d.ts.map +1 -0
- package/declarations/test-support.d.ts +20 -0
- package/declarations/test-support.d.ts.map +1 -0
- package/dist/_commonjsHelpers-BAGoDD49.js +37 -0
- package/dist/_commonjsHelpers-BAGoDD49.js.map +1 -0
- package/dist/babel-8wMrbxkT.js +110427 -0
- package/dist/babel-8wMrbxkT.js.map +1 -0
- package/dist/blank-line-Bzg2Qt4K.js +482 -0
- package/dist/blank-line-Bzg2Qt4K.js.map +1 -0
- package/dist/compile/Compiled.js +26 -0
- package/dist/compile/Compiled.js.map +1 -0
- package/dist/compile/compile.js +62 -0
- package/dist/compile/compile.js.map +1 -0
- package/dist/compile/state.js +75 -0
- package/dist/compile/state.js.map +1 -0
- package/dist/compile/utils.js +213 -2
- package/dist/compile/utils.js.map +1 -1
- package/dist/default-CoqAuVeH.js +4 -0
- package/dist/default-CoqAuVeH.js.map +1 -0
- package/dist/index-BTx1k6gT.js +323 -0
- package/dist/index-BTx1k6gT.js.map +1 -0
- package/dist/index-Bxzjtr16.js +87 -0
- package/dist/index-Bxzjtr16.js.map +1 -0
- package/dist/index-C371bO_b.js +1553 -0
- package/dist/index-C371bO_b.js.map +1 -0
- package/dist/index-C4AyeeIa.js +5721 -0
- package/dist/index-C4AyeeIa.js.map +1 -0
- package/dist/index-C8S2G0FH.js +1953 -0
- package/dist/index-C8S2G0FH.js.map +1 -0
- package/dist/index-CCcIVEUK.js +409 -0
- package/dist/index-CCcIVEUK.js.map +1 -0
- package/dist/index-CDSIcg03.js +9070 -0
- package/dist/index-CDSIcg03.js.map +1 -0
- package/dist/index-D8szzCn3.js +2 -0
- package/dist/index-D8szzCn3.js.map +1 -0
- package/dist/index-DBBNT106.js +2644 -0
- package/dist/index-DBBNT106.js.map +1 -0
- package/dist/index-DP_Su7Zc.js +362 -0
- package/dist/index-DP_Su7Zc.js.map +1 -0
- package/dist/index-DejgrVqh.js +11299 -0
- package/dist/index-DejgrVqh.js.map +1 -0
- package/dist/index-Dr5iYoKt.js +1551 -0
- package/dist/index-Dr5iYoKt.js.map +1 -0
- package/dist/index-DxolpiGq.js +3336 -0
- package/dist/index-DxolpiGq.js.map +1 -0
- package/dist/index-ZyJlPFQY.js +249 -0
- package/dist/index-ZyJlPFQY.js.map +1 -0
- package/dist/index-k6CfLgeq.js +26 -0
- package/dist/index-k6CfLgeq.js.map +1 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/services/compiler.js +329 -0
- package/dist/services/compiler.js.map +1 -0
- package/dist/services/known-modules.js +123 -0
- package/dist/services/known-modules.js.map +1 -0
- package/dist/setup.js +15 -0
- package/dist/setup.js.map +1 -0
- package/dist/test-support.js +33 -0
- package/dist/test-support.js.map +1 -0
- package/package.json +117 -138
- package/src/compile/Compiled.ts +45 -0
- package/src/compile/compile.ts +89 -0
- package/src/compile/state.ts +88 -0
- package/src/compile/types.ts +14 -13
- package/src/index.ts +6 -2
- package/src/services/compiler.ts +401 -0
- package/src/services/known-modules.ts +130 -0
- package/src/setup.ts +26 -0
- package/src/test-support.ts +64 -0
- package/addon-main.cjs +0 -5
- package/declarations/__PRIVATE__.d.ts +0 -2
- package/declarations/__PRIVATE__.d.ts.map +0 -1
- package/declarations/compile/formats/gjs/babel.d.ts +0 -7
- package/declarations/compile/formats/gjs/babel.d.ts.map +0 -1
- package/declarations/compile/formats/gjs/eval.d.ts +0 -8
- package/declarations/compile/formats/gjs/eval.d.ts.map +0 -1
- package/declarations/compile/formats/gjs/index.d.ts +0 -24
- package/declarations/compile/formats/gjs/index.d.ts.map +0 -1
- package/declarations/compile/formats/gjs/known-modules.d.ts +0 -48
- package/declarations/compile/formats/gjs/known-modules.d.ts.map +0 -1
- package/declarations/compile/formats/hbs.d.ts +0 -17
- package/declarations/compile/formats/hbs.d.ts.map +0 -1
- package/declarations/compile/formats/markdown.d.ts +0 -22
- package/declarations/compile/formats/markdown.d.ts.map +0 -1
- package/declarations/compile/formats.d.ts +0 -17
- package/declarations/compile/formats.d.ts.map +0 -1
- package/declarations/compile/index.d.ts +0 -80
- package/declarations/compile/index.d.ts.map +0 -1
- package/declarations/test-support/index.d.ts +0 -2
- package/declarations/test-support/index.d.ts.map +0 -1
- package/dist/__PRIVATE__.js +0 -2
- package/dist/__PRIVATE__.js.map +0 -1
- package/dist/compile/formats/gjs/babel.js +0 -2
- package/dist/compile/formats/gjs/babel.js.map +0 -1
- package/dist/compile/formats/gjs/eval.js +0 -19
- package/dist/compile/formats/gjs/eval.js.map +0 -1
- package/dist/compile/formats/gjs/index.js +0 -122
- package/dist/compile/formats/gjs/index.js.map +0 -1
- package/dist/compile/formats/gjs/known-modules.js +0 -52
- package/dist/compile/formats/gjs/known-modules.js.map +0 -1
- package/dist/compile/formats/hbs.js +0 -93
- package/dist/compile/formats/hbs.js.map +0 -1
- package/dist/compile/formats/markdown.js +0 -266
- package/dist/compile/formats/markdown.js.map +0 -1
- package/dist/compile/formats.js +0 -173
- package/dist/compile/formats.js.map +0 -1
- package/dist/compile/index.js +0 -113
- package/dist/compile/index.js.map +0 -1
- package/dist/test-support/index.js +0 -8
- package/dist/test-support/index.js.map +0 -1
- package/src/__PRIVATE__.ts +0 -1
- package/src/compile/formats/gjs/babel.ts +0 -7
- package/src/compile/formats/gjs/eval.ts +0 -29
- package/src/compile/formats/gjs/index.ts +0 -153
- package/src/compile/formats/gjs/known-modules.ts +0 -49
- package/src/compile/formats/hbs.ts +0 -100
- package/src/compile/formats/markdown.ts +0 -345
- package/src/compile/formats.ts +0 -178
- package/src/compile/index.ts +0 -219
- package/src/test-support/index.ts +0 -5
package/dist/compile/formats.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { invocationName } from './utils.js';
|
|
2
|
-
|
|
3
|
-
async function compileGJSArray(js, importMap) {
|
|
4
|
-
const modules = await Promise.all(js.map(async ({
|
|
5
|
-
code
|
|
6
|
-
}) => {
|
|
7
|
-
return await compileGJS(code, importMap);
|
|
8
|
-
}));
|
|
9
|
-
return modules;
|
|
10
|
-
}
|
|
11
|
-
async function compileGJS(gjsInput, importMap) {
|
|
12
|
-
try {
|
|
13
|
-
const {
|
|
14
|
-
compileJS
|
|
15
|
-
} = await import('./formats/gjs/index.js');
|
|
16
|
-
return await compileJS(gjsInput, importMap);
|
|
17
|
-
} catch (error) {
|
|
18
|
-
return {
|
|
19
|
-
error: error,
|
|
20
|
-
name: 'unknown'
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
async function compileHBS(hbsInput, options) {
|
|
25
|
-
try {
|
|
26
|
-
const {
|
|
27
|
-
compileHBS
|
|
28
|
-
} = await import('./formats/hbs.js');
|
|
29
|
-
return compileHBS(hbsInput, options);
|
|
30
|
-
} catch (error) {
|
|
31
|
-
return {
|
|
32
|
-
error: error,
|
|
33
|
-
name: 'unknown'
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
async function extractScope(liveCode, options) {
|
|
38
|
-
const scope = [];
|
|
39
|
-
const hbs = liveCode.filter(code => code.lang === 'hbs');
|
|
40
|
-
const js = liveCode.filter(code => ['js', 'gjs'].includes(code.lang));
|
|
41
|
-
if (js.length > 0) {
|
|
42
|
-
const compiled = await compileGJSArray(js, options?.importMap);
|
|
43
|
-
await Promise.all(compiled.map(async info => {
|
|
44
|
-
// using web worker + import maps is not available yet (need firefox support)
|
|
45
|
-
// (and to somehow be able to point at npm)
|
|
46
|
-
//
|
|
47
|
-
// if ('importPath' in info) {
|
|
48
|
-
// return scope.push({
|
|
49
|
-
// moduleName: name,
|
|
50
|
-
// component: await import(/* webpackIgnore: true */ info.importPath),
|
|
51
|
-
// });
|
|
52
|
-
// }
|
|
53
|
-
|
|
54
|
-
return scope.push(info);
|
|
55
|
-
}));
|
|
56
|
-
}
|
|
57
|
-
for (const {
|
|
58
|
-
code
|
|
59
|
-
} of hbs) {
|
|
60
|
-
const compiled = await compileHBS(code, {
|
|
61
|
-
scope: options?.topLevelScope
|
|
62
|
-
});
|
|
63
|
-
scope.push(compiled);
|
|
64
|
-
}
|
|
65
|
-
return scope;
|
|
66
|
-
}
|
|
67
|
-
async function compileMD(glimdownInput, options) {
|
|
68
|
-
const topLevelScope = options?.topLevelScope ?? {};
|
|
69
|
-
let rootTemplate;
|
|
70
|
-
let liveCode;
|
|
71
|
-
let scope = [];
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Step 1: Convert Markdown To HTML (Ember).
|
|
75
|
-
*
|
|
76
|
-
* The remark plugin, remark-code-extra also extracts
|
|
77
|
-
* and transforms the code blocks we care about.
|
|
78
|
-
*
|
|
79
|
-
* These blocks will be compiled through babel and eval'd so the
|
|
80
|
-
* compiled rootTemplate can invoke them
|
|
81
|
-
*/
|
|
82
|
-
try {
|
|
83
|
-
const {
|
|
84
|
-
parseMarkdown
|
|
85
|
-
} = await import('./formats/markdown.js');
|
|
86
|
-
const {
|
|
87
|
-
templateOnlyGlimdown,
|
|
88
|
-
blocks
|
|
89
|
-
} = await parseMarkdown(glimdownInput, {
|
|
90
|
-
CopyComponent: options?.CopyComponent,
|
|
91
|
-
ShadowComponent: options?.ShadowComponent,
|
|
92
|
-
remarkPlugins: options?.remarkPlugins,
|
|
93
|
-
rehypePlugins: options?.rehypePlugins
|
|
94
|
-
});
|
|
95
|
-
rootTemplate = templateOnlyGlimdown;
|
|
96
|
-
liveCode = blocks;
|
|
97
|
-
} catch (error) {
|
|
98
|
-
return {
|
|
99
|
-
error: error,
|
|
100
|
-
name: 'unknown'
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Step 2: Compile the live code samples
|
|
106
|
-
*/
|
|
107
|
-
if (liveCode.length > 0) {
|
|
108
|
-
try {
|
|
109
|
-
scope = await extractScope(liveCode, options);
|
|
110
|
-
} catch (error) {
|
|
111
|
-
console.info({
|
|
112
|
-
scope
|
|
113
|
-
});
|
|
114
|
-
console.error(error);
|
|
115
|
-
return {
|
|
116
|
-
error: error,
|
|
117
|
-
rootTemplate,
|
|
118
|
-
name: 'unknown'
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Make sure non of our snippets errored
|
|
125
|
-
*
|
|
126
|
-
* TODO: for these errors, report them differently so that we
|
|
127
|
-
* can render the 'Ember' and still highlight the correct line?
|
|
128
|
-
* or maybe there is a way to highlight in the editor instead?
|
|
129
|
-
*/
|
|
130
|
-
for (const {
|
|
131
|
-
error,
|
|
132
|
-
component
|
|
133
|
-
} of scope) {
|
|
134
|
-
if (!component) {
|
|
135
|
-
if (error) {
|
|
136
|
-
return {
|
|
137
|
-
error,
|
|
138
|
-
rootTemplate,
|
|
139
|
-
name: 'unknown'
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Step 4: Compile the Ember Template
|
|
147
|
-
*/
|
|
148
|
-
try {
|
|
149
|
-
const localScope = scope.reduce((accum, {
|
|
150
|
-
component,
|
|
151
|
-
name
|
|
152
|
-
}) => {
|
|
153
|
-
accum[invocationName(name)] = component;
|
|
154
|
-
return accum;
|
|
155
|
-
}, {});
|
|
156
|
-
return await compileHBS(rootTemplate, {
|
|
157
|
-
moduleName: 'DynamicRootTemplate',
|
|
158
|
-
scope: {
|
|
159
|
-
...topLevelScope,
|
|
160
|
-
...localScope
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
} catch (error) {
|
|
164
|
-
return {
|
|
165
|
-
error: error,
|
|
166
|
-
rootTemplate,
|
|
167
|
-
name: 'unknown'
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export { compileGJS, compileHBS, compileMD };
|
|
173
|
-
//# sourceMappingURL=formats.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formats.js","sources":["../../src/compile/formats.ts"],"sourcesContent":["import { invocationName } from './utils.ts';\n\nimport type { ExtractedCode } from './formats/markdown.ts';\nimport type { CompileResult, EvalImportMap, ScopeMap, UnifiedPlugin } from './types.ts';\n\nasync function compileGJSArray(js: { code: string }[], importMap?: EvalImportMap) {\n const modules = await Promise.all(\n js.map(async ({ code }) => {\n return await compileGJS(code, importMap);\n })\n );\n\n return modules;\n}\n\nexport async function compileGJS(\n gjsInput: string,\n importMap?: EvalImportMap\n): Promise<CompileResult> {\n try {\n const { compileJS } = await import('./formats/gjs/index.ts');\n\n return await compileJS(gjsInput, importMap);\n } catch (error) {\n return { error: error as Error, name: 'unknown' };\n }\n}\n\nexport async function compileHBS(\n hbsInput: string,\n options?: {\n moduleName?: string;\n scope?: Record<string, unknown>;\n }\n): Promise<CompileResult> {\n try {\n const { compileHBS } = await import('./formats/hbs.ts');\n\n return compileHBS(hbsInput, options);\n } catch (error) {\n return { error: error as Error, name: 'unknown' };\n }\n}\n\nasync function extractScope(\n liveCode: ExtractedCode[],\n options?: {\n importMap?: EvalImportMap;\n topLevelScope?: ScopeMap;\n }\n): Promise<CompileResult[]> {\n const scope: CompileResult[] = [];\n\n const hbs = liveCode.filter((code) => code.lang === 'hbs');\n const js = liveCode.filter((code) => ['js', 'gjs'].includes(code.lang));\n\n if (js.length > 0) {\n const compiled = await compileGJSArray(js, options?.importMap);\n\n await Promise.all(\n compiled.map(async (info) => {\n // using web worker + import maps is not available yet (need firefox support)\n // (and to somehow be able to point at npm)\n //\n // if ('importPath' in info) {\n // return scope.push({\n // moduleName: name,\n // component: await import(/* webpackIgnore: true */ info.importPath),\n // });\n // }\n\n return scope.push(info);\n })\n );\n }\n\n for (const { code } of hbs) {\n const compiled = await compileHBS(code, { scope: options?.topLevelScope });\n\n scope.push(compiled);\n }\n\n return scope;\n}\n\nexport async function compileMD(\n glimdownInput: string,\n options?: {\n importMap?: EvalImportMap;\n topLevelScope?: ScopeMap;\n remarkPlugins?: UnifiedPlugin[];\n rehypePlugins?: UnifiedPlugin[];\n CopyComponent?: string;\n ShadowComponent?: string;\n }\n): Promise<CompileResult & { rootTemplate?: string }> {\n const topLevelScope = options?.topLevelScope ?? {};\n let rootTemplate: string;\n let liveCode: ExtractedCode[];\n let scope: CompileResult[] = [];\n\n /**\n * Step 1: Convert Markdown To HTML (Ember).\n *\n * The remark plugin, remark-code-extra also extracts\n * and transforms the code blocks we care about.\n *\n * These blocks will be compiled through babel and eval'd so the\n * compiled rootTemplate can invoke them\n */\n try {\n const { parseMarkdown } = await import('./formats/markdown.ts');\n const { templateOnlyGlimdown, blocks } = await parseMarkdown(glimdownInput, {\n CopyComponent: options?.CopyComponent,\n ShadowComponent: options?.ShadowComponent,\n remarkPlugins: options?.remarkPlugins,\n rehypePlugins: options?.rehypePlugins,\n });\n\n rootTemplate = templateOnlyGlimdown;\n liveCode = blocks;\n } catch (error) {\n return { error: error as Error, name: 'unknown' };\n }\n\n /**\n * Step 2: Compile the live code samples\n */\n if (liveCode.length > 0) {\n try {\n scope = await extractScope(liveCode, options);\n } catch (error) {\n console.info({ scope });\n console.error(error);\n\n return { error: error as Error, rootTemplate, name: 'unknown' };\n }\n }\n\n /**\n * Make sure non of our snippets errored\n *\n * TODO: for these errors, report them differently so that we\n * can render the 'Ember' and still highlight the correct line?\n * or maybe there is a way to highlight in the editor instead?\n */\n for (const { error, component } of scope) {\n if (!component) {\n if (error) {\n return { error, rootTemplate, name: 'unknown' };\n }\n }\n }\n\n /**\n * Step 4: Compile the Ember Template\n */\n try {\n const localScope = scope.reduce(\n (accum, { component, name }) => {\n accum[invocationName(name)] = component;\n\n return accum;\n },\n {} as Record<string, unknown>\n );\n\n return await compileHBS(rootTemplate, {\n moduleName: 'DynamicRootTemplate',\n scope: {\n ...topLevelScope,\n ...localScope,\n },\n });\n } catch (error) {\n return { error: error as Error, rootTemplate, name: 'unknown' };\n }\n}\n"],"names":["compileGJSArray","js","importMap","modules","Promise","all","map","code","compileGJS","gjsInput","compileJS","error","name","compileHBS","hbsInput","options","extractScope","liveCode","scope","hbs","filter","lang","includes","length","compiled","info","push","topLevelScope","compileMD","glimdownInput","rootTemplate","parseMarkdown","templateOnlyGlimdown","blocks","CopyComponent","ShadowComponent","remarkPlugins","rehypePlugins","console","component","localScope","reduce","accum","invocationName","moduleName"],"mappings":";;AAKA,eAAeA,eAAeA,CAACC,EAAsB,EAAEC,SAAyB,EAAE;EAChF,MAAMC,OAAO,GAAG,MAAMC,OAAO,CAACC,GAAG,CAC/BJ,EAAE,CAACK,GAAG,CAAC,OAAO;AAAEC,IAAAA;AAAK,GAAC,KAAK;AACzB,IAAA,OAAO,MAAMC,UAAU,CAACD,IAAI,EAAEL,SAAS,CAAC;AAC1C,GAAC,CACH,CAAC;AAED,EAAA,OAAOC,OAAO;AAChB;AAEO,eAAeK,UAAUA,CAC9BC,Q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import { resourceFactory, resource, cell } from 'ember-resources';
|
|
2
|
-
import { compileMD, compileGJS, compileHBS } from './formats.js';
|
|
3
|
-
import { nameFor } from './utils.js';
|
|
4
|
-
|
|
5
|
-
const CACHE = new Map();
|
|
6
|
-
const SUPPORTED_FORMATS = ['glimdown', 'gjs', 'hbs'];
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Compile GitHub-flavored Markdown with GJS support
|
|
10
|
-
* and optionally render gjs-snippets via a `live` meta tag
|
|
11
|
-
* on the code fences.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Compile GJS
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Compile a stateless component using just the template
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* This compileMD is a more robust version of the raw compiling used in "formats".
|
|
24
|
-
* This function manages cache, and has events for folks building UIs to hook in to
|
|
25
|
-
*/
|
|
26
|
-
async function compile(text, options) {
|
|
27
|
-
const {
|
|
28
|
-
onSuccess,
|
|
29
|
-
onError,
|
|
30
|
-
onCompileStart
|
|
31
|
-
} = options;
|
|
32
|
-
const id = nameFor(`${options.format}:${text}`);
|
|
33
|
-
const existing = CACHE.get(id);
|
|
34
|
-
if (existing) {
|
|
35
|
-
onSuccess(existing);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (!SUPPORTED_FORMATS.includes(options.format)) {
|
|
39
|
-
await onError(`Unsupported format: ${options.format}. Supported formats: ${SUPPORTED_FORMATS}`);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
await onCompileStart();
|
|
43
|
-
if (!text) {
|
|
44
|
-
await onError('No Input Document yet');
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
let result;
|
|
48
|
-
if (options.format === 'glimdown') {
|
|
49
|
-
result = await compileMD(text, options);
|
|
50
|
-
} else if (options.format === 'gjs') {
|
|
51
|
-
result = await compileGJS(text, options.importMap);
|
|
52
|
-
} else if (options.format === 'hbs') {
|
|
53
|
-
result = await compileHBS(text, {
|
|
54
|
-
scope: options.topLevelScope
|
|
55
|
-
});
|
|
56
|
-
} else {
|
|
57
|
-
await onError(`Unsupported format: ${options.format}. Supported formats: ${SUPPORTED_FORMATS}`);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (result.error) {
|
|
61
|
-
await onError(result.error.message || `${result.error}`);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
CACHE.set(id, result.component);
|
|
65
|
-
await onSuccess(result.component);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @internal
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* By default, this compiles to `glimdown`. A Markdown format which
|
|
74
|
-
* extracts `live` tagged code snippets and compiles them to components.
|
|
75
|
-
*/
|
|
76
|
-
function Compiled(markdownText, maybeOptions) {
|
|
77
|
-
return resource(() => {
|
|
78
|
-
const maybeObject = typeof maybeOptions === 'function' ? maybeOptions() : maybeOptions;
|
|
79
|
-
const format = (typeof maybeObject === 'string' ? maybeObject : maybeObject?.format) || 'glimdown';
|
|
80
|
-
const options = (typeof maybeObject === 'string' ? {} : maybeObject) || {};
|
|
81
|
-
const input = typeof markdownText === 'function' ? markdownText() : markdownText;
|
|
82
|
-
const ready = cell(false);
|
|
83
|
-
const error = cell();
|
|
84
|
-
const result = cell();
|
|
85
|
-
if (input) {
|
|
86
|
-
compile(input, {
|
|
87
|
-
// narrowing is hard here, but this is an implementation detail
|
|
88
|
-
format: format,
|
|
89
|
-
onSuccess: async component => {
|
|
90
|
-
result.current = component;
|
|
91
|
-
ready.set(true);
|
|
92
|
-
error.set(null);
|
|
93
|
-
},
|
|
94
|
-
onError: async e => {
|
|
95
|
-
error.set(e);
|
|
96
|
-
},
|
|
97
|
-
onCompileStart: async () => {
|
|
98
|
-
ready.set(false);
|
|
99
|
-
},
|
|
100
|
-
...options
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
return () => ({
|
|
104
|
-
isReady: ready.current,
|
|
105
|
-
error: error.current,
|
|
106
|
-
component: result.current
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
resourceFactory(Compiled);
|
|
111
|
-
|
|
112
|
-
export { CACHE, Compiled, compile };
|
|
113
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/compile/index.ts"],"sourcesContent":["import { cell, resource, resourceFactory } from 'ember-resources';\n\nimport {\n compileGJS as processGJS,\n compileHBS as processHBS,\n compileMD as processMD,\n} from './formats.ts';\nimport { nameFor } from './utils.ts';\n\nimport type { CompileResult, EvalImportMap, ScopeMap, UnifiedPlugin } from './types.ts';\nimport type { ComponentLike } from '@glint/template';\n\ntype Format = 'glimdown' | 'gjs' | 'hbs';\n\nexport const CACHE = new Map<string, ComponentLike>();\n\ninterface Events {\n onSuccess: (component: ComponentLike) => Promise<unknown> | unknown;\n onError: (error: string) => Promise<unknown> | unknown;\n onCompileStart: () => Promise<unknown> | unknown;\n}\n\ninterface Scope {\n importMap?: EvalImportMap;\n}\n\nconst SUPPORTED_FORMATS = ['glimdown', 'gjs', 'hbs'];\n\ninterface GlimdownOptions extends Scope, Events {\n format: 'glimdown';\n remarkPlugins?: UnifiedPlugin[];\n rehypePlugins?: UnifiedPlugin[];\n CopyComponent?: string;\n ShadowComponent?: string;\n topLevelScope?: ScopeMap;\n}\ninterface GJSOptions extends Scope, Events {\n format: 'gjs';\n\n // Make overloads easier?\n remarkPlugins?: never;\n rehypePlugins?: never;\n CopyComponent?: never;\n ShadowComponent?: never;\n}\n\ninterface HBSOptions extends Scope, Events {\n format: 'hbs';\n topLevelScope?: ScopeMap;\n\n // Make overloads easier?\n remarkPlugins?: never;\n rehypePlugins?: never;\n CopyComponent?: never;\n ShadowComponent?: never;\n}\n\n/**\n * Compile GitHub-flavored Markdown with GJS support\n * and optionally render gjs-snippets via a `live` meta tag\n * on the code fences.\n */\nexport async function compile(text: string, options: GlimdownOptions): Promise<void>;\n\n/**\n * Compile GJS\n */\nexport async function compile(text: string, options: GJSOptions): Promise<void>;\n\n/**\n * Compile a stateless component using just the template\n */\nexport async function compile(text: string, options: HBSOptions): Promise<void>;\n\n/**\n * This compileMD is a more robust version of the raw compiling used in \"formats\".\n * This function manages cache, and has events for folks building UIs to hook in to\n */\nexport async function compile(\n text: string,\n options: GlimdownOptions | GJSOptions | HBSOptions\n): Promise<void> {\n const { onSuccess, onError, onCompileStart } = options;\n const id = nameFor(`${options.format}:${text}`);\n\n const existing = CACHE.get(id);\n\n if (existing) {\n onSuccess(existing);\n\n return;\n }\n\n if (!SUPPORTED_FORMATS.includes(options.format)) {\n await onError(`Unsupported format: ${options.format}. Supported formats: ${SUPPORTED_FORMATS}`);\n\n return;\n }\n\n await onCompileStart();\n\n if (!text) {\n await onError('No Input Document yet');\n\n return;\n }\n\n let result: CompileResult;\n\n if (options.format === 'glimdown') {\n result = await processMD(text, options);\n } else if (options.format === 'gjs') {\n result = await processGJS(text, options.importMap);\n } else if (options.format === 'hbs') {\n result = await processHBS(text, {\n scope: options.topLevelScope,\n });\n } else {\n await onError(\n `Unsupported format: ${(options as any).format}. Supported formats: ${SUPPORTED_FORMATS}`\n );\n\n return;\n }\n\n if (result.error) {\n await onError(result.error.message || `${result.error}`);\n\n return;\n }\n\n CACHE.set(id, result.component as ComponentLike);\n\n await onSuccess(result.component as ComponentLike);\n}\n\ntype Input = string | undefined | null;\n\ntype ExtraOptions =\n | {\n format: 'glimdown';\n remarkPlugins?: UnifiedPlugin[];\n rehypePlugins?: UnifiedPlugin[];\n importMap?: EvalImportMap;\n CopyComponent?: string;\n ShadowComponent?: string;\n topLevelScope?: ScopeMap;\n }\n | {\n format: 'hbs';\n topLevelScope?: ScopeMap;\n }\n | {\n format: 'gjs';\n importMap?: EvalImportMap;\n };\n\n/**\n * @internal\n */\nexport interface Value {\n isReady: boolean;\n error: string | null;\n component: ComponentLike;\n}\n\nexport function Compiled(markdownText: Input | (() => Input)): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: Format): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: () => Format): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: ExtraOptions): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: () => ExtraOptions): Value;\n\n/**\n * By default, this compiles to `glimdown`. A Markdown format which\n * extracts `live` tagged code snippets and compiles them to components.\n */\nexport function Compiled(\n markdownText: Input | (() => Input),\n maybeOptions?: Format | (() => Format) | ExtraOptions | (() => ExtraOptions)\n): Value {\n return resource(() => {\n const maybeObject = typeof maybeOptions === 'function' ? maybeOptions() : maybeOptions;\n const format =\n (typeof maybeObject === 'string' ? maybeObject : maybeObject?.format) || 'glimdown';\n const options = (typeof maybeObject === 'string' ? {} : maybeObject) || {};\n\n const input = typeof markdownText === 'function' ? markdownText() : markdownText;\n const ready = cell(false);\n const error = cell<string | null>();\n const result = cell<ComponentLike>();\n\n if (input) {\n compile(input, {\n // narrowing is hard here, but this is an implementation detail\n format: format as any,\n onSuccess: async (component) => {\n result.current = component;\n ready.set(true);\n error.set(null);\n },\n onError: async (e) => {\n error.set(e);\n },\n onCompileStart: async () => {\n ready.set(false);\n },\n ...options,\n });\n }\n\n return () => ({\n isReady: ready.current,\n error: error.current,\n component: result.current,\n });\n });\n}\n\nresourceFactory(Compiled);\n"],"names":["CACHE","Map","SUPPORTED_FORMATS","compile","text","options","onSuccess","onError","onCompileStart","id","nameFor","format","existing","get","includes","result","processMD","processGJS","importMap","processHBS","scope","topLevelScope","error","message","set","component","Compiled","markdownText","maybeOptions","resource","maybeObject","input","ready","cell","current","e","isReady","resourceFactory"],"mappings":";;;;MAcaA,KAAK,GAAG,IAAIC,GAAG;AAY5B,MAAMC,iBAAiB,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC;;AA+BpD;AACA;A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,EAAEA,MAAa;QACrBL,SAAS,EAAE,MAAOmB,SAAS,IAAK;UAC9BV,MAAM,CAACmB,OAAO,GAAGT,SAAS;AAC1BO,UAAAA,KAAK,CAACR,GAAG,CAAC,IAAI,CAAC;AACfF,UAAAA,KAAK,CAACE,GAAG,CAAC,IAAI,CAAC;SAChB;QACDjB,OAAO,EAAE,MAAO4B,CAAC,IAAK;AACpBb,UAAAA,KAAK,CAACE,GAAG,CAACW,CAAC,CAAC;SACb;QACD3B,cAAc,EAAE,YAAY;AAC1BwB,UAAAA,KAAK,CAACR,GAAG,CAAC,KAAK,CAAC;SACjB;QACD,GAAGnB;AACL,OAAC,CAAC;AACJ;AAEA,IAAA,OAAO,OAAO;MACZ+B,OAAO,EAAEJ,KAAK,CAACE,OAAO;MACtBZ,KAAK,EAAEA,KAAK,CAACY,OAAO;MACpBT,SAAS,EAAEV,MAAM,CAACmB;AACpB,KAAC,CAAC;AACJ,GAAC,CAAC;AACJ;AAEAG,eAAe,CAACX,QAAQ,CAAC;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/test-support/index.ts"],"sourcesContent":["import { CACHE } from '../compile/index.ts';\n\nexport function clearCompileCache() {\n CACHE.clear();\n}\n"],"names":["clearCompileCache","CACHE","clear"],"mappings":";;AAEO,SAASA,iBAAiBA,GAAG;EAClCC,KAAK,CAACC,KAAK,EAAE;AACf;;;;"}
|
package/src/__PRIVATE__.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { CACHE } from './compile/index.ts';
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { modules } from './known-modules.ts';
|
|
2
|
-
|
|
3
|
-
import type Component from '@glimmer/component';
|
|
4
|
-
|
|
5
|
-
export function evalSnippet(
|
|
6
|
-
compiled: string,
|
|
7
|
-
extraModules: Record<string, unknown /* imported module */> = {}
|
|
8
|
-
): {
|
|
9
|
-
default: Component;
|
|
10
|
-
services?: { [key: string]: unknown };
|
|
11
|
-
} {
|
|
12
|
-
const exports = {};
|
|
13
|
-
|
|
14
|
-
function require(moduleName: keyof typeof modules): unknown {
|
|
15
|
-
const preConfigured = modules[moduleName] || extraModules[moduleName];
|
|
16
|
-
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
return preConfigured || window.require(moduleName);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
eval(compiled);
|
|
23
|
-
|
|
24
|
-
return Object.assign(exports, { require }) as {
|
|
25
|
-
default: Component;
|
|
26
|
-
services?: { [key: string]: unknown };
|
|
27
|
-
require: unknown;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import * as compiler from 'ember-source/dist/ember-template-compiler.js';
|
|
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
|
-
const name = nameFor(code);
|
|
38
|
-
let component: undefined | ComponentLike;
|
|
39
|
-
let error: undefined | Error;
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
const 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
|
-
const preprocessed = await preprocess(input, name);
|
|
58
|
-
const result = await transform(preprocessed, name);
|
|
59
|
-
|
|
60
|
-
if (!result) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const { code } = result;
|
|
65
|
-
|
|
66
|
-
return code;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
import type { Babel } from './babel.ts';
|
|
70
|
-
|
|
71
|
-
let processor: any;
|
|
72
|
-
let fetchingPromise: Promise<any>;
|
|
73
|
-
|
|
74
|
-
async function preprocess(input: string, name: string): Promise<string> {
|
|
75
|
-
if (!fetchingPromise) {
|
|
76
|
-
fetchingPromise = import('content-tag');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (!processor) {
|
|
80
|
-
const { Preprocessor } = await fetchingPromise;
|
|
81
|
-
|
|
82
|
-
processor = new Preprocessor();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const { code /* map */ } = processor.process(input, {
|
|
86
|
-
filename: `${name}.js`,
|
|
87
|
-
inline_source_map: true,
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
return code;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async function transform(
|
|
94
|
-
intermediate: string,
|
|
95
|
-
name: string
|
|
96
|
-
): Promise<ReturnType<Babel['transform']>> {
|
|
97
|
-
const [
|
|
98
|
-
// _parser, _traverse, _generator,
|
|
99
|
-
_decoratorTransforms,
|
|
100
|
-
_emberTemplateCompilation,
|
|
101
|
-
] = await Promise.all([
|
|
102
|
-
// @babel/* doesn't have the greatest ESM compat yet
|
|
103
|
-
// https://github.com/babel/babel/issues/14314#issuecomment-1054505190
|
|
104
|
-
//
|
|
105
|
-
// babel-standalone is so easy...
|
|
106
|
-
// import('@babel/parser'),
|
|
107
|
-
// import('@babel/traverse'),
|
|
108
|
-
// import('@babel/generator'),
|
|
109
|
-
import('decorator-transforms'),
|
|
110
|
-
import('babel-plugin-ember-template-compilation'),
|
|
111
|
-
]);
|
|
112
|
-
|
|
113
|
-
// These libraries are compiled incorrectly for cjs<->ESM compat
|
|
114
|
-
const decoratorTransforms =
|
|
115
|
-
'default' in _decoratorTransforms ? _decoratorTransforms.default : _decoratorTransforms;
|
|
116
|
-
|
|
117
|
-
const emberTemplateCompilation =
|
|
118
|
-
'default' in _emberTemplateCompilation
|
|
119
|
-
? _emberTemplateCompilation.default
|
|
120
|
-
: _emberTemplateCompilation;
|
|
121
|
-
|
|
122
|
-
// so we have to use the default export (which is all the exports)
|
|
123
|
-
const maybeBabel = (await import('@babel/standalone')) as any;
|
|
124
|
-
// Handle difference between vite and webpack in consuming projects...
|
|
125
|
-
const babel: Babel = 'availablePlugins' in maybeBabel ? maybeBabel : maybeBabel.default;
|
|
126
|
-
|
|
127
|
-
return babel.transform(intermediate, {
|
|
128
|
-
filename: `${name}.js`,
|
|
129
|
-
plugins: [
|
|
130
|
-
[
|
|
131
|
-
emberTemplateCompilation,
|
|
132
|
-
{
|
|
133
|
-
compiler,
|
|
134
|
-
},
|
|
135
|
-
],
|
|
136
|
-
[
|
|
137
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
138
|
-
// @ts-ignore - we don't care about types here..
|
|
139
|
-
decoratorTransforms,
|
|
140
|
-
{
|
|
141
|
-
runtime: {
|
|
142
|
-
import: 'decorator-transforms/runtime',
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
],
|
|
146
|
-
// Womp.
|
|
147
|
-
// See this exploration into true ESM:
|
|
148
|
-
// https://github.com/NullVoxPopuli/limber/pull/1805
|
|
149
|
-
[babel.availablePlugins['transform-modules-commonjs']],
|
|
150
|
-
],
|
|
151
|
-
presets: [],
|
|
152
|
-
});
|
|
153
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* We need to import and hang on to these references so that they
|
|
3
|
-
* don't get optimized away during deploy
|
|
4
|
-
*/
|
|
5
|
-
import _GlimmerComponent from '@glimmer/component';
|
|
6
|
-
import * as _tracking from '@glimmer/tracking';
|
|
7
|
-
import * as _application from '@ember/application';
|
|
8
|
-
import * as _array from '@ember/array';
|
|
9
|
-
import * as _EmberComponent from '@ember/component';
|
|
10
|
-
import * as _EmberComponentHelper from '@ember/component/helper';
|
|
11
|
-
import _TO from '@ember/component/template-only';
|
|
12
|
-
import * as _debug from '@ember/debug';
|
|
13
|
-
import * as _destroyable from '@ember/destroyable';
|
|
14
|
-
import * as _helpers from '@ember/helper';
|
|
15
|
-
import * as _modifier from '@ember/modifier';
|
|
16
|
-
import * as _object from '@ember/object';
|
|
17
|
-
import * as _owner from '@ember/owner';
|
|
18
|
-
import * as _runloop from '@ember/runloop';
|
|
19
|
-
import * as _service from '@ember/service';
|
|
20
|
-
import * as _template from '@ember/template';
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
import { createTemplateFactory } from '@ember/template-factory';
|
|
24
|
-
import * as _utils from '@ember/utils';
|
|
25
|
-
|
|
26
|
-
import * as _decoratorsRuntime from 'decorator-transforms/runtime';
|
|
27
|
-
|
|
28
|
-
export const modules = {
|
|
29
|
-
'@ember/application': _application,
|
|
30
|
-
'@ember/array': _array,
|
|
31
|
-
'@ember/component': _EmberComponent,
|
|
32
|
-
'@ember/component/helper': _EmberComponentHelper,
|
|
33
|
-
'@ember/component/template-only': Object.assign(_TO, { default: _TO }),
|
|
34
|
-
'@ember/debug': _debug,
|
|
35
|
-
'@ember/destroyable': _destroyable,
|
|
36
|
-
'@ember/helper': _helpers,
|
|
37
|
-
'@ember/modifier': _modifier,
|
|
38
|
-
'@ember/object': _object,
|
|
39
|
-
'@ember/runloop': _runloop,
|
|
40
|
-
'@ember/service': _service,
|
|
41
|
-
'@ember/template-factory': { createTemplateFactory },
|
|
42
|
-
'@ember/utils': _utils,
|
|
43
|
-
'@ember/template': _template,
|
|
44
|
-
'@ember/owner': _owner,
|
|
45
|
-
|
|
46
|
-
'@glimmer/component': _GlimmerComponent,
|
|
47
|
-
'@glimmer/tracking': _tracking,
|
|
48
|
-
'decorator-transforms/runtime': _decoratorsRuntime,
|
|
49
|
-
};
|