Skip to content

Commit b5d4923

Browse files
justin808claude
andcommitted
Merge PR #2078: Improve node-renderer package structure
Merges judahmeek/move-node-renderer-package-json branch which contains significant improvements to the node-renderer package configuration and build system. Key improvements: **Package Structure:** - Added proper ES module exports map for main package and integrations - Added resolutions for problematic sentry-testkit dependencies - Moved from versioned dependencies to file references for workspace packages - Removed duplicate/obsolete package.json and tsconfig.json files **Dependencies:** - Cleaned up devDependencies, removing many unused ESLint/Babel packages - Added missing test dependencies (@jest/globals, babel-jest, etc.) - Uses file: protocol for react-on-rails dependency for better monorepo support **Build & Scripts:** - Updated package-scripts.yml to support multiple output files (ReactOnRails.full.js OR ReactOnRailsProNodeRenderer.js) - Moved scripts to use nps consistently - Added preinstall.js script to node-renderer package **Knip Configuration:** - Removed many unused ignoreDependencies entries - Updated entry points to use glob for integrations/* - Added ignoreExportsUsedInFile: true for better accuracy - Cleaned up test fixture ignores **Code Quality:** - Removed import attributes syntax for better compatibility - Updated test imports to use relative paths - Exposed additional types for integrations API - Added @internal tags for test-only exports **CI/Workflow:** - Updated pro-test-package-and-gem.yml to use yarn run consistently - Updated ci-changes-detector to trigger pro tests on react-on-rails changes - Updated playwright.yml for consistency This merge preserves git history by moving react_on_rails_pro/package.json to become the node-renderer package.json, then applying improvements. Co-authored-by: Judah Meek <[email protected]> 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
2 parents c17ee4c + 882baf1 commit b5d4923

37 files changed

+643
-2051
lines changed

.github/workflows/playwright.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ jobs:
7878

7979
- name: Build test assets
8080
working-directory: spec/dummy
81-
run: yarn build:test
81+
run: yarn run build:test
8282

8383
- name: Run Playwright tests
8484
working-directory: spec/dummy
85-
run: yarn test:e2e
85+
run: yarn run test:e2e
8686

8787
- uses: actions/upload-artifact@v4
8888
if: always()

.github/workflows/pro-test-package-and-gem.yml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -218,29 +218,14 @@ jobs:
218218
path: react_on_rails_pro/node_modules
219219
key: v4-pro-package-node-modules-cache-${{ hashFiles('react_on_rails_pro/yarn.lock') }}
220220

221-
- name: Remove old webpack bundles
222-
run: |
223-
rm -rf spec/dummy/public/webpack
224-
rm -rf spec/dummy/ssr-generated
225-
226-
- id: get-sha
227-
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
228-
229-
- name: Restore test webpack bundles from cache
230-
uses: actions/cache@v4
231-
with:
232-
path: |
233-
react_on_rails_pro/spec/dummy/public/webpack/test
234-
react_on_rails_pro/spec/dummy/ssr-generated
235-
key: v4-pro-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }}
236-
237221
- name: Install Node modules with Yarn for Pro package
222+
working-directory: packages/react-on-rails-pro-node-renderer
238223
run: |
239224
sudo yarn global add yalc
240225
yarn install --frozen-lockfile --no-progress --no-emoji
241226
242227
- name: Run JS unit tests for Pro package
243-
run: yarn run nps test.ci
228+
run: yarn workspace react-on-rails-pro-node-renderer run ci
244229
env:
245230
JEST_JUNIT_OUTPUT_DIR: ./jest
246231
JEST_JUNIT_ADD_FILE_ATTRIBUTE: "true"
@@ -250,10 +235,10 @@ jobs:
250235
if: always()
251236
with:
252237
name: pro-jest-results
253-
path: react_on_rails_pro/jest
238+
path: packages/react-on-rails-pro-node-renderer/jest
254239

255240
# RSpec tests for Pro package
256-
rspec-package-specs:
241+
rspec-gem-specs:
257242
needs: detect-changes
258243
if: |
259244
!(

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ node_modules/
22
package.json
33
# Exclude pro package (has its own formatting)
44
react_on_rails_pro/
5+
packages/react-on-rails-pro-node-renderer/tests/fixtures/projects
56
tmp/
67
coverage/
78
**/app/assets/webpack/

knip.ts

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,6 @@ const config: KnipConfig = {
3939
// SWC transpiler dependencies used in dummy apps
4040
'@swc/core',
4141
'swc-loader',
42-
// Test dependencies used by child workspaces (packages/react-on-rails, packages/react-on-rails-pro)
43-
'@testing-library/dom',
44-
'@testing-library/jest-dom',
45-
'@testing-library/react',
46-
'@types/react-dom',
47-
'create-react-class',
48-
'jest-fetch-mock',
49-
'prop-types',
50-
'react',
51-
'react-dom',
52-
'redux',
5342
],
5443
},
5544

@@ -70,8 +59,7 @@ const config: KnipConfig = {
7059
entry: [
7160
'src/ReactOnRailsProNodeRenderer.ts!',
7261
'src/default-node-renderer.ts!',
73-
'src/master.ts!',
74-
'src/worker.ts!',
62+
'src/integrations/*.ts!',
7563
],
7664
project: ['src/**/*.[jt]s{x,}!', 'tests/**/*.[jt]s{x,}', '!lib/**'],
7765
ignore: [
@@ -84,11 +72,9 @@ const config: KnipConfig = {
8472
'tests/httpRequestUtils.ts',
8573
],
8674
ignoreDependencies: [
87-
// These are runtime dependencies needed for the package to work
88-
// even though they may not be directly imported in the source
89-
'react-on-rails-pro',
90-
// Dev dependencies used only in tests
75+
// Optional dependencies used in integrations
9176
'@honeybadger-io/js',
77+
'@sentry/*',
9278
],
9379
},
9480

@@ -125,11 +111,6 @@ const config: KnipConfig = {
125111
'src/RSCRoute.tsx:RSCRouteProps',
126112
'src/streamServerRenderedReactComponent.ts:StreamingTrackers',
127113
],
128-
ignoreDependencies: [
129-
// Test dependencies used only in tests
130-
'@types/mock-fs',
131-
'mock-fs',
132-
],
133114
},
134115
'spec/dummy': {
135116
entry: [
@@ -192,18 +173,10 @@ const config: KnipConfig = {
192173
// Dependencies not detected in production mode (runtime injected or dynamic imports)
193174
'@babel/runtime',
194175
'mini-css-extract-plugin',
195-
'css-loader',
196-
'sass',
197-
'sass-loader',
198-
// Dependencies used dynamically by React on Rails
199-
'create-react-class',
200-
'react-helmet',
201-
'@types/react-helmet',
202-
'react-redux',
203-
'react-router-dom',
204176
],
205177
},
206178
},
179+
ignoreExportsUsedInFile: true,
207180
};
208181

209182
export default config;

package-scripts.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
scripts:
2+
test:
3+
default:
4+
description: Run all JS tests
5+
script: jest
6+
ci:
7+
description: Run all JS tests in CI mode
8+
# https://circleci.com/docs/collect-test-data/#jest
9+
script: jest --ci --runInBand --reporters=default --reporters=jest-junit
10+
debug:
11+
description: Debug all JS tests
12+
script: ndb jest --runInBand
13+
check:
14+
description: Run all checks
15+
script: nps lint && nps format.listDifferent && nps test && nps check-typescript
16+
check-typescript:
17+
description: Check for TypeScript errors
18+
script: nps "build --noEmit" && tsc --project ../packages/react-on-rails-pro-node-renderer/tests
19+
220
lint:
321
description: Run all linters (eslint, tsc)
422
script: nps eslint
@@ -25,10 +43,10 @@ scripts:
2543
# 3. Check if the project is built now;
2644
# 4. If it failed, print an error message (still follow https://docs.npmjs.com/cli/v8/using-npm/scripts#best-practices).
2745
script: >
28-
[ -f lib/ReactOnRails.full.js ] ||
46+
[ -f lib/ReactOnRails.full.js ] || [ -f lib/ReactOnRailsProNodeRenderer.js ] ||
2947
(npm run build >/dev/null 2>&1 || true) &&
30-
[ -f lib/ReactOnRails.full.js ] ||
31-
{ echo 'Building react-on-rails seems to have failed!'; }
48+
[ -f lib/ReactOnRails.full.js ] || [ -f lib/ReactOnRailsProNodeRenderer.js ] ||
49+
{ echo 'Building this package seems to have failed!'; }
3250
3351
format:
3452
default:

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@babel/preset-react": "^7.26.3",
2121
"@babel/preset-typescript": "^7.27.1",
2222
"@eslint/compat": "^1.2.7",
23+
"@jest/globals": "^29.7.0",
2324
"@swc/core": "^1.15.0",
2425
"@testing-library/dom": "^10.4.0",
2526
"@testing-library/jest-dom": "^6.6.3",
@@ -66,10 +67,10 @@
6667
"scripts": {
6768
"test": "yarn workspaces run test",
6869
"clean": "yarn workspaces run clean",
69-
"start": "nps",
70+
"start": "yarn run nps",
7071
"build": "yarn workspace react-on-rails run build && yarn workspace react-on-rails-pro run build && yarn workspace react-on-rails-pro-node-renderer run build",
7172
"build-watch": "yarn workspaces run build-watch",
72-
"lint": "nps eslint",
73+
"lint": "yarn run nps eslint",
7374
"lint:scss": "stylelint \"spec/dummy/app/assets/stylesheets/**/*.scss\" \"spec/dummy/client/**/*.scss\"",
7475
"check": "yarn run lint && yarn workspaces run check",
7576
"type-check": "yarn workspaces run type-check",

packages/react-on-rails-pro-node-renderer/package.json

Lines changed: 81 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,61 @@
33
"version": "16.2.0-beta.11",
44
"protocolVersion": "2.0.0",
55
"description": "React on Rails Pro Node Renderer for server-side rendering",
6-
"type": "module",
7-
"main": "lib/ReactOnRailsProNodeRenderer.js",
8-
"scripts": {
9-
"build": "yarn run clean && tsc --project src",
10-
"build-watch": "yarn run clean && tsc --project src --watch",
11-
"clean": "rm -rf ./lib",
12-
"test": "jest tests",
13-
"type-check": "tsc --project src --noEmit --noErrorTruncation",
14-
"prepack": "yarn run build",
15-
"prepare": "yarn run build",
16-
"prepublishOnly": "yarn run build",
17-
"yalc:publish": "yalc publish",
18-
"yalc": "yalc"
6+
"directories": {
7+
"doc": "docs"
198
},
20-
"repository": {
21-
"type": "git",
22-
"url": "git+https://github.com/shakacode/react_on_rails.git"
9+
"exports": {
10+
".": {
11+
"types": "./lib/ReactOnRailsProNodeRenderer.d.ts",
12+
"default": "./lib/ReactOnRailsProNodeRenderer.js"
13+
},
14+
"./integrations/*": {
15+
"types": "./lib/integrations/*.d.ts",
16+
"default": "./lib/integrations/*.js"
17+
},
18+
"./package.json": "./package.json"
19+
},
20+
"resolutions": {
21+
"sentry-testkit/body-parser": "npm:[email protected]",
22+
"sentry-testkit/express": "npm:[email protected]"
2323
},
24-
"keywords": [
25-
"react",
26-
"react-on-rails",
27-
"node-renderer",
28-
"server-side-rendering",
29-
"ssr"
30-
],
31-
"author": "[email protected]",
32-
"license": "UNLICENSED",
3324
"dependencies": {
3425
"@fastify/formbody": "^7.4.0 || ^8.0.2",
3526
"@fastify/multipart": "^8.3.1 || ^9.0.3",
3627
"fastify": "^4.29.0 || ^5.2.1",
3728
"fs-extra": "^11.2.0",
3829
"jsonwebtoken": "^9.0.2",
3930
"lockfile": "^1.0.4",
40-
"pino": "^9.0.0",
41-
"pino-pretty": "^13.0.0",
42-
"react-on-rails": "16.2.0-beta.11",
43-
"react-on-rails-pro": "16.2.0-beta.11"
31+
"pino": "^9.0.0"
4432
},
4533
"devDependencies": {
34+
"@babel/core": "^7.26.10",
35+
"@babel/eslint-parser": "^7.27.0",
36+
"@babel/preset-react": "^7.26.3",
4637
"@honeybadger-io/js": "^6.10.1",
47-
"@jest/globals": "^29.7.0",
4838
"@sentry/node": "^7.120.0",
49-
"@sentry/types": "^7.120.0",
50-
"@tsconfig/node14": "^14.1.2",
5139
"@types/fs-extra": "^11.0.4",
40+
"@types/jest": "^29.5.12",
5241
"@types/jsonwebtoken": "^9.0.10",
5342
"@types/lockfile": "^1.0.4",
54-
"@types/node": "^20.0.0",
5543
"@types/touch": "^3.1.5",
44+
"babel-jest": "^29.7.0",
5645
"form-auto-content": "^3.2.1",
5746
"form-data": "^4.0.1",
47+
"jsdom": "^16.5.0",
5848
"node-html-parser": "^7.0.1",
49+
"nps": "^5.9.12",
50+
"pino-pretty": "^13.0.0",
51+
"react-on-rails": "./packages/react-on-rails",
5952
"redis": "^5.0.1",
6053
"sentry-testkit": "^5.0.6",
61-
"touch": "^3.1.0"
54+
"touch": "^3.1.0",
55+
"typescript": "^5.4.3"
6256
},
6357
"peerDependencies": {
6458
"@honeybadger-io/js": ">=4.0.0",
6559
"@sentry/node": ">=5.0.0 <9.0.0",
66-
"@sentry/tracing": ">=5.0.0",
67-
"react": ">= 16",
68-
"react-dom": ">= 16"
60+
"@sentry/tracing": ">=5.0.0"
6961
},
7062
"peerDependenciesMeta": {
7163
"@honeybadger-io/js": {
@@ -78,12 +70,60 @@
7870
"optional": true
7971
}
8072
},
81-
"files": [
82-
"lib/**/*.js",
83-
"lib/**/*.d.ts"
73+
"scripts": {
74+
"build": "yarn run clean && yarn run tsc --project src/tsconfig.json",
75+
"build-watch": "yarn run clean && yarn run tsc --watch --project src/tsconfig.json",
76+
"clean": "rm -rf ./lib",
77+
"ci": "jest --ci --runInBand --reporters=default --reporters=jest-junit",
78+
"developing": "nps node-renderer.debug",
79+
"test": "jest tests",
80+
"type-check": "yarn run tsc --noEmit --noErrorTruncation --project src/tsconfig.json",
81+
"prepack": "nps build.prepack",
82+
"prepare": "nps build.prepack",
83+
"prepublishOnly": "yarn run build",
84+
"yalc:publish": "yalc publish",
85+
"yalc": "yalc"
86+
},
87+
"repository": {
88+
"type": "git",
89+
"url": "git+https://github.com/shakacode/react_on_rails.git"
90+
},
91+
"keywords": [
92+
"react",
93+
"webpack",
94+
"JavaScript",
95+
"Ruby",
96+
"on",
97+
"Rails"
8498
],
99+
"author": "[email protected]",
100+
"license": "UNLICENSED",
85101
"bugs": {
86102
"url": "https://github.com/shakacode/react_on_rails/issues"
87103
},
88-
"homepage": "https://github.com/shakacode/react_on_rails#readme"
104+
"homepage": "https://github.com/shakacode/react_on_rails/tree/master/packages/react-on-rails-pro-node-renderer#readme",
105+
"jest": {
106+
"clearMocks": true,
107+
"moduleNameMapper": {
108+
"^(\\.{1,2}/.*)\\.js$": "$1"
109+
},
110+
"resetModules": true,
111+
"resetMocks": true,
112+
"roots": [
113+
"."
114+
],
115+
"setupFiles": [
116+
"./tests/helper.ts"
117+
],
118+
"testEnvironment": "node",
119+
"transform": {
120+
"^.+\\.[jt]sx?$": "babel-jest"
121+
}
122+
},
123+
"husky": {
124+
"hooks": {
125+
"pre-commit": "yalc check"
126+
}
127+
},
128+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
89129
}

packages/react-on-rails-pro-node-renderer/src/ReactOnRailsProNodeRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cluster from 'cluster';
2-
import fastifyPackageJson from 'fastify/package.json' with { type: 'json' };
2+
import fastifyPackageJson from 'fastify/package.json';
33
import { Config, buildConfig } from './shared/configBuilder.js';
44

55
const { version: fastifyVersion } = fastifyPackageJson;

packages/react-on-rails-pro-node-renderer/src/integrations/api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export {
3030
addNotifier,
3131
error,
3232
message,
33+
Notifier,
34+
ErrorNotifier,
35+
MessageNotifier,
3336
} from '../shared/errorReporter.js';
3437
export {
3538
setupTracing,

0 commit comments

Comments
 (0)