Skip to content

Commit

Permalink
fix(devkit): catch errors resolving configs while formatting files (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored May 9, 2023
1 parent 854b180 commit ec22b7e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
34 changes: 17 additions & 17 deletions packages/devkit/src/generators/format-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ export async function formatFiles(tree: Tree): Promise<void> {

await Promise.all(
Array.from(files).map(async (file) => {
const systemPath = path.join(tree.root, file.path);
try {
const systemPath = path.join(tree.root, file.path);

const resolvedOptions = await prettier.resolveConfig(systemPath, {
editorconfig: true,
});
const resolvedOptions = await prettier.resolveConfig(systemPath, {
editorconfig: true,
});

const options: Prettier.Options = {
...resolvedOptions,
...changedPrettierInTree,
filepath: systemPath,
};
const options: Prettier.Options = {
...resolvedOptions,
...changedPrettierInTree,
filepath: systemPath,
};

if (file.path.endsWith('.swcrc')) {
options.parser = 'json';
}
if (file.path.endsWith('.swcrc')) {
options.parser = 'json';
}

const support = await prettier.getFileInfo(systemPath, options as any);
if (support.ignored || !support.inferredParser) {
return;
}
const support = await prettier.getFileInfo(systemPath, options as any);
if (support.ignored || !support.inferredParser) {
return;
}

try {
tree.write(
file.path,
prettier.format(file.content.toString('utf-8'), options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ export async function formatChangedFilesWithPrettierIfAvailable(
);
await Promise.all(
Array.from(files).map(async (file) => {
const systemPath = path.join(tree.root, file.path);
let options: any = {
filepath: systemPath,
};
try {
const systemPath = path.join(tree.root, file.path);
let options: any = {
filepath: systemPath,
};

const resolvedOptions = await prettier.resolveConfig(systemPath, {
editorconfig: true,
});
if (!resolvedOptions) {
return;
}
options = {
...options,
...resolvedOptions,
};
const resolvedOptions = await prettier.resolveConfig(systemPath, {
editorconfig: true,
});
if (!resolvedOptions) {
return;
}
options = {
...options,
...resolvedOptions,
};

const support = await prettier.getFileInfo(systemPath, options);
if (support.ignored || !support.inferredParser) {
return;
}
const support = await prettier.getFileInfo(systemPath, options);
if (support.ignored || !support.inferredParser) {
return;
}

try {
tree.write(
file.path,
prettier.format(file.content.toString('utf-8'), options)
Expand Down

1 comment on commit ec22b7e

@vercel
Copy link

@vercel vercel bot commented on ec22b7e May 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev

Please sign in to comment.