@atlaspack/packager-css 2.14.5-canary.26 → 2.14.5-canary.261
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +256 -0
- package/dist/CSSPackager.js +330 -0
- package/lib/CSSPackager.js +28 -5
- package/lib/types/CSSPackager.d.ts +5 -0
- package/package.json +13 -8
- package/src/{CSSPackager.js → CSSPackager.ts} +49 -25
- package/tsconfig.json +21 -0
- package/tsconfig.tsbuildinfo +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,261 @@
|
|
|
1
1
|
# @atlaspack/packager-css
|
|
2
2
|
|
|
3
|
+
## 2.14.36
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`5776be2`](https://github.com/atlassian-labs/atlaspack/commit/5776be21f70a3f2b9471ba33da3ba1a883f21f1a)]:
|
|
8
|
+
- @atlaspack/utils@3.1.0
|
|
9
|
+
- @atlaspack/types-internal@2.20.6
|
|
10
|
+
- @atlaspack/plugin@2.14.36
|
|
11
|
+
|
|
12
|
+
## 2.14.35
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`c372f3f`](https://github.com/atlassian-labs/atlaspack/commit/c372f3fd6fce8200d5cf47f41bc7895c6cbb5558), [`17dfea9`](https://github.com/atlassian-labs/atlaspack/commit/17dfea9e9f3169807808520df9c09ebf70dc8b10)]:
|
|
17
|
+
- @atlaspack/types-internal@2.20.5
|
|
18
|
+
- @atlaspack/utils@3.0.3
|
|
19
|
+
- @atlaspack/plugin@2.14.35
|
|
20
|
+
|
|
21
|
+
## 2.14.34
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies []:
|
|
26
|
+
- @atlaspack/types-internal@2.20.4
|
|
27
|
+
- @atlaspack/utils@3.0.2
|
|
28
|
+
- @atlaspack/plugin@2.14.34
|
|
29
|
+
|
|
30
|
+
## 2.14.33
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Updated dependencies [[`236e546`](https://github.com/atlassian-labs/atlaspack/commit/236e5465863dca6044a7191e05260a5b924c342e)]:
|
|
35
|
+
- @atlaspack/utils@3.0.1
|
|
36
|
+
- @atlaspack/types-internal@2.20.3
|
|
37
|
+
- @atlaspack/plugin@2.14.33
|
|
38
|
+
|
|
39
|
+
## 2.14.32
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- Updated dependencies [[`1180103`](https://github.com/atlassian-labs/atlaspack/commit/118010351ed444f8178988afb3f77807154dd933)]:
|
|
44
|
+
- @atlaspack/utils@3.0.0
|
|
45
|
+
- @atlaspack/types-internal@2.20.2
|
|
46
|
+
- @atlaspack/plugin@2.14.32
|
|
47
|
+
|
|
48
|
+
## 2.14.31
|
|
49
|
+
|
|
50
|
+
### Patch Changes
|
|
51
|
+
|
|
52
|
+
- [#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.
|
|
53
|
+
|
|
54
|
+
- Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922)]:
|
|
55
|
+
- @atlaspack/diagnostic@2.14.4
|
|
56
|
+
- @atlaspack/plugin@2.14.31
|
|
57
|
+
- @atlaspack/types-internal@2.20.1
|
|
58
|
+
- @atlaspack/utils@2.19.3
|
|
59
|
+
|
|
60
|
+
## 2.14.30
|
|
61
|
+
|
|
62
|
+
### Patch Changes
|
|
63
|
+
|
|
64
|
+
- Updated dependencies [[`eedcbc4`](https://github.com/atlassian-labs/atlaspack/commit/eedcbc408fc1e86a2a8e25f1a41c57146d8529e1), [`f6532d7`](https://github.com/atlassian-labs/atlaspack/commit/f6532d7a4f7f007bd4e5e36af04dd466f0b9f572)]:
|
|
65
|
+
- @atlaspack/types-internal@2.20.0
|
|
66
|
+
- @atlaspack/utils@2.19.2
|
|
67
|
+
- @atlaspack/plugin@2.14.30
|
|
68
|
+
|
|
69
|
+
## 2.14.29
|
|
70
|
+
|
|
71
|
+
### Patch Changes
|
|
72
|
+
|
|
73
|
+
- Updated dependencies []:
|
|
74
|
+
- @atlaspack/types-internal@2.19.5
|
|
75
|
+
- @atlaspack/utils@2.19.1
|
|
76
|
+
- @atlaspack/plugin@2.14.29
|
|
77
|
+
|
|
78
|
+
## 2.14.28
|
|
79
|
+
|
|
80
|
+
### Patch Changes
|
|
81
|
+
|
|
82
|
+
- Updated dependencies [[`f0349a6`](https://github.com/atlassian-labs/atlaspack/commit/f0349a6b9b04755088f121095ca6301a2ada3767)]:
|
|
83
|
+
- @atlaspack/utils@2.19.0
|
|
84
|
+
- @atlaspack/types-internal@2.19.4
|
|
85
|
+
- @atlaspack/plugin@2.14.28
|
|
86
|
+
|
|
87
|
+
## 2.14.27
|
|
88
|
+
|
|
89
|
+
### Patch Changes
|
|
90
|
+
|
|
91
|
+
- Updated dependencies []:
|
|
92
|
+
- @atlaspack/types-internal@2.19.3
|
|
93
|
+
- @atlaspack/utils@2.18.4
|
|
94
|
+
- @atlaspack/plugin@2.14.27
|
|
95
|
+
|
|
96
|
+
## 2.14.26
|
|
97
|
+
|
|
98
|
+
### Patch Changes
|
|
99
|
+
|
|
100
|
+
- [#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
|
|
101
|
+
|
|
102
|
+
- Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd), [`889c65c`](https://github.com/atlassian-labs/atlaspack/commit/889c65cd25b811045e26a117e7404f694dde77a2)]:
|
|
103
|
+
- @atlaspack/types-internal@2.19.2
|
|
104
|
+
- @atlaspack/diagnostic@2.14.3
|
|
105
|
+
- @atlaspack/plugin@2.14.26
|
|
106
|
+
- @atlaspack/utils@2.18.3
|
|
107
|
+
|
|
108
|
+
## 2.14.25
|
|
109
|
+
|
|
110
|
+
### Patch Changes
|
|
111
|
+
|
|
112
|
+
- Updated dependencies []:
|
|
113
|
+
- @atlaspack/types-internal@2.19.1
|
|
114
|
+
- @atlaspack/utils@2.18.2
|
|
115
|
+
- @atlaspack/plugin@2.14.25
|
|
116
|
+
|
|
117
|
+
## 2.14.24
|
|
118
|
+
|
|
119
|
+
### Patch Changes
|
|
120
|
+
|
|
121
|
+
- Updated dependencies [[`7f5841c`](https://github.com/atlassian-labs/atlaspack/commit/7f5841c39df049f9546cccbeea2a7337e0337b45)]:
|
|
122
|
+
- @atlaspack/types-internal@2.19.0
|
|
123
|
+
- @atlaspack/utils@2.18.1
|
|
124
|
+
- @atlaspack/plugin@2.14.24
|
|
125
|
+
|
|
126
|
+
## 2.14.23
|
|
127
|
+
|
|
128
|
+
### Patch Changes
|
|
129
|
+
|
|
130
|
+
- Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
|
|
131
|
+
- @atlaspack/utils@2.18.0
|
|
132
|
+
- @atlaspack/plugin@2.14.23
|
|
133
|
+
|
|
134
|
+
## 2.14.22
|
|
135
|
+
|
|
136
|
+
### Patch Changes
|
|
137
|
+
|
|
138
|
+
- [#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
|
|
139
|
+
|
|
140
|
+
- Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94)]:
|
|
141
|
+
- @atlaspack/diagnostic@2.14.2
|
|
142
|
+
- @atlaspack/plugin@2.14.22
|
|
143
|
+
- @atlaspack/utils@2.17.4
|
|
144
|
+
|
|
145
|
+
## 2.14.21
|
|
146
|
+
|
|
147
|
+
### Patch Changes
|
|
148
|
+
|
|
149
|
+
- Updated dependencies []:
|
|
150
|
+
- @atlaspack/utils@2.17.3
|
|
151
|
+
- @atlaspack/plugin@2.14.21
|
|
152
|
+
|
|
153
|
+
## 2.14.20
|
|
154
|
+
|
|
155
|
+
### Patch Changes
|
|
156
|
+
|
|
157
|
+
- [#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
|
|
158
|
+
|
|
159
|
+
- Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa)]:
|
|
160
|
+
- @atlaspack/plugin@2.14.20
|
|
161
|
+
- @atlaspack/utils@2.17.2
|
|
162
|
+
|
|
163
|
+
## 2.14.19
|
|
164
|
+
|
|
165
|
+
### Patch Changes
|
|
166
|
+
|
|
167
|
+
- Updated dependencies []:
|
|
168
|
+
- @atlaspack/utils@2.17.1
|
|
169
|
+
- @atlaspack/plugin@2.14.19
|
|
170
|
+
|
|
171
|
+
## 2.14.18
|
|
172
|
+
|
|
173
|
+
### Patch Changes
|
|
174
|
+
|
|
175
|
+
- 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)]:
|
|
176
|
+
- @atlaspack/utils@2.17.0
|
|
177
|
+
- @atlaspack/plugin@2.14.18
|
|
178
|
+
|
|
179
|
+
## 2.14.17
|
|
180
|
+
|
|
181
|
+
### Patch Changes
|
|
182
|
+
|
|
183
|
+
- Updated dependencies []:
|
|
184
|
+
- @atlaspack/utils@2.16.1
|
|
185
|
+
- @atlaspack/plugin@2.14.17
|
|
186
|
+
|
|
187
|
+
## 2.14.16
|
|
188
|
+
|
|
189
|
+
### Patch Changes
|
|
190
|
+
|
|
191
|
+
- Updated dependencies [[`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
|
|
192
|
+
- @atlaspack/utils@2.16.0
|
|
193
|
+
- @atlaspack/plugin@2.14.16
|
|
194
|
+
|
|
195
|
+
## 2.14.15
|
|
196
|
+
|
|
197
|
+
### Patch Changes
|
|
198
|
+
|
|
199
|
+
- Updated dependencies []:
|
|
200
|
+
- @atlaspack/utils@2.15.3
|
|
201
|
+
- @atlaspack/plugin@2.14.15
|
|
202
|
+
|
|
203
|
+
## 2.14.14
|
|
204
|
+
|
|
205
|
+
### Patch Changes
|
|
206
|
+
|
|
207
|
+
- Updated dependencies []:
|
|
208
|
+
- @atlaspack/utils@2.15.2
|
|
209
|
+
- @atlaspack/plugin@2.14.14
|
|
210
|
+
|
|
211
|
+
## 2.14.13
|
|
212
|
+
|
|
213
|
+
### Patch Changes
|
|
214
|
+
|
|
215
|
+
- Updated dependencies []:
|
|
216
|
+
- @atlaspack/utils@2.15.1
|
|
217
|
+
- @atlaspack/plugin@2.14.13
|
|
218
|
+
|
|
219
|
+
## 2.14.12
|
|
220
|
+
|
|
221
|
+
### Patch Changes
|
|
222
|
+
|
|
223
|
+
- Updated dependencies [[`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
|
|
224
|
+
- @atlaspack/utils@2.15.0
|
|
225
|
+
- @atlaspack/plugin@2.14.12
|
|
226
|
+
|
|
227
|
+
## 2.14.11
|
|
228
|
+
|
|
229
|
+
### Patch Changes
|
|
230
|
+
|
|
231
|
+
- Updated dependencies []:
|
|
232
|
+
- @atlaspack/utils@2.14.11
|
|
233
|
+
- @atlaspack/plugin@2.14.11
|
|
234
|
+
|
|
235
|
+
## 2.14.10
|
|
236
|
+
|
|
237
|
+
### Patch Changes
|
|
238
|
+
|
|
239
|
+
- Updated dependencies []:
|
|
240
|
+
- @atlaspack/plugin@2.14.10
|
|
241
|
+
- @atlaspack/utils@2.14.10
|
|
242
|
+
|
|
243
|
+
## 2.14.9
|
|
244
|
+
|
|
245
|
+
### Patch Changes
|
|
246
|
+
|
|
247
|
+
- Updated dependencies []:
|
|
248
|
+
- @atlaspack/utils@2.14.9
|
|
249
|
+
- @atlaspack/plugin@2.14.9
|
|
250
|
+
|
|
251
|
+
## 2.14.8
|
|
252
|
+
|
|
253
|
+
### Patch Changes
|
|
254
|
+
|
|
255
|
+
- Updated dependencies []:
|
|
256
|
+
- @atlaspack/utils@2.14.8
|
|
257
|
+
- @atlaspack/plugin@2.14.8
|
|
258
|
+
|
|
3
259
|
## 2.14.7
|
|
4
260
|
|
|
5
261
|
### Patch Changes
|
|
@@ -0,0 +1,330 @@
|
|
|
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
|
+
exports.getSpecifier = getSpecifier;
|
|
40
|
+
const lightningcss_1 = __importStar(require("lightningcss"));
|
|
41
|
+
const assert_1 = __importDefault(require("assert"));
|
|
42
|
+
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
43
|
+
const source_map_1 = __importDefault(require("@parcel/source-map"));
|
|
44
|
+
const plugin_1 = require("@atlaspack/plugin");
|
|
45
|
+
const diagnostic_1 = require("@atlaspack/diagnostic");
|
|
46
|
+
const utils_1 = require("@atlaspack/utils");
|
|
47
|
+
exports.default = new plugin_1.Packager({
|
|
48
|
+
async package({ bundle, bundleGraph, getInlineBundleContents, getSourceMapReference, logger, options, }) {
|
|
49
|
+
// Inline style attributes are parsed differently from full CSS files.
|
|
50
|
+
if (bundle.bundleBehavior === 'inline') {
|
|
51
|
+
let entry = bundle.getMainEntry();
|
|
52
|
+
if (entry?.meta.type === 'attr') {
|
|
53
|
+
return replaceReferences(bundle, bundleGraph, await entry.getCode(), await entry.getMap(), getInlineBundleContents);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
let queue = new utils_1.PromiseQueue({
|
|
57
|
+
maxConcurrent: 32,
|
|
58
|
+
});
|
|
59
|
+
// @ts-expect-error TS2304
|
|
60
|
+
let hoistedImports = [];
|
|
61
|
+
let assetsByPlaceholder = new Map();
|
|
62
|
+
// @ts-expect-error TS7034
|
|
63
|
+
let entry = null;
|
|
64
|
+
let entryContents = '';
|
|
65
|
+
bundle.traverse({
|
|
66
|
+
enter: (node, context) => {
|
|
67
|
+
if (node.type === 'asset' && !context) {
|
|
68
|
+
// If there is only one entry, we'll use it directly.
|
|
69
|
+
// Otherwise, we'll create a fake bundle entry with @import rules for each root asset.
|
|
70
|
+
// @ts-expect-error TS7005
|
|
71
|
+
if (entry == null) {
|
|
72
|
+
entry = node.value.id;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
entry = bundle.id;
|
|
76
|
+
}
|
|
77
|
+
assetsByPlaceholder.set(node.value.id, node.value);
|
|
78
|
+
entryContents += `@import "${node.value.id}";\n`;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
},
|
|
82
|
+
exit: (node) => {
|
|
83
|
+
if (node.type === 'dependency') {
|
|
84
|
+
let resolved = bundleGraph.getResolvedAsset(node.value, bundle);
|
|
85
|
+
// Hoist unresolved external dependencies (i.e. http: imports)
|
|
86
|
+
if (node.value.priority === 'sync' &&
|
|
87
|
+
!bundleGraph.isDependencySkipped(node.value) &&
|
|
88
|
+
!resolved) {
|
|
89
|
+
hoistedImports.push(node.value.specifier);
|
|
90
|
+
}
|
|
91
|
+
if (resolved && bundle.hasAsset(resolved)) {
|
|
92
|
+
assetsByPlaceholder.set(node.value.meta.placeholder ?? node.value.specifier, resolved);
|
|
93
|
+
}
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
let asset = node.value;
|
|
97
|
+
queue.add(() => {
|
|
98
|
+
if (!asset.symbols.isCleared &&
|
|
99
|
+
options.mode === 'production' &&
|
|
100
|
+
asset.astGenerator?.type === 'postcss') {
|
|
101
|
+
// a CSS Modules asset
|
|
102
|
+
return processCSSModule(options, logger, bundleGraph, bundle, asset);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
return Promise.all([
|
|
106
|
+
asset,
|
|
107
|
+
asset.getCode().then((css) => {
|
|
108
|
+
// Replace CSS variable references with resolved symbols.
|
|
109
|
+
if (asset.meta.hasReferences) {
|
|
110
|
+
let replacements = new Map();
|
|
111
|
+
for (let dep of asset.getDependencies()) {
|
|
112
|
+
for (let [exported, { local }] of dep.symbols) {
|
|
113
|
+
let resolved = bundleGraph.getResolvedAsset(dep, bundle);
|
|
114
|
+
if (resolved) {
|
|
115
|
+
let resolution = bundleGraph.getSymbolResolution(resolved, exported, bundle);
|
|
116
|
+
if (resolution.symbol) {
|
|
117
|
+
replacements.set(local, resolution.symbol);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (replacements.size > 0) {
|
|
123
|
+
let regex = new RegExp([...replacements.keys()].join('|'), 'g');
|
|
124
|
+
css = css.replace(regex, (m) => escapeDashedIdent(replacements.get(m) || m));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return css;
|
|
128
|
+
}),
|
|
129
|
+
bundle.env.sourceMap ? asset.getMap() : null,
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
let outputs = new Map(
|
|
136
|
+
// @ts-expect-error TS2345
|
|
137
|
+
(await queue.run()).map(([asset, code, map]) => [
|
|
138
|
+
asset,
|
|
139
|
+
[code, map],
|
|
140
|
+
]));
|
|
141
|
+
let map = new source_map_1.default(options.projectRoot);
|
|
142
|
+
// @ts-expect-error TS2339
|
|
143
|
+
if (process.browser) {
|
|
144
|
+
// @ts-expect-error TS2349
|
|
145
|
+
await (0, lightningcss_1.default)();
|
|
146
|
+
}
|
|
147
|
+
let res = await (0, lightningcss_1.bundleAsync)({
|
|
148
|
+
// @ts-expect-error TS2322
|
|
149
|
+
filename: (0, nullthrows_1.default)(entry),
|
|
150
|
+
sourceMap: !!bundle.env.sourceMap,
|
|
151
|
+
resolver: {
|
|
152
|
+
resolve(specifier) {
|
|
153
|
+
return specifier;
|
|
154
|
+
},
|
|
155
|
+
async read(file) {
|
|
156
|
+
if (file === bundle.id) {
|
|
157
|
+
return entryContents;
|
|
158
|
+
}
|
|
159
|
+
let asset = assetsByPlaceholder.get(file);
|
|
160
|
+
if (!asset) {
|
|
161
|
+
return '';
|
|
162
|
+
}
|
|
163
|
+
let [code, map] = (0, nullthrows_1.default)(outputs.get(asset));
|
|
164
|
+
if (map) {
|
|
165
|
+
let sm = await map.stringify({ format: 'inline' });
|
|
166
|
+
(0, assert_1.default)(typeof sm === 'string');
|
|
167
|
+
code += `\n/*# sourceMappingURL=${sm} */`;
|
|
168
|
+
}
|
|
169
|
+
return code;
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
let contents = res.code.toString();
|
|
174
|
+
if (res.map) {
|
|
175
|
+
let vlqMap = JSON.parse(res.map.toString());
|
|
176
|
+
map.addVLQMap(vlqMap);
|
|
177
|
+
let reference = await getSourceMapReference(map);
|
|
178
|
+
if (reference != null) {
|
|
179
|
+
contents += '/*# sourceMappingURL=' + reference + ' */\n';
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// Prepend hoisted external imports.
|
|
183
|
+
if (hoistedImports.length > 0) {
|
|
184
|
+
let lineOffset = 0;
|
|
185
|
+
let hoistedCode = '';
|
|
186
|
+
for (let url of hoistedImports) {
|
|
187
|
+
hoistedCode += `@import "${url}";\n`;
|
|
188
|
+
lineOffset++;
|
|
189
|
+
}
|
|
190
|
+
if (bundle.env.sourceMap) {
|
|
191
|
+
map.offsetLines(1, lineOffset);
|
|
192
|
+
}
|
|
193
|
+
contents = hoistedCode + contents;
|
|
194
|
+
}
|
|
195
|
+
return replaceReferences(bundle, bundleGraph, contents, map, getInlineBundleContents);
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
function replaceReferences(
|
|
199
|
+
// @ts-expect-error TS2304
|
|
200
|
+
bundle,
|
|
201
|
+
// @ts-expect-error TS2304
|
|
202
|
+
bundleGraph, contents,
|
|
203
|
+
// @ts-expect-error TS2552
|
|
204
|
+
map, getInlineBundleContents) {
|
|
205
|
+
({ contents, map } = (0, utils_1.replaceURLReferences)({
|
|
206
|
+
bundle,
|
|
207
|
+
bundleGraph,
|
|
208
|
+
contents,
|
|
209
|
+
map,
|
|
210
|
+
getReplacement: escapeString,
|
|
211
|
+
}));
|
|
212
|
+
return (0, utils_1.replaceInlineReferences)({
|
|
213
|
+
bundle,
|
|
214
|
+
bundleGraph,
|
|
215
|
+
contents,
|
|
216
|
+
getInlineBundleContents,
|
|
217
|
+
getInlineReplacement: (dep, inlineType, contents) => ({
|
|
218
|
+
from: getSpecifier(dep),
|
|
219
|
+
to: escapeString(contents),
|
|
220
|
+
}),
|
|
221
|
+
map,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
function getSpecifier(dep) {
|
|
225
|
+
if (typeof dep.meta.placeholder === 'string') {
|
|
226
|
+
return dep.meta.placeholder;
|
|
227
|
+
}
|
|
228
|
+
return dep.id;
|
|
229
|
+
}
|
|
230
|
+
function escapeString(contents) {
|
|
231
|
+
return contents.replace(/(["\\])/g, '\\$1');
|
|
232
|
+
}
|
|
233
|
+
async function processCSSModule(
|
|
234
|
+
// @ts-expect-error TS2552
|
|
235
|
+
options,
|
|
236
|
+
// @ts-expect-error TS2304
|
|
237
|
+
logger,
|
|
238
|
+
// @ts-expect-error TS2304
|
|
239
|
+
bundleGraph,
|
|
240
|
+
// @ts-expect-error TS2304
|
|
241
|
+
bundle, asset) {
|
|
242
|
+
// @ts-expect-error TS2709
|
|
243
|
+
let postcss = await options.packageManager.require('postcss', options.projectRoot + '/index', {
|
|
244
|
+
range: '^8.4.5',
|
|
245
|
+
saveDev: true,
|
|
246
|
+
shouldAutoInstall: options.shouldAutoInstall,
|
|
247
|
+
});
|
|
248
|
+
let ast = postcss.fromJSON((0, nullthrows_1.default)((await asset.getAST())?.program));
|
|
249
|
+
let usedSymbols = bundleGraph.getUsedSymbols(asset);
|
|
250
|
+
if (usedSymbols != null) {
|
|
251
|
+
let localSymbols = new Set([...asset.symbols].map(([, { local }]) => `.${local}`));
|
|
252
|
+
let defaultImport = null;
|
|
253
|
+
if (usedSymbols.has('default')) {
|
|
254
|
+
let incoming = bundleGraph.getIncomingDependencies(asset);
|
|
255
|
+
// @ts-expect-error TS7006
|
|
256
|
+
defaultImport = incoming.find((d) => d.symbols.hasExportSymbol('default'));
|
|
257
|
+
if (defaultImport) {
|
|
258
|
+
let loc = defaultImport.symbols.get('default')?.loc;
|
|
259
|
+
logger.warn({
|
|
260
|
+
message: 'CSS modules cannot be tree shaken when imported with a default specifier',
|
|
261
|
+
...(loc && {
|
|
262
|
+
codeFrames: [
|
|
263
|
+
{
|
|
264
|
+
filePath: (0, nullthrows_1.default)(loc?.filePath ?? defaultImport.sourcePath),
|
|
265
|
+
codeHighlights: [(0, diagnostic_1.convertSourceLocationToHighlight)(loc)],
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
}),
|
|
269
|
+
hints: [
|
|
270
|
+
`Instead do: import * as style from "${defaultImport.specifier}";`,
|
|
271
|
+
],
|
|
272
|
+
documentationURL: 'https://parceljs.org/languages/css/#tree-shaking',
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (!defaultImport && !usedSymbols.has('*')) {
|
|
277
|
+
let usedLocalSymbols = new Set([...usedSymbols].map((exportSymbol) => `.${(0, nullthrows_1.default)(asset.symbols.get(exportSymbol)).local}`));
|
|
278
|
+
ast.walkRules((rule) => {
|
|
279
|
+
if (localSymbols.has(rule.selector) &&
|
|
280
|
+
!usedLocalSymbols.has(rule.selector)) {
|
|
281
|
+
rule.remove();
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
let { content, map } = await postcss().process(ast, {
|
|
287
|
+
from: undefined,
|
|
288
|
+
to: options.projectRoot + '/index',
|
|
289
|
+
map: {
|
|
290
|
+
annotation: false,
|
|
291
|
+
inline: false,
|
|
292
|
+
},
|
|
293
|
+
// Pass postcss's own stringifier to it to silence its warning
|
|
294
|
+
// as we don't want to perform any transformations -- only generate
|
|
295
|
+
stringifier: postcss.stringify,
|
|
296
|
+
});
|
|
297
|
+
let sourceMap;
|
|
298
|
+
if (bundle.env.sourceMap && map != null) {
|
|
299
|
+
sourceMap = new source_map_1.default(options.projectRoot);
|
|
300
|
+
sourceMap.addVLQMap(map.toJSON());
|
|
301
|
+
}
|
|
302
|
+
return [asset, content, sourceMap];
|
|
303
|
+
}
|
|
304
|
+
function escapeDashedIdent(name) {
|
|
305
|
+
// https://drafts.csswg.org/cssom/#serialize-an-identifier
|
|
306
|
+
let res = '';
|
|
307
|
+
// @ts-expect-error TS2488
|
|
308
|
+
for (let c of name) {
|
|
309
|
+
let code = c.codePointAt(0);
|
|
310
|
+
if (code === 0) {
|
|
311
|
+
res += '\ufffd';
|
|
312
|
+
}
|
|
313
|
+
else if ((code >= 0x1 && code <= 0x1f) || code === 0x7f) {
|
|
314
|
+
res += '\\' + code.toString(16) + ' ';
|
|
315
|
+
}
|
|
316
|
+
else if ((code >= 48 /* '0' */ && code <= 57) /* '9' */ ||
|
|
317
|
+
(code >= 65 /* 'A' */ && code <= 90) /* 'Z' */ ||
|
|
318
|
+
(code >= 97 /* 'a' */ && code <= 122) /* 'z' */ ||
|
|
319
|
+
code === 95 /* '_' */ ||
|
|
320
|
+
code === 45 /* '-' */ ||
|
|
321
|
+
code & 128 // non-ascii
|
|
322
|
+
) {
|
|
323
|
+
res += c;
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
res += '\\' + c;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return res;
|
|
330
|
+
}
|
package/lib/CSSPackager.js
CHANGED
|
@@ -57,7 +57,6 @@ function _utils() {
|
|
|
57
57
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
58
58
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
59
59
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
60
|
-
// $FlowFixMe - init for browser build.
|
|
61
60
|
var _default = exports.default = new (_plugin().Packager)({
|
|
62
61
|
async package({
|
|
63
62
|
bundle,
|
|
@@ -77,8 +76,10 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
77
76
|
let queue = new (_utils().PromiseQueue)({
|
|
78
77
|
maxConcurrent: 32
|
|
79
78
|
});
|
|
79
|
+
// @ts-expect-error TS2304
|
|
80
80
|
let hoistedImports = [];
|
|
81
81
|
let assetsByPlaceholder = new Map();
|
|
82
|
+
// @ts-expect-error TS7034
|
|
82
83
|
let entry = null;
|
|
83
84
|
let entryContents = '';
|
|
84
85
|
bundle.traverse({
|
|
@@ -86,6 +87,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
86
87
|
if (node.type === 'asset' && !context) {
|
|
87
88
|
// If there is only one entry, we'll use it directly.
|
|
88
89
|
// Otherwise, we'll create a fake bundle entry with @import rules for each root asset.
|
|
90
|
+
// @ts-expect-error TS7005
|
|
89
91
|
if (entry == null) {
|
|
90
92
|
entry = node.value.id;
|
|
91
93
|
} else {
|
|
@@ -144,14 +146,18 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
144
146
|
});
|
|
145
147
|
}
|
|
146
148
|
});
|
|
147
|
-
let outputs = new Map(
|
|
149
|
+
let outputs = new Map(
|
|
150
|
+
// @ts-expect-error TS2345
|
|
151
|
+
(await queue.run()).map(([asset, code, map]) => [asset, [code, map]]));
|
|
148
152
|
let map = new (_sourceMap().default)(options.projectRoot);
|
|
149
153
|
|
|
150
|
-
//
|
|
154
|
+
// @ts-expect-error TS2339
|
|
151
155
|
if (process.browser) {
|
|
156
|
+
// @ts-expect-error TS2349
|
|
152
157
|
await (0, _lightningcss().default)();
|
|
153
158
|
}
|
|
154
159
|
let res = await (0, _lightningcss().bundleAsync)({
|
|
160
|
+
// @ts-expect-error TS2322
|
|
155
161
|
filename: (0, _nullthrows().default)(entry),
|
|
156
162
|
sourceMap: !!bundle.env.sourceMap,
|
|
157
163
|
resolver: {
|
|
@@ -204,7 +210,13 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
204
210
|
return replaceReferences(bundle, bundleGraph, contents, map, getInlineBundleContents);
|
|
205
211
|
}
|
|
206
212
|
});
|
|
207
|
-
function replaceReferences(
|
|
213
|
+
function replaceReferences(
|
|
214
|
+
// @ts-expect-error TS2304
|
|
215
|
+
bundle,
|
|
216
|
+
// @ts-expect-error TS2304
|
|
217
|
+
bundleGraph, contents,
|
|
218
|
+
// @ts-expect-error TS2552
|
|
219
|
+
map, getInlineBundleContents) {
|
|
208
220
|
({
|
|
209
221
|
contents,
|
|
210
222
|
map
|
|
@@ -236,8 +248,17 @@ function getSpecifier(dep) {
|
|
|
236
248
|
function escapeString(contents) {
|
|
237
249
|
return contents.replace(/(["\\])/g, '\\$1');
|
|
238
250
|
}
|
|
239
|
-
async function processCSSModule(
|
|
251
|
+
async function processCSSModule(
|
|
252
|
+
// @ts-expect-error TS2552
|
|
253
|
+
options,
|
|
254
|
+
// @ts-expect-error TS2304
|
|
255
|
+
logger,
|
|
256
|
+
// @ts-expect-error TS2304
|
|
257
|
+
bundleGraph,
|
|
258
|
+
// @ts-expect-error TS2304
|
|
259
|
+
bundle, asset) {
|
|
240
260
|
var _await$asset$getAST;
|
|
261
|
+
// @ts-expect-error TS2709
|
|
241
262
|
let postcss = await options.packageManager.require('postcss', options.projectRoot + '/index', {
|
|
242
263
|
range: '^8.4.5',
|
|
243
264
|
saveDev: true,
|
|
@@ -252,6 +273,7 @@ async function processCSSModule(options, logger, bundleGraph, bundle, asset) {
|
|
|
252
273
|
let defaultImport = null;
|
|
253
274
|
if (usedSymbols.has('default')) {
|
|
254
275
|
let incoming = bundleGraph.getIncomingDependencies(asset);
|
|
276
|
+
// @ts-expect-error TS7006
|
|
255
277
|
defaultImport = incoming.find(d => d.symbols.hasExportSymbol('default'));
|
|
256
278
|
if (defaultImport) {
|
|
257
279
|
var _defaultImport$symbol;
|
|
@@ -302,6 +324,7 @@ async function processCSSModule(options, logger, bundleGraph, bundle, asset) {
|
|
|
302
324
|
function escapeDashedIdent(name) {
|
|
303
325
|
// https://drafts.csswg.org/cssom/#serialize-an-identifier
|
|
304
326
|
let res = '';
|
|
327
|
+
// @ts-expect-error TS2488
|
|
305
328
|
for (let c of name) {
|
|
306
329
|
let code = c.codePointAt(0);
|
|
307
330
|
if (code === 0) {
|