swc_node_bundler/v1/
resolve.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::{collections::HashMap, path::PathBuf};

use serde::Deserialize;
use swc_atoms::JsWord;

/// https://webpack.js.org/configuration/resolve/
#[derive(Debug, Deserialize)]
#[serde(rename = "Resolve", rename_all = "camelCase")]
pub struct ResolveConfig {
    #[serde(default)]
    pub alias: Option<AliasConfig>,

    #[serde(default)]
    pub alias_fields: Vec<JsWord>,

    #[serde(default)]
    pub description_files: Vec<JsWord>,

    #[serde(default)]
    pub enforce_extension: bool,

    #[serde(default = "default_extensions")]
    pub extensions: Vec<JsWord>,

    #[serde(default)]
    pub main_fields: Vec<JsWord>,

    #[serde(default = "default_symlinks")]
    pub symlinks: bool,
}

fn default_extensions() -> Vec<JsWord> {
    vec![
        ".wasm".into(),
        ".mjs".into(),
        ".js".into(),
        ".json".into(),
        ".ts".into(),
        ".tsc".into(),
    ]
}

fn default_symlinks() -> bool {
    true
}

#[derive(Debug, Deserialize)]
#[serde(rename = "Resolve.Alias", rename_all = "camelCase")]
pub struct AliasConfig {
    #[serde(flatten)]
    pub map: HashMap<JsWord, PathBuf>,
}