fix: cut off file names when project is at root / (#1957)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
// -- $std --
|
||||
export {
|
||||
fromFileUrl,
|
||||
join,
|
||||
relative,
|
||||
toFileUrl,
|
||||
} from "https://deno.land/std@0.193.0/path/mod.ts";
|
||||
export { escape as regexpEscape } from "https://deno.land/std@0.193.0/regexp/escape.ts";
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
esbuildWasmURL,
|
||||
fromFileUrl,
|
||||
regexpEscape,
|
||||
toFileUrl,
|
||||
relative,
|
||||
} from "./deps.ts";
|
||||
import { Builder, BuildSnapshot } from "./mod.ts";
|
||||
|
||||
@@ -21,6 +21,7 @@ export interface EsbuildBuilderOptions {
|
||||
/** The JSX configuration. */
|
||||
jsxConfig: JSXConfig;
|
||||
target: string | string[];
|
||||
absoluteWorkingDir: string;
|
||||
}
|
||||
|
||||
export interface JSXConfig {
|
||||
@@ -40,7 +41,7 @@ export class EsbuildBuilder implements Builder {
|
||||
try {
|
||||
await initEsbuild();
|
||||
|
||||
const absWorkingDir = Deno.cwd();
|
||||
const absWorkingDir = opts.absoluteWorkingDir;
|
||||
|
||||
// In dev-mode we skip identifier minification to be able to show proper
|
||||
// component names in Preact DevTools instead of single characters.
|
||||
@@ -82,10 +83,8 @@ export class EsbuildBuilder implements Builder {
|
||||
const files = new Map<string, Uint8Array>();
|
||||
const dependencies = new Map<string, string[]>();
|
||||
|
||||
const absWorkingDirLen = toFileUrl(absWorkingDir).href.length + 1;
|
||||
|
||||
for (const file of bundle.outputFiles) {
|
||||
const path = toFileUrl(file.path).href.slice(absWorkingDirLen);
|
||||
const path = relative(absWorkingDir, file.path);
|
||||
files.set(path, file.contents);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { assertEquals } from "$std/testing/asserts.ts";
|
||||
import { fromFileUrl, join, toFileUrl } from "../server/deps.ts";
|
||||
import { EsbuildBuilder } from "./esbuild.ts";
|
||||
|
||||
const denoJson = join(
|
||||
fromFileUrl(import.meta.url),
|
||||
"..",
|
||||
"..",
|
||||
"..",
|
||||
"deno.json",
|
||||
);
|
||||
|
||||
const mainEntry = toFileUrl(join(
|
||||
fromFileUrl(import.meta.url),
|
||||
"..",
|
||||
"..",
|
||||
"runtime",
|
||||
"entrypoints",
|
||||
"client.ts",
|
||||
)).href;
|
||||
|
||||
Deno.test("esbuild snapshot with cwd=Deno.cwd()", async () => {
|
||||
const builder = new EsbuildBuilder({
|
||||
absoluteWorkingDir: Deno.cwd(),
|
||||
buildID: "foo",
|
||||
configPath: denoJson,
|
||||
dev: false,
|
||||
entrypoints: {
|
||||
main: mainEntry,
|
||||
},
|
||||
jsxConfig: {
|
||||
jsx: "react-jsx",
|
||||
},
|
||||
target: "es2020",
|
||||
});
|
||||
|
||||
const snapshot = await builder.build();
|
||||
assertEquals(snapshot.paths, ["main.js", "metafile.json"]);
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "esbuild snapshot with cwd=/",
|
||||
ignore: Deno.build.os === "windows",
|
||||
fn: async () => {
|
||||
const builder = new EsbuildBuilder({
|
||||
absoluteWorkingDir: "/",
|
||||
buildID: "foo",
|
||||
configPath: denoJson,
|
||||
dev: false,
|
||||
entrypoints: {
|
||||
main: mainEntry,
|
||||
},
|
||||
jsxConfig: {
|
||||
jsx: "react-jsx",
|
||||
},
|
||||
target: "es2020",
|
||||
});
|
||||
|
||||
const snapshot = await builder.build();
|
||||
assertEquals(snapshot.paths, ["main.js", "metafile.json"]);
|
||||
},
|
||||
});
|
||||
@@ -450,6 +450,7 @@ export class ServerContext {
|
||||
dev: this.#dev,
|
||||
jsxConfig,
|
||||
target,
|
||||
absoluteWorkingDir: Deno.cwd(),
|
||||
});
|
||||
this.#routerOptions = routerOptions;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user