Skip to content

Commit 95b946b

Browse files
committed
adding glint support
1 parent 7d74858 commit 95b946b

File tree

10 files changed

+878
-75
lines changed

10 files changed

+878
-75
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# compiled output
44
dist/
5+
declarations/
56
tmp/
67

78
# dependencies

ember-element-helper/babel.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"presets": ["@babel/preset-typescript"],
23
"plugins": [
34
"@embroider/addon-dev/template-colocation-plugin",
45
["@babel/plugin-proposal-decorators", { "legacy": true }],

ember-element-helper/package.json

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,27 @@
1111
"dynamic element"
1212
],
1313
"exports": {
14-
".": "./dist/index.js",
15-
"./*": "./dist/*"
14+
".": {
15+
"types": "./declarations/index.d.ts",
16+
"default": "./dist/index.js"
17+
},
18+
"./*": {
19+
"types": "./declarations/*.d.ts",
20+
"default": "./dist/*"
21+
},
22+
"./addon-main.js": "./addon-main.cjs"
1623
},
1724
"files": [
1825
"dist",
26+
"declarations",
1927
"addon-main.cjs",
2028
"CHANGELOG.md",
2129
"README.md"
2230
],
2331
"scripts": {
2432
"start": "concurrently 'npm:watch:*'",
2533
"build": "concurrently 'npm:build:*'",
26-
"build:js": "rollup -c ./rollup.config.js",
34+
"build:js": "rollup -c",
2735
"build:docs": "cp ../README.md ./README.md",
2836
"watch:js": "rollup -c --watch --no-watch.clearScreen",
2937
"lint": "concurrently 'npm:lint:js'",
@@ -44,9 +52,18 @@
4452
"@babel/plugin-proposal-class-properties": "7.18.6",
4553
"@babel/plugin-syntax-decorators": "7.18.6",
4654
"@babel/plugin-proposal-decorators": "7.18.6",
47-
"@embroider/addon-dev": "1.8.3",
55+
"@babel/preset-typescript": "7.22.5",
56+
"@babel/runtime": "^7.22.6",
57+
"@embroider/addon-dev": "3.2.0",
4858
"@nullvoxpopuli/eslint-configs": "2.2.36",
59+
"@rollup/plugin-babel": "6.0.3",
60+
"@rollup/plugin-node-resolve": "15.1.0",
61+
"@tsconfig/ember": "^3.0.0",
62+
"@types/rsvp": "^4.0.4",
63+
"@typescript-eslint/eslint-plugin": "^5.62.0",
64+
"@typescript-eslint/parser": "^5.62.0",
4965
"concurrently": "7.2.2",
66+
"ember-source": "~4.12.3",
5067
"eslint-config-prettier": "8.5.0",
5168
"eslint-plugin-decorator-position": "5.0.0",
5269
"eslint-plugin-ember": "10.6.1",
@@ -55,10 +72,10 @@
5572
"eslint-plugin-node": "11.1.0",
5673
"eslint-plugin-prettier": "4.2.1",
5774
"eslint-plugin-simple-import-sort": "7.0.0",
58-
"rollup": "2.77.0",
75+
"rollup": "3.26.3",
5976
"babel-eslint": "10.1.0",
6077
"eslint": "^7.0.0",
61-
"@rollup/plugin-babel": "5.3.1"
78+
"typescript": "5.1.6"
6279
},
6380
"publishConfig": {
6481
"registry": "https://registry.npmjs.org"
@@ -81,7 +98,7 @@
8198
"extends": "../package.json"
8299
},
83100
"peerDependencies": {
84-
"ember-source": "^3.8 || 4"
101+
"ember-source": "^3.8 || >= 4.0.0"
85102
},
86103
"release-it": {
87104
"plugins": {
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
1-
import babel from '@rollup/plugin-babel';
1+
import { babel } from '@rollup/plugin-babel';
22
import { Addon } from '@embroider/addon-dev/rollup';
3+
import { defineConfig } from 'rollup';
4+
import { nodeResolve } from '@rollup/plugin-node-resolve';
35

46
const addon = new Addon({
57
srcDir: 'src',
68
destDir: 'dist',
79
});
810

9-
export default {
11+
const extensions = ['.js', '.ts'];
12+
13+
export default defineConfig({
1014
// This provides defaults that work well alongside `publicEntrypoints` below.
1115
// You can augment this if you need to.
1216
output: addon.output(),
1317

1418
plugins: [
1519
// These are the modules that users should be able to import from your
1620
// addon. Anything not listed here may get optimized away.
17-
addon.publicEntrypoints(['**/*.js']),
21+
addon.publicEntrypoints(['index.js', 'helpers/element.js']),
1822

1923
// These are the modules that should get reexported into the traditional
2024
// "app" tree. Things in here should also be in publicEntrypoints above, but
2125
// not everything in publicEntrypoints necessarily needs to go here.
22-
addon.appReexports([
23-
'components/**/*.js',
24-
'helpers/**/*.js',
25-
'modifiers/**/*.js',
26-
'services/**/*.js',
27-
'initializers/**/*.js',
28-
'instance-initializers/**/*.js',
29-
]),
26+
addon.appReexports(['helpers/element.js']),
27+
28+
// Follow the V2 Addon rules about dependencies. Your code can import from
29+
// `dependencies` and `peerDependencies` as well as standard Ember-provided
30+
// package names.
31+
addon.dependencies(),
32+
33+
nodeResolve({ extensions }),
3034

3135
// This babel config should *not* apply presets or compile away ES modules.
3236
// It exists only to provide development niceties for you, like automatic
@@ -35,14 +39,10 @@ export default {
3539
// By default, this will load the actual babel config from the file
3640
// babel.config.json.
3741
babel({
42+
extensions,
3843
babelHelpers: 'bundled',
3944
}),
4045

41-
// Follow the V2 Addon rules about dependencies. Your code can import from
42-
// `dependencies` and `peerDependencies` as well as standard Ember-provided
43-
// package names.
44-
addon.dependencies(),
45-
4646
// Ensure that standalone .hbs files are properly integrated as Javascript.
4747
addon.hbs(),
4848

@@ -53,4 +53,4 @@ export default {
5353
// Remove leftover build artifacts when starting a new build.
5454
addon.clean(),
5555
],
56-
};
56+
});

ember-element-helper/src/helpers/element.js renamed to ember-element-helper/src/helpers/element.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,24 @@ import { ensureSafeComponent } from '@embroider/util';
77

88
function UNINITIALIZED() {}
99

10-
export default class ElementHelper extends Helper {
11-
constructor() {
12-
super(...arguments);
13-
this.tagName = UNINITIALIZED;
14-
this.componentClass = null;
15-
}
10+
type Positional<T> = [name: T];
11+
type Return<T> = EmberComponent<{
12+
Element: T extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[T] : Element;
13+
Blocks: { default: [] };
14+
}>;
15+
16+
export interface ElementSignature<T extends string> {
17+
Args: {
18+
Positional: Positional<T>;
19+
};
20+
Return: Return<T> | undefined;
21+
}
22+
23+
export default class ElementHelper<T extends string> extends Helper<ElementSignature<T>> {
24+
tagName: string | (() => void) = UNINITIALIZED;
25+
componentClass?: Return<T>;
1626

17-
compute(params, hash) {
27+
compute(params: Positional<T>, hash: object) {
1828
assert('The `element` helper takes a single positional argument', params.length === 1);
1929
assert(
2030
'The `element` helper does not take any named arguments',
@@ -32,9 +42,9 @@ export default class ElementHelper extends Helper {
3242
tagName = tagName; // eslint-disable-line ember/require-tagless-components
3343
},
3444
this
35-
);
45+
) as Return<T>;
3646
} else {
37-
this.componentClass = null;
47+
this.componentClass = undefined;
3848

3949
runInDebug(() => {
4050
let message = 'The argument passed to the `element` helper must be a string';

ember-element-helper/src/index.js

Whitespace-only changes.

ember-element-helper/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import ElementHelper from './helpers/element';
2+
3+
export { ElementHelper as element };

ember-element-helper/tsconfig.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": "@tsconfig/ember/tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": false,
5+
"emitDeclarationOnly": true,
6+
"declarationDir": "./declarations",
7+
"paths": {
8+
"*": [
9+
"./types/*"
10+
]
11+
}
12+
},
13+
"include": [
14+
"src/**/*",
15+
"types/**/*"
16+
],
17+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import 'ember-source/types';
2+
import 'ember-source/types/preview';

0 commit comments

Comments
 (0)