@reckona/mreact-router 0.0.151 → 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.
@@ -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/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, relative, sep } from "node:path";
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 prependDevTailwindSourceDirectives({
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[],