@dvaji/cheerox 0.1.1 → 0.1.2
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/Cargo.lock +1 -4
- package/Cargo.toml +3 -2
- package/THIRD_PARTY_NOTICES.md +5 -3
- package/cheerox.darwin-arm64.node +0 -0
- package/cheerox.darwin-x64.node +0 -0
- package/cheerox.linux-arm64-gnu.node +0 -0
- package/cheerox.linux-arm64-musl.node +0 -0
- package/cheerox.linux-x64-gnu.node +0 -0
- package/cheerox.linux-x64-musl.node +0 -0
- package/cheerox.win32-arm64-msvc.node +0 -0
- package/cheerox.win32-x64-msvc.node +0 -0
- package/dist/{cheerio-compat-BS--qPzw.mjs → cheerio-compat-BKkfJEAr.mjs} +2 -2
- package/dist/{cheerio-compat-BS--qPzw.mjs.map → cheerio-compat-BKkfJEAr.mjs.map} +1 -1
- package/dist/{cheerio-compat-DSwBAJ1s.cjs → cheerio-compat-DcnYK9OB.cjs} +2 -2
- package/dist/{cheerio-compat-DSwBAJ1s.cjs.map → cheerio-compat-DcnYK9OB.cjs.map} +1 -1
- package/dist/cheerio-compat.cjs +1 -1
- package/dist/cheerio-compat.mjs +1 -1
- package/native/src/lib.rs +2 -1
- package/native/vendor/README.md +12 -3
- package/native/vendor/scraper-0.24.0/Cargo.toml +52 -0
- package/native/vendor/scraper-0.24.0/LICENSE +15 -0
- package/native/vendor/scraper-0.24.0/src/element_ref/element.rs +212 -0
- package/native/vendor/scraper-0.24.0/src/element_ref/mod.rs +236 -0
- package/native/vendor/scraper-0.24.0/src/element_ref/serializable.rs +15 -0
- package/native/vendor/scraper-0.24.0/src/error/utils.rs +91 -0
- package/native/vendor/scraper-0.24.0/src/error.rs +118 -0
- package/native/vendor/scraper-0.24.0/src/html/mod.rs +270 -0
- package/native/vendor/scraper-0.24.0/src/html/serializable.rs +27 -0
- package/native/vendor/scraper-0.24.0/src/html/tree_sink.rs +285 -0
- package/native/vendor/scraper-0.24.0/src/lib.rs +180 -0
- package/native/vendor/scraper-0.24.0/src/node/serializable.rs +52 -0
- package/native/vendor/scraper-0.24.0/src/node.rs +465 -0
- package/native/vendor/scraper-0.24.0/src/selectable.rs +70 -0
- package/native/vendor/scraper-0.24.0/src/selector.rs +290 -0
- package/package.json +1 -1
- package/scripts/check-release.mjs +2 -2
- package/scripts/generate-notices.mjs +10 -4
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//! Provides the [`Selectable`] to abstract over collections of elements
|
|
2
|
+
|
|
3
|
+
use crate::{
|
|
4
|
+
element_ref::{self, ElementRef},
|
|
5
|
+
html::{self, Html},
|
|
6
|
+
selector::Selector,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/// Trait to abstract over collections of elements to which a [CSS selector][Selector] can be applied
|
|
10
|
+
///
|
|
11
|
+
/// The mainly enables writing helper functions which are generic over [`Html`] and [`ElementRef`], e.g.
|
|
12
|
+
///
|
|
13
|
+
/// ```
|
|
14
|
+
/// use scraper::{selectable::Selectable, selector::Selector};
|
|
15
|
+
///
|
|
16
|
+
/// fn text_of_first_match<'a, S>(selectable: S, selector: &Selector) -> Option<String>
|
|
17
|
+
/// where
|
|
18
|
+
/// S: Selectable<'a>,
|
|
19
|
+
/// {
|
|
20
|
+
/// selectable.select(selector).next().map(|element| element.text().collect())
|
|
21
|
+
/// }
|
|
22
|
+
/// ```
|
|
23
|
+
pub trait Selectable<'a> {
|
|
24
|
+
/// Iterator over [element references][ElementRef] matching a [CSS selector[Selector]
|
|
25
|
+
type Select<'b>: Iterator<Item = ElementRef<'a>>;
|
|
26
|
+
|
|
27
|
+
/// Applies the given `selector` to the collection of elements represented by `self`
|
|
28
|
+
fn select(self, selector: &Selector) -> Self::Select<'_>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
impl<'a> Selectable<'a> for &'a Html {
|
|
32
|
+
type Select<'b> = html::Select<'a, 'b>;
|
|
33
|
+
|
|
34
|
+
fn select(self, selector: &Selector) -> Self::Select<'_> {
|
|
35
|
+
Html::select(self, selector)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
impl<'a> Selectable<'a> for ElementRef<'a> {
|
|
40
|
+
type Select<'b> = element_ref::Select<'a, 'b>;
|
|
41
|
+
|
|
42
|
+
fn select(self, selector: &Selector) -> Self::Select<'_> {
|
|
43
|
+
ElementRef::select(&self, selector)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#[cfg(test)]
|
|
48
|
+
mod tests {
|
|
49
|
+
use super::*;
|
|
50
|
+
|
|
51
|
+
fn select_one<'a, S>(selectable: S, selector: &Selector) -> Option<ElementRef<'a>>
|
|
52
|
+
where
|
|
53
|
+
S: Selectable<'a>,
|
|
54
|
+
{
|
|
55
|
+
selectable.select(selector).next()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#[test]
|
|
59
|
+
fn html_and_element_ref_are_selectable() {
|
|
60
|
+
let fragment = Html::parse_fragment(
|
|
61
|
+
r#"<select class="foo"><option value="bar">foobar</option></select>"#,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
let selector = Selector::parse("select.foo").unwrap();
|
|
65
|
+
let element = select_one(&fragment, &selector).unwrap();
|
|
66
|
+
|
|
67
|
+
let selector = Selector::parse("select.foo option[value='bar']").unwrap();
|
|
68
|
+
let _element = select_one(element, &selector).unwrap();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
//! CSS selectors.
|
|
2
|
+
|
|
3
|
+
use std::convert::TryFrom;
|
|
4
|
+
use std::fmt;
|
|
5
|
+
|
|
6
|
+
pub use cssparser::ToCss;
|
|
7
|
+
use html5ever::{LocalName, Namespace};
|
|
8
|
+
use precomputed_hash::PrecomputedHash;
|
|
9
|
+
use selectors::{
|
|
10
|
+
matching,
|
|
11
|
+
parser::{self, ParseRelative, SelectorList, SelectorParseErrorKind},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
#[cfg(feature = "serde")]
|
|
15
|
+
use serde::{de::Visitor, Deserialize, Serialize};
|
|
16
|
+
|
|
17
|
+
use crate::error::SelectorErrorKind;
|
|
18
|
+
use crate::ElementRef;
|
|
19
|
+
|
|
20
|
+
/// Wrapper around CSS selectors.
|
|
21
|
+
///
|
|
22
|
+
/// Represents a "selector group", i.e. a comma-separated list of selectors.
|
|
23
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
24
|
+
pub struct Selector {
|
|
25
|
+
/// The CSS selectors.
|
|
26
|
+
selectors: SelectorList<Simple>,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
impl Selector {
|
|
30
|
+
/// Parses a CSS selector group.
|
|
31
|
+
pub fn parse(selectors: &str) -> Result<Self, SelectorErrorKind<'_>> {
|
|
32
|
+
let mut parser_input = cssparser::ParserInput::new(selectors);
|
|
33
|
+
let mut parser = cssparser::Parser::new(&mut parser_input);
|
|
34
|
+
|
|
35
|
+
SelectorList::parse(&Parser, &mut parser, ParseRelative::No)
|
|
36
|
+
.map(|selectors| Self { selectors })
|
|
37
|
+
.map_err(SelectorErrorKind::from)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// Returns true if the element matches this selector.
|
|
41
|
+
pub fn matches(&self, element: &ElementRef) -> bool {
|
|
42
|
+
self.matches_with_scope(element, None)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/// Returns true if the element matches this selector.
|
|
46
|
+
/// The optional `scope` argument is used to specify which element has `:scope` pseudo-class.
|
|
47
|
+
/// When it is `None`, `:scope` will match the root element.
|
|
48
|
+
pub fn matches_with_scope(&self, element: &ElementRef, scope: Option<ElementRef>) -> bool {
|
|
49
|
+
self.matches_with_scope_and_cache(element, scope, &mut Default::default())
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// The `nth_index_cache` must not be used after `self` is dropped
|
|
53
|
+
// to avoid incorrect results (even though no undefined behaviour is possible)
|
|
54
|
+
// due to the usage of selector memory addresses as cache keys.
|
|
55
|
+
pub(crate) fn matches_with_scope_and_cache(
|
|
56
|
+
&self,
|
|
57
|
+
element: &ElementRef,
|
|
58
|
+
scope: Option<ElementRef>,
|
|
59
|
+
caches: &mut matching::SelectorCaches,
|
|
60
|
+
) -> bool {
|
|
61
|
+
let mut context = matching::MatchingContext::new(
|
|
62
|
+
matching::MatchingMode::Normal,
|
|
63
|
+
None,
|
|
64
|
+
caches,
|
|
65
|
+
matching::QuirksMode::NoQuirks,
|
|
66
|
+
matching::NeedsSelectorFlags::No,
|
|
67
|
+
matching::MatchingForInvalidation::No,
|
|
68
|
+
);
|
|
69
|
+
context.scope_element = scope.map(|x| selectors::Element::opaque(&x));
|
|
70
|
+
self.selectors
|
|
71
|
+
.slice()
|
|
72
|
+
.iter()
|
|
73
|
+
.any(|s| matching::matches_selector(s, 0, None, element, &mut context))
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
impl ToCss for Selector {
|
|
78
|
+
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
|
79
|
+
where
|
|
80
|
+
W: fmt::Write,
|
|
81
|
+
{
|
|
82
|
+
self.selectors.to_css(dest)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
#[cfg(feature = "serde")]
|
|
87
|
+
impl Serialize for Selector {
|
|
88
|
+
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
|
89
|
+
serializer.serialize_str(&self.to_css_string())
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
#[cfg(feature = "serde")]
|
|
94
|
+
impl<'de> Deserialize<'de> for Selector {
|
|
95
|
+
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
|
96
|
+
deserializer.deserialize_str(SelectorVisitor)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
#[cfg(feature = "serde")]
|
|
101
|
+
struct SelectorVisitor;
|
|
102
|
+
|
|
103
|
+
#[cfg(feature = "serde")]
|
|
104
|
+
impl Visitor<'_> for SelectorVisitor {
|
|
105
|
+
type Value = Selector;
|
|
106
|
+
|
|
107
|
+
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
108
|
+
write!(formatter, "a css selector string")
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
fn visit_str<E: serde::de::Error>(self, v: &str) -> Result<Self::Value, E> {
|
|
112
|
+
Selector::parse(v).map_err(serde::de::Error::custom)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/// An implementation of `Parser` for `selectors`
|
|
117
|
+
#[derive(Clone, Copy, Debug)]
|
|
118
|
+
pub struct Parser;
|
|
119
|
+
impl<'i> parser::Parser<'i> for Parser {
|
|
120
|
+
type Impl = Simple;
|
|
121
|
+
type Error = SelectorParseErrorKind<'i>;
|
|
122
|
+
|
|
123
|
+
fn parse_is_and_where(&self) -> bool {
|
|
124
|
+
true
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
fn parse_has(&self) -> bool {
|
|
128
|
+
true
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/// A simple implementation of `SelectorImpl` with no pseudo-classes or pseudo-elements.
|
|
133
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
134
|
+
pub struct Simple;
|
|
135
|
+
|
|
136
|
+
impl parser::SelectorImpl for Simple {
|
|
137
|
+
type AttrValue = CssString;
|
|
138
|
+
type Identifier = CssLocalName;
|
|
139
|
+
type LocalName = CssLocalName;
|
|
140
|
+
type NamespacePrefix = CssLocalName;
|
|
141
|
+
type NamespaceUrl = Namespace;
|
|
142
|
+
type BorrowedNamespaceUrl = Namespace;
|
|
143
|
+
type BorrowedLocalName = CssLocalName;
|
|
144
|
+
|
|
145
|
+
type NonTSPseudoClass = NonTSPseudoClass;
|
|
146
|
+
type PseudoElement = PseudoElement;
|
|
147
|
+
|
|
148
|
+
// see: https://github.com/servo/servo/pull/19747#issuecomment-357106065
|
|
149
|
+
type ExtraMatchingData<'a> = ();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/// Wraps [`String`] so that it can be used with [`selectors`]
|
|
153
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
154
|
+
pub struct CssString(pub String);
|
|
155
|
+
|
|
156
|
+
impl<'a> From<&'a str> for CssString {
|
|
157
|
+
fn from(val: &'a str) -> Self {
|
|
158
|
+
Self(val.to_owned())
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
impl AsRef<str> for CssString {
|
|
163
|
+
fn as_ref(&self) -> &str {
|
|
164
|
+
&self.0
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
impl ToCss for CssString {
|
|
169
|
+
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
|
170
|
+
where
|
|
171
|
+
W: fmt::Write,
|
|
172
|
+
{
|
|
173
|
+
cssparser::serialize_string(&self.0, dest)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/// Wraps [`LocalName`] so that it can be used with [`selectors`]
|
|
178
|
+
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
|
179
|
+
pub struct CssLocalName(pub LocalName);
|
|
180
|
+
|
|
181
|
+
impl<'a> From<&'a str> for CssLocalName {
|
|
182
|
+
fn from(val: &'a str) -> Self {
|
|
183
|
+
Self(val.into())
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
impl ToCss for CssLocalName {
|
|
188
|
+
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
|
189
|
+
where
|
|
190
|
+
W: fmt::Write,
|
|
191
|
+
{
|
|
192
|
+
dest.write_str(&self.0)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
impl PrecomputedHash for CssLocalName {
|
|
197
|
+
fn precomputed_hash(&self) -> u32 {
|
|
198
|
+
self.0.precomputed_hash()
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/// Non Tree-Structural Pseudo-Class.
|
|
203
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
204
|
+
pub enum NonTSPseudoClass {}
|
|
205
|
+
|
|
206
|
+
impl parser::NonTSPseudoClass for NonTSPseudoClass {
|
|
207
|
+
type Impl = Simple;
|
|
208
|
+
|
|
209
|
+
fn is_active_or_hover(&self) -> bool {
|
|
210
|
+
false
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
fn is_user_action_state(&self) -> bool {
|
|
214
|
+
false
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
impl ToCss for NonTSPseudoClass {
|
|
219
|
+
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
|
220
|
+
where
|
|
221
|
+
W: fmt::Write,
|
|
222
|
+
{
|
|
223
|
+
dest.write_str("")
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/// CSS Pseudo-Element
|
|
228
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
229
|
+
pub enum PseudoElement {}
|
|
230
|
+
|
|
231
|
+
impl parser::PseudoElement for PseudoElement {
|
|
232
|
+
type Impl = Simple;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
impl ToCss for PseudoElement {
|
|
236
|
+
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
|
237
|
+
where
|
|
238
|
+
W: fmt::Write,
|
|
239
|
+
{
|
|
240
|
+
dest.write_str("")
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
impl<'i> TryFrom<&'i str> for Selector {
|
|
245
|
+
type Error = SelectorErrorKind<'i>;
|
|
246
|
+
|
|
247
|
+
fn try_from(s: &'i str) -> Result<Self, Self::Error> {
|
|
248
|
+
Selector::parse(s)
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
#[cfg(test)]
|
|
253
|
+
mod tests {
|
|
254
|
+
use super::*;
|
|
255
|
+
use std::convert::TryInto;
|
|
256
|
+
|
|
257
|
+
#[test]
|
|
258
|
+
fn selector_conversions() {
|
|
259
|
+
let s = "#testid.testclass";
|
|
260
|
+
let _sel: Selector = s.try_into().unwrap();
|
|
261
|
+
|
|
262
|
+
let s = s.to_owned();
|
|
263
|
+
let _sel: Selector = (*s).try_into().unwrap();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
#[test]
|
|
267
|
+
#[should_panic]
|
|
268
|
+
fn invalid_selector_conversions() {
|
|
269
|
+
let s = "<failing selector>";
|
|
270
|
+
let _sel: Selector = s.try_into().unwrap();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
#[test]
|
|
274
|
+
fn has_selector() {
|
|
275
|
+
let s = ":has(a)";
|
|
276
|
+
let _sel: Selector = s.try_into().unwrap();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
#[test]
|
|
280
|
+
fn is_selector() {
|
|
281
|
+
let s = ":is(a)";
|
|
282
|
+
let _sel: Selector = s.try_into().unwrap();
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
#[test]
|
|
286
|
+
fn where_selector() {
|
|
287
|
+
let s = ":where(a)";
|
|
288
|
+
let _sel: Selector = s.try_into().unwrap();
|
|
289
|
+
}
|
|
290
|
+
}
|
package/package.json
CHANGED
|
@@ -114,7 +114,7 @@ export function validateNativeBinary(name, data) {
|
|
|
114
114
|
function allowedFile(path) {
|
|
115
115
|
return requiredFiles.includes(path) || /^dist\/[\w./-]+\.(?:[cm]?js|map|[cm]?ts)$/.test(path)
|
|
116
116
|
|| /^(?:src\/[\w/-]+\.ts|native\/src\/[\w/-]+\.rs)$/.test(path)
|
|
117
|
-
|| /^native\/vendor\/(?:(?:html5ever|markup5ever)-0\.35\.0|html5gum-0\.8\.4)\/(?:[\w./-]+\.(?:rs|c|h|html|md|toml|orig|json)|Cargo\.lock|LICENSE(?:-(?:MIT|APACHE))?)$/.test(path)
|
|
117
|
+
|| /^native\/vendor\/(?:(?:html5ever|markup5ever)-0\.35\.0|html5gum-0\.8\.4|scraper-0\.24\.0)\/(?:[\w./-]+\.(?:rs|c|h|html|md|toml|orig|json)|Cargo\.lock|LICENSE(?:-(?:MIT|APACHE))?)$/.test(path)
|
|
118
118
|
|| /^scripts\/notices\/[\w-]+\.(?:txt|md|json)$/.test(path)
|
|
119
119
|
|| nativeTargets.some(target => path === `cheerox.${target}.node`);
|
|
120
120
|
}
|
|
@@ -125,7 +125,7 @@ export function validatePackageFiles(files, { allTargets = true } = {}) {
|
|
|
125
125
|
assert.ok(allowedFile(path), `Unexpected package file: ${path}`);
|
|
126
126
|
}
|
|
127
127
|
for (const path of requiredFiles) assert.ok(files.get(path)?.length > 0, `Package is missing ${path}`);
|
|
128
|
-
for (const path of ['native/vendor/html5gum-0.8.4/Cargo.toml', 'native/vendor/html5gum-0.8.4/src/lib.rs', 'native/vendor/html5gum-0.8.4/LICENSE']) assert.ok(files.get(path)?.length > 0, `Package is missing ${path}`);
|
|
128
|
+
for (const path of ['native/vendor/html5gum-0.8.4/Cargo.toml', 'native/vendor/html5gum-0.8.4/src/lib.rs', 'native/vendor/html5gum-0.8.4/LICENSE', 'native/vendor/scraper-0.24.0/Cargo.toml', 'native/vendor/scraper-0.24.0/src/lib.rs', 'native/vendor/scraper-0.24.0/src/node.rs', 'native/vendor/scraper-0.24.0/LICENSE']) assert.ok(files.get(path)?.length > 0, `Package is missing ${path}`);
|
|
129
129
|
assert.match(files.get('LICENSE').toString(), /MIT License/);
|
|
130
130
|
assert.match(files.get('THIRD_PARTY_NOTICES.md').toString(), /cheerio/i);
|
|
131
131
|
assert.match(files.get('README.md').toString(), /drop-in replacement/i);
|
|
@@ -18,7 +18,7 @@ const legalName = /^(?:licen[cs]e(?:[-_.].*)?|unlicense|copying(?:[-_.].*)?|copy
|
|
|
18
18
|
const metadata = JSON.parse(execFileSync(process.env.CARGO || 'cargo', [
|
|
19
19
|
'metadata', '--locked', '--format-version', '1',
|
|
20
20
|
], { cwd: root, encoding: 'utf8', maxBuffer: 32 * 1024 * 1024 }));
|
|
21
|
-
const vendored = new Set(['html5ever@0.35.0', 'markup5ever@0.35.0', 'html5gum@0.8.4']);
|
|
21
|
+
const vendored = new Set(['html5ever@0.35.0', 'markup5ever@0.35.0', 'html5gum@0.8.4', 'scraper@0.24.0']);
|
|
22
22
|
// The Rust crate keeps its internal name `cheerox`; the npm package is `@dvaji/cheerox`.
|
|
23
23
|
for (const pkg of metadata.packages) {
|
|
24
24
|
if (!pkg.source && pkg.name !== 'cheerox' && !vendored.has(`${pkg.name}@${pkg.version}`)) throw new Error(`Review notices for the new local dependency ${pkg.name}@${pkg.version}`);
|
|
@@ -118,7 +118,7 @@ const parts = [
|
|
|
118
118
|
'',
|
|
119
119
|
'This file preserves third-party license and attribution notices for the Rust native addon and the upstream Cheerio compatibility tests. cheerox itself is distributed under its MIT LICENSE. Third-party components retain their own licenses.',
|
|
120
120
|
'',
|
|
121
|
-
'Generated by `node scripts/generate-notices.mjs` from `cargo metadata --locked`, crate license files, and the pinned supplemental sources recorded in `scripts/notices/sources.json`. It includes build dependencies and dependencies for all target platforms; a particular binary may use a subset. Identical notice texts are reproduced once and referenced below. The html5ever, markup5ever and html5gum crates contain local observer-hook and opt-in UTF-16 transport patches; their complete patched source and original notices are included in `native/vendor`. Other dependency source files are unmodified.',
|
|
121
|
+
'Generated by `node scripts/generate-notices.mjs` from `cargo metadata --locked`, crate license files, and the pinned supplemental sources recorded in `scripts/notices/sources.json`. It includes build dependencies and dependencies for all target platforms; a particular binary may use a subset. Identical notice texts are reproduced once and referenced below. The html5ever, markup5ever and html5gum crates contain local observer-hook and opt-in UTF-16 transport patches, and the scraper crate carries a vector-backed attribute store; their complete patched source and original notices are included in `native/vendor`. Other dependency source files are unmodified.',
|
|
122
122
|
'',
|
|
123
123
|
`Cargo.lock SHA-256: \`${sha256(readFileSync(join(root, 'Cargo.lock')))}\`.`,
|
|
124
124
|
'',
|
|
@@ -126,7 +126,7 @@ const parts = [
|
|
|
126
126
|
'',
|
|
127
127
|
'The native addon includes code from packages licensed under MPL-2.0. The complete, unmodified Source Code Form of each dependency is available without charge from the version-specific source download links below. These downloads contain the corresponding upstream source and notices. MPL-covered source remains available under MPL-2.0, whose full text is included in this file. The MIT license for cheerox does not restrict rights granted by third-party source licenses.',
|
|
128
128
|
'',
|
|
129
|
-
'The locally patched html5ever and markup5ever components are licensed under MIT OR Apache-2.0; html5gum is licensed under MIT. Their upstream archives are linked below; the exact patched Source Code Form is shipped in the npm package under `native/vendor` and maintained in [this repository](https://github.com/dvaJi/cheerox/tree/main/native/vendor). See `native/vendor/README.md` for the patch scope. Their original license and copyright files remain intact.',
|
|
129
|
+
'The locally patched html5ever and markup5ever components are licensed under MIT OR Apache-2.0; html5gum is licensed under MIT; the locally patched scraper is licensed under ISC. Their upstream archives are linked below; the exact patched Source Code Form is shipped in the npm package under `native/vendor` and maintained in [this repository](https://github.com/dvaJi/cheerox/tree/main/native/vendor). See `native/vendor/README.md` for the patch scope. Their original license and copyright files remain intact.',
|
|
130
130
|
'',
|
|
131
131
|
'## Cheerio compatibility tests',
|
|
132
132
|
'',
|
|
@@ -180,7 +180,13 @@ for (const [digest, text] of [...texts].sort(([a], [b]) => compare(a, b))) {
|
|
|
180
180
|
}
|
|
181
181
|
const generated = parts.join('\n') + '\n';
|
|
182
182
|
if (check) {
|
|
183
|
-
if (!existsSync(output) || read(output) !== generated)
|
|
183
|
+
if (!existsSync(output) || read(output) !== generated) {
|
|
184
|
+
const existing = existsSync(output) ? read(output) : '';
|
|
185
|
+
let at = 0;
|
|
186
|
+
while (at < existing.length && at < generated.length && existing[at] === generated[at]) at++;
|
|
187
|
+
const context = (text) => text.slice(at, at + 160).replace(/\n/g, '\\n');
|
|
188
|
+
throw new Error(`THIRD_PARTY_NOTICES.md is stale at byte ${at}. Committed: "${context(existing)}" Generated: "${context(generated)}". Run npm run notices:generate and commit the updated file.`);
|
|
189
|
+
}
|
|
184
190
|
console.log(`Third-party notices match ${records.length} locked Rust packages and Cheerio 1.2.0.`);
|
|
185
191
|
} else {
|
|
186
192
|
writeFileSync(output, generated);
|