File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ const validator = require('./lib/config/validator');
15
15
const PrettyError = require ( 'pretty-error' ) ;
16
16
const logger = require ( './lib/logger' ) ;
17
17
const parseRuntime = require ( './lib/config/parse-runtime' ) ;
18
+ const chalk = require ( 'chalk' ) ;
19
+ const levenshtein = require ( 'fast-levenshtein' ) ;
18
20
19
21
let webpackConfig = null ;
20
22
let runtimeConfig = require ( './lib/context' ) . runtimeConfig ;
@@ -631,6 +633,21 @@ const publicApiProxy = new Proxy(publicApi, {
631
633
process . exit ( 1 ) ; // eslint-disable-line
632
634
}
633
635
} ;
636
+ } else if ( typeof target [ prop ] === 'undefined' ) {
637
+ // Find the property with the closest Levenshtein distance
638
+ let similarProperty ;
639
+ let minDistance = Number . MAX_VALUE ;
640
+ for ( const apiProperty in target ) {
641
+ const distance = levenshtein . get ( apiProperty , prop ) ;
642
+ if ( distance <= minDistance ) {
643
+ similarProperty = apiProperty ;
644
+ minDistance = distance ;
645
+ }
646
+ }
647
+
648
+ const error = new Error ( `${ chalk . red ( `Encore.${ prop } ` ) } is not a recognized property, did you mean ${ chalk . green ( `Encore.${ similarProperty } ` ) } ?` ) ;
649
+ console . log ( new PrettyError ( ) . render ( error ) ) ;
650
+ process . exit ( 1 ) ; // eslint-disable-line
634
651
}
635
652
636
653
return target [ prop ] ;
Original file line number Diff line number Diff line change 33
33
"clean-webpack-plugin" : " ^0.1.16" ,
34
34
"css-loader" : " ^0.26.2" ,
35
35
"extract-text-webpack-plugin" : " ^3.0.0" ,
36
+ "fast-levenshtein" : " ^2.0.6" ,
36
37
"file-loader" : " ^0.10.1" ,
37
38
"friendly-errors-webpack-plugin" : " ^1.6.1" ,
38
39
"fs-extra" : " ^2.0.0" ,
Original file line number Diff line number Diff line change @@ -2156,7 +2156,7 @@ fast-deep-equal@^1.0.0:
2156
2156
version "1.0.0"
2157
2157
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz#96256a3bc975595eb36d82e9929d060d893439ff"
2158
2158
2159
- fast-levenshtein@~2.0.4 :
2159
+ fast-levenshtein@^2.0.6, fast-levenshtein@ ~2.0.4 :
2160
2160
version "2.0.6"
2161
2161
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
2162
2162
You can’t perform that action at this time.
0 commit comments