Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"workspaces": [
"packages/@apphosting/*",
"packages/create-next-on-firebase/*",
"packages/create-next-on-firebase",
"packages/firebase-frameworks"
],
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/@apphosting/adapter-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
],
"license": "Apache-2.0",
"dependencies": {
"@apphosting/common": "^0.0.2",
"@apphosting/common": "*",
"firebase-functions": "^4.3.1",
"fs-extra": "^11.1.1",
"strip-ansi": "^7.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@apphosting/adapter-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
],
"license": "Apache-2.0",
"dependencies": {
"@apphosting/common": "^0.0.2",
"@apphosting/common": "*",
"fs-extra": "^11.1.1",
"yaml": "^2.3.4"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/@apphosting/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
],
"license": "Apache-2.0",
"dependencies": {
"@apphosting/discover": "*",
"colorette": "^2.0.20",
"commander": "^11.1.0",
"npm-pick-manifest": "^9.0.0",
"ts-node": "^10.9.1",
"@apphosting/discover": "*"
"ts-node": "^10.9.1"
},
"devDependencies": {
"@types/commander": "*"
Expand Down
2 changes: 1 addition & 1 deletion packages/@apphosting/discover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"commander": "^11.1.0",
"fs-extra": "^11.1.1",
"npm-pick-manifest": "^9.0.0",
"ts-node": "^10.9.1",
"toml": "^3.0.0",
"ts-node": "^10.9.1",
"yaml": "^2.3.4"
},
"devDependencies": {
Expand Down
6 changes: 4 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#! /usr/bin/env node
const { spawn } = require("child_process");
const { lernaScopeArgs } = require("./github.js");
const { lernaScopes } = require("./github.js");

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

buildProcess.on("close", (code) => {
process.exit(code);
Expand Down
49 changes: 28 additions & 21 deletions scripts/github.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node
const { execSync } = require("child_process");

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

const since = process.env.GITHUB_ACTION
Expand All @@ -10,34 +10,41 @@ const since = process.env.GITHUB_ACTION
}`
: "";

const lernaList = JSON.parse(
execSync(
`lerna list --json --include-dependencies --include-dependents ${
packageFromRef ? `--scope='{,*/}${packageFromRef}'` : since
}`,
{ stdio: ["ignore", "pipe", "ignore"] },
).toString(),
);
const lernaList = JSON.parse(execSync("lerna list --json --loglevel silent"));

const ref = process.env.GITHUB_SHA ?? "HEAD";
const shortSHA = execSync(`git rev-parse --short ${ref}`).toString().trim();

const filteredLernaList = lernaList.filter((lerna) => {
if (lerna.private) return false;
return true;
});
const scopedLernaList = JSON.parse(
execSync(
`lerna list --json --no-private --toposort --loglevel silent --include-dependents ${
packagePatternFromRef ? `--scope='{,*/}${packagePatternFromRef}'` : since
}`,
),
);

if (packageFromRef && filteredLernaList.length === 0) {
throw new Error(`Lerna didn't find ${packageFromRef} in this workspace`);
const packagesFromRef =
packagePatternFromRef &&
JSON.parse(
execSync(
`lerna list --json --no-private --loglevel silent --scope='{,*/}${packagePatternFromRef}'`,
),
);
if (packagePatternFromRef && packagesFromRef.length !== 1) {
throw new Error(`Tag pattern matched more than one package...`);
}
const packageFromRef = packagesFromRef?.[0].name;

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

module.exports = {
packageFromRef,
versionFromRef,
prerelease: !packageFromRef || !!prerelease,
filteredLernaList,
taggedRelease: packageFromRef && {
name: packageFromRef,
version: versionFromRef,
tag: prereleaseFromRef ? "next" : "latest",
},
lernaList,
scopedLernaList,
shortSHA,
lernaScopeArgs,
lernaScopes,
};
51 changes: 40 additions & 11 deletions scripts/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
const { execSync } = require("child_process");
const { writeFileSync, readFileSync } = require("fs");
const { join } = require("path");
const { filteredLernaList, versionFromRef, shortSHA, prerelease } = require("./github.js");
const {
scopedLernaList,
lernaList,
versionFromRef,
shortSHA,
taggedRelease,
} = require("./github.js");

const wombatDressingRoomTokens = new Map([
// ['firebase-frameworks', process.env.FIREBASE_FRAMEWORKS_NPM_TOKEN],
Expand All @@ -17,21 +23,44 @@ wombatDressingRoomTokens.forEach((token, pkg) => {
});
});

for (const lerna of filteredLernaList) {
if (versionFromRef && versionFromRef.split("-")[0] !== lerna.version) {
const packagesToPublish = scopedLernaList.map((lerna) => {
const isTaggedRelease = lerna.name === taggedRelease?.name;
if (isTaggedRelease && taggedRelease.version.split("-")[0] !== lerna.version) {
throw new Error(
`Cowardly refusing to publish ${lerna.name}@${versionFromRef} from ${lerna.version}, version needs to be bumped in source.`,
);
}
const version = versionFromRef || `${lerna.version}-canary.${shortSHA}`;
const cwd = lerna.location;
const tag = versionFromRef ? (prerelease ? "next" : "latest") : "canary";
const packageJsonPath = join(lerna.location, "package.json");
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
packageJson.version = version;
writeFileSync(packageJsonPath, JSON.stringify(packageJson, undefined, 2));
const newVersion = isTaggedRelease
? taggedRelease.version
: `${lerna.version}-canary.${shortSHA}`;
const registry = wombatDressingRoomTokens.get(lerna.name)
? `https://wombat-dressing-room.appspot.com/${lerna.name}/_ns`
: "https://registry.npmjs.org";
execSync(`npm publish --registry ${registry} --access public --tag ${tag} --provenance`, { cwd });
const tag = isTaggedRelease ? taggedRelease.tag : "canary";
const packageJsonPath = join(lerna.location, "package.json");
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
packageJson.version = newVersion;
packageJson.publishConfig = { tag, registry, provenance: true, access: "public" };
return packageJson;
});

for (const package of packagesToPublish) {
for (const dependencyName in package.dependencies) {
// for/in needs an if to make lint happy
if (dependencyName) {
const lernaDependency = lernaList.find((it) => it.name === dependencyName);
if (lernaDependency) {
const dependencyBeingPublished = packagesToPublish.find((it) => it.name === dependencyName);
const dependencyVersion = dependencyBeingPublished?.version || lernaDependency.version;
const dependencyPrerelease = dependencyVersion.includes("-");
package.dependencies[dependencyName] = dependencyPrerelease
? dependencyVersion
: `^${dependencyVersion}`;
}
}
}
const { location } = lernaList.find((it) => it.name === package.name);
const packageJsonPath = join(location, "package.json");
writeFileSync(packageJsonPath, JSON.stringify(package, undefined, 2));
execSync(`npm publish`, { cwd: location });
}
4 changes: 2 additions & 2 deletions scripts/test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#! /usr/bin/env node
const { spawn } = require("child_process");
const { lernaScopeArgs } = require("./github.js");
const { lernaScopes } = require("./github.js");

const testProcess = spawn("lerna", ["run", "test", "--verbose", "--no-bail", ...lernaScopeArgs], {
const testProcess = spawn("lerna", ["run", "test", "--verbose", "--no-bail", ...lernaScopes], {
stdio: "inherit",
});
testProcess.on("close", (code) => {
Expand Down
Loading