codify-plugin-lib 1.0.182-beta7 → 1.0.182-beta70

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 (52) hide show
  1. package/bin/build.js +189 -0
  2. package/dist/bin/build.js +0 -0
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.js +3 -0
  5. package/dist/messages/handlers.js +10 -2
  6. package/dist/plan/plan.js +7 -1
  7. package/dist/plugin/plugin.d.ts +2 -1
  8. package/dist/plugin/plugin.js +6 -1
  9. package/dist/pty/background-pty.d.ts +3 -2
  10. package/dist/pty/background-pty.js +7 -14
  11. package/dist/pty/index.d.ts +8 -2
  12. package/dist/pty/seqeuntial-pty.d.ts +3 -2
  13. package/dist/pty/seqeuntial-pty.js +47 -12
  14. package/dist/resource/parsed-resource-settings.d.ts +5 -2
  15. package/dist/resource/parsed-resource-settings.js +16 -2
  16. package/dist/resource/resource-controller.js +5 -5
  17. package/dist/resource/resource-settings.d.ts +13 -3
  18. package/dist/resource/resource-settings.js +2 -2
  19. package/dist/test.d.ts +1 -0
  20. package/dist/test.js +5 -0
  21. package/dist/utils/file-utils.d.ts +14 -7
  22. package/dist/utils/file-utils.js +65 -51
  23. package/dist/utils/functions.js +2 -2
  24. package/dist/utils/index.d.ts +21 -1
  25. package/dist/utils/index.js +160 -0
  26. package/dist/utils/load-resources.d.ts +1 -0
  27. package/dist/utils/load-resources.js +46 -0
  28. package/dist/utils/package-json-utils.d.ts +12 -0
  29. package/dist/utils/package-json-utils.js +34 -0
  30. package/package.json +5 -4
  31. package/rollup.config.js +24 -0
  32. package/src/index.ts +3 -0
  33. package/src/messages/handlers.test.ts +23 -0
  34. package/src/messages/handlers.ts +11 -2
  35. package/src/plan/plan.ts +11 -1
  36. package/src/plugin/plugin.test.ts +31 -0
  37. package/src/plugin/plugin.ts +8 -2
  38. package/src/pty/background-pty.ts +10 -18
  39. package/src/pty/index.ts +10 -4
  40. package/src/pty/seqeuntial-pty.ts +62 -16
  41. package/src/pty/sequential-pty.test.ts +137 -4
  42. package/src/resource/parsed-resource-settings.test.ts +24 -0
  43. package/src/resource/parsed-resource-settings.ts +26 -8
  44. package/src/resource/resource-controller.test.ts +126 -0
  45. package/src/resource/resource-controller.ts +5 -6
  46. package/src/resource/resource-settings.test.ts +36 -0
  47. package/src/resource/resource-settings.ts +17 -5
  48. package/src/utils/file-utils.test.ts +7 -0
  49. package/src/utils/file-utils.ts +70 -55
  50. package/src/utils/functions.ts +3 -3
  51. package/src/utils/index.ts +197 -1
  52. package/src/utils/internal-utils.test.ts +1 -0
@@ -1,7 +1,11 @@
1
- import { OS } from 'codify-schemas';
1
+ import { LinuxDistro, OS } from 'codify-schemas';
2
+ import * as fsSync from 'node:fs';
3
+ import * as fs from 'node:fs/promises';
2
4
  import os from 'node:os';
3
5
  import path from 'node:path';
4
6
 
7
+ import { SpawnStatus, getPty } from '../pty/index.js';
8
+
5
9
  export function isDebug(): boolean {
6
10
  return process.env.DEBUG != null && process.env.DEBUG.includes('codify'); // TODO: replace with debug library
7
11
  }
@@ -40,6 +44,34 @@ export const Utils = {
40
44
  return os.platform() === 'linux';
41
45
  },
42
46
 
47
+ async isArmArch(): Promise<boolean> {
48
+ const $ = getPty();
49
+ if (!Utils.isMacOS()) {
50
+ // On Linux, check uname -m
51
+ const query = await $.spawn('uname -m');
52
+ return query.data.trim() === 'aarch64' || query.data.trim() === 'arm64';
53
+ }
54
+
55
+ const query = await $.spawn('sysctl -n machdep.cpu.brand_string');
56
+ return /M(\d)/.test(query.data);
57
+ },
58
+
59
+ async isHomebrewInstalled(): Promise<boolean> {
60
+ const $ = getPty();
61
+ const query = await $.spawnSafe('which brew', { interactive: true });
62
+ return query.status === SpawnStatus.SUCCESS;
63
+ },
64
+
65
+ async isRosetta2Installed(): Promise<boolean> {
66
+ if (!Utils.isMacOS()) {
67
+ return false;
68
+ }
69
+
70
+ const $ = getPty();
71
+ const query = await $.spawnSafe('arch -x86_64 /usr/bin/true 2> /dev/null', { interactive: true });
72
+ return query.status === SpawnStatus.SUCCESS;
73
+ },
74
+
43
75
  getShell(): Shell | undefined {
44
76
  const shell = process.env.SHELL || '';
45
77
 
@@ -138,6 +170,170 @@ export const Utils = {
138
170
  path.join(homeDir, '.profile'),
139
171
  ];
140
172
  },
173
+
174
+ async isDirectoryOnPath(directory: string): Promise<boolean> {
175
+ const $ = getPty();
176
+ const { data: pathQuery } = await $.spawn('echo $PATH', { interactive: true });
177
+ const lines = pathQuery.split(':');
178
+ return lines.includes(directory);
179
+ },
180
+
181
+ async assertBrewInstalled(): Promise<void> {
182
+ const $ = getPty();
183
+ const brewCheck = await $.spawnSafe('which brew', { interactive: true });
184
+ if (brewCheck.status === SpawnStatus.ERROR) {
185
+ throw new Error(
186
+ `Homebrew is not installed. Cannot install git-lfs without Homebrew installed.
187
+
188
+ Brew can be installed using Codify:
189
+ {
190
+ "type": "homebrew",
191
+ }`
192
+ );
193
+ }
194
+ },
195
+
196
+ /**
197
+ * Installs a package via the system package manager. This will use Homebrew on macOS and apt on Ubuntu/Debian or dnf on Fedora.
198
+ * @param packageName
199
+ */
200
+ async installViaPkgMgr(packageName: string): Promise<void> {
201
+ const $ = getPty();
202
+
203
+ if (Utils.isMacOS()) {
204
+ await this.assertBrewInstalled();
205
+ await $.spawn(`brew install ${packageName}`, { interactive: true, env: { HOMEBREW_NO_AUTO_UPDATE: 1 } });
206
+ }
207
+
208
+ if (Utils.isLinux()) {
209
+ const isAptInstalled = await $.spawnSafe('which apt');
210
+ if (isAptInstalled.status === SpawnStatus.SUCCESS) {
211
+ await $.spawn('apt-get update', { requiresRoot: true });
212
+ const { status, data } = await $.spawnSafe(`apt-get -y install ${packageName}`, {
213
+ requiresRoot: true,
214
+ env: { DEBIAN_FRONTEND: 'noninteractive' }
215
+ });
216
+
217
+ if (status === SpawnStatus.ERROR && data.includes('E: dpkg was interrupted, you must manually run \'sudo dpkg --configure -a\' to correct the problem.')) {
218
+ await $.spawn('dpkg --configure -a', { requiresRoot: true });
219
+ await $.spawn(`apt-get -y install ${packageName}`, {
220
+ requiresRoot: true,
221
+ env: { DEBIAN_FRONTEND: 'noninteractive' }
222
+ });
223
+
224
+ return;
225
+ }
226
+
227
+ if (status === SpawnStatus.ERROR) {
228
+ throw new Error(`Failed to install package ${packageName} via apt: ${data}`);
229
+ }
230
+ }
231
+
232
+ const isDnfInstalled = await $.spawnSafe('which dnf');
233
+ if (isDnfInstalled.status === SpawnStatus.SUCCESS) {
234
+ await $.spawn('dnf update', { requiresRoot: true });
235
+ await $.spawn(`dnf install ${packageName} -y`, { requiresRoot: true });
236
+ }
237
+
238
+ const isYumInstalled = await $.spawnSafe('which yum');
239
+ if (isYumInstalled.status === SpawnStatus.SUCCESS) {
240
+ await $.spawn('yum update', { requiresRoot: true });
241
+ await $.spawn(`yum install ${packageName} -y`, { requiresRoot: true });
242
+ }
243
+
244
+ const isPacmanInstalled = await $.spawnSafe('which pacman');
245
+ if (isPacmanInstalled.status === SpawnStatus.SUCCESS) {
246
+ await $.spawn('pacman -Syu', { requiresRoot: true });
247
+ await $.spawn(`pacman -S ${packageName} --noconfirm`, { requiresRoot: true });
248
+ }
249
+
250
+ }
251
+ },
252
+
253
+ async uninstallViaPkgMgr(packageName: string): Promise<boolean> {
254
+ const $ = getPty();
255
+
256
+ if (Utils.isMacOS()) {
257
+ await this.assertBrewInstalled();
258
+ const { status } = await $.spawnSafe(`brew uninstall --zap ${packageName}`, {
259
+ interactive: true,
260
+ env: { HOMEBREW_NO_AUTO_UPDATE: 1 }
261
+ });
262
+ return status === SpawnStatus.SUCCESS;
263
+ }
264
+
265
+ if (Utils.isLinux()) {
266
+ const isAptInstalled = await $.spawnSafe('which apt');
267
+ if (isAptInstalled.status === SpawnStatus.SUCCESS) {
268
+ const { status } = await $.spawnSafe(`apt-get autoremove -y --purge ${packageName}`, {
269
+ requiresRoot: true,
270
+ env: { DEBIAN_FRONTEND: 'noninteractive' }
271
+ });
272
+ return status === SpawnStatus.SUCCESS;
273
+ }
274
+
275
+ const isDnfInstalled = await $.spawnSafe('which dnf');
276
+ if (isDnfInstalled.status === SpawnStatus.SUCCESS) {
277
+ const { status } = await $.spawnSafe(`dnf autoremove ${packageName} -y`, { requiresRoot: true });
278
+ return status === SpawnStatus.SUCCESS;
279
+ }
280
+
281
+ const isYumInstalled = await $.spawnSafe('which yum');
282
+ if (isYumInstalled.status === SpawnStatus.SUCCESS) {
283
+ const { status } = await $.spawnSafe(`yum autoremove ${packageName} -y`, { requiresRoot: true });
284
+ return status === SpawnStatus.SUCCESS;
285
+ }
286
+
287
+ return false;
288
+ }
289
+
290
+ return false;
291
+ },
292
+
293
+ async getLinuxDistro(): Promise<LinuxDistro | undefined> {
294
+ const osRelease = await fs.readFile('/etc/os-release', 'utf8');
295
+ const lines = osRelease.split('\n');
296
+ for (const line of lines) {
297
+ if (line.startsWith('ID=')) {
298
+ const distroId = line.slice(3).trim().replaceAll('"', '');
299
+ return Object.values(LinuxDistro).includes(distroId as LinuxDistro) ? distroId as LinuxDistro : undefined;
300
+ }
301
+ }
302
+
303
+ return undefined;
304
+ },
305
+
306
+ async isUbuntu(): Promise<boolean> {
307
+ return (await this.getLinuxDistro()) === LinuxDistro.UBUNTU;
308
+ },
309
+
310
+ async isDebian(): Promise<boolean> {
311
+ return (await this.getLinuxDistro()) === LinuxDistro.DEBIAN;
312
+ },
313
+
314
+ async isArch(): Promise<boolean> {
315
+ return (await this.getLinuxDistro()) === LinuxDistro.ARCH;
316
+ },
317
+
318
+ async isCentOS(): Promise<boolean> {
319
+ return (await this.getLinuxDistro()) === LinuxDistro.CENTOS;
320
+ },
321
+
322
+ async isFedora(): Promise<boolean> {
323
+ return (await this.getLinuxDistro()) === LinuxDistro.FEDORA;
324
+ },
325
+
326
+ async isRHEL(): Promise<boolean> {
327
+ return (await this.getLinuxDistro()) === LinuxDistro.RHEL;
328
+ },
329
+
330
+ isDebianBased(): boolean {
331
+ return fsSync.existsSync('/etc/debian_version');
332
+ },
333
+
334
+ isRedhatBased(): boolean {
335
+ return fsSync.existsSync('/etc/redhat-release');
336
+ }
141
337
  };
142
338
 
143
339
 
@@ -8,6 +8,7 @@ describe('Utils tests', () => {
8
8
  type: 'type',
9
9
  name: 'name',
10
10
  dependsOn: ['a', 'b', 'c'],
11
+ os: ['linux'],
11
12
  propA: 'propA',
12
13
  propB: 'propB',
13
14
  propC: 'propC',