@srvkit/rsbuild 0.1.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/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/_virtual/_rolldown/runtime.js +35 -0
- package/dist/constants/path.js +13 -0
- package/dist/constants/path.js.map +1 -0
- package/dist/constants/path.mjs +12 -0
- package/dist/constants/path.mjs.map +1 -0
- package/dist/functions/ssr.js +18 -0
- package/dist/functions/ssr.js.map +1 -0
- package/dist/functions/ssr.mjs +17 -0
- package/dist/functions/ssr.mjs.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +17 -0
- package/dist/index.mjs +11 -0
- package/dist/node.d.ts +5 -0
- package/dist/node.js +17 -0
- package/dist/node.mjs +11 -0
- package/dist/package.js +18 -0
- package/dist/package.js.map +1 -0
- package/dist/package.mjs +12 -0
- package/dist/package.mjs.map +1 -0
- package/dist/plugin.d.ts +7 -0
- package/dist/plugin.js +12 -0
- package/dist/plugin.mjs +11 -0
- package/dist/plugins/build/index.d.ts +7 -0
- package/dist/plugins/build/index.js +97 -0
- package/dist/plugins/build/index.js.map +1 -0
- package/dist/plugins/build/index.mjs +96 -0
- package/dist/plugins/build/index.mjs.map +1 -0
- package/dist/plugins/copy/index.d.ts +7 -0
- package/dist/plugins/copy/index.js +35 -0
- package/dist/plugins/copy/index.js.map +1 -0
- package/dist/plugins/copy/index.mjs +33 -0
- package/dist/plugins/copy/index.mjs.map +1 -0
- package/dist/plugins/dev/index.d.ts +7 -0
- package/dist/plugins/dev/index.js +170 -0
- package/dist/plugins/dev/index.js.map +1 -0
- package/dist/plugins/dev/index.mjs +166 -0
- package/dist/plugins/dev/index.mjs.map +1 -0
- package/dist/plugins/index.d.ts +7 -0
- package/dist/plugins/index.js +24 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/index.mjs +24 -0
- package/dist/plugins/index.mjs.map +1 -0
- package/dist/runtime.d.ts +4 -0
- package/dist/runtime.js +17 -0
- package/dist/runtime.mjs +11 -0
- package/package.json +86 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugins/copy/index.ts"],"sourcesContent":["import type {\n RsbuildConfig,\n RsbuildPlugin,\n RsbuildPluginAPI,\n} from \"@rsbuild/core\";\nimport type {\n ResolvedBuildOptions,\n ResolvedOptions,\n} from \"@srvkit/common/@types/options/resolved\";\n\nconst copyPlugin = (opts: ResolvedOptions): RsbuildPlugin[] => {\n const build: ResolvedBuildOptions = opts.build;\n\n if (build.target !== \"server\" || !build.copyPublicDir) {\n return [];\n }\n\n return [\n {\n name: \"srvkit:copy\",\n apply: \"build\",\n async setup(api: RsbuildPluginAPI): Promise<void> {\n api.modifyRsbuildConfig(\n (config: RsbuildConfig): RsbuildConfig => {\n return {\n ...config,\n output: {\n ...config.output,\n copy: [\n {\n from: build.publicDir,\n to: build.publicDir,\n },\n ],\n },\n };\n },\n );\n },\n },\n ];\n};\n\nexport { copyPlugin };\n"],"mappings":";;;;;;;;AAUA,MAAM,cAAc,SAA2C;CAC3D,MAAM,QAA8B,KAAK;CAEzC,IAAI,MAAM,WAAW,YAAY,CAAC,MAAM,eACpC,OAAO,CAAC;CAGZ,OAAO,CACH;EACI,MAAM;EACN,OAAO;EACP,MAAM,MAAM,KAAsC;GAC9C,IAAI,qBACC,WAAyC;IACtC,OAAO;KACH,GAAG;KACH,QAAQ;MACJ,GAAG,OAAO;MACV,MAAM,CACF;OACI,MAAM,MAAM;OACZ,IAAI,MAAM;MACd,CACJ;KACJ;IACJ;GACJ,CACJ;EACJ;CACJ,CACJ;AACJ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import __tsdown_shims_path from 'node:path';
|
|
2
|
+
import __tsdown_shims_url from 'node:url';
|
|
3
|
+
import { RsbuildPlugin } from "@rsbuild/core";
|
|
4
|
+
import { ResolvedOptions } from "@srvkit/common/@types/options/resolved";
|
|
5
|
+
declare const devPlugin: (opts: ResolvedOptions) => RsbuildPlugin;
|
|
6
|
+
export { devPlugin };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
10
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
11
|
+
const require_path = require('../../constants/path.js');
|
|
12
|
+
const require_ssr = require('../../functions/ssr.js');
|
|
13
|
+
let node_module = require("node:module");
|
|
14
|
+
let _srvkit_common_functions_package_package_json = require("@srvkit/common/functions/package/package-json");
|
|
15
|
+
let node_fs_promises = require("node:fs/promises");
|
|
16
|
+
node_fs_promises = require_runtime.__toESM(node_fs_promises);
|
|
17
|
+
let node_path = require("node:path");
|
|
18
|
+
node_path = require_runtime.__toESM(node_path);
|
|
19
|
+
let node_url = require("node:url");
|
|
20
|
+
let _srvkit_common_functions_http_request_header = require("@srvkit/common/functions/http/request/header");
|
|
21
|
+
let _srvkit_common_functions_http_response_write = require("@srvkit/common/functions/http/response/write");
|
|
22
|
+
let _srvkit_common_functions_path_posix = require("@srvkit/common/functions/path/posix");
|
|
23
|
+
let _srvkit_common_functions_server_live = require("@srvkit/common/functions/server/live");
|
|
24
|
+
|
|
25
|
+
const createMiddleware = ({ server, isHttps, port }) => {
|
|
26
|
+
return async (req, res) => {
|
|
27
|
+
const protocol = `http${isHttps ? "s" : ""}`;
|
|
28
|
+
const host = server.options.hostname ?? "localhost";
|
|
29
|
+
const path = req.url ?? "";
|
|
30
|
+
const url = new URL(`${protocol}://${host}:${port}${path}`);
|
|
31
|
+
const body = req.method !== "GET" && req.method !== "HEAD" ? req : void 0;
|
|
32
|
+
const request = new Request(url, {
|
|
33
|
+
method: req.method,
|
|
34
|
+
headers: (0, _srvkit_common_functions_http_request_header.toHeaders)(req.headers),
|
|
35
|
+
body,
|
|
36
|
+
duplex: "half"
|
|
37
|
+
});
|
|
38
|
+
await (0, _srvkit_common_functions_http_response_write.writeHttpResponse)({
|
|
39
|
+
response: await server.fetch(request),
|
|
40
|
+
httpResponse: res
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const createDevVirtualEntryCode = (opts) => {
|
|
45
|
+
let code = "";
|
|
46
|
+
code += `import options from "${(0, _srvkit_common_functions_path_posix.toPosix)(opts.entry)}";`;
|
|
47
|
+
code += `export default options;`;
|
|
48
|
+
return code;
|
|
49
|
+
};
|
|
50
|
+
const devPlugin = (opts) => {
|
|
51
|
+
const dev = opts.dev;
|
|
52
|
+
const https = opts.dev.https ?? {};
|
|
53
|
+
const build = opts.build;
|
|
54
|
+
const isHttps = https.cert !== void 0 && https.key !== void 0;
|
|
55
|
+
const packageJson = (0, _srvkit_common_functions_package_package_json.getPackageJson)(opts.cwd);
|
|
56
|
+
return {
|
|
57
|
+
name: "srvkit:dev",
|
|
58
|
+
apply: "serve",
|
|
59
|
+
async setup(api) {
|
|
60
|
+
let middleware;
|
|
61
|
+
let liveUpdate;
|
|
62
|
+
let port;
|
|
63
|
+
let compileCount = 0;
|
|
64
|
+
const ssrTarget = require_ssr.getSsrTarget(opts.runtime);
|
|
65
|
+
api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {
|
|
66
|
+
return mergeRsbuildConfig(config, {
|
|
67
|
+
source: { entry: { index: require_path.VIRTUAL_ENTRY } },
|
|
68
|
+
output: {
|
|
69
|
+
target: "node",
|
|
70
|
+
distPath: build.outputDir,
|
|
71
|
+
copy: void 0
|
|
72
|
+
},
|
|
73
|
+
dev: { writeToDisk: true },
|
|
74
|
+
server: {
|
|
75
|
+
host: dev.host,
|
|
76
|
+
port: dev.port,
|
|
77
|
+
...https.cert !== void 0 && https.key !== void 0 ? { https: {
|
|
78
|
+
cert: https.cert,
|
|
79
|
+
key: https.key,
|
|
80
|
+
passphrase: https.passphrase
|
|
81
|
+
} } : {}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
api.modifyBundlerChain((chain, { rspack }) => {
|
|
86
|
+
chain.plugin("virtual-modules").use(rspack.experiments.VirtualModulesPlugin, [{ [require_path.VIRTUAL_ENTRY]: createDevVirtualEntryCode(opts) }]);
|
|
87
|
+
});
|
|
88
|
+
api.modifyRspackConfig((config, { mergeConfig }) => {
|
|
89
|
+
const isModule = packageJson.type === "module";
|
|
90
|
+
const nodeExternals = [...node_module.builtinModules, /^node:/];
|
|
91
|
+
const overrideConfig = {
|
|
92
|
+
resolve: {
|
|
93
|
+
/** @see https://rspack.rs/config/resolve#extend-default-value */
|
|
94
|
+
conditionNames: [opts.runtime, "..."] },
|
|
95
|
+
output: {
|
|
96
|
+
filename: build.outputFile,
|
|
97
|
+
...isModule ? { module: true } : {}
|
|
98
|
+
},
|
|
99
|
+
target: ssrTarget,
|
|
100
|
+
node: {
|
|
101
|
+
__dirname: false,
|
|
102
|
+
__filename: false
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
if (build.bundle === "external") {
|
|
106
|
+
const depExternals = [
|
|
107
|
+
...Object.keys(packageJson.dependencies ?? {}),
|
|
108
|
+
...Object.keys(packageJson.peerDependencies ?? {}),
|
|
109
|
+
...Object.keys(packageJson.optionalDependencies ?? {})
|
|
110
|
+
].map((depName) => new RegExp(`^${depName.replace(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`)}([\\/]|$)`));
|
|
111
|
+
overrideConfig.externals = [...nodeExternals, ...depExternals];
|
|
112
|
+
overrideConfig.externalsType = isModule ? "module-import" : "commonjs";
|
|
113
|
+
}
|
|
114
|
+
if (build.bundle === "standalone") overrideConfig.externals = nodeExternals;
|
|
115
|
+
return mergeConfig(config, overrideConfig);
|
|
116
|
+
});
|
|
117
|
+
api.onAfterDevCompile(async ({ isFirstCompile }) => {
|
|
118
|
+
const distPath = api.context.distPath;
|
|
119
|
+
const outputPath = node_path.resolve(distPath, "index.js");
|
|
120
|
+
compileCount++;
|
|
121
|
+
if (isFirstCompile) {
|
|
122
|
+
const serverOptions = (await import((0, node_url.pathToFileURL)(outputPath).href)).default;
|
|
123
|
+
const { server, update } = (0, _srvkit_common_functions_server_live.createLiveServer)({
|
|
124
|
+
gracefulShutdown: false,
|
|
125
|
+
...serverOptions,
|
|
126
|
+
manual: true,
|
|
127
|
+
hostname: dev.host,
|
|
128
|
+
port: dev.port,
|
|
129
|
+
tls: {
|
|
130
|
+
cert: https.cert,
|
|
131
|
+
key: https.key,
|
|
132
|
+
passphrase: https.passphrase
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
liveUpdate = update;
|
|
136
|
+
middleware = createMiddleware({
|
|
137
|
+
server,
|
|
138
|
+
isHttps,
|
|
139
|
+
port
|
|
140
|
+
});
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
const importPath = node_path.resolve(distPath, `index-${compileCount}.js`);
|
|
145
|
+
await node_fs_promises.copyFile(outputPath, importPath);
|
|
146
|
+
const newServerOptions = (await import((0, node_url.pathToFileURL)(importPath).href)).default;
|
|
147
|
+
await node_fs_promises.unlink(importPath);
|
|
148
|
+
liveUpdate?.(newServerOptions);
|
|
149
|
+
} catch {
|
|
150
|
+
try {
|
|
151
|
+
await node_fs_promises.unlink(node_path.resolve(distPath, `index-${compileCount}.js`));
|
|
152
|
+
} catch {}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
api.onBeforeStartDevServer(({ server }) => {
|
|
156
|
+
port = server.port;
|
|
157
|
+
server.middlewares.use(async (req, res, next) => {
|
|
158
|
+
if (middleware === void 0) {
|
|
159
|
+
next();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
return middleware(req, res);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
exports.devPlugin = devPlugin;
|
|
170
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["getSsrTarget","VIRTUAL_ENTRY","builtinModules","Path","Fsp"],"sources":["../../../src/plugins/dev/index.ts"],"sourcesContent":["import type HTTP from \"node:http\";\n\nimport type {\n ModifyBundlerChainUtils,\n RsbuildConfig,\n RsbuildPlugin,\n RsbuildPluginAPI,\n Rspack,\n RspackChain,\n} from \"@rsbuild/core\";\nimport type {\n ResolvedBuildOptions,\n ResolvedDevOptions,\n ResolvedHttpsOptions,\n ResolvedOptions,\n} from \"@srvkit/common/@types/options/resolved\";\nimport type { Server, ServerOptions } from \"@srvkit/common/@types/server\";\nimport type { PackageJson } from \"@srvkit/common/functions/package/package-json\";\n\nimport * as Fsp from \"node:fs/promises\";\nimport { builtinModules } from \"node:module\";\nimport * as Path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\nimport { toHeaders } from \"@srvkit/common/functions/http/request/header\";\nimport { writeHttpResponse } from \"@srvkit/common/functions/http/response/write\";\nimport { getPackageJson } from \"@srvkit/common/functions/package/package-json\";\nimport { toPosix } from \"@srvkit/common/functions/path/posix\";\nimport { createLiveServer } from \"@srvkit/common/functions/server/live\";\n\nimport { VIRTUAL_ENTRY } from \"#/constants/path\";\nimport { getSsrTarget } from \"#/functions/ssr\";\n\ntype CreateMiddlewareOptions = {\n server: Server;\n isHttps: boolean;\n port: number;\n};\n\nconst createMiddleware = ({\n server,\n isHttps,\n port,\n}: CreateMiddlewareOptions) => {\n return async (\n req: HTTP.IncomingMessage,\n res: HTTP.ServerResponse,\n ): Promise<void> => {\n const protocol: string = `http${isHttps ? \"s\" : \"\"}`;\n\n const host: string = server.options.hostname ?? \"localhost\";\n\n const path: string = req.url ?? \"\";\n\n const url: URL = new URL(`${protocol}://${host}:${port}${path}`);\n\n const body: HTTP.IncomingMessage | undefined =\n req.method !== \"GET\" && req.method !== \"HEAD\" ? req : void 0;\n\n const request: Request = new Request(url, {\n method: req.method,\n headers: toHeaders(req.headers),\n // @ts-expect-error\n body,\n duplex: \"half\",\n });\n\n const response: Response = await server.fetch(request);\n\n await writeHttpResponse({\n response,\n httpResponse: res,\n });\n };\n};\n\ntype Middleware = ReturnType<typeof createMiddleware>;\n\nconst createDevVirtualEntryCode = (opts: ResolvedOptions): string => {\n let code: string = \"\";\n\n code += `import options from \"${toPosix(opts.entry)}\";`;\n code += `export default options;`;\n\n return code;\n};\n\nconst devPlugin = (opts: ResolvedOptions): RsbuildPlugin => {\n const dev: ResolvedDevOptions = opts.dev;\n const https: ResolvedHttpsOptions = opts.dev.https ?? {};\n const build: ResolvedBuildOptions = opts.build;\n\n const isHttps: boolean = https.cert !== void 0 && https.key !== void 0;\n\n const packageJson: PackageJson = getPackageJson(opts.cwd);\n\n return {\n name: \"srvkit:dev\",\n apply: \"serve\",\n async setup(api: RsbuildPluginAPI): Promise<void> {\n let middleware: Middleware | undefined;\n\n let liveUpdate: ((options: ServerOptions) => void) | undefined;\n\n let port: number;\n\n let compileCount: number = 0;\n\n const ssrTarget: Rspack.Target = getSsrTarget(opts.runtime);\n\n api.modifyRsbuildConfig(\n (\n config: RsbuildConfig,\n { mergeRsbuildConfig },\n ): RsbuildConfig => {\n const overrideConfig: RsbuildConfig = {\n source: {\n entry: {\n index: VIRTUAL_ENTRY,\n },\n },\n output: {\n target: \"node\",\n distPath: build.outputDir,\n copy: void 0,\n },\n dev: {\n writeToDisk: true,\n },\n server: {\n host: dev.host,\n port: dev.port,\n ...(https.cert !== void 0 && https.key !== void 0\n ? {\n https: {\n cert: https.cert,\n key: https.key,\n passphrase: https.passphrase,\n },\n }\n : {}),\n },\n };\n\n return mergeRsbuildConfig(config, overrideConfig);\n },\n );\n\n api.modifyBundlerChain(\n (\n chain: RspackChain,\n { rspack }: ModifyBundlerChainUtils,\n ): void => {\n // Add support for virtual modules\n chain\n .plugin(\"virtual-modules\")\n .use(rspack.experiments.VirtualModulesPlugin, [\n {\n [VIRTUAL_ENTRY]:\n createDevVirtualEntryCode(opts),\n },\n ]);\n },\n );\n\n api.modifyRspackConfig(\n (config, { mergeConfig }): Rspack.Configuration => {\n const isModule: boolean = packageJson.type === \"module\";\n\n const nodeExternals: (string | RegExp)[] = [\n ...builtinModules,\n /^node:/,\n ];\n\n const overrideConfig: Rspack.Configuration = {\n resolve: {\n /** @see https://rspack.rs/config/resolve#extend-default-value */\n conditionNames: [\n opts.runtime,\n \"...\", // Default values\n ],\n },\n output: {\n filename: build.outputFile,\n ...(isModule\n ? {\n module: true,\n }\n : {}),\n },\n target: ssrTarget,\n node: {\n __dirname: false,\n __filename: false,\n },\n };\n\n // bundle: external\n\n if (build.bundle === \"external\") {\n const depNames: string[] = [\n ...Object.keys(packageJson.dependencies ?? {}),\n ...Object.keys(packageJson.peerDependencies ?? {}),\n ...Object.keys(\n packageJson.optionalDependencies ?? {},\n ),\n ];\n\n const depExternals: RegExp[] = depNames.map(\n (depName: string): RegExp =>\n new RegExp(\n `^${depName.replace(/[.*+?^${}()|[\\]\\\\]/g, String.raw`\\$&`)}([\\\\/]|$)`,\n ),\n );\n\n overrideConfig.externals = [\n ...nodeExternals,\n ...depExternals,\n ];\n\n overrideConfig.externalsType = isModule\n ? \"module-import\"\n : \"commonjs\";\n }\n\n // bundle: standalone\n\n if (build.bundle === \"standalone\") {\n overrideConfig.externals = nodeExternals;\n }\n\n return mergeConfig(config, overrideConfig);\n },\n );\n\n api.onAfterDevCompile(async ({ isFirstCompile }): Promise<void> => {\n const distPath: string = api.context.distPath;\n\n const outputPath: string = Path.resolve(distPath, \"index.js\");\n\n compileCount++;\n\n // Initial compile\n\n if (isFirstCompile) {\n const serverOptions: ServerOptions = (\n await import(pathToFileURL(outputPath).href)\n ).default;\n\n const { server, update } = createLiveServer({\n gracefulShutdown: false,\n ...serverOptions,\n manual: true,\n hostname: dev.host,\n port: dev.port,\n tls: {\n cert: https.cert,\n key: https.key,\n passphrase: https.passphrase,\n },\n });\n\n liveUpdate = update;\n\n middleware = createMiddleware({\n server,\n isHttps,\n port,\n });\n\n return void 0;\n }\n\n // Live update\n\n try {\n const importPath: string = Path.resolve(\n distPath,\n `index-${compileCount}.js`,\n );\n\n await Fsp.copyFile(outputPath, importPath);\n\n const newServerOptions: ServerOptions = (\n await import(pathToFileURL(importPath).href)\n ).default;\n\n await Fsp.unlink(importPath);\n\n liveUpdate?.(newServerOptions);\n } catch {\n // Keep old handler running on error\n\n try {\n await Fsp.unlink(\n Path.resolve(distPath, `index-${compileCount}.js`),\n );\n } catch {}\n }\n });\n\n api.onBeforeStartDevServer(({ server }): void => {\n port = server.port;\n\n server.middlewares.use(\n async (\n req: HTTP.IncomingMessage,\n res: HTTP.ServerResponse,\n next: () => void,\n ): Promise<void> => {\n if (middleware === void 0) {\n next();\n\n return void 0;\n }\n\n return middleware(req, res);\n },\n );\n });\n },\n };\n};\n\nexport { devPlugin };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAM,oBAAoB,EACtB,QACA,SACA,WAC2B;CAC3B,OAAO,OACH,KACA,QACgB;EAChB,MAAM,WAAmB,OAAO,UAAU,MAAM;EAEhD,MAAM,OAAe,OAAO,QAAQ,YAAY;EAEhD,MAAM,OAAe,IAAI,OAAO;EAEhC,MAAM,MAAW,IAAI,IAAI,GAAG,SAAS,KAAK,KAAK,GAAG,OAAO,MAAM;EAE/D,MAAM,OACF,IAAI,WAAW,SAAS,IAAI,WAAW,SAAS,MAAM,KAAK;EAE/D,MAAM,UAAmB,IAAI,QAAQ,KAAK;GACtC,QAAQ,IAAI;GACZ,qEAAmB,IAAI,OAAO;GAE9B;GACA,QAAQ;EACZ,CAA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KACA,MAAM,aAAqBA,UAAK,QAC5B,UACA,SAAS,aAAa,IAC1B;KAEA,MAAMC,iBAAI,SAAS,YAAY,UAAU;KAEzC,MAAM,oBACF,MAAM,mCAAqB,UAAU,CAAC,CAAC,MAAK,CAC9C;KAEF,MAAMA,iBAAI,OAAO,UAAU;KAE3B,aAAa,gBAAgB;IACjC,QAAQ;KAGJ,IAAI;MACA,MAAMA,iBAAI,OACND,UAAK,QAAQ,UAAU,SAAS,aAAa,IAAI,CACrD;KACJ,QAAQ,CAAC;IACb;GACJ,CAAC;GAED,IAAI,wBAAwB,EAAE,aAAmB;IAC7C,OAAO,OAAO;IAEd,OAAO,YAAY,IACf,OACI,KACA,KACA,SACgB;KAChB,IAAI,eAAe,KAAK,GAAG;MACvB,KAAK;MAEL;KACJ;KAEA,OAAO,WAAW,KAAK,GAAG;IAC9B,CACJ;GACJ,CAAC;EACL;CACJ;AACJ"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
9
|
+
import { VIRTUAL_ENTRY } from "../../constants/path.mjs";
|
|
10
|
+
import { getSsrTarget } from "../../functions/ssr.mjs";
|
|
11
|
+
import { builtinModules } from "node:module";
|
|
12
|
+
import { getPackageJson } from "@srvkit/common/functions/package/package-json";
|
|
13
|
+
import * as Fsp from "node:fs/promises";
|
|
14
|
+
import * as Path from "node:path";
|
|
15
|
+
import { pathToFileURL } from "node:url";
|
|
16
|
+
import { toHeaders } from "@srvkit/common/functions/http/request/header";
|
|
17
|
+
import { writeHttpResponse } from "@srvkit/common/functions/http/response/write";
|
|
18
|
+
import { toPosix } from "@srvkit/common/functions/path/posix";
|
|
19
|
+
import { createLiveServer } from "@srvkit/common/functions/server/live";
|
|
20
|
+
|
|
21
|
+
const createMiddleware = ({ server, isHttps, port }) => {
|
|
22
|
+
return async (req, res) => {
|
|
23
|
+
const protocol = `http${isHttps ? "s" : ""}`;
|
|
24
|
+
const host = server.options.hostname ?? "localhost";
|
|
25
|
+
const path = req.url ?? "";
|
|
26
|
+
const url = new URL(`${protocol}://${host}:${port}${path}`);
|
|
27
|
+
const body = req.method !== "GET" && req.method !== "HEAD" ? req : void 0;
|
|
28
|
+
const request = new Request(url, {
|
|
29
|
+
method: req.method,
|
|
30
|
+
headers: toHeaders(req.headers),
|
|
31
|
+
body,
|
|
32
|
+
duplex: "half"
|
|
33
|
+
});
|
|
34
|
+
await writeHttpResponse({
|
|
35
|
+
response: await server.fetch(request),
|
|
36
|
+
httpResponse: res
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
const createDevVirtualEntryCode = (opts) => {
|
|
41
|
+
let code = "";
|
|
42
|
+
code += `import options from "${toPosix(opts.entry)}";`;
|
|
43
|
+
code += `export default options;`;
|
|
44
|
+
return code;
|
|
45
|
+
};
|
|
46
|
+
const devPlugin = (opts) => {
|
|
47
|
+
const dev = opts.dev;
|
|
48
|
+
const https = opts.dev.https ?? {};
|
|
49
|
+
const build = opts.build;
|
|
50
|
+
const isHttps = https.cert !== void 0 && https.key !== void 0;
|
|
51
|
+
const packageJson = getPackageJson(opts.cwd);
|
|
52
|
+
return {
|
|
53
|
+
name: "srvkit:dev",
|
|
54
|
+
apply: "serve",
|
|
55
|
+
async setup(api) {
|
|
56
|
+
let middleware;
|
|
57
|
+
let liveUpdate;
|
|
58
|
+
let port;
|
|
59
|
+
let compileCount = 0;
|
|
60
|
+
const ssrTarget = getSsrTarget(opts.runtime);
|
|
61
|
+
api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {
|
|
62
|
+
return mergeRsbuildConfig(config, {
|
|
63
|
+
source: { entry: { index: VIRTUAL_ENTRY } },
|
|
64
|
+
output: {
|
|
65
|
+
target: "node",
|
|
66
|
+
distPath: build.outputDir,
|
|
67
|
+
copy: void 0
|
|
68
|
+
},
|
|
69
|
+
dev: { writeToDisk: true },
|
|
70
|
+
server: {
|
|
71
|
+
host: dev.host,
|
|
72
|
+
port: dev.port,
|
|
73
|
+
...https.cert !== void 0 && https.key !== void 0 ? { https: {
|
|
74
|
+
cert: https.cert,
|
|
75
|
+
key: https.key,
|
|
76
|
+
passphrase: https.passphrase
|
|
77
|
+
} } : {}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
api.modifyBundlerChain((chain, { rspack }) => {
|
|
82
|
+
chain.plugin("virtual-modules").use(rspack.experiments.VirtualModulesPlugin, [{ [VIRTUAL_ENTRY]: createDevVirtualEntryCode(opts) }]);
|
|
83
|
+
});
|
|
84
|
+
api.modifyRspackConfig((config, { mergeConfig }) => {
|
|
85
|
+
const isModule = packageJson.type === "module";
|
|
86
|
+
const nodeExternals = [...builtinModules, /^node:/];
|
|
87
|
+
const overrideConfig = {
|
|
88
|
+
resolve: {
|
|
89
|
+
/** @see https://rspack.rs/config/resolve#extend-default-value */
|
|
90
|
+
conditionNames: [opts.runtime, "..."] },
|
|
91
|
+
output: {
|
|
92
|
+
filename: build.outputFile,
|
|
93
|
+
...isModule ? { module: true } : {}
|
|
94
|
+
},
|
|
95
|
+
target: ssrTarget,
|
|
96
|
+
node: {
|
|
97
|
+
__dirname: false,
|
|
98
|
+
__filename: false
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
if (build.bundle === "external") {
|
|
102
|
+
const depExternals = [
|
|
103
|
+
...Object.keys(packageJson.dependencies ?? {}),
|
|
104
|
+
...Object.keys(packageJson.peerDependencies ?? {}),
|
|
105
|
+
...Object.keys(packageJson.optionalDependencies ?? {})
|
|
106
|
+
].map((depName) => new RegExp(`^${depName.replace(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`)}([\\/]|$)`));
|
|
107
|
+
overrideConfig.externals = [...nodeExternals, ...depExternals];
|
|
108
|
+
overrideConfig.externalsType = isModule ? "module-import" : "commonjs";
|
|
109
|
+
}
|
|
110
|
+
if (build.bundle === "standalone") overrideConfig.externals = nodeExternals;
|
|
111
|
+
return mergeConfig(config, overrideConfig);
|
|
112
|
+
});
|
|
113
|
+
api.onAfterDevCompile(async ({ isFirstCompile }) => {
|
|
114
|
+
const distPath = api.context.distPath;
|
|
115
|
+
const outputPath = Path.resolve(distPath, "index.js");
|
|
116
|
+
compileCount++;
|
|
117
|
+
if (isFirstCompile) {
|
|
118
|
+
const serverOptions = (await import(pathToFileURL(outputPath).href)).default;
|
|
119
|
+
const { server, update } = createLiveServer({
|
|
120
|
+
gracefulShutdown: false,
|
|
121
|
+
...serverOptions,
|
|
122
|
+
manual: true,
|
|
123
|
+
hostname: dev.host,
|
|
124
|
+
port: dev.port,
|
|
125
|
+
tls: {
|
|
126
|
+
cert: https.cert,
|
|
127
|
+
key: https.key,
|
|
128
|
+
passphrase: https.passphrase
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
liveUpdate = update;
|
|
132
|
+
middleware = createMiddleware({
|
|
133
|
+
server,
|
|
134
|
+
isHttps,
|
|
135
|
+
port
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const importPath = Path.resolve(distPath, `index-${compileCount}.js`);
|
|
141
|
+
await Fsp.copyFile(outputPath, importPath);
|
|
142
|
+
const newServerOptions = (await import(pathToFileURL(importPath).href)).default;
|
|
143
|
+
await Fsp.unlink(importPath);
|
|
144
|
+
liveUpdate?.(newServerOptions);
|
|
145
|
+
} catch {
|
|
146
|
+
try {
|
|
147
|
+
await Fsp.unlink(Path.resolve(distPath, `index-${compileCount}.js`));
|
|
148
|
+
} catch {}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
api.onBeforeStartDevServer(({ server }) => {
|
|
152
|
+
port = server.port;
|
|
153
|
+
server.middlewares.use(async (req, res, next) => {
|
|
154
|
+
if (middleware === void 0) {
|
|
155
|
+
next();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
return middleware(req, res);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export { devPlugin };
|
|
166
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugins/dev/index.ts"],"sourcesContent":["import type HTTP from \"node:http\";\n\nimport type {\n ModifyBundlerChainUtils,\n RsbuildConfig,\n RsbuildPlugin,\n RsbuildPluginAPI,\n Rspack,\n RspackChain,\n} from \"@rsbuild/core\";\nimport type {\n ResolvedBuildOptions,\n ResolvedDevOptions,\n ResolvedHttpsOptions,\n ResolvedOptions,\n} from \"@srvkit/common/@types/options/resolved\";\nimport type { Server, ServerOptions } from \"@srvkit/common/@types/server\";\nimport type { PackageJson } from \"@srvkit/common/functions/package/package-json\";\n\nimport * as Fsp from \"node:fs/promises\";\nimport { builtinModules } from \"node:module\";\nimport * as Path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\nimport { toHeaders } from \"@srvkit/common/functions/http/request/header\";\nimport { writeHttpResponse } from \"@srvkit/common/functions/http/response/write\";\nimport { getPackageJson } from \"@srvkit/common/functions/package/package-json\";\nimport { toPosix } from \"@srvkit/common/functions/path/posix\";\nimport { createLiveServer } from \"@srvkit/common/functions/server/live\";\n\nimport { VIRTUAL_ENTRY } from \"#/constants/path\";\nimport { getSsrTarget } from \"#/functions/ssr\";\n\ntype CreateMiddlewareOptions = {\n server: Server;\n isHttps: boolean;\n port: number;\n};\n\nconst createMiddleware = ({\n server,\n isHttps,\n port,\n}: CreateMiddlewareOptions) => {\n return async (\n req: HTTP.IncomingMessage,\n res: HTTP.ServerResponse,\n ): Promise<void> => {\n const protocol: string = `http${isHttps ? \"s\" : \"\"}`;\n\n const host: string = server.options.hostname ?? \"localhost\";\n\n const path: string = req.url ?? \"\";\n\n const url: URL = new URL(`${protocol}://${host}:${port}${path}`);\n\n const body: HTTP.IncomingMessage | undefined =\n req.method !== \"GET\" && req.method !== \"HEAD\" ? req : void 0;\n\n const request: Request = new Request(url, {\n method: req.method,\n headers: toHeaders(req.headers),\n // @ts-expect-error\n body,\n duplex: \"half\",\n });\n\n const response: Response = await server.fetch(request);\n\n await writeHttpResponse({\n response,\n httpResponse: res,\n });\n };\n};\n\ntype Middleware = ReturnType<typeof createMiddleware>;\n\nconst createDevVirtualEntryCode = (opts: ResolvedOptions): string => {\n let code: string = \"\";\n\n code += `import options from \"${toPosix(opts.entry)}\";`;\n code += `export default options;`;\n\n return code;\n};\n\nconst devPlugin = (opts: ResolvedOptions): RsbuildPlugin => {\n const dev: ResolvedDevOptions = opts.dev;\n const https: ResolvedHttpsOptions = opts.dev.https ?? {};\n const build: ResolvedBuildOptions = opts.build;\n\n const isHttps: boolean = https.cert !== void 0 && https.key !== void 0;\n\n const packageJson: PackageJson = getPackageJson(opts.cwd);\n\n return {\n name: \"srvkit:dev\",\n apply: \"serve\",\n async setup(api: RsbuildPluginAPI): Promise<void> {\n let middleware: Middleware | undefined;\n\n let liveUpdate: ((options: ServerOptions) => void) | undefined;\n\n let port: number;\n\n let compileCount: number = 0;\n\n const ssrTarget: Rspack.Target = getSsrTarget(opts.runtime);\n\n api.modifyRsbuildConfig(\n (\n config: RsbuildConfig,\n { mergeRsbuildConfig },\n ): RsbuildConfig => {\n const overrideConfig: RsbuildConfig = {\n source: {\n entry: {\n index: VIRTUAL_ENTRY,\n },\n },\n output: {\n target: \"node\",\n distPath: build.outputDir,\n copy: void 0,\n },\n dev: {\n writeToDisk: true,\n },\n server: {\n host: dev.host,\n port: dev.port,\n ...(https.cert !== void 0 && https.key !== void 0\n ? {\n https: {\n cert: https.cert,\n key: https.key,\n passphrase: https.passphrase,\n },\n }\n : {}),\n },\n };\n\n return mergeRsbuildConfig(config, overrideConfig);\n },\n );\n\n api.modifyBundlerChain(\n (\n chain: RspackChain,\n { rspack }: ModifyBundlerChainUtils,\n ): void => {\n // Add support for virtual modules\n chain\n .plugin(\"virtual-modules\")\n .use(rspack.experiments.VirtualModulesPlugin, [\n {\n [VIRTUAL_ENTRY]:\n createDevVirtualEntryCode(opts),\n },\n ]);\n },\n );\n\n api.modifyRspackConfig(\n (config, { mergeConfig }): Rspack.Configuration => {\n const isModule: boolean = packageJson.type === \"module\";\n\n const nodeExternals: (string | RegExp)[] = [\n ...builtinModules,\n /^node:/,\n ];\n\n const overrideConfig: Rspack.Configuration = {\n resolve: {\n /** @see https://rspack.rs/config/resolve#extend-default-value */\n conditionNames: [\n opts.runtime,\n \"...\", // Default values\n ],\n },\n output: {\n filename: build.outputFile,\n ...(isModule\n ? {\n module: true,\n }\n : {}),\n },\n target: ssrTarget,\n node: {\n __dirname: false,\n __filename: false,\n },\n };\n\n // bundle: external\n\n if (build.bundle === \"external\") {\n const depNames: string[] = [\n ...Object.keys(packageJson.dependencies ?? {}),\n ...Object.keys(packageJson.peerDependencies ?? {}),\n ...Object.keys(\n packageJson.optionalDependencies ?? {},\n ),\n ];\n\n const depExternals: RegExp[] = depNames.map(\n (depName: string): RegExp =>\n new RegExp(\n `^${depName.replace(/[.*+?^${}()|[\\]\\\\]/g, String.raw`\\$&`)}([\\\\/]|$)`,\n ),\n );\n\n overrideConfig.externals = [\n ...nodeExternals,\n ...depExternals,\n ];\n\n overrideConfig.externalsType = isModule\n ? \"module-import\"\n : \"commonjs\";\n }\n\n // bundle: standalone\n\n if (build.bundle === \"standalone\") {\n overrideConfig.externals = nodeExternals;\n }\n\n return mergeConfig(config, overrideConfig);\n },\n );\n\n api.onAfterDevCompile(async ({ isFirstCompile }): Promise<void> => {\n const distPath: string = api.context.distPath;\n\n const outputPath: string = Path.resolve(distPath, \"index.js\");\n\n compileCount++;\n\n // Initial compile\n\n if (isFirstCompile) {\n const serverOptions: ServerOptions = (\n await import(pathToFileURL(outputPath).href)\n ).default;\n\n const { server, update } = createLiveServer({\n gracefulShutdown: false,\n ...serverOptions,\n manual: true,\n hostname: dev.host,\n port: dev.port,\n tls: {\n cert: https.cert,\n key: https.key,\n passphrase: https.passphrase,\n },\n });\n\n liveUpdate = update;\n\n middleware = createMiddleware({\n server,\n isHttps,\n port,\n });\n\n return void 0;\n }\n\n // Live update\n\n try {\n const importPath: string = Path.resolve(\n distPath,\n `index-${compileCount}.js`,\n );\n\n await Fsp.copyFile(outputPath, importPath);\n\n const newServerOptions: ServerOptions = (\n await import(pathToFileURL(importPath).href)\n ).default;\n\n await Fsp.unlink(importPath);\n\n liveUpdate?.(newServerOptions);\n } catch {\n // Keep old handler running on error\n\n try {\n await Fsp.unlink(\n Path.resolve(distPath, `index-${compileCount}.js`),\n );\n } catch {}\n }\n });\n\n api.onBeforeStartDevServer(({ server }): void => {\n port = server.port;\n\n server.middlewares.use(\n async (\n req: HTTP.IncomingMessage,\n res: HTTP.ServerResponse,\n next: () => void,\n ): Promise<void> => {\n if (middleware === void 0) {\n next();\n\n return void 0;\n }\n\n return middleware(req, res);\n },\n );\n });\n },\n };\n};\n\nexport { devPlugin };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuCA,MAAM,oBAAoB,EACtB,QACA,SACA,WAC2B;CAC3B,OAAO,OACH,KACA,QACgB;EAChB,MAAM,WAAmB,OAAO,UAAU,MAAM;EAEhD,MAAM,OAAe,OAAO,QAAQ,YAAY;EAEhD,MAAM,OAAe,IAAI,OAAO;EAEhC,MAAM,MAAW,IAAI,IAAI,GAAG,SAAS,KAAK,KAAK,GAAG,OAAO,MAAM;EAE/D,MAAM,OACF,IAAI,WAAW,SAAS,IAAI,WAAW,SAAS,MAAM,KAAK;EAE/D,MAAM,UAAmB,IAAI,QAAQ,KAAK;GACtC,QAAQ,IAAI;GACZ,SAAS,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aAAa,iBAAiB;MAC1B;MACA;MACA;KACJ,CAAC;KAED;IACJ;IAIA,IAAI;KACA,MAAM,aAAqB,KAAK,QAC5B,UACA,SAAS,aAAa,IAC1B;KAEA,MAAM,IAAI,SAAS,YAAY,UAAU;KAEzC,MAAM,oBACF,MAAM,OAAO,cAAc,UAAU,CAAC,CAAC,MAAK,CAC9C;KAEF,MAAM,IAAI,OAAO,UAAU;KAE3B,aAAa,gBAAgB;IACjC,QAAQ;KAGJ,IAAI;MACA,MAAM,IAAI,OACN,KAAK,QAAQ,UAAU,SAAS,aAAa,IAAI,CACrD;KACJ,QAAQ,CAAC;IACb;GACJ,CAAC;GAED,IAAI,wBAAwB,EAAE,aAAmB;IAC7C,OAAO,OAAO;IAEd,OAAO,YAAY,IACf,OACI,KACA,KACA,SACgB;KAChB,IAAI,eAAe,KAAK,GAAG;MACvB,KAAK;MAEL;KACJ;KAEA,OAAO,WAAW,KAAK,GAAG;IAC9B,CACJ;GACJ,CAAC;EACL;CACJ;AACJ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import __tsdown_shims_path from 'node:path';
|
|
2
|
+
import __tsdown_shims_url from 'node:url';
|
|
3
|
+
import { Options } from "@srvkit/common/@types/options/default";
|
|
4
|
+
import { RsbuildPlugin } from "@rsbuild/core";
|
|
5
|
+
declare const plugin: (options?: Options) => RsbuildPlugin[];
|
|
6
|
+
export { plugin };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
9
|
+
const require_plugins_build_index = require('./build/index.js');
|
|
10
|
+
const require_plugins_copy_index = require('./copy/index.js');
|
|
11
|
+
const require_plugins_dev_index = require('./dev/index.js');
|
|
12
|
+
let _srvkit_common_functions_options_resolve = require("@srvkit/common/functions/options/resolve");
|
|
13
|
+
|
|
14
|
+
const plugin = (options) => {
|
|
15
|
+
const opts = (0, _srvkit_common_functions_options_resolve.resolveOptions)(options);
|
|
16
|
+
return [
|
|
17
|
+
require_plugins_dev_index.devPlugin({ ...opts }),
|
|
18
|
+
require_plugins_build_index.buildPlugin({ ...opts }),
|
|
19
|
+
...require_plugins_copy_index.copyPlugin({ ...opts })
|
|
20
|
+
];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.plugin = plugin;
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["devPlugin","buildPlugin","copyPlugin"],"sources":["../../src/plugins/index.ts"],"sourcesContent":["import type { RsbuildPlugin } from \"@rsbuild/core\";\nimport type { Options } from \"@srvkit/common/@types/options/default\";\nimport type { ResolvedOptions } from \"@srvkit/common/@types/options/resolved\";\n\nimport { resolveOptions } from \"@srvkit/common/functions/options/resolve\";\n\nimport { buildPlugin } from \"#/plugins/build\";\nimport { copyPlugin } from \"#/plugins/copy\";\nimport { devPlugin } from \"#/plugins/dev\";\n\nconst plugin = (options?: Options): RsbuildPlugin[] => {\n const opts: ResolvedOptions = resolveOptions(options);\n\n return [\n devPlugin({\n ...opts,\n }),\n buildPlugin({\n ...opts,\n }),\n ...copyPlugin({\n ...opts,\n }),\n ];\n};\n\nexport { plugin };\n"],"mappings":";;;;;;;;;;;;;AAUA,MAAM,UAAU,YAAuC;CACnD,MAAM,oEAAuC,OAAO;CAEpD,OAAO;EACHA,oCAAU,EACN,GAAG,KACP,CAAC;EACDC,wCAAY,EACR,GAAG,KACP,CAAC;EACD,GAAGC,sCAAW,EACV,GAAG,KACP,CAAC;CACL;AACJ"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
9
|
+
import { buildPlugin } from "./build/index.mjs";
|
|
10
|
+
import { copyPlugin } from "./copy/index.mjs";
|
|
11
|
+
import { devPlugin } from "./dev/index.mjs";
|
|
12
|
+
import { resolveOptions } from "@srvkit/common/functions/options/resolve";
|
|
13
|
+
|
|
14
|
+
const plugin = (options) => {
|
|
15
|
+
const opts = resolveOptions(options);
|
|
16
|
+
return [
|
|
17
|
+
devPlugin({ ...opts }),
|
|
18
|
+
buildPlugin({ ...opts }),
|
|
19
|
+
...copyPlugin({ ...opts })
|
|
20
|
+
];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { plugin };
|
|
24
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/plugins/index.ts"],"sourcesContent":["import type { RsbuildPlugin } from \"@rsbuild/core\";\nimport type { Options } from \"@srvkit/common/@types/options/default\";\nimport type { ResolvedOptions } from \"@srvkit/common/@types/options/resolved\";\n\nimport { resolveOptions } from \"@srvkit/common/functions/options/resolve\";\n\nimport { buildPlugin } from \"#/plugins/build\";\nimport { copyPlugin } from \"#/plugins/copy\";\nimport { devPlugin } from \"#/plugins/dev\";\n\nconst plugin = (options?: Options): RsbuildPlugin[] => {\n const opts: ResolvedOptions = resolveOptions(options);\n\n return [\n devPlugin({\n ...opts,\n }),\n buildPlugin({\n ...opts,\n }),\n ...copyPlugin({\n ...opts,\n }),\n ];\n};\n\nexport { plugin };\n"],"mappings":";;;;;;;;;;;;;AAUA,MAAM,UAAU,YAAuC;CACnD,MAAM,OAAwB,eAAe,OAAO;CAEpD,OAAO;EACH,UAAU,EACN,GAAG,KACP,CAAC;EACD,YAAY,EACR,GAAG,KACP,CAAC;EACD,GAAG,WAAW,EACV,GAAG,KACP,CAAC;CACL;AACJ"}
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
10
|
+
let _srvkit_common_runtime = require("@srvkit/common/runtime");
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, 'serve', {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _srvkit_common_runtime.serve;
|
|
16
|
+
}
|
|
17
|
+
});
|
package/dist/runtime.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
9
|
+
import { serve } from "@srvkit/common/runtime";
|
|
10
|
+
|
|
11
|
+
export { serve };
|
package/package.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@srvkit/rsbuild",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A toolkit for building JavaScript server applications",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"srvkit",
|
|
7
|
+
"rsbuild-plugin",
|
|
8
|
+
"rsbuild",
|
|
9
|
+
"plugin",
|
|
10
|
+
"srvx",
|
|
11
|
+
"ts",
|
|
12
|
+
"typescript",
|
|
13
|
+
"js",
|
|
14
|
+
"javascript"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/srvkit/srvkit",
|
|
17
|
+
"bugs": "https://github.com/srvkit/srvkit/issues",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/srvkit/srvkit.git",
|
|
21
|
+
"directory": "packages/rsbuild"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"author": {
|
|
25
|
+
"name": "Alpheus",
|
|
26
|
+
"email": "contact@alphe.us"
|
|
27
|
+
},
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.mjs",
|
|
32
|
+
"require": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./node": {
|
|
35
|
+
"types": "./dist/node.d.ts",
|
|
36
|
+
"import": "./dist/node.mjs",
|
|
37
|
+
"require": "./dist/node.js"
|
|
38
|
+
},
|
|
39
|
+
"./plugin": {
|
|
40
|
+
"types": "./dist/plugin.d.ts",
|
|
41
|
+
"import": "./dist/plugin.mjs",
|
|
42
|
+
"require": "./dist/plugin.js"
|
|
43
|
+
},
|
|
44
|
+
"./runtime": {
|
|
45
|
+
"types": "./dist/runtime.d.ts",
|
|
46
|
+
"import": "./dist/runtime.mjs",
|
|
47
|
+
"require": "./dist/runtime.js"
|
|
48
|
+
},
|
|
49
|
+
"./plugins/dev": {
|
|
50
|
+
"types": "./dist/plugins/dev/index.d.ts",
|
|
51
|
+
"import": "./dist/plugins/dev/index.mjs",
|
|
52
|
+
"require": "./dist/plugins/dev/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./plugins/build": {
|
|
55
|
+
"types": "./dist/plugins/build/index.d.ts",
|
|
56
|
+
"import": "./dist/plugins/build/index.mjs",
|
|
57
|
+
"require": "./dist/plugins/build/index.js"
|
|
58
|
+
},
|
|
59
|
+
"./plugins/copy": {
|
|
60
|
+
"types": "./dist/plugins/copy/index.d.ts",
|
|
61
|
+
"import": "./dist/plugins/copy/index.mjs",
|
|
62
|
+
"require": "./dist/plugins/copy/index.js"
|
|
63
|
+
},
|
|
64
|
+
"./package.json": "./package.json"
|
|
65
|
+
},
|
|
66
|
+
"main": "./dist/index.js",
|
|
67
|
+
"module": "./dist/index.mjs",
|
|
68
|
+
"types": "./dist/index.d.ts",
|
|
69
|
+
"files": [
|
|
70
|
+
"dist"
|
|
71
|
+
],
|
|
72
|
+
"dependencies": {
|
|
73
|
+
"@srvkit/common": "~0.1.0"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@rsbuild/core": "2.0.0"
|
|
77
|
+
},
|
|
78
|
+
"peerDependencies": {
|
|
79
|
+
"@rsbuild/core": "^2.0.0"
|
|
80
|
+
},
|
|
81
|
+
"peerDependenciesMeta": {
|
|
82
|
+
"@rsbuild/core": {
|
|
83
|
+
"optional": true
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|