Skip to content

Commit

Permalink
Get rid of unnamed packages. Closes issue #157
Browse files Browse the repository at this point in the history
  • Loading branch information
iecker authored and jmoalves committed Oct 16, 2023
1 parent 66e9d42 commit 8d5d96d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
20 changes: 20 additions & 0 deletions src/lib/package/package_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ Deno.test('Managers should resolve packages with a transitive dependency', async
assertEquals(packageNames, ['transitive dependency', 'dependency with transitive', 'package with a transitive dependency',])
})

Deno.test('Managers should not crash with empty package', async () => {
// Given
const config = await getConfigWithMockRepo()
const manager = new PackageManager(config)
// When
const resolvedPackages = manager.resolvePackages(['package without dependencies', '', ' ', 'package with a transitive dependency'])
// Then
let packageNames = resolvedPackages?.map(it => it.name)
assertEquals(packageNames, ['package without dependencies', 'transitive dependency', 'dependency with transitive', 'package with a transitive dependency'])
})

Deno.test('Managers should ignore empty package', async () => {
// Given
let packageNames = ['package without dependencies', '', ' ', 'package with a transitive dependency']
// When
PackageManager.removeExtension(packageNames)
// Then
assertEquals(packageNames, ['package without dependencies', 'package with a transitive dependency'])
})

async function getConfigWithMockRepo(): Promise<Config> {
const config = TestHelper.getConfig();
const repoMock = new MockRepository('mockRepo1', [
Expand Down
31 changes: 21 additions & 10 deletions src/lib/package/package_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export default class PackageManager {
let names: Set<string> = new Set(); // Solving circular references - Issue #11
let error: boolean = false;
for (const pkgName of pkgNames) {
if (!pkgName || !pkgName.trim()) {
continue
}
let repo = (installedOnly ? this.config.repositoryManager.repositoryInstalled : this.config.repositoryManager.repository);
let myError: boolean = this.resolveInRepo(repo, pkgs, names, pkgName, showLog);
error = error || myError;
Expand Down Expand Up @@ -62,16 +65,24 @@ export default class PackageManager {
}

static removeExtension(pkgNames: string[]) {
log.debug(`removeExtension <- ${pkgNames}`)

for (let idx in pkgNames) {
pkgNames[idx] = pkgNames[idx]
.replace(/\.levain\.yaml$/, "")
.replace(/\.levain\.yml$/, "")
.replace(/\.levain$/, "")
}

log.debug(`removeExtension -> ${pkgNames}`)
log.debug(`removeExtension <- ${pkgNames}`);

let filteredPkgNames = pkgNames
.map(pkgName => {
if (!pkgName || !pkgName.trim()) {
log.warning(`Ignoring package with null name, check your configuration file.`)
return "";
} else {
return pkgName
.replace(/\.levain\.yaml$/, "")
.replace(/\.levain\.yml$/, "")
.replace(/\.levain$/, "");
}})
.filter(pkg => pkg !== "");

pkgNames.splice(0, pkgNames.length, ...filteredPkgNames);

log.debug(`removeExtension -> ${pkgNames}`);
}

package(pkgName: string): Package | undefined {
Expand Down

0 comments on commit 8d5d96d

Please sign in to comment.