@reckona/mreact-router 0.0.150 → 0.0.152
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +60 -8
- package/dist/build.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/link.d.ts +17 -7
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js.map +1 -1
- package/dist/tailwind-source.d.ts +6 -0
- package/dist/tailwind-source.d.ts.map +1 -0
- package/dist/tailwind-source.js +25 -0
- package/dist/tailwind-source.js.map +1 -0
- package/dist/typed-routes.d.ts +6 -1
- package/dist/typed-routes.d.ts.map +1 -1
- package/dist/typed-routes.js.map +1 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +3 -25
- package/dist/vite.js.map +1 -1
- package/package.json +11 -11
- package/src/build.ts +81 -10
- package/src/index.ts +9 -0
- package/src/link.ts +34 -11
- package/src/tailwind-source.ts +37 -0
- package/src/typed-routes.ts +22 -3
- package/src/vite.ts +3 -38
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { dirname, relative, sep } from "node:path";
|
|
2
|
+
|
|
3
|
+
export function prependTailwindSourceDirectives(options: {
|
|
4
|
+
code: string;
|
|
5
|
+
cssFile: string;
|
|
6
|
+
sourceDirs: readonly string[];
|
|
7
|
+
}): string {
|
|
8
|
+
if (!isTailwindCssEntry(options.code)) {
|
|
9
|
+
return options.code;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const cssDir = dirname(options.cssFile);
|
|
13
|
+
const directives = [...new Set(options.sourceDirs)]
|
|
14
|
+
.map((sourceDir) => `${tailwindSourceDirective(cssDir, sourceDir)}\n`)
|
|
15
|
+
.join("");
|
|
16
|
+
|
|
17
|
+
return directives.length === 0 ? options.code : `${directives}${options.code}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function isTailwindCssEntry(code: string): boolean {
|
|
21
|
+
return (
|
|
22
|
+
/@import\s+(?:url\()?["']tailwindcss(?:\/[^"']*)?["']\)?/u.test(code) ||
|
|
23
|
+
/@tailwind\s+(?:base|components|utilities)\b/u.test(code)
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function tailwindSourceDirective(cssDir: string, sourceDir: string): string {
|
|
28
|
+
const relativeSourceDir = relative(cssDir, sourceDir).split(sep).join("/");
|
|
29
|
+
const normalizedSourceDir =
|
|
30
|
+
relativeSourceDir === ""
|
|
31
|
+
? "."
|
|
32
|
+
: relativeSourceDir.startsWith(".")
|
|
33
|
+
? relativeSourceDir
|
|
34
|
+
: `./${relativeSourceDir}`;
|
|
35
|
+
|
|
36
|
+
return `@source ${JSON.stringify(`${normalizedSourceDir}/**/*.{js,jsx,ts,tsx,mdx}`)};`;
|
|
37
|
+
}
|
package/src/typed-routes.ts
CHANGED
|
@@ -6,9 +6,12 @@ export type RouteSearchParams = Record<
|
|
|
6
6
|
|
|
7
7
|
export type RouteParamsFor<Path extends `/${string}`> = Simplify<ExtractRouteParams<Path>>;
|
|
8
8
|
|
|
9
|
-
export type AppRouteHref<Path extends `/${string}`> =
|
|
10
|
-
? (options
|
|
11
|
-
: (options
|
|
9
|
+
export type AppRouteHref<Path extends `/${string}`> = keyof RouteParamsFor<Path> extends never
|
|
10
|
+
? (options?: StaticHrefOptions) => string
|
|
11
|
+
: (options: DynamicHrefOptions<Path>) => string;
|
|
12
|
+
|
|
13
|
+
export type AppRouteLinkHref<Path extends `/${string}`> =
|
|
14
|
+
`${AppRouteLinkPathname<Path>}${AppRouteLinkHrefSuffix}`;
|
|
12
15
|
|
|
13
16
|
export interface StaticHrefOptions {
|
|
14
17
|
hash?: string | undefined;
|
|
@@ -35,6 +38,22 @@ type SegmentRouteParam<Segment extends string> = Segment extends `:...${infer Na
|
|
|
35
38
|
|
|
36
39
|
type Simplify<T> = { [Key in keyof T]: T[Key] } & {};
|
|
37
40
|
|
|
41
|
+
export type AppRouteLinkHrefSuffix = "" | `?${string}` | `#${string}` | `?${string}#${string}`;
|
|
42
|
+
|
|
43
|
+
export type AppRouteLinkPathname<Path extends `/${string}`> = Path extends "/"
|
|
44
|
+
? "/"
|
|
45
|
+
: Path extends `/${infer Segments}`
|
|
46
|
+
? `/${AppRouteLinkSegments<Segments>}`
|
|
47
|
+
: never;
|
|
48
|
+
|
|
49
|
+
export type AppRouteLinkSegments<Segments extends string> = Segments extends `${infer Segment}/${infer Rest}`
|
|
50
|
+
? `${AppRouteLinkSegment<Segment>}/${AppRouteLinkSegments<Rest>}`
|
|
51
|
+
: AppRouteLinkSegment<Segments>;
|
|
52
|
+
|
|
53
|
+
export type AppRouteLinkSegment<Segment extends string> = Segment extends `:${string}`
|
|
54
|
+
? string
|
|
55
|
+
: Segment;
|
|
56
|
+
|
|
38
57
|
export function href<const Path extends `/${string}`>(
|
|
39
58
|
path: Path,
|
|
40
59
|
...args: HasRouteParams<Path> extends true
|
package/src/vite.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import type { ServerResponse } from "node:http";
|
|
3
|
-
import { dirname
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
4
|
import { formatDiagnostic } from "@reckona/mreact-compiler";
|
|
5
5
|
import {
|
|
6
6
|
createCompilerModuleContext,
|
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
import { createRouteMatcher, scanAppRoutes, type AppRoute } from "./routes.js";
|
|
50
50
|
import { resolveRequestHost, type RequestHostPolicy } from "./serve.js";
|
|
51
51
|
import { hasJsxSyntax } from "./source-jsx.js";
|
|
52
|
+
import { prependTailwindSourceDirectives } from "./tailwind-source.js";
|
|
52
53
|
import { workspacePackageFile } from "./workspace-packages.js";
|
|
53
54
|
|
|
54
55
|
export interface AppRouterViteMiddlewareOptions extends AppRouterProjectOptions {
|
|
@@ -743,49 +744,13 @@ async function loadDevCssSourceModule(options: {
|
|
|
743
744
|
}): Promise<string | undefined> {
|
|
744
745
|
const code = await readFile(options.cssFile, "utf8");
|
|
745
746
|
|
|
746
|
-
return
|
|
747
|
+
return prependTailwindSourceDirectives({
|
|
747
748
|
code,
|
|
748
749
|
cssFile: options.cssFile,
|
|
749
750
|
sourceDirs: options.sourceDirs,
|
|
750
751
|
});
|
|
751
752
|
}
|
|
752
753
|
|
|
753
|
-
function prependDevTailwindSourceDirectives(options: {
|
|
754
|
-
code: string;
|
|
755
|
-
cssFile: string;
|
|
756
|
-
sourceDirs: readonly string[];
|
|
757
|
-
}): string {
|
|
758
|
-
if (!isTailwindCssEntry(options.code)) {
|
|
759
|
-
return options.code;
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
const cssDir = dirname(options.cssFile);
|
|
763
|
-
const directives = [...new Set(options.sourceDirs)]
|
|
764
|
-
.map((sourceDir) => `${devTailwindSourceDirective(cssDir, sourceDir)}\n`)
|
|
765
|
-
.join("");
|
|
766
|
-
|
|
767
|
-
return directives.length === 0 ? options.code : `${directives}${options.code}`;
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
function isTailwindCssEntry(code: string): boolean {
|
|
771
|
-
return (
|
|
772
|
-
/@import\s+(?:url\()?["']tailwindcss(?:\/[^"']*)?["']\)?/u.test(code) ||
|
|
773
|
-
/@tailwind\s+(?:base|components|utilities)\b/u.test(code)
|
|
774
|
-
);
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
function devTailwindSourceDirective(cssDir: string, sourceDir: string): string {
|
|
778
|
-
const relativeSourceDir = relative(cssDir, sourceDir).split(sep).join("/");
|
|
779
|
-
const normalizedSourceDir =
|
|
780
|
-
relativeSourceDir === ""
|
|
781
|
-
? "."
|
|
782
|
-
: relativeSourceDir.startsWith(".")
|
|
783
|
-
? relativeSourceDir
|
|
784
|
-
: `./${relativeSourceDir}`;
|
|
785
|
-
|
|
786
|
-
return `@source ${JSON.stringify(`${normalizedSourceDir}/**/*.{js,jsx,ts,tsx,mdx}`)};`;
|
|
787
|
-
}
|
|
788
|
-
|
|
789
754
|
function importerInRuntimePackage(
|
|
790
755
|
importer: string | undefined,
|
|
791
756
|
directories: readonly string[],
|