codify-plugin-lib 1.0.163 → 1.0.165
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/resource/resource-settings.js +13 -3
- package/package.json +1 -1
- package/src/resource/resource-controller.test.ts +103 -1
- package/src/resource/resource-controller.ts +3 -1
- package/src/resource/resource-settings.test.ts +26 -0
- package/src/resource/resource-settings.ts +16 -3
- package/src/utils/utils.test.ts +2 -2
|
@@ -4,9 +4,19 @@ import { addVariablesToPath, areArraysEqual, resolvePathWithVariables, tildify,
|
|
|
4
4
|
const ParameterEqualsDefaults = {
|
|
5
5
|
'boolean': (a, b) => Boolean(a) === Boolean(b),
|
|
6
6
|
'directory': (a, b) => {
|
|
7
|
+
let transformedA = resolvePathWithVariables(untildify(String(a)));
|
|
8
|
+
let transformedB = resolvePathWithVariables(untildify(String(b)));
|
|
9
|
+
if (transformedA.startsWith('.')) { // Only relative paths start with '.'
|
|
10
|
+
transformedA = path.resolve(transformedA);
|
|
11
|
+
}
|
|
12
|
+
if (transformedB.startsWith('.')) { // Only relative paths start with '.'
|
|
13
|
+
transformedB = path.resolve(transformedB);
|
|
14
|
+
}
|
|
7
15
|
const notCaseSensitive = process.platform === 'darwin';
|
|
8
|
-
|
|
9
|
-
|
|
16
|
+
if (notCaseSensitive) {
|
|
17
|
+
transformedA = transformedA.toLowerCase();
|
|
18
|
+
transformedB = transformedB.toLowerCase();
|
|
19
|
+
}
|
|
10
20
|
return transformedA === transformedB;
|
|
11
21
|
},
|
|
12
22
|
'number': (a, b) => Number(a) === Number(b),
|
|
@@ -91,7 +101,7 @@ export function resolveParameterTransformFn(parameter) {
|
|
|
91
101
|
from(input, original) {
|
|
92
102
|
return input.map((i, idx) => {
|
|
93
103
|
const originalElement = Array.isArray(original)
|
|
94
|
-
? original.find((o) =>
|
|
104
|
+
? original.find((o) => resolveElementEqualsFn(parameter)(o, i)) ?? original[idx]
|
|
95
105
|
: original;
|
|
96
106
|
return itemTransformation.from(i, originalElement);
|
|
97
107
|
});
|
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@ import { TestConfig, testPlan, TestResource, TestStatefulParameter } from '../ut
|
|
|
10
10
|
import { tildify, untildify } from '../utils/utils.js';
|
|
11
11
|
import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
|
|
12
12
|
import { Plan } from '../plan/plan.js';
|
|
13
|
+
import os from 'node:os';
|
|
13
14
|
|
|
14
15
|
describe('Resource tests', () => {
|
|
15
16
|
|
|
@@ -828,6 +829,107 @@ describe('Resource tests', () => {
|
|
|
828
829
|
}
|
|
829
830
|
|
|
830
831
|
const controller = new ResourceController(resource);
|
|
831
|
-
|
|
832
|
+
await controller.import({ type: 'path' }, {});
|
|
833
|
+
;
|
|
834
|
+
})
|
|
835
|
+
|
|
836
|
+
it('Can import and return all of the imported parameters', async () => {
|
|
837
|
+
const resource = new class extends TestResource {
|
|
838
|
+
getSettings(): ResourceSettings<any> {
|
|
839
|
+
return {
|
|
840
|
+
id: 'path',
|
|
841
|
+
parameterSettings: {
|
|
842
|
+
path: { type: 'directory' },
|
|
843
|
+
paths: { canModify: true, type: 'array', itemType: 'directory' },
|
|
844
|
+
prepend: { default: false, setting: true },
|
|
845
|
+
declarationsOnly: { default: false, setting: true },
|
|
846
|
+
},
|
|
847
|
+
importAndDestroy: {
|
|
848
|
+
refreshMapper: (input, context) => {
|
|
849
|
+
if (Object.keys(input).length === 0) {
|
|
850
|
+
return { paths: [], declarationsOnly: true };
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
return input;
|
|
854
|
+
}
|
|
855
|
+
},
|
|
856
|
+
allowMultiple: {
|
|
857
|
+
matcher: (desired, current) => {
|
|
858
|
+
if (desired.path) {
|
|
859
|
+
return desired.path === current.path;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
const currentPaths = new Set(current.paths)
|
|
863
|
+
return desired.paths?.some((p) => currentPaths.has(p));
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
async refresh(parameters: Partial<TestConfig>): Promise<Partial<TestConfig> | null> {
|
|
870
|
+
return {
|
|
871
|
+
paths: [
|
|
872
|
+
`${os.homedir()}/.pyenv/bin`,
|
|
873
|
+
`${os.homedir()}/.bun/bin`,
|
|
874
|
+
`${os.homedir()}/.deno/bin`,
|
|
875
|
+
`${os.homedir()}/.jenv/bin`,
|
|
876
|
+
`${os.homedir()}/a/random/path`,
|
|
877
|
+
`${os.homedir()}/.nvm/.bin/2`,
|
|
878
|
+
`${os.homedir()}/.nvm/.bin/3`
|
|
879
|
+
]
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
const oldProcessEnv = structuredClone(process.env);
|
|
885
|
+
|
|
886
|
+
process.env['PYENV_ROOT'] = `${os.homedir()}/.pyenv`
|
|
887
|
+
process.env['BUN_INSTALL'] = `${os.homedir()}/.bun`
|
|
888
|
+
process.env['DENO_INSTALL'] = `${os.homedir()}/.deno`
|
|
889
|
+
process.env['JENV'] = `${os.homedir()}/.jenv`
|
|
890
|
+
process.env['NVM_DIR'] = `${os.homedir()}/.nvm`
|
|
891
|
+
|
|
892
|
+
const controller = new ResourceController(resource);
|
|
893
|
+
const importResult1 = await controller.import({ type: 'path' }, {});
|
|
894
|
+
expect(importResult1).toMatchObject([
|
|
895
|
+
{
|
|
896
|
+
'core': {
|
|
897
|
+
'type': 'path'
|
|
898
|
+
},
|
|
899
|
+
'parameters': {
|
|
900
|
+
'paths': [
|
|
901
|
+
'$PYENV_ROOT/bin',
|
|
902
|
+
'$BUN_INSTALL/bin',
|
|
903
|
+
'$DENO_INSTALL/bin',
|
|
904
|
+
'$JENV/bin',
|
|
905
|
+
'~/a/random/path',
|
|
906
|
+
'$NVM_DIR/.bin/2',
|
|
907
|
+
'$NVM_DIR/.bin/3'
|
|
908
|
+
]
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
])
|
|
912
|
+
|
|
913
|
+
const importResult2 = await controller.import({ type: 'path' }, { paths: ['$PYENV_ROOT/bin', '$BUN_INSTALL/bin'] });
|
|
914
|
+
expect(importResult2).toMatchObject([
|
|
915
|
+
{
|
|
916
|
+
'core': {
|
|
917
|
+
'type': 'path'
|
|
918
|
+
},
|
|
919
|
+
'parameters': {
|
|
920
|
+
'paths': [
|
|
921
|
+
'$PYENV_ROOT/bin',
|
|
922
|
+
'$BUN_INSTALL/bin',
|
|
923
|
+
'$DENO_INSTALL/bin',
|
|
924
|
+
'$JENV/bin',
|
|
925
|
+
'~/a/random/path',
|
|
926
|
+
'$NVM_DIR/.bin/2',
|
|
927
|
+
'$NVM_DIR/.bin/3'
|
|
928
|
+
]
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
])
|
|
932
|
+
|
|
933
|
+
process.env = oldProcessEnv;
|
|
832
934
|
})
|
|
833
935
|
});
|
|
@@ -381,7 +381,9 @@ ${JSON.stringify(refresh, null, 2)}
|
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
-
private async applyTransformParameters(config: Partial<T> | null, reverse?: {
|
|
384
|
+
private async applyTransformParameters(config: Partial<T> | null, reverse?: {
|
|
385
|
+
original: Partial<T> | null
|
|
386
|
+
}): Promise<void> {
|
|
385
387
|
if (!config) {
|
|
386
388
|
return;
|
|
387
389
|
}
|
|
@@ -1119,4 +1119,30 @@ describe('Resource parameter tests', () => {
|
|
|
1119
1119
|
propB: 'random2',
|
|
1120
1120
|
})).to.be.false;
|
|
1121
1121
|
})
|
|
1122
|
+
|
|
1123
|
+
it('Can match directories 1', async () => {
|
|
1124
|
+
const resource = new class extends TestResource {
|
|
1125
|
+
getSettings(): ResourceSettings<TestConfig> {
|
|
1126
|
+
return {
|
|
1127
|
+
id: 'resourceType',
|
|
1128
|
+
parameterSettings: {
|
|
1129
|
+
propA: { type: 'directory' }
|
|
1130
|
+
},
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
};
|
|
1134
|
+
|
|
1135
|
+
const controller = new ResourceController(resource);
|
|
1136
|
+
const transformations = controller.parsedSettings.inputTransformations.propA;
|
|
1137
|
+
|
|
1138
|
+
const to = transformations!.to('$HOME/abc/def')
|
|
1139
|
+
expect(to).to.eq(os.homedir() + '/abc/def')
|
|
1140
|
+
|
|
1141
|
+
const from = transformations!.from(os.homedir() + '/abc/def')
|
|
1142
|
+
expect(from).to.eq('~/abc/def')
|
|
1143
|
+
|
|
1144
|
+
const from2 = transformations!.from(os.homedir() + '/abc/def', '$HOME/abc/def')
|
|
1145
|
+
expect(from2).to.eq('$HOME/abc/def')
|
|
1146
|
+
|
|
1147
|
+
})
|
|
1122
1148
|
})
|
|
@@ -313,9 +313,22 @@ export interface StatefulParameterSetting extends DefaultParameterSetting {
|
|
|
313
313
|
const ParameterEqualsDefaults: Partial<Record<ParameterSettingType, (a: unknown, b: unknown) => boolean>> = {
|
|
314
314
|
'boolean': (a: unknown, b: unknown) => Boolean(a) === Boolean(b),
|
|
315
315
|
'directory': (a: unknown, b: unknown) => {
|
|
316
|
+
let transformedA = resolvePathWithVariables(untildify(String(a)))
|
|
317
|
+
let transformedB = resolvePathWithVariables(untildify(String(b)))
|
|
318
|
+
|
|
319
|
+
if (transformedA.startsWith('.')) { // Only relative paths start with '.'
|
|
320
|
+
transformedA = path.resolve(transformedA)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (transformedB.startsWith('.')) { // Only relative paths start with '.'
|
|
324
|
+
transformedB = path.resolve(transformedB)
|
|
325
|
+
}
|
|
326
|
+
|
|
316
327
|
const notCaseSensitive = process.platform === 'darwin';
|
|
317
|
-
|
|
318
|
-
|
|
328
|
+
if (notCaseSensitive) {
|
|
329
|
+
transformedA = transformedA.toLowerCase();
|
|
330
|
+
transformedB = transformedB.toLowerCase();
|
|
331
|
+
}
|
|
319
332
|
|
|
320
333
|
return transformedA === transformedB;
|
|
321
334
|
},
|
|
@@ -425,7 +438,7 @@ export function resolveParameterTransformFn(
|
|
|
425
438
|
from(input: unknown[], original) {
|
|
426
439
|
return input.map((i, idx) => {
|
|
427
440
|
const originalElement = Array.isArray(original)
|
|
428
|
-
? original.find((o) =>
|
|
441
|
+
? original.find((o) => resolveElementEqualsFn(parameter as ArrayParameterSetting)(o, i)) ?? original[idx]
|
|
429
442
|
: original;
|
|
430
443
|
|
|
431
444
|
return itemTransformation.from(i, originalElement);
|
package/src/utils/utils.test.ts
CHANGED
|
@@ -41,11 +41,11 @@ describe('Utils tests', () => {
|
|
|
41
41
|
expect(result2).to.eq('/var' + home + '/my/path');
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
it('Can add variables to a path', () => {
|
|
44
|
+
it('Can add variables to a path (ignores home)', () => {
|
|
45
45
|
const testPath1 = os.homedir() + '/my/path';
|
|
46
46
|
const result1 = addVariablesToPath(testPath1);
|
|
47
47
|
|
|
48
48
|
const home = os.homedir();
|
|
49
|
-
expect(result1).to.eq('
|
|
49
|
+
expect(result1).to.eq(home + '/my/path');
|
|
50
50
|
})
|
|
51
51
|
})
|