diff --git a/.changeset/clever-rings-cheer.md b/.changeset/clever-rings-cheer.md new file mode 100644 index 00000000..8ebaa544 --- /dev/null +++ b/.changeset/clever-rings-cheer.md @@ -0,0 +1,5 @@ +--- +"@stephansama/multipublish": patch +--- + +Updated jsr to have auth token. fail without error for unscoped packages diff --git a/.config/.multipublishrc.json b/.config/.multipublishrc.json index 54fda179..4162e2cb 100644 --- a/.config/.multipublishrc.json +++ b/.config/.multipublishrc.json @@ -1,6 +1,14 @@ { "$schema": "../node_modules/@stephansama/multipublish/config/schema.json", "platforms": [ + [ + "jsr", + { + "experimentalUpdateCatalogs": true, + "experimentalGenerateJSR": true, + "defaultExclude": ["!config"] + } + ], [ "npm", { diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 54bafe69..f60399bd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,6 +10,7 @@ env: ZX_VERBOSE: true DO_NOT_TRACK: 1 NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}} + JSR_AUTH_TOKEN: ${{secrets.JSR_AUTH_TOKEN}} CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} TURBO_TOKEN: ${{secrets.TURBO_TOKEN}} diff --git a/core/multipublish/src/jsr.test.ts b/core/multipublish/src/jsr.test.ts index 3f4383b3..a322ab9f 100644 --- a/core/multipublish/src/jsr.test.ts +++ b/core/multipublish/src/jsr.test.ts @@ -50,6 +50,7 @@ describe("jsr", () => { defaultInclude: ["src"], experimentalGenerateJSR: false, experimentalUpdateCatalogs: false, + tokenEnvironmentKey: "test", }; updateIncludeExcludeList(jsrConfig, appConfig); @@ -72,6 +73,7 @@ describe("jsr", () => { defaultInclude: ["new-include"], experimentalGenerateJSR: false, experimentalUpdateCatalogs: false, + tokenEnvironmentKey: "test" }; updateIncludeExcludeList(jsrConfig, appConfig); diff --git a/core/multipublish/src/publish.test.ts b/core/multipublish/src/publish.test.ts index 7234129a..e2f5b5ed 100644 --- a/core/multipublish/src/publish.test.ts +++ b/core/multipublish/src/publish.test.ts @@ -150,7 +150,8 @@ describe("publish", () => { ); }); - it("should publish to jsr", async () => { + it("should publish to jsr without token", async () => { + vi.stubEnv("JSR_AUTH_TOKEN", ""); vi.mocked(mocks.loadConfig).mockResolvedValue({ config: { exports: "index.ts", @@ -183,5 +184,42 @@ describe("publish", () => { { stdio: "inherit" }, ); }); + + it("should publish to jsr with token", async () => { + const token = "test-token"; + vi.stubEnv("JSR_AUTH_TOKEN", token); + + vi.mocked(mocks.loadConfig).mockResolvedValue({ + config: { + exports: "index.ts", + name: "@scope/pkg", + version: "1.0.0", + }, + filename: "/path/to/pkg/jsr.json", + }); + + const pkg = { + dir: "/path/to/pkg", + packageJson: { + name: "@scope/pkg", + version: "1.0.0", + }, + relativeDir: "./pkg", + }; + + const platform = "jsr"; + + await publishPlatform(pkg, platform); + + expect(mocks.writeFile).toHaveBeenCalledWith( + "/path/to/pkg/jsr.json", + expect.any(String), + ); + + expect(mocks.execSync).toHaveBeenCalledWith( + `pnpm dlx jsr publish --allow-dirty --allow-slow-types --token ${token}`, + { stdio: "inherit" }, + ); + }); }); }); diff --git a/core/multipublish/src/publish.ts b/core/multipublish/src/publish.ts index c1473827..3fffdba2 100644 --- a/core/multipublish/src/publish.ts +++ b/core/multipublish/src/publish.ts @@ -75,15 +75,18 @@ export async function publishPlatform( } } + const authToken = process.env[config.tokenEnvironmentKey]; + await util.chdir(pkg.dir, () => { cp.execSync( [ jsrPublishCommand[packageManager], "--allow-dirty", - isDryRun && "--dry-run", config.allowSlowTypes && "--allow-slow-types", + isDryRun && "--dry-run", + authToken && `--token ${authToken}`, ] - .filter((x) => x) + .filter((x): x is string => !!x) .join(" "), { stdio: "inherit" }, ); @@ -120,7 +123,9 @@ export async function publishPlatform( const scope = pkg.packageJson.name.split("/").at(0); if (!scope?.startsWith("@")) { - throw new Error("scope must start with `@` symbol"); + return console.error( + "scope does not start with @ symbol. aborting.", + ); } const npmrcFile = diff --git a/core/multipublish/src/schema.test.ts b/core/multipublish/src/schema.test.ts index 6beb0a7f..3fdb8a49 100644 --- a/core/multipublish/src/schema.test.ts +++ b/core/multipublish/src/schema.test.ts @@ -30,6 +30,7 @@ describe("schema", () => { allowSlowTypes: false, experimentalGenerateJSR: false, experimentalUpdateCatalogs: false, + tokenEnvironmentKey: "JSR_AUTH_TOKEN", }, ], ]; diff --git a/core/multipublish/src/schema.ts b/core/multipublish/src/schema.ts index b8d75ba2..91ac9b31 100644 --- a/core/multipublish/src/schema.ts +++ b/core/multipublish/src/schema.ts @@ -7,6 +7,7 @@ export const jsrPlatformOptionsSchema = z.object({ defaultInclude: z.array(z.string()).optional(), experimentalGenerateJSR: z.boolean().default(false), experimentalUpdateCatalogs: z.boolean().default(false), + tokenEnvironmentKey: z.string().default("JSR_AUTH_TOKEN"), }); export type NpmPlatformOptionsSchema = z.infer; diff --git a/package.json b/package.json index 7932e6c6..4e26dae8 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "scripts:pkg-pr-new": "node ./scripts/pkg-pr-new.js", "test": "turbo test", "pretest:ci": "pnpm run scripts:generate-examples", - "test:ci": "vitest --run --coverage --reporter=junit --outputFile=test-report.junit.xml", + "test:ci": "vitest --run --coverage", "test:ui": "vitest --ui", "version": "changeset version && pnpm install --lockfile-only" }, @@ -87,9 +87,9 @@ "vitest": "catalog:vitest", "yaml-eslint-parser": "^1.3.2" }, - "packageManager": "pnpm@10.29.3", "devDependencies": { "actions-up": "^1.11.0", "taze": "^19.9.2" - } + }, + "packageManager": "pnpm@10.29.3" } diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 856394cc..98ac11d2 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -52,6 +52,7 @@ catalog: "@types/react": ^19.2.14 "@types/vfile": ^4.0.0 "@types/yargs": ^17.0.35 + actions-up: ^1.11.0 deepmerge: "^4.3.1" es-toolkit: 1.43.0 astro: 5.9.3 @@ -63,6 +64,7 @@ catalog: prettier: ^3.8.1 react: 19.2.0 remark: ^15.0.1 + taze: ^19.9.2 tsdown: 0.15.12 tsx: 4.21.0 typescript: 5.9.3 diff --git a/vitest.config.ts b/vitest.config.ts index 93d2b68b..60791e86 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -7,7 +7,7 @@ export default defineConfig({ provider: "v8", reporter: ["html", "json", "text"], }, - outputFile: { junit: "./coverage/test-report.junit.xml" }, + outputFile: { junit: "./test-report.junit.xml" }, projects: ["./core/*"], reporters: ["default", "junit"], },