Skip to content
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

Before compiling, try to fetch built js from backend #9778

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions pxtlib/emitter/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ namespace pxt.Cloud {
})
}

export function downloadBuiltSimJsInfoAsync(id: string): Promise<pxtc.BuiltSimJsInfo> {
eanders-ms marked this conversation as resolved.
Show resolved Hide resolved
const targetVersion = pxt.appTarget.versions && pxt.appTarget.versions.target || "";
const url = pxt.U.stringifyQueryString(id + "/js", { v: "v" + targetVersion }) + (id.startsWith("S") ? `&time=${Date.now()}` : "");
return privateRequestAsync({
url,
forceLiveEndpoint: true,
}).then(resp => {
return resp.json
});
}

export async function markdownAsync(docid: string, locale?: string, propagateExceptions?: boolean): Promise<string> {
// 1h check on markdown content if not on development server
const MARKDOWN_EXPIRATION = pxt.BrowserUtils.isLocalHostDev() ? 0 : 1 * 60 * 60 * 1000;
Expand Down
10 changes: 9 additions & 1 deletion pxtrunner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ namespace pxt.runner {
}

export async function simulateAsync(container: HTMLElement, simOptions: SimulateOptions): Promise<pxtc.BuiltSimJsInfo> {
const builtSimJS = simOptions.builtJsInfo || await buildSimJsInfo(simOptions);
const builtSimJS = simOptions.builtJsInfo || await fetchSimJsInfo(simOptions) || await buildSimJsInfo(simOptions);
const { js } = builtSimJS;

if (!js) {
Expand Down Expand Up @@ -466,6 +466,14 @@ namespace pxt.runner {
simDriver?.postMessage(msg);
}

export async function fetchSimJsInfo(simOptions: SimulateOptions): Promise<pxtc.BuiltSimJsInfo> {
try {
return await pxt.Cloud.downloadBuiltSimJsInfoAsync(simOptions.id);
} catch {
return undefined;
eanders-ms marked this conversation as resolved.
Show resolved Hide resolved
}
}

export async function buildSimJsInfo(simOptions: SimulateOptions): Promise<pxtc.BuiltSimJsInfo> {
await loadPackageAsync(simOptions.id, simOptions.code, simOptions.dependencies);

Expand Down
Loading