Skip to content

Commit 217bcd7

Browse files
authored
Merge branch 'v2' into upgrade-napi-rs
2 parents 5f1f055 + d58c1ce commit 217bcd7

File tree

4 files changed

+88
-51
lines changed

4 files changed

+88
-51
lines changed

crates/parcel_config/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ indexmap = { version = "2.2.6", features = ["serde", "std"] }
1111
parcel_filesystem = { path = "../parcel_filesystem" }
1212
parcel_package_manager = { path = "../parcel_package_manager" }
1313
pathdiff = "0.2.1"
14-
serde = { version = "1.0.123", features = ["derive"] }
14+
serde = { version = "1.0.123", features = ["derive", "rc"] }
1515
serde_json5 = "0.1.0"
1616
thiserror = "1.0.59"
1717

crates/parcel_config/src/parcel_config.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ use std::path::PathBuf;
33
use std::rc::Rc;
44

55
use indexmap::IndexMap;
6+
use serde::Deserialize;
7+
use serde::Serialize;
68

79
use super::config_error::ConfigError;
810
use super::partial_parcel_config::PartialParcelConfig;
911
use super::pipeline::is_match;
1012
use super::pipeline::PipelineMap;
1113

12-
#[derive(Clone, Debug, PartialEq)]
14+
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
15+
#[serde(rename_all = "camelCase")]
1316
pub struct PluginNode {
1417
pub package_name: String,
1518
pub resolve_from: Rc<PathBuf>,
1619
}
1720

1821
/// Represents a fully merged and validated .parcel_rc config
19-
#[derive(Debug, PartialEq)]
22+
#[derive(Debug, Deserialize, PartialEq, Serialize)]
2023
pub struct ParcelConfig {
2124
pub(crate) bundler: PluginNode,
2225
pub(crate) compressors: PipelineMap,

crates/parcel_config/src/pipeline.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use std::path::Path;
22

33
use glob_match::glob_match;
44
use indexmap::IndexMap;
5+
use serde::Deserialize;
6+
use serde::Serialize;
57

68
use super::parcel_config::PluginNode;
79

@@ -25,15 +27,15 @@ use super::parcel_config::PluginNode;
2527
/// });
2628
/// ```
2729
///
28-
#[derive(Debug, Default, PartialEq)]
29-
pub struct PipelineMap {
30+
#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
31+
pub struct PipelineMap(
3032
/// Maps patterns to a series of plugins, called pipelines
31-
map: IndexMap<String, Vec<PluginNode>>,
32-
}
33+
IndexMap<String, Vec<PluginNode>>,
34+
);
3335

3436
impl PipelineMap {
3537
pub fn new(map: IndexMap<String, Vec<PluginNode>>) -> Self {
36-
Self { map }
38+
Self(map)
3739
}
3840

3941
/// Finds pipelines contained by a pattern that match the given file path and named pipeline
@@ -74,7 +76,7 @@ impl PipelineMap {
7476
// If a pipeline is requested, a the glob needs to match exactly
7577
if let Some(pipeline) = named_pipeline {
7678
let exact_match = self
77-
.map
79+
.0
7880
.iter()
7981
.find(|(pattern, _)| is_match(pattern, path, basename, pipeline.as_ref()));
8082

@@ -85,7 +87,7 @@ impl PipelineMap {
8587
}
8688
}
8789

88-
for (pattern, pipelines) in self.map.iter() {
90+
for (pattern, pipelines) in self.0.iter() {
8991
if is_match(&pattern, path, basename, "") {
9092
matches.extend(pipelines.iter().cloned());
9193
}
@@ -97,15 +99,12 @@ impl PipelineMap {
9799
pub fn contains_named_pipeline(&self, pipeline: impl AsRef<str>) -> bool {
98100
let named_pipeline = format!("{}:", pipeline.as_ref());
99101

100-
self
101-
.map
102-
.keys()
103-
.any(|glob| glob.starts_with(&named_pipeline))
102+
self.0.keys().any(|glob| glob.starts_with(&named_pipeline))
104103
}
105104

106105
pub fn named_pipelines(&self) -> Vec<&str> {
107106
self
108-
.map
107+
.0
109108
.keys()
110109
.filter_map(|glob| glob.split_once(':').map(|g| g.0))
111110
.collect()

packages/core/core/src/RequestTracker.js

+71-36
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ export const requestGraphEdgeTypes = {
6565
dirname: 7,
6666
};
6767

68+
class FSBailoutError extends Error {
69+
name: string = 'FSBailoutError';
70+
}
71+
6872
export type RequestGraphEdgeType = $Values<typeof requestGraphEdgeTypes>;
6973

7074
type RequestGraphOpts = {|
@@ -855,7 +859,7 @@ export class RequestGraph extends ContentGraph<
855859
predictedTime,
856860
},
857861
});
858-
throw new Error(
862+
throw new FSBailoutError(
859863
'Responding to file system events exceeded threshold, start with empty cache.',
860864
);
861865
}
@@ -1543,55 +1547,58 @@ async function loadRequestGraph(options): Async<RequestGraph> {
15431547

15441548
let cacheKey = getCacheKey(options);
15451549
let requestGraphKey = `requestGraph-${cacheKey}`;
1546-
1550+
let timeout;
1551+
const snapshotKey = `snapshot-${cacheKey}`;
1552+
const snapshotPath = path.join(options.cacheDir, snapshotKey + '.txt');
15471553
if (await options.cache.hasLargeBlob(requestGraphKey)) {
1548-
let {requestGraph} = await readAndDeserializeRequestGraph(
1549-
options.cache,
1550-
requestGraphKey,
1551-
cacheKey,
1552-
);
1554+
try {
1555+
let {requestGraph} = await readAndDeserializeRequestGraph(
1556+
options.cache,
1557+
requestGraphKey,
1558+
cacheKey,
1559+
);
15531560

1554-
let opts = getWatcherOptions(options);
1555-
let snapshotKey = `snapshot-${cacheKey}`;
1556-
let snapshotPath = path.join(options.cacheDir, snapshotKey + '.txt');
1561+
let opts = getWatcherOptions(options);
1562+
1563+
timeout = setTimeout(() => {
1564+
logger.warn({
1565+
origin: '@parcel/core',
1566+
message: `Retrieving file system events since last build...\nThis can take upto a minute after branch changes or npm/yarn installs.`,
1567+
});
1568+
}, 5000);
1569+
let startTime = Date.now();
1570+
let events = await options.inputFS.getEventsSince(
1571+
options.watchDir,
1572+
snapshotPath,
1573+
opts,
1574+
);
1575+
clearTimeout(timeout);
15571576

1558-
let timeout = setTimeout(() => {
1559-
logger.warn({
1577+
logger.verbose({
15601578
origin: '@parcel/core',
1561-
message: `Retrieving file system events since last build...\nThis can take upto a minute after branch changes or npm/yarn installs.`,
1579+
message: `File system event count: ${events.length}`,
1580+
meta: {
1581+
trackableEvent: 'watcher_events_count',
1582+
watcherEventCount: events.length,
1583+
duration: Date.now() - startTime,
1584+
},
15621585
});
1563-
}, 5000);
1564-
let startTime = Date.now();
1565-
let events = await options.inputFS.getEventsSince(
1566-
options.watchDir,
1567-
snapshotPath,
1568-
opts,
1569-
);
1570-
clearTimeout(timeout);
1571-
1572-
logger.verbose({
1573-
origin: '@parcel/core',
1574-
message: `File system event count: ${events.length}`,
1575-
meta: {
1576-
trackableEvent: 'watcher_events_count',
1577-
watcherEventCount: events.length,
1578-
duration: Date.now() - startTime,
1579-
},
1580-
});
15811586

1582-
requestGraph.invalidateUnpredictableNodes();
1583-
requestGraph.invalidateOnBuildNodes();
1584-
requestGraph.invalidateEnvNodes(options.env);
1585-
requestGraph.invalidateOptionNodes(options);
1587+
requestGraph.invalidateUnpredictableNodes();
1588+
requestGraph.invalidateOnBuildNodes();
1589+
requestGraph.invalidateEnvNodes(options.env);
1590+
requestGraph.invalidateOptionNodes(options);
15861591

1587-
try {
15881592
await requestGraph.respondToFSEvents(
15891593
options.unstableFileInvalidations || events,
15901594
options,
15911595
10000,
15921596
);
15931597
return requestGraph;
15941598
} catch (e) {
1599+
// Prevent logging fs events took too long warning
1600+
clearTimeout(timeout);
1601+
logErrorOnBailout(options, snapshotPath, e);
15951602
// This error means respondToFSEvents timed out handling the invalidation events
15961603
// In this case we'll return a fresh RequestGraph
15971604
return new RequestGraph();
@@ -1600,3 +1607,31 @@ async function loadRequestGraph(options): Async<RequestGraph> {
16001607

16011608
return new RequestGraph();
16021609
}
1610+
function logErrorOnBailout(
1611+
options: ParcelOptions,
1612+
snapshotPath: string,
1613+
e: Error,
1614+
): void {
1615+
if (e.message && e.message.includes('invalid clockspec')) {
1616+
const snapshotContents = options.inputFS.readFileSync(
1617+
snapshotPath,
1618+
'utf-8',
1619+
);
1620+
logger.warn({
1621+
origin: '@parcel/core',
1622+
message: `Error reading clockspec from snapshot, building with clean cache.`,
1623+
meta: {
1624+
snapshotContents: snapshotContents,
1625+
trackableEvent: 'invalid_clockspec_error',
1626+
},
1627+
});
1628+
} else if (!(e instanceof FSBailoutError)) {
1629+
logger.warn({
1630+
origin: '@parcel/core',
1631+
message: `Unexpected error loading cache from disk, building with clean cache.`,
1632+
meta: {
1633+
trackableEvent: 'cache_load_error',
1634+
},
1635+
});
1636+
}
1637+
}

0 commit comments

Comments
 (0)