@@ -184,6 +184,7 @@ async function runDtsBundler(entrypoint, output) {
184184 * @typedef BundlerTaskOptions
185185 * @property {boolean } [exportIsTsObject]
186186 * @property {boolean } [treeShaking]
187+ * @property {boolean } [usePublicAPI]
187188 * @property {() => void } [onWatchRebuild]
188189 */
189190function createBundler ( entrypoint , outfile , taskOptions = { } ) {
@@ -208,6 +209,19 @@ function createBundler(entrypoint, outfile, taskOptions = {}) {
208209 // legalComments: "none", // If we add copyright headers to the source files, uncomment.
209210 } ;
210211
212+ if ( taskOptions . usePublicAPI ) {
213+ options . external = [ "./typescript.js" ] ;
214+ options . plugins = options . plugins || [ ] ;
215+ options . plugins . push ( {
216+ name : "remap-typescript-to-require" ,
217+ setup ( build ) {
218+ build . onLoad ( { filter : / s r c [ \\ / ] t y p e s c r i p t [ \\ / ] t y p e s c r i p t \. t s $ / } , ( ) => {
219+ return { contents : `export * from "./typescript.js"` } ;
220+ } ) ;
221+ } ,
222+ } ) ;
223+ }
224+
211225 if ( taskOptions . exportIsTsObject ) {
212226 // Monaco bundles us as ESM by wrapping our code with something that defines module.exports
213227 // but then does not use it, instead using the `ts` variable. Ensure that if we think we're CJS
@@ -235,7 +249,8 @@ function createBundler(entrypoint, outfile, taskOptions = {}) {
235249 const toCommonJsRegExp = / v a r _ _ t o C o m m o n J S .* / ;
236250 const toCommonJsRegExpReplacement = "var __toCommonJS = (mod) => (__copyProps, mod); // Modified helper to skip setting __esModule." ;
237251
238- options . plugins = [
252+ options . plugins = options . plugins || [ ] ;
253+ options . plugins . push (
239254 {
240255 name : "post-process" ,
241256 setup : build => {
@@ -252,7 +267,7 @@ function createBundler(entrypoint, outfile, taskOptions = {}) {
252267 } ) ;
253268 } ,
254269 } ,
255- ] ;
270+ ) ;
256271 }
257272
258273 return options ;
@@ -422,7 +437,8 @@ const { main: tsserver, watch: watchTsserver } = entrypointBuildTask({
422437 srcEntrypoint : "./src/tsserver/server.ts" ,
423438 builtEntrypoint : "./built/local/tsserver/server.js" ,
424439 output : "./built/local/tsserver.js" ,
425- mainDeps : [ generateLibs ] ,
440+ mainDeps : [ generateLibs , services ] ,
441+ bundlerOptions : { usePublicAPI : true } ,
426442} ) ;
427443export { tsserver , watchTsserver } ;
428444
@@ -572,6 +588,8 @@ const { main: typingsInstaller, watch: watchTypingsInstaller } = entrypointBuild
572588 srcEntrypoint : "./src/typingsInstaller/nodeTypingsInstaller.ts" ,
573589 builtEntrypoint : "./built/local/typingsInstaller/nodeTypingsInstaller.js" ,
574590 output : "./built/local/typingsInstaller.js" ,
591+ mainDeps : [ services ] ,
592+ bundlerOptions : { usePublicAPI : true } ,
575593} ) ;
576594
577595const { main : watchGuard , watch : watchWatchGuard } = entrypointBuildTask ( {
0 commit comments