@mapl/web 0.3.1 → 0.3.3
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 +3 -45
- package/build/rolldown.d.ts +33 -3
- package/build/rolldown.js +10 -11
- package/package.json +9 -12
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ const app = router(
|
|
|
14
14
|
|
|
15
15
|
// Routes
|
|
16
16
|
[
|
|
17
|
-
handle.get('/path', (c) => c.id, {
|
|
17
|
+
handle.get('/path', (c) => '' + c.id, {
|
|
18
18
|
// Response wrapper
|
|
19
19
|
type: handle.text
|
|
20
20
|
})
|
|
@@ -32,47 +32,5 @@ export default {
|
|
|
32
32
|
## AOT compilation (experimental)
|
|
33
33
|
Build `@mapl/web` to improve startup time.
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// main.ts
|
|
38
|
-
import { handle, layer, router } from '@mapl/web';
|
|
39
|
-
|
|
40
|
-
export default router(
|
|
41
|
-
[
|
|
42
|
-
layer.tap((c) => {
|
|
43
|
-
console.log(c.req);
|
|
44
|
-
}),
|
|
45
|
-
layer.attach('id', () => performance.now()),
|
|
46
|
-
],
|
|
47
|
-
[handle.any('/path', (c) => c.id)],
|
|
48
|
-
{
|
|
49
|
-
'/api': router(
|
|
50
|
-
[layer.parse('body', async (c) => c.req.text())],
|
|
51
|
-
[handle.post('/body', (c) => c.body)],
|
|
52
|
-
),
|
|
53
|
-
},
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
// build.ts
|
|
57
|
-
import terser from '@rollup/plugin-terser';
|
|
58
|
-
import build from '@mapl/web/build/rolldown';
|
|
59
|
-
|
|
60
|
-
build({
|
|
61
|
-
input: INPUT,
|
|
62
|
-
output: {
|
|
63
|
-
file: OUTPUT,
|
|
64
|
-
},
|
|
65
|
-
finalizeOptions: {
|
|
66
|
-
plugins: [
|
|
67
|
-
terser({
|
|
68
|
-
compress: {
|
|
69
|
-
// passes should be >= 2, recommend 3
|
|
70
|
-
passes: 3,
|
|
71
|
-
},
|
|
72
|
-
mangle: false,
|
|
73
|
-
}),
|
|
74
|
-
],
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
```
|
|
78
|
-
As of rn only `terser` can DCE `@mapl/web` patterns.
|
|
35
|
+
### Rolldown
|
|
36
|
+
See in `examples/dev`.
|
package/build/rolldown.d.ts
CHANGED
|
@@ -1,13 +1,43 @@
|
|
|
1
|
-
import { type BuildOptions, type OutputOptions } from "rolldown";
|
|
1
|
+
import { type BuildOptions, type OutputOptions, type RolldownWatcher, type WatcherOptions } from "rolldown";
|
|
2
2
|
export interface MaplBuildOptions {
|
|
3
|
+
/**
|
|
4
|
+
* App entry point
|
|
5
|
+
*/
|
|
3
6
|
input: string;
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Output options
|
|
9
|
+
*/
|
|
10
|
+
output: Omit<OutputOptions, "file"> & {
|
|
11
|
+
dir: string
|
|
6
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* App build options
|
|
15
|
+
*/
|
|
7
16
|
buildOptions?: Omit<BuildOptions, "input" | "output">;
|
|
17
|
+
/**
|
|
18
|
+
* App output build options
|
|
19
|
+
*/
|
|
8
20
|
finalizeOptions?: Omit<BuildOptions, "input" | "output">;
|
|
21
|
+
/**
|
|
22
|
+
* Whether to emit asynchronous output
|
|
23
|
+
*/
|
|
9
24
|
asynchronous?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Build target
|
|
27
|
+
*/
|
|
10
28
|
target?: "bun";
|
|
11
29
|
}
|
|
30
|
+
export interface MaplDevOptions extends Omit<MaplBuildOptions, "finalizeOptions"> {
|
|
31
|
+
/**
|
|
32
|
+
* File watcher option
|
|
33
|
+
*/
|
|
34
|
+
watcherOptions?: WatcherOptions;
|
|
35
|
+
}
|
|
36
|
+
export interface MaplAllOptions {
|
|
37
|
+
common: MaplDevOptions & MaplBuildOptions;
|
|
38
|
+
dev?: Partial<MaplDevOptions>;
|
|
39
|
+
build?: Partial<MaplBuildOptions>;
|
|
40
|
+
}
|
|
12
41
|
declare const _default: (opts: MaplBuildOptions) => Promise<void>;
|
|
13
42
|
export default _default;
|
|
43
|
+
export declare const dev: (opts: MaplDevOptions) => RolldownWatcher;
|
package/build/rolldown.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import{writeFileSync}from"node:fs";import{build}from"rolldown";import{compileToExportedDependency as generic}from"../compiler/jit.js";import{compileToExportedDependency as bun}from"../compiler/bun/jit.js";import{evaluateToString}from"runtime-compiler/jit";import{clear}from"runtime-compiler";export default async opts=>{let output=opts.output;let
|
|
1
|
+
import{mkdirSync,writeFileSync}from"node:fs";import{build,watch}from"rolldown";import{compileToExportedDependency as generic}from"../compiler/jit.js";import{compileToExportedDependency as bun}from"../compiler/bun/jit.js";import{evaluateToString}from"runtime-compiler/jit";import{clear}from"runtime-compiler";import{join,resolve}from"node:path";export default async opts=>{let output=opts.output;let outputFile=join(output.dir,`server-exports.js`);let tmpFile=resolve(output.dir,`tmp.js`);await build({...opts.buildOptions,input:opts.input,output:{file:tmpFile}});let appMod=await import(tmpFile);let HANDLER=(opts.target===`bun`?bun:generic)(appMod.default);try{mkdirSync(output.dir,{recursive:true})}catch{}writeFileSync(outputFile,`
|
|
2
2
|
import 'runtime-compiler/hydrate-loader';
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import * as app from ${JSON.stringify(tmpFile)};
|
|
5
5
|
import hydrateRouter from '@mapl/web/compiler/${opts.target===`bun`?`bun/`:``}aot';
|
|
6
|
-
hydrateRouter(app);
|
|
6
|
+
hydrateRouter(app.default);
|
|
7
7
|
|
|
8
8
|
import { hydrate } from 'runtime-compiler/hydrate';
|
|
9
9
|
import { getDependency } from 'runtime-compiler';
|
|
10
10
|
|
|
11
11
|
${opts.asynchronous?`await(async`:`(`}${evaluateToString()})(...hydrate());
|
|
12
|
-
${opts.target===`bun`?`
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
`);clear();await build({...opts.finalizeOptions??opts.buildOptions,input:output.file,output})};
|
|
12
|
+
${opts.target===`bun`?`export default { routes: getDependency(${HANDLER}), ...app.serveOptions };`:`export default { fetch: getDependency(${HANDLER}), ...app.serveOptions };`}
|
|
13
|
+
`);clear();await build({...opts.finalizeOptions??opts.buildOptions,input:outputFile,output:{...output,file:outputFile,dir:void 0}})};export let dev=opts=>{let output=opts.output;let input=resolve(opts.input);let tmpFile=join(output.dir,`tmp.js`);let compileResult=opts.asynchronous?`await compileToHandler(app.default)`:`compileToHandlerSync(app.default)`;try{mkdirSync(output.dir,{recursive:true})}catch{}writeFileSync(tmpFile,`
|
|
14
|
+
import * as app from ${JSON.stringify(input)};
|
|
15
|
+
import { compileToHandler${opts.asynchronous?``:`Sync`} } from '@mapl/web/compiler/${opts.target===`bun`?`bun/`:``}jit';
|
|
16
|
+
|
|
17
|
+
${opts.target===`bun`?`export default { routes: ${compileResult}, ...app.serveOptions };`:`export default { fetch: ${compileResult}, ...app.serveOptions };`}
|
|
18
|
+
`);return watch({...opts.buildOptions,input:tmpFile,output:{file:join(output.dir,`server-exports.js`),dir:void 0}})};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapl/web",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "A compiled web framework for all runtimes",
|
|
5
5
|
"keywords": ["fast", "lightweight", "cross-runtime", "framework", "web", "backend"],
|
|
6
6
|
"repository": {
|
|
@@ -17,25 +17,22 @@
|
|
|
17
17
|
"@safe-std/error": "^1.0.1",
|
|
18
18
|
"runtime-compiler": "^1.2.5"
|
|
19
19
|
},
|
|
20
|
-
"optionalDependencies": {
|
|
21
|
-
"secure-headers": "^0.0.6"
|
|
22
|
-
},
|
|
23
20
|
"exports": {
|
|
24
21
|
"./constants": "./constants.js",
|
|
25
|
-
"./core": "./core/index.js",
|
|
26
|
-
".": "./index.js",
|
|
27
|
-
"./core/context": "./core/context.js",
|
|
28
22
|
"./core/handler": "./core/handler.js",
|
|
29
|
-
"
|
|
23
|
+
".": "./index.js",
|
|
30
24
|
"./core/utils": "./core/utils.js",
|
|
31
|
-
"./utils/static-headers": "./utils/static-headers.js",
|
|
32
|
-
"./utils/secure-headers": "./utils/secure-headers.js",
|
|
33
25
|
"./utils/cors": "./utils/cors.js",
|
|
34
26
|
"./build/rolldown": "./build/rolldown.js",
|
|
35
27
|
"./compiler/jit": "./compiler/jit.js",
|
|
28
|
+
"./core/context": "./core/context.js",
|
|
36
29
|
"./compiler/aot": "./compiler/aot.js",
|
|
37
|
-
"./
|
|
30
|
+
"./core": "./core/index.js",
|
|
31
|
+
"./core/middleware": "./core/middleware.js",
|
|
32
|
+
"./utils/secure-headers": "./utils/secure-headers.js",
|
|
38
33
|
"./compiler/bun/router": "./compiler/bun/router.js",
|
|
39
|
-
"./compiler/bun/aot": "./compiler/bun/aot.js"
|
|
34
|
+
"./compiler/bun/aot": "./compiler/bun/aot.js",
|
|
35
|
+
"./compiler/bun/jit": "./compiler/bun/jit.js",
|
|
36
|
+
"./utils/static-headers": "./utils/static-headers.js"
|
|
40
37
|
}
|
|
41
38
|
}
|