-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(importer): passing a `this` context to sass-extract's own `importer()` call * feat(importer): allow importers to return an array of resolved files node-sass allows custom importers to resolve a given URL to multiple files paths, by returning an Array containing multiple objects: `[{file: '...'}, {file: '...'}, ...]`. This change implements this feature also for sass-extract's extracting phase. * refactor(importer): importer functions should always call a callback instead of returning a Promise. BREAKING CHANGE: Compatibility with node-sass: importers so far had to either call a callback (when they're called in the rendering phase, by `node-sass`) or return a Promise (when they're called in the extracting phase, by `makeImporter()`). From now, importers should always call the callback function provided in the third parameter of the importer function. fix #36 * fix(importer): should work also with single importer This has been removed by accident from the original code. * --temp: adding lib files to git (until it will be available in npm) * .gitignore cosm. * chore: NPM script to install peer dependencies for development * chore: Fixing tests - `foundation-sites` changed its folder structure, and also some internal Sass values, which breaks the tests. We rather stick to the exact version from `foundation-sites`. - `node-sass` throws Error for the nested `(1, 2, 3)` key. The problem should be with node-sass itself, as it works OK with `sass`. * feat: adding `getSassImplementation()` to resolve the correct Sass implementation + Dart Sass added to `peerDependencies` * chore(deps): updating all dependencies to their latest * test: add test for the upcoming `extractOptions.implementation` option We are iterating over each test with both the Node Sass and the Dart Sass implementations * feat: Removing inner `node-sass` imports, using the `extractOptions.implementation` option instead everywhere * fix(dart sass): Function signature in the `functions` options property must have attribute block if the function will accept parameters While Node Sass allowed the signature without the `($params)` block after the function name, Dart Sass is more strict on this, and throws Error if we try to call the function with parameters. * fix (dart-sass): constructor-based comparison causes error sometimes in Dart Sass - We had issues eg. in case of `SassBooleans`. - Dart Sass did not report the constructor name correctly before `1.22.5`. It instead reported a minified name, which we cannot rely on. We either need to increase the peerDependency version to `^1.22.5`, or use our `getConstructorName()`. * fix: Upgrading to `getFileId` to the new `Buffer()` API * we only promisify the render function and we only do it if renderAsync does not already exist, it is not necessarily the case for dart sass * dart sass seems to require a semicolon (or curly brackets) after mixin inclusions * dart sass does not call our importer for each file so instead, we patch fs.readFile and fs.readFileSync * dart sass seems to honor the order of @import directives unlike node sass * fix: fix extraction on windows dart sass extraction was not working on windows because paths of patched files included backslashes * chore: New build * refactor: Revert adding lib folder to git * refactor: Remove lib folder * chore: Minor code style changes --------- Co-authored-by: Pierre-Dominique CHARRON <[email protected]> Co-authored-by: Athorcis <[email protected]>
- Loading branch information
1 parent
618fd93
commit 90e4225
Showing
36 changed files
with
521 additions
and
263 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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules | ||
lib/ | ||
lib/ | ||
.idea | ||
package-lock.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { patchFs } from 'fs-monkey'; | ||
import fs from 'fs'; | ||
|
||
const originalReadFileSync = fs.readFileSync; | ||
const originalReadFile = fs.readFile; | ||
|
||
function getInjectedData(path, extractions, entryFilename) { | ||
path = fs.realpathSync(path); | ||
|
||
if (process.platform === 'win32') { | ||
path = path.replace(/\\/g, '/'); | ||
} | ||
|
||
if (path in extractions && path !== entryFilename) { | ||
return extractions[path].injectedData; | ||
} | ||
} | ||
|
||
export function patchReadFile(extractions, entryFilename) { | ||
|
||
patchFs({ | ||
readFileSync(path, options) { | ||
const injectedData = getInjectedData(path, extractions, entryFilename); | ||
|
||
if (injectedData) { | ||
return injectedData; | ||
} | ||
|
||
return originalReadFileSync(path, options); | ||
}, | ||
|
||
readFile(path, options, callback) { | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = null; | ||
} | ||
|
||
const injectedData = getInjectedData(path, extractions, entryFilename); | ||
|
||
if (injectedData) { | ||
callback(null, injectedData); | ||
} | ||
else { | ||
originalReadFile(path, options, callback); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
export function unpatchReadFile() { | ||
fs.readFileSync = originalReadFileSync; | ||
fs.readFile = originalReadFile; | ||
} |
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.