Skip to content

Commit

Permalink
chore: update routeDataHmr for compatiable with esm (#1077)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Carniato <[email protected]>
  • Loading branch information
jqhr and ryansolid authored Oct 17, 2023
1 parent 4ed94f6 commit 219fe32
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/start/server/routeDataHmr.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
// @ts-nocheck
import generate from "@babel/generator";
import template from "@babel/template";
import _generate from "@babel/generator";
import _template from "@babel/template";
import crypto from "crypto";

/**
* NOTE: @babel/generator and @babel/template have not
* publish esm vision.
* detail: https://github.com/babel/babel/issues/15269#issue-1494499461
*
*/
const generate = typeof _generate.default == 'function' ? _generate.default : _generate
const template = typeof _template.default == 'function' ? _template.default : _template

export default function routeDataHmr() {
return {
visitor: {
Program(path) {
const result = generate.default(path.node);
const result = generate(path.node);
const hash = crypto.createHash("sha256").update(result.code).digest("base64");
const modHash = path.scope.generateUidIdentifier("modHash").name;
const statements = template.default.ast(`
const statements = template.ast(`
export const ${modHash} = "${hash}";
if (import.meta.hot) {
import.meta.hot.data.modHash = ${modHash};
Expand Down

0 comments on commit 219fe32

Please sign in to comment.