rollup-plugin-lib-style 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Daniel Amenou
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -112,6 +112,11 @@ Type: Array<string | RegExp> | string | RegExp<br />
112
112
  Default: null<br />
113
113
  Description: exclude files from load by the loader
114
114
 
115
+ ### customPath
116
+ Type: string<br />
117
+ Default: "."<br />
118
+ Description: Change custom path for starting of reference to CSS file, useful for nested component structure
119
+
115
120
 
116
121
  ## Global Styles
117
122
  In some cases, we will want to create global class names (without hash)
package/lib/index.es.js CHANGED
@@ -50,8 +50,7 @@ const postCssLoader = async ({code, fiePath, options}) => {
50
50
  const postCssPluginsWithCssModules = [
51
51
  postcssModules({
52
52
  generateScopedName: (name, filename, css) => {
53
- const newClassName = classNamePrefix + ((isInNodeModules || isGlobalStyle) ? name : replaceFormat(scopedName, name, css));
54
- return newClassName
53
+ return isInNodeModules || isGlobalStyle ? name : classNamePrefix + replaceFormat(scopedName, name, css)
55
54
  },
56
55
  getJSON: (cssFileName, json) => (modulesExported[cssFileName] = json),
57
56
  }),
@@ -110,10 +109,10 @@ const defaultLoaders = [
110
109
  },
111
110
  ];
112
111
 
113
- const replaceMagicPath = (fileContent) => fileContent.replace(MAGIC_PATH_REGEX, ".");
112
+ const replaceMagicPath = (fileContent, customPath = ".") => fileContent.replace(MAGIC_PATH_REGEX, customPath);
114
113
 
115
114
  const libStylePlugin = (options = {}) => {
116
- const {loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
115
+ const {customPath, loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
117
116
  const allLoaders = [...(loaders || []), ...defaultLoaders];
118
117
  const filter = createFilter(include, exclude);
119
118
  const getLoader = (filepath) => allLoaders.find((loader) => loader.regex.test(filepath));
@@ -173,7 +172,7 @@ const libStylePlugin = (options = {}) => {
173
172
  fs
174
173
  .readFile(currentPath)
175
174
  .then((buffer) => buffer.toString())
176
- .then(replaceMagicPath)
175
+ .then((fileContent) => replaceMagicPath(fileContent, customPath))
177
176
  .then((fileContent) => fs.writeFile(currentPath, fileContent))
178
177
  )
179
178
  );
package/lib/index.js CHANGED
@@ -52,8 +52,7 @@ const postCssLoader = async ({code, fiePath, options}) => {
52
52
  const postCssPluginsWithCssModules = [
53
53
  postcssModules({
54
54
  generateScopedName: (name, filename, css) => {
55
- const newClassName = classNamePrefix + ((isInNodeModules || isGlobalStyle) ? name : replaceFormat(scopedName, name, css));
56
- return newClassName
55
+ return isInNodeModules || isGlobalStyle ? name : classNamePrefix + replaceFormat(scopedName, name, css)
57
56
  },
58
57
  getJSON: (cssFileName, json) => (modulesExported[cssFileName] = json),
59
58
  }),
@@ -112,10 +111,10 @@ const defaultLoaders = [
112
111
  },
113
112
  ];
114
113
 
115
- const replaceMagicPath = (fileContent) => fileContent.replace(MAGIC_PATH_REGEX, ".");
114
+ const replaceMagicPath = (fileContent, customPath = ".") => fileContent.replace(MAGIC_PATH_REGEX, customPath);
116
115
 
117
116
  const libStylePlugin = (options = {}) => {
118
- const {loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
117
+ const {customPath, loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
119
118
  const allLoaders = [...(loaders || []), ...defaultLoaders];
120
119
  const filter = rollupPluginutils.createFilter(include, exclude);
121
120
  const getLoader = (filepath) => allLoaders.find((loader) => loader.regex.test(filepath));
@@ -175,7 +174,7 @@ const libStylePlugin = (options = {}) => {
175
174
  fs
176
175
  .readFile(currentPath)
177
176
  .then((buffer) => buffer.toString())
178
- .then(replaceMagicPath)
177
+ .then((fileContent) => replaceMagicPath(fileContent, customPath))
179
178
  .then((fileContent) => fs.writeFile(currentPath, fileContent))
180
179
  )
181
180
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup-plugin-lib-style",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "A Rollup plugin that converts CSS and extensions for CSS into CSS modules and imports the generated CSS files",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.es.js",
package/types/index.d.ts CHANGED
@@ -19,6 +19,7 @@ declare interface Options {
19
19
  postCssPlugins?: object[]
20
20
  classNamePrefix?: string
21
21
  scopedName?: string
22
+ customPath?: string
22
23
  }
23
24
 
24
25
  declare const onwarn: (warning: RollupWarning, defaultHandler: (warning: string | RollupWarning) => void) => void