@modern-js/plugin 1.21.5 → 2.0.0-beta.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +22 -3
  2. package/dist/js/modern/farrow-pipeline/context.js +1 -8
  3. package/dist/js/modern/farrow-pipeline/counter.js +1 -3
  4. package/dist/js/modern/farrow-pipeline/pipeline.js +0 -16
  5. package/dist/js/modern/manager/async.js +8 -27
  6. package/dist/js/modern/manager/shared.js +3 -23
  7. package/dist/js/modern/manager/sync.js +10 -41
  8. package/dist/js/modern/utils/pluginDagSort.js +48 -0
  9. package/dist/js/modern/waterfall/async.js +0 -10
  10. package/dist/js/modern/waterfall/sync.js +0 -10
  11. package/dist/js/modern/workflow/async.js +0 -10
  12. package/dist/js/modern/workflow/parallel.js +0 -8
  13. package/dist/js/modern/workflow/sync.js +0 -8
  14. package/dist/js/node/farrow-pipeline/context.js +1 -10
  15. package/dist/js/node/farrow-pipeline/counter.js +1 -5
  16. package/dist/js/node/farrow-pipeline/index.js +0 -2
  17. package/dist/js/node/farrow-pipeline/pipeline.js +0 -23
  18. package/dist/js/node/index.js +0 -8
  19. package/dist/js/node/manager/async.js +8 -32
  20. package/dist/js/node/manager/index.js +0 -6
  21. package/dist/js/node/manager/shared.js +3 -32
  22. package/dist/js/node/manager/sync.js +10 -54
  23. package/dist/js/node/utils/pluginDagSort.js +55 -0
  24. package/dist/js/node/waterfall/async.js +0 -18
  25. package/dist/js/node/waterfall/index.js +0 -4
  26. package/dist/js/node/waterfall/sync.js +0 -18
  27. package/dist/js/node/workflow/async.js +0 -16
  28. package/dist/js/node/workflow/index.js +0 -6
  29. package/dist/js/node/workflow/parallel.js +0 -14
  30. package/dist/js/node/workflow/sync.js +0 -14
  31. package/dist/js/treeshaking/farrow-pipeline/context.js +1 -8
  32. package/dist/js/treeshaking/farrow-pipeline/counter.js +1 -3
  33. package/dist/js/treeshaking/farrow-pipeline/pipeline.js +0 -16
  34. package/dist/js/treeshaking/manager/async.js +6 -28
  35. package/dist/js/treeshaking/manager/shared.js +2 -46
  36. package/dist/js/treeshaking/manager/sync.js +9 -44
  37. package/dist/js/treeshaking/utils/pluginDagSort.js +74 -0
  38. package/dist/js/treeshaking/waterfall/async.js +0 -11
  39. package/dist/js/treeshaking/waterfall/sync.js +0 -8
  40. package/dist/js/treeshaking/workflow/async.js +0 -16
  41. package/dist/js/treeshaking/workflow/parallel.js +0 -8
  42. package/dist/js/treeshaking/workflow/sync.js +0 -6
  43. package/dist/types/manager/async.d.ts +0 -9
  44. package/dist/types/manager/sync.d.ts +0 -9
  45. package/dist/types/manager/types.d.ts +2 -9
  46. package/dist/types/utils/pluginDagSort.d.ts +1 -0
  47. package/package.json +5 -28
@@ -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 declare 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 declare type Plugin<Hooks, API> = {
@@ -17,46 +16,38 @@ export declare 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,24 +2,18 @@ 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 declare type Hook = Waterfall<any> | AsyncWaterfall<any> | Workflow<any, any> | AsyncWorkflow<any, any> | ParallelWorkflow<any> | Pipeline<any, any> | AsyncPipeline<any, any>;
7
6
  export declare type HooksMap = Record<string, Hook>;
8
7
  /** Extract the type of callback function from a hook. */
9
-
10
8
  export declare 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 declare 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 declare 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 declare 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
- export declare type PluginOptions<Hooks, Setup = undefined> = {
16
+ export declare type PluginOptions<Hooks, Setup = undefined, ExtendHooks = Record<string, unknown>> = {
23
17
  name?: string;
24
18
  pre?: string[];
25
19
  post?: string[];
@@ -27,10 +21,9 @@ export declare type PluginOptions<Hooks, Setup = undefined> = {
27
21
  rivals?: string[];
28
22
  required?: string[];
29
23
  usePlugins?: PluginOptions<Hooks, Setup>[];
30
- registerHook?: Partial<Hooks>;
24
+ registerHook?: Partial<Hooks & ExtendHooks>;
31
25
  };
32
26
  /** Common api of setup function. */
33
-
34
27
  export declare type CommonAPI<Hooks> = {
35
28
  useHookRunners: () => ToRunners<Hooks>;
36
29
  };
@@ -0,0 +1 @@
1
+ export declare const dagSort: <P extends Record<string, any>>(plugins: P[], key?: string, preKey?: string, postKey?: string) => P[];
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.21.5",
14
+ "version": "2.0.0-beta.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -36,41 +36,18 @@
36
36
  "@types/node": "^14",
37
37
  "typescript": "^4",
38
38
  "jest": "^27",
39
- "@scripts/build": "1.21.5",
40
- "@scripts/jest-config": "1.21.5"
39
+ "@scripts/build": "2.0.0-beta.1",
40
+ "@scripts/jest-config": "2.0.0-beta.1"
41
41
  },
42
42
  "sideEffects": false,
43
43
  "publishConfig": {
44
44
  "registry": "https://registry.npmjs.org/",
45
45
  "access": "public"
46
46
  },
47
- "wireit": {
48
- "build": {
49
- "command": "modern build",
50
- "files": [
51
- "src/**/*",
52
- "tsconfig.json",
53
- "package.json"
54
- ],
55
- "output": [
56
- "dist/**/*"
57
- ]
58
- },
59
- "test": {
60
- "command": "jest --passWithNoTests",
61
- "files": [
62
- "src/**/*",
63
- "tsconfig.json",
64
- "package.json",
65
- "tests/**/*"
66
- ],
67
- "output": []
68
- }
69
- },
70
47
  "scripts": {
71
48
  "new": "modern new",
72
49
  "dev": "modern build --watch",
73
- "build": "wireit",
74
- "test": "wireit"
50
+ "build": "modern build",
51
+ "test": "jest --passWithNoTests"
75
52
  }
76
53
  }