webpack_stats/v5.rs
1/*
2 * Copyright [2022] [Kevin Velasco]
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//! # Wepback V5 Stats
18//!
19//! As much of the webpack stats file as described in
20//! [webpack docs](https://webpack.js.org/api/stat)
21//!
22
23use serde::Deserialize;
24use std::borrow::Cow;
25use std::collections::HashMap;
26
27use crate::common::chunk::ChunkName;
28use asset::Asset;
29
30use crate::v5::chunk::Chunks;
31use crate::v5::module::Modules;
32use crate::DurationMillis;
33
34use crate::v5::entry_point::EntryPoint;
35use emit::AssetPath;
36
37pub mod asset;
38pub mod chunk;
39pub mod emit;
40pub mod entry_point;
41pub mod module;
42pub mod reason;
43
44/// # Webpack stats file
45///
46/// Deserialized representation of the webpack v5 stats file. Will
47/// try to borrow as much as it can from the underlying buffer.
48#[derive(Deserialize, Debug, Default)]
49#[serde(rename_all = "camelCase", default)]
50pub struct Stats<'a> {
51 /// Version of webpack used for the compilation (5.x.x)
52 pub version: Cow<'a, str>,
53 /// Compilation specific hash
54 pub hash: Cow<'a, str>,
55 /// Compilation time in milliseconds
56 pub time: DurationMillis,
57 /// Undocumented by webpack
58 pub public_path: Cow<'a, str>,
59 /// path to webpack output directory
60 pub output_path: Cow<'a, str>,
61 /// Chunk name to emitted asset(s) mapping
62 #[serde(borrow)]
63 pub assets_by_chunk_name: ChunkMapping<'a>,
64 pub entrypoints: HashMap<Cow<'a, str>, EntryPoint<'a>>,
65 pub assets: Vec<Asset<'a>>,
66 pub chunks: Chunks<'a>,
67 pub modules: Modules<'a>,
68 // pub entry_points: Vec<EntryPoint<'a>>
69
70 // TODO:
71 #[serde(skip)]
72 errors: Vec<()>,
73 errors_count: usize,
74 #[serde(skip)]
75 warnings: Vec<()>,
76 warnings_count: usize,
77 children: Vec<Self>,
78}
79
80type ChunkMapping<'a> = HashMap<ChunkName<'a>, Vec<AssetPath<'a>>>;
81
82#[cfg(test)]
83mod tests;