@take-out/scripts 0.0.62 → 0.0.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/src/release.ts +33 -77
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "@take-out/scripts",
3
- "version": "0.0.62",
3
+ "version": "0.0.64",
4
4
  "type": "module",
5
5
  "main": "./src/run.ts",
6
6
  "sideEffects": false,
7
7
  "exports": {
8
8
  ".": {
9
- "types": "./types/run.d.ts",
9
+ "types": "./src/run.ts",
10
10
  "default": "./src/run.ts"
11
11
  },
12
12
  "./package.json": "./package.json",
13
13
  "./helpers/*": {
14
- "types": "./types/helpers/*.d.ts",
14
+ "types": "./src/helpers/*.ts",
15
15
  "default": "./src/helpers/*.ts"
16
16
  },
17
17
  "./*": {
18
- "types": "./types/*.d.ts",
18
+ "types": "./src/*.ts",
19
19
  "default": "./src/*.ts"
20
20
  }
21
21
  },
package/src/release.ts CHANGED
@@ -1,10 +1,11 @@
1
+ import { tmpdir } from 'node:os'
1
2
  import path, { join } from 'node:path'
2
3
 
3
4
  // note! this is an helper script used by tamagui team for publishing the takeout packages
4
5
  // you can delete this from your own app
5
6
 
6
7
  import { run } from '@take-out/scripts/helpers/run'
7
- import fs, { ensureDir, writeJSON } from 'fs-extra'
8
+ import fs, { writeJSON } from 'fs-extra'
8
9
  import pMap from 'p-map'
9
10
 
10
11
  // avoid emitter error
@@ -170,104 +171,59 @@ async function main() {
170
171
  )
171
172
  }
172
173
 
173
- if (!finish && dryRun) {
174
- console.info(`Dry run, exiting before publish`)
175
- return
176
- }
177
-
178
174
  if (!finish && !rePublish) {
179
175
  await run(`git diff`)
180
176
  }
181
177
 
182
178
  if (!finish) {
183
- const tmpDir = `/tmp/one-publish`
184
- // clean up from previous runs
185
- await fs.remove(tmpDir)
186
- await ensureDir(tmpDir)
179
+ const packDir = join(tmpdir(), `takeout-release-${nextVersion}`)
180
+ await fs.ensureDir(packDir)
187
181
 
188
182
  await pMap(
189
183
  packageJsons,
190
- async ({ name, cwd }) => {
191
- const publishOptions = [canary && `--tag canary`].filter(Boolean).join(' ')
192
-
193
- // pack with workspace:* converted to versions
194
- const tmpPackageDir = join(tmpDir, name.replace('/', '_'))
195
- await fs.copy(cwd, tmpPackageDir, {
196
- filter: (src) => {
197
- // exclude node_modules to avoid symlink issues
198
- return !src.includes('node_modules')
199
- },
200
- })
184
+ async ({ name, cwd, json }) => {
185
+ const publishOptions = [canary && `--tag canary`, dryRun && `--dry-run`]
186
+ .filter(Boolean)
187
+ .join(' ')
188
+ const tgzPath = join(packDir, `${name.replace('/', '-')}.tgz`)
201
189
 
202
- // replace workspace:* with version
203
- const pkgJsonPath = join(tmpPackageDir, 'package.json')
204
- const pkgJson = await fs.readJSON(pkgJsonPath)
205
- for (const field of [
206
- 'dependencies',
207
- 'devDependencies',
208
- 'optionalDependencies',
209
- 'peerDependencies',
210
- ]) {
211
- if (!pkgJson[field]) continue
212
- for (const depName in pkgJson[field]) {
213
- if (pkgJson[field][depName].startsWith('workspace:')) {
214
- pkgJson[field][depName] = nextVersion
215
- }
216
- }
217
- }
218
- await writeJSON(pkgJsonPath, pkgJson, { spaces: 2 })
219
-
220
- const filename = `${name.replace('/', '_')}-package.tmp.tgz`
221
- const absolutePath = `${tmpDir}/${filename}`
222
-
223
- // swap exports.types from ./src/*.ts to ./types/*.d.ts for publishing
224
- if (pkgJson.exports) {
225
- const swapTypes = (obj: any) => {
226
- for (const key in obj) {
227
- const val = obj[key]
228
- if (typeof val === 'object' && val !== null) {
229
- swapTypes(val)
230
- } else if (
231
- key === 'types' &&
232
- typeof val === 'string' &&
233
- val.includes('/src/')
234
- ) {
235
- obj[key] = val.replace('/src/', '/types/').replace('.ts', '.d.ts')
236
- }
237
- }
238
- }
239
- swapTypes(pkgJson.exports)
240
- await writeJSON(pkgJsonPath, pkgJson, { spaces: 2 })
190
+ // pack with bun (properly converts workspace:* to versions)
191
+ // use swap-exports for packages with build scripts, otherwise just pack
192
+ if (json.scripts?.build) {
193
+ await run(`bun run build --swap-exports -- bun pm pack --filename ${tgzPath}`, {
194
+ cwd,
195
+ silent: true,
196
+ })
197
+ } else {
198
+ await run(`bun pm pack --filename ${tgzPath}`, {
199
+ cwd,
200
+ silent: true,
201
+ })
241
202
  }
242
203
 
243
- await run(`npm pack --pack-destination ${tmpDir}`, {
244
- cwd: tmpPackageDir,
204
+ // publish the tgz directly
205
+ await run(`npm publish ${tgzPath} ${publishOptions}`.trim(), {
206
+ cwd: packDir,
245
207
  silent: true,
246
208
  })
247
209
 
248
- // rename npm's output to our expected filename
249
- const npmFilename = `${name.replace('@', '').replace('/', '-')}-${nextVersion}.tgz`
250
- await fs.rename(join(tmpDir, npmFilename), absolutePath)
251
-
252
- const publishCommand = ['npm publish', absolutePath, publishOptions]
253
- .filter(Boolean)
254
- .join(' ')
255
-
256
- console.info(`Publishing ${name}: ${publishCommand}`)
257
-
258
- await run(publishCommand, {
259
- cwd: tmpDir,
260
- }).catch((err) => console.error(err))
210
+ console.info(`${dryRun ? '[dry-run] ' : ''}Published ${name}`)
261
211
  },
262
212
  {
263
213
  concurrency: 15,
264
214
  }
265
215
  )
266
216
 
267
- console.info(`✅ Published\n`)
217
+ console.info(`✅ ${dryRun ? '[dry-run] ' : ''}Published\n`)
218
+
219
+ // revert version changes after dry-run
220
+ if (dryRun) {
221
+ await run(`git checkout -- packages/*/package.json`, { silent: true })
222
+ console.info('Reverted version changes\n')
223
+ }
268
224
  }
269
225
 
270
- if (!skipFinish) {
226
+ if (!skipFinish && !dryRun) {
271
227
  // then git tag, commit, push
272
228
  if (!finish) {
273
229
  await run(`bun install`)