Skip to content

Commit 8a3e37b

Browse files
authored
Merge pull request #13 from mafr/bugfix/update-type-hints
Add missing type hints for bundle_css
2 parents 2037873 + 340203a commit 8a3e37b

2 files changed

Lines changed: 41 additions & 7 deletions

File tree

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,20 @@ output_css = lightningcss.process_stylesheet(
5252
)
5353
```
5454

55+
The `filename` keyword parameter is only used for displaying error messages from
56+
the parser. When using `browsers_list`, lightningcss will try to transpile the
57+
code to be compatible with the specified
58+
[browserslist target](https://browsersl.ist/).
59+
5560
This package also supports creating a CSS bundle where all `@import` rules are
5661
resolved into a single stylesheet:
5762

5863
```py
5964
bundled_css = lightningcss.bundle_css(
6065
"main.css",
61-
filename = "main.css",
6266
browsers_list = ["defaults"],
6367
minify = False,
6468
)
6569
```
6670

67-
All resources referenced via `@import` are resolved relative to the main file. The
68-
`filename` keyword parameter is only used for displaying error messages from the
69-
parser. When using `browsers_list`, lightningcss will try to transpile the code
70-
to be compatible with the specified [browserslist target](https://browsersl.ist/).
71+
All resources referenced via `@import` are resolved relative to the main file.

lightningcss.pyi

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def calc_parser_flags(
1212
deep_selector_combinator: bool = False
1313
) -> ParserFlags:
1414
"""
15-
Calculates the `parser_flags` argument of `process_stylesheet()`.
15+
Calculates the `parser_flags` argument of `process_stylesheet()` and `bundle_css()`.
1616
"""
1717

1818
def process_stylesheet(
@@ -42,7 +42,40 @@ def process_stylesheet(
4242
:param browsers_list: An optional list of browserslist targets to be used
4343
to determine automatic prefixing and transpilation. If it is not
4444
specified, no prefixing/transpilation will occur.
45-
:param minify: Is True, the final output will be minified. Otherwise, it
45+
:param minify: If True, the final output will be minified. Otherwise, it
4646
will be pretty-printed.
4747
:return: A string containing a processed CSS stylesheet.
4848
"""
49+
50+
def bundle_css(
51+
path: str,
52+
/,
53+
error_recovery: bool = False,
54+
parser_flags: ParserFlags = ParserFlags(0),
55+
unused_symbols: set[str] | None = None,
56+
browsers_list: list[str] | None = None,
57+
minify: bool = True
58+
) -> str:
59+
"""
60+
Processes the supplied CSS stylesheet file and returns the bundle as a string.
61+
62+
Resolves all `@import` rules to create a single CSS bundle. The resources
63+
referenced via `@import` are resolved relative to the main file.
64+
65+
:param path: A string containing the path of the stylesheet file to process.
66+
:param error_recovery: Whether or not to omit broken CSS rather than
67+
producing a parse error. Enable with caution!
68+
:param parser_flags: An optional flag created by `calc_parser_flags()`.
69+
See that function for more details.
70+
:param unused_symbols: An optional set of known unused symbols, like
71+
classnames, ids, or keyframe names, to be removed from the output.
72+
Note that symbols should be specified in bare form, i.e.
73+
`unused_symbols={'a', 'b'}`, not `unused_symbols={'.a', '#b'}`, and
74+
will remove both ids and classes if they share a name. Use with caution!
75+
:param browsers_list: An optional list of browserslist targets to be used
76+
to determine automatic prefixing and transpilation. If it is not
77+
specified, no prefixing/transpilation will occur.
78+
:param minify: If True, the final output will be minified. Otherwise, it
79+
will be pretty-printed.
80+
:return: A string containing the CSS bundle.
81+
"""

0 commit comments

Comments
 (0)