Skip to content
Merged
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
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@dfinity/identity": "^2.3.0",
"@dfinity/principal": "^2.3.0",
"@junobuild/admin": "^0.1.6",
"@junobuild/cli-tools": "^0.1.7-next-2025-04-05.2",
"@junobuild/cli-tools": "^0.1.7-next-2025-04-05.4",
"@junobuild/config-loader": "^0.2.0",
"@junobuild/core": "^0.1.9",
"@junobuild/did-tools": "^0.2.0",
Expand Down
3 changes: 0 additions & 3 deletions src/constants/dev.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,3 @@ export const PACKAGE_JSON_PATH = join(process.cwd(), 'package.json');

export const SPUTNIK_INDEX_MJS = 'sputnik.index.mjs';
export const DEPLOY_SPUTNIK_PATH = join(DEPLOY_LOCAL_REPLICA_PATH, SPUTNIK_INDEX_MJS);

export const SPUTNIK_PACKAGE_JSON = 'sputnik.package.json';
export const PACKAGE_JSON_SPUTNIK_PATH = join(DEPLOY_LOCAL_REPLICA_PATH, SPUTNIK_PACKAGE_JSON);
41 changes: 18 additions & 23 deletions src/services/build/build.javascript.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import {isEmptyString, isNullish, notEmptyString} from '@dfinity/utils';
import {isEmptyString, notEmptyString} from '@dfinity/utils';
import {buildEsm, execute, type PackageJson} from '@junobuild/cli-tools';
import type {Metafile} from 'esbuild';
import {green, magenta, red, yellow} from 'kleur';
import {existsSync} from 'node:fs';
import {mkdir, writeFile} from 'node:fs/promises';
import {mkdir} from 'node:fs/promises';
import {join} from 'node:path';
import {
DEPLOY_LOCAL_REPLICA_PATH,
DEPLOY_SPUTNIK_PATH,
DEVELOPER_PROJECT_SATELLITE_PATH,
INDEX_MJS,
INDEX_TS,
PACKAGE_JSON_PATH,
PACKAGE_JSON_SPUTNIK_PATH
PACKAGE_JSON_PATH
} from '../../constants/dev.constants';
import type {BuildArgs, BuildLang} from '../../types/build';
import {formatBytes, formatTime} from '../../utils/format.utils';
Expand All @@ -37,9 +36,7 @@ const build = async (params: BuildArgsTsJs) => {

const metadata = await prepareMetadata();

await copyMetadata(metadata);

const buildResult = await buildWithEsbuild(params);
const buildResult = await buildWithEsbuild({params, metadata});

printResults({metadata, buildResult});
};
Expand All @@ -49,13 +46,25 @@ interface BuildResult {
output: [string, Metafile['outputs'][0]];
}

const buildWithEsbuild = async ({lang, path}: BuildArgsTsJs): Promise<BuildResult> => {
const buildWithEsbuild = async ({
params: {lang, path},
metadata
}: {
params: BuildArgsTsJs;
metadata: BuildMetadata;
}): Promise<BuildResult> => {
const infile =
path ?? join(DEVELOPER_PROJECT_SATELLITE_PATH, lang === 'mjs' ? INDEX_MJS : INDEX_TS);

// We pass the package information as metadata so the Docker container can read it and embed it into the `juno:package` custom section of the WASM’s public metadata.
const banner = {
js: `// @juno:package ${JSON.stringify(metadata)};`
};

const {metafile, errors, warnings, version} = await buildEsm({
infile,
outfile: DEPLOY_SPUTNIK_PATH
outfile: DEPLOY_SPUTNIK_PATH,
banner
});

for (const {text} of warnings) {
Expand Down Expand Up @@ -145,20 +154,6 @@ const prepareMetadata = async (): Promise<BuildMetadata> => {
}
};

const copyMetadata = async (metadata: BuildMetadata): Promise<void> => {
if (isNullish(metadata)) {
// No metadata to pass to the build in the container.
return;
}

try {
await writeFile(PACKAGE_JSON_SPUTNIK_PATH, JSON.stringify(metadata, null, 2), 'utf-8');
} catch (_err: unknown) {
console.log(red('⚠️ Could not copy package.json metadata for the build.'));
process.exit(1);
}
};

const printResults = ({
metadata,
buildResult
Expand Down