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
5 changes: 5 additions & 0 deletions packages/liveblocks-server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## vNEXT (not yet released)

## v1.7.0

- Add `--skip-install` (`-s`) flag to `liveblocks upgrade` to update
`package.json` and the lockfile without installing dependencies.

## v1.6.2

- Fix route parity
Expand Down
2 changes: 1 addition & 1 deletion packages/liveblocks-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@liveblocks/server",
"version": "1.6.2",
"version": "1.7.0",
"description": "Liveblocks backend server foundation.",
"type": "module",
"main": "./dist/index.js",
Expand Down
63 changes: 60 additions & 3 deletions scripts/for-all-examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,37 @@ err () {
}

usage () {
err "usage: for-all-examples.sh [-qfh] [-c <shell-cmd>] <cmd> [<arg1> [<arg2> ...]]"
err "usage: for-all-examples.sh [-pqfh] [-c <shell-cmd>] <cmd> [<arg1> [<arg2> ...]]"
err
err "Runs the given script inside all of our examples directories."
err
err "Options:"
err "-p Run up to 8 commands in parallel and buffer their output"
err "-q Don't print the current directory"
err "-f Continue, even after an error occurs"
err "-c Run command with \`sh -c\` instead"
err "-h Show this help"
}

cmd=
parallel=0
quiet=0
force=0
while getopts qc:fh flag; do
while getopts pqc:fh flag; do
case "$flag" in
c) cmd="$OPTARG" ; ;;
p) parallel=1 ; ;;
q) quiet=1 ; ;;
f) force=1 ; ;;
*) usage; exit 2;;
esac
done
shift $(($OPTIND - 1))

for dir in $(find examples starter-kits -maxdepth 1 -type d | grep -Ee /); do
run_in_dir () {
dir="$1"
shift

if [ $quiet -eq 0 ]; then
err
err "==> In $dir"
Expand All @@ -62,4 +68,55 @@ for dir in $(find examples starter-kits -maxdepth 1 -type d | grep -Ee /); do
set -e
fi
) )
}

if [ $parallel -eq 0 ]; then
for dir in $(find examples starter-kits -maxdepth 1 -type d | grep -Ee /); do
run_in_dir "$dir" "$@"
done
exit
fi

output_dir="$(mktemp -d)"
trap 'rm -r "$output_dir"' 0
trap 'exit 1' 1 2 15

jobs=
active_jobs=0
output_index=0

flush_jobs () {
failed=0

for job in $jobs; do
pid="${job%%:*}"
output_file="${job#*:}"

if ! wait "$pid"; then
failed=1
fi

cat "$output_file"
rm "$output_file"
done

jobs=
active_jobs=0
return "$failed"
}

for dir in $(find examples starter-kits -maxdepth 1 -type d | grep -Ee /); do
output_file="$output_dir/$output_index"
run_in_dir "$dir" "$@" > "$output_file" 2>&1 &
jobs="$jobs $!:$output_file"
active_jobs=$((active_jobs + 1))
output_index=$((output_index + 1))

if [ $active_jobs -eq 8 ]; then
flush_jobs
fi
done

if [ $active_jobs -gt 0 ]; then
flush_jobs
fi
9 changes: 6 additions & 3 deletions scripts/upgrade-examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,25 @@ err () {
}

usage () {
err "usage: upgrade-examples.sh [<version>]"
err "usage: upgrade-examples.sh [-s] [<version>]"
err
err "Upgrades all the example projects by bumping the Liveblocks dependencies"
err "to the given version. If not provided, uses the latest version."
err
err "Options:"
err "-s Skip installing dependencies"
err "-h Show this help"
}

while getopts h flag; do
upgrade_options=
while getopts sh flag; do
case "$flag" in
s) upgrade_options="--skip-install" ; ;;
*) usage; exit 2;;
esac
done
shift $(($OPTIND - 1))

VERSION="${1:-latest}"

scripts/for-all-examples.sh -c "pnpm dlx liveblocks@latest upgrade $VERSION" -f
scripts/for-all-examples.sh -p -c "pnpm dlx liveblocks@latest upgrade $upgrade_options $VERSION" -f
2 changes: 1 addition & 1 deletion tools/liveblocks-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "liveblocks",
"version": "1.6.2",
"version": "1.7.0",
"description": "Liveblocks command line interface",
"type": "module",
"bin": {
Expand Down
42 changes: 36 additions & 6 deletions tools/liveblocks-cli/src/upgrade/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,23 @@ function detectPackageManager(): "yarn" | "pnpm" | "bun" | "npm" {
return "npm";
}

export function getSkipInstallArgs(
packageManager: "yarn" | "pnpm" | "bun" | "npm"
): string[] {
switch (packageManager) {
case "yarn":
return ["--mode=update-lockfile"];
case "npm":
return ["--package-lock-only"];
case "pnpm":
case "bun":
return ["--lockfile-only"];
}
}

type Options = {
help: boolean;
"skip-install": boolean;
};

const upgrade: SubCommand = {
Expand All @@ -100,7 +115,10 @@ const upgrade: SubCommand = {
run(argv) {
const { options, args } = parseArgs<Options>(
argv,
{ help: { type: "boolean", short: "h", default: false } },
{
help: { type: "boolean", short: "h", default: false },
"skip-install": { type: "boolean", short: "s", default: false },
},
{ allowPositionals: true }
);

Expand All @@ -113,7 +131,8 @@ const upgrade: SubCommand = {
console.log(' version Target version or tag (default: "latest")');
console.log();
console.log("Options:");
console.log(" --help, -h Show this help message");
console.log(" --skip-install, -s Update package.json and the lockfile without installing packages"); // prettier-ignore
console.log(" --help, -h Show this help message");
return;
}

Expand Down Expand Up @@ -154,6 +173,9 @@ const upgrade: SubCommand = {

// Detect package manager
const pm = detectPackageManager();
const skipInstallArgs = options["skip-install"]
? getSkipInstallArgs(pm)
: [];
let installCmd: string;
let uninstallCmd: string;

Expand All @@ -175,16 +197,24 @@ const upgrade: SubCommand = {

// Uninstall renamed packages first
if (depsToUninstall.length > 0) {
execFileSync(pm, [uninstallCmd, ...depsToUninstall], {
stdio: "inherit",
});
execFileSync(
pm,
[uninstallCmd, ...skipInstallArgs, ...depsToUninstall],
{
stdio: "inherit",
}
);
}

// Install/upgrade packages
if (depsToUpgrade.length > 0) {
execFileSync(
pm,
[installCmd, ...depsToUpgrade.map((dep) => `${dep}@${version}`)],
[
installCmd,
...skipInstallArgs,
...depsToUpgrade.map((dep) => `${dep}@${version}`),
],
{ stdio: "inherit" }
);
}
Expand Down
17 changes: 16 additions & 1 deletion tools/liveblocks-cli/test/upgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,22 @@

import { describe, expect, test } from "bun:test";

import { highestVersion } from "~/upgrade/index";
import { getSkipInstallArgs, highestVersion } from "~/upgrade/index";

describe("getSkipInstallArgs", () => {
test("uses npm's package lock option", () => {
expect(getSkipInstallArgs("npm")).toEqual(["--package-lock-only"]);
});

test("uses pnpm and Bun's lockfile option", () => {
expect(getSkipInstallArgs("pnpm")).toEqual(["--lockfile-only"]);
expect(getSkipInstallArgs("bun")).toEqual(["--lockfile-only"]);
});

test("uses Yarn's update-lockfile mode", () => {
expect(getSkipInstallArgs("yarn")).toEqual(["--mode=update-lockfile"]);
});
});

describe("pickHighestVersion", () => {
// Simulates: npm view @liveblocks/core@latest version --json
Expand Down
Loading