Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import fs from 'fs';
import { Path } from '@beemo/core';
import { ESLintConfig } from '@beemo/driver-eslint';
import { EXTS, EXT_PATTERN, IGNORE_PATHS } from '../constants';
import { BeemoProcess } from '../types';
const { tool } = (process.beemo as unknown) as BeemoProcess;
const { node } = tool.config.settings;
// @ts-ignore
const workspacesEnabled = !!tool.package.workspaces;
let project: Path;
// Lint crashes with an OOM error when using project references,
// so just use a single file that globs everything.
if (workspacesEnabled) {
project = Path.resolve('tsconfig.eslint.json');
const include: Path[] = [];
tool.getWorkspacePaths({ relative: true }).forEach(wsPath => {
include.push(
new Path(wsPath, 'src/**/*'),
new Path(wsPath, 'tests/**/*'),
new Path(wsPath, 'types/**/*'),
);
});
fs.writeFileSync(
project.path(),
JSON.stringify({
extends: './tsconfig.options.json',
include: include.map(i => i.path()),
import { Path } from '@beemo/core';
import { JestConfig } from '@beemo/driver-jest';
import { IGNORE_PATHS } from '../constants';
import { BeemoProcess } from '../types';
// Package: Run in root
// Workspaces: Run in root
const { tool } = (process.beemo as unknown) as BeemoProcess;
const { react } = tool.config.settings;
// @ts-ignore
const workspacesEnabled = !!tool.package.workspaces;
const setupFilePath = Path.resolve('./tests/setup.ts');
const setupFilesAfterEnv: string[] = [];
const roots: string[] = [];
if (workspacesEnabled) {
tool.getWorkspacePaths({ relative: true }).forEach(wsPath => {
roots.push(`/${wsPath.replace('/*', '')}`);
});
} else {
roots.push('');
}
if (setupFilePath.exists()) {
setupFilesAfterEnv.push(setupFilePath.path());
}
const config: JestConfig = {
new Path(wsPath, 'src/**/*'),
new Path(wsPath, 'tests/**/*'),
new Path(wsPath, 'types/**/*'),
);
});
fs.writeFileSync(
project.path(),
JSON.stringify({
extends: './tsconfig.options.json',
include: include.map(i => i.path()),
}),
'utf8',
);
} else {
project = Path.resolve('tsconfig.json');
}
// Package: Run in root
// Workspaces: Run in root
const config: ESLintConfig = {
root: true,
parser: '@typescript-eslint/parser',
extends: ['airbnb', 'prettier', 'prettier/react', 'prettier/@typescript-eslint'],
plugins: ['react-hooks', 'promise', 'unicorn', 'compat', 'babel'],
ignore: [...IGNORE_PATHS, '*.min.js', '*.map'],
env: {
browser: true,
},
globals: {
__DEV__: 'readable',
},
private handleCleanTarget = ({ args }: DriverContext) => {
const outDir =
args.outDir || (this.config.compilerOptions && this.config.compilerOptions.outDir);
if (args.clean && outDir) {
rimraf.sync(Path.resolve(outDir).path());
}
return Promise.resolve();
};
tool.getPlugin('driver', 'typescript').onAfterExecute.listen(() => {
const corePackage = Path.resolve('packages/core', tool.options.root);
if (corePackage.exists()) {
fs.copySync(
Path.resolve('README.md', tool.options.root).path(),
corePackage.append('README.md').path(),
);
}
return Promise.resolve();
});
}
tool.getPlugin('driver', 'typescript').onAfterExecute.listen(() => {
const corePackage = Path.resolve('packages/core', tool.options.root);
if (corePackage.exists()) {
fs.copySync(
Path.resolve('README.md', tool.options.root).path(),
corePackage.append('README.md').path(),
);
}
return Promise.resolve();
});
}
private handleCleanTarget = ({ args }: DriverContext) => {
if (args.clean && args.outDir) {
rimraf.sync(Path.resolve(args.outDir).path());
}
return Promise.resolve();
};
}
env: {
browser: true,
node: false,
},
reportUnusedDisableDirectives: true,
settings: {
propWrapperFunctions: ['forbidExtraProps', 'exact', 'Object.freeze'],
'import/ignore': ['node_modules', '\\.json$', ASSET_EXT_PATTERN.source, GQL_EXT_PATTERN.source],
'import/extensions': EXTS,
'import/resolver': {
node: {
extensions: EXTS,
},
[Path.resolve('../resolvers/graphql.js', __dirname).path()]: {
extensions: ['.gql', '.graphql'],
},
},
},
rules: {
'react-hooks/exhaustive-deps': 'error',
'react-hooks/rules-of-hooks': 'error',
},
overrides: [
{
files: [`*.test.${EXTS_GROUP}`],
plugins: ['jest'],
globals: {
jsdom: 'readonly',