Skip to content

Commit

Permalink
fix!: don't delete "main" in package.json (#7)
Browse files Browse the repository at this point in the history
* fix!: don't delete "main" in package.json

esbuild still doesn't support exports evanw/esbuild#187
it's uncertain as yet what impact this might have on other bundlers and
loaders, hence this is a BREAKING CHANGE.

* fixup! fix!: don't delete "main" in package.json
  • Loading branch information
rvagg authored Mar 6, 2021
1 parent 782fa5e commit f5e35fe
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class Package {

const exports = {}
if (!json.exports) {
if (!json.main) exports['.'] = { import: this.file(toURL('./index.js')) }
exports['.'] = { import: this.file(toURL(json.main)) }
exports['.'] = { import: this.file(toURL(json.main || './index.js')) }
} else {
for (const [key, value] of Object.entries(json.exports)) {
if (typeof value === 'string') exports[key] = { import: this.file(toURL(value)) }
Expand Down Expand Up @@ -182,7 +181,7 @@ class Package {
const json = copy(this.pkgjson)

delete json.type
delete json.main
json.main = `./${join('./cjs', json.main || './index.js')}`
json.browser = {}
json.exports = {}
const _join = (...args) => './' + join(...args)
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/pkg-kitchensink/input/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pkg-kitchensink",
"version": "0.0.0",
"description": "",
"main": "index.js",
"main": "src/index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/pkg-kitchensink/output-notests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "pkg-kitchensink",
"version": "0.0.0",
"description": "",
"main": "./cjs/src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/pkg-kitchensink/output-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "pkg-kitchensink",
"version": "0.0.0",
"description": "",
"main": "./cjs/src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down

0 comments on commit f5e35fe

Please sign in to comment.