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

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,277 @@
1
1
  # @atlaspack/transformer-postcss
2
2
 
3
+ ## 2.14.36
4
+
5
+ ### Patch Changes
6
+
7
+ - 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)]:
8
+ - @atlaspack/rust@3.9.0
9
+ - @atlaspack/utils@3.1.0
10
+ - @atlaspack/types-internal@2.20.6
11
+ - @atlaspack/plugin@2.14.36
12
+
13
+ ## 2.14.35
14
+
15
+ ### Patch Changes
16
+
17
+ - 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)]:
18
+ - @atlaspack/rust@3.8.3
19
+ - @atlaspack/types-internal@2.20.5
20
+ - @atlaspack/utils@3.0.3
21
+ - @atlaspack/plugin@2.14.35
22
+
23
+ ## 2.14.34
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies []:
28
+ - @atlaspack/types-internal@2.20.4
29
+ - @atlaspack/utils@3.0.2
30
+ - @atlaspack/plugin@2.14.34
31
+
32
+ ## 2.14.33
33
+
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies [[`236e546`](https://github.com/atlassian-labs/atlaspack/commit/236e5465863dca6044a7191e05260a5b924c342e)]:
37
+ - @atlaspack/utils@3.0.1
38
+ - @atlaspack/types-internal@2.20.3
39
+ - @atlaspack/plugin@2.14.33
40
+
41
+ ## 2.14.32
42
+
43
+ ### Patch Changes
44
+
45
+ - 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)]:
46
+ - @atlaspack/rust@3.8.2
47
+ - @atlaspack/utils@3.0.0
48
+ - @atlaspack/types-internal@2.20.2
49
+ - @atlaspack/plugin@2.14.32
50
+
51
+ ## 2.14.31
52
+
53
+ ### Patch Changes
54
+
55
+ - [#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.
56
+
57
+ - Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922), [`686a398`](https://github.com/atlassian-labs/atlaspack/commit/686a398faa1f9e19cbf9274add2c46e246bafba8)]:
58
+ - @atlaspack/diagnostic@2.14.4
59
+ - @atlaspack/plugin@2.14.31
60
+ - @atlaspack/rust@3.8.1
61
+ - @atlaspack/types-internal@2.20.1
62
+ - @atlaspack/utils@2.19.3
63
+
64
+ ## 2.14.30
65
+
66
+ ### Patch Changes
67
+
68
+ - 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)]:
69
+ - @atlaspack/types-internal@2.20.0
70
+ - @atlaspack/rust@3.8.0
71
+ - @atlaspack/utils@2.19.2
72
+ - @atlaspack/plugin@2.14.30
73
+
74
+ ## 2.14.29
75
+
76
+ ### Patch Changes
77
+
78
+ - Updated dependencies [[`53dd47b`](https://github.com/atlassian-labs/atlaspack/commit/53dd47bd6d23cd47f87297347f03a609ab38a03d)]:
79
+ - @atlaspack/rust@3.7.0
80
+ - @atlaspack/types-internal@2.19.5
81
+ - @atlaspack/utils@2.19.1
82
+ - @atlaspack/plugin@2.14.29
83
+
84
+ ## 2.14.28
85
+
86
+ ### Patch Changes
87
+
88
+ - Updated dependencies [[`f0349a6`](https://github.com/atlassian-labs/atlaspack/commit/f0349a6b9b04755088f121095ca6301a2ada3767)]:
89
+ - @atlaspack/utils@2.19.0
90
+ - @atlaspack/types-internal@2.19.4
91
+ - @atlaspack/plugin@2.14.28
92
+
93
+ ## 2.14.27
94
+
95
+ ### Patch Changes
96
+
97
+ - Updated dependencies [[`3cfb7cf`](https://github.com/atlassian-labs/atlaspack/commit/3cfb7cfd90b78a5c48ce717e779ff789769825a3)]:
98
+ - @atlaspack/rust@3.6.2
99
+ - @atlaspack/types-internal@2.19.3
100
+ - @atlaspack/utils@2.18.4
101
+ - @atlaspack/plugin@2.14.27
102
+
103
+ ## 2.14.26
104
+
105
+ ### Patch Changes
106
+
107
+ - [#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
108
+
109
+ - Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd), [`889c65c`](https://github.com/atlassian-labs/atlaspack/commit/889c65cd25b811045e26a117e7404f694dde77a2)]:
110
+ - @atlaspack/types-internal@2.19.2
111
+ - @atlaspack/diagnostic@2.14.3
112
+ - @atlaspack/plugin@2.14.26
113
+ - @atlaspack/utils@2.18.3
114
+ - @atlaspack/rust@3.6.1
115
+
116
+ ## 2.14.25
117
+
118
+ ### Patch Changes
119
+
120
+ - Updated dependencies []:
121
+ - @atlaspack/types-internal@2.19.1
122
+ - @atlaspack/utils@2.18.2
123
+ - @atlaspack/plugin@2.14.25
124
+
125
+ ## 2.14.24
126
+
127
+ ### Patch Changes
128
+
129
+ - 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)]:
130
+ - @atlaspack/rust@3.6.0
131
+ - @atlaspack/types-internal@2.19.0
132
+ - @atlaspack/utils@2.18.1
133
+ - @atlaspack/plugin@2.14.24
134
+
135
+ ## 2.14.23
136
+
137
+ ### Patch Changes
138
+
139
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
140
+ - @atlaspack/utils@2.18.0
141
+ - @atlaspack/rust@3.5.0
142
+ - @atlaspack/plugin@2.14.23
143
+
144
+ ## 2.14.22
145
+
146
+ ### Patch Changes
147
+
148
+ - [#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
149
+
150
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94)]:
151
+ - @atlaspack/diagnostic@2.14.2
152
+ - @atlaspack/plugin@2.14.22
153
+ - @atlaspack/utils@2.17.4
154
+ - @atlaspack/rust@3.4.2
155
+
156
+ ## 2.14.21
157
+
158
+ ### Patch Changes
159
+
160
+ - Updated dependencies []:
161
+ - @atlaspack/utils@2.17.3
162
+ - @atlaspack/plugin@2.14.21
163
+
164
+ ## 2.14.20
165
+
166
+ ### Patch Changes
167
+
168
+ - [#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
169
+
170
+ - Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa)]:
171
+ - @atlaspack/plugin@2.14.20
172
+ - @atlaspack/utils@2.17.2
173
+
174
+ ## 2.14.19
175
+
176
+ ### Patch Changes
177
+
178
+ - Updated dependencies []:
179
+ - @atlaspack/utils@2.17.1
180
+ - @atlaspack/plugin@2.14.19
181
+
182
+ ## 2.14.18
183
+
184
+ ### Patch Changes
185
+
186
+ - 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)]:
187
+ - @atlaspack/utils@2.17.0
188
+ - @atlaspack/rust@3.4.1
189
+ - @atlaspack/plugin@2.14.18
190
+
191
+ ## 2.14.17
192
+
193
+ ### Patch Changes
194
+
195
+ - Updated dependencies [[`c75bf55`](https://github.com/atlassian-labs/atlaspack/commit/c75bf553fff4decc285b5fd499a275853b18f8f2)]:
196
+ - @atlaspack/rust@3.4.0
197
+ - @atlaspack/utils@2.16.1
198
+ - @atlaspack/plugin@2.14.17
199
+
200
+ ## 2.14.16
201
+
202
+ ### Patch Changes
203
+
204
+ - Updated dependencies [[`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
205
+ - @atlaspack/utils@2.16.0
206
+ - @atlaspack/plugin@2.14.16
207
+
208
+ ## 2.14.15
209
+
210
+ ### Patch Changes
211
+
212
+ - Updated dependencies []:
213
+ - @atlaspack/utils@2.15.3
214
+ - @atlaspack/plugin@2.14.15
215
+
216
+ ## 2.14.14
217
+
218
+ ### Patch Changes
219
+
220
+ - Updated dependencies []:
221
+ - @atlaspack/utils@2.15.2
222
+ - @atlaspack/plugin@2.14.14
223
+
224
+ ## 2.14.13
225
+
226
+ ### Patch Changes
227
+
228
+ - Updated dependencies []:
229
+ - @atlaspack/utils@2.15.1
230
+ - @atlaspack/plugin@2.14.13
231
+
232
+ ## 2.14.12
233
+
234
+ ### Patch Changes
235
+
236
+ - Updated dependencies [[`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
237
+ - @atlaspack/utils@2.15.0
238
+ - @atlaspack/plugin@2.14.12
239
+
240
+ ## 2.14.11
241
+
242
+ ### Patch Changes
243
+
244
+ - Updated dependencies []:
245
+ - @atlaspack/utils@2.14.11
246
+ - @atlaspack/plugin@2.14.11
247
+
248
+ ## 2.14.10
249
+
250
+ ### Patch Changes
251
+
252
+ - Updated dependencies [[`35fdd4b`](https://github.com/atlassian-labs/atlaspack/commit/35fdd4b52da0af20f74667f7b8adfb2f90279b7c), [`6dd4ccb`](https://github.com/atlassian-labs/atlaspack/commit/6dd4ccb753541de32322d881f973d571dd57e4ca)]:
253
+ - @atlaspack/rust@3.3.5
254
+ - @atlaspack/plugin@2.14.10
255
+ - @atlaspack/utils@2.14.10
256
+
257
+ ## 2.14.9
258
+
259
+ ### Patch Changes
260
+
261
+ - 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)]:
262
+ - @atlaspack/rust@3.3.4
263
+ - @atlaspack/utils@2.14.9
264
+ - @atlaspack/plugin@2.14.9
265
+
266
+ ## 2.14.8
267
+
268
+ ### Patch Changes
269
+
270
+ - Updated dependencies [[`1ab0a27`](https://github.com/atlassian-labs/atlaspack/commit/1ab0a275aeca40350415e2b03e7440d1dddc6228), [`b8a4ae8`](https://github.com/atlassian-labs/atlaspack/commit/b8a4ae8f83dc0a83d8b145c5f729936ce52080a3)]:
271
+ - @atlaspack/rust@3.3.3
272
+ - @atlaspack/utils@2.14.8
273
+ - @atlaspack/plugin@2.14.8
274
+
3
275
  ## 2.14.7
4
276
 
5
277
  ### 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';