@strapi/typescript-utils
Advanced tools
Comparing version 0.0.0-experimental.c3e9d4b26f9fd3d9eb530b5c11f9baa1d09b13ad to 0.0.0-experimental.c4796a8a857b6e4d1d5ce6bd2606f6438e63962f
@@ -683,4 +683,9 @@ 'use strict'; | ||
const [min, max] = definition.members; | ||
const [max, min] = definition.members; | ||
expect(max.kind).toBe(ts.SyntaxKind.PropertyDeclaration); | ||
expect(max.name.escapedText).toBe('max'); | ||
expect(max.type.kind).toBe(ts.SyntaxKind.NumericLiteral); | ||
expect(max.type.text).toBe('12'); | ||
expect(min.kind).toBe(ts.SyntaxKind.PropertyDeclaration); | ||
@@ -691,7 +696,2 @@ expect(min.name.escapedText).toBe('min'); | ||
expect(max.kind).toBe(ts.SyntaxKind.PropertyDeclaration); | ||
expect(max.name.escapedText).toBe('max'); | ||
expect(max.type.kind).toBe(ts.SyntaxKind.NumericLiteral); | ||
expect(max.type.text).toBe('12'); | ||
// Check for number keyword on the second typeArgument | ||
@@ -835,20 +835,15 @@ expect(typeofMinMax.kind).toBe(ts.SyntaxKind.NumberKeyword); | ||
const [maxLength, minLength] = modifiers[0].typeArguments[0].members; | ||
// Max | ||
expect(maxLength.kind).toBe(ts.SyntaxKind.PropertyDeclaration); | ||
expect(maxLength.name.escapedText).toBe('maxLength'); | ||
expect(maxLength.type.kind).toBe(ts.SyntaxKind.NumericLiteral); | ||
expect(maxLength.type.text).toBe('12'); | ||
// Min | ||
expect(modifiers[0].typeArguments[0].members[0].kind).toBe( | ||
ts.SyntaxKind.PropertyDeclaration | ||
); | ||
expect(modifiers[0].typeArguments[0].members[0].name.escapedText).toBe('minLength'); | ||
expect(modifiers[0].typeArguments[0].members[0].type.kind).toBe( | ||
ts.SyntaxKind.NumericLiteral | ||
); | ||
expect(modifiers[0].typeArguments[0].members[0].type.text).toBe('4'); | ||
expect(modifiers[0].typeArguments[0].members[1].kind).toBe( | ||
ts.SyntaxKind.PropertyDeclaration | ||
); | ||
expect(modifiers[0].typeArguments[0].members[1].name.escapedText).toBe('maxLength'); | ||
expect(modifiers[0].typeArguments[0].members[1].type.kind).toBe( | ||
ts.SyntaxKind.NumericLiteral | ||
); | ||
expect(modifiers[0].typeArguments[0].members[1].type.text).toBe('12'); | ||
expect(minLength.kind).toBe(ts.SyntaxKind.PropertyDeclaration); | ||
expect(minLength.name.escapedText).toBe('minLength'); | ||
expect(minLength.type.kind).toBe(ts.SyntaxKind.NumericLiteral); | ||
expect(minLength.type.text).toBe('4'); | ||
}); | ||
@@ -855,0 +850,0 @@ }); |
@@ -250,9 +250,9 @@ 'use strict'; | ||
expect(objectNode.members[0].kind).toBe(ts.SyntaxKind.PropertyDeclaration); | ||
expect(objectNode.members[0].name.escapedText).toBe('foo'); | ||
expect(objectNode.members[0].type.kind).toBe(ts.SyntaxKind.StringLiteral); | ||
expect(objectNode.members[0].type.text).toBe('bar'); | ||
expect(objectNode.members[0].name.escapedText).toBe('bar'); | ||
expect(objectNode.members[0].type.kind).toBe(ts.SyntaxKind.TrueKeyword); | ||
expect(objectNode.members[1].kind).toBe(ts.SyntaxKind.PropertyDeclaration); | ||
expect(objectNode.members[1].name.escapedText).toBe('bar'); | ||
expect(objectNode.members[1].type.kind).toBe(ts.SyntaxKind.TrueKeyword); | ||
expect(objectNode.members[1].name.escapedText).toBe('foo'); | ||
expect(objectNode.members[1].type.kind).toBe(ts.SyntaxKind.StringLiteral); | ||
expect(objectNode.members[1].type.text).toBe('bar'); | ||
}); | ||
@@ -266,16 +266,16 @@ | ||
const [firstMember, secondMember] = node.members; | ||
const [barMember, fooMember] = node.members; | ||
expect(firstMember.kind).toBe(ts.SyntaxKind.PropertyDeclaration); | ||
expect(firstMember.name.escapedText).toBe('foo'); | ||
expect(firstMember.type.kind).toBe(ts.SyntaxKind.TupleType); | ||
expect(firstMember.type.elements).toHaveLength(3); | ||
expect(firstMember.type.elements[0].kind).toBe(ts.SyntaxKind.StringLiteral); | ||
expect(firstMember.type.elements[1].kind).toBe(ts.SyntaxKind.TrueKeyword); | ||
expect(firstMember.type.elements[2].kind).toBe(ts.SyntaxKind.FirstLiteralToken); | ||
expect(barMember.kind).toBe(ts.SyntaxKind.PropertyDeclaration); | ||
expect(barMember.name.escapedText).toBe('bar'); | ||
expect(barMember.type.kind).toBe(ts.SyntaxKind.LiteralType); | ||
expect(barMember.type.literal).toBe(ts.SyntaxKind.NullKeyword); | ||
expect(secondMember.kind).toBe(ts.SyntaxKind.PropertyDeclaration); | ||
expect(secondMember.name.escapedText).toBe('bar'); | ||
expect(secondMember.type.kind).toBe(ts.SyntaxKind.LiteralType); | ||
expect(secondMember.type.literal).toBe(ts.SyntaxKind.NullKeyword); | ||
expect(fooMember.kind).toBe(ts.SyntaxKind.PropertyDeclaration); | ||
expect(fooMember.name.escapedText).toBe('foo'); | ||
expect(fooMember.type.kind).toBe(ts.SyntaxKind.TupleType); | ||
expect(fooMember.type.elements).toHaveLength(3); | ||
expect(fooMember.type.elements[0].kind).toBe(ts.SyntaxKind.StringLiteral); | ||
expect(fooMember.type.elements[1].kind).toBe(ts.SyntaxKind.TrueKeyword); | ||
expect(fooMember.type.elements[2].kind).toBe(ts.SyntaxKind.FirstLiteralToken); | ||
}); | ||
@@ -289,15 +289,15 @@ | ||
const [firstMember, secondMember] = node.members; | ||
const [fooBar, fooDashBar] = node.members; | ||
expect(firstMember.kind).toBe(ts.SyntaxKind.PropertyDeclaration); | ||
expect(firstMember.name.kind).toBe(ts.SyntaxKind.StringLiteral); | ||
expect(firstMember.name.text).toBe('foo-bar'); | ||
expect(firstMember.type.kind).toBe(ts.SyntaxKind.StringLiteral); | ||
expect(firstMember.type.text).toBe('foobar'); | ||
expect(fooBar.kind).toBe(ts.SyntaxKind.PropertyDeclaration); | ||
expect(fooBar.name.kind).toBe(ts.SyntaxKind.Identifier); | ||
expect(fooBar.name.escapedText).toBe('foo'); | ||
expect(fooBar.type.kind).toBe(ts.SyntaxKind.StringLiteral); | ||
expect(fooBar.type.text).toBe('bar'); | ||
expect(secondMember.kind).toBe(ts.SyntaxKind.PropertyDeclaration); | ||
expect(secondMember.name.kind).toBe(ts.SyntaxKind.Identifier); | ||
expect(secondMember.name.escapedText).toBe('foo'); | ||
expect(secondMember.type.kind).toBe(ts.SyntaxKind.StringLiteral); | ||
expect(secondMember.type.text).toBe('bar'); | ||
expect(fooDashBar.kind).toBe(ts.SyntaxKind.PropertyDeclaration); | ||
expect(fooDashBar.name.kind).toBe(ts.SyntaxKind.StringLiteral); | ||
expect(fooDashBar.name.text).toBe('foo-bar'); | ||
expect(fooDashBar.type.kind).toBe(ts.SyntaxKind.StringLiteral); | ||
expect(fooDashBar.type.text).toBe('foobar'); | ||
}); | ||
@@ -304,0 +304,0 @@ |
@@ -21,5 +21,5 @@ 'use strict'; | ||
generateImportDefinition() { | ||
const formattedImports = imports.map((key) => | ||
factory.createImportSpecifier(false, undefined, factory.createIdentifier(key)) | ||
); | ||
const formattedImports = imports | ||
.sort() | ||
.map((key) => factory.createImportSpecifier(false, undefined, factory.createIdentifier(key))); | ||
@@ -26,0 +26,0 @@ return [ |
@@ -25,5 +25,7 @@ 'use strict'; | ||
const properties = Object.entries(attributes).map(([attributeName, attribute]) => { | ||
return attributeToPropertySignature(schema, attributeName, attribute); | ||
}); | ||
const properties = Object.entries(attributes) | ||
.sort((a, b) => a[0].localeCompare(b[0])) | ||
.map(([attributeName, attribute]) => { | ||
return attributeToPropertySignature(schema, attributeName, attribute); | ||
}); | ||
@@ -30,0 +32,0 @@ return factory.createPropertySignature( |
@@ -114,3 +114,3 @@ 'use strict'; | ||
const entries = Object.entries(data); | ||
const entries = Object.entries(data).sort((a, b) => a[0].localeCompare(b[0])); | ||
@@ -117,0 +117,0 @@ const props = entries.reduce((acc, [key, value]) => { |
'use strict'; | ||
const { factory } = require('typescript'); | ||
const { pipe, values, sortBy, map } = require('lodash/fp'); | ||
@@ -8,2 +9,7 @@ const { models } = require('../common'); | ||
const NO_COMPONENT_PLACEHOLDER_COMMENT = `/* | ||
* The app doesn't have any components yet. | ||
*/ | ||
`; | ||
/** | ||
@@ -22,7 +28,17 @@ * Generate type definitions for Strapi Components | ||
const componentsDefinitions = Object.values(components).map((contentType) => ({ | ||
uid: contentType.uid, | ||
definition: models.schema.generateSchemaDefinition(contentType), | ||
})); | ||
const componentsDefinitions = pipe( | ||
values, | ||
sortBy('uid'), | ||
map((component) => ({ | ||
uid: component.uid, | ||
definition: models.schema.generateSchemaDefinition(component), | ||
})) | ||
)(components); | ||
options.logger.debug(`Found ${componentsDefinitions.length} components.`); | ||
if (componentsDefinitions.length === 0) { | ||
return { output: NO_COMPONENT_PLACEHOLDER_COMMENT, stats: {} }; | ||
} | ||
const formattedSchemasDefinitions = componentsDefinitions.reduce((acc, def) => { | ||
@@ -29,0 +45,0 @@ acc.push( |
'use strict'; | ||
const { factory } = require('typescript'); | ||
const { values, pipe, map, sortBy } = require('lodash/fp'); | ||
@@ -8,2 +9,7 @@ const { models } = require('../common'); | ||
const NO_CONTENT_TYPE_PLACEHOLDER_COMMENT = `/* | ||
* The app doesn't have any content-types yet. | ||
*/ | ||
`; | ||
/** | ||
@@ -22,7 +28,17 @@ * Generate type definitions for Strapi Content-Types | ||
const contentTypesDefinitions = Object.values(contentTypes).map((contentType) => ({ | ||
uid: contentType.uid, | ||
definition: models.schema.generateSchemaDefinition(contentType), | ||
})); | ||
const contentTypesDefinitions = pipe( | ||
values, | ||
sortBy('uid'), | ||
map((contentType) => ({ | ||
uid: contentType.uid, | ||
definition: models.schema.generateSchemaDefinition(contentType), | ||
})) | ||
)(contentTypes); | ||
options.logger.debug(`Found ${contentTypesDefinitions.length} content-types.`); | ||
if (contentTypesDefinitions.length === 0) { | ||
return { output: NO_CONTENT_TYPE_PLACEHOLDER_COMMENT, stats: {} }; | ||
} | ||
const formattedSchemasDefinitions = contentTypesDefinitions.reduce((acc, def) => { | ||
@@ -29,0 +45,0 @@ acc.push( |
@@ -5,3 +5,2 @@ 'use strict'; | ||
const compilers = require('./compilers'); | ||
const admin = require('./admin'); | ||
const utils = require('./utils'); | ||
@@ -13,6 +12,4 @@ const generators = require('./generators'); | ||
compilers, | ||
admin, | ||
generators, | ||
...utils, | ||
}; |
@@ -10,2 +10,3 @@ 'use strict'; | ||
const resolveOutDir = require('./resolve-outdir'); | ||
const resolveOutDirSync = require('./resolve-outdir-sync'); | ||
@@ -20,2 +21,3 @@ module.exports = { | ||
resolveOutDir, | ||
resolveOutDirSync, | ||
}; |
{ | ||
"name": "@strapi/typescript-utils", | ||
"version": "0.0.0-experimental.c3e9d4b26f9fd3d9eb530b5c11f9baa1d09b13ad", | ||
"version": "0.0.0-experimental.c4796a8a857b6e4d1d5ce6bd2606f6438e63962f", | ||
"description": "Typescript support for Strapi", | ||
@@ -39,7 +39,7 @@ "keywords": [ | ||
"chalk": "4.1.2", | ||
"cli-table3": "0.6.2", | ||
"cli-table3": "0.6.5", | ||
"fs-extra": "11.2.0", | ||
"lodash": "4.17.21", | ||
"prettier": "3.2.5", | ||
"typescript": "5.3.2" | ||
"prettier": "3.3.3", | ||
"typescript": "5.4.4" | ||
}, | ||
@@ -50,6 +50,5 @@ "devDependencies": { | ||
"engines": { | ||
"node": ">=18.0.0 <=20.x.x", | ||
"node": ">=18.0.0 <=22.x.x", | ||
"npm": ">=6.0.0" | ||
}, | ||
"gitHead": "c3e9d4b26f9fd3d9eb530b5c11f9baa1d09b13ad" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
89968
2158
3
0
36
1
80
+ Addedcli-table3@0.6.5(transitive)
+ Addedprettier@3.3.3(transitive)
+ Addedtypescript@5.4.4(transitive)
- Removedcli-table3@0.6.2(transitive)
- Removedprettier@3.2.5(transitive)
- Removedtypescript@5.3.2(transitive)
Updatedcli-table3@0.6.5
Updatedprettier@3.3.3
Updatedtypescript@5.4.4