Open-source SEO, GEO, and marketing skills for AI agents.
build(release): dereference standalone symlinks so npm pack ships a runnable tarball
Yuting Zhongd69df65d76af
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex e81f1d40..b008e15e 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -3,7 +3,8 @@ name: Releaseon:push:tags:- - 'v*'+ - 'v[0-9]+.[0-9]+.[0-9]+'+ - 'v[0-9]+.[0-9]+.[0-9]+-*'permissions:contents: readdiff --git a/.gitignore b/.gitignoreindex c10d7221..b95e255f 100644--- a/.gitignore+++ b/.gitignore@@ -18,3 +18,6 @@ tsconfig.tsbuildinfo# Local data dir if symlinked into repo for dev.notfair-cmo-dev/++# npm pack artifacts (release.yml builds these in CI; not for git)+*.tgzdiff --git a/next-env.d.ts b/next-env.d.tsindex c4b7818f..9edff1c7 100644--- a/next-env.d.ts+++ b/next-env.d.ts@@ -1,6 +1,6 @@/// <reference types="next" />/// <reference types="next/image-types/global" />-import "./.next/dev/types/routes.d.ts";+import "./.next/types/routes.d.ts";// NOTE: This file should not be edited// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.diff --git a/scripts/copy-standalone-assets.mjs b/scripts/copy-standalone-assets.mjsindex 6ed2d1dd..c1c056f5 100644--- a/scripts/copy-standalone-assets.mjs+++ b/scripts/copy-standalone-assets.mjs@@ -3,9 +3,17 @@// include `.next/static/` or `public/` so they can be served from a CDN in// production. We ship as a local-first npm package, so we copy them into the// standalone tree where `server.js` will serve them automatically.+//+// We also dereference every symlink under .next/standalone/. With pnpm, the+// standalone tree is full of symlinks into .pnpm/<pkg>@<ver>/... and+// .next/node_modules/<pkg>-<hash> aliases that Turbopack emits for externals.+// `npm pack` drops these symlinks, so the published tarball can't resolve+// modules like better-sqlite3. Replacing them with real copies makes the+// tarball self-contained at the cost of some size.-import { existsSync, cpSync } from "node:fs";-import { dirname, join } from "node:path";+import { existsSync, cpSync, lstatSync, readdirSync, realpathSync, rmSync, renameSync } from "node:fs";+import { execSync } from "node:child_process";+import { basename, dirname, join } from "node:path";import { fileURLToPath } from "node:url";const __dirname = dirname(fileURLToPath(import.meta.url));@@ -27,3 +35,46 @@ for (const { src, dest } of targets) {cpSync(src, dest, { recursive: true });console.log(`Copied ${src.replace(ROOT + "/", "")} → ${dest.replace(ROOT + "/", "")}`);}++// Dereference symlinks in-place so npm pack ships real files. We use `cp -RL`+// via the system shell because Node's cpSync has trouble with the pnpm-style+// symlink layout (multiple symlinks pointing into the same .pnpm dir create+// cpSync EISDIR errors).+const DEREF = STANDALONE + ".deref-tmp";+rmSync(DEREF, { recursive: true, force: true });+const parent = dirname(STANDALONE);+const standaloneName = basename(STANDALONE);+// `cp -RL` exits 1 on any dangling symlink it encounters (pnpm sometimes+// leaves a `.pnpm/node_modules/semver` symlink with no target). The copy+// still completes successfully — the dangling entry is just dropped. We+// verify the result via countSymlinks() below rather than relying on cp's+// exit code.+try {+ execSync(`cp -RL "${standaloneName}" "${basename(DEREF)}"`, { cwd: parent, stdio: "inherit" });+} catch (err) {+ if (!existsSync(DEREF)) throw err;+}+rmSync(STANDALONE, { recursive: true, force: true });+renameSync(DEREF, STANDALONE);+console.log(`Dereferenced symlinks under ${STANDALONE.replace(ROOT + "/", "")}`);++// Sanity check: there should be no symlinks left in standalone after dereferencing.+const remaining = countSymlinks(STANDALONE);+if (remaining > 0) {+ console.warn(`Warning: ${remaining} symlinks still present under .next/standalone/`);+}++function countSymlinks(dir) {+ let count = 0;+ const entries = readdirSync(dir, { withFileTypes: true });+ for (const entry of entries) {+ const p = join(dir, entry.name);+ const st = lstatSync(p);+ if (st.isSymbolicLink()) {+ count += 1;+ } else if (st.isDirectory()) {+ count += countSymlinks(p);+ }+ }+ return count;+}