Skip to content

Commit 3986035

Browse files
committed
fix: delimiter
1 parent e989b92 commit 3986035

File tree

7 files changed

+35
-25
lines changed

7 files changed

+35
-25
lines changed

.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test/extract
2+
dist
3+
.github
4+
.vscode

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## 3.0.1
4+
5+
BREAKING CHANGE:
6+
7+
- fix: `styleDelineator` option changed to `styleDelimiter`. Ugh, English.
8+
39
## 3.0.0
410

511
- feat: support multiple style declarations in same file

README.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ export default {
2323

2424
## Options
2525

26-
| Property | Description |
27-
| --------------- | ------------------------------------------------------------------------ |
28-
| configPath | Path to directory that contains postcss.config.js |
29-
| env | Environment variable, defaults to `process.env.NODE_ENV` where available |
30-
| exclude | Files to exclude |
31-
| failOnError | Allows errors to propagate when `true`, otherwise warnings are thrown |
32-
| from | Input file name (usually set by rollup) |
33-
| include | Files to include |
34-
| plugins | Array of PostCSS plugins, defaults to `postcss.config.js` |
35-
| styleDelineator | Custom delineator for parsing styles in a file, default is /`/ |
36-
| styleRegex | Custom regex for selecting CSS in file |
37-
| to | Output file name (usually set by rollup) |
26+
| Property | Description |
27+
| -------------- | ------------------------------------------------------------------------ |
28+
| configPath | Path to directory that contains postcss.config.js |
29+
| env | Environment variable, defaults to `process.env.NODE_ENV` where available |
30+
| exclude | Files to exclude |
31+
| failOnError | Allows errors to propagate when `true`, otherwise warnings are thrown |
32+
| from | Input file name (usually set by rollup) |
33+
| include | Files to include |
34+
| plugins | Array of PostCSS plugins, defaults to `postcss.config.js` |
35+
| styleDelimiter | Custom delimiter for parsing styles in a file, default is /`/ |
36+
| styleRegex | Custom regex for selecting CSS in file |
37+
| to | Output file name (usually set by rollup) |
3838

3939
## Template Literals in JavaScript
4040

@@ -62,14 +62,14 @@ The default regex for selecting template literals in a file is:
6262

6363
The lookahead in the above RegExp statement allows for multiple matches of styles in the same file.
6464

65-
Customize the regex that is used to parse inline CSS with the `styleRegex` and `styleDelineator` options.
65+
Customize the regex that is used to parse inline CSS with the `styleRegex` and `styleDelimiter` options.
6666

6767
For example, to parse inline `<style>` tags:
6868

6969
```js
7070
inlinePostCSS({
7171
styleRegex: /(?:<style>)((.|\n)+?)(?=(<\/style>))/gi,
72-
styleDelineator: /<\/?style>/g,
72+
styleDelimiter: /<\/?style>/g,
7373
});
7474
```
7575

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rollup-plugin-inline-postcss",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "Rollup plugin that transforms inline styling with PostCSS",
55
"scripts": {
66
"build": "tsc -p tsconfig.json",
@@ -40,4 +40,4 @@
4040
"prettier": "^2.2.1",
4141
"typescript": "^4.1.3"
4242
}
43-
}
43+
}

src/index.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ declare interface InlinePostCSSOptions {
1313
failOnError?: boolean;
1414
from?: string;
1515
plugins?: any[];
16-
styleDelineator?: string;
16+
styleDelimiter?: string;
1717
styleRegex?: RegExp;
1818
to?: string;
1919
}
@@ -77,24 +77,24 @@ export default function inlinePostCSS(options: InlinePostCSSOptions = {}) {
7777
.filter((key) => config.plugins[key])
7878
.map((key) => require(key));
7979

80-
const styleDelineator = options.styleDelineator
81-
? options.styleDelineator
80+
const styleDelimiter = options.styleDelimiter
81+
? options.styleDelimiter
8282
: /`/;
8383

8484
let matches = code.match(styleRegex);
8585

8686
return Promise.all(
8787
matches.map((css: string) =>
8888
postcss(outputConfig).process(
89-
styleDelineator ? css.split(styleDelineator)[1] : css,
89+
styleDelimiter ? css.split(styleDelimiter)[1] : css,
9090
postcssOptions
9191
)
9292
)
9393
).then((transforms: any[]) => {
9494
transforms.forEach((transform, index) => {
9595
code = code.replace(
96-
styleDelineator
97-
? matches[index].split(styleDelineator)[1]
96+
styleDelimiter
97+
? matches[index].split(styleDelimiter)[1]
9898
: matches[index],
9999
transform.css
100100
);

src/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rollup-plugin-inline-postcss",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "Rollup plugin that transforms inline styling with PostCSS",
55
"main": "index.js",
66
"author": "Steve Belovarich",
@@ -24,4 +24,4 @@
2424
"rollup": "^2.0.0",
2525
"rollup-pluginutils": "^2.3.3"
2626
}
27-
}
27+
}

test/index.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ test('should process file with style template', async () => {
9797
outDir: 'test/extract',
9898
plugin: inlinePostCSS({
9999
styleRegex: /(?:<style>)((.|\n)+?)(?=(<\/style>))/gi,
100-
styleDelineator: /<\/?style>/g,
100+
styleDelimiter: /<\/?style>/g,
101101
configPath: path.join(__dirname, 'config'),
102102
}),
103103
options: {},

0 commit comments

Comments
 (0)