From f5e35fe9ed400582cf7cc2dcaf2d2d153b3b6434 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Sat, 6 Mar 2021 13:57:42 +1100 Subject: [PATCH] fix!: don't delete "main" in package.json (#7) * fix!: don't delete "main" in package.json esbuild still doesn't support exports https://github.com/evanw/esbuild/issues/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 --- src/package/index.js | 5 ++--- test/fixtures/pkg-kitchensink/input/package.json | 2 +- test/fixtures/pkg-kitchensink/output-notests/package.json | 1 + test/fixtures/pkg-kitchensink/output-tests/package.json | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/package/index.js b/src/package/index.js index 9fef037..b2ad5f7 100644 --- a/src/package/index.js +++ b/src/package/index.js @@ -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)) } @@ -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) diff --git a/test/fixtures/pkg-kitchensink/input/package.json b/test/fixtures/pkg-kitchensink/input/package.json index 4494099..2915acb 100644 --- a/test/fixtures/pkg-kitchensink/input/package.json +++ b/test/fixtures/pkg-kitchensink/input/package.json @@ -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" diff --git a/test/fixtures/pkg-kitchensink/output-notests/package.json b/test/fixtures/pkg-kitchensink/output-notests/package.json index e1b70af..08423f9 100644 --- a/test/fixtures/pkg-kitchensink/output-notests/package.json +++ b/test/fixtures/pkg-kitchensink/output-notests/package.json @@ -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" }, diff --git a/test/fixtures/pkg-kitchensink/output-tests/package.json b/test/fixtures/pkg-kitchensink/output-tests/package.json index e1b70af..08423f9 100644 --- a/test/fixtures/pkg-kitchensink/output-tests/package.json +++ b/test/fixtures/pkg-kitchensink/output-tests/package.json @@ -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" },