Skip to content

Commit

Permalink
Merge pull request #2252 from demergent-labs/progressive_writing
Browse files Browse the repository at this point in the history
Progressive writing
  • Loading branch information
lastmjs authored Nov 1, 2024
2 parents 9956d04 + afd17b0 commit aad34cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
16 changes: 7 additions & 9 deletions src/build/experimental/commands/compile/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { IOType } from 'child_process';
import { rm } from 'fs/promises';
import { outputFile } from 'fs-extra';
import { join } from 'path';

import { writeGeneratedFiles } from '../../../stable/commands/compile';
import { execSyncPretty } from '../../../stable/utils/exec_sync_pretty';
import { CanisterConfig } from '../../../stable/utils/types';
import { logSuccess } from '../../utils/log_success';
Expand Down Expand Up @@ -32,6 +33,8 @@ export async function runCommand(

const javaScript = await compileJavaScript(main, esmAliases, esmExternals);

await outputFile(join(canisterPath, 'main.js'), javaScript);

const { candid, methodMeta } = await getCandidAndMethodMeta(
canisterConfig.custom?.candid_gen,
candidPath,
Expand All @@ -40,21 +43,16 @@ export async function runCommand(
wasmData
);

await outputFile(candidPath, candid);

const wasmBinary = await getWasmBinary(
ioType,
javaScript,
wasmData,
methodMeta
);

await writeGeneratedFiles(
canisterPath,
candidPath,
wasmBinaryPath,
candid,
javaScript,
wasmBinary
);
await outputFile(wasmBinaryPath, wasmBinary);

buildAssets(canisterConfig, ioType);

Expand Down
24 changes: 4 additions & 20 deletions src/build/stable/commands/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export async function runCommand(

const javaScript = await compileJavaScript(main);

await outputFile(join(canisterPath, 'main.js'), javaScript);

const { candid, methodMeta } = await getCandidAndMethodMeta(
canisterConfig.custom?.candid_gen,
candidPath,
Expand All @@ -29,32 +31,14 @@ export async function runCommand(
wasmData
);

await outputFile(candidPath, candid);

const wasmBinary = await getWasmBinary(
ioType,
javaScript,
wasmData,
methodMeta
);

await writeGeneratedFiles(
canisterPath,
candidPath,
wasmBinaryPath,
candid,
javaScript,
wasmBinary
);
}

export async function writeGeneratedFiles(
canisterPath: string,
candidPath: string,
wasmBinaryPath: string,
candid: string,
javaScript: string,
wasmBinary: Uint8Array
): Promise<void> {
await outputFile(candidPath, candid);
await outputFile(join(canisterPath, 'main.js'), javaScript);
await outputFile(wasmBinaryPath, wasmBinary);
}

0 comments on commit aad34cb

Please sign in to comment.