@atlaspack/transformer-css 2.14.5-canary.24 → 2.14.5-canary.240

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