chore: standardize tsconfig (#9568)

This commit is contained in:
forehalo
2025-01-08 04:07:56 +00:00
parent 39f4b17315
commit c0ed74dfed
151 changed files with 1041 additions and 1566 deletions

View File

@@ -1,4 +1,3 @@
import type { BUILD_CONFIG_TYPE } from '@affine/env/global';
import type { Package } from '@affine-tools/utils/workspace';
import { PackageToDistribution } from './distribution';
@@ -37,7 +36,6 @@ export function getBuildConfig(
isAdmin: distribution === 'admin',
appBuildType: 'stable' as const,
serverUrlPrefix: 'https://app.affine.pro',
appVersion: pkg.version,
// editorVersion: pkg.dependencies['@blocksuite/affine'],
editorVersion: pkg.version,
@@ -52,7 +50,6 @@ export function getBuildConfig(
return {
...this.stable,
appBuildType: 'beta' as const,
serverUrlPrefix: 'https://insider.affine.pro',
changelogUrl: 'https://github.com/toeverything/AFFiNE/releases',
};
},
@@ -60,7 +57,6 @@ export function getBuildConfig(
return {
...this.stable,
appBuildType: 'internal' as const,
serverUrlPrefix: 'https://insider.affine.pro',
changelogUrl: 'https://github.com/toeverything/AFFiNE/releases',
};
},
@@ -69,7 +65,6 @@ export function getBuildConfig(
return {
...this.stable,
appBuildType: 'canary' as const,
serverUrlPrefix: 'https://affine.fail',
changelogUrl: 'https://github.com/toeverything/AFFiNE/releases',
};
},
@@ -87,10 +82,6 @@ export function getBuildConfig(
changelogUrl: process.env.CHANGELOG_URL ?? currentBuildPreset.changelogUrl,
};
if (buildFlags.mode === 'development') {
currentBuildPreset.serverUrlPrefix = 'http://localhost:8080';
}
return {
...currentBuildPreset,
// environment preset will overwrite current build preset

View File

@@ -1,5 +1,3 @@
import type { BUILD_CONFIG_TYPE } from '@affine/env/global';
import { PackageList, type PackageName } from './workspace.gen';
export const PackageToDistribution = new Map<

View File

@@ -1,5 +1,5 @@
import { existsSync, statSync } from 'node:fs';
import { join } from 'node:path';
import { join, relative } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
export class Path {
@@ -21,6 +21,10 @@ export class Path {
return new Path(join(this.path, ...paths));
}
parent() {
return this.join('..');
}
toString() {
return this.path;
}
@@ -44,6 +48,10 @@ export class Path {
toFileUrl() {
return pathToFileURL(this.path);
}
relative(to: string) {
return relative(this.value, to);
}
}
export const ProjectRoot = Path.dir(import.meta.url).join('../../../');

View File

@@ -429,6 +429,7 @@ export const PackageList = [
workspaceDependencies: [
'blocksuite/affine/components',
'blocksuite/affine/model',
'blocksuite/affine/shared',
'blocksuite/framework/block-std',
'blocksuite/framework/global',
'blocksuite/presets',
@@ -582,7 +583,7 @@ export const PackageList = [
{
location: 'packages/frontend/electron-api',
name: '@affine/electron-api',
workspaceDependencies: [],
workspaceDependencies: ['packages/frontend/apps/electron'],
},
{
location: 'packages/frontend/graphql',
@@ -642,6 +643,11 @@ export const PackageList = [
{
location: 'tests/kit',
name: '@affine-test/kit',
workspaceDependencies: ['tools/utils'],
},
{
location: 'tools/@types/build-config',
name: '@types/build-config',
workspaceDependencies: [],
},
{
@@ -750,6 +756,7 @@ export type PackageName =
| '@affine-test/affine-local'
| '@affine-test/affine-mobile'
| '@affine-test/kit'
| '@types/build-config'
| '@types/affine__env'
| '@affine/changelog'
| '@affine-tools/cli'

View File

@@ -49,11 +49,15 @@ export class Workspace {
return this.packageJson.dependencies ?? {};
}
constructor() {
get isTsProject() {
return this.join('tsconfig.json').exists();
}
constructor(list: typeof PackageList = PackageList) {
this.packageJson = readPackageJson(ProjectRoot);
const packages = new Map<string, Package>();
for (const meta of PackageList) {
for (const meta of list) {
try {
const pkg = new Package(meta.name as PackageName, meta);
// @ts-expect-error internal api
@@ -70,6 +74,7 @@ export class Workspace {
} catch (e) {
if (e instanceof CircularDependenciesError) {
const inProcessPackages = Array.from(building);
console.log(inProcessPackages, e.currentName);
const circle = inProcessPackages
.slice(inProcessPackages.indexOf(e.currentName))
.concat(e.currentName);
@@ -127,7 +132,7 @@ export class Workspace {
}
if (building.has(dep.name)) {
throw new CircularDependenciesError(pkg.name);
throw new CircularDependenciesError(dep.name);
}
if (!pkg.packageJson.private && dep.packageJson.private) {
@@ -158,44 +163,6 @@ export class Workspace {
return packageList.filter(p => p.location !== '.');
});
genWorkspaceInfo() {
const list = this.yarnList();
const names = list.map(p => p.name);
const content = [
'// Auto generated content',
'// DO NOT MODIFY THIS FILE MANUALLY',
`export const PackageList = ${JSON.stringify(list, null, 2)}`,
'',
`export type PackageName = ${names.map(n => `'${n}'`).join(' | ')}`,
];
return content.join('\n');
}
genProjectTsConfig() {
const content = [
'// Auto generated content',
'// DO NOT MODIFY THIS FILE MANUALLY',
'{',
' "compilerOptions": {',
' "noEmit": true',
' },',
' "include": [],',
' "references": [',
this.packages
.filter(p => p.isTsProject)
.map(p => ` { "path": "${p.path.relativePath}" }`)
.join(',\n'),
' ]',
'}',
'',
];
return content.join('\n');
}
forEach(callback: (pkg: Package) => void) {
this.packages.forEach(callback);
}