Skip to content

fix(plugins): resolve relative options against the bundler project root - #962

Merged
owjs3901 merged 6 commits into
mainfrom
fix/plugin-project-root
Nov 17, 2026
Merged

owjs3901 merged 6 commits into
mainfrom
fix/plugin-project-root

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

PLG-18: When a build was run from a parent directory, as turbo/nx do, the plugins resolved relative options against process.cwd(). As a result they read the wrong devup.json, wrote df to a different location, and the webpack file ids (class names) changed. Following the maintainer's decision, this PR uses the bundler/project root as the base.

cwd usages re-checked on origin/main and what was fixed

  • plugin-utils: Added resolveProjectPath(root, path) and resolveDevupFile(root, devupFile). When the root equals cwd they return the path exactly as given, so the common case (cwd = root) behaves byte-for-byte the same.
  • webpack: Moved the option normalization done in the constructor (devupFile/distDir/cssDir defaults, productionPrewarmFiles, tsconfig jsxImportSource) to apply time, based on compiler.options.context. A root option is passed to the loader so extraction ids, dependency paths and the module resolver are root-based. The plugin's canonical map, atom-hoist, numbering, prewarm, and toId/cwd/tsconfigPath in reservation.ts use the same root.
  • Rsbuild: Options and tsconfig are resolved against api.context.rootPath. The atom-hoist graph (const root = process.cwd()) and cwd/tsconfigPath in reservation.ts are also root-based now.
  • Vite: Finished what had been only partly fixed. devupFile/distDir/cssDir and tsconfig are now also resolved against config.root in configResolved. The reservation reads the latest paths through getters.
  • Next (webpack): The cssDir default and the production prewarm graph are computed against the project directory Next passes in (_options.dir). This directory is the same as the webpack context. Turbopack cannot know the project directory at the config stage, so it keeps using cwd as before (documented in the README).
  • Bun: Uses root from Bun.build if present, otherwise cwd.

Compatibility fallback

  • If the user did not set devupFile, and the project root has no devup.json but cwd does, the file in cwd is still used.
  • In that case a warning is printed only once per root. The warning contains:
    • that the file was found relative to cwd
    • that root-relative is now the default
    • how to fix it: move the file to the root or set devupFile
  • When the user sets devupFile, it is resolved only against the root, with no fallback.

Docs and changepack

  • Added a "Project root" note to the vite/webpack/rsbuild/next/bun plugin READMEs and to the landing doc devup/devup-json.
  • There is a single changepack, changepack_log_plugin_project_root.json, which bumps plugin-utils and all 5 plugins as Patch. It states that webpack/Next webpack builds run from a parent directory may see class names change once.

Overlap with other PRs

Test plan

  • Cases checked in plugin-utils/project-root.test.ts:
    • root = cwd keeps the path as is
    • root ≠ cwd resolves to an absolute path
    • absolute paths are kept as is
    • no fallback for a user-specified devupFile
    • cwd fallback, with the warning printed only once
  • Cases checked in the webpack plugin/loader/reservation tests:
    • context ≠ cwd: options, sheetFile, loader root, productionPrewarmFiles, extraction ids, dependencies, resolver
    • context = cwd: existing values kept
    • fallback and warning
  • Cases checked in the Rsbuild plugin/reservation tests: rootPath ≠ cwd, rootPath = cwd, user relative paths, fallback and warning
  • Cases checked in the Vite plugin tests: config.root ≠ cwd (including resolveId), root = cwd, user relative paths, fallback and warning
  • Cases checked in the Next plugin tests: prod/dev cssDir and the route graph based on _options.dir
  • Cases checked in the Bun plugin tests: Bun.build root, no root, fallback and warning
  • bun test --coverage (webpack/rsbuild/bun/next/plugin-utils): 4997 passed, all changed files at 100%
  • Vite suite: plugin.ts/reservation.ts at 100%
    • 3 native tests (2 in serve-coherence-prereq-native, 1 in reservation-native-boundary) fail, but they fail the same way when built from origin/main sources, so it is a local environment issue.
  • bunx tsc --noEmit -p passes for all 6 packages, prettier check passes
  • CI

요약

PLG-18: turbo/nx처럼 상위 디렉터리에서 빌드를 실행하면, 플러그인이 상대 옵션을 process.cwd() 기준으로 해석했습니다. 그 결과 엉뚱한 devup.json을 읽고, df를 다른 위치에 쓰고, webpack 파일 id(클래스 이름)가 바뀌었습니다. 이 PR은 메인테이너 결정대로 번들러/프로젝트 루트를 기준으로 삼습니다.

origin/main에서 다시 확인한 cwd 사용처와 수정 내용

  • plugin-utils: resolveProjectPath(root, path)와 resolveDevupFile(root, devupFile)를 추가했습니다. 루트가 cwd와 같으면 경로를 받은 그대로 돌려주므로, 흔한 경우(cwd = root)의 동작은 바이트 단위로 같습니다.
  • webpack: 생성자에서 하던 옵션 정규화(devupFile/distDir/cssDir 기본값, productionPrewarmFiles, tsconfig jsxImportSource)를 apply 시점의 compiler.options.context 기준으로 옮겼습니다. 로더에 root 옵션을 넘겨 추출 id, 의존성 경로, module resolver를 루트 기준으로 만듭니다. 플러그인의 canonical map, atom-hoist, numbering, prewarm 그리고 reservation.ts의 toId/cwd/tsconfigPath도 같은 루트를 씁니다.
  • Rsbuild: 옵션과 tsconfig를 api.context.rootPath 기준으로 해석합니다. atom-hoist 그래프(const root = process.cwd())와 reservation.ts의 cwd/tsconfigPath도 루트 기준으로 바꿨습니다.
  • Vite: 일부만 고쳐져 있던 부분을 마저 고쳤습니다. 이제 devupFile/distDir/cssDir와 tsconfig도 configResolved에서 config.root 기준으로 해석합니다. reservation은 getter로 최신 경로를 읽습니다.
  • Next (webpack): cssDir 기본값과 production prewarm 그래프를 Next가 넘겨주는 프로젝트 디렉터리(_options.dir) 기준으로 계산합니다. 이 디렉터리는 webpack context와 같습니다. Turbopack은 config 단계에서 프로젝트 디렉터리를 알 수 없어서 기존처럼 cwd를 씁니다(README에 적어 두었습니다).
  • Bun: Bun.build에 root가 있으면 그 경로를, 없으면 cwd를 씁니다.

호환 fallback

  • devupFile을 사용자가 지정하지 않았고, 프로젝트 루트에는 devup.json이 없지만 cwd에는 있으면 cwd의 파일을 계속 씁니다.
  • 이때 경고를 루트마다 한 번만 출력합니다. 경고에는 다음 내용이 들어갑니다.
    • cwd 기준으로 찾았다는 사실
    • 이제 루트 기준이 기본이라는 점
    • 파일을 루트로 옮기거나 devupFile을 지정하라는 해결 방법
  • 사용자가 devupFile을 지정한 경우에는 fallback 없이 루트 기준으로만 해석합니다.

문서와 changepack

  • vite/webpack/rsbuild/next/bun 플러그인 README와 랜딩 문서 devup/devup-json에 "Project root" 설명을 추가했습니다.
  • changepack은 changepack_log_plugin_project_root.json 하나이고, plugin-utils와 5개 플러그인을 모두 Patch로 올립니다. 상위 디렉터리에서 실행한 webpack/Next webpack 빌드는 클래스 이름이 한 번 바뀔 수 있다는 점을 명시했습니다.

다른 PR과 겹치는 부분

  • 열려 있는 fix(plugins): compile modern modules, resolve bundler conditions and hoist over every source root #934(PLG-13)가 같은 코드를 수정합니다. 대상은 webpack plugin.ts의 prewarm/canonical-map 블록과 loader.ts의 setCwdModuleResolver, reservation.ts, Rsbuild plugin.ts의 atom-hoist 그래프입니다.
  • 이 PR은 그 부분을 process.cwd() → 루트로 바꾸는 한 줄 수준으로만 고쳤습니다.
  • #934가 의도적으로 넣은 cwd + context 소스 루트 합집합(roots)은 건드리지 않았습니다.
  • 두 PR 중 나중에 머지되는 쪽은 충돌을 해결해야 합니다. 이때 #934의 sourceGraph/conventionalSourceRoots(process.cwd(), …), toId, buildStaticImportGraph(cwd, …)에서 cwd 자리에 루트를 넣으면 됩니다.

테스트 계획

  • plugin-utils/project-root.test.ts에서 확인한 경우:
    • root = cwd이면 경로를 그대로 유지
    • root ≠ cwd이면 절대 경로로 해석
    • 절대 경로는 그대로 유지
    • 사용자가 지정한 devupFile에는 fallback 없음
    • cwd fallback과 경고가 한 번만 출력됨
  • webpack plugin/loader/reservation 테스트에서 확인한 경우:
    • context ≠ cwd: 옵션, sheetFile, 로더 root, productionPrewarmFiles, 추출 id, 의존성, resolver
    • context = cwd: 기존 값 유지
    • fallback과 경고
  • Rsbuild plugin/reservation 테스트에서 확인한 경우: rootPath ≠ cwd, rootPath = cwd, 사용자 상대 경로, fallback과 경고
  • Vite plugin 테스트에서 확인한 경우: config.root ≠ cwd(resolveId 포함), root = cwd, 사용자 상대 경로, fallback과 경고
  • Next plugin 테스트에서 확인한 경우: _options.dir 기준 prod/dev cssDir와 라우트 그래프
  • Bun plugin 테스트에서 확인한 경우: Bun.build root, root 없음, fallback과 경고
  • bun test --coverage (webpack/rsbuild/bun/next/plugin-utils): 4997개 통과, 변경한 파일은 모두 100%
  • Vite 스위트: plugin.ts/reservation.ts는 100%
    • native 테스트 3개(serve-coherence-prereq-native 2개, reservation-native-boundary 1개)는 실패하는데, origin/main 소스로 빌드해도 똑같이 실패하므로 로컬 환경 문제입니다.
  • 6개 패키지 모두 bunx tsc --noEmit -p 통과, prettier 검사 통과
  • CI

Refs #686

🤖 Generated with Claude Code

owjs3901 and others added 2 commits November 15, 2026 19:29
Builds started from a parent directory (turbo, nx, `next build apps/web`)
resolved devupFile, distDir, cssDir, the tsconfig and the webpack extraction
ids against process.cwd(), so they read the wrong devup.json, wrote df into
the wrong directory and changed class names.

- plugin-utils: add resolveProjectPath and resolveDevupFile. A relative path
  resolves against the project root, and is returned unchanged when the root
  is the cwd. The default devup.json falls back to the cwd one, with a
  one-time warning, when only the cwd holds one.
- webpack: normalize the path options, productionPrewarmFiles and the
  tsconfig against compiler.options.context at apply time, pass the root to
  the loader, and key loader ids, dependencies, the canonical map, numbering
  and reservation on it.
- Rsbuild: resolve the options and tsconfig against api.context.rootPath,
  and build the atom-hoist graph and reservation from it.
- Vite: resolve devupFile, distDir, cssDir and the tsconfig against
  config.root in configResolved.
- Next (webpack): place cssDir and the prewarm graph under the project
  directory Next passes to webpack. Turbopack keeps the cwd.
- Bun: use the root of Bun.build when it sets one.

Refs #686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each setup updates one project object in place, so the watcher needs no
extra closure.

Refs #686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
packages/bun-plugin/src/plugin.ts 100.00% <100.00%> (ø)
packages/next-plugin/src/plugin.ts 100.00% <100.00%> (ø)
packages/plugin-utils/src/index.ts 100.00% <100.00%> (ø)
packages/plugin-utils/src/project-root.ts 100.00% <100.00%> (ø)
packages/rsbuild-plugin/src/plugin.ts 100.00% <100.00%> (ø)
packages/rsbuild-plugin/src/reservation.ts 100.00% <100.00%> (ø)
packages/vite-plugin/src/plugin.ts 100.00% <100.00%> (ø)
packages/webpack-plugin/src/loader.ts 100.00% <100.00%> (ø)
packages/webpack-plugin/src/plugin.ts 100.00% <100.00%> (ø)
packages/webpack-plugin/src/reservation.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

owjs3901 and others added 4 commits November 16, 2026 08:36
Conflicts:
- rsbuild-plugin/src/plugin.ts: imports keep both resolveDevupFile /
  resolveProjectPath (this branch) and setupWarning (#945).
- webpack-plugin/src/__tests__/plugin.test.ts: kept both the "project
  root" describe and main's deleted-source tests (#951).

Main's new paths now follow the project root, not the cwd:
- webpack: removeFiles (#951) names deleted files relative to this.root,
  and the import graph warning (#945) checks this.root/src for a missing
  directory. Added a test for removeFiles with a context other than cwd.
- Rsbuild: the import graph warning checks projectRoot/src.
- Bun: the file numbering warning checks <root>/src.
Vite's removeSource and Rsbuild's removeFiles use absolute ids already.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the conflict with #924 in the Bun plugin: writeDataFiles takes the
located project, so devup.json, df and the CSS directory still resolve
against the project root, and takes main's `reloading` flag after it. The
first load rejects a theme error; the Tailwind CSS watcher reloads the same
project with `reloading` set, so it reports the error and clears the theme.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the conflict with #960 in webpack: main builds the source loader
rule once and reuses it for the MDX post loader. That rule now passes the
project `root` to the loader, so MDX modules get root-relative extraction
ids and dependencies as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pick up the #983 snapshot fix so CI runs against current main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@owjs3901
owjs3901 merged commit 7b2255a into main Nov 17, 2026
27 checks passed
@owjs3901
owjs3901 deleted the fix/plugin-project-root branch November 17, 2026 07:31
owjs3901 added a commit that referenced this pull request Nov 17, 2026
#963 keeps the CSS state of an engine session in CssState; carry the license
banner there too (stored inverted so a fresh session keeps it on), so the
test guard and session swaps restore it. #990 counts 46 validated argument
positions; setLicenseBanner.enabled makes 47. Set the banner next to #962's
project-root setup in Rsbuild and Bun, keep both README sections, and pass
#928's inputs Set in #962's webpack project-root assertion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
…t test

#962 asserts loadDevupConfigSync is called with only the resolved devup.json,
but since #928 the plugin also passes the set it collects extended configs
into. Both merged, so the assertion fails on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Resolve against #962: the synchronous loadSourceFile now takes the
BunProject, so the CommonJS runtime path extracts with the project's
cssDir, importAliases and compiledPackages (the stylesheet import it drops
is the one made from that cssDir) instead of module-level paths. Keep both
the CommonJS and the project-root test suites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
#962 resolves the project from the bundler root: the Rsbuild and webpack
source graphs, canonical maps and resolver ids now use that root instead of
the cwd (the graph tests follow), while this branch keeps its source filters
and per-environment bundler conditions. The webpack loader caches one
resolver per root and condition set; Bun passes its project and conditions
to initialize. Also pass #928's inputs Set in #962's webpack project-root
assertion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant