Skip to content

Commit

Permalink
Fix names of UMD exports
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkcz committed Nov 12, 2020
1 parent 79a09f4 commit 2f3dcb2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changeset/short-badgers-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"mobx-react": patch
"mobx-react-lite": patch
---

Fix names of UMD exports [#2517](https://github.com/mobxjs/mobx/issues/2617)
2 changes: 1 addition & 1 deletion packages/mobx-react-lite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/mobx-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 15 additions & 10 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,33 @@ 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) {
args.push("--env", env)
}
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 => {
Expand All @@ -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")
}
}
Expand Down

0 comments on commit 2f3dcb2

Please sign in to comment.