diff --git a/scripts/bundles/internal.ts b/scripts/bundles/internal.ts index fbf7decc4a5..f43350e181b 100644 --- a/scripts/bundles/internal.ts +++ b/scripts/bundles/internal.ts @@ -1,3 +1,4 @@ +import { generateDtsBundle } from 'dts-bundle-generator'; import fs from 'fs-extra'; import { join } from 'path'; @@ -56,6 +57,29 @@ async function copyStencilInternalDts(opts: BuildOptions, outputInternalDir: str const privateDtsDestPath = join(outputInternalDir, 'stencil-private.d.ts'); let privateDts = cleanDts(await fs.readFile(privateDtsSrcPath, 'utf8')); + // @stencil/core/internal/child_process.d.ts + const childProcessSrcPath = join(declarationsInputDir, 'child_process.d.ts'); + const childProcessDestPath = join(outputInternalDir, 'child_process.d.ts'); + + // we generate a tiny tiny bundle here of just + // `src/declarations/child_process.ts` so that `internal/stencil-private.d.ts` + // can import from `'./child_process'` without worrying about resolving the + // types from `node_modules`. + const childProcessDts = generateDtsBundle([ + { + filePath: childProcessSrcPath, + libraries: { + // we need to mark this library so that types imported from it are inlined + inlinedLibraries: ['child_process'], + }, + output: { + noBanner: true, + exportReferencedTypes: false, + }, + }, + ]).join('\n'); + await fs.writeFile(childProcessDestPath, childProcessDts); + // the private `.d.ts` imports the `Result` type from the `@utils` module, so // we need to rewrite the path so it imports from the right relative path privateDts = privateDts.replace('@utils', './utils'); diff --git a/scripts/utils/bundle-dts.ts b/scripts/utils/bundle-dts.ts index 2ae6c2186a5..f95aae9b0a8 100644 --- a/scripts/utils/bundle-dts.ts +++ b/scripts/utils/bundle-dts.ts @@ -1,4 +1,4 @@ -import { EntryPointConfig, generateDtsBundle, OutputOptions } from 'dts-bundle-generator/dist/bundle-generator.js'; +import { EntryPointConfig, generateDtsBundle, OutputOptions } from 'dts-bundle-generator'; import fs from 'fs-extra'; import { BuildOptions } from './options'; diff --git a/src/declarations/child_process.ts b/src/declarations/child_process.ts new file mode 100644 index 00000000000..b1429c312e6 --- /dev/null +++ b/src/declarations/child_process.ts @@ -0,0 +1,5 @@ +import type { Serializable } from 'child_process'; + +// this is just so that we can bundle this type for `stencil-private.d.ts` +// without having to run dts-bundle-generator on that whole file +export { Serializable as CPSerializable }; diff --git a/src/declarations/stencil-private.ts b/src/declarations/stencil-private.ts index d1951288e6d..f05b3292dd6 100644 --- a/src/declarations/stencil-private.ts +++ b/src/declarations/stencil-private.ts @@ -1,7 +1,7 @@ import { result } from '@utils'; -import type { Serializable as CPSerializable } from 'child_process'; import type { InMemoryFileSystem } from '../compiler/sys/in-memory-fs'; +import type { CPSerializable } from './child_process'; import type { BuildEvents, BuildLog,