-
-
Notifications
You must be signed in to change notification settings - Fork 611
feat(typescript): process .js when allowJs is enabled #1920
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
feat(typescript): process .js when allowJs is enabled #1920
Conversation
…efault include to JS/JSX/MJS/CJS when is enabled\n- Avoid TS5055 by redirecting JS emit to a temp outDir when none is set\n- Add tests for downleveling JS (direct entry and TS->JS import)\n- Document behavior in README
…r and clean up\n\n- Use brace expansion in default include glob\n- Create per-build temp outDir under os.tmpdir(), exclude it from filter, and remove on build end\n- Document behavior in README
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.
- Cleaning the temp
outDirinbuildEndrisks extra churn and potential interference in watch mode; prefer cleaning incloseBundleor only when not watching. - Direct use of
fs.rmSyncmay break on older Node.js versions; consider a fallback to maintain compatibility. - README should clarify when the temp directory is removed in watch mode to match runtime behavior and avoid confusion.
Additional notes (1)
- Readability |
packages/typescript/README.md:82-83
The README note says the temp outDir is removed "after the build". In watch mode, the directory may be deleted after the first build while the watcher continues running, which can be surprising. Clarifying that it’s removed when the build finishes or the watcher stops would reduce confusion.
Summary of changes
- Typescript plugin now honors
allowJs: when enabled, the defaultincludeexpands to*.{js,jsx,mjs,cjs}in addition to TS extensions. - Introduces a temporary
outDirunder the OS temp folder whenallowJsis on and nooutDiris configured, to avoid TS5055 overwrite errors. The temp directory is excluded from the plugin filter and cleaned up at the end of the build. - Adds tests that confirm JS downleveling (optional chaining and nullish coalescing assignment) for both direct
.jsentry and.tsimporting.js. - README updated to document
allowJsbehavior, include expansion, and tempoutDirhandling.
…cessing outputs\n\n- Exclude user-configured or auto temp outDir from the plugin filter\n- Guard against excluding sources when outDir contains the filter root (e.g., outDir='.' with rootDir='src')\n\nImplements review feedback to avoid feedback loops with allowJs and user outDir.
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.
Primary concern: deleting the temp outDir in buildEnd can disrupt watch mode; cleanup should be gated or moved to closeBundle. The path containment check for excluding outDir would be more robust using path.relative rather than startsWith. README’s note should clarify watch-mode cleanup timing to match runtime behavior. Consider adding a test for user-configured outDir to prevent regressions in output re-processing.
Additional notes (1)
- Maintainability |
packages/typescript/test/test.js:1633-1662
Nice coverage on downleveling behavior. Consider adding a test to guard the new filter exclusion for a user-configuredoutDir(not just the auto temp one). Without this, a regression could re-introduce a feedback loop by re-processing emitted JS.
Summary of changes
- Add support for
allowJsin the TypeScript plugin: when enabled, the default include expands to*.{js,jsx,mjs,cjs}in addition to TS extensions. - Introduce an automatic temporary
outDirwhenallowJsis enabled and nooutDiris configured, to avoid TS5055 overwrite errors; exclude the effectiveoutDirfrom the filter. - Guard exclusion logic to not accidentally exclude sources when
outDircontains the filter root. - Clean up the auto-created temp
outDirinbuildEnd. - Add tests that verify downleveling of modern JS syntax for
.jsentry and.tsimporting.js. - Update README to document the expanded include and temp
outDirbehavior.
- Replace brittle startsWith-based check with path.relative to detect containment - Address ESLint prefer-template with template literal Refs #1920
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.
- The
path.relativecontainment check can mis-detect containment on Windows whenoutDirand the filter base are on different drives, leading to re-processing emitted files. Add a root-equality and absolute-path guard. - Cleaning the temp
outDirinbuildEndis suboptimal for watch mode; restrict it to non-watch builds and perform final cleanup incloseWatcher. - README’s note should clarify watch-mode cleanup timing to align with runtime behavior.
- Consider a regression test ensuring user-configured
outDiroutputs are excluded from the bundle to prevent future feedback-loop regressions.
Additional notes (1)
- Readability |
packages/typescript/README.md:82-82
The note says the tempoutDiris removed "after the build". In watch mode the behavior differs; with the current implementation it may be removed during the session (and with the suggested change, when the watcher stops). Clarifying the timing avoids confusion.
Summary of changes
- Add first-class support for
allowJsin the TypeScript plugin:- Expand the default
includeto also match*.{js,jsx,mjs,cjs}whenallowJsis enabled. - Auto-create a per-build temporary
outDirunder the OS temp folder whenallowJsis true and nooutDiris set to avoid TS5055. - Exclude the effective
outDir(user-provided or auto) from the plugin’s filter to prevent re-processing emitted files; use apath.relative-based containment check. - Clean up the auto-created temp
outDirinbuildEnd.
- Expand the default
- Add tests verifying JS downleveling for
.jsentry and for.tsimporting.js. - Update README to document the expanded default include and temp
outDirbehavior whenallowJsis enabled.
…xcluded with allowJs
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.
- The
path.relativecontainment check can mis-detect on Windows whenoutDirand the filter base are on different drives, causing emitted files to be re-processed. Add a root-equality and absolute-path guard. - Auto-excluding
outDirwhenfilterRootisfalserisks unintentionally excluding sources (e.g.,outDir='.'). Skip exclusion in this mode or use a safe fallback base. - Cleaning the temp
outDirinbuildEndcan disrupt watch mode and doesn’t ensure final cleanup; gate it for non-watch and clean once incloseWatcher. - README should clarify cleanup timing in watch mode; the test for excluding
outDircan use a cross-platform containment check to avoid path edge cases.
Additional notes (2)
-
Readability |
packages/typescript/README.md:82-83
The note states the tempoutDiris removed “after the build,” which is ambiguous in watch mode. Given the current implementation (cleanup inbuildEnd), it may be removed during the watch session after the first build. Clarifying the timing for watch mode will prevent confusion. -
Compatibility |
packages/typescript/test/test.js:1681-1684
Good regression test. To make this robust across platforms (Windows drive letters, case differences), avoidstartsWithon normalized strings and use a containment check withpath.relativethat handles cross-drive and absolute-path cases.
Summary of changes
- Add
allowJssupport in the TypeScript Rollup plugin:- Expand default
includeto*.{js,jsx,mjs,cjs}whenallowJsis enabled. - Auto-create a per-build temporary
outDir(underos.tmpdir()) whenallowJsis on and nooutDiris configured. - Exclude the effective
outDirfrom the plugin filter to avoid re-processing emitted outputs using apath.relativecontainment check. - Clean up the auto-created
outDirduringbuildEnd.
- Expand default
- Add tests verifying JS downleveling and a regression ensuring user-configured
outDiris excluded from processing. - Update README to document
allowJsbehavior, expanded default include, and tempoutDirhandling.
…in watch mode\n\n- Guard containment with cross-drive root check and absolute-relative detection\n- Skip over-exclusion when filterRoot is false by falling back to process.cwd()\n- Delete temp outDir only for non-watch builds; clean up in closeWatcher for watch\n- Docs: clarify effective outDir exclusion and watch-mode cleanup timing\n\nRefs #1920
…oseWatcher; harden outDir exclusion\n\n- Clean temp outDir only when not watching; perform final cleanup in closeWatcher to avoid watch-mode churn\n- Robust containment check for excluding outDir using drive-root equality + path.relative + !isAbsolute (handles Windows cross-drive)\n- When filterRoot=false, use CWD fallback for containment to avoid over-excluding sources (e.g., outDir='.')\n- Docs: clarify cleanup timing in README (non-watch vs watch)
851dee7 to
f110caa
Compare
…k, guaranteed cleanup)
PR Review: feat(typescript): process .js when allowJs is enabled (#1920)SummaryThis PR adds robust first-class support for Strengths
Feedback
Suggestions
VerificationAll commands (build, AVA tests, typechecks, ESLint, Prettier) pass without additional warnings. Snapshots and type input baselines remain unchanged where not intended. Final ThoughtsThis is a thoughtful, battle-tested addition to the plugin, unlocking smooth consumption of modern JavaScript and bridging TypeScript’s capabilities for mixed codebases. The rollout addresses technical, usability, and cross-platform concerns elegantly! Ready to merge! |
…in watch mode\n\n- Guard containment with cross-drive root check and absolute-relative detection\n- Skip over-exclusion when filterRoot is false by falling back to process.cwd()\n- Delete temp outDir only for non-watch builds; clean up in closeWatcher for watch\n- Docs: clarify effective outDir exclusion and watch-mode cleanup timing\n\nRefs #1920 # Conflicts: # packages/typescript/README.md # packages/typescript/src/index.ts
…rror plugin containment semantics
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.
- Using
filterRoot: truecurrently feeds a boolean intopath.resolve, producing a bogus base path and risking incorrect include/exclude behavior; guard for stringfilterRoot. - The watch program is not closed in
closeWatcher, which can leak watchers in long-running sessions; close it when the watcher stops. - Root comparison in the containment check is case-sensitive; normalize Windows drive roots to avoid misclassifying paths.
- With JS auto-inclusion, defaulting to transform files in
node_modulescan cause unnecessary work and behavioral changes; excludenode_modulesby default unless the user overrides patterns.
Summary of changes
- Add first-class
allowJssupport to@rollup/plugin-typescript.- When
allowJsis enabled and nooutDiris set, create a per-build temporaryoutDirunderos.tmpdir()to avoid TS5055 and assign it to the compiler options. - Expand the plugin’s default
includeto*.{js,jsx,mjs,cjs}in addition to TS extensions whenallowJsis true. - Exclude the effective
outDir(user or temp) from plugin processing with a containment check that usespath.relative, and guard behavior whenfilterRoot === falseby falling back toprocess.cwd(). - Add cleanup of the temporary
outDirin non-watch builds (buildEnd) and on watcher shutdown (closeWatcher).
- When
- Documentation: README updated to describe the expanded include behavior and temp
outDirlifecycle. - Tests: add fixtures and tests verifying JS downleveling and a regression test ensuring outputs under a user-configured
outDirare not re-processed.
Links:
- Updated files:
packages/typescript/src/index.ts,packages/typescript/README.md, tests and fixtures underpackages/typescript/test/.
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.
- In watch mode, the TS watch program isn’t closed in
closeWatcher, risking leaked file handles and watchers. Addprogram?.close()there. configuredBaseincorrectly accepts a boolean whenfilterRootistrue, leading to bogus path resolution and broken containment checks; guard for string values only.- Root equality checks should normalize Windows drive-letter case to avoid misclassification in path containment.
- Consider excluding
node_modulesby default when auto-expanding to JS to avoid transforming third-party code and unnecessary work; also deduplicate the temp outDir cleanup into a helper.
Summary of changes
- Add first-class
allowJssupport to@rollup/plugin-typescript. - When
allowJsis enabled andoutDiris not set, create a per-build temporaryoutDirunder the OS temp directory and assign it totscto avoid TS5055. - Expand the plugin’s default include to also match
*.{js,jsx,mjs,cjs}whenallowJsis enabled; otherwise, keep TS-only. - Exclude the effective
outDir(user-provided or temporary) from the plugin filter; add a cross-platform containment guard usingpath.relativeand a fallback whenfilterRoot === false. - Gate temp
outDirdeletion to non-watch builds inbuildEnd; addcloseWatcherto clean up in watch mode. - Add tests for downleveling JS (direct
.jsentry and.tsimporting.js) and a regression test ensuring a user-configuredoutDiris excluded. - Update README to document default includes with
allowJs, tempoutDir, and cleanup timing.
…am on shutdown\n\n- Treat only string values of as a base path; fall back to tsconfig otherwise to avoid resolving boolean to 'true'\n- Align 's option with the same guard to prevent passing non-string truthy values\n- Close the TypeScript watch program in to release resources in watch mode\n\nRefs #1920
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.
- Path containment compares Windows drive roots case-sensitively, which can misclassify same-drive paths and break exclusion logic; normalize root case on win32.
- With JS auto-inclusion, the plugin may transform files in
node_modulesby default, causing unnecessary work and potential behavior changes; excludenode_modulesby default unless patterns are provided. createFilter({ resolve })lacks an explicitprocess.cwd()fallback when neitherfilterRootnorrootDirare set, diverging from the documented default.autoOutDircleanup code is duplicated between hooks; a small helper would reduce drift and improve maintainability.
Additional notes (2)
-
Readability |
packages/typescript/README.md:80-83
Docs describe the expanded default include and tempoutDirlifecycle. If you adopt the defaultnode_modulesexclusion for the auto-JS path, calling that out here will prevent surprises for users expecting third‑party code to be transformed. -
Maintainability |
packages/typescript/test/test.js:1633-1696
Good regression coverage. If you implement the defaultnode_modulesexclusion, adding a small test ensures we don’t regress and accidentally process dependency code whenallowJsis on.
Summary of changes
- Add first-class handling for
allowJsin the TypeScript plugin. - Auto-create a per-build temporary
outDirwhenallowJsis enabled and nooutDiris configured; exclude the effectiveoutDirfrom processing and clean it up safely (non-watch inbuildEnd, watch incloseWatcher). - Expand the plugin’s default
includeto also match*.{js,jsx,mjs,cjs}whenallowJsis set. - Harden
filterRoothandling (use only string values as base) and add robust outDir containment checks usingpath.relativewith a fallback whenfilterRoot === false. - Update README to document default include expansion and temporary
outDirbehavior. - Add fixtures and tests verifying JS downleveling and regression coverage for excluding a user-configured
outDir.
packages/typescript/src/index.ts
Outdated
| // Guard against non-string truthy values (e.g., boolean true). Only strings are valid | ||
| // for `resolve`; `false` disables resolution. Otherwise, fall back to `rootDir`. | ||
| resolve: | ||
| typeof filterRoot === 'string' | ||
| ? filterRoot | ||
| : filterRoot === false | ||
| ? false | ||
| : parsedOptions.options.rootDir |
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.
The resolve option passed to createFilter may end up undefined if neither filterRoot (string) nor parsedOptions.options.rootDir are set. The README documents a default of rootDir ?? tsconfig rootDir ?? process.cwd(). To align runtime behavior with docs and avoid implicit defaults, fall back to process.cwd() explicitly.
Suggestion
Explicitly fall back to process.cwd() when neither filterRoot (string) nor rootDir are available:
resolve:
typeof filterRoot === 'string'
? filterRoot
: filterRoot === false
? false
: parsedOptions.options.rootDir || process.cwd()Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this change
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.
@CharlieHelps is this comment still relevant/needed?
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.
Expand this to see my work.
- Confirmed in PR #1920 that the inline comment in
packages/typescript/src/index.tsis obsolete sincedefaultIncludealready matches*.{js,jsx,mjs,cjs}withallowJs,autoOutDirprevents TS5055, andcreateFilter(..., { resolve })respectsfilterRoot. - Updated
packages/typescript/src/index.tsto setresolveincreateFilter(include || defaultInclude, filterExclude, { ... })toparsedOptions.options.rootDir || process.cwd()to handle configs withoutrootDir. - Built @rollup/plugin-typescript successfully; artifacts created at
./dist/cjs/index.jsand./dist/es/index.js.
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.
Yes—still relevant. I’ve added an explicit fallback to process.cwd() when filterRoot isn’t a string (and not false) and rootDir is unset, so createFilter({ resolve }) never receives undefined. This aligns runtime with the README’s documented default. Change in e1fa4f0.
Verification
# Build (scoped)
$ pnpm --filter @rollup/plugin-typescript build
# Result: success
# Tests (AVA, serial)
$ pnpm --filter @rollup/plugin-typescript test -- --verbose --serial
# Result: 87 tests passed, 2 skipped
# TypeScript
$ pnpm --filter @rollup/plugin-typescript run test:ts
# Result: No errors
# ESLint (scoped)
$ pnpm exec eslint --cache packages/typescript --ext .js,.ts,.mjs
# Result: 0 problems…e node_modules by default when auto‑including JS\n\n- Normalize drive‑letter case when comparing roots in outDir containment (win32)\n- When allowJs expands include and user did not set include/exclude, add '**/node_modules/**' to exclude to avoid transforming third‑party code\n\nRefs #1920
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.
- Runtime default for
createFilter({ resolve })lacks an explicitprocess.cwd()fallback, diverging from the documented default and risking environment-dependent behavior. - README omits the new default exclusion of
**/node_modules/**when auto-including JS without user patterns, which can surprise users. - Minor duplication of temp
outDircleanup logic across hooks could be centralized to reduce drift.
Functionality, containment checks, and watch-mode lifecycle look solid otherwise.
Additional notes (1)
- Maintainability |
packages/typescript/src/index.ts:178-199
Cleanup of the auto-created tempoutDiris duplicated in bothbuildEndandcloseWatcher. While small, duplication tends to drift over time, especially around error handling. A tiny helper will centralize the logic and reduce maintenance risk.
Summary of changes
- Add first-class
allowJssupport to@rollup/plugin-typescript.- When
allowJsis enabled and nooutDiris set, create a per-build temporaryoutDirunderos.tmpdir()and assign it totscto avoid TS5055. - Expand the plugin’s default include to also match
*.{js,jsx,mjs,cjs}whenallowJsis true. - Exclude the effective
outDir(user or temp) from plugin processing using a robust cross‑platform containment check. - When auto‑including JS and no user patterns are provided, exclude
**/node_modules/**by default to avoid transforming third‑party code. - In watch mode, clean the temp
outDirand close the TS program incloseWatcher; in non‑watch builds, perform cleanup inbuildEnd. - Add fixtures and AVA tests verifying JS downleveling and excluding a user‑configured
outDir. - Update README to document the expanded default include and temp
outDirlifecycle.
- When
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.
createFilter({ resolve })doesn’t explicitly fall back toprocess.cwd()whenrootDiris absent, which diverges from the documented default; add aprocess.cwd()fallback for consistency.- README omits mentioning the new default exclusion of
**/node_modules/**when auto-including JS without user patterns—this should be documented to avoid surprises. - Temp
outDircleanup is duplicated across hooks; a small helper reduces drift and keeps behavior consistent.
Summary of changes
- Add first-class
allowJshandling in the TypeScript plugin:- Auto-create a temporary
outDirwhenallowJsis enabled and nooutDiris set; ensure it’s excluded from processing and cleaned up. - Expand the default include to also match
*.{js,jsx,mjs,cjs}whenallowJsis true; exclude**/node_modules/**by default if the user didn’t specify patterns. - Exclude the effective
outDir(user or temp) from the filter using a robust containment check (path.relative+ Windows root normalization) with a safe fallback whenfilterRoot === false. - Gate cleanup to non-watch builds (
buildEnd) and perform final cleanup (and now also close the TS program) incloseWatcher.
- Auto-create a temporary
- Add tests validating JS downleveling and excluding a user-configured
outDir. - Update README to document the expanded default include and temp
outDirlifecycle.
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.
Overall implementation is solid and thoughtfully hardened for cross‑platform correctness and watch‑mode lifecycle. Two minor maintainability gaps remain: an explicit process.cwd() fallback for createFilter({ resolve }) would better align code with the README’s documented default, and the temp outDir cleanup code is duplicated across hooks. Addressing these will improve clarity and reduce the chance of future drift.
Summary of changes
- Add first-class
allowJshandling to@rollup/plugin-typescript.- Auto-create a per-build temporary
outDirwhenallowJsis enabled and nooutDiris set; exclude the effectiveoutDirfrom processing and clean it up safely (non‑watch inbuildEnd, watch incloseWatcher). - Expand the default include to also match
*.{js,jsx,mjs,cjs}whenallowJsis true; when no user patterns are provided, also exclude**/node_modules/**by default. - Harden
filterRoothandling (only accept string base), and implement a cross‑platform outDir containment guard usingpath.relativewith Windows drive‑root normalization and aprocess.cwd()fallback when patterns aren’t resolved.
- Auto-create a per-build temporary
- README: document
allowJsdefault include expansion, effectiveoutDirexclusion, watch/non‑watch cleanup behavior, and the defaultnode_modulesexclusion when auto‑including JS. - Tests and fixtures: add downleveling coverage for
.jsentries and.tsimporting.js, plus a regression test ensuring outputs under a user‑configuredoutDiraren’t re‑processed. - Minor updates to a fixture
.tsbuildinfoto keep tests consistent.
…- Align runtime with README for default: when is not a string and resolution is enabled\n- Prevents from receiving base in edge configs\n\nRefs #1920
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.
Overall implementation is solid and addresses correctness and lifecycle concerns. The only notable improvement is deduplicating the temp outDir cleanup across hooks to reduce drift. The containment logic is correct but can be made clearer by extracting a tiny helper. No functional correctness issues detected in the changed code.
Additional notes (2)
-
Maintainability |
packages/typescript/src/index.ts:178-199
The tempoutDircleanup logic is duplicated in bothbuildEndandcloseWatcher. Duplicated try/catch blocks tend to drift over time and make behavior harder to tweak consistently. A tiny helper would centralize cleanup and reduce maintenance risk. -
Readability |
packages/typescript/src/index.ts:97-105
The Windows-root normalization and containment logic is correct and robust, but it’s embedded within an IIFE and mixes responsibilities (root normalization, relative computation, containment rules). Extracting it into a small local utility (e.g.,isInside(parent, child)) would improve readability and make it easier to mirror in tests without re-implementing the semantics.
Summary of changes
- Add first-class
allowJshandling in@rollup/plugin-typescript.- When
compilerOptions.allowJsis true and nooutDiris set, create a per-build temporaryoutDirunderos.tmpdir()and assign it to the compiler options to avoid TS5055. - Expand the default include to also match
*.{js,jsx,mjs,cjs}whenallowJsis enabled; keep TS-only otherwise. - Exclude the effective
outDir(user-provided or temp) from plugin processing using a robust containment check that guards cross-drive roots and falls back toprocess.cwd()whenfilterRoot === false. - When auto-including JS and no user patterns are provided, default-exclude
**/node_modules/**to avoid transforming third‑party code. - Normalize
filterRootusage: only accept string values for resolve base; otherwise userootDirorprocess.cwd(). - Gate temp
outDircleanup to non-watch builds (buildEnd) and perform final cleanup (and close the TS program) incloseWatcher.
- When
- Tests: add fixtures and AVA tests verifying JS downleveling and a regression that ensures outputs under a user-configured
outDirare not re-processed. - Docs: update README to describe expanded include, effective
outDirexclusion, watch vs non‑watch cleanup timing, and the defaultnode_modulesexclusion when auto-including JS.
Please implement that |
Expand this to see my work.
|
- Deduplicate try/catch cleanup in buildEnd and closeWatcher via local function - No behavior change; preserves watch vs non-watch cleanup semantics Refs #1920
…elper - Add local closeProgramAndCleanup() that always cleans in finally - Use in buildEnd (non-watch) and closeWatcher (watch) Refs #1920
|
Implemented. I centralized the temp outDir cleanup and removed the duplication. Changes
Verification# Build+Tests (scoped to @rollup/plugin-typescript): 87 passed, 2 skipped
$ pnpm --filter @rollup/plugin-typescript test -- --verbose --serial
# TypeScript: No errors
$ pnpm --filter @rollup/plugin-typescript run test:ts
# ESLint (scoped): 0 problems
$ pnpm exec eslint --cache packages/typescript --ext .js,.ts,.mjsRe-requested review from @CharlieHelps and @shellscape. |
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.
No functional, performance, or correctness issues detected in the modified code. The implementation robustly covers edge cases (watch mode, Windows drive roots, filterRoot handling) and improves maintainability with a centralized cleanup helper. Tests and README updates align with the new behavior. No changes required.
Summary of changes
- Add first-class
allowJssupport to@rollup/plugin-typescript.- When
allowJsis enabled and nooutDiris set, create a per-build temporaryoutDirunderos.tmpdir()and point TypeScript emit there to avoid TS5055. - Expand the default include to also match
*.{js,jsx,mjs,cjs}whenallowJsis true; otherwise keep TS-only. - Exclude the effective
outDir(user-provided or auto temp) from processing, guarded by a robust cross-platform containment check usingpath.relativeand Windows drive-root normalization. - When auto-including JS and the user hasn’t specified patterns, default-exclude
**/node_modules/**to avoid transforming third‑party code. - Centralize temp outDir cleanup via a helper and perform cleanup in
buildEnd(non-watch) andcloseWatcher(watch). Also close the TS watch program on watcher stop.
- When
- README: document the expanded default include, effective
outDirexclusion, and cleanup timing; note defaultnode_modulesexclusion when auto-including JS. - Tests: add fixtures and AVA tests verifying JS downleveling and that a user-configured
outDiris excluded from processing. - Update a fixture
.tsbuildinfoto keep tests consistent.
Adds first-class support for
allowJsin@rollup/plugin-typescriptso modern JavaScript in .js files is transformed when a project opts in via tsconfig.Changes
compilerOptions.allowJsis true, expand the plugin’s default include to also match*.{js,jsx,mjs,cjs}(in addition to TS extensions).outDirunder the OS temp directory when the user hasn’t provided one..jsentry whenallowJsis enabled..tsentry imports a.jsmodule.allowJsbehavior in the README.Verification
@rollup/plugin-typescriptbecause only this package was changed.Closes #1896.