Skip to content

Commit

Permalink
chore: update naming to implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Jan 19, 2021
1 parent 1eb52d8 commit 7d2eac2
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 42 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,14 @@ module.exports = {
};
```

### `customPostcss`
### `implementation`

Type: `Function`
Default: `undefined`

A custom `postcss` factory function for the loader to use. **This option is only really useful for downstream tooling authors to ease the PostCSS 7-to-8 transition.**
The special `implementation` option determines which implementation of PostCSS to use. Overrides the locally installed `peerDependency` version of `postcss`.

**This option is only really useful for downstream tooling authors to ease the PostCSS 7-to-8 transition.**

**webpack.config.js**

Expand All @@ -613,7 +615,7 @@ module.exports = {
{ loader: "css-loader" },
{
loader: "postcss-loader",
options: { customPostcss: require("postcss") },
options: { implementation: require("postcss") },
},
{ loader: "sass-loader" },
],
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default async function loader(content, sourceMap, meta) {
? true
: options.postcssOptions.config;

const postcss = options.customPostcss || ourPostcss;
const postcss = options.implementation || ourPostcss;

let loadedConfig;

Expand Down
4 changes: 2 additions & 2 deletions src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"description": "Enables/Disables generation of source maps (https://github.com/postcss/postcss-loader#sourcemap)",
"type": "boolean"
},
"customPostcss": {
"description": "An explicit PostCSS function to use, instead of the locally installed version (https://github.com/postcss/postcss-loader#customPostcss)",
"implementation": {
"description": "The implementation of postcss to use, instead of the locally installed version (https://github.com/postcss/postcss-loader#implementation)",
"instanceof": "Function"
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`"customPostcss" option should work with a custom instance of PostCSS: css 1`] = `
exports[`"implementation" option should work with a custom instance of PostCSS: css 1`] = `
"a {
color: black;
}
Expand Down Expand Up @@ -47,6 +47,6 @@ a {
"
`;

exports[`"customPostcss" option should work with a custom instance of PostCSS: errors 1`] = `Array []`;
exports[`"implementation" option should work with a custom instance of PostCSS: errors 1`] = `Array []`;

exports[`"customPostcss" option should work with a custom instance of PostCSS: warnings 1`] = `Array []`;
exports[`"implementation" option should work with a custom instance of PostCSS: warnings 1`] = `Array []`;
60 changes: 30 additions & 30 deletions test/__snapshots__/validate-options.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,35 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`validate options should throw an error on the "customPostcss" option with "/test/" value 1`] = `
"Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema.
- options.customPostcss should be an instance of function.
-> An explicit PostCSS function to use, instead of the locally installed version (https://github.com/postcss/postcss-loader#customPostcss)"
`;

exports[`validate options should throw an error on the "customPostcss" option with "[]" value 1`] = `
"Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema.
- options.customPostcss should be an instance of function.
-> An explicit PostCSS function to use, instead of the locally installed version (https://github.com/postcss/postcss-loader#customPostcss)"
`;

exports[`validate options should throw an error on the "customPostcss" option with "{}" value 1`] = `
"Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema.
- options.customPostcss should be an instance of function.
-> An explicit PostCSS function to use, instead of the locally installed version (https://github.com/postcss/postcss-loader#customPostcss)"
`;

exports[`validate options should throw an error on the "customPostcss" option with "1" value 1`] = `
"Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema.
- options.customPostcss should be an instance of function.
-> An explicit PostCSS function to use, instead of the locally installed version (https://github.com/postcss/postcss-loader#customPostcss)"
`;

exports[`validate options should throw an error on the "customPostcss" option with "something" value 1`] = `
"Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema.
- options.customPostcss should be an instance of function.
-> An explicit PostCSS function to use, instead of the locally installed version (https://github.com/postcss/postcss-loader#customPostcss)"
`;

exports[`validate options should throw an error on the "execute" option with "/test/" value 1`] = `
"Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema.
- options.execute should be a boolean.
Expand Down Expand Up @@ -66,6 +36,36 @@ exports[`validate options should throw an error on the "execute" option with "te
-> Enables/Disables PostCSS parser support in 'CSS-in-JS' (https://github.com/postcss/postcss-loader#execute)"
`;

exports[`validate options should throw an error on the "implementation" option with "/test/" value 1`] = `
"Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema.
- options.implementation should be an instance of function.
-> The implementation of postcss to use, instead of the locally installed version (https://github.com/postcss/postcss-loader#implementation)"
`;

exports[`validate options should throw an error on the "implementation" option with "[]" value 1`] = `
"Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema.
- options.implementation should be an instance of function.
-> The implementation of postcss to use, instead of the locally installed version (https://github.com/postcss/postcss-loader#implementation)"
`;

exports[`validate options should throw an error on the "implementation" option with "{}" value 1`] = `
"Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema.
- options.implementation should be an instance of function.
-> The implementation of postcss to use, instead of the locally installed version (https://github.com/postcss/postcss-loader#implementation)"
`;

exports[`validate options should throw an error on the "implementation" option with "1" value 1`] = `
"Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema.
- options.implementation should be an instance of function.
-> The implementation of postcss to use, instead of the locally installed version (https://github.com/postcss/postcss-loader#implementation)"
`;

exports[`validate options should throw an error on the "implementation" option with "something" value 1`] = `
"Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema.
- options.implementation should be an instance of function.
-> The implementation of postcss to use, instead of the locally installed version (https://github.com/postcss/postcss-loader#implementation)"
`;

exports[`validate options should throw an error on the "postcssOptions" option with "{"config":[]}" value 1`] = `
"Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema.
- options.postcssOptions should be one of these:
Expand Down
4 changes: 2 additions & 2 deletions test/customPostcss.test.js → test/implementation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
getWarnings,
} from "./helpers";

describe('"customPostcss" option', () => {
describe('"implementation" option', () => {
it("should work with a custom instance of PostCSS", async () => {
const spy = jest.fn(postcss);
const compiler = getCompiler("./css/index.js", {
// Wrap the spy so it is an instanceof Function
customPostcss: (...args) => spy(...args),
implementation: (...args) => spy(...args),
});
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle("style.css", stats);
Expand Down
2 changes: 1 addition & 1 deletion test/validate-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("validate options", () => {
success: [true, false],
failure: [1, /test/, [], {}, "something"],
},
customPostcss: {
implementation: {
success: [require("postcss")],
failure: [1, /test/, [], {}, "something"],
},
Expand Down

0 comments on commit 7d2eac2

Please sign in to comment.