Skip to content

Commit 0093f68

Browse files
authored
Add a Sass executable wrapper that forwards to the correct exe (#313)
This allows users to run `npx sass` when they've just installed `sass-embedded` and directly run the Dart VM. Due to npm/cmd-shim#152, there's no way to make this work on Windows CMD/Powershell without substantially curtailing the performance on other operating systems.
1 parent 53abf98 commit 0093f68

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

bin/sass.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env node
2+
3+
import * as child_process from 'child_process';
4+
import {compilerCommand} from '../lib/src/compiler-path';
5+
6+
// TODO npm/cmd-shim#152 and yarnpkg/berry#6422 - If and when the package
7+
// managers support it, we should make this a proper shell script rather than a
8+
// JS wrapper.
9+
10+
try {
11+
child_process.execFileSync(
12+
compilerCommand[0],
13+
[...compilerCommand.slice(1), ...process.argv.slice(2)],
14+
{
15+
stdio: 'inherit',
16+
windowsHide: true,
17+
}
18+
);
19+
} catch (error) {
20+
if (error.code) {
21+
throw error;
22+
} else {
23+
process.exitCode = error.status;
24+
}
25+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"engines": {
2424
"node": ">=16.0.0"
2525
},
26+
"bin": {"sass": "dist/bin/sass.js"},
2627
"scripts": {
2728
"init": "ts-node ./tool/init.ts",
2829
"check": "npm-run-all check:gts check:tsc",

tsconfig.build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "./tsconfig.json",
33
"exclude": [
4+
"jest.config.js",
45
"lib/src/vendor/dart-sass/**",
56
"**/*.test.ts"
67
]

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"include": [
1313
"*.ts",
14+
"bin/*.ts",
1415
"lib/**/*.ts",
1516
"tool/**/*.ts",
1617
"test/**/*.ts"

0 commit comments

Comments
 (0)