chore(root): migrate to biome

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-09-16 12:20:40 +02:00
parent 1f6e198336
commit 32e91959f6
383 changed files with 1943 additions and 3085 deletions

View File

@@ -1,58 +0,0 @@
/** @type {import("eslint").Linter.Config} */
const config = {
extends: [
'turbo',
'eslint:recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'prettier',
],
env: {
es2022: true,
node: true,
},
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
},
plugins: ['@typescript-eslint', 'import'],
rules: {
'turbo/no-undeclared-env-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
],
'@typescript-eslint/consistent-type-imports': [
'warn',
{ prefer: 'type-imports', fixStyle: 'separate-type-imports' },
],
'@typescript-eslint/no-misused-promises': [
2,
{ checksVoidReturn: { attributes: false } },
],
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/prefer-interface': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',
},
ignorePatterns: [
'**/.eslintrc.cjs',
'**/*.config.js',
'**/*.config.cjs',
'.next',
'dist',
'public',
'pnpm-lock.yaml',
],
reportUnusedDisableDirectives: true,
};
module.exports = config;

View File

@@ -1,10 +0,0 @@
/** @type {import('eslint').Linter.Config} */
const config = {
extends: ['next'],
rules: {
'@next/next/no-html-link-for-pages': 'off',
'@next/next/no-img-element': 'off',
},
};
module.exports = config;

View File

@@ -1,45 +0,0 @@
{
"name": "@openpanel/eslint-config",
"version": "0.1.0",
"private": true,
"license": "MIT",
"files": [
"./base.js",
"./nextjs.js",
"./react.js"
],
"scripts": {
"clean": "rm -rf .turbo node_modules",
"lint": "eslint .",
"format": "prettier --check \"**/*.{mjs,ts,md,json}\"",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@next/eslint-plugin-next": "^14.0.4",
"@types/eslint": "^8.44.2",
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@typescript-eslint/parser": "^6.6.0",
"eslint-config-next": "^14.0.4",
"eslint-config-prettier": "^9.0.0",
"eslint-config-turbo": "^1.10.13",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0"
},
"devDependencies": {
"@openpanel/prettier-config": "workspace:*",
"@openpanel/tsconfig": "workspace:*",
"@types/eslint": "^8.44.2",
"eslint": "^8.48.0",
"prettier": "^3.0.3",
"typescript": "^5.2.2"
},
"eslintConfig": {
"root": true,
"extends": [
"./base.js"
]
},
"prettier": "@openpanel/prettier-config"
}

View File

@@ -1,27 +0,0 @@
/** @type {import('eslint').Linter.Config} */
const config = {
extends: [
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:jsx-a11y/recommended',
],
rules: {
'react/prop-types': 'off',
'react/no-unknown-property': 'off',
'jsx-a11y/click-events-have-key-events': 'off',
'jsx-a11y/label-has-associated-control': 'off',
},
globals: {
React: 'writable',
},
settings: {
react: {
version: 'detect',
},
},
env: {
browser: true,
},
};
module.exports = config;

View File

@@ -1,8 +0,0 @@
{
"extends": "@openpanel/tsconfig/base.json",
"compilerOptions": {
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
},
"include": ["."],
"exclude": ["node_modules"]
}

View File

@@ -1,41 +0,0 @@
import { fileURLToPath } from 'url';
/** @typedef {import("prettier").Config} PrettierConfig */
/** @typedef {import("prettier-plugin-tailwindcss").PluginOptions} TailwindConfig */
/** @typedef {import("@ianvs/prettier-plugin-sort-imports").PluginConfig} SortImportsConfig */
/** @type { PrettierConfig | SortImportsConfig | TailwindConfig } */
const config = {
plugins: [
'@ianvs/prettier-plugin-sort-imports',
'prettier-plugin-tailwindcss',
],
tailwindConfig: fileURLToPath(
new URL('../../apps/dashboard/tailwind.config.js', import.meta.url)
),
tailwindFunctions: ['cn', 'cva'],
importOrder: [
'^(react/(.*)$)|^(react$)|^(react-native(.*)$)',
'<THIRD_PARTY_MODULES>',
'',
'^@openpanel/(.*)$',
'',
'^~/',
'^[../]',
'^[./]',
],
importOrderParserPlugins: [
'typescript',
'jsx',
'decorators-legacy',
'importAssertions',
],
importOrderTypeScriptVersion: '4.4.0',
singleQuote: true,
semi: true,
trailingComma: 'es5',
printWidth: 80,
tabWidth: 2,
};
export default config;

View File

@@ -1,20 +0,0 @@
{
"name": "@openpanel/prettier-config",
"version": "0.1.0",
"private": true,
"main": "index.mjs",
"type": "module",
"scripts": {
"clean": "rm -rf .turbo node_modules"
},
"dependencies": {
"@ianvs/prettier-plugin-sort-imports": "^4.1.0",
"prettier-plugin-tailwindcss": "^0.5.11"
},
"devDependencies": {
"@openpanel/tsconfig": "workspace:*",
"eslint": "^8.48.0",
"prettier": "^3.0.3",
"typescript": "^5.2.2"
}
}

View File

@@ -1,9 +0,0 @@
{
"extends": "@openpanel/tsconfig/base.json",
"compilerOptions": {
"checkJs": false,
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
},
"include": ["."],
"exclude": ["node_modules"]
}

View File

@@ -4,9 +4,7 @@
"private": true,
"license": "MIT",
"scripts": {
"publish": "pnpm dlx ts-node publish.ts",
"lint": "eslint .",
"format": "prettier --check \"**/*.{mjs,ts,md,json}\"",
"publish": "pnpm run publish.ts",
"typecheck": "tsc --noEmit"
},
"dependencies": {
@@ -14,21 +12,9 @@
"semver": "^7.5.4"
},
"devDependencies": {
"@openpanel/eslint-config": "workspace:*",
"@openpanel/prettier-config": "workspace:*",
"@openpanel/tsconfig": "workspace:*",
"@types/eslint": "^8.44.2",
"@types/node": "^18.16.0",
"@types/semver": "^7.5.4",
"eslint": "^8.48.0",
"prettier": "^3.0.3",
"typescript": "^5.2.2"
},
"eslintConfig": {
"root": true,
"extends": [
"@openpanel/eslint-config/base"
]
},
"prettier": "@openpanel/prettier-config"
}
}

View File

@@ -11,7 +11,7 @@ interface PackageJson {
version: string;
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
[key: string]: any;
[key: string]: unknown;
}
interface PackageInfo extends PackageJson {
@@ -60,7 +60,7 @@ const getNextVersion = (version: string, type: ReleaseType): string => {
// Core functions
const loadPackages = (
releaseType: ReleaseType
releaseType: ReleaseType,
): Record<string, PackageInfo> => {
const sdksPath = workspacePath('./packages/sdks');
const sdks = fs
@@ -72,7 +72,7 @@ const loadPackages = (
sdks.map((sdk) => {
const pkgPath = path.join(sdksPath, sdk, 'package.json');
const pkgJson = JSON.parse(
fs.readFileSync(pkgPath, 'utf-8')
fs.readFileSync(pkgPath, 'utf-8'),
) as PackageJson;
const version = pkgJson.version.replace(/-local$/, '');
return [
@@ -84,22 +84,22 @@ const loadPackages = (
localPath: `./packages/sdks/${sdk}`,
},
];
})
}),
);
};
const findDependents = (
packages: Record<string, PackageInfo>,
targetName: string
targetName: string,
): string[] => {
const dependents = new Set([targetName]);
const findDeps = (name: string) => {
Object.entries(packages).forEach(([pkgName, pkg]) => {
for (const [pkgName, pkg] of Object.entries(packages)) {
if (pkg.dependencies?.[name] && !dependents.has(pkgName)) {
dependents.add(pkgName);
findDeps(pkgName);
}
});
}
};
findDeps(targetName);
return Array.from(dependents);
@@ -108,7 +108,7 @@ const findDependents = (
const updatePackageJsonForRelease = (
packages: Record<string, PackageInfo>,
name: string,
dependents: string[]
dependents: string[],
): void => {
const { nextVersion, localPath, ...restPkgJson } = packages[name]!;
const newPkgJson: PackageJson = {
@@ -144,8 +144,8 @@ const updatePackageJsonForRelease = (
? packages[depName]?.nextVersion ||
depVersion.replace(/-local$/, '')
: depVersion.replace(/-local$/, ''),
]
)
],
),
),
};
@@ -157,7 +157,7 @@ const updatePackageJsonForRelease = (
const buildPackages = (
packages: Record<string, PackageInfo>,
dependents: string[]
dependents: string[],
): void => {
const versionEnvs = dependents.map((dep) => {
const envName = dep
@@ -167,26 +167,26 @@ const buildPackages = (
return `--env.${envName}_VERSION=${packages[dep]!.nextVersion}`;
});
dependents.forEach((dep) => {
for (const dep of dependents) {
console.log(`🔨 Building ${dep}`);
const cmd = `pnpm build ${versionEnvs.join(' ')}`;
console.log(` Running: ${cmd}`);
execSync(cmd, {
cwd: workspacePath(packages[dep]!.localPath),
});
});
}
};
const publishPackages = (
packages: Record<string, PackageInfo>,
dependents: string[],
config: PublishConfig
config: PublishConfig,
): void => {
if (config.test) {
execSync('rm -rf ~/.local/share/verdaccio/storage/@openpanel');
}
dependents.forEach((dep) => {
for (const dep of dependents) {
console.log(`🚀 Publishing ${dep} to ${config.registry}`);
execSync(`npm publish --access=public --registry ${config.registry}`, {
cwd: workspacePath(packages[dep]!.localPath),
@@ -194,15 +194,15 @@ const publishPackages = (
if (dep === '@openpanel/web') {
execSync(
`cp ${workspacePath('packages/sdks/web/dist/src/tracker.global.js')} ${workspacePath('./apps/public/public/op1.js')}`
`cp ${workspacePath('packages/sdks/web/dist/src/tracker.global.js')} ${workspacePath('./apps/public/public/op1.js')}`,
);
}
});
}
};
const restoreAndUpdateLocal = (
packages: Record<string, PackageInfo>,
dependents: string[]
dependents: string[],
): void => {
const filesToRestore = dependents
.map((dep) => workspacePath(packages[dep]!.localPath))
@@ -211,7 +211,7 @@ const restoreAndUpdateLocal = (
execSync(`git checkout ${filesToRestore}`);
dependents.forEach((dep) => {
for (const dep of dependents) {
const { nextVersion, localPath, ...restPkgJson } = packages[dep]!;
console.log(`🚀 Updating ${dep} (${nextVersion}-local)`);
@@ -227,8 +227,8 @@ const restoreAndUpdateLocal = (
: packages[depName]
? `${packages[depName]!.version}-local`
: depVersion,
]
)
],
),
),
devDependencies: Object.fromEntries(
Object.entries(restPkgJson.devDependencies || {}).map(
@@ -239,13 +239,13 @@ const restoreAndUpdateLocal = (
: packages[depName]
? `${packages[depName]!.version}-local`
: depVersion,
]
)
],
),
),
};
savePackageJson(workspacePath(`${localPath}/package.json`), updatedPkgJson);
});
}
};
function main() {
@@ -268,7 +268,7 @@ function main() {
if (!RELEASE_TYPES.includes(args['--type'] as ReleaseType)) {
return exit(
`Invalid release type. Valid types are: ${RELEASE_TYPES.join(', ')}`
`Invalid release type. Valid types are: ${RELEASE_TYPES.join(', ')}`,
);
}
@@ -282,12 +282,12 @@ function main() {
const dependents = findDependents(packages, target.name);
dependents.forEach((dep) => {
for (const dep of dependents) {
console.log(
`📦 ${dep} · Old Version: ${packages[dep]!.version} · Next Version: ${packages[dep]!.nextVersion}`
`📦 ${dep} · Old Version: ${packages[dep]!.version} · Next Version: ${packages[dep]!.nextVersion}`,
);
updatePackageJsonForRelease(packages, dep, dependents);
});
}
buildPackages(packages, dependents);

View File

@@ -2,11 +2,7 @@
"name": "@openpanel/tsconfig",
"version": "0.1.0",
"private": true,
"files": [
"base.json",
"sdk.json",
"tsup.config.json"
],
"files": ["base.json", "sdk.json", "tsup.config.json"],
"devDependencies": {
"tsup": "^7.2.0"
}

View File

@@ -1,14 +1,9 @@
{
"entry": [
"index.ts"
],
"format": [
"cjs",
"esm"
],
"entry": ["index.ts"],
"format": ["cjs", "esm"],
"dts": true,
"splitting": false,
"sourcemap": false,
"clean": true,
"minify": true
}
}