-
-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcea88e
commit fab50ab
Showing
15 changed files
with
91,580 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,33 @@ | ||
import semver from 'semver'; | ||
import async from 'neo-async'; | ||
|
||
let nodeSassJobQueue = null; | ||
|
||
/** | ||
* Verifies that the implementation and version of Sass is supported by this loader. | ||
* | ||
* @param {Object} module | ||
* @param {Object} implementation | ||
* @returns {Function} | ||
*/ | ||
function getRenderFunctionFromSassImplementation(module) { | ||
const { info } = module; | ||
function getRenderFunctionFromSassImplementation(implementation) { | ||
const isDartSass = implementation.info.includes('dart-sass'); | ||
|
||
if (!info) { | ||
throw new Error('Unknown Sass implementation.'); | ||
if (isDartSass) { | ||
return implementation.render.bind(implementation); | ||
} | ||
|
||
const components = info.split('\t'); | ||
// There is an issue with node-sass when async custom importers are used | ||
// See https://github.com/sass/node-sass/issues/857#issuecomment-93594360 | ||
// We need to use a job queue to make sure that one thread is always available to the UV lib | ||
if (nodeSassJobQueue === null) { | ||
const threadPoolSize = Number(process.env.UV_THREADPOOL_SIZE || 4); | ||
|
||
if (components.length < 2) { | ||
throw new Error(`Unknown Sass implementation "${info}".`); | ||
nodeSassJobQueue = async.queue( | ||
implementation.render.bind(implementation), | ||
threadPoolSize - 1 | ||
); | ||
} | ||
|
||
const [implementation, version] = components; | ||
|
||
if (!semver.valid(version)) { | ||
throw new Error(`Invalid Sass version "${version}".`); | ||
} | ||
|
||
if (implementation === 'dart-sass') { | ||
if (!semver.satisfies(version, '^1.3.0')) { | ||
throw new Error( | ||
`Dart Sass version ${version} is incompatible with ^1.3.0.` | ||
); | ||
} | ||
|
||
return module.render.bind(module); | ||
} else if (implementation === 'node-sass') { | ||
if (!semver.satisfies(version, '^4.0.0')) { | ||
throw new Error( | ||
`Node Sass version ${version} is incompatible with ^4.0.0.` | ||
); | ||
} | ||
|
||
// There is an issue with node-sass when async custom importers are used | ||
// See https://github.com/sass/node-sass/issues/857#issuecomment-93594360 | ||
// We need to use a job queue to make sure that one thread is always available to the UV lib | ||
if (nodeSassJobQueue === null) { | ||
const threadPoolSize = Number(process.env.UV_THREADPOOL_SIZE || 4); | ||
|
||
nodeSassJobQueue = async.queue( | ||
module.render.bind(module), | ||
threadPoolSize - 1 | ||
); | ||
} | ||
|
||
return nodeSassJobQueue.push.bind(nodeSassJobQueue); | ||
} | ||
|
||
throw new Error(`Unknown Sass implementation "${implementation}".`); | ||
return nodeSassJobQueue.push.bind(nodeSassJobQueue); | ||
} | ||
|
||
export default getRenderFunctionFromSassImplementation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import semver from 'semver'; | ||
|
||
import getDefaultSassImplementation from './getDefaultSassImplementation'; | ||
|
||
function getSassImplementation(implementation) { | ||
let resolvedImplementation = implementation; | ||
|
||
if (!resolvedImplementation) { | ||
// eslint-disable-next-line no-param-reassign | ||
resolvedImplementation = getDefaultSassImplementation(); | ||
} | ||
|
||
const { info } = resolvedImplementation; | ||
|
||
if (!info) { | ||
throw new Error('Unknown Sass implementation.'); | ||
} | ||
|
||
const infoParts = info.split('\t'); | ||
|
||
if (infoParts.length < 2) { | ||
throw new Error(`Unknown Sass implementation "${info}".`); | ||
} | ||
|
||
const [implementationName, version] = infoParts; | ||
|
||
if (implementationName === 'dart-sass') { | ||
if (!semver.satisfies(version, '^1.3.0')) { | ||
throw new Error( | ||
`Dart Sass version ${version} is incompatible with ^1.3.0.` | ||
); | ||
} | ||
|
||
return resolvedImplementation; | ||
} else if (implementationName === 'node-sass') { | ||
if (!semver.satisfies(version, '^4.0.0')) { | ||
throw new Error( | ||
`Node Sass version ${version} is incompatible with ^4.0.0.` | ||
); | ||
} | ||
|
||
return resolvedImplementation; | ||
} | ||
|
||
throw new Error(`Unknown Sass implementation "${implementationName}".`); | ||
} | ||
|
||
export default getSassImplementation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.