chore: build

This commit is contained in:
2026-05-01 22:28:13 +02:00
parent ece977f268
commit 99ce3e4bb3
532 changed files with 5244 additions and 13124 deletions
+11 -3
View File
@@ -1,15 +1,23 @@
// @ts-check
/** @typedef {import('./index').Visitor} Visitor */
/** @typedef {import('./index').VisitorFunction} VisitorFunction */
/**
* Composes multiple visitor objects into a single one.
* @param {Visitor[]} visitors
* @return {Visitor}
* @param {(Visitor | VisitorFunction)[]} visitors
* @return {Visitor | VisitorFunction}
*/
function composeVisitors(visitors) {
if (visitors.length === 1) {
return visitors[0];
}
if (visitors.some(v => typeof v === 'function')) {
return (opts) => {
let v = visitors.map(v => typeof v === 'function' ? v(opts) : v);
return composeVisitors(v);
};
}
/** @type Visitor */
let res = {};
@@ -366,7 +374,7 @@ function createArrayVisitor(visitors, apply) {
// For each value, call all visitors. If a visitor returns a new value,
// we start over, but skip the visitor that generated the value or saw
// it before (to avoid cycles). This way, visitors can be composed in any order.
for (let v = 0; v < visitors.length;) {
for (let v = 0; v < visitors.length && i < arr.length;) {
if (seen.get(v)) {
v++;
continue;
+21 -4
View File
@@ -63,7 +63,7 @@ export interface TransformOptions<C extends CustomAtRules> {
* For optimal performance, visitors should be as specific as possible about what types of values
* they care about so that JavaScript has to be called as little as possible.
*/
visitor?: Visitor<C>,
visitor?: Visitor<C> | VisitorFunction<C>,
/**
* Defines how to parse custom CSS at-rules. Each at-rule can have a prelude, defined using a CSS
* [syntax string](https://drafts.css-houdini.org/css-properties-values-api/#syntax-strings), and
@@ -213,6 +213,13 @@ export interface Visitor<C extends CustomAtRules> {
EnvironmentVariableExit?: EnvironmentVariableVisitor | EnvironmentVariableVisitors;
}
export type VisitorDependency = FileDependency | GlobDependency;
export interface VisitorOptions {
addDependency: (dep: VisitorDependency) => void
}
export type VisitorFunction<C extends CustomAtRules> = (options: VisitorOptions) => Visitor<C>;
export interface CustomAtRules {
[name: string]: CustomAtRuleDefinition
}
@@ -358,7 +365,7 @@ export interface DependencyCSSModuleReference {
specifier: string
}
export type Dependency = ImportDependency | UrlDependency;
export type Dependency = ImportDependency | UrlDependency | FileDependency | GlobDependency;
export interface ImportDependency {
type: 'import',
@@ -384,6 +391,16 @@ export interface UrlDependency {
placeholder: string
}
export interface FileDependency {
type: 'file',
filePath: string
}
export interface GlobDependency {
type: 'glob',
glob: string
}
export interface SourceLocation {
/** The file path in which the dependency exists. */
filePath: string,
@@ -438,7 +455,7 @@ export interface TransformAttributeOptions {
* For optimal performance, visitors should be as specific as possible about what types of values
* they care about so that JavaScript has to be called as little as possible.
*/
visitor?: Visitor<never>
visitor?: Visitor<never> | VisitorFunction<never>
}
export interface TransformAttributeResult {
@@ -474,4 +491,4 @@ export declare function bundleAsync<C extends CustomAtRules>(options: BundleAsyn
/**
* Composes multiple visitor objects into a single one.
*/
export declare function composeVisitors<C extends CustomAtRules>(visitors: Visitor<C>[]): Visitor<C>;
export declare function composeVisitors<C extends CustomAtRules>(visitors: (Visitor<C> | VisitorFunction<C>)[]): Visitor<C> | VisitorFunction<C>;
+39 -8
View File
@@ -13,16 +13,47 @@ if (process.platform === 'linux') {
parts.push('msvc');
}
if (process.env.CSS_TRANSFORMER_WASM) {
module.exports = require(`../pkg`);
} else {
try {
module.exports = require(`lightningcss-${parts.join('-')}`);
} catch (err) {
module.exports = require(`../lightningcss.${parts.join('-')}.node`);
}
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);
}
};
}
+24 -5
View File
@@ -141,7 +141,7 @@ export type TransformOptions<C: CustomAtRules> = {|
* For optimal performance, visitors should be as specific as possible about what types of values
* they care about so that JavaScript has to be called as little as possible.
*/
visitor?: Visitor<C>,
visitor?: Visitor<C> | VisitorFunction<C>,
/**
* Defines how to parse custom CSS at-rules. Each at-rule can have a prelude, defined using a CSS
@@ -431,6 +431,13 @@ export type Visitor<C: CustomAtRules> = {|
| EnvironmentVariableVisitor
| EnvironmentVariableVisitors,
|};
export type VisitorDependency = FileDependency | GlobDependency;
export type VisitorOptions = {|
addDependency: (dep: VisitorDependency) => void,
|};
export type VisitorFunction<C: CustomAtRules> = (
options: VisitorOptions
) => Visitor<C>;
export type CustomAtRules = {|
[name: string]: CustomAtRuleDefinition,
|};
@@ -641,7 +648,11 @@ export type DependencyCSSModuleReference = {|
*/
specifier: string,
|};
export type Dependency = ImportDependency | UrlDependency;
export type Dependency =
| ImportDependency
| UrlDependency
| FileDependency
| GlobDependency;
export type ImportDependency = {|
type: "import",
@@ -688,6 +699,14 @@ export type UrlDependency = {|
*/
placeholder: string,
|};
export type FileDependency = {|
type: "file",
filePath: string,
|};
export type GlobDependency = {|
type: "glob",
glob: string,
|};
export type SourceLocation = {|
/**
* The file path in which the dependency exists.
@@ -770,7 +789,7 @@ export type TransformAttributeOptions = {|
* For optimal performance, visitors should be as specific as possible about what types of values
* they care about so that JavaScript has to be called as little as possible.
*/
visitor?: Visitor<empty>,
visitor?: Visitor<empty> | VisitorFunction<empty>,
|};
export type TransformAttributeResult = {|
/**
@@ -820,5 +839,5 @@ declare export function bundleAsync<C: CustomAtRules>(
* Composes multiple visitor objects into a single one.
*/
declare export function composeVisitors<C: CustomAtRules>(
visitors: Visitor<C>[]
): Visitor<C>;
visitors: (Visitor<C> | VisitorFunction<C>)[]
): Visitor<C> | VisitorFunction<C>;