rollup-plugin-lib-style 1.2.4 → 1.2.6

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 +97 -97
  2. package/lib/index.js +97 -97
  3. package/package.json +69 -68
package/lib/index.es.js CHANGED
@@ -52,13 +52,13 @@ const postCssLoader = async ({code, fiePath, options}) => {
52
52
  const dependencies = [];
53
53
  for (const message of result.messages) {
54
54
  if (message.type === "dependency") {
55
- dependencies.add(message.file);
55
+ dependencies.push(message.file);
56
56
  }
57
57
  }
58
58
 
59
59
  // print postcss warnings
60
60
  for (const warning of result.warnings()) {
61
- console.warn(warning.message || warning.text);
61
+ console.warn(`WARNING: ${warning.plugin}:`, warning.text);
62
62
  }
63
63
 
64
64
  return {
@@ -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 dependency of postCssResult.dependencies) this.addWatchFile(dependency);
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
@@ -54,13 +54,13 @@ const postCssLoader = async ({code, fiePath, options}) => {
54
54
  const dependencies = [];
55
55
  for (const message of result.messages) {
56
56
  if (message.type === "dependency") {
57
- dependencies.add(message.file);
57
+ dependencies.push(message.file);
58
58
  }
59
59
  }
60
60
 
61
61
  // print postcss warnings
62
62
  for (const warning of result.warnings()) {
63
- console.warn(warning.message || warning.text);
63
+ console.warn(`WARNING: ${warning.plugin}:`, warning.text);
64
64
  }
65
65
 
66
66
  return {
@@ -73,101 +73,101 @@ const postCssLoader = async ({code, fiePath, options}) => {
73
73
  }
74
74
  };
75
75
 
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);
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 dependency of postCssResult.dependencies) this.addWatchFile(dependency);
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);
171
171
  };
172
172
 
173
173
  exports.libStylePlugin = libStylePlugin;
package/package.json CHANGED
@@ -1,68 +1,69 @@
1
- {
2
- "name": "rollup-plugin-lib-style",
3
- "version": "1.2.4",
4
- "description": "A Rollup plugin that converts CSS and extensions for CSS into CSS modules and imports the generated CSS files",
5
- "main": "lib/index.js",
6
- "module": "lib/index.es.js",
7
- "files": [
8
- "lib",
9
- "types/index.d.ts"
10
- ],
11
- "scripts": {
12
- "build": "rollup --input src/index.js --file lib/index.es.js --format es && rollup --input src/index.js --file lib/index.js --format cjs",
13
- "prepublishOnly": "npm run build && npm run test",
14
- "postpublish": "git push && git push --tags",
15
- "publish:beta": "npm version prerelease --preid=beta -m \"beta version - %s\" && npm publish --tag beta",
16
- "publish:patch": "npm version patch -m \"patch version - %s\" && npm publish",
17
- "publish:minor": "npm version minor -m \"minor version - %s\" && npm publish",
18
- "publish:major": "npm version major -m \"major version - %s\" && npm publish",
19
- "lint:fix": "eslint **/*.{js,jsx} --fix",
20
- "lint": "eslint **/*.{js,jsx}",
21
- "test": "jest",
22
- "test:cov": "jest --coverage"
23
- },
24
- "repository": {
25
- "type": "git",
26
- "url": "git+https://github.com/danielamenou/rollup-plugin-lib-style"
27
- },
28
- "keywords": [
29
- "library",
30
- "rollup",
31
- "plugin",
32
- "style",
33
- "sass",
34
- "scss",
35
- "css"
36
- ],
37
- "author": "Daniel Amenou <amenou.daniel@gmail.com>",
38
- "license": "MIT",
39
- "engines": {
40
- "node": ">=16"
41
- },
42
- "types": "./types/index.d.ts",
43
- "devDependencies": {
44
- "@babel/core": "^7.20.5",
45
- "@babel/eslint-parser": "^7.19.1",
46
- "@babel/preset-env": "^7.20.2",
47
- "@types/jest": "^29.2.3",
48
- "babel-core": "^6.26.3",
49
- "babel-jest": "^29.3.1",
50
- "eslint": "^8.28.0",
51
- "eslint-config-prettier": "^8.5.0",
52
- "eslint-config-rem": "^4.0.0",
53
- "eslint-plugin-import": "^2.26.0",
54
- "eslint-plugin-prettier": "^4.2.1",
55
- "eslint-plugin-promise": "^6.1.1",
56
- "fs-extra": "^11.0.0",
57
- "jest": "^29.3.1",
58
- "jest-environment-node-single-context": "^29.0.0",
59
- "prettier": "^2.8.0",
60
- "rollup": "^3.5.0"
61
- },
62
- "dependencies": {
63
- "postcss": "^8.4.19",
64
- "postcss-modules": "^6.0.0",
65
- "rollup-pluginutils": "^2.8.2",
66
- "sass": "^1.56.1"
67
- }
68
- }
1
+ {
2
+ "name": "rollup-plugin-lib-style",
3
+ "version": "1.2.6",
4
+ "description": "A Rollup plugin that converts CSS and extensions for CSS into CSS modules and imports the generated CSS files",
5
+ "main": "lib/index.js",
6
+ "module": "lib/index.es.js",
7
+ "files": [
8
+ "lib",
9
+ "types/index.d.ts"
10
+ ],
11
+ "scripts": {
12
+ "build": "rollup --input src/index.js --file lib/index.es.js --format es && rollup --input src/index.js --file lib/index.js --format cjs",
13
+ "prepublishOnly": "npm run build && npm run test",
14
+ "prepack": "npm run build",
15
+ "postpublish": "git push && git push --tags",
16
+ "publish:beta": "npm version prerelease --preid=beta -m \"beta version - %s\" && npm publish --tag beta",
17
+ "publish:patch": "npm version patch -m \"patch version - %s\" && npm publish",
18
+ "publish:minor": "npm version minor -m \"minor version - %s\" && npm publish",
19
+ "publish:major": "npm version major -m \"major version - %s\" && npm publish",
20
+ "lint:fix": "eslint **/*.{js,jsx} --fix",
21
+ "lint": "eslint **/*.{js,jsx}",
22
+ "test": "jest",
23
+ "test:cov": "jest --coverage"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/danielamenou/rollup-plugin-lib-style"
28
+ },
29
+ "keywords": [
30
+ "library",
31
+ "rollup",
32
+ "plugin",
33
+ "style",
34
+ "sass",
35
+ "scss",
36
+ "css"
37
+ ],
38
+ "author": "Daniel Amenou <amenou.daniel@gmail.com>",
39
+ "license": "MIT",
40
+ "engines": {
41
+ "node": ">=16"
42
+ },
43
+ "types": "./types/index.d.ts",
44
+ "devDependencies": {
45
+ "@babel/core": "^7.20.5",
46
+ "@babel/eslint-parser": "^7.19.1",
47
+ "@babel/preset-env": "^7.20.2",
48
+ "@types/jest": "^29.2.3",
49
+ "babel-core": "^6.26.3",
50
+ "babel-jest": "^29.3.1",
51
+ "eslint": "^8.28.0",
52
+ "eslint-config-prettier": "^8.5.0",
53
+ "eslint-config-rem": "^4.0.0",
54
+ "eslint-plugin-import": "^2.26.0",
55
+ "eslint-plugin-prettier": "^4.2.1",
56
+ "eslint-plugin-promise": "^6.1.1",
57
+ "fs-extra": "^11.0.0",
58
+ "jest": "^29.3.1",
59
+ "jest-environment-node-single-context": "^29.0.0",
60
+ "prettier": "^2.8.0",
61
+ "rollup": "^3.5.0"
62
+ },
63
+ "dependencies": {
64
+ "postcss": "^8.4.17",
65
+ "postcss-modules": "^4.0.0",
66
+ "rollup-pluginutils": "^2.8.2",
67
+ "sass": "^1.55.0"
68
+ }
69
+ }