uniweb 0.12.20 → 0.12.22

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.
@@ -54,6 +54,7 @@ import {
54
54
  updateRootScripts,
55
55
  } from '../utils/config.js'
56
56
  import { discoverFoundations, discoverSites } from '../utils/discover.js'
57
+ import { writeJsonPreservingStyleAsync } from '../utils/json-file.js'
57
58
  import { getExistingPackageNames, validatePackageName } from '../utils/names.js'
58
59
  import { detectPackageManager, installCmd } from '../utils/pm.js'
59
60
  import { getCliPrefix } from '../utils/interactive.js'
@@ -184,9 +185,10 @@ async function validateRenameName(rootDir, newName) {
184
185
  * Rewrite the `name` field in a package.json file.
185
186
  */
186
187
  async function rewritePackageJsonName(pkgPath, newName) {
187
- const pkg = JSON.parse(await readFile(pkgPath, 'utf-8'))
188
+ const src = await readFile(pkgPath, 'utf-8')
189
+ const pkg = JSON.parse(src)
188
190
  pkg.name = newName
189
- await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
191
+ await writeJsonPreservingStyleAsync(pkgPath, pkg, src)
190
192
  }
191
193
 
192
194
  // ─── Foundation rename ───────────────────────────────────────────
@@ -234,11 +236,13 @@ async function renameFoundation(rootDir, oldName, newName, prefix) {
234
236
  for (const site of sites) {
235
237
  const sitePkgPath = join(rootDir, site.path, 'package.json')
236
238
  const siteYmlPath = join(rootDir, site.path, 'site.yml')
237
- let pkg, ymlData
239
+ let pkg, pkgSrc, ymlData
238
240
  try {
239
- pkg = JSON.parse(await readFile(sitePkgPath, 'utf-8'))
241
+ pkgSrc = await readFile(sitePkgPath, 'utf-8')
242
+ pkg = JSON.parse(pkgSrc)
240
243
  } catch {
241
244
  pkg = null
245
+ pkgSrc = null
242
246
  }
243
247
  try {
244
248
  ymlData = yaml.load(await readFile(siteYmlPath, 'utf-8')) || {}
@@ -252,6 +256,7 @@ async function renameFoundation(rootDir, oldName, newName, prefix) {
252
256
  path: site.path,
253
257
  name: site.name,
254
258
  pkg,
259
+ pkgSrc,
255
260
  sitePkgPath,
256
261
  siteYmlPath,
257
262
  ymlData,
@@ -295,7 +300,7 @@ async function renameFoundation(rootDir, oldName, newName, prefix) {
295
300
  s.pkg.dependencies[newName] = oldValue.startsWith('file:')
296
301
  ? `file:${newRel}`
297
302
  : oldValue // npm-pinned, leave it; rename-then-republish is out of scope.
298
- await writeFile(s.sitePkgPath, JSON.stringify(s.pkg, null, 2) + '\n')
303
+ await writeJsonPreservingStyleAsync(s.sitePkgPath, s.pkg, s.pkgSrc)
299
304
  }
300
305
  if (s.ymlMatches) {
301
306
  const newYmlData = { ...s.ymlData, foundation: newName }