From 0093f6858b6e8cea26148c795274331217c3ce96 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Thu, 1 Aug 2024 13:14:01 -0700 Subject: [PATCH] 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. --- bin/sass.ts | 25 +++++++++++++++++++++++++ package.json | 1 + tsconfig.build.json | 1 + tsconfig.json | 1 + 4 files changed, 28 insertions(+) create mode 100755 bin/sass.ts diff --git a/bin/sass.ts b/bin/sass.ts new file mode 100755 index 00000000..d25d834a --- /dev/null +++ b/bin/sass.ts @@ -0,0 +1,25 @@ +#!/usr/bin/env node + +import * as child_process from 'child_process'; +import {compilerCommand} from '../lib/src/compiler-path'; + +// TODO npm/cmd-shim#152 and yarnpkg/berry#6422 - If and when the package +// managers support it, we should make this a proper shell script rather than a +// JS wrapper. + +try { + child_process.execFileSync( + compilerCommand[0], + [...compilerCommand.slice(1), ...process.argv.slice(2)], + { + stdio: 'inherit', + windowsHide: true, + } + ); +} catch (error) { + if (error.code) { + throw error; + } else { + process.exitCode = error.status; + } +} diff --git a/package.json b/package.json index e9125b74..2983f245 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "engines": { "node": ">=16.0.0" }, + "bin": {"sass": "dist/bin/sass.js"}, "scripts": { "init": "ts-node ./tool/init.ts", "check": "npm-run-all check:gts check:tsc", diff --git a/tsconfig.build.json b/tsconfig.build.json index 0673a92b..5ca9532f 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,6 +1,7 @@ { "extends": "./tsconfig.json", "exclude": [ + "jest.config.js", "lib/src/vendor/dart-sass/**", "**/*.test.ts" ] diff --git a/tsconfig.json b/tsconfig.json index 35577090..d83f95cd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,7 @@ }, "include": [ "*.ts", + "bin/*.ts", "lib/**/*.ts", "tool/**/*.ts", "test/**/*.ts"