@chuckcchen/vite-plugin 0.0.2 → 0.0.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/dist/helpers.d.ts +40 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +166 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +6 -75
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -56
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helper functions for EdgeOne adapters
|
|
3
|
+
*/
|
|
4
|
+
import type { RouteInfo, MetaConfig, Logger } from "./types.js";
|
|
5
|
+
/** Detect config file from candidate list */
|
|
6
|
+
export declare function detectConfigFile(projectRoot: string, patterns: string[]): Promise<string | null>;
|
|
7
|
+
/** Dynamically import config file */
|
|
8
|
+
export declare function loadConfigFile<T = unknown>(configPath: string): Promise<T | null>;
|
|
9
|
+
/** Create default meta configuration */
|
|
10
|
+
export declare function createDefaultMeta(routes: RouteInfo[], options?: {
|
|
11
|
+
isSSR?: boolean;
|
|
12
|
+
has404?: boolean;
|
|
13
|
+
}): MetaConfig;
|
|
14
|
+
/** Node.js IncomingMessage to Web Request converter code */
|
|
15
|
+
export declare const NODE_REQUEST_CONVERTER_CODE: string;
|
|
16
|
+
/** Server wrapper generator options */
|
|
17
|
+
export interface ServerWrapperGeneratorOptions {
|
|
18
|
+
serverEntryPath: string;
|
|
19
|
+
handlerSetup?: string;
|
|
20
|
+
handlerCall: string;
|
|
21
|
+
imports?: string;
|
|
22
|
+
needsNodeRequestConversion?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** Generate server wrapper code */
|
|
25
|
+
export declare function generateServerWrapperCode(options: ServerWrapperGeneratorOptions): Promise<string>;
|
|
26
|
+
/** Normalize route path */
|
|
27
|
+
export declare function normalizeRoutePath(routePath: string): string;
|
|
28
|
+
/** Convert route path to regex format */
|
|
29
|
+
export declare function routePathToRegex(routePath: string): string;
|
|
30
|
+
/** Detect server entry file */
|
|
31
|
+
export declare function detectServerEntry(serverDir: string, candidates?: string[]): Promise<string | null>;
|
|
32
|
+
/** Detect build directory */
|
|
33
|
+
export declare function detectBuildDir(projectRoot: string, candidates: string[]): Promise<string | null>;
|
|
34
|
+
/** Log build artifacts info */
|
|
35
|
+
export declare function logBuildArtifacts(logger: Logger, adapterName: string, artifacts: {
|
|
36
|
+
clientDir?: string | null;
|
|
37
|
+
serverDir?: string | null;
|
|
38
|
+
serverEntry?: string | null;
|
|
39
|
+
}): void;
|
|
40
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGhE,6CAA6C;AAC7C,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAQxB;AAED,qCAAqC;AACrC,wBAAsB,cAAc,CAAC,CAAC,GAAG,OAAO,EAC9C,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAQnB;AAED,wCAAwC;AACxC,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,EAAE,EACnB,OAAO,GAAE;IACP,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;CACb,GACL,UAAU,CAeZ;AAED,4DAA4D;AAC5D,eAAO,MAAM,2BAA2B,QA8BhC,CAAC;AAET,uCAAuC;AACvC,MAAM,WAAW,6BAA6B;IAC5C,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0BAA0B,CAAC,EAAE,OAAO,CAAC;CACtC;AAED,mCAAmC;AACnC,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,MAAM,CAAC,CA+CjB;AAED,2BAA2B;AAC3B,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAY5D;AAED,yCAAyC;AACzC,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAc1D;AAED,+BAA+B;AAC/B,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,MAAM,EACjB,UAAU,GAAE,MAAM,EAAqD,GACtE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAQxB;AAED,6BAA6B;AAC7B,wBAAsB,cAAc,CAClC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAAE,GACnB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAQxB;AAED,+BAA+B;AAC/B,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE;IACT,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,GACA,IAAI,CAON"}
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helper functions for EdgeOne adapters
|
|
3
|
+
*/
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { pathToFileURL } from "url";
|
|
6
|
+
import { pathExists, readFile } from "./utils.js";
|
|
7
|
+
/** Detect config file from candidate list */
|
|
8
|
+
export async function detectConfigFile(projectRoot, patterns) {
|
|
9
|
+
for (const pattern of patterns) {
|
|
10
|
+
const fullPath = path.join(projectRoot, pattern);
|
|
11
|
+
if (await pathExists(fullPath)) {
|
|
12
|
+
return fullPath;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
/** Dynamically import config file */
|
|
18
|
+
export async function loadConfigFile(configPath) {
|
|
19
|
+
try {
|
|
20
|
+
const fileUrl = pathToFileURL(configPath).href;
|
|
21
|
+
const module = await import(`${fileUrl}?t=${Date.now()}`);
|
|
22
|
+
return module.default;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Create default meta configuration */
|
|
29
|
+
export function createDefaultMeta(routes, options = {}) {
|
|
30
|
+
const { isSSR = false, has404 = false } = options;
|
|
31
|
+
return {
|
|
32
|
+
conf: {
|
|
33
|
+
headers: [],
|
|
34
|
+
redirects: [],
|
|
35
|
+
rewrites: [],
|
|
36
|
+
caches: [],
|
|
37
|
+
has404,
|
|
38
|
+
ssr404: isSSR && !has404,
|
|
39
|
+
},
|
|
40
|
+
has404,
|
|
41
|
+
frameworkRoutes: routes,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Node.js IncomingMessage to Web Request converter code */
|
|
45
|
+
export const NODE_REQUEST_CONVERTER_CODE = `
|
|
46
|
+
function nodeRequestToWebRequest(nodeReq) {
|
|
47
|
+
const protocol = nodeReq.connection?.encrypted ? 'https' : 'http';
|
|
48
|
+
const host = nodeReq.headers.host || 'localhost';
|
|
49
|
+
const url = \`\${protocol}://\${host}\${nodeReq.url}\`;
|
|
50
|
+
|
|
51
|
+
// 转换请求头
|
|
52
|
+
const headers = new Headers();
|
|
53
|
+
for (const [key, value] of Object.entries(nodeReq.headers)) {
|
|
54
|
+
if (value) {
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
value.forEach(v => headers.append(key, v));
|
|
57
|
+
} else {
|
|
58
|
+
headers.set(key, value);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const init = {
|
|
64
|
+
method: nodeReq.method,
|
|
65
|
+
headers: headers,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// 非 GET/HEAD 请求添加请求体
|
|
69
|
+
if (nodeReq.method !== 'GET' && nodeReq.method !== 'HEAD') {
|
|
70
|
+
init.body = nodeReq;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return new Request(url, init);
|
|
74
|
+
}
|
|
75
|
+
`.trim();
|
|
76
|
+
/** Generate server wrapper code */
|
|
77
|
+
export async function generateServerWrapperCode(options) {
|
|
78
|
+
const { serverEntryPath, handlerSetup = "", handlerCall, imports = "", needsNodeRequestConversion = true, } = options;
|
|
79
|
+
const serverBuildContent = await readFile(serverEntryPath);
|
|
80
|
+
const parts = [
|
|
81
|
+
`// Server build content`,
|
|
82
|
+
serverBuildContent,
|
|
83
|
+
``,
|
|
84
|
+
`// HTTP server wrapper`,
|
|
85
|
+
];
|
|
86
|
+
// 添加额外导入
|
|
87
|
+
if (imports) {
|
|
88
|
+
parts.push(imports);
|
|
89
|
+
parts.push(``);
|
|
90
|
+
}
|
|
91
|
+
// 添加 handler 初始化代码
|
|
92
|
+
if (handlerSetup) {
|
|
93
|
+
parts.push(handlerSetup);
|
|
94
|
+
parts.push(``);
|
|
95
|
+
}
|
|
96
|
+
// 添加请求转换函数
|
|
97
|
+
if (needsNodeRequestConversion) {
|
|
98
|
+
parts.push(NODE_REQUEST_CONVERTER_CODE);
|
|
99
|
+
parts.push(``);
|
|
100
|
+
}
|
|
101
|
+
// Add request handler
|
|
102
|
+
parts.push(`
|
|
103
|
+
async function nodeRequestHandler(nodeReq, ...args) {
|
|
104
|
+
const webRequest = nodeRequestToWebRequest(nodeReq);
|
|
105
|
+
return ${handlerCall};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export default nodeRequestHandler;
|
|
109
|
+
`.trim());
|
|
110
|
+
return parts.join("\n");
|
|
111
|
+
}
|
|
112
|
+
/** Normalize route path */
|
|
113
|
+
export function normalizeRoutePath(routePath) {
|
|
114
|
+
let normalized = routePath.replace(/\/+/g, "/");
|
|
115
|
+
if (!normalized.startsWith("/")) {
|
|
116
|
+
normalized = "/" + normalized;
|
|
117
|
+
}
|
|
118
|
+
if (normalized !== "/" && normalized.endsWith("/")) {
|
|
119
|
+
normalized = normalized.slice(0, -1);
|
|
120
|
+
}
|
|
121
|
+
return normalized;
|
|
122
|
+
}
|
|
123
|
+
/** Convert route path to regex format */
|
|
124
|
+
export function routePathToRegex(routePath) {
|
|
125
|
+
let result = normalizeRoutePath(routePath);
|
|
126
|
+
if (result.includes("*")) {
|
|
127
|
+
result = result.replace(/[.+?^${}|[\]\\]/g, "\\$&");
|
|
128
|
+
if (result.endsWith("/*")) {
|
|
129
|
+
result = result.slice(0, -2) + "/?.*";
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
result = result.replace(/\*/g, ".*");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
/** Detect server entry file */
|
|
138
|
+
export async function detectServerEntry(serverDir, candidates = ["index.js", "index.mjs", "entry.js", "main.js"]) {
|
|
139
|
+
for (const candidate of candidates) {
|
|
140
|
+
const entryPath = path.join(serverDir, candidate);
|
|
141
|
+
if (await pathExists(entryPath)) {
|
|
142
|
+
return entryPath;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
/** Detect build directory */
|
|
148
|
+
export async function detectBuildDir(projectRoot, candidates) {
|
|
149
|
+
for (const candidate of candidates) {
|
|
150
|
+
const dirPath = path.join(projectRoot, candidate);
|
|
151
|
+
if (await pathExists(dirPath)) {
|
|
152
|
+
return dirPath;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
/** Log build artifacts info */
|
|
158
|
+
export function logBuildArtifacts(logger, adapterName, artifacts) {
|
|
159
|
+
logger.verbose(`${adapterName} build artifacts:`);
|
|
160
|
+
logger.verbose(` Client: ${artifacts.clientDir || "not found"}`);
|
|
161
|
+
logger.verbose(` Server: ${artifacts.serverDir || "not found"}`);
|
|
162
|
+
if (artifacts.serverEntry) {
|
|
163
|
+
logger.verbose(` Server entry: ${artifacts.serverEntry}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAElD,6CAA6C;AAC7C,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,WAAmB,EACnB,QAAkB;IAElB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QACjD,IAAI,MAAM,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/B,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,qCAAqC;AACrC,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,UAAkB;IAElB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;QAC/C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,OAAO,MAAM,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC1D,OAAO,MAAM,CAAC,OAAY,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,I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C,CAAC;IAC7D,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,80 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @edgeone/vite-plugin-adapter
|
|
3
|
-
*
|
|
4
|
-
* EdgeOne 平台的核心适配器插件
|
|
5
|
-
*
|
|
6
|
-
* 本包为构建框架特定适配器提供基础设施,主要功能包括:
|
|
7
|
-
* - 构建产物检测和处理
|
|
8
|
-
* - 使用 esbuild 打包服务端代码
|
|
9
|
-
* - 静态资源管理
|
|
10
|
-
* - 路由配置生成
|
|
11
|
-
* - 生成 EdgeOne 部署所需的 meta.json 配置文件
|
|
12
|
-
*
|
|
13
|
-
* 使用场景:
|
|
14
|
-
* 1. 直接使用核心适配器构建自定义适配器
|
|
15
|
-
* 2. 作为其他框架适配器(如 React Router、TanStack Start)的基础依赖
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* // 直接使用核心适配器创建自定义适配器
|
|
20
|
-
* import { createCoreAdapter } from '@edgeone/vite-plugin-adapter';
|
|
21
|
-
*
|
|
22
|
-
* export default defineConfig({
|
|
23
|
-
* plugins: [
|
|
24
|
-
* createCoreAdapter({
|
|
25
|
-
* verbose: true, // 启用详细日志
|
|
26
|
-
* hooks: {
|
|
27
|
-
* // 自定义路由生成逻辑
|
|
28
|
-
* generateRoutes: async (ctx) => [...],
|
|
29
|
-
* // 自定义服务端包装器生成逻辑
|
|
30
|
-
* generateServerWrapper: async (ctx, config) => '...',
|
|
31
|
-
* }
|
|
32
|
-
* })
|
|
33
|
-
* ]
|
|
34
|
-
* });
|
|
35
|
-
* ```
|
|
3
|
+
* Core adapter plugin for EdgeOne platform
|
|
36
4
|
*/
|
|
37
5
|
export { createCoreAdapter, default } from "./core.js";
|
|
38
|
-
export { bundleServerCode,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export {
|
|
43
|
-
pathExists, // 检查路径是否存在
|
|
44
|
-
findExistingPath, // 从候选列表中找到第一个存在的路径
|
|
45
|
-
copyDirectory, // 递归复制目录
|
|
46
|
-
cleanDirectory, // 清理目录(删除后重建)
|
|
47
|
-
ensureDirectory, // 确保目录存在
|
|
48
|
-
readFile, // 读取文件内容
|
|
49
|
-
writeFile, // 写入文件内容
|
|
50
|
-
deleteFile, // 删除文件
|
|
51
|
-
formatSize, // 格式化文件大小
|
|
52
|
-
waitFor, // 等待条件满足(带重试)
|
|
53
|
-
listFiles, // 列出目录内容
|
|
54
|
-
countFiles, } from "./utils.js";
|
|
55
|
-
export type { RouteInfo, // 路由信息
|
|
56
|
-
MetaConfig, // 元数据配置
|
|
57
|
-
HeaderRule, // HTTP 响应头规则
|
|
58
|
-
RedirectRule, // 重定向规则
|
|
59
|
-
RewriteRule, // URL 重写规则
|
|
60
|
-
CacheRule, // 缓存规则
|
|
61
|
-
BuildContext, // 构建上下文
|
|
62
|
-
Logger, // 日志接口
|
|
63
|
-
BuildArtifacts, // 构建产物信息
|
|
64
|
-
ServerWrapperConfig, // 服务端包装器配置
|
|
65
|
-
ServerBundleConfig, // esbuild 打包配置
|
|
66
|
-
BeforeBuildHook, // 构建前钩子
|
|
67
|
-
AfterBuildHook, // 构建后钩子
|
|
68
|
-
BeforeBundleHook, // 打包前钩子
|
|
69
|
-
AfterBundleHook, // 打包后钩子
|
|
70
|
-
GenerateRoutesHook, // 路由生成钩子
|
|
71
|
-
GenerateMetaHook, // 元数据生成钩子
|
|
72
|
-
GenerateServerWrapperHook, // 服务端包装器生成钩子
|
|
73
|
-
AdapterHooks, // 适配器钩子集合
|
|
74
|
-
FrameworkAdapter, // 框架适配器接口
|
|
75
|
-
CoreAdapterOptions, // 核心适配器选项
|
|
76
|
-
ViteAdapterOptions, // Vite 适配器选项
|
|
77
|
-
ReactRouterAdapterOptions, // React Router 适配器选项
|
|
78
|
-
TanStackStartAdapterOptions, // TanStack Start 适配器选项
|
|
79
|
-
CreateAdapterPlugin, } from "./types.js";
|
|
6
|
+
export { bundleServerCode, createServerWrapper, cleanupWrapper, getBundleSize, } from "./bundler.js";
|
|
7
|
+
export { createLogger, pathExists, findExistingPath, copyDirectory, cleanDirectory, ensureDirectory, readFile, writeFile, deleteFile, formatSize, waitFor, listFiles, countFiles, } from "./utils.js";
|
|
8
|
+
export { detectConfigFile, loadConfigFile, createDefaultMeta, NODE_REQUEST_CONVERTER_CODE, generateServerWrapperCode, normalizeRoutePath, routePathToRegex, detectServerEntry, detectBuildDir, logBuildArtifacts, } from "./helpers.js";
|
|
9
|
+
export type { RouteInfo, MetaConfig, HeaderRule, RedirectRule, RewriteRule, CacheRule, BuildContext, Logger, BuildArtifacts, ServerWrapperConfig, ServerBundleConfig, BeforeBuildHook, AfterBuildHook, BeforeBundleHook, AfterBundleHook, GenerateRoutesHook, GenerateMetaHook, GenerateServerWrapperHook, AdapterHooks, FrameworkAdapter, CoreAdapterOptions, ViteAdapterOptions, ReactRouterAdapterOptions, TanStackStartAdapterOptions, CreateAdapterPlugin, } from "./types.js";
|
|
10
|
+
export type { ServerWrapperGeneratorOptions } from "./helpers.js";
|
|
80
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGvD,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,aAAa,GACd,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,eAAe,EACf,QAAQ,EACR,SAAS,EACT,UAAU,EACV,UAAU,EACV,OAAO,EACP,SAAS,EACT,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,2BAA2B,EAC3B,yBAAyB,EACzB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,SAAS,EACT,UAAU,EACV,UAAU,EACV,YAAY,EACZ,WAAW,EACX,SAAS,EACT,YAAY,EACZ,MAAM,EACN,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,yBAAyB,EACzB,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,2BAA2B,EAC3B,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,61 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @edgeone/vite-plugin-adapter
|
|
3
|
-
*
|
|
4
|
-
* EdgeOne 平台的核心适配器插件
|
|
5
|
-
*
|
|
6
|
-
* 本包为构建框架特定适配器提供基础设施,主要功能包括:
|
|
7
|
-
* - 构建产物检测和处理
|
|
8
|
-
* - 使用 esbuild 打包服务端代码
|
|
9
|
-
* - 静态资源管理
|
|
10
|
-
* - 路由配置生成
|
|
11
|
-
* - 生成 EdgeOne 部署所需的 meta.json 配置文件
|
|
12
|
-
*
|
|
13
|
-
* 使用场景:
|
|
14
|
-
* 1. 直接使用核心适配器构建自定义适配器
|
|
15
|
-
* 2. 作为其他框架适配器(如 React Router、TanStack Start)的基础依赖
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* // 直接使用核心适配器创建自定义适配器
|
|
20
|
-
* import { createCoreAdapter } from '@edgeone/vite-plugin-adapter';
|
|
21
|
-
*
|
|
22
|
-
* export default defineConfig({
|
|
23
|
-
* plugins: [
|
|
24
|
-
* createCoreAdapter({
|
|
25
|
-
* verbose: true, // 启用详细日志
|
|
26
|
-
* hooks: {
|
|
27
|
-
* // 自定义路由生成逻辑
|
|
28
|
-
* generateRoutes: async (ctx) => [...],
|
|
29
|
-
* // 自定义服务端包装器生成逻辑
|
|
30
|
-
* generateServerWrapper: async (ctx, config) => '...',
|
|
31
|
-
* }
|
|
32
|
-
* })
|
|
33
|
-
* ]
|
|
34
|
-
* });
|
|
35
|
-
* ```
|
|
3
|
+
* Core adapter plugin for EdgeOne platform
|
|
36
4
|
*/
|
|
37
|
-
//
|
|
38
|
-
// createCoreAdapter: 创建核心适配器插件的工厂函数
|
|
5
|
+
// Core
|
|
39
6
|
export { createCoreAdapter, default } from "./core.js";
|
|
40
|
-
//
|
|
41
|
-
export { bundleServerCode,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} from "./
|
|
46
|
-
// ==================== 工具函数导出 ====================
|
|
47
|
-
export { createLogger, // 创建日志记录器
|
|
48
|
-
pathExists, // 检查路径是否存在
|
|
49
|
-
findExistingPath, // 从候选列表中找到第一个存在的路径
|
|
50
|
-
copyDirectory, // 递归复制目录
|
|
51
|
-
cleanDirectory, // 清理目录(删除后重建)
|
|
52
|
-
ensureDirectory, // 确保目录存在
|
|
53
|
-
readFile, // 读取文件内容
|
|
54
|
-
writeFile, // 写入文件内容
|
|
55
|
-
deleteFile, // 删除文件
|
|
56
|
-
formatSize, // 格式化文件大小
|
|
57
|
-
waitFor, // 等待条件满足(带重试)
|
|
58
|
-
listFiles, // 列出目录内容
|
|
59
|
-
countFiles, // 递归统计文件数量
|
|
60
|
-
} from "./utils.js";
|
|
7
|
+
// Bundler
|
|
8
|
+
export { bundleServerCode, createServerWrapper, cleanupWrapper, getBundleSize, } from "./bundler.js";
|
|
9
|
+
// Utils
|
|
10
|
+
export { createLogger, pathExists, findExistingPath, copyDirectory, cleanDirectory, ensureDirectory, readFile, writeFile, deleteFile, formatSize, waitFor, listFiles, countFiles, } from "./utils.js";
|
|
11
|
+
// Helpers
|
|
12
|
+
export { detectConfigFile, loadConfigFile, createDefaultMeta, NODE_REQUEST_CONVERTER_CODE, generateServerWrapperCode, normalizeRoutePath, routePathToRegex, detectServerEntry, detectBuildDir, logBuildArtifacts, } from "./helpers.js";
|
|
61
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO;AACP,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEvD,UAAU;AACV,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,QAAQ;AACR,OAAO,EACL,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,eAAe,EACf,QAAQ,EACR,SAAS,EACT,UAAU,EACV,UAAU,EACV,OAAO,EACP,SAAS,EACT,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,UAAU;AACV,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,2BAA2B,EAC3B,yBAAyB,EACzB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,GAClB,MAAM,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chuckcchen/vite-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Core adapter plugin for EdgeOne platform - handles build artifacts, bundling, and deployment configuration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
|
+
"development": "./src/index.ts",
|
|
11
12
|
"import": "./dist/index.js"
|
|
12
13
|
}
|
|
13
14
|
},
|