Skip to content

Commit

Permalink
fixup: add trailing slash if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous committed Mar 29, 2024
1 parent 4c8bc45 commit bafea60
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/npm/use-npm-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,21 @@ export async function useNpmEnvironment<TReturn>(
task: NpmCliTask<TReturn>
): Promise<TReturn> {
const { registry, token, logger, temporaryDirectory } = options;
const npmrcDirectory = await fs.mkdtemp(
path.join(temporaryDirectory, "npm-publish-")
);
const npmrc = path.join(npmrcDirectory, ".npmrc");
const environment = {
NODE_AUTH_TOKEN: token,
npm_config_userconfig: npmrc,
};

const { host, origin, pathname } = registry;
const pathnameWithSlash = pathname.endsWith("/") ? pathname : `${pathname}/`;
const config = [
"; created by jsdevtools/npm-publish",
`//${registry.host}${registry.pathname}:_authToken=\${NODE_AUTH_TOKEN}`,
`registry=${registry.href}`,
`//${host}${pathnameWithSlash}:_authToken=\${NODE_AUTH_TOKEN}`,
`registry=${origin}${pathnameWithSlash}`,
"",
].join(os.EOL);

const npmrcDirectory = await fs.mkdtemp(
path.join(temporaryDirectory, "npm-publish-")
);
const npmrc = path.join(npmrcDirectory, ".npmrc");
const environment = { NODE_AUTH_TOKEN: token, npm_config_userconfig: npmrc };

await fs.writeFile(npmrc, config, "utf8");

logger?.debug?.(`Temporary .npmrc created at ${npmrc}\n${config}`);
Expand Down

0 comments on commit bafea60

Please sign in to comment.