Giter Club home page Giter Club logo

Comments (21)

samusgray avatar samusgray commented on August 16, 2024

Thanks for looping me in. I agree that the current format will be confusing to most.

How about something that looks more like Ruby / ES6 string interpolation?

@import "#{my_file_name}/file";

or

@import "${my_file_name}/file";

The dollar sign is my preference between the two since we are dealing with Node modules and that's the ES6 way.

from eyeglass.

chriseppstein avatar chriseppstein commented on August 16, 2024

I'm hesitant to do that because it's standard sass syntax for escaping to sassscript and users will think they can use variables in there, etc.

An idea I had was @import "~foo/bar.png"; which is borrowing from the unix "home directory" syntax, which may also be a bad idea.

from eyeglass.

samusgray avatar samusgray commented on August 16, 2024

I'm not a fan of using ~ here because it's not clear where the module name and path begin.

It seems like there are three approaches to this:

  1. Wrap the module name in two identifiers (ie < & >)
  2. Begin the string with a non-standard path character
  3. Split the string on a non-standard path character

My preference is 1 or 3. Am I missing any alternatives?

Also, I updated my comment above to include ES6 example. Does changing that example to use $ instead of # mitigate your concerns about the sassscript association? Would something else entirely work better (~{file_name})?

Here are a couple other ideas that use the 3rd approach:

@import "susy:susyone";
@import "susy@susyone";

We could split the string on either of these characters to determine the module name and path as needed.

from eyeglass.

mirisuzanne avatar mirisuzanne commented on August 16, 2024

Another, more verbose option would be a function syntax: plugin(foo). Not sure that's the right association either β€”Β it actually makes me just want the ability to interpolate import strings. :)

from eyeglass.

mirisuzanne avatar mirisuzanne commented on August 16, 2024

@aaronagray What would the base import of susy be in your proposal? If you are not grabbing a nested partial, you lose the delimiter: @import 'susy'; unless we require a full @import 'susy:susy';. (I like @ less than : because I can't tell which side is the plugin, and which side is the path).

from eyeglass.

samusgray avatar samusgray commented on August 16, 2024

That's a great point, @ericam.

My understanding is that we need to A) identify the node_module folder name, B) determine which file to expose from there, and C) use something that sasscript won't try to import on its own. Are these accurate constraints @chriseppstein? If so, maybe option 3 (described above) won't work. In which case, I'd like to hear thoughts on using the ES6 format.

from eyeglass.

eoneill avatar eoneill commented on August 16, 2024

I would like to avoid anything that feels interpolated (e.g. #{...} or ${...}). If they feel like interpolation, I expect interpolation to work (e.g. @import "my/${dynamic}/file").

Instead, I'll propose that we follow a pattern similar to C/ObjectiveC for distinguishing between global vs local includes...

#include "example.h"
#include <example.h>

These will resolve to different files, where the former is a local include and the latter is a global include.

Granted, in our case, this isn't really global vs local, but we can easily take this to mean that one is from my code and the other is from external code.

So I propose that we do...

@import "foo"; // local `foo`
@import "<foo>"; // external `foo`
...
asset-url("<foo/bar.png>"); // external `foo/bar.png`

Note that this proposal wraps the entire path reference in <...>, not just the module name, but the module name will be assumed to be the first dirname.

C++ hasn't had any issues documenting the usage of angle bracket includes, so I think we'll be fine :)

from eyeglass.

samusgray avatar samusgray commented on August 16, 2024

@eoneill, I'm happy with that as long as we explicitely document the usage and include an example like the one you provided above. A lot of people don't read, apparently, so as long as we're explicit about including the brackets then we could be safe with most users.

from eyeglass.

chriseppstein avatar chriseppstein commented on August 16, 2024

Another approach: we could be more verbose. That is the CSS way, right?

@import "module foo";
@import "bar from module foo";
.foo{ background: asset-url("foo.png in module foo");

from eyeglass.

mirisuzanne avatar mirisuzanne commented on August 16, 2024

That's starting to look more like @nex3's proposal for advanced imports in Sass. That may be a good tie-in.

from eyeglass.

samusgray avatar samusgray commented on August 16, 2024

@chriseppstein I like this best so far.

from eyeglass.

eoneill avatar eoneill commented on August 16, 2024

I don't like that @chriseppstein :)

It feels like an awkward/broken ES6 import statement.

from eyeglass.

jakobo avatar jakobo commented on August 16, 2024

I'd like to keep it simple. Perhaps we even err further on the side of npm nomenclature.

  • starts with a ., it's a relative include
  • starts with /[a-z0-9]/i it's a node module include

At least then there's no learning curve for people already familiar with node.js and npm. We can also just refer to those docs on module / id resolution.

Resolution would be of "foo/bar" (when using eyeglass):

  1. attempt to look for node module foo with a bar import (node.js resolution)
  2. fall back to the default importer (sass) which would check for ./foo/(_)?bar{.css|.scss|/index.scss}

This means that when using eyeglass, you should really use relative paths explicitly for relative things.

from eyeglass.

mirisuzanne avatar mirisuzanne commented on August 16, 2024

I tend to prefer readable & explicit over short and clever when reasonable, so that's my vote. I also think we should be consistent with the direction of advanced sass imports (if those are still in the plans). I know it can feel bulky to advanced users, but that's what text-editor snippets are for. I don't want to make users look up the node docs to know what a sass import is doing.

from eyeglass.

jakobo avatar jakobo commented on August 16, 2024

It seems to have a lot to do with our perspective on eyeglass. From the Sass side, the more verbose approach makes sense. From the node side, staying as true as possible to the require() logic through either module resolution or some sort of </> demarcation makes sense.

Eyeglass has the enjoyable(?) position of sitting squarely between these two worlds. This is probably as much a philosophical discussion as a technical one.

from eyeglass.

scottdavis avatar scottdavis commented on August 16, 2024

Just spitballing but.

@import "lens foo"; //eyeclass modules are called "len's"
@import "bar from lens foo";

// or maybe supply it as a function to make it more declarative like susy 
lens('foo');
lens("bar from foo");
lens("bar as baz from foo");
lens-asset("bar.png from foo") 

I'm more for this verbose sentence style import syntax then I would be for the proposed @ or : Using those in import declarations just seems gross to me from a code readability standpoint and the sentence style is also more declarative.

from eyeglass.

jakobo avatar jakobo commented on August 16, 2024

#27
I'm just throwing some code up. This would remove the < and > entirely. It would also allow us to adopt the proposal for advanced imports that @ericam mentioned when Sass => libsass => node-sass adopt it.

At that point, the "eyeglass" importer's job is to automatically check your node modules on your behalf and not much more, falling back to a native Sass import if there is no node.js resolution.

from eyeglass.

chriseppstein avatar chriseppstein commented on August 16, 2024

Ok, after sleeping on this, I think @jakobo has the right of it. Even though we are using a custom importer, we should not need any special syntax, the importer simply acts as if we put the eyeglass modules on the load path. The first directory will be checked if it is an eyeglass module and if it is, we import as if it had been wrapped in angle brackets.

from eyeglass.

samusgray avatar samusgray commented on August 16, 2024

+1. That seems best. I like that we can document this in one place whereas something like angle brackets would require more explanation in more places.

from eyeglass.

Snugug avatar Snugug commented on August 16, 2024

πŸ‘ for @jakobo's proposal for npm style. It'll also make sure that things written in node-sass with Eyeglass have a chance of being compatible with Ruby Sass.

from eyeglass.

chriseppstein avatar chriseppstein commented on August 16, 2024

This landed on master.

from eyeglass.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.