codify-plugin-lib 1.0.110 → 1.0.111

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/dist/index.d.ts CHANGED
@@ -9,4 +9,5 @@ export * from './resource/parsed-resource-settings.js';
9
9
  export * from './resource/resource.js';
10
10
  export * from './resource/resource-settings.js';
11
11
  export * from './stateful-parameter/stateful-parameter.js';
12
+ export * from './utils/utils.js';
12
13
  export declare function runPlugin(plugin: Plugin): Promise<void>;
package/dist/index.js CHANGED
@@ -4,12 +4,12 @@ export * from './plan/change-set.js';
4
4
  export * from './plan/plan.js';
5
5
  export * from './plan/plan-types.js';
6
6
  export * from './plugin/plugin.js';
7
- // export * from './utils/utils.js'
8
7
  export * from './pty/index.js';
9
8
  export * from './resource/parsed-resource-settings.js';
10
9
  export * from './resource/resource.js';
11
10
  export * from './resource/resource-settings.js';
12
11
  export * from './stateful-parameter/stateful-parameter.js';
12
+ export * from './utils/utils.js';
13
13
  export async function runPlugin(plugin) {
14
14
  const messageHandler = new MessageHandler(plugin);
15
15
  process.on('message', (message) => messageHandler.onMessage(message));
@@ -1,34 +1,4 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import { ResourceConfig, StringIndexedObject } from 'codify-schemas';
3
- import { SpawnOptions } from 'node:child_process';
4
- export declare enum SpawnStatus {
5
- SUCCESS = "success",
6
- ERROR = "error"
7
- }
8
- export interface SpawnResult {
9
- status: SpawnStatus;
10
- data: string;
11
- }
12
- type CodifySpawnOptions = {
13
- cwd?: string;
14
- stdioString?: boolean;
15
- } & SpawnOptions;
16
- /**
17
- *
18
- * @param cmd Command to run. Ex: `rm -rf`
19
- * @param args Optional additional arguments to append
20
- * @param opts Standard options for node spawn. Additional argument:
21
- * throws determines if a shell will throw a JS error. Defaults to true
22
- * @param extras From PromiseSpawn
23
- *
24
- * @see promiseSpawn
25
- * @see spawn
26
- *
27
- * @returns SpawnResult { status: SUCCESS | ERROR; data: string }
28
- */
29
- export declare function codifySpawn(cmd: string, args?: string[], opts?: Omit<CodifySpawnOptions, 'stdio' | 'stdioString'> & {
30
- throws?: boolean;
31
- }, extras?: Record<any, any>): Promise<SpawnResult>;
32
2
  export declare function isDebug(): boolean;
33
3
  export declare function splitUserConfig<T extends StringIndexedObject>(config: ResourceConfig & T): {
34
4
  parameters: T;
@@ -37,4 +7,3 @@ export declare function splitUserConfig<T extends StringIndexedObject>(config: R
37
7
  export declare function setsEqual(set1: Set<unknown>, set2: Set<unknown>): boolean;
38
8
  export declare function untildify(pathWithTilde: string): string;
39
9
  export declare function areArraysEqual(isElementEqual: ((desired: unknown, current: unknown) => boolean) | undefined, desired: unknown, current: unknown): boolean;
40
- export {};
@@ -1,54 +1,4 @@
1
- import promiseSpawn from '@npmcli/promise-spawn';
2
1
  import os from 'node:os';
3
- export var SpawnStatus;
4
- (function (SpawnStatus) {
5
- SpawnStatus["SUCCESS"] = "success";
6
- SpawnStatus["ERROR"] = "error";
7
- })(SpawnStatus || (SpawnStatus = {}));
8
- /**
9
- *
10
- * @param cmd Command to run. Ex: `rm -rf`
11
- * @param args Optional additional arguments to append
12
- * @param opts Standard options for node spawn. Additional argument:
13
- * throws determines if a shell will throw a JS error. Defaults to true
14
- * @param extras From PromiseSpawn
15
- *
16
- * @see promiseSpawn
17
- * @see spawn
18
- *
19
- * @returns SpawnResult { status: SUCCESS | ERROR; data: string }
20
- */
21
- export async function codifySpawn(cmd, args, opts, extras) {
22
- try {
23
- // TODO: Need to benchmark the effects of using sh vs zsh for shell.
24
- // Seems like zsh shells run slower
25
- const result = await promiseSpawn(cmd, args ?? [], { ...opts, stdio: 'pipe', stdioString: true, shell: opts?.shell ?? process.env.SHELL }, extras);
26
- if (isDebug()) {
27
- console.log(`codifySpawn result for: ${cmd}`);
28
- console.log(JSON.stringify(result, null, 2));
29
- }
30
- const status = result.code === 0
31
- ? SpawnStatus.SUCCESS
32
- : SpawnStatus.ERROR;
33
- return {
34
- status,
35
- data: status === SpawnStatus.SUCCESS ? result.stdout : result.stderr
36
- };
37
- }
38
- catch (error) {
39
- const shouldThrow = opts?.throws ?? true;
40
- if (isDebug() || shouldThrow) {
41
- console.error(`CodifySpawn Error for command ${cmd} ${args}`, error);
42
- }
43
- if (shouldThrow) {
44
- throw error;
45
- }
46
- return {
47
- status: SpawnStatus.ERROR,
48
- data: error,
49
- };
50
- }
51
- }
52
2
  export function isDebug() {
53
3
  return process.env.DEBUG != null && process.env.DEBUG.includes('codify'); // TODO: replace with debug library
54
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.110",
3
+ "version": "1.0.111",
4
4
  "description": "Library plugin library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -6,12 +6,12 @@ export * from './plan/change-set.js'
6
6
  export * from './plan/plan.js'
7
7
  export * from './plan/plan-types.js'
8
8
  export * from './plugin/plugin.js'
9
- // export * from './utils/utils.js'
10
9
  export * from './pty/index.js'
11
10
  export * from './resource/parsed-resource-settings.js';
12
11
  export * from './resource/resource.js'
13
12
  export * from './resource/resource-settings.js'
14
13
  export * from './stateful-parameter/stateful-parameter.js'
14
+ export * from './utils/utils.js'
15
15
 
16
16
  export async function runPlugin(plugin: Plugin) {
17
17
  const messageHandler = new MessageHandler(plugin);
@@ -1,82 +1,6 @@
1
- import promiseSpawn from '@npmcli/promise-spawn';
2
1
  import { ResourceConfig, StringIndexedObject } from 'codify-schemas';
3
- import { SpawnOptions } from 'node:child_process';
4
2
  import os from 'node:os';
5
3
 
6
- export enum SpawnStatus {
7
- SUCCESS = 'success',
8
- ERROR = 'error',
9
- }
10
-
11
- export interface SpawnResult {
12
- status: SpawnStatus,
13
- data: string;
14
- }
15
-
16
- type CodifySpawnOptions = {
17
- cwd?: string;
18
- stdioString?: boolean;
19
- } & SpawnOptions
20
-
21
- /**
22
- *
23
- * @param cmd Command to run. Ex: `rm -rf`
24
- * @param args Optional additional arguments to append
25
- * @param opts Standard options for node spawn. Additional argument:
26
- * throws determines if a shell will throw a JS error. Defaults to true
27
- * @param extras From PromiseSpawn
28
- *
29
- * @see promiseSpawn
30
- * @see spawn
31
- *
32
- * @returns SpawnResult { status: SUCCESS | ERROR; data: string }
33
- */
34
- export async function codifySpawn(
35
- cmd: string,
36
- args?: string[],
37
- opts?: Omit<CodifySpawnOptions, 'stdio' | 'stdioString'> & { throws?: boolean },
38
- extras?: Record<any, any>,
39
- ): Promise<SpawnResult> {
40
- try {
41
- // TODO: Need to benchmark the effects of using sh vs zsh for shell.
42
- // Seems like zsh shells run slower
43
- const result = await promiseSpawn(
44
- cmd,
45
- args ?? [],
46
- { ...opts, stdio: 'pipe', stdioString: true, shell: opts?.shell ?? process.env.SHELL },
47
- extras,
48
- );
49
-
50
- if (isDebug()) {
51
- console.log(`codifySpawn result for: ${cmd}`);
52
- console.log(JSON.stringify(result, null, 2))
53
- }
54
-
55
- const status = result.code === 0
56
- ? SpawnStatus.SUCCESS
57
- : SpawnStatus.ERROR;
58
-
59
- return {
60
- status,
61
- data: status === SpawnStatus.SUCCESS ? result.stdout : result.stderr
62
- }
63
- } catch (error) {
64
- const shouldThrow = opts?.throws ?? true;
65
- if (isDebug() || shouldThrow) {
66
- console.error(`CodifySpawn Error for command ${cmd} ${args}`, error);
67
- }
68
-
69
- if (shouldThrow) {
70
- throw error;
71
- }
72
-
73
- return {
74
- status: SpawnStatus.ERROR,
75
- data: error as string,
76
- }
77
- }
78
- }
79
-
80
4
  export function isDebug(): boolean {
81
5
  return process.env.DEBUG != null && process.env.DEBUG.includes('codify'); // TODO: replace with debug library
82
6
  }