@moneko/core 4.2.0-beta.0 → 4.2.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/lib/bin/build-app.mjs.d.ts +17 -0
- package/lib/bin/{commit-lint.d.mts → commit-lint.mjs.d.ts} +5 -8
- package/lib/bin/{index.d.mts → index.mjs.d.ts} +1 -1
- package/lib/bin/{pin.d.mts → pin.mjs.d.ts} +1 -2
- package/lib/bin/{pure-lint.d.mts → pure-lint.mjs.d.ts} +1 -1
- package/lib/bin/server.mjs +1 -1
- package/lib/bin/server.mjs.d.ts +2 -0
- package/lib/bin/tsc.mjs.d.ts +2 -0
- package/lib/bin/utils/{bundle-app.d.mts → bundle-app.mjs.d.ts} +2 -0
- package/lib/bin/utils/convert-react.mjs.d.ts +174 -0
- package/lib/bin/utils/get-commit-files.mjs.d.ts +2 -0
- package/lib/build-dev.mjs.d.ts +1 -0
- package/lib/build.mjs.d.ts +1 -0
- package/lib/commom/{ca.d.mts → ca.mjs.d.ts} +3 -5
- package/lib/commom/{check-npm.d.mts → check-npm.mjs.d.ts} +1 -2
- package/lib/commom/{corepack.d.mts → corepack.mjs.d.ts} +1 -2
- package/lib/commom/css-in-js-minify.mjs.d.ts +12 -0
- package/lib/commom/{is-ci-environment.d.mts → is-ci-environment.mjs.d.ts} +1 -2
- package/lib/commom/{match-path.d.mts → match-path.mjs.d.ts} +1 -2
- package/lib/commom/{package-manager.d.mts → package-manager.mjs.d.ts} +2 -3
- package/lib/commom/paths.mjs.d.ts +33 -0
- package/lib/commom/{reactive-object.d.mts → reactive-object.mjs.d.ts} +1 -0
- package/lib/commom/rule.mjs.d.ts +2 -0
- package/lib/commom/{setup-env.d.mts → setup-env.mjs.d.ts} +4 -2
- package/lib/commom/{timer.d.mts → timer.mjs.d.ts} +1 -2
- package/lib/commom/transfer-import-on-demand.mjs.d.ts +54 -0
- package/lib/create-development-configuration.mjs.d.ts +2 -0
- package/lib/dev/config.mjs.d.ts +9 -0
- package/lib/dev/get-cert.mjs.d.ts +10 -0
- package/lib/dev/{json-schema.d.mts → json-schema.mjs.d.ts} +3 -1
- package/lib/dev/mock.mjs +1 -1
- package/lib/dev/{mock.d.mts → mock.mjs.d.ts} +17 -21
- package/lib/dev/{proxy.d.mts → proxy.mjs.d.ts} +1 -1
- package/lib/dev.mjs.d.ts +1 -0
- package/lib/{index.d.mts → index.mjs.d.ts} +5 -5
- package/lib/lint/stylelint/{index.d.mts → index.mjs.d.ts} +1 -1
- package/lib/loader/{lightning-css.d.cts → lightning-css.cjs.d.ts} +2 -0
- package/lib/loader/mdx.cjs.d.ts +5 -0
- package/lib/loader/react-compiler.cjs.d.ts +27 -0
- package/lib/loader/{solid.d.cts → solid.cjs.d.ts} +1 -1
- package/lib/module.config.mjs.d.ts +3 -0
- package/lib/options/reslove.mjs.d.ts +10 -0
- package/lib/options/{swcrc.d.mts → swcrc.mjs.d.ts} +2 -2
- package/lib/plugin/{compression.d.mts → compression.mjs.d.ts} +1 -1
- package/lib/plugin/{copy.d.mts → copy.mjs.d.ts} +3 -6
- package/lib/plugin/{exposes-declararion.d.mts → exposes-declararion.mjs.d.ts} +1 -1
- package/lib/plugin/{html-plugin.d.mts → html-plugin.mjs.d.ts} +20 -29
- package/lib/plugin/{lightningcss-plugin.d.mts → lightningcss-plugin.mjs.d.ts} +1 -1
- package/lib/plugin/manifest/index.mjs +1 -1
- package/lib/plugin/manifest/{index.d.mts → index.mjs.d.ts} +1 -1
- package/lib/plugin/manifest/types.mjs.d.ts +508 -0
- package/lib/plugin/override-resolve.mjs.d.ts +23 -0
- package/lib/plugin/{virtual-module.d.mts → virtual-module.mjs.d.ts} +1 -1
- package/lib/polyfills/inject-react-refresh.mjs.d.ts +1 -0
- package/lib/polyfills/replace-children.mjs.d.ts +1 -0
- package/lib/{process-env.d.mts → process-env.mjs.d.ts} +14 -14
- package/lib/utils/{compile-dts.d.mts → compile-dts.mjs.d.ts} +2 -3
- package/lib/utils/{dts.d.mts → dts.mjs.d.ts} +2 -4
- package/lib/utils/{index.d.mts → index.mjs.d.ts} +9 -15
- package/lib/utils/run.mjs.d.ts +2 -0
- package/lib/utils/seo.mjs +2 -2
- package/lib/utils/seo.mjs.d.ts +2 -0
- package/lib/utils/{vts.d.mts → vts.mjs.d.ts} +3 -3
- package/lib/vm/{docs.d.mts → docs.mjs.d.ts} +1 -0
- package/lib/vm/{locales.d.mts → locales.mjs.d.ts} +1 -0
- package/lib/worker/compression.mjs.d.ts +1 -0
- package/lib/worker/css-in-js-minify.mjs.d.ts +1 -0
- package/lib/worker/dts.mjs.d.ts +1 -0
- package/lib/worker/react-compiler.mjs.d.ts +1 -0
- package/lib/worker/solid.mjs.d.ts +1 -0
- package/lib/worker/swc-minify.mjs.d.ts +1 -0
- package/package.json +2 -2
- package/lib/bin/build-app.d.mts +0 -16
- package/lib/bin/server.d.mts +0 -2
- package/lib/bin/tsc.d.mts +0 -2
- package/lib/bin/utils/convert-react.d.mts +0 -1
- package/lib/bin/utils/get-commit-files.d.mts +0 -2
- package/lib/build-dev.d.mts +0 -1
- package/lib/build.d.mts +0 -1
- package/lib/commom/css-in-js-minify.d.mts +0 -13
- package/lib/commom/paths.d.mts +0 -52
- package/lib/commom/rule.d.mts +0 -27
- package/lib/commom/transfer-import-on-demand.d.mts +0 -78
- package/lib/create-development-configuration.d.mts +0 -2
- package/lib/dev/config.d.mts +0 -4
- package/lib/dev/get-cert.d.mts +0 -8
- package/lib/dev.d.mts +0 -1
- package/lib/loader/mdx.d.cts +0 -3
- package/lib/loader/react-compiler.d.cts +0 -29
- package/lib/module.config.d.mts +0 -3
- package/lib/options/reslove.d.mts +0 -9
- package/lib/plugin/manifest/types.d.mts +0 -576
- package/lib/plugin/override-resolve.d.mts +0 -25
- package/lib/polyfills/inject-react-refresh.d.mts +0 -1
- package/lib/polyfills/replace-children.d.mts +0 -1
- package/lib/utils/run.d.mts +0 -2
- package/lib/utils/seo.d.mts +0 -2
- package/lib/worker/compression.d.mts +0 -1
- package/lib/worker/css-in-js-minify.d.mts +0 -1
- package/lib/worker/dts.d.mts +0 -1
- package/lib/worker/react-compiler.d.mts +0 -1
- package/lib/worker/solid.d.mts +0 -1
- package/lib/worker/swc-minify.d.mts +0 -1
- /package/lib/bin/{build-dev.d.mts → build-dev.mjs.d.ts} +0 -0
- /package/lib/bin/{build.d.mts → build.mjs.d.ts} +0 -0
- /package/lib/bin/{changelog.d.mts → changelog.mjs.d.ts} +0 -0
- /package/lib/bin/{eslint.d.mts → eslint.mjs.d.ts} +0 -0
- /package/lib/bin/{file.d.mts → file.mjs.d.ts} +0 -0
- /package/lib/bin/{git-hooks.d.mts → git-hooks.mjs.d.ts} +0 -0
- /package/lib/bin/{help.d.mts → help.mjs.d.ts} +0 -0
- /package/lib/bin/{lessc.d.mts → lessc.mjs.d.ts} +0 -0
- /package/lib/bin/{setup.d.mts → setup.mjs.d.ts} +0 -0
- /package/lib/bin/{start.d.mts → start.mjs.d.ts} +0 -0
- /package/lib/bin/{stylelint.d.mts → stylelint.mjs.d.ts} +0 -0
- /package/lib/bin/utils/{config.d.mts → config.mjs.d.ts} +0 -0
- /package/lib/bin/utils/{setup-swcrc.d.mts → setup-swcrc.mjs.d.ts} +0 -0
- /package/lib/build/{common.d.mts → common.mjs.d.ts} +0 -0
- /package/lib/build/{server.d.mts → server.mjs.d.ts} +0 -0
- /package/lib/commom/{diff-object.d.mts → diff-object.mjs.d.ts} +0 -0
- /package/lib/commom/{esm.d.mts → esm.mjs.d.ts} +0 -0
- /package/lib/commom/{has-pkg.d.mts → has-pkg.mjs.d.ts} +0 -0
- /package/lib/commom/{host.d.mts → host.mjs.d.ts} +0 -0
- /package/lib/commom/{log.d.mts → log.mjs.d.ts} +0 -0
- /package/lib/commom/{mime.d.mts → mime.mjs.d.ts} +0 -0
- /package/lib/commom/{module-resolve.d.mts → module-resolve.mjs.d.ts} +0 -0
- /package/lib/commom/{net.d.mts → net.mjs.d.ts} +0 -0
- /package/lib/commom/{open.d.mts → open.mjs.d.ts} +0 -0
- /package/lib/commom/{parse-args.d.mts → parse-args.mjs.d.ts} +0 -0
- /package/lib/commom/{print-log.d.mts → print-log.mjs.d.ts} +0 -0
- /package/lib/commom/{read-json.d.mts → read-json.mjs.d.ts} +0 -0
- /package/lib/commom/{require.d.mts → require.mjs.d.ts} +0 -0
- /package/lib/commom/{sigint-exit.d.mts → sigint-exit.mjs.d.ts} +0 -0
- /package/lib/commom/{transform-solid-js.d.mts → transform-solid-js.mjs.d.ts} +0 -0
- /package/lib/{common.d.mts → common.mjs.d.ts} +0 -0
- /package/lib/{config.d.mts → config.mjs.d.ts} +0 -0
- /package/lib/dev/{generate-progress-html.d.mts → generate-progress-html.mjs.d.ts} +0 -0
- /package/lib/dev/{server.d.mts → server.mjs.d.ts} +0 -0
- /package/lib/{file-system.d.mts → file-system.mjs.d.ts} +0 -0
- /package/lib/lint/eslint/{base.d.mts → base.mjs.d.ts} +0 -0
- /package/lib/lint/eslint/{index.d.mts → index.mjs.d.ts} +0 -0
- /package/lib/lint/eslint/{react-jsx.d.mts → react-jsx.mjs.d.ts} +0 -0
- /package/lib/lint/eslint/{react-legacy.d.mts → react-legacy.mjs.d.ts} +0 -0
- /package/lib/lint/eslint/{react.d.mts → react.mjs.d.ts} +0 -0
- /package/lib/lint/eslint/{solid.d.mts → solid.mjs.d.ts} +0 -0
- /package/lib/lint/eslint/{vue.d.mts → vue.mjs.d.ts} +0 -0
- /package/lib/lint/stylelint/{config.d.mts → config.mjs.d.ts} +0 -0
- /package/lib/loader/{css-in-js-minify.d.cts → css-in-js-minify.cjs.d.ts} +0 -0
- /package/lib/options/{jsx-dom-expressions.d.mts → jsx-dom-expressions.mjs.d.ts} +0 -0
- /package/lib/options/{md-to-html.d.mts → md-to-html.mjs.d.ts} +0 -0
- /package/lib/options/{modify-vars.d.mts → modify-vars.mjs.d.ts} +0 -0
- /package/lib/options/{split-chunk.d.mts → split-chunk.mjs.d.ts} +0 -0
- /package/lib/plugin/{css-module-dts.d.mts → css-module-dts.mjs.d.ts} +0 -0
- /package/lib/plugin/{done.d.mts → done.mjs.d.ts} +0 -0
- /package/lib/plugin/{eslint.d.mts → eslint.mjs.d.ts} +0 -0
- /package/lib/plugin/{external-remotes.d.mts → external-remotes.mjs.d.ts} +0 -0
- /package/lib/plugin/{module-federation.d.mts → module-federation.mjs.d.ts} +0 -0
- /package/lib/plugin/{stylelint.d.mts → stylelint.mjs.d.ts} +0 -0
- /package/lib/plugin/{swc-minify-plugin.d.mts → swc-minify-plugin.mjs.d.ts} +0 -0
- /package/lib/{plugins.config.d.mts → plugins.config.mjs.d.ts} +0 -0
- /package/lib/polyfills/{polyfills.d.mts → polyfills.mjs.d.ts} +0 -0
- /package/lib/polyfills/{public-path.d.mts → public-path.mjs.d.ts} +0 -0
- /package/lib/polyfills/{targets.d.mts → targets.mjs.d.ts} +0 -0
- /package/lib/utils/{create-types.d.mts → create-types.mjs.d.ts} +0 -0
- /package/lib/utils/{fetch-module-federation-dts.d.mts → fetch-module-federation-dts.mjs.d.ts} +0 -0
- /package/lib/utils/{svg-to-data-uri.d.mts → svg-to-data-uri.mjs.d.ts} +0 -0
- /package/lib/vm/{app.d.mts → app.mjs.d.ts} +0 -0
- /package/lib/vm/{coverage.d.mts → coverage.mjs.d.ts} +0 -0
- /package/lib/vm/{dts.d.mts → dts.mjs.d.ts} +0 -0
- /package/lib/vm/{example.d.mts → example.mjs.d.ts} +0 -0
- /package/lib/vm/{generate-doc.d.mts → generate-doc.mjs.d.ts} +0 -0
- /package/lib/vm/{render-app.d.mts → render-app.mjs.d.ts} +0 -0
- /package/lib/vm/{routes.d.mts → routes.mjs.d.ts} +0 -0
- /package/lib/vm/{scope.d.mts → scope.mjs.d.ts} +0 -0
- /package/lib/vm/{virtual.d.mts → virtual.mjs.d.ts} +0 -0
- /package/lib/worker/{eslint.d.mts → eslint.mjs.d.ts} +0 -0
- /package/lib/worker/{stylelint.d.mts → stylelint.mjs.d.ts} +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 拷贝文件
|
|
3
|
+
* @param {String} source 源文件
|
|
4
|
+
* @param {String} target 目标文件
|
|
5
|
+
* @constructor
|
|
6
|
+
* */ export declare function copyFileSync(source: string, target: string): void;
|
|
7
|
+
/**
|
|
8
|
+
* 拷贝文件夹
|
|
9
|
+
* @param {String} source 源文件夹
|
|
10
|
+
* @param {String} target 目标文件夹
|
|
11
|
+
* @param {String} sun 是否子文件夹
|
|
12
|
+
* @constructor
|
|
13
|
+
* */ export declare function copyFolderRecursiveSync(source: string, target: string, sun?: boolean): void;
|
|
14
|
+
export default function createApp(): Promise<void>; // program
|
|
15
|
+
// .command('buildApp')
|
|
16
|
+
// .description('编译将 h5 应用打包成移动客户端,使用 Flutter')
|
|
17
|
+
// .action(createApp);
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
// Rules definitions
|
|
2
3
|
declare const LEVEL: {
|
|
3
4
|
readonly DISABLED: 0;
|
|
4
5
|
readonly WARNING: 1;
|
|
5
6
|
readonly ERROR: 2;
|
|
6
7
|
};
|
|
7
8
|
declare const RULE_OUTCOME: {
|
|
8
|
-
readonly ALWAYS:
|
|
9
|
-
readonly NEVER:
|
|
9
|
+
readonly ALWAYS: 'always';
|
|
10
|
+
readonly NEVER: 'never';
|
|
10
11
|
};
|
|
11
12
|
type Level = (typeof LEVEL)[keyof typeof LEVEL];
|
|
12
13
|
type When = (typeof RULE_OUTCOME)[keyof typeof RULE_OUTCOME];
|
|
@@ -17,11 +18,7 @@ export type CommitRules = {
|
|
|
17
18
|
'footer-max-line-length': [level: Level, when: When, value: number];
|
|
18
19
|
'header-max-length': [level: Level, when: When, value: number];
|
|
19
20
|
'header-trim': [level: Level, when: When];
|
|
20
|
-
'subject-case': [
|
|
21
|
-
level: Level,
|
|
22
|
-
when: When,
|
|
23
|
-
value: ('sentence-case' | 'start-case' | 'pascal-case' | 'upper-case')[]
|
|
24
|
-
];
|
|
21
|
+
'subject-case': [level: Level, when: When, value: ('sentence-case' | 'start-case' | 'pascal-case' | 'upper-case')[]];
|
|
25
22
|
'subject-empty': [level: Level, when: When];
|
|
26
23
|
'subject-full-stop': [level: Level, when: When, value: string];
|
|
27
24
|
'type-case': [level: Level, when: When, value: 'lower-case' | 'upper-case'];
|
|
@@ -29,4 +26,4 @@ export type CommitRules = {
|
|
|
29
26
|
'type-enum': [level: Level, when: When, value: [type: string, message: string | string[]][]];
|
|
30
27
|
};
|
|
31
28
|
export type CommitRuleConfig = Partial<CommitRules>;
|
|
32
|
-
export {};
|
|
29
|
+
export { };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
export {};
|
|
2
|
+
export { };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
export {};
|
|
2
|
+
export { };
|
package/lib/bin/server.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"node:fs";import{ink as r,println as o}from"@moneko/utils";import m from"../commom/parse-args.mjs";import
|
|
1
|
+
import e from"node:fs";import{ink as r,println as o}from"@moneko/utils";import m from"../commom/parse-args.mjs";import t from"../commom/print-log.mjs";import{CONFIG as s}from"../config.mjs";import i from"../dev/server.mjs";async function p(){let{argv:p}=process,{port:a=s.devServer.port??8080,root_dir:n="./dist",https:l=s.devServer.https,host:v=s.devServer.host??"localhost"}=m(p.slice(2));i({port:a,root_dir:n,https:l,host:v,fileSystem:e,headers:s.devServer.headers,open:s.devServer.open,basename:s.basename}),o(r("You application is running here:","245"),!0),o("",!0),t("Preview",`${l?"https":"http"}://${v}:${a}`,{timestamp:!1,labelBackgroundColor:"blue"}),o("",!0)}export default p;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// import { join, sep, extname, normalize } from 'node:path';
|
|
2
|
+
// import { copyFile, ink, println, scanFolderSync, updateFile } from '@moneko/utils';
|
|
3
|
+
// import { JsMinifyOptions, type Options, type Output, transformFile } from '@swc/core';
|
|
4
|
+
// function getOutfilePath(outDir: string, file: string, outFileExtension?: string) {
|
|
5
|
+
// // 处理输出路径
|
|
6
|
+
// const parts = file.split(sep);
|
|
7
|
+
// const baseDir = parts[0] === '' ? parts[1] : parts[0];
|
|
8
|
+
// const outputPath = file.replace(baseDir, '');
|
|
9
|
+
// const output = join(outDir, outputPath);
|
|
10
|
+
// if (outFileExtension) {
|
|
11
|
+
// return output.replace(extname(output), outFileExtension);
|
|
12
|
+
// }
|
|
13
|
+
// return output;
|
|
14
|
+
// }
|
|
15
|
+
// interface ConvertOptions {
|
|
16
|
+
// outDir: string;
|
|
17
|
+
// inputDir: string;
|
|
18
|
+
// options: Options;
|
|
19
|
+
// ignore?: RegExp[];
|
|
20
|
+
// extensions?: string[];
|
|
21
|
+
// copy?: boolean;
|
|
22
|
+
// quiet?: boolean;
|
|
23
|
+
// outputExtension?: string;
|
|
24
|
+
// }
|
|
25
|
+
// interface ConvertResult {
|
|
26
|
+
// duration: number;
|
|
27
|
+
// compiled: string[];
|
|
28
|
+
// copied: string[];
|
|
29
|
+
// failed: string[];
|
|
30
|
+
// }
|
|
31
|
+
// interface ConvertOutput extends Output {
|
|
32
|
+
// output?: string;
|
|
33
|
+
// }
|
|
34
|
+
// const normalizeExtension: Record<string, string> = {
|
|
35
|
+
// '.ts': '.js',
|
|
36
|
+
// '.tsx': '.js',
|
|
37
|
+
// '.mts': '.mjs',
|
|
38
|
+
// '.cts': '.cjs',
|
|
39
|
+
// '.js': '.js',
|
|
40
|
+
// '.jsx': '.js',
|
|
41
|
+
// '.mjs': '.mjs',
|
|
42
|
+
// '.cjs': '.cjs',
|
|
43
|
+
// };
|
|
44
|
+
// const jscMinify: JsMinifyOptions = {
|
|
45
|
+
// format: {
|
|
46
|
+
// comments: false,
|
|
47
|
+
// },
|
|
48
|
+
// ecma: 2015,
|
|
49
|
+
// compress: {
|
|
50
|
+
// drop_console: true,
|
|
51
|
+
// drop_debugger: true,
|
|
52
|
+
// global_defs: {
|
|
53
|
+
// '@alert': 'console.log',
|
|
54
|
+
// },
|
|
55
|
+
// pure_funcs: ['console.log', 'console.warn', 'console.error', 'console.info'], // 移除console
|
|
56
|
+
// ecma: 2015,
|
|
57
|
+
// toplevel: false, // 为true表示只在顶级作用域压缩清理变量
|
|
58
|
+
// module: false,
|
|
59
|
+
// ie8: false,
|
|
60
|
+
// keep_classnames: void 0,
|
|
61
|
+
// keep_fnames: false,
|
|
62
|
+
// top_retain: [],
|
|
63
|
+
// keep_infinity: true,
|
|
64
|
+
// },
|
|
65
|
+
// mangle: true,
|
|
66
|
+
// };
|
|
67
|
+
// export async function convert({
|
|
68
|
+
// ignore = [],
|
|
69
|
+
// quiet = true,
|
|
70
|
+
// copy = true,
|
|
71
|
+
// outDir,
|
|
72
|
+
// outputExtension,
|
|
73
|
+
// inputDir,
|
|
74
|
+
// options,
|
|
75
|
+
// extensions = ['.ts', '.js', '.tsx', '.jsx', '.mts', '.mjs', '.cts', '.cjs'],
|
|
76
|
+
// }: ConvertOptions): Promise<ConvertResult> {
|
|
77
|
+
// // 记录运行时间
|
|
78
|
+
// const start = process.hrtime();
|
|
79
|
+
// const result: ConvertResult = {
|
|
80
|
+
// duration: 0,
|
|
81
|
+
// compiled: [],
|
|
82
|
+
// copied: [],
|
|
83
|
+
// failed: [],
|
|
84
|
+
// };
|
|
85
|
+
// const allfile = scanFolderSync(inputDir, ['^.*']).map((file) => normalize(file));
|
|
86
|
+
// // 获取匹配的文件
|
|
87
|
+
// const files: string[] = [];
|
|
88
|
+
// const copyFiles: string[] = [];
|
|
89
|
+
// allfile.forEach((file) => {
|
|
90
|
+
// if (/\.DS_Store/.test(file) || ignore.some((item: RegExp) => item.test(file))) {
|
|
91
|
+
// return;
|
|
92
|
+
// }
|
|
93
|
+
// if (extensions.includes(extname(file))) {
|
|
94
|
+
// files.push(file);
|
|
95
|
+
// } else if (copy) {
|
|
96
|
+
// copyFiles.push(file);
|
|
97
|
+
// }
|
|
98
|
+
// });
|
|
99
|
+
// const promises = files
|
|
100
|
+
// .map(async (file) => {
|
|
101
|
+
// try {
|
|
102
|
+
// const outExtension = outputExtension || normalizeExtension[extname(file)];
|
|
103
|
+
// // 使用 SWC 转换文件
|
|
104
|
+
// const { code, map, output } = (await transformFile(file, {
|
|
105
|
+
// ...options,
|
|
106
|
+
// jsc: {
|
|
107
|
+
// externalHelpers: false,
|
|
108
|
+
// ...options.jsc,
|
|
109
|
+
// minify: {
|
|
110
|
+
// ...jscMinify,
|
|
111
|
+
// ...options.jsc?.minify,
|
|
112
|
+
// },
|
|
113
|
+
// },
|
|
114
|
+
// })) as ConvertOutput;
|
|
115
|
+
// // 处理输出路径
|
|
116
|
+
// const outputPath = getOutfilePath(outDir, file, outExtension);
|
|
117
|
+
// // 写入转换后的代码
|
|
118
|
+
// await updateFile(outputPath, code);
|
|
119
|
+
// // 如果存在 sourcemap,也写入
|
|
120
|
+
// if (map) {
|
|
121
|
+
// await updateFile(`${outputPath}.map`, map);
|
|
122
|
+
// }
|
|
123
|
+
// result.compiled.push(`${file} -> ${outputPath}`);
|
|
124
|
+
// if (output) {
|
|
125
|
+
// const dtsContent = JSON.parse(output);
|
|
126
|
+
// if (dtsContent.__swc_isolated_declarations__) {
|
|
127
|
+
// const ext = extname(file);
|
|
128
|
+
// const dtsPath = getOutfilePath(outDir, file.replace(ext, `.d${ext}`));
|
|
129
|
+
// await updateFile(dtsPath, dtsContent.__swc_isolated_declarations__);
|
|
130
|
+
// }
|
|
131
|
+
// }
|
|
132
|
+
// } catch (error) {
|
|
133
|
+
// result.failed.push(`Error converting ${file}: ${error}`);
|
|
134
|
+
// }
|
|
135
|
+
// })
|
|
136
|
+
// .concat(
|
|
137
|
+
// copyFiles.map(async (file) => {
|
|
138
|
+
// const outputPath = getOutfilePath(outDir, file);
|
|
139
|
+
// const isCopy = await copyFile(file, outputPath);
|
|
140
|
+
// if (isCopy) {
|
|
141
|
+
// result.copied.push(`${file} -> ${outputPath}`);
|
|
142
|
+
// } else {
|
|
143
|
+
// result.failed.push(`Error copying ${file} -> ${outputPath}`);
|
|
144
|
+
// }
|
|
145
|
+
// }),
|
|
146
|
+
// );
|
|
147
|
+
// await Promise.all(promises);
|
|
148
|
+
// const end = process.hrtime(start);
|
|
149
|
+
// result.duration = end[0] * 1000 + end[1] / 1e6;
|
|
150
|
+
// // 调用成功回调
|
|
151
|
+
// if (quiet) {
|
|
152
|
+
// const moduleType = {
|
|
153
|
+
// es6: 'ES6',
|
|
154
|
+
// commonjs: 'CommonJS',
|
|
155
|
+
// esm: 'ESM',
|
|
156
|
+
// amd: 'AMD',
|
|
157
|
+
// umd: 'UMD',
|
|
158
|
+
// systemjs: 'SystemJS',
|
|
159
|
+
// nodenext: 'NodeNext',
|
|
160
|
+
// }[options.module!.type];
|
|
161
|
+
// const list = [
|
|
162
|
+
// `${ink('✨ 编译成功!🎉', '82', { bold: true })} ${ink(`(${moduleType})`, '213')}`,
|
|
163
|
+
// ink(`⏱️ 总耗时:${result.duration.toFixed(3)} ms`, '117'),
|
|
164
|
+
// result.compiled.length && ink(`📄 编译文件:${result.compiled.length} 个`, '111'),
|
|
165
|
+
// result.copied.length && ink(`📋 复制文件:${result.copied.length} 个`, '226'),
|
|
166
|
+
// result.failed.length && ink(`❌ 编译失败:${result.failed.length} 个`, '203'),
|
|
167
|
+
// ]
|
|
168
|
+
// .filter(Boolean)
|
|
169
|
+
// .join('\n- ');
|
|
170
|
+
// println(list);
|
|
171
|
+
// }
|
|
172
|
+
// return result;
|
|
173
|
+
// }
|
|
174
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { type ChildProcess } from 'node:child_process';
|
|
2
2
|
import { type CertificateResult } from '@moneko/utils';
|
|
3
|
-
export declare const CA_ORGANIZATION =
|
|
3
|
+
export declare const CA_ORGANIZATION = 'Local Root Certificate Authority - Moneko';
|
|
4
4
|
/**
|
|
5
5
|
* 检查根证书是否已安装
|
|
6
6
|
* @param organization 颁发机构
|
|
7
7
|
* @returns Promise<boolean> 是否已安装
|
|
8
|
-
*/
|
|
9
|
-
export declare function isCertificateInstalled(organization: string): Promise<boolean>;
|
|
8
|
+
*/ export declare function isCertificateInstalled(organization: string): Promise<boolean>;
|
|
10
9
|
/**
|
|
11
10
|
* 安装本地根 CA 到用户证书存储区(开发时信任 HTTPS 证书)
|
|
12
11
|
* @param certPath 本地 CA 证书路径
|
|
13
|
-
*/
|
|
14
|
-
export declare function installCA(certPath: string): ChildProcess | void;
|
|
12
|
+
*/ export declare function installCA(certPath: string): ChildProcess | void;
|
|
15
13
|
export declare function setupCert(domain?: string, install?: boolean): Promise<CertificateResult>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Output } from '@swc/core';
|
|
2
|
+
export interface CssInJsMinifyOption {
|
|
3
|
+
/**
|
|
4
|
+
* css in js 使用的模块
|
|
5
|
+
* @default '@moneko/css'
|
|
6
|
+
*/ moduleName: string;
|
|
7
|
+
/**
|
|
8
|
+
* css in js 字符串模版函数
|
|
9
|
+
* @default ['css', 'injectGlobal']
|
|
10
|
+
*/ allowFuncs: string[];
|
|
11
|
+
}
|
|
12
|
+
export declare function cssInJsMinify(sourceCode: string, options: CssInJsMinifyOption): Promise<Output>;
|
|
@@ -17,6 +17,5 @@ type MatchPath = {
|
|
|
17
17
|
* console.log('No match found.');
|
|
18
18
|
* }
|
|
19
19
|
* @returns {MatchPath|null} MatchPath
|
|
20
|
-
*/
|
|
21
|
-
declare function matchPath(pattern: string, path: string): MatchPath | null;
|
|
20
|
+
*/ declare function matchPath(pattern: string, path: string): MatchPath | null;
|
|
22
21
|
export default matchPath;
|
|
@@ -3,6 +3,5 @@ type PackageManager = 'pnpm' | 'yarn' | 'bun' | 'deno' | 'npm';
|
|
|
3
3
|
* 获取包管理器
|
|
4
4
|
* @param {string | void} packageManager 包管理器
|
|
5
5
|
* @returns {PackageManager}
|
|
6
|
-
*/
|
|
7
|
-
export
|
|
8
|
-
export {};
|
|
6
|
+
*/ export declare function getPackageManager(packageManager?: string): PackageManager;
|
|
7
|
+
export { };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** 当前文件所在目录的绝对路径 */ export declare const __dirname: string;
|
|
2
|
+
/** yarn 命令行参数对象,包含配置选项 */ export declare const yarnArgv: Record<string, string> & {
|
|
3
|
+
config?: string;
|
|
4
|
+
};
|
|
5
|
+
/** 附加启动配置名称
|
|
6
|
+
* @example
|
|
7
|
+
* 当通过以下命令启动时, 此时 CUSTOMCONFIG 为 test
|
|
8
|
+
* ```sh
|
|
9
|
+
* npm run start --config=test
|
|
10
|
+
* ```
|
|
11
|
+
*/ export declare const CUSTOMCONFIG: string | undefined;
|
|
12
|
+
export declare const TMP_DIR: string;
|
|
13
|
+
declare const paths: {
|
|
14
|
+
/** node_modules 目录路径 */ readonly nodeModules: string;
|
|
15
|
+
/** pnpm node_modules 目录路径 */ readonly pnpmNodeModules: string;
|
|
16
|
+
/** deno node_modules 目录路径 */ readonly denoNodeModules: string;
|
|
17
|
+
/** 核心代码路径 */ readonly corePath: string;
|
|
18
|
+
/** 项目根目录路径 */ readonly programPath: string;
|
|
19
|
+
/** CA 目录路径 */ readonly CA_DIR: string;
|
|
20
|
+
/** webpack 缓存目录路径 */ readonly webpackCachePath: string;
|
|
21
|
+
/** 代码检查工具(ESLint、Stylelint等)的缓存目录路径 */ readonly lintCachePath: string;
|
|
22
|
+
/** HTTP 远程模块缓存路径 */ readonly httpCachePath: string;
|
|
23
|
+
/** SWC 缓存目录路径 */ readonly swcCachePath: string;
|
|
24
|
+
/** 默认配置文件路径 */ readonly configPath: string;
|
|
25
|
+
/** 自定义配置文件路径 */ readonly customConfigPath: string;
|
|
26
|
+
/** 测试覆盖率报告路径 */ readonly coveragePath: string;
|
|
27
|
+
/** 页面目录路径 */ readonly pagesPath: string;
|
|
28
|
+
/** 组件目录路径 */ readonly componentsPath: string;
|
|
29
|
+
/** Mock 数据目录路径 */ readonly mockPath: string;
|
|
30
|
+
};
|
|
31
|
+
export declare const config_files: string[];
|
|
32
|
+
export declare const routeDir: string;
|
|
33
|
+
export default paths;
|
|
@@ -6,6 +6,7 @@ declare class ReactiveObject<T extends object = Record<string, unknown | undefin
|
|
|
6
6
|
setData(key: keyof T, value: T[keyof T]): void;
|
|
7
7
|
getData(key: keyof T): T[keyof T];
|
|
8
8
|
removeData(key: keyof T): void;
|
|
9
|
+
// 实现迭代器接口
|
|
9
10
|
[Symbol.iterator](): Iterator<[keyof T, T[keyof T]]>;
|
|
10
11
|
}
|
|
11
12
|
export default ReactiveObject;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
interface SetupEnv {
|
|
2
2
|
NODE_ENV: string;
|
|
3
3
|
APPTYPE: string;
|
|
4
4
|
FRAMEWORK: string;
|
|
5
5
|
IS_BUILD: boolean;
|
|
6
|
-
|
|
6
|
+
[key: string]: string | boolean | number;
|
|
7
|
+
}
|
|
8
|
+
declare function setupEnv(mode: string, type: string, framework: string, args: string[], IS_BUILD: boolean): Promise<SetupEnv>;
|
|
7
9
|
export default setupEnv;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type MemberTransformer = /** 帕斯卡拼写法(大驼峰): 所有单词的首字母大写,然后直接连接起来,单词之间没有连接符 */ 'pascal_case' | 'camel_case' | 'kebab_case' | 'dashed_case' | 'snake_case' | 'upper_case' | 'upper_first' | 'lower_case' | 'lower_first';
|
|
2
|
+
export interface TransformerOption {
|
|
3
|
+
/**
|
|
4
|
+
* 要使用的库名称,而不是导入语句中指定的库名称。`${member}` 是替换的成员
|
|
5
|
+
*/ transform: string;
|
|
6
|
+
/**
|
|
7
|
+
* 设置转换时需要单独导入的样式,`${member}` 是替换的成员
|
|
8
|
+
* @default false
|
|
9
|
+
*/ style?: string | boolean;
|
|
10
|
+
/**
|
|
11
|
+
* 当设置为true时,将保留 `import { Button }` 语法,而不是转换为 `import Button`
|
|
12
|
+
* @default false
|
|
13
|
+
*/ skipDefaultConversion?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 当遇到会导致导入整个模块时,是否抛出
|
|
16
|
+
* @default true
|
|
17
|
+
*/ preventFullImport?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* `${member}` 成员转换规则
|
|
20
|
+
* @default []
|
|
21
|
+
*/ memberTransformers?: MemberTransformer[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 引入语法转换
|
|
25
|
+
* @example
|
|
26
|
+
* ```javascript
|
|
27
|
+
* // 案例
|
|
28
|
+
* const conf = {
|
|
29
|
+
* importOnDemand: {
|
|
30
|
+
* antd: {
|
|
31
|
+
* transform: 'lib/${member}',
|
|
32
|
+
* skipDefaultConversion: false,
|
|
33
|
+
* preventFullImport: true,
|
|
34
|
+
* style: 'lib/${member}/style',
|
|
35
|
+
* memberTransformers: ['dashed_case'],
|
|
36
|
+
* },
|
|
37
|
+
* lodash: {
|
|
38
|
+
* transform: '${member}',
|
|
39
|
+
* preventFullImport: true,
|
|
40
|
+
* },
|
|
41
|
+
* },
|
|
42
|
+
* };
|
|
43
|
+
* // 以下代码将会按照预期进行转换
|
|
44
|
+
* import { Button as MyButton, BackTop } from "antd";
|
|
45
|
+
* import { merge } from "lodash";
|
|
46
|
+
* // to
|
|
47
|
+
* import MyButton from "antd/lib/button";
|
|
48
|
+
* import BackTop from "antd/lib/back-top";
|
|
49
|
+
* import "antd/lib/back-top/style";
|
|
50
|
+
* import "antd/lib/button/style";
|
|
51
|
+
* import merge from "lodash/merge";
|
|
52
|
+
* ```
|
|
53
|
+
*/ export type SwcImportOnDemandTransform = Record<string, TransformerOption | false>;
|
|
54
|
+
export declare function swcImportOnDemandConfig(config: SwcImportOnDemandTransform): SwcImportOnDemandTransform;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import webpack from 'webpack';
|
|
2
|
+
export declare const PORT: number;
|
|
3
|
+
export declare function getServerAddress(type: 'local' | 'net'): string;
|
|
4
|
+
// const serverSuccessMsg: string = `${ink(' Local ', '231', { bg: 'blue' })} ${ink(
|
|
5
|
+
// getServerAddress('local'),
|
|
6
|
+
// '75',
|
|
7
|
+
// )}
|
|
8
|
+
// ${ink(' Network ', '231', { bg: '29' })} ${ink(getServerAddress('net'), 'green')}`;
|
|
9
|
+
export declare function devLog(err?: Error | null, stats?: webpack.Stats): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface CertInstallOption {
|
|
2
|
+
install: boolean;
|
|
3
|
+
}
|
|
4
|
+
interface CertKeyCertOption {
|
|
5
|
+
key: string;
|
|
6
|
+
cert: string;
|
|
7
|
+
}
|
|
8
|
+
export type CertOption = CertInstallOption | CertKeyCertOption;
|
|
9
|
+
declare function getCert(domain: string, option: CertOption): Promise<CertKeyCertOption>;
|
|
10
|
+
export default getCert;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1
2
|
type Any = any;
|
|
2
3
|
type NonArraySchemaObjectType = 'boolean' | 'object' | 'number' | 'string' | 'integer';
|
|
3
4
|
type ArraySchemaObjectType = 'array';
|
|
@@ -66,5 +67,6 @@ interface XMLObject {
|
|
|
66
67
|
interface ReferenceObject {
|
|
67
68
|
$ref: string;
|
|
68
69
|
}
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
71
|
export declare function jsonSchema<T>(schema: SchemaObject): any;
|
|
70
|
-
export {};
|
|
72
|
+
export { };
|
package/lib/dev/mock.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{watch as e}from"node:fs";import t from"node:http";import{join as r}from"node:path";import{StringDecoder as o}from"node:string_decoder";import{URL as n}from"node:url";import{directoryExists as a,ink as i,print as c,scanFolderSync as s}from"@moneko/utils";import{merge as m}from"webpack-merge";import d from"../commom/log.mjs";import l from"../commom/match-path.mjs";import p from"../commom/paths.mjs";import u,{METHOD_COLOR as f}from"../commom/print-log.mjs";import h from"../commom/require.mjs";import g from"../commom/sigint-exit.mjs";import{jsonSchema as y}from"./json-schema.mjs";function b(e){return!["GET","HEAD","OPTIONS"].includes(e.method?.toUpperCase()||"")}export function cacheBody(e){if(!e._bodyCached&&b(e)&&!e.readableEnded){e._bodyCached=!0;try{let t=[],r=e.on.bind(e),o=e.emit.bind(e),n=!1;e.on=function(e,o){return"data"!==e||n||(n=!0,r("data",e=>{t.push(e)})),r(e,o)};let a=!1;e.emit=function(r,...n){return"end"===r&&!a&&(a=!0,t.length>0&&(e._dataChunks=t)),o.call(this,r,...n)}}catch(e){d(e)}}}function k(e,t){try{let r=Buffer.concat(e);if(t.includes("application/json")){let e=new o("utf-8").write(r);return JSON.parse(e)}if(t.includes("application/octet-stream")||t.startsWith("image/"));else if(t.includes("text/"))return r.toString("utf-8");else if(t.includes("application/x-www-form-urlencoded"))return Object.fromEntries(new URLSearchParams(r.toString("utf8")));return r}catch(e){return d(e),null}}async function j(e){return new Promise(t=>{if(!b(e))return void t(null);let r=e.headers["content-type"]||"",o=e.headers["content-length"],n=e.headers["transfer-encoding"],a=[];void 0!==e._dataChunks?t(k(e._dataChunks,r)):o||n?(e.on("data",e=>{a.push(e)}),e.on("end",()=>{t(k(a,r))}),e.on("error",e=>{t(null),d(e)})):t(null)})}export const yApiSchemaMock=(e,r)=>new Promise(o=>{t.get(`${e.host}/api/interface/get?id=${e.id}&token=${e.token}`,e=>{e.setEncoding("utf8");let t="";e.on("data",e=>{t+=e}),e.on("end",()=>{try{let e=JSON.parse(t);if(e?.data?.res_body_is_json_schema){let t=JSON.parse(e.data.res_body),n=y(t);void 0!==r?o(m(n,r)):o(n)}}catch(e){d(e)}})})});export const yApiMock=(e,r)=>new Promise((o,a)=>{let i=new n(r.host),c={hostname:i.hostname,port:i.port,path:e.url?.replace(new RegExp(r.pathRewrite),`/mock/${r.projectId}/`),method:e.method,headers:e.headers,query:Object.fromEntries(i.searchParams)},s=t.request(c,e=>{e.setEncoding("utf8");let t="";e.on("data",e=>{t+=e}),e.on("end",()=>{try{o(JSON.parse(t))}catch(e){d(e)}})});s.on("error",e=>{a(e.message)}),s.write(JSON.stringify(e.body)),s.end()});let w=()=>{if(!a(p.mockPath)){O={};return}let e={},t=s(p.mockPath,["\\.(t|j)s$"]);c(i("Updating mock...","245"),!0),t.forEach(t=>{try{Object.assign(e,h(t).default)}catch(e){d(e)}}),c(i("Mock update successful","245"),!0),O=e},O={};w();export function containMockUrl(e){return Object.keys(O).find(t=>RegExp(`^${t.replace(/(:\w*)[^/]/g,"((?!/).)")}*$`).test(e))}
|
|
1
|
+
import{watch as e}from"node:fs";import t from"node:http";import{join as r}from"node:path";import{StringDecoder as o}from"node:string_decoder";import{URL as n}from"node:url";import{directoryExists as a,ink as i,print as c,scanFolderSync as s}from"@moneko/utils";import{merge as m}from"webpack-merge";import d from"../commom/log.mjs";import l from"../commom/match-path.mjs";import p from"../commom/paths.mjs";import u,{METHOD_COLOR as f}from"../commom/print-log.mjs";import h from"../commom/require.mjs";import g from"../commom/sigint-exit.mjs";import{jsonSchema as y}from"./json-schema.mjs";function b(e){return!["GET","HEAD","OPTIONS"].includes(e.method?.toUpperCase()||"")}export function cacheBody(e){if(!e._bodyCached&&b(e)&&!e.readableEnded){e._bodyCached=!0;try{let t=[],r=e.on.bind(e),o=e.emit.bind(e),n=!1;e.on=function(e,o){return"data"!==e||n||(n=!0,r("data",e=>{t.push(e)})),r(e,o)};let a=!1;e.emit=function(r,...n){return"end"===r&&!a&&(a=!0,t.length>0&&(e._dataChunks=t)),o.call(this,r,...n)}}catch(e){d(e)}}}function k(e,t){try{let r=Buffer.concat(e);if(t.includes("application/json")){let e=new o("utf-8").write(r);return JSON.parse(e)}if(t.includes("application/octet-stream")||t.startsWith("image/"));else if(t.includes("text/"))return r.toString("utf-8");else if(t.includes("application/x-www-form-urlencoded"))return Object.fromEntries(new URLSearchParams(r.toString("utf8")));return r}catch(e){return d(e),null}}async function j(e){return new Promise(t=>{if(!b(e))return void t(null);let r=e.headers["content-type"]||"",o=e.headers["content-length"],n=e.headers["transfer-encoding"],a=[];void 0!==e._dataChunks?t(k(e._dataChunks,r)):o||n?(e.on("data",e=>{a.push(e)}),e.on("end",()=>{t(k(a,r))}),e.on("error",e=>{t(null),d(e)})):t(null)})}export const yApiSchemaMock=(e,r)=>new Promise(o=>{t.get(`${e.host}/api/interface/get?id=${e.id}&token=${e.token}`,e=>{e.setEncoding("utf8");let t="";e.on("data",e=>{t+=e}),e.on("end",()=>{try{let e=JSON.parse(t);if(e?.data?.res_body_is_json_schema){let t=JSON.parse(e.data.res_body),n=y(t);void 0!==r?o(m(n,r)):o(n)}}catch(e){d(e)}})})});export const yApiMock=(e,r)=>new Promise((o,a)=>{let i=new n(r.host),c={hostname:i.hostname,port:i.port,path:e.url?.replace(new RegExp(r.pathRewrite),`/mock/${r.projectId}/`),method:e.method,headers:e.headers,query:Object.fromEntries(i.searchParams)},s=t.request(c,e=>{e.setEncoding("utf8");let t="";e.on("data",e=>{t+=e}),e.on("end",()=>{try{o(JSON.parse(t))}catch(e){d(e)}})});s.on("error",e=>{a(e.message)}),s.write(JSON.stringify(e.body)),s.end()});let w=()=>{if(!a(p.mockPath)){O={};return}let e={},t=s(p.mockPath,["\\.(t|j)s$"]);c(i("Updating mock...","245"),!0),t.forEach(t=>{try{Object.assign(e,h(t).default)}catch(e){d(e)}}),c(i("Mock update successful","245"),!0),O=e},O={};w();export function containMockUrl(e){return Object.keys(O).find(t=>RegExp(`^${t.replace(/(:\w*)[^/]/g,"((?!/).)")}*$`).test(e))}function E(e,t){if(t.writableEnded)return t;let r=new n(`http://localhost:3000${e.url}`),o=e.method||"GET",a=`${o} ${r.pathname}`,i=containMockUrl(a)||a,c=O[i];if(c){if(u(o,r.pathname,{note:"MOCK",labelAlign:"center",labelLen:8,labelForegroundColor:f[o].fg,labelBackgroundColor:f[o].bg}),t.send=e=>t.end("string"==typeof e?e:JSON.stringify(e)),t.writeHead(200,{"Content-Type":e.headers["content-type"]}),"function"==typeof c){let o=l(i.split(" ")[1],r.pathname);r.searchParams&&Object.assign(e,{query:Object.fromEntries(r.searchParams)}),o&&Object.assign(e,{params:o.params}),e.body=j(e);try{c(e,t)}catch(e){d(e)}return!0}return t.end("string"==typeof c?c:JSON.stringify(c)),!0}return!1}export default(()=>{if(!a(p.mockPath))return;let t=e(p.mockPath,(e,t)=>{if(t){let e=r(p.mockPath,t);delete h.cache[e]}w()});return g(()=>{t.close()}),E});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
2
|
export declare function cacheBody(req: RequestFormData & {
|
|
3
3
|
_bodyCached?: boolean;
|
|
4
4
|
_dataChunks?: Uint8Array[];
|
|
5
5
|
}): void;
|
|
6
|
+
// 更新请求类型定义
|
|
6
7
|
export interface RequestFormData extends IncomingMessage {
|
|
7
8
|
files?: {
|
|
8
9
|
fieldname: string;
|
|
@@ -20,43 +21,38 @@ export interface MockServerResponse extends ServerResponse<IncomingMessage> {
|
|
|
20
21
|
req: IncomingMessage;
|
|
21
22
|
send<T>(chunk: T): ReturnType<ServerResponse<IncomingMessage>['end']>;
|
|
22
23
|
}
|
|
24
|
+
// 更新处理函数类型
|
|
23
25
|
export type ProxyFuncType = (req: RequestFormData, res: MockServerResponse) => void | Promise<void>;
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
27
|
export type MockConfiguration = Record<string, ProxyFuncType | Record<string, any> | null>;
|
|
25
28
|
export type YApiOptionBySchema = {
|
|
26
|
-
/** YApi host */
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
id: string;
|
|
30
|
-
/** YApi开放接口token */
|
|
31
|
-
token: string;
|
|
29
|
+
/** YApi host */ host: string;
|
|
30
|
+
/** 接口id */ id: string;
|
|
31
|
+
/** YApi开放接口token */ token: string;
|
|
32
32
|
};
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
34
|
type Any = any;
|
|
34
35
|
/**
|
|
35
36
|
* 通过 YApi 接口对应的响应JSON Schema生成默认的数据
|
|
36
37
|
* @param {YApiOptionBySchema} option Schema
|
|
37
38
|
* @param {T} data data
|
|
38
39
|
* @returns {Promise} mockData
|
|
39
|
-
*/
|
|
40
|
-
export declare const yApiSchemaMock: <T extends Any>(option: YApiOptionBySchema, data?: T) => Promise<T>;
|
|
40
|
+
*/ export declare const yApiSchemaMock: <T extends Any>(option: YApiOptionBySchema, data?: T) => Promise<T>;
|
|
41
41
|
export type YApiOption = {
|
|
42
|
-
/** YApi host */
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
projectId: number;
|
|
46
|
-
/** 重写请求路径, 例如:'^/api/' */
|
|
47
|
-
pathRewrite: string;
|
|
42
|
+
/** YApi host */ host: string;
|
|
43
|
+
/** YApi 项目ID */ projectId: number;
|
|
44
|
+
/** 重写请求路径, 例如:'^/api/' */ pathRewrite: string;
|
|
48
45
|
};
|
|
49
46
|
/**
|
|
50
47
|
* 请求YApi高级mock接口数据
|
|
51
48
|
* @param {RequestFormData} req req
|
|
52
49
|
* @param {YApiOption} yapi YApiOption
|
|
53
50
|
* @returns {Promise} data
|
|
54
|
-
*/
|
|
55
|
-
export declare const yApiMock: (req: RequestFormData, yapi: YApiOption) => Promise<Any>;
|
|
51
|
+
*/ export declare const yApiMock: (req: RequestFormData, yapi: YApiOption) => Promise<Any>;
|
|
56
52
|
export declare function containMockUrl(url: string): string | undefined;
|
|
57
|
-
|
|
53
|
+
type MockResponse = ServerResponse<IncomingMessage> & {
|
|
58
54
|
req: IncomingMessage;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
};
|
|
56
|
+
declare function mockPlugin(req: RequestFormData, res: MockResponse): boolean | MockResponse;
|
|
57
|
+
declare const setupMock: () => typeof mockPlugin | void;
|
|
62
58
|
export default setupMock;
|
package/lib/dev.mjs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|