Skip to content

Commit

Permalink
Fix names of dist files (for real now)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkcz committed Nov 7, 2020
1 parent 5399d46 commit 8bbbc7c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changeset/good-lizards-invite.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 dist files (for real now). Third time is the charm 😅
25 changes: 15 additions & 10 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require("fs-extra")
const path = require("path")
const execa = require("execa")
const minimist = require("minimist")
const { basename } = require("path")

const stdio = ["ignore", "inherit", "pipe"]
const opts = { stdio }
Expand All @@ -18,28 +19,32 @@ const isPublish = target === "publish"
// for running tests in CI we need CJS only
const isTest = target === "test"

const tempMove = name => fs.move(`dist/${name}`, `temp/${name}`)
const moveTemp = name => fs.move(`temp/${name}`, `dist/${name}`)

const run = async () => {
const tempMove = name => fs.move(`dist/${name}`, `temp/${name}`)
const moveTemp = name => fs.move(`temp/${name}`, `dist/${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 execa("tsdx", ["build", "--format", "esm", "--env", "development"], opts)
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 execa("tsdx", ["build", "--format", "esm", "--env", "production"], opts)
// cannot build these concurrently
await build("esm", "production")
await tempMove(`${packageName}.esm.production.min.js`)
await tempMove(`${packageName}.esm.production.min.js.map`)
}

await execa(
"tsdx",
["build", "--name", packageName, "--format", isTest ? "cjs" : "esm,cjs,umd"],
opts
).catch(err => {
await build(isTest ? "cjs" : "esm,cjs,umd").catch(err => {
console.error(err.stderr)
throw new Error("build failed")
})
Expand Down

0 comments on commit 8bbbc7c

Please sign in to comment.