fix: invalid identifier in manifest (#2070)
This commit is contained in:
@@ -42,7 +42,6 @@ async function initTailwind(
|
|||||||
const root = path.dirname(config.staticDir);
|
const root = path.dirname(config.staticDir);
|
||||||
|
|
||||||
const configPath = await findTailwindConfigFile(root);
|
const configPath = await findTailwindConfigFile(root);
|
||||||
console.log({ configPath, cwd: Deno.cwd() });
|
|
||||||
const url = path.toFileUrl(configPath).href;
|
const url = path.toFileUrl(configPath).href;
|
||||||
const tailwindConfig = (await import(url)).default as Config;
|
const tailwindConfig = (await import(url)).default as Config;
|
||||||
|
|
||||||
|
|||||||
+16
-3
@@ -1,3 +1,4 @@
|
|||||||
|
import { isIdentifierChar, isIdentifierStart } from "$fresh/src/server/deps.ts";
|
||||||
import { extname, join, normalize } from "./deps.ts";
|
import { extname, join, normalize } from "./deps.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,11 +22,23 @@ export function specifierToIdentifier(specifier: string, used: Set<string>) {
|
|||||||
const ext = extname(specifier);
|
const ext = extname(specifier);
|
||||||
if (ext) specifier = specifier.slice(0, -ext.length);
|
if (ext) specifier = specifier.slice(0, -ext.length);
|
||||||
|
|
||||||
|
// Turn the specifier into a readable JS identifier
|
||||||
let ident = "";
|
let ident = "";
|
||||||
if (/^[\d]/.test(specifier)) {
|
for (let i = 0; i < specifier.length; i++) {
|
||||||
ident += "_";
|
const char = specifier.charCodeAt(i);
|
||||||
|
if (i === 0 && !isIdentifierStart(char)) {
|
||||||
|
ident += "_";
|
||||||
|
if (isIdentifierChar(char)) {
|
||||||
|
ident += specifier[i];
|
||||||
|
}
|
||||||
|
} else if (!isIdentifierChar(char)) {
|
||||||
|
if (ident[ident.length - 1] !== "_") {
|
||||||
|
ident += "_";
|
||||||
|
}
|
||||||
|
} else if (ident[ident.length - 1] !== "_" || specifier[i] !== "_") {
|
||||||
|
ident += specifier[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ident += specifier.replace(/[\/.\(\)\[\]\s@-]/g, "_").replace(/_+/g, "_");
|
|
||||||
|
|
||||||
if (used.has(ident)) {
|
if (used.has(ident)) {
|
||||||
let check = ident;
|
let check = ident;
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ Deno.test("specifierToIdentifier", () => {
|
|||||||
assertEquals(run("foo/[[optional]]/bar", used), "foo_optional_bar");
|
assertEquals(run("foo/[[optional]]/bar", used), "foo_optional_bar");
|
||||||
assertEquals(run("foo/as-df/bar", used), "foo_as_df_bar");
|
assertEquals(run("foo/as-df/bar", used), "foo_as_df_bar");
|
||||||
assertEquals(run("foo/as@df", used), "foo_as_df");
|
assertEquals(run("foo/as@df", used), "foo_as_df");
|
||||||
|
assertEquals(run("foo/foo.bar.baz.tsx", used), "foo_foo_bar_baz");
|
||||||
|
assertEquals(run("404", used), "_404");
|
||||||
|
assertEquals(run("foo/_middleware", used), "foo_middleware");
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test("specifierToIdentifier deals with duplicates", () => {
|
Deno.test("specifierToIdentifier deals with duplicates", () => {
|
||||||
|
|||||||
@@ -26,3 +26,7 @@ export {
|
|||||||
assertEquals,
|
assertEquals,
|
||||||
assertThrows,
|
assertThrows,
|
||||||
} from "https://deno.land/std@0.205.0/assert/mod.ts";
|
} from "https://deno.land/std@0.205.0/assert/mod.ts";
|
||||||
|
export {
|
||||||
|
isIdentifierChar,
|
||||||
|
isIdentifierStart,
|
||||||
|
} from "https://esm.sh/@babel/helper-validator-identifier@7.22.20";
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import { PARTIAL_SEARCH_PARAM } from "$fresh/src/constants.ts";
|
import { PARTIAL_SEARCH_PARAM } from "../constants.ts";
|
||||||
import { BaseRoute, ErrorHandlerContext, ServeHandlerInfo } from "./types.ts";
|
import { BaseRoute, ErrorHandlerContext, ServeHandlerInfo } from "./types.ts";
|
||||||
import {
|
import { isIdentifierChar, isIdentifierStart } from "./deps.ts";
|
||||||
isIdentifierChar,
|
|
||||||
isIdentifierStart,
|
|
||||||
} from "https://esm.sh/@babel/helper-validator-identifier@7.22.20";
|
|
||||||
|
|
||||||
type HandlerContext<T = unknown> = T & ServeHandlerInfo & {
|
type HandlerContext<T = unknown> = T & ServeHandlerInfo & {
|
||||||
isPartial: boolean;
|
isPartial: boolean;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import * as $event_handler_string from "./routes/event_handler_string.tsx";
|
|||||||
import * as $event_handler_string_island from "./routes/event_handler_string_island.tsx";
|
import * as $event_handler_string_island from "./routes/event_handler_string_island.tsx";
|
||||||
import * as $evil from "./routes/evil.tsx";
|
import * as $evil from "./routes/evil.tsx";
|
||||||
import * as $failure from "./routes/failure.ts";
|
import * as $failure from "./routes/failure.ts";
|
||||||
|
import * as $foo_bar_baz from "./routes/foo.bar.baz.tsx";
|
||||||
import * as $head_deduplicate from "./routes/head_deduplicate.tsx";
|
import * as $head_deduplicate from "./routes/head_deduplicate.tsx";
|
||||||
import * as $hooks_server_island from "./routes/hooks-server/island.tsx";
|
import * as $hooks_server_island from "./routes/hooks-server/island.tsx";
|
||||||
import * as $hooks_server_useReducer from "./routes/hooks-server/useReducer.tsx";
|
import * as $hooks_server_useReducer from "./routes/hooks-server/useReducer.tsx";
|
||||||
@@ -121,6 +122,7 @@ const manifest = {
|
|||||||
"./routes/event_handler_string_island.tsx": $event_handler_string_island,
|
"./routes/event_handler_string_island.tsx": $event_handler_string_island,
|
||||||
"./routes/evil.tsx": $evil,
|
"./routes/evil.tsx": $evil,
|
||||||
"./routes/failure.ts": $failure,
|
"./routes/failure.ts": $failure,
|
||||||
|
"./routes/foo.bar.baz.tsx": $foo_bar_baz,
|
||||||
"./routes/head_deduplicate.tsx": $head_deduplicate,
|
"./routes/head_deduplicate.tsx": $head_deduplicate,
|
||||||
"./routes/hooks-server/island.tsx": $hooks_server_island,
|
"./routes/hooks-server/island.tsx": $hooks_server_island,
|
||||||
"./routes/hooks-server/useReducer.tsx": $hooks_server_useReducer,
|
"./routes/hooks-server/useReducer.tsx": $hooks_server_useReducer,
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export default function Page() {
|
||||||
|
return <p>it works</p>;
|
||||||
|
}
|
||||||
@@ -77,3 +77,13 @@ Deno.test("support <Head /> with jsx precompile", async () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("Ensure manifest has valid specifiers", async () => {
|
||||||
|
await withFakeServe(
|
||||||
|
"./tests/fixture/main.ts",
|
||||||
|
async (server) => {
|
||||||
|
const doc = await server.getHtml("/foo.bar.baz");
|
||||||
|
assertTextMany(doc, "p", ["it works"]);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ Deno.test("index.tsx route handler test...", async (t) => {
|
|||||||
const ctx = createHandlerContext(req, { manifest });
|
const ctx = createHandlerContext(req, { manifest });
|
||||||
// @ts-ignore handler is not null
|
// @ts-ignore handler is not null
|
||||||
const resp = handler.GET(req, ctx) as Response;
|
const resp = handler.GET(req, ctx) as Response;
|
||||||
console.log("resp", resp);
|
|
||||||
expect(resp.status).toBe(307);
|
expect(resp.status).toBe(307);
|
||||||
expect(resp.headers.get("Location")?.endsWith("init.ts"));
|
expect(resp.headers.get("Location")?.endsWith("init.ts"));
|
||||||
});
|
});
|
||||||
@@ -31,7 +30,6 @@ Deno.test("index.tsx route handler test...", async (t) => {
|
|||||||
};
|
};
|
||||||
// @ts-ignore handler is not null
|
// @ts-ignore handler is not null
|
||||||
const resp = handler.GET(req, ctx) as Response;
|
const resp = handler.GET(req, ctx) as Response;
|
||||||
// console.log("resp", resp);
|
|
||||||
expect(resp.status).toBe(200);
|
expect(resp.status).toBe(200);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user