diff --git a/packages/create-project/src/helpers/install.ts b/packages/create-project/src/helpers/install.ts index 724ef05e8..d9aac6843 100644 --- a/packages/create-project/src/helpers/install.ts +++ b/packages/create-project/src/helpers/install.ts @@ -75,9 +75,13 @@ export async function replaceSdkVersion({ root, sdkVersion }: InstallArgs): Prom const fileName = `${root}/package.json`; const packageJson = JSON.parse(await readFile(fileName, 'utf8')); - for (const packageName in packageJson.dependencies) { - if (packageName.startsWith('@temporalio/')) { - packageJson.dependencies[packageName] = sdkVersion; + for (const depType of ['dependencies', 'devDependencies', 'peerDependencies']) { + if (packageJson[depType]) { + for (const packageName in packageJson[depType]) { + if (packageName.startsWith('@temporalio/')) { + packageJson[depType][packageName] = sdkVersion; + } + } } } await writeFile(fileName, JSON.stringify(packageJson, null, 2)); diff --git a/scripts/init-from-verdaccio.js b/scripts/init-from-verdaccio.js index 9709a0f1b..141ecb3b5 100644 --- a/scripts/init-from-verdaccio.js +++ b/scripts/init-from-verdaccio.js @@ -14,7 +14,16 @@ async function main() { console.log('spawning npx @temporalio/create with args:', initArgs); try { const npmConfigFile = resolve(registryDir, 'npmrc-custom'); - const npmConfig = `@temporalio:registry=http://127.0.0.1:4873`; + let npmConfig = `@temporalio:registry=http://127.0.0.1:4873`; + + if (!process.env?.['CI']) { + // When testing on dev's local machine, uses an isolated NPM cache directory to avoid mixing + // existing @temporalio/* cached packages with the ones from the local registry. We don't do + // that in CI though, as it is not needed (i.e. there should be no such cached packages yet) + // and would slow down the tests (i.e. it requires redownloading ALL packages). + npmConfig += `\ncache=${resolve(registryDir, 'npm-cache')}`; + } + writeFileSync(npmConfigFile, npmConfig, { encoding: 'utf-8' }); await spawnNpx( diff --git a/scripts/utils.js b/scripts/utils.js index 397417514..4f82aeef4 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -50,4 +50,4 @@ async function spawnNpx(args, opts) { await waitOnChild(spawn(npx, npxArgs, { ...opts, shell })); } -module.exports = { kill, spawnNpx, ChildProcessError, shell, sleep }; +module.exports = { kill, spawnNpx, waitOnChild, ChildProcessError, shell, sleep };