Skip to content

Commit b52c9b0

Browse files
ntkmenex3
andauthored
Support musl-libc and android (#265)
Co-authored-by: Natalie Weizenbaum <[email protected]>
1 parent 7c0f559 commit b52c9b0

File tree

21 files changed

+289
-15
lines changed

21 files changed

+289
-15
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ jobs:
157157
env:
158158
NODE_AUTH_TOKEN: '${{ secrets.NPM_TOKEN }}'
159159
run: |
160-
for pkg in linux-arm linux-arm64 linux-ia32 linux-x64 darwin-arm64 darwin-x64 win32-ia32 win32-x64; do
161-
npx ts-node ./tool/prepare-optional-release.ts --package=$pkg && npm publish ./npm/$pkg
162-
done
160+
find ./npm -mindepth 1 -maxdepth 1 -print0 | xargs -0 -n 1 -- sh -xc 'npx ts-node ./tool/prepare-optional-release.ts --package=$(basename $1) && npm publish $1' --
163161
164162
- run: npm publish
165163
env:

lib/src/compiler-path.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,35 @@ import * as fs from 'fs';
66
import * as p from 'path';
77
import {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. */
1018
export 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
})();

npm/android-arm/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `sass-embedded-android-arm`
2+
3+
This is the **android-arm** binary for [`sass-embedded`](https://www.npmjs.com/package/sass-embedded)

npm/android-arm/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "sass-embedded-android-arm",
3+
"version": "1.69.5",
4+
"description": "The android-arm binary for sass-embedded",
5+
"repository": "sass/embedded-host-node",
6+
"author": "Google Inc.",
7+
"license": "MIT",
8+
"files": [
9+
"dart-sass/**/*"
10+
],
11+
"engines": {
12+
"node": ">=14.0.0"
13+
},
14+
"bin": {
15+
"sass": "./dart-sass/sass"
16+
},
17+
"os": [
18+
"android"
19+
],
20+
"cpu": [
21+
"arm"
22+
]
23+
}

npm/android-arm64/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `sass-embedded-android-arm64`
2+
3+
This is the **android-arm64** binary for [`sass-embedded`](https://www.npmjs.com/package/sass-embedded)

npm/android-arm64/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "sass-embedded-android-arm64",
3+
"version": "1.69.5",
4+
"description": "The android-arm64 binary for sass-embedded",
5+
"repository": "sass/embedded-host-node",
6+
"author": "Google Inc.",
7+
"license": "MIT",
8+
"files": [
9+
"dart-sass/**/*"
10+
],
11+
"engines": {
12+
"node": ">=14.0.0"
13+
},
14+
"bin": {
15+
"sass": "./dart-sass/sass"
16+
},
17+
"os": [
18+
"android"
19+
],
20+
"cpu": [
21+
"arm64"
22+
]
23+
}

npm/android-ia32/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `sass-embedded-android-ia32`
2+
3+
This is the **android-ia32** binary for [`sass-embedded`](https://www.npmjs.com/package/sass-embedded)

npm/android-ia32/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "sass-embedded-android-ia32",
3+
"version": "1.69.5",
4+
"description": "The android-ia32 binary for sass-embedded",
5+
"repository": "sass/embedded-host-node",
6+
"author": "Google Inc.",
7+
"license": "MIT",
8+
"files": [
9+
"dart-sass/**/*"
10+
],
11+
"engines": {
12+
"node": ">=14.0.0"
13+
},
14+
"bin": {
15+
"sass": "./dart-sass/sass"
16+
},
17+
"os": [
18+
"android"
19+
],
20+
"cpu": [
21+
"ia32"
22+
]
23+
}

npm/android-x64/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `sass-embedded-android-x64`
2+
3+
This is the **android-x64** binary for [`sass-embedded`](https://www.npmjs.com/package/sass-embedded)

npm/android-x64/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "sass-embedded-android-x64",
3+
"version": "1.69.5",
4+
"description": "The android-x64 binary for sass-embedded",
5+
"repository": "sass/embedded-host-node",
6+
"author": "Google Inc.",
7+
"license": "MIT",
8+
"files": [
9+
"dart-sass/**/*"
10+
],
11+
"engines": {
12+
"node": ">=14.0.0"
13+
},
14+
"bin": {
15+
"sass": "./dart-sass/sass"
16+
},
17+
"os": [
18+
"android"
19+
],
20+
"cpu": [
21+
"x64"
22+
]
23+
}

0 commit comments

Comments
 (0)