({
script,
cwd = process.cwd(),
}: PublishOptions)
| 26 | }; |
| 27 | |
| 28 | export async function runPublish({ |
| 29 | script, |
| 30 | cwd = process.cwd(), |
| 31 | }: PublishOptions): Promise<PublishResult> { |
| 32 | let branch = await gitUtils.getCurrentBranch(cwd); |
| 33 | let [publishCommand, ...publishArgs] = script.split(/\s+/); |
| 34 | |
| 35 | let changesetPublishOutput = await execWithOutput( |
| 36 | publishCommand, |
| 37 | publishArgs, |
| 38 | { cwd } |
| 39 | ); |
| 40 | |
| 41 | await gitUtils.pullBranch(branch, cwd); |
| 42 | await gitUtils.push(branch, { includeTags: true, cwd }); |
| 43 | |
| 44 | let { packages, tool } = await getPackages(cwd); |
| 45 | let releasedPackages: Package[] = []; |
| 46 | |
| 47 | if (tool !== "root") { |
| 48 | let newTagRegex = /New tag:\s+(@[^/]+\/[^@]+|[^/]+)@([^\s]+)/; |
| 49 | let packagesByName = new Map(packages.map((x) => [x.packageJson.name, x])); |
| 50 | |
| 51 | for (let line of changesetPublishOutput.stdout.split("\n")) { |
| 52 | let match = line.match(newTagRegex); |
| 53 | if (match === null) { |
| 54 | continue; |
| 55 | } |
| 56 | let pkgName = match[1]; |
| 57 | let pkg = packagesByName.get(pkgName); |
| 58 | if (pkg === undefined) { |
| 59 | throw new Error( |
| 60 | `Package "${pkgName}" not found.` + |
| 61 | "This is probably a bug in the action, please open an issue" |
| 62 | ); |
| 63 | } |
| 64 | releasedPackages.push(pkg); |
| 65 | } |
| 66 | } else { |
| 67 | if (packages.length === 0) { |
| 68 | throw new Error( |
| 69 | `No package found.` + |
| 70 | "This is probably a bug in the action, please open an issue" |
| 71 | ); |
| 72 | } |
| 73 | let pkg = packages[0]; |
| 74 | let newTagRegex = /New tag:/; |
| 75 | |
| 76 | for (let line of changesetPublishOutput.stdout.split("\n")) { |
| 77 | let match = line.match(newTagRegex); |
| 78 | |
| 79 | if (match) { |
| 80 | releasedPackages.push(pkg); |
| 81 | break; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 |
no test coverage detected