Keep a lockfile-less site with a root index.html off the Node SDK - #999
Open
Ref34t wants to merge 1 commit into
Open
Keep a lockfile-less site with a root index.html off the Node SDK#999Ref34t wants to merge 1 commit into
Ref34t wants to merge 1 commit into
Conversation
Ref34t
force-pushed
the
static-site-detection
branch
from
July 28, 2026 08:10
f5d2237 to
607c476
Compare
Ref34t
force-pushed
the
static-site-detection
branch
2 times, most recently
from
July 28, 2026 08:21
171242a to
b943f01
Compare
…l off the Node SDK javascript_web requires a committed lockfile and javascript_node matches any package.json, so a browser-only project whose lockfile is not committed falls through to the Node integration and the run installs the server SDK. Add one branch, reached only after the existing lockfile check declines, that claims the project when index.html sits in the ROOT and no server framework is in dependencies. Root-only matters: the existing hasIndexHtml helper globs six levels deep, which is fine alongside a lockfile and far too loose deciding alone, and would pull in a Node library with a docs/index.html. dependencies and not devDependencies, since a static site may keep a server around to preview itself locally. Sites whose index.html lives under public/ or dist/ are left to javascript_node: without a lockfile that shape is indistinguishable from a server's asset directory. A site with no package.json at all also stays unclaimed, since PostHog/posthog.com#18390 routes those users to the JS snippet from the docs. Both limits are pinned as tests. Refs PostHog#870
Ref34t
force-pushed
the
static-site-detection
branch
from
July 28, 2026 08:28
b943f01 to
3f6de12
Compare
Ref34t
marked this pull request as ready for review
July 28, 2026 08:34
5 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Found while looking at #870. It isn't the discoverability problem that issue reports — PostHog/posthog.com#18390 covers that — it's a separate defect in the same corner of detection.
Problem
javascript_webrequires a committed lockfile.javascript_nodematches anypackage.json. So a browser-only project whose lockfile isn't committed falls past the web integration and gets picked up by the Node one.Reproducing against
detectFrameworkonmain:index.html+package.json+ lockfilejavascript_webindex.html+package.json, no lockfilejavascript_nodeIn the second case the run installs
posthog-nodeand instruments a server that doesn't exist. Nothing errors, so there's no prompt telling the user to correct it.What changed
One new branch in
javascript_web'sdetect(), reached only after the existinghasLockfile && (indexHtml || bundler)check has already declined. Nothing that matches today stops matching — this can only add matches.With no lockfile, claim the project when both hold:
index.htmlis in the project root.dependencies(express,fastify,koa,@nestjs/core, hapi,restify,h3).dependenciesand notdevDependencies, because a static site may well keep a server around to preview itself locally, and that shouldn't read as a backend.Why root-only
Reusing the existing
hasIndexHtmlhelper here is wrong. It globs**/index.htmlsix levels deep, which is fine when a lockfile is corroborating it and much too loose when it's deciding alone:**/index.htmldocs/index.htmljavascript_web✗javascript_node✓honoserver +public/index.htmljavascript_web✗javascript_node✓index.htmljavascript_web✓javascript_web✓Root-only carries most of the weight, which is the point: the fix doesn't depend on the server list being complete.
honoisn't on that list and is handled correctly anyway, because itsindex.htmlis underpublic/. The list is a second guard for a server with a rootindex.html, so an omission from it is a small miss rather than a misroute.What it doesn't cover
A site whose
index.htmllives underpublic/ordist/is still routed tojavascript_node. Without a lockfile there's nothing separating that shape from a server's asset directory, and the wrong guess there is the same wrong guess this PR is fixing. So it's left alone deliberately rather than covered by a heuristic I can't defend. Pinned as a test so the limit is visible rather than surprising.Also unchanged: a site with no
package.jsonat all stays unclaimed. Routing those users to the JS snippet from the docs, as PostHog/posthog.com#18390 does, is a better answer than the wizard adopting static sites. Also pinned, with a pointer to that PR.Tests
Nine in
framework.test.ts, seven of them negatives: thedocs/andpublic/cases above, express independenciesagainstdevDependencies, a Node project with no frontend signal, and the existing lockfile path unchanged.Refs #870, PostHog/posthog.com#18390