@@ -6,14 +6,35 @@ import * as fs from 'fs';
66import * as p from 'path' ;
77import { isErrnoException } from './utils' ;
88
9+ /**
10+ * Detect if the current running node binary is linked with musl libc by
11+ * checking if the binary contains a string like "/.../ld-musl-$ARCH.so"
12+ */
13+ const isLinuxMusl = function ( ) {
14+ return fs . readFileSync ( process . execPath ) . includes ( '/ld-musl-' ) ;
15+ } ;
16+
917/** The full command for the embedded compiler executable. */
1018export const compilerCommand = ( ( ) => {
19+ const platform =
20+ process . platform === 'linux' && isLinuxMusl ( )
21+ ? 'linux-musl'
22+ : ( process . platform as string ) ;
23+
24+ // https://github.com/sass/embedded-host-node/issues/263
25+ // Use windows-x64 emulation on windows-arm64
26+ //
27+ // TODO: Make sure to remove "arm64" from "npm/win32-x64/package.json" when
28+ // this logic is removed once we have true windows-arm64 support.
29+ const arch =
30+ platform === 'win32' && process . arch === 'arm64' ? 'x86' : process . arch ;
31+
1132 // find for development
1233 for ( const path of [ 'vendor' , '../../../lib/src/vendor' ] ) {
1334 const executable = p . resolve (
1435 __dirname ,
1536 path ,
16- `dart-sass/sass${ process . platform === 'win32' ? '.bat' : '' } `
37+ `dart-sass/sass${ platform === 'win32' ? '.bat' : '' } `
1738 ) ;
1839
1940 if ( fs . existsSync ( executable ) ) return [ executable ] ;
@@ -22,13 +43,11 @@ export const compilerCommand = (() => {
2243 try {
2344 return [
2445 require . resolve (
25- `sass-embedded-${ process . platform } -${ process . arch } /` +
26- 'dart-sass/src/dart' +
27- ( process . platform === 'win32' ? '.exe' : '' )
46+ `sass-embedded-${ platform } -${ arch } /dart-sass/src/dart` +
47+ ( platform === 'win32' ? '.exe' : '' )
2848 ) ,
2949 require . resolve (
30- `sass-embedded-${ process . platform } -${ process . arch } /` +
31- 'dart-sass/src/sass.snapshot'
50+ `sass-embedded-${ platform } -${ arch } /dart-sass/src/sass.snapshot`
3251 ) ,
3352 ] ;
3453 } catch ( ignored ) {
@@ -38,9 +57,8 @@ export const compilerCommand = (() => {
3857 try {
3958 return [
4059 require . resolve (
41- `sass-embedded-${ process . platform } -${ process . arch } /` +
42- 'dart-sass/sass' +
43- ( process . platform === 'win32' ? '.bat' : '' )
60+ `sass-embedded-${ platform } -${ arch } /dart-sass/sass` +
61+ ( platform === 'win32' ? '.bat' : '' )
4462 ) ,
4563 ] ;
4664 } catch ( e : unknown ) {
@@ -52,7 +70,7 @@ export const compilerCommand = (() => {
5270 throw new Error (
5371 "Embedded Dart Sass couldn't find the embedded compiler executable. " +
5472 'Please make sure the optional dependency ' +
55- `sass-embedded-${ process . platform } -${ process . arch } is installed in ` +
73+ `sass-embedded-${ platform } -${ arch } is installed in ` +
5674 'node_modules.'
5775 ) ;
5876} ) ( ) ;
0 commit comments