2
2
// MIT-style license that can be found in the LICENSE file or at
3
3
// https://opensource.org/licenses/MIT.
4
4
5
- import * as fs from 'fs' ;
6
5
import * as p from 'path' ;
7
6
import { getElfInterpreter } from './elf' ;
8
- import { isErrnoException } from './utils' ;
9
7
10
8
/**
11
9
* Detect if the given binary is linked with musl libc by checking if
@@ -23,51 +21,43 @@ function isLinuxMusl(path: string): boolean {
23
21
}
24
22
}
25
23
26
- /** The full command for the embedded compiler executable. */
27
- export const compilerCommand = ( ( ) => {
24
+ /** The module name for the embedded compiler executable. */
25
+ export const compilerModule = ( ( ) => {
28
26
const platform =
29
27
process . platform === 'linux' && isLinuxMusl ( process . execPath )
30
28
? 'linux-musl'
31
29
: ( process . platform as string ) ;
32
30
33
31
const arch = process . arch ;
34
32
35
- // find for development
36
- for ( const path of [ 'vendor' , '../../../lib/src/vendor' ] ) {
37
- const executable = p . resolve (
38
- __dirname ,
39
- path ,
40
- `dart-sass/sass${ platform === 'win32' ? '.bat' : '' } `
41
- ) ;
42
-
43
- if ( fs . existsSync ( executable ) ) return [ executable ] ;
44
- }
33
+ return `sass-embedded-${ platform } -${ arch } ` ;
34
+ } ) ( ) ;
45
35
36
+ /** The full command for the embedded compiler executable. */
37
+ export const compilerCommand = ( ( ) => {
46
38
try {
47
39
return [
48
40
require . resolve (
49
- `sass-embedded-${ platform } -${ arch } /dart-sass/src/dart` +
50
- ( platform === 'win32' ? '.exe' : '' )
51
- ) ,
52
- require . resolve (
53
- `sass-embedded-${ platform } -${ arch } /dart-sass/src/sass.snapshot`
41
+ `${ compilerModule } /dart-sass/src/dart` +
42
+ ( process . platform === 'win32' ? '.exe' : '' )
54
43
) ,
44
+ require . resolve ( `${ compilerModule } /dart-sass/src/sass.snapshot` ) ,
55
45
] ;
56
46
} catch ( e ) {
57
- if ( ! ( isErrnoException ( e ) && e . code === 'MODULE_NOT_FOUND' ) ) {
47
+ if ( e . code !== 'MODULE_NOT_FOUND' ) {
58
48
throw e ;
59
49
}
60
50
}
61
51
62
52
try {
63
53
return [
64
54
require . resolve (
65
- `sass-embedded- ${ platform } - ${ arch } /dart-sass/sass` +
66
- ( platform === 'win32' ? '.bat' : '' )
55
+ `${ compilerModule } /dart-sass/sass` +
56
+ ( process . platform === 'win32' ? '.bat' : '' )
67
57
) ,
68
58
] ;
69
- } catch ( e : unknown ) {
70
- if ( ! ( isErrnoException ( e ) && e . code === 'MODULE_NOT_FOUND' ) ) {
59
+ } catch ( e ) {
60
+ if ( e . code !== 'MODULE_NOT_FOUND' ) {
71
61
throw e ;
72
62
}
73
63
}
@@ -77,16 +67,15 @@ export const compilerCommand = (() => {
77
67
process . execPath ,
78
68
p . join ( p . dirname ( require . resolve ( 'sass' ) ) , 'sass.js' ) ,
79
69
] ;
80
- } catch ( e : unknown ) {
81
- if ( ! ( isErrnoException ( e ) && e . code === 'MODULE_NOT_FOUND' ) ) {
70
+ } catch ( e ) {
71
+ if ( e . code !== 'MODULE_NOT_FOUND' ) {
82
72
throw e ;
83
73
}
84
74
}
85
75
86
76
throw new Error (
87
77
"Embedded Dart Sass couldn't find the embedded compiler executable. " +
88
- 'Please make sure the optional dependency ' +
89
- `sass-embedded-${ platform } -${ arch } or sass is installed in ` +
90
- 'node_modules.'
78
+ `Please make sure the optional dependency ${ compilerModule } or sass is ` +
79
+ 'installed in node_modules.'
91
80
) ;
92
81
} ) ( ) ;
0 commit comments