-
-
Notifications
You must be signed in to change notification settings - Fork 755
Expand file tree
/
Copy pathpatch-lib0.sh
More file actions
executable file
·98 lines (77 loc) · 3.03 KB
/
Copy pathpatch-lib0.sh
File metadata and controls
executable file
·98 lines (77 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
#
# Regenerates the pnpm patch for lib0 from a local build.
#
# Usage:
# ./scripts/patch-lib0.sh [path-to-lib0]
#
# Defaults to ../lib0 relative to this repo root.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
BLOCKNOTE_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
LOCAL_LIB0="${1:-$(cd "$BLOCKNOTE_ROOT/../lib0" && pwd)}"
if [[ ! -d "$LOCAL_LIB0/src" ]]; then
echo "ERROR: Cannot find lib0 at $LOCAL_LIB0"
echo "Pass the path as an argument: $0 /path/to/lib0"
exit 1
fi
echo "==> Using local lib0 at: $LOCAL_LIB0"
echo "==> BlockNote root: $BLOCKNOTE_ROOT"
# 0. Build lib0 so dist/ is up to date
echo "==> Building lib0 (npm run dist) ..."
(cd "$LOCAL_LIB0" && npm run dist)
# Best-effort cleanup of any leftover patch dir (case-insensitive FS resolves this fine).
STALE_PATCH_DIR="$BLOCKNOTE_ROOT/node_modules/.pnpm_patches/lib0@1.0.0-rc.14"
# 1. Clean up any leftover patch dir, then start fresh
if [[ -d "$STALE_PATCH_DIR" ]]; then
echo "==> Cleaning up old patch dir ..."
rm -rf "$STALE_PATCH_DIR"
fi
echo "==> Running pnpm patch lib0@1.0.0-rc.14 ..."
cd "$BLOCKNOTE_ROOT"
# Capture pnpm's reported patch dir so we use the canonical on-disk path casing.
# Constructing PATCH_DIR manually breaks on macOS when the repo is entered via a
# differently-cased path (e.g. blockNote vs BlockNote): pnpm patch-commit matches
# the path against state.json case-sensitively and fails with ERR_PNPM_INVALID_PATCH_DIR.
PATCH_OUTPUT="$(pnpm patch lib0@1.0.0-rc.14)"
echo "$PATCH_OUTPUT"
PATCH_DIR="$(printf '%s\n' "$PATCH_OUTPUT" | grep -Eo '/.*/\.pnpm_patches/lib0@1\.0\.0-rc\.14' | head -n1)"
if [[ -z "$PATCH_DIR" || ! -d "$PATCH_DIR" ]]; then
echo "ERROR: Could not determine patch dir from 'pnpm patch' output"
exit 1
fi
echo "==> Patch temp dir: $PATCH_DIR"
# 2. Replace src/ with local build
echo "==> Replacing src/ ..."
rm -rf "$PATCH_DIR/src"
cp -R "$LOCAL_LIB0/src" "$PATCH_DIR/src"
# 3. Replace dist/ with local build (.d.ts files)
echo "==> Replacing dist/ ..."
rm -rf "$PATCH_DIR/dist"
cp -R "$LOCAL_LIB0/dist" "$PATCH_DIR/dist"
# 4. Update package.json in the patch dir
echo "==> Updating package.json ..."
node -e "
const fs = require('fs');
const orig = JSON.parse(fs.readFileSync('$PATCH_DIR/package.json', 'utf8'));
const local = JSON.parse(fs.readFileSync('$LOCAL_LIB0/package.json', 'utf8'));
// Keep the original version so pnpm doesn't try to fetch a different version from registry
orig.version = '1.0.0-rc.14';
// Update exports
orig.exports = local.exports;
// Update files list
orig.files = local.files;
// Update type/sideEffects if present
if (local.type) orig.type = local.type;
if ('sideEffects' in local) orig.sideEffects = local.sideEffects;
// Update bin if present
if (local.bin) orig.bin = local.bin;
fs.writeFileSync('$PATCH_DIR/package.json', JSON.stringify(orig, null, 2) + '\n');
console.log(' package.json updated');
"
# 5. Commit the patch
echo ""
echo "==> Running pnpm patch-commit ..."
pnpm patch-commit "$PATCH_DIR"
echo ""
echo "==> Done! Patch regenerated at patches/lib0@1.0.0-rc.14.patch"