rollup-plugin-lib-style 1.2.3 → 1.2.4

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.
Files changed (3) hide show
  1. package/lib/index.es.js +95 -95
  2. package/lib/index.js +97 -107
  3. package/package.json +14 -14
package/lib/index.es.js CHANGED
@@ -71,101 +71,101 @@ const postCssLoader = async ({code, fiePath, options}) => {
71
71
  }
72
72
  };
73
73
 
74
- const PLUGIN_NAME = "rollup-plugin-lib-style";
75
- const MAGIC_PATH_REGEX = /@@_MAGIC_PATH_@@/g;
76
- const MAGIC_PATH = "@@_MAGIC_PATH_@@";
77
-
78
- const modulesIds = new Set();
79
-
80
- const outputPaths = [];
81
-
82
- const defaultLoaders = [
83
- {
84
- name: "sass",
85
- regex: /\.(sass|scss)$/,
86
- process: ({filePath}) => ({code: sass.compile(filePath).css.toString()}),
87
- },
88
- {
89
- name: "css",
90
- regex: /\.(css)$/,
91
- process: ({code}) => ({code}),
92
- },
93
- ];
94
-
95
- const replaceMagicPath = (fileContent) => fileContent.replace(MAGIC_PATH_REGEX, ".");
96
-
97
- const libStylePlugin = (options = {}) => {
98
- const {loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
99
- const allLoaders = [...(loaders || []), ...defaultLoaders];
100
- const filter = createFilter(include, exclude);
101
- const getLoader = (filepath) => allLoaders.find((loader) => loader.regex.test(filepath));
102
-
103
- return {
104
- name: PLUGIN_NAME,
105
-
106
- options(options) {
107
- if (!options.output) console.error("missing output options");
108
- else options.output.forEach((outputOptions) => outputPaths.push(outputOptions.dir));
109
- },
110
-
111
- async transform(code, id) {
112
- const loader = getLoader(id);
113
- if (!filter(id) || !loader) return null
114
-
115
- modulesIds.add(id);
116
-
117
- const rawCss = await loader.process({filePath: id, code});
118
-
119
- const postCssResult = await postCssLoader({code: rawCss.code, fiePath: id, options: postCssOptions});
120
-
121
- for (const dependence of postCssResult.dependencies) this.addWatchFile(dependence);
122
-
123
- const cssFilePath = id.replace(process.cwd(), "").replace(/\\/g, "/");
124
-
125
- // create a new css file with the generated hash class names
126
- this.emitFile({
127
- type: "asset",
128
- fileName: cssFilePath.replace("/", "").replace(loader.regex, ".css"),
129
- source: postCssResult.extracted.code,
130
- });
131
-
132
- const importStr = importCSS ? `import "${MAGIC_PATH}${cssFilePath.replace(loader.regex, ".css")}";\n` : "";
133
-
134
- // create a new js file with css module
135
- return {
136
- code: importStr + postCssResult.code,
137
- map: {mappings: ""},
138
- }
139
- },
140
-
141
- async closeBundle() {
142
- if (!importCSS) return
143
-
144
- // get all the modules that import CSS files
145
- const importersPaths = outputPaths
146
- .reduce((result, currentPath) => {
147
- result.push(glob.sync(`${currentPath}/**/*.js`));
148
- return result
149
- }, [])
150
- .flat();
151
-
152
- // replace magic path with relative path
153
- await Promise.all(
154
- importersPaths.map((currentPath) =>
155
- fs
156
- .readFile(currentPath)
157
- .then((buffer) => buffer.toString())
158
- .then(replaceMagicPath)
159
- .then((fileContent) => fs.writeFile(currentPath, fileContent))
160
- )
161
- );
162
- },
163
- }
164
- };
165
-
166
- const onwarn = (warning, warn) => {
167
- if (warning.code === "UNRESOLVED_IMPORT" && warning.message.includes(MAGIC_PATH)) return
168
- warn(warning);
74
+ const PLUGIN_NAME = "rollup-plugin-lib-style";
75
+ const MAGIC_PATH_REGEX = /@@_MAGIC_PATH_@@/g;
76
+ const MAGIC_PATH = "@@_MAGIC_PATH_@@";
77
+
78
+ const modulesIds = new Set();
79
+
80
+ const outputPaths = [];
81
+
82
+ const defaultLoaders = [
83
+ {
84
+ name: "sass",
85
+ regex: /\.(sass|scss)$/,
86
+ process: ({filePath}) => ({code: sass.compile(filePath).css.toString()}),
87
+ },
88
+ {
89
+ name: "css",
90
+ regex: /\.(css)$/,
91
+ process: ({code}) => ({code}),
92
+ },
93
+ ];
94
+
95
+ const replaceMagicPath = (fileContent) => fileContent.replace(MAGIC_PATH_REGEX, ".");
96
+
97
+ const libStylePlugin = (options = {}) => {
98
+ const {loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
99
+ const allLoaders = [...(loaders || []), ...defaultLoaders];
100
+ const filter = createFilter(include, exclude);
101
+ const getLoader = (filepath) => allLoaders.find((loader) => loader.regex.test(filepath));
102
+
103
+ return {
104
+ name: PLUGIN_NAME,
105
+
106
+ options(options) {
107
+ if (!options.output) console.error("missing output options");
108
+ else options.output.forEach((outputOptions) => outputPaths.push(outputOptions.dir));
109
+ },
110
+
111
+ async transform(code, id) {
112
+ const loader = getLoader(id);
113
+ if (!filter(id) || !loader) return null
114
+
115
+ modulesIds.add(id);
116
+
117
+ const rawCss = await loader.process({filePath: id, code});
118
+
119
+ const postCssResult = await postCssLoader({code: rawCss.code, fiePath: id, options: postCssOptions});
120
+
121
+ for (const dependence of postCssResult.dependencies) this.addWatchFile(dependence);
122
+
123
+ const cssFilePath = id.replace(process.cwd(), "").replace(/\\/g, "/");
124
+
125
+ // create a new css file with the generated hash class names
126
+ this.emitFile({
127
+ type: "asset",
128
+ fileName: cssFilePath.replace("/", "").replace(loader.regex, ".css"),
129
+ source: postCssResult.extracted.code,
130
+ });
131
+
132
+ const importStr = importCSS ? `import "${MAGIC_PATH}${cssFilePath.replace(loader.regex, ".css")}";\n` : "";
133
+
134
+ // create a new js file with css module
135
+ return {
136
+ code: importStr + postCssResult.code,
137
+ map: {mappings: ""},
138
+ }
139
+ },
140
+
141
+ async closeBundle() {
142
+ if (!importCSS) return
143
+
144
+ // get all the modules that import CSS files
145
+ const importersPaths = outputPaths
146
+ .reduce((result, currentPath) => {
147
+ result.push(glob.sync(`${currentPath}/**/*.js`));
148
+ return result
149
+ }, [])
150
+ .flat();
151
+
152
+ // replace magic path with relative path
153
+ await Promise.all(
154
+ importersPaths.map((currentPath) =>
155
+ fs
156
+ .readFile(currentPath)
157
+ .then((buffer) => buffer.toString())
158
+ .then(replaceMagicPath)
159
+ .then((fileContent) => fs.writeFile(currentPath, fileContent))
160
+ )
161
+ );
162
+ },
163
+ }
164
+ };
165
+
166
+ const onwarn = (warning, warn) => {
167
+ if (warning.code === "UNRESOLVED_IMPORT" && warning.message.includes(MAGIC_PATH)) return
168
+ warn(warning);
169
169
  };
170
170
 
171
171
  export { libStylePlugin, onwarn };
package/lib/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var rollupPluginutils = require('rollup-pluginutils');
6
4
  var postcss = require('postcss');
7
5
  var postcssModules = require('postcss-modules');
@@ -9,14 +7,6 @@ var fs = require('fs-extra');
9
7
  var sass = require('sass');
10
8
  var glob = require('glob');
11
9
 
12
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
-
14
- var postcss__default = /*#__PURE__*/_interopDefaultLegacy(postcss);
15
- var postcssModules__default = /*#__PURE__*/_interopDefaultLegacy(postcssModules);
16
- var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
17
- var sass__default = /*#__PURE__*/_interopDefaultLegacy(sass);
18
- var glob__default = /*#__PURE__*/_interopDefaultLegacy(glob);
19
-
20
10
  const defaultScopedName = "[local]_[hash:base64:6]";
21
11
 
22
12
  /**
@@ -46,7 +36,7 @@ const postCssLoader = async ({code, fiePath, options}) => {
46
36
  const isGlobalStyle = /\.global.(css|scss|sass|less|stylus)$/.test(fiePath);
47
37
 
48
38
  postCssPlugins.unshift(
49
- postcssModules__default["default"]({
39
+ postcssModules({
50
40
  generateScopedName: isGlobalStyle ? "[local]" : classNamePrefix + scopedName,
51
41
  getJSON: (cssFileName, json) => (modulesExported[cssFileName] = json),
52
42
  })
@@ -58,7 +48,7 @@ const postCssLoader = async ({code, fiePath, options}) => {
58
48
  map: false,
59
49
  };
60
50
 
61
- const result = await postcss__default["default"](postCssPlugins).process(code, postcssOptions);
51
+ const result = await postcss(postCssPlugins).process(code, postcssOptions);
62
52
 
63
53
  // collect dependencies
64
54
  const dependencies = [];
@@ -83,101 +73,101 @@ const postCssLoader = async ({code, fiePath, options}) => {
83
73
  }
84
74
  };
85
75
 
86
- const PLUGIN_NAME = "rollup-plugin-lib-style";
87
- const MAGIC_PATH_REGEX = /@@_MAGIC_PATH_@@/g;
88
- const MAGIC_PATH = "@@_MAGIC_PATH_@@";
89
-
90
- const modulesIds = new Set();
91
-
92
- const outputPaths = [];
93
-
94
- const defaultLoaders = [
95
- {
96
- name: "sass",
97
- regex: /\.(sass|scss)$/,
98
- process: ({filePath}) => ({code: sass__default["default"].compile(filePath).css.toString()}),
99
- },
100
- {
101
- name: "css",
102
- regex: /\.(css)$/,
103
- process: ({code}) => ({code}),
104
- },
105
- ];
106
-
107
- const replaceMagicPath = (fileContent) => fileContent.replace(MAGIC_PATH_REGEX, ".");
108
-
109
- const libStylePlugin = (options = {}) => {
110
- const {loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
111
- const allLoaders = [...(loaders || []), ...defaultLoaders];
112
- const filter = rollupPluginutils.createFilter(include, exclude);
113
- const getLoader = (filepath) => allLoaders.find((loader) => loader.regex.test(filepath));
114
-
115
- return {
116
- name: PLUGIN_NAME,
117
-
118
- options(options) {
119
- if (!options.output) console.error("missing output options");
120
- else options.output.forEach((outputOptions) => outputPaths.push(outputOptions.dir));
121
- },
122
-
123
- async transform(code, id) {
124
- const loader = getLoader(id);
125
- if (!filter(id) || !loader) return null
126
-
127
- modulesIds.add(id);
128
-
129
- const rawCss = await loader.process({filePath: id, code});
130
-
131
- const postCssResult = await postCssLoader({code: rawCss.code, fiePath: id, options: postCssOptions});
132
-
133
- for (const dependence of postCssResult.dependencies) this.addWatchFile(dependence);
134
-
135
- const cssFilePath = id.replace(process.cwd(), "").replace(/\\/g, "/");
136
-
137
- // create a new css file with the generated hash class names
138
- this.emitFile({
139
- type: "asset",
140
- fileName: cssFilePath.replace("/", "").replace(loader.regex, ".css"),
141
- source: postCssResult.extracted.code,
142
- });
143
-
144
- const importStr = importCSS ? `import "${MAGIC_PATH}${cssFilePath.replace(loader.regex, ".css")}";\n` : "";
145
-
146
- // create a new js file with css module
147
- return {
148
- code: importStr + postCssResult.code,
149
- map: {mappings: ""},
150
- }
151
- },
152
-
153
- async closeBundle() {
154
- if (!importCSS) return
155
-
156
- // get all the modules that import CSS files
157
- const importersPaths = outputPaths
158
- .reduce((result, currentPath) => {
159
- result.push(glob__default["default"].sync(`${currentPath}/**/*.js`));
160
- return result
161
- }, [])
162
- .flat();
163
-
164
- // replace magic path with relative path
165
- await Promise.all(
166
- importersPaths.map((currentPath) =>
167
- fs__default["default"]
168
- .readFile(currentPath)
169
- .then((buffer) => buffer.toString())
170
- .then(replaceMagicPath)
171
- .then((fileContent) => fs__default["default"].writeFile(currentPath, fileContent))
172
- )
173
- );
174
- },
175
- }
176
- };
177
-
178
- const onwarn = (warning, warn) => {
179
- if (warning.code === "UNRESOLVED_IMPORT" && warning.message.includes(MAGIC_PATH)) return
180
- warn(warning);
76
+ const PLUGIN_NAME = "rollup-plugin-lib-style";
77
+ const MAGIC_PATH_REGEX = /@@_MAGIC_PATH_@@/g;
78
+ const MAGIC_PATH = "@@_MAGIC_PATH_@@";
79
+
80
+ const modulesIds = new Set();
81
+
82
+ const outputPaths = [];
83
+
84
+ const defaultLoaders = [
85
+ {
86
+ name: "sass",
87
+ regex: /\.(sass|scss)$/,
88
+ process: ({filePath}) => ({code: sass.compile(filePath).css.toString()}),
89
+ },
90
+ {
91
+ name: "css",
92
+ regex: /\.(css)$/,
93
+ process: ({code}) => ({code}),
94
+ },
95
+ ];
96
+
97
+ const replaceMagicPath = (fileContent) => fileContent.replace(MAGIC_PATH_REGEX, ".");
98
+
99
+ const libStylePlugin = (options = {}) => {
100
+ const {loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
101
+ const allLoaders = [...(loaders || []), ...defaultLoaders];
102
+ const filter = rollupPluginutils.createFilter(include, exclude);
103
+ const getLoader = (filepath) => allLoaders.find((loader) => loader.regex.test(filepath));
104
+
105
+ return {
106
+ name: PLUGIN_NAME,
107
+
108
+ options(options) {
109
+ if (!options.output) console.error("missing output options");
110
+ else options.output.forEach((outputOptions) => outputPaths.push(outputOptions.dir));
111
+ },
112
+
113
+ async transform(code, id) {
114
+ const loader = getLoader(id);
115
+ if (!filter(id) || !loader) return null
116
+
117
+ modulesIds.add(id);
118
+
119
+ const rawCss = await loader.process({filePath: id, code});
120
+
121
+ const postCssResult = await postCssLoader({code: rawCss.code, fiePath: id, options: postCssOptions});
122
+
123
+ for (const dependence of postCssResult.dependencies) this.addWatchFile(dependence);
124
+
125
+ const cssFilePath = id.replace(process.cwd(), "").replace(/\\/g, "/");
126
+
127
+ // create a new css file with the generated hash class names
128
+ this.emitFile({
129
+ type: "asset",
130
+ fileName: cssFilePath.replace("/", "").replace(loader.regex, ".css"),
131
+ source: postCssResult.extracted.code,
132
+ });
133
+
134
+ const importStr = importCSS ? `import "${MAGIC_PATH}${cssFilePath.replace(loader.regex, ".css")}";\n` : "";
135
+
136
+ // create a new js file with css module
137
+ return {
138
+ code: importStr + postCssResult.code,
139
+ map: {mappings: ""},
140
+ }
141
+ },
142
+
143
+ async closeBundle() {
144
+ if (!importCSS) return
145
+
146
+ // get all the modules that import CSS files
147
+ const importersPaths = outputPaths
148
+ .reduce((result, currentPath) => {
149
+ result.push(glob.sync(`${currentPath}/**/*.js`));
150
+ return result
151
+ }, [])
152
+ .flat();
153
+
154
+ // replace magic path with relative path
155
+ await Promise.all(
156
+ importersPaths.map((currentPath) =>
157
+ fs
158
+ .readFile(currentPath)
159
+ .then((buffer) => buffer.toString())
160
+ .then(replaceMagicPath)
161
+ .then((fileContent) => fs.writeFile(currentPath, fileContent))
162
+ )
163
+ );
164
+ },
165
+ }
166
+ };
167
+
168
+ const onwarn = (warning, warn) => {
169
+ if (warning.code === "UNRESOLVED_IMPORT" && warning.message.includes(MAGIC_PATH)) return
170
+ warn(warning);
181
171
  };
182
172
 
183
173
  exports.libStylePlugin = libStylePlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup-plugin-lib-style",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
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",
@@ -41,28 +41,28 @@
41
41
  },
42
42
  "types": "./types/index.d.ts",
43
43
  "devDependencies": {
44
- "@babel/core": "^7.19.3",
44
+ "@babel/core": "^7.20.5",
45
45
  "@babel/eslint-parser": "^7.19.1",
46
- "@babel/preset-env": "^7.19.3",
47
- "@types/jest": "^29.1.2",
46
+ "@babel/preset-env": "^7.20.2",
47
+ "@types/jest": "^29.2.3",
48
48
  "babel-core": "^6.26.3",
49
- "babel-jest": "^29.1.2",
50
- "eslint": "^8.25.0",
49
+ "babel-jest": "^29.3.1",
50
+ "eslint": "^8.28.0",
51
51
  "eslint-config-prettier": "^8.5.0",
52
52
  "eslint-config-rem": "^4.0.0",
53
53
  "eslint-plugin-import": "^2.26.0",
54
54
  "eslint-plugin-prettier": "^4.2.1",
55
- "eslint-plugin-promise": "^6.0.1",
56
- "fs-extra": "^10.1.0",
57
- "jest": "^29.1.2",
55
+ "eslint-plugin-promise": "^6.1.1",
56
+ "fs-extra": "^11.0.0",
57
+ "jest": "^29.3.1",
58
58
  "jest-environment-node-single-context": "^29.0.0",
59
- "prettier": "^2.7.1",
60
- "rollup": "^2.79.1"
59
+ "prettier": "^2.8.0",
60
+ "rollup": "^3.5.0"
61
61
  },
62
62
  "dependencies": {
63
- "postcss": "^8.4.17",
64
- "postcss-modules": "^4.0.0",
63
+ "postcss": "^8.4.19",
64
+ "postcss-modules": "^6.0.0",
65
65
  "rollup-pluginutils": "^2.8.2",
66
- "sass": "^1.55.0"
66
+ "sass": "^1.56.1"
67
67
  }
68
68
  }