diff --git a/src/npm/use-npm-environment.ts b/src/npm/use-npm-environment.ts index d6a0da9..ac0b543 100644 --- a/src/npm/use-npm-environment.ts +++ b/src/npm/use-npm-environment.ts @@ -29,22 +29,21 @@ export async function useNpmEnvironment( task: NpmCliTask ): Promise { 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}`);