diff --git a/scripts/next-repro-generators/generate-repros.ts b/scripts/next-repro-generators/generate-repros.ts index 724ba4f2ad9..63f103d2b18 100755 --- a/scripts/next-repro-generators/generate-repros.ts +++ b/scripts/next-repro-generators/generate-repros.ts @@ -12,8 +12,7 @@ import reproTemplates from '../../code/lib/cli/src/repro-templates'; import storybookVersions from '../../code/lib/cli/src/versions'; import { JsPackageManagerFactory } from '../../code/lib/cli/src/js-package-manager/JsPackageManagerFactory'; -// @ts-expect-error (Converted from ts-ignore) -import { maxConcurrentTasks } from '../utils/concurrency'; +import { maxConcurrentTasks } from '../utils/maxConcurrentTasks'; import { localizeYarnConfigFiles, setupYarn } from './utils/yarn'; import { GeneratorConfig } from './utils/types'; diff --git a/scripts/task.ts b/scripts/task.ts index e66d35a0fa6..9cc7be90c95 100644 --- a/scripts/task.ts +++ b/scripts/task.ts @@ -71,7 +71,7 @@ export type Task = { /** * Is this task already "ready", and potentially not required? */ - ready: (details: TemplateDetails) => MaybePromise; + ready: (details: TemplateDetails, options: PassedOptionValues) => MaybePromise; /** * Run the task */ @@ -320,7 +320,9 @@ async function run() { }; const { sortedTasks, tasksThatDepend } = getTaskList(finalTask, optionValues); - const sortedTasksReady = await Promise.all(sortedTasks.map((t) => t.ready(details))); + const sortedTasksReady = await Promise.all( + sortedTasks.map((t) => t.ready(details, optionValues)) + ); logger.info(`Task readiness up to ${taskKey}`); const initialTaskStatus = (task: Task, ready: boolean) => { diff --git a/scripts/tasks/bootstrap-repo.ts b/scripts/tasks/bootstrap-repo.ts index dfd27459cdd..bd87c8a48e2 100644 --- a/scripts/tasks/bootstrap-repo.ts +++ b/scripts/tasks/bootstrap-repo.ts @@ -1,19 +1,29 @@ -import { pathExists } from 'fs-extra'; +import { readFile } from 'fs-extra'; import { resolve } from 'path'; +import { maxConcurrentTasks } from '../utils/maxConcurrentTasks'; import { exec } from '../utils/exec'; import type { Task } from '../task'; +const linkedContents = `export * from '../../src/index';`; +const linkCommand = `nx run-many --target="prep" --all --parallel --exclude=@storybook/addon-storyshots,@storybook/addon-storyshots-puppeteer -- --reset`; +const noLinkCommand = `nx run-many --target="prep" --all --parallel=8 ${ + process.env.CI ? `--max-parallel=${maxConcurrentTasks}` : '' +} -- --reset --optimized`; + export const bootstrapRepo: Task = { before: ['install-repo'], - async ready({ codeDir }) { - // TODO: Ask norbert - return pathExists(resolve(codeDir, './lib/store/dist/cjs/index.js')); + async ready({ codeDir }, { link }) { + const contents = await readFile(resolve(codeDir, './lib/store/dist/types/index.d.ts'), 'utf8'); + + if (!contents) return false; + + if (link) return contents === linkedContents; + return contents !== linkedContents; }, - async run() { - // TODO -- what if they want to do `bootstrap --core`? + async run(_, { link }) { return exec( - 'yarn bootstrap --prep', + link ? linkCommand : noLinkCommand, {}, { startMessage: '🥾 Bootstrapping', diff --git a/scripts/utils/maxConcurrentTasks.ts b/scripts/utils/maxConcurrentTasks.ts new file mode 100644 index 00000000000..645ab009962 --- /dev/null +++ b/scripts/utils/maxConcurrentTasks.ts @@ -0,0 +1,8 @@ +import { cpus } from 'os'; + +/** + * The maximum number of concurrent tasks we want to have on some CLI and CI tasks. + * The amount of CPUS minus one, arbitrary limited to 15 to not overload CI executors. + * @type {number} + */ +export const maxConcurrentTasks = Math.min(Math.max(1, cpus().length - 1), 15);