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.

Overhaul JS Importer API

See original GitHub issue

The JavaScript importer API shared by Dart Sass and Node Sass needs an overhaul. The current API has a number of issues:

  • It doesn’t respect URL semantics. In particular, it doesn’t provide any guarantee that @import "./bar" within a stylesheet with URL foo means the same thing as @import "foo/bar", even when resolved by the same importer.

  • It doesn’t have a notion of resolving an imported URL to an absolute URL—for example, an npm-aware importer might resolve ~foo to file:///home/nex3/app/node_modules/foo/_index.scss. This makes canonicalization of imported stylesheets impossible, and means that importers are fundamentally less expressive than built-in filesystem imports. It also means that the URLs reported in source maps and other APIs are unlikely to be resolvable.

  • It doesn’t support the indented syntax.

  • Its notion of “redirecting” to a file import has some strange corner cases—for example, a relative path redirect can be resolved relative to the file that contains the import, relative to the working directory, or relative to an import path.

  • It doesn’t seem to do much error checking for invalid responses.

  • It uses the string "stdin" to refer to files passed by data, even when they don’t come from standard input. This could potentially conflict with a real file named "stdin".

  • The this context includes a bunch of undocumented information without a clear use-case.

We should design a new API that addresses these issues and makes it easy to write importers that work similarly to native filesystem imports. I strongly favor writing the API in such a way that filesystem imports themselves can be modeled as an importer.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nex3commented, Dec 1, 2021

This is now usable in Dart Sass 1.45.0-rc.1! We’d love people’s feedback on it before we launch a full stable release some time next week.

1reaction
nex3commented, Sep 7, 2021

It’s been a month and there have been no objections, so I’m going to mark the proposal as accepted and start merging it into the main spec directory.

Read more comments on GitHub >

github_iconTop Results From Across the Web

import - JavaScript - MDN Web Docs - Mozilla
The static import declaration is used to import read-only live bindings which are exported by another module. The imported bindings are ...
Read more >
API - esbuild
API. The API can be accessed in one of three ways: on the command line, in JavaScript, and in Go. The concepts and...
Read more >
Import and Export in Node.js - GeeksforGeeks
Importing a Module: We need to import the module to use the functions defined in the imported module in another file. The result...
Read more >
Documentation - Modules - TypeScript
Modules import one another using a module loader. At runtime the module loader is responsible for locating and executing all dependencies of a...
Read more >
electron/rebuild: Package to rebuild native Node.js ... - GitHub
import packager from 'electron-packager'; import rebuild from '@electron/rebuild'; packager({ // … other options afterCopy: [(buildPath, electronVersion, ...
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