diff --git a/biome.json b/biome.json index af16f524..ce71e9e0 100644 --- a/biome.json +++ b/biome.json @@ -54,8 +54,9 @@ "useNumberNamespace": "error", "noInferrableTypes": "error", "noUselessElse": "error", - "noNestedTernary": "off", - "useDefaultSwitchClause": "off" + "useDefaultSwitchClause": "off", + "noParameterProperties": "off", + "useConsistentMemberAccessibility": "off" }, "correctness": { "useExhaustiveDependencies": "off", @@ -64,7 +65,8 @@ "performance": { "noDelete": "off", "noAccumulatingSpread": "off", - "noBarrelFile": "off" + "noBarrelFile": "off", + "noNamespaceImport": "off" }, "suspicious": { "noExplicitAny": "off", diff --git a/tooling/publish/publish.ts b/tooling/publish/publish.ts index a1386c8e..a1b211ce 100644 --- a/tooling/publish/publish.ts +++ b/tooling/publish/publish.ts @@ -1,7 +1,6 @@ import { execSync } from 'node:child_process'; import fs from 'node:fs'; -import { join, resolve } from 'node:path'; -import { dirname } from 'node:path'; +import { dirname, join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import arg from 'arg'; import type { ReleaseType } from 'semver'; @@ -47,7 +46,9 @@ const savePackageJson = (absPath: string, data: PackageJson) => { const exit = (message: string, error?: unknown) => { console.error(`\n\nāŒ ${message}`); - if (error) console.error('Error:', error); + if (error) { + console.error('Error:', error); + } process.exit(1); }; @@ -56,7 +57,9 @@ const checkUncommittedChanges = () => { const uncommittedFiles = execSync('git status --porcelain') .toString() .trim(); - if (uncommittedFiles) throw new Error('Uncommitted changes detected'); + if (uncommittedFiles) { + throw new Error('Uncommitted changes detected'); + } console.log('āœ… No uncommitted changes'); } catch (error) { exit('Uncommitted changes', error); @@ -65,7 +68,9 @@ const checkUncommittedChanges = () => { const getNextVersion = (version: string, type: ReleaseType): string => { const nextVersion = semver.inc(version, type); - if (!nextVersion) throw new Error('Invalid version'); + if (!nextVersion) { + throw new Error('Invalid version'); + } return type.startsWith('pre') ? nextVersion.replace(/-.*$/, '-rc') : nextVersion; @@ -73,7 +78,7 @@ const getNextVersion = (version: string, type: ReleaseType): string => { // Core functions const loadPackages = ( - releaseType: ReleaseType, + releaseType: ReleaseType ): Record => { const sdksPath = workspacePath('./packages/sdks'); const sdks = fs @@ -85,25 +90,25 @@ const loadPackages = ( sdks.map((sdk) => { const pkgPath = 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 [ pkgJson.name, { ...pkgJson, - version: version, + version, nextVersion: getNextVersion(version, releaseType), localPath: `./packages/sdks/${sdk}`, }, ]; - }), + }) ); }; const findDependents = ( packages: Record, - targetName: string, + targetName: string ): string[] => { const dependents = new Set([targetName]); const findDeps = (name: string) => { @@ -121,7 +126,7 @@ const findDependents = ( const updatePackageJsonForRelease = ( packages: Record, name: string, - dependents: string[], + dependents: string[] ): void => { const { nextVersion, localPath, ...restPkgJson } = packages[name]!; let newPkgJson: PackageJson = { @@ -137,8 +142,8 @@ const updatePackageJsonForRelease = ( ? packages[depName]?.nextVersion || depVersion.replace(/-local$/, '').replace(/^workspace:/, '') : depVersion.replace(/-local$/, '').replace(/^workspace:/, ''), - ], - ), + ] + ) ), }; @@ -200,7 +205,7 @@ const searchAndReplace = (path: string, search: RegExp, replace: string) => { const transformPackages = ( packages: Record, - dependents: string[], + dependents: string[] ): void => { for (const dep of dependents) { const pkg = packages[dep]; @@ -210,7 +215,7 @@ const transformPackages = ( searchAndReplace( workspacePath(pkg.localPath), new RegExp(`${currentVersion}`, 'g'), - nextVersion, + nextVersion ); } } @@ -218,7 +223,7 @@ const transformPackages = ( const buildPackages = ( packages: Record, - dependents: string[], + dependents: string[] ): void => { const versionEnvs = dependents.map((dep) => { const envName = dep @@ -245,7 +250,7 @@ const buildPackages = ( const publishPackages = ( packages: Record, dependents: string[], - config: PublishConfig, + config: PublishConfig ): void => { if (config.clear) { execSync('rm -rf ~/.local/share/verdaccio/storage/@openpanel'); @@ -253,16 +258,19 @@ const publishPackages = ( for (const dep of dependents) { console.log(`šŸš€ Publishing ${dep} to ${config.registry}`); + console.log( + `šŸ“¦ Install: pnpm install ${dep} --registry ${config.registry}` + ); execSync(`npm publish --access=public --registry ${config.registry}`, { cwd: workspacePath(packages[dep]!.localPath), }); 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')}` ); execSync( - `cp ${workspacePath('packages/sdks/web/dist/src/replay.global.js')} ${workspacePath('./apps/public/public/op1-replay.js')}`, + `cp ${workspacePath('packages/sdks/web/dist/src/replay.global.js')} ${workspacePath('./apps/public/public/op1-replay.js')}` ); } } @@ -271,7 +279,7 @@ const publishPackages = ( const restoreAndUpdateLocal = ( packages: Record, dependents: string[], - generatedReadmes: string[], + generatedReadmes: string[] ): void => { const filesToRestore = dependents .map((dep) => join(workspacePath(packages[dep]!.localPath), 'package.json')) @@ -303,8 +311,8 @@ const restoreAndUpdateLocal = ( : packages[depName] ? `workspace:${packages[depName]!.version}-local` : depVersion, - ], - ), + ] + ) ), devDependencies: Object.fromEntries( Object.entries(restPkgJson.devDependencies || {}).map( @@ -315,8 +323,8 @@ const restoreAndUpdateLocal = ( : packages[depName] ? `${packages[depName]!.version}-local` : depVersion, - ], - ), + ] + ) ), }; @@ -345,7 +353,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(', ')}` ); } @@ -361,7 +369,7 @@ function main() { 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); } @@ -377,7 +385,7 @@ function main() { registry: args['--npm'] ? 'https://registry.npmjs.org' : 'http://localhost:4873', - clear: args['--clear'] || false, + clear: args['--clear'] ?? false, }; publishPackages(packages, dependents, config);