Skip to content

fix: be compatible with esm output#11

Merged
chenjiahan merged 1 commit intorstackjs:mainfrom
xc2:esm-output
Nov 3, 2024
Merged

fix: be compatible with esm output#11
chenjiahan merged 1 commit intorstackjs:mainfrom
xc2:esm-output

Conversation

@xc2
Copy link
Copy Markdown
Contributor

@xc2 xc2 commented Nov 2, 2024

Esm output is possible even though the entry file is resolved by require.resolve. It typically happens on esm only packages, e.g., https://www.npmjs.com/package/@sindresorhus/slugify

start   prebundle: @sindresorhus/slugify
ncc: Version 0.38.1
ncc: Compiling file index.js into ESM
success prebundle: @sindresorhus/slugify

ncc creates a package.json with { "type": "module" }. We could just merge it into the package.json generated by prebundle.

src/prebundle.ts Outdated
Object.assign(
pickedPackageJson,
// will be `{"type":"module"}` if the output is of esm format
JSON.parse(assets['package.json'].source),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All properties in source will override pickedPackageJson, such as types, is this expected?

I prefer to only override the type property

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE.

ncc does not intend to produce packages or types at this time. It will only create a package.json with the type field if necessary, along with fields such as exports and imports in the foreseeable future

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get 👌

@chenjiahan chenjiahan merged commit 4c56b80 into rstackjs:main Nov 3, 2024
@xc2 xc2 deleted the esm-output branch November 3, 2024 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants