Skip to content

Commit

Permalink
feat: bump prettier and add lib publishing checks
Browse files Browse the repository at this point in the history
  • Loading branch information
SimeonC committed Jul 28, 2023
1 parent 2aa346e commit 6a61092
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 34 deletions.
132 changes: 119 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"lodash": "^4.17.21",
"nx": "16.5.0",
"nx-cloud": "16.0.5",
"prettier": "2.8.8",
"prettier": "3.0.0",
"storybook": "^6.5.16",
"type-fest": "4.0.0",
"typescript": "5.1.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config/src/rules/namingConvention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const namingRules: Linter.RulesRecord = {
},
},
{
selector: ['property'],
selector: ['property', 'parameterProperty'],
format: ['camelCase', 'PascalCase', 'snake_case', 'UPPER_CASE'],
leadingUnderscore: 'allowDouble', // double for __html
},
Expand All @@ -109,7 +109,7 @@ export const namingRules: Linter.RulesRecord = {
},
{
selector: 'parameter',
format: ['camelCase'],
format: ['camelCase', 'PascalCase'],
leadingUnderscore: 'allow',
},
],
Expand Down
6 changes: 6 additions & 0 deletions packages/eslint-config/src/rules/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export const reactRules: Linter.RulesRecord = {
'react/prop-types': 'off',
// see https://github.com/jsx-eslint/eslint-plugin-react/issues/3384#issuecomment-1236371796
'react/no-unknown-property': ['error', { ignore: ['css'] }],
'react/no-unstable-nested-components': [
'error',
{
allowAsProps: true,
},
],

// These cause typing conflicts
'react/require-default-props': ['off'],
Expand Down
23 changes: 13 additions & 10 deletions packages/eslint-plugin/src/shortestImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,22 @@ export const shortestImport: TSESLint.RuleModule<
.readdirSync(baseUrl, {
withFileTypes: true,
})
.reduce((directoryMap, dirrent) => {
if (dirrent.isDirectory())
.reduce(
(directoryMap, dirrent) => {
if (dirrent.isDirectory())
return {
...directoryMap,
[dirrent.name]: path.join(relativeBaseUrl, dirrent.name),
};
return {
...directoryMap,
[dirrent.name]: path.join(relativeBaseUrl, dirrent.name),
[dirrent.name.replace(/\.[^.]+$/gi, '')]: path
.join(relativeBaseUrl, dirrent.name)
.replace(/^\.\//gi, ''),
};
return {
...directoryMap,
[dirrent.name.replace(/\.[^.]+$/gi, '')]: path
.join(relativeBaseUrl, dirrent.name)
.replace(/^\.\//gi, ''),
};
}, {} as Record<string, string>)
},
{} as Record<string, string>,
)
: {};
const compilerPaths = Object.entries(compilerOptions.paths ?? {}).reduce(
(compilerPathsMap, [key, [value]]) => ({
Expand Down
5 changes: 3 additions & 2 deletions packages/nx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@
"flat": "5.0.2",
"fs-extra": "11.1.1",
"lodash": "4.17.21",
"prettier": "^2"
"prettier": "^3",
"publint": "0.2.0",
"tsimportlib": "0.0.5"
},
"devDependencies": {
"@types/flat": "5.0.2",
"@types/lodash": "4.14.195",
"@types/prettier": "2.7.3",
"type-fest": "4.0.0",
"typescript": "5.1.6"
},
Expand Down
41 changes: 39 additions & 2 deletions packages/nx/src/executors/build-lib/executor.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,52 @@
import { ExecutorContext } from '@nx/devkit';
import { buildPackage } from '@tablecheck/frontend-library';
import { dynamicImport } from 'tsimportlib';

import { BuildLibExecutorSchema } from './schema.js';

export default async function runExecutor(
options: BuildLibExecutorSchema,
context: ExecutorContext,
) {
if (!context.projectName) {
throw new Error('Lib build must be run on a project');
}
const metadata =
context.projectsConfigurations?.projects[context.projectName || '.'];
context.projectsConfigurations?.projects[context.projectName];
if (!metadata) {
throw new Error(
`Could not find project configuration for ${context.projectName}`,
);
}
const isBuildSuccessful = await buildPackage({
cwd: metadata.root,
...options,
});

const { publint } = (await dynamicImport(
'publint',
module,
// @ts-expect-error - this is a dynamic import
)) as typeof import('publint');

const { messages } = await publint({
pkgDir: metadata.root,
/**
* Report warnings as errors.
*/
strict: true,
});

return {
success: await buildPackage({ cwd: metadata!.root, ...options }),
success: isBuildSuccessful && messages.length === 0,
terminalOutput: messages
.map((message) => {
const { args, code, path, type } = message;
return `${type}: ${code}
- ${path.join('\n - ')}
${JSON.stringify(args, null, 2)}`;
})
.join('\n'),
};
}
20 changes: 20 additions & 0 deletions packages/nx/src/executors/quality/executor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { execSync } from 'child_process';

import { ExecutorContext } from '@nx/devkit';
import lintRun from '@nx/linter/src/executors/eslint/lint.impl.js';

Expand Down Expand Up @@ -39,6 +41,24 @@ export default async function runExecutor(
},
context,
);

try {
execSync(
`npx prettier ${[
options.fix ? '-w' : '-c',
'--log-level warn',
'--no-error-on-unmatched-pattern',
'--ignore-unknown',
'--cache',
].join(' ')} --log-level warn .`,
{
cwd: root,
stdio: 'inherit',
},
);
} catch (e) {
return { success: false };
}
return { success: lintResult.success && packageCheckResult.success };
} catch (e) {
console.log(e as Error);
Expand Down
Loading

0 comments on commit 6a61092

Please sign in to comment.