feat: add --incremental and --tsgo flags to @sveltejs/package#15467
Open
datstarkey wants to merge 2 commits intosveltejs:mainfrom
Open
feat: add --incremental and --tsgo flags to @sveltejs/package#15467datstarkey wants to merge 2 commits intosveltejs:mainfrom
datstarkey wants to merge 2 commits intosveltejs:mainfrom
Conversation
Add write-to-disk + shell-out pipeline for declaration emit, adapted from the approach used in svelte-check's incremental mode (PR sveltejs#2932). When `--incremental` or `--tsgo` is passed, svelte-package: 1. Pre-transpiles .svelte files to .ts via svelte2tsx() with manifest caching 2. Generates an overlay tsconfig with declaration emit settings 3. Spawns tsc (or tsgo from @typescript/native-preview) as a child process 4. Post-processes emitted .d.ts files (alias resolution, sourcemap fixup) The default path (no flags) is completely unchanged. Benchmarks on a 264-component Svelte library: - Baseline (emitDts): ~7.2s every run - --incremental warm: ~3.1s (2.3x faster) - --tsgo cold: ~3.7s (2x faster) - --incremental --tsgo: ~1.6s (4.5x faster) Also bumps svelte2tsx to ~0.7.51 for rewriteExternalImports and emitJsDoc support, and adds @typescript/native-preview as an optional peer dependency.
|
The optional peer dependency caused lockfile sync issues in CI. The --tsgo flag already handles the missing package gracefully with a clear error message directing users to install it.
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.
Summary
Adds
--incrementaland--tsgoCLI flags tosvelte-packagefor faster declaration emit. This adapts the write-to-disk + shell-out architecture from svelte-check's incremental mode (language-tools PR #2932) for declaration emit in@sveltejs/package.When either flag is set, the new pipeline replaces the
emitDts()call with:.sveltefiles to.tson disk viasvelte2tsx()with manifest-based caching (mtime+size)declaration: true,emitDeclarationOnly: truetscortsgoas a child process to emit.d.tsfiles.d.tsfiles: resolve$libaliases, fix sourcemap paths, handle hand-written.d.tsprecedenceThe default path (no flags) is completely unchanged — all existing tests pass unmodified.
How the flags interact
emitDts()--incremental.tsbuildinfo--tsgo--incremental --tsgo.tsbuildinfoBenchmarks
Tested on a 264-component Svelte library (420 total files):
svelte-package(baseline)--incremental--tsgo--incremental --tsgoChanges
packages/package/src/emit-dts-incremental.js— core pipeline (~500 lines)cli.js(flags),types.d.ts(types),index.js(routing),typescript.js(extracted sharedresolve_svelte_shimshelper)svelte2tsxto~0.7.51forrewriteExternalImportsandemitJsDocsupport@typescript/native-previewas optional peer dependencyKnown limitations
.d.tsoutput from the incremental path may have minor differences from the default path (whitespace from tsc formatting, slightly less precise types for edge cases in dts mode). Functionally equivalent.Test plan
@sveltejs/packagetests pass (default path unchanged)pnpm run lintpassespnpm run checkpasses (0 errors)pnpm -F @sveltejs/kit test:unitpassespnpm test:otherspasses--incrementalproduces equivalent output ontypescript-esnextfixture--tsgofails gracefully when@typescript/native-previewnot installed