@strapi/typescript-utils
Advanced tools
Comparing version
@@ -441,2 +441,57 @@ 'use strict'; | ||
describe('Custom field', () => { | ||
test('No custom field', () => { | ||
const attribute = {}; | ||
const modifiers = getAttributeModifiers(attribute); | ||
expect(modifiers).toHaveLength(0); | ||
}); | ||
test('Basic custom field', () => { | ||
const attribute = { | ||
type: 'string', | ||
customField: 'plugin::color-picker.color', | ||
}; | ||
const modifiers = getAttributeModifiers(attribute); | ||
expect(modifiers).toHaveLength(1); | ||
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); | ||
expect(modifiers[0].typeName.escapedText).toBe('CustomField'); | ||
expect(modifiers[0].typeArguments).toHaveLength(1); | ||
expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral); | ||
expect(modifiers[0].typeArguments[0].text).toBe('plugin::color-picker.color'); | ||
}); | ||
test('Advanced custom field', () => { | ||
const attribute = { | ||
type: 'string', | ||
customField: 'plugin::color-picker.color', | ||
options: { | ||
format: 'hex', | ||
}, | ||
}; | ||
const modifiers = getAttributeModifiers(attribute); | ||
expect(modifiers).toHaveLength(1); | ||
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); | ||
expect(modifiers[0].typeName.escapedText).toBe('CustomField'); | ||
expect(modifiers[0].typeArguments).toHaveLength(2); | ||
expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral); | ||
expect(modifiers[0].typeArguments[0].text).toBe('plugin::color-picker.color'); | ||
expect(modifiers[0].typeArguments[1].kind).toBe(ts.SyntaxKind.TypeLiteral); | ||
expect(modifiers[0].typeArguments[1].members).toHaveLength(1); | ||
expect(modifiers[0].typeArguments[1].members[0].kind).toBe( | ||
ts.SyntaxKind.PropertyDeclaration | ||
); | ||
expect(modifiers[0].typeArguments[1].members[0].name.escapedText).toBe('format'); | ||
expect(modifiers[0].typeArguments[1].members[0].kind).toBe( | ||
ts.SyntaxKind.PropertyDeclaration | ||
); | ||
expect(modifiers[0].typeArguments[1].members[0].type.kind).toBe( | ||
ts.SyntaxKind.StringLiteral | ||
); | ||
expect(modifiers[0].typeArguments[1].members[0].type.text).toBe('hex'); | ||
}); | ||
}); | ||
describe('Plugin Options', () => { | ||
@@ -443,0 +498,0 @@ test('No plugin options', () => { |
@@ -73,2 +73,18 @@ 'use strict'; | ||
// Custom field | ||
if (attribute.customField) { | ||
addImport('CustomField'); | ||
const customFieldUid = factory.createStringLiteral(attribute.customField); | ||
const typeArguments = [customFieldUid]; | ||
if (attribute.options) { | ||
typeArguments.push(toTypeLiteral(attribute.options)); | ||
} | ||
modifiers.push( | ||
factory.createTypeReferenceNode(factory.createIdentifier('CustomField'), typeArguments) | ||
); | ||
} | ||
// Plugin Options | ||
@@ -75,0 +91,0 @@ if (!_.isEmpty(attribute.pluginOptions)) { |
@@ -20,4 +20,6 @@ 'use strict'; | ||
const dirAbsolutePath = path.resolve(dir); | ||
const configFilePath = ts.findConfigFile(dirAbsolutePath, ts.sys.fileExists, filename); | ||
let configFilePath = ts.findConfigFile(dirAbsolutePath, ts.sys.fileExists, filename); | ||
if (configFilePath) configFilePath = path.resolve(configFilePath); | ||
if (!configFilePath || ancestorsLookup) { | ||
@@ -24,0 +26,0 @@ return configFilePath; |
{ | ||
"name": "@strapi/typescript-utils", | ||
"version": "0.0.0-c84fe78a134b3e2d6741d08a15d8bf4b848ec184", | ||
"version": "0.0.0-c85bf229301ca7c315c08db141cd7e0789c79fa3", | ||
"description": "Typescript support for Strapi", | ||
@@ -35,6 +35,6 @@ "keywords": [ | ||
"engines": { | ||
"node": ">=12.22.0 <=16.x.x", | ||
"node": ">=14.19.1 <=18.x.x", | ||
"npm": ">=6.0.0" | ||
}, | ||
"gitHead": "c84fe78a134b3e2d6741d08a15d8bf4b848ec184" | ||
"gitHead": "c85bf229301ca7c315c08db141cd7e0789c79fa3" | ||
} |
80060
3.72%1970
3.25%