@4399ywkf/core 4.0.61

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.
Files changed (61) hide show
  1. package/README.md +3 -0
  2. package/compiled/dotenv/LICENSE +23 -0
  3. package/compiled/dotenv/index.js +1 -0
  4. package/compiled/dotenv/lib/main.d.ts +73 -0
  5. package/compiled/dotenv/package.json +1 -0
  6. package/compiled/dotenv/types/index.d.ts +59 -0
  7. package/compiled/dotenv-expand/LICENSE +24 -0
  8. package/compiled/dotenv-expand/index.js +1 -0
  9. package/compiled/dotenv-expand/lib/main.d.ts +29 -0
  10. package/compiled/dotenv-expand/package.json +1 -0
  11. package/compiled/just-diff/LICENSE +21 -0
  12. package/compiled/just-diff/index.d.ts +20 -0
  13. package/compiled/just-diff/index.js +1 -0
  14. package/compiled/just-diff/package.json +1 -0
  15. package/dist/config/config.d.ts +62 -0
  16. package/dist/config/config.js +240 -0
  17. package/dist/config/utils.d.ts +8 -0
  18. package/dist/config/utils.js +40 -0
  19. package/dist/constants.d.ts +9 -0
  20. package/dist/constants.js +45 -0
  21. package/dist/index.d.ts +6 -0
  22. package/dist/index.js +51 -0
  23. package/dist/route/defineRoutes.d.ts +1 -0
  24. package/dist/route/defineRoutes.js +61 -0
  25. package/dist/route/route.d.ts +3 -0
  26. package/dist/route/route.js +27 -0
  27. package/dist/route/routeUtils.d.ts +8 -0
  28. package/dist/route/routeUtils.js +46 -0
  29. package/dist/route/routesConfig.d.ts +6 -0
  30. package/dist/route/routesConfig.js +125 -0
  31. package/dist/route/routesConvention.d.ts +5 -0
  32. package/dist/route/routesConvention.js +88 -0
  33. package/dist/route/utils.d.ts +8 -0
  34. package/dist/route/utils.js +59 -0
  35. package/dist/service/command.d.ts +30 -0
  36. package/dist/service/command.js +46 -0
  37. package/dist/service/env.d.ts +4 -0
  38. package/dist/service/env.js +46 -0
  39. package/dist/service/generatePlugin.d.ts +4 -0
  40. package/dist/service/generatePlugin.js +102 -0
  41. package/dist/service/generator.d.ts +71 -0
  42. package/dist/service/generator.js +40 -0
  43. package/dist/service/hook.d.ts +16 -0
  44. package/dist/service/hook.js +57 -0
  45. package/dist/service/path.d.ts +15 -0
  46. package/dist/service/path.js +55 -0
  47. package/dist/service/plugin.d.ts +61 -0
  48. package/dist/service/plugin.js +177 -0
  49. package/dist/service/pluginAPI.d.ts +49 -0
  50. package/dist/service/pluginAPI.js +237 -0
  51. package/dist/service/service.d.ts +147 -0
  52. package/dist/service/service.js +538 -0
  53. package/dist/service/servicePlugin.d.ts +3 -0
  54. package/dist/service/servicePlugin.js +37 -0
  55. package/dist/service/telemetry.d.ts +32 -0
  56. package/dist/service/telemetry.js +127 -0
  57. package/dist/service/utils.d.ts +2 -0
  58. package/dist/service/utils.js +36 -0
  59. package/dist/types.d.ts +116 -0
  60. package/dist/types.js +77 -0
  61. package/package.json +49 -0
@@ -0,0 +1,46 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/service/env.ts
20
+ var env_exports = {};
21
+ __export(env_exports, {
22
+ loadEnv: () => loadEnv
23
+ });
24
+ module.exports = __toCommonJS(env_exports);
25
+ var import_fs = require("fs");
26
+ var import_path = require("path");
27
+ var import_dotenv = require("../../compiled/dotenv");
28
+ var import_dotenv_expand = require("../../compiled/dotenv-expand");
29
+ function loadEnv(opts) {
30
+ const files = [
31
+ (0, import_path.join)(opts.cwd, opts.envFile),
32
+ (0, import_path.join)(opts.cwd, `${opts.envFile}.local`)
33
+ ];
34
+ for (const file of files) {
35
+ if (!(0, import_fs.existsSync)(file)) continue;
36
+ const parsed = (0, import_dotenv.parse)((0, import_fs.readFileSync)(file)) || {};
37
+ (0, import_dotenv_expand.expand)({ parsed, ignoreProcessEnv: true });
38
+ for (const key of Object.keys(parsed)) {
39
+ process.env[key] = parsed[key];
40
+ }
41
+ }
42
+ }
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ loadEnv
46
+ });
@@ -0,0 +1,4 @@
1
+ import { PluginAPI } from './pluginAPI';
2
+ import { IServicePluginAPI } from './service';
3
+ declare const _default: (api: PluginAPI & IServicePluginAPI) => void;
4
+ export default _default;
@@ -0,0 +1,102 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/service/generatePlugin.ts
20
+ var generatePlugin_exports = {};
21
+ __export(generatePlugin_exports, {
22
+ default: () => generatePlugin_default
23
+ });
24
+ module.exports = __toCommonJS(generatePlugin_exports);
25
+ var import_utils = require("@4399ywkf/utils");
26
+ var import_generator = require("./generator");
27
+ var generatePlugin_default = (api) => {
28
+ api.registerCommand({
29
+ name: "generate",
30
+ alias: "g",
31
+ details: `
32
+ umi generate
33
+ `,
34
+ description: "generate code snippets quickly",
35
+ configResolveMode: "loose",
36
+ async fn({ args }) {
37
+ var _a;
38
+ const [type] = args._;
39
+ const runGenerator = async (generator) => {
40
+ await (generator == null ? void 0 : generator.fn({
41
+ args,
42
+ generateFile: import_utils.generateFile,
43
+ installDeps: import_utils.installDeps,
44
+ updatePackageJSON: import_utils.updatePackageJSON
45
+ }));
46
+ };
47
+ if (type) {
48
+ const generator = api.service.generators[type];
49
+ if (!generator) {
50
+ throw new Error(`Generator ${type} not found.`);
51
+ }
52
+ if (generator.type === import_generator.GeneratorType.enable) {
53
+ const enable = await ((_a = generator.checkEnable) == null ? void 0 : _a.call(generator, {
54
+ args
55
+ }));
56
+ if (!enable) {
57
+ if (typeof generator.disabledDescription === "function") {
58
+ import_utils.logger.warn(generator.disabledDescription());
59
+ } else {
60
+ import_utils.logger.warn(generator.disabledDescription);
61
+ }
62
+ return;
63
+ }
64
+ }
65
+ await runGenerator(generator);
66
+ } else {
67
+ const getEnableGenerators = async (generators) => {
68
+ var _a2;
69
+ const questions2 = [];
70
+ for (const key of Object.keys(generators)) {
71
+ const g = generators[key];
72
+ if (g.type === import_generator.GeneratorType.generate) {
73
+ questions2.push({
74
+ title: `${g.name} -- ${g.description}` || "",
75
+ value: g.key
76
+ });
77
+ } else {
78
+ const enable = await ((_a2 = g == null ? void 0 : g.checkEnable) == null ? void 0 : _a2.call(g, {
79
+ args
80
+ }));
81
+ if (enable) {
82
+ questions2.push({
83
+ title: `${g.name} -- ${g.description}` || "",
84
+ value: g.key
85
+ });
86
+ }
87
+ }
88
+ }
89
+ return questions2;
90
+ };
91
+ const questions = await getEnableGenerators(api.service.generators);
92
+ const { gType } = await (0, import_utils.prompts)({
93
+ type: "select",
94
+ name: "gType",
95
+ message: "Pick generator type",
96
+ choices: questions
97
+ });
98
+ await runGenerator(api.service.generators[gType]);
99
+ }
100
+ }
101
+ });
102
+ };
@@ -0,0 +1,71 @@
1
+ import { generateFile } from '@4399ywkf/utils';
2
+ import { Plugin } from './plugin';
3
+ export declare enum GeneratorType {
4
+ generate = "generate",
5
+ enable = "enable"
6
+ }
7
+ declare type IGeneratorOptsWithoutEnableCheck = {
8
+ key: string;
9
+ name: string;
10
+ description: string;
11
+ type: GeneratorType.generate;
12
+ fn: {
13
+ (opts: {
14
+ args: any;
15
+ generateFile: typeof generateFile;
16
+ updatePackageJSON: {
17
+ (opts: {
18
+ opts: object;
19
+ cwd?: string;
20
+ }): void;
21
+ };
22
+ installDeps: {
23
+ (opts: {
24
+ opts: {
25
+ devDependencies?: string[];
26
+ dependencies?: string[];
27
+ };
28
+ cwd?: string;
29
+ }): void;
30
+ };
31
+ }): void;
32
+ };
33
+ plugin: Plugin;
34
+ };
35
+ declare type IGeneratorOptsWithEnableCheck = {
36
+ key: string;
37
+ name: string;
38
+ description: string;
39
+ type: GeneratorType.enable;
40
+ checkEnable: {
41
+ (opts: {
42
+ args: any;
43
+ }): boolean;
44
+ };
45
+ disabledDescription: string | (() => string);
46
+ fn: {
47
+ (opts: {
48
+ args: any;
49
+ generateFile: typeof generateFile;
50
+ updatePackageJSON: {
51
+ (opts: {
52
+ opts: object;
53
+ cwd?: string;
54
+ }): void;
55
+ };
56
+ installDeps: {
57
+ (opts: {
58
+ opts: {
59
+ devDependencies?: string[];
60
+ dependencies?: string[];
61
+ };
62
+ cwd?: string;
63
+ }): void;
64
+ };
65
+ }): void;
66
+ };
67
+ plugin: Plugin;
68
+ };
69
+ export declare type Generator = IGeneratorOptsWithEnableCheck | IGeneratorOptsWithoutEnableCheck;
70
+ export declare function makeGenerator<T>(opts: T): T;
71
+ export {};
@@ -0,0 +1,40 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/service/generator.ts
20
+ var generator_exports = {};
21
+ __export(generator_exports, {
22
+ GeneratorType: () => GeneratorType,
23
+ makeGenerator: () => makeGenerator
24
+ });
25
+ module.exports = __toCommonJS(generator_exports);
26
+ var GeneratorType = /* @__PURE__ */ ((GeneratorType2) => {
27
+ GeneratorType2["generate"] = "generate";
28
+ GeneratorType2["enable"] = "enable";
29
+ return GeneratorType2;
30
+ })(GeneratorType || {});
31
+ function makeGenerator(opts) {
32
+ return {
33
+ ...opts
34
+ };
35
+ }
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ GeneratorType,
39
+ makeGenerator
40
+ });
@@ -0,0 +1,16 @@
1
+ import { Plugin } from './plugin';
2
+ export interface IOpts {
3
+ plugin: Plugin;
4
+ key: string;
5
+ fn: Function;
6
+ before?: string;
7
+ stage?: number;
8
+ }
9
+ export declare class Hook {
10
+ plugin: Plugin;
11
+ key: string;
12
+ fn: Function;
13
+ before?: string;
14
+ stage?: number;
15
+ constructor(opts: IOpts);
16
+ }
@@ -0,0 +1,57 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/service/hook.ts
30
+ var hook_exports = {};
31
+ __export(hook_exports, {
32
+ Hook: () => Hook
33
+ });
34
+ module.exports = __toCommonJS(hook_exports);
35
+ var import_assert = __toESM(require("assert"));
36
+ var Hook = class {
37
+ plugin;
38
+ key;
39
+ fn;
40
+ before;
41
+ stage;
42
+ constructor(opts) {
43
+ (0, import_assert.default)(
44
+ opts.key && opts.fn,
45
+ `Invalid hook ${opts}, key and fn must supplied.`
46
+ );
47
+ this.plugin = opts.plugin;
48
+ this.key = opts.key;
49
+ this.fn = opts.fn;
50
+ this.before = opts.before;
51
+ this.stage = opts.stage || 0;
52
+ }
53
+ };
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ Hook
57
+ });
@@ -0,0 +1,15 @@
1
+ import { Env } from '../types';
2
+ export declare function getPaths(opts: {
3
+ cwd: string;
4
+ prefix: string;
5
+ env: Env;
6
+ }): {
7
+ cwd: string;
8
+ absSrcPath: string;
9
+ absPagesPath: string;
10
+ absApiRoutesPath: string;
11
+ absTmpPath: string;
12
+ absNodeModulesPath: string;
13
+ absOutputPath: string;
14
+ };
15
+ export declare type Paths = ReturnType<typeof getPaths>;
@@ -0,0 +1,55 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/service/path.ts
20
+ var path_exports = {};
21
+ __export(path_exports, {
22
+ getPaths: () => getPaths
23
+ });
24
+ module.exports = __toCommonJS(path_exports);
25
+ var import_utils = require("@4399ywkf/utils");
26
+ var import_fs = require("fs");
27
+ var import_path = require("path");
28
+ var import_types = require("../types");
29
+ function winJoin(...args) {
30
+ return (0, import_utils.winPath)((0, import_path.join)(...args));
31
+ }
32
+ function getPaths(opts) {
33
+ const cwd = opts.cwd;
34
+ const src = winJoin(cwd, "src");
35
+ const absSrcPath = (0, import_fs.existsSync)(src) && (0, import_fs.statSync)(src).isDirectory() ? src : cwd;
36
+ const absPagesPath = winJoin(absSrcPath, "pages");
37
+ const absApiRoutesPath = winJoin(absSrcPath, "api");
38
+ const tmp = opts.env === import_types.Env.development ? `.${opts.prefix}` : `.${opts.prefix}-${opts.env}`;
39
+ const absTmpPath = winJoin(absSrcPath, tmp);
40
+ const absNodeModulesPath = winJoin(cwd, "node_modules");
41
+ const absOutputPath = winJoin(cwd, "dist");
42
+ return {
43
+ cwd,
44
+ absSrcPath,
45
+ absPagesPath,
46
+ absApiRoutesPath,
47
+ absTmpPath,
48
+ absNodeModulesPath,
49
+ absOutputPath
50
+ };
51
+ }
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ getPaths
55
+ });
@@ -0,0 +1,61 @@
1
+ import { EnableBy, Env, IPluginConfig } from '../types';
2
+ declare type PluginType = 'plugin' | 'preset';
3
+ interface IOpts {
4
+ path: string;
5
+ cwd: string;
6
+ type: PluginType;
7
+ }
8
+ export interface IPluginObject {
9
+ id: string;
10
+ key: string;
11
+ apply?: Function;
12
+ config?: IPluginConfig;
13
+ enableBy?: EnableBy | (() => boolean);
14
+ }
15
+ export declare class Plugin {
16
+ private cwd;
17
+ type: PluginType;
18
+ path: string;
19
+ id: string;
20
+ key: string;
21
+ apply: Function;
22
+ config: IPluginConfig;
23
+ time: {
24
+ register?: number;
25
+ hooks: Record<string, number[]>;
26
+ };
27
+ enableBy: EnableBy | ((opts: {
28
+ userConfig: any;
29
+ config: any;
30
+ env: Env;
31
+ }) => boolean);
32
+ constructor(opts: IOpts);
33
+ merge(opts: {
34
+ key?: string;
35
+ config?: IPluginConfig;
36
+ enableBy?: any;
37
+ }): void;
38
+ getId(opts: {
39
+ pkg: any;
40
+ isPkgEntry: boolean;
41
+ pkgJSONPath: string | null;
42
+ }): any;
43
+ getKey(opts: {
44
+ pkg: any;
45
+ isPkgEntry: boolean;
46
+ }): string;
47
+ static isPluginOrPreset(type: 'plugin' | 'preset', name: string): boolean;
48
+ static stripNoneUmiScope(name: string): string;
49
+ static getPluginsAndPresets(opts: {
50
+ cwd: string;
51
+ pkg: any;
52
+ userConfig: any;
53
+ plugins?: string[];
54
+ presets?: string[];
55
+ prefix: string;
56
+ }): {
57
+ presets: Plugin[];
58
+ plugins: Plugin[];
59
+ };
60
+ }
61
+ export {};
@@ -0,0 +1,177 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/service/plugin.ts
30
+ var plugin_exports = {};
31
+ __export(plugin_exports, {
32
+ Plugin: () => Plugin
33
+ });
34
+ module.exports = __toCommonJS(plugin_exports);
35
+ var import_esbuild = __toESM(require("@4399ywkf/bundler-utils/compiled/esbuild"));
36
+ var import_utils = require("@4399ywkf/utils");
37
+ var import_assert = __toESM(require("assert"));
38
+ var import_fs = require("fs");
39
+ var import_path = require("path");
40
+ var import_types = require("../types");
41
+ var RE = {
42
+ plugin: /^(@umijs\/|umi-)plugin-/,
43
+ preset: /^(@umijs\/|umi-)preset-/
44
+ };
45
+ var Plugin = class _Plugin {
46
+ cwd;
47
+ type;
48
+ path;
49
+ id;
50
+ key;
51
+ apply;
52
+ config = {};
53
+ time = { hooks: {} };
54
+ enableBy = import_types.EnableBy.register;
55
+ constructor(opts) {
56
+ this.type = opts.type;
57
+ this.path = (0, import_utils.winPath)(opts.path);
58
+ this.cwd = opts.cwd;
59
+ (0, import_assert.default)(
60
+ (0, import_fs.existsSync)(this.path),
61
+ `Invalid ${this.type} ${this.path}, it's not exists.`
62
+ );
63
+ let pkg = null;
64
+ let isPkgEntry = false;
65
+ const pkgJSONPath = import_utils.pkgUp.pkgUpSync({ cwd: this.path });
66
+ if (pkgJSONPath) {
67
+ pkg = require(pkgJSONPath);
68
+ isPkgEntry = (0, import_utils.winPath)((0, import_path.join)((0, import_path.dirname)(pkgJSONPath), pkg.main || "index.js")) === (0, import_utils.winPath)(this.path);
69
+ }
70
+ this.id = this.getId({ pkg, isPkgEntry, pkgJSONPath });
71
+ this.key = this.getKey({ pkg, isPkgEntry });
72
+ this.apply = () => {
73
+ import_utils.register.register({
74
+ implementor: import_esbuild.default,
75
+ exts: [".ts", ".mjs"]
76
+ });
77
+ import_utils.register.clearFiles();
78
+ let ret;
79
+ try {
80
+ ret = require(this.path);
81
+ } catch (e) {
82
+ throw new Error(
83
+ `Register ${this.type} ${this.path} failed, since ${e.message}`,
84
+ { cause: e }
85
+ );
86
+ } finally {
87
+ import_utils.register.restore();
88
+ }
89
+ return ret.__esModule ? ret.default : ret;
90
+ };
91
+ }
92
+ merge(opts) {
93
+ if (opts.key) this.key = opts.key;
94
+ if (opts.config) this.config = opts.config;
95
+ if (opts.enableBy) this.enableBy = opts.enableBy;
96
+ }
97
+ getId(opts) {
98
+ let id;
99
+ if (opts.isPkgEntry) {
100
+ id = opts.pkg.name;
101
+ } else if ((0, import_utils.winPath)(this.path).startsWith((0, import_utils.winPath)(this.cwd))) {
102
+ id = `./${(0, import_utils.winPath)((0, import_path.relative)(this.cwd, this.path))}`;
103
+ } else if (opts.pkgJSONPath) {
104
+ id = (0, import_utils.winPath)(
105
+ (0, import_path.join)(opts.pkg.name, (0, import_path.relative)((0, import_path.dirname)(opts.pkgJSONPath), this.path))
106
+ );
107
+ } else {
108
+ id = (0, import_utils.winPath)(this.path);
109
+ }
110
+ id = id.replace("@4399ywkf/preset-umi/lib/plugins", "@@");
111
+ id = id.replace(/\.js$/, "");
112
+ return id;
113
+ }
114
+ getKey(opts) {
115
+ function nameToKey(name) {
116
+ return name.split(".").map((part) => import_utils.lodash.camelCase(part)).join(".");
117
+ }
118
+ return nameToKey(
119
+ opts.isPkgEntry ? _Plugin.stripNoneUmiScope(opts.pkg.name).replace(RE[this.type], "") : (0, import_path.basename)(this.path, (0, import_path.extname)(this.path))
120
+ );
121
+ }
122
+ static isPluginOrPreset(type, name) {
123
+ return RE[type].test(_Plugin.stripNoneUmiScope(name));
124
+ }
125
+ static stripNoneUmiScope(name) {
126
+ if (name.charAt(0) === "@" && !name.startsWith("@4399ywkf/")) {
127
+ name = name.split("/")[1];
128
+ }
129
+ return name;
130
+ }
131
+ static getPluginsAndPresets(opts) {
132
+ function get(type) {
133
+ const types = `${type}s`;
134
+ return [
135
+ // opts
136
+ ...opts[types] || [],
137
+ // env
138
+ ...(process.env[`${opts.prefix}_${types}`.toUpperCase()] || "").split(",").filter(Boolean),
139
+ // dependencies
140
+ // ...Object.keys(opts.pkg.devDependencies || {})
141
+ // .concat(Object.keys(opts.pkg.dependencies || {}))
142
+ // .filter(Plugin.isPluginOrPreset.bind(null, type)),
143
+ // user config
144
+ ...opts.userConfig[types] || []
145
+ ].map((path) => {
146
+ (0, import_assert.default)(
147
+ typeof path === "string",
148
+ `Invalid plugin ${path}, it must be string.`
149
+ );
150
+ let resolved;
151
+ try {
152
+ resolved = import_utils.resolve.sync(path, {
153
+ basedir: opts.cwd,
154
+ extensions: [".tsx", ".ts", ".mjs", ".jsx", ".js"]
155
+ });
156
+ } catch (_e) {
157
+ throw new Error(`Invalid plugin ${path}, can not be resolved.`, {
158
+ cause: _e
159
+ });
160
+ }
161
+ return new _Plugin({
162
+ path: resolved,
163
+ type,
164
+ cwd: opts.cwd
165
+ });
166
+ });
167
+ }
168
+ return {
169
+ presets: get("preset"),
170
+ plugins: get("plugin")
171
+ };
172
+ }
173
+ };
174
+ // Annotate the CommonJS export names for ESM import in node:
175
+ 0 && (module.exports = {
176
+ Plugin
177
+ });