File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ import {
45
45
emptyCssComments ,
46
46
generateCodeFrame ,
47
47
getHash ,
48
+ getPackageManagerCommand ,
48
49
isDataUrl ,
49
50
isExternalUrl ,
50
51
isObject ,
@@ -1694,8 +1695,9 @@ function loadPreprocessor(
1694
1695
return ( loadedPreprocessors [ lang ] = _require ( resolved ) )
1695
1696
} catch ( e ) {
1696
1697
if ( e . code === 'MODULE_NOT_FOUND' ) {
1698
+ const installCommand = getPackageManagerCommand ( 'install' )
1697
1699
throw new Error (
1698
- `Preprocessor dependency "${ lang } " not found. Did you install it?` ,
1700
+ `Preprocessor dependency "${ lang } " not found. Did you install it? Try \` ${ installCommand } -D ${ lang } \`. ` ,
1699
1701
)
1700
1702
} else {
1701
1703
const message = new Error (
Original file line number Diff line number Diff line change @@ -1257,3 +1257,25 @@ const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g
1257
1257
export function escapeRegex ( str : string ) : string {
1258
1258
return str . replace ( escapeRegexRE , '\\$&' )
1259
1259
}
1260
+
1261
+ type CommandType = 'install' | 'uninstall' | 'update'
1262
+ export function getPackageManagerCommand (
1263
+ type : CommandType = 'install' ,
1264
+ ) : string {
1265
+ const packageManager =
1266
+ process . env . npm_config_user_agent ?. split ( ' ' ) [ 0 ] . split ( '/' ) [ 0 ] || 'npm'
1267
+ switch ( type ) {
1268
+ case 'install' :
1269
+ return packageManager === 'npm' ? 'npm install' : `${ packageManager } add`
1270
+ case 'uninstall' :
1271
+ return packageManager === 'npm'
1272
+ ? 'npm uninstall'
1273
+ : `${ packageManager } remove`
1274
+ case 'update' :
1275
+ return packageManager === 'yarn'
1276
+ ? 'yarn upgrade'
1277
+ : `${ packageManager } update`
1278
+ default :
1279
+ throw new TypeError ( `Unknown command type: ${ type } ` )
1280
+ }
1281
+ }
You can’t perform that action at this time.
0 commit comments