Skip to content

Commit 3f327e1

Browse files
committed
refactor: Build only ESM, correct TS types
1 parent b4a484b commit 3f327e1

25 files changed

+94
-224
lines changed

babel.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
module.exports = function (api) {
1+
import mangle from './mangle.json' with { type: 'json' };
2+
3+
export default function (api) {
24
api.cache(true);
35

46
const noModules = String(process.env.BABEL_NO_MODULES) === 'true';
57

68
const rename = {};
7-
const mangle = require('./mangle.json');
89
for (let prop in mangle.props.props) {
910
let name = prop;
1011
if (name[0] === '$') {
@@ -47,4 +48,4 @@ module.exports = function (api) {
4748
}
4849
]
4950
};
50-
};
51+
}

compat/client.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { render, hydrate, unmountComponentAtNode } = require('preact/compat');
1+
import { render, hydrate, unmountComponentAtNode } from 'preact/compat';
22

3-
function createRoot(container) {
3+
export function createRoot(container) {
44
return {
55
// eslint-disable-next-line
66
render: function (children) {
@@ -13,9 +13,12 @@ function createRoot(container) {
1313
};
1414
}
1515

16-
exports.createRoot = createRoot;
17-
18-
exports.hydrateRoot = function (container, children) {
16+
export function hydrateRoot(container, children) {
1917
hydrate(children, container);
2018
return createRoot(container);
19+
}
20+
21+
export default {
22+
createRoot,
23+
hydrateRoot
2124
};

compat/client.mjs

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

compat/jsx-dev-runtime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
require('preact/compat');
1+
import 'preact/compat';
22

3-
module.exports = require('preact/jsx-runtime');
3+
export * from 'preact/jsx-runtime';

compat/jsx-dev-runtime.mjs

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

compat/jsx-runtime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
require('preact/compat');
1+
import 'preact/compat';
22

3-
module.exports = require('preact/jsx-runtime');
3+
export * from 'preact/jsx-runtime';

compat/jsx-runtime.mjs

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

compat/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
22
"name": "preact-compat",
3-
"amdName": "preactCompat",
43
"private": true,
54
"description": "A React compatibility layer for Preact",
5+
"type": "module",
66
"main": "dist/compat.js",
7-
"module": "dist/compat.mjs",
8-
"umd:main": "dist/compat.umd.js",
97
"source": "src/index.js",
108
"types": "src/index.d.ts",
119
"license": "MIT",

compat/scheduler.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
// see scheduler.mjs
1+
/* eslint-disable */
22

3-
function unstable_runWithPriority(priority, callback) {
3+
// This file includes experimental React APIs exported from the "scheduler"
4+
// npm package. Despite being explicitely marked as unstable some libraries
5+
// already make use of them. This file is not a full replacement for the
6+
// scheduler package, but includes the necessary shims to make those libraries
7+
// work with Preact.
8+
9+
export var unstable_ImmediatePriority = 1;
10+
export var unstable_UserBlockingPriority = 2;
11+
export var unstable_NormalPriority = 3;
12+
export var unstable_LowPriority = 4;
13+
export var unstable_IdlePriority = 5;
14+
15+
/**
16+
* @param {number} priority
17+
* @param {() => void} callback
18+
*/
19+
export function unstable_runWithPriority(priority, callback) {
420
return callback();
521
}
622

7-
module.exports = {
8-
unstable_ImmediatePriority: 1,
9-
unstable_UserBlockingPriority: 2,
10-
unstable_NormalPriority: 3,
11-
unstable_LowPriority: 4,
12-
unstable_IdlePriority: 5,
13-
unstable_runWithPriority,
14-
unstable_now: performance.now.bind(performance)
15-
};
23+
export var unstable_now = performance.now.bind(performance);

compat/scheduler.mjs

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

0 commit comments

Comments
 (0)