From ff9828fccffd6b7fcb2b572143a98d59162a2740 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Tue, 23 Sep 2025 14:45:56 +0200 Subject: [PATCH 1/8] feat: juno run --- package-lock.json | 18 ++++++------- package.json | 2 +- src/commands/run.ts | 10 +++++++ src/index.ts | 7 +++++ src/services/run.services.ts | 51 ++++++++++++++++++++++++++++++++++++ 5 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 src/commands/run.ts create mode 100644 src/services/run.services.ts diff --git a/package-lock.json b/package-lock.json index 13107442..d137de67 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@junobuild/admin": "^2.2.2", "@junobuild/cdn": "^1.3.2", "@junobuild/cli-tools": "^0.7.2", - "@junobuild/config": "^2.1.1", + "@junobuild/config": "^2.1.1-next-2025-09-23.4", "@junobuild/config-loader": "^0.4.5", "@junobuild/core": "^2.1.2", "@junobuild/did-tools": "^0.3.3", @@ -1490,13 +1490,13 @@ } }, "node_modules/@junobuild/config": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@junobuild/config/-/config-2.1.1.tgz", - "integrity": "sha512-V8gqFrbg39TZhZvWgRobLcN5HEG4tLIQb58ZWZLHyK1LvbRKC7j3XaYZphkNAoxcqOte72dIdOxEROGdqr2H3w==", + "version": "2.1.1-next-2025-09-23.4", + "resolved": "https://registry.npmjs.org/@junobuild/config/-/config-2.1.1-next-2025-09-23.4.tgz", + "integrity": "sha512-TB8QxILvU6NaMc/DUh06n/0h5msjJ1mmHl/21I980b5EggrDbGMLsduYRM/DDTk6VBqYwOMVwpEE+aO1UEAnyA==", "license": "MIT", "peerDependencies": { - "@dfinity/zod-schemas": "^1.1.0", - "zod": "^3.25" + "@dfinity/zod-schemas": "*", + "zod": "*" } }, "node_modules/@junobuild/config-loader": { @@ -7304,9 +7304,9 @@ } }, "@junobuild/config": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@junobuild/config/-/config-2.1.1.tgz", - "integrity": "sha512-V8gqFrbg39TZhZvWgRobLcN5HEG4tLIQb58ZWZLHyK1LvbRKC7j3XaYZphkNAoxcqOte72dIdOxEROGdqr2H3w==", + "version": "2.1.1-next-2025-09-23.4", + "resolved": "https://registry.npmjs.org/@junobuild/config/-/config-2.1.1-next-2025-09-23.4.tgz", + "integrity": "sha512-TB8QxILvU6NaMc/DUh06n/0h5msjJ1mmHl/21I980b5EggrDbGMLsduYRM/DDTk6VBqYwOMVwpEE+aO1UEAnyA==", "requires": {} }, "@junobuild/config-loader": { diff --git a/package.json b/package.json index cc86fde0..85fe81b6 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@junobuild/admin": "^2.2.2", "@junobuild/cdn": "^1.3.2", "@junobuild/cli-tools": "^0.7.2", - "@junobuild/config": "^2.1.1", + "@junobuild/config": "^2.1.1-next-2025-09-23.4", "@junobuild/config-loader": "^0.4.5", "@junobuild/core": "^2.1.2", "@junobuild/did-tools": "^0.3.3", diff --git a/src/commands/run.ts b/src/commands/run.ts new file mode 100644 index 00000000..b9aa7ed0 --- /dev/null +++ b/src/commands/run.ts @@ -0,0 +1,10 @@ +import {logHelpDev} from '../help/dev.help'; +import {run as runServices} from '../services/run.services'; + +export const run = async (args?: string[]) => { + await runServices(args); +}; + +export const helpRun = (args?: string[]) => { + logHelpDev(args); +}; diff --git a/src/index.ts b/src/index.ts index 6e3ef8f1..5579423d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,6 +32,7 @@ import {logHelpUpgrade} from './help/upgrade.help'; import {logHelpVersion} from './help/version.help'; import {logHelpWhoAmI} from './help/whoami.help'; import {checkNodeVersion} from './utils/env.utils'; +import {helpRun, run as runCmd} from './commands/run'; export const run = async () => { const {valid} = checkNodeVersion(); @@ -85,6 +86,9 @@ export const run = async () => { case 'dev': helpDev(args); break; + case 'run': + helpRun(args); + break; case 'fn': case 'functions': helpFunctions(args); @@ -169,6 +173,9 @@ export const run = async () => { case 'dev': await dev(args); break; + case 'run': + await runCmd(args); + break; case 'fn': case 'functions': await functions(args); diff --git a/src/services/run.services.ts b/src/services/run.services.ts new file mode 100644 index 00000000..500c57df --- /dev/null +++ b/src/services/run.services.ts @@ -0,0 +1,51 @@ +import {assertNonNullish} from '@dfinity/utils'; +import {nextArg} from '@junobuild/cli-tools'; +import {TaskFnOrObjectSchema} from '@junobuild/config'; +import {build} from 'esbuild'; +import {extname} from 'node:path'; + +export const run = async (args?: string[]) => { + const infile = nextArg({args, option: '-s'}) ?? nextArg({args, option: '--src'}); + + // TODO + assertNonNullish(infile); + + const isPathTypeScript = extname(infile) === '.ts'; + + const {outputFiles} = await build({ + entryPoints: [infile], + bundle: true, + minify: true, + format: 'esm', + platform: 'node', + write: false, + supported: { + 'top-level-await': false, + 'inline-script': false + }, + define: { + self: 'globalThis' + }, + metafile: true, + banner: { + js: `import { createRequire as topLevelCreateRequire } from 'node:module'; +import { resolve } from 'node:path'; +const require = topLevelCreateRequire(resolve(process.cwd(), '.juno-pseudo-require-anchor.mjs'));` + } + }); + + const script = outputFiles[0].contents; + + const {onRun} = await import( + `data:text/javascript;base64,${Buffer.from(script).toString(`base64`)}` + ); + + if (typeof onRun === 'undefined') { + return; + } + + TaskFnOrObjectSchema.parse(onRun); + + const config = typeof onRun === 'function' ? onRun({}) : onRun; + await config.run({}); +}; From 36f35bd68704a538fb8412662d2830e87afad11c Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Wed, 24 Sep 2025 06:34:24 +0200 Subject: [PATCH 2/8] feat: wip --- package-lock.json | 14 +++++++------- package.json | 2 +- src/services/run.services.ts | 28 +++++++++++++++++++++------- src/utils/satellite.utils.ts | 2 ++ 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index d137de67..51330cb4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@junobuild/admin": "^2.2.2", "@junobuild/cdn": "^1.3.2", "@junobuild/cli-tools": "^0.7.2", - "@junobuild/config": "^2.1.1-next-2025-09-23.4", + "@junobuild/config": "^2.1.1-next-2025-09-24", "@junobuild/config-loader": "^0.4.5", "@junobuild/core": "^2.1.2", "@junobuild/did-tools": "^0.3.3", @@ -1490,9 +1490,9 @@ } }, "node_modules/@junobuild/config": { - "version": "2.1.1-next-2025-09-23.4", - "resolved": "https://registry.npmjs.org/@junobuild/config/-/config-2.1.1-next-2025-09-23.4.tgz", - "integrity": "sha512-TB8QxILvU6NaMc/DUh06n/0h5msjJ1mmHl/21I980b5EggrDbGMLsduYRM/DDTk6VBqYwOMVwpEE+aO1UEAnyA==", + "version": "2.1.1-next-2025-09-24", + "resolved": "https://registry.npmjs.org/@junobuild/config/-/config-2.1.1-next-2025-09-24.tgz", + "integrity": "sha512-09jBX0AMgCAs+TRQCBmi479BJ2itUgvi4XOxX/HRVLsx98ZBwZlLY0tVr9aKp16hWVYazZjYxBDRRHKnztGcBA==", "license": "MIT", "peerDependencies": { "@dfinity/zod-schemas": "*", @@ -7304,9 +7304,9 @@ } }, "@junobuild/config": { - "version": "2.1.1-next-2025-09-23.4", - "resolved": "https://registry.npmjs.org/@junobuild/config/-/config-2.1.1-next-2025-09-23.4.tgz", - "integrity": "sha512-TB8QxILvU6NaMc/DUh06n/0h5msjJ1mmHl/21I980b5EggrDbGMLsduYRM/DDTk6VBqYwOMVwpEE+aO1UEAnyA==", + "version": "2.1.1-next-2025-09-24", + "resolved": "https://registry.npmjs.org/@junobuild/config/-/config-2.1.1-next-2025-09-24.tgz", + "integrity": "sha512-09jBX0AMgCAs+TRQCBmi479BJ2itUgvi4XOxX/HRVLsx98ZBwZlLY0tVr9aKp16hWVYazZjYxBDRRHKnztGcBA==", "requires": {} }, "@junobuild/config-loader": { diff --git a/package.json b/package.json index 85fe81b6..abd58752 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@junobuild/admin": "^2.2.2", "@junobuild/cdn": "^1.3.2", "@junobuild/cli-tools": "^0.7.2", - "@junobuild/config": "^2.1.1-next-2025-09-23.4", + "@junobuild/config": "^2.1.1-next-2025-09-24", "@junobuild/config-loader": "^0.4.5", "@junobuild/core": "^2.1.2", "@junobuild/did-tools": "^0.3.3", diff --git a/src/services/run.services.ts b/src/services/run.services.ts index 500c57df..107a46cf 100644 --- a/src/services/run.services.ts +++ b/src/services/run.services.ts @@ -1,8 +1,10 @@ +import {Principal} from '@dfinity/principal'; import {assertNonNullish} from '@dfinity/utils'; import {nextArg} from '@junobuild/cli-tools'; -import {TaskFnOrObjectSchema} from '@junobuild/config'; +import {OnRunSchema} from '@junobuild/config'; import {build} from 'esbuild'; -import {extname} from 'node:path'; +import {ENV} from '../env'; +import {assertConfigAndLoadSatelliteContext} from '../utils/satellite.utils'; export const run = async (args?: string[]) => { const infile = nextArg({args, option: '-s'}) ?? nextArg({args, option: '--src'}); @@ -10,8 +12,6 @@ export const run = async (args?: string[]) => { // TODO assertNonNullish(infile); - const isPathTypeScript = extname(infile) === '.ts'; - const {outputFiles} = await build({ entryPoints: [infile], bundle: true, @@ -44,8 +44,22 @@ const require = topLevelCreateRequire(resolve(process.cwd(), '.juno-pseudo-requi return; } - TaskFnOrObjectSchema.parse(onRun); + const task = + typeof onRun === 'function' + ? onRun({ + mode: ENV.mode, + profile: ENV.profile + }) + : onRun; + + const assertedTask = OnRunSchema.parse(task); - const config = typeof onRun === 'function' ? onRun({}) : onRun; - await config.run({}); + const { + satellite: {satelliteId, identity} + } = await assertConfigAndLoadSatelliteContext(); + + await assertedTask.run({ + satelliteId: Principal.fromText(satelliteId), + identity + }); }; diff --git a/src/utils/satellite.utils.ts b/src/utils/satellite.utils.ts index f99b4abd..77a4f9c0 100644 --- a/src/utils/satellite.utils.ts +++ b/src/utils/satellite.utils.ts @@ -60,6 +60,8 @@ const assertAndReadSatelliteId = ({ const satelliteId = ids?.[mode] ?? id ?? deprecatedSatelliteId; + // TODO: Principal.isPrincipal + if (isNullish(satelliteId)) { console.log(red(`A satellite ID for ${mode} must be set in your configuration.`)); process.exit(1); From c688c51a0c9e57f65ab50923a522edd983f8c637 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Wed, 24 Sep 2025 06:40:33 +0200 Subject: [PATCH 3/8] feat: help --- src/commands/run.ts | 4 ++-- src/constants/help.constants.ts | 1 + src/help/run.help.ts | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/help/run.help.ts diff --git a/src/commands/run.ts b/src/commands/run.ts index b9aa7ed0..65763831 100644 --- a/src/commands/run.ts +++ b/src/commands/run.ts @@ -1,4 +1,4 @@ -import {logHelpDev} from '../help/dev.help'; +import {logHelpRun} from '../help/run.help'; import {run as runServices} from '../services/run.services'; export const run = async (args?: string[]) => { @@ -6,5 +6,5 @@ export const run = async (args?: string[]) => { }; export const helpRun = (args?: string[]) => { - logHelpDev(args); + logHelpRun(args); }; diff --git a/src/constants/help.constants.ts b/src/constants/help.constants.ts index c6fed6d4..e75a2e34 100644 --- a/src/constants/help.constants.ts +++ b/src/constants/help.constants.ts @@ -23,6 +23,7 @@ export const VERSION_DESCRIPTION = 'Check the version of the CLI.'; export const STATUS_DESCRIPTION = 'Check the status of the modules.'; export const WHOAMI_DESCRIPTION = 'Display your current profile, access key, and links to your satellite.'; +export const RUN_DESCRIPTION = 'Run a custom script in the CLI context.'; export const EMULATOR_START_DESCRIPTION = 'Start the emulator for local development.'; export const EMULATOR_WAIT_DESCRIPTION = 'Wait until the emulator is ready.'; diff --git a/src/help/run.help.ts b/src/help/run.help.ts new file mode 100644 index 00000000..913e1a79 --- /dev/null +++ b/src/help/run.help.ts @@ -0,0 +1,29 @@ +import {cyan, green, yellow} from 'kleur'; +import {RUN_DESCRIPTION, OPTIONS_ENV, OPTION_HELP} from '../constants/help.constants'; +import {helpOutput} from './common.help'; +import {TITLE} from './help'; + +const usage = `Usage: ${green('juno')} ${cyan('run')} ${yellow('[options]')} + +Options: + ${yellow('-s, --src')} The path to your JavaScript or TypeScript script. + ${OPTIONS_ENV} + ${OPTION_HELP}`; + +const doc = `${RUN_DESCRIPTION} + +\`\`\` +${usage} +\`\`\` +`; + +const help = `${TITLE} + +${RUN_DESCRIPTION} + +${usage} +`; + +export const logHelpRun = (args?: string[]) => { + console.log(helpOutput(args) === 'doc' ? doc : help); +}; From 8f03cc39076d94d7375e1128de8c7eb92b39b3af Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Wed, 24 Sep 2025 07:20:04 +0200 Subject: [PATCH 4/8] feat: review --- src/constants/help.constants.ts | 3 +- src/help/run.help.ts | 10 +- .../build/build.javascript.services.ts | 35 +----- src/services/run.services.ts | 105 +++++++++++++----- src/utils/esbuild.utils.ts | 30 +++++ 5 files changed, 118 insertions(+), 65 deletions(-) create mode 100644 src/utils/esbuild.utils.ts diff --git a/src/constants/help.constants.ts b/src/constants/help.constants.ts index e75a2e34..2c6e6743 100644 --- a/src/constants/help.constants.ts +++ b/src/constants/help.constants.ts @@ -59,8 +59,9 @@ export const OPTIONS_BUILD = `${yellow('-l, --lang')} Specify the lan ${yellow('--source-path')} Optional path to the TypeScript or JavaScript entry file.`; export const OPTIONS_CONFIG = `${OPTION_MODE} ${OPTION_PROFILE}`; +export const OPTIONS_CONTAINER = `${yellow('--container-url')} Override a custom container URL. If not provided, defaults to production or the local container in development mode.`; export const OPTIONS_ENV = `${OPTIONS_CONFIG} - ${yellow('--container-url')} Override a custom container URL. If not provided, defaults to production or the local container in development mode. + ${OPTIONS_CONTAINER} ${yellow('--console-url')} Specify a custom URL to access the developer Console.`; export const NOTE_KEEP_STAGED = `The option ${yellow('--keep-staged')} only applies when ${yellow('--no-apply')} is NOT used (i.e. the change is applied immediately).`; diff --git a/src/help/run.help.ts b/src/help/run.help.ts index 913e1a79..93253669 100644 --- a/src/help/run.help.ts +++ b/src/help/run.help.ts @@ -1,5 +1,10 @@ import {cyan, green, yellow} from 'kleur'; -import {RUN_DESCRIPTION, OPTIONS_ENV, OPTION_HELP} from '../constants/help.constants'; +import { + OPTION_HELP, + OPTIONS_CONFIG, + OPTIONS_CONTAINER, + RUN_DESCRIPTION +} from '../constants/help.constants'; import {helpOutput} from './common.help'; import {TITLE} from './help'; @@ -7,7 +12,8 @@ const usage = `Usage: ${green('juno')} ${cyan('run')} ${yellow('[options]')} Options: ${yellow('-s, --src')} The path to your JavaScript or TypeScript script. - ${OPTIONS_ENV} + ${OPTIONS_CONFIG} + ${OPTIONS_CONTAINER} ${OPTION_HELP}`; const doc = `${RUN_DESCRIPTION} diff --git a/src/services/functions/build/build.javascript.services.ts b/src/services/functions/build/build.javascript.services.ts index 119d57f4..5c57220f 100644 --- a/src/services/functions/build/build.javascript.services.ts +++ b/src/services/functions/build/build.javascript.services.ts @@ -1,7 +1,7 @@ import {notEmptyString} from '@dfinity/utils'; -import {buildEsm, execute, formatBytes} from '@junobuild/cli-tools'; +import {buildEsm, formatBytes} from '@junobuild/cli-tools'; import type {Metafile} from 'esbuild'; -import {green, magenta, red, yellow} from 'kleur'; +import {green, red, yellow} from 'kleur'; import {join} from 'node:path'; import { DEPLOY_SPUTNIK_PATH, @@ -10,9 +10,8 @@ import { INDEX_TS } from '../../../constants/dev.constants'; import type {BuildArgs, BuildLang, BuildMetadata} from '../../../types/build'; +import {installEsbuild} from '../../../utils/esbuild.utils'; import {formatTime} from '../../../utils/format.utils'; -import {detectPackageManager} from '../../../utils/pm.utils'; -import {confirmAndExit} from '../../../utils/prompt.utils'; import {readEmulatorConfigAndCreateDeployTargetDir} from '../../emulator/_fs.services'; import {prepareJavaScriptBuildMetadata} from './build.metadata.services'; @@ -101,34 +100,6 @@ const buildWithEsbuild = async ({ }; }; -const installEsbuild = async () => { - const esbuildInstalled = await hasEsbuild(); - - if (esbuildInstalled) { - return; - } - - await confirmAndExit( - `${magenta('esbuild')} is required to build the serverless functions. Install it now?` - ); - - const pm = detectPackageManager(); - - await execute({ - command: pm ?? 'npm', - args: [pm === 'npm' ? 'i' : 'add', 'esbuild', '-D'] - }); -}; - -const hasEsbuild = async (): Promise => { - try { - await import('esbuild'); - return true; - } catch (_err: unknown) { - return false; - } -}; - const printResults = ({ metadata, buildResult diff --git a/src/services/run.services.ts b/src/services/run.services.ts index 107a46cf..fde6edfd 100644 --- a/src/services/run.services.ts +++ b/src/services/run.services.ts @@ -1,17 +1,85 @@ import {Principal} from '@dfinity/principal'; -import {assertNonNullish} from '@dfinity/utils'; +import {assertNonNullish, isNullish, nonNullish} from '@dfinity/utils'; import {nextArg} from '@junobuild/cli-tools'; -import {OnRunSchema} from '@junobuild/config'; +import {OnRunSchema, type RunFnOrObject, RunFnOrObjectSchema} from '@junobuild/config'; import {build} from 'esbuild'; +import {red, yellow} from 'kleur'; +import {readFile} from 'node:fs/promises'; +import {extname} from 'node:path'; import {ENV} from '../env'; import {assertConfigAndLoadSatelliteContext} from '../utils/satellite.utils'; export const run = async (args?: string[]) => { const infile = nextArg({args, option: '-s'}) ?? nextArg({args, option: '--src'}); - // TODO - assertNonNullish(infile); + if (isNullish(infile)) { + console.log(red('Missing required path to script: --src ')); + return; + } + + const {onRun} = await importOnRun({infile}); + + if (isNullish(onRun)) { + console.log(yellow('Cannot import a task to run. 🤷‍♂️')); + console.log(`\nDoes your script ${infile} export a function named "onRun"?`); + return; + } + + if (!RunFnOrObjectSchema.safeParse(onRun).success) { + console.log(red('Your "onRun" export is invalid. It must be of type RunFnOrObject.')); + return; + } + + const job = + typeof onRun === 'function' + ? onRun({ + mode: ENV.mode, + profile: ENV.profile + }) + : onRun; + + const assertJob = OnRunSchema.safeParse(job); + + if (!assertJob.success) { + console.log(red('Your job to run is invalid. It must be of type OnRun.')); + return; + } + + const {data: assertedJob} = assertJob; + + const { + satellite: {satelliteId, identity} + } = await assertConfigAndLoadSatelliteContext(); + + await assertedJob.run({ + satelliteId: Principal.fromText(satelliteId), + identity, + ...(nonNullish(ENV.containerUrl) && {container: ENV.containerUrl}) + }); +}; +const importOnRun = async ({ + infile +}: { + infile: string; +}): Promise<{onRun: RunFnOrObject | undefined}> => { + const isTypeScript = extname(infile) === '.ts'; + + const {code} = await (isTypeScript ? buildCode({infile}) : readCode({infile})); + + const {onRun} = await import( + `data:text/javascript;base64,${Buffer.from(code).toString(`base64`)}` + ); + + return {onRun: typeof onRun === 'undefined' ? undefined : onRun}; +}; + +const readCode = async ({infile}: {infile: string}): Promise<{code: Uint8Array}> => { + const code = await readFile(infile); + return {code}; +}; + +const buildCode = async ({infile}: {infile: string}): Promise<{code: Uint8Array}> => { const {outputFiles} = await build({ entryPoints: [infile], bundle: true, @@ -34,32 +102,9 @@ const require = topLevelCreateRequire(resolve(process.cwd(), '.juno-pseudo-requi } }); - const script = outputFiles[0].contents; - - const {onRun} = await import( - `data:text/javascript;base64,${Buffer.from(script).toString(`base64`)}` - ); - - if (typeof onRun === 'undefined') { - return; - } - - const task = - typeof onRun === 'function' - ? onRun({ - mode: ENV.mode, - profile: ENV.profile - }) - : onRun; - - const assertedTask = OnRunSchema.parse(task); + const code = outputFiles[0]?.contents; - const { - satellite: {satelliteId, identity} - } = await assertConfigAndLoadSatelliteContext(); + assertNonNullish(code, 'No script build'); - await assertedTask.run({ - satelliteId: Principal.fromText(satelliteId), - identity - }); + return {code}; }; diff --git a/src/utils/esbuild.utils.ts b/src/utils/esbuild.utils.ts new file mode 100644 index 00000000..925f8e39 --- /dev/null +++ b/src/utils/esbuild.utils.ts @@ -0,0 +1,30 @@ +import {execute} from '@junobuild/cli-tools'; +import {magenta} from 'kleur'; +import {detectPackageManager} from './pm.utils'; +import {confirmAndExit} from './prompt.utils'; + +export const installEsbuild = async () => { + const esbuildInstalled = await hasEsbuild(); + + if (esbuildInstalled) { + return; + } + + await confirmAndExit(`${magenta('esbuild')} is required for building. Install it now?`); + + const pm = detectPackageManager(); + + await execute({ + command: pm ?? 'npm', + args: [pm === 'npm' ? 'i' : 'add', 'esbuild', '-D'] + }); +}; + +const hasEsbuild = async (): Promise => { + try { + await import('esbuild'); + return true; + } catch (_err: unknown) { + return false; + } +}; From 07f65bbbd818ab54c78280e84a01a43dc07946cd Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Wed, 24 Sep 2025 07:20:19 +0200 Subject: [PATCH 5/8] chore: fmt --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 5579423d..5c794c26 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,6 +10,7 @@ import {emulator, helpEmulator} from './commands/emulator'; import {functions, helpFunctions} from './commands/functions'; import {init} from './commands/init'; import {open} from './commands/open'; +import {helpRun, run as runCmd} from './commands/run'; import {snapshot} from './commands/snapshot'; import {startStop} from './commands/start-stop'; import {status} from './commands/status'; @@ -32,7 +33,6 @@ import {logHelpUpgrade} from './help/upgrade.help'; import {logHelpVersion} from './help/version.help'; import {logHelpWhoAmI} from './help/whoami.help'; import {checkNodeVersion} from './utils/env.utils'; -import {helpRun, run as runCmd} from './commands/run'; export const run = async () => { const {valid} = checkNodeVersion(); From 32397203e0a93b5d044b609804e8a474414130f3 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Wed, 24 Sep 2025 07:22:00 +0200 Subject: [PATCH 6/8] feat: we need to build js as well --- src/services/run.services.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/services/run.services.ts b/src/services/run.services.ts index fde6edfd..2e416dad 100644 --- a/src/services/run.services.ts +++ b/src/services/run.services.ts @@ -4,8 +4,6 @@ import {nextArg} from '@junobuild/cli-tools'; import {OnRunSchema, type RunFnOrObject, RunFnOrObjectSchema} from '@junobuild/config'; import {build} from 'esbuild'; import {red, yellow} from 'kleur'; -import {readFile} from 'node:fs/promises'; -import {extname} from 'node:path'; import {ENV} from '../env'; import {assertConfigAndLoadSatelliteContext} from '../utils/satellite.utils'; @@ -63,9 +61,7 @@ const importOnRun = async ({ }: { infile: string; }): Promise<{onRun: RunFnOrObject | undefined}> => { - const isTypeScript = extname(infile) === '.ts'; - - const {code} = await (isTypeScript ? buildCode({infile}) : readCode({infile})); + const {code} = await buildCode({infile}); const {onRun} = await import( `data:text/javascript;base64,${Buffer.from(code).toString(`base64`)}` @@ -74,11 +70,6 @@ const importOnRun = async ({ return {onRun: typeof onRun === 'undefined' ? undefined : onRun}; }; -const readCode = async ({infile}: {infile: string}): Promise<{code: Uint8Array}> => { - const code = await readFile(infile); - return {code}; -}; - const buildCode = async ({infile}: {infile: string}): Promise<{code: Uint8Array}> => { const {outputFiles} = await build({ entryPoints: [infile], From bc078f5bb01855fea3f679a4d393b0f41e877b97 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Wed, 24 Sep 2025 07:22:47 +0200 Subject: [PATCH 7/8] feat: no space --- src/services/run.services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/run.services.ts b/src/services/run.services.ts index 2e416dad..8030566a 100644 --- a/src/services/run.services.ts +++ b/src/services/run.services.ts @@ -19,7 +19,7 @@ export const run = async (args?: string[]) => { if (isNullish(onRun)) { console.log(yellow('Cannot import a task to run. 🤷‍♂️')); - console.log(`\nDoes your script ${infile} export a function named "onRun"?`); + console.log(`Does your script ${infile} export a function named "onRun"?`); return; } From e5b43bd7c7889a6a8a46eebbd61933d3dd7a4c0f Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Wed, 24 Sep 2025 08:56:36 +0200 Subject: [PATCH 8/8] build: use released config --- package-lock.json | 18 +++++++++--------- package.json | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 51330cb4..c5da8a0a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@junobuild/admin": "^2.2.2", "@junobuild/cdn": "^1.3.2", "@junobuild/cli-tools": "^0.7.2", - "@junobuild/config": "^2.1.1-next-2025-09-24", + "@junobuild/config": "^2.2.0", "@junobuild/config-loader": "^0.4.5", "@junobuild/core": "^2.1.2", "@junobuild/did-tools": "^0.3.3", @@ -1490,13 +1490,13 @@ } }, "node_modules/@junobuild/config": { - "version": "2.1.1-next-2025-09-24", - "resolved": "https://registry.npmjs.org/@junobuild/config/-/config-2.1.1-next-2025-09-24.tgz", - "integrity": "sha512-09jBX0AMgCAs+TRQCBmi479BJ2itUgvi4XOxX/HRVLsx98ZBwZlLY0tVr9aKp16hWVYazZjYxBDRRHKnztGcBA==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@junobuild/config/-/config-2.2.0.tgz", + "integrity": "sha512-nRhvQ02CdDuKL3fCGoMrY0zRc/MHOZg8Z9swIhFXyXf1cPNurNN4c5ek1okZA5okAUIchF9WXEXhVGRIU+6Lkg==", "license": "MIT", "peerDependencies": { - "@dfinity/zod-schemas": "*", - "zod": "*" + "@dfinity/zod-schemas": "^1.1.0", + "zod": "^3.25" } }, "node_modules/@junobuild/config-loader": { @@ -7304,9 +7304,9 @@ } }, "@junobuild/config": { - "version": "2.1.1-next-2025-09-24", - "resolved": "https://registry.npmjs.org/@junobuild/config/-/config-2.1.1-next-2025-09-24.tgz", - "integrity": "sha512-09jBX0AMgCAs+TRQCBmi479BJ2itUgvi4XOxX/HRVLsx98ZBwZlLY0tVr9aKp16hWVYazZjYxBDRRHKnztGcBA==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@junobuild/config/-/config-2.2.0.tgz", + "integrity": "sha512-nRhvQ02CdDuKL3fCGoMrY0zRc/MHOZg8Z9swIhFXyXf1cPNurNN4c5ek1okZA5okAUIchF9WXEXhVGRIU+6Lkg==", "requires": {} }, "@junobuild/config-loader": { diff --git a/package.json b/package.json index abd58752..ecea8984 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@junobuild/admin": "^2.2.2", "@junobuild/cdn": "^1.3.2", "@junobuild/cli-tools": "^0.7.2", - "@junobuild/config": "^2.1.1-next-2025-09-24", + "@junobuild/config": "^2.2.0", "@junobuild/config-loader": "^0.4.5", "@junobuild/core": "^2.1.2", "@junobuild/did-tools": "^0.3.3",