Skip to content

Commit

Permalink
Merge branch 'main' into tom/ap-3253-update-cli-to-be-callable-from-n…
Browse files Browse the repository at this point in the history
…ode-and-return-buildid
  • Loading branch information
tmeasday committed Jun 9, 2023
2 parents 3964211 + 329cf67 commit e11f582
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 6.18.2 - 2023-06-07

- [758](https://github.com/chromaui/chromatic-cli/pull/758) Add additional logging for turbosnap
- [753](https://github.com/chromaui/chromatic-cli/pull/753) Update getStorybookMetadata to safely record version even if fails to parse mainConfig



# 6.18.0 - 2023-05-03

- [737](https://github.com/chromaui/chromatic-cli/pull/737) Better discovery for TurboSnap trace-changed and related directories
Expand Down
13 changes: 13 additions & 0 deletions node-src/lib/getDependentStoryFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export async function getDependentStoryFiles(
const storybookDir = normalize(posix(storybookConfigDir));
const staticDirs = staticDir.map((dir: string) => normalize(posix(dir)));

ctx.log.debug('BASE Directory:', baseDir);
ctx.log.debug('Storybook CONFIG Directory:', storybookDir);

// NOTE: this only works with `main:stories` -- if stories are imported from files in `.storybook/preview.js`
// we'll need a different approach to figure out CSF files (maybe the user should pass a glob?).
const storiesEntryFiles = [
Expand Down Expand Up @@ -231,6 +234,10 @@ export async function getDependentStoryFiles(
const normalizedName = namesById.get(id);
if (shouldBail(normalizedName)) return;

ctx.log.debug('Trace file...');
ctx.log.debug(name);
ctx.log.debug(id || 'no moduleId found for this file');

if (!id || !reasonsById.get(id) || checkedIds[id]) return;
// Queue this id for tracing
toCheck.push([id, [...tracePath, id]]);
Expand All @@ -241,6 +248,9 @@ export async function getDependentStoryFiles(
}
}

ctx.log.debug('Traced files...');
ctx.log.debug(tracedFiles);

// First, check the files that have changed according to git
tracedFiles.forEach((posixPath) => traceName(posixPath));
// If more were found during that process, check them too.
Expand All @@ -257,6 +267,9 @@ export async function getDependentStoryFiles(
Array.from(affectedModuleIds).map((id) => [String(id), files(namesById.get(id))])
);

ctx.log.debug('Affected modules...');
ctx.log.debug(affectedModules);

if (ctx.options.traceChanged) {
ctx.log.info(
tracedAffectedFiles(ctx, {
Expand Down
24 changes: 18 additions & 6 deletions node-src/lib/getStorybookMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ const findViewlayer = async ({ env, log, options, packageJson }) => {
};

const findAddons = async (ctx, mainConfig, v7) => {
if (!mainConfig) {
return { addons: [{ name: 'unknown', packageName: 'unknown', packageVersion: '0' }] };
}

const addons = v7
? await Promise.all(
mainConfig.getSafeFieldValue(['addons']).map((addon) => resolvePackageJson(addon))
Expand Down Expand Up @@ -159,6 +163,10 @@ const findConfigFlags = async ({ options, packageJson }) => {
};

export const findBuilder = async (mainConfig, v7) => {
if (!mainConfig) {
return { builder: { name: 'unknown', packageVersion: '0' } };
}

const framework = v7 ? mainConfig.getSafeFieldValue(['framework']) : mainConfig?.framework;
const core = v7 ? mainConfig.getSafeFieldValue(['core']) : mainConfig?.core;

Expand Down Expand Up @@ -195,12 +203,16 @@ export const getStorybookMetadata = async (ctx: Context) => {
let v7 = false;
try {
mainConfig = await r(path.resolve(configDir, 'main'));
} catch (e) {
const files = await readdir(configDir);
const mainConfigFileName = files.find((file) => file.startsWith('main')) || null;
const mainConfigFilePath = join(configDir, mainConfigFileName);
mainConfig = await readConfig(mainConfigFilePath);
v7 = true;
} catch (storybookV6error) {
try {
const files = await readdir(configDir);
const mainConfigFileName = files.find((file) => file.startsWith('main')) || null;
const mainConfigFilePath = join(configDir, mainConfigFileName);
mainConfig = await readConfig(mainConfigFilePath);
v7 = true;
} catch (storybookV7error) {
mainConfig = null;
}
}

const info = await Promise.allSettled([
Expand Down
4 changes: 1 addition & 3 deletions node-src/ui/messages/info/tracedAffectedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ export default (
let directoryDebug = null;

if (expanded) {
const bailReason = ctx.turboSnap?.bailReason
? `${chalk.magenta('Bail Reason:')} ${ctx.turboSnap.bailReason}\n\n`
: '';
const bailReason = ctx.turboSnap?.bailReason ? `${ctx.turboSnap.bailReason}\n\n` : '';
const rootPath = `${chalk.magenta(rootDirNote)} ${ctx.turboSnap.rootPath}\n\n`;
const basePath = `${chalk.magenta(baseDirNote)} ${basedir}\n\n`;
const storybookPath = `${chalk.magenta(storybookDirNote)} ${storybookConfigDir}\n\n`;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chromatic",
"version": "6.19.0-canary.2",
"version": "6.18.2",
"description": "Automate visual testing across browsers. Gather UI feedback. Versioned documentation.",
"keywords": [
"storybook-addon",
Expand Down

0 comments on commit e11f582

Please sign in to comment.