@quilted/rollup 0.3.3 → 0.4.1
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/CHANGELOG.md +12 -0
- package/build/esm/app.mjs +24 -44
- package/build/esm/constants.mjs +2 -2
- package/build/esm/index.mjs +1 -1
- package/build/esm/server.mjs +34 -17
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +24 -25
- package/build/typescript/app.d.ts.map +1 -1
- package/build/typescript/constants.d.ts +1 -1
- package/build/typescript/constants.d.ts.map +1 -1
- package/build/typescript/module.d.ts +1 -1
- package/build/typescript/package.d.ts +2 -2
- package/build/typescript/server.d.ts +22 -17
- package/build/typescript/server.d.ts.map +1 -1
- package/package.json +1 -1
- package/source/app.ts +47 -83
- package/source/constants.ts +1 -1
- package/source/server.ts +55 -32
package/source/server.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
|
|
12
12
|
import {multiline} from './shared/strings.ts';
|
|
13
13
|
import {resolveEnvOption, type MagicModuleEnvOptions} from './features/env.ts';
|
|
14
|
-
import {MAGIC_MODULE_ENTRY,
|
|
14
|
+
import {MAGIC_MODULE_ENTRY, MAGIC_MODULE_HONO} from './constants.ts';
|
|
15
15
|
import {createMagicModulePlugin} from './shared/magic-module.ts';
|
|
16
16
|
import type {ModuleRuntime} from './module.ts';
|
|
17
17
|
|
|
@@ -33,17 +33,16 @@ export interface ServerOptions {
|
|
|
33
33
|
entry?: string;
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* Whether this server code uses
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* `request-router` adaptor.
|
|
36
|
+
* Whether this server code uses `hono` to define itself in a generic way,
|
|
37
|
+
* which can be adapted to a variety of environments. By default, this is
|
|
38
|
+
* `'hono'`, and when `'hono'`, the `entry` you specified must export an
|
|
39
|
+
* `Hono` object as its default export. When set to `'custom'`, the app
|
|
40
|
+
* server will be built as a basic server-side JavaScript project, without
|
|
41
|
+
* the special `hono` adaptor.
|
|
43
42
|
*
|
|
44
|
-
* @default '
|
|
43
|
+
* @default 'hono'
|
|
45
44
|
*/
|
|
46
|
-
format?: '
|
|
45
|
+
format?: 'hono' | 'custom';
|
|
47
46
|
|
|
48
47
|
/**
|
|
49
48
|
* Whether to include GraphQL-related code transformations.
|
|
@@ -76,12 +75,19 @@ export interface ServerRuntime extends ModuleRuntime {
|
|
|
76
75
|
env?: string;
|
|
77
76
|
|
|
78
77
|
/**
|
|
79
|
-
* The content to use as the entry point when the server uses the `
|
|
80
|
-
* format for their server. This file should import the
|
|
81
|
-
* this app from 'quilt:module/
|
|
78
|
+
* The content to use as the entry point when the server uses the `hono`
|
|
79
|
+
* format for their server. This file should import the hono instance for
|
|
80
|
+
* this app from 'quilt:module/hono', and create a server that is appropriate
|
|
82
81
|
* for this runtime.
|
|
83
82
|
*/
|
|
84
|
-
|
|
83
|
+
hono?(): string;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Provides additional Rollup options to customize the server build.
|
|
87
|
+
* This function receives the current Rollup options and can return
|
|
88
|
+
* modified options or a partial override.
|
|
89
|
+
*/
|
|
90
|
+
rollup?(options: RollupOptions): InputPluginOption;
|
|
85
91
|
}
|
|
86
92
|
|
|
87
93
|
export interface ServerOutputOptions
|
|
@@ -112,12 +118,12 @@ export interface ServerOutputOptions
|
|
|
112
118
|
hash?: boolean | 'async-only';
|
|
113
119
|
}
|
|
114
120
|
|
|
115
|
-
export {MAGIC_MODULE_ENTRY,
|
|
121
|
+
export {MAGIC_MODULE_ENTRY, MAGIC_MODULE_HONO};
|
|
116
122
|
|
|
117
123
|
export async function quiltServer({
|
|
118
124
|
root: rootPath = process.cwd(),
|
|
119
125
|
entry,
|
|
120
|
-
format = '
|
|
126
|
+
format = 'hono',
|
|
121
127
|
env,
|
|
122
128
|
graphql = true,
|
|
123
129
|
output,
|
|
@@ -163,7 +169,7 @@ export async function quiltServer({
|
|
|
163
169
|
: await sourceForServer(project);
|
|
164
170
|
|
|
165
171
|
const finalEntry =
|
|
166
|
-
format === '
|
|
172
|
+
format === 'hono'
|
|
167
173
|
? MAGIC_MODULE_ENTRY
|
|
168
174
|
: (serverEntry ?? MAGIC_MODULE_ENTRY);
|
|
169
175
|
|
|
@@ -188,21 +194,19 @@ export async function quiltServer({
|
|
|
188
194
|
removeBuildFiles([outputDirectory, reportDirectory], {root: project.root}),
|
|
189
195
|
];
|
|
190
196
|
|
|
191
|
-
if (format === '
|
|
197
|
+
if (format === 'hono') {
|
|
192
198
|
plugins.push(
|
|
193
199
|
createMagicModulePlugin({
|
|
194
|
-
name: '@quilted/magic-module/server-
|
|
195
|
-
module:
|
|
200
|
+
name: '@quilted/magic-module/server-hono',
|
|
201
|
+
module: MAGIC_MODULE_HONO,
|
|
196
202
|
alias: serverEntry,
|
|
197
203
|
}),
|
|
198
204
|
createMagicModulePlugin({
|
|
199
|
-
name: '@quilted/
|
|
205
|
+
name: '@quilted/hono',
|
|
200
206
|
sideEffects: true,
|
|
201
207
|
module: MAGIC_MODULE_ENTRY,
|
|
202
208
|
source() {
|
|
203
|
-
return (
|
|
204
|
-
runtime.requestRouter?.() ?? nodeServerRuntime().requestRouter()
|
|
205
|
-
);
|
|
209
|
+
return runtime.hono?.() ?? nodeServerRuntime().hono();
|
|
206
210
|
},
|
|
207
211
|
}),
|
|
208
212
|
);
|
|
@@ -227,7 +231,7 @@ export async function quiltServer({
|
|
|
227
231
|
}),
|
|
228
232
|
);
|
|
229
233
|
|
|
230
|
-
|
|
234
|
+
const options = {
|
|
231
235
|
input: {[finalEntryName]: finalEntry},
|
|
232
236
|
plugins,
|
|
233
237
|
output: {
|
|
@@ -242,6 +246,12 @@ export async function quiltServer({
|
|
|
242
246
|
...runtime.output?.options,
|
|
243
247
|
},
|
|
244
248
|
} satisfies RollupOptions;
|
|
249
|
+
|
|
250
|
+
if (runtime.rollup) {
|
|
251
|
+
plugins.push(runtime.rollup(options));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return options;
|
|
245
255
|
}
|
|
246
256
|
|
|
247
257
|
export interface NodeServerRuntimeOptions {
|
|
@@ -288,18 +298,31 @@ export function nodeServerRuntime({
|
|
|
288
298
|
resolve: {
|
|
289
299
|
exportConditions: ['node'],
|
|
290
300
|
},
|
|
291
|
-
|
|
301
|
+
hono() {
|
|
292
302
|
return multiline`
|
|
293
|
-
import
|
|
294
|
-
MAGIC_MODULE_REQUEST_ROUTER,
|
|
295
|
-
)};
|
|
303
|
+
import app from ${JSON.stringify(MAGIC_MODULE_HONO)};
|
|
296
304
|
|
|
297
|
-
import {
|
|
305
|
+
import {serve} from '@quilted/quilt/hono/node';
|
|
298
306
|
|
|
299
307
|
const port = ${port ?? 'Number.parseInt(process.env.PORT, 10)'};
|
|
300
308
|
const host = ${host ? JSON.stringify(host) : 'process.env.HOST'};
|
|
301
|
-
|
|
302
|
-
|
|
309
|
+
|
|
310
|
+
const server = serve(app);
|
|
311
|
+
|
|
312
|
+
process.on('SIGINT', () => {
|
|
313
|
+
server.close();
|
|
314
|
+
process.exit(0);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
process.on('SIGTERM', () => {
|
|
318
|
+
server.close((err) => {
|
|
319
|
+
if (err) {
|
|
320
|
+
console.error(err);
|
|
321
|
+
process.exit(1);
|
|
322
|
+
}
|
|
323
|
+
process.exit(0);
|
|
324
|
+
});
|
|
325
|
+
});
|
|
303
326
|
`;
|
|
304
327
|
},
|
|
305
328
|
} satisfies ServerRuntime;
|