Skip to content

Added configFile option #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ module.exports = {

## Options

| Name | Type | Description |
| :-------------------------------------: | :---------: | :------------------------------------------------------------------------------: |
| **[`banner`](#banner)** | `{String}` | To add a 'banner' prefix to each generated `*.d.ts` file |
| **[`formatter`](#formatter)** | `{String}` | Formats the generated `*.d.ts` file with specified formatter, eg. `prettier` |
| **[`eol`](#eol)** | `{String}` | Newline character to be used in generated `*.d.ts` files |
| **[`verifyOnly`](#verifyOnly)** | `{Boolean}` | Validate generated `*.d.ts` files and fail if an update is needed (useful in CI) |
| **[`disableLocalsExport`](#disableLocalsExport)** | `{Boolean}` | Disable the use of locals export. |
| Name | Type | Description |
| :-----------------------------------------------: | :---------: | :----------------------------------------------------------: |
| **[`banner`](#banner)** | `{String}` | To add a 'banner' prefix to each generated `*.d.ts` file |
| **[`formatter`](#formatter)** | `{String}` | Formats the generated `*.d.ts` file with specified formatter, eg. `prettier` |
| **[`eol`](#eol)** | `{String}` | Newline character to be used in generated `*.d.ts` files |
| **[`verifyOnly`](#verifyOnly)** | `{Boolean}` | Validate generated `*.d.ts` files and fail if an update is needed (useful in CI) |
| **[`disableLocalsExport`](#disableLocalsExport)** | `{Boolean}` | Disable the use of locals export. |
| **[`prettierConfigFile`](#prettierConfigFile)** | `{String}` | Path to prettier config file |

### `banner`

Expand Down Expand Up @@ -188,6 +189,35 @@ module.exports = {
};
```

### `prettierConfigFile`

Path to the prettier config file

```js
module.exports = {
module: {
rules: [
{
test: /\.css$/i,
use: [
{
loader: "@teamsupercell/typings-for-css-modules-loader",
options: {
prettierConfigFile: resolve(__dirname, '../.prettierrc'),
}
},
{
loader: "css-loader",
options: { modules: true }
}
]
}
]
}
};
```



## Example

Expand Down
13 changes: 10 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ const schema = {
"Validate generated `*.d.ts` files and fail if an update is needed (useful in CI). Defaults to `false`",
type: "boolean",
},
prettierConfigFile: {
description:
"Path to prettier config file",
type: "string",
}
},
additionalProperties: false,
};
Expand Down Expand Up @@ -114,7 +119,7 @@ async function applyFormattingAndOptions(cssModuleDefinition, options) {
options.formatter === "prettier" ||
(!options.formatter && canUsePrettier())
) {
cssModuleDefinition = await applyPrettier(cssModuleDefinition);
cssModuleDefinition = await applyPrettier(cssModuleDefinition, options);
} else {
// at very least let's ensure we're using OS eol if it's not provided
cssModuleDefinition = cssModuleDefinition.replace(
Expand All @@ -128,12 +133,14 @@ async function applyFormattingAndOptions(cssModuleDefinition, options) {

/**
* @param {string} input
* @param {any} options
* @returns {Promise<string>}
*/
async function applyPrettier(input) {
async function applyPrettier(input, options) {
const prettier = require("prettier");

const config = await prettier.resolveConfig("./", {
const configPath = options.prettierConfigFile ? options.prettierConfigFile : "./";
const config = await prettier.resolveConfig(configPath, {
editorconfig: true,
});

Expand Down