@modern-js/plugin-v2 2.63.7-alpha.0 → 2.63.7-alpha.2

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.
@@ -22,11 +22,12 @@ __export(api_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(api_exports);
24
24
  var import_lodash = require("@modern-js/utils/lodash");
25
+ var import_debug = require("./run/utils/debug");
25
26
  function initPluginAPI({ context, pluginManager }) {
26
27
  const { hooks, extendsHooks, plugins } = context;
27
28
  function getAppContext() {
28
29
  if (context) {
29
- const { hooks: hooks2, extendsHooks: extendsHooks2, config, normalizedConfig, pluginAPI, ...appContext } = context;
30
+ const { hooks: hooks2, extendsHooks: extendsHooks2, config, normalizedConfig, pluginAPI: pluginAPI2, ...appContext } = context;
30
31
  appContext._internalContext = context;
31
32
  return appContext;
32
33
  }
@@ -65,7 +66,7 @@ function initPluginAPI({ context, pluginManager }) {
65
66
  function updateAppContext(updateContext) {
66
67
  context = (0, import_lodash.merge)(context, updateContext);
67
68
  }
68
- return {
69
+ const pluginAPI = {
69
70
  isPluginExists: pluginManager.isPluginExists,
70
71
  getAppContext,
71
72
  getConfig,
@@ -98,6 +99,16 @@ function initPluginAPI({ context, pluginManager }) {
98
99
  onBeforeExit: hooks.onBeforeExit.tap,
99
100
  ...extendsPluginApi
100
101
  };
102
+ return new Proxy(pluginAPI, {
103
+ get(target, prop) {
104
+ if (prop in target) {
105
+ return target[prop];
106
+ }
107
+ return () => {
108
+ (0, import_debug.debug)(`api.${prop.toString()} not exist`);
109
+ };
110
+ }
111
+ });
101
112
  }
102
113
  // Annotate the CommonJS export names for ESM import in node:
103
114
  0 && (module.exports = {
@@ -63,7 +63,7 @@ function assignPkgConfig(userConfig, pkgConfig) {
63
63
  return void 0;
64
64
  });
65
65
  }
66
- async function createLoadedConfig(appDirectory, configFilePath, packageJsonConfig) {
66
+ async function createLoadedConfig(appDirectory, configFilePath, packageJsonConfig, otherConfig) {
67
67
  const configFile = (0, import_loadConfig.getConfigFilePath)(appDirectory, configFilePath);
68
68
  const loaded = await (0, import_loadConfig.loadConfig)(appDirectory, configFile, packageJsonConfig);
69
69
  if (!loaded.config && !loaded.pkgConfig) {
@@ -84,6 +84,12 @@ async function createLoadedConfig(appDirectory, configFilePath, packageJsonConfi
84
84
  ]);
85
85
  }
86
86
  }
87
+ if (otherConfig) {
88
+ mergedConfig = (0, import_mergeConfig.mergeConfig)([
89
+ mergedConfig,
90
+ otherConfig
91
+ ]);
92
+ }
87
93
  return {
88
94
  packageName: loaded.packageName,
89
95
  config: mergedConfig,
@@ -40,12 +40,12 @@ const createCli = () => {
40
40
  var _context_hooks_onAfterPrepare, _context_hooks;
41
41
  pluginManager.clear();
42
42
  initOptions = options;
43
- const { metaName = "MODERN", configFile, command, version, packageJsonConfig, internalPlugins, handleSetupResult } = options;
43
+ const { metaName = "MODERN", configFile, config, command, version, packageJsonConfig, internalPlugins, handleSetupResult } = options;
44
44
  const appDirectory = await (0, import_initAppDir.initAppDir)(options === null || options === void 0 ? void 0 : options.cwd);
45
45
  (0, import_commander2.initCommandsMap)();
46
46
  (0, import_commander2.setProgramVersion)(version);
47
47
  (0, import_loadEnv.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
48
- const loaded = await (0, import_createLoadedConfig.createLoadedConfig)(appDirectory, configFile, packageJsonConfig);
48
+ const loaded = await (0, import_createLoadedConfig.createLoadedConfig)(appDirectory, configFile, packageJsonConfig, config);
49
49
  const allPlugins = [
50
50
  ...internalPlugins || [],
51
51
  ...loaded.config.plugins || []
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var debug_exports = {};
20
+ __export(debug_exports, {
21
+ debug: () => debug
22
+ });
23
+ module.exports = __toCommonJS(debug_exports);
24
+ var import_utils = require("@modern-js/utils");
25
+ const debug = (0, import_utils.createDebugger)("plugin-v2");
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ debug
29
+ });
@@ -22,7 +22,7 @@ __export(manager_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(manager_exports);
24
24
  var import_utils = require("@modern-js/utils");
25
- const debug = (0, import_utils.createDebugger)("plugin-v2");
25
+ var import_debug = require("./cli/run/utils/debug");
26
26
  function validatePlugin(plugin) {
27
27
  const type = typeof plugin;
28
28
  if (type !== "object" || plugin === null) {
@@ -135,7 +135,7 @@ function createPluginManager() {
135
135
  visit(name);
136
136
  });
137
137
  result = result.filter((result2) => result2);
138
- debug("CLI Plugins:", result.map((p) => p.name));
138
+ (0, import_debug.debug)("CLI Plugins:", result.map((p) => p.name));
139
139
  return result;
140
140
  };
141
141
  const clear = () => {
package/dist/esm/index.js CHANGED
@@ -1,7 +1,12 @@
1
1
  // src/manager.ts
2
2
  import { _ as _type_of } from "@swc/helpers/_/_type_of";
3
- import { createDebugger, isFunction, logger } from "@modern-js/utils";
3
+ import { isFunction, logger } from "@modern-js/utils";
4
+
5
+ // src/cli/run/utils/debug.ts
6
+ import { createDebugger } from "@modern-js/utils";
4
7
  var debug = createDebugger("plugin-v2");
8
+
9
+ // src/manager.ts
5
10
  function validatePlugin(plugin) {
6
11
  var type = typeof plugin === "undefined" ? "undefined" : _type_of(plugin);
7
12
  if (type !== "object" || plugin === null) {
@@ -1,9 +1,10 @@
1
1
  import { merge } from "@modern-js/utils/lodash";
2
+ import { debug } from "./run/utils/debug";
2
3
  function initPluginAPI({ context, pluginManager }) {
3
4
  const { hooks, extendsHooks, plugins } = context;
4
5
  function getAppContext() {
5
6
  if (context) {
6
- const { hooks: hooks2, extendsHooks: extendsHooks2, config, normalizedConfig, pluginAPI, ...appContext } = context;
7
+ const { hooks: hooks2, extendsHooks: extendsHooks2, config, normalizedConfig, pluginAPI: pluginAPI2, ...appContext } = context;
7
8
  appContext._internalContext = context;
8
9
  return appContext;
9
10
  }
@@ -42,7 +43,7 @@ function initPluginAPI({ context, pluginManager }) {
42
43
  function updateAppContext(updateContext) {
43
44
  context = merge(context, updateContext);
44
45
  }
45
- return {
46
+ const pluginAPI = {
46
47
  isPluginExists: pluginManager.isPluginExists,
47
48
  getAppContext,
48
49
  getConfig,
@@ -75,6 +76,16 @@ function initPluginAPI({ context, pluginManager }) {
75
76
  onBeforeExit: hooks.onBeforeExit.tap,
76
77
  ...extendsPluginApi
77
78
  };
79
+ return new Proxy(pluginAPI, {
80
+ get(target, prop) {
81
+ if (prop in target) {
82
+ return target[prop];
83
+ }
84
+ return () => {
85
+ debug(`api.${prop.toString()} not exist`);
86
+ };
87
+ }
88
+ });
78
89
  }
79
90
  export {
80
91
  initPluginAPI
@@ -39,7 +39,7 @@ function assignPkgConfig(userConfig, pkgConfig) {
39
39
  return void 0;
40
40
  });
41
41
  }
42
- async function createLoadedConfig(appDirectory, configFilePath, packageJsonConfig) {
42
+ async function createLoadedConfig(appDirectory, configFilePath, packageJsonConfig, otherConfig) {
43
43
  const configFile = getConfigFilePath(appDirectory, configFilePath);
44
44
  const loaded = await loadConfig(appDirectory, configFile, packageJsonConfig);
45
45
  if (!loaded.config && !loaded.pkgConfig) {
@@ -60,6 +60,12 @@ async function createLoadedConfig(appDirectory, configFilePath, packageJsonConfi
60
60
  ]);
61
61
  }
62
62
  }
63
+ if (otherConfig) {
64
+ mergedConfig = mergeConfig([
65
+ mergedConfig,
66
+ otherConfig
67
+ ]);
68
+ }
63
69
  return {
64
70
  packageName: loaded.packageName,
65
71
  config: mergedConfig,
@@ -17,12 +17,12 @@ const createCli = () => {
17
17
  var _context_hooks_onAfterPrepare, _context_hooks;
18
18
  pluginManager.clear();
19
19
  initOptions = options;
20
- const { metaName = "MODERN", configFile, command, version, packageJsonConfig, internalPlugins, handleSetupResult } = options;
20
+ const { metaName = "MODERN", configFile, config, command, version, packageJsonConfig, internalPlugins, handleSetupResult } = options;
21
21
  const appDirectory = await initAppDir(options === null || options === void 0 ? void 0 : options.cwd);
22
22
  initCommandsMap();
23
23
  setProgramVersion(version);
24
24
  loadEnv(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
25
- const loaded = await createLoadedConfig(appDirectory, configFile, packageJsonConfig);
25
+ const loaded = await createLoadedConfig(appDirectory, configFile, packageJsonConfig, config);
26
26
  const allPlugins = [
27
27
  ...internalPlugins || [],
28
28
  ...loaded.config.plugins || []
@@ -0,0 +1,5 @@
1
+ import { createDebugger } from "@modern-js/utils";
2
+ const debug = createDebugger("plugin-v2");
3
+ export {
4
+ debug
5
+ };
@@ -1,5 +1,5 @@
1
- import { createDebugger, isFunction, logger } from "@modern-js/utils";
2
- const debug = createDebugger("plugin-v2");
1
+ import { isFunction, logger } from "@modern-js/utils";
2
+ import { debug } from "./cli/run/utils/debug";
3
3
  function validatePlugin(plugin) {
4
4
  const type = typeof plugin;
5
5
  if (type !== "object" || plugin === null) {
@@ -3,4 +3,4 @@ import type { LoadedConfig } from '../types';
3
3
  * Assign the pkg config into the user config.
4
4
  */
5
5
  export declare function assignPkgConfig<T>(userConfig: T, pkgConfig: T): {} & T;
6
- export declare function createLoadedConfig<T>(appDirectory: string, configFilePath: string, packageJsonConfig?: string): Promise<LoadedConfig<T>>;
6
+ export declare function createLoadedConfig<T>(appDirectory: string, configFilePath: string, packageJsonConfig?: string, otherConfig?: T): Promise<LoadedConfig<T>>;
@@ -1,9 +1,9 @@
1
1
  import type { CLIPluginExtends } from '../../types/cli/plugin';
2
2
  import type { CLIRunOptions } from './types';
3
3
  export declare const createCli: <Extends extends CLIPluginExtends>() => {
4
- init: (options: CLIRunOptions) => Promise<{
4
+ init: (options: CLIRunOptions<Extends>) => Promise<{
5
5
  appContext: import("../..").InternalContext<Extends>;
6
6
  }>;
7
- run: (options: CLIRunOptions) => Promise<void>;
8
- getPrevInitOptions: () => CLIRunOptions;
7
+ run: (options: CLIRunOptions<Extends>) => Promise<void>;
8
+ getPrevInitOptions: () => CLIRunOptions<Extends>;
9
9
  };
@@ -3,9 +3,9 @@ export { createLoadedConfig } from './config/createLoadedConfig';
3
3
  export { initAppDir } from './utils/initAppDir';
4
4
  export { createCli };
5
5
  export declare const cli: {
6
- init: (options: import("./types").CLIRunOptions) => Promise<{
6
+ init: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>) => Promise<{
7
7
  appContext: import("../..").InternalContext<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>;
8
8
  }>;
9
- run: (options: import("./types").CLIRunOptions) => Promise<void>;
10
- getPrevInitOptions: () => import("./types").CLIRunOptions;
9
+ run: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>) => Promise<void>;
10
+ getPrevInitOptions: () => import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>;
11
11
  };
@@ -1,5 +1,8 @@
1
+ import type { CLIPluginExtends } from '../../types/cli';
1
2
  import type { Plugin } from '../../types/plugin';
2
- export interface CLIOptions {
3
+ export interface CLIOptions<Extends extends CLIPluginExtends = {
4
+ config: {};
5
+ }> {
3
6
  cwd?: string;
4
7
  version?: string;
5
8
  metaName?: string;
@@ -7,6 +10,10 @@ export interface CLIOptions {
7
10
  * The initial log message when CLI started
8
11
  */
9
12
  initialLog?: string;
13
+ /**
14
+ * other config, overrides config file content
15
+ */
16
+ config?: Extends['config'];
10
17
  configFile: string;
11
18
  /**
12
19
  * @deprecated
@@ -23,6 +30,8 @@ export type LoadedConfig<T> = {
23
30
  pkgConfig?: T;
24
31
  jsConfig?: T;
25
32
  };
26
- export interface CLIRunOptions extends CLIOptions {
33
+ export interface CLIRunOptions<Extends extends CLIPluginExtends = {
34
+ config: {};
35
+ }> extends CLIOptions<Extends> {
27
36
  command: string;
28
37
  }
@@ -0,0 +1 @@
1
+ export declare const debug: import("@modern-js/utils/compiled/debug").Debugger;
@@ -42,7 +42,7 @@ export type OnFileChangedFn = (params: {
42
42
  export type OnBeforeRestartFn = () => Promise<void> | void;
43
43
  export type OnBeforeDevFn = () => Promise<void> | void;
44
44
  export type OnAfterDevFn = (params: {
45
- isFirstCompile: boolean;
45
+ port: number;
46
46
  }) => Promise<void> | void;
47
47
  export type OnBeforeDeployFn = (options: Record<string, any>) => Promise<void> | void;
48
48
  export type OnAfterDeployFn = (options: Record<string, any>) => Promise<void> | void;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.63.7-alpha.0",
18
+ "version": "2.63.7-alpha.2",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -70,9 +70,9 @@
70
70
  "@types/node": "^14",
71
71
  "jest": "^29",
72
72
  "typescript": "^5",
73
- "@scripts/build": "2.63.6",
74
73
  "@modern-js/types": "2.63.6",
75
74
  "@modern-js/uni-builder": "2.63.6",
75
+ "@scripts/build": "2.63.6",
76
76
  "@scripts/jest-config": "2.63.6"
77
77
  },
78
78
  "sideEffects": false,