fix: manifest file encoding non-latin chars (#1433)
This commit is contained in:
@@ -5,6 +5,7 @@ export {
|
||||
extname,
|
||||
fromFileUrl,
|
||||
join,
|
||||
posix,
|
||||
relative,
|
||||
resolve,
|
||||
SEP,
|
||||
|
||||
+35
-10
@@ -1,4 +1,12 @@
|
||||
import { dirname, fromFileUrl, gte, join, toFileUrl, walk } from "./deps.ts";
|
||||
import {
|
||||
dirname,
|
||||
fromFileUrl,
|
||||
gte,
|
||||
join,
|
||||
posix,
|
||||
relative,
|
||||
walk,
|
||||
} from "./deps.ts";
|
||||
import { error } from "./error.ts";
|
||||
|
||||
const MIN_DENO_VERSION = "1.31.0";
|
||||
@@ -30,7 +38,6 @@ async function collectDir(dir: string): Promise<string[]> {
|
||||
throw err;
|
||||
}
|
||||
|
||||
const dirUrl = toFileUrl(dir);
|
||||
const paths = [];
|
||||
const routesFolder = walk(dir, {
|
||||
includeDirs: false,
|
||||
@@ -39,10 +46,7 @@ async function collectDir(dir: string): Promise<string[]> {
|
||||
});
|
||||
|
||||
for await (const entry of routesFolder) {
|
||||
const path = toFileUrl(entry.path).href.substring(
|
||||
dirUrl.href.length,
|
||||
);
|
||||
paths.push(path);
|
||||
paths.push(relative(dir, entry.path));
|
||||
}
|
||||
|
||||
paths.sort();
|
||||
@@ -63,6 +67,17 @@ export async function collect(directory: string): Promise<Manifest> {
|
||||
return { routes, islands };
|
||||
}
|
||||
|
||||
/**
|
||||
* Import specifiers must have forward slashes
|
||||
*/
|
||||
function toImportSpecifier(file: string) {
|
||||
let specifier = posix.normalize(file).replace(/\\/g, "/");
|
||||
if (!specifier.startsWith(".")) {
|
||||
specifier = "./" + specifier;
|
||||
}
|
||||
return specifier;
|
||||
}
|
||||
|
||||
export async function generate(directory: string, manifest: Manifest) {
|
||||
const { routes, islands } = manifest;
|
||||
|
||||
@@ -71,25 +86,35 @@ export async function generate(directory: string, manifest: Manifest) {
|
||||
// This file is automatically updated during development when running \`dev.ts\`.
|
||||
|
||||
${
|
||||
routes.map((file, i) => `import * as $${i} from "./routes${file}";`).join(
|
||||
routes.map((file, i) =>
|
||||
`import * as $${i} from "${toImportSpecifier(join("routes", file))}";`
|
||||
).join(
|
||||
"\n",
|
||||
)
|
||||
}
|
||||
${
|
||||
islands.map((file, i) => `import * as $$${i} from "./islands${file}";`)
|
||||
islands.map((file, i) =>
|
||||
`import * as $$${i} from "${toImportSpecifier(join("islands", file))}";`
|
||||
)
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
${
|
||||
routes.map((file, i) => `${JSON.stringify(`./routes${file}`)}: $${i},`)
|
||||
routes.map((file, i) =>
|
||||
`${JSON.stringify(`${toImportSpecifier(join("routes", file))}`)}: $${i},`
|
||||
)
|
||||
.join("\n ")
|
||||
}
|
||||
},
|
||||
islands: {
|
||||
${
|
||||
islands.map((file, i) => `${JSON.stringify(`./islands${file}`)}: $$${i},`)
|
||||
islands.map((file, i) =>
|
||||
`${
|
||||
JSON.stringify(`${toImportSpecifier(join("islands", file))}`)
|
||||
}: $$${i},`
|
||||
)
|
||||
.join("\n ")
|
||||
}
|
||||
},
|
||||
|
||||
@@ -38,7 +38,8 @@ import * as $32 from "./routes/state-in-props/_middleware.ts";
|
||||
import * as $33 from "./routes/state-in-props/index.tsx";
|
||||
import * as $34 from "./routes/static.tsx";
|
||||
import * as $35 from "./routes/status_overwrite.tsx";
|
||||
import * as $36 from "./routes/wildcard.tsx";
|
||||
import * as $36 from "./routes/umlaut-äöüß.tsx";
|
||||
import * as $37 from "./routes/wildcard.tsx";
|
||||
import * as $$0 from "./islands/Counter.tsx";
|
||||
import * as $$1 from "./islands/MultipleCounters.tsx";
|
||||
import * as $$2 from "./islands/ReturningNull.tsx";
|
||||
@@ -87,7 +88,8 @@ const manifest = {
|
||||
"./routes/state-in-props/index.tsx": $33,
|
||||
"./routes/static.tsx": $34,
|
||||
"./routes/status_overwrite.tsx": $35,
|
||||
"./routes/wildcard.tsx": $36,
|
||||
"./routes/umlaut-äöüß.tsx": $36,
|
||||
"./routes/wildcard.tsx": $37,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Counter.tsx": $$0,
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function Umlaut() {
|
||||
return <h1>it works</h1>;
|
||||
}
|
||||
@@ -879,3 +879,28 @@ Deno.test("renders error boundary", {
|
||||
assertEquals(text, "it works");
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "Resolves routes with non-latin characters",
|
||||
|
||||
async fn() {
|
||||
await withPageName("./tests/fixture/main.ts", async (page, address) => {
|
||||
// Check that we can navigate to the page
|
||||
await page.goto(`${address}/umlaut-äöüß`);
|
||||
await page.waitForSelector("h1");
|
||||
const text = await page.$eval("h1", (el) => el.textContent);
|
||||
assertEquals(text, "it works");
|
||||
|
||||
// Check the manifest
|
||||
const mod = (await import("./fixture/fresh.gen.ts")).default;
|
||||
|
||||
assert(
|
||||
"./routes/umlaut-äöüß.tsx" in mod.routes,
|
||||
"Umlaut route not found",
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user