@atlaspack/transformer-css 2.14.5-canary.29 → 2.14.5-canary.291

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,285 @@
1
1
  # @atlaspack/transformer-css
2
2
 
3
+ ## 2.14.38
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`ec3abe4`](https://github.com/atlassian-labs/atlaspack/commit/ec3abe4dffc98560a850fd2f71fb566577e6c99c), [`c7fe3f7`](https://github.com/atlassian-labs/atlaspack/commit/c7fe3f76f247e9e20299e205e2df0a16c418eaf2), [`7d7a55d`](https://github.com/atlassian-labs/atlaspack/commit/7d7a55dd6395ec391a2e4c33b3dec0d1ea477d4c)]:
8
+ - @atlaspack/feature-flags@2.26.2
9
+ - @atlaspack/utils@3.1.2
10
+ - @atlaspack/plugin@2.14.38
11
+ - @atlaspack/types@2.15.28
12
+
13
+ ## 2.14.37
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [[`373ee2d`](https://github.com/atlassian-labs/atlaspack/commit/373ee2d3b5cc315df1e90e647619f915892e2b87)]:
18
+ - @atlaspack/feature-flags@2.26.1
19
+ - @atlaspack/utils@3.1.1
20
+ - @atlaspack/plugin@2.14.37
21
+ - @atlaspack/types@2.15.27
22
+
23
+ ## 2.14.36
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [[`58527ee`](https://github.com/atlassian-labs/atlaspack/commit/58527eec15c1aebaaadbeb63586f3082c16beae3), [`cfb39a0`](https://github.com/atlassian-labs/atlaspack/commit/cfb39a0d729eb620cf2ca1611750a2bf7a080d08), [`d0c7bea`](https://github.com/atlassian-labs/atlaspack/commit/d0c7bea04458255b4c5d4299600e734b5f919fe1), [`9cd9521`](https://github.com/atlassian-labs/atlaspack/commit/9cd9521978f783046e2ae4ce78f2de7aeb07d073), [`5776be2`](https://github.com/atlassian-labs/atlaspack/commit/5776be21f70a3f2b9471ba33da3ba1a883f21f1a)]:
28
+ - @atlaspack/feature-flags@2.26.0
29
+ - @atlaspack/utils@3.1.0
30
+ - @atlaspack/plugin@2.14.36
31
+ - @atlaspack/types@2.15.26
32
+
33
+ ## 2.14.35
34
+
35
+ ### Patch Changes
36
+
37
+ - Updated dependencies [[`79a7e22`](https://github.com/atlassian-labs/atlaspack/commit/79a7e22ef119891a2f4180a9d3cc66b38dd52092), [`3da8e69`](https://github.com/atlassian-labs/atlaspack/commit/3da8e690605472d81c531366b65fa9844f8ca337), [`c372f3f`](https://github.com/atlassian-labs/atlaspack/commit/c372f3fd6fce8200d5cf47f41bc7895c6cbb5558), [`17dfea9`](https://github.com/atlassian-labs/atlaspack/commit/17dfea9e9f3169807808520df9c09ebf70dc8b10), [`f1070ec`](https://github.com/atlassian-labs/atlaspack/commit/f1070ec48e99b4ec111a03179c5ab5b74163fab1)]:
38
+ - @atlaspack/feature-flags@2.25.5
39
+ - @atlaspack/utils@3.0.3
40
+ - @atlaspack/plugin@2.14.35
41
+ - @atlaspack/types@2.15.25
42
+
43
+ ## 2.14.34
44
+
45
+ ### Patch Changes
46
+
47
+ - Updated dependencies [[`662d3c6`](https://github.com/atlassian-labs/atlaspack/commit/662d3c627888b16bf27df15cfac5a9094509e93d)]:
48
+ - @atlaspack/feature-flags@2.25.4
49
+ - @atlaspack/types@2.15.24
50
+ - @atlaspack/utils@3.0.2
51
+ - @atlaspack/plugin@2.14.34
52
+
53
+ ## 2.14.33
54
+
55
+ ### Patch Changes
56
+
57
+ - Updated dependencies [[`236e546`](https://github.com/atlassian-labs/atlaspack/commit/236e5465863dca6044a7191e05260a5b924c342e), [`f07351a`](https://github.com/atlassian-labs/atlaspack/commit/f07351a2398b6a8e5155a2daad77e69b7dcb2b4b)]:
58
+ - @atlaspack/utils@3.0.1
59
+ - @atlaspack/feature-flags@2.25.3
60
+ - @atlaspack/types@2.15.23
61
+ - @atlaspack/plugin@2.14.33
62
+
63
+ ## 2.14.32
64
+
65
+ ### Patch Changes
66
+
67
+ - [#800](https://github.com/atlassian-labs/atlaspack/pull/800) [`1180103`](https://github.com/atlassian-labs/atlaspack/commit/118010351ed444f8178988afb3f77807154dd933) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Fix errors when creating diagnostics with relative file paths
68
+
69
+ BREAKING CHANGE: The `remapSourceLocation` API in `@atlaspack/utils` now requires the project root
70
+
71
+ - Updated dependencies [[`0207171`](https://github.com/atlassian-labs/atlaspack/commit/0207171e59e985c51e105aec2e0a99de174374bd), [`10ee3fa`](https://github.com/atlassian-labs/atlaspack/commit/10ee3fa5b75a92acde8973673d9b3c5b6f3958e5), [`1180103`](https://github.com/atlassian-labs/atlaspack/commit/118010351ed444f8178988afb3f77807154dd933), [`2bc93b1`](https://github.com/atlassian-labs/atlaspack/commit/2bc93b17cea07fd7cbb68acec84d8471345a22b4)]:
72
+ - @atlaspack/feature-flags@2.25.2
73
+ - @atlaspack/utils@3.0.0
74
+ - @atlaspack/plugin@2.14.32
75
+ - @atlaspack/types@2.15.22
76
+
77
+ ## 2.14.31
78
+
79
+ ### Patch Changes
80
+
81
+ - [#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.
82
+
83
+ - Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922)]:
84
+ - @atlaspack/diagnostic@2.14.4
85
+ - @atlaspack/feature-flags@2.25.1
86
+ - @atlaspack/plugin@2.14.31
87
+ - @atlaspack/types@2.15.21
88
+ - @atlaspack/utils@2.19.3
89
+
90
+ ## 2.14.30
91
+
92
+ ### Patch Changes
93
+
94
+ - [#779](https://github.com/atlassian-labs/atlaspack/pull/779) [`7a52bab`](https://github.com/atlassian-labs/atlaspack/commit/7a52bab6281e8edbfa66af248eb6f872c6b4b7bd) Thanks [@marcins](https://github.com/marcins)! - Add new feature flag `preserveUnstableSingleFileOutputInCss` which when enabled will ensure the `unstableSingleFileOutput` property on the asset environment is preserved when transforming CSS.
95
+
96
+ - Updated dependencies [[`7a52bab`](https://github.com/atlassian-labs/atlaspack/commit/7a52bab6281e8edbfa66af248eb6f872c6b4b7bd), [`038e87a`](https://github.com/atlassian-labs/atlaspack/commit/038e87a7858d39556d59d3a2d17db534d45f62c6), [`f6532d7`](https://github.com/atlassian-labs/atlaspack/commit/f6532d7a4f7f007bd4e5e36af04dd466f0b9f572), [`602f8ed`](https://github.com/atlassian-labs/atlaspack/commit/602f8ed9d8381301df8b2cc82c1d5cf6f2f94fec)]:
97
+ - @atlaspack/feature-flags@2.25.0
98
+ - @atlaspack/utils@2.19.2
99
+ - @atlaspack/plugin@2.14.30
100
+ - @atlaspack/types@2.15.20
101
+
102
+ ## 2.14.29
103
+
104
+ ### Patch Changes
105
+
106
+ - Updated dependencies []:
107
+ - @atlaspack/utils@2.19.1
108
+ - @atlaspack/plugin@2.14.29
109
+ - @atlaspack/types@2.15.19
110
+
111
+ ## 2.14.28
112
+
113
+ ### Patch Changes
114
+
115
+ - Updated dependencies [[`f0349a6`](https://github.com/atlassian-labs/atlaspack/commit/f0349a6b9b04755088f121095ca6301a2ada3767)]:
116
+ - @atlaspack/utils@2.19.0
117
+ - @atlaspack/plugin@2.14.28
118
+ - @atlaspack/types@2.15.18
119
+
120
+ ## 2.14.27
121
+
122
+ ### Patch Changes
123
+
124
+ - [#752](https://github.com/atlassian-labs/atlaspack/pull/752) [`a0aed1d`](https://github.com/atlassian-labs/atlaspack/commit/a0aed1dac6111096f7061675ac16a1417cbf6a17) Thanks [@marcins](https://github.com/marcins)! - Fix missing dependencies in package.json
125
+
126
+ - Updated dependencies []:
127
+ - @atlaspack/utils@2.18.4
128
+ - @atlaspack/plugin@2.14.27
129
+ - @atlaspack/types@2.15.17
130
+
131
+ ## 2.14.26
132
+
133
+ ### Patch Changes
134
+
135
+ - [#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
136
+
137
+ - Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd), [`889c65c`](https://github.com/atlassian-labs/atlaspack/commit/889c65cd25b811045e26a117e7404f694dde77a2)]:
138
+ - @atlaspack/diagnostic@2.14.3
139
+ - @atlaspack/plugin@2.14.26
140
+ - @atlaspack/utils@2.18.3
141
+
142
+ ## 2.14.25
143
+
144
+ ### Patch Changes
145
+
146
+ - Updated dependencies []:
147
+ - @atlaspack/utils@2.18.2
148
+ - @atlaspack/plugin@2.14.25
149
+
150
+ ## 2.14.24
151
+
152
+ ### Patch Changes
153
+
154
+ - Updated dependencies []:
155
+ - @atlaspack/utils@2.18.1
156
+ - @atlaspack/plugin@2.14.24
157
+
158
+ ## 2.14.23
159
+
160
+ ### Patch Changes
161
+
162
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
163
+ - @atlaspack/utils@2.18.0
164
+ - @atlaspack/plugin@2.14.23
165
+
166
+ ## 2.14.22
167
+
168
+ ### Patch Changes
169
+
170
+ - [#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
171
+
172
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94)]:
173
+ - @atlaspack/diagnostic@2.14.2
174
+ - @atlaspack/plugin@2.14.22
175
+ - @atlaspack/utils@2.17.4
176
+
177
+ ## 2.14.21
178
+
179
+ ### Patch Changes
180
+
181
+ - Updated dependencies []:
182
+ - @atlaspack/utils@2.17.3
183
+ - @atlaspack/plugin@2.14.21
184
+
185
+ ## 2.14.20
186
+
187
+ ### Patch Changes
188
+
189
+ - [#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
190
+
191
+ - Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa)]:
192
+ - @atlaspack/plugin@2.14.20
193
+ - @atlaspack/utils@2.17.2
194
+
195
+ ## 2.14.19
196
+
197
+ ### Patch Changes
198
+
199
+ - Updated dependencies []:
200
+ - @atlaspack/utils@2.17.1
201
+ - @atlaspack/plugin@2.14.19
202
+
203
+ ## 2.14.18
204
+
205
+ ### Patch Changes
206
+
207
+ - Updated dependencies [[`dbb4072`](https://github.com/atlassian-labs/atlaspack/commit/dbb40721ebeb45990a14ba04e6b44e7f836fb32d), [`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)]:
208
+ - @atlaspack/utils@2.17.0
209
+ - @atlaspack/plugin@2.14.18
210
+
211
+ ## 2.14.17
212
+
213
+ ### Patch Changes
214
+
215
+ - Updated dependencies []:
216
+ - @atlaspack/utils@2.16.1
217
+ - @atlaspack/plugin@2.14.17
218
+
219
+ ## 2.14.16
220
+
221
+ ### Patch Changes
222
+
223
+ - Updated dependencies [[`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
224
+ - @atlaspack/utils@2.16.0
225
+ - @atlaspack/plugin@2.14.16
226
+
227
+ ## 2.14.15
228
+
229
+ ### Patch Changes
230
+
231
+ - Updated dependencies []:
232
+ - @atlaspack/utils@2.15.3
233
+ - @atlaspack/plugin@2.14.15
234
+
235
+ ## 2.14.14
236
+
237
+ ### Patch Changes
238
+
239
+ - Updated dependencies []:
240
+ - @atlaspack/utils@2.15.2
241
+ - @atlaspack/plugin@2.14.14
242
+
243
+ ## 2.14.13
244
+
245
+ ### Patch Changes
246
+
247
+ - Updated dependencies []:
248
+ - @atlaspack/utils@2.15.1
249
+ - @atlaspack/plugin@2.14.13
250
+
251
+ ## 2.14.12
252
+
253
+ ### Patch Changes
254
+
255
+ - Updated dependencies [[`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
256
+ - @atlaspack/utils@2.15.0
257
+ - @atlaspack/plugin@2.14.12
258
+
259
+ ## 2.14.11
260
+
261
+ ### Patch Changes
262
+
263
+ - Updated dependencies []:
264
+ - @atlaspack/utils@2.14.11
265
+ - @atlaspack/plugin@2.14.11
266
+
267
+ ## 2.14.10
268
+
269
+ ### Patch Changes
270
+
271
+ - Updated dependencies []:
272
+ - @atlaspack/plugin@2.14.10
273
+ - @atlaspack/utils@2.14.10
274
+
275
+ ## 2.14.9
276
+
277
+ ### Patch Changes
278
+
279
+ - Updated dependencies []:
280
+ - @atlaspack/utils@2.14.9
281
+ - @atlaspack/plugin@2.14.9
282
+
3
283
  ## 2.14.8
4
284
 
5
285
  ### Patch Changes
@@ -0,0 +1,405 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const path_1 = __importDefault(require("path"));
40
+ const source_map_1 = __importDefault(require("@atlaspack/source-map"));
41
+ const plugin_1 = require("@atlaspack/plugin");
42
+ const utils_1 = require("@atlaspack/utils");
43
+ const native = __importStar(require("lightningcss"));
44
+ const browserslist_1 = __importDefault(require("browserslist"));
45
+ const nullthrows_1 = __importDefault(require("nullthrows"));
46
+ const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
47
+ const feature_flags_1 = require("@atlaspack/feature-flags");
48
+ const { transform, transformStyleAttribute, browserslistToTargets } = native;
49
+ exports.default = new plugin_1.Transformer({
50
+ async loadConfig({ config, options }) {
51
+ let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
52
+ packageKey: '@atlaspack/transformer-css',
53
+ });
54
+ let contents = conf?.contents;
55
+ // @ts-expect-error TS2339
56
+ if (typeof contents?.cssModules?.include === 'string') {
57
+ // @ts-expect-error TS2339
58
+ contents.cssModules.include = [(0, utils_1.globToRegex)(contents.cssModules.include)];
59
+ // @ts-expect-error TS2339
60
+ }
61
+ else if (Array.isArray(contents?.cssModules?.include)) {
62
+ // @ts-expect-error TS2339
63
+ contents.cssModules.include = contents.cssModules.include.map(
64
+ // @ts-expect-error TS7006
65
+ (include) => typeof include === 'string' ? (0, utils_1.globToRegex)(include) : include);
66
+ }
67
+ // @ts-expect-error TS2339
68
+ if (typeof contents?.cssModules?.exclude === 'string') {
69
+ // @ts-expect-error TS2339
70
+ contents.cssModules.exclude = [(0, utils_1.globToRegex)(contents.cssModules.exclude)];
71
+ // @ts-expect-error TS2339
72
+ }
73
+ else if (Array.isArray(contents?.cssModules?.exclude)) {
74
+ // @ts-expect-error TS2339
75
+ contents.cssModules.exclude = contents.cssModules.exclude.map(
76
+ // @ts-expect-error TS7006
77
+ (exclude) => typeof exclude === 'string' ? (0, utils_1.globToRegex)(exclude) : exclude);
78
+ }
79
+ return contents;
80
+ },
81
+ async transform({ asset, config, options, logger }) {
82
+ if ((0, feature_flags_1.getFeatureFlag)('compiledCssInJsTransformer') &&
83
+ asset.filePath.endsWith('.compiled.css')) {
84
+ return handleCompiledCssAsset(asset);
85
+ }
86
+ // Normalize the asset's environment so that properties that only affect JS don't cause CSS to be duplicated.
87
+ // For example, with ESModule and CommonJS targets, only a single shared CSS bundle should be produced.
88
+ let env = asset.env;
89
+ asset.setEnvironment({
90
+ context: 'browser',
91
+ engines: {
92
+ browsers: asset.env.engines.browsers,
93
+ },
94
+ shouldOptimize: asset.env.shouldOptimize,
95
+ shouldScopeHoist: asset.env.shouldScopeHoist,
96
+ sourceMap: asset.env.sourceMap,
97
+ unstableSingleFileOutput: (0, feature_flags_1.getFeatureFlag)('preserveUnstableSingleFileOutputInCss')
98
+ ? asset.env.unstableSingleFileOutput
99
+ : undefined,
100
+ });
101
+ let [code, originalMap] = await Promise.all([
102
+ asset.getBuffer(),
103
+ asset.getMap(),
104
+ // @ts-expect-error TS2339
105
+ process.browser && native.default(),
106
+ ]);
107
+ let targets = getTargets(asset.env.engines.browsers);
108
+ let res;
109
+ try {
110
+ if (asset.meta.type === 'attr') {
111
+ res = transformStyleAttribute({
112
+ code,
113
+ analyzeDependencies: true,
114
+ // @ts-expect-error TS2339
115
+ errorRecovery: config?.errorRecovery || false,
116
+ targets,
117
+ });
118
+ }
119
+ else {
120
+ let cssModules = false;
121
+ if (asset.meta.type !== 'tag' &&
122
+ asset.meta.cssModulesCompiled == null) {
123
+ // @ts-expect-error TS2339
124
+ let cssModulesConfig = config?.cssModules;
125
+ let isCSSModule = /\.module\./.test(asset.filePath);
126
+ if (asset.isSource) {
127
+ let projectRootPath = path_1.default.relative(options.projectRoot, asset.filePath);
128
+ if (typeof cssModulesConfig === 'boolean') {
129
+ isCSSModule = true;
130
+ }
131
+ else if (cssModulesConfig?.include) {
132
+ // @ts-expect-error TS7006
133
+ isCSSModule = cssModulesConfig.include.some((include) => include.test(projectRootPath));
134
+ }
135
+ else if (cssModulesConfig?.global) {
136
+ isCSSModule = true;
137
+ }
138
+ if (cssModulesConfig?.exclude?.some((exclude) => exclude.test(projectRootPath))) {
139
+ isCSSModule = false;
140
+ }
141
+ }
142
+ if (isCSSModule) {
143
+ if (cssModulesConfig?.dashedIdents && !asset.isSource) {
144
+ cssModulesConfig.dashedIdents = false;
145
+ }
146
+ cssModules = cssModulesConfig ?? true;
147
+ }
148
+ }
149
+ res = transform({
150
+ filename: (0, utils_1.normalizeSeparators)(path_1.default.relative(options.projectRoot, asset.filePath)),
151
+ code,
152
+ cssModules,
153
+ analyzeDependencies: asset.meta.hasDependencies !== false
154
+ ? {
155
+ preserveImports: true,
156
+ }
157
+ : false,
158
+ sourceMap: !!asset.env.sourceMap,
159
+ // @ts-expect-error TS2339
160
+ drafts: config?.drafts,
161
+ // @ts-expect-error TS2339
162
+ pseudoClasses: config?.pseudoClasses,
163
+ // @ts-expect-error TS2339
164
+ errorRecovery: config?.errorRecovery || false,
165
+ targets,
166
+ });
167
+ }
168
+ }
169
+ catch (err) {
170
+ err.filePath = asset.filePath;
171
+ let diagnostic = (0, diagnostic_1.errorToDiagnostic)(err, {
172
+ origin: '@atlaspack/transformer-css',
173
+ });
174
+ if (err.data?.type === 'AmbiguousUrlInCustomProperty' && err.data.url) {
175
+ let p = '/' +
176
+ (0, utils_1.relativePath)(options.projectRoot, path_1.default.resolve(path_1.default.dirname(asset.filePath), err.data.url), false);
177
+ diagnostic[0].hints = [`Replace with: url(${p})`];
178
+ diagnostic[0].documentationURL =
179
+ 'https://parceljs.org/languages/css/#url()';
180
+ }
181
+ throw new diagnostic_1.default({
182
+ diagnostic,
183
+ });
184
+ }
185
+ if (res.warnings) {
186
+ for (let warning of res.warnings) {
187
+ logger.warn({
188
+ message: warning.message,
189
+ codeFrames: [
190
+ {
191
+ filePath: asset.filePath,
192
+ codeHighlights: [
193
+ {
194
+ start: {
195
+ line: warning.loc.line,
196
+ column: warning.loc.column + 1,
197
+ },
198
+ end: {
199
+ line: warning.loc.line,
200
+ column: warning.loc.column + 1,
201
+ },
202
+ },
203
+ ],
204
+ },
205
+ ],
206
+ });
207
+ }
208
+ }
209
+ // @ts-expect-error TS2339
210
+ if (res.map != null) {
211
+ // @ts-expect-error TS2339
212
+ let vlqMap = JSON.parse(Buffer.from(res.map).toString());
213
+ let map = new source_map_1.default(options.projectRoot);
214
+ map.addVLQMap(vlqMap);
215
+ if (originalMap) {
216
+ map.extends(originalMap);
217
+ }
218
+ asset.setMap(map);
219
+ }
220
+ if (res.dependencies) {
221
+ for (let dep of res.dependencies) {
222
+ let loc = convertLoc(dep.loc);
223
+ if (originalMap) {
224
+ loc = (0, utils_1.remapSourceLocation)(loc, originalMap, options.projectRoot);
225
+ }
226
+ // @ts-expect-error TS2339
227
+ if (dep.type === 'import' && !res.exports) {
228
+ asset.addDependency({
229
+ specifier: dep.url,
230
+ specifierType: 'url',
231
+ loc,
232
+ packageConditions: ['style'],
233
+ meta: {
234
+ // For the glob resolver to distinguish between `@import` and other URL dependencies.
235
+ isCSSImport: true,
236
+ media: dep.media,
237
+ placeholder: dep.placeholder,
238
+ },
239
+ });
240
+ }
241
+ else if (dep.type === 'url') {
242
+ asset.addURLDependency(dep.url, {
243
+ loc,
244
+ meta: {
245
+ placeholder: dep.placeholder,
246
+ },
247
+ });
248
+ }
249
+ }
250
+ }
251
+ let assets = [asset];
252
+ let buffer = Buffer.from(res.code);
253
+ // @ts-expect-error TS2339
254
+ if (res.exports != null) {
255
+ // @ts-expect-error TS2339
256
+ let exports = res.exports;
257
+ asset.symbols.ensure();
258
+ asset.symbols.set('default', 'default');
259
+ let dependencies = new Map();
260
+ let locals = new Map();
261
+ let c = 0;
262
+ let depjs = '';
263
+ let js = '';
264
+ let cssImports = '';
265
+ let jsDeps = [];
266
+ for (let key in exports) {
267
+ locals.set(exports[key].name, key);
268
+ }
269
+ asset.uniqueKey ?? (asset.uniqueKey = asset.id);
270
+ let seen = new Set();
271
+ let add = (key) => {
272
+ if (seen.has(key)) {
273
+ return;
274
+ }
275
+ seen.add(key);
276
+ let e = exports[key];
277
+ let s = `module.exports[${JSON.stringify(key)}] = \`${e.name}`;
278
+ for (let ref of e.composes) {
279
+ s += ' ';
280
+ if (ref.type === 'local') {
281
+ let exported = (0, nullthrows_1.default)(locals.get(ref.name));
282
+ add(exported);
283
+ s += '${' + `module.exports[${JSON.stringify(exported)}]` + '}';
284
+ asset.addDependency({
285
+ specifier: (0, nullthrows_1.default)(asset.uniqueKey),
286
+ specifierType: 'esm',
287
+ symbols: new Map([
288
+ [exported, { local: ref.name, isWeak: false, loc: null }],
289
+ ]),
290
+ });
291
+ }
292
+ else if (ref.type === 'global') {
293
+ s += ref.name;
294
+ }
295
+ else if (ref.type === 'dependency') {
296
+ let d = dependencies.get(ref.specifier);
297
+ if (d == null) {
298
+ d = `dep_${c++}`;
299
+ depjs += `import * as ${d} from ${JSON.stringify(ref.specifier)};\n`;
300
+ dependencies.set(ref.specifier, d);
301
+ cssImports += `@import "${ref.specifier}";\n`;
302
+ asset.addDependency({
303
+ specifier: ref.specifier,
304
+ specifierType: 'esm',
305
+ packageConditions: ['style'],
306
+ });
307
+ }
308
+ s += '${' + `${d}[${JSON.stringify(ref.name)}]` + '}';
309
+ }
310
+ }
311
+ s += '`;\n';
312
+ // If the export is referenced internally (e.g. used @keyframes), add a self-reference
313
+ // to the JS so the symbol is retained during tree-shaking.
314
+ if (e.isReferenced) {
315
+ s += `module.exports[${JSON.stringify(key)}];\n`;
316
+ asset.addDependency({
317
+ specifier: (0, nullthrows_1.default)(asset.uniqueKey),
318
+ specifierType: 'esm',
319
+ symbols: new Map([
320
+ [key, { local: exports[key].name, isWeak: false, loc: null }],
321
+ ]),
322
+ });
323
+ }
324
+ js += s;
325
+ };
326
+ // It's possible that the exports can be ordered differently between builds.
327
+ // Sorting by key is safe as the order is irrelevant but needs to be deterministic.
328
+ for (let key of Object.keys(exports).sort()) {
329
+ asset.symbols.set(key, exports[key].name);
330
+ add(key);
331
+ }
332
+ if (res.dependencies) {
333
+ for (let dep of res.dependencies) {
334
+ if (dep.type === 'import') {
335
+ // TODO: Figure out how to treeshake this
336
+ let d = `dep_$${c++}`;
337
+ depjs += `import * as ${d} from ${JSON.stringify(dep.url)};\n`;
338
+ js += `for (let key in ${d}) { if (key in module.exports) module.exports[key] += ' ' + ${d}[key]; else module.exports[key] = ${d}[key]; }\n`;
339
+ asset.symbols.set('*', '*');
340
+ }
341
+ }
342
+ }
343
+ // @ts-expect-error TS2339
344
+ if (res.references != null) {
345
+ // @ts-expect-error TS2339
346
+ let references = res.references;
347
+ for (let symbol in references) {
348
+ let reference = references[symbol];
349
+ asset.addDependency({
350
+ specifier: reference.specifier,
351
+ specifierType: 'esm',
352
+ packageConditions: ['style'],
353
+ symbols: new Map([
354
+ [reference.name, { local: symbol, isWeak: false, loc: null }],
355
+ ]),
356
+ });
357
+ asset.meta.hasReferences = true;
358
+ cssImports += `@import "${reference.specifier}";\n`;
359
+ }
360
+ }
361
+ assets.push({
362
+ type: 'js',
363
+ // @ts-expect-error TS2353
364
+ content: depjs + js,
365
+ dependencies: jsDeps,
366
+ env,
367
+ });
368
+ // Prepend @import rules for each composes dependency so packager knows where to insert them.
369
+ if (cssImports.length > 0) {
370
+ buffer = Buffer.concat([Buffer.from(cssImports), buffer]);
371
+ }
372
+ }
373
+ asset.setBuffer(buffer);
374
+ return assets;
375
+ },
376
+ });
377
+ let cache = new Map();
378
+ function getTargets(browsers) {
379
+ if (browsers == null) {
380
+ return undefined;
381
+ }
382
+ let cached = cache.get(browsers);
383
+ if (cached != null) {
384
+ return cached;
385
+ }
386
+ let targets = browserslistToTargets((0, browserslist_1.default)(browsers));
387
+ cache.set(browsers, targets);
388
+ return targets;
389
+ }
390
+ function convertLoc(loc) {
391
+ return {
392
+ filePath: loc.filePath,
393
+ start: { line: loc.start.line, column: loc.start.column },
394
+ end: { line: loc.end.line, column: loc.end.column + 1 },
395
+ };
396
+ }
397
+ async function handleCompiledCssAsset(asset) {
398
+ const code = await asset.getCode();
399
+ const rules = code.split('\n').map((line) => line.trim());
400
+ // styleRules will be consumed by the optimiser in @compiled/parcel-optimizer
401
+ asset.meta.styleRules = rules;
402
+ // Empty the code because we only use compiled CSS assets for their metadata
403
+ asset.setCode('');
404
+ return [asset];
405
+ }