ember-repl 2.0.63 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/addon-main.cjs +5 -0
- package/dist/browser/cjs/eval.d.ts +10 -0
- package/dist/browser/cjs/eval.d.ts.map +1 -0
- package/dist/browser/cjs/eval.js +22 -0
- package/dist/browser/cjs/eval.js.map +1 -0
- package/dist/browser/cjs/index.d.ts +7 -0
- package/dist/browser/cjs/index.js +43 -0
- package/dist/browser/cjs/index.js.map +1 -0
- package/dist/browser/esm/index.d.ts +8 -0
- package/dist/browser/esm/index.js +67 -0
- package/dist/browser/esm/index.js.map +1 -0
- package/dist/browser/eti/babel-plugin.d.ts +54 -0
- package/dist/browser/eti/babel-plugin.js +95 -0
- package/dist/browser/eti/babel-plugin.js.map +1 -0
- package/dist/browser/eti/debug.d.ts +2 -0
- package/dist/browser/eti/debug.js +9 -0
- package/dist/browser/eti/debug.js.map +1 -0
- package/dist/browser/eti/parse-templates.d.ts +56 -0
- package/dist/browser/eti/parse-templates.js +181 -0
- package/dist/browser/eti/parse-templates.js.map +1 -0
- package/dist/browser/eti/preprocess.d.ts +57 -0
- package/dist/browser/eti/preprocess.js +271 -0
- package/dist/browser/eti/preprocess.js.map +1 -0
- package/dist/browser/eti/template-tag-transform.d.ts +15 -0
- package/dist/browser/eti/template-tag-transform.js +46 -0
- package/dist/browser/eti/template-tag-transform.js.map +1 -0
- package/dist/browser/eti/util.d.ts +14 -0
- package/dist/browser/eti/util.js +39 -0
- package/dist/browser/eti/util.js.map +1 -0
- package/dist/browser/gjs.d.ts +4 -0
- package/dist/browser/gjs.js +40 -0
- package/dist/browser/gjs.js.map +1 -0
- package/{hbs.d.ts → dist/browser/hbs.d.ts} +3 -6
- package/dist/browser/hbs.js +94 -0
- package/dist/browser/hbs.js.map +1 -0
- package/dist/browser/index.d.ts +5 -0
- package/dist/browser/index.js +5 -0
- package/dist/browser/index.js.map +1 -0
- package/{js.d.ts → dist/browser/js.d.ts} +3 -6
- package/dist/browser/js.js +38 -0
- package/dist/browser/js.js.map +1 -0
- package/{known-modules.d.ts → dist/browser/known-modules.d.ts} +6 -3
- package/dist/browser/known-modules.js +48 -0
- package/dist/browser/known-modules.js.map +1 -0
- package/dist/browser/types.d.ts +17 -0
- package/dist/browser/types.js +2 -0
- package/dist/browser/types.js.map +1 -0
- package/{utils.d.ts → dist/browser/utils.d.ts} +8 -3
- package/dist/browser/utils.js +46 -0
- package/dist/browser/utils.js.map +1 -0
- package/dist/build/ember-cli.cjs +36 -0
- package/package.json +98 -125
- package/{addon → src/browser}/cjs/eval.ts +9 -5
- package/src/browser/cjs/index.ts +44 -0
- package/src/browser/esm/index.ts +80 -0
- package/src/browser/eti/babel-plugin.ts +105 -0
- package/src/browser/eti/debug.ts +7 -0
- package/src/browser/eti/parse-templates.ts +284 -0
- package/src/browser/eti/preprocess.ts +187 -0
- package/src/browser/eti/template-tag-transform.ts +100 -0
- package/src/browser/eti/util.ts +72 -0
- package/src/browser/gjs.ts +59 -0
- package/{addon → src/browser}/hbs.ts +18 -6
- package/{addon → src/browser}/js.ts +6 -2
- package/{addon → src/browser}/known-modules.ts +4 -0
- package/{addon → src/browser}/types.ts +2 -1
- package/{addon → src/browser}/utils.ts +6 -2
- package/src/build/ember-cli.cjs +36 -0
- package/.github/renovate.json5 +0 -93
- package/.github/workflows/ci.yml +0 -120
- package/.github/workflows/lint.yml +0 -88
- package/.github/workflows/types.yml +0 -30
- package/CHANGELOG.md +0 -745
- package/addon/cjs/index.ts +0 -100
- package/addon/esm/index.ts +0 -131
- package/cjs/eval.d.ts +0 -8
- package/cjs/index.d.ts +0 -10
- package/config/environment.js +0 -5
- package/esm/index.d.ts +0 -11
- package/index.d.ts +0 -5
- package/index.js +0 -105
- package/tsconfig.json +0 -56
- package/types/dummy/index.d.ts +0 -1
- package/types/global.d.ts +0 -43
- package/types/overrides.d.ts +0 -18
- package/types.d.ts +0 -15
- /package/{addon → src/browser}/index.ts +0 -0
package/package.json
CHANGED
|
@@ -1,152 +1,125 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-repl",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-beta.0",
|
|
4
4
|
"description": "Addon for enabling REPL and Playground creation with Ember/Glimmer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
7
7
|
],
|
|
8
|
-
"repository":
|
|
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
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
15
|
+
"typesVersions": {
|
|
16
|
+
"*": {
|
|
17
|
+
"*": [
|
|
18
|
+
"dist/browser/*",
|
|
19
|
+
"dist/browser/*/index.d.ts"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
14
22
|
},
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
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"
|
|
23
|
+
"exports": {
|
|
24
|
+
".": "./dist/browser/index.js",
|
|
25
|
+
"./esm": "./dist/browser/esm/index.js",
|
|
26
|
+
"./ember-cli": {
|
|
27
|
+
"require": "./src/build/ember-cli.cjs"
|
|
28
|
+
},
|
|
29
|
+
"./addon-main.js": "./addon-main.cjs"
|
|
29
30
|
},
|
|
31
|
+
"files": [
|
|
32
|
+
"src",
|
|
33
|
+
"dist",
|
|
34
|
+
"addon-main.cjs"
|
|
35
|
+
],
|
|
30
36
|
"dependencies": {
|
|
31
|
-
"@babel/
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"babel-
|
|
37
|
+
"@babel/helper-plugin-utils": "^7.21.5",
|
|
38
|
+
"@babel/standalone": "^7.21.8",
|
|
39
|
+
"@embroider/addon-shim": "^1.8.4",
|
|
40
|
+
"@embroider/macros": "^1.10.0",
|
|
41
|
+
"babel-import-util": "^1.3.0",
|
|
42
|
+
"babel-plugin-ember-template-compilation": "^2.0.2",
|
|
36
43
|
"broccoli-file-creator": "^2.1.1",
|
|
37
|
-
"
|
|
38
|
-
"broccoli-merge-trees": "^4.2.0",
|
|
44
|
+
"change-case": "^4.1.2",
|
|
39
45
|
"common-tags": "^1.8.2",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"ember-compatibility-helpers": "^1.2.6",
|
|
45
|
-
"path-browserify": "^1.0.1",
|
|
46
|
-
"uuid": "8.3.2"
|
|
46
|
+
"line-column": "^1.0.2",
|
|
47
|
+
"magic-string": "^0.30.0",
|
|
48
|
+
"parse-static-imports": "^1.1.0",
|
|
49
|
+
"uuid": "^9.0.0"
|
|
47
50
|
},
|
|
48
51
|
"devDependencies": {
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
51
|
-
"@ember/
|
|
52
|
-
"@ember/test-helpers": "^2.8.1",
|
|
52
|
+
"@babel/core": "^7.21.8",
|
|
53
|
+
"@babel/types": "^7.21.5",
|
|
54
|
+
"@ember/test-helpers": "^2.9.3",
|
|
53
55
|
"@ember/test-waiters": "^3.0.2",
|
|
54
|
-
"@embroider/
|
|
55
|
-
"@glimmer/
|
|
56
|
-
"@glimmer/
|
|
57
|
-
"@glimmer/
|
|
58
|
-
"@
|
|
59
|
-
"@
|
|
60
|
-
"@
|
|
61
|
-
"@
|
|
56
|
+
"@embroider/addon-dev": "^3.0.0",
|
|
57
|
+
"@glimmer/compiler": "^0.84.3",
|
|
58
|
+
"@glimmer/component": "^1.1.2",
|
|
59
|
+
"@glimmer/interfaces": "^0.84.3",
|
|
60
|
+
"@glimmer/reference": "^0.84.3",
|
|
61
|
+
"@glimmer/syntax": "^0.84.3",
|
|
62
|
+
"@glimmer/tracking": "^1.1.2",
|
|
63
|
+
"@glimmer/util": "^0.84.3",
|
|
64
|
+
"@glint/core": "^1.0.2",
|
|
65
|
+
"@glint/environment-ember-loose": "^1.0.2",
|
|
66
|
+
"@glint/environment-ember-template-imports": "^1.0.2",
|
|
67
|
+
"@glint/template": "^1.0.2",
|
|
68
|
+
"@nullvoxpopuli/eslint-configs": "^3.1.3",
|
|
69
|
+
"@rollup/plugin-commonjs": "^25.0.0",
|
|
70
|
+
"@tsconfig/ember": "^2.0.0",
|
|
71
|
+
"@types/babel__core": "^7.20.0",
|
|
62
72
|
"@types/babel__standalone": "^7.1.4",
|
|
63
|
-
"@types/
|
|
64
|
-
"@types/
|
|
65
|
-
"@
|
|
66
|
-
"@
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
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",
|
|
73
|
+
"@types/babel__traverse": "^7.18.5",
|
|
74
|
+
"@types/uuid": "^9.0.1",
|
|
75
|
+
"@typescript-eslint/eslint-plugin": "^5.59.2",
|
|
76
|
+
"@typescript-eslint/parser": "^5.59.2",
|
|
77
|
+
"concurrently": "^8.0.1",
|
|
78
|
+
"ember-source": "^4.12.0",
|
|
79
|
+
"ember-template-imports": "^3.4.2",
|
|
80
|
+
"ember-template-lint": "^5.7.3",
|
|
81
|
+
"eslint": "^8.40.0",
|
|
82
|
+
"eslint-plugin-ember": "^11.5.2",
|
|
112
83
|
"eslint-plugin-node": "^11.1.0",
|
|
113
84
|
"eslint-plugin-prettier": "^4.2.1",
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
"
|
|
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
|
-
]
|
|
85
|
+
"prettier": "^2.8.8",
|
|
86
|
+
"prettier-plugin-ember-template-tag": "^0.3.2",
|
|
87
|
+
"rollup": "^3.21.6",
|
|
88
|
+
"rollup-plugin-copy": "^3.4.0",
|
|
89
|
+
"rollup-plugin-glimmer-template-tag": "^0.4.1",
|
|
90
|
+
"rollup-plugin-ts": "^3.2.0",
|
|
91
|
+
"typescript": "^5.0.4",
|
|
92
|
+
"@nullvoxpopuli/limber-untyped": "0.0.0"
|
|
138
93
|
},
|
|
139
94
|
"volta": {
|
|
140
|
-
"
|
|
141
|
-
"yarn": "1.22.19"
|
|
142
|
-
},
|
|
143
|
-
"engines": {
|
|
144
|
-
"node": "12.* || >= 14.*"
|
|
95
|
+
"extends": "../../../package.json"
|
|
145
96
|
},
|
|
146
97
|
"ember": {
|
|
147
98
|
"edition": "octane"
|
|
148
99
|
},
|
|
149
100
|
"ember-addon": {
|
|
150
|
-
"
|
|
101
|
+
"version": 2,
|
|
102
|
+
"type": "addon",
|
|
103
|
+
"main": "addon-main.cjs",
|
|
104
|
+
"app-js": {}
|
|
105
|
+
},
|
|
106
|
+
"peerDependencies": {
|
|
107
|
+
"@glimmer/compiler": "^0.84.3",
|
|
108
|
+
"@glimmer/component": "^1.1.2",
|
|
109
|
+
"@glimmer/syntax": "^0.84.3",
|
|
110
|
+
"ember-source": "^4.12.0"
|
|
111
|
+
},
|
|
112
|
+
"scripts": {
|
|
113
|
+
"build": "rollup --config",
|
|
114
|
+
"lint:types": "glint",
|
|
115
|
+
"lint:fix": "pnpm -w exec lint fix",
|
|
116
|
+
"start": "rollup --config --watch",
|
|
117
|
+
"lint": "pnpm -w exec lint",
|
|
118
|
+
"lint:js": "pnpm -w exec lint js",
|
|
119
|
+
"lint:js:fix": "pnpm -w exec lint js:fix",
|
|
120
|
+
"lint:hbs": "pnpm -w exec lint hbs",
|
|
121
|
+
"lint:hbs:fix": "pnpm -w exec lint hbs:fix",
|
|
122
|
+
"lint:prettier:fix": "pnpm -w exec lint prettier:fix",
|
|
123
|
+
"lint:prettier": "pnpm -w exec lint prettier"
|
|
151
124
|
}
|
|
152
|
-
}
|
|
125
|
+
}
|
|
@@ -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
|
|
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,80 @@
|
|
|
1
|
+
import { preprocess, transform } from '../gjs';
|
|
2
|
+
import { modules } from '../known-modules';
|
|
3
|
+
import { nameFor } from '../utils';
|
|
4
|
+
|
|
5
|
+
import type { CompileResult, ExtraModules } from '../types';
|
|
6
|
+
import type Component from '@glimmer/component';
|
|
7
|
+
import type { ComponentLike } from '@glint/template';
|
|
8
|
+
|
|
9
|
+
export interface Info {
|
|
10
|
+
code: string;
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function compileJS(code: string, extraModules?: ExtraModules): Promise<CompileResult> {
|
|
15
|
+
let name = nameFor(code);
|
|
16
|
+
let component: undefined | ComponentLike;
|
|
17
|
+
let error: undefined | Error;
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
let compiled = await compileGJS({ code: code, name });
|
|
21
|
+
|
|
22
|
+
if (!compiled) {
|
|
23
|
+
throw new Error(`Compiled output is missing`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// NOTE: we cannot `eval` ESM
|
|
27
|
+
compiled = proxyToSkypack(compiled, extraModules);
|
|
28
|
+
component = (await evalSnippet(compiled)) as unknown as ComponentLike;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
error = e as Error | undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return { name, component, error };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function proxyToSkypack(code: string, extraModules?: ExtraModules) {
|
|
37
|
+
let knownModules = [...Object.keys(extraModules || {}), ...Object.keys(modules)];
|
|
38
|
+
let origin = location.origin;
|
|
39
|
+
|
|
40
|
+
let result = code.replaceAll(/from ('|")([^"']+)('|")/g, (_, __, modulePath) => {
|
|
41
|
+
if (knownModules.includes(modulePath)) {
|
|
42
|
+
return `from '${origin}/${modulePath}'`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return `from 'https://cdn.skypack.dev/${modulePath}'`;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function evalSnippet(code: string) {
|
|
52
|
+
let encodedJs = encodeURIComponent(code);
|
|
53
|
+
let result = await import(
|
|
54
|
+
/* webpackIgnore: true */ `data:text/javascript;charset=utf-8,${encodedJs}`
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
if (!result.default) {
|
|
58
|
+
throw new Error(`Expected module to have a default export, found ${Object.keys(result)}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return result as {
|
|
62
|
+
default: Component;
|
|
63
|
+
services?: { [key: string]: unknown };
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function compileGJS({ code: input, name }: Info) {
|
|
68
|
+
let preprocessed = preprocess(input, name);
|
|
69
|
+
let result = await transform(preprocessed, name, {
|
|
70
|
+
modules: false,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (!result) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let { code } = result;
|
|
78
|
+
|
|
79
|
+
return code;
|
|
80
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ImportUtil } from 'babel-import-util';
|
|
2
|
+
|
|
3
|
+
import { transformTemplateTag } from './template-tag-transform';
|
|
4
|
+
import * as util from './util';
|
|
5
|
+
|
|
6
|
+
import type { NodePath } from '@babel/traverse';
|
|
7
|
+
import type { CallExpression, Class, Program } from '@babel/types';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* This Babel plugin takes parseable code emitted by the string-based
|
|
11
|
+
* preprocessor plugin in this package and converts it into calls to
|
|
12
|
+
* the standardized `precompileTemplate` macro from `@ember/template-compilation`.
|
|
13
|
+
*
|
|
14
|
+
* Its goal is to convert code like this:
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* import { hbs } from 'ember-template-imports';
|
|
18
|
+
*
|
|
19
|
+
* const A = hbs(`A`, {...});
|
|
20
|
+
* const B = [__GLIMMER_TEMPLATE(`B`, {...})];
|
|
21
|
+
* class C {
|
|
22
|
+
* template = hbs(`C`, {...});
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* [__GLIMMER_TEMPLATE(`default`, {...})];
|
|
26
|
+
*
|
|
27
|
+
* class D {
|
|
28
|
+
* [__GLIMMER_TEMPLATE(`D`, {...})]
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* Into this:
|
|
33
|
+
*
|
|
34
|
+
* ```js
|
|
35
|
+
* import { precompileTemplate } from '@ember/template-compilation';
|
|
36
|
+
* import { setComponentTemplate } from '@ember/component';
|
|
37
|
+
* import templateOnlyComponent from '@ember/component/template-only';
|
|
38
|
+
*
|
|
39
|
+
* const A = setComponentTemplate(
|
|
40
|
+
* precompileTemplate(`A`, {...}),
|
|
41
|
+
* templateOnlyComponent('this-module.js', 'A')
|
|
42
|
+
* );
|
|
43
|
+
* const B = setComponentTemplate(
|
|
44
|
+
* precompileTemplate(`B`, {...}),
|
|
45
|
+
* templateOnlyComponent('this-module.js', 'B')
|
|
46
|
+
* );
|
|
47
|
+
* class C {}
|
|
48
|
+
* setComponentTemplate(precompileTemplate(`C`, {...}), C);
|
|
49
|
+
*
|
|
50
|
+
* export default setComponentTemplate(
|
|
51
|
+
* precompileTemplate(`default`, {...}),
|
|
52
|
+
* templateOnlyComponent('this-module.js', '_thisModule')
|
|
53
|
+
* );
|
|
54
|
+
*
|
|
55
|
+
* class D {}
|
|
56
|
+
* setComponentTemplate(precompileTemplate(`D`, {...}), D);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export default function (babel: any) {
|
|
60
|
+
let t = babel.types;
|
|
61
|
+
|
|
62
|
+
let visitor: any = {
|
|
63
|
+
Program: {
|
|
64
|
+
enter(path: NodePath<Program>, state: any) {
|
|
65
|
+
state.importUtil = new ImportUtil(t, path);
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
// Process class bodies before things like class properties get transformed
|
|
70
|
+
// into imperative constructor code that we can't recognize. Taken directly
|
|
71
|
+
// from babel-plugin-htmlbars-inline-precompile https://git.io/JMi1G
|
|
72
|
+
Class(path: NodePath<Class>, state: any) {
|
|
73
|
+
let bodyPath = path.get('body.body');
|
|
74
|
+
|
|
75
|
+
if (!Array.isArray(bodyPath)) return;
|
|
76
|
+
|
|
77
|
+
bodyPath.forEach((path) => {
|
|
78
|
+
if (path.type !== 'ClassProperty') return;
|
|
79
|
+
|
|
80
|
+
let keyPath = path.get('key');
|
|
81
|
+
let valuePath = path.get('value');
|
|
82
|
+
|
|
83
|
+
if (Array.isArray(keyPath)) return;
|
|
84
|
+
|
|
85
|
+
if (keyPath && visitor[keyPath.type]) {
|
|
86
|
+
visitor[keyPath.type](keyPath, state);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (Array.isArray(valuePath)) return;
|
|
90
|
+
|
|
91
|
+
if (valuePath && visitor[valuePath.type]) {
|
|
92
|
+
visitor[valuePath.type](valuePath, state);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
CallExpression(path: NodePath<CallExpression>, state: any) {
|
|
98
|
+
if (util.isTemplateTag(path)) {
|
|
99
|
+
transformTemplateTag(t, path, state);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return { visitor };
|
|
105
|
+
}
|