Skip to content

Commit

Permalink
feat(resolution): add built-in aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
innocenzi committed Mar 10, 2023
1 parent 7e11d4e commit f04492d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/core/src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export async function parseResolvable(options: ApplyOptions, cwd: string = proce
debug.resolve('Parsing resolvable:', options.resolvable)
const resolved
= await resolveConfiguredAlias(options)
|| await resolveAlias(options)
|| await resolveNamespacedAlias(options)
|| await resolveLocalFile(options, cwd)
|| await resolveLocalDirectory(options, cwd)
Expand Down Expand Up @@ -175,6 +176,25 @@ export async function resolveLocalFile(options: ApplyOptions, cwd: string): Prom
return false
}

/**
* Resolves an alias.
*/
export async function resolveAlias(options: ApplyOptions): Promise<ResolvedPreset | false> {
const aliases: Record<string, ResolvedPreset> = {
hybridly: {
organization: 'hybridly',
repository: 'preset',
type: 'repository',
} as RepositoryPreset,
}

if (options.resolvable in aliases) {
return aliases[options.resolvable]
}

return false
}

/**
* Resolves a configured alias.
*/
Expand Down Expand Up @@ -296,5 +316,5 @@ export async function cloneRepository(preset: RepositoryPreset, options: ApplyOp
throw new PresetError({ code: 'ERR_CLONE_PRESET', details: `Repository ${repositoryUrl} could not be cloned.`, parent })
}

return path.resolve(targetDirectory, preset.path)
return path.resolve(targetDirectory, preset.path ?? '')
}

0 comments on commit f04492d

Please sign in to comment.