@strapi/typescript-utils 0.0.0-next.f426350b859ddae6592e9bfa99e6be94ae22e117 → 0.0.0-next.f4ff842a3cb7b83db540bee67554b704e042b042
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/lib/__tests__/generators/schemas/attributes.test.js +193 -43
- package/lib/admin/create-tsconfig-file.js +2 -16
- package/lib/compile.js +2 -6
- package/lib/compilers/basic.js +12 -4
- package/lib/compilers/index.js +0 -2
- package/lib/generators/common/models/attributes.js +30 -3
- package/lib/generators/common/models/mappers.js +23 -2
- package/lib/generators/utils.js +1 -1
- package/package.json +9 -4
- package/tsconfigs/admin.json +18 -19
- package/tsconfigs/server.json +17 -16
- package/lib/compilers/watch.js +0 -37
|
@@ -148,6 +148,72 @@ describe('Attributes', () => {
|
|
|
148
148
|
expect(addImport).toHaveBeenCalledWith('Attribute');
|
|
149
149
|
};
|
|
150
150
|
|
|
151
|
+
describe('Media', () => {
|
|
152
|
+
test('Media with multiple and with no allowedTypes', () => {
|
|
153
|
+
const attribute = { type: 'media', multiple: true };
|
|
154
|
+
const typeNode = getAttributeType('foo', attribute);
|
|
155
|
+
|
|
156
|
+
defaultAssertions(typeNode, 'Attribute.Media');
|
|
157
|
+
|
|
158
|
+
expect(typeNode.typeArguments).toHaveLength(2);
|
|
159
|
+
|
|
160
|
+
expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.UndefinedKeyword);
|
|
161
|
+
|
|
162
|
+
expect(typeNode.typeArguments[1].kind).toBe(ts.SyntaxKind.TrueKeyword);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('Media without multiple with allowedTypes', () => {
|
|
166
|
+
const attribute = { type: 'media', allowedTypes: ['images', 'videos'] };
|
|
167
|
+
const typeNode = getAttributeType('foo', attribute);
|
|
168
|
+
|
|
169
|
+
defaultAssertions(typeNode, 'Attribute.Media');
|
|
170
|
+
|
|
171
|
+
expect(typeNode.typeArguments).toHaveLength(1);
|
|
172
|
+
|
|
173
|
+
expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.UnionType);
|
|
174
|
+
|
|
175
|
+
const unionTypes = typeNode.typeArguments[0].types;
|
|
176
|
+
|
|
177
|
+
attribute.allowedTypes.forEach((value, index) => {
|
|
178
|
+
const element = unionTypes[index];
|
|
179
|
+
|
|
180
|
+
expect(element.kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
181
|
+
expect(element.text).toBe(value);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test('Media with multiple and with allowedTypes', () => {
|
|
186
|
+
const attribute = { type: 'media', multiple: true, allowedTypes: ['images', 'videos'] };
|
|
187
|
+
const typeNode = getAttributeType('foo', attribute);
|
|
188
|
+
|
|
189
|
+
defaultAssertions(typeNode, 'Attribute.Media');
|
|
190
|
+
|
|
191
|
+
expect(typeNode.typeArguments).toHaveLength(2);
|
|
192
|
+
|
|
193
|
+
expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.UnionType);
|
|
194
|
+
|
|
195
|
+
const unionTypes = typeNode.typeArguments[0].types;
|
|
196
|
+
|
|
197
|
+
attribute.allowedTypes.forEach((value, index) => {
|
|
198
|
+
const element = unionTypes[index];
|
|
199
|
+
|
|
200
|
+
expect(element.kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
201
|
+
expect(element.text).toBe(value);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
expect(typeNode.typeArguments[1].kind).toBe(ts.SyntaxKind.TrueKeyword);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test('Media without multiple and with no allowedTypes', () => {
|
|
208
|
+
const attribute = { type: 'media' };
|
|
209
|
+
const typeNode = getAttributeType('foo', attribute);
|
|
210
|
+
|
|
211
|
+
defaultAssertions(typeNode, 'Attribute.Media');
|
|
212
|
+
|
|
213
|
+
expect(typeNode.typeArguments).toBeUndefined();
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
151
217
|
describe('Enumeration', () => {
|
|
152
218
|
test('Enumeration with an enum property', () => {
|
|
153
219
|
const attribute = { type: 'enumeration', enum: ['a', 'b', 'c'] };
|
|
@@ -548,19 +614,27 @@ describe('Attributes', () => {
|
|
|
548
614
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
549
615
|
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
|
|
550
616
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
617
|
+
const [setMinMax] = modifiers;
|
|
618
|
+
const { typeArguments } = setMinMax;
|
|
619
|
+
|
|
620
|
+
expect(typeArguments).toBeDefined();
|
|
621
|
+
expect(typeArguments).toHaveLength(2);
|
|
622
|
+
|
|
623
|
+
const [definition, typeofMinMax] = typeArguments;
|
|
554
624
|
|
|
555
625
|
// Min
|
|
556
|
-
expect(
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
);
|
|
563
|
-
expect(
|
|
626
|
+
expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
627
|
+
expect(definition.members).toHaveLength(1);
|
|
628
|
+
|
|
629
|
+
const [min] = definition.members;
|
|
630
|
+
|
|
631
|
+
expect(min.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
632
|
+
expect(min.name.escapedText).toBe('min');
|
|
633
|
+
expect(min.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
634
|
+
expect(min.type.text).toBe('2');
|
|
635
|
+
|
|
636
|
+
// Check for number keyword on the second typeArgument
|
|
637
|
+
expect(typeofMinMax.kind).toBe(ts.SyntaxKind.NumberKeyword);
|
|
564
638
|
});
|
|
565
639
|
|
|
566
640
|
test('No Min, Max: 3', () => {
|
|
@@ -572,19 +646,27 @@ describe('Attributes', () => {
|
|
|
572
646
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
573
647
|
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
|
|
574
648
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
expect(modifiers[0].typeArguments[0].members).toHaveLength(1);
|
|
649
|
+
const [setMinMax] = modifiers;
|
|
650
|
+
const { typeArguments } = setMinMax;
|
|
578
651
|
|
|
579
|
-
|
|
580
|
-
expect(
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
);
|
|
587
|
-
|
|
652
|
+
expect(typeArguments).toBeDefined();
|
|
653
|
+
expect(typeArguments).toHaveLength(2);
|
|
654
|
+
|
|
655
|
+
const [definition, typeofMinMax] = typeArguments;
|
|
656
|
+
|
|
657
|
+
// Max
|
|
658
|
+
expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
659
|
+
expect(definition.members).toHaveLength(1);
|
|
660
|
+
|
|
661
|
+
const [max] = definition.members;
|
|
662
|
+
|
|
663
|
+
expect(max.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
664
|
+
expect(max.name.escapedText).toBe('max');
|
|
665
|
+
expect(max.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
666
|
+
expect(max.type.text).toBe('3');
|
|
667
|
+
|
|
668
|
+
// Check for number keyword on the second typeArgument
|
|
669
|
+
expect(typeofMinMax.kind).toBe(ts.SyntaxKind.NumberKeyword);
|
|
588
670
|
});
|
|
589
671
|
|
|
590
672
|
test('Min: 4, Max: 12', () => {
|
|
@@ -596,28 +678,96 @@ describe('Attributes', () => {
|
|
|
596
678
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
597
679
|
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
|
|
598
680
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
expect(modifiers[0].typeArguments[0].members).toHaveLength(2);
|
|
681
|
+
const [setMinMax] = modifiers;
|
|
682
|
+
const { typeArguments } = setMinMax;
|
|
602
683
|
|
|
603
|
-
|
|
604
|
-
expect(
|
|
605
|
-
ts.SyntaxKind.PropertyDeclaration
|
|
606
|
-
);
|
|
607
|
-
expect(modifiers[0].typeArguments[0].members[0].name.escapedText).toBe('min');
|
|
608
|
-
expect(modifiers[0].typeArguments[0].members[0].type.kind).toBe(
|
|
609
|
-
ts.SyntaxKind.NumericLiteral
|
|
610
|
-
);
|
|
611
|
-
expect(modifiers[0].typeArguments[0].members[0].type.text).toBe('4');
|
|
684
|
+
expect(typeArguments).toBeDefined();
|
|
685
|
+
expect(typeArguments).toHaveLength(2);
|
|
612
686
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
expect(
|
|
617
|
-
expect(
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
687
|
+
const [definition, typeofMinMax] = typeArguments;
|
|
688
|
+
|
|
689
|
+
// Min/Max
|
|
690
|
+
expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
691
|
+
expect(definition.members).toHaveLength(2);
|
|
692
|
+
|
|
693
|
+
const [min, max] = definition.members;
|
|
694
|
+
|
|
695
|
+
expect(min.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
696
|
+
expect(min.name.escapedText).toBe('min');
|
|
697
|
+
expect(min.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
698
|
+
expect(min.type.text).toBe('4');
|
|
699
|
+
|
|
700
|
+
expect(max.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
701
|
+
expect(max.name.escapedText).toBe('max');
|
|
702
|
+
expect(max.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
703
|
+
expect(max.type.text).toBe('12');
|
|
704
|
+
|
|
705
|
+
// Check for number keyword on the second typeArgument
|
|
706
|
+
expect(typeofMinMax.kind).toBe(ts.SyntaxKind.NumberKeyword);
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
test('Min: "1"', () => {
|
|
710
|
+
const attribute = { min: '1' };
|
|
711
|
+
const modifiers = getAttributeModifiers(attribute);
|
|
712
|
+
|
|
713
|
+
expect(modifiers).toHaveLength(1);
|
|
714
|
+
|
|
715
|
+
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
716
|
+
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
|
|
717
|
+
|
|
718
|
+
const [setMinMax] = modifiers;
|
|
719
|
+
const { typeArguments } = setMinMax;
|
|
720
|
+
|
|
721
|
+
expect(typeArguments).toBeDefined();
|
|
722
|
+
expect(typeArguments).toHaveLength(2);
|
|
723
|
+
|
|
724
|
+
const [definition, typeofMinMax] = typeArguments;
|
|
725
|
+
|
|
726
|
+
// Min/Max
|
|
727
|
+
expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
728
|
+
expect(definition.members).toHaveLength(1);
|
|
729
|
+
|
|
730
|
+
const [min] = definition.members;
|
|
731
|
+
|
|
732
|
+
expect(min.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
733
|
+
expect(min.name.escapedText).toBe('min');
|
|
734
|
+
expect(min.type.kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
735
|
+
expect(min.type.text).toBe('1');
|
|
736
|
+
|
|
737
|
+
// Check for string keyword on the second typeArgument
|
|
738
|
+
expect(typeofMinMax.kind).toBe(ts.SyntaxKind.StringKeyword);
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
test('Min: 0', () => {
|
|
742
|
+
const attribute = { min: 0 };
|
|
743
|
+
const modifiers = getAttributeModifiers(attribute);
|
|
744
|
+
|
|
745
|
+
expect(modifiers).toHaveLength(1);
|
|
746
|
+
|
|
747
|
+
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
748
|
+
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
|
|
749
|
+
|
|
750
|
+
const [setMinMax] = modifiers;
|
|
751
|
+
const { typeArguments } = setMinMax;
|
|
752
|
+
|
|
753
|
+
expect(typeArguments).toBeDefined();
|
|
754
|
+
expect(typeArguments).toHaveLength(2);
|
|
755
|
+
|
|
756
|
+
const [definition, typeofMinMax] = typeArguments;
|
|
757
|
+
|
|
758
|
+
// Min/Max
|
|
759
|
+
expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
760
|
+
expect(definition.members).toHaveLength(1);
|
|
761
|
+
|
|
762
|
+
const [min] = definition.members;
|
|
763
|
+
|
|
764
|
+
expect(min.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
765
|
+
expect(min.name.escapedText).toBe('min');
|
|
766
|
+
expect(min.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
767
|
+
expect(min.type.text).toBe('0');
|
|
768
|
+
|
|
769
|
+
// Check for string keyword on the second typeArgument
|
|
770
|
+
expect(typeofMinMax.kind).toBe(ts.SyntaxKind.NumberKeyword);
|
|
621
771
|
});
|
|
622
772
|
});
|
|
623
773
|
|
|
@@ -2,25 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const fs = require('fs-extra');
|
|
5
|
+
const adminTsConfig = require('../../tsconfigs/admin.json');
|
|
5
6
|
|
|
6
7
|
module.exports = async (dest) => {
|
|
7
8
|
const tsConfig = {
|
|
8
|
-
|
|
9
|
-
lib: ['es2019', 'es2020.promise', 'es2020.bigint', 'es2020.string', 'DOM'],
|
|
10
|
-
noImplicitAny: false,
|
|
11
|
-
module: 'es2020',
|
|
12
|
-
target: 'es5',
|
|
13
|
-
jsx: 'react',
|
|
14
|
-
allowJs: true,
|
|
15
|
-
strict: true,
|
|
16
|
-
moduleResolution: 'node',
|
|
17
|
-
skipLibCheck: true,
|
|
18
|
-
esModuleInterop: true,
|
|
19
|
-
allowSyntheticDefaultImports: true,
|
|
20
|
-
resolveJsonModule: true,
|
|
21
|
-
noEmit: false,
|
|
22
|
-
incremental: true,
|
|
23
|
-
},
|
|
9
|
+
...adminTsConfig,
|
|
24
10
|
include: ['../../../src/admin/*', '../../../src/**/**/admin/src/*'],
|
|
25
11
|
exclude: ['node_modules', '**/*.test.js', '*.js'],
|
|
26
12
|
};
|
package/lib/compile.js
CHANGED
|
@@ -3,12 +3,8 @@
|
|
|
3
3
|
const compilers = require('./compilers');
|
|
4
4
|
const getConfigPath = require('./utils/get-config-path');
|
|
5
5
|
|
|
6
|
-
module.exports = async (srcDir, {
|
|
7
|
-
// TODO: Use the Strapi debug logger instead or don't log at all
|
|
8
|
-
console.log(`Starting the compilation for TypeScript files in ${srcDir}`);
|
|
9
|
-
|
|
10
|
-
const compiler = watch ? compilers.watch : compilers.basic;
|
|
6
|
+
module.exports = async (srcDir, { configOptions = {} } = {}) => {
|
|
11
7
|
const configPath = getConfigPath(srcDir);
|
|
12
8
|
|
|
13
|
-
|
|
9
|
+
compilers.basic.run(configPath, configOptions);
|
|
14
10
|
};
|
package/lib/compilers/basic.js
CHANGED
|
@@ -13,15 +13,23 @@ module.exports = {
|
|
|
13
13
|
* @param {Object} configOptions
|
|
14
14
|
* @param {Array.<string>} configOptions.fileNames
|
|
15
15
|
* @param {Object} configOptions.options
|
|
16
|
+
* @param {boolean} configOptions.ignoreDiagnostics
|
|
16
17
|
*/
|
|
17
18
|
run(tsConfigPath, configOptions = {}) {
|
|
19
|
+
const { ignoreDiagnostics = false } = configOptions;
|
|
18
20
|
// Parse the tsconfig.json file & resolve the configuration options
|
|
19
21
|
const { fileNames, options, projectReferences } = resolveConfigOptions(tsConfigPath);
|
|
20
22
|
|
|
23
|
+
const compilerOptions = merge(options, configOptions.options);
|
|
24
|
+
|
|
25
|
+
if (ignoreDiagnostics) {
|
|
26
|
+
Object.assign(compilerOptions, { noEmit: false, noEmitOnError: false });
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
const program = ts.createProgram({
|
|
22
30
|
rootNames: configOptions.fileNames ? configOptions.fileNames : fileNames,
|
|
23
31
|
projectReferences,
|
|
24
|
-
options:
|
|
32
|
+
options: compilerOptions,
|
|
25
33
|
});
|
|
26
34
|
|
|
27
35
|
const emitResults = program.emit();
|
|
@@ -30,12 +38,12 @@ module.exports = {
|
|
|
30
38
|
ts.getPreEmitDiagnostics(program).concat(emitResults.diagnostics)
|
|
31
39
|
);
|
|
32
40
|
|
|
33
|
-
if (diagnostics.length > 0) {
|
|
41
|
+
if (!ignoreDiagnostics && diagnostics.length > 0) {
|
|
34
42
|
reportDiagnostics(diagnostics);
|
|
35
43
|
}
|
|
36
44
|
|
|
37
|
-
// If the compilation failed, exit early
|
|
38
|
-
if (emitResults.emitSkipped) {
|
|
45
|
+
// If the compilation failed and diagnostics are not ignored, exit early
|
|
46
|
+
if (!ignoreDiagnostics && emitResults.emitSkipped) {
|
|
39
47
|
process.exit(1);
|
|
40
48
|
}
|
|
41
49
|
},
|
package/lib/compilers/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const ts = require('typescript');
|
|
4
4
|
const _ = require('lodash/fp');
|
|
5
5
|
|
|
6
6
|
const { addImport } = require('../imports');
|
|
7
7
|
const { getTypeNode, toTypeLiteral, withAttributeNamespace, NAMESPACES } = require('./utils');
|
|
8
8
|
const mappers = require('./mappers');
|
|
9
9
|
|
|
10
|
+
const { factory } = ts;
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* Create the base type node for a given attribute
|
|
12
14
|
*
|
|
@@ -100,14 +102,39 @@ const getAttributeModifiers = (attribute) => {
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
// Min / Max
|
|
103
|
-
// TODO: Always provide a second type argument for min/max (ie: resolve the attribute scalar type with a `GetAttributeType<${mappers[attribute][0]}>` (useful for biginter (string values)))
|
|
104
105
|
if (!_.isNil(attribute.min) || !_.isNil(attribute.max)) {
|
|
105
106
|
const minMaxProperties = _.pick(['min', 'max'], attribute);
|
|
107
|
+
const { min, max } = minMaxProperties;
|
|
108
|
+
|
|
109
|
+
const typeofMin = typeof min;
|
|
110
|
+
const typeofMax = typeof max;
|
|
111
|
+
|
|
112
|
+
// Throws error if min/max exist but have different types to prevent unexpected behavior
|
|
113
|
+
if (min !== undefined && max !== undefined && typeofMin !== typeofMax) {
|
|
114
|
+
throw new Error('typeof min/max values mismatch');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let typeKeyword;
|
|
118
|
+
|
|
119
|
+
// use 'string'
|
|
120
|
+
if (typeofMin === 'string' || typeofMax === 'string') {
|
|
121
|
+
typeKeyword = ts.SyntaxKind.StringKeyword;
|
|
122
|
+
}
|
|
123
|
+
// use 'number'
|
|
124
|
+
else if (typeofMin === 'number' || typeofMax === 'number') {
|
|
125
|
+
typeKeyword = ts.SyntaxKind.NumberKeyword;
|
|
126
|
+
}
|
|
127
|
+
// invalid type
|
|
128
|
+
else {
|
|
129
|
+
throw new Error(
|
|
130
|
+
`Invalid data type for min/max options. Must be string, number or undefined, but found { min: ${min} (${typeofMin}), max: ${max} (${typeofMax}) }`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
106
133
|
|
|
107
134
|
modifiers.push(
|
|
108
135
|
factory.createTypeReferenceNode(
|
|
109
136
|
factory.createIdentifier(withAttributeNamespace('SetMinMax')),
|
|
110
|
-
[toTypeLiteral(minMaxProperties)]
|
|
137
|
+
[toTypeLiteral(minMaxProperties), factory.createKeywordTypeNode(typeKeyword)]
|
|
111
138
|
)
|
|
112
139
|
);
|
|
113
140
|
}
|
|
@@ -87,8 +87,29 @@ module.exports = {
|
|
|
87
87
|
json() {
|
|
88
88
|
return [withAttributeNamespace('JSON')];
|
|
89
89
|
},
|
|
90
|
-
|
|
91
|
-
return [withAttributeNamespace('
|
|
90
|
+
blocks() {
|
|
91
|
+
return [withAttributeNamespace('Blocks')];
|
|
92
|
+
},
|
|
93
|
+
media({ attribute }) {
|
|
94
|
+
const { allowedTypes, multiple } = attribute;
|
|
95
|
+
|
|
96
|
+
const params = [];
|
|
97
|
+
|
|
98
|
+
const typesParam = allowedTypes
|
|
99
|
+
? factory.createUnionTypeNode(
|
|
100
|
+
allowedTypes.map((allowedType) => factory.createStringLiteral(allowedType))
|
|
101
|
+
)
|
|
102
|
+
: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword);
|
|
103
|
+
|
|
104
|
+
if (allowedTypes || multiple) {
|
|
105
|
+
params.push(typesParam);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (multiple) {
|
|
109
|
+
params.push(factory.createTrue());
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return [withAttributeNamespace('Media'), params];
|
|
92
113
|
},
|
|
93
114
|
relation({ uid, attribute }) {
|
|
94
115
|
const { relation, target } = attribute;
|
package/lib/generators/utils.js
CHANGED
|
@@ -92,7 +92,7 @@ const generateSharedExtensionDefinition = (registry, definitions) => {
|
|
|
92
92
|
|
|
93
93
|
return factory.createModuleDeclaration(
|
|
94
94
|
[factory.createModifier(ts.SyntaxKind.DeclareKeyword)],
|
|
95
|
-
factory.createStringLiteral('@strapi/
|
|
95
|
+
factory.createStringLiteral('@strapi/types', true),
|
|
96
96
|
factory.createModuleBlock([
|
|
97
97
|
factory.createModuleDeclaration(
|
|
98
98
|
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/typescript-utils",
|
|
3
|
-
"version": "0.0.0-next.
|
|
3
|
+
"version": "0.0.0-next.f4ff842a3cb7b83db540bee67554b704e042b042",
|
|
4
4
|
"description": "Typescript support for Strapi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
7
7
|
"generators"
|
|
8
8
|
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git://github.com/strapi/strapi.git",
|
|
12
|
+
"directory": "packages/utils/typescript"
|
|
13
|
+
},
|
|
9
14
|
"license": "SEE LICENSE IN LICENSE",
|
|
10
15
|
"author": {
|
|
11
16
|
"name": "Strapi Solutions SAS",
|
|
@@ -35,11 +40,11 @@
|
|
|
35
40
|
"fs-extra": "10.0.0",
|
|
36
41
|
"lodash": "4.17.21",
|
|
37
42
|
"prettier": "2.8.4",
|
|
38
|
-
"typescript": "5.
|
|
43
|
+
"typescript": "5.2.2"
|
|
39
44
|
},
|
|
40
45
|
"engines": {
|
|
41
|
-
"node": ">=
|
|
46
|
+
"node": ">=18.0.0 <=20.x.x",
|
|
42
47
|
"npm": ">=6.0.0"
|
|
43
48
|
},
|
|
44
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "f4ff842a3cb7b83db540bee67554b704e042b042"
|
|
45
50
|
}
|
package/tsconfigs/admin.json
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "Bundler",
|
|
7
|
+
"useDefineForClassFields": true,
|
|
8
|
+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
9
|
+
"allowJs": false,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"noEmit": true,
|
|
17
|
+
"jsx": "react-jsx"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/tsconfigs/server.json
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"module": "CommonJS",
|
|
6
|
-
"moduleResolution": "Node",
|
|
7
|
-
"lib": ["ES2020"],
|
|
8
|
-
"target": "ES2019",
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
9
3
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"module": "CommonJS",
|
|
6
|
+
"moduleResolution": "Node",
|
|
7
|
+
"lib": ["ES2020"],
|
|
8
|
+
"target": "ES2019",
|
|
13
9
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
"strict": false,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
|
|
14
|
+
"incremental": true,
|
|
15
|
+
"esModuleInterop": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"noEmitOnError": true,
|
|
18
|
+
"noImplicitThis": true
|
|
19
|
+
}
|
|
20
|
+
}
|
package/lib/compilers/watch.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const ts = require('typescript');
|
|
4
|
-
|
|
5
|
-
const reportDiagnostics = require('../utils/report-diagnostics');
|
|
6
|
-
const formatHost = require('../utils/format-host');
|
|
7
|
-
const resolveConfigOptions = require('../utils/resolve-config-options');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Prints a diagnostic every time the watch status changes.
|
|
11
|
-
* This is mainly for messages like "Starting compilation" or "Compilation completed".
|
|
12
|
-
*/
|
|
13
|
-
const reportWatchStatusChanged = (diagnostic) => {
|
|
14
|
-
console.info(ts.formatDiagnostic(diagnostic, formatHost));
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
module.exports = {
|
|
18
|
-
run(configPath) {
|
|
19
|
-
const createProgram = ts.createSemanticDiagnosticsBuilderProgram;
|
|
20
|
-
|
|
21
|
-
const { fileNames, options, projectReferences, watchOptions } =
|
|
22
|
-
resolveConfigOptions(configPath);
|
|
23
|
-
|
|
24
|
-
const host = ts.createWatchCompilerHost(
|
|
25
|
-
fileNames,
|
|
26
|
-
options,
|
|
27
|
-
ts.sys,
|
|
28
|
-
createProgram,
|
|
29
|
-
reportDiagnostics,
|
|
30
|
-
reportWatchStatusChanged,
|
|
31
|
-
projectReferences,
|
|
32
|
-
watchOptions
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
ts.createWatchProgram(host);
|
|
36
|
-
},
|
|
37
|
-
};
|