@parcel/transformer-css 2.0.0-nightly.149 → 2.0.0-nightly.1490
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/lib/CSSTransformer.js +357 -144
- package/package.json +21 -9
- package/src/CSSTransformer.js +351 -139
package/lib/CSSTransformer.js
CHANGED
|
@@ -4,174 +4,387 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
|
15
|
-
|
|
16
|
-
var _semver = _interopRequireDefault(require("semver"));
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
const URL_RE = /url\s*\("?(?![a-z]+:)/;
|
|
21
|
-
const IMPORT_RE = /@import/;
|
|
22
|
-
|
|
23
|
-
function canHaveDependencies(filePath, code) {
|
|
24
|
-
return !/\.css$/.test(filePath) || IMPORT_RE.test(code) || URL_RE.test(code);
|
|
7
|
+
function _path() {
|
|
8
|
+
const data = _interopRequireDefault(require("path"));
|
|
9
|
+
_path = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
25
13
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
14
|
+
function _sourceMap() {
|
|
15
|
+
const data = _interopRequireDefault(require("@parcel/source-map"));
|
|
16
|
+
_sourceMap = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _plugin() {
|
|
22
|
+
const data = require("@parcel/plugin");
|
|
23
|
+
_plugin = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _utils() {
|
|
29
|
+
const data = require("@parcel/utils");
|
|
30
|
+
_utils = function () {
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
function native() {
|
|
36
|
+
const data = _interopRequireWildcard(require("lightningcss"));
|
|
37
|
+
native = function () {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
function _browserslist() {
|
|
43
|
+
const data = _interopRequireDefault(require("browserslist"));
|
|
44
|
+
_browserslist = function () {
|
|
45
|
+
return data;
|
|
46
|
+
};
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
function _nullthrows() {
|
|
50
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
|
51
|
+
_nullthrows = function () {
|
|
52
|
+
return data;
|
|
53
|
+
};
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
function _diagnostic() {
|
|
57
|
+
const data = _interopRequireWildcard(require("@parcel/diagnostic"));
|
|
58
|
+
_diagnostic = function () {
|
|
59
|
+
return data;
|
|
60
|
+
};
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
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); }
|
|
64
|
+
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; }
|
|
65
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
66
|
+
const {
|
|
67
|
+
transform,
|
|
68
|
+
transformStyleAttribute,
|
|
69
|
+
browserslistToTargets
|
|
70
|
+
} = native();
|
|
71
|
+
var _default = exports.default = new (_plugin().Transformer)({
|
|
72
|
+
async loadConfig({
|
|
73
|
+
config,
|
|
74
|
+
options
|
|
36
75
|
}) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
76
|
+
var _contents$cssModules, _contents$cssModules2, _contents$cssModules3, _contents$cssModules4;
|
|
77
|
+
let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
78
|
+
packageKey: '@parcel/transformer-css'
|
|
79
|
+
});
|
|
80
|
+
let contents = conf === null || conf === void 0 ? void 0 : conf.contents;
|
|
81
|
+
if (typeof (contents === null || contents === void 0 || (_contents$cssModules = contents.cssModules) === null || _contents$cssModules === void 0 ? void 0 : _contents$cssModules.include) === 'string') {
|
|
82
|
+
contents.cssModules.include = [(0, _utils().globToRegex)(contents.cssModules.include)];
|
|
83
|
+
} else if (Array.isArray(contents === null || contents === void 0 || (_contents$cssModules2 = contents.cssModules) === null || _contents$cssModules2 === void 0 ? void 0 : _contents$cssModules2.include)) {
|
|
84
|
+
contents.cssModules.include = contents.cssModules.include.map(include => typeof include === 'string' ? (0, _utils().globToRegex)(include) : include);
|
|
45
85
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return null;
|
|
86
|
+
if (typeof (contents === null || contents === void 0 || (_contents$cssModules3 = contents.cssModules) === null || _contents$cssModules3 === void 0 ? void 0 : _contents$cssModules3.exclude) === 'string') {
|
|
87
|
+
contents.cssModules.exclude = [(0, _utils().globToRegex)(contents.cssModules.exclude)];
|
|
88
|
+
} else if (Array.isArray(contents === null || contents === void 0 || (_contents$cssModules4 = contents.cssModules) === null || _contents$cssModules4 === void 0 ? void 0 : _contents$cssModules4.exclude)) {
|
|
89
|
+
contents.cssModules.exclude = contents.cssModules.exclude.map(exclude => typeof exclude === 'string' ? (0, _utils().globToRegex)(exclude) : exclude);
|
|
51
90
|
}
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
type: 'postcss',
|
|
55
|
-
version: '7.0.0',
|
|
56
|
-
isDirty: false,
|
|
57
|
-
program: _postcss.default.parse(code, {
|
|
58
|
-
from: asset.filePath
|
|
59
|
-
})
|
|
60
|
-
};
|
|
91
|
+
return contents;
|
|
61
92
|
},
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
93
|
+
async transform({
|
|
94
|
+
asset,
|
|
95
|
+
config,
|
|
96
|
+
options,
|
|
97
|
+
logger
|
|
65
98
|
}) {
|
|
66
99
|
// Normalize the asset's environment so that properties that only affect JS don't cause CSS to be duplicated.
|
|
67
100
|
// For example, with ESModule and CommonJS targets, only a single shared CSS bundle should be produced.
|
|
101
|
+
let env = asset.env;
|
|
68
102
|
asset.setEnvironment({
|
|
69
103
|
context: 'browser',
|
|
70
104
|
engines: {
|
|
71
105
|
browsers: asset.env.engines.browsers
|
|
72
106
|
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
107
|
+
shouldOptimize: asset.env.shouldOptimize,
|
|
108
|
+
shouldScopeHoist: asset.env.shouldScopeHoist,
|
|
109
|
+
sourceMap: asset.env.sourceMap
|
|
110
|
+
});
|
|
111
|
+
let [code, originalMap] = await Promise.all([asset.getBuffer(), asset.getMap(),
|
|
112
|
+
// $FlowFixMe native.default is the init function only when bundled for the browser build
|
|
113
|
+
process.browser && native().default()]);
|
|
114
|
+
let targets = getTargets(asset.env.engines.browsers);
|
|
115
|
+
let res;
|
|
116
|
+
try {
|
|
117
|
+
if (asset.meta.type === 'attr') {
|
|
118
|
+
res = transformStyleAttribute({
|
|
119
|
+
code,
|
|
120
|
+
analyzeDependencies: true,
|
|
121
|
+
errorRecovery: (config === null || config === void 0 ? void 0 : config.errorRecovery) || false,
|
|
122
|
+
targets
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
let cssModules = false;
|
|
126
|
+
if (asset.meta.type !== 'tag' && asset.meta.cssModulesCompiled == null) {
|
|
127
|
+
let cssModulesConfig = config === null || config === void 0 ? void 0 : config.cssModules;
|
|
128
|
+
let isCSSModule = /\.module\./.test(asset.filePath);
|
|
129
|
+
if (asset.isSource) {
|
|
130
|
+
var _cssModulesConfig$exc;
|
|
131
|
+
let projectRootPath = _path().default.relative(options.projectRoot, asset.filePath);
|
|
132
|
+
if (typeof cssModulesConfig === 'boolean') {
|
|
133
|
+
isCSSModule = true;
|
|
134
|
+
} else if (cssModulesConfig !== null && cssModulesConfig !== void 0 && cssModulesConfig.include) {
|
|
135
|
+
isCSSModule = cssModulesConfig.include.some(include => include.test(projectRootPath));
|
|
136
|
+
} else if (cssModulesConfig !== null && cssModulesConfig !== void 0 && cssModulesConfig.global) {
|
|
137
|
+
isCSSModule = true;
|
|
138
|
+
}
|
|
139
|
+
if (cssModulesConfig !== null && cssModulesConfig !== void 0 && (_cssModulesConfig$exc = cssModulesConfig.exclude) !== null && _cssModulesConfig$exc !== void 0 && _cssModulesConfig$exc.some(exclude => exclude.test(projectRootPath))) {
|
|
140
|
+
isCSSModule = false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (isCSSModule) {
|
|
144
|
+
if (cssModulesConfig !== null && cssModulesConfig !== void 0 && cssModulesConfig.dashedIdents && !asset.isSource) {
|
|
145
|
+
cssModulesConfig.dashedIdents = false;
|
|
146
|
+
}
|
|
147
|
+
cssModules = cssModulesConfig !== null && cssModulesConfig !== void 0 ? cssModulesConfig : true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
res = transform({
|
|
151
|
+
filename: (0, _utils().normalizeSeparators)(_path().default.relative(options.projectRoot, asset.filePath)),
|
|
152
|
+
code,
|
|
153
|
+
cssModules,
|
|
154
|
+
analyzeDependencies: asset.meta.hasDependencies !== false ? {
|
|
155
|
+
preserveImports: true
|
|
156
|
+
} : false,
|
|
157
|
+
sourceMap: !!asset.env.sourceMap,
|
|
158
|
+
drafts: config === null || config === void 0 ? void 0 : config.drafts,
|
|
159
|
+
pseudoClasses: config === null || config === void 0 ? void 0 : config.pseudoClasses,
|
|
160
|
+
errorRecovery: (config === null || config === void 0 ? void 0 : config.errorRecovery) || false,
|
|
161
|
+
targets
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
} catch (err) {
|
|
165
|
+
var _err$data;
|
|
166
|
+
err.filePath = asset.filePath;
|
|
167
|
+
let diagnostic = (0, _diagnostic().errorToDiagnostic)(err, {
|
|
168
|
+
origin: '@parcel/transformer-css'
|
|
169
|
+
});
|
|
170
|
+
if (((_err$data = err.data) === null || _err$data === void 0 ? void 0 : _err$data.type) === 'AmbiguousUrlInCustomProperty' && err.data.url) {
|
|
171
|
+
let p = '/' + (0, _utils().relativePath)(options.projectRoot, _path().default.resolve(_path().default.dirname(asset.filePath), err.data.url), false);
|
|
172
|
+
diagnostic[0].hints = [`Replace with: url(${p})`];
|
|
173
|
+
diagnostic[0].documentationURL = 'https://parceljs.org/languages/css/#url()';
|
|
174
|
+
}
|
|
175
|
+
throw new (_diagnostic().default)({
|
|
176
|
+
diagnostic
|
|
177
|
+
});
|
|
79
178
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
179
|
+
if (res.warnings) {
|
|
180
|
+
for (let warning of res.warnings) {
|
|
181
|
+
logger.warn({
|
|
182
|
+
message: warning.message,
|
|
183
|
+
codeFrames: [{
|
|
184
|
+
filePath: asset.filePath,
|
|
185
|
+
codeHighlights: [{
|
|
186
|
+
start: {
|
|
187
|
+
line: warning.loc.line,
|
|
188
|
+
column: warning.loc.column + 1
|
|
189
|
+
},
|
|
190
|
+
end: {
|
|
191
|
+
line: warning.loc.line,
|
|
192
|
+
column: warning.loc.column + 1
|
|
193
|
+
}
|
|
194
|
+
}]
|
|
195
|
+
}]
|
|
196
|
+
});
|
|
197
|
+
}
|
|
87
198
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
let
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (name.type === 'function' && name.value === 'url' && name.nodes.length) {
|
|
95
|
-
name = name.nodes[0];
|
|
199
|
+
if (res.map != null) {
|
|
200
|
+
let vlqMap = JSON.parse(Buffer.from(res.map).toString());
|
|
201
|
+
let map = new (_sourceMap().default)(options.projectRoot);
|
|
202
|
+
map.addVLQMap(vlqMap);
|
|
203
|
+
if (originalMap) {
|
|
204
|
+
map.extends(originalMap);
|
|
96
205
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
206
|
+
asset.setMap(map);
|
|
207
|
+
}
|
|
208
|
+
if (res.dependencies) {
|
|
209
|
+
for (let dep of res.dependencies) {
|
|
210
|
+
let loc = convertLoc(dep.loc);
|
|
211
|
+
if (originalMap) {
|
|
212
|
+
loc = (0, _utils().remapSourceLocation)(loc, originalMap);
|
|
213
|
+
}
|
|
214
|
+
if (dep.type === 'import' && !res.exports) {
|
|
215
|
+
asset.addDependency({
|
|
216
|
+
specifier: dep.url,
|
|
217
|
+
specifierType: 'url',
|
|
218
|
+
loc,
|
|
219
|
+
packageConditions: ['style'],
|
|
220
|
+
meta: {
|
|
221
|
+
// For the glob resolver to distinguish between `@import` and other URL dependencies.
|
|
222
|
+
isCSSImport: true,
|
|
223
|
+
media: dep.media,
|
|
224
|
+
placeholder: dep.placeholder
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
} else if (dep.type === 'url') {
|
|
228
|
+
asset.addURLDependency(dep.url, {
|
|
229
|
+
loc,
|
|
230
|
+
meta: {
|
|
231
|
+
placeholder: dep.placeholder
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
102
235
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
moduleSpecifier,
|
|
120
|
-
// Offset by 8 as it does not include `@import `
|
|
121
|
-
loc: (0, _utils.createDependencyLocation)(rule.source.start, moduleSpecifier, 0, 8),
|
|
122
|
-
meta: {
|
|
123
|
-
media
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
asset.addDependency(dep);
|
|
127
|
-
rule.remove(); // }
|
|
236
|
+
}
|
|
237
|
+
let assets = [asset];
|
|
238
|
+
let buffer = Buffer.from(res.code);
|
|
239
|
+
if (res.exports != null) {
|
|
240
|
+
var _asset$uniqueKey;
|
|
241
|
+
let exports = res.exports;
|
|
242
|
+
asset.symbols.ensure();
|
|
243
|
+
asset.symbols.set('default', 'default');
|
|
244
|
+
let dependencies = new Map();
|
|
245
|
+
let locals = new Map();
|
|
246
|
+
let c = 0;
|
|
247
|
+
let depjs = '';
|
|
248
|
+
let js = '';
|
|
249
|
+
let cssImports = '';
|
|
250
|
+
for (let key in exports) {
|
|
251
|
+
locals.set(exports[key].name, key);
|
|
128
252
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
253
|
+
(_asset$uniqueKey = asset.uniqueKey) !== null && _asset$uniqueKey !== void 0 ? _asset$uniqueKey : asset.uniqueKey = asset.id;
|
|
254
|
+
let seen = new Set();
|
|
255
|
+
let add = key => {
|
|
256
|
+
if (seen.has(key)) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
seen.add(key);
|
|
260
|
+
let e = exports[key];
|
|
261
|
+
let s = `module.exports[${JSON.stringify(key)}] = \`${e.name}`;
|
|
262
|
+
for (let ref of e.composes) {
|
|
263
|
+
s += ' ';
|
|
264
|
+
if (ref.type === 'local') {
|
|
265
|
+
let exported = (0, _nullthrows().default)(locals.get(ref.name));
|
|
266
|
+
add(exported);
|
|
267
|
+
s += '${' + `module.exports[${JSON.stringify(exported)}]` + '}';
|
|
268
|
+
asset.addDependency({
|
|
269
|
+
specifier: (0, _nullthrows().default)(asset.uniqueKey),
|
|
270
|
+
specifierType: 'esm',
|
|
271
|
+
symbols: new Map([[exported, {
|
|
272
|
+
local: ref.name,
|
|
273
|
+
isWeak: false,
|
|
274
|
+
loc: null
|
|
275
|
+
}]])
|
|
276
|
+
});
|
|
277
|
+
} else if (ref.type === 'global') {
|
|
278
|
+
s += ref.name;
|
|
279
|
+
} else if (ref.type === 'dependency') {
|
|
280
|
+
let d = dependencies.get(ref.specifier);
|
|
281
|
+
if (d == null) {
|
|
282
|
+
d = `dep_${c++}`;
|
|
283
|
+
depjs += `import * as ${d} from ${JSON.stringify(ref.specifier)};\n`;
|
|
284
|
+
dependencies.set(ref.specifier, d);
|
|
285
|
+
cssImports += `@import "${ref.specifier}";\n`;
|
|
286
|
+
asset.addDependency({
|
|
287
|
+
specifier: ref.specifier,
|
|
288
|
+
specifierType: 'esm',
|
|
289
|
+
packageConditions: ['style']
|
|
141
290
|
});
|
|
142
|
-
isDirty = true;
|
|
143
291
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (isDirty) {
|
|
147
|
-
decl.value = parsed.toString();
|
|
148
|
-
ast.isDirty = true;
|
|
292
|
+
s += '${' + `${d}[${JSON.stringify(ref.name)}]` + '}';
|
|
293
|
+
}
|
|
149
294
|
}
|
|
150
|
-
|
|
151
|
-
});
|
|
152
|
-
return [asset];
|
|
153
|
-
},
|
|
295
|
+
s += '`;\n';
|
|
154
296
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
297
|
+
// If the export is referenced internally (e.g. used @keyframes), add a self-reference
|
|
298
|
+
// to the JS so the symbol is retained during tree-shaking.
|
|
299
|
+
if (e.isReferenced) {
|
|
300
|
+
s += `module.exports[${JSON.stringify(key)}];\n`;
|
|
301
|
+
asset.addDependency({
|
|
302
|
+
specifier: (0, _nullthrows().default)(asset.uniqueKey),
|
|
303
|
+
specifierType: 'esm',
|
|
304
|
+
symbols: new Map([[key, {
|
|
305
|
+
local: exports[key].name,
|
|
306
|
+
isWeak: false,
|
|
307
|
+
loc: null
|
|
308
|
+
}]])
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
js += s;
|
|
312
|
+
};
|
|
164
313
|
|
|
165
|
-
|
|
166
|
-
|
|
314
|
+
// It's possible that the exports can be ordered differently between builds.
|
|
315
|
+
// Sorting by key is safe as the order is irrelevant but needs to be deterministic.
|
|
316
|
+
for (let key of Object.keys(exports).sort()) {
|
|
317
|
+
asset.symbols.set(key, exports[key].name);
|
|
318
|
+
add(key);
|
|
319
|
+
}
|
|
320
|
+
if (res.dependencies) {
|
|
321
|
+
for (let dep of res.dependencies) {
|
|
322
|
+
if (dep.type === 'import') {
|
|
323
|
+
// TODO: Figure out how to treeshake this
|
|
324
|
+
let d = `dep_$${c++}`;
|
|
325
|
+
depjs += `import * as ${d} from ${JSON.stringify(dep.url)};\n`;
|
|
326
|
+
js += `for (let key in ${d}) { if (key in module.exports) module.exports[key] += ' ' + ${d}[key]; else module.exports[key] = ${d}[key]; }\n`;
|
|
327
|
+
asset.symbols.set('*', '*');
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (res.references != null) {
|
|
332
|
+
let references = res.references;
|
|
333
|
+
for (let symbol in references) {
|
|
334
|
+
let reference = references[symbol];
|
|
335
|
+
asset.addDependency({
|
|
336
|
+
specifier: reference.specifier,
|
|
337
|
+
specifierType: 'esm',
|
|
338
|
+
packageConditions: ['style'],
|
|
339
|
+
symbols: new Map([[reference.name, {
|
|
340
|
+
local: symbol,
|
|
341
|
+
isWeak: false,
|
|
342
|
+
loc: null
|
|
343
|
+
}]])
|
|
344
|
+
});
|
|
345
|
+
asset.meta.hasReferences = true;
|
|
346
|
+
cssImports += `@import "${reference.specifier}";\n`;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
assets.push({
|
|
350
|
+
type: 'js',
|
|
351
|
+
content: depjs + js,
|
|
352
|
+
dependencies: [],
|
|
353
|
+
env
|
|
167
354
|
});
|
|
168
|
-
}
|
|
169
355
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
356
|
+
// Prepend @import rules for each composes dependency so packager knows where to insert them.
|
|
357
|
+
if (cssImports.length > 0) {
|
|
358
|
+
buffer = Buffer.concat([Buffer.from(cssImports), buffer]);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
asset.setBuffer(buffer);
|
|
362
|
+
return assets;
|
|
173
363
|
}
|
|
174
|
-
|
|
175
364
|
});
|
|
176
|
-
|
|
177
|
-
|
|
365
|
+
let cache = new Map();
|
|
366
|
+
function getTargets(browsers) {
|
|
367
|
+
if (browsers == null) {
|
|
368
|
+
return undefined;
|
|
369
|
+
}
|
|
370
|
+
let cached = cache.get(browsers);
|
|
371
|
+
if (cached != null) {
|
|
372
|
+
return cached;
|
|
373
|
+
}
|
|
374
|
+
let targets = browserslistToTargets((0, _browserslist().default)(browsers));
|
|
375
|
+
cache.set(browsers, targets);
|
|
376
|
+
return targets;
|
|
377
|
+
}
|
|
378
|
+
function convertLoc(loc) {
|
|
379
|
+
return {
|
|
380
|
+
filePath: loc.filePath,
|
|
381
|
+
start: {
|
|
382
|
+
line: loc.start.line,
|
|
383
|
+
column: loc.start.column
|
|
384
|
+
},
|
|
385
|
+
end: {
|
|
386
|
+
line: loc.end.line,
|
|
387
|
+
column: loc.end.column + 1
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/transformer-css",
|
|
3
|
-
"version": "2.0.0-nightly.
|
|
3
|
+
"version": "2.0.0-nightly.1490+642d9cabc",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
+
"funding": {
|
|
9
|
+
"type": "opencollective",
|
|
10
|
+
"url": "https://opencollective.com/parcel"
|
|
11
|
+
},
|
|
8
12
|
"repository": {
|
|
9
13
|
"type": "git",
|
|
10
14
|
"url": "https://github.com/parcel-bundler/parcel.git"
|
|
@@ -12,15 +16,23 @@
|
|
|
12
16
|
"main": "lib/CSSTransformer.js",
|
|
13
17
|
"source": "src/CSSTransformer.js",
|
|
14
18
|
"engines": {
|
|
15
|
-
"node": ">=
|
|
16
|
-
"parcel": "
|
|
19
|
+
"node": ">= 12.0.0",
|
|
20
|
+
"parcel": "2.0.0-nightly.1488+642d9cabc"
|
|
17
21
|
},
|
|
18
22
|
"dependencies": {
|
|
19
|
-
"@parcel/
|
|
20
|
-
"@parcel/
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
23
|
+
"@parcel/diagnostic": "2.0.0-nightly.1490+642d9cabc",
|
|
24
|
+
"@parcel/plugin": "2.0.0-nightly.1490+642d9cabc",
|
|
25
|
+
"@parcel/source-map": "^2.1.1",
|
|
26
|
+
"@parcel/utils": "2.0.0-nightly.1490+642d9cabc",
|
|
27
|
+
"browserslist": "^4.6.6",
|
|
28
|
+
"lightningcss": "^1.22.1",
|
|
29
|
+
"nullthrows": "^1.1.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"lightningcss-wasm": "^1.22.1"
|
|
33
|
+
},
|
|
34
|
+
"browser": {
|
|
35
|
+
"lightningcss": "lightningcss-wasm"
|
|
24
36
|
},
|
|
25
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "642d9cabc600bcb4681bbee0be168e05f5a8ffe5"
|
|
26
38
|
}
|
package/src/CSSTransformer.js
CHANGED
|
@@ -1,178 +1,390 @@
|
|
|
1
|
-
// @flow
|
|
1
|
+
// @flow strict-local
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {SourceLocation} from '@parcel/types';
|
|
4
4
|
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import SourceMap from '@parcel/source-map';
|
|
5
7
|
import {Transformer} from '@parcel/plugin';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
import {
|
|
9
|
+
remapSourceLocation,
|
|
10
|
+
relativePath,
|
|
11
|
+
globToRegex,
|
|
12
|
+
normalizeSeparators,
|
|
13
|
+
} from '@parcel/utils';
|
|
14
|
+
import {type SourceLocation as LightningSourceLocation} from 'lightningcss';
|
|
15
|
+
import * as native from 'lightningcss';
|
|
16
|
+
import browserslist from 'browserslist';
|
|
17
|
+
import nullthrows from 'nullthrows';
|
|
18
|
+
import ThrowableDiagnostic, {errorToDiagnostic} from '@parcel/diagnostic';
|
|
10
19
|
|
|
11
|
-
const
|
|
12
|
-
const IMPORT_RE = /@import/;
|
|
20
|
+
const {transform, transformStyleAttribute, browserslistToTargets} = native;
|
|
13
21
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// required because when stylus processes e.g. url() it replaces them with a dependency id
|
|
27
|
-
// to be filled in later. When the CSS transformer runs, it would pick that up and try to
|
|
28
|
-
// resolve a dependency for the id which obviously doesn't exist. Also, it's faster to do
|
|
29
|
-
// it this way since the resulting CSS doesn't need to be re-parsed.
|
|
30
|
-
if (asset.meta.hasDependencies === false) {
|
|
31
|
-
return null;
|
|
22
|
+
export default (new Transformer({
|
|
23
|
+
async loadConfig({config, options}) {
|
|
24
|
+
let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
25
|
+
packageKey: '@parcel/transformer-css',
|
|
26
|
+
});
|
|
27
|
+
let contents = conf?.contents;
|
|
28
|
+
if (typeof contents?.cssModules?.include === 'string') {
|
|
29
|
+
contents.cssModules.include = [globToRegex(contents.cssModules.include)];
|
|
30
|
+
} else if (Array.isArray(contents?.cssModules?.include)) {
|
|
31
|
+
contents.cssModules.include = contents.cssModules.include.map(include =>
|
|
32
|
+
typeof include === 'string' ? globToRegex(include) : include,
|
|
33
|
+
);
|
|
32
34
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
|
|
35
|
+
if (typeof contents?.cssModules?.exclude === 'string') {
|
|
36
|
+
contents.cssModules.exclude = [globToRegex(contents.cssModules.exclude)];
|
|
37
|
+
} else if (Array.isArray(contents?.cssModules?.exclude)) {
|
|
38
|
+
contents.cssModules.exclude = contents.cssModules.exclude.map(exclude =>
|
|
39
|
+
typeof exclude === 'string' ? globToRegex(exclude) : exclude,
|
|
40
|
+
);
|
|
37
41
|
}
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
type: 'postcss',
|
|
41
|
-
version: '7.0.0',
|
|
42
|
-
isDirty: false,
|
|
43
|
-
program: postcss.parse(code, {
|
|
44
|
-
from: asset.filePath,
|
|
45
|
-
}),
|
|
46
|
-
};
|
|
42
|
+
return contents;
|
|
47
43
|
},
|
|
48
|
-
|
|
49
|
-
transform({asset}) {
|
|
44
|
+
async transform({asset, config, options, logger}) {
|
|
50
45
|
// Normalize the asset's environment so that properties that only affect JS don't cause CSS to be duplicated.
|
|
51
46
|
// For example, with ESModule and CommonJS targets, only a single shared CSS bundle should be produced.
|
|
47
|
+
let env = asset.env;
|
|
52
48
|
asset.setEnvironment({
|
|
53
49
|
context: 'browser',
|
|
54
50
|
engines: {
|
|
55
51
|
browsers: asset.env.engines.browsers,
|
|
56
52
|
},
|
|
57
|
-
|
|
53
|
+
shouldOptimize: asset.env.shouldOptimize,
|
|
54
|
+
shouldScopeHoist: asset.env.shouldScopeHoist,
|
|
55
|
+
sourceMap: asset.env.sourceMap,
|
|
58
56
|
});
|
|
59
57
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
let [code, originalMap] = await Promise.all([
|
|
59
|
+
asset.getBuffer(),
|
|
60
|
+
asset.getMap(),
|
|
61
|
+
// $FlowFixMe native.default is the init function only when bundled for the browser build
|
|
62
|
+
process.browser && native.default(),
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
let targets = getTargets(asset.env.engines.browsers);
|
|
66
|
+
let res;
|
|
67
|
+
try {
|
|
68
|
+
if (asset.meta.type === 'attr') {
|
|
69
|
+
res = transformStyleAttribute({
|
|
70
|
+
code,
|
|
71
|
+
analyzeDependencies: true,
|
|
72
|
+
errorRecovery: config?.errorRecovery || false,
|
|
73
|
+
targets,
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
let cssModules = false;
|
|
77
|
+
if (
|
|
78
|
+
asset.meta.type !== 'tag' &&
|
|
79
|
+
asset.meta.cssModulesCompiled == null
|
|
80
|
+
) {
|
|
81
|
+
let cssModulesConfig = config?.cssModules;
|
|
82
|
+
let isCSSModule = /\.module\./.test(asset.filePath);
|
|
83
|
+
if (asset.isSource) {
|
|
84
|
+
let projectRootPath = path.relative(
|
|
85
|
+
options.projectRoot,
|
|
86
|
+
asset.filePath,
|
|
87
|
+
);
|
|
88
|
+
if (typeof cssModulesConfig === 'boolean') {
|
|
89
|
+
isCSSModule = true;
|
|
90
|
+
} else if (cssModulesConfig?.include) {
|
|
91
|
+
isCSSModule = cssModulesConfig.include.some(include =>
|
|
92
|
+
include.test(projectRootPath),
|
|
93
|
+
);
|
|
94
|
+
} else if (cssModulesConfig?.global) {
|
|
95
|
+
isCSSModule = true;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (
|
|
99
|
+
cssModulesConfig?.exclude?.some(exclude =>
|
|
100
|
+
exclude.test(projectRootPath),
|
|
101
|
+
)
|
|
102
|
+
) {
|
|
103
|
+
isCSSModule = false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (isCSSModule) {
|
|
108
|
+
if (cssModulesConfig?.dashedIdents && !asset.isSource) {
|
|
109
|
+
cssModulesConfig.dashedIdents = false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
cssModules = cssModulesConfig ?? true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
res = transform({
|
|
117
|
+
filename: normalizeSeparators(
|
|
118
|
+
path.relative(options.projectRoot, asset.filePath),
|
|
119
|
+
),
|
|
120
|
+
code,
|
|
121
|
+
cssModules,
|
|
122
|
+
analyzeDependencies:
|
|
123
|
+
asset.meta.hasDependencies !== false
|
|
124
|
+
? {
|
|
125
|
+
preserveImports: true,
|
|
126
|
+
}
|
|
127
|
+
: false,
|
|
128
|
+
sourceMap: !!asset.env.sourceMap,
|
|
129
|
+
drafts: config?.drafts,
|
|
130
|
+
pseudoClasses: config?.pseudoClasses,
|
|
131
|
+
errorRecovery: config?.errorRecovery || false,
|
|
132
|
+
targets,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
} catch (err) {
|
|
136
|
+
err.filePath = asset.filePath;
|
|
137
|
+
let diagnostic = errorToDiagnostic(err, {
|
|
138
|
+
origin: '@parcel/transformer-css',
|
|
139
|
+
});
|
|
140
|
+
if (err.data?.type === 'AmbiguousUrlInCustomProperty' && err.data.url) {
|
|
141
|
+
let p =
|
|
142
|
+
'/' +
|
|
143
|
+
relativePath(
|
|
144
|
+
options.projectRoot,
|
|
145
|
+
path.resolve(path.dirname(asset.filePath), err.data.url),
|
|
146
|
+
false,
|
|
147
|
+
);
|
|
148
|
+
diagnostic[0].hints = [`Replace with: url(${p})`];
|
|
149
|
+
diagnostic[0].documentationURL =
|
|
150
|
+
'https://parceljs.org/languages/css/#url()';
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
throw new ThrowableDiagnostic({
|
|
154
|
+
diagnostic,
|
|
155
|
+
});
|
|
64
156
|
}
|
|
65
157
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
158
|
+
if (res.warnings) {
|
|
159
|
+
for (let warning of res.warnings) {
|
|
160
|
+
logger.warn({
|
|
161
|
+
message: warning.message,
|
|
162
|
+
codeFrames: [
|
|
163
|
+
{
|
|
164
|
+
filePath: asset.filePath,
|
|
165
|
+
codeHighlights: [
|
|
166
|
+
{
|
|
167
|
+
start: {
|
|
168
|
+
line: warning.loc.line,
|
|
169
|
+
column: warning.loc.column + 1,
|
|
170
|
+
},
|
|
171
|
+
end: {
|
|
172
|
+
line: warning.loc.line,
|
|
173
|
+
column: warning.loc.column + 1,
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
});
|
|
180
|
+
}
|
|
72
181
|
}
|
|
73
182
|
|
|
74
|
-
|
|
75
|
-
let
|
|
76
|
-
let
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
name.nodes.length
|
|
82
|
-
) {
|
|
83
|
-
name = name.nodes[0];
|
|
183
|
+
if (res.map != null) {
|
|
184
|
+
let vlqMap = JSON.parse(Buffer.from(res.map).toString());
|
|
185
|
+
let map = new SourceMap(options.projectRoot);
|
|
186
|
+
map.addVLQMap(vlqMap);
|
|
187
|
+
|
|
188
|
+
if (originalMap) {
|
|
189
|
+
map.extends(originalMap);
|
|
84
190
|
}
|
|
85
191
|
|
|
86
|
-
|
|
192
|
+
asset.setMap(map);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (res.dependencies) {
|
|
196
|
+
for (let dep of res.dependencies) {
|
|
197
|
+
let loc = convertLoc(dep.loc);
|
|
198
|
+
if (originalMap) {
|
|
199
|
+
loc = remapSourceLocation(loc, originalMap);
|
|
200
|
+
}
|
|
87
201
|
|
|
88
|
-
|
|
89
|
-
|
|
202
|
+
if (dep.type === 'import' && !res.exports) {
|
|
203
|
+
asset.addDependency({
|
|
204
|
+
specifier: dep.url,
|
|
205
|
+
specifierType: 'url',
|
|
206
|
+
loc,
|
|
207
|
+
packageConditions: ['style'],
|
|
208
|
+
meta: {
|
|
209
|
+
// For the glob resolver to distinguish between `@import` and other URL dependencies.
|
|
210
|
+
isCSSImport: true,
|
|
211
|
+
media: dep.media,
|
|
212
|
+
placeholder: dep.placeholder,
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
} else if (dep.type === 'url') {
|
|
216
|
+
asset.addURLDependency(dep.url, {
|
|
217
|
+
loc,
|
|
218
|
+
meta: {
|
|
219
|
+
placeholder: dep.placeholder,
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
}
|
|
90
223
|
}
|
|
224
|
+
}
|
|
91
225
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
let dep = {
|
|
112
|
-
moduleSpecifier,
|
|
113
|
-
// Offset by 8 as it does not include `@import `
|
|
114
|
-
loc: createDependencyLocation(
|
|
115
|
-
rule.source.start,
|
|
116
|
-
moduleSpecifier,
|
|
117
|
-
0,
|
|
118
|
-
8,
|
|
119
|
-
),
|
|
120
|
-
meta: {
|
|
121
|
-
media,
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
asset.addDependency(dep);
|
|
125
|
-
rule.remove();
|
|
126
|
-
// }
|
|
226
|
+
let assets = [asset];
|
|
227
|
+
let buffer = Buffer.from(res.code);
|
|
228
|
+
|
|
229
|
+
if (res.exports != null) {
|
|
230
|
+
let exports = res.exports;
|
|
231
|
+
asset.symbols.ensure();
|
|
232
|
+
asset.symbols.set('default', 'default');
|
|
233
|
+
|
|
234
|
+
let dependencies = new Map();
|
|
235
|
+
let locals = new Map();
|
|
236
|
+
let c = 0;
|
|
237
|
+
let depjs = '';
|
|
238
|
+
let js = '';
|
|
239
|
+
let cssImports = '';
|
|
240
|
+
|
|
241
|
+
let jsDeps = [];
|
|
242
|
+
|
|
243
|
+
for (let key in exports) {
|
|
244
|
+
locals.set(exports[key].name, key);
|
|
127
245
|
}
|
|
128
|
-
ast.isDirty = true;
|
|
129
|
-
});
|
|
130
246
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
247
|
+
asset.uniqueKey ??= asset.id;
|
|
248
|
+
|
|
249
|
+
let seen = new Set();
|
|
250
|
+
let add = key => {
|
|
251
|
+
if (seen.has(key)) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
seen.add(key);
|
|
255
|
+
|
|
256
|
+
let e = exports[key];
|
|
257
|
+
let s = `module.exports[${JSON.stringify(key)}] = \`${e.name}`;
|
|
258
|
+
|
|
259
|
+
for (let ref of e.composes) {
|
|
260
|
+
s += ' ';
|
|
261
|
+
if (ref.type === 'local') {
|
|
262
|
+
let exported = nullthrows(locals.get(ref.name));
|
|
263
|
+
add(exported);
|
|
264
|
+
s += '${' + `module.exports[${JSON.stringify(exported)}]` + '}';
|
|
265
|
+
asset.addDependency({
|
|
266
|
+
specifier: nullthrows(asset.uniqueKey),
|
|
267
|
+
specifierType: 'esm',
|
|
268
|
+
symbols: new Map([
|
|
269
|
+
[exported, {local: ref.name, isWeak: false, loc: null}],
|
|
270
|
+
]),
|
|
148
271
|
});
|
|
149
|
-
|
|
272
|
+
} else if (ref.type === 'global') {
|
|
273
|
+
s += ref.name;
|
|
274
|
+
} else if (ref.type === 'dependency') {
|
|
275
|
+
let d = dependencies.get(ref.specifier);
|
|
276
|
+
if (d == null) {
|
|
277
|
+
d = `dep_${c++}`;
|
|
278
|
+
depjs += `import * as ${d} from ${JSON.stringify(
|
|
279
|
+
ref.specifier,
|
|
280
|
+
)};\n`;
|
|
281
|
+
dependencies.set(ref.specifier, d);
|
|
282
|
+
cssImports += `@import "${ref.specifier}";\n`;
|
|
283
|
+
asset.addDependency({
|
|
284
|
+
specifier: ref.specifier,
|
|
285
|
+
specifierType: 'esm',
|
|
286
|
+
packageConditions: ['style'],
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
s += '${' + `${d}[${JSON.stringify(ref.name)}]` + '}';
|
|
150
290
|
}
|
|
151
|
-
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
s += '`;\n';
|
|
152
294
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
295
|
+
// If the export is referenced internally (e.g. used @keyframes), add a self-reference
|
|
296
|
+
// to the JS so the symbol is retained during tree-shaking.
|
|
297
|
+
if (e.isReferenced) {
|
|
298
|
+
s += `module.exports[${JSON.stringify(key)}];\n`;
|
|
299
|
+
asset.addDependency({
|
|
300
|
+
specifier: nullthrows(asset.uniqueKey),
|
|
301
|
+
specifierType: 'esm',
|
|
302
|
+
symbols: new Map([
|
|
303
|
+
[key, {local: exports[key].name, isWeak: false, loc: null}],
|
|
304
|
+
]),
|
|
305
|
+
});
|
|
156
306
|
}
|
|
307
|
+
|
|
308
|
+
js += s;
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
// It's possible that the exports can be ordered differently between builds.
|
|
312
|
+
// Sorting by key is safe as the order is irrelevant but needs to be deterministic.
|
|
313
|
+
for (let key of Object.keys(exports).sort()) {
|
|
314
|
+
asset.symbols.set(key, exports[key].name);
|
|
315
|
+
add(key);
|
|
157
316
|
}
|
|
158
|
-
});
|
|
159
317
|
|
|
160
|
-
|
|
161
|
-
|
|
318
|
+
if (res.dependencies) {
|
|
319
|
+
for (let dep of res.dependencies) {
|
|
320
|
+
if (dep.type === 'import') {
|
|
321
|
+
// TODO: Figure out how to treeshake this
|
|
322
|
+
let d = `dep_$${c++}`;
|
|
323
|
+
depjs += `import * as ${d} from ${JSON.stringify(dep.url)};\n`;
|
|
324
|
+
js += `for (let key in ${d}) { if (key in module.exports) module.exports[key] += ' ' + ${d}[key]; else module.exports[key] = ${d}[key]; }\n`;
|
|
325
|
+
asset.symbols.set('*', '*');
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
162
329
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
330
|
+
if (res.references != null) {
|
|
331
|
+
let references = res.references;
|
|
332
|
+
for (let symbol in references) {
|
|
333
|
+
let reference = references[symbol];
|
|
334
|
+
asset.addDependency({
|
|
335
|
+
specifier: reference.specifier,
|
|
336
|
+
specifierType: 'esm',
|
|
337
|
+
packageConditions: ['style'],
|
|
338
|
+
symbols: new Map([
|
|
339
|
+
[reference.name, {local: symbol, isWeak: false, loc: null}],
|
|
340
|
+
]),
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
asset.meta.hasReferences = true;
|
|
344
|
+
cssImports += `@import "${reference.specifier}";\n`;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
assets.push({
|
|
349
|
+
type: 'js',
|
|
350
|
+
content: depjs + js,
|
|
351
|
+
dependencies: jsDeps,
|
|
352
|
+
env,
|
|
171
353
|
});
|
|
354
|
+
|
|
355
|
+
// Prepend @import rules for each composes dependency so packager knows where to insert them.
|
|
356
|
+
if (cssImports.length > 0) {
|
|
357
|
+
buffer = Buffer.concat([Buffer.from(cssImports), buffer]);
|
|
358
|
+
}
|
|
172
359
|
}
|
|
173
360
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
};
|
|
361
|
+
asset.setBuffer(buffer);
|
|
362
|
+
return assets;
|
|
177
363
|
},
|
|
178
|
-
});
|
|
364
|
+
}): Transformer);
|
|
365
|
+
|
|
366
|
+
let cache = new Map();
|
|
367
|
+
|
|
368
|
+
function getTargets(browsers) {
|
|
369
|
+
if (browsers == null) {
|
|
370
|
+
return undefined;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
let cached = cache.get(browsers);
|
|
374
|
+
if (cached != null) {
|
|
375
|
+
return cached;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
let targets = browserslistToTargets(browserslist(browsers));
|
|
379
|
+
|
|
380
|
+
cache.set(browsers, targets);
|
|
381
|
+
return targets;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function convertLoc(loc: LightningSourceLocation): SourceLocation {
|
|
385
|
+
return {
|
|
386
|
+
filePath: loc.filePath,
|
|
387
|
+
start: {line: loc.start.line, column: loc.start.column},
|
|
388
|
+
end: {line: loc.end.line, column: loc.end.column + 1},
|
|
389
|
+
};
|
|
390
|
+
}
|