include README.md and license files in 'files' field of package.json

master
rhysd 6 years ago
parent bedbf3de9d
commit 6dbcba22e8
  1. 10
      src/command/build.rs
  2. 46
      src/manifest/mod.rs

@ -239,29 +239,29 @@ impl Build {
step_add_wasm_target,
step_build_wasm,
step_create_dir,
step_create_json,
step_copy_readme,
step_copy_license,
step_install_wasm_bindgen,
step_run_wasm_bindgen,
step_create_json,
],
BuildMode::Noinstall => steps![
step_check_rustc_version,
step_check_crate_config,
step_build_wasm,
step_create_dir,
step_create_json,
step_copy_readme,
step_copy_license,
step_run_wasm_bindgen
step_run_wasm_bindgen,
step_create_json,
],
BuildMode::Force => steps![
step_build_wasm,
step_create_dir,
step_create_json,
step_copy_readme,
step_copy_license,
step_run_wasm_bindgen
step_run_wasm_bindgen,
step_create_json,
],
}
}

@ -374,11 +374,11 @@ impl CrateData {
PBAR.step(step, &msg);
let pkg_file_path = out_dir.join("package.json");
let npm_data = if target == "nodejs" {
self.to_commonjs(scope, disable_dts)
self.to_commonjs(scope, disable_dts, out_dir)
} else if target == "no-modules" {
self.to_nomodules(scope, disable_dts)
self.to_nomodules(scope, disable_dts, out_dir)
} else {
self.to_esmodules(scope, disable_dts)
self.to_esmodules(scope, disable_dts, out_dir)
};
let npm_json = serde_json::to_string_pretty(&npm_data)?;
@ -392,6 +392,7 @@ impl CrateData {
scope: &Option<String>,
include_commonjs_shim: bool,
disable_dts: bool,
out_dir: &Path,
) -> NpmData {
let crate_name = self.crate_name();
let wasm_file = format!("{}_bg.wasm", crate_name);
@ -417,6 +418,23 @@ impl CrateData {
} else {
None
};
let readme_file = out_dir.join("README.md");
if readme_file.is_file() {
files.push("README.md".to_string());
}
if let Ok(entries) = fs::read_dir(out_dir) {
let file_names = entries
.filter_map(|e| e.ok())
.filter(|e| e.metadata().map(|m| m.is_file()).unwrap_or(false))
.filter_map(|e| e.file_name().into_string().ok())
.filter(|f| f.starts_with("LICENSE"));
for file_name in file_names {
files.push(file_name);
}
}
NpmData {
name: npm_name,
dts_file,
@ -425,8 +443,8 @@ impl CrateData {
}
}
fn to_commonjs(&self, scope: &Option<String>, disable_dts: bool) -> NpmPackage {
let data = self.npm_data(scope, true, disable_dts);
fn to_commonjs(&self, scope: &Option<String>, disable_dts: bool, out_dir: &Path) -> NpmPackage {
let data = self.npm_data(scope, true, disable_dts, out_dir);
let pkg = &self.data.packages[self.current_idx];
self.check_optional_fields();
@ -452,8 +470,13 @@ impl CrateData {
})
}
fn to_esmodules(&self, scope: &Option<String>, disable_dts: bool) -> NpmPackage {
let data = self.npm_data(scope, false, disable_dts);
fn to_esmodules(
&self,
scope: &Option<String>,
disable_dts: bool,
out_dir: &Path,
) -> NpmPackage {
let data = self.npm_data(scope, false, disable_dts, out_dir);
let pkg = &self.data.packages[self.current_idx];
self.check_optional_fields();
@ -480,8 +503,13 @@ impl CrateData {
})
}
fn to_nomodules(&self, scope: &Option<String>, disable_dts: bool) -> NpmPackage {
let data = self.npm_data(scope, false, disable_dts);
fn to_nomodules(
&self,
scope: &Option<String>,
disable_dts: bool,
out_dir: &Path,
) -> NpmPackage {
let data = self.npm_data(scope, false, disable_dts, out_dir);
let pkg = &self.data.packages[self.current_idx];
self.check_optional_fields();

Loading…
Cancel
Save