@mapl/web 0.3.6 → 0.3.11
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/build/rolldown.d.ts +19 -21
- package/build/rolldown.js +13 -11
- package/build/utils.d.ts +1 -0
- package/build/utils.js +1 -0
- package/package.json +13 -11
package/build/rolldown.d.ts
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import { type BuildOptions, type OutputOptions, type RolldownWatcher } from "rolldown";
|
|
2
|
-
export interface MaplBuildOptions {
|
|
1
|
+
import { type BuildOptions, type OutputOptions, type RolldownWatcher, type RolldownPluginOption } from "rolldown";
|
|
2
|
+
export interface MaplBuildOptions extends Omit<BuildOptions, "input" | "output"> {
|
|
3
|
+
output?: Omit<OutputOptions, "file" | "dir">;
|
|
4
|
+
}
|
|
5
|
+
export interface MaplOptions {
|
|
3
6
|
/**
|
|
4
7
|
* App entry point
|
|
5
8
|
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Output options
|
|
9
|
-
*/
|
|
10
|
-
output: Omit<OutputOptions, "file"> & {
|
|
11
|
-
dir: string
|
|
12
|
-
};
|
|
9
|
+
main: string;
|
|
13
10
|
/**
|
|
14
|
-
*
|
|
11
|
+
* Output directory
|
|
15
12
|
*/
|
|
16
|
-
|
|
13
|
+
outputDir: string;
|
|
17
14
|
/**
|
|
18
|
-
*
|
|
15
|
+
* Build options
|
|
19
16
|
*/
|
|
20
|
-
|
|
17
|
+
build?: MaplBuildOptions;
|
|
21
18
|
/**
|
|
22
19
|
* Whether to emit asynchronous output
|
|
23
20
|
*/
|
|
@@ -26,13 +23,14 @@ export interface MaplBuildOptions {
|
|
|
26
23
|
* Build target
|
|
27
24
|
*/
|
|
28
25
|
target?: "bun";
|
|
26
|
+
/**
|
|
27
|
+
* Hydrate specific options
|
|
28
|
+
*/
|
|
29
|
+
hydrate?: MaplBuildOptions;
|
|
29
30
|
}
|
|
30
|
-
export
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
dev?: Partial<MaplDevOptions>;
|
|
34
|
-
build?: Partial<MaplBuildOptions>;
|
|
35
|
-
}
|
|
36
|
-
declare const _default: (opts: MaplBuildOptions) => Promise<void>;
|
|
31
|
+
export declare const hydrateImportsPlugin: RolldownPluginOption;
|
|
32
|
+
export declare const SERVER_ENTRY = "index.js";
|
|
33
|
+
declare const _default: (options: MaplOptions) => Promise<void>;
|
|
37
34
|
export default _default;
|
|
38
|
-
export declare const
|
|
35
|
+
export declare const watcherReady: (watcher: RolldownWatcher) => Promise<void>;
|
|
36
|
+
export declare const dev: (options: MaplOptions) => RolldownWatcher | void;
|
package/build/rolldown.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
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{
|
|
2
|
-
import 'runtime-compiler/hydrate-loader';
|
|
3
|
-
|
|
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{resolve}from"node:path";import{EXTERNALS}from"./utils.js";export let hydrateImportsPlugin={name:`mapl-web-hydrate-config-replacer`,resolveId(source){return this.resolve(source===`runtime-compiler/config`?`runtime-compiler/hydrate-config`:source)}};export let SERVER_ENTRY=`index.js`;let mkdirSafe=dir=>{try{mkdirSync(dir,{recursive:true})}catch{}};export default async options=>{let buildOptions=options.build;let hydrateOptions=options.hydrate;let targetOption=options.target;let asyncOption=options.asynchronous;let inputFile=resolve(options.main);let tmpFile;if(buildOptions==null){tmpFile=inputFile;mkdirSafe(options.outputDir)}else{tmpFile=resolve(options.outputDir,`tmp.js`);let outputOptions=buildOptions?.output;let currentExternals=buildOptions?.external;await build({...buildOptions,input:inputFile,output:{...outputOptions,file:tmpFile},external:currentExternals==null?EXTERNALS:typeof currentExternals===`function`?(id,...args)=>EXTERNALS.includes(id)||currentExternals(id,...args):EXTERNALS.concat(currentExternals)})}let appMod=await import(tmpFile);let HANDLER=(targetOption===`bun`?bun:generic)(appMod.default);let outputFile=resolve(options.outputDir,SERVER_ENTRY);writeFileSync(outputFile,`
|
|
4
2
|
import app from ${JSON.stringify(tmpFile)};
|
|
5
|
-
import hydrateRouter from '@mapl/web/compiler/${
|
|
3
|
+
import hydrateRouter from '@mapl/web/compiler/${targetOption===`bun`?`bun/`:``}aot';
|
|
6
4
|
hydrateRouter(app);
|
|
7
5
|
|
|
8
6
|
import { hydrate } from 'runtime-compiler/hydrate';
|
|
9
7
|
import { getDependency } from 'runtime-compiler';
|
|
10
8
|
|
|
11
|
-
${
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
${asyncOption?`await(async`:`(`}${evaluateToString()})(...hydrate());
|
|
10
|
+
export default {
|
|
11
|
+
${targetOption===`bun`?`routes`:`fetch`}: getDependency(${HANDLER})
|
|
12
|
+
};
|
|
13
|
+
`);let currentPlugins=hydrateOptions?.plugins;await build({...hydrateOptions,input:outputFile,output:{...hydrateOptions?.output,file:outputFile},plugins:!currentPlugins?hydrateImportsPlugin:Array.isArray(currentPlugins)?[hydrateImportsPlugin].concat(currentPlugins):[hydrateImportsPlugin,currentPlugins]})};let jitContent=(inputFile,options)=>{let asyncOption=options.asynchronous===true;let targetOption=options.target;return`
|
|
14
|
+
import app from ${JSON.stringify(inputFile)};
|
|
15
|
+
import { ${asyncOption?`compileToHandler`:`compileToHandlerSync`} } from '@mapl/web/compiler/${targetOption===`bun`?`bun/`:``}jit';
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
export default {
|
|
18
|
+
${targetOption===`bun`?`routes`:`fetch`}: ${asyncOption?`await compileToHandler`:`compileToHandlerSync`}(app)
|
|
19
|
+
};
|
|
20
|
+
`};export let watcherReady=watcher=>new Promise((res,rej)=>{let listener=e=>{if(e.code===`ERROR`)rej(e.error);else if(e.code===`BUNDLE_END`)res();watcher.off(`event`,listener)};watcher.on(`event`,listener)});export let dev=options=>{let outputFile=resolve(options.outputDir,SERVER_ENTRY);mkdirSafe(options.outputDir);let content=jitContent(resolve(options.main),options);if(options.build!=null){let buildOptions=options.build;let outputOptions=buildOptions?.output;let tmpFile=resolve(options.outputDir,`tmp.js`);mkdirSafe(options.outputDir);writeFileSync(tmpFile,content);return watch({...buildOptions,input:tmpFile,output:{...outputOptions,file:outputFile}})}writeFileSync(outputFile,content)};
|
package/build/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const EXTERNALS: string[];
|
package/build/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let EXTERNALS=[`runtime-compiler`,`runtime-compiler/config`,`@mapl/framework`,`@mapl/web`];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapl/web",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.11",
|
|
4
4
|
"description": "A compiled web framework for all runtimes",
|
|
5
5
|
"keywords": ["fast", "lightweight", "cross-runtime", "framework", "web", "backend"],
|
|
6
6
|
"repository": {
|
|
@@ -14,24 +14,26 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@mapl/framework": "^0.5.3",
|
|
16
16
|
"@mapl/router": "^0.6.2",
|
|
17
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
17
18
|
"@safe-std/error": "^1.0.1",
|
|
18
|
-
"runtime-compiler": "^1.2.
|
|
19
|
+
"runtime-compiler": "^1.2.6"
|
|
19
20
|
},
|
|
20
21
|
"exports": {
|
|
21
|
-
"./core/context": "./core/context.js",
|
|
22
22
|
"./constants": "./constants.js",
|
|
23
|
-
"./core/middleware": "./core/middleware.js",
|
|
24
|
-
"./utils/cors": "./utils/cors.js",
|
|
25
|
-
"./core": "./core/index.js",
|
|
26
23
|
"./core/handler": "./core/handler.js",
|
|
27
|
-
"./
|
|
28
|
-
"./utils/static-headers": "./utils/static-headers.js",
|
|
29
|
-
"./compiler/aot": "./compiler/aot.js",
|
|
24
|
+
"./core": "./core/index.js",
|
|
30
25
|
"./core/utils": "./core/utils.js",
|
|
31
26
|
".": "./index.js",
|
|
27
|
+
"./core/context": "./core/context.js",
|
|
28
|
+
"./core/middleware": "./core/middleware.js",
|
|
29
|
+
"./build/utils": "./build/utils.js",
|
|
30
|
+
"./utils/static-headers": "./utils/static-headers.js",
|
|
31
|
+
"./compiler/jit": "./compiler/jit.js",
|
|
32
32
|
"./build/rolldown": "./build/rolldown.js",
|
|
33
|
+
"./compiler/bun/jit": "./compiler/bun/jit.js",
|
|
33
34
|
"./compiler/bun/router": "./compiler/bun/router.js",
|
|
34
|
-
"./
|
|
35
|
-
"./compiler/
|
|
35
|
+
"./utils/cors": "./utils/cors.js",
|
|
36
|
+
"./compiler/aot": "./compiler/aot.js",
|
|
37
|
+
"./compiler/bun/aot": "./compiler/bun/aot.js"
|
|
36
38
|
}
|
|
37
39
|
}
|