Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SassMQ import path #637

Closed
wants to merge 1 commit into from
Closed

Update SassMQ import path #637

wants to merge 1 commit into from

Conversation

kr8n3r
Copy link

@kr8n3r kr8n3r commented Apr 9, 2018

In certain use cases as outlined in #636 the way we were importing SassMQ wasn't resolving correctly.
This change should fix that.

  • Updated path in src/globals/helpers/_media-queries.scss
  • includePaths: 'node_modules' added to gulp compilation task
  • includePaths: 'node_modules' added to node-sass configuration in tests
  • Changelog updated

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-637 April 9, 2018 15:39 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-637 April 9, 2018 15:41 Inactive
@kr8n3r kr8n3r changed the title Fix sass mq import path Update SassMQ import path Apr 10, 2018
@NickColley
Copy link
Contributor

NickColley commented Apr 10, 2018

Does this require any documentation updates, or is this a transparent change for users?

Is there anyway we can have a failing test for this?

@@ -11,6 +11,6 @@ $sass-mq-already-included: false !default;
$mq-show-breakpoints: ();
}

@import "./node_modules/sass-mq/mq";
@import "sass-mq/mq";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the webpack sass-loader way of doing this would be "~sass-mq/mq" https://github.com/webpack-contrib/sass-loader#imports

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason not to use the ~ syntax here? I think the current implementation would mean that the parent project would need to manually ensure sass-mq was on the resolution path for sass files, wheras ~ should always work as long as the parent project used sass loader.

Or are you saying that compatibility with Sass build systems that don't support ~ is more important than manual setup?

Would be good to see how existing Sass libraries distributed via npm that have Sass sub-dependencies handle this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what the support is for that syntax? We can make very few assumptions about the technologies involved our consumer's build pipelines, so unless that syntax is very well supported I would be wary of relying on it.

Copy link

@penx penx Apr 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem (as described at https://github.com/webpack-contrib/sass-loader#imports) is Sass doesn't have a default syntax for library imports.

The 3 options are:

  1. ~
  2. node_modules or ./node_modules
  3. mixing relative + lib paths (@import "sass-mq/mq";)

I think all 3 infer either an assumption or requirement from the parent project.

I'll take a look around and see if I can find examples in other Sass projects dealing with this.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related, but not found an answer yet:

sass/node-sass#1596
webpack-contrib/sass-loader#466

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~ is webpack specific, node-sass doesnt supoort that

Copy link

@penx penx Apr 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a couple comments on sass/node-sass#1596 and also found and commented on sass/sass#2350

Is it ok to assume the parent project will use node-sass (given that it's distributed via npm)?

Looks like eyeglass may be the recommended solution if so.

@NickColley
Copy link
Contributor

NickColley commented Apr 10, 2018

Added an example based on the reproduction @penx gave us. I'm not sure this PR is enough to fix it...

Edit: Branch I'm talking about: https://github.com/alphagov/govuk-frontend/tree/fix-sass-mq-import-example-tests/examples/using-yarn-workspaces

@kr8n3r
Copy link
Author

kr8n3r commented Apr 11, 2018

Does this require any documentation updates, or is this a transparent change for users?

with this option: no change
but if they use this option @import "node_modules/@govuk-frontend/all/all";
then it possibly won't work

Is there anyway we can have a failing test for this?
compile-individual-components test fails if you just change
@import "./node_modules/sass-mq/mq"; to @import "sass-mq/mq"; without adding node_modules to its config

@36degrees
Copy link
Contributor

36degrees commented Apr 11, 2018

In #615 we made adding node_modules being in the consumers' Sass paths optional in the documentation, by making the 'default' import relative to the project root. Unless I'm misunderstanding, this looks like it would rely on consumers having node_modules back in their Sass path definition again.

If this is the only way to do it that shouldn't be a blocker, but we'll need to make sure we update the documentation appropriately.

@kr8n3r
Copy link
Author

kr8n3r commented Apr 11, 2018

yeah if they choose the option without needing to specify the path definition then it feels wrong in having to ask them to do it regardless for this to resolve.

  • we can revert back to @import "./node_modules/sass-mq/mq"; but wrap it in a variable so it can be modified for cases mentioned in the issues. Then there is no change for most users

Radical
Add Eyeglass to here as devDependency

More radical
go back to our own breakpoint mixins

@kr8n3r
Copy link
Author

kr8n3r commented Apr 16, 2018

won't fix, closing in favour of #657

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants