@codifycli/plugin-core 1.1.0-beta9 → 1.2.1-beta.1
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/common/apply-notes.d.ts +5 -0
- package/dist/common/apply-notes.js +10 -0
- package/dist/common/errors.d.ts +2 -1
- package/dist/common/errors.js +3 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/messages/handlers.js +24 -15
- package/dist/messages/sender.d.ts +1 -0
- package/dist/messages/sender.js +12 -0
- package/dist/plan/change-set.d.ts +1 -0
- package/dist/plan/change-set.js +13 -3
- package/dist/plugin/plugin.d.ts +7 -2
- package/dist/plugin/plugin.js +14 -7
- package/dist/pty/background-pty.d.ts +1 -0
- package/dist/pty/background-pty.js +3 -0
- package/dist/pty/index.d.ts +3 -1
- package/dist/pty/index.js +5 -2
- package/dist/pty/seqeuntial-pty.d.ts +4 -0
- package/dist/pty/seqeuntial-pty.js +18 -3
- package/dist/resource/parsed-resource-settings.js +1 -1
- package/dist/utils/file-utils.js +8 -2
- package/dist/utils/functions.js +3 -2
- package/dist/utils/index.js +15 -1
- package/package.json +3 -3
- package/src/common/apply-notes.ts +12 -0
- package/src/common/errors.ts +3 -1
- package/src/index.ts +1 -0
- package/src/messages/handlers.ts +24 -16
- package/src/messages/sender.ts +21 -1
- package/src/plan/change-set.test.ts +46 -0
- package/src/plan/change-set.ts +11 -3
- package/src/plugin/plugin.ts +22 -8
- package/src/pty/background-pty.ts +4 -0
- package/src/pty/index.ts +8 -2
- package/src/pty/seqeuntial-pty.ts +21 -3
- package/src/resource/parsed-resource-settings.ts +1 -1
- package/src/utils/file-utils.ts +7 -2
- package/src/utils/functions.ts +3 -2
- package/src/utils/index.ts +18 -1
- package/src/utils/internal-utils.test.ts +1 -0
- package/.claude/settings.local.json +0 -5
- package/dist/bin/build.d.ts +0 -1
- package/dist/bin/build.js +0 -80
- package/dist/bin/deploy-plugin.d.ts +0 -2
- package/dist/bin/deploy-plugin.js +0 -8
- package/dist/entities/change-set.d.ts +0 -24
- package/dist/entities/change-set.js +0 -152
- package/dist/entities/errors.d.ts +0 -4
- package/dist/entities/errors.js +0 -7
- package/dist/entities/plan-types.d.ts +0 -25
- package/dist/entities/plan-types.js +0 -1
- package/dist/entities/plan.d.ts +0 -15
- package/dist/entities/plan.js +0 -127
- package/dist/entities/plugin.d.ts +0 -16
- package/dist/entities/plugin.js +0 -80
- package/dist/entities/resource-options.d.ts +0 -31
- package/dist/entities/resource-options.js +0 -76
- package/dist/entities/resource-types.d.ts +0 -11
- package/dist/entities/resource-types.js +0 -1
- package/dist/entities/resource.d.ts +0 -42
- package/dist/entities/resource.js +0 -303
- package/dist/entities/stateful-parameter.d.ts +0 -29
- package/dist/entities/stateful-parameter.js +0 -46
- package/dist/entities/transform-parameter.d.ts +0 -4
- package/dist/entities/transform-parameter.js +0 -2
- package/dist/pty/vitest.config.d.ts +0 -2
- package/dist/pty/vitest.config.js +0 -11
- package/dist/resource/stateful-parameter.d.ts +0 -165
- package/dist/resource/stateful-parameter.js +0 -94
- package/dist/scripts/deploy.d.ts +0 -1
- package/dist/scripts/deploy.js +0 -2
- package/dist/test.d.ts +0 -1
- package/dist/test.js +0 -5
- package/dist/utils/codify-spawn.d.ts +0 -29
- package/dist/utils/codify-spawn.js +0 -136
- package/dist/utils/internal-utils.d.ts +0 -12
- package/dist/utils/internal-utils.js +0 -74
- package/dist/utils/load-resources.d.ts +0 -1
- package/dist/utils/load-resources.js +0 -46
- package/dist/utils/package-json-utils.d.ts +0 -12
- package/dist/utils/package-json-utils.js +0 -34
- package/dist/utils/spawn-2.d.ts +0 -5
- package/dist/utils/spawn-2.js +0 -7
- package/dist/utils/spawn.d.ts +0 -29
- package/dist/utils/spawn.js +0 -124
- package/dist/utils/utils.d.ts +0 -18
- package/dist/utils/utils.js +0 -86
|
@@ -107,6 +107,7 @@ describe('Change set tests', () => {
|
|
|
107
107
|
|
|
108
108
|
const parameterSettings = new ParsedResourceSettings({
|
|
109
109
|
id: 'type',
|
|
110
|
+
operatingSystems: [],
|
|
110
111
|
parameterSettings: {
|
|
111
112
|
propA: { type: 'array' }
|
|
112
113
|
}
|
|
@@ -129,6 +130,7 @@ describe('Change set tests', () => {
|
|
|
129
130
|
|
|
130
131
|
const parameterSettings = new ParsedResourceSettings({
|
|
131
132
|
id: 'type',
|
|
133
|
+
operatingSystems: [],
|
|
132
134
|
parameterSettings: {
|
|
133
135
|
propA: { type: 'array' }
|
|
134
136
|
}
|
|
@@ -152,6 +154,7 @@ describe('Change set tests', () => {
|
|
|
152
154
|
|
|
153
155
|
const parameterSettings = new ParsedResourceSettings({
|
|
154
156
|
id: 'type',
|
|
157
|
+
operatingSystems: [],
|
|
155
158
|
parameterSettings: {
|
|
156
159
|
propA: { canModify: true }
|
|
157
160
|
}
|
|
@@ -176,6 +179,7 @@ describe('Change set tests', () => {
|
|
|
176
179
|
|
|
177
180
|
const parameterSettings = new ParsedResourceSettings({
|
|
178
181
|
id: 'type',
|
|
182
|
+
operatingSystems: [],
|
|
179
183
|
parameterSettings: {
|
|
180
184
|
propA: { canModify: true },
|
|
181
185
|
propB: { canModify: true }
|
|
@@ -196,6 +200,7 @@ describe('Change set tests', () => {
|
|
|
196
200
|
|
|
197
201
|
const parameterSettings = new ParsedResourceSettings({
|
|
198
202
|
id: 'type',
|
|
203
|
+
operatingSystems: [],
|
|
199
204
|
parameterSettings: {
|
|
200
205
|
propA: { type: 'array' }
|
|
201
206
|
},
|
|
@@ -213,6 +218,7 @@ describe('Change set tests', () => {
|
|
|
213
218
|
|
|
214
219
|
const parameterSettings = new ParsedResourceSettings({
|
|
215
220
|
id: 'type',
|
|
221
|
+
operatingSystems: [],
|
|
216
222
|
parameterSettings: {
|
|
217
223
|
propA: { type: 'array' }
|
|
218
224
|
},
|
|
@@ -229,6 +235,7 @@ describe('Change set tests', () => {
|
|
|
229
235
|
|
|
230
236
|
const parameterSettings = new ParsedResourceSettings({
|
|
231
237
|
id: 'type',
|
|
238
|
+
operatingSystems: [],
|
|
232
239
|
parameterSettings: {
|
|
233
240
|
propA: { type: 'array' }
|
|
234
241
|
},
|
|
@@ -245,6 +252,7 @@ describe('Change set tests', () => {
|
|
|
245
252
|
|
|
246
253
|
const parameterSettings = new ParsedResourceSettings({
|
|
247
254
|
id: 'type',
|
|
255
|
+
operatingSystems: [],
|
|
248
256
|
parameterSettings: {
|
|
249
257
|
propA: {
|
|
250
258
|
type: 'array',
|
|
@@ -259,12 +267,50 @@ describe('Change set tests', () => {
|
|
|
259
267
|
expect(result.parameterChanges[0].operation).to.eq(ParameterOperation.MODIFY);
|
|
260
268
|
})
|
|
261
269
|
|
|
270
|
+
it('excludes setting parameters from destroy change set', () => {
|
|
271
|
+
const settings = {
|
|
272
|
+
id: 'type',
|
|
273
|
+
operatingSystems: [],
|
|
274
|
+
parameterSettings: {
|
|
275
|
+
propA: {},
|
|
276
|
+
propB: { setting: true },
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
const cs = ChangeSet.destroy({ propA: 'val', propB: true }, settings as any);
|
|
281
|
+
expect(cs.parameterChanges.length).to.eq(1);
|
|
282
|
+
expect(cs.parameterChanges[0].name).to.eq('propA');
|
|
283
|
+
expect(cs.parameterChanges[0].operation).to.eq(ParameterOperation.REMOVE);
|
|
284
|
+
expect(cs.operation).to.eq(ResourceOperation.DESTROY);
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
it('excludes multiple setting parameters from destroy change set', () => {
|
|
288
|
+
const settings = {
|
|
289
|
+
id: 'type',
|
|
290
|
+
operatingSystems: [],
|
|
291
|
+
parameterSettings: {
|
|
292
|
+
skipAlreadyInstalledCasks: { type: 'boolean', default: true, setting: true },
|
|
293
|
+
onlyPlanUserInstalled: { type: 'boolean', default: true, setting: true },
|
|
294
|
+
directory: { type: 'directory' },
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const cs = ChangeSet.destroy(
|
|
299
|
+
{ skipAlreadyInstalledCasks: true, onlyPlanUserInstalled: true, directory: '/opt/homebrew' },
|
|
300
|
+
settings as any
|
|
301
|
+
);
|
|
302
|
+
expect(cs.parameterChanges.length).to.eq(1);
|
|
303
|
+
expect(cs.parameterChanges[0].name).to.eq('directory');
|
|
304
|
+
expect(cs.operation).to.eq(ResourceOperation.DESTROY);
|
|
305
|
+
})
|
|
306
|
+
|
|
262
307
|
it('correctly determines array equality 5', () => {
|
|
263
308
|
const arrA = [{ key1: 'b' }, { key1: 'a' }, { key1: 'a' }];
|
|
264
309
|
const arrB = [{ key1: 'a' }, { key1: 'a' }, { key1: 'b' }];
|
|
265
310
|
|
|
266
311
|
const parameterSettings = new ParsedResourceSettings({
|
|
267
312
|
id: 'type',
|
|
313
|
+
operatingSystems: [],
|
|
268
314
|
parameterSettings: {
|
|
269
315
|
propA: {
|
|
270
316
|
type: 'array',
|
package/src/plan/change-set.ts
CHANGED
|
@@ -94,6 +94,7 @@ export class ChangeSet<T extends StringIndexedObject> {
|
|
|
94
94
|
|
|
95
95
|
static destroy<T extends StringIndexedObject>(current: Partial<T>, settings?: ResourceSettings<T>): ChangeSet<T> {
|
|
96
96
|
const parameterChanges = Object.entries(current)
|
|
97
|
+
.filter(([k]) => !settings?.parameterSettings?.[k]?.setting)
|
|
97
98
|
.map(([k, v]) => ({
|
|
98
99
|
name: k,
|
|
99
100
|
operation: ParameterOperation.REMOVE,
|
|
@@ -153,13 +154,13 @@ export class ChangeSet<T extends StringIndexedObject> {
|
|
|
153
154
|
): ParameterChange<T>[] {
|
|
154
155
|
const parameterChangeSet = new Array<ParameterChange<T>>();
|
|
155
156
|
|
|
156
|
-
// Filter out null
|
|
157
|
+
// Filter out null, undefined, [], and {} — all treated as "no value"
|
|
157
158
|
const desired = Object.fromEntries(
|
|
158
|
-
Object.entries(desiredParameters).filter(([, v]) => v
|
|
159
|
+
Object.entries(desiredParameters).filter(([, v]) => !ChangeSet.isAbsent(v))
|
|
159
160
|
) as Partial<T>
|
|
160
161
|
|
|
161
162
|
const current = Object.fromEntries(
|
|
162
|
-
Object.entries(currentParameters).filter(([, v]) => v
|
|
163
|
+
Object.entries(currentParameters).filter(([, v]) => !ChangeSet.isAbsent(v))
|
|
163
164
|
) as Partial<T>
|
|
164
165
|
|
|
165
166
|
for (const k of new Set([...Object.keys(current), ...Object.keys(desired)])) {
|
|
@@ -226,6 +227,13 @@ export class ChangeSet<T extends StringIndexedObject> {
|
|
|
226
227
|
return orderOfOperations[Math.max(indexPrev, indexNext)];
|
|
227
228
|
}
|
|
228
229
|
|
|
230
|
+
private static isAbsent(v: unknown): boolean {
|
|
231
|
+
if (v === null || v === undefined) return true;
|
|
232
|
+
if (Array.isArray(v)) return v.length === 0;
|
|
233
|
+
if (typeof v === 'object') return Object.keys(v as object).length === 0;
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
|
|
229
237
|
private static isSame(
|
|
230
238
|
desired: unknown,
|
|
231
239
|
current: unknown,
|
package/src/plugin/plugin.ts
CHANGED
|
@@ -31,15 +31,22 @@ import { VerbosityLevel } from '../utils/verbosity-level.js';
|
|
|
31
31
|
export class Plugin {
|
|
32
32
|
planStorage: Map<string, Plan<any>>;
|
|
33
33
|
planPty = new BackgroundPty();
|
|
34
|
+
minSupportedCliVersion: string | undefined;
|
|
34
35
|
|
|
35
36
|
constructor(
|
|
36
37
|
public name: string,
|
|
37
|
-
public resourceControllers: Map<string, ResourceController<ResourceConfig
|
|
38
|
+
public resourceControllers: Map<string, ResourceController<ResourceConfig>>,
|
|
39
|
+
options?: { minSupportedCliVersion?: string }
|
|
38
40
|
) {
|
|
39
41
|
this.planStorage = new Map();
|
|
42
|
+
this.minSupportedCliVersion = options?.minSupportedCliVersion;
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
static create(
|
|
45
|
+
static create(
|
|
46
|
+
name: string,
|
|
47
|
+
resources: Resource<any>[],
|
|
48
|
+
options?: { minSupportedCliVersion?: string }
|
|
49
|
+
) {
|
|
43
50
|
const controllers = resources
|
|
44
51
|
.map((resource) => new ResourceController(resource))
|
|
45
52
|
|
|
@@ -47,7 +54,7 @@ export class Plugin {
|
|
|
47
54
|
controllers.map((r) => [r.typeId, r] as const)
|
|
48
55
|
);
|
|
49
56
|
|
|
50
|
-
return new Plugin(name, controllersMap);
|
|
57
|
+
return new Plugin(name, controllersMap, options);
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
async initialize(data: InitializeRequestData): Promise<InitializeResponseData> {
|
|
@@ -60,6 +67,7 @@ export class Plugin {
|
|
|
60
67
|
}
|
|
61
68
|
|
|
62
69
|
return {
|
|
70
|
+
minSupportedCliVersion: this.minSupportedCliVersion,
|
|
63
71
|
resourceDefinitions: [...this.resourceControllers.values()]
|
|
64
72
|
.map((r) => {
|
|
65
73
|
const sensitiveParameters = Object.entries(r.settings.parameterSettings ?? {})
|
|
@@ -174,9 +182,11 @@ export class Plugin {
|
|
|
174
182
|
throw new Error(`Resource type not found: ${core.type}`);
|
|
175
183
|
}
|
|
176
184
|
|
|
177
|
-
const validation = await this.
|
|
178
|
-
.
|
|
179
|
-
|
|
185
|
+
const validation = await ptyLocalStorage.run(this.planPty, () =>
|
|
186
|
+
this.resourceControllers
|
|
187
|
+
.get(core.type)!
|
|
188
|
+
.validate(core, parameters)
|
|
189
|
+
);
|
|
180
190
|
|
|
181
191
|
validationResults.push(validation);
|
|
182
192
|
}
|
|
@@ -240,7 +250,11 @@ export class Plugin {
|
|
|
240
250
|
throw new Error('Malformed plan with resource that cannot be found');
|
|
241
251
|
}
|
|
242
252
|
|
|
243
|
-
|
|
253
|
+
let applyLogs: string[] = [];
|
|
254
|
+
await ptyLocalStorage.run(new SequentialPty(), async () => {
|
|
255
|
+
await resource.apply(plan);
|
|
256
|
+
applyLogs = getPty().getLogs();
|
|
257
|
+
});
|
|
244
258
|
|
|
245
259
|
// Validate using desired/desired. If the apply was successful, no changes should be reported back.
|
|
246
260
|
// Default back desired back to current if it is not defined (for destroys only)
|
|
@@ -258,7 +272,7 @@ export class Plugin {
|
|
|
258
272
|
})
|
|
259
273
|
|
|
260
274
|
if (validationPlan.requiresChanges()) {
|
|
261
|
-
throw new ApplyValidationError(
|
|
275
|
+
throw new ApplyValidationError(validationPlan, applyLogs);
|
|
262
276
|
}
|
|
263
277
|
}
|
|
264
278
|
|
package/src/pty/index.ts
CHANGED
|
@@ -34,6 +34,7 @@ export interface SpawnOptions {
|
|
|
34
34
|
env?: Record<string, unknown>;
|
|
35
35
|
interactive?: boolean;
|
|
36
36
|
requiresRoot?: boolean;
|
|
37
|
+
requiresSudoAskpass?: boolean;
|
|
37
38
|
stdin?: boolean;
|
|
38
39
|
disableWrapping?: boolean;
|
|
39
40
|
}
|
|
@@ -43,8 +44,11 @@ export class SpawnError extends Error {
|
|
|
43
44
|
cmd: string;
|
|
44
45
|
exitCode: number;
|
|
45
46
|
|
|
46
|
-
constructor(cmd: string, exitCode: number, data: string) {
|
|
47
|
-
|
|
47
|
+
constructor(cmd: string, exitCode: number, data: string, logs?: string[]) {
|
|
48
|
+
const logSection = logs?.length
|
|
49
|
+
? `\nLast logs:\n${logs.join('\n')}`
|
|
50
|
+
: '';
|
|
51
|
+
super(`Spawn Error: on command "${cmd}" with exit code: ${exitCode}\nOutput:\n${data}${logSection}`);
|
|
48
52
|
|
|
49
53
|
this.data = data;
|
|
50
54
|
this.cmd = cmd;
|
|
@@ -59,6 +63,8 @@ export interface IPty {
|
|
|
59
63
|
spawnSafe(cmd: string | string[], options?: SpawnOptions): Promise<SpawnResult>
|
|
60
64
|
|
|
61
65
|
kill(): Promise<{ exitCode: number, signal?: number | undefined }>
|
|
66
|
+
|
|
67
|
+
getLogs(): string[]
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
export function getPty(): IPty {
|
|
@@ -28,11 +28,26 @@ const validateSudoRequestResponse = ajv.compile(CommandRequestResponseDataSchema
|
|
|
28
28
|
* without a tty (or even a stdin) attached so interactive commands will not work.
|
|
29
29
|
*/
|
|
30
30
|
export class SequentialPty implements IPty {
|
|
31
|
+
private logBuffer: string[] = [];
|
|
32
|
+
private static readonly MAX_LOG_LINES = 30;
|
|
33
|
+
|
|
34
|
+
getLogs(): string[] {
|
|
35
|
+
return [...this.logBuffer];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private appendLog(data: string): void {
|
|
39
|
+
const lines = data.split('\n');
|
|
40
|
+
this.logBuffer.push(...lines);
|
|
41
|
+
if (this.logBuffer.length > SequentialPty.MAX_LOG_LINES) {
|
|
42
|
+
this.logBuffer = this.logBuffer.slice(-SequentialPty.MAX_LOG_LINES);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
31
46
|
async spawn(cmd: string | string[], options?: SpawnOptions): Promise<SpawnResult> {
|
|
32
47
|
const spawnResult = await this.spawnSafe(cmd, options);
|
|
33
48
|
|
|
34
49
|
if (spawnResult.status !== 'success') {
|
|
35
|
-
throw new SpawnError(Array.isArray(cmd) ? cmd.join('\n') : cmd, spawnResult.exitCode, spawnResult.data);
|
|
50
|
+
throw new SpawnError(Array.isArray(cmd) ? cmd.join('\n') : cmd, spawnResult.exitCode, spawnResult.data, this.logBuffer);
|
|
36
51
|
}
|
|
37
52
|
|
|
38
53
|
return spawnResult;
|
|
@@ -46,11 +61,13 @@ export class SequentialPty implements IPty {
|
|
|
46
61
|
}
|
|
47
62
|
|
|
48
63
|
// If sudo is required, we must delegate to the main codify process.
|
|
49
|
-
if (options?.stdin || options?.requiresRoot) {
|
|
64
|
+
if (options?.stdin || options?.requiresRoot || options?.requiresSudoAskpass) {
|
|
50
65
|
return this.externalSpawn(cmd, options);
|
|
51
66
|
}
|
|
52
67
|
|
|
53
|
-
|
|
68
|
+
const cmdLine = `Running command: ${Array.isArray(cmd) ? cmd.join('\\\n') : cmd}` + (options?.cwd ? `(${options?.cwd})` : '');
|
|
69
|
+
console.log(cmdLine);
|
|
70
|
+
this.appendLog(cmdLine);
|
|
54
71
|
|
|
55
72
|
return new Promise((resolve) => {
|
|
56
73
|
const output: string[] = [];
|
|
@@ -87,6 +104,7 @@ export class SequentialPty implements IPty {
|
|
|
87
104
|
}
|
|
88
105
|
|
|
89
106
|
output.push(data.toString());
|
|
107
|
+
this.appendLog(data.toString());
|
|
90
108
|
})
|
|
91
109
|
|
|
92
110
|
const resizeListener = () => {
|
|
@@ -76,7 +76,7 @@ export class ParsedResourceSettings<T extends StringIndexedObject> implements Re
|
|
|
76
76
|
if (ctx.path.length === 0) {
|
|
77
77
|
ctx.jsonSchema.title = settings.id;
|
|
78
78
|
ctx.jsonSchema.description = schema.description ?? settings.description ?? `${settings.id} resource. Can be used to manage ${settings.id}`;
|
|
79
|
-
ctx.jsonSchema.$comment = (schema.meta() as Record<string, string | undefined>)
|
|
79
|
+
ctx.jsonSchema.$comment = (schema.meta() as Record<string, string | undefined> | undefined)?.$comment;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
}) as JSONSchemaType<T>
|
package/src/utils/file-utils.ts
CHANGED
|
@@ -4,6 +4,8 @@ import path from 'node:path';
|
|
|
4
4
|
import { Readable } from 'node:stream';
|
|
5
5
|
import { finished } from 'node:stream/promises';
|
|
6
6
|
|
|
7
|
+
import { ApplyNotes } from '../common/apply-notes.js';
|
|
8
|
+
import { CodifyCliSender } from '../messages/sender.js';
|
|
7
9
|
import { Utils } from './index.js';
|
|
8
10
|
|
|
9
11
|
const SPACE_REGEX = /^\s*$/
|
|
@@ -33,6 +35,7 @@ export class FileUtils {
|
|
|
33
35
|
);
|
|
34
36
|
|
|
35
37
|
await fs.appendFile(Utils.getPrimaryShellRc(), lineToInsert)
|
|
38
|
+
await CodifyCliSender.sendApplyNote(ApplyNotes.sourceShellRc());
|
|
36
39
|
|
|
37
40
|
function addLeadingSpacer(line: string): string {
|
|
38
41
|
return line.startsWith('\n')
|
|
@@ -57,6 +60,7 @@ export class FileUtils {
|
|
|
57
60
|
${lines.join('\n')}`)
|
|
58
61
|
|
|
59
62
|
await fs.appendFile(shellRc, formattedLines)
|
|
63
|
+
await CodifyCliSender.sendApplyNote(ApplyNotes.sourceShellRc());
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
/**
|
|
@@ -77,10 +81,11 @@ ${lines.join('\n')}`)
|
|
|
77
81
|
|
|
78
82
|
if (prepend) {
|
|
79
83
|
await fs.appendFile(shellRc, `\nexport PATH=$PATH:${value};`, { encoding: 'utf8' });
|
|
80
|
-
|
|
84
|
+
} else {
|
|
85
|
+
await fs.appendFile(shellRc, `\nexport PATH=${value}:$PATH;`, { encoding: 'utf8' });
|
|
81
86
|
}
|
|
82
87
|
|
|
83
|
-
await
|
|
88
|
+
await CodifyCliSender.sendApplyNote(ApplyNotes.sourceShellRc());
|
|
84
89
|
}
|
|
85
90
|
|
|
86
91
|
static async removeFromFile(filePath: string, search: string): Promise<void> {
|
package/src/utils/functions.ts
CHANGED
|
@@ -10,10 +10,11 @@ export function splitUserConfig<T extends StringIndexedObject>(
|
|
|
10
10
|
...(config.name ? { name: config.name } : {}),
|
|
11
11
|
...(config.dependsOn ? { dependsOn: config.dependsOn } : {}),
|
|
12
12
|
...(config.os ? { os: config.os } : {}),
|
|
13
|
+
...(config.distro ? { distro: config.distro } : {})
|
|
13
14
|
};
|
|
14
15
|
|
|
15
16
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
-
const { type, name, dependsOn, os, ...parameters } = config;
|
|
17
|
+
const { type, name, dependsOn, os, distro, ...parameters } = config;
|
|
17
18
|
|
|
18
19
|
return {
|
|
19
20
|
parameters: parameters as T,
|
|
@@ -42,7 +43,7 @@ export function resolvePathWithVariables(pathWithVariables: string) {
|
|
|
42
43
|
export function addVariablesToPath(pathWithoutVariables: string) {
|
|
43
44
|
let result = pathWithoutVariables;
|
|
44
45
|
for (const [key, value] of Object.entries(process.env)) {
|
|
45
|
-
if (!value || !path.isAbsolute(value) || value === '/' || key === 'HOME' || key === 'PATH' || key === 'SHELL' || key === 'PWD') {
|
|
46
|
+
if (!value || !path.isAbsolute(value) || value === '/' || value === homeDirectory || key === 'HOME' || key === 'PATH' || key === 'SHELL' || key === 'PWD') {
|
|
46
47
|
continue;
|
|
47
48
|
}
|
|
48
49
|
|
package/src/utils/index.ts
CHANGED
|
@@ -225,7 +225,24 @@ Brew can be installed using Codify:
|
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
if (status === SpawnStatus.ERROR) {
|
|
228
|
-
|
|
228
|
+
// Attempt to fix broken dependencies then retry
|
|
229
|
+
const fixResult = await $.spawnSafe('apt-get install -f -y -o Dpkg::Use-Pty=0 -o Dpkg::Progress-Fancy=0', {
|
|
230
|
+
requiresRoot: true,
|
|
231
|
+
env: { DEBIAN_FRONTEND: 'noninteractive', NEEDRESTART_MODE: 'a' }
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
if (fixResult.status === SpawnStatus.ERROR) {
|
|
235
|
+
throw new Error(`Failed to install package ${packageName} via apt: ${data}`);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const retryResult = await $.spawnSafe(`apt-get -y -qq install -o Dpkg::Use-Pty=0 -o Dpkg::Progress-Fancy=0 ${packageName}`, {
|
|
239
|
+
requiresRoot: true,
|
|
240
|
+
env: { DEBIAN_FRONTEND: 'noninteractive', NEEDRESTART_MODE: 'a' }
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
if (retryResult.status === SpawnStatus.ERROR) {
|
|
244
|
+
throw new Error(`Failed to install package ${packageName} via apt after fixing dependencies: ${retryResult.data}`);
|
|
245
|
+
}
|
|
229
246
|
}
|
|
230
247
|
}
|
|
231
248
|
|
package/dist/bin/build.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function build(): Promise<void>;
|
package/dist/bin/build.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { Ajv } from 'ajv';
|
|
2
|
-
import { IpcMessageSchema, MessageStatus, ResourceSchema } from 'codify-schemas';
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import mergeJsonSchemas from 'merge-json-schemas';
|
|
5
|
-
import { fork } from 'node:child_process';
|
|
6
|
-
import fs from 'node:fs/promises';
|
|
7
|
-
import path from 'node:path';
|
|
8
|
-
import * as url from 'node:url';
|
|
9
|
-
import { codifySpawn } from '../utils/codify-spawn.js';
|
|
10
|
-
const ajv = new Ajv({
|
|
11
|
-
strict: true
|
|
12
|
-
});
|
|
13
|
-
const ipcMessageValidator = ajv.compile(IpcMessageSchema);
|
|
14
|
-
function sendMessageAndAwaitResponse(process, message) {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
process.on('message', (response) => {
|
|
17
|
-
if (!ipcMessageValidator(response)) {
|
|
18
|
-
throw new Error(`Invalid message from plugin. ${JSON.stringify(message, null, 2)}`);
|
|
19
|
-
}
|
|
20
|
-
// Wait for the message response. Other messages such as sudoRequest may be sent before the response returns
|
|
21
|
-
if (response.cmd === message.cmd + '_Response') {
|
|
22
|
-
if (response.status === MessageStatus.SUCCESS) {
|
|
23
|
-
resolve(response.data);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
reject(new Error(String(response.data)));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
// Send message last to ensure listeners are all registered
|
|
31
|
-
process.send(message);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
export async function build() {
|
|
35
|
-
await fs.rm('./dist', { force: true, recursive: true });
|
|
36
|
-
await codifySpawn('npm run rollup -- -f es');
|
|
37
|
-
const plugin = fork('./dist/index.js', [], {
|
|
38
|
-
// Use default true to test plugins in secure mode (un-able to request sudo directly)
|
|
39
|
-
detached: true,
|
|
40
|
-
env: { ...process.env },
|
|
41
|
-
execArgv: ['--import', 'tsx/esm'],
|
|
42
|
-
});
|
|
43
|
-
const initializeResult = await sendMessageAndAwaitResponse(plugin, {
|
|
44
|
-
cmd: 'initialize',
|
|
45
|
-
data: {}
|
|
46
|
-
});
|
|
47
|
-
const { resourceDefinitions } = initializeResult;
|
|
48
|
-
const resourceTypes = resourceDefinitions.map((i) => i.type);
|
|
49
|
-
const schemasMap = new Map();
|
|
50
|
-
for (const type of resourceTypes) {
|
|
51
|
-
const resourceInfo = await sendMessageAndAwaitResponse(plugin, {
|
|
52
|
-
cmd: 'getResourceInfo',
|
|
53
|
-
data: { type }
|
|
54
|
-
});
|
|
55
|
-
schemasMap.set(type, resourceInfo.schema);
|
|
56
|
-
}
|
|
57
|
-
const mergedSchemas = [...schemasMap.entries()].map(([type, schema]) => {
|
|
58
|
-
// const resolvedSchema = await $RefParser.dereference(schema)
|
|
59
|
-
const resourceSchema = JSON.parse(JSON.stringify(ResourceSchema));
|
|
60
|
-
delete resourceSchema.$id;
|
|
61
|
-
delete resourceSchema.$schema;
|
|
62
|
-
delete resourceSchema.title;
|
|
63
|
-
delete resourceSchema.oneOf;
|
|
64
|
-
delete resourceSchema.properties.type;
|
|
65
|
-
if (schema) {
|
|
66
|
-
delete schema.$id;
|
|
67
|
-
delete schema.$schema;
|
|
68
|
-
delete schema.title;
|
|
69
|
-
delete schema.oneOf;
|
|
70
|
-
}
|
|
71
|
-
return mergeJsonSchemas([schema ?? {}, resourceSchema, { properties: { type: { const: type, type: 'string' } } }]);
|
|
72
|
-
});
|
|
73
|
-
await fs.rm('./dist', { force: true, recursive: true });
|
|
74
|
-
await codifySpawn('npm run rollup'); // re-run rollup without building for es
|
|
75
|
-
console.log('Generated JSON Schemas for all resources');
|
|
76
|
-
const distFolder = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '..', 'dist');
|
|
77
|
-
const schemaOutputPath = path.resolve(distFolder, 'schemas.json');
|
|
78
|
-
await fs.writeFile(schemaOutputPath, JSON.stringify(mergedSchemas, null, 2));
|
|
79
|
-
console.log('Successfully wrote schema to ./dist/schemas.json');
|
|
80
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import * as fs from 'node:fs';
|
|
4
|
-
import { build } from './build.js';
|
|
5
|
-
const packageJson = fs.readFileSync(path.join(process.env['npm_config_local_prefix'], 'package.json'), 'utf8');
|
|
6
|
-
const { name: libraryName, version: libraryVersion } = JSON.parse(packageJson);
|
|
7
|
-
console.log(libraryName, libraryVersion);
|
|
8
|
-
await build();
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ParameterOperation, ResourceOperation, StringIndexedObject } from 'codify-schemas';
|
|
2
|
-
import { ParameterOptions } from './plan-types.js';
|
|
3
|
-
export interface ParameterChange<T extends StringIndexedObject> {
|
|
4
|
-
name: keyof T & string;
|
|
5
|
-
operation: ParameterOperation;
|
|
6
|
-
previousValue: any | null;
|
|
7
|
-
newValue: any | null;
|
|
8
|
-
}
|
|
9
|
-
export declare class ChangeSet<T extends StringIndexedObject> {
|
|
10
|
-
operation: ResourceOperation;
|
|
11
|
-
parameterChanges: Array<ParameterChange<T>>;
|
|
12
|
-
constructor(operation: ResourceOperation, parameterChanges: Array<ParameterChange<T>>);
|
|
13
|
-
get desiredParameters(): T;
|
|
14
|
-
get currentParameters(): T;
|
|
15
|
-
static calculateParameterChangeSet<T extends StringIndexedObject>(desired: T | null, current: T | null, options: {
|
|
16
|
-
statefulMode: boolean;
|
|
17
|
-
parameterOptions?: Record<keyof T, ParameterOptions>;
|
|
18
|
-
}): ParameterChange<T>[];
|
|
19
|
-
static combineResourceOperations(prev: ResourceOperation, next: ResourceOperation): ResourceOperation;
|
|
20
|
-
static isSame(desired: unknown, current: unknown, options?: ParameterOptions): boolean;
|
|
21
|
-
private static calculateStatefulModeChangeSet;
|
|
22
|
-
private static calculateStatelessModeChangeSet;
|
|
23
|
-
private static addDefaultValues;
|
|
24
|
-
}
|