Skip to content

Commit

Permalink
fix: fix sourcemap
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Nov 29, 2024
1 parent 065b0c9 commit 593358c
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 193 deletions.
31 changes: 0 additions & 31 deletions viteroll/examples/ssr-simple/e2e/basic.test.ts

This file was deleted.

17 changes: 0 additions & 17 deletions viteroll/examples/ssr-simple/package.json

This file was deleted.

1 change: 0 additions & 1 deletion viteroll/examples/ssr-simple/playwright.config.ts

This file was deleted.

21 changes: 0 additions & 21 deletions viteroll/examples/ssr-simple/src/app.tsx

This file was deleted.

7 changes: 0 additions & 7 deletions viteroll/examples/ssr-simple/src/entry-client.tsx

This file was deleted.

27 changes: 0 additions & 27 deletions viteroll/examples/ssr-simple/src/entry-server.tsx

This file was deleted.

16 changes: 0 additions & 16 deletions viteroll/examples/ssr-simple/tsconfig.json

This file was deleted.

54 changes: 0 additions & 54 deletions viteroll/examples/ssr-simple/vite.config.ts

This file was deleted.

3 changes: 2 additions & 1 deletion viteroll/examples/ssr/src/entry-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import ReactDOMServer from "react-dom/server.browser";
import type { Connect } from "vite";
import { App } from "./app";
import { throwError } from "./error";

const handler: Connect.SimpleHandleFunction = (req, res) => {
const url = new URL(req.url ?? "/", "https://vite.dev");
console.log(`[SSR] ${req.method} ${url.pathname}`);
if (url.pathname === "/crash-ssr") {
throw new Error("crash-ssr");
throwError();
}
const ssrHtml = ReactDOMServer.renderToString(<App />);
res.setHeader("content-type", "text/html");
Expand Down
9 changes: 9 additions & 0 deletions viteroll/examples/ssr/src/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// random new lines
//
export function throwError() {
//
// and more
//
throw new Error("boom");
}
23 changes: 5 additions & 18 deletions viteroll/viteroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export class RolldownEnvironment extends DevEnvironment {
if (this.outputOptions.format === "app") {
console.time(`[rolldown:${this.name}:hmr]`);
const result = await this.instance.experimental_hmr_rebuild([ctx.file]);
this.getRunner().evaluate(result[1].toString());
this.getRunner().evaluate(result[1].toString(), result[0]);
console.timeEnd(`[rolldown:${this.name}:hmr]`);
} else {
await this.build();
Expand All @@ -301,7 +301,7 @@ export class RolldownEnvironment extends DevEnvironment {
const filepath = path.join(this.outDir, output.fileName);
this.runner = new RolldownModuleRunner();
const code = fs.readFileSync(filepath, "utf-8");
this.runner.evaluate(code);
this.runner.evaluate(code, filepath);
}
return this.runner;
}
Expand Down Expand Up @@ -337,12 +337,11 @@ class RolldownModuleRunner {
return mod.exports;
}

evaluate(code: string) {
evaluate(code: string, sourceURL: string) {
const context = {
self: this.context,
...this.context,
};
// TODO: sourcemap not working?
// extract sourcemap
const sourcemap = code.match(/^\/\/# sourceMappingURL=.*/m)?.[0] ?? "";
if (sourcemap) {
Expand All @@ -356,23 +355,11 @@ self.__toCommonJS = __toCommonJS;
self.__export = __export;
self.__toESM = __toESM;
}}
//# sourceMappingSource=rolldown-module-runner
//# sourceURL=${sourceURL}
${sourcemap}
`;
// as new Function
// code = `\
// ${code}
// // TODO: need to re-expose runtime utilities for now
// self.__toCommonJS = __toCommonJS;
// self.__export = __export;
// self.__toESM = __toESM;
// //# sourceMappingSource=rolldown-module-runner
// ${sourcemap}
// `;
fs.writeFileSync("dump.js", code);
const fn = (0, eval)(code);
// const fn = new Function(...Object.keys(context), code);
try {
const fn = (0, eval)(code);
fn(...Object.values(context));
} catch (e) {
console.error(e);
Expand Down

0 comments on commit 593358c

Please sign in to comment.