@@ -342,6 +342,7 @@ export async function build(options: BuildOptions): Promise<void> {
342342 const esmOutDir = path . join ( options . outDir , "esm" ) ;
343343 const scriptOutDir = path . join ( options . outDir , "script" ) ;
344344 const typesOutDir = path . join ( options . outDir , "types" ) ;
345+ const srcOutDir = path . join ( options . outDir , "src" ) ;
345346 const compilerScriptTarget = getCompilerScriptTarget ( scriptTarget ) ;
346347 // TypeScript 6.0 no longer automatically discovers the `@types` packages
347348 // installed in the output's node_modules, so resolve and include them
@@ -352,6 +353,10 @@ export async function build(options: BuildOptions): Promise<void> {
352353 const project = createProjectSync ( {
353354 compilerOptions : {
354355 outDir : typesOutDir ,
356+ // pin the root so that a dependency resolving to a file outside the
357+ // sources (ex. a package that ships a .ts file) can't shift the output
358+ // down a directory and leave the package.json paths dangling
359+ rootDir : srcOutDir ,
355360 allowJs : true ,
356361 alwaysStrict : true ,
357362 stripInternal : options . compilerOptions ?. stripInternal ,
@@ -588,10 +593,20 @@ export async function build(options: BuildOptions): Promise<void> {
588593 d . code !== 1343 &&
589594 // 1470: The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output
590595 d . code !== 1470 &&
596+ ! isInNodeModules ( d ) &&
591597 ( options . filterDiagnostic ?.( d ) ?? true )
592598 ) ;
593599 }
594600
601+ /** A dependency shipping a .ts file that resolution lands on is compiled
602+ * as a source rather than a declaration file, so `skipLibCheck` doesn't
603+ * cover it. Its code is no more the package author's problem than a .d.ts
604+ * would be, so ignore it all the same. */
605+ function isInNodeModules ( diagnostic : ts . Diagnostic ) {
606+ const fileName = diagnostic . file ?. fileName ;
607+ return fileName != null && fileName . includes ( "/node_modules/" ) ;
608+ }
609+
595610 function shouldTypeCheck ( ) {
596611 const typeCheck = options . typeCheck ! ;
597612 switch ( typeCheck ) {
0 commit comments