arri 0.12.8 → 0.13.0
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/dist/cli.cjs +92 -130
- package/dist/cli.mjs +92 -130
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/shared/{arri.fa32b1ba.cjs → arri.165b8604.cjs} +2 -2
- package/dist/shared/{arri.4d91d9b0.mjs → arri.cc0da87a.mjs} +2 -2
- package/package.json +10 -9
package/dist/cli.cjs
CHANGED
|
@@ -9,9 +9,10 @@ const arriCodegenUtils = require('arri-codegen-utils');
|
|
|
9
9
|
const c12 = require('c12');
|
|
10
10
|
const consola = require('consola');
|
|
11
11
|
const esbuild = require('esbuild');
|
|
12
|
+
const esbuildPluginReplace = require('esbuild-plugin-replace');
|
|
12
13
|
const path = require('pathe');
|
|
13
14
|
const prettier = require('prettier');
|
|
14
|
-
const config = require('./shared/arri.
|
|
15
|
+
const config = require('./shared/arri.165b8604.cjs');
|
|
15
16
|
const globby = require('globby');
|
|
16
17
|
const scule = require('scule');
|
|
17
18
|
const arriCodegenDart = require('arri-codegen-dart');
|
|
@@ -45,10 +46,11 @@ const prettier__default = /*#__PURE__*/_interopDefaultCompat(prettier);
|
|
|
45
46
|
const chokidar__default = /*#__PURE__*/_interopDefaultCompat(chokidar);
|
|
46
47
|
const Degit__default = /*#__PURE__*/_interopDefaultCompat(Degit);
|
|
47
48
|
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
49
|
+
const GEN_APP_FILE = "__arri_app.js";
|
|
50
|
+
const GEN_SERVER_ENTRY_FILE = "__arri_server.js";
|
|
51
|
+
const OUT_APP_FILE = "app.js";
|
|
52
|
+
const OUT_SERVER_ENTRY = "server.js";
|
|
53
|
+
const OUT_CODEGEN = "codegen.js";
|
|
52
54
|
async function setupWorkingDir(config) {
|
|
53
55
|
const arriDir = path__default.resolve(config.rootDir, config.buildDir);
|
|
54
56
|
const outDir = path__default.resolve(config.rootDir, ".output");
|
|
@@ -61,12 +63,15 @@ async function setupWorkingDir(config) {
|
|
|
61
63
|
await fs__default.mkdir(arriDir);
|
|
62
64
|
await fs__default.mkdir(outDir);
|
|
63
65
|
}
|
|
64
|
-
async function
|
|
66
|
+
async function createAppWithRoutesModule(config) {
|
|
67
|
+
const appModule = path__default.resolve(config.rootDir, config.srcDir, config.entry);
|
|
68
|
+
const appImportParts = path__default.relative(path__default.resolve(config.rootDir, config.srcDir), appModule).split(".");
|
|
69
|
+
appImportParts.pop();
|
|
65
70
|
const routes = [];
|
|
66
71
|
const existingRoutes = [];
|
|
67
72
|
await Promise.all(
|
|
68
73
|
config.procedureGlobPatterns.map(async (pattern) => {
|
|
69
|
-
const results = await
|
|
74
|
+
const results = await getFsRouteBatch(pattern, config);
|
|
70
75
|
for (const result of results) {
|
|
71
76
|
if (!existingRoutes.includes(result.name)) {
|
|
72
77
|
routes.push(result);
|
|
@@ -77,22 +82,33 @@ async function createRoutesModule(config) {
|
|
|
77
82
|
);
|
|
78
83
|
routes.sort((a, b) => a.name < b.name ? -1 : 1);
|
|
79
84
|
const module = await prettier__default.format(
|
|
80
|
-
|
|
85
|
+
`import app from './${appImportParts.join(".")}';
|
|
86
|
+
${routes.map(
|
|
81
87
|
(route) => `import ${route.importName} from '${route.importPath}';`
|
|
82
88
|
).join("\n")}
|
|
83
89
|
const routes = [${routes.map(
|
|
84
90
|
(route) => `{ id: '${route.name}', route: ${route.importName} }`
|
|
85
91
|
).join(",\n")}
|
|
86
92
|
];
|
|
87
|
-
|
|
93
|
+
for(const route of routes) {
|
|
94
|
+
app.rpc({
|
|
95
|
+
name: route.id,
|
|
96
|
+
method: route.route.method,
|
|
97
|
+
params: route.route.params,
|
|
98
|
+
response: route.route.response,
|
|
99
|
+
handler: route.route.handler,
|
|
100
|
+
postHandler: route.route.postHandler,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
export default app`,
|
|
88
104
|
{ parser: "typescript", tabWidth: 4 }
|
|
89
105
|
);
|
|
90
106
|
await fs__default.writeFile(
|
|
91
|
-
path__default.resolve(config.rootDir, config.buildDir,
|
|
107
|
+
path__default.resolve(config.rootDir, config.buildDir, GEN_APP_FILE),
|
|
92
108
|
module
|
|
93
109
|
);
|
|
94
110
|
}
|
|
95
|
-
async function
|
|
111
|
+
async function getFsRouteBatch(globPattern, config) {
|
|
96
112
|
if (!config.procedureDir) {
|
|
97
113
|
return [];
|
|
98
114
|
}
|
|
@@ -198,19 +214,15 @@ async function startBuild(config, skipCodeGen = false) {
|
|
|
198
214
|
logger$2.log("Bundling server....");
|
|
199
215
|
await setupWorkingDir(config);
|
|
200
216
|
await Promise.all([
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
217
|
+
createAppWithRoutesModule(config),
|
|
218
|
+
createServerEntryFile(config),
|
|
219
|
+
createCodegenEntryFile(config),
|
|
220
|
+
transpileFiles(config)
|
|
204
221
|
]);
|
|
205
|
-
await
|
|
206
|
-
await bundleFiles(config);
|
|
222
|
+
await bundleAppEntry(config);
|
|
207
223
|
logger$2.log("Finished bundling");
|
|
208
224
|
const clientCount = config.clientGenerators.length;
|
|
209
|
-
const codegenModule = path__default.resolve(
|
|
210
|
-
config.rootDir,
|
|
211
|
-
".output",
|
|
212
|
-
CODEGEN_OUTPUT
|
|
213
|
-
);
|
|
225
|
+
const codegenModule = path__default.resolve(config.rootDir, ".output", OUT_CODEGEN);
|
|
214
226
|
if (!skipCodeGen) {
|
|
215
227
|
logger$2.log("Generating Arri app definition (__definition.json)");
|
|
216
228
|
node_child_process.execSync(`node ${codegenModule}`, { env: process.env });
|
|
@@ -237,48 +249,18 @@ async function startBuild(config, skipCodeGen = false) {
|
|
|
237
249
|
logger$2.log("Cleaning up files");
|
|
238
250
|
await fs__default.rm(codegenModule);
|
|
239
251
|
logger$2.success(
|
|
240
|
-
`Build finished! You can start your server by running "node .output/${
|
|
252
|
+
`Build finished! You can start your server by running "node .output/${OUT_SERVER_ENTRY}"`
|
|
241
253
|
);
|
|
242
254
|
}
|
|
243
|
-
async function
|
|
244
|
-
|
|
245
|
-
await esbuild.build({
|
|
246
|
-
...config.esbuild,
|
|
247
|
-
entryPoints: [
|
|
248
|
-
path__default.resolve(
|
|
249
|
-
config.rootDir,
|
|
250
|
-
config.buildDir,
|
|
251
|
-
DEFAULT_CODEGEN_FILE
|
|
252
|
-
)
|
|
253
|
-
],
|
|
254
|
-
platform: config.esbuild.platform ?? "node",
|
|
255
|
-
target: config.esbuild.target ?? "node20",
|
|
256
|
-
packages: "external",
|
|
257
|
-
bundle: true,
|
|
258
|
-
format: "esm",
|
|
259
|
-
sourcemap: false,
|
|
260
|
-
minifyWhitespace: false,
|
|
261
|
-
banner: {
|
|
262
|
-
js: `import { createRequire as topLevelCreateRequire } from 'module';
|
|
263
|
-
const require = topLevelCreateRequire(import.meta.url);`
|
|
264
|
-
},
|
|
265
|
-
outfile: path__default.resolve(config.rootDir, ".output", CODEGEN_OUTPUT)
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
let buildEntry = path__default.resolve(
|
|
255
|
+
async function bundleAppEntry(config, allowCodegen = true) {
|
|
256
|
+
const appEntry = path__default.resolve(
|
|
269
257
|
config.rootDir,
|
|
270
258
|
config.buildDir,
|
|
271
|
-
|
|
259
|
+
GEN_APP_FILE
|
|
272
260
|
);
|
|
273
|
-
if (config.buildEntry) {
|
|
274
|
-
const parts = config.buildEntry.split(".");
|
|
275
|
-
parts.pop();
|
|
276
|
-
const mergedParts = `${parts.join(".")}.js`;
|
|
277
|
-
buildEntry = path__default.resolve(config.rootDir, config.buildDir, mergedParts);
|
|
278
|
-
}
|
|
279
261
|
await esbuild.build({
|
|
280
262
|
...config.esbuild,
|
|
281
|
-
entryPoints: [
|
|
263
|
+
entryPoints: [appEntry],
|
|
282
264
|
platform: config.esbuild.platform ?? "node",
|
|
283
265
|
target: config.esbuild.target ?? "node20",
|
|
284
266
|
bundle: true,
|
|
@@ -291,11 +273,34 @@ const require = topLevelCreateRequire(import.meta.url);`
|
|
|
291
273
|
const require = topLevelCreateRequire(import.meta.url);`
|
|
292
274
|
},
|
|
293
275
|
allowOverwrite: true,
|
|
294
|
-
outfile: path__default.resolve(config.rootDir, ".output",
|
|
276
|
+
outfile: path__default.resolve(config.rootDir, ".output", OUT_APP_FILE)
|
|
295
277
|
});
|
|
296
278
|
}
|
|
297
|
-
async function
|
|
298
|
-
if (config.
|
|
279
|
+
async function createServerEntryFile(config) {
|
|
280
|
+
if (config.serverEntry) {
|
|
281
|
+
const buildEntry = path__default.resolve(
|
|
282
|
+
config.rootDir,
|
|
283
|
+
config.srcDir,
|
|
284
|
+
config.serverEntry
|
|
285
|
+
);
|
|
286
|
+
await esbuild.build({
|
|
287
|
+
...config.esbuild,
|
|
288
|
+
entryPoints: [buildEntry],
|
|
289
|
+
platform: config.esbuild.platform ?? "node",
|
|
290
|
+
target: config.esbuild.target ?? "node20",
|
|
291
|
+
bundle: false,
|
|
292
|
+
packages: "external",
|
|
293
|
+
format: "esm",
|
|
294
|
+
sourcemap: true,
|
|
295
|
+
minifyWhitespace: true,
|
|
296
|
+
banner: {
|
|
297
|
+
js: `import { createRequire as topLevelCreateRequire } from 'module';
|
|
298
|
+
const require = topLevelCreateRequire(import.meta.url);`
|
|
299
|
+
},
|
|
300
|
+
plugins: [esbuildPluginReplace.replace({ "virtual:arri/app": "./app.js" })],
|
|
301
|
+
allowOverwrite: true,
|
|
302
|
+
outfile: path__default.resolve(config.rootDir, ".output", OUT_SERVER_ENTRY)
|
|
303
|
+
});
|
|
299
304
|
return;
|
|
300
305
|
}
|
|
301
306
|
const appModule = path__default.resolve(config.rootDir, config.srcDir, config.entry);
|
|
@@ -303,34 +308,18 @@ async function createBuildEntryModule(config) {
|
|
|
303
308
|
appImportParts.pop();
|
|
304
309
|
const virtualEntry = `import { toNodeListener } from 'arri';
|
|
305
310
|
import { listen } from 'listhen';
|
|
306
|
-
import
|
|
307
|
-
import app from './${appImportParts.join(".")}.js';
|
|
308
|
-
|
|
309
|
-
for (const route of routes) {
|
|
310
|
-
app.rpc({
|
|
311
|
-
name: route.id,
|
|
312
|
-
method: route.route.method,
|
|
313
|
-
params: route.route.params,
|
|
314
|
-
response: route.route.response,
|
|
315
|
-
handler: route.route.handler,
|
|
316
|
-
postHandler: route.route.postHandler,
|
|
317
|
-
});
|
|
318
|
-
}
|
|
311
|
+
import app from './${OUT_APP_FILE}';
|
|
319
312
|
|
|
320
313
|
void listen(toNodeListener(app.h3App), {
|
|
321
314
|
port: process.env.PORT ?? ${config.port},
|
|
322
315
|
public: true,
|
|
323
316
|
});`;
|
|
324
317
|
await fs__default.writeFile(
|
|
325
|
-
path__default.resolve(
|
|
326
|
-
config.rootDir,
|
|
327
|
-
config.buildDir,
|
|
328
|
-
DEFAULT_SERVER_ENTRY_FILE
|
|
329
|
-
),
|
|
318
|
+
path__default.resolve(config.rootDir, ".output", GEN_SERVER_ENTRY_FILE),
|
|
330
319
|
virtualEntry
|
|
331
320
|
);
|
|
332
321
|
}
|
|
333
|
-
async function
|
|
322
|
+
async function createCodegenEntryFile(config) {
|
|
334
323
|
const appModule = path__default.resolve(config.rootDir, config.srcDir, config.entry);
|
|
335
324
|
const appImportParts = path__default.relative(path__default.resolve(config.rootDir, config.srcDir), appModule).split(".");
|
|
336
325
|
appImportParts.pop();
|
|
@@ -338,20 +327,7 @@ async function createBuildCodegenModule(config) {
|
|
|
338
327
|
`
|
|
339
328
|
import { writeFileSync } from 'node:fs';
|
|
340
329
|
import path from 'pathe';
|
|
341
|
-
import app from './${
|
|
342
|
-
import routes from './routes.js';
|
|
343
|
-
|
|
344
|
-
for (const route of routes) {
|
|
345
|
-
app.rpc({
|
|
346
|
-
name: route.id,
|
|
347
|
-
method: route.route.method,
|
|
348
|
-
path: route.route.path,
|
|
349
|
-
params: route.route.params,
|
|
350
|
-
response: route.route.response,
|
|
351
|
-
handler: route.route.handler,
|
|
352
|
-
postHandler: route.route.postHandler,
|
|
353
|
-
});
|
|
354
|
-
}
|
|
330
|
+
import app from './${OUT_APP_FILE}';
|
|
355
331
|
|
|
356
332
|
const __dirname = new URL(".", import.meta.url).pathname;
|
|
357
333
|
const def = app.getAppDefinition();
|
|
@@ -362,7 +338,7 @@ async function createBuildCodegenModule(config) {
|
|
|
362
338
|
{ tabWidth: 4, parser: "typescript" }
|
|
363
339
|
);
|
|
364
340
|
await fs__default.writeFile(
|
|
365
|
-
path__default.resolve(config.rootDir,
|
|
341
|
+
path__default.resolve(config.rootDir, ".output", OUT_CODEGEN),
|
|
366
342
|
virtualModule
|
|
367
343
|
);
|
|
368
344
|
}
|
|
@@ -464,26 +440,26 @@ const dev = citty.defineCommand({
|
|
|
464
440
|
await startDevServer(config$1);
|
|
465
441
|
}
|
|
466
442
|
});
|
|
467
|
-
const startListener = (config, showQr = false) => listhen.listenAndWatch(
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
qr: showQr
|
|
474
|
-
}
|
|
475
|
-
);
|
|
443
|
+
const startListener = (config, showQr = false) => listhen.listenAndWatch(path__default.resolve(config.rootDir, ".output", OUT_SERVER_ENTRY), {
|
|
444
|
+
public: true,
|
|
445
|
+
port: config.port,
|
|
446
|
+
logger: logger$1,
|
|
447
|
+
qr: showQr
|
|
448
|
+
});
|
|
476
449
|
async function bundleFilesContext(config) {
|
|
450
|
+
const serverContent = `import app from './${OUT_APP_FILE}';
|
|
451
|
+
|
|
452
|
+
export default app.h3App;`;
|
|
453
|
+
await fs__default.writeFile(
|
|
454
|
+
path__default.resolve(config.rootDir, ".output", OUT_SERVER_ENTRY),
|
|
455
|
+
serverContent
|
|
456
|
+
);
|
|
477
457
|
return await esbuild__namespace.context({
|
|
478
458
|
...config.esbuild,
|
|
479
459
|
entryPoints: [
|
|
480
|
-
path__default.resolve(
|
|
481
|
-
config.rootDir,
|
|
482
|
-
config.buildDir,
|
|
483
|
-
DEFAULT_SERVER_ENTRY_FILE
|
|
484
|
-
)
|
|
460
|
+
path__default.resolve(config.rootDir, config.buildDir, GEN_APP_FILE)
|
|
485
461
|
],
|
|
486
|
-
outfile: path__default.resolve(config.rootDir, ".output",
|
|
462
|
+
outfile: path__default.resolve(config.rootDir, ".output", OUT_APP_FILE),
|
|
487
463
|
format: "esm",
|
|
488
464
|
bundle: true,
|
|
489
465
|
sourcemap: true,
|
|
@@ -495,8 +471,11 @@ async function bundleFilesContext(config) {
|
|
|
495
471
|
async function startDevServer(config) {
|
|
496
472
|
await setupWorkingDir(config);
|
|
497
473
|
let fileWatcher;
|
|
498
|
-
await Promise.all([
|
|
499
|
-
|
|
474
|
+
await Promise.all([
|
|
475
|
+
createEntryModule(config),
|
|
476
|
+
createAppWithRoutesModule(config),
|
|
477
|
+
transpileFiles(config)
|
|
478
|
+
]);
|
|
500
479
|
const bundleFiles = await bundleFilesContext(config);
|
|
501
480
|
await bundleFiles.rebuild();
|
|
502
481
|
const listener = await startListener(config, true);
|
|
@@ -534,7 +513,7 @@ async function startDevServer(config) {
|
|
|
534
513
|
if (event === "add" || event === "addDir") {
|
|
535
514
|
return;
|
|
536
515
|
}
|
|
537
|
-
await
|
|
516
|
+
await createAppWithRoutesModule(config);
|
|
538
517
|
let bundleCreated = false;
|
|
539
518
|
try {
|
|
540
519
|
logger$1.log(
|
|
@@ -587,28 +566,11 @@ async function createEntryModule(config) {
|
|
|
587
566
|
appImportParts.pop();
|
|
588
567
|
const virtualEntry = `import { toNodeListener } from 'h3';
|
|
589
568
|
import { listen } from 'listhen';
|
|
590
|
-
import
|
|
591
|
-
import app from './${appImportParts.join(".")}';
|
|
592
|
-
|
|
593
|
-
for (const route of routes) {
|
|
594
|
-
app.rpc({
|
|
595
|
-
name: route.id,
|
|
596
|
-
method: route.route.method,
|
|
597
|
-
path: route.route.path,
|
|
598
|
-
params: route.route.params,
|
|
599
|
-
response: route.route.response,
|
|
600
|
-
handler: route.route.handler,
|
|
601
|
-
postHandler: route.route.postHandler,
|
|
602
|
-
});
|
|
603
|
-
}
|
|
569
|
+
import app from './${GEN_APP_FILE}';
|
|
604
570
|
|
|
605
571
|
export default app.h3App;`;
|
|
606
572
|
await fs__default.writeFile(
|
|
607
|
-
path__default.resolve(
|
|
608
|
-
config.rootDir,
|
|
609
|
-
config.buildDir,
|
|
610
|
-
DEFAULT_SERVER_ENTRY_FILE
|
|
611
|
-
),
|
|
573
|
+
path__default.resolve(config.rootDir, config.buildDir, GEN_SERVER_ENTRY_FILE),
|
|
612
574
|
virtualEntry
|
|
613
575
|
);
|
|
614
576
|
}
|
package/dist/cli.mjs
CHANGED
|
@@ -8,9 +8,10 @@ import { loadConfig } from 'c12';
|
|
|
8
8
|
import consola, { createConsola } from 'consola';
|
|
9
9
|
import * as esbuild from 'esbuild';
|
|
10
10
|
import { build as build$1 } from 'esbuild';
|
|
11
|
+
import { replace } from 'esbuild-plugin-replace';
|
|
11
12
|
import path from 'pathe';
|
|
12
13
|
import prettier from 'prettier';
|
|
13
|
-
import { n as defaultConfig, m as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.
|
|
14
|
+
import { n as defaultConfig, m as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.cc0da87a.mjs';
|
|
14
15
|
import { globby } from 'globby';
|
|
15
16
|
import { camelCase, kebabCase } from 'scule';
|
|
16
17
|
import { dartClientGenerator } from 'arri-codegen-dart';
|
|
@@ -21,10 +22,11 @@ import Degit from 'degit';
|
|
|
21
22
|
import 'h3';
|
|
22
23
|
import 'arri-validate';
|
|
23
24
|
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
25
|
+
const GEN_APP_FILE = "__arri_app.js";
|
|
26
|
+
const GEN_SERVER_ENTRY_FILE = "__arri_server.js";
|
|
27
|
+
const OUT_APP_FILE = "app.js";
|
|
28
|
+
const OUT_SERVER_ENTRY = "server.js";
|
|
29
|
+
const OUT_CODEGEN = "codegen.js";
|
|
28
30
|
async function setupWorkingDir(config) {
|
|
29
31
|
const arriDir = path.resolve(config.rootDir, config.buildDir);
|
|
30
32
|
const outDir = path.resolve(config.rootDir, ".output");
|
|
@@ -37,12 +39,15 @@ async function setupWorkingDir(config) {
|
|
|
37
39
|
await fs.mkdir(arriDir);
|
|
38
40
|
await fs.mkdir(outDir);
|
|
39
41
|
}
|
|
40
|
-
async function
|
|
42
|
+
async function createAppWithRoutesModule(config) {
|
|
43
|
+
const appModule = path.resolve(config.rootDir, config.srcDir, config.entry);
|
|
44
|
+
const appImportParts = path.relative(path.resolve(config.rootDir, config.srcDir), appModule).split(".");
|
|
45
|
+
appImportParts.pop();
|
|
41
46
|
const routes = [];
|
|
42
47
|
const existingRoutes = [];
|
|
43
48
|
await Promise.all(
|
|
44
49
|
config.procedureGlobPatterns.map(async (pattern) => {
|
|
45
|
-
const results = await
|
|
50
|
+
const results = await getFsRouteBatch(pattern, config);
|
|
46
51
|
for (const result of results) {
|
|
47
52
|
if (!existingRoutes.includes(result.name)) {
|
|
48
53
|
routes.push(result);
|
|
@@ -53,22 +58,33 @@ async function createRoutesModule(config) {
|
|
|
53
58
|
);
|
|
54
59
|
routes.sort((a, b) => a.name < b.name ? -1 : 1);
|
|
55
60
|
const module = await prettier.format(
|
|
56
|
-
|
|
61
|
+
`import app from './${appImportParts.join(".")}';
|
|
62
|
+
${routes.map(
|
|
57
63
|
(route) => `import ${route.importName} from '${route.importPath}';`
|
|
58
64
|
).join("\n")}
|
|
59
65
|
const routes = [${routes.map(
|
|
60
66
|
(route) => `{ id: '${route.name}', route: ${route.importName} }`
|
|
61
67
|
).join(",\n")}
|
|
62
68
|
];
|
|
63
|
-
|
|
69
|
+
for(const route of routes) {
|
|
70
|
+
app.rpc({
|
|
71
|
+
name: route.id,
|
|
72
|
+
method: route.route.method,
|
|
73
|
+
params: route.route.params,
|
|
74
|
+
response: route.route.response,
|
|
75
|
+
handler: route.route.handler,
|
|
76
|
+
postHandler: route.route.postHandler,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
export default app`,
|
|
64
80
|
{ parser: "typescript", tabWidth: 4 }
|
|
65
81
|
);
|
|
66
82
|
await fs.writeFile(
|
|
67
|
-
path.resolve(config.rootDir, config.buildDir,
|
|
83
|
+
path.resolve(config.rootDir, config.buildDir, GEN_APP_FILE),
|
|
68
84
|
module
|
|
69
85
|
);
|
|
70
86
|
}
|
|
71
|
-
async function
|
|
87
|
+
async function getFsRouteBatch(globPattern, config) {
|
|
72
88
|
if (!config.procedureDir) {
|
|
73
89
|
return [];
|
|
74
90
|
}
|
|
@@ -174,19 +190,15 @@ async function startBuild(config, skipCodeGen = false) {
|
|
|
174
190
|
logger$2.log("Bundling server....");
|
|
175
191
|
await setupWorkingDir(config);
|
|
176
192
|
await Promise.all([
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
193
|
+
createAppWithRoutesModule(config),
|
|
194
|
+
createServerEntryFile(config),
|
|
195
|
+
createCodegenEntryFile(config),
|
|
196
|
+
transpileFiles(config)
|
|
180
197
|
]);
|
|
181
|
-
await
|
|
182
|
-
await bundleFiles(config);
|
|
198
|
+
await bundleAppEntry(config);
|
|
183
199
|
logger$2.log("Finished bundling");
|
|
184
200
|
const clientCount = config.clientGenerators.length;
|
|
185
|
-
const codegenModule = path.resolve(
|
|
186
|
-
config.rootDir,
|
|
187
|
-
".output",
|
|
188
|
-
CODEGEN_OUTPUT
|
|
189
|
-
);
|
|
201
|
+
const codegenModule = path.resolve(config.rootDir, ".output", OUT_CODEGEN);
|
|
190
202
|
if (!skipCodeGen) {
|
|
191
203
|
logger$2.log("Generating Arri app definition (__definition.json)");
|
|
192
204
|
execSync(`node ${codegenModule}`, { env: process.env });
|
|
@@ -213,48 +225,18 @@ async function startBuild(config, skipCodeGen = false) {
|
|
|
213
225
|
logger$2.log("Cleaning up files");
|
|
214
226
|
await fs.rm(codegenModule);
|
|
215
227
|
logger$2.success(
|
|
216
|
-
`Build finished! You can start your server by running "node .output/${
|
|
228
|
+
`Build finished! You can start your server by running "node .output/${OUT_SERVER_ENTRY}"`
|
|
217
229
|
);
|
|
218
230
|
}
|
|
219
|
-
async function
|
|
220
|
-
|
|
221
|
-
await build$1({
|
|
222
|
-
...config.esbuild,
|
|
223
|
-
entryPoints: [
|
|
224
|
-
path.resolve(
|
|
225
|
-
config.rootDir,
|
|
226
|
-
config.buildDir,
|
|
227
|
-
DEFAULT_CODEGEN_FILE
|
|
228
|
-
)
|
|
229
|
-
],
|
|
230
|
-
platform: config.esbuild.platform ?? "node",
|
|
231
|
-
target: config.esbuild.target ?? "node20",
|
|
232
|
-
packages: "external",
|
|
233
|
-
bundle: true,
|
|
234
|
-
format: "esm",
|
|
235
|
-
sourcemap: false,
|
|
236
|
-
minifyWhitespace: false,
|
|
237
|
-
banner: {
|
|
238
|
-
js: `import { createRequire as topLevelCreateRequire } from 'module';
|
|
239
|
-
const require = topLevelCreateRequire(import.meta.url);`
|
|
240
|
-
},
|
|
241
|
-
outfile: path.resolve(config.rootDir, ".output", CODEGEN_OUTPUT)
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
let buildEntry = path.resolve(
|
|
231
|
+
async function bundleAppEntry(config, allowCodegen = true) {
|
|
232
|
+
const appEntry = path.resolve(
|
|
245
233
|
config.rootDir,
|
|
246
234
|
config.buildDir,
|
|
247
|
-
|
|
235
|
+
GEN_APP_FILE
|
|
248
236
|
);
|
|
249
|
-
if (config.buildEntry) {
|
|
250
|
-
const parts = config.buildEntry.split(".");
|
|
251
|
-
parts.pop();
|
|
252
|
-
const mergedParts = `${parts.join(".")}.js`;
|
|
253
|
-
buildEntry = path.resolve(config.rootDir, config.buildDir, mergedParts);
|
|
254
|
-
}
|
|
255
237
|
await build$1({
|
|
256
238
|
...config.esbuild,
|
|
257
|
-
entryPoints: [
|
|
239
|
+
entryPoints: [appEntry],
|
|
258
240
|
platform: config.esbuild.platform ?? "node",
|
|
259
241
|
target: config.esbuild.target ?? "node20",
|
|
260
242
|
bundle: true,
|
|
@@ -267,11 +249,34 @@ const require = topLevelCreateRequire(import.meta.url);`
|
|
|
267
249
|
const require = topLevelCreateRequire(import.meta.url);`
|
|
268
250
|
},
|
|
269
251
|
allowOverwrite: true,
|
|
270
|
-
outfile: path.resolve(config.rootDir, ".output",
|
|
252
|
+
outfile: path.resolve(config.rootDir, ".output", OUT_APP_FILE)
|
|
271
253
|
});
|
|
272
254
|
}
|
|
273
|
-
async function
|
|
274
|
-
if (config.
|
|
255
|
+
async function createServerEntryFile(config) {
|
|
256
|
+
if (config.serverEntry) {
|
|
257
|
+
const buildEntry = path.resolve(
|
|
258
|
+
config.rootDir,
|
|
259
|
+
config.srcDir,
|
|
260
|
+
config.serverEntry
|
|
261
|
+
);
|
|
262
|
+
await build$1({
|
|
263
|
+
...config.esbuild,
|
|
264
|
+
entryPoints: [buildEntry],
|
|
265
|
+
platform: config.esbuild.platform ?? "node",
|
|
266
|
+
target: config.esbuild.target ?? "node20",
|
|
267
|
+
bundle: false,
|
|
268
|
+
packages: "external",
|
|
269
|
+
format: "esm",
|
|
270
|
+
sourcemap: true,
|
|
271
|
+
minifyWhitespace: true,
|
|
272
|
+
banner: {
|
|
273
|
+
js: `import { createRequire as topLevelCreateRequire } from 'module';
|
|
274
|
+
const require = topLevelCreateRequire(import.meta.url);`
|
|
275
|
+
},
|
|
276
|
+
plugins: [replace({ "virtual:arri/app": "./app.js" })],
|
|
277
|
+
allowOverwrite: true,
|
|
278
|
+
outfile: path.resolve(config.rootDir, ".output", OUT_SERVER_ENTRY)
|
|
279
|
+
});
|
|
275
280
|
return;
|
|
276
281
|
}
|
|
277
282
|
const appModule = path.resolve(config.rootDir, config.srcDir, config.entry);
|
|
@@ -279,34 +284,18 @@ async function createBuildEntryModule(config) {
|
|
|
279
284
|
appImportParts.pop();
|
|
280
285
|
const virtualEntry = `import { toNodeListener } from 'arri';
|
|
281
286
|
import { listen } from 'listhen';
|
|
282
|
-
import
|
|
283
|
-
import app from './${appImportParts.join(".")}.js';
|
|
284
|
-
|
|
285
|
-
for (const route of routes) {
|
|
286
|
-
app.rpc({
|
|
287
|
-
name: route.id,
|
|
288
|
-
method: route.route.method,
|
|
289
|
-
params: route.route.params,
|
|
290
|
-
response: route.route.response,
|
|
291
|
-
handler: route.route.handler,
|
|
292
|
-
postHandler: route.route.postHandler,
|
|
293
|
-
});
|
|
294
|
-
}
|
|
287
|
+
import app from './${OUT_APP_FILE}';
|
|
295
288
|
|
|
296
289
|
void listen(toNodeListener(app.h3App), {
|
|
297
290
|
port: process.env.PORT ?? ${config.port},
|
|
298
291
|
public: true,
|
|
299
292
|
});`;
|
|
300
293
|
await fs.writeFile(
|
|
301
|
-
path.resolve(
|
|
302
|
-
config.rootDir,
|
|
303
|
-
config.buildDir,
|
|
304
|
-
DEFAULT_SERVER_ENTRY_FILE
|
|
305
|
-
),
|
|
294
|
+
path.resolve(config.rootDir, ".output", GEN_SERVER_ENTRY_FILE),
|
|
306
295
|
virtualEntry
|
|
307
296
|
);
|
|
308
297
|
}
|
|
309
|
-
async function
|
|
298
|
+
async function createCodegenEntryFile(config) {
|
|
310
299
|
const appModule = path.resolve(config.rootDir, config.srcDir, config.entry);
|
|
311
300
|
const appImportParts = path.relative(path.resolve(config.rootDir, config.srcDir), appModule).split(".");
|
|
312
301
|
appImportParts.pop();
|
|
@@ -314,20 +303,7 @@ async function createBuildCodegenModule(config) {
|
|
|
314
303
|
`
|
|
315
304
|
import { writeFileSync } from 'node:fs';
|
|
316
305
|
import path from 'pathe';
|
|
317
|
-
import app from './${
|
|
318
|
-
import routes from './routes.js';
|
|
319
|
-
|
|
320
|
-
for (const route of routes) {
|
|
321
|
-
app.rpc({
|
|
322
|
-
name: route.id,
|
|
323
|
-
method: route.route.method,
|
|
324
|
-
path: route.route.path,
|
|
325
|
-
params: route.route.params,
|
|
326
|
-
response: route.route.response,
|
|
327
|
-
handler: route.route.handler,
|
|
328
|
-
postHandler: route.route.postHandler,
|
|
329
|
-
});
|
|
330
|
-
}
|
|
306
|
+
import app from './${OUT_APP_FILE}';
|
|
331
307
|
|
|
332
308
|
const __dirname = new URL(".", import.meta.url).pathname;
|
|
333
309
|
const def = app.getAppDefinition();
|
|
@@ -338,7 +314,7 @@ async function createBuildCodegenModule(config) {
|
|
|
338
314
|
{ tabWidth: 4, parser: "typescript" }
|
|
339
315
|
);
|
|
340
316
|
await fs.writeFile(
|
|
341
|
-
path.resolve(config.rootDir,
|
|
317
|
+
path.resolve(config.rootDir, ".output", OUT_CODEGEN),
|
|
342
318
|
virtualModule
|
|
343
319
|
);
|
|
344
320
|
}
|
|
@@ -440,26 +416,26 @@ const dev = defineCommand({
|
|
|
440
416
|
await startDevServer(config);
|
|
441
417
|
}
|
|
442
418
|
});
|
|
443
|
-
const startListener = (config, showQr = false) => listenAndWatch(
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
qr: showQr
|
|
450
|
-
}
|
|
451
|
-
);
|
|
419
|
+
const startListener = (config, showQr = false) => listenAndWatch(path.resolve(config.rootDir, ".output", OUT_SERVER_ENTRY), {
|
|
420
|
+
public: true,
|
|
421
|
+
port: config.port,
|
|
422
|
+
logger: logger$1,
|
|
423
|
+
qr: showQr
|
|
424
|
+
});
|
|
452
425
|
async function bundleFilesContext(config) {
|
|
426
|
+
const serverContent = `import app from './${OUT_APP_FILE}';
|
|
427
|
+
|
|
428
|
+
export default app.h3App;`;
|
|
429
|
+
await fs.writeFile(
|
|
430
|
+
path.resolve(config.rootDir, ".output", OUT_SERVER_ENTRY),
|
|
431
|
+
serverContent
|
|
432
|
+
);
|
|
453
433
|
return await esbuild.context({
|
|
454
434
|
...config.esbuild,
|
|
455
435
|
entryPoints: [
|
|
456
|
-
path.resolve(
|
|
457
|
-
config.rootDir,
|
|
458
|
-
config.buildDir,
|
|
459
|
-
DEFAULT_SERVER_ENTRY_FILE
|
|
460
|
-
)
|
|
436
|
+
path.resolve(config.rootDir, config.buildDir, GEN_APP_FILE)
|
|
461
437
|
],
|
|
462
|
-
outfile: path.resolve(config.rootDir, ".output",
|
|
438
|
+
outfile: path.resolve(config.rootDir, ".output", OUT_APP_FILE),
|
|
463
439
|
format: "esm",
|
|
464
440
|
bundle: true,
|
|
465
441
|
sourcemap: true,
|
|
@@ -471,8 +447,11 @@ async function bundleFilesContext(config) {
|
|
|
471
447
|
async function startDevServer(config) {
|
|
472
448
|
await setupWorkingDir(config);
|
|
473
449
|
let fileWatcher;
|
|
474
|
-
await Promise.all([
|
|
475
|
-
|
|
450
|
+
await Promise.all([
|
|
451
|
+
createEntryModule(config),
|
|
452
|
+
createAppWithRoutesModule(config),
|
|
453
|
+
transpileFiles(config)
|
|
454
|
+
]);
|
|
476
455
|
const bundleFiles = await bundleFilesContext(config);
|
|
477
456
|
await bundleFiles.rebuild();
|
|
478
457
|
const listener = await startListener(config, true);
|
|
@@ -510,7 +489,7 @@ async function startDevServer(config) {
|
|
|
510
489
|
if (event === "add" || event === "addDir") {
|
|
511
490
|
return;
|
|
512
491
|
}
|
|
513
|
-
await
|
|
492
|
+
await createAppWithRoutesModule(config);
|
|
514
493
|
let bundleCreated = false;
|
|
515
494
|
try {
|
|
516
495
|
logger$1.log(
|
|
@@ -563,28 +542,11 @@ async function createEntryModule(config) {
|
|
|
563
542
|
appImportParts.pop();
|
|
564
543
|
const virtualEntry = `import { toNodeListener } from 'h3';
|
|
565
544
|
import { listen } from 'listhen';
|
|
566
|
-
import
|
|
567
|
-
import app from './${appImportParts.join(".")}';
|
|
568
|
-
|
|
569
|
-
for (const route of routes) {
|
|
570
|
-
app.rpc({
|
|
571
|
-
name: route.id,
|
|
572
|
-
method: route.route.method,
|
|
573
|
-
path: route.route.path,
|
|
574
|
-
params: route.route.params,
|
|
575
|
-
response: route.route.response,
|
|
576
|
-
handler: route.route.handler,
|
|
577
|
-
postHandler: route.route.postHandler,
|
|
578
|
-
});
|
|
579
|
-
}
|
|
545
|
+
import app from './${GEN_APP_FILE}';
|
|
580
546
|
|
|
581
547
|
export default app.h3App;`;
|
|
582
548
|
await fs.writeFile(
|
|
583
|
-
path.resolve(
|
|
584
|
-
config.rootDir,
|
|
585
|
-
config.buildDir,
|
|
586
|
-
DEFAULT_SERVER_ENTRY_FILE
|
|
587
|
-
),
|
|
549
|
+
path.resolve(config.rootDir, config.buildDir, GEN_SERVER_ENTRY_FILE),
|
|
588
550
|
virtualEntry
|
|
589
551
|
);
|
|
590
552
|
}
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -152,7 +152,7 @@ declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOption
|
|
|
152
152
|
interface ArriConfig {
|
|
153
153
|
port: number;
|
|
154
154
|
entry: string;
|
|
155
|
-
|
|
155
|
+
serverEntry?: string;
|
|
156
156
|
rootDir?: string;
|
|
157
157
|
srcDir?: string;
|
|
158
158
|
procedureDir?: string | false;
|
package/dist/index.d.mts
CHANGED
|
@@ -152,7 +152,7 @@ declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOption
|
|
|
152
152
|
interface ArriConfig {
|
|
153
153
|
port: number;
|
|
154
154
|
entry: string;
|
|
155
|
-
|
|
155
|
+
serverEntry?: string;
|
|
156
156
|
rootDir?: string;
|
|
157
157
|
srcDir?: string;
|
|
158
158
|
procedureDir?: string | false;
|
package/dist/index.d.ts
CHANGED
|
@@ -152,7 +152,7 @@ declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOption
|
|
|
152
152
|
interface ArriConfig {
|
|
153
153
|
port: number;
|
|
154
154
|
entry: string;
|
|
155
|
-
|
|
155
|
+
serverEntry?: string;
|
|
156
156
|
rootDir?: string;
|
|
157
157
|
srcDir?: string;
|
|
158
158
|
procedureDir?: string | false;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as ArriApp, p as ArriRouter, a as DEV_DEFINITION_ENDPOINT, D as DEV_ENDPOINT_ROOT, E as ErrorResponse, c as createRpcDefinition, n as defaultConfig, o as defineConfig, h as defineError, q as defineRoute, d as defineRpc, j as errorResponseFromValidationErrors, e as getRpcParamName, g as getRpcPath, f as getRpcResponseName, k as handleH3Error, t as handleRoute, l as isArriConfig, m as isResolvedArriConfig, b as isRpc, i as isRpcParamSchema, s as registerRoute, r as registerRpc } from './shared/arri.
|
|
1
|
+
export { A as ArriApp, p as ArriRouter, a as DEV_DEFINITION_ENDPOINT, D as DEV_ENDPOINT_ROOT, E as ErrorResponse, c as createRpcDefinition, n as defaultConfig, o as defineConfig, h as defineError, q as defineRoute, d as defineRpc, j as errorResponseFromValidationErrors, e as getRpcParamName, g as getRpcPath, f as getRpcResponseName, k as handleH3Error, t as handleRoute, l as isArriConfig, m as isResolvedArriConfig, b as isRpc, i as isRpcParamSchema, s as registerRoute, r as registerRpc } from './shared/arri.cc0da87a.mjs';
|
|
2
2
|
export * from 'h3';
|
|
3
3
|
import 'arri-validate';
|
|
4
4
|
import 'arri-codegen-utils';
|
|
@@ -715,7 +715,7 @@ const defaultConfig = {
|
|
|
715
715
|
procedureGlobPatterns: ["**/*.rpc.ts"],
|
|
716
716
|
clientGenerators: [],
|
|
717
717
|
buildDir: ".arri",
|
|
718
|
-
|
|
718
|
+
serverEntry: "",
|
|
719
719
|
esbuild: {}
|
|
720
720
|
};
|
|
721
721
|
function defineConfig(config) {
|
|
@@ -729,7 +729,7 @@ function defineConfig(config) {
|
|
|
729
729
|
clientGenerators: config.clientGenerators ?? defaultConfig.clientGenerators,
|
|
730
730
|
buildDir: config.buildDir ?? defaultConfig.buildDir,
|
|
731
731
|
esbuild: config.esbuild ?? defaultConfig.esbuild,
|
|
732
|
-
|
|
732
|
+
serverEntry: config.serverEntry ?? ""
|
|
733
733
|
};
|
|
734
734
|
}
|
|
735
735
|
|
|
@@ -713,7 +713,7 @@ const defaultConfig = {
|
|
|
713
713
|
procedureGlobPatterns: ["**/*.rpc.ts"],
|
|
714
714
|
clientGenerators: [],
|
|
715
715
|
buildDir: ".arri",
|
|
716
|
-
|
|
716
|
+
serverEntry: "",
|
|
717
717
|
esbuild: {}
|
|
718
718
|
};
|
|
719
719
|
function defineConfig(config) {
|
|
@@ -727,7 +727,7 @@ function defineConfig(config) {
|
|
|
727
727
|
clientGenerators: config.clientGenerators ?? defaultConfig.clientGenerators,
|
|
728
728
|
buildDir: config.buildDir ?? defaultConfig.buildDir,
|
|
729
729
|
esbuild: config.esbuild ?? defaultConfig.esbuild,
|
|
730
|
-
|
|
730
|
+
serverEntry: config.serverEntry ?? ""
|
|
731
731
|
};
|
|
732
732
|
}
|
|
733
733
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arri",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -27,27 +27,28 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"c12": "^1.5.1",
|
|
29
29
|
"chokidar": "^3.5.3",
|
|
30
|
-
"citty": "^0.1.
|
|
30
|
+
"citty": "^0.1.5",
|
|
31
31
|
"consola": "^3.2.3",
|
|
32
32
|
"degit": "^2.8.4",
|
|
33
|
-
"esbuild": "^0.19.
|
|
33
|
+
"esbuild": "^0.19.7",
|
|
34
|
+
"esbuild-plugin-replace": "^1.4.0",
|
|
34
35
|
"globby": "^14.0.0",
|
|
35
|
-
"h3": "^1.
|
|
36
|
+
"h3": "^1.9.0",
|
|
36
37
|
"jiti": "^1.21.0",
|
|
37
38
|
"ofetch": "^1.3.3",
|
|
38
39
|
"pathe": "^1.1.1",
|
|
39
40
|
"prettier": "^3.1.0",
|
|
40
41
|
"scule": "^1.1.0",
|
|
41
|
-
"arri-codegen-dart": "0.
|
|
42
|
-
"arri-
|
|
43
|
-
"arri-codegen-ts": "0.
|
|
44
|
-
"arri-
|
|
42
|
+
"arri-codegen-dart": "0.13.0",
|
|
43
|
+
"arri-codegen-utils": "0.13.0",
|
|
44
|
+
"arri-codegen-ts": "0.13.0",
|
|
45
|
+
"arri-validate": "0.13.0"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"listhen": "1.x"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
51
|
"@types/degit": "^2.8.6",
|
|
51
|
-
"bun-types": "^1.0.
|
|
52
|
+
"bun-types": "^1.0.13"
|
|
52
53
|
}
|
|
53
54
|
}
|