Repository navigation
test: check built pkgs in Node & test the Next.js server-utils #3239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4c8cf7e
test: check the built packages in plain Node, and turn the Next.js se…
YousefED 1db75b0
Merge origin/main into test/built-packages-smoke
nperez0111 37596e9
test: harden built-package consumer smoke tests
nperez0111 2b91408
test: simplify consumer harness and strengthen math assertions
nperez0111 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ node_modules | |
| .tarballs | ||
| package-lock.json | ||
| next-env.d.ts | ||
| AGENTS.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,64 +1,41 @@ | ||
| #!/bin/bash | ||
| # Packs @blocknote packages as tarballs and installs them so Next.js sees | ||
| # real files in node_modules (not symlinks) — required for serverExternalPackages. | ||
| # | ||
| # Skips pack+install if packages haven't changed since last run. | ||
| set -e | ||
| # Packs and installs into a fresh consumer directory outside the checkout. | ||
| # Usage: bash setup.sh /absolute/path/to/empty-consumer-directory | ||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| TARBALLS_DIR="$SCRIPT_DIR/.tarballs" | ||
| # Resolve the repo root (works from git worktrees too). | ||
| REPO_ROOT="$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel)" | ||
| PACKAGES_DIR="$REPO_ROOT/packages" | ||
|
|
||
| # Compute a hash of package dist directories + package.json manifests. | ||
| HASH_FILE="$TARBALLS_DIR/.packages-hash" | ||
| CURRENT_HASH=$( (find "$PACKAGES_DIR/core/dist" "$PACKAGES_DIR/react/dist" "$PACKAGES_DIR/server-util/dist" "$PACKAGES_DIR/mantine/dist" -type f 2>/dev/null | sort | xargs cat 2>/dev/null; cat "$PACKAGES_DIR/core/package.json" "$PACKAGES_DIR/react/package.json" "$PACKAGES_DIR/server-util/package.json" "$PACKAGES_DIR/mantine/package.json" 2>/dev/null) | shasum -a 256 | cut -d' ' -f1) | ||
|
|
||
| if [ -f "$HASH_FILE" ] && [ -d "$SCRIPT_DIR/node_modules/@blocknote/core" ] && [ "$(cat "$HASH_FILE")" = "$CURRENT_HASH" ]; then | ||
| echo "Tarballs up to date, skipping pack+install" | ||
| exit 0 | ||
| CONSUMER_DIR="$(cd "${1:?Pass an empty consumer directory outside the checkout}" && pwd -P)" | ||
| case "$CONSUMER_DIR/" in | ||
| "$REPO_ROOT/"*) echo "Consumer must be outside the checkout" >&2; exit 1 ;; | ||
| esac | ||
| if [ -n "$(ls -A "$CONSUMER_DIR")" ]; then | ||
| echo "Consumer directory must be empty" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| rm -rf "$TARBALLS_DIR" | ||
| mkdir -p "$TARBALLS_DIR" | ||
| # No setup cache: every run uses the current sources, manifests and tarballs. | ||
| cp -R "$SCRIPT_DIR/app" "$SCRIPT_DIR/next.config.ts" "$SCRIPT_DIR/tsconfig.json" "$SCRIPT_DIR/package.json" "$CONSUMER_DIR/" | ||
| TARBALLS_DIR="$CONSUMER_DIR/.tarballs" | ||
| mkdir "$TARBALLS_DIR" | ||
|
|
||
| # Pack each package (use pnpm pack so workspace:* refs are resolved to versions) | ||
| for pkg in core react server-util mantine; do | ||
| cd "$PACKAGES_DIR/$pkg" | ||
| pnpm pack --pack-destination "$TARBALLS_DIR" 2>/dev/null | ||
| done | ||
|
|
||
| # Update package.json to point to tarballs | ||
| # Fixed names, so that package.json does not change with the version | ||
| cd "$TARBALLS_DIR" | ||
| CORE_TGZ=$(ls blocknote-core-*.tgz) | ||
| REACT_TGZ=$(ls blocknote-react-*.tgz) | ||
| SERVER_TGZ=$(ls blocknote-server-util-*.tgz) | ||
| MANTINE_TGZ=$(ls blocknote-mantine-*.tgz) | ||
|
|
||
| cd "$SCRIPT_DIR" | ||
| cat > package.json << EOF | ||
| { | ||
| "name": "@blocknote/nextjs-test-app", | ||
| "private": true, | ||
| "version": "0.0.0", | ||
| "dependencies": { | ||
| "@blocknote/core": "file:.tarballs/$CORE_TGZ", | ||
| "@blocknote/mantine": "file:.tarballs/$MANTINE_TGZ", | ||
| "@blocknote/react": "file:.tarballs/$REACT_TGZ", | ||
| "@blocknote/server-util": "file:.tarballs/$SERVER_TGZ", | ||
| "@mantine/core": "^9.0.2", | ||
| "@mantine/hooks": "^9.0.2", | ||
| "next": "^16.0.0", | ||
| "react": "^19.2.3", | ||
| "react-dom": "^19.2.3" | ||
| } | ||
| } | ||
| EOF | ||
|
|
||
| # Install with npm (not pnpm — avoid workspace resolution) | ||
| rm -rf node_modules .next package-lock.json | ||
| npm install --ignore-scripts | ||
| for pkg in core react server-util mantine; do | ||
| mv blocknote-$pkg-*.tgz blocknote-$pkg.tgz | ||
| done | ||
|
|
||
| # Save hash for next run | ||
| echo "$CURRENT_HASH" > "$HASH_FILE" | ||
| cd "$CONSUMER_DIR" | ||
| # Install independently of the workspace, with real package directories for | ||
| # Next.js serverExternalPackages rather than pnpm's default symlink layout. | ||
| # Direct fixture dependencies are pinned. Transitives still resolve fresh: | ||
| # tarball integrity changes with every package build, so no frozen lockfile. | ||
| pnpm --ignore-workspace install --node-linker=hoisted --lockfile=false --ignore-scripts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { execFileSync } from "node:child_process"; | ||
| import { existsSync, readdirSync, readFileSync } from "node:fs"; | ||
| import { join, resolve } from "node:path"; | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| // These tests check the build output as an app installs it: in plain Node, | ||
| // without the aliases to the sources that the other tests use. They cannot find | ||
| // a missing dependency, as the workspace installs all of them (see nextjs/). | ||
| const packagesDir = resolve(__dirname, "../../../../packages"); | ||
|
|
||
| function publishedPackages() { | ||
| return readdirSync(packagesDir).flatMap((dir) => { | ||
| const path = join(packagesDir, dir, "package.json"); | ||
| if (!existsSync(path)) { | ||
| return []; | ||
| } | ||
| const pkg = JSON.parse(readFileSync(path, "utf8")); | ||
| return pkg.private ? [] : [{ dir, pkg }]; | ||
| }); | ||
| } | ||
|
|
||
| function exportTargets(exports: unknown): string[] { | ||
| if (typeof exports === "string") { | ||
| return [exports]; | ||
| } | ||
| if (exports && typeof exports === "object") { | ||
| return Object.values(exports).flatMap(exportTargets); | ||
| } | ||
| return []; | ||
| } | ||
|
|
||
| function runNode(script: string, env: Record<string, string> = {}) { | ||
| return execFileSync(process.execPath, [join(__dirname, script)], { | ||
| encoding: "utf8", | ||
| env: { ...process.env, ...env }, | ||
| timeout: 120_000, | ||
| }); | ||
| } | ||
|
|
||
| // CI runs this after `vp run -r build`. Locally, it waits for a build. | ||
| describe.skipIf(!existsSync(join(packagesDir, "core/dist")) && !process.env.CI)( | ||
| "Built packages", | ||
| () => { | ||
| it("point to files that exist", () => { | ||
| const missing = publishedPackages().flatMap(({ dir, pkg }) => | ||
| [pkg.main, pkg.module, pkg.types, ...exportTargets(pkg.exports)] | ||
| .filter((target): target is string => typeof target === "string") | ||
| .filter((target) => !existsSync(resolve(packagesDir, dir, target))) | ||
| .map((target) => `${pkg.name}: ${target}`), | ||
| ); | ||
| expect([...new Set(missing)]).toEqual([]); | ||
| }); | ||
|
|
||
| it("load in plain Node", { timeout: 60_000 }, () => { | ||
| expect(JSON.parse(runNode("loadEntries.mjs"))).toEqual([]); | ||
| }); | ||
|
|
||
| // React's development build crashed the process after the export (#3230). | ||
| it.each(["development", "production"])( | ||
| "export React and optional blocks on a server (NODE_ENV=%s)", | ||
| { timeout: 60_000 }, | ||
| (nodeEnv) => { | ||
| expect(runNode("serverExport.mjs", { NODE_ENV: nodeEnv })).toContain( | ||
| "exported", | ||
| ); | ||
| }, | ||
| ); | ||
| }, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Imports every entry of every published package from its build output, in | ||
| // plain Node (no bundler, no Vitest), and prints the entries that fail as JSON. | ||
| import { existsSync, readdirSync, readFileSync } from "node:fs"; | ||
| import { join, resolve } from "node:path"; | ||
| import { pathToFileURL } from "node:url"; | ||
|
|
||
| const packagesDir = resolve(import.meta.dirname, "../../../../packages"); | ||
|
|
||
| const failures = []; | ||
| for (const dir of readdirSync(packagesDir)) { | ||
| const packageJSONPath = join(packagesDir, dir, "package.json"); | ||
| if (!existsSync(packageJSONPath)) { | ||
| continue; | ||
| } | ||
| const pkg = JSON.parse(readFileSync(packageJSONPath, "utf8")); | ||
| if (pkg.private || !pkg.exports) { | ||
| continue; | ||
| } | ||
| for (const [subpath, target] of Object.entries(pkg.exports)) { | ||
| const file = | ||
| typeof target === "string" ? target : (target.import ?? target.default); | ||
| // Stylesheets and WebAssembly files are for bundlers, not for Node. | ||
| if (!file || !/\.m?js$/.test(file)) { | ||
| continue; | ||
| } | ||
| try { | ||
| await import(pathToFileURL(resolve(packagesDir, dir, file)).href); | ||
| } catch (error) { | ||
| failures.push({ | ||
| entry: pkg.name + subpath.slice(1), | ||
| error: String(error).split("\n")[0], | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| console.log(JSON.stringify(failures)); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 158
🏁 Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 4240
Handle string root exports before iterating entries.
If a published package declares
"exports": "./dist/index.js",Object.entries(pkg.exports)iterates the string's characters. The loader can then skip every character and report success without importing the entry. Normalize a string export to a"."entry before iterating.🐛 Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents