ember-repl 2.0.63 → 3.0.0-beta.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.
Files changed (108) hide show
  1. package/README.md +200 -35
  2. package/addon-main.cjs +5 -0
  3. package/dist/browser/cjs/eval.d.ts +10 -0
  4. package/dist/browser/cjs/eval.d.ts.map +1 -0
  5. package/dist/browser/cjs/eval.js +22 -0
  6. package/dist/browser/cjs/eval.js.map +1 -0
  7. package/dist/browser/cjs/index.d.ts +7 -0
  8. package/dist/browser/cjs/index.js +43 -0
  9. package/dist/browser/cjs/index.js.map +1 -0
  10. package/dist/browser/compile/formats.d.ts +15 -0
  11. package/dist/browser/compile/formats.js +169 -0
  12. package/dist/browser/compile/formats.js.map +1 -0
  13. package/dist/browser/compile/index.d.ts +32 -0
  14. package/dist/browser/compile/index.js +90 -0
  15. package/dist/browser/compile/index.js.map +1 -0
  16. package/dist/browser/compile/markdown-to-ember.d.ts +18 -0
  17. package/dist/browser/compile/markdown-to-ember.js +237 -0
  18. package/dist/browser/compile/markdown-to-ember.js.map +1 -0
  19. package/dist/browser/compile/types.d.ts +7 -0
  20. package/dist/browser/compile/types.js +2 -0
  21. package/dist/browser/compile/types.js.map +1 -0
  22. package/dist/browser/esm/index.d.ts +8 -0
  23. package/dist/browser/esm/index.js +67 -0
  24. package/dist/browser/esm/index.js.map +1 -0
  25. package/dist/browser/eti/babel-plugin.d.ts +54 -0
  26. package/dist/browser/eti/babel-plugin.js +95 -0
  27. package/dist/browser/eti/babel-plugin.js.map +1 -0
  28. package/dist/browser/eti/debug.d.ts +2 -0
  29. package/dist/browser/eti/debug.js +9 -0
  30. package/dist/browser/eti/debug.js.map +1 -0
  31. package/dist/browser/eti/parse-templates.d.ts +56 -0
  32. package/dist/browser/eti/parse-templates.js +181 -0
  33. package/dist/browser/eti/parse-templates.js.map +1 -0
  34. package/dist/browser/eti/preprocess.d.ts +57 -0
  35. package/dist/browser/eti/preprocess.js +270 -0
  36. package/dist/browser/eti/preprocess.js.map +1 -0
  37. package/dist/browser/eti/template-tag-transform.d.ts +15 -0
  38. package/dist/browser/eti/template-tag-transform.js +46 -0
  39. package/dist/browser/eti/template-tag-transform.js.map +1 -0
  40. package/dist/browser/eti/util.d.ts +14 -0
  41. package/dist/browser/eti/util.js +39 -0
  42. package/dist/browser/eti/util.js.map +1 -0
  43. package/dist/browser/gjs.d.ts +4 -0
  44. package/dist/browser/gjs.js +40 -0
  45. package/dist/browser/gjs.js.map +1 -0
  46. package/{hbs.d.ts → dist/browser/hbs.d.ts} +7 -7
  47. package/dist/browser/hbs.js +91 -0
  48. package/dist/browser/hbs.js.map +1 -0
  49. package/dist/browser/index.d.ts +6 -0
  50. package/dist/browser/index.js +6 -0
  51. package/dist/browser/index.js.map +1 -0
  52. package/{js.d.ts → dist/browser/js.d.ts} +3 -6
  53. package/dist/browser/js.js +38 -0
  54. package/dist/browser/js.js.map +1 -0
  55. package/{known-modules.d.ts → dist/browser/known-modules.d.ts} +6 -5
  56. package/dist/browser/known-modules.js +46 -0
  57. package/dist/browser/known-modules.js.map +1 -0
  58. package/dist/browser/types.d.ts +21 -0
  59. package/dist/browser/types.js +2 -0
  60. package/dist/browser/types.js.map +1 -0
  61. package/{utils.d.ts → dist/browser/utils.d.ts} +8 -3
  62. package/dist/browser/utils.js +46 -0
  63. package/dist/browser/utils.js.map +1 -0
  64. package/dist/build/ember-cli.cjs +36 -0
  65. package/dist/test-support/index.d.ts +2 -0
  66. package/dist/test-support/index.js +8 -0
  67. package/dist/test-support/index.js.map +1 -0
  68. package/package.json +122 -125
  69. package/{addon → src/browser}/cjs/eval.ts +9 -5
  70. package/src/browser/cjs/index.ts +44 -0
  71. package/src/browser/compile/formats.ts +168 -0
  72. package/src/browser/compile/index.ts +131 -0
  73. package/src/browser/compile/markdown-to-ember.ts +318 -0
  74. package/src/browser/compile/types.ts +7 -0
  75. package/src/browser/esm/index.ts +80 -0
  76. package/src/browser/eti/babel-plugin.ts +105 -0
  77. package/src/browser/eti/debug.ts +7 -0
  78. package/src/browser/eti/parse-templates.ts +284 -0
  79. package/src/browser/eti/preprocess.ts +187 -0
  80. package/src/browser/eti/template-tag-transform.ts +100 -0
  81. package/src/browser/eti/util.ts +72 -0
  82. package/src/browser/gjs.ts +59 -0
  83. package/{addon → src/browser}/hbs.ts +24 -12
  84. package/{addon → src/browser}/index.ts +1 -0
  85. package/{addon → src/browser}/js.ts +6 -2
  86. package/{addon → src/browser}/known-modules.ts +4 -2
  87. package/{addon → src/browser}/types.ts +6 -1
  88. package/{addon → src/browser}/utils.ts +6 -2
  89. package/src/build/ember-cli.cjs +36 -0
  90. package/src/test-support/index.ts +5 -0
  91. package/.github/renovate.json5 +0 -93
  92. package/.github/workflows/ci.yml +0 -120
  93. package/.github/workflows/lint.yml +0 -88
  94. package/.github/workflows/types.yml +0 -30
  95. package/CHANGELOG.md +0 -745
  96. package/addon/cjs/index.ts +0 -100
  97. package/addon/esm/index.ts +0 -131
  98. package/cjs/eval.d.ts +0 -8
  99. package/cjs/index.d.ts +0 -10
  100. package/config/environment.js +0 -5
  101. package/esm/index.d.ts +0 -11
  102. package/index.d.ts +0 -5
  103. package/index.js +0 -105
  104. package/tsconfig.json +0 -56
  105. package/types/dummy/index.d.ts +0 -1
  106. package/types/global.d.ts +0 -43
  107. package/types/overrides.d.ts +0 -18
  108. package/types.d.ts +0 -15
@@ -0,0 +1,46 @@
1
+ import { assert } from '@ember/debug';
2
+ import { pascalCase } from 'change-case';
3
+ import { v5 } from 'uuid';
4
+
5
+ /**
6
+ * a namespace is required for uuid v5
7
+ *
8
+ * it helps generate stable outputs for for any given input.
9
+ */
10
+ const NAMESPACE = '926f034a-f480-4112-a363-321244f4e5de';
11
+ const DEFAULT_PREFIX = 'ember-repl';
12
+
13
+ /**
14
+ * For any given code block, a reasonably stable name can be
15
+ * generated.
16
+ * This can help with cacheing previously compiled components,
17
+ * and generally allowing a consumer to derive "known references" to user-input
18
+ */
19
+ function nameFor(code, prefix = DEFAULT_PREFIX) {
20
+ let id = v5(code, NAMESPACE);
21
+ return `${prefix ? `${prefix}-` : ''}${id}`;
22
+ }
23
+
24
+ /**
25
+ * Returns the text for invoking a component with a given name.
26
+ * It is assumed the component takes no arguments, as would be the
27
+ * case in REPLs / Playgrounds for the "root" component.
28
+ */
29
+ function invocationOf(name) {
30
+ assert(`You must pass a name to invocationOf. Received: \`${name}\``, typeof name === 'string' && name.length > 0);
31
+ if (name.length === 0) {
32
+ throw new Error(`name passed to invocationOf must have non-0 length`);
33
+ }
34
+ return `<${invocationName(name)} />`;
35
+ }
36
+
37
+ /**
38
+ * Core team does not want to support changes to '@ember/string' (v2 addonification, specifically)
39
+ * inflection does not support hyphens
40
+ */
41
+ function invocationName(name) {
42
+ return pascalCase(name).replaceAll('_', '');
43
+ }
44
+
45
+ export { invocationName, invocationOf, nameFor };
46
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../../src/browser/utils.ts"],"sourcesContent":["import { assert } from '@ember/debug';\n\nimport { pascalCase } from 'change-case';\nimport { v5 as uuidv5 } from 'uuid';\n\n/**\n * a namespace is required for uuid v5\n *\n * it helps generate stable outputs for for any given input.\n */\nconst NAMESPACE = '926f034a-f480-4112-a363-321244f4e5de';\nconst DEFAULT_PREFIX = 'ember-repl';\n\n/**\n * For any given code block, a reasonably stable name can be\n * generated.\n * This can help with cacheing previously compiled components,\n * and generally allowing a consumer to derive \"known references\" to user-input\n */\nexport function nameFor(code: string, prefix = DEFAULT_PREFIX) {\n let id = uuidv5(code, NAMESPACE);\n\n return `${prefix ? `${prefix}-` : ''}${id}`;\n}\n\n/**\n * Returns the text for invoking a component with a given name.\n * It is assumed the component takes no arguments, as would be the\n * case in REPLs / Playgrounds for the \"root\" component.\n */\nexport function invocationOf(name: string) {\n assert(\n `You must pass a name to invocationOf. Received: \\`${name}\\``,\n typeof name === 'string' && name.length > 0\n );\n\n if (name.length === 0) {\n throw new Error(`name passed to invocationOf must have non-0 length`);\n }\n\n return `<${invocationName(name)} />`;\n}\n\n/**\n * Core team does not want to support changes to '@ember/string' (v2 addonification, specifically)\n * inflection does not support hyphens\n */\nexport function invocationName(name: string) {\n return pascalCase(name).replaceAll('_', '');\n}\n"],"names":["NAMESPACE","DEFAULT_PREFIX","nameFor","code","prefix","id","uuidv5","invocationOf","name","assert","length","Error","invocationName","pascalCase","replaceAll"],"mappings":";;;;AAKA;AACA;AACA;AACA;AACA;AACA,MAAMA,SAAS,GAAG,sCAAsC,CAAA;AACxD,MAAMC,cAAc,GAAG,YAAY,CAAA;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,OAAOA,CAACC,IAAY,EAAEC,MAAM,GAAGH,cAAc,EAAE;AAC7D,EAAA,IAAII,EAAE,GAAGC,EAAM,CAACH,IAAI,EAAEH,SAAS,CAAC,CAAA;EAEhC,OAAQ,CAAA,EAAEI,MAAM,GAAI,CAAEA,EAAAA,MAAO,GAAE,GAAG,EAAG,CAAEC,EAAAA,EAAG,CAAC,CAAA,CAAA;AAC7C,CAAA;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASE,YAAYA,CAACC,IAAY,EAAE;AACzCC,EAAAA,MAAM,CACH,CAAA,kDAAA,EAAoDD,IAAK,CAAA,EAAA,CAAG,EAC7D,OAAOA,IAAI,KAAK,QAAQ,IAAIA,IAAI,CAACE,MAAM,GAAG,CAC5C,CAAC,CAAA;AAED,EAAA,IAAIF,IAAI,CAACE,MAAM,KAAK,CAAC,EAAE;AACrB,IAAA,MAAM,IAAIC,KAAK,CAAE,CAAA,kDAAA,CAAmD,CAAC,CAAA;AACvE,GAAA;AAEA,EAAA,OAAQ,CAAGC,CAAAA,EAAAA,cAAc,CAACJ,IAAI,CAAE,CAAI,GAAA,CAAA,CAAA;AACtC,CAAA;;AAEA;AACA;AACA;AACA;AACO,SAASI,cAAcA,CAACJ,IAAY,EAAE;EAC3C,OAAOK,UAAU,CAACL,IAAI,CAAC,CAACM,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;AAC7C;;;;"}
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ const { stripIndents } = require('common-tags');
4
+
5
+ /**
6
+ * Builds a file with a single export, COMPONENT_MAP, that
7
+ * is a map of the provided paths *to* all exported identifiers
8
+ * from each of the provided paths.
9
+ *
10
+ * This is helpful for building a map of imports to force to be included
11
+ * in the build - a requirement for builds that tend to tree shake.
12
+ *
13
+ * @param {string[]} paths - list of import paths for each module that you want availableb to the REPL
14
+ */
15
+ module.exports.buildComponentMap = function buildComponentMap(paths) {
16
+ const writeFile = require('broccoli-file-creator');
17
+ const fileContent = stripIndents`
18
+ ${paths
19
+ .map((path, i) => {
20
+ return `import * as ComponentMapPart${i} from '${path}';`;
21
+ })
22
+ .join('\n')}
23
+
24
+ export const COMPONENT_MAP = {
25
+ ${paths
26
+ .map((path, i) => {
27
+ return `'${path}': ComponentMapPart${i},`;
28
+ })
29
+ .join('\n')}
30
+ };
31
+ `;
32
+
33
+ const tree = writeFile('/ember-repl/component-map.js', fileContent);
34
+
35
+ return tree;
36
+ };
@@ -0,0 +1,2 @@
1
+ declare function clearCompileCache(): void;
2
+ export { clearCompileCache };
@@ -0,0 +1,8 @@
1
+ import { CACHE } from '../browser/compile/index.js';
2
+
3
+ function clearCompileCache() {
4
+ CACHE.clear();
5
+ }
6
+
7
+ export { clearCompileCache };
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/test-support/index.ts"],"sourcesContent":["import { CACHE } from '../browser/compile/index';\n\nexport function clearCompileCache() {\n CACHE.clear();\n}\n"],"names":["clearCompileCache","CACHE","clear"],"mappings":";;AAEO,SAASA,iBAAiBA,GAAG;EAClCC,KAAK,CAACC,KAAK,EAAE,CAAA;AACf;;;;"}
package/package.json CHANGED
@@ -1,152 +1,149 @@
1
1
  {
2
2
  "name": "ember-repl",
3
- "version": "2.0.63",
3
+ "version": "3.0.0-beta.1",
4
4
  "description": "Addon for enabling REPL and Playground creation with Ember/Glimmer",
5
5
  "keywords": [
6
6
  "ember-addon"
7
7
  ],
8
- "repository": "https://github.com/NullVoxPopuli/ember-repl",
8
+ "repository": {
9
+ "type": "https",
10
+ "url": "https://github.com/NullVoxPopuli/limber",
11
+ "directory": "packages/ember-repl/addon"
12
+ },
9
13
  "license": "MIT",
10
14
  "author": "NullVoxPopuli",
11
- "directories": {
12
- "doc": "doc",
13
- "test": "tests"
15
+ "typesVersions": {
16
+ "*": {
17
+ "test-support": [
18
+ "dist/test-support/index.d.ts"
19
+ ],
20
+ "markdown/parse": [
21
+ "./dist/browser/compile/markdown-to-ember.d.ts"
22
+ ],
23
+ "*": [
24
+ "dist/browser/*",
25
+ "dist/browser/*/index.d.ts"
26
+ ]
27
+ }
14
28
  },
15
- "scripts": {
16
- "build": "ember build --environment=production",
17
- "lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"",
18
- "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
19
- "lint:hbs": "ember-template-lint .",
20
- "lint:hbs:fix": "ember-template-lint . --fix",
21
- "lint:js": "eslint . --cache",
22
- "lint:js:fix": "eslint . --fix",
23
- "start": "ember serve",
24
- "test": "npm-run-all lint test:*",
25
- "test:ember": "ember test",
26
- "test:ember-compatibility": "ember try:each",
27
- "prepack": "ember ts:precompile",
28
- "postpack": "ember ts:clean"
29
+ "exports": {
30
+ ".": "./dist/browser/index.js",
31
+ "./esm": "./dist/browser/esm/index.js",
32
+ "./markdown/parse": "./dist/browser/compile/markdown-to-ember.js",
33
+ "./ember-cli": {
34
+ "require": "./src/build/ember-cli.cjs"
35
+ },
36
+ "./test-support": "./dist/test-support/index.js",
37
+ "./addon-main.js": "./addon-main.cjs"
29
38
  },
39
+ "files": [
40
+ "src",
41
+ "dist",
42
+ "addon-main.cjs"
43
+ ],
30
44
  "dependencies": {
31
- "@babel/standalone": "^7.18.13",
32
- "@embroider/macros": "^1.8.3",
33
- "@glimmer/component": "^1.1.2",
34
- "@glimmer/tracking": "^1.1.2",
35
- "babel-plugin-htmlbars-inline-precompile": "^5.3.1",
45
+ "@babel/helper-plugin-utils": "^7.21.5",
46
+ "@babel/standalone": "^7.21.8",
47
+ "@embroider/addon-shim": "1.8.5",
48
+ "@embroider/macros": "1.11.0",
49
+ "babel-import-util": "^1.3.0",
50
+ "babel-plugin-ember-template-compilation": "^2.0.3",
36
51
  "broccoli-file-creator": "^2.1.1",
37
- "broccoli-funnel": "^3.0.8",
38
- "broccoli-merge-trees": "^4.2.0",
52
+ "change-case": "^4.1.2",
39
53
  "common-tags": "^1.8.2",
40
- "ember-auto-import": "2.4.2",
41
- "ember-cli-babel": "^7.26.11",
42
- "ember-cli-htmlbars": "^6.1.0",
43
- "ember-cli-typescript": "^5.1.0",
44
- "ember-compatibility-helpers": "^1.2.6",
45
- "path-browserify": "^1.0.1",
46
- "uuid": "8.3.2"
54
+ "line-column": "^1.0.2",
55
+ "magic-string": "^0.30.0",
56
+ "mdast": "^3.0.0",
57
+ "parse-static-imports": "^1.1.0",
58
+ "rehype-raw": "^6.1.1",
59
+ "rehype-stringify": "^9.0.3",
60
+ "remark-parse": "^10.0.2",
61
+ "remark-rehype": "^10.1.0",
62
+ "unified": "^10.1.2",
63
+ "unist-util-visit": "^4.1.2",
64
+ "uuid": "^9.0.0",
65
+ "vfile": "^5.3.7"
47
66
  },
48
67
  "devDependencies": {
49
- "@commitlint/cli": "^15.0.0",
50
- "@commitlint/config-conventional": "^15.0.0",
51
- "@ember/optional-features": "^2.0.0",
52
- "@ember/test-helpers": "^2.8.1",
68
+ "@babel/core": "^7.21.8",
69
+ "@babel/types": "^7.21.5",
70
+ "@ember/test-helpers": "^2.9.3",
53
71
  "@ember/test-waiters": "^3.0.2",
54
- "@embroider/test-setup": "^1.8.3",
55
- "@glimmer/interfaces": "^0.84.2",
56
- "@glimmer/reference": "^0.84.2",
57
- "@glimmer/util": "^0.84.2",
58
- "@nullvoxpopuli/eslint-configs": "^2.2.49",
59
- "@semantic-release/changelog": "^6.0.1",
60
- "@semantic-release/git": "^10.0.1",
61
- "@types/babel__core": "^7.1.19",
72
+ "@embroider/addon-dev": "3.1.0",
73
+ "@glimmer/compiler": "^0.84.3",
74
+ "@glimmer/component": "^1.1.2",
75
+ "@glimmer/interfaces": "^0.84.3",
76
+ "@glimmer/reference": "^0.84.3",
77
+ "@glimmer/syntax": "^0.84.3",
78
+ "@glimmer/tracking": "^1.1.2",
79
+ "@glimmer/util": "^0.84.3",
80
+ "@glint/core": "^1.0.2",
81
+ "@glint/environment-ember-loose": "^1.0.2",
82
+ "@glint/environment-ember-template-imports": "^1.0.2",
83
+ "@glint/template": "^1.0.2",
84
+ "@nullvoxpopuli/eslint-configs": "^3.1.3",
85
+ "@rollup/plugin-commonjs": "^25.0.0",
86
+ "@tsconfig/ember": "^2.0.0",
87
+ "@types/babel__core": "^7.20.0",
62
88
  "@types/babel__standalone": "^7.1.4",
63
- "@types/ember-qunit": "^5.0.0",
64
- "@types/ember-resolver": "^5.0.11",
65
- "@types/ember__application": "^4.0.0",
66
- "@types/ember__array": "^4.0.1",
67
- "@types/ember__component": "^4.0.8",
68
- "@types/ember__controller": "^4.0.0",
69
- "@types/ember__debug": "^4.0.1",
70
- "@types/ember__destroyable": "^4.0.0",
71
- "@types/ember__engine": "^4.0.0",
72
- "@types/ember__error": "^4.0.0",
73
- "@types/ember__object": "^4.0.2",
74
- "@types/ember__polyfills": "^4.0.0",
75
- "@types/ember__routing": "^4.0.7",
76
- "@types/ember__runloop": "^4.0.1",
77
- "@types/ember__service": "^4.0.0",
78
- "@types/ember__string": "^3.16.3",
79
- "@types/ember__template": "^4.0.0",
80
- "@types/ember__test": "^4.0.0",
81
- "@types/ember__test-helpers": "^2.6.1",
82
- "@types/ember__utils": "^4.0.0",
83
- "@types/htmlbars-inline-precompile": "^3.0.0",
84
- "@types/qunit": "^2.11.3",
85
- "@types/rsvp": "^4.0.4",
86
- "@types/uuid": "^8.3.4",
87
- "@typescript-eslint/eslint-plugin": "^5.33.1",
88
- "@typescript-eslint/parser": "^5.33.1",
89
- "babel-eslint": "^10.1.0",
90
- "broccoli-asset-rev": "^3.0.0",
91
- "ember-cli": "~4.6.0",
92
- "ember-cli-dependency-checker": "^3.3.1",
93
- "ember-cli-inject-live-reload": "^2.1.0",
94
- "ember-cli-sri": "^2.1.1",
95
- "ember-cli-terser": "^4.0.2",
96
- "ember-could-get-used-to-this": "^1.0.1",
97
- "ember-disable-prototype-extensions": "^1.1.3",
98
- "ember-export-application-global": "^2.0.1",
99
- "ember-load-initializers": "^2.1.2",
100
- "ember-page-title": "^7.0.0",
101
- "ember-qunit": "^5.1.5",
102
- "ember-resolver": "^8.0.3",
103
- "ember-source": "~4.6.0",
104
- "ember-source-channel-url": "^3.0.0",
105
- "ember-template-lint": "^4.12.0",
106
- "ember-try": "^2.0.0",
107
- "eslint": "^7.32.0",
108
- "eslint-config-prettier": "^8.5.0",
109
- "eslint-plugin-decorator-position": "^4.0.1",
110
- "eslint-plugin-ember": "^10.6.1",
111
- "eslint-plugin-import": "^2.26.0",
89
+ "@types/babel__traverse": "^7.18.5",
90
+ "@types/hast": "^2.3.4",
91
+ "@types/mdast": "^3.0.11",
92
+ "@types/unist": "^2.0.6",
93
+ "@types/uuid": "^9.0.1",
94
+ "@typescript-eslint/eslint-plugin": "^5.59.6",
95
+ "@typescript-eslint/parser": "^5.59.6",
96
+ "concurrently": "^8.0.1",
97
+ "ember-resources": "^6.1.0",
98
+ "ember-source": "^5.0.0",
99
+ "ember-template-imports": "^3.4.2",
100
+ "ember-template-lint": "^5.7.3",
101
+ "eslint": "^8.41.0",
102
+ "eslint-plugin-ember": "^11.7.1",
112
103
  "eslint-plugin-node": "^11.1.0",
113
104
  "eslint-plugin-prettier": "^4.2.1",
114
- "eslint-plugin-qunit": "^7.3.1",
115
- "eslint-plugin-simple-import-sort": "^7.0.0",
116
- "loader.js": "^4.7.0",
117
- "npm-run-all": "^4.1.5",
118
- "prettier": "^2.7.1",
119
- "qunit": "^2.19.1",
120
- "qunit-dom": "^2.0.0",
121
- "semantic-release": "^19.0.3",
122
- "typescript": "^4.7.4",
123
- "webpack": "^5.74.0"
124
- },
125
- "release": {
126
- "branches": [
127
- "main",
128
- "master"
129
- ],
130
- "plugins": [
131
- "@semantic-release/commit-analyzer",
132
- "@semantic-release/release-notes-generator",
133
- "@semantic-release/changelog",
134
- "@semantic-release/npm",
135
- "@semantic-release/github",
136
- "@semantic-release/git"
137
- ]
105
+ "prettier": "^2.8.8",
106
+ "prettier-plugin-ember-template-tag": "^0.3.2",
107
+ "publint": "^0.1.12",
108
+ "rollup": "~3.21.0",
109
+ "rollup-plugin-copy": "^3.4.0",
110
+ "rollup-plugin-glimmer-template-tag": "^0.4.1",
111
+ "rollup-plugin-ts": "^3.2.0",
112
+ "typescript": "^5.0.4",
113
+ "@nullvoxpopuli/limber-untyped": "0.0.0"
138
114
  },
139
115
  "volta": {
140
- "node": "16.17.0",
141
- "yarn": "1.22.19"
142
- },
143
- "engines": {
144
- "node": "12.* || >= 14.*"
116
+ "extends": "../../../package.json"
145
117
  },
146
118
  "ember": {
147
119
  "edition": "octane"
148
120
  },
149
121
  "ember-addon": {
150
- "configPath": "tests/dummy/config"
122
+ "version": 2,
123
+ "type": "addon",
124
+ "main": "addon-main.cjs",
125
+ "app-js": {}
126
+ },
127
+ "peerDependencies": {
128
+ "@glimmer/compiler": "^0.84.3",
129
+ "@glimmer/component": "^1.1.2",
130
+ "@glimmer/syntax": "^0.84.3",
131
+ "@glint/template": "^1.0.2",
132
+ "ember-resources": "^6.1.0",
133
+ "ember-source": "^5.0.0"
134
+ },
135
+ "scripts": {
136
+ "build": "rollup --config",
137
+ "lint:types": "glint",
138
+ "lint:fix": "pnpm -w exec lint fix",
139
+ "start": "rollup --config --watch",
140
+ "lint": "pnpm -w exec lint",
141
+ "lint:package": "pnpm publint",
142
+ "lint:js": "pnpm -w exec lint js",
143
+ "lint:js:fix": "pnpm -w exec lint js:fix",
144
+ "lint:hbs": "pnpm -w exec lint hbs",
145
+ "lint:hbs:fix": "pnpm -w exec lint hbs:fix",
146
+ "lint:prettier:fix": "pnpm -w exec lint prettier:fix",
147
+ "lint:prettier": "pnpm -w exec lint prettier"
151
148
  }
152
- }
149
+ }
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
2
2
  import { modules } from '../known-modules';
3
3
 
4
+ import type { ExtraModules } from '../types';
4
5
  import type Component from '@glimmer/component';
5
- import type { ExtraModules } from 'ember-repl/types';
6
6
 
7
7
  export function evalSnippet(
8
8
  compiled: string,
@@ -13,16 +13,20 @@ export function evalSnippet(
13
13
  } {
14
14
  const exports = {};
15
15
 
16
- // https://github.com/glimmerjs/glimmer-experimental/blob/master/packages/examples/playground/src/utils/eval-snippet.ts
17
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
18
- // @ts-ignore
19
16
  function require(moduleName: keyof typeof modules): unknown {
20
17
  let preConfigured = modules[moduleName] || extraModules[moduleName];
21
18
 
19
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
20
+ // @ts-ignore
22
21
  return preConfigured || window.require(moduleName);
23
22
  }
24
23
 
24
+ // https://github.com/glimmerjs/glimmer-experimental/blob/master/packages/examples/playground/src/utils/eval-snippet.ts
25
25
  eval(compiled);
26
26
 
27
- return exports as { default: Component; services?: { [key: string]: unknown } };
27
+ return Object.assign(exports, { require }) as {
28
+ default: Component;
29
+ services?: { [key: string]: unknown };
30
+ require: unknown;
31
+ };
28
32
  }
@@ -0,0 +1,44 @@
1
+ import { preprocess, transform } from '../gjs';
2
+ import { nameFor } from '../utils';
3
+ import { evalSnippet } from './eval';
4
+
5
+ import type { CompileResult, ExtraModules } from '../types';
6
+ import type { ComponentLike } from '@glint/template';
7
+
8
+ export interface Info {
9
+ code: string;
10
+ name: string;
11
+ }
12
+
13
+ export async function compileJS(code: string, extraModules?: ExtraModules): Promise<CompileResult> {
14
+ let name = nameFor(code);
15
+ let component: undefined | ComponentLike;
16
+ let error: undefined | Error;
17
+
18
+ try {
19
+ let compiled = await compileGJS({ code: code, name });
20
+
21
+ if (!compiled) {
22
+ throw new Error(`Compiled output is missing`);
23
+ }
24
+
25
+ component = evalSnippet(compiled, extraModules).default as unknown as ComponentLike;
26
+ } catch (e) {
27
+ error = e as Error | undefined;
28
+ }
29
+
30
+ return { name, component, error };
31
+ }
32
+
33
+ async function compileGJS({ code: input, name }: Info) {
34
+ let preprocessed = preprocess(input, name);
35
+ let result = await transform(preprocessed, name);
36
+
37
+ if (!result) {
38
+ return;
39
+ }
40
+
41
+ let { code } = result;
42
+
43
+ return code;
44
+ }
@@ -0,0 +1,168 @@
1
+ import { invocationName } from '../utils';
2
+
3
+ import type { CompileResult } from '../types';
4
+ import type { ExtractedCode } from './markdown-to-ember';
5
+ import type { EvalImportMap, ScopeMap } from './types';
6
+
7
+ async function compileAll(js: { code: string }[], importMap?: EvalImportMap) {
8
+ let modules = await Promise.all(
9
+ js.map(async ({ code }) => {
10
+ return await compileGJS(code, importMap);
11
+ })
12
+ );
13
+
14
+ return modules;
15
+ }
16
+
17
+ export async function compileGJS(
18
+ gjsInput: string,
19
+ importMap?: EvalImportMap
20
+ ): Promise<CompileResult> {
21
+ try {
22
+ let { compileJS } = await import('../js');
23
+
24
+ return await compileJS(gjsInput, importMap);
25
+ } catch (error) {
26
+ return { error: error as Error, name: 'unknown' };
27
+ }
28
+ }
29
+
30
+ export async function compileHBS(
31
+ hbsInput: string,
32
+ options?: {
33
+ moduleName?: string;
34
+ scope?: Record<string, unknown>;
35
+ }
36
+ ): Promise<CompileResult> {
37
+ try {
38
+ let { compileHBS } = await import('../hbs');
39
+
40
+ return compileHBS(hbsInput, options);
41
+ } catch (error) {
42
+ return { error: error as Error, name: 'unknown' };
43
+ }
44
+ }
45
+
46
+ async function extractScope(
47
+ liveCode: ExtractedCode[],
48
+ importMap?: EvalImportMap
49
+ ): Promise<CompileResult[]> {
50
+ let scope: CompileResult[] = [];
51
+
52
+ let hbs = liveCode.filter((code) => code.lang === 'hbs');
53
+ let js = liveCode.filter((code) => ['js', 'gjs'].includes(code.lang));
54
+
55
+ if (js.length > 0) {
56
+ let compiled = await compileAll(js, importMap);
57
+
58
+ await Promise.all(
59
+ compiled.map(async (info) => {
60
+ // using web worker + import maps is not available yet (need firefox support)
61
+ // (and to somehow be able to point at npm)
62
+ //
63
+ // if ('importPath' in info) {
64
+ // return scope.push({
65
+ // moduleName: name,
66
+ // component: await import(/* webpackIgnore: true */ info.importPath),
67
+ // });
68
+ // }
69
+
70
+ return scope.push(info);
71
+ })
72
+ );
73
+ }
74
+
75
+ for (let { code } of hbs) {
76
+ let compiled = await compileHBS(code);
77
+
78
+ scope.push(compiled);
79
+ }
80
+
81
+ return scope;
82
+ }
83
+
84
+ export async function compileMD(
85
+ glimdownInput: string,
86
+ options?: {
87
+ importMap?: EvalImportMap;
88
+ topLevelScope?: ScopeMap;
89
+ CopyComponent?: string;
90
+ }
91
+ ): Promise<CompileResult & { rootTemplate?: string }> {
92
+ let importMap = options?.importMap;
93
+ let topLevelScope = options?.topLevelScope ?? {};
94
+ let rootTemplate: string;
95
+ let liveCode: ExtractedCode[];
96
+ let scope: CompileResult[] = [];
97
+
98
+ /**
99
+ * Step 1: Convert Markdown To HTML (Ember).
100
+ *
101
+ * The remark plugin, remark-code-extra also extracts
102
+ * and transforms the code blocks we care about.
103
+ *
104
+ * These blocks will be compiled through babel and eval'd so the
105
+ * compiled rootTemplate can invoke them
106
+ */
107
+ try {
108
+ let { parseMarkdown } = await import('./markdown-to-ember');
109
+ let { templateOnlyGlimdown, blocks } = await parseMarkdown(glimdownInput, {
110
+ CopyComponent: options?.CopyComponent,
111
+ });
112
+
113
+ rootTemplate = templateOnlyGlimdown;
114
+ liveCode = blocks;
115
+ } catch (error) {
116
+ return { error: error as Error, name: 'unknown' };
117
+ }
118
+
119
+ /**
120
+ * Step 2: Compile the live code samples
121
+ */
122
+ if (liveCode.length > 0) {
123
+ try {
124
+ scope = await extractScope(liveCode, importMap);
125
+ } catch (error) {
126
+ console.info({ scope });
127
+ console.error(error);
128
+
129
+ return { error: error as Error, rootTemplate, name: 'unknown' };
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Make sure non of our snippets errored
135
+ *
136
+ * TODO: for these errors, report them differently so that we
137
+ * can render the 'Ember' and still highlight the correct line?
138
+ * or maybe there is a way to highlight in the editor instead?
139
+ */
140
+ for (let { error, component } of scope) {
141
+ if (!component) {
142
+ if (error) {
143
+ return { error, rootTemplate, name: 'unknown' };
144
+ }
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Step 4: Compile the Ember Template
150
+ */
151
+ try {
152
+ let localScope = scope.reduce((accum, { component, name }) => {
153
+ accum[invocationName(name)] = component;
154
+
155
+ return accum;
156
+ }, {} as Record<string, unknown>);
157
+
158
+ return await compileHBS(rootTemplate, {
159
+ moduleName: 'DynamicRootTemplate',
160
+ scope: {
161
+ ...topLevelScope,
162
+ ...localScope,
163
+ },
164
+ });
165
+ } catch (error) {
166
+ return { error: error as Error, rootTemplate, name: 'unknown' };
167
+ }
168
+ }