fix: manifest file encoding non-latin chars (#1433)
This commit is contained in:
@@ -5,6 +5,7 @@ export {
|
|||||||
extname,
|
extname,
|
||||||
fromFileUrl,
|
fromFileUrl,
|
||||||
join,
|
join,
|
||||||
|
posix,
|
||||||
relative,
|
relative,
|
||||||
resolve,
|
resolve,
|
||||||
SEP,
|
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";
|
import { error } from "./error.ts";
|
||||||
|
|
||||||
const MIN_DENO_VERSION = "1.31.0";
|
const MIN_DENO_VERSION = "1.31.0";
|
||||||
@@ -30,7 +38,6 @@ async function collectDir(dir: string): Promise<string[]> {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dirUrl = toFileUrl(dir);
|
|
||||||
const paths = [];
|
const paths = [];
|
||||||
const routesFolder = walk(dir, {
|
const routesFolder = walk(dir, {
|
||||||
includeDirs: false,
|
includeDirs: false,
|
||||||
@@ -39,10 +46,7 @@ async function collectDir(dir: string): Promise<string[]> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
for await (const entry of routesFolder) {
|
for await (const entry of routesFolder) {
|
||||||
const path = toFileUrl(entry.path).href.substring(
|
paths.push(relative(dir, entry.path));
|
||||||
dirUrl.href.length,
|
|
||||||
);
|
|
||||||
paths.push(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
paths.sort();
|
paths.sort();
|
||||||
@@ -63,6 +67,17 @@ export async function collect(directory: string): Promise<Manifest> {
|
|||||||
return { routes, islands };
|
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) {
|
export async function generate(directory: string, manifest: Manifest) {
|
||||||
const { routes, islands } = 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\`.
|
// 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",
|
"\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")
|
.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
const manifest = {
|
const manifest = {
|
||||||
routes: {
|
routes: {
|
||||||
${
|
${
|
||||||
routes.map((file, i) => `${JSON.stringify(`./routes${file}`)}: $${i},`)
|
routes.map((file, i) =>
|
||||||
|
`${JSON.stringify(`${toImportSpecifier(join("routes", file))}`)}: $${i},`
|
||||||
|
)
|
||||||
.join("\n ")
|
.join("\n ")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
islands: {
|
islands: {
|
||||||
${
|
${
|
||||||
islands.map((file, i) => `${JSON.stringify(`./islands${file}`)}: $$${i},`)
|
islands.map((file, i) =>
|
||||||
|
`${
|
||||||
|
JSON.stringify(`${toImportSpecifier(join("islands", file))}`)
|
||||||
|
}: $$${i},`
|
||||||
|
)
|
||||||
.join("\n ")
|
.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 $33 from "./routes/state-in-props/index.tsx";
|
||||||
import * as $34 from "./routes/static.tsx";
|
import * as $34 from "./routes/static.tsx";
|
||||||
import * as $35 from "./routes/status_overwrite.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 $$0 from "./islands/Counter.tsx";
|
||||||
import * as $$1 from "./islands/MultipleCounters.tsx";
|
import * as $$1 from "./islands/MultipleCounters.tsx";
|
||||||
import * as $$2 from "./islands/ReturningNull.tsx";
|
import * as $$2 from "./islands/ReturningNull.tsx";
|
||||||
@@ -87,7 +88,8 @@ const manifest = {
|
|||||||
"./routes/state-in-props/index.tsx": $33,
|
"./routes/state-in-props/index.tsx": $33,
|
||||||
"./routes/static.tsx": $34,
|
"./routes/static.tsx": $34,
|
||||||
"./routes/status_overwrite.tsx": $35,
|
"./routes/status_overwrite.tsx": $35,
|
||||||
"./routes/wildcard.tsx": $36,
|
"./routes/umlaut-äöüß.tsx": $36,
|
||||||
|
"./routes/wildcard.tsx": $37,
|
||||||
},
|
},
|
||||||
islands: {
|
islands: {
|
||||||
"./islands/Counter.tsx": $$0,
|
"./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");
|
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