Install compiler executable using optional dependencies rather than postinstall
See original GitHub issueCurrently, sass-embedded depends on a post-install script to download the native binary. In some cases corp environments package managers are run with ignore-script
. This causes the binary not be download.
I propose that this download happens on first run instead of the mentioned hook.
Example of the code needed https://github.com/sass/embedded-host-node/blob/main/lib/src/compiler-path.ts
// Copyright 2021 Google LLC. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import * as fs from 'fs';
import * as p from 'path';
import { spawnSync } from 'child_process';
/** The path to the embedded compiler executable. */
export const compilerPath = (() => {
let sassCompilerPath = findCompilerPath();
if (sassCompilerPath) return sassCompilerPath;
// Try to download native compiler.
spawnSync(process.execPath, [p.resolve(__dirname, '../../../download-compiler-for-end-user.js')]);
sassCompilerPath = findCompilerPath();
if (sassCompilerPath) return sassCompilerPath;
throw new Error(
"Embedded Dart Sass couldn't find the embedded compiler executable."
);
})();
/** Finds the path to the embedded compiler executable. Returns `null` when it's not found. */
function findCompilerPath(): string | null {
for (const path of ['vendor', '../../../lib/src/vendor']) {
const executable = p.resolve(
__dirname,
path,
`dart-sass-embedded/dart-sass-embedded${
process.platform === 'win32' ? '.bat' : ''
}`
);
if (fs.existsSync(executable)) return executable;
}
return null;
}
Other packages that depend on native componets such as esbuild, appear to be moving towards leveraging npm to pick the appropriate platform code via the os
and platform
package fields in the platform packages combined with optionalDependencies
. This has the advantage of leveraging npm’s registry as well as package verification and lock file based versioning.
Example: https://unpkg.com/browse/esbuild@0.14.39/package.json
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
I think they should be published from this repository.
dart-sass-embedded
is host-agnostic, so it doesn’t make sense for it to own the publishing of packages used by one particular host.This is definitely something that I am interesting in helping out with.
I did go briefly through the release script of this repo. I do have a question for now.
From where should the platform specific native binaries be published to NPM? should this be done from this or the repo they live in https://github.com/sass/dart-sass-embedded? I am thinking the latter but I wanted to confirm.