@modern-js/plugin 2.20.0 → 2.21.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @modern-js/plugin
2
2
 
3
+ ## 2.21.1
4
+
5
+ ### Patch Changes
6
+
7
+ - @modern-js/utils@2.21.1
8
+
9
+ ## 2.21.0
10
+
11
+ ### Patch Changes
12
+
13
+ - 26dcf3a: chore: bump typescript to v5 in devDependencies
14
+
15
+ chore: 升级 devDependencies 中的 typescript 版本到 v5
16
+
17
+ - Updated dependencies [e81eeaf]
18
+ - Updated dependencies [26dcf3a]
19
+ - Updated dependencies [056627f]
20
+ - Updated dependencies [0fc15ca]
21
+ - Updated dependencies [43b4e83]
22
+ - Updated dependencies [ad78387]
23
+ - @modern-js/utils@2.21.0
24
+
3
25
  ## 2.20.0
4
26
 
5
27
  ### Patch Changes
@@ -1,6 +1,5 @@
1
1
  import type { ToRunners, ToThreads, CommonAPI, PluginOptions } from './types';
2
2
  /** Setup function of async plugin. */
3
-
4
3
  export type AsyncSetup<Hooks, API = Record<string, never>> = (api: API & CommonAPI<Hooks>) => Partial<ToThreads<Hooks>> | Promise<Partial<ToThreads<Hooks>> | void> | void;
5
4
  declare const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
6
5
  export type AsyncPlugin<Hooks, API> = {
@@ -17,46 +16,38 @@ export type AsyncManager<Hooks, API> = {
17
16
  * Determine if a value is a async plugin.
18
17
  * @param input
19
18
  */
20
-
21
19
  isPlugin: (input: unknown) => input is AsyncPlugin<Hooks, API>;
22
20
  /**
23
21
  * Register new plugins to current manager.
24
22
  * @param plugins one or more plugin.
25
23
  */
26
-
27
24
  usePlugin: (...plugins: Array<AsyncPlugin<Hooks, API> | PluginOptions<Hooks, AsyncSetup<Hooks, API>> | (() => PluginOptions<Hooks, AsyncSetup<Hooks, API>>)>) => AsyncManager<Hooks, API>;
28
25
  /**
29
26
  * Init manager, it will call the setup function of all registered plugins.
30
27
  */
31
-
32
28
  init: () => Promise<ToRunners<Hooks>>;
33
29
  /**
34
30
  * Run callback function.
35
31
  * @param callback
36
32
  */
37
-
38
33
  run: <O>(cb: () => O) => O;
39
34
  /**
40
35
  * Register new hooks.
41
36
  * @param newHooks
42
37
  */
43
-
44
38
  registerHook: (newHooks: Partial<Hooks>) => void;
45
39
  /**
46
40
  * Return a cloned manager.
47
41
  * @param overrideAPI override the default plugin API.
48
42
  */
49
-
50
43
  clone: (overrideAPI?: Partial<API & CommonAPI<Hooks>>) => AsyncManager<Hooks, API>;
51
44
  /**
52
45
  * Clear all registered plugins.
53
46
  */
54
-
55
47
  clear: () => void;
56
48
  /**
57
49
  * Get all runner functions of the hooks.
58
50
  */
59
-
60
51
  useRunner: () => ToRunners<Hooks>;
61
52
  };
62
53
  export declare const createAsyncManager: <Hooks extends Record<string, any>, API extends Record<string, any> = Record<string, never>>(hooks?: Partial<Hooks> | undefined, api?: API | undefined) => AsyncManager<Hooks, API>;
@@ -1,6 +1,5 @@
1
1
  import type { Hook, CommonAPI, ToRunners, ToThreads, PluginOptions } from './types';
2
2
  /** Setup function of sync plugin. */
3
-
4
3
  export type Setup<Hooks, API = Record<string, never>> = (api: API) => Partial<ToThreads<Hooks>> | void;
5
4
  declare const SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
6
5
  export type Plugin<Hooks, API> = {
@@ -17,46 +16,38 @@ export type Manager<Hooks, API> = {
17
16
  * Determine if a value is a sync plugin.
18
17
  * @param input
19
18
  */
20
-
21
19
  isPlugin: (input: unknown) => input is Plugin<Hooks, API>;
22
20
  /**
23
21
  * Register new plugins to current manager.
24
22
  * @param plugins one or more plugin.
25
23
  */
26
-
27
24
  usePlugin: (...plugins: Array<Plugin<Hooks, API> | PluginOptions<Hooks, Setup<Hooks, API>> | (() => PluginOptions<Hooks, Setup<Hooks, API>>)>) => Manager<Hooks, API>;
28
25
  /**
29
26
  * Init manager, it will call the setup function of all registered plugins.
30
27
  */
31
-
32
28
  init: () => ToRunners<Hooks>;
33
29
  /**
34
30
  * Run callback function.
35
31
  * @param callback
36
32
  */
37
-
38
33
  run: <O>(cb: () => O) => O;
39
34
  /**
40
35
  * Register new hooks.
41
36
  * @param newHooks
42
37
  */
43
-
44
38
  registerHook: (hewHooks: Partial<Hooks>) => void;
45
39
  /**
46
40
  * Clear all registered plugins.
47
41
  */
48
-
49
42
  clear: () => void;
50
43
  /**
51
44
  * Return a cloned manager.
52
45
  * @param overrideAPI override the default plugin API.
53
46
  */
54
-
55
47
  clone: (overrideAPI?: Partial<API & CommonAPI<Hooks>>) => Manager<Hooks, API>;
56
48
  /**
57
49
  * Get all runner functions of the hooks.
58
50
  */
59
-
60
51
  useRunner: () => ToRunners<Hooks>;
61
52
  };
62
53
  export declare const DEFAULT_OPTIONS: {
@@ -2,23 +2,17 @@ import type { Pipeline, MaybeAsync, Middleware, AsyncPipeline } from '../farrow-
2
2
  import type { Brook, Waterfall, AsyncBrook, AsyncWaterfall } from '../waterfall';
3
3
  import type { Worker, Workflow, AsyncWorker, AsyncWorkflow, ParallelWorkflow } from '../workflow';
4
4
  /** All hook types. */
5
-
6
5
  export type Hook = Waterfall<any> | AsyncWaterfall<any> | Workflow<any, any> | AsyncWorkflow<any, any> | ParallelWorkflow<any> | Pipeline<any, any> | AsyncPipeline<any, any>;
7
6
  export type HooksMap = Record<string, Hook>;
8
7
  /** Extract the type of callback function from a hook. */
9
-
10
8
  export type ToThread<P extends Hook> = P extends Workflow<infer I, infer O> ? Worker<I, O> : P extends AsyncWorkflow<infer I, infer O> ? AsyncWorker<I, O> : P extends ParallelWorkflow<infer I, infer O> ? AsyncWorker<I, O> : P extends Waterfall<infer I> ? Brook<I> : P extends AsyncWaterfall<infer I> ? AsyncBrook<I> : P extends Pipeline<infer I, infer O> ? Middleware<I, O> : P extends AsyncPipeline<infer I, infer O> ? Middleware<I, MaybeAsync<O>> : never;
11
9
  /** Extract types of callback function from hooks. */
12
-
13
10
  export type ToThreads<PS> = { [K in keyof PS]: PS[K] extends Hook ? ToThread<PS[K]> : PS[K] extends void ? void : never };
14
11
  /** Extract run method from a hook. */
15
-
16
12
  export type RunnerFromHook<P extends Hook> = P extends Waterfall<infer I> ? Waterfall<I>['run'] : P extends AsyncWaterfall<infer I> ? AsyncWaterfall<I>['run'] : P extends Workflow<infer I, infer O> ? Workflow<I, O>['run'] : P extends AsyncWorkflow<infer I, infer O> ? AsyncWorkflow<I, O>['run'] : P extends ParallelWorkflow<infer I, infer O> ? ParallelWorkflow<I, O>['run'] : P extends Pipeline<infer I, infer O> ? Pipeline<I, O>['run'] : P extends AsyncPipeline<infer I, infer O> ? AsyncPipeline<I, O>['run'] : never;
17
13
  /** Extract all run methods from hooks. */
18
-
19
14
  export type ToRunners<PS> = { [K in keyof PS]: PS[K] extends Hook ? RunnerFromHook<PS[K]> : PS[K] extends void ? void : never };
20
15
  /** All options to define a plugin. */
21
-
22
16
  export type PluginOptions<Hooks, Setup = undefined, ExtendHooks = Record<string, unknown>> = {
23
17
  name?: string;
24
18
  pre?: string[];
@@ -30,7 +24,6 @@ export type PluginOptions<Hooks, Setup = undefined, ExtendHooks = Record<string,
30
24
  registerHook?: Partial<Hooks & ExtendHooks>;
31
25
  };
32
26
  /** Common api of setup function. */
33
-
34
27
  export type CommonAPI<Hooks> = {
35
28
  useHookRunners: () => ToRunners<Hooks>;
36
29
  };
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.20.0",
18
+ "version": "2.21.1",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -33,15 +33,15 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@swc/helpers": "0.5.1",
36
- "@modern-js/utils": "2.20.0"
36
+ "@modern-js/utils": "2.21.1"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/jest": "^29",
40
40
  "@types/node": "^14",
41
- "typescript": "^4",
41
+ "typescript": "^5",
42
42
  "jest": "^29",
43
- "@scripts/build": "2.20.0",
44
- "@scripts/jest-config": "2.20.0"
43
+ "@scripts/build": "2.21.1",
44
+ "@scripts/jest-config": "2.21.1"
45
45
  },
46
46
  "sideEffects": false,
47
47
  "publishConfig": {