File tree 5 files changed +22
-9
lines changed
5 files changed +22
-9
lines changed Original file line number Diff line number Diff line change 1
1
{
2
+ "plugins" : [" @babel/plugin-syntax-dynamic-import" ],
2
3
"env" : {
3
4
"test" : {
4
5
"presets" : [
5
- [ " @babel/preset- env" , {
6
+ [ " @babel/env" , {
6
7
"targets" : { "node" : " current" }
7
8
}]
8
9
]
Original file line number Diff line number Diff line change 13
13
"test" : " run-s test:*"
14
14
},
15
15
"dependencies" : {
16
- "ajv" : " ^6.10.2" ,
17
16
"os-locale" : " ^4.0.0" ,
18
17
"semver" : " ^6.3.0"
19
18
},
20
19
"devDependencies" : {
20
+ "@babel/plugin-syntax-dynamic-import" : " ^7.7.4" ,
21
21
"@babel/preset-env" : " ^7.7.4" ,
22
22
"@nuxtjs/eslint-config" : " ^2.0.0" ,
23
23
"ajv-cli" : " ^3.0.0" ,
27
27
"eslint" : " ^6.7.1" ,
28
28
"jest" : " ^24.9.0" ,
29
29
"npm-run-all" : " ^4.1.5"
30
+ },
31
+ "peerDependencies" : {
32
+ "ajv" : " ^6.10.2"
30
33
}
31
34
}
Original file line number Diff line number Diff line change 1
- import Ajv from 'ajv'
2
1
import osLocale from 'os-locale'
3
2
import semver from 'semver'
4
3
import schema from '../src/schema'
@@ -104,9 +103,19 @@ export function filter(data, options) {
104
103
105
104
let ajvValidate
106
105
107
- export function validate ( data ) {
106
+ export async function validate ( data ) {
108
107
if ( ! ajvValidate ) {
109
- ajvValidate = new Ajv ( ) . compile ( schema )
108
+ try {
109
+ const Ajv = await import ( 'ajv' ) . then ( m => m . default || m )
110
+ ajvValidate = new Ajv ( ) . compile ( schema )
111
+ } catch ( err ) {
112
+ if ( err . code === 'MODULE_NOT_FOUND' ) {
113
+ console . error ( 'ajv not found, please install the peer dependency' ) // eslint-disable-line no-console
114
+ return true
115
+ }
116
+
117
+ throw err
118
+ }
110
119
}
111
120
112
121
return ajvValidate ( data )
Original file line number Diff line number Diff line change @@ -44,8 +44,8 @@ describe('motd', () => {
44
44
jest . restoreAllMocks ( )
45
45
} )
46
46
47
- test ( 'schema' , ( ) => {
48
- expect ( motd . validate ( data ) ) . toBe ( true )
47
+ test ( 'schema' , async ( ) => {
48
+ await expect ( motd . validate ( data ) ) . resolves . toBe ( true )
49
49
} )
50
50
51
51
test ( 'getRegion only returns region part from locale' , ( ) => {
Original file line number Diff line number Diff line change @@ -54,8 +54,8 @@ const data = [
54
54
]
55
55
56
56
describe ( 'motd' , ( ) => {
57
- test ( 'schema' , ( ) => {
58
- expect ( motd . validate ( data ) ) . toBe ( true )
57
+ test ( 'schema' , async ( ) => {
58
+ await expect ( motd . validate ( data ) ) . resolves . toBe ( true )
59
59
} )
60
60
61
61
test ( 'filterTags doesnt filter without tags specified' , ( ) => {
You can’t perform that action at this time.
0 commit comments