(project_path: &Path, build_debug: bool)
| 42 | } |
| 43 | |
| 44 | pub(crate) fn build_javascript(project_path: &Path, build_debug: bool) -> anyhow::Result<PathBuf> { |
| 45 | let cwd = fs::canonicalize(project_path)?; |
| 46 | |
| 47 | let mut tsc_path = cwd.join("node_modules/.bin/tsc"); |
| 48 | if cfg!(windows) { |
| 49 | tsc_path.set_extension("cmd"); |
| 50 | } |
| 51 | if tsc_path.exists() { |
| 52 | let status = std::process::Command::new(tsc_path) |
| 53 | .arg("--noEmit") |
| 54 | .current_dir(&cwd) |
| 55 | .status() |
| 56 | .context("Failed to execute tsc")?; |
| 57 | if !status.success() { |
| 58 | if let Some(code) = status.code() |
| 59 | && let Ok(code) = u8::try_from(code).map(ExitCode::from) |
| 60 | { |
| 61 | anyhow::bail!(ExitWithCode(code)); |
| 62 | } |
| 63 | // For an abnormal exit, show the details of the status. |
| 64 | anyhow::bail!("tsc exited with {status}"); |
| 65 | } |
| 66 | } else { |
| 67 | eprintln!( |
| 68 | "tsc not found in node_modules. Make sure you have the `typescript` package \ |
| 69 | as a dev-dependency and that your dependencies are installed." |
| 70 | ) |
| 71 | } |
| 72 | |
| 73 | let mut bundler = Bundler::new(BundlerOptions { |
| 74 | input: Some(vec!["./src/index.ts".to_string().into()]), |
| 75 | cwd: Some(cwd.clone()), |
| 76 | sourcemap: Some(SourceMapType::Inline), |
| 77 | external: Some(rolldown::IsExternal::StringOrRegex(vec![ |
| 78 | // Mark the bindings as external so we don't get a warning. |
| 79 | StringOrRegex::Regex(HybridRegex::Optimize(Regex::new("spacetime:sys.*").unwrap())), |
| 80 | ])), |
| 81 | platform: Some(rolldown::Platform::Browser), // Browser is the correct choice here because it doesn't inject Node.js polyfills. |
| 82 | shim_missing_exports: Some(false), |
| 83 | name: None, |
| 84 | entry_filenames: None, |
| 85 | chunk_filenames: None, // The pattern to use for naming shared chunks created when code-splitting |
| 86 | css_entry_filenames: None, |
| 87 | css_chunk_filenames: None, // We're not doing CSS |
| 88 | asset_filenames: None, // assets/[name]-[hash][extname] |
| 89 | sanitize_filename: Some(rolldown::SanitizeFilename::Boolean(true)), // Replace characters that are invalid in filenames with underscores |
| 90 | dir: None, // The output directory to write to. We only want a single output file, so we won't set this. |
| 91 | file: Some("./dist/bundle.js".into()), // The output file to write to. We want a single output file. |
| 92 | format: Some(rolldown::OutputFormat::Esm), // We want to use ES Modules in SpacetimeDB |
| 93 | exports: Some(rolldown::OutputExports::Named), // Use named exports for ES modules. |
| 94 | globals: None, // We don't have any external dependencies except for `spacetimedb` which is a dependency and declares all its globals |
| 95 | paths: None, // Maps external module IDs to paths |
| 96 | generated_code: Some(rolldown::GeneratedCodeOptions::es2015()), |
| 97 | es_module: Some(rolldown::EsModuleFlag::IfDefaultProp), // See https://rollupjs.org/configuration-options/#output-esmodule |
| 98 | drop_labels: None, |
| 99 | hash_characters: None, // File name hash characters, we don't care |
| 100 | banner: None, // String to prepend to the bundle |
| 101 | footer: None, // String to append to the bundle |
no test coverage detected
searching dependent graphs…