Bootstrap directly in the bootstrap task

This commit is contained in:
Tom Coleman 2022-10-04 20:54:40 +11:00
parent 56b504be1b
commit ecff39f1b2
4 changed files with 30 additions and 11 deletions

View File

@ -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';

View File

@ -71,7 +71,7 @@ export type Task = {
/**
* Is this task already "ready", and potentially not required?
*/
ready: (details: TemplateDetails) => MaybePromise<boolean>;
ready: (details: TemplateDetails, options: PassedOptionValues) => MaybePromise<boolean>;
/**
* 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) => {

View File

@ -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',

View File

@ -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);