Skip to content

refactor: clean up upm auth #338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cli/cmd-login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function makeLoginCmd(
_auth,
} satisfies BasicAuth).promise;
if (result.isErr()) return result;
log.notice("config", "saved unity config at " + result.value);
log.notice("config", "saved unity config at " + configPath);
} else {
// npm login
const loginResult = await npmLogin(
Expand Down Expand Up @@ -126,7 +126,7 @@ export function makeLoginCmd(
token,
} satisfies TokenAuth).promise;
if (storeResult.isErr()) return storeResult;
log.notice("config", "saved unity config at " + storeResult.value);
log.notice("config", "saved unity config at " + configPath);
}

return Ok(undefined);
Expand Down
5 changes: 2 additions & 3 deletions src/io/upm-config-io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,12 @@ export type UpmConfigSaveError = IOError;
* Save the upm config.
* @param config The config to save.
* @param configFilePath The path of the file that should be saved to.
* @returns The path to which the file was saved.
*/
export const trySaveUpmConfig = (
writeFile: WriteTextFile,
config: UPMConfig,
configFilePath: string
): AsyncResult<string, UpmConfigSaveError> => {
): AsyncResult<void, UpmConfigSaveError> => {
const content = TOML.stringify(config);
return writeFile(configFilePath, content).map(() => configFilePath);
return writeFile(configFilePath, content);
};
14 changes: 6 additions & 8 deletions src/services/upm-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ export type UpmAuthStoreError = UpmConfigLoadError | IOError;

/**
* Service function for storing authentication information in an upmconfig file.
* @param configDir Path to the directory in which the upmconfig file is
* located.
* @param configPath Path to the upmconfig file.
* @param registry Url of the registry for which to authenticate.
* @param auth Authentication information.
* @returns The path of the upmconfig file.
*/
export type SaveAuthToUpmConfig = (
configDir: string,
configPath: string,
registry: RegistryUrl,
auth: UpmAuth
) => AsyncResult<string, UpmAuthStoreError>;
) => AsyncResult<void, UpmAuthStoreError>;

/**
* Makes a {@link SaveAuthToUpmConfig} function.
Expand All @@ -35,9 +33,9 @@ export function makeSaveAuthToUpmConfigService(
writeFile: WriteTextFile
): SaveAuthToUpmConfig {
// TODO: Add tests for this service
return (configDir, registry, auth) =>
loadUpmConfig(configDir)
return (configPath, registry, auth) =>
loadUpmConfig(configPath)
.map((maybeConfig) => maybeConfig || {})
.map((config) => addAuth(registry, auth, config))
.andThen((config) => trySaveUpmConfig(writeFile, config, configDir));
.andThen((config) => trySaveUpmConfig(writeFile, config, configPath));
}
Loading