Skip to content

Remove dynamicImport and setDynamicImport #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ async function runDtsBundler(entrypoint, output) {
* @typedef BundlerTaskOptions
* @property {string[]} [external]
* @property {boolean} [exportIsTsObject]
* @property {boolean} [setDynamicImport]
* @property {boolean} [treeShaking]
*/
function createBundler(entrypoint, outfile, taskOptions = {}) {
Expand Down Expand Up @@ -257,22 +256,12 @@ function createBundler(entrypoint, outfile, taskOptions = {}) {
};

if (taskOptions.exportIsTsObject) {
// These snippets cannot appear in the actual source files, otherwise they will be rewritten
// to things like exports or requires.

// We use an IIFE so we can inject the footer, and so that "ts" is global if not loaded as a module.
options.format = "iife";
// Name the variable ts, matching our old big bundle and so we can use the code below.
options.globalName = "ts";
// If we are in a CJS context, export the ts namespace.
let footer = `\nif (typeof module !== "undefined" && module.exports) { module.exports = ts; }`;

if (taskOptions.setDynamicImport) {
// If we are in a server bundle, inject the dynamicImport function.
// This only works because the web server's "start" function returns;
// the node server does not, but we don't use this there.
footer += `\nif (ts.server && ts.server.setDynamicImport) { ts.server.setDynamicImport(id => import(id)); }`;
}

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.
options.globalName = "ts"; // Name the variable ts, matching our old big bundle and so we can use the code below.
options.footer = { js: footer };
options.footer = { js: `\nif (typeof module !== "undefined" && module.exports) { module.exports = ts; }` };
}

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

Expand Down
11 changes: 1 addition & 10 deletions src/webServer/webServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,6 @@ export class MainProcessLogger extends BaseLogger {
}
}

let dynamicImport = async (_id: string): Promise<any> => {
throw new Error("Dynamic import not implemented");
};

/** @internal */
export function setDynamicImport(fn: (id: string) => Promise<any>) {
dynamicImport = fn;
}

/** @internal */
export function createWebSystem(host: WebHost, args: string[], getExecutingFilePath: () => string): ServerHost {
const returnEmptyString = () => "";
Expand Down Expand Up @@ -182,7 +173,7 @@ export function createWebSystem(host: WebHost, args: string[], getExecutingFileP

const scriptPath = combinePaths(packageRoot, browser);
try {
const { default: module } = await dynamicImport(scriptPath);
const { default: module } = await import(scriptPath);
return { module, error: undefined };
}
catch (e) {
Expand Down