Skip to content

Commit

Permalink
Always include trailing slash for registry urls in .npmrc (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzyl authored May 7, 2024
1 parent 90801d4 commit 7ed0984
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-lies-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osdk/create-app": minor
---

Always include trailing slash for registry urls in .npmrc
4 changes: 2 additions & 2 deletions packages/create-app/src/generate/generateNpmRc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { expect, test } from "vitest";
import { generateNpmRc } from "./generateNpmRc.js";

const expected = `
//registry.com:_authToken=\${FOUNDRY_TOKEN}
@myapp:registry=https://registry.com
//registry.com/:_authToken=\${FOUNDRY_TOKEN}
@myapp:registry=https://registry.com/
`.trimStart();

test("it generates .npmrc for packge and registry", () => {
Expand Down
11 changes: 9 additions & 2 deletions packages/create-app/src/generate/generateNpmRc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ export function generateNpmRc({
osdkPackage: string;
osdkRegistryUrl: string;
}): string {
const withoutProtocol = osdkRegistryUrl.replace(/^https:\/\//, "");
// pnpm requires a trailing slash in .npmrc
// https://github.com/pnpm/pnpm/issues/5941
const withTrailingSlash = osdkRegistryUrl.endsWith("/")
? osdkRegistryUrl
: osdkRegistryUrl + "/";
const withoutProtocol = withTrailingSlash.replace(/^https:\/\//, "");
const packageScope = osdkPackage.split("/")[0];

return `//${withoutProtocol}:_authToken=\${FOUNDRY_TOKEN}\n`
+ `${osdkPackage.split("/")[0]}:registry=${osdkRegistryUrl}\n`;
+ `${packageScope}:registry=${withTrailingSlash}\n`;
}

0 comments on commit 7ed0984

Please sign in to comment.