@atlaspack/packager-css 2.14.5-canary.49 → 2.14.5-canary.490
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 +518 -0
- package/dist/CSSPackager.js +330 -0
- package/lib/CSSPackager.js +31 -9
- package/lib/types/CSSPackager.d.ts +5 -0
- package/package.json +14 -9
- package/src/{CSSPackager.js → CSSPackager.ts} +50 -26
- package/tsconfig.json +24 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -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("@atlaspack/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
|
@@ -27,7 +27,7 @@ function _nullthrows() {
|
|
|
27
27
|
return data;
|
|
28
28
|
}
|
|
29
29
|
function _sourceMap() {
|
|
30
|
-
const data = _interopRequireDefault(require("@
|
|
30
|
+
const data = _interopRequireDefault(require("@atlaspack/source-map"));
|
|
31
31
|
_sourceMap = function () {
|
|
32
32
|
return data;
|
|
33
33
|
};
|
|
@@ -54,10 +54,8 @@ function _utils() {
|
|
|
54
54
|
};
|
|
55
55
|
return data;
|
|
56
56
|
}
|
|
57
|
-
function _interopRequireDefault(
|
|
58
|
-
function
|
|
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.
|
|
57
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
58
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
61
59
|
var _default = exports.default = new (_plugin().Packager)({
|
|
62
60
|
async package({
|
|
63
61
|
bundle,
|
|
@@ -77,8 +75,10 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
77
75
|
let queue = new (_utils().PromiseQueue)({
|
|
78
76
|
maxConcurrent: 32
|
|
79
77
|
});
|
|
78
|
+
// @ts-expect-error TS2304
|
|
80
79
|
let hoistedImports = [];
|
|
81
80
|
let assetsByPlaceholder = new Map();
|
|
81
|
+
// @ts-expect-error TS7034
|
|
82
82
|
let entry = null;
|
|
83
83
|
let entryContents = '';
|
|
84
84
|
bundle.traverse({
|
|
@@ -86,6 +86,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
86
86
|
if (node.type === 'asset' && !context) {
|
|
87
87
|
// If there is only one entry, we'll use it directly.
|
|
88
88
|
// Otherwise, we'll create a fake bundle entry with @import rules for each root asset.
|
|
89
|
+
// @ts-expect-error TS7005
|
|
89
90
|
if (entry == null) {
|
|
90
91
|
entry = node.value.id;
|
|
91
92
|
} else {
|
|
@@ -144,14 +145,18 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
144
145
|
});
|
|
145
146
|
}
|
|
146
147
|
});
|
|
147
|
-
let outputs = new Map(
|
|
148
|
+
let outputs = new Map(
|
|
149
|
+
// @ts-expect-error TS2345
|
|
150
|
+
(await queue.run()).map(([asset, code, map]) => [asset, [code, map]]));
|
|
148
151
|
let map = new (_sourceMap().default)(options.projectRoot);
|
|
149
152
|
|
|
150
|
-
//
|
|
153
|
+
// @ts-expect-error TS2339
|
|
151
154
|
if (process.browser) {
|
|
155
|
+
// @ts-expect-error TS2349
|
|
152
156
|
await (0, _lightningcss().default)();
|
|
153
157
|
}
|
|
154
158
|
let res = await (0, _lightningcss().bundleAsync)({
|
|
159
|
+
// @ts-expect-error TS2322
|
|
155
160
|
filename: (0, _nullthrows().default)(entry),
|
|
156
161
|
sourceMap: !!bundle.env.sourceMap,
|
|
157
162
|
resolver: {
|
|
@@ -204,7 +209,13 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
204
209
|
return replaceReferences(bundle, bundleGraph, contents, map, getInlineBundleContents);
|
|
205
210
|
}
|
|
206
211
|
});
|
|
207
|
-
function replaceReferences(
|
|
212
|
+
function replaceReferences(
|
|
213
|
+
// @ts-expect-error TS2304
|
|
214
|
+
bundle,
|
|
215
|
+
// @ts-expect-error TS2304
|
|
216
|
+
bundleGraph, contents,
|
|
217
|
+
// @ts-expect-error TS2552
|
|
218
|
+
map, getInlineBundleContents) {
|
|
208
219
|
({
|
|
209
220
|
contents,
|
|
210
221
|
map
|
|
@@ -236,8 +247,17 @@ function getSpecifier(dep) {
|
|
|
236
247
|
function escapeString(contents) {
|
|
237
248
|
return contents.replace(/(["\\])/g, '\\$1');
|
|
238
249
|
}
|
|
239
|
-
async function processCSSModule(
|
|
250
|
+
async function processCSSModule(
|
|
251
|
+
// @ts-expect-error TS2552
|
|
252
|
+
options,
|
|
253
|
+
// @ts-expect-error TS2304
|
|
254
|
+
logger,
|
|
255
|
+
// @ts-expect-error TS2304
|
|
256
|
+
bundleGraph,
|
|
257
|
+
// @ts-expect-error TS2304
|
|
258
|
+
bundle, asset) {
|
|
240
259
|
var _await$asset$getAST;
|
|
260
|
+
// @ts-expect-error TS2709
|
|
241
261
|
let postcss = await options.packageManager.require('postcss', options.projectRoot + '/index', {
|
|
242
262
|
range: '^8.4.5',
|
|
243
263
|
saveDev: true,
|
|
@@ -252,6 +272,7 @@ async function processCSSModule(options, logger, bundleGraph, bundle, asset) {
|
|
|
252
272
|
let defaultImport = null;
|
|
253
273
|
if (usedSymbols.has('default')) {
|
|
254
274
|
let incoming = bundleGraph.getIncomingDependencies(asset);
|
|
275
|
+
// @ts-expect-error TS7006
|
|
255
276
|
defaultImport = incoming.find(d => d.symbols.hasExportSymbol('default'));
|
|
256
277
|
if (defaultImport) {
|
|
257
278
|
var _defaultImport$symbol;
|
|
@@ -302,6 +323,7 @@ async function processCSSModule(options, logger, bundleGraph, bundle, asset) {
|
|
|
302
323
|
function escapeDashedIdent(name) {
|
|
303
324
|
// https://drafts.csswg.org/cssom/#serialize-an-identifier
|
|
304
325
|
let res = '';
|
|
326
|
+
// @ts-expect-error TS2488
|
|
305
327
|
for (let c of name) {
|
|
306
328
|
let code = c.codePointAt(0);
|
|
307
329
|
if (code === 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/packager-css",
|
|
3
|
-
"version": "2.14.5-canary.
|
|
3
|
+
"version": "2.14.5-canary.490+c97de81b0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -9,16 +9,18 @@
|
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
11
11
|
},
|
|
12
|
-
"main": "lib/CSSPackager.js",
|
|
13
|
-
"source": "src/CSSPackager.
|
|
12
|
+
"main": "./lib/CSSPackager.js",
|
|
13
|
+
"source": "./src/CSSPackager.ts",
|
|
14
|
+
"types": "./lib/types/CSSPackager.d.ts",
|
|
14
15
|
"engines": {
|
|
15
16
|
"node": ">= 16.0.0"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@atlaspack/diagnostic": "2.14.1-canary.
|
|
19
|
-
"@atlaspack/plugin": "2.14.5-canary.
|
|
20
|
-
"@atlaspack/
|
|
21
|
-
"@
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.1-canary.558+c97de81b0",
|
|
20
|
+
"@atlaspack/plugin": "2.14.5-canary.490+c97de81b0",
|
|
21
|
+
"@atlaspack/source-map": "3.3.8-canary.4269+c97de81b0",
|
|
22
|
+
"@atlaspack/types-internal": "2.14.1-canary.558+c97de81b0",
|
|
23
|
+
"@atlaspack/utils": "2.14.5-canary.490+c97de81b0",
|
|
22
24
|
"lightningcss": "^1.28.2",
|
|
23
25
|
"nullthrows": "^1.1.1"
|
|
24
26
|
},
|
|
@@ -30,5 +32,8 @@
|
|
|
30
32
|
"lightningcss": "lightningcss-wasm"
|
|
31
33
|
},
|
|
32
34
|
"type": "commonjs",
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
37
|
+
},
|
|
38
|
+
"gitHead": "c97de81b0b4b866bef4396e9131f37ffd273258d"
|
|
39
|
+
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import type {Root} from 'postcss';
|
|
4
|
-
import type {Asset, Dependency} from '@atlaspack/types';
|
|
5
|
-
import
|
|
6
|
-
// $FlowFixMe - init for browser build.
|
|
2
|
+
import type {Asset, Dependency} from '@atlaspack/types-internal';
|
|
3
|
+
import PostCSS from 'postcss';
|
|
7
4
|
import init, {bundleAsync} from 'lightningcss';
|
|
8
5
|
|
|
9
6
|
import invariant from 'assert';
|
|
10
7
|
import nullthrows from 'nullthrows';
|
|
11
|
-
import SourceMap from '@
|
|
8
|
+
import SourceMap from '@atlaspack/source-map';
|
|
12
9
|
import {Packager} from '@atlaspack/plugin';
|
|
13
10
|
import {convertSourceLocationToHighlight} from '@atlaspack/diagnostic';
|
|
14
11
|
import {
|
|
@@ -17,7 +14,7 @@ import {
|
|
|
17
14
|
replaceURLReferences,
|
|
18
15
|
} from '@atlaspack/utils';
|
|
19
16
|
|
|
20
|
-
export default
|
|
17
|
+
export default new Packager({
|
|
21
18
|
async package({
|
|
22
19
|
bundle,
|
|
23
20
|
bundleGraph,
|
|
@@ -43,8 +40,10 @@ export default (new Packager({
|
|
|
43
40
|
let queue = new PromiseQueue({
|
|
44
41
|
maxConcurrent: 32,
|
|
45
42
|
});
|
|
46
|
-
|
|
43
|
+
// @ts-expect-error TS2304
|
|
44
|
+
let hoistedImports: Array<DependencySpecifier> = [];
|
|
47
45
|
let assetsByPlaceholder = new Map();
|
|
46
|
+
// @ts-expect-error TS7034
|
|
48
47
|
let entry = null;
|
|
49
48
|
let entryContents = '';
|
|
50
49
|
|
|
@@ -53,6 +52,7 @@ export default (new Packager({
|
|
|
53
52
|
if (node.type === 'asset' && !context) {
|
|
54
53
|
// If there is only one entry, we'll use it directly.
|
|
55
54
|
// Otherwise, we'll create a fake bundle entry with @import rules for each root asset.
|
|
55
|
+
// @ts-expect-error TS7005
|
|
56
56
|
if (entry == null) {
|
|
57
57
|
entry = node.value.id;
|
|
58
58
|
} else {
|
|
@@ -145,23 +145,29 @@ export default (new Packager({
|
|
|
145
145
|
});
|
|
146
146
|
|
|
147
147
|
let outputs = new Map(
|
|
148
|
-
|
|
148
|
+
// @ts-expect-error TS2345
|
|
149
|
+
(await queue.run()).map(([asset, code, map]: [any, any, any]) => [
|
|
150
|
+
asset,
|
|
151
|
+
[code, map],
|
|
152
|
+
]),
|
|
149
153
|
);
|
|
150
154
|
let map = new SourceMap(options.projectRoot);
|
|
151
155
|
|
|
152
|
-
//
|
|
156
|
+
// @ts-expect-error TS2339
|
|
153
157
|
if (process.browser) {
|
|
158
|
+
// @ts-expect-error TS2349
|
|
154
159
|
await init();
|
|
155
160
|
}
|
|
156
161
|
|
|
157
162
|
let res = await bundleAsync({
|
|
163
|
+
// @ts-expect-error TS2322
|
|
158
164
|
filename: nullthrows(entry),
|
|
159
165
|
sourceMap: !!bundle.env.sourceMap,
|
|
160
166
|
resolver: {
|
|
161
|
-
resolve(specifier) {
|
|
167
|
+
resolve(specifier: string) {
|
|
162
168
|
return specifier;
|
|
163
169
|
},
|
|
164
|
-
async read(file) {
|
|
170
|
+
async read(file: string) {
|
|
165
171
|
if (file === bundle.id) {
|
|
166
172
|
return entryContents;
|
|
167
173
|
}
|
|
@@ -216,14 +222,25 @@ export default (new Packager({
|
|
|
216
222
|
getInlineBundleContents,
|
|
217
223
|
);
|
|
218
224
|
},
|
|
219
|
-
})
|
|
225
|
+
}) as Packager<unknown, unknown>;
|
|
220
226
|
|
|
221
227
|
function replaceReferences(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
228
|
+
// @ts-expect-error TS2304
|
|
229
|
+
bundle: NamedBundle,
|
|
230
|
+
// @ts-expect-error TS2304
|
|
231
|
+
bundleGraph: BundleGraph<NamedBundle>,
|
|
232
|
+
contents: string,
|
|
233
|
+
// @ts-expect-error TS2552
|
|
234
|
+
map: NodeSourceMap | null | undefined,
|
|
235
|
+
getInlineBundleContents: (
|
|
236
|
+
// @ts-expect-error TS2304
|
|
237
|
+
arg1: Bundle,
|
|
238
|
+
// @ts-expect-error TS2304
|
|
239
|
+
arg2: BundleGraph<NamedBundle>,
|
|
240
|
+
// @ts-expect-error TS2304
|
|
241
|
+
) => Async<{
|
|
242
|
+
contents: Blob;
|
|
243
|
+
}>,
|
|
227
244
|
) {
|
|
228
245
|
({contents, map} = replaceURLReferences({
|
|
229
246
|
bundle,
|
|
@@ -259,12 +276,17 @@ function escapeString(contents: string): string {
|
|
|
259
276
|
}
|
|
260
277
|
|
|
261
278
|
async function processCSSModule(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
279
|
+
// @ts-expect-error TS2552
|
|
280
|
+
options: PluginOptions,
|
|
281
|
+
// @ts-expect-error TS2304
|
|
282
|
+
logger: PluginLogger,
|
|
283
|
+
// @ts-expect-error TS2304
|
|
284
|
+
bundleGraph: BundleGraph<NamedBundle>,
|
|
285
|
+
// @ts-expect-error TS2304
|
|
286
|
+
bundle: NamedBundle,
|
|
287
|
+
asset: Asset,
|
|
288
|
+
): Promise<[Asset, string, SourceMap | null | undefined]> {
|
|
289
|
+
// @ts-expect-error TS2709
|
|
268
290
|
let postcss: PostCSS = await options.packageManager.require(
|
|
269
291
|
'postcss',
|
|
270
292
|
options.projectRoot + '/index',
|
|
@@ -280,12 +302,13 @@ async function processCSSModule(
|
|
|
280
302
|
let usedSymbols = bundleGraph.getUsedSymbols(asset);
|
|
281
303
|
if (usedSymbols != null) {
|
|
282
304
|
let localSymbols = new Set(
|
|
283
|
-
[...asset.symbols].map(([, {local}]) => `.${local}`),
|
|
305
|
+
[...asset.symbols].map(([, {local}]: [any, any]) => `.${local}`),
|
|
284
306
|
);
|
|
285
307
|
|
|
286
308
|
let defaultImport = null;
|
|
287
309
|
if (usedSymbols.has('default')) {
|
|
288
310
|
let incoming = bundleGraph.getIncomingDependencies(asset);
|
|
311
|
+
// @ts-expect-error TS7006
|
|
289
312
|
defaultImport = incoming.find((d) =>
|
|
290
313
|
d.symbols.hasExportSymbol('default'),
|
|
291
314
|
);
|
|
@@ -349,9 +372,10 @@ async function processCSSModule(
|
|
|
349
372
|
return [asset, content, sourceMap];
|
|
350
373
|
}
|
|
351
374
|
|
|
352
|
-
function escapeDashedIdent(name) {
|
|
375
|
+
function escapeDashedIdent(name: symbol | string) {
|
|
353
376
|
// https://drafts.csswg.org/cssom/#serialize-an-identifier
|
|
354
377
|
let res = '';
|
|
378
|
+
// @ts-expect-error TS2488
|
|
355
379
|
for (let c of name) {
|
|
356
380
|
let code = c.codePointAt(0);
|
|
357
381
|
if (code === 0) {
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.base.json",
|
|
3
|
+
"include": ["src"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"composite": true
|
|
6
|
+
},
|
|
7
|
+
"references": [
|
|
8
|
+
{
|
|
9
|
+
"path": "../../core/diagnostic/tsconfig.json"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "../../core/plugin/tsconfig.json"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "../../core/types-internal/tsconfig.json"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "../../core/utils/tsconfig.json"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"path": "../../core/source-map/tsconfig.json"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|