@atlaspack/transformer-css 2.14.5-canary.25 → 2.14.5-canary.251

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,263 @@
1
1
  # @atlaspack/transformer-css
2
2
 
3
+ ## 2.14.35
4
+
5
+ ### Patch Changes
6
+
7
+ - 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)]:
8
+ - @atlaspack/feature-flags@2.25.5
9
+ - @atlaspack/utils@3.0.3
10
+ - @atlaspack/plugin@2.14.35
11
+ - @atlaspack/types@2.15.25
12
+
13
+ ## 2.14.34
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [[`662d3c6`](https://github.com/atlassian-labs/atlaspack/commit/662d3c627888b16bf27df15cfac5a9094509e93d)]:
18
+ - @atlaspack/feature-flags@2.25.4
19
+ - @atlaspack/types@2.15.24
20
+ - @atlaspack/utils@3.0.2
21
+ - @atlaspack/plugin@2.14.34
22
+
23
+ ## 2.14.33
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [[`236e546`](https://github.com/atlassian-labs/atlaspack/commit/236e5465863dca6044a7191e05260a5b924c342e), [`f07351a`](https://github.com/atlassian-labs/atlaspack/commit/f07351a2398b6a8e5155a2daad77e69b7dcb2b4b)]:
28
+ - @atlaspack/utils@3.0.1
29
+ - @atlaspack/feature-flags@2.25.3
30
+ - @atlaspack/types@2.15.23
31
+ - @atlaspack/plugin@2.14.33
32
+
33
+ ## 2.14.32
34
+
35
+ ### Patch Changes
36
+
37
+ - [#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
38
+
39
+ BREAKING CHANGE: The `remapSourceLocation` API in `@atlaspack/utils` now requires the project root
40
+
41
+ - 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)]:
42
+ - @atlaspack/feature-flags@2.25.2
43
+ - @atlaspack/utils@3.0.0
44
+ - @atlaspack/plugin@2.14.32
45
+ - @atlaspack/types@2.15.22
46
+
47
+ ## 2.14.31
48
+
49
+ ### Patch Changes
50
+
51
+ - [#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.
52
+
53
+ - Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922)]:
54
+ - @atlaspack/diagnostic@2.14.4
55
+ - @atlaspack/feature-flags@2.25.1
56
+ - @atlaspack/plugin@2.14.31
57
+ - @atlaspack/types@2.15.21
58
+ - @atlaspack/utils@2.19.3
59
+
60
+ ## 2.14.30
61
+
62
+ ### Patch Changes
63
+
64
+ - [#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.
65
+
66
+ - 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)]:
67
+ - @atlaspack/feature-flags@2.25.0
68
+ - @atlaspack/utils@2.19.2
69
+ - @atlaspack/plugin@2.14.30
70
+ - @atlaspack/types@2.15.20
71
+
72
+ ## 2.14.29
73
+
74
+ ### Patch Changes
75
+
76
+ - Updated dependencies []:
77
+ - @atlaspack/utils@2.19.1
78
+ - @atlaspack/plugin@2.14.29
79
+ - @atlaspack/types@2.15.19
80
+
81
+ ## 2.14.28
82
+
83
+ ### Patch Changes
84
+
85
+ - Updated dependencies [[`f0349a6`](https://github.com/atlassian-labs/atlaspack/commit/f0349a6b9b04755088f121095ca6301a2ada3767)]:
86
+ - @atlaspack/utils@2.19.0
87
+ - @atlaspack/plugin@2.14.28
88
+ - @atlaspack/types@2.15.18
89
+
90
+ ## 2.14.27
91
+
92
+ ### Patch Changes
93
+
94
+ - [#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
95
+
96
+ - Updated dependencies []:
97
+ - @atlaspack/utils@2.18.4
98
+ - @atlaspack/plugin@2.14.27
99
+ - @atlaspack/types@2.15.17
100
+
101
+ ## 2.14.26
102
+
103
+ ### Patch Changes
104
+
105
+ - [#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
106
+
107
+ - Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd), [`889c65c`](https://github.com/atlassian-labs/atlaspack/commit/889c65cd25b811045e26a117e7404f694dde77a2)]:
108
+ - @atlaspack/diagnostic@2.14.3
109
+ - @atlaspack/plugin@2.14.26
110
+ - @atlaspack/utils@2.18.3
111
+
112
+ ## 2.14.25
113
+
114
+ ### Patch Changes
115
+
116
+ - Updated dependencies []:
117
+ - @atlaspack/utils@2.18.2
118
+ - @atlaspack/plugin@2.14.25
119
+
120
+ ## 2.14.24
121
+
122
+ ### Patch Changes
123
+
124
+ - Updated dependencies []:
125
+ - @atlaspack/utils@2.18.1
126
+ - @atlaspack/plugin@2.14.24
127
+
128
+ ## 2.14.23
129
+
130
+ ### Patch Changes
131
+
132
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
133
+ - @atlaspack/utils@2.18.0
134
+ - @atlaspack/plugin@2.14.23
135
+
136
+ ## 2.14.22
137
+
138
+ ### Patch Changes
139
+
140
+ - [#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
141
+
142
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94)]:
143
+ - @atlaspack/diagnostic@2.14.2
144
+ - @atlaspack/plugin@2.14.22
145
+ - @atlaspack/utils@2.17.4
146
+
147
+ ## 2.14.21
148
+
149
+ ### Patch Changes
150
+
151
+ - Updated dependencies []:
152
+ - @atlaspack/utils@2.17.3
153
+ - @atlaspack/plugin@2.14.21
154
+
155
+ ## 2.14.20
156
+
157
+ ### Patch Changes
158
+
159
+ - [#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
160
+
161
+ - Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa)]:
162
+ - @atlaspack/plugin@2.14.20
163
+ - @atlaspack/utils@2.17.2
164
+
165
+ ## 2.14.19
166
+
167
+ ### Patch Changes
168
+
169
+ - Updated dependencies []:
170
+ - @atlaspack/utils@2.17.1
171
+ - @atlaspack/plugin@2.14.19
172
+
173
+ ## 2.14.18
174
+
175
+ ### Patch Changes
176
+
177
+ - 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)]:
178
+ - @atlaspack/utils@2.17.0
179
+ - @atlaspack/plugin@2.14.18
180
+
181
+ ## 2.14.17
182
+
183
+ ### Patch Changes
184
+
185
+ - Updated dependencies []:
186
+ - @atlaspack/utils@2.16.1
187
+ - @atlaspack/plugin@2.14.17
188
+
189
+ ## 2.14.16
190
+
191
+ ### Patch Changes
192
+
193
+ - Updated dependencies [[`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
194
+ - @atlaspack/utils@2.16.0
195
+ - @atlaspack/plugin@2.14.16
196
+
197
+ ## 2.14.15
198
+
199
+ ### Patch Changes
200
+
201
+ - Updated dependencies []:
202
+ - @atlaspack/utils@2.15.3
203
+ - @atlaspack/plugin@2.14.15
204
+
205
+ ## 2.14.14
206
+
207
+ ### Patch Changes
208
+
209
+ - Updated dependencies []:
210
+ - @atlaspack/utils@2.15.2
211
+ - @atlaspack/plugin@2.14.14
212
+
213
+ ## 2.14.13
214
+
215
+ ### Patch Changes
216
+
217
+ - Updated dependencies []:
218
+ - @atlaspack/utils@2.15.1
219
+ - @atlaspack/plugin@2.14.13
220
+
221
+ ## 2.14.12
222
+
223
+ ### Patch Changes
224
+
225
+ - Updated dependencies [[`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
226
+ - @atlaspack/utils@2.15.0
227
+ - @atlaspack/plugin@2.14.12
228
+
229
+ ## 2.14.11
230
+
231
+ ### Patch Changes
232
+
233
+ - Updated dependencies []:
234
+ - @atlaspack/utils@2.14.11
235
+ - @atlaspack/plugin@2.14.11
236
+
237
+ ## 2.14.10
238
+
239
+ ### Patch Changes
240
+
241
+ - Updated dependencies []:
242
+ - @atlaspack/plugin@2.14.10
243
+ - @atlaspack/utils@2.14.10
244
+
245
+ ## 2.14.9
246
+
247
+ ### Patch Changes
248
+
249
+ - Updated dependencies []:
250
+ - @atlaspack/utils@2.14.9
251
+ - @atlaspack/plugin@2.14.9
252
+
253
+ ## 2.14.8
254
+
255
+ ### Patch Changes
256
+
257
+ - Updated dependencies []:
258
+ - @atlaspack/utils@2.14.8
259
+ - @atlaspack/plugin@2.14.8
260
+
3
261
  ## 2.14.7
4
262
 
5
263
  ### 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("@parcel/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
+ }