@take-out/scripts 0.0.49 → 0.0.51

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@take-out/scripts",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
4
4
  "type": "module",
5
5
  "main": "./src/run.ts",
6
6
  "sideEffects": false,
@@ -24,7 +24,7 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@take-out/helpers": "^0.0.47",
27
+ "@take-out/helpers": "0.0.51",
28
28
  "glob": "^11.0.0"
29
29
  },
30
30
  "devDependencies": {
@@ -66,9 +66,14 @@ Instructions:
66
66
  - update the "last updated" comment to: ${latestSha}
67
67
  - create new week sections if needed (weeks start monday)
68
68
  - format: "## Week of January 20, 2026" with sha in backticks below
69
- - use ✚ symbol only for new features, no other emoji
69
+ - no emoji, plain text only
70
70
  - group small fixes/chores into "Bug fixes and chores (N)"
71
71
  - for tamagui/one upgrades, check ~/tamagui or ~/one repos or github for what actually changed
72
72
  - write useful descriptions - explain WHY and WHAT improved, not just "fixed X"
73
73
  - stop when you reach commits already in the changelog
74
+
75
+ Archiving old entries:
76
+ - keep only 10 weeks in changelog.mdx
77
+ - when over 10 weeks, move oldest entries to changelog-YYYY.mdx (by year, e.g. changelog-2025.mdx)
78
+ - add a link at the bottom of changelog.mdx: "See [2025 changes](/docs/changelog-2025)" etc (use absolute path)
74
79
  `)
@@ -4,7 +4,7 @@
4
4
  * @description Update dependencies across workspace packages
5
5
  */
6
6
 
7
- import { existsSync, readdirSync, readFileSync, rmSync } from 'node:fs'
7
+ import { existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
8
8
  import { join } from 'node:path'
9
9
 
10
10
  import { $ } from 'bun'
@@ -129,61 +129,48 @@ function doesPackageMatchPattern(packageName: string, pattern: string): boolean
129
129
  return packageName === pattern
130
130
  }
131
131
 
132
- async function updatePackagesInWorkspace(
132
+ function updatePackageJsonVersions(
133
+ packageJsonPath: string,
133
134
  packagesToUpdate: string[],
134
- cwd: string,
135
- workspaceName: string
136
- ) {
137
- if (packagesToUpdate.length === 0) {
138
- return
139
- }
140
-
141
- $.cwd(cwd)
142
-
143
- if (globalTag) {
144
- // check which packages actually have the tag
145
- const packagesWithTag = (
146
- await Promise.all(
147
- packagesToUpdate.map(async (pkg) => {
148
- try {
149
- await $`npm view ${pkg}@${globalTag} version --json`.quiet()
150
- return pkg
151
- } catch {
152
- return null
153
- }
154
- })
155
- )
156
- ).filter((pkg): pkg is string => pkg !== null)
157
-
158
- if (packagesWithTag.length === 0) {
159
- return
135
+ versionMap: Map<string, string>
136
+ ): number {
137
+ const content = readFileSync(packageJsonPath, 'utf-8')
138
+ const packageJson = JSON.parse(content) as PackageJson
139
+ let updatedCount = 0
140
+
141
+ const updateDeps = (depsObject: Record<string, string> | undefined) => {
142
+ if (!depsObject) return
143
+ for (const pkg of packagesToUpdate) {
144
+ if (pkg in depsObject && !depsObject[pkg].startsWith('workspace:')) {
145
+ const newVersion = versionMap.get(pkg)
146
+ if (newVersion) {
147
+ const currentVersion = depsObject[pkg]
148
+ // preserve version prefix (^, ~, >=, etc) or use exact if none
149
+ const prefixMatch = currentVersion.match(/^([^\d]*)/)
150
+ const prefix = prefixMatch?.[1] || ''
151
+ depsObject[pkg] = `${prefix}${newVersion}`
152
+ updatedCount++
153
+ }
154
+ }
160
155
  }
156
+ }
161
157
 
162
- console.info(` šŸ“¦ ${workspaceName}: updating ${packagesWithTag.length} package(s)`)
163
-
164
- const packageNamesWithTags = packagesWithTag.map((pkg) => `${pkg}@${globalTag}`)
165
-
166
- try {
167
- await $`bun add ${packageNamesWithTags} --ignore-scripts`.quiet()
168
- } catch (error: any) {
169
- const errorMessage = error.message?.split('\n')[0]
170
- console.warn(` āš ļø ${workspaceName}: ${errorMessage}`)
171
- }
172
- } else {
173
- console.info(` šŸ“¦ ${workspaceName}: updating ${packagesToUpdate.length} package(s)`)
158
+ updateDeps(packageJson.dependencies)
159
+ updateDeps(packageJson.devDependencies)
160
+ updateDeps(packageJson.peerDependencies)
161
+ updateDeps(packageJson.optionalDependencies)
174
162
 
175
- try {
176
- await $`bun update ${packagesToUpdate} --latest --ignore-scripts`.quiet()
177
- } catch (error: any) {
178
- const errorMessage = error.message?.split('\n')[0]
179
- console.warn(` āš ļø ${workspaceName}: ${errorMessage}`)
180
- }
163
+ if (updatedCount > 0) {
164
+ writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n')
181
165
  }
166
+
167
+ return updatedCount
182
168
  }
183
169
 
184
170
  async function updatePackages(
185
171
  packagesByWorkspace: Map<string, { dir: string; packages: string[] }>,
186
- rootDir: string
172
+ rootDir: string,
173
+ packageJsonFiles: string[]
187
174
  ) {
188
175
  try {
189
176
  rmSync(`node_modules/vite`, {
@@ -194,58 +181,73 @@ async function updatePackages(
194
181
  // ignore if vite is not there
195
182
  }
196
183
 
197
- if (globalTag) {
198
- console.info(`šŸ” Checking which packages have tag '${globalTag}'...\n`)
199
- const allPackages = new Set<string>()
200
- for (const { packages } of packagesByWorkspace.values()) {
201
- packages.forEach((pkg) => allPackages.add(pkg))
202
- }
184
+ // collect all unique packages to update
185
+ const allPackages = new Set<string>()
186
+ for (const { packages } of packagesByWorkspace.values()) {
187
+ packages.forEach((pkg) => allPackages.add(pkg))
188
+ }
203
189
 
204
- const packagesWithTag = new Set<string>()
205
- await Promise.all(
206
- [...allPackages].map(async (pkg) => {
207
- try {
208
- await $`npm view ${pkg}@${globalTag} version --json`.quiet()
209
- console.info(` āœ“ ${pkg}@${globalTag} exists`)
210
- packagesWithTag.add(pkg)
211
- } catch {
190
+ // fetch versions for all packages (with tag if specified)
191
+ const versionMap = new Map<string, string>()
192
+ console.info(`\nšŸ” Fetching versions for ${allPackages.size} package(s)...`)
193
+
194
+ await Promise.all(
195
+ [...allPackages].map(async (pkg) => {
196
+ try {
197
+ const tag = globalTag || 'latest'
198
+ const result = await $`npm view ${pkg}@${tag} version`.quiet()
199
+ const version = result.text().trim()
200
+ if (version) {
201
+ versionMap.set(pkg, version)
202
+ console.info(` āœ“ ${pkg}@${tag} → ${version}`)
203
+ }
204
+ } catch {
205
+ if (globalTag) {
212
206
  console.info(` ⊘ ${pkg}@${globalTag} not found, skipping`)
207
+ } else {
208
+ console.info(` ⊘ ${pkg} not found, skipping`)
213
209
  }
214
- })
215
- )
216
-
217
- if (packagesWithTag.size === 0) {
218
- console.info(`\nāš ļø No packages found with tag '${globalTag}'`)
219
- return
220
- }
210
+ }
211
+ })
212
+ )
221
213
 
222
- console.info(`\nšŸ“¦ Updating packages across workspaces...`)
214
+ if (versionMap.size === 0) {
215
+ console.info(`\nāš ļø No packages found to update`)
216
+ return
217
+ }
223
218
 
224
- for (const [name, { dir, packages }] of packagesByWorkspace) {
225
- const validPackages = packages.filter((pkg) => packagesWithTag.has(pkg))
226
- await updatePackagesInWorkspace(validPackages, dir, name)
227
- }
228
- } else {
229
- console.info(`\nšŸ“¦ Updating packages across workspaces...`)
219
+ // update all package.json files directly
220
+ console.info(`\nšŸ“¦ Updating ${packageJsonFiles.length} package.json file(s)...`)
221
+ let totalUpdates = 0
230
222
 
231
- for (const [name, { dir, packages }] of packagesByWorkspace) {
232
- await updatePackagesInWorkspace(packages, dir, name)
223
+ for (const packageJsonPath of packageJsonFiles) {
224
+ const packagesInWorkspace =
225
+ packagesByWorkspace.get(getWorkspaceName(packageJsonPath, rootDir))?.packages || []
226
+
227
+ if (packagesInWorkspace.length > 0) {
228
+ const updates = updatePackageJsonVersions(
229
+ packageJsonPath,
230
+ packagesInWorkspace,
231
+ versionMap
232
+ )
233
+ if (updates > 0) {
234
+ const name = getWorkspaceName(packageJsonPath, rootDir)
235
+ console.info(` āœ“ ${name}: ${updates} package(s)`)
236
+ totalUpdates += updates
237
+ }
233
238
  }
234
239
  }
235
240
 
236
- console.info(
237
- "\nāš™ļø Running a final 'bun install' to process all changes and run lifecycle scripts..."
238
- )
241
+ console.info(`\nšŸ“ Updated ${totalUpdates} dependency version(s)`)
242
+
243
+ console.info(`\nāš™ļø Running 'bun install'...`)
239
244
  $.cwd(rootDir)
240
245
  try {
241
246
  await $`bun install`
242
- console.info("āœ… Final 'bun install' completed successfully.")
247
+ console.info('āœ… Done!')
243
248
  } catch (error: any) {
244
249
  const errorMessage = error.message?.split('\n')[0]
245
- console.error(`🚨 Final 'bun install' failed. Error: ${errorMessage}`)
246
- console.error(
247
- 'Your dependencies might be in an inconsistent state. Please check manually.'
248
- )
250
+ console.error(`🚨 'bun install' failed: ${errorMessage}`)
249
251
  }
250
252
  }
251
253
 
@@ -322,7 +324,7 @@ async function main() {
322
324
  console.info(`šŸ·ļø Using tag '${globalTag}'`)
323
325
  }
324
326
 
325
- await updatePackages(packagesByWorkspace, rootDir)
327
+ await updatePackages(packagesByWorkspace, rootDir, packageJsonFiles)
326
328
 
327
329
  console.info('\nšŸŽ‰ Dependency update complete!')
328
330
  }