Skip to content

Commit da6f067

Browse files
committed
Remove dynamicImport and setDynamicImport
It turns out that the import expression won't actally be rewritten by esbuild, so we can just write it directly. While this won't help CJS emit, that already didn't work anyway, and it's likely that this code is going to be moved outside of the codebase into VS Code or a shared package elsewhere anyway.
1 parent 7988e40 commit da6f067

File tree

2 files changed

+7
-27
lines changed

2 files changed

+7
-27
lines changed

Diff for: Herebyfile.mjs

+6-17
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ async function runDtsBundler(entrypoint, output) {
190190
* @typedef BundlerTaskOptions
191191
* @property {string[]} [external]
192192
* @property {boolean} [exportIsTsObject]
193-
* @property {boolean} [setDynamicImport]
194193
* @property {boolean} [treeShaking]
195194
*/
196195
function createBundler(entrypoint, outfile, taskOptions = {}) {
@@ -257,22 +256,12 @@ function createBundler(entrypoint, outfile, taskOptions = {}) {
257256
};
258257

259258
if (taskOptions.exportIsTsObject) {
260-
// These snippets cannot appear in the actual source files, otherwise they will be rewritten
261-
// to things like exports or requires.
262-
259+
// We use an IIFE so we can inject the footer, and so that "ts" is global if not loaded as a module.
260+
options.format = "iife";
261+
// Name the variable ts, matching our old big bundle and so we can use the code below.
262+
options.globalName = "ts";
263263
// If we are in a CJS context, export the ts namespace.
264-
let footer = `\nif (typeof module !== "undefined" && module.exports) { module.exports = ts; }`;
265-
266-
if (taskOptions.setDynamicImport) {
267-
// If we are in a server bundle, inject the dynamicImport function.
268-
// This only works because the web server's "start" function returns;
269-
// the node server does not, but we don't use this there.
270-
footer += `\nif (ts.server && ts.server.setDynamicImport) { ts.server.setDynamicImport(id => import(id)); }`;
271-
}
272-
273-
options.format = "iife"; // We use an IIFE so we can inject the footer, and so that "ts" is global if not loaded as a module.
274-
options.globalName = "ts"; // Name the variable ts, matching our old big bundle and so we can use the code below.
275-
options.footer = { js: footer };
264+
options.footer = { js: `\nif (typeof module !== "undefined" && module.exports) { module.exports = ts; }` };
276265
}
277266

278267
return options;
@@ -416,7 +405,7 @@ const { main: tsserver, watch: watchTsserver } = entrypointBuildTask({
416405
// this is used in the browser too. Do the same thing that we do for our
417406
// libraries and generate an IIFE with name `ts`, as to not pollute the global
418407
// scope.
419-
bundlerOptions: { exportIsTsObject: true, setDynamicImport: true },
408+
bundlerOptions: { exportIsTsObject: true },
420409
});
421410
export { tsserver, watchTsserver };
422411

Diff for: src/webServer/webServer.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,6 @@ export class MainProcessLogger extends BaseLogger {
125125
}
126126
}
127127

128-
let dynamicImport = async (_id: string): Promise<any> => {
129-
throw new Error("Dynamic import not implemented");
130-
};
131-
132-
/** @internal */
133-
export function setDynamicImport(fn: (id: string) => Promise<any>) {
134-
dynamicImport = fn;
135-
}
136-
137128
/** @internal */
138129
export function createWebSystem(host: WebHost, args: string[], getExecutingFilePath: () => string): ServerHost {
139130
const returnEmptyString = () => "";
@@ -182,7 +173,7 @@ export function createWebSystem(host: WebHost, args: string[], getExecutingFileP
182173

183174
const scriptPath = combinePaths(packageRoot, browser);
184175
try {
185-
const { default: module } = await dynamicImport(scriptPath);
176+
const { default: module } = await import(scriptPath);
186177
return { module, error: undefined };
187178
}
188179
catch (e) {

0 commit comments

Comments
 (0)