Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

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

Closed
ntkme opened this issue Apr 3, 2022 · 1 comment · Fixed by #83
Closed
Assignees

Comments

@ntkme
Copy link
Contributor

ntkme commented Apr 3, 2022

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
@ntkme
Copy link
Contributor Author

ntkme commented Apr 3, 2022

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants