Skip to content

Commit 4711c23

Browse files
authored
fix: types node16 resolution (#117)
* fix: Types * fix: ESLint configuration * ci: Merge the workflows (sorry for sneaking in)
1 parent a16c3e1 commit 4711c23

File tree

6 files changed

+39
-48
lines changed

6 files changed

+39
-48
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,28 @@ jobs:
1818
with:
1919
node-version: 22
2020
cache: npm
21+
cache-dependency-path: '**/package-lock.json'
2122

2223
- name: Install NPM dependencies
2324
run: npm ci
2425

25-
- name: build
26-
run: npm run build
27-
2826
- name: test
2927
env:
3028
CI: true
3129
run: |
3230
npm run lint
3331
npm run test
32+
33+
size:
34+
name: Compressed Size
35+
runs-on: ubuntu-latest
36+
timeout-minutes: 5
37+
steps:
38+
- uses: actions/checkout@v4
39+
- uses: actions/setup-node@v4
40+
with:
41+
node-version: 22
42+
cache: 'npm'
43+
cache-dependency-path: '**/package-lock.json'
44+
45+
- uses: preactjs/compressed-size-action@v2

.github/workflows/size.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"scripts": {
1111
"prepare": "npx simple-git-hooks",
1212
"build": "microbundle -f cjs,es,umd --no-generateTypes",
13-
"lint": "eslint src/*.{js,jsx}",
13+
"lint": "eslint src/*.js",
1414
"test": "npm run test:types & npm run test:browser",
1515
"test:browser": "wtr test/*.test.{js,jsx}",
1616
"test:types": "tsc -p test/",

src/index.d.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import { h, AnyComponent } from 'preact';
2-
3-
type PreactCustomElement = HTMLElement & {
4-
_root: ShadowRoot | HTMLElement;
5-
_vdomComponent: AnyComponent;
6-
_vdom: ReturnType<typeof h> | null;
7-
_props: Record<string, unknown>;
8-
};
1+
import { AnyComponent } from 'preact';
92

103
type Options =
114
| {
@@ -46,9 +39,11 @@ type Options =
4639
* const klass = register(PreactComponent, 'my-component');
4740
* ```
4841
*/
49-
export default function register<P = {}, S = {}>(
42+
declare function register<P = {}, S = {}>(
5043
Component: AnyComponent<P, S>,
5144
tagName?: string,
5245
propNames?: (keyof P)[],
5346
options?: Options
5447
): HTMLElement;
48+
49+
export = register;

src/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
import { h, cloneElement, render, hydrate, Fragment } from 'preact';
22

33
/**
4-
* @typedef {import('./index.d.ts').PreactCustomElement} PreactCustomElement
4+
* @typedef {import('./internal.d.ts').PreactCustomElement} PreactCustomElement
55
*/
66

77
/**
8-
* @type {import('./index.d.ts').default}
8+
* @type {import('./index.d.ts')}
99
*/
1010
export default function register(Component, tagName, propNames, options) {
1111
function PreactElement() {
1212
const inst = /** @type {PreactCustomElement} */ (
1313
Reflect.construct(HTMLElement, [], PreactElement)
1414
);
1515
inst._vdomComponent = Component;
16-
inst._root =
17-
options && options.shadow
18-
? inst.attachShadow({ mode: options.mode || 'open' })
19-
: inst;
2016

21-
if (options && options.adoptedStyleSheets) {
22-
inst._root.adoptedStyleSheets = options.adoptedStyleSheets;
17+
if (options && options.shadow) {
18+
inst._root = inst.attachShadow({ mode: options.mode || 'open' });
19+
20+
if (options.adoptedStyleSheets) {
21+
inst._root.adoptedStyleSheets = options.adoptedStyleSheets;
22+
}
23+
} else {
24+
inst._root = inst;
2325
}
2426

2527
return inst;
@@ -49,9 +51,7 @@ export default function register(Component, tagName, propNames, options) {
4951
propNames.forEach((name) => {
5052
Object.defineProperty(PreactElement.prototype, name, {
5153
get() {
52-
return this._vdom
53-
? this._vdom.props[name]
54-
: this._props[name];
54+
return this._vdom ? this._vdom.props[name] : this._props[name];
5555
},
5656
set(v) {
5757
if (this._vdom) {

src/internal.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { h, AnyComponent } from 'preact';
2+
3+
export type PreactCustomElement = HTMLElement & {
4+
_root: ShadowRoot | HTMLElement;
5+
_vdomComponent: AnyComponent;
6+
_vdom: ReturnType<typeof h> | null;
7+
_props: Record<string, unknown>;
8+
};

0 commit comments

Comments
 (0)