@adobedjangir/commerce-admin-management 0.0.16 → 0.0.17

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 +1 -1
  2. package/scripts/setup.js +40 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobedjangir/commerce-admin-management",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "Schema-driven system configuration for Adobe Commerce App Builder sync apps. Magento-style scoped config in Adobe App Builder Database (ABDB) with encryption, Commerce REST helpers, and React Admin UI.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Adobe Inc.",
package/scripts/setup.js CHANGED
@@ -591,24 +591,55 @@ function ensureHostDeps (projectRoot) {
591
591
  try { pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')) } catch (_) {
592
592
  return { changed: false, reason: 'unreadable-package-json' }
593
593
  }
594
- pkg.dependencies = pkg.dependencies || {}
595
594
 
595
+ // Decide which deps need bumping by reading the current package.json.
596
596
  const bumped = []
597
597
  for (const [name, floor] of Object.entries(REQUIRED_HOST_DEPS)) {
598
- const declared = pkg.dependencies[name] || (pkg.devDependencies && pkg.devDependencies[name])
598
+ const declared = (pkg.dependencies && pkg.dependencies[name]) ||
599
+ (pkg.devDependencies && pkg.devDependencies[name])
599
600
  if (declared && satisfiesFloor(declared, floor)) continue
600
- // Move it to dependencies (out of devDependencies if it was there) and
601
- // set to the floor.
602
- pkg.dependencies[name] = floor
603
- if (pkg.devDependencies && pkg.devDependencies[name]) {
604
- delete pkg.devDependencies[name]
605
- }
606
601
  bumped.push({ name, was: declared || '(missing)', now: floor })
607
602
  }
608
603
 
609
604
  if (bumped.length === 0) return { changed: false, reason: 'already-satisfies' }
610
605
 
611
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8')
606
+ // Persist via `npm pkg set` rather than fs.writeFileSync. The outer
607
+ // `npm install <pkg>` keeps a buffered copy of package.json that it
608
+ // writes at the very end of the install (to add the package itself
609
+ // as a dependency) — that write clobbers anything we'd done via
610
+ // fs.writeFileSync. `npm pkg set` goes through npm's own metadata
611
+ // layer and persists across that final write.
612
+ const { execSync } = require('child_process')
613
+ const args = bumped
614
+ .map((b) => `dependencies.${b.name}=${b.now}`)
615
+ // Some keys contain "@" which `npm pkg set` accepts unquoted; we
616
+ // shell-quote the whole assignment to be safe.
617
+ .map((a) => `'${a.replace(/'/g, "'\\''")}'`)
618
+ .join(' ')
619
+ try {
620
+ execSync(`npm pkg set ${args}`, {
621
+ cwd: projectRoot,
622
+ stdio: 'pipe',
623
+ env: { ...process.env, COMMERCE_ADMIN_MANAGEMENT_SKIP_SETUP: '1' }
624
+ })
625
+ } catch (e) {
626
+ return { changed: false, reason: `npm-pkg-set-failed: ${e.message}` }
627
+ }
628
+
629
+ // Also remove from devDependencies so the bumped value in dependencies
630
+ // is the only spec npm will see on the next resolution.
631
+ const inDev = bumped.filter((b) => pkg.devDependencies && pkg.devDependencies[b.name])
632
+ if (inDev.length) {
633
+ const delArgs = inDev.map((b) => `'devDependencies.${b.name}'`).join(' ')
634
+ try {
635
+ execSync(`npm pkg delete ${delArgs}`, {
636
+ cwd: projectRoot,
637
+ stdio: 'pipe',
638
+ env: { ...process.env, COMMERCE_ADMIN_MANAGEMENT_SKIP_SETUP: '1' }
639
+ })
640
+ } catch (_) { /* non-fatal */ }
641
+ }
642
+
612
643
  return { changed: true, bumped }
613
644
  }
614
645