diff --git a/distribution/src/pkgbase.js b/distribution/src/pkgbase.js index ae1254e..78736cc 100644 --- a/distribution/src/pkgbase.js +++ b/distribution/src/pkgbase.js @@ -12,20 +12,30 @@ async function parse(previous, current) { }; if (isDelete(actions)) { const repo = prev.repos[actions.removeRepo]; - result.delete.push(...repo.packages.map(p => `${actions.removeRepo}/${p.split(`-${repo.version}`)[0]}`)); + result.delete.push(...parseRepoContents(repo, actions.removeRepo)); } - else if (result.move = isMove(actions)) { - result.delete.push(...getDropped(prev.repos[actions.addRepo], curr.repos[actions.removeRepo])); + else if (prev && (result.move = isMove(actions))) { + const moving = parseRepoContents(curr.repos[actions.addRepo], actions.removeRepo); + result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), moving)); + result.delete.push(...moving); } - else if (result.build = isAdd(actions)) { - result.delete.push(...getDropped(prev.repos[actions.addRepo], curr.repos[actions.addRepo])); + else if ((result.build = isAdd(actions)) && prev) { + result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), parseRepoContents(curr.repos[actions.addRepo], actions.addRepo))); } return result; } -function getDropped(oldRepoContents, newRepoContents) { - const oldPackages = oldRepoContents.packages.map(p => p.split(`-${oldRepoContents.version}`)[0]); - const newPackages = newRepoContents.packages.map(p => p.split(`-${newRepoContents.version}`)[0]); - return oldPackages.filter(p => newPackages.indexOf(p) === -1); +function parseRepoContents(repoContents, repository) { + return repoContents.packages.map(p => { + return { + version: repoContents.version, + repository, + package: p.split(`-${repoContents.version}`)[0], + architecture: p.split(`${repoContents.version}-`)[1].split('.')[0] + }; + }); +} +function getDropped(oldPackages, newPackages) { + return oldPackages.filter(p => newPackages.filter(np => np.package === p.package).length === 0); } function isDelete(actions) { return !!(actions.removeRepo && actions.addRepo === null); diff --git a/distribution/src/pkgbase.js.map b/distribution/src/pkgbase.js.map index 5de9f80..64cc153 100644 --- a/distribution/src/pkgbase.js.map +++ b/distribution/src/pkgbase.js.map @@ -1 +1 @@ -{"version":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AC,QAAQ,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QACjE,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IACD,MAAM,CAAC;QACH,OAAO,IAAI,CAAC;IAChB,CAAC;AACL,CAAC;AAED,OAAO,EAAE,KAAK,EAAE,CAAC","sourcesContent":["import { type PathLike } from 'fs';\nimport fsp from 'fs/promises';\nimport * as YAML from 'yaml';\n\ninterface Actions {\n addRepo: string | null;\n removeRepo: string | null;\n triggersBuild: boolean;\n triggersRebuild: boolean;\n triggersRepoAdd: boolean;\n triggersRepoRemove: boolean;\n triggersNoCheck: boolean;\n}\n\ninterface Result {\n build: boolean;\n move: boolean;\n delete: string[];\n actions: Actions;\n}\n\ninterface RepoContents {\n version: string | null;\n packages: string[];\n debug: string[];\n}\n\ninterface PkgBase {\n actions: Actions;\n team: string;\n repos: {\n \"system-goblins\": RepoContents;\n \"system-gremlins\": RepoContents;\n \"system\": RepoContents;\n \"world-goblins\": RepoContents;\n \"world-gremlins\": RepoContents;\n \"world\": RepoContents;\n \"lib32-goblins\": RepoContents;\n \"lib32-gremlins\": RepoContents;\n \"lib32\": RepoContents;\n \"galaxy-goblins\": RepoContents;\n \"galaxy-gremlins\": RepoContents;\n \"galaxy\": RepoContents;\n }\n}\n\nasync function parse(previous: PathLike, current: PathLike): Promise {\n const prev = await tryRead(previous);\n const curr = await tryRead(current);\n const actions = curr?.actions;\n const result: Result = {\n build: false,\n move: false,\n delete: [],\n actions,\n };\n\n if (isDelete(actions)) {\n const repo: RepoContents = prev.repos[actions.removeRepo];\n result.delete.push(...repo.packages.map(p => `${actions.removeRepo}/${p.split(`-${repo.version}`)[0]}`));\n }\n else if (result.move = isMove(actions)) {\n result.delete.push(...getDropped(prev.repos[actions.addRepo], curr.repos[actions.removeRepo]));\n }\n else if (result.build = isAdd(actions)) {\n result.delete.push(...getDropped(prev.repos[actions.addRepo], curr.repos[actions.addRepo]));\n }\n\n return result;\n}\n\nfunction getDropped(oldRepoContents: RepoContents, newRepoContents: RepoContents): string[] {\n const oldPackages = oldRepoContents.packages.map(p => p.split(`-${oldRepoContents.version}`)[0]);\n const newPackages = newRepoContents.packages.map(p => p.split(`-${newRepoContents.version}`)[0]);\n return oldPackages.filter(p => newPackages.indexOf(p) === -1);\n}\n\nfunction isDelete(actions: Actions): boolean {\n return !!(actions.removeRepo && actions.addRepo === null);\n}\n\nfunction isAdd(actions: Actions): boolean {\n return !!(actions.addRepo && actions.removeRepo === null);\n}\n\nfunction isMove(actions: Actions): boolean {\n return !!(actions.removeRepo && actions.addRepo);\n}\n\nasync function tryRead(file: PathLike): Promise {\n try {\n const contents = await fsp.readFile(file, { encoding: 'utf-8' });\n return YAML.parse(contents);\n }\n catch {\n return null;\n }\n}\n\nexport { parse };\nexport type { Actions, Result, RepoContents, PkgBase };\n"]} \ No newline at end of file +{"version":3,"file":"pkgbase.js","sourceRoot":"","sources":["../../src/pkgbase.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,aAAa,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAmD7B,KAAK,UAAU,KAAK,CAAC,QAAkB,EAAE,OAAiB;IACtD,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrC,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,OAAO,GAAG,IAAI,EAAE,OAAO,CAAC;IAC9B,MAAM,MAAM,GAAW;QACnB,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,KAAK;QACX,MAAM,EAAE,EAAE;QACV,OAAO;KACV,CAAC;IAEF,IAAI,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,GAAiB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC1D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GA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\nimport * as YAML from 'yaml';\n\ninterface PackageInfo {\n package: string;\n repository: string;\n version: string;\n architecture: string;\n}\n\ninterface Actions {\n addRepo: string | null;\n removeRepo: string | null;\n triggersBuild: boolean;\n triggersRebuild: boolean;\n triggersRepoAdd: boolean;\n triggersRepoRemove: boolean;\n triggersNoCheck: boolean;\n}\n\ninterface Result {\n build: boolean;\n move: boolean;\n delete: PackageInfo[];\n actions: Actions;\n}\n\ninterface RepoContents {\n version: string | null;\n packages: string[];\n debug: string[];\n}\n\ninterface PkgBase {\n actions: Actions;\n team: string;\n repos: {\n \"system-goblins\": RepoContents;\n \"system-gremlins\": RepoContents;\n \"system\": RepoContents;\n \"world-goblins\": RepoContents;\n \"world-gremlins\": RepoContents;\n \"world\": RepoContents;\n \"lib32-goblins\": RepoContents;\n \"lib32-gremlins\": RepoContents;\n \"lib32\": RepoContents;\n \"galaxy-goblins\": RepoContents;\n \"galaxy-gremlins\": RepoContents;\n \"galaxy\": RepoContents;\n }\n}\n\nasync function parse(previous: PathLike, current: PathLike): Promise {\n const prev = await tryRead(previous);\n const curr = await tryRead(current);\n const actions = curr?.actions;\n const result: Result = {\n build: false,\n move: false,\n delete: [],\n actions,\n };\n\n if (isDelete(actions)) {\n const repo: RepoContents = prev.repos[actions.removeRepo];\n result.delete.push(...parseRepoContents(repo, actions.removeRepo));\n }\n else if (prev && (result.move = isMove(actions))) {\n const moving = parseRepoContents(curr.repos[actions.addRepo], actions.removeRepo);\n result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), moving));\n result.delete.push(...moving);\n }\n else if ((result.build = isAdd(actions)) && prev) {\n result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), parseRepoContents(curr.repos[actions.addRepo], actions.addRepo)));\n }\n\n return result;\n}\n\nfunction parseRepoContents(repoContents: RepoContents, repository: string): PackageInfo[] {\n return repoContents.packages.map(p => {\n return {\n version: repoContents.version,\n repository,\n package: p.split(`-${repoContents.version}`)[0],\n architecture: p.split(`${repoContents.version}-`)[1].split('.')[0]\n }\n });\n}\n\nfunction getDropped(oldPackages: PackageInfo[], newPackages: PackageInfo[]): PackageInfo[] {\n return oldPackages.filter(p => newPackages.filter(np => np.package === p.package).length === 0);\n}\n\nfunction isDelete(actions: Actions): boolean {\n return !!(actions.removeRepo && actions.addRepo === null);\n}\n\nfunction isAdd(actions: Actions): boolean {\n return !!(actions.addRepo && actions.removeRepo === null);\n}\n\nfunction isMove(actions: Actions): boolean {\n return !!(actions.removeRepo && actions.addRepo);\n}\n\nasync function tryRead(file: PathLike): Promise {\n try {\n const contents = await fsp.readFile(file, { encoding: 'utf-8' });\n return YAML.parse(contents);\n }\n catch {\n return null;\n }\n}\n\nexport { parse };\nexport type { Actions, Result, RepoContents, PkgBase, PackageInfo };\n"]} \ No newline at end of file diff --git a/distribution/test/pkgbase.test.js b/distribution/test/pkgbase.test.js index 9e6cb7d..4bc82a6 100644 --- a/distribution/test/pkgbase.test.js +++ b/distribution/test/pkgbase.test.js @@ -24,7 +24,14 @@ describe('pkgbase parser', () => { const expected = { build: true, move: false, - delete: ['pidgin'], + delete: [ + { + architecture: "x86_64", + package: "pidgin", + repository: "world", + version: "2.14.14-3", + } + ], actions: { addRepo: 'world', removeRepo: null, @@ -42,7 +49,12 @@ describe('pkgbase parser', () => { const expected = { build: false, move: true, - delete: ['opencascade'], + delete: [{ + architecture: "x86_64", + package: "opencascade", + repository: "world-gremlins", + version: "1:7.9.2-1", + }], actions: { addRepo: 'world', removeRepo: 'world-gremlins', @@ -60,7 +72,26 @@ describe('pkgbase parser', () => { const expected = { build: false, move: true, - delete: ['pidgin', 'libpurple', 'finch'], + delete: [ + { + architecture: "x86_64", + package: "pidgin", + repository: "world", + version: "2.14.14-3", + }, + { + architecture: "x86_64", + package: "libpurple", + repository: "world-gremlins", + version: "2.14.14-4", + }, + { + architecture: "x86_64", + package: "finch", + repository: "world-gremlins", + version: "2.14.14-4", + } + ], actions: { addRepo: 'world', removeRepo: 'world-gremlins', @@ -78,7 +109,26 @@ describe('pkgbase parser', () => { const expected = { build: false, move: false, - delete: ['world/python-nntplib', 'world/python-cgi', 'world/python-mailcap'], + delete: [ + { + architecture: "any", + package: "python-nntplib", + repository: "world", + version: "3.13.0-2", + }, + { + architecture: "any", + package: "python-cgi", + repository: "world", + version: "3.13.0-2", + }, + { + architecture: "any", + package: "python-mailcap", + repository: "world", + version: "3.13.0-2", + } + ], actions: { addRepo: null, removeRepo: 'world', diff --git a/distribution/test/pkgbase.test.js.map b/distribution/test/pkgbase.test.js.map index 54da200..19bee86 100644 --- a/distribution/test/pkgbase.test.js.map +++ b/distribution/test/pkgbase.test.js.map @@ -1 +1 @@ -{"version":3,"file":"pkgbase.test.js","sourceRoot":"","sources":["../../test/pkgbase.test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAe,MAAM,mBAAmB,CAAC;AAEvD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,6BAA6B,EAAE,KAAK,IAAI,EAAE;QACzC,MAAM,QAAQ,GAAW;YACrB,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,KAAK;YACX,MAAM,EAAE,EAAE;YACV,OAAO,EAAE;gBACL,OAAO,EAAE,gBAAgB;gBACzB,UAAU,EAAE,IAAI;gBAChB,aAAa,EAAE,KAAK;gBACpB,eAAe,EAAE,IAAI;gBACrB,eAAe,EAAE,IAAI;gBACrB,kBAAkB,EAAE,KAAK;gBACzB,eAAe,EAAE,KAAK;aACzB;SACJ,CAAC;QACF,MAAM,IAAI,GAAG,WAAW,CAAC;QACzB,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,kBAAkB,CAAC,EAAE,IAA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E;gBACL,OAAO,EAAE,IAAI;gBACb,UAAU,EAAE,OAAO;gBACnB,aAAa,EAAE,KAAK;gBACpB,eAAe,EAAE,KAAK;gBACtB,eAAe,EAAE,KAAK;gBACtB,kBAAkB,EAAE,IAAI;gBACxB,eAAe,EAAE,KAAK;aACzB;SACJ,CAAC;QACF,MAAM,IAAI,GAAG,QAAQ,CAAC;QACtB,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,kBAAkB,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvK,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import path from 'path';\nimport { describe, expect, it } from 'vitest';\nimport { parse, type Result } from '../src/pkgbase.js';\n\ndescribe('pkgbase parser', () => {\n it('can detect an add operation', async () => {\n const expected: Result = {\n build: true,\n move: false,\n delete: [],\n actions: {\n addRepo: 'system-goblins',\n removeRepo: null,\n triggersBuild: false,\n triggersRebuild: true,\n triggersRepoAdd: true,\n triggersRepoRemove: false,\n triggersNoCheck: false\n }\n };\n const rDir = 'add-clean';\n await expect(parse(path.join('test', 'resources', rDir, 'pkgbase.old.yaml'), path.join('test', 'resources', rDir, 'pkgbase.new.yaml'))).resolves.toEqual(expected);\n });\n\n it('can remove dangling packages in an add operation', async () => {\n const expected: Result = {\n build: true,\n move: false,\n delete: ['pidgin'],\n actions: {\n addRepo: 'world',\n removeRepo: null,\n triggersBuild: true,\n triggersRebuild: false,\n triggersRepoAdd: true,\n triggersRepoRemove: false,\n triggersNoCheck: false\n }\n };\n const rDir = 'add-with-dropped';\n await expect(parse(path.join('test', 'resources', rDir, 'pkgbase.old.yaml'), path.join('test', 'resources', rDir, 'pkgbase.new.yaml'))).resolves.toEqual(expected);\n });\n\n it('can detect a move operation', async () => {\n const expected: Result = {\n build: false,\n move: true,\n delete: ['opencascade'],\n actions: {\n addRepo: 'world',\n removeRepo: 'world-gremlins',\n triggersBuild: false,\n triggersRebuild: false,\n triggersRepoAdd: true,\n triggersRepoRemove: true,\n triggersNoCheck: false\n }\n };\n const rDir = 'move-clean';\n await expect(parse(path.join('test', 'resources', rDir, 'pkgbase.old.yaml'), path.join('test', 'resources', rDir, 'pkgbase.new.yaml'))).resolves.toEqual(expected);\n });\n\n it('can remove dangling packages in a move operation', async () => {\n const expected: Result = {\n build: false,\n move: true,\n delete: ['pidgin', 'libpurple', 'finch'],\n actions: {\n addRepo: 'world',\n removeRepo: 'world-gremlins',\n triggersBuild: false,\n triggersRebuild: false,\n triggersRepoAdd: true,\n triggersRepoRemove: true,\n triggersNoCheck: false\n }\n };\n const rDir = 'move-with-dropped';\n await expect(parse(path.join('test', 'resources', rDir, 'pkgbase.old.yaml'), path.join('test', 'resources', rDir, 'pkgbase.new.yaml'))).resolves.toEqual(expected);\n });\n\n it('can detect a delete operation', async () => {\n const expected: Result = {\n build: false,\n move: false,\n delete: ['world/python-nntplib', 'world/python-cgi', 'world/python-mailcap'],\n actions: {\n addRepo: null,\n removeRepo: 'world',\n triggersBuild: false,\n triggersRebuild: false,\n triggersRepoAdd: false,\n triggersRepoRemove: true,\n triggersNoCheck: false\n }\n };\n const rDir = 'remove';\n await expect(parse(path.join('test', 'resources', rDir, 'pkgbase.old.yaml'), path.join('test', 'resources', rDir, 'pkgbase.new.yaml'))).resolves.toEqual(expected);\n });\n});"]} \ No newline at end of file +{"version":3,"file":"pkgbase.test.js","sourceRoot":"","sources":["../../test/pkgbase.test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAe,MAAM,mBAAmB,CAAC;AAEvD,QAA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BACtB;gBACD;oBACI,YAAY,EAAE,KAAK;oBACnB,OAAO,EAAE,gBAAgB;oBACzB,UAAU,EAAE,OAAO;oBACnB,OAAO,EAAE,UAAU;iBACtB;aACJ;YACD,OAAO,EAAE;gBACL,OAAO,EAAE,IAAI;gBACb,UAAU,EAAE,OAAO;gBACnB,aAAa,EAAE,KAAK;gBACpB,eAAe,EAAE,KAAK;gBACtB,eAAe,EAAE,KAAK;gBACtB,kBAAkB,EAAE,IAAI;gBACxB,eAAe,EAAE,KAAK;aACzB;SACJ,CAAC;QACF,MAAM,IAAI,GAAG,QAAQ,CAAC;QACtB,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,kBAAkB,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvK,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import path from 'path';\nimport { describe, expect, it } from 'vitest';\nimport { parse, type Result } from '../src/pkgbase.js';\n\ndescribe('pkgbase parser', () => {\n it('can detect an add operation', async () => {\n const expected: Result = {\n build: true,\n move: false,\n delete: [],\n actions: {\n addRepo: 'system-goblins',\n removeRepo: null,\n triggersBuild: false,\n triggersRebuild: true,\n triggersRepoAdd: true,\n triggersRepoRemove: false,\n triggersNoCheck: false\n }\n };\n const rDir = 'add-clean';\n await expect(parse(path.join('test', 'resources', rDir, 'pkgbase.old.yaml'), path.join('test', 'resources', rDir, 'pkgbase.new.yaml'))).resolves.toEqual(expected);\n });\n\n it('can remove dangling packages in an add operation', async () => {\n const expected: Result = {\n build: true,\n move: false,\n delete: [\n {\n architecture: \"x86_64\",\n package: \"pidgin\",\n repository: \"world\",\n version: \"2.14.14-3\",\n }\n ],\n actions: {\n addRepo: 'world',\n removeRepo: null,\n triggersBuild: true,\n triggersRebuild: false,\n triggersRepoAdd: true,\n triggersRepoRemove: false,\n triggersNoCheck: false\n }\n };\n const rDir = 'add-with-dropped';\n await expect(parse(path.join('test', 'resources', rDir, 'pkgbase.old.yaml'), path.join('test', 'resources', rDir, 'pkgbase.new.yaml'))).resolves.toEqual(expected);\n });\n\n it('can detect a move operation', async () => {\n const expected: Result = {\n build: false,\n move: true,\n delete: [{\n architecture: \"x86_64\",\n package: \"opencascade\",\n repository: \"world-gremlins\",\n version: \"1:7.9.2-1\",\n }],\n actions: {\n addRepo: 'world',\n removeRepo: 'world-gremlins',\n triggersBuild: false,\n triggersRebuild: false,\n triggersRepoAdd: true,\n triggersRepoRemove: true,\n triggersNoCheck: false\n }\n };\n const rDir = 'move-clean';\n await expect(parse(path.join('test', 'resources', rDir, 'pkgbase.old.yaml'), path.join('test', 'resources', rDir, 'pkgbase.new.yaml'))).resolves.toEqual(expected);\n });\n\n it('can remove dangling packages in a move operation', async () => {\n const expected: Result = {\n build: false,\n move: true,\n delete: [\n {\n architecture: \"x86_64\",\n package: \"pidgin\",\n repository: \"world\",\n version: \"2.14.14-3\",\n },\n {\n architecture: \"x86_64\",\n package: \"libpurple\",\n repository: \"world-gremlins\",\n version: \"2.14.14-4\",\n },\n {\n architecture: \"x86_64\",\n package: \"finch\",\n repository: \"world-gremlins\",\n version: \"2.14.14-4\",\n }\n ],\n actions: {\n addRepo: 'world',\n removeRepo: 'world-gremlins',\n triggersBuild: false,\n triggersRebuild: false,\n triggersRepoAdd: true,\n triggersRepoRemove: true,\n triggersNoCheck: false\n }\n };\n const rDir = 'move-with-dropped';\n await expect(parse(path.join('test', 'resources', rDir, 'pkgbase.old.yaml'), path.join('test', 'resources', rDir, 'pkgbase.new.yaml'))).resolves.toEqual(expected);\n });\n\n it('can detect a delete operation', async () => {\n const expected: Result = {\n build: false,\n move: false,\n delete: [\n {\n architecture: \"any\",\n package: \"python-nntplib\",\n repository: \"world\",\n version: \"3.13.0-2\",\n },\n {\n architecture: \"any\",\n package: \"python-cgi\",\n repository: \"world\",\n version: \"3.13.0-2\",\n },\n {\n architecture: \"any\",\n package: \"python-mailcap\",\n repository: \"world\",\n version: \"3.13.0-2\",\n }\n ],\n actions: {\n addRepo: null,\n removeRepo: 'world',\n triggersBuild: false,\n triggersRebuild: false,\n triggersRepoAdd: false,\n triggersRepoRemove: true,\n triggersNoCheck: false\n }\n };\n const rDir = 'remove';\n await expect(parse(path.join('test', 'resources', rDir, 'pkgbase.old.yaml'), path.join('test', 'resources', rDir, 'pkgbase.new.yaml'))).resolves.toEqual(expected);\n });\n});"]} \ No newline at end of file diff --git a/src/pkgbase.ts b/src/pkgbase.ts index 326f9e0..884e14a 100644 --- a/src/pkgbase.ts +++ b/src/pkgbase.ts @@ -2,6 +2,13 @@ import { type PathLike } from 'fs'; import fsp from 'fs/promises'; import * as YAML from 'yaml'; +interface PackageInfo { + package: string; + repository: string; + version: string; + architecture: string; +} + interface Actions { addRepo: string | null; removeRepo: string | null; @@ -15,7 +22,7 @@ interface Actions { interface Result { build: boolean; move: boolean; - delete: string[]; + delete: PackageInfo[]; actions: Actions; } @@ -57,22 +64,33 @@ async function parse(previous: PathLike, current: PathLike): Promise { if (isDelete(actions)) { const repo: RepoContents = prev.repos[actions.removeRepo]; - result.delete.push(...repo.packages.map(p => `${actions.removeRepo}/${p.split(`-${repo.version}`)[0]}`)); + result.delete.push(...parseRepoContents(repo, actions.removeRepo)); } - else if (result.move = isMove(actions)) { - result.delete.push(...getDropped(prev.repos[actions.addRepo], curr.repos[actions.removeRepo])); + else if (prev && (result.move = isMove(actions))) { + const moving = parseRepoContents(curr.repos[actions.addRepo], actions.removeRepo); + result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), moving)); + result.delete.push(...moving); } - else if (result.build = isAdd(actions)) { - result.delete.push(...getDropped(prev.repos[actions.addRepo], curr.repos[actions.addRepo])); + else if ((result.build = isAdd(actions)) && prev) { + result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), parseRepoContents(curr.repos[actions.addRepo], actions.addRepo))); } return result; } -function getDropped(oldRepoContents: RepoContents, newRepoContents: RepoContents): string[] { - const oldPackages = oldRepoContents.packages.map(p => p.split(`-${oldRepoContents.version}`)[0]); - const newPackages = newRepoContents.packages.map(p => p.split(`-${newRepoContents.version}`)[0]); - return oldPackages.filter(p => newPackages.indexOf(p) === -1); +function parseRepoContents(repoContents: RepoContents, repository: string): PackageInfo[] { + return repoContents.packages.map(p => { + return { + version: repoContents.version, + repository, + package: p.split(`-${repoContents.version}`)[0], + architecture: p.split(`${repoContents.version}-`)[1].split('.')[0] + } + }); +} + +function getDropped(oldPackages: PackageInfo[], newPackages: PackageInfo[]): PackageInfo[] { + return oldPackages.filter(p => newPackages.filter(np => np.package === p.package).length === 0); } function isDelete(actions: Actions): boolean { @@ -98,4 +116,4 @@ async function tryRead(file: PathLike): Promise { } export { parse }; -export type { Actions, Result, RepoContents, PkgBase }; +export type { Actions, Result, RepoContents, PkgBase, PackageInfo }; diff --git a/test/pkgbase.test.ts b/test/pkgbase.test.ts index 8041098..47dfb11 100644 --- a/test/pkgbase.test.ts +++ b/test/pkgbase.test.ts @@ -26,7 +26,14 @@ describe('pkgbase parser', () => { const expected: Result = { build: true, move: false, - delete: ['pidgin'], + delete: [ + { + architecture: "x86_64", + package: "pidgin", + repository: "world", + version: "2.14.14-3", + } + ], actions: { addRepo: 'world', removeRepo: null, @@ -45,7 +52,12 @@ describe('pkgbase parser', () => { const expected: Result = { build: false, move: true, - delete: ['opencascade'], + delete: [{ + architecture: "x86_64", + package: "opencascade", + repository: "world-gremlins", + version: "1:7.9.2-1", + }], actions: { addRepo: 'world', removeRepo: 'world-gremlins', @@ -64,7 +76,26 @@ describe('pkgbase parser', () => { const expected: Result = { build: false, move: true, - delete: ['pidgin', 'libpurple', 'finch'], + delete: [ + { + architecture: "x86_64", + package: "pidgin", + repository: "world", + version: "2.14.14-3", + }, + { + architecture: "x86_64", + package: "libpurple", + repository: "world-gremlins", + version: "2.14.14-4", + }, + { + architecture: "x86_64", + package: "finch", + repository: "world-gremlins", + version: "2.14.14-4", + } + ], actions: { addRepo: 'world', removeRepo: 'world-gremlins', @@ -83,7 +114,26 @@ describe('pkgbase parser', () => { const expected: Result = { build: false, move: false, - delete: ['world/python-nntplib', 'world/python-cgi', 'world/python-mailcap'], + delete: [ + { + architecture: "any", + package: "python-nntplib", + repository: "world", + version: "3.13.0-2", + }, + { + architecture: "any", + package: "python-cgi", + repository: "world", + version: "3.13.0-2", + }, + { + architecture: "any", + package: "python-mailcap", + repository: "world", + version: "3.13.0-2", + } + ], actions: { addRepo: null, removeRepo: 'world',