From 2f3dcb274f795ffca4ae724b6b4795958620838d Mon Sep 17 00:00:00 2001 From: Daniel K Date: Thu, 12 Nov 2020 17:06:00 +0100 Subject: [PATCH] Fix names of UMD exports --- .changeset/short-badgers-wink.md | 6 ++++++ packages/mobx-react-lite/package.json | 2 +- packages/mobx-react/package.json | 2 +- scripts/build.js | 25 +++++++++++++++---------- 4 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 .changeset/short-badgers-wink.md diff --git a/.changeset/short-badgers-wink.md b/.changeset/short-badgers-wink.md new file mode 100644 index 000000000..f93e652f4 --- /dev/null +++ b/.changeset/short-badgers-wink.md @@ -0,0 +1,6 @@ +--- +"mobx-react": patch +"mobx-react-lite": patch +--- + +Fix names of UMD exports [#2517](https://github.com/mobxjs/mobx/issues/2617) diff --git a/packages/mobx-react-lite/package.json b/packages/mobx-react-lite/package.json index 63ec34924..1dee0a089 100644 --- a/packages/mobx-react-lite/package.json +++ b/packages/mobx-react-lite/package.json @@ -67,7 +67,7 @@ ], "scripts": { "lint": "eslint src/**/* --ext .js,.ts,.tsx", - "build": "node ../../scripts/build.js mobxreactlite", + "build": "node ../../scripts/build.js mobxReactLite", "build:test": "yarn build --target test", "build:cjs": "tsc --project tsconfig.build.cjs.json", "build:es": "tsc --project tsconfig.build.es.json", diff --git a/packages/mobx-react/package.json b/packages/mobx-react/package.json index 31b756024..60241d9ec 100644 --- a/packages/mobx-react/package.json +++ b/packages/mobx-react/package.json @@ -64,7 +64,7 @@ ], "scripts": { "lint": "eslint src/**/* --ext .js,.ts,.tsx", - "build": "node ../../scripts/build.js mobxreact", + "build": "node ../../scripts/build.js mobxReact", "build:test": "yarn build --target test", "test": "jest", "test:size": "yarn import-size --report . observer", diff --git a/scripts/build.js b/scripts/build.js index 54d934309..dd9137300 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -20,8 +20,12 @@ const isPublish = target === "publish" const isTest = target === "test" const run = async () => { - const tempMove = name => fs.move(`dist/${name}`, `temp/${name}`) - const moveTemp = name => fs.move(`temp/${name}`, `dist/${name}`) + // TSDX converts passed name argument to lowercase for file name + const pkgPrefix = `${packageName.toLowerCase()}.` + + const tempMove = name => fs.move(`dist/${pkgPrefix}${name}`, `temp/${pkgPrefix}${name}`) + const moveTemp = name => fs.move(`temp/${pkgPrefix}${name}`, `dist/${pkgPrefix}${name}`) + const build = (format, env) => { const args = ["build", "--name", packageName, "--format", format] if (env) { @@ -29,19 +33,20 @@ const run = async () => { } return execa("tsdx", args, opts) } + if (isPublish) { await fs.emptyDir("temp") // build dev/prod ESM bundles that can be consumed in browser without NODE_ENV annoyance // and these builds cannot be run in parallel because tsdx doesn't allow to change target dir await build("esm", "development") // tsdx will purge dist folder, so it's necessary to move these - await tempMove(`${packageName}.esm.development.js`) - await tempMove(`${packageName}.esm.development.js.map`) + await tempMove(`esm.development.js`) + await tempMove(`esm.development.js.map`) // cannot build these concurrently await build("esm", "production") - await tempMove(`${packageName}.esm.production.min.js`) - await tempMove(`${packageName}.esm.production.min.js.map`) + await tempMove(`esm.production.min.js`) + await tempMove(`esm.production.min.js.map`) } await build(isTest ? "cjs" : "esm,cjs,umd").catch(err => { @@ -51,10 +56,10 @@ const run = async () => { if (isPublish) { // move ESM bundles back to dist folder and remove temp - await moveTemp(`${packageName}.esm.development.js`) - await moveTemp(`${packageName}.esm.development.js.map`) - await moveTemp(`${packageName}.esm.production.min.js`) - await moveTemp(`${packageName}.esm.production.min.js.map`) + await moveTemp(`esm.development.js`) + await moveTemp(`esm.development.js.map`) + await moveTemp(`esm.production.min.js`) + await moveTemp(`esm.production.min.js.map`) await fs.remove("temp") } }