@reckona/mreact-router 0.0.88 → 0.0.90
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 +5 -6
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +6 -2
- package/dist/build.js.map +1 -1
- package/dist/bundle-pipeline.d.ts +2 -0
- package/dist/bundle-pipeline.d.ts.map +1 -1
- package/dist/bundle-pipeline.js +7 -0
- package/dist/bundle-pipeline.js.map +1 -1
- package/dist/client.d.ts +5 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +133 -3
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +7 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +36 -3
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/src/build.ts +10 -2
- package/src/bundle-pipeline.ts +12 -0
- package/src/client.ts +141 -3
- package/src/config.ts +57 -3
- package/src/index.ts +2 -0
package/src/config.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { isAbsolute, relative, resolve } from "node:path";
|
|
1
|
+
import { basename, dirname, isAbsolute, relative, resolve } from "node:path";
|
|
2
2
|
|
|
3
3
|
export type AppRouterBuildTarget = "node" | "cloudflare" | "aws-lambda";
|
|
4
|
+
export type AppRouterClientConsoleMethod = "debug" | "error" | "info" | "log" | "trace" | "warn";
|
|
4
5
|
export type AppRouterClientSourceMapMode = "none" | "hidden" | "linked";
|
|
5
6
|
export type AppRouterClientSourceMapOption = boolean | AppRouterClientSourceMapMode;
|
|
6
7
|
|
|
8
|
+
export interface AppRouterProductionOptions {
|
|
9
|
+
dropClientConsole?: boolean | readonly AppRouterClientConsoleMethod[] | undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
export interface AppRouterProjectOptions {
|
|
8
13
|
assetBaseUrl?: string | undefined;
|
|
9
14
|
buildTargets?: readonly AppRouterBuildTarget[] | undefined;
|
|
@@ -19,6 +24,7 @@ export interface AppRouterProjectOptions {
|
|
|
19
24
|
appDir?: string | undefined;
|
|
20
25
|
allowedSourceDirs?: readonly string[] | undefined;
|
|
21
26
|
projectRoot?: string | undefined;
|
|
27
|
+
production?: AppRouterProductionOptions | undefined;
|
|
22
28
|
publicDir?: string | undefined;
|
|
23
29
|
publicAssetBaseUrl?: string | undefined;
|
|
24
30
|
routesDir?: string | undefined;
|
|
@@ -29,6 +35,7 @@ export interface ResolvedAppRouterProject {
|
|
|
29
35
|
assetBaseUrl?: string | undefined;
|
|
30
36
|
buildTargets: readonly AppRouterBuildTarget[];
|
|
31
37
|
clientSourceMaps: AppRouterClientSourceMapMode;
|
|
38
|
+
clientConsolePureFunctions?: readonly string[] | undefined;
|
|
32
39
|
projectRoot: string;
|
|
33
40
|
publicAssetBaseUrl?: string | undefined;
|
|
34
41
|
publicDir: string;
|
|
@@ -38,6 +45,10 @@ export interface ResolvedAppRouterProject {
|
|
|
38
45
|
export function resolveAppRouterProjectOptions(
|
|
39
46
|
options: AppRouterProjectOptions,
|
|
40
47
|
): ResolvedAppRouterProject {
|
|
48
|
+
const clientConsolePureFunctions = resolveClientConsolePureFunctions(
|
|
49
|
+
options.production?.dropClientConsole,
|
|
50
|
+
);
|
|
51
|
+
|
|
41
52
|
if (
|
|
42
53
|
options.appDir !== undefined &&
|
|
43
54
|
options.projectRoot === undefined &&
|
|
@@ -52,6 +63,7 @@ export function resolveAppRouterProjectOptions(
|
|
|
52
63
|
...(options.assetBaseUrl === undefined ? {} : { assetBaseUrl: options.assetBaseUrl }),
|
|
53
64
|
buildTargets: resolveBuildTargets(options.buildTargets),
|
|
54
65
|
clientSourceMaps: resolveClientSourceMapMode(options.clientSourceMaps),
|
|
66
|
+
...(clientConsolePureFunctions === undefined ? {} : { clientConsolePureFunctions }),
|
|
55
67
|
projectRoot: appDir,
|
|
56
68
|
...(options.publicAssetBaseUrl === undefined
|
|
57
69
|
? {}
|
|
@@ -62,23 +74,65 @@ export function resolveAppRouterProjectOptions(
|
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
const projectRoot = resolve(options.projectRoot ?? process.cwd());
|
|
77
|
+
const routesDir = resolveProjectPath(projectRoot, options.routesDir ?? "src/app", "routesDir");
|
|
78
|
+
const defaultAllowedSourceDirs =
|
|
79
|
+
options.routesDir === undefined ? ["src"] : [defaultAllowedSourceDir(projectRoot, routesDir)];
|
|
65
80
|
|
|
66
81
|
return {
|
|
67
|
-
allowedSourceDirs: (options.allowedSourceDirs ??
|
|
82
|
+
allowedSourceDirs: (options.allowedSourceDirs ?? defaultAllowedSourceDirs).map((directory) =>
|
|
68
83
|
resolveProjectPath(projectRoot, directory, "allowedSourceDirs"),
|
|
69
84
|
),
|
|
70
85
|
...(options.assetBaseUrl === undefined ? {} : { assetBaseUrl: options.assetBaseUrl }),
|
|
71
86
|
buildTargets: resolveBuildTargets(options.buildTargets),
|
|
72
87
|
clientSourceMaps: resolveClientSourceMapMode(options.clientSourceMaps),
|
|
88
|
+
...(clientConsolePureFunctions === undefined ? {} : { clientConsolePureFunctions }),
|
|
73
89
|
projectRoot,
|
|
74
90
|
...(options.publicAssetBaseUrl === undefined
|
|
75
91
|
? {}
|
|
76
92
|
: { publicAssetBaseUrl: options.publicAssetBaseUrl }),
|
|
77
93
|
publicDir: resolveProjectPath(projectRoot, options.publicDir ?? "public", "publicDir"),
|
|
78
|
-
routesDir
|
|
94
|
+
routesDir,
|
|
79
95
|
};
|
|
80
96
|
}
|
|
81
97
|
|
|
98
|
+
function defaultAllowedSourceDir(projectRoot: string, routesDir: string): string {
|
|
99
|
+
const sourceRoot = dirname(routesDir);
|
|
100
|
+
return basename(routesDir) === "app" && sourceRoot !== projectRoot ? sourceRoot : routesDir;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const defaultDroppedClientConsoleMethods = ["debug", "info", "log"] as const;
|
|
104
|
+
const supportedClientConsoleMethods = new Set<AppRouterClientConsoleMethod>([
|
|
105
|
+
"debug",
|
|
106
|
+
"error",
|
|
107
|
+
"info",
|
|
108
|
+
"log",
|
|
109
|
+
"trace",
|
|
110
|
+
"warn",
|
|
111
|
+
]);
|
|
112
|
+
|
|
113
|
+
export function resolveClientConsolePureFunctions(
|
|
114
|
+
value: AppRouterProductionOptions["dropClientConsole"],
|
|
115
|
+
): readonly string[] | undefined {
|
|
116
|
+
if (value === undefined || value === false) {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const methods = value === true ? defaultDroppedClientConsoleMethods : value;
|
|
121
|
+
const uniqueMethods = [...new Set(methods)];
|
|
122
|
+
|
|
123
|
+
for (const method of uniqueMethods) {
|
|
124
|
+
if (!supportedClientConsoleMethods.has(method)) {
|
|
125
|
+
throw new Error(
|
|
126
|
+
`Unsupported mreactRouter production.dropClientConsole method ${JSON.stringify(method)}. Expected "debug", "error", "info", "log", "trace", or "warn".`,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return uniqueMethods.length === 0
|
|
132
|
+
? undefined
|
|
133
|
+
: uniqueMethods.map((method) => `console.${method}`);
|
|
134
|
+
}
|
|
135
|
+
|
|
82
136
|
export function resolveClientSourceMapMode(
|
|
83
137
|
value: AppRouterClientSourceMapOption | undefined,
|
|
84
138
|
): AppRouterClientSourceMapMode {
|
package/src/index.ts
CHANGED
|
@@ -105,8 +105,10 @@ export type {
|
|
|
105
105
|
} from "./types.js";
|
|
106
106
|
export type {
|
|
107
107
|
AppRouterBuildTarget,
|
|
108
|
+
AppRouterClientConsoleMethod,
|
|
108
109
|
AppRouterClientSourceMapMode,
|
|
109
110
|
AppRouterClientSourceMapOption,
|
|
111
|
+
AppRouterProductionOptions,
|
|
110
112
|
} from "./config.js";
|
|
111
113
|
export type {
|
|
112
114
|
AssetHelperOptions,
|