@payloadcms/figma 0.0.1-alpha.63 → 0.0.1-alpha.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.
@@ -40,24 +40,33 @@ import * as log from './log.js';
40
40
  * Install a package as a production dependency
41
41
  * @param version - Version to install (without caret). Defaults to 'latest'.
42
42
  */ export async function installPackage(projectPath, packageName, packageManager, version = 'latest') {
43
+ return installPackages(projectPath, [
44
+ {
45
+ name: packageName,
46
+ version
47
+ }
48
+ ], packageManager);
49
+ }
50
+ /**
51
+ * Install multiple packages as production dependencies in a single package-manager call.
52
+ * No-op when packages is empty. Throws on failure with exit code and truncated stderr.
53
+ */ export async function installPackages(projectPath, packages, packageManager) {
54
+ if (packages.length === 0) {
55
+ return;
56
+ }
43
57
  return new Promise((resolve, reject)=>{
44
58
  const command = packageManager;
45
- const packageSpec = packageName.endsWith('.tgz') ? packageName : `${packageName}@${version}`;
59
+ const packageSpecs = packages.map(({ name, version })=>name.endsWith('.tgz') ? name : `${name}@${version ?? 'latest'}`);
46
60
  const args = [
47
- 'add',
48
- packageSpec
61
+ packageManager === 'npm' ? 'install' : 'add',
62
+ ...packageSpecs
49
63
  ];
50
- // npm uses 'install' instead of 'add'
51
- if (packageManager === 'npm') {
52
- args[0] = 'install';
53
- }
54
64
  log.debug(`Running: ${command} ${args.join(' ')} in ${projectPath}`);
55
65
  let stderr = '';
56
66
  const child = spawn(command, args, {
57
67
  cwd: projectPath,
58
68
  stdio: 'pipe'
59
69
  });
60
- // Capture stderr for debug logging
61
70
  if (child.stderr) {
62
71
  child.stderr.on('data', (data)=>{
63
72
  stderr += data.toString();
@@ -69,15 +78,17 @@ import * as log from './log.js';
69
78
  });
70
79
  child.on('close', (code)=>{
71
80
  if (code === 0) {
72
- log.debug(`Successfully installed ${packageName}`);
81
+ log.debug(`Successfully installed ${packageSpecs.join(', ')}`);
73
82
  resolve();
74
- } else {
75
- log.debug(`Failed to install ${packageName} (exit code: ${code})`);
76
- if (stderr) {
77
- log.debug(`stderr: ${stderr}`);
78
- }
79
- reject(new Error(`Failed to install ${packageName}`));
83
+ return;
84
+ }
85
+ log.debug(`Batched install failed (exit code: ${code})`);
86
+ if (stderr) {
87
+ log.debug(`stderr: ${stderr}`);
80
88
  }
89
+ const truncatedStderr = stderr.trim().slice(-500);
90
+ const detail = truncatedStderr ? `\n${truncatedStderr}` : '';
91
+ reject(new Error(`Failed to install: ${packageSpecs.join(', ')} (exit code ${code})${detail}`));
81
92
  });
82
93
  });
83
94
  }
@@ -85,29 +96,58 @@ import * as log from './log.js';
85
96
  * Uninstall a package
86
97
  * Does not throw on failure - orphaned package is better than broken config
87
98
  */ export async function uninstallPackage(projectPath, packageName, packageManager) {
99
+ return uninstallPackages(projectPath, [
100
+ packageName
101
+ ], packageManager);
102
+ }
103
+ /**
104
+ * Uninstall multiple packages in a single package-manager call.
105
+ * No-op when packageNames is empty. Does not throw — orphaned packages are
106
+ * preferable to a crash mid-config-rewrite. Returns a success flag so callers
107
+ * can avoid claiming "Uninstalled X" when the package manager actually failed.
108
+ */ export async function uninstallPackages(projectPath, packageNames, packageManager) {
109
+ if (packageNames.length === 0) {
110
+ return {
111
+ failedPackages: [],
112
+ success: true
113
+ };
114
+ }
88
115
  return new Promise((resolve)=>{
89
116
  const command = packageManager;
90
117
  const args = [
91
- 'remove',
92
- packageName
118
+ packageManager === 'npm' ? 'uninstall' : 'remove',
119
+ ...packageNames
93
120
  ];
94
- // npm uses 'uninstall' instead of 'remove'
95
- if (packageManager === 'npm') {
96
- args[0] = 'uninstall';
97
- }
98
121
  log.debug(`Running: ${command} ${args.join(' ')} in ${projectPath}`);
99
122
  const child = spawn(command, args, {
100
123
  cwd: projectPath,
101
124
  stdio: 'pipe'
102
125
  });
126
+ child.on('error', (error)=>{
127
+ log.debug(`Spawn error for ${command}: ${error.message}`);
128
+ resolve({
129
+ failedPackages: [
130
+ ...packageNames
131
+ ],
132
+ success: false
133
+ });
134
+ });
103
135
  child.on('close', (code)=>{
104
136
  if (code === 0) {
105
- log.debug(`Successfully uninstalled ${packageName}`);
106
- } else {
107
- log.debug(`Failed to uninstall ${packageName} (exit code: ${code}), continuing anyway`);
137
+ log.debug(`Successfully uninstalled ${packageNames.join(', ')}`);
138
+ resolve({
139
+ failedPackages: [],
140
+ success: true
141
+ });
142
+ return;
108
143
  }
109
- // Always resolve, even on error
110
- resolve();
144
+ log.debug(`Batched uninstall failed (exit code: ${code}), continuing anyway`);
145
+ resolve({
146
+ failedPackages: [
147
+ ...packageNames
148
+ ],
149
+ success: false
150
+ });
111
151
  });
112
152
  });
113
153
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/figma",
3
- "version": "0.0.1-alpha.63",
3
+ "version": "0.0.1-alpha.64",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "type": "module",
6
6
  "exports": {