sass / dart-sass-embedded

A wrapper for Dart Sass that implements the compiler side of the Embedded Sass protocol

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Imports shall not be resolved relative to working directory of dart-sass-embedded process

ntkme opened this issue · comments

compileString should not resolve imports relative to working directory of compiler process.

This issue can be reproduced with both node host and ruby host.

Correct behavior of throwing [Error]: Can't find stylesheet to import on sass:

const fs = require('fs')
const sass = require('sass')
fs.writeFileSync('child.scss', 'a{b:c}');
console.log(sass.compileString('@import "child.scss";').css)

Reproduction with node host:

const fs = require('fs')
const sass = require('sass-embedded')
fs.writeFileSync('child.scss', 'a{b:c}');
console.log(sass.compileString('@import "child.scss";').css)

Reproduction with ruby host (fixed in 1.3.0, need version before <1.3 to reproduce):

require 'sass-embedded'
File.write('child.scss', 'a{b:c}')
puts Sass.compile_string('@import "child.scss";').css

Since ruby host has the capability of launching embedded compiler process and keep re-using it, here is another experiment involving changing working directory on host after embedded compiler has been launched:

require 'sass-embedded'
File.write('child.scss', 'a{b:c}')
Sass.info # launch dart-sass-embedded in the same working directory as host
Dir.chdir '/tmp' do # change working directory of host
  # import can still be resolved relative to compiler's working directory
  puts Sass.compile_string('@import "child.scss";').css
end

Dart API's importer defaults to FilesystemImporter('.'):

https://github.com/sass/dart-sass/blob/ba38c09c6869c1c7da19f05298a270da29d93e73/lib/src/async_compile.dart#L111

Node JS API (sass) override the default to a NoOpImporter():

https://github.com/sass/dart-sass/blob/33f18c4b54b7dfe5b5c7a9e41de392fba8f4ba15/lib/src/node/compile.dart#L77-L78

Embedded Compiler have the same default as Dart API, so that it ends up with completely different behavior than JS API.