Skip to content

Commit 03b3fa4

Browse files
committed
fix: Fix array transformation using resolve equals fn instead it should be using elementEqualsFn
1 parent dacf48d commit 03b3fa4

File tree

4 files changed

+107
-5
lines changed

4 files changed

+107
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codify-plugin-lib",
3-
"version": "1.0.163",
3+
"version": "1.0.165",
44
"description": "Library plugin library",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",

src/resource/resource-controller.test.ts

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { TestConfig, testPlan, TestResource, TestStatefulParameter } from '../ut
1010
import { tildify, untildify } from '../utils/utils.js';
1111
import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
1212
import { Plan } from '../plan/plan.js';
13+
import os from 'node:os';
1314

1415
describe('Resource tests', () => {
1516

@@ -828,6 +829,107 @@ describe('Resource tests', () => {
828829
}
829830

830831
const controller = new ResourceController(resource);
831-
const plan = await controller.import({ type: 'path' }, {});
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;
832934
})
833935
});

src/resource/resource-settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ export function resolveParameterTransformFn(
438438
from(input: unknown[], original) {
439439
return input.map((i, idx) => {
440440
const originalElement = Array.isArray(original)
441-
? original.find((o) => resolveEqualsFn(parameter)(o, i)) ?? original[idx]
441+
? original.find((o) => resolveElementEqualsFn(parameter as ArrayParameterSetting)(o, i)) ?? original[idx]
442442
: original;
443443

444444
return itemTransformation.from(i, originalElement);

src/utils/utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ describe('Utils tests', () => {
4141
expect(result2).to.eq('/var' + home + '/my/path');
4242
})
4343

44-
it('Can add variables to a path', () => {
44+
it('Can add variables to a path (ignores home)', () => {
4545
const testPath1 = os.homedir() + '/my/path';
4646
const result1 = addVariablesToPath(testPath1);
4747

4848
const home = os.homedir();
49-
expect(result1).to.eq('$HOME/my/path');
49+
expect(result1).to.eq(home + '/my/path');
5050
})
5151
})

0 commit comments

Comments
 (0)