@mapl/web 0.3.2 → 0.3.5
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 +6 -48
- package/build/rolldown.d.ts +16 -4
- package/build/rolldown.js +9 -10
- package/package.json +10 -10
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
|
})
|
|
@@ -33,51 +33,9 @@ export default {
|
|
|
33
33
|
Build `@mapl/web` to improve startup time.
|
|
34
34
|
|
|
35
35
|
### Rolldown
|
|
36
|
-
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// Main app
|
|
42
|
-
export default router(
|
|
43
|
-
[
|
|
44
|
-
layer.tap((c) => {
|
|
45
|
-
console.log(c.req);
|
|
46
|
-
}),
|
|
47
|
-
layer.attach('id', () => performance.now()),
|
|
48
|
-
],
|
|
49
|
-
[handle.any('/path', (c) => c.id)],
|
|
50
|
-
{
|
|
51
|
-
'/api': router(
|
|
52
|
-
[layer.parse('body', async (c) => c.req.text())],
|
|
53
|
-
[handle.post('/body', (c) => c.body)],
|
|
54
|
-
),
|
|
55
|
-
},
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
// Additional options
|
|
59
|
-
export const serveOptions = {};
|
|
60
|
-
|
|
61
|
-
// build.ts
|
|
62
|
-
import terser from '@rollup/plugin-terser';
|
|
63
|
-
import build from '@mapl/web/build/rolldown';
|
|
64
|
-
|
|
65
|
-
build({
|
|
66
|
-
input: INPUT,
|
|
67
|
-
output: {
|
|
68
|
-
file: OUTPUT,
|
|
69
|
-
},
|
|
70
|
-
finalizeOptions: {
|
|
71
|
-
plugins: [
|
|
72
|
-
terser({
|
|
73
|
-
compress: {
|
|
74
|
-
// passes should be >= 2
|
|
75
|
-
passes: 3,
|
|
76
|
-
},
|
|
77
|
-
mangle: false,
|
|
78
|
-
}),
|
|
79
|
-
],
|
|
80
|
-
},
|
|
81
|
-
});
|
|
36
|
+
Try it out using:
|
|
37
|
+
```sh
|
|
38
|
+
npm install -g degit
|
|
39
|
+
degit github:mapljs/web/examples/generic
|
|
82
40
|
```
|
|
83
|
-
|
|
41
|
+
And change `@mapl/web` version in `package.json`.
|
package/build/rolldown.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
3
|
/**
|
|
4
4
|
* App entry point
|
|
@@ -7,15 +7,15 @@ export interface MaplBuildOptions {
|
|
|
7
7
|
/**
|
|
8
8
|
* Output options
|
|
9
9
|
*/
|
|
10
|
-
output: Omit<OutputOptions, "
|
|
11
|
-
|
|
10
|
+
output: Omit<OutputOptions, "file"> & {
|
|
11
|
+
dir: string
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
14
|
* App build options
|
|
15
15
|
*/
|
|
16
16
|
buildOptions?: Omit<BuildOptions, "input" | "output">;
|
|
17
17
|
/**
|
|
18
|
-
* App
|
|
18
|
+
* App finalize options
|
|
19
19
|
*/
|
|
20
20
|
finalizeOptions?: Omit<BuildOptions, "input" | "output">;
|
|
21
21
|
/**
|
|
@@ -27,5 +27,17 @@ export interface MaplBuildOptions {
|
|
|
27
27
|
*/
|
|
28
28
|
target?: "bun";
|
|
29
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
|
+
}
|
|
30
41
|
declare const _default: (opts: MaplBuildOptions) => Promise<void>;
|
|
31
42
|
export default _default;
|
|
43
|
+
export declare const dev: (opts: MaplDevOptions) => RolldownWatcher;
|
package/build/rolldown.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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 inputFile=resolve(opts.input);let outputFile=join(output.dir,`server-exports.js`);let tmpFile=resolve(output.dir,`tmp.js`);let external=opts.buildOptions?.external;await build({...opts.buildOptions,input:inputFile,output:{file:tmpFile},external:external==null?`runtime-compiler/config`:Array.isArray(external)?external.concat(`runtime-compiler/config`):typeof external===`function`?(id,parentId,isResolved)=>id===`runtime-compiler/config`||external(id,parentId,isResolved):[external,`runtime-compiler/config`]});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 app
|
|
4
|
+
import app from ${JSON.stringify(tmpFile)};
|
|
5
5
|
import hydrateRouter from '@mapl/web/compiler/${opts.target===`bun`?`bun/`:``}aot';
|
|
6
6
|
hydrateRouter(app);
|
|
7
7
|
|
|
@@ -9,11 +9,10 @@ import{writeFileSync}from"node:fs";import{build}from"rolldown";import{compileToE
|
|
|
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}) };`:`export default { fetch: getDependency(${HANDLER}) };`}
|
|
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 tmpFile=resolve(output.dir,`tmp.js`);let watcher=watch({...opts.buildOptions,input:resolve(opts.input),output:{...output,file:tmpFile,dir:void 0},watch:opts.watcherOptions});let compileResult=opts.asynchronous?`await compileToHandler(app)`:`compileToHandlerSync(app)`;try{mkdirSync(output.dir,{recursive:true})}catch{}writeFileSync(join(output.dir,`server-exports.js`),`
|
|
14
|
+
import app from ${JSON.stringify(tmpFile)};
|
|
15
|
+
import { compileToHandler${opts.asynchronous?``:`Sync`} } from '@mapl/web/compiler/${opts.target===`bun`?`bun/`:``}jit';
|
|
16
|
+
|
|
17
|
+
${opts.target===`bun`?`export default { routes: ${compileResult} };`:`export default { fetch: ${compileResult} };`}
|
|
18
|
+
`);return watcher};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapl/web",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "A compiled web framework for all runtimes",
|
|
5
5
|
"keywords": ["fast", "lightweight", "cross-runtime", "framework", "web", "backend"],
|
|
6
6
|
"repository": {
|
|
@@ -19,20 +19,20 @@
|
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
21
|
"./constants": "./constants.js",
|
|
22
|
-
"./
|
|
22
|
+
"./core/middleware": "./core/middleware.js",
|
|
23
|
+
"./core/handler": "./core/handler.js",
|
|
23
24
|
".": "./index.js",
|
|
24
|
-
"./
|
|
25
|
-
"./
|
|
25
|
+
"./core": "./core/index.js",
|
|
26
|
+
"./core/utils": "./core/utils.js",
|
|
26
27
|
"./utils/cors": "./utils/cors.js",
|
|
27
|
-
"./compiler/aot": "./compiler/aot.js",
|
|
28
28
|
"./utils/secure-headers": "./utils/secure-headers.js",
|
|
29
|
-
"./core": "./core/index.js",
|
|
30
29
|
"./core/context": "./core/context.js",
|
|
30
|
+
"./compiler/aot": "./compiler/aot.js",
|
|
31
31
|
"./compiler/bun/router": "./compiler/bun/router.js",
|
|
32
|
-
"./
|
|
33
|
-
"./core/handler": "./core/handler.js",
|
|
34
|
-
"./core/utils": "./core/utils.js",
|
|
32
|
+
"./compiler/bun/jit": "./compiler/bun/jit.js",
|
|
35
33
|
"./compiler/bun/aot": "./compiler/bun/aot.js",
|
|
36
|
-
"./
|
|
34
|
+
"./utils/static-headers": "./utils/static-headers.js",
|
|
35
|
+
"./build/rolldown": "./build/rolldown.js",
|
|
36
|
+
"./compiler/jit": "./compiler/jit.js"
|
|
37
37
|
}
|
|
38
38
|
}
|