-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add logic to sass rule conditional on sass-loader version
- Loading branch information
Showing
9 changed files
with
101 additions
and
8 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,4 @@ | ||
{ | ||
"main": "./wat", | ||
"version": "12.0.0" | ||
} |
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,4 @@ | ||
{ | ||
"main": "./lib/api.js", | ||
"version": "16.56.81" | ||
} |
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,4 +1,5 @@ | ||
module.exports = { | ||
roots: ["<rootDir>/test"], | ||
testPathIgnorePatterns: ["/__fixtures__/", "/__utils__/"] | ||
testPathIgnorePatterns: ["/__fixtures__/", "/__utils__/"], | ||
resolver: "<rootDir>/test/resolver" | ||
} |
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,16 +1,18 @@ | ||
/* eslint global-require: 0 */ | ||
|
||
const getStyleRule = require("../utils/getStyleRule") | ||
const { canProcess } = require("../utils/helpers") | ||
const { additional_paths: includePaths } = require("../config") | ||
const { canProcess, packageMajorVersion } = require("../utils/helpers") | ||
const { additional_paths: extraPaths } = require("../config") | ||
|
||
module.exports = canProcess("sass-loader", (resolvedPath) => | ||
getStyleRule(/\.(scss|sass)(\.erb)?$/i, [ | ||
module.exports = canProcess("sass-loader", (resolvedPath) => { | ||
const optionKey = | ||
packageMajorVersion("sass-loader") > 15 ? "loadPaths" : "includePaths" | ||
return getStyleRule(/\.(scss|sass)(\.erb)?$/i, [ | ||
{ | ||
loader: resolvedPath, | ||
options: { | ||
sassOptions: { includePaths } | ||
sassOptions: { [optionKey]: extraPaths } | ||
} | ||
} | ||
]) | ||
) | ||
}) |
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,11 @@ | ||
const { packageMajorVersion } = require("../../package/utils/helpers") | ||
|
||
describe("packageMajorVersion", () => { | ||
test("should find that sass-loader is v16", () => { | ||
expect(packageMajorVersion("sass-loader")).toBe("16") | ||
}) | ||
|
||
test("should find that nonexistent is v12", () => { | ||
expect(packageMajorVersion("nonexistent")).toBe("12") | ||
}) | ||
}) |
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,25 @@ | ||
const sass = require("../../../package/rules/sass") | ||
|
||
jest.mock("../../../package/utils/helpers", () => { | ||
const original = jest.requireActual("../../../package/utils/helpers") | ||
const canProcess = (rule, fn) => { | ||
return fn("This path was mocked") | ||
} | ||
const moduleExists = () => true | ||
const packageMajorVersion = () => "15" | ||
return { | ||
...original, | ||
canProcess, | ||
moduleExists, | ||
packageMajorVersion | ||
} | ||
}) | ||
|
||
jest.mock("../../../package/utils/inliningCss", () => true) | ||
|
||
describe("sass rule", () => { | ||
test("contains loadPaths as the sassOptions key if sass-loader is v15 or earlier", () => { | ||
expect(typeof sass.use[3].options.sassOptions.includePaths).toBe("object") | ||
expect(typeof sass.use[3].options.sassOptions.loadPaths).toBe("undefined") | ||
}) | ||
}) |
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,25 @@ | ||
const sass = require("../../../package/rules/sass") | ||
|
||
jest.mock("../../../package/utils/helpers", () => { | ||
const original = jest.requireActual("../../../package/utils/helpers") | ||
const canProcess = (rule, fn) => { | ||
return fn("This path was mocked") | ||
} | ||
const moduleExists = () => true | ||
return { | ||
...original, | ||
canProcess, | ||
moduleExists | ||
} | ||
}) | ||
|
||
jest.mock("../../../package/utils/inliningCss", () => true) | ||
|
||
describe("sass rule", () => { | ||
test("contains loadPaths as the sassOptions key if sass-loader is v15 or earlier", () => { | ||
expect(typeof sass.use[3].options.sassOptions.includePaths).toBe( | ||
"undefined" | ||
) | ||
expect(typeof sass.use[3].options.sassOptions.loadPaths).toBe("object") | ||
}) | ||
}) |
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,13 @@ | ||
const mapping = { | ||
"css-loader": "this path was mocked", | ||
"sass-loader/package.json": "../../__mocks__/sass-loader/package.json", | ||
"nonexistent/package.json": "../../__mocks__/nonexistent/package.json" | ||
} | ||
|
||
function resolver(module, options) { | ||
// If the path corresponds to a key in the mapping object, returns the fakely resolved path | ||
// otherwise it calls the Jest's default resolver | ||
return mapping[module] || options.defaultResolver(module, options) | ||
} | ||
|
||
module.exports = resolver |