@rainfw/core 0.2.5 → 0.2.6
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/package.json +9 -1
- package/scripts/generate.js +31 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rainfw/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "A TypeScript web framework for Cloudflare Workers",
|
|
5
5
|
"bin": {
|
|
6
6
|
"rainjs": "./cli/index.js"
|
|
@@ -62,6 +62,14 @@
|
|
|
62
62
|
"./client": {
|
|
63
63
|
"types": "./dist/client/hooks.d.ts",
|
|
64
64
|
"import": "./dist/client/hooks.js"
|
|
65
|
+
},
|
|
66
|
+
"./client/runtime": {
|
|
67
|
+
"types": "./dist/client/runtime.d.ts",
|
|
68
|
+
"import": "./dist/client/runtime.js"
|
|
69
|
+
},
|
|
70
|
+
"./client/jsx-runtime": {
|
|
71
|
+
"types": "./dist/client/jsx-runtime.d.ts",
|
|
72
|
+
"import": "./dist/client/jsx-runtime.js"
|
|
65
73
|
}
|
|
66
74
|
},
|
|
67
75
|
"devDependencies": {
|
package/scripts/generate.js
CHANGED
|
@@ -244,12 +244,20 @@ function buildIslandImportLines(index, file, srcDir, entryDir) {
|
|
|
244
244
|
return lines;
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
function
|
|
247
|
+
function resolveClientRuntimeImport(fwPkg) {
|
|
248
|
+
if (fwPkg.startsWith(".") || fwPkg.startsWith("/")) {
|
|
249
|
+
const entryDir = path.join(PROJECT_ROOT, BUILD_CONFIG.outDir);
|
|
250
|
+
const runtimePath = path
|
|
251
|
+
.relative(entryDir, path.join(PROJECT_ROOT, fwPkg, "client/runtime"))
|
|
252
|
+
.replace(/\\/g, "/");
|
|
253
|
+
return ensureRelativeImport(runtimePath);
|
|
254
|
+
}
|
|
255
|
+
return `${fwPkg}/client/runtime`;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function generateClientEntrySource(clientFiles, srcDir, fwPkg) {
|
|
248
259
|
const entryDir = path.join(PROJECT_ROOT, BUILD_CONFIG.outDir);
|
|
249
|
-
const
|
|
250
|
-
.relative(entryDir, path.join(PROJECT_ROOT, "src/framework/client/runtime"))
|
|
251
|
-
.replace(/\\/g, "/");
|
|
252
|
-
const runtimeImport = ensureRelativeImport(runtimePath);
|
|
260
|
+
const runtimeImport = resolveClientRuntimeImport(fwPkg);
|
|
253
261
|
|
|
254
262
|
const lines = [];
|
|
255
263
|
lines.push(
|
|
@@ -266,7 +274,19 @@ function generateClientEntrySource(clientFiles, srcDir) {
|
|
|
266
274
|
return lines.join("\n");
|
|
267
275
|
}
|
|
268
276
|
|
|
269
|
-
function
|
|
277
|
+
function buildClientEsbuildAliases(fwPkg) {
|
|
278
|
+
if (fwPkg.startsWith(".") || fwPkg.startsWith("/")) {
|
|
279
|
+
const clientDir = path.resolve(PROJECT_ROOT, fwPkg, "client");
|
|
280
|
+
return {
|
|
281
|
+
"@rainfw/core/jsx-runtime": path.join(clientDir, "jsx-runtime.ts"),
|
|
282
|
+
"@rainfw/core/client/runtime": path.join(clientDir, "runtime.ts"),
|
|
283
|
+
"@rainfw/core/client/jsx-runtime": path.join(clientDir, "jsx-runtime.ts"),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
return {};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function bundleClientFilesSync(clientFiles, srcDir, fwPkg) {
|
|
270
290
|
if (clientFiles.length === 0) return [];
|
|
271
291
|
if (!esbuild) {
|
|
272
292
|
console.warn(
|
|
@@ -288,7 +308,7 @@ function bundleClientFilesSync(clientFiles, srcDir) {
|
|
|
288
308
|
}
|
|
289
309
|
}
|
|
290
310
|
|
|
291
|
-
const entrySource = generateClientEntrySource(clientFiles, srcDir);
|
|
311
|
+
const entrySource = generateClientEntrySource(clientFiles, srcDir, fwPkg);
|
|
292
312
|
const entryDir = path.join(PROJECT_ROOT, BUILD_CONFIG.outDir);
|
|
293
313
|
if (!fs.existsSync(entryDir)) {
|
|
294
314
|
fs.mkdirSync(entryDir, { recursive: true });
|
|
@@ -310,12 +330,7 @@ function bundleClientFilesSync(clientFiles, srcDir) {
|
|
|
310
330
|
target: ["es2022"],
|
|
311
331
|
jsx: "automatic",
|
|
312
332
|
jsxImportSource: "@rainfw/core",
|
|
313
|
-
alias:
|
|
314
|
-
"@rainfw/core/jsx-runtime": path.resolve(
|
|
315
|
-
PROJECT_ROOT,
|
|
316
|
-
"src/framework/client/jsx-runtime.ts",
|
|
317
|
-
),
|
|
318
|
-
},
|
|
333
|
+
alias: buildClientEsbuildAliases(fwPkg),
|
|
319
334
|
loader: { ".ts": "ts", ".tsx": "tsx" },
|
|
320
335
|
});
|
|
321
336
|
|
|
@@ -875,7 +890,8 @@ function buildAppInitLine(clientScripts, hasConfig) {
|
|
|
875
890
|
function regenerateClient() {
|
|
876
891
|
const srcDir = path.join(PROJECT_ROOT, "src");
|
|
877
892
|
const clientFiles = getClientFiles(srcDir);
|
|
878
|
-
const
|
|
893
|
+
const fwPkg = BUILD_CONFIG.frameworkPackage;
|
|
894
|
+
const clientScripts = bundleClientFilesSync(clientFiles, srcDir, fwPkg);
|
|
879
895
|
|
|
880
896
|
if (!fs.existsSync(ENTRY_FILE)) return;
|
|
881
897
|
|
|
@@ -1111,10 +1127,9 @@ function generate() {
|
|
|
1111
1127
|
|
|
1112
1128
|
const srcDir = path.join(PROJECT_ROOT, "src");
|
|
1113
1129
|
const clientFiles = getClientFiles(srcDir);
|
|
1114
|
-
const clientScripts = bundleClientFilesSync(clientFiles, srcDir);
|
|
1115
|
-
|
|
1116
1130
|
const hasConfig = fs.existsSync(CONFIG_FILE);
|
|
1117
1131
|
const fwPkg = BUILD_CONFIG.frameworkPackage;
|
|
1132
|
+
const clientScripts = bundleClientFilesSync(clientFiles, srcDir, fwPkg);
|
|
1118
1133
|
const frameworkImport =
|
|
1119
1134
|
fwPkg.startsWith(".") || fwPkg.startsWith("/")
|
|
1120
1135
|
? relativeImportPath(path.join(PROJECT_ROOT, fwPkg))
|