@graphql-codegen/cli 3.3.2-rc-20230512163717-1630c07c5 → 3.3.2-rc-20230512165054-b97b5118a
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/cjs/generate-and-save.js +1 -1
- package/cjs/utils/abort-controller-polyfill.js +95 -0
- package/cjs/utils/file-system.js +6 -2
- package/cjs/utils/patterns.js +235 -0
- package/cjs/utils/watcher.js +79 -59
- package/esm/generate-and-save.js +1 -1
- package/esm/utils/abort-controller-polyfill.js +92 -0
- package/esm/utils/file-system.js +4 -1
- package/esm/utils/patterns.js +226 -0
- package/esm/utils/watcher.js +80 -60
- package/package.json +5 -5
- package/typings/utils/abort-controller-polyfill.d.cts +5 -0
- package/typings/utils/abort-controller-polyfill.d.ts +5 -0
- package/typings/utils/file-system.d.cts +5 -0
- package/typings/utils/file-system.d.ts +5 -0
- package/typings/utils/patterns.d.cts +91 -0
- package/typings/utils/patterns.d.ts +91 -0
- package/typings/utils/watcher.d.cts +14 -1
- package/typings/utils/watcher.d.ts +14 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import { CodegenContext } from '../config.cjs';
|
|
3
|
+
type NegatedPattern = `!${string}`;
|
|
4
|
+
/**
|
|
5
|
+
* Flatten a list of pattern sets to be a list of only the affirmative patterns
|
|
6
|
+
* are contained in all of them.
|
|
7
|
+
*
|
|
8
|
+
* This can be used, for example, to find the "longest common prefix directory"
|
|
9
|
+
* by examining `mm.scan(pattern).base` for each `pattern`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const allAffirmativePatternsFromPatternSets: (patternSets: PatternSet[]) => string[];
|
|
12
|
+
/**
|
|
13
|
+
* Create a rebuild trigger that follows the algorithm described here:
|
|
14
|
+
* https://github.com/dotansimha/graphql-code-generator/issues/9270#issuecomment-1496765045
|
|
15
|
+
*
|
|
16
|
+
* There is a flow chart diagram in that comment.
|
|
17
|
+
*
|
|
18
|
+
* Basically:
|
|
19
|
+
*
|
|
20
|
+
* * "Global" patterns are defined at top level of config file, and "local"
|
|
21
|
+
* patterns are defined for each output target
|
|
22
|
+
* * Each pattern can have "watch", "documents", and "schemas"
|
|
23
|
+
* * Watch patterns (global and local) always take precedence over documents and
|
|
24
|
+
* schemas patterns, i.e. a watch negation always negates, and a watch match is
|
|
25
|
+
* a match even if it would be negated by some pattern in documents or schemas
|
|
26
|
+
* * The trigger returns true if any output target's local patterns result in
|
|
27
|
+
* a match, after considering the precedence of any global and local negations
|
|
28
|
+
*/
|
|
29
|
+
export declare const makeShouldRebuild: ({ globalPatternSet, localPatternSets, }: {
|
|
30
|
+
globalPatternSet: PatternSet;
|
|
31
|
+
localPatternSets: PatternSet[];
|
|
32
|
+
}) => ({ path: absolutePath }: {
|
|
33
|
+
path: string;
|
|
34
|
+
}) => boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Create the pattern set for the "global" (top level) config.
|
|
37
|
+
*
|
|
38
|
+
* In the `shouldRebuild` algorithm, any of these watch patterns will take
|
|
39
|
+
* precedence over local configs, and any schemas and documents patterns will be
|
|
40
|
+
* mixed into the pattern set of each local config.
|
|
41
|
+
*/
|
|
42
|
+
export declare const makeGlobalPatternSet: (initialContext: CodegenContext) => {
|
|
43
|
+
watch: SortedPatterns<string>;
|
|
44
|
+
schemas: SortedPatterns<string>;
|
|
45
|
+
documents: SortedPatterns<string>;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Create the pattern set for a "local" (output target) config
|
|
49
|
+
*
|
|
50
|
+
* In the `shouldRebuild` algorithm, any of these watch patterns will take
|
|
51
|
+
* precedence over documents or schemas patterns, and the documents and schemas
|
|
52
|
+
* patterns will be mixed into the pattern set of their respective gobal pattern
|
|
53
|
+
* set equivalents.
|
|
54
|
+
*/
|
|
55
|
+
export declare const makeLocalPatternSet: (conf: Types.ConfiguredOutput) => {
|
|
56
|
+
watch: SortedPatterns<string>;
|
|
57
|
+
documents: SortedPatterns<string>;
|
|
58
|
+
schemas: SortedPatterns<string>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Given a list of micromatch patterns, sort them into `patterns` (all of them),
|
|
62
|
+
* `affirmative` (only the affirmative patterns), and `negated` (only the negated patterns)
|
|
63
|
+
*
|
|
64
|
+
* @param patterns List of micromatch patterns
|
|
65
|
+
*/
|
|
66
|
+
export declare const sortPatterns: <P extends string>(patterns: P[]) => SortedPatterns<P>;
|
|
67
|
+
/**
|
|
68
|
+
* A type that "sorts" (or "groups") patterns. For a given list of `patterns`,
|
|
69
|
+
* this type will include the original list in `patterns`, all of its
|
|
70
|
+
* "affirmative" (non-negated) patterns in `affirmative`, and all of its
|
|
71
|
+
* "negated" patterns in `negated`
|
|
72
|
+
*/
|
|
73
|
+
type SortedPatterns<PP extends string | NegatedPattern = string | NegatedPattern> = {
|
|
74
|
+
/** List of patterns, which could include both negated and affirmative patterns */
|
|
75
|
+
patterns: PP[];
|
|
76
|
+
/** List of only the affirmative (non-negated) patterns in `patterns` */
|
|
77
|
+
affirmative: PP[];
|
|
78
|
+
/** List of only the negated patterns in `patterns` */
|
|
79
|
+
negated: Extract<PP, NegatedPattern>[];
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* The global (top-level) config and each local (output target) config can have
|
|
83
|
+
* patterns which are separable into "watch" (always takes precedence), "documents",
|
|
84
|
+
* and "schemas". This type can hold sorted versions of these patterns.
|
|
85
|
+
*/
|
|
86
|
+
type PatternSet = {
|
|
87
|
+
watch: SortedPatterns;
|
|
88
|
+
documents: SortedPatterns;
|
|
89
|
+
schemas: SortedPatterns;
|
|
90
|
+
};
|
|
91
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import { CodegenContext } from '../config.js';
|
|
3
|
+
type NegatedPattern = `!${string}`;
|
|
4
|
+
/**
|
|
5
|
+
* Flatten a list of pattern sets to be a list of only the affirmative patterns
|
|
6
|
+
* are contained in all of them.
|
|
7
|
+
*
|
|
8
|
+
* This can be used, for example, to find the "longest common prefix directory"
|
|
9
|
+
* by examining `mm.scan(pattern).base` for each `pattern`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const allAffirmativePatternsFromPatternSets: (patternSets: PatternSet[]) => string[];
|
|
12
|
+
/**
|
|
13
|
+
* Create a rebuild trigger that follows the algorithm described here:
|
|
14
|
+
* https://github.com/dotansimha/graphql-code-generator/issues/9270#issuecomment-1496765045
|
|
15
|
+
*
|
|
16
|
+
* There is a flow chart diagram in that comment.
|
|
17
|
+
*
|
|
18
|
+
* Basically:
|
|
19
|
+
*
|
|
20
|
+
* * "Global" patterns are defined at top level of config file, and "local"
|
|
21
|
+
* patterns are defined for each output target
|
|
22
|
+
* * Each pattern can have "watch", "documents", and "schemas"
|
|
23
|
+
* * Watch patterns (global and local) always take precedence over documents and
|
|
24
|
+
* schemas patterns, i.e. a watch negation always negates, and a watch match is
|
|
25
|
+
* a match even if it would be negated by some pattern in documents or schemas
|
|
26
|
+
* * The trigger returns true if any output target's local patterns result in
|
|
27
|
+
* a match, after considering the precedence of any global and local negations
|
|
28
|
+
*/
|
|
29
|
+
export declare const makeShouldRebuild: ({ globalPatternSet, localPatternSets, }: {
|
|
30
|
+
globalPatternSet: PatternSet;
|
|
31
|
+
localPatternSets: PatternSet[];
|
|
32
|
+
}) => ({ path: absolutePath }: {
|
|
33
|
+
path: string;
|
|
34
|
+
}) => boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Create the pattern set for the "global" (top level) config.
|
|
37
|
+
*
|
|
38
|
+
* In the `shouldRebuild` algorithm, any of these watch patterns will take
|
|
39
|
+
* precedence over local configs, and any schemas and documents patterns will be
|
|
40
|
+
* mixed into the pattern set of each local config.
|
|
41
|
+
*/
|
|
42
|
+
export declare const makeGlobalPatternSet: (initialContext: CodegenContext) => {
|
|
43
|
+
watch: SortedPatterns<string>;
|
|
44
|
+
schemas: SortedPatterns<string>;
|
|
45
|
+
documents: SortedPatterns<string>;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Create the pattern set for a "local" (output target) config
|
|
49
|
+
*
|
|
50
|
+
* In the `shouldRebuild` algorithm, any of these watch patterns will take
|
|
51
|
+
* precedence over documents or schemas patterns, and the documents and schemas
|
|
52
|
+
* patterns will be mixed into the pattern set of their respective gobal pattern
|
|
53
|
+
* set equivalents.
|
|
54
|
+
*/
|
|
55
|
+
export declare const makeLocalPatternSet: (conf: Types.ConfiguredOutput) => {
|
|
56
|
+
watch: SortedPatterns<string>;
|
|
57
|
+
documents: SortedPatterns<string>;
|
|
58
|
+
schemas: SortedPatterns<string>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Given a list of micromatch patterns, sort them into `patterns` (all of them),
|
|
62
|
+
* `affirmative` (only the affirmative patterns), and `negated` (only the negated patterns)
|
|
63
|
+
*
|
|
64
|
+
* @param patterns List of micromatch patterns
|
|
65
|
+
*/
|
|
66
|
+
export declare const sortPatterns: <P extends string>(patterns: P[]) => SortedPatterns<P>;
|
|
67
|
+
/**
|
|
68
|
+
* A type that "sorts" (or "groups") patterns. For a given list of `patterns`,
|
|
69
|
+
* this type will include the original list in `patterns`, all of its
|
|
70
|
+
* "affirmative" (non-negated) patterns in `affirmative`, and all of its
|
|
71
|
+
* "negated" patterns in `negated`
|
|
72
|
+
*/
|
|
73
|
+
type SortedPatterns<PP extends string | NegatedPattern = string | NegatedPattern> = {
|
|
74
|
+
/** List of patterns, which could include both negated and affirmative patterns */
|
|
75
|
+
patterns: PP[];
|
|
76
|
+
/** List of only the affirmative (non-negated) patterns in `patterns` */
|
|
77
|
+
affirmative: PP[];
|
|
78
|
+
/** List of only the negated patterns in `patterns` */
|
|
79
|
+
negated: Extract<PP, NegatedPattern>[];
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* The global (top-level) config and each local (output target) config can have
|
|
83
|
+
* patterns which are separable into "watch" (always takes precedence), "documents",
|
|
84
|
+
* and "schemas". This type can hold sorted versions of these patterns.
|
|
85
|
+
*/
|
|
86
|
+
type PatternSet = {
|
|
87
|
+
watch: SortedPatterns;
|
|
88
|
+
documents: SortedPatterns;
|
|
89
|
+
schemas: SortedPatterns;
|
|
90
|
+
};
|
|
91
|
+
export {};
|
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { CodegenContext } from '../config.cjs';
|
|
3
|
-
export declare const createWatcher: (
|
|
3
|
+
export declare const createWatcher: (initialContext: CodegenContext, onNext: (result: Types.FileOutput[]) => Promise<Types.FileOutput[]>) => {
|
|
4
|
+
/**
|
|
5
|
+
* Call this function to stop the running watch server
|
|
6
|
+
*
|
|
7
|
+
* @returns Promise that resolves when watcher has terminated ({@link runningWatcher} promise settled)
|
|
8
|
+
* */
|
|
9
|
+
stopWatching: () => Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Promise that will never resolve as long as the watcher is running. To stop
|
|
12
|
+
* the watcher, call {@link stopWatching}, which will send a stop signal and
|
|
13
|
+
* then return a promise that doesn't resolve until `runningWatcher` has resolved.
|
|
14
|
+
* */
|
|
15
|
+
runningWatcher: Promise<void>;
|
|
16
|
+
};
|
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { CodegenContext } from '../config.js';
|
|
3
|
-
export declare const createWatcher: (
|
|
3
|
+
export declare const createWatcher: (initialContext: CodegenContext, onNext: (result: Types.FileOutput[]) => Promise<Types.FileOutput[]>) => {
|
|
4
|
+
/**
|
|
5
|
+
* Call this function to stop the running watch server
|
|
6
|
+
*
|
|
7
|
+
* @returns Promise that resolves when watcher has terminated ({@link runningWatcher} promise settled)
|
|
8
|
+
* */
|
|
9
|
+
stopWatching: () => Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Promise that will never resolve as long as the watcher is running. To stop
|
|
12
|
+
* the watcher, call {@link stopWatching}, which will send a stop signal and
|
|
13
|
+
* then return a promise that doesn't resolve until `runningWatcher` has resolved.
|
|
14
|
+
* */
|
|
15
|
+
runningWatcher: Promise<void>;
|
|
16
|
+
};
|