Skip to content

Commit

Permalink
fix: declare ES module in package.json
Browse files Browse the repository at this point in the history
In bundler mode, generate the package.json with "type": "module" and use the
"main" attribute instead of the "module" attribute.

This change makes the built ES module palatable to node in
--experimental-wasm-modules mode as well as to webpack as illustrated in
webpack/webpack#14313
  • Loading branch information
gthb committed Sep 23, 2021
1 parent 7ccacca commit c5298f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/manifest/mod.rs
Expand Up @@ -699,6 +699,7 @@ impl CrateData {

NpmPackage::ESModulesPackage(ESModulesPackage {
name: data.name,
type_: "module".into(),
collaborators: pkg.authors.clone(),
description: self.manifest.package.description.clone(),
version: pkg.version.to_string(),
Expand All @@ -713,7 +714,7 @@ impl CrateData {
url: repo_url,
}),
files: data.files,
module: data.main,
main: data.main,
homepage: data.homepage,
types: data.dts_file,
side_effects: false,
Expand All @@ -729,6 +730,7 @@ impl CrateData {

NpmPackage::ESModulesPackage(ESModulesPackage {
name: data.name,
type_: "module".into(),
collaborators: pkg.authors.clone(),
description: self.manifest.package.description.clone(),
version: pkg.version.to_string(),
Expand All @@ -743,7 +745,7 @@ impl CrateData {
url: repo_url,
}),
files: data.files,
module: data.main,
main: data.main,
homepage: data.homepage,
types: data.dts_file,
side_effects: false,
Expand Down
4 changes: 3 additions & 1 deletion src/manifest/npm/esmodules.rs
Expand Up @@ -3,6 +3,8 @@ use manifest::npm::repository::Repository;
#[derive(Serialize)]
pub struct ESModulesPackage {
pub name: String,
#[serde(rename = "type")]
pub type_: String,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub collaborators: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -14,7 +16,7 @@ pub struct ESModulesPackage {
pub repository: Option<Repository>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub files: Vec<String>,
pub module: String,
pub main: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub homepage: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down

0 comments on commit c5298f1

Please sign in to comment.