|
1 | | -import type { ReleaseOpts } from "./main.ts"; |
| 1 | +import type { ReleaseOpts } from "./main"; |
2 | 2 | import { $ } from "execa"; |
3 | | -import { transformPackageJsonToDenoJson } from "./transform_pkg_to_deno.ts"; |
4 | | - |
5 | | -function assertStringIncludes(actual: string, expected: string, message?: string): void { |
6 | | - if (!actual.includes(expected)) { |
7 | | - throw new Error(message || `String does not include expected substring: ${expected}`); |
8 | | - } |
9 | | -} |
| 3 | +import { readFile } from "fs/promises"; |
| 4 | +import { join } from "path"; |
10 | 5 |
|
11 | 6 | async function npmVersionExists( |
12 | 7 | packageName: string, |
13 | 8 | version: string, |
14 | 9 | ): Promise<boolean> { |
15 | | - console.log(`==> Checking if NPM version exists: ${packageName}@${version}`); |
| 10 | + console.log( |
| 11 | + `==> Checking if NPM version exists: ${packageName}@${version}`, |
| 12 | + ); |
16 | 13 | try { |
17 | | - await $({ stdout: 'ignore', stderr: 'pipe' })`npm view ${packageName}@${version} version`; |
| 14 | + await $({ |
| 15 | + stdout: "ignore", |
| 16 | + stderr: "pipe", |
| 17 | + })`npm view ${packageName}@${version} version`; |
18 | 18 | return true; |
19 | 19 | } catch (error: any) { |
20 | 20 | if (error.stderr) { |
21 | | - assertStringIncludes( |
22 | | - error.stderr, |
23 | | - `No match found for version ${version}`, |
24 | | - "unexpected output", |
25 | | - ); |
26 | | - } |
27 | | - return false; |
28 | | - } |
29 | | -} |
30 | | - |
31 | | -async function jsrVersionExists( |
32 | | - packageName: string, |
33 | | - version: string, |
34 | | -): Promise<boolean> { |
35 | | - console.log(`==> Checking if JSR version exists: ${packageName}@${version}`); |
36 | | - try { |
37 | | - await $({ stdout: 'ignore', stderr: 'pipe' })`deno info jsr:${packageName}@${version}`; |
38 | | - return true; |
39 | | - } catch (error: any) { |
40 | | - if (error.stderr) { |
41 | | - assertStringIncludes( |
42 | | - error.stderr, |
43 | | - `Could not find version of '${packageName}' that matches specified version constraint '${version}'`, |
44 | | - "unexpected output", |
45 | | - ); |
| 21 | + if ( |
| 22 | + !error.stderr.includes( |
| 23 | + `No match found for version ${version}`, |
| 24 | + ) && |
| 25 | + !error.stderr.includes( |
| 26 | + `'${packageName}@${version}' is not in this registry.`, |
| 27 | + ) |
| 28 | + ) { |
| 29 | + throw new Error( |
| 30 | + `unexpected npm view version output: ${error.stderr}`, |
| 31 | + ); |
| 32 | + } |
46 | 33 | } |
47 | 34 | return false; |
48 | 35 | } |
49 | 36 | } |
50 | 37 |
|
51 | 38 | export async function publishSdk(opts: ReleaseOpts) { |
52 | | - const packages: { path: string, name: string, npm: boolean, jsr?: boolean, turbo?: boolean }[] = [ |
53 | | - { |
54 | | - path: `${opts.root}/sdks/typescript/api-full`, |
55 | | - name: "@rivet-gg/api-full", |
56 | | - npm: true, |
57 | | - }, |
| 39 | + const packagePaths = [ |
| 40 | + `${opts.root}/sdks/typescript/tunnel-protocol`, |
| 41 | + `${opts.root}/sdks/typescript/runner`, |
| 42 | + `${opts.root}/sdks/typescript/runner-protocol`, |
| 43 | + `${opts.root}/sdks/typescript/api-full`, |
58 | 44 | ]; |
59 | 45 |
|
60 | | - for (const pkg of packages) { |
61 | | - if (pkg.turbo) { |
62 | | - await $`pnpm build --filter ${pkg.name}`; |
63 | | - } |
| 46 | + for (const path of packagePaths) { |
| 47 | + // Read package.json to get the name |
| 48 | + const packageJsonPath = join(path, "package.json"); |
| 49 | + const packageJson = JSON.parse(await readFile(packageJsonPath, "utf-8")); |
| 50 | + const name = packageJson.name; |
64 | 51 |
|
65 | 52 | // Check if version already exists |
66 | 53 | let versionExists = false; |
67 | | - if (pkg.npm) { |
68 | | - versionExists = await npmVersionExists(pkg.name, opts.version); |
69 | | - } else if (pkg.jsr) { |
70 | | - versionExists = await jsrVersionExists(pkg.name, opts.version); |
71 | | - } |
| 54 | + versionExists = await npmVersionExists(name, opts.version); |
72 | 55 |
|
73 | 56 | if (versionExists) { |
74 | 57 | console.log( |
75 | | - `Version ${opts.version} of ${pkg.name} already exists. Skipping...`, |
| 58 | + `Version ${opts.version} of ${name} already exists. Skipping...`, |
76 | 59 | ); |
77 | 60 | continue; |
78 | 61 | } |
79 | 62 |
|
80 | 63 | // Publish |
81 | | - if (pkg.npm) { |
82 | | - console.log(`==> Publishing to NPM: ${pkg.name}@${opts.version}`); |
83 | | - await $({ cwd: pkg.path })`pnpm install`; |
84 | | - await $({ cwd: pkg.path })`pnpm npm publish --access public --tolerate-republish`; |
85 | | - } |
86 | | - |
87 | | - if (pkg.jsr) { |
88 | | - console.log(`==> Publishing to JSR: ${pkg.name}@${opts.version}`); |
89 | | - |
90 | | - // TODO(https://github.com/denoland/deno/issues/27428): `--set-version` not working, so we have to manually update `jsr.jsonc` |
91 | | - |
92 | | - await transformPackageJsonToDenoJson({ |
93 | | - cwd: pkg.path, |
94 | | - skipPathInInternalPackages: "src", |
95 | | - internalPackagesLinkPath: "internal", |
96 | | - }); |
97 | | - |
98 | | - // TODO: Auto-populate token here |
99 | | - // --allow-slow-types = we use zod which doesn't support this |
100 | | - // --allow-dirty = we change the version on the fly |
101 | | - // --set-version = validate the correct version is used |
102 | | - await $({ cwd: pkg.path, env: { DENO_NO_PACKAGE_JSON: '1' } })`deno publish --allow-slow-types --allow-dirty`; |
103 | | - } |
| 64 | + console.log(`==> Publishing to NPM: ${name}@${opts.version}`); |
| 65 | + await $({ cwd: path })`pnpm install`; |
| 66 | + await $({ |
| 67 | + cwd: path, |
| 68 | + })`pnpm npm publish --access public --tolerate-republish`; |
104 | 69 | } |
105 | 70 | } |
0 commit comments