Skip to content

Commit 0499510

Browse files
committed
Naming and cleanup
1 parent 3177560 commit 0499510

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

scripts/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#! /usr/bin/env node
22
const { spawn } = require("child_process");
3-
const { lernaScopeArgs } = require("./github.js");
3+
const { lernaScopes } = require("./github.js");
44

5-
const buildProcess = spawn("lerna", ["run", "build", ...lernaScopeArgs], { stdio: "inherit" });
5+
const buildProcess = spawn("lerna", ["run", "build", ...lernaScopes], { stdio: "inherit" });
66

77
buildProcess.on("close", (code) => {
88
process.exit(code);

scripts/github.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env node
22
const { execSync } = require("child_process");
33

4-
const [, packageFromRef, versionFromRef, , prerelease] =
4+
const [, packagePatternFromRef, versionFromRef, , prereleaseFromRef] =
55
/^refs\/tags\/(.+)-v(\d\d*\.\d\d*(\.\d\d*)?(-.+)?)$/.exec(process.env.GITHUB_REF ?? "") ?? [];
66

77
const since = process.env.GITHUB_ACTION
@@ -17,30 +17,36 @@ const lernaList = JSON.parse(
1717
const ref = process.env.GITHUB_SHA ?? "HEAD";
1818
const shortSHA = execSync(`git rev-parse --short ${ref}`).toString().trim();
1919

20-
const filteredLernaList = JSON.parse(
20+
const scopedLernaList = JSON.parse(
2121
execSync(
22-
`lerna list --json --toposort --include-dependents ${
23-
packageFromRef ? `--scope='{,*/}${packageFromRef}'` : since
22+
`lerna list --json --no-private --toposort --include-dependents ${
23+
packagePatternFromRef ? `--scope='{,*/}${packagePatternFromRef}'` : since
2424
}`,
2525
{ stdio: ["ignore", "pipe", "ignore"] },
2626
).toString(),
27-
).filter((lerna) => {
28-
if (lerna.private) return false;
29-
return true;
30-
});
27+
);
3128

32-
if (packageFromRef && filteredLernaList.length === 0) {
29+
const packagesFromRef = packagePatternFromRef && JSON.parse(
30+
execSync(
31+
`lerna list --json --no-private --scope='{,*/}${packagePatternFromRef}'`,
32+
{ stdio: ["ignore", "pipe", "ignore"] },
33+
).toString(),
34+
);
35+
if (packagePatternFromRef && packagesFromRef.length !== 1) {
3336
throw new Error(`Lerna didn't find ${packageFromRef} in this workspace`);
3437
}
38+
const packageFromRef = packagesFromRef?.[0].name;
3539

36-
const lernaScopeArgs = filteredLernaList.map(({ name }) => ["--scope", name]).flat();
40+
const lernaScopes = scopedLernaList.map(({ name }) => ["--scope", name]).flat();
3741

3842
module.exports = {
39-
packageFromRef,
40-
versionFromRef,
41-
prerelease: !packageFromRef || !!prerelease,
43+
taggedRelease: packageFromRef ? {
44+
name: packageFromRef,
45+
version: versionFromRef,
46+
tag: prereleaseFromRef ? "next" : "latest",
47+
} : undefined,
4248
lernaList,
43-
filteredLernaList,
49+
scopedLernaList,
4450
shortSHA,
45-
lernaScopeArgs,
51+
lernaScopes,
4652
};

scripts/publish.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ const { execSync } = require("child_process");
33
const { writeFileSync, readFileSync } = require("fs");
44
const { join } = require("path");
55
const {
6-
filteredLernaList,
6+
scopedLernaList,
77
lernaList,
88
versionFromRef,
99
shortSHA,
10-
prerelease,
11-
packageFromRef,
10+
taggedRelease,
1211
} = require("./github.js");
1312

1413
const wombatDressingRoomTokens = new Map([
@@ -24,18 +23,18 @@ wombatDressingRoomTokens.forEach((token, pkg) => {
2423
});
2524
});
2625

27-
const packagesToPublish = filteredLernaList.map((lerna) => {
28-
const useVersionFromRef = versionFromRef && lerna.name.endsWith(packageFromRef);
29-
if (useVersionFromRef && versionFromRef.split("-")[0] !== lerna.version) {
26+
const packagesToPublish = scopedLernaList.map((lerna) => {
27+
const isTaggedRelease = lerna.name === taggedRelease?.name;
28+
if (isTaggedRelease && taggedRelease.version.split("-")[0] !== lerna.version) {
3029
throw new Error(
3130
`Cowardly refusing to publish ${lerna.name}@${versionFromRef} from ${lerna.version}, version needs to be bumped in source.`,
3231
);
3332
}
34-
const newVersion = useVersionFromRef ? versionFromRef : `${lerna.version}-canary.${shortSHA}`;
33+
const newVersion = isTaggedRelease ? taggedRelease.version : `${lerna.version}-canary.${shortSHA}`;
3534
const registry = wombatDressingRoomTokens.get(lerna.name)
3635
? `https://wombat-dressing-room.appspot.com/${lerna.name}/_ns`
3736
: "https://registry.npmjs.org";
38-
const tag = useVersionFromRef ? (prerelease ? "next" : "latest") : "canary";
37+
const tag = isTaggedRelease ? taggedRelease.tag : "canary";
3938
const packageJsonPath = join(lerna.location, "package.json");
4039
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
4140
packageJson.version = newVersion;

scripts/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#! /usr/bin/env node
22
const { spawn } = require("child_process");
3-
const { lernaScopeArgs } = require("./github.js");
3+
const { lernaScopes } = require("./github.js");
44

5-
const testProcess = spawn("lerna", ["run", "test", "--verbose", "--no-bail", ...lernaScopeArgs], {
5+
const testProcess = spawn("lerna", ["run", "test", "--verbose", "--no-bail", ...lernaScopes], {
66
stdio: "inherit",
77
});
88
testProcess.on("close", (code) => {

0 commit comments

Comments
 (0)