@strapi/typescript-utils 0.0.0-next.f6dca5adf05ef6bed9605a1535999ab0bbbf063e → 0.0.0-next.f86041c89a8c1545c6437a881dc613e98bc52bd7

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.
@@ -680,18 +680,18 @@ describe('Attributes', () => {
680
680
  expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
681
681
  expect(definition.members).toHaveLength(2);
682
682
 
683
- const [min, max] = definition.members;
684
-
685
- expect(min.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
686
- expect(min.name.escapedText).toBe('min');
687
- expect(min.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
688
- expect(min.type.text).toBe('4');
683
+ const [max, min] = definition.members;
689
684
 
690
685
  expect(max.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
691
686
  expect(max.name.escapedText).toBe('max');
692
687
  expect(max.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
693
688
  expect(max.type.text).toBe('12');
694
689
 
690
+ expect(min.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
691
+ expect(min.name.escapedText).toBe('min');
692
+ expect(min.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
693
+ expect(min.type.text).toBe('4');
694
+
695
695
  // Check for number keyword on the second typeArgument
696
696
  expect(typeofMinMax.kind).toBe(ts.SyntaxKind.NumberKeyword);
697
697
  });
@@ -830,24 +830,19 @@ describe('Attributes', () => {
830
830
  expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral);
831
831
  expect(modifiers[0].typeArguments[0].members).toHaveLength(2);
832
832
 
833
- // Min
834
- expect(modifiers[0].typeArguments[0].members[0].kind).toBe(
835
- ts.SyntaxKind.PropertyDeclaration
836
- );
837
- expect(modifiers[0].typeArguments[0].members[0].name.escapedText).toBe('minLength');
838
- expect(modifiers[0].typeArguments[0].members[0].type.kind).toBe(
839
- ts.SyntaxKind.NumericLiteral
840
- );
841
- expect(modifiers[0].typeArguments[0].members[0].type.text).toBe('4');
833
+ const [maxLength, minLength] = modifiers[0].typeArguments[0].members;
842
834
 
843
- expect(modifiers[0].typeArguments[0].members[1].kind).toBe(
844
- ts.SyntaxKind.PropertyDeclaration
845
- );
846
- expect(modifiers[0].typeArguments[0].members[1].name.escapedText).toBe('maxLength');
847
- expect(modifiers[0].typeArguments[0].members[1].type.kind).toBe(
848
- ts.SyntaxKind.NumericLiteral
849
- );
850
- expect(modifiers[0].typeArguments[0].members[1].type.text).toBe('12');
835
+ // Max
836
+ expect(maxLength.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
837
+ expect(maxLength.name.escapedText).toBe('maxLength');
838
+ expect(maxLength.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
839
+ expect(maxLength.type.text).toBe('12');
840
+
841
+ // Min
842
+ expect(minLength.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
843
+ expect(minLength.name.escapedText).toBe('minLength');
844
+ expect(minLength.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
845
+ expect(minLength.type.text).toBe('4');
851
846
  });
852
847
  });
853
848
 
@@ -168,10 +168,16 @@ describe('Utils', () => {
168
168
  });
169
169
 
170
170
  test('Number', () => {
171
- const node = toTypeLiteral(42);
171
+ const nodePositive = toTypeLiteral(42);
172
+ const nodeNegative = toTypeLiteral(-42);
172
173
 
173
- expect(node.kind).toBe(ts.SyntaxKind.FirstLiteralToken);
174
- expect(node.text).toBe('42');
174
+ expect(nodePositive.kind).toBe(ts.SyntaxKind.FirstLiteralToken);
175
+ expect(nodePositive.text).toBe('42');
176
+
177
+ expect(nodeNegative.kind).toBe(ts.SyntaxKind.PrefixUnaryExpression);
178
+ expect(nodeNegative.operator).toBe(ts.SyntaxKind.MinusToken);
179
+ expect(nodeNegative.operand.kind).toBe(ts.SyntaxKind.FirstLiteralToken);
180
+ expect(nodeNegative.operand.text).toBe('42');
175
181
  });
176
182
 
177
183
  test('Boolean', () => {
@@ -247,13 +253,13 @@ describe('Utils', () => {
247
253
  expect(objectNode.members).toHaveLength(2);
248
254
 
249
255
  expect(objectNode.members[0].kind).toBe(ts.SyntaxKind.PropertyDeclaration);
250
- expect(objectNode.members[0].name.escapedText).toBe('foo');
251
- expect(objectNode.members[0].type.kind).toBe(ts.SyntaxKind.StringLiteral);
252
- expect(objectNode.members[0].type.text).toBe('bar');
256
+ expect(objectNode.members[0].name.escapedText).toBe('bar');
257
+ expect(objectNode.members[0].type.kind).toBe(ts.SyntaxKind.TrueKeyword);
253
258
 
254
259
  expect(objectNode.members[1].kind).toBe(ts.SyntaxKind.PropertyDeclaration);
255
- expect(objectNode.members[1].name.escapedText).toBe('bar');
256
- expect(objectNode.members[1].type.kind).toBe(ts.SyntaxKind.TrueKeyword);
260
+ expect(objectNode.members[1].name.escapedText).toBe('foo');
261
+ expect(objectNode.members[1].type.kind).toBe(ts.SyntaxKind.StringLiteral);
262
+ expect(objectNode.members[1].type.text).toBe('bar');
257
263
  });
258
264
 
259
265
  test('Object', () => {
@@ -262,20 +268,20 @@ describe('Utils', () => {
262
268
  expect(node.kind).toBe(ts.SyntaxKind.TypeLiteral);
263
269
  expect(node.members).toHaveLength(2);
264
270
 
265
- const [firstMember, secondMember] = node.members;
271
+ const [barMember, fooMember] = node.members;
266
272
 
267
- expect(firstMember.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
268
- expect(firstMember.name.escapedText).toBe('foo');
269
- expect(firstMember.type.kind).toBe(ts.SyntaxKind.TupleType);
270
- expect(firstMember.type.elements).toHaveLength(3);
271
- expect(firstMember.type.elements[0].kind).toBe(ts.SyntaxKind.StringLiteral);
272
- expect(firstMember.type.elements[1].kind).toBe(ts.SyntaxKind.TrueKeyword);
273
- expect(firstMember.type.elements[2].kind).toBe(ts.SyntaxKind.FirstLiteralToken);
273
+ expect(barMember.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
274
+ expect(barMember.name.escapedText).toBe('bar');
275
+ expect(barMember.type.kind).toBe(ts.SyntaxKind.LiteralType);
276
+ expect(barMember.type.literal).toBe(ts.SyntaxKind.NullKeyword);
274
277
 
275
- expect(secondMember.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
276
- expect(secondMember.name.escapedText).toBe('bar');
277
- expect(secondMember.type.kind).toBe(ts.SyntaxKind.LiteralType);
278
- expect(secondMember.type.literal).toBe(ts.SyntaxKind.NullKeyword);
278
+ expect(fooMember.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
279
+ expect(fooMember.name.escapedText).toBe('foo');
280
+ expect(fooMember.type.kind).toBe(ts.SyntaxKind.TupleType);
281
+ expect(fooMember.type.elements).toHaveLength(3);
282
+ expect(fooMember.type.elements[0].kind).toBe(ts.SyntaxKind.StringLiteral);
283
+ expect(fooMember.type.elements[1].kind).toBe(ts.SyntaxKind.TrueKeyword);
284
+ expect(fooMember.type.elements[2].kind).toBe(ts.SyntaxKind.FirstLiteralToken);
279
285
  });
280
286
 
281
287
  test('Object with complex keys', () => {
@@ -284,19 +290,19 @@ describe('Utils', () => {
284
290
  expect(node.kind).toBe(ts.SyntaxKind.TypeLiteral);
285
291
  expect(node.members).toHaveLength(2);
286
292
 
287
- const [firstMember, secondMember] = node.members;
293
+ const [fooBar, fooDashBar] = node.members;
288
294
 
289
- expect(firstMember.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
290
- expect(firstMember.name.kind).toBe(ts.SyntaxKind.StringLiteral);
291
- expect(firstMember.name.text).toBe('foo-bar');
292
- expect(firstMember.type.kind).toBe(ts.SyntaxKind.StringLiteral);
293
- expect(firstMember.type.text).toBe('foobar');
295
+ expect(fooBar.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
296
+ expect(fooBar.name.kind).toBe(ts.SyntaxKind.Identifier);
297
+ expect(fooBar.name.escapedText).toBe('foo');
298
+ expect(fooBar.type.kind).toBe(ts.SyntaxKind.StringLiteral);
299
+ expect(fooBar.type.text).toBe('bar');
294
300
 
295
- expect(secondMember.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
296
- expect(secondMember.name.kind).toBe(ts.SyntaxKind.Identifier);
297
- expect(secondMember.name.escapedText).toBe('foo');
298
- expect(secondMember.type.kind).toBe(ts.SyntaxKind.StringLiteral);
299
- expect(secondMember.type.text).toBe('bar');
301
+ expect(fooDashBar.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
302
+ expect(fooDashBar.name.kind).toBe(ts.SyntaxKind.StringLiteral);
303
+ expect(fooDashBar.name.text).toBe('foo-bar');
304
+ expect(fooDashBar.type.kind).toBe(ts.SyntaxKind.StringLiteral);
305
+ expect(fooDashBar.type.text).toBe('foobar');
300
306
  });
301
307
 
302
308
  test('Invalid data type supplied (function)', () => {
@@ -92,7 +92,12 @@ const toTypeLiteral = (data) => {
92
92
  }
93
93
 
94
94
  if (isNumber(data)) {
95
- return factory.createNumericLiteral(data);
95
+ return data < 0
96
+ ? factory.createPrefixUnaryExpression(
97
+ ts.SyntaxKind.MinusToken,
98
+ factory.createNumericLiteral(-data)
99
+ )
100
+ : factory.createNumericLiteral(data);
96
101
  }
97
102
 
98
103
  if (isBoolean(data)) {
@@ -7,6 +7,7 @@ const reportDiagnostics = require('./report-diagnostics');
7
7
  const resolveConfigOptions = require('./resolve-config-options');
8
8
  const formatHost = require('./format-host');
9
9
  const resolveOutDir = require('./resolve-outdir');
10
+ const resolveOutDirSync = require('./resolve-outdir-sync');
10
11
 
11
12
  module.exports = {
12
13
  isUsingTypeScript,
@@ -16,4 +17,5 @@ module.exports = {
16
17
  resolveConfigOptions,
17
18
  formatHost,
18
19
  resolveOutDir,
20
+ resolveOutDirSync,
19
21
  };
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const resolveConfigOptions = require('./resolve-config-options');
5
+ const isUsingTypescriptSync = require('./is-using-typescript-sync');
6
+
7
+ const DEFAULT_TS_CONFIG_FILENAME = 'tsconfig.json';
8
+ /**
9
+ * Gets the outDir value from config file (tsconfig)
10
+ * @param {string} dir
11
+ * @param {string | undefined} configFilename
12
+ * @returns {string | undefined}
13
+ */
14
+ module.exports = (dir, configFilename = DEFAULT_TS_CONFIG_FILENAME) => {
15
+ return isUsingTypescriptSync(dir)
16
+ ? resolveConfigOptions(path.join(dir, configFilename)).options.outDir
17
+ : undefined;
18
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/typescript-utils",
3
- "version": "0.0.0-next.f6dca5adf05ef6bed9605a1535999ab0bbbf063e",
3
+ "version": "0.0.0-next.f86041c89a8c1545c6437a881dc613e98bc52bd7",
4
4
  "description": "Typescript support for Strapi",
5
5
  "keywords": [
6
6
  "strapi",
@@ -40,14 +40,13 @@
40
40
  "fs-extra": "11.2.0",
41
41
  "lodash": "4.17.21",
42
42
  "prettier": "3.3.3",
43
- "typescript": "5.3.2"
43
+ "typescript": "5.4.4"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/fs-extra": "11.0.4"
47
47
  },
48
48
  "engines": {
49
- "node": ">=18.0.0 <=22.x.x",
49
+ "node": ">=20.0.0 <=24.x.x",
50
50
  "npm": ">=6.0.0"
51
- },
52
- "gitHead": "f6dca5adf05ef6bed9605a1535999ab0bbbf063e"
51
+ }
53
52
  }