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

fix: allow passing an array as sass / scss importer #3529

Merged
merged 2 commits into from May 25, 2021
Merged

Conversation

j000
Copy link
Contributor

@j000 j000 commented May 24, 2021

Description

This change allows passing an array with multiple custom importers. Fixes #3526.

Additional context

JavaScript does not mind passing undefined to concat, so additional checks are not needed. In that case shallow copy is created, but it does not matter here.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

This change allows passing an array with multiple custom importers.

JavaScript does not mind passing `undefined` to concat, so additional checks are not needed. In that case shallow copy is created, but it does not matter here.

Closes vitejs#3526.
@Shinigami92 Shinigami92 added p3-minor-bug An edge case that only affects very specific usage (priority) feat: css labels May 24, 2021
? importer.concat(options.importer)
: importer.push(options.importer)
}
const importer = [internalImporter].concat(options.importer!)
Copy link
Member

Choose a reason for hiding this comment

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

If options.importer would be undefined here, this would add an undefined value to the array 🤔
Do we really want this non-null assertion here?


Beside that, does this really fix the issue? And if so: why?

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking on something like this to fix the issue:

  const importer = [internalImporter]
  if (options.importer) {
    if( Array.isArray(options.importer) ) {
      importer.push(...options.importer)
    }
    else {
      importer.push(options.importer)
    }
  }

This could be written in a more compact form but I don't think we will gain in readability.

Copy link
Member

Choose a reason for hiding this comment

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

@patak-js So your solution is exactly the same as before but using push instead of concat?

? importer.concat(options.importer)
: importer.push(options.importer)
}
const importer = [internalImporter].concat(options.importer!)
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking on something like this to fix the issue:

  const importer = [internalImporter]
  if (options.importer) {
    if( Array.isArray(options.importer) ) {
      importer.push(...options.importer)
    }
    else {
      importer.push(options.importer)
    }
  }

This could be written in a more compact form but I don't think we will gain in readability.

@j000
Copy link
Contributor Author

j000 commented May 24, 2021

Well, you're right :) Anyway, here is another attempt.

@antfu antfu merged commit e344cdd into vitejs:main May 25, 2021
ygj6 pushed a commit to ygj6/vite that referenced this pull request Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: css p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Passing an array as sass / scss importer does not work properly.
4 participants