Skip to content

Commit ca3e406

Browse files
authored
Put all of serde behind feature flag (parcel-bundler#360)
1 parent 787f46f commit ca3e406

File tree

11 files changed

+67
-45
lines changed

11 files changed

+67
-45
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ path = "src/lib.rs"
2727
crate-type = ["rlib"]
2828

2929
[features]
30-
default = ["bundler", "grid"]
30+
default = ["bundler", "grid", "nodejs"]
3131
browserslist = ["browserslist-rs"]
3232
bundler = ["dashmap", "rayon"]
3333
cli = ["clap", "serde_json", "browserslist", "jemallocator"]
3434
grid = []
35-
serde = ["smallvec/serde", "cssparser/serde"]
35+
nodejs = ["dep:serde"]
36+
serde = ["dep:serde", "smallvec/serde", "cssparser/serde"]
3637

3738
[dependencies]
38-
serde = { version = "1.0.123", features = ["derive"] }
39+
serde = { version = "1.0.123", features = ["derive"], optional = true }
3940
cssparser = "0.29.1"
4041
parcel_selectors = { version = "0.24.9", path = "./selectors" }
4142
itertools = "0.10.1"

node/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ crate-type = ["cdylib"]
1212
serde = { version = "1.0.123", features = ["derive"] }
1313
serde_bytes = "0.11.5"
1414
cssparser = "0.29.1"
15-
lightningcss = { path = "../" }
15+
lightningcss = { path = "../", features = ["nodejs"] }
1616
parcel_sourcemap = { version = "2.1.1", features = ["json"] }
1717

1818
[target.'cfg(target_os = "macos")'.dependencies]

selectors/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2709,7 +2709,7 @@ pub mod tests {
27092709
use super::*;
27102710
use crate::builder::SelectorFlags;
27112711
use crate::parser;
2712-
use cssparser::{serialize_identifier, Parser as CssParser, ParserInput, ToCss, serialize_string};
2712+
use cssparser::{serialize_identifier, serialize_string, Parser as CssParser, ParserInput, ToCss};
27132713
use std::collections::HashMap;
27142714
use std::fmt;
27152715

src/bundler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ use cssparser::AtRuleParser;
5252
use dashmap::DashMap;
5353
use parcel_sourcemap::SourceMap;
5454
use rayon::prelude::*;
55-
use serde::Serialize;
5655
use std::{
5756
collections::HashSet,
5857
fs,
@@ -144,7 +143,8 @@ impl Drop for FileProvider {
144143
}
145144

146145
/// An error that could occur during bundling.
147-
#[derive(Debug, Serialize)]
146+
#[derive(Debug)]
147+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(serde::Serialize))]
148148
pub enum BundleErrorKind<'i, T: std::error::Error> {
149149
/// A parser error occurred.
150150
ParserError(ParserError<'i>),
@@ -155,7 +155,7 @@ pub enum BundleErrorKind<'i, T: std::error::Error> {
155155
/// Unsupported media query boolean logic was encountered.
156156
UnsupportedMediaBooleanLogic,
157157
/// A custom resolver error.
158-
ResolverError(#[serde(skip)] T),
158+
ResolverError(#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(skip))] T),
159159
}
160160

161161
impl<'i, T: std::error::Error> From<Error<ParserError<'i>>> for Error<BundleErrorKind<'i, T>> {

src/css_modules.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::selector::SelectorList;
1414
use data_encoding::{Encoding, Specification};
1515
use lazy_static::lazy_static;
1616
use pathdiff::diff_paths;
17+
#[cfg(any(feature = "serde", feature = "nodejs"))]
1718
use serde::Serialize;
1819
use smallvec::{smallvec, SmallVec};
1920
use std::borrow::Cow;
@@ -164,8 +165,9 @@ pub enum Segment<'i> {
164165
/// A referenced name within a CSS module, e.g. via the `composes` property.
165166
///
166167
/// See [CssModuleExport](CssModuleExport).
167-
#[derive(PartialEq, Debug, Clone, Serialize)]
168-
#[serde(tag = "type", rename_all = "lowercase")]
168+
#[derive(PartialEq, Debug, Clone)]
169+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(Serialize))]
170+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(tag = "type", rename_all = "lowercase"))]
169171
pub enum CssModuleReference {
170172
/// A local reference.
171173
Local {
@@ -187,8 +189,9 @@ pub enum CssModuleReference {
187189
}
188190

189191
/// An exported value from a CSS module.
190-
#[derive(PartialEq, Debug, Clone, Serialize)]
191-
#[serde(rename_all = "camelCase")]
192+
#[derive(PartialEq, Debug, Clone)]
193+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(Serialize))]
194+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(rename_all = "camelCase"))]
192195
pub struct CssModuleExport {
193196
/// The local (compiled) name for this export.
194197
pub name: String,

src/dependencies.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::traits::ToCss;
1515
use crate::values::url::Url;
1616
use crate::visitor::Visit;
1717
use cssparser::SourceLocation;
18+
#[cfg(any(feature = "serde", feature = "nodejs"))]
1819
use serde::Serialize;
1920

2021
/// Options for `analyze_dependencies` in `PrinterOptions`.
@@ -25,8 +26,9 @@ pub struct DependencyOptions {
2526
}
2627

2728
/// A dependency.
28-
#[derive(Serialize, Debug)]
29-
#[serde(tag = "type", rename_all = "lowercase")]
29+
#[derive(Debug)]
30+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(Serialize))]
31+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(tag = "type", rename_all = "lowercase"))]
3032
pub enum Dependency {
3133
/// An `@import` dependency.
3234
Import(ImportDependency),
@@ -35,7 +37,8 @@ pub enum Dependency {
3537
}
3638

3739
/// An `@import` dependency.
38-
#[derive(Serialize, Debug)]
40+
#[derive(Debug)]
41+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(Serialize))]
3942
pub struct ImportDependency {
4043
/// The url to import.
4144
pub url: String,
@@ -87,7 +90,8 @@ impl ImportDependency {
8790
}
8891

8992
/// A `url()` dependency.
90-
#[derive(Serialize, Debug)]
93+
#[derive(Debug)]
94+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(Serialize))]
9195
pub struct UrlDependency {
9296
/// The url of the dependency.
9397
pub url: String,
@@ -110,8 +114,9 @@ impl UrlDependency {
110114
}
111115

112116
/// Represents the range of source code where a dependency was found.
113-
#[derive(Serialize, Debug)]
114-
#[serde(rename_all = "camelCase")]
117+
#[derive(Debug)]
118+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(Serialize))]
119+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(rename_all = "camelCase"))]
115120
pub struct SourceRange {
116121
/// The filename in which the dependency was found.
117122
pub file_path: String,
@@ -122,8 +127,9 @@ pub struct SourceRange {
122127
}
123128

124129
/// A line and column position within a source file.
125-
#[derive(Serialize, Debug, Clone, Copy, PartialEq, Visit)]
126-
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
130+
#[derive(Debug, Clone, Copy, PartialEq, Visit)]
131+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(serde::Serialize))]
132+
#[cfg_attr(any(feature = "serde"), derive(serde::Deserialize))]
127133
pub struct Location {
128134
/// The line number, starting from 1.
129135
pub line: u32,

src/error.rs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ use crate::rules::Location;
55
use crate::values::string::CowArcStr;
66
use cssparser::{BasicParseErrorKind, ParseError, ParseErrorKind};
77
use parcel_selectors::parser::SelectorParseErrorKind;
8+
#[cfg(any(feature = "serde", feature = "nodejs"))]
89
use serde::Serialize;
910
use std::fmt;
1011

1112
/// An error with a source location.
12-
#[derive(Debug, PartialEq, Clone, Serialize)]
13-
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
13+
#[derive(Debug, PartialEq, Clone)]
14+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(serde::Serialize))]
15+
#[cfg_attr(any(feature = "serde"), derive(serde::Deserialize))]
1416
pub struct Error<T> {
1517
/// The type of error that occurred.
1618
pub kind: T,
@@ -31,8 +33,9 @@ impl<T: fmt::Display> fmt::Display for Error<T> {
3133
impl<T: fmt::Display + fmt::Debug> std::error::Error for Error<T> {}
3234

3335
/// A line and column location within a source file.
34-
#[derive(Debug, PartialEq, Clone, Serialize)]
35-
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
36+
#[derive(Debug, PartialEq, Clone)]
37+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(serde::Serialize))]
38+
#[cfg_attr(any(feature = "serde"), derive(serde::Deserialize))]
3639
pub struct ErrorLocation {
3740
/// The filename in which the error occurred.
3841
pub filename: String,
@@ -60,8 +63,9 @@ impl fmt::Display for ErrorLocation {
6063
}
6164

6265
/// A parser error.
63-
#[derive(Debug, PartialEq, Serialize, Clone)]
64-
#[serde(tag = "type", content = "value")]
66+
#[derive(Debug, PartialEq, Clone)]
67+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(Serialize))]
68+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(tag = "type", content = "value"))]
6569
pub enum ParserError<'i> {
6670
/// An at rule body was invalid.
6771
AtRuleBodyInvalid,
@@ -90,7 +94,7 @@ pub enum ParserError<'i> {
9094
/// A `@namespace` rule was encountered after any rules besides `@charset`, `@import`, or `@layer`.
9195
UnexpectedNamespaceRule,
9296
/// An unexpected token was encountered.
93-
UnexpectedToken(#[serde(skip)] Token<'i>),
97+
UnexpectedToken(#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(skip))] Token<'i>),
9498
/// Maximum nesting depth was reached.
9599
MaximumNestingDepth,
96100
}
@@ -164,45 +168,46 @@ impl<'i> ParserError<'i> {
164168
}
165169

166170
/// A selector parsing error.
167-
#[derive(Debug, PartialEq, Serialize, Clone)]
168-
#[serde(tag = "type", content = "value")]
171+
#[derive(Debug, PartialEq, Clone)]
172+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(Serialize))]
173+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(tag = "type", content = "value"))]
169174
pub enum SelectorError<'i> {
170175
/// An unexpected token was found in an attribute selector.
171-
BadValueInAttr(#[serde(skip)] Token<'i>),
176+
BadValueInAttr(#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(skip))] Token<'i>),
172177
/// An unexpected token was found in a class selector.
173-
ClassNeedsIdent(#[serde(skip)] Token<'i>),
178+
ClassNeedsIdent(#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(skip))] Token<'i>),
174179
/// A dangling combinator was found.
175180
DanglingCombinator,
176181
/// An empty selector.
177182
EmptySelector,
178183
/// A `|` was expected in an attribute selector.
179-
ExpectedBarInAttr(#[serde(skip)] Token<'i>),
184+
ExpectedBarInAttr(#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(skip))] Token<'i>),
180185
/// A namespace was expected.
181186
ExpectedNamespace(CowArcStr<'i>),
182187
/// An unexpected token was encountered in a namespace.
183-
ExplicitNamespaceUnexpectedToken(#[serde(skip)] Token<'i>),
188+
ExplicitNamespaceUnexpectedToken(#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(skip))] Token<'i>),
184189
/// An invalid pseudo class was encountered after a pseudo element.
185190
InvalidPseudoClassAfterPseudoElement,
186191
/// An invalid pseudo class was encountered after a `-webkit-scrollbar` pseudo element.
187192
InvalidPseudoClassAfterWebKitScrollbar,
188193
/// A `-webkit-scrollbar` state was encountered before a `-webkit-scrollbar` pseudo element.
189194
InvalidPseudoClassBeforeWebKitScrollbar,
190195
/// Invalid qualified name in attribute selector.
191-
InvalidQualNameInAttr(#[serde(skip)] Token<'i>),
196+
InvalidQualNameInAttr(#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(skip))] Token<'i>),
192197
/// The current token is not allowed in this state.
193198
InvalidState,
194199
/// The selector is required to have the `&` nesting selector at the start.
195200
MissingNestingPrefix,
196201
/// The selector is missing a `&` nesting selector.
197202
MissingNestingSelector,
198203
/// No qualified name in attribute selector.
199-
NoQualifiedNameInAttributeSelector(#[serde(skip)] Token<'i>),
204+
NoQualifiedNameInAttributeSelector(#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(skip))] Token<'i>),
200205
/// An Invalid token was encountered in a pseudo element.
201-
PseudoElementExpectedIdent(#[serde(skip)] Token<'i>),
206+
PseudoElementExpectedIdent(#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(skip))] Token<'i>),
202207
/// An unexpected identifier was encountered.
203208
UnexpectedIdent(CowArcStr<'i>),
204209
/// An unexpected token was encountered inside an attribute selector.
205-
UnexpectedTokenInAttributeSelector(#[serde(skip)] Token<'i>),
210+
UnexpectedTokenInAttributeSelector(#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(skip))] Token<'i>),
206211
/// An unsupported pseudo class or pseudo element was encountered.
207212
UnsupportedPseudoClassOrElement(CowArcStr<'i>),
208213
}
@@ -291,8 +296,9 @@ impl<T: fmt::Display + fmt::Debug> std::error::Error for ErrorWithLocation<T> {}
291296
pub(crate) type MinifyError = ErrorWithLocation<MinifyErrorKind>;
292297

293298
/// A transformation error.
294-
#[derive(Debug, PartialEq, Serialize)]
295-
#[serde(tag = "type")]
299+
#[derive(Debug, PartialEq)]
300+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(Serialize))]
301+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(tag = "type"))]
296302
pub enum MinifyErrorKind {
297303
/// A circular `@custom-media` rule was detected.
298304
CircularCustomMedia {
@@ -337,8 +343,9 @@ impl MinifyErrorKind {
337343
pub type PrinterError = Error<PrinterErrorKind>;
338344

339345
/// A printer error type.
340-
#[derive(Debug, PartialEq, Serialize)]
341-
#[serde(tag = "type")]
346+
#[derive(Debug, PartialEq)]
347+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(Serialize))]
348+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(tag = "type"))]
342349
pub enum PrinterErrorKind {
343350
/// An ambiguous relative `url()` was encountered in a custom property declaration.
344351
AmbiguousUrlInCustomProperty {

src/rules/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ use media::MediaRule;
8585
use namespace::NamespaceRule;
8686
use nesting::NestingRule;
8787
use page::PageRule;
88-
use serde::Serialize;
8988
use std::collections::{HashMap, HashSet};
9089
use style::StyleRule;
9190
use supports::SupportsRule;
@@ -108,7 +107,8 @@ pub(crate) struct StyleContext<'a, 'i, T> {
108107
}
109108

110109
/// A source location.
111-
#[derive(PartialEq, Eq, Debug, Clone, Copy, Serialize)]
110+
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
111+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(serde::Serialize))]
112112
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
113113
pub struct Location {
114114
/// The index of the source file within the source map.

src/targets.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Browser target options.
22
// This file is autogenerated by build-prefixes.js. DO NOT EDIT!
33

4-
use serde::{Deserialize, Serialize};
4+
#[cfg(any(feature = "serde", feature = "nodejs"))]
5+
use serde::{Serialize, Deserialize};
56

67
/// Browser versions to compile CSS for.
78
///
@@ -20,7 +21,8 @@ use serde::{Deserialize, Serialize};
2021
/// ..Browsers::default()
2122
/// };
2223
/// ```
23-
#[derive(Serialize, Debug, Deserialize, Clone, Copy, Default)]
24+
#[derive(Debug, Clone, Copy, Default)]
25+
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(Serialize, Deserialize))]
2426
#[allow(missing_docs)]
2527
pub struct Browsers {
2628
pub android: Option<u32>,

0 commit comments

Comments
 (0)