@atlaspack/transformer-postcss 2.14.5-canary.21 → 2.14.5-canary.211

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,239 @@
1
1
  # @atlaspack/transformer-postcss
2
2
 
3
+ ## 2.14.32
4
+
5
+ ### Patch Changes
6
+
7
+ - 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)]:
8
+ - @atlaspack/rust@3.8.2
9
+ - @atlaspack/utils@3.0.0
10
+ - @atlaspack/types-internal@2.20.2
11
+ - @atlaspack/plugin@2.14.32
12
+
13
+ ## 2.14.31
14
+
15
+ ### Patch Changes
16
+
17
+ - [#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.
18
+
19
+ - Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922), [`686a398`](https://github.com/atlassian-labs/atlaspack/commit/686a398faa1f9e19cbf9274add2c46e246bafba8)]:
20
+ - @atlaspack/diagnostic@2.14.4
21
+ - @atlaspack/plugin@2.14.31
22
+ - @atlaspack/rust@3.8.1
23
+ - @atlaspack/types-internal@2.20.1
24
+ - @atlaspack/utils@2.19.3
25
+
26
+ ## 2.14.30
27
+
28
+ ### Patch Changes
29
+
30
+ - 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)]:
31
+ - @atlaspack/types-internal@2.20.0
32
+ - @atlaspack/rust@3.8.0
33
+ - @atlaspack/utils@2.19.2
34
+ - @atlaspack/plugin@2.14.30
35
+
36
+ ## 2.14.29
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [[`53dd47b`](https://github.com/atlassian-labs/atlaspack/commit/53dd47bd6d23cd47f87297347f03a609ab38a03d)]:
41
+ - @atlaspack/rust@3.7.0
42
+ - @atlaspack/types-internal@2.19.5
43
+ - @atlaspack/utils@2.19.1
44
+ - @atlaspack/plugin@2.14.29
45
+
46
+ ## 2.14.28
47
+
48
+ ### Patch Changes
49
+
50
+ - Updated dependencies [[`f0349a6`](https://github.com/atlassian-labs/atlaspack/commit/f0349a6b9b04755088f121095ca6301a2ada3767)]:
51
+ - @atlaspack/utils@2.19.0
52
+ - @atlaspack/types-internal@2.19.4
53
+ - @atlaspack/plugin@2.14.28
54
+
55
+ ## 2.14.27
56
+
57
+ ### Patch Changes
58
+
59
+ - Updated dependencies [[`3cfb7cf`](https://github.com/atlassian-labs/atlaspack/commit/3cfb7cfd90b78a5c48ce717e779ff789769825a3)]:
60
+ - @atlaspack/rust@3.6.2
61
+ - @atlaspack/types-internal@2.19.3
62
+ - @atlaspack/utils@2.18.4
63
+ - @atlaspack/plugin@2.14.27
64
+
65
+ ## 2.14.26
66
+
67
+ ### Patch Changes
68
+
69
+ - [#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
70
+
71
+ - Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd), [`889c65c`](https://github.com/atlassian-labs/atlaspack/commit/889c65cd25b811045e26a117e7404f694dde77a2)]:
72
+ - @atlaspack/types-internal@2.19.2
73
+ - @atlaspack/diagnostic@2.14.3
74
+ - @atlaspack/plugin@2.14.26
75
+ - @atlaspack/utils@2.18.3
76
+ - @atlaspack/rust@3.6.1
77
+
78
+ ## 2.14.25
79
+
80
+ ### Patch Changes
81
+
82
+ - Updated dependencies []:
83
+ - @atlaspack/types-internal@2.19.1
84
+ - @atlaspack/utils@2.18.2
85
+ - @atlaspack/plugin@2.14.25
86
+
87
+ ## 2.14.24
88
+
89
+ ### Patch Changes
90
+
91
+ - 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)]:
92
+ - @atlaspack/rust@3.6.0
93
+ - @atlaspack/types-internal@2.19.0
94
+ - @atlaspack/utils@2.18.1
95
+ - @atlaspack/plugin@2.14.24
96
+
97
+ ## 2.14.23
98
+
99
+ ### Patch Changes
100
+
101
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
102
+ - @atlaspack/utils@2.18.0
103
+ - @atlaspack/rust@3.5.0
104
+ - @atlaspack/plugin@2.14.23
105
+
106
+ ## 2.14.22
107
+
108
+ ### Patch Changes
109
+
110
+ - [#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
111
+
112
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94)]:
113
+ - @atlaspack/diagnostic@2.14.2
114
+ - @atlaspack/plugin@2.14.22
115
+ - @atlaspack/utils@2.17.4
116
+ - @atlaspack/rust@3.4.2
117
+
118
+ ## 2.14.21
119
+
120
+ ### Patch Changes
121
+
122
+ - Updated dependencies []:
123
+ - @atlaspack/utils@2.17.3
124
+ - @atlaspack/plugin@2.14.21
125
+
126
+ ## 2.14.20
127
+
128
+ ### Patch Changes
129
+
130
+ - [#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
131
+
132
+ - Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa)]:
133
+ - @atlaspack/plugin@2.14.20
134
+ - @atlaspack/utils@2.17.2
135
+
136
+ ## 2.14.19
137
+
138
+ ### Patch Changes
139
+
140
+ - Updated dependencies []:
141
+ - @atlaspack/utils@2.17.1
142
+ - @atlaspack/plugin@2.14.19
143
+
144
+ ## 2.14.18
145
+
146
+ ### Patch Changes
147
+
148
+ - 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)]:
149
+ - @atlaspack/utils@2.17.0
150
+ - @atlaspack/rust@3.4.1
151
+ - @atlaspack/plugin@2.14.18
152
+
153
+ ## 2.14.17
154
+
155
+ ### Patch Changes
156
+
157
+ - Updated dependencies [[`c75bf55`](https://github.com/atlassian-labs/atlaspack/commit/c75bf553fff4decc285b5fd499a275853b18f8f2)]:
158
+ - @atlaspack/rust@3.4.0
159
+ - @atlaspack/utils@2.16.1
160
+ - @atlaspack/plugin@2.14.17
161
+
162
+ ## 2.14.16
163
+
164
+ ### Patch Changes
165
+
166
+ - Updated dependencies [[`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
167
+ - @atlaspack/utils@2.16.0
168
+ - @atlaspack/plugin@2.14.16
169
+
170
+ ## 2.14.15
171
+
172
+ ### Patch Changes
173
+
174
+ - Updated dependencies []:
175
+ - @atlaspack/utils@2.15.3
176
+ - @atlaspack/plugin@2.14.15
177
+
178
+ ## 2.14.14
179
+
180
+ ### Patch Changes
181
+
182
+ - Updated dependencies []:
183
+ - @atlaspack/utils@2.15.2
184
+ - @atlaspack/plugin@2.14.14
185
+
186
+ ## 2.14.13
187
+
188
+ ### Patch Changes
189
+
190
+ - Updated dependencies []:
191
+ - @atlaspack/utils@2.15.1
192
+ - @atlaspack/plugin@2.14.13
193
+
194
+ ## 2.14.12
195
+
196
+ ### Patch Changes
197
+
198
+ - Updated dependencies [[`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
199
+ - @atlaspack/utils@2.15.0
200
+ - @atlaspack/plugin@2.14.12
201
+
202
+ ## 2.14.11
203
+
204
+ ### Patch Changes
205
+
206
+ - Updated dependencies []:
207
+ - @atlaspack/utils@2.14.11
208
+ - @atlaspack/plugin@2.14.11
209
+
210
+ ## 2.14.10
211
+
212
+ ### Patch Changes
213
+
214
+ - Updated dependencies [[`35fdd4b`](https://github.com/atlassian-labs/atlaspack/commit/35fdd4b52da0af20f74667f7b8adfb2f90279b7c), [`6dd4ccb`](https://github.com/atlassian-labs/atlaspack/commit/6dd4ccb753541de32322d881f973d571dd57e4ca)]:
215
+ - @atlaspack/rust@3.3.5
216
+ - @atlaspack/plugin@2.14.10
217
+ - @atlaspack/utils@2.14.10
218
+
219
+ ## 2.14.9
220
+
221
+ ### Patch Changes
222
+
223
+ - 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)]:
224
+ - @atlaspack/rust@3.3.4
225
+ - @atlaspack/utils@2.14.9
226
+ - @atlaspack/plugin@2.14.9
227
+
228
+ ## 2.14.8
229
+
230
+ ### Patch Changes
231
+
232
+ - Updated dependencies [[`1ab0a27`](https://github.com/atlassian-labs/atlaspack/commit/1ab0a275aeca40350415e2b03e7440d1dddc6228), [`b8a4ae8`](https://github.com/atlassian-labs/atlaspack/commit/b8a4ae8f83dc0a83d8b145c5f729936ce52080a3)]:
233
+ - @atlaspack/rust@3.3.3
234
+ - @atlaspack/utils@2.14.8
235
+ - @atlaspack/plugin@2.14.8
236
+
3
237
  ## 2.14.7
4
238
 
5
239
  ### 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';
@@ -0,0 +1,149 @@
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
+ exports.load = load;
7
+ const path_1 = __importDefault(require("path"));
8
+ const diagnostic_1 = require("@atlaspack/diagnostic");
9
+ const nullthrows_1 = __importDefault(require("nullthrows"));
10
+ // @ts-expect-error TS7016
11
+ const clone_1 = __importDefault(require("clone"));
12
+ const constants_1 = require("./constants");
13
+ const loadPlugins_1 = __importDefault(require("./loadPlugins"));
14
+ async function configHydrator(configFile, config, resolveFrom, options, logger) {
15
+ if (configFile == null) {
16
+ return;
17
+ }
18
+ // Load the custom config...
19
+ let modulesConfig;
20
+ let configFilePlugins = (0, clone_1.default)(configFile.plugins);
21
+ if (configFilePlugins != null &&
22
+ typeof configFilePlugins === 'object' &&
23
+ configFilePlugins['postcss-modules'] != null) {
24
+ modulesConfig = configFilePlugins['postcss-modules'];
25
+ delete configFilePlugins['postcss-modules'];
26
+ }
27
+ if (!modulesConfig && configFile.modules) {
28
+ modulesConfig = {};
29
+ }
30
+ let plugins = await (0, loadPlugins_1.default)(configFilePlugins, (0, nullthrows_1.default)(resolveFrom), options);
31
+ // contents is either:
32
+ // from JSON: { plugins: { 'postcss-foo': { ...opts } } }
33
+ // from JS (v8): { plugins: [ { postcssPlugin: 'postcss-foo', ...visitor callback functions } ]
34
+ // from JS (v7): { plugins: [ [Function: ...] ]
35
+ let pluginArray = Array.isArray(configFilePlugins)
36
+ ? configFilePlugins
37
+ : Object.keys(configFilePlugins);
38
+ for (let p of pluginArray) {
39
+ if (typeof p === 'string') {
40
+ config.addDevDependency({
41
+ specifier: p,
42
+ resolveFrom: (0, nullthrows_1.default)(resolveFrom),
43
+ });
44
+ }
45
+ }
46
+ let redundantPlugins = pluginArray.filter((p) => p === 'autoprefixer' || p === 'postcss-preset-env');
47
+ if (redundantPlugins.length > 0) {
48
+ let filename = path_1.default.basename(resolveFrom);
49
+ let isPackageJson = filename === 'package.json';
50
+ let message;
51
+ let hints = [];
52
+ if (!isPackageJson && redundantPlugins.length === pluginArray.length) {
53
+ message = (0, diagnostic_1.md) `Parcel includes CSS transpilation and vendor prefixing by default. PostCSS config __${filename}__ contains only redundant plugins. Deleting it may significantly improve build performance.`;
54
+ hints.push((0, diagnostic_1.md) `Delete __${filename}__`);
55
+ }
56
+ else {
57
+ message = (0, diagnostic_1.md) `Parcel includes CSS transpilation and vendor prefixing by default. PostCSS config __${filename}__ contains the following redundant plugins: ${[
58
+ ...redundantPlugins,
59
+ ].map((p) => diagnostic_1.md.underline(p))}. Removing these may improve build performance.`;
60
+ hints.push((0, diagnostic_1.md) `Remove the above plugins from __${filename}__`);
61
+ }
62
+ let codeFrames;
63
+ if (path_1.default.extname(filename) !== '.js') {
64
+ let contents = await options.inputFS.readFile(resolveFrom, 'utf8');
65
+ let prefix = isPackageJson ? '/postcss' : '';
66
+ codeFrames = [
67
+ {
68
+ language: 'json',
69
+ filePath: resolveFrom,
70
+ code: contents,
71
+ codeHighlights: (0, diagnostic_1.generateJSONCodeHighlights)(contents, redundantPlugins.map((plugin) => ({
72
+ key: `${prefix}/plugins/${plugin}`,
73
+ type: 'key',
74
+ }))),
75
+ },
76
+ ];
77
+ }
78
+ else {
79
+ codeFrames = [
80
+ {
81
+ filePath: resolveFrom,
82
+ codeHighlights: [
83
+ {
84
+ start: { line: 1, column: 1 },
85
+ end: { line: 1, column: 1 },
86
+ },
87
+ ],
88
+ },
89
+ ];
90
+ }
91
+ logger.warn({
92
+ message,
93
+ hints,
94
+ documentationURL: 'https://parceljs.org/languages/css/#default-plugins',
95
+ codeFrames,
96
+ });
97
+ }
98
+ return {
99
+ raw: configFile,
100
+ filePath: resolveFrom,
101
+ hydrated: {
102
+ plugins,
103
+ from: config.searchPath,
104
+ to: config.searchPath,
105
+ modules: modulesConfig,
106
+ },
107
+ };
108
+ }
109
+ async function load({ config, options, logger, }) {
110
+ if (!config.isSource) {
111
+ return;
112
+ }
113
+ let configFile = await config.getConfig([
114
+ '.postcssrc',
115
+ '.postcssrc.json',
116
+ '.postcssrc.js',
117
+ '.postcssrc.cjs',
118
+ '.postcssrc.mjs',
119
+ 'postcss.config.js',
120
+ 'postcss.config.cjs',
121
+ 'postcss.config.mjs',
122
+ ], { packageKey: 'postcss' });
123
+ let contents = null;
124
+ if (configFile) {
125
+ config.addDevDependency({
126
+ specifier: 'postcss',
127
+ resolveFrom: config.searchPath,
128
+ range: constants_1.POSTCSS_RANGE,
129
+ });
130
+ contents = configFile.contents;
131
+ let isDynamic = configFile && path_1.default.extname(configFile.filePath).endsWith('js');
132
+ if (isDynamic) {
133
+ // We have to invalidate on startup in case the config is non-deterministic,
134
+ // e.g. using unknown environment variables, reading from the filesystem, etc.
135
+ logger.warn({
136
+ message: 'WARNING: Using a JavaScript PostCSS config file means losing out on caching features of Parcel. Use a .postcssrc(.json) file whenever possible.',
137
+ });
138
+ }
139
+ if (typeof contents !== 'object') {
140
+ throw new Error('PostCSS config should be an object.');
141
+ }
142
+ if (contents.plugins == null ||
143
+ typeof contents.plugins !== 'object' ||
144
+ Object.keys(contents.plugins).length === 0) {
145
+ throw new Error('PostCSS config must have plugins');
146
+ }
147
+ }
148
+ return configHydrator(contents, config, configFile?.filePath, options, logger);
149
+ }