question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Install compiler executable using optional dependencies rather than postinstall

See original GitHub issue

Currently, 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:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nex3commented, Jun 13, 2022

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.

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.

0reactions
alan-agius4commented, Jun 10, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Different strategy for installing platform-specific binaries #789
Hi! We're looking to integrate esbuild with the Netlify CLI and some users are reporting permission-related errors when installing the ...
Read more >
NPM node-sass installation fails - Stack Overflow
I am trying to install node-sass in ...
Read more >
scripts - npm Docs
Scripts from dependencies can be run with npm explore <pkg> -- npm run <stage> . ... npm will default the install command to...
Read more >
Getting Started - ESBuild
#Install esbuild. First, download and install the esbuild command locally. A prebuilt native executable can be installed using npm (which is automatically ...
Read more >
PKGBUILD - ArchWiki
Packages in Arch Linux are built using the makepkg utility. ... alternative dependencies, all of them can be listed here, instead of the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found