Skip to content

Commit

Permalink
fix: convert client modules to ESM (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Oct 31, 2024
1 parent 386155a commit d720bbb
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 28 deletions.
File renamed without changes.
3 changes: 3 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
4 changes: 2 additions & 2 deletions client/prefresh.cjs → client/prefresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* https://github.com/preactjs/prefresh/blob/018f5cc907629b82ffb201c32e948efe4b40098a/LICENSE
*/

const { isComponent, flush } = require('@prefresh/utils');
import { flush, isComponent } from '@prefresh/utils';

// eslint-disable-next-line
const getExports = (m) => m.exports || m.__proto__.exports;
Expand Down Expand Up @@ -62,7 +62,7 @@ const shouldBind = (m) => {
return isCitizen;
};

module.exports = Object.freeze({
export default Object.freeze({
getExports,
shouldBind,
flush,
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ interface NormalizedPluginOptions extends IPreactRefreshRspackPluginOptions {

const PREFRESH_CORE_PATH = require.resolve('@prefresh/core');
const PREFRESH_UTILS_PATH = require.resolve('@prefresh/utils');
const RUNTIME_UTIL_PATH = require.resolve('../client/prefresh.cjs');
const RUNTIME_INTERCEPT_PATH = require.resolve('../client/intercept.cjs');
const RUNTIME_UTIL_PATH = require.resolve('../client/prefresh.js');
const RUNTIME_INTERCEPT_PATH = require.resolve('../client/intercept.js');

const runtimeSource = fs.readFileSync(RUNTIME_INTERCEPT_PATH, 'utf-8');

Expand Down Expand Up @@ -79,7 +79,7 @@ class PreactRefreshRspackPlugin implements RspackPluginInstance {
];

new compiler.webpack.ProvidePlugin({
__prefresh_utils__: RUNTIME_UTIL_PATH,
__prefresh_utils__: [RUNTIME_UTIL_PATH, 'default'],
...(this.options.overlay
? {
__prefresh_errors__: require.resolve(this.options.overlay.module),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Asset Files
- Bundle: bundle.js
- Manifest: main.LAST_HASH.hot-update.json, size: 28
- Update: main.LAST_HASH.hot-update.js, size: 5127
- Update: main.LAST_HASH.hot-update.js, size: 5136

## Manifest

Expand Down Expand Up @@ -41,7 +41,7 @@ __webpack_require__.d(__webpack_exports__, {
/* ESM import */var preact_compat__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! preact/compat */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/compat/dist/compat.module.js");
/* ESM import */var preact_hooks__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! preact/hooks */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/hooks/dist/hooks.module.js");
/* module decorator */ module = __webpack_require__.hmd(module);
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.cjs */ "../../../../client/prefresh.cjs");
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.js */ "../../../../client/prefresh.js")["default"];

var _s = $RefreshSig$();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Asset Files
- Bundle: bundle.js
- Manifest: main.LAST_HASH.hot-update.json, size: 28
- Update: main.LAST_HASH.hot-update.js, size: 5432
- Update: main.LAST_HASH.hot-update.js, size: 5441

## Manifest

Expand Down Expand Up @@ -41,7 +41,7 @@ __webpack_require__.d(__webpack_exports__, {
/* ESM import */var preact_compat__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! preact/compat */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/compat/dist/compat.module.js");
/* ESM import */var preact_hooks__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! preact/hooks */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/hooks/dist/hooks.module.js");
/* module decorator */ module = __webpack_require__.hmd(module);
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.cjs */ "../../../../client/prefresh.cjs");
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.js */ "../../../../client/prefresh.js")["default"];

var _s = $RefreshSig$();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Asset Files
- Bundle: bundle.js
- Manifest: main.LAST_HASH.hot-update.json, size: 28
- Update: main.LAST_HASH.hot-update.js, size: 5448
- Update: main.LAST_HASH.hot-update.js, size: 5457

## Manifest

Expand Down Expand Up @@ -41,7 +41,7 @@ __webpack_require__.d(__webpack_exports__, {
/* ESM import */var preact_compat__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! preact/compat */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/compat/dist/compat.module.js");
/* ESM import */var preact_hooks__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! preact/hooks */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/hooks/dist/hooks.module.js");
/* module decorator */ module = __webpack_require__.hmd(module);
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.cjs */ "../../../../client/prefresh.cjs");
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.js */ "../../../../client/prefresh.js")["default"];

var _s = $RefreshSig$();

Expand Down
4 changes: 2 additions & 2 deletions test/hotCases/hook/useState#keep/__snapshots__/web/1.snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Asset Files
- Bundle: bundle.js
- Manifest: main.LAST_HASH.hot-update.json, size: 28
- Update: main.LAST_HASH.hot-update.js, size: 4704
- Update: main.LAST_HASH.hot-update.js, size: 4713

## Manifest

Expand Down Expand Up @@ -41,7 +41,7 @@ __webpack_require__.d(__webpack_exports__, {
/* ESM import */var react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react/jsx-dev-runtime */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/compat/jsx-dev-runtime.js");
/* ESM import */var preact_hooks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! preact/hooks */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/hooks/dist/hooks.module.js");
/* module decorator */ module = __webpack_require__.hmd(module);
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.cjs */ "../../../../client/prefresh.cjs");
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.js */ "../../../../client/prefresh.js")["default"];


var _s = $RefreshSig$();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Asset Files
- Bundle: bundle.js
- Manifest: main.LAST_HASH.hot-update.json, size: 28
- Update: main.LAST_HASH.hot-update.js, size: 4596
- Update: main.LAST_HASH.hot-update.js, size: 4605

## Manifest

Expand Down Expand Up @@ -41,7 +41,7 @@ __webpack_require__.d(__webpack_exports__, {
/* ESM import */var react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react/jsx-dev-runtime */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/compat/jsx-dev-runtime.js");
/* ESM import */var preact_hooks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! preact/hooks */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/hooks/dist/hooks.module.js");
/* module decorator */ module = __webpack_require__.hmd(module);
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.cjs */ "../../../../client/prefresh.cjs");
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.js */ "../../../../client/prefresh.js")["default"];


var _s = $RefreshSig$();
Expand Down
4 changes: 2 additions & 2 deletions test/hotCases/jsx/basic/__snapshots__/web/1.snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Asset Files
- Bundle: bundle.js
- Manifest: main.LAST_HASH.hot-update.json, size: 28
- Update: main.LAST_HASH.hot-update.js, size: 3809
- Update: main.LAST_HASH.hot-update.js, size: 3818

## Manifest

Expand Down Expand Up @@ -39,7 +39,7 @@ __webpack_require__.d(__webpack_exports__, {
});
/* ESM import */var react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react/jsx-dev-runtime */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/compat/jsx-dev-runtime.js");
/* module decorator */ module = __webpack_require__.hmd(module);
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.cjs */ "../../../../client/prefresh.cjs");
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.js */ "../../../../client/prefresh.js")["default"];

function App() {
return /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)("div", {
Expand Down
4 changes: 2 additions & 2 deletions test/hotCases/jsx/basic/__snapshots__/web/2.snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Asset Files
- Bundle: bundle.js
- Manifest: main.LAST_HASH.hot-update.json, size: 28
- Update: main.LAST_HASH.hot-update.js, size: 3809
- Update: main.LAST_HASH.hot-update.js, size: 3818

## Manifest

Expand Down Expand Up @@ -39,7 +39,7 @@ __webpack_require__.d(__webpack_exports__, {
});
/* ESM import */var react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react/jsx-dev-runtime */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/compat/jsx-dev-runtime.js");
/* module decorator */ module = __webpack_require__.hmd(module);
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.cjs */ "../../../../client/prefresh.cjs");
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.js */ "../../../../client/prefresh.js")["default"];

function App() {
return /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)("div", {
Expand Down
6 changes: 3 additions & 3 deletions test/hotCases/jsx/child/__snapshots__/web/1.snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## Asset Files
- Bundle: bundle.js
- Manifest: main.LAST_HASH.hot-update.json, size: 28
- Update: main.LAST_HASH.hot-update.js, size: 7251
- Update: main.LAST_HASH.hot-update.js, size: 7269

## Manifest

Expand Down Expand Up @@ -42,7 +42,7 @@ __webpack_require__.d(__webpack_exports__, {
/* ESM import */var react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react/jsx-dev-runtime */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/compat/jsx-dev-runtime.js");
/* ESM import */var _child__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./child */ "./child.jsx");
/* module decorator */ module = __webpack_require__.hmd(module);
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.cjs */ "../../../../client/prefresh.cjs");
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.js */ "../../../../client/prefresh.js")["default"];


function App() {
Expand Down Expand Up @@ -144,7 +144,7 @@ __webpack_require__.d(__webpack_exports__, {
});
/* ESM import */var react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react/jsx-dev-runtime */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/compat/jsx-dev-runtime.js");
/* module decorator */ module = __webpack_require__.hmd(module);
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.cjs */ "../../../../client/prefresh.cjs");
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.js */ "../../../../client/prefresh.js")["default"];

function Child() {
return /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)("span", {
Expand Down
4 changes: 2 additions & 2 deletions test/hotCases/jsx/child/__snapshots__/web/2.snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Asset Files
- Bundle: bundle.js
- Manifest: main.LAST_HASH.hot-update.json, size: 28
- Update: main.LAST_HASH.hot-update.js, size: 3546
- Update: main.LAST_HASH.hot-update.js, size: 3555

## Manifest

Expand Down Expand Up @@ -39,7 +39,7 @@ __webpack_require__.d(__webpack_exports__, {
});
/* ESM import */var react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react/jsx-dev-runtime */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/compat/jsx-dev-runtime.js");
/* module decorator */ module = __webpack_require__.hmd(module);
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.cjs */ "../../../../client/prefresh.cjs");
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.js */ "../../../../client/prefresh.js")["default"];

function Child() {
return /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)("span", {
Expand Down
4 changes: 2 additions & 2 deletions test/hotCases/jsx/value/__snapshots__/web/1.snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Asset Files
- Bundle: bundle.js
- Manifest: main.LAST_HASH.hot-update.json, size: 28
- Update: main.LAST_HASH.hot-update.js, size: 3832
- Update: main.LAST_HASH.hot-update.js, size: 3841

## Manifest

Expand Down Expand Up @@ -39,7 +39,7 @@ __webpack_require__.d(__webpack_exports__, {
});
/* ESM import */var react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react/jsx-dev-runtime */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/compat/jsx-dev-runtime.js");
/* module decorator */ module = __webpack_require__.hmd(module);
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.cjs */ "../../../../client/prefresh.cjs");
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.js */ "../../../../client/prefresh.js")["default"];

function App() {
var value = "content 2";
Expand Down
4 changes: 2 additions & 2 deletions test/hotCases/jsx/value/__snapshots__/web/2.snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Asset Files
- Bundle: bundle.js
- Manifest: main.LAST_HASH.hot-update.json, size: 28
- Update: main.LAST_HASH.hot-update.js, size: 3832
- Update: main.LAST_HASH.hot-update.js, size: 3841

## Manifest

Expand Down Expand Up @@ -39,7 +39,7 @@ __webpack_require__.d(__webpack_exports__, {
});
/* ESM import */var react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react/jsx-dev-runtime */ "../../../../node_modules/.pnpm/[email protected]/node_modules/preact/compat/jsx-dev-runtime.js");
/* module decorator */ module = __webpack_require__.hmd(module);
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.cjs */ "../../../../client/prefresh.cjs");
/* provided dependency */ var __prefresh_utils__ = __webpack_require__(/*! ../../../../client/prefresh.js */ "../../../../client/prefresh.js")["default"];

function App() {
var value = "content 3";
Expand Down

0 comments on commit d720bbb

Please sign in to comment.