-
-
Notifications
You must be signed in to change notification settings - Fork 431
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
716de3c
commit 33a23f8
Showing
11 changed files
with
196 additions
and
258 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,30 @@ | ||
class SassError extends Error { | ||
constructor(sassError, resourcePath) { | ||
super(); | ||
|
||
this.name = 'SassError'; | ||
this.originalSassError = sassError; | ||
this.loc = { | ||
line: sassError.line, | ||
column: sassError.column, | ||
}; | ||
|
||
// Keep original error if `sassError.formatted` is unavailable | ||
this.message = `${this.name}: ${this.originalSassError.message}`; | ||
|
||
if (this.originalSassError.formatted) { | ||
this.message = `${this.name}: ${this.originalSassError.formatted | ||
.replace(/^Error: /, '') | ||
.replace(/(\s*)stdin(\s*)/, `$1${resourcePath}$2`)}`; | ||
|
||
// Instruct webpack to hide the JS stack from the console. | ||
// Usually you're only interested in the SASS stack in this case. | ||
// eslint-disable-next-line no-param-reassign | ||
this.hideStack = true; | ||
|
||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
} | ||
} | ||
|
||
export default SassError; |
This file was deleted.
Oops, something went wrong.
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,19 @@ | ||
function getDefaultSassImplementation() { | ||
let sassImplPkg = 'node-sass'; | ||
|
||
try { | ||
require.resolve('node-sass'); | ||
} catch (error) { | ||
try { | ||
require.resolve('sass'); | ||
sassImplPkg = 'sass'; | ||
} catch (ignoreError) { | ||
sassImplPkg = 'node-sass'; | ||
} | ||
} | ||
|
||
// eslint-disable-next-line import/no-dynamic-require, global-require | ||
return require(sassImplPkg); | ||
} | ||
|
||
export default getDefaultSassImplementation; |
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,64 @@ | ||
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 | ||
* @returns {Function} | ||
*/ | ||
function getRenderFunctionFromSassImplementation(module) { | ||
const { info } = module; | ||
|
||
if (!info) { | ||
throw new Error('Unknown Sass implementation.'); | ||
} | ||
|
||
const components = info.split('\t'); | ||
|
||
if (components.length < 2) { | ||
throw new Error(`Unknown Sass implementation "${info}".`); | ||
} | ||
|
||
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}".`); | ||
} | ||
|
||
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
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
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.