From 67f0307ef56c8a8ea1e29006f771a0575d82c24e Mon Sep 17 00:00:00 2001 From: Ian Thomas Date: Mon, 2 Dec 2024 09:09:03 +0000 Subject: [PATCH] Add COCKLE_WASM_EXTRA_CHANNEL env var to get wasm command packages from local directory (#79) --- CHANGELOG.md | 2 +- src/tools/prepare_wasm.ts | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f365274..44abcca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ - Check and recreate cockle_wasm_env if it does not contain all required packages [#72](https://github.com/jupyterlite/cockle/pull/72) ([@ianthomas23](https://github.com/ianthomas23)) - Separate external and internal defs [#70](https://github.com/jupyterlite/cockle/pull/70) ([@ianthomas23](https://github.com/ianthomas23)) - Add tests for cp and mv [#68](https://github.com/jupyterlite/cockle/pull/68) ([@ianthomas23](https://github.com/ianthomas23)) -- Support filename expansion of * and ? [#67](https://github.com/jupyterlite/cockle/pull/67) ([@ianthomas23](https://github.com/ianthomas23)) +- Support filename expansion of \* and ? [#67](https://github.com/jupyterlite/cockle/pull/67) ([@ianthomas23](https://github.com/ianthomas23)) - Add Shell.dispose and new exit command [#66](https://github.com/jupyterlite/cockle/pull/66) ([@ianthomas23](https://github.com/ianthomas23)) ### Bugs fixed diff --git a/src/tools/prepare_wasm.ts b/src/tools/prepare_wasm.ts index 7470744..146ccf8 100644 --- a/src/tools/prepare_wasm.ts +++ b/src/tools/prepare_wasm.ts @@ -17,7 +17,7 @@ const zod = require('zod'); const ENV_NAME = 'cockle_wasm_env'; const PLATFORM = 'emscripten-wasm32'; -const REPOS = '-c https://repo.mamba.pm/emscripten-forge -c https://repo.mamba.pm/conda-forge'; +const CHANNELS = ['https://repo.mamba.pm/emscripten-forge', 'https://repo.mamba.pm/conda-forge']; if (process.argv.length !== 4 || (process.argv[2] !== '--list' && process.argv[2] !== '--copy')) { console.log('Usage: prepare_wasm --list list-filename'); @@ -31,11 +31,24 @@ function isLocalPackage(packageConfig: object): boolean { return Object.hasOwn(packageConfig, 'local_directory'); } +function getChannelsString(): string { + console.log('Using channels:'); + CHANNELS.map(channel => console.log(` ${channel}`)); + return CHANNELS.map(channel => `-c ${channel}`).join(' '); +} + function getWasmPackageInfo(micromambaCmd: string, envPath: string): any { const cmd = `${micromambaCmd} -p ${envPath} list --json`; return JSON.parse(execSync(cmd).toString()); } +// Handle environment variables. +const COCKLE_WASM_EXTRA_CHANNEL = process.env.COCKLE_WASM_EXTRA_CHANNEL; +if (COCKLE_WASM_EXTRA_CHANNEL !== undefined) { + // Prepend so used first. + CHANNELS.unshift(COCKLE_WASM_EXTRA_CHANNEL); +} + // Base cockle config file from this repo. const baseConfigFilename = path.join(__dirname, '..', '..', 'cockle-config-base.json'); console.log('Using base config', baseConfigFilename); @@ -114,7 +127,7 @@ if (fs.existsSync(envPath)) { } if (wasmPackageInfo === undefined) { - const suffix = `--platform=${PLATFORM} ${REPOS}`; + const suffix = `--platform=${PLATFORM} ${getChannelsString()}`; console.log(`Creating new environment in ${envPath}`); const createEnvCmd = `${micromambaCmd} create -p ${envPath} -y ${packageNames.join(' ')} ${suffix}`; console.log(execSync(createEnvCmd).toString());