@anaemia/bundler 0.3.5 → 0.3.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,MAAM,cAAc,CAAC;AAGrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAqB1D,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,aAAkB,GAAG,OAAO,CAAC,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,CAwI1H;AAED,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,MAAM,cAAc,CAAC;AAGrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAqB1D,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,aAAkB,GAAG,OAAO,CAAC,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,CAuK1H;AAED,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ const __filename = fileURLToPath(import.meta.url);
18
18
  const __dirname = path.dirname(__filename);
19
19
  export async function getRspackConfig(appRoot, config = {}) {
20
20
  const isDev = process.env.NODE_ENV !== "production";
21
+ const rawEnv = process.env;
21
22
  const coreRuntimeDir = path.dirname(require.resolve("@anaemia/core/package.json"));
22
23
  const runtimeDir = path.resolve(coreRuntimeDir, "./dist/runtime");
23
24
  const routes = await scanRoutes(appRoot);
@@ -33,6 +34,25 @@ export async function getRspackConfig(appRoot, config = {}) {
33
34
  const extraClientBabelPlugins = config.plugins?.flatMap((p) => p.babelPlugins?.client ?? []) ?? [];
34
35
  const extraServerBabelPlugins = config.plugins?.flatMap((p) => p.babelPlugins?.server ?? []) ?? [];
35
36
  const solidRefreshPlugin = [require.resolve("solid-refresh/babel"), { bundler: "rspack-esm", jsx: false }];
37
+ // env processing
38
+ const serverEnv = {
39
+ MODE: JSON.stringify(process.env.NODE_ENV || "development"),
40
+ DEV: JSON.stringify(isDev),
41
+ PROD: JSON.stringify(!isDev),
42
+ };
43
+ for (const key in rawEnv) {
44
+ serverEnv[key] = JSON.stringify(rawEnv[key]);
45
+ }
46
+ const clientEnv = {
47
+ MODE: JSON.stringify(process.env.NODE_ENV || "development"),
48
+ DEV: JSON.stringify(isDev),
49
+ PROD: JSON.stringify(!isDev),
50
+ };
51
+ for (const key in rawEnv) {
52
+ if (key.startsWith("PUBLIC_")) {
53
+ clientEnv[key] = JSON.stringify(rawEnv[key]);
54
+ }
55
+ }
36
56
  const sharedResolve = {
37
57
  extensions: [".tsx", ".ts", ".jsx", ".js", ".json", ".scss", ".css"],
38
58
  extensionAlias: { ".js": [".ts", ".js"], ".jsx": [".tsx", ".jsx"] },
@@ -81,6 +101,7 @@ export async function getRspackConfig(appRoot, config = {}) {
81
101
  new rspack.DefinePlugin({
82
102
  __ANAEMIA_RUNTIME_CONFIG__: JSON.stringify({ port: config.port, assets: config.assets, styles: config.styles }),
83
103
  ...config.define?.client,
104
+ "import.meta.env": clientEnv,
84
105
  }),
85
106
  new rspack.NormalModuleReplacementPlugin(/^node:/, (resource) => {
86
107
  resource.request = resource.request.replace(/^node:/, "");
@@ -99,7 +120,13 @@ export async function getRspackConfig(appRoot, config = {}) {
99
120
  styleRules.client,
100
121
  {
101
122
  ...createBabelRule({ isServer: false, isDev, plugins: [clientServerFnTransform, ...(isDev ? [solidRefreshPlugin] : []), ...extraClientBabelPlugins] }),
102
- exclude: /[\\/]node_modules[\\/](?!@anaemia[\\/]core|@solidjs[\\/]router)/,
123
+ exclude: (modulePath) => {
124
+ if (modulePath.includes("@anaemia") && modulePath.includes("core"))
125
+ return false;
126
+ if (modulePath.includes("@solidjs") && modulePath.includes("router"))
127
+ return false;
128
+ return modulePath.includes("node_modules");
129
+ },
103
130
  },
104
131
  ],
105
132
  },
@@ -124,14 +151,20 @@ export async function getRspackConfig(appRoot, config = {}) {
124
151
  __anaemia_server_routes__: serverRoutesFile,
125
152
  },
126
153
  },
127
- plugins: [new rspack.DefinePlugin({ ...config.define?.server })],
154
+ plugins: [new rspack.DefinePlugin({ ...config.define?.server, "import.meta.env": serverEnv })],
128
155
  module: {
129
156
  parser: { "css/auto": { namedExports: false } },
130
157
  rules: [
131
158
  styleRules.server,
132
159
  {
133
160
  ...createBabelRule({ isServer: true, isDev, plugins: [serverHashInjector, ...extraServerBabelPlugins] }),
134
- exclude: /[\\/]node_modules[\\/](?!@anaemia[\\/]core|@solidjs[\\/]router)/,
161
+ exclude: (modulePath) => {
162
+ if (modulePath.includes("@anaemia") && modulePath.includes("core"))
163
+ return false;
164
+ if (modulePath.includes("@solidjs") && modulePath.includes("router"))
165
+ return false;
166
+ return modulePath.includes("node_modules");
167
+ },
135
168
  },
136
169
  ],
137
170
  },
@@ -1 +1 @@
1
- {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/router/scan.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,mBAAmB,EAAE,CAAC;IAC/B,MAAM,EA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,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAiE/E"}
@@ -14,10 +14,13 @@ const CATCH_ALL_FILE = /^\[\.\.\.(.+?)\]\.(tsx|jsx)$/;
14
14
  const DYNAMIC_SEGMENT = /^\[(.+?)\]\.(tsx|jsx)$/;
15
15
  export function scanServerRoutes(appRoot) {
16
16
  const routesDir = path.resolve(appRoot, "./src/routes");
17
- const files = glob.sync("**/_route.{ts,tsx}", { cwd: routesDir, posix: true });
17
+ const files = glob.sync("**/_route.{ts,tsx,js,jsx}", { cwd: routesDir, posix: true });
18
18
  return files.map((file) => {
19
19
  const dir = path.dirname(file);
20
- const urlPattern = dir === "." ? "/" : `/${dir}`;
20
+ const normalizedDir = dir
21
+ .replace(/\[\.\.\.(.+?)\]/g, "*")
22
+ .replace(/\[(.+?)\]/g, ":$1");
23
+ const urlPattern = normalizedDir === "." ? "/" : `/${normalizedDir}`;
21
24
  return {
22
25
  urlPattern,
23
26
  filePath: path.resolve(routesDir, file),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anaemia/bundler",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",
@@ -11,7 +11,7 @@
11
11
  }
12
12
  },
13
13
  "dependencies": {
14
- "@anaemia/core": "^0.3.5",
14
+ "@anaemia/core": "^0.3.7",
15
15
  "@babel/core": "^7.29.7",
16
16
  "@babel/preset-typescript": "^7.29.7",
17
17
  "@rspack/core": "^2.0.5",
package/src/index.ts CHANGED
@@ -24,6 +24,7 @@ const __dirname = path.dirname(__filename);
24
24
 
25
25
  export async function getRspackConfig(appRoot: string, config: AnaemiaConfig = {}): Promise<[Configuration, Configuration]> {
26
26
  const isDev = process.env.NODE_ENV !== "production";
27
+ const rawEnv = process.env;
27
28
  const coreRuntimeDir = path.dirname(require.resolve("@anaemia/core/package.json"));
28
29
  const runtimeDir = path.resolve(coreRuntimeDir, "./dist/runtime");
29
30
 
@@ -43,6 +44,27 @@ export async function getRspackConfig(appRoot: string, config: AnaemiaConfig = {
43
44
  const extraServerBabelPlugins = config.plugins?.flatMap((p) => p.babelPlugins?.server ?? []) ?? [];
44
45
  const solidRefreshPlugin = [require.resolve("solid-refresh/babel"), { bundler: "rspack-esm", jsx: false }];
45
46
 
47
+ // env processing
48
+ const serverEnv: Record<string, string> = {
49
+ MODE: JSON.stringify(process.env.NODE_ENV || "development"),
50
+ DEV: JSON.stringify(isDev),
51
+ PROD: JSON.stringify(!isDev),
52
+ };
53
+ for (const key in rawEnv) {
54
+ serverEnv[key] = JSON.stringify(rawEnv[key]);
55
+ }
56
+
57
+ const clientEnv: Record<string, string> = {
58
+ MODE: JSON.stringify(process.env.NODE_ENV || "development"),
59
+ DEV: JSON.stringify(isDev),
60
+ PROD: JSON.stringify(!isDev),
61
+ };
62
+ for (const key in rawEnv) {
63
+ if (key.startsWith("PUBLIC_")) {
64
+ clientEnv[key] = JSON.stringify(rawEnv[key]);
65
+ }
66
+ }
67
+
46
68
  const sharedResolve = {
47
69
  extensions: [".tsx", ".ts", ".jsx", ".js", ".json", ".scss", ".css"],
48
70
  extensionAlias: { ".js": [".ts", ".js"], ".jsx": [".tsx", ".jsx"] },
@@ -92,6 +114,7 @@ export async function getRspackConfig(appRoot: string, config: AnaemiaConfig = {
92
114
  new rspack.DefinePlugin({
93
115
  __ANAEMIA_RUNTIME_CONFIG__: JSON.stringify({ port: config.port, assets: config.assets, styles: config.styles }),
94
116
  ...config.define?.client,
117
+ "import.meta.env": clientEnv,
95
118
  }),
96
119
  new rspack.NormalModuleReplacementPlugin(/^node:/, (resource) => {
97
120
  resource.request = resource.request.replace(/^node:/, "");
@@ -113,7 +136,11 @@ export async function getRspackConfig(appRoot: string, config: AnaemiaConfig = {
113
136
  styleRules.client,
114
137
  {
115
138
  ...createBabelRule({ isServer: false, isDev, plugins: [clientServerFnTransform, ...(isDev ? [solidRefreshPlugin] : []), ...extraClientBabelPlugins] }),
116
- exclude: /[\\/]node_modules[\\/](?!@anaemia[\\/]core|@solidjs[\\/]router)/,
139
+ exclude: (modulePath: string) => {
140
+ if (modulePath.includes("@anaemia") && modulePath.includes("core")) return false;
141
+ if (modulePath.includes("@solidjs") && modulePath.includes("router")) return false;
142
+ return modulePath.includes("node_modules");
143
+ },
117
144
  },
118
145
  ],
119
146
  },
@@ -139,14 +166,18 @@ export async function getRspackConfig(appRoot: string, config: AnaemiaConfig = {
139
166
  __anaemia_server_routes__: serverRoutesFile,
140
167
  },
141
168
  },
142
- plugins: [new rspack.DefinePlugin({ ...config.define?.server })],
169
+ plugins: [new rspack.DefinePlugin({ ...config.define?.server, "import.meta.env": serverEnv })],
143
170
  module: {
144
171
  parser: { "css/auto": { namedExports: false } },
145
172
  rules: [
146
173
  styleRules.server,
147
174
  {
148
175
  ...createBabelRule({ isServer: true, isDev, plugins: [serverHashInjector, ...extraServerBabelPlugins] }),
149
- exclude: /[\\/]node_modules[\\/](?!@anaemia[\\/]core|@solidjs[\\/]router)/,
176
+ exclude: (modulePath: string) => {
177
+ if (modulePath.includes("@anaemia") && modulePath.includes("core")) return false;
178
+ if (modulePath.includes("@solidjs") && modulePath.includes("router")) return false;
179
+ return modulePath.includes("node_modules");
180
+ },
150
181
  },
151
182
  ],
152
183
  },
@@ -50,11 +50,17 @@ const DYNAMIC_SEGMENT = /^\[(.+?)\]\.(tsx|jsx)$/;
50
50
 
51
51
  export function scanServerRoutes(appRoot: string): ServerRouteEntry[] {
52
52
  const routesDir = path.resolve(appRoot, "./src/routes");
53
- const files = glob.sync("**/_route.{ts,tsx}", { cwd: routesDir, posix: true });
54
-
53
+ const files = glob.sync("**/_route.{ts,tsx,js,jsx}", { cwd: routesDir, posix: true });
54
+
55
55
  return files.map((file) => {
56
56
  const dir = path.dirname(file);
57
- const urlPattern = dir === "." ? "/" : `/${dir}`;
57
+
58
+ const normalizedDir = dir
59
+ .replace(/\[\.\.\.(.+?)\]/g, "*")
60
+ .replace(/\[(.+?)\]/g, ":$1");
61
+
62
+ const urlPattern = normalizedDir === "." ? "/" : `/${normalizedDir}`;
63
+
58
64
  return {
59
65
  urlPattern,
60
66
  filePath: path.resolve(routesDir, file),