Skip to content

Commit

Permalink
Fix fake module export names resolving (close #510)
Browse files Browse the repository at this point in the history
  • Loading branch information
ije committed Jan 28, 2023
1 parent 427edfa commit acc1be1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
15 changes: 13 additions & 2 deletions server/esm.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,20 @@ func initModule(wd string, pkg Pkg, target string, isDev bool) (esm *ESM, npm Np
return
}

log.Warnf("fake ES module '%s' of '%s', use the `main` field instead", npm.Module, npm.Name)
var ret cjsExportsResult
ret, err = parseCJSModuleExports(wd, path.Join(wd, "node_modules", pkg.Name, modulePath), nodeEnv)
if err == nil && ret.Error != "" {
err = fmt.Errorf("parseCJSModuleExports: %s", ret.Error)
}
if err != nil {
return
}
npm.Main = npm.Module
npm.Module = ""
esm.ExportDefault = ret.ExportDefault
esm.Exports = ret.Exports
log.Warnf("fake ES module '%s' of '%s'", npm.Main, npm.Name)
return
}

if npm.Main != "" {
Expand All @@ -189,7 +201,6 @@ func initModule(wd string, pkg Pkg, target string, isDev bool) (esm *ESM, npm Np
esm.ExportDefault = ret.ExportDefault
esm.Exports = ret.Exports
}

return
}

Expand Down
8 changes: 8 additions & 0 deletions test/react-18-stream/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"lib": [
"dom",
"deno.ns"
]
}
}
18 changes: 18 additions & 0 deletions test/react-18-stream/react-steam.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { assertStringIncludes } from "https://deno.land/[email protected]/testing/asserts.ts";

import React from "http://localhost:8080/react@18";
import { renderToReadableStream } from "http://localhost:8080/react-dom@18/server";

Deno.test("react-18-stream", async () => {
const res = new Response(
await renderToReadableStream(
<main>
<h1>Hi :)</h1>
</main>,
),
);
const html = await res.text();
assertStringIncludes(html, "<main");
assertStringIncludes(html, "<h1>Hi :)</h1>");
assertStringIncludes(html, "</main>");
});

0 comments on commit acc1be1

Please sign in to comment.