@atlaspack/transformer-postcss 2.14.5-canary.26 → 2.14.5-canary.262

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/CHANGELOG.md CHANGED
@@ -1,5 +1,287 @@
1
1
  # @atlaspack/transformer-postcss
2
2
 
3
+ ## 2.14.37
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`339b600`](https://github.com/atlassian-labs/atlaspack/commit/339b60095d755742cea50f811d08ccc44a4ae521), [`373ee2d`](https://github.com/atlassian-labs/atlaspack/commit/373ee2d3b5cc315df1e90e647619f915892e2b87)]:
8
+ - @atlaspack/rust@3.9.1
9
+ - @atlaspack/utils@3.1.1
10
+ - @atlaspack/types-internal@2.20.7
11
+ - @atlaspack/plugin@2.14.37
12
+
13
+ ## 2.14.36
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [[`02f6aa1`](https://github.com/atlassian-labs/atlaspack/commit/02f6aa1906953fc184d2b49c905c2ef815cb878d), [`58527ee`](https://github.com/atlassian-labs/atlaspack/commit/58527eec15c1aebaaadbeb63586f3082c16beae3), [`525898e`](https://github.com/atlassian-labs/atlaspack/commit/525898e33cc229a4bc938ae853732be36d20c01a), [`cfb39a0`](https://github.com/atlassian-labs/atlaspack/commit/cfb39a0d729eb620cf2ca1611750a2bf7a080d08), [`d0c7bea`](https://github.com/atlassian-labs/atlaspack/commit/d0c7bea04458255b4c5d4299600e734b5f919fe1), [`1086c6a`](https://github.com/atlassian-labs/atlaspack/commit/1086c6a2c59271b63b3fb78e6acdb9d3a0dbf354), [`9cd9521`](https://github.com/atlassian-labs/atlaspack/commit/9cd9521978f783046e2ae4ce78f2de7aeb07d073), [`5776be2`](https://github.com/atlassian-labs/atlaspack/commit/5776be21f70a3f2b9471ba33da3ba1a883f21f1a)]:
18
+ - @atlaspack/rust@3.9.0
19
+ - @atlaspack/utils@3.1.0
20
+ - @atlaspack/types-internal@2.20.6
21
+ - @atlaspack/plugin@2.14.36
22
+
23
+ ## 2.14.35
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [[`79a7e22`](https://github.com/atlassian-labs/atlaspack/commit/79a7e22ef119891a2f4180a9d3cc66b38dd52092), [`c372f3f`](https://github.com/atlassian-labs/atlaspack/commit/c372f3fd6fce8200d5cf47f41bc7895c6cbb5558), [`17dfea9`](https://github.com/atlassian-labs/atlaspack/commit/17dfea9e9f3169807808520df9c09ebf70dc8b10), [`27fd73f`](https://github.com/atlassian-labs/atlaspack/commit/27fd73fa07d358653f1be6f2d15d72dc5d8fc2fd), [`3091fa3`](https://github.com/atlassian-labs/atlaspack/commit/3091fa36425ecffe3938e55247a035b08cda37a2)]:
28
+ - @atlaspack/rust@3.8.3
29
+ - @atlaspack/types-internal@2.20.5
30
+ - @atlaspack/utils@3.0.3
31
+ - @atlaspack/plugin@2.14.35
32
+
33
+ ## 2.14.34
34
+
35
+ ### Patch Changes
36
+
37
+ - Updated dependencies []:
38
+ - @atlaspack/types-internal@2.20.4
39
+ - @atlaspack/utils@3.0.2
40
+ - @atlaspack/plugin@2.14.34
41
+
42
+ ## 2.14.33
43
+
44
+ ### Patch Changes
45
+
46
+ - Updated dependencies [[`236e546`](https://github.com/atlassian-labs/atlaspack/commit/236e5465863dca6044a7191e05260a5b924c342e)]:
47
+ - @atlaspack/utils@3.0.1
48
+ - @atlaspack/types-internal@2.20.3
49
+ - @atlaspack/plugin@2.14.33
50
+
51
+ ## 2.14.32
52
+
53
+ ### Patch Changes
54
+
55
+ - Updated dependencies [[`0207171`](https://github.com/atlassian-labs/atlaspack/commit/0207171e59e985c51e105aec2e0a99de174374bd), [`bbe4e28`](https://github.com/atlassian-labs/atlaspack/commit/bbe4e28c89e5e9284bd730075d4d6f2a3cb37b21), [`1180103`](https://github.com/atlassian-labs/atlaspack/commit/118010351ed444f8178988afb3f77807154dd933)]:
56
+ - @atlaspack/rust@3.8.2
57
+ - @atlaspack/utils@3.0.0
58
+ - @atlaspack/types-internal@2.20.2
59
+ - @atlaspack/plugin@2.14.32
60
+
61
+ ## 2.14.31
62
+
63
+ ### Patch Changes
64
+
65
+ - [#785](https://github.com/atlassian-labs/atlaspack/pull/785) [`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922) Thanks [@matt-koko](https://github.com/matt-koko)! - We need to re-publish every package in Atlaspack with the corrected types field.
66
+
67
+ - Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922), [`686a398`](https://github.com/atlassian-labs/atlaspack/commit/686a398faa1f9e19cbf9274add2c46e246bafba8)]:
68
+ - @atlaspack/diagnostic@2.14.4
69
+ - @atlaspack/plugin@2.14.31
70
+ - @atlaspack/rust@3.8.1
71
+ - @atlaspack/types-internal@2.20.1
72
+ - @atlaspack/utils@2.19.3
73
+
74
+ ## 2.14.30
75
+
76
+ ### Patch Changes
77
+
78
+ - Updated dependencies [[`eedcbc4`](https://github.com/atlassian-labs/atlaspack/commit/eedcbc408fc1e86a2a8e25f1a41c57146d8529e1), [`5a0363f`](https://github.com/atlassian-labs/atlaspack/commit/5a0363f1086e81068959b87e92064bed5a11a9b4), [`038e87a`](https://github.com/atlassian-labs/atlaspack/commit/038e87a7858d39556d59d3a2d17db534d45f62c6), [`f6532d7`](https://github.com/atlassian-labs/atlaspack/commit/f6532d7a4f7f007bd4e5e36af04dd466f0b9f572), [`0684997`](https://github.com/atlassian-labs/atlaspack/commit/0684997c127a6204af1376b36e556fddd1ba5557), [`602f8ed`](https://github.com/atlassian-labs/atlaspack/commit/602f8ed9d8381301df8b2cc82c1d5cf6f2f94fec)]:
79
+ - @atlaspack/types-internal@2.20.0
80
+ - @atlaspack/rust@3.8.0
81
+ - @atlaspack/utils@2.19.2
82
+ - @atlaspack/plugin@2.14.30
83
+
84
+ ## 2.14.29
85
+
86
+ ### Patch Changes
87
+
88
+ - Updated dependencies [[`53dd47b`](https://github.com/atlassian-labs/atlaspack/commit/53dd47bd6d23cd47f87297347f03a609ab38a03d)]:
89
+ - @atlaspack/rust@3.7.0
90
+ - @atlaspack/types-internal@2.19.5
91
+ - @atlaspack/utils@2.19.1
92
+ - @atlaspack/plugin@2.14.29
93
+
94
+ ## 2.14.28
95
+
96
+ ### Patch Changes
97
+
98
+ - Updated dependencies [[`f0349a6`](https://github.com/atlassian-labs/atlaspack/commit/f0349a6b9b04755088f121095ca6301a2ada3767)]:
99
+ - @atlaspack/utils@2.19.0
100
+ - @atlaspack/types-internal@2.19.4
101
+ - @atlaspack/plugin@2.14.28
102
+
103
+ ## 2.14.27
104
+
105
+ ### Patch Changes
106
+
107
+ - Updated dependencies [[`3cfb7cf`](https://github.com/atlassian-labs/atlaspack/commit/3cfb7cfd90b78a5c48ce717e779ff789769825a3)]:
108
+ - @atlaspack/rust@3.6.2
109
+ - @atlaspack/types-internal@2.19.3
110
+ - @atlaspack/utils@2.18.4
111
+ - @atlaspack/plugin@2.14.27
112
+
113
+ ## 2.14.26
114
+
115
+ ### Patch Changes
116
+
117
+ - [#742](https://github.com/atlassian-labs/atlaspack/pull/742) [`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd) Thanks [@yamadapc](https://github.com/yamadapc)! - Internal changes and bug fixes to environmentDeduplication flag
118
+
119
+ - Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd), [`889c65c`](https://github.com/atlassian-labs/atlaspack/commit/889c65cd25b811045e26a117e7404f694dde77a2)]:
120
+ - @atlaspack/types-internal@2.19.2
121
+ - @atlaspack/diagnostic@2.14.3
122
+ - @atlaspack/plugin@2.14.26
123
+ - @atlaspack/utils@2.18.3
124
+ - @atlaspack/rust@3.6.1
125
+
126
+ ## 2.14.25
127
+
128
+ ### Patch Changes
129
+
130
+ - Updated dependencies []:
131
+ - @atlaspack/types-internal@2.19.1
132
+ - @atlaspack/utils@2.18.2
133
+ - @atlaspack/plugin@2.14.25
134
+
135
+ ## 2.14.24
136
+
137
+ ### Patch Changes
138
+
139
+ - Updated dependencies [[`ad26146`](https://github.com/atlassian-labs/atlaspack/commit/ad26146f13b4c1cc65d4a0f9c67060b90ef14ff3), [`f1b48e7`](https://github.com/atlassian-labs/atlaspack/commit/f1b48e7a04e005cef0f36a3e692087a9ecdb6f7a), [`7f5841c`](https://github.com/atlassian-labs/atlaspack/commit/7f5841c39df049f9546cccbeea2a7337e0337b45)]:
140
+ - @atlaspack/rust@3.6.0
141
+ - @atlaspack/types-internal@2.19.0
142
+ - @atlaspack/utils@2.18.1
143
+ - @atlaspack/plugin@2.14.24
144
+
145
+ ## 2.14.23
146
+
147
+ ### Patch Changes
148
+
149
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
150
+ - @atlaspack/utils@2.18.0
151
+ - @atlaspack/rust@3.5.0
152
+ - @atlaspack/plugin@2.14.23
153
+
154
+ ## 2.14.22
155
+
156
+ ### Patch Changes
157
+
158
+ - [#720](https://github.com/atlassian-labs/atlaspack/pull/720) [`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94) Thanks [@alshdavid](https://github.com/alshdavid)! - Migrate to TypeScript
159
+
160
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94)]:
161
+ - @atlaspack/diagnostic@2.14.2
162
+ - @atlaspack/plugin@2.14.22
163
+ - @atlaspack/utils@2.17.4
164
+ - @atlaspack/rust@3.4.2
165
+
166
+ ## 2.14.21
167
+
168
+ ### Patch Changes
169
+
170
+ - Updated dependencies []:
171
+ - @atlaspack/utils@2.17.3
172
+ - @atlaspack/plugin@2.14.21
173
+
174
+ ## 2.14.20
175
+
176
+ ### Patch Changes
177
+
178
+ - [#702](https://github.com/atlassian-labs/atlaspack/pull/702) [`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa) Thanks [@alshdavid](https://github.com/alshdavid)! - Fixes to Flow types
179
+
180
+ - Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa)]:
181
+ - @atlaspack/plugin@2.14.20
182
+ - @atlaspack/utils@2.17.2
183
+
184
+ ## 2.14.19
185
+
186
+ ### Patch Changes
187
+
188
+ - Updated dependencies []:
189
+ - @atlaspack/utils@2.17.1
190
+ - @atlaspack/plugin@2.14.19
191
+
192
+ ## 2.14.18
193
+
194
+ ### Patch Changes
195
+
196
+ - Updated dependencies [[`dbb4072`](https://github.com/atlassian-labs/atlaspack/commit/dbb40721ebeb45990a14ba04e6b44e7f836fb32d), [`becf977`](https://github.com/atlassian-labs/atlaspack/commit/becf977f625d5ee46dae3d4c679f173bf5f40cc0), [`f0f7c71`](https://github.com/atlassian-labs/atlaspack/commit/f0f7c7168a1d3d18c6f30d2daed611275692b7c5), [`de23e0c`](https://github.com/atlassian-labs/atlaspack/commit/de23e0ce49d5504fe3947ac26640a3d951087da3), [`18a57cf`](https://github.com/atlassian-labs/atlaspack/commit/18a57cf8a4789b2de5ad8e2676f317a26cc91417), [`a5ed1b4`](https://github.com/atlassian-labs/atlaspack/commit/a5ed1b414498560f393ff491af4da25b6e8dde56)]:
197
+ - @atlaspack/utils@2.17.0
198
+ - @atlaspack/rust@3.4.1
199
+ - @atlaspack/plugin@2.14.18
200
+
201
+ ## 2.14.17
202
+
203
+ ### Patch Changes
204
+
205
+ - Updated dependencies [[`c75bf55`](https://github.com/atlassian-labs/atlaspack/commit/c75bf553fff4decc285b5fd499a275853b18f8f2)]:
206
+ - @atlaspack/rust@3.4.0
207
+ - @atlaspack/utils@2.16.1
208
+ - @atlaspack/plugin@2.14.17
209
+
210
+ ## 2.14.16
211
+
212
+ ### Patch Changes
213
+
214
+ - Updated dependencies [[`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
215
+ - @atlaspack/utils@2.16.0
216
+ - @atlaspack/plugin@2.14.16
217
+
218
+ ## 2.14.15
219
+
220
+ ### Patch Changes
221
+
222
+ - Updated dependencies []:
223
+ - @atlaspack/utils@2.15.3
224
+ - @atlaspack/plugin@2.14.15
225
+
226
+ ## 2.14.14
227
+
228
+ ### Patch Changes
229
+
230
+ - Updated dependencies []:
231
+ - @atlaspack/utils@2.15.2
232
+ - @atlaspack/plugin@2.14.14
233
+
234
+ ## 2.14.13
235
+
236
+ ### Patch Changes
237
+
238
+ - Updated dependencies []:
239
+ - @atlaspack/utils@2.15.1
240
+ - @atlaspack/plugin@2.14.13
241
+
242
+ ## 2.14.12
243
+
244
+ ### Patch Changes
245
+
246
+ - Updated dependencies [[`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
247
+ - @atlaspack/utils@2.15.0
248
+ - @atlaspack/plugin@2.14.12
249
+
250
+ ## 2.14.11
251
+
252
+ ### Patch Changes
253
+
254
+ - Updated dependencies []:
255
+ - @atlaspack/utils@2.14.11
256
+ - @atlaspack/plugin@2.14.11
257
+
258
+ ## 2.14.10
259
+
260
+ ### Patch Changes
261
+
262
+ - Updated dependencies [[`35fdd4b`](https://github.com/atlassian-labs/atlaspack/commit/35fdd4b52da0af20f74667f7b8adfb2f90279b7c), [`6dd4ccb`](https://github.com/atlassian-labs/atlaspack/commit/6dd4ccb753541de32322d881f973d571dd57e4ca)]:
263
+ - @atlaspack/rust@3.3.5
264
+ - @atlaspack/plugin@2.14.10
265
+ - @atlaspack/utils@2.14.10
266
+
267
+ ## 2.14.9
268
+
269
+ ### Patch Changes
270
+
271
+ - Updated dependencies [[`124b7ff`](https://github.com/atlassian-labs/atlaspack/commit/124b7fff44f71aac9fbad289a9a9509b3dfc9aaa), [`e052521`](https://github.com/atlassian-labs/atlaspack/commit/e0525210850ed1606146eb86991049cf567c5dec), [`15c6d70`](https://github.com/atlassian-labs/atlaspack/commit/15c6d7000bd89da876bc590aa75b17a619a41896), [`e4d966c`](https://github.com/atlassian-labs/atlaspack/commit/e4d966c3c9c4292c5013372ae65b10d19d4bacc6), [`42a775d`](https://github.com/atlassian-labs/atlaspack/commit/42a775de8eec638ad188f3271964170d8c04d84b), [`29c2f10`](https://github.com/atlassian-labs/atlaspack/commit/29c2f106de9679adfb5afa04e1910471dc65a427), [`1ef91fc`](https://github.com/atlassian-labs/atlaspack/commit/1ef91fcc863fdd2831511937083dbbc1263b3d9d)]:
272
+ - @atlaspack/rust@3.3.4
273
+ - @atlaspack/utils@2.14.9
274
+ - @atlaspack/plugin@2.14.9
275
+
276
+ ## 2.14.8
277
+
278
+ ### Patch Changes
279
+
280
+ - Updated dependencies [[`1ab0a27`](https://github.com/atlassian-labs/atlaspack/commit/1ab0a275aeca40350415e2b03e7440d1dddc6228), [`b8a4ae8`](https://github.com/atlassian-labs/atlaspack/commit/b8a4ae8f83dc0a83d8b145c5f729936ce52080a3)]:
281
+ - @atlaspack/rust@3.3.3
282
+ - @atlaspack/utils@2.14.8
283
+ - @atlaspack/plugin@2.14.8
284
+
3
285
  ## 2.14.7
4
286
 
5
287
  ### Patch Changes
@@ -0,0 +1,281 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const rust_1 = require("@atlaspack/rust");
7
+ const utils_1 = require("@atlaspack/utils");
8
+ const plugin_1 = require("@atlaspack/plugin");
9
+ const nullthrows_1 = __importDefault(require("nullthrows"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const semver_1 = __importDefault(require("semver"));
12
+ const postcss_value_parser_1 = __importDefault(require("postcss-value-parser"));
13
+ const loadConfig_1 = require("./loadConfig");
14
+ const constants_1 = require("./constants");
15
+ const diagnostic_1 = require("@atlaspack/diagnostic");
16
+ const COMPOSES_RE = /composes:.+from\s*("|').*("|')\s*;?/;
17
+ const FROM_IMPORT_RE = /.+from\s*(?:"|')(.*)(?:"|')\s*;?/;
18
+ const LEGACY_MODULE_RE = /@value|:export|(:global|:local|:import)(?!\s*\()/i;
19
+ const MODULE_BY_NAME_RE = /\.module\./;
20
+ exports.default = new plugin_1.Transformer({
21
+ loadConfig({ config, options, logger }) {
22
+ return (0, loadConfig_1.load)({ config, options, logger });
23
+ },
24
+ canReuseAST({ ast }) {
25
+ return (ast.type === 'postcss' && semver_1.default.satisfies(ast.version, constants_1.POSTCSS_RANGE));
26
+ },
27
+ async parse({ asset, config, options }) {
28
+ let isLegacy = await isLegacyCssModule(asset);
29
+ if (!config && !isLegacy) {
30
+ return;
31
+ }
32
+ const postcss = await loadPostcss(options, asset.filePath);
33
+ return {
34
+ type: 'postcss',
35
+ version: '8.2.1',
36
+ program: postcss
37
+ .parse(await asset.getCode(), {
38
+ from: asset.filePath,
39
+ })
40
+ .toJSON(),
41
+ };
42
+ },
43
+ async transform({ asset, config, options, resolve, logger }) {
44
+ asset.type = 'css';
45
+ let isLegacy = await isLegacyCssModule(asset);
46
+ if (isLegacy && !config) {
47
+ config = {
48
+ raw: {},
49
+ filePath: '',
50
+ hydrated: {
51
+ plugins: [],
52
+ from: asset.filePath,
53
+ to: asset.filePath,
54
+ modules: {},
55
+ },
56
+ };
57
+ // TODO: warning?
58
+ }
59
+ if (!config) {
60
+ return [asset];
61
+ }
62
+ // @ts-expect-error TS2709
63
+ const postcss = await loadPostcss(options, asset.filePath);
64
+ let ast = (0, nullthrows_1.default)(await asset.getAST());
65
+ let program = postcss.fromJSON(ast.program);
66
+ let plugins = [...config.hydrated.plugins];
67
+ let cssModules = null;
68
+ if (config.hydrated.modules) {
69
+ asset.meta.cssModulesCompiled = 'postcss';
70
+ let code = asset.isASTDirty() ? null : await asset.getCode();
71
+ if (Object.keys(config.hydrated.modules).length === 0 &&
72
+ code &&
73
+ !isLegacy &&
74
+ !LEGACY_MODULE_RE.test(code)) {
75
+ let filename = path_1.default.basename(config.filePath);
76
+ let message;
77
+ let configKey;
78
+ let hint;
79
+ if (config.raw.modules) {
80
+ message = (0, diagnostic_1.md) `The "modules" option in __${filename}__ can be replaced with configuration for @atlaspack/transformer-css to improve build performance.`;
81
+ configKey = '/modules';
82
+ hint = (0, diagnostic_1.md) `Remove the "modules" option from __${filename}__`;
83
+ }
84
+ else {
85
+ message = (0, diagnostic_1.md) `The "postcss-modules" plugin in __${filename}__ can be replaced with configuration for @atlaspack/transformer-css to improve build performance.`;
86
+ configKey = '/plugins/postcss-modules';
87
+ hint = (0, diagnostic_1.md) `Remove the "postcss-modules" plugin from __${filename}__`;
88
+ }
89
+ if (filename === 'package.json') {
90
+ configKey = `/postcss${configKey}`;
91
+ }
92
+ let hints = [
93
+ 'Enable the "cssModules" option for "@atlaspack/transformer-css" in your package.json',
94
+ ];
95
+ if (plugins.length === 0) {
96
+ message += (0, diagnostic_1.md) ` Since there are no other plugins, __${filename}__ can be deleted safely.`;
97
+ hints.push((0, diagnostic_1.md) `Delete __${filename}__`);
98
+ }
99
+ else {
100
+ hints.push(hint);
101
+ }
102
+ let codeFrames;
103
+ if (path_1.default.extname(filename) !== '.js') {
104
+ let contents = await asset.fs.readFile(config.filePath, 'utf8');
105
+ codeFrames = [
106
+ {
107
+ language: 'json',
108
+ filePath: config.filePath,
109
+ code: contents,
110
+ codeHighlights: (0, diagnostic_1.generateJSONCodeHighlights)(contents, [
111
+ {
112
+ key: configKey,
113
+ type: 'key',
114
+ },
115
+ ]),
116
+ },
117
+ ];
118
+ }
119
+ else {
120
+ codeFrames = [
121
+ {
122
+ filePath: config.filePath,
123
+ codeHighlights: [
124
+ {
125
+ start: { line: 1, column: 1 },
126
+ end: { line: 1, column: 1 },
127
+ },
128
+ ],
129
+ },
130
+ ];
131
+ }
132
+ logger.warn({
133
+ message,
134
+ hints,
135
+ documentationURL: 'https://parceljs.org/languages/css/#enabling-css-modules-globally',
136
+ codeFrames,
137
+ });
138
+ }
139
+ // TODO: should this be resolved from the project root?
140
+ let postcssModules = await options.packageManager.require('postcss-modules', asset.filePath, {
141
+ range: '^4.3.0',
142
+ saveDev: true,
143
+ shouldAutoInstall: options.shouldAutoInstall,
144
+ });
145
+ plugins.push(postcssModules({
146
+ // @ts-expect-error TS7006
147
+ getJSON: (filename, json) => (cssModules = json),
148
+ Loader: await createLoader(asset, resolve, options),
149
+ // @ts-expect-error TS7006
150
+ generateScopedName: (name, filename) => `${name}_${(0, rust_1.hashString)(path_1.default.relative(options.projectRoot, filename)).substr(0, 6)}`,
151
+ ...config.hydrated.modules,
152
+ }));
153
+ if (code == null || COMPOSES_RE.test(code)) {
154
+ // @ts-expect-error TS7006
155
+ program.walkDecls((decl) => {
156
+ let [, importPath] = FROM_IMPORT_RE.exec(decl.value) || [];
157
+ if (decl.prop === 'composes' && importPath != null) {
158
+ let parsed = (0, postcss_value_parser_1.default)(decl.value);
159
+ parsed.walk((node) => {
160
+ if (node.type === 'string') {
161
+ asset.addDependency({
162
+ specifier: importPath,
163
+ specifierType: 'url',
164
+ loc: {
165
+ filePath: asset.filePath,
166
+ start: decl.source.start,
167
+ end: {
168
+ line: decl.source.start.line,
169
+ column: decl.source.start.column + importPath.length,
170
+ },
171
+ },
172
+ });
173
+ }
174
+ });
175
+ }
176
+ });
177
+ }
178
+ }
179
+ let { messages, root } = await postcss(plugins).process(program, config.hydrated);
180
+ asset.setAST({
181
+ type: 'postcss',
182
+ version: '8.2.1',
183
+ program: root.toJSON(),
184
+ });
185
+ for (let msg of messages) {
186
+ if (msg.type === 'dependency') {
187
+ asset.invalidateOnFileChange(msg.file);
188
+ }
189
+ else if (msg.type === 'dir-dependency') {
190
+ let pattern = `${msg.dir}/${msg.glob ?? '**/*'}`;
191
+ let files = await (0, utils_1.glob)(pattern, asset.fs, { onlyFiles: true });
192
+ for (let file of files) {
193
+ asset.invalidateOnFileChange(path_1.default.normalize(file));
194
+ }
195
+ asset.invalidateOnFileCreate({ glob: pattern });
196
+ }
197
+ }
198
+ let assets = [asset];
199
+ if (cssModules) {
200
+ let cssModulesList = Object.entries(cssModules);
201
+ let deps = asset
202
+ .getDependencies()
203
+ .filter((dep) => dep.priority === 'sync');
204
+ let code;
205
+ if (deps.length > 0) {
206
+ code = `
207
+ module.exports = Object.assign({}, ${deps
208
+ .map((dep) => `require(${JSON.stringify(dep.specifier)})`)
209
+ .join(', ')}, ${JSON.stringify(cssModules, null, 2)});
210
+ `;
211
+ }
212
+ else {
213
+ code = cssModulesList
214
+ .map(
215
+ // This syntax enables shaking the invidual statements, so that unused classes don't even exist in JS.
216
+ ([className, classNameHashed]) => `module.exports[${JSON.stringify(className)}] = ${JSON.stringify(classNameHashed)};`)
217
+ .join('\n');
218
+ }
219
+ asset.symbols.ensure();
220
+ for (let [k, v] of cssModulesList) {
221
+ asset.symbols.set(k, v);
222
+ }
223
+ asset.symbols.set('default', 'default');
224
+ assets.push({
225
+ type: 'js',
226
+ // @ts-expect-error TS2353
227
+ content: code,
228
+ });
229
+ }
230
+ return assets;
231
+ },
232
+ async generate({ asset, ast, options }) {
233
+ // @ts-expect-error TS2709
234
+ const postcss = await loadPostcss(options, asset.filePath);
235
+ let code = '';
236
+ // @ts-expect-error TS7006
237
+ postcss.stringify(postcss.fromJSON(ast.program), (c) => {
238
+ code += c;
239
+ });
240
+ return {
241
+ content: code,
242
+ };
243
+ },
244
+ });
245
+ async function createLoader(asset, resolve, options) {
246
+ let { default: FileSystemLoader } = await options.packageManager.require('postcss-modules/build/css-loader-core/loader', asset.filePath);
247
+ return class AtlaspackFileSystemLoader extends FileSystemLoader {
248
+ async fetch(composesPath, relativeTo) {
249
+ let importPath = composesPath.replace(/^["']|["']$/g, '');
250
+ let resolved = await resolve(relativeTo, importPath);
251
+ let rootRelativePath = path_1.default.resolve(path_1.default.dirname(relativeTo), resolved);
252
+ let root = path_1.default.resolve('/');
253
+ // fixes an issue on windows which is part of the css-modules-loader-core
254
+ // see https://github.com/css-modules/css-modules-loader-core/issues/230
255
+ if (rootRelativePath.startsWith(root)) {
256
+ rootRelativePath = rootRelativePath.substr(root.length);
257
+ }
258
+ let source = await asset.fs.readFile(resolved, 'utf-8');
259
+ let { exportTokens } = await this.core.load(source, rootRelativePath, undefined, this.fetch.bind(this));
260
+ return exportTokens;
261
+ }
262
+ get finalSource() {
263
+ return '';
264
+ }
265
+ };
266
+ }
267
+ // @ts-expect-error TS2709
268
+ function loadPostcss(options, from) {
269
+ return options.packageManager.require('postcss', from, {
270
+ range: constants_1.POSTCSS_RANGE,
271
+ saveDev: true,
272
+ shouldAutoInstall: options.shouldAutoInstall,
273
+ });
274
+ }
275
+ async function isLegacyCssModule(asset) {
276
+ if (!MODULE_BY_NAME_RE.test(asset.filePath)) {
277
+ return false;
278
+ }
279
+ let code = await asset.getCode();
280
+ return LEGACY_MODULE_RE.test(code);
281
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.POSTCSS_RANGE = void 0;
4
+ exports.POSTCSS_RANGE = '^8.2.1';