forked from parcel-bundler/lightningcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (55 loc) · 1.63 KB
/
index.js
File metadata and controls
59 lines (55 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
let parts = [process.platform, process.arch];
if (process.platform === 'linux') {
const { MUSL, familySync } = require('detect-libc');
const family = familySync();
if (family === MUSL) {
parts.push('musl');
} else if (process.arch === 'arm') {
parts.push('gnueabihf');
} else {
parts.push('gnu');
}
} else if (process.platform === 'win32') {
parts.push('msvc');
}
let native;
try {
native = require(`lightningcss-${parts.join('-')}`);
} catch (err) {
native = require(`../lightningcss.${parts.join('-')}.node`);
}
module.exports.transform = wrap(native.transform);
module.exports.transformStyleAttribute = wrap(native.transformStyleAttribute);
module.exports.bundle = wrap(native.bundle);
module.exports.bundleAsync = wrap(native.bundleAsync);
module.exports.browserslistToTargets = require('./browserslistToTargets');
module.exports.composeVisitors = require('./composeVisitors');
module.exports.Features = require('./flags').Features;
function wrap(call) {
return (options) => {
if (typeof options.visitor === 'function') {
let deps = [];
options.visitor = options.visitor({
addDependency(dep) {
deps.push(dep);
}
});
let result = call(options);
if (result instanceof Promise) {
result = result.then(res => {
if (deps.length) {
res.dependencies ??= [];
res.dependencies.push(...deps);
}
return res;
});
} else if (deps.length) {
result.dependencies ??= [];
result.dependencies.push(...deps);
}
return result;
} else {
return call(options);
}
};
}