2023-03-02 05:13:45 +03:00
|
|
|
// @ts-check
|
2023-03-02 21:01:09 +03:00
|
|
|
import { createRequire } from 'node:module';
|
2023-02-19 11:40:39 +03:00
|
|
|
import path from 'node:path';
|
2023-03-02 21:01:09 +03:00
|
|
|
|
2023-05-04 08:35:09 +03:00
|
|
|
import { runCli } from '@magic-works/i18n-codegen';
|
2023-03-02 21:01:09 +03:00
|
|
|
import { PerfseePlugin } from '@perfsee/webpack';
|
2023-03-28 22:06:16 +03:00
|
|
|
import { withSentryConfig } from '@sentry/nextjs';
|
2023-04-13 05:26:06 +03:00
|
|
|
import SentryWebpackPlugin from '@sentry/webpack-plugin';
|
2023-02-19 11:40:39 +03:00
|
|
|
import debugLocal from 'next-debug-local';
|
2023-05-04 08:35:09 +03:00
|
|
|
import { fileURLToPath } from 'url';
|
2023-03-02 21:01:09 +03:00
|
|
|
|
2023-04-25 06:33:09 +03:00
|
|
|
import { blockSuiteFeatureFlags, buildFlags } from './preset.config.mjs';
|
2023-05-09 01:37:07 +03:00
|
|
|
import { getCommitHash, getGitVersion } from './scripts/git-info.mjs';
|
2023-02-19 11:40:39 +03:00
|
|
|
|
2023-03-01 10:40:01 +03:00
|
|
|
const require = createRequire(import.meta.url);
|
2023-04-04 20:46:33 +03:00
|
|
|
const { createVanillaExtractPlugin } = require('@vanilla-extract/next-plugin');
|
|
|
|
const withVanillaExtract = createVanillaExtractPlugin();
|
2023-03-01 10:40:01 +03:00
|
|
|
|
2023-04-25 06:33:09 +03:00
|
|
|
console.info('Build Flags', buildFlags);
|
|
|
|
console.info('Editor Flags', blockSuiteFeatureFlags);
|
2022-10-17 20:31:40 +03:00
|
|
|
|
2023-05-04 08:35:09 +03:00
|
|
|
if (process.env.NODE_ENV !== 'development') {
|
|
|
|
await runCli(
|
|
|
|
{
|
|
|
|
config: fileURLToPath(
|
|
|
|
new URL('../../.i18n-codegen.json', import.meta.url)
|
|
|
|
),
|
|
|
|
watch: false,
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
console.error(error);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-01 19:57:08 +03:00
|
|
|
const enableDebugLocal = path.isAbsolute(process.env.LOCAL_BLOCK_SUITE ?? '');
|
|
|
|
|
2023-03-22 09:09:30 +03:00
|
|
|
if (enableDebugLocal) {
|
|
|
|
console.info('Debugging local blocksuite');
|
|
|
|
}
|
|
|
|
|
2023-04-14 02:20:41 +03:00
|
|
|
if (process.env.COVERAGE === 'true') {
|
|
|
|
console.info('Enable coverage report');
|
|
|
|
}
|
|
|
|
|
2023-01-07 12:01:10 +03:00
|
|
|
const profileTarget = {
|
|
|
|
ac: '100.85.73.88:12001',
|
2023-02-09 10:24:25 +03:00
|
|
|
dev: '100.84.105.99:11001',
|
|
|
|
test: '100.84.105.99:11001',
|
2023-01-14 05:07:59 +03:00
|
|
|
stage: '',
|
2023-04-12 17:11:47 +03:00
|
|
|
prod: 'https://app.affine.pro',
|
2023-01-07 12:01:10 +03:00
|
|
|
local: '127.0.0.1:3000',
|
|
|
|
};
|
|
|
|
|
|
|
|
const getRedirectConfig = profile => {
|
|
|
|
const target = profileTarget[profile || 'dev'] || profileTarget['dev'];
|
|
|
|
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
{ source: '/api/:path*', destination: `http://${target}/api/:path*` },
|
|
|
|
{
|
|
|
|
source: '/collaboration/:path*',
|
|
|
|
destination: `http://${target}/collaboration/:path*`,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
target,
|
2023-02-10 15:41:01 +03:00
|
|
|
profile || 'dev',
|
2023-01-07 12:01:10 +03:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2022-09-22 10:39:53 +03:00
|
|
|
/** @type {import('next').NextConfig} */
|
2022-11-03 09:53:44 +03:00
|
|
|
const nextConfig = {
|
2023-03-28 22:06:16 +03:00
|
|
|
sentry: {
|
|
|
|
hideSourceMaps: true,
|
|
|
|
},
|
2022-10-14 14:29:36 +03:00
|
|
|
productionBrowserSourceMaps: true,
|
2023-03-01 10:40:01 +03:00
|
|
|
compiler: {
|
2023-03-04 10:36:20 +03:00
|
|
|
styledComponents: true,
|
2023-03-01 10:40:01 +03:00
|
|
|
removeConsole: {
|
|
|
|
exclude: ['error', 'log', 'warn', 'info'],
|
|
|
|
},
|
2023-05-05 07:18:54 +03:00
|
|
|
reactRemoveProperties: !buildFlags.enableTestProperties
|
|
|
|
? {
|
|
|
|
properties: ['^data-testid$'],
|
|
|
|
}
|
|
|
|
: false,
|
2023-03-01 10:40:01 +03:00
|
|
|
emotion: {
|
|
|
|
sourceMap: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
images: {
|
|
|
|
unoptimized: true,
|
|
|
|
},
|
|
|
|
experimental: {
|
|
|
|
swcPlugins: [
|
2023-05-03 06:40:53 +03:00
|
|
|
process.env.COVERAGE === 'true' && ['swc-plugin-coverage-instrument', {}],
|
2023-03-20 10:05:02 +03:00
|
|
|
// ['@swc-jotai/debug-label', {}],
|
2023-03-01 10:40:01 +03:00
|
|
|
// ['@swc-jotai/react-refresh', {}],
|
2023-03-08 11:29:50 +03:00
|
|
|
].filter(Boolean),
|
2022-12-30 16:40:15 +03:00
|
|
|
},
|
2023-03-01 10:40:01 +03:00
|
|
|
reactStrictMode: true,
|
2023-02-17 05:43:52 +03:00
|
|
|
transpilePackages: [
|
2023-04-17 00:02:41 +03:00
|
|
|
'jotai-devtools',
|
2023-02-17 05:43:52 +03:00
|
|
|
'@affine/component',
|
2023-03-01 10:40:01 +03:00
|
|
|
'@affine/i18n',
|
2023-03-02 05:13:45 +03:00
|
|
|
'@affine/debug',
|
2023-03-02 04:26:55 +03:00
|
|
|
'@affine/env',
|
2023-03-11 08:15:19 +03:00
|
|
|
'@affine/templates',
|
2023-04-04 02:40:07 +03:00
|
|
|
'@affine/workspace',
|
|
|
|
'@affine/jotai',
|
2023-05-30 13:02:49 +03:00
|
|
|
'@affine/copilot',
|
2023-04-26 02:44:17 +03:00
|
|
|
'@toeverything/hooks',
|
2023-04-04 02:40:07 +03:00
|
|
|
'@toeverything/y-indexeddb',
|
2023-06-08 04:41:20 +03:00
|
|
|
'@toeverything/infra',
|
2023-05-30 13:02:49 +03:00
|
|
|
'@toeverything/plugin-infra',
|
2023-02-17 05:43:52 +03:00
|
|
|
],
|
2023-03-01 10:40:01 +03:00
|
|
|
publicRuntimeConfig: {
|
2023-03-24 01:15:40 +03:00
|
|
|
PROJECT_NAME: process.env.npm_package_name ?? 'AFFiNE',
|
2023-03-01 10:40:01 +03:00
|
|
|
BUILD_DATE: new Date().toISOString(),
|
|
|
|
gitVersion: getGitVersion(),
|
|
|
|
hash: getCommitHash(),
|
|
|
|
serverAPI:
|
2023-04-12 08:26:42 +03:00
|
|
|
profileTarget[process.env.API_SERVER_PROFILE || 'dev'] ??
|
|
|
|
profileTarget.dev,
|
2023-03-01 10:40:01 +03:00
|
|
|
editorVersion: require('./package.json').dependencies['@blocksuite/editor'],
|
2023-04-25 06:33:09 +03:00
|
|
|
editorFlags: blockSuiteFeatureFlags,
|
|
|
|
...buildFlags,
|
2023-03-01 10:40:01 +03:00
|
|
|
},
|
2023-03-02 11:49:33 +03:00
|
|
|
webpack: (config, { dev, isServer }) => {
|
2022-12-30 14:42:01 +03:00
|
|
|
config.experiments = { ...config.experiments, topLevelAwait: true };
|
2022-12-30 16:40:15 +03:00
|
|
|
config.module.rules.push({
|
|
|
|
test: /\.md$/i,
|
|
|
|
loader: 'raw-loader',
|
|
|
|
});
|
2023-03-02 22:50:23 +03:00
|
|
|
config.resolve.alias['yjs'] = require.resolve('yjs');
|
2022-12-30 16:40:15 +03:00
|
|
|
|
2023-03-28 07:05:49 +03:00
|
|
|
if (!isServer && !dev && process.env.PERFSEE_TOKEN) {
|
2023-03-02 11:49:33 +03:00
|
|
|
config.devtool = 'hidden-nosources-source-map';
|
|
|
|
const perfsee = new PerfseePlugin({
|
|
|
|
project: 'affine-toeverything',
|
|
|
|
});
|
|
|
|
if (Array.isArray(config.plugins)) {
|
|
|
|
config.plugins.push(perfsee);
|
|
|
|
} else {
|
|
|
|
config.plugins = [perfsee];
|
|
|
|
}
|
|
|
|
}
|
2023-04-13 05:26:06 +03:00
|
|
|
if (
|
|
|
|
process.env.SENTRY_AUTH_TOKEN &&
|
|
|
|
process.env.SENTRY_ORG &&
|
|
|
|
process.env.SENTRY_PROJECT
|
|
|
|
) {
|
|
|
|
config.plugins.push(
|
|
|
|
new SentryWebpackPlugin({
|
|
|
|
include: '.next',
|
|
|
|
ignore: ['node_modules', 'cypress', 'test'],
|
|
|
|
urlPrefix: '~/_next',
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2023-03-02 11:49:33 +03:00
|
|
|
|
2022-12-30 16:40:15 +03:00
|
|
|
return config;
|
|
|
|
},
|
|
|
|
rewrites: async () => {
|
2023-02-10 15:41:01 +03:00
|
|
|
const [profile, target, desc] = getRedirectConfig(
|
2023-04-12 08:26:42 +03:00
|
|
|
process.env.API_SERVER_PROFILE
|
2023-01-07 12:01:10 +03:00
|
|
|
);
|
2023-03-01 10:40:01 +03:00
|
|
|
console.info(`API request proxy to [${desc} Server]: ` + target);
|
2023-01-07 12:01:10 +03:00
|
|
|
return profile;
|
2022-11-03 13:50:27 +03:00
|
|
|
},
|
2023-02-14 09:51:05 +03:00
|
|
|
basePath: process.env.NEXT_BASE_PATH,
|
2023-04-13 16:37:50 +03:00
|
|
|
assetPrefix: process.env.NEXT_ASSET_PREFIX,
|
2023-04-25 06:33:09 +03:00
|
|
|
pageExtensions: [
|
|
|
|
...(buildFlags.enableDebugPage ? ['tsx', 'dev.tsx'] : ['tsx']),
|
|
|
|
],
|
2022-11-03 09:53:44 +03:00
|
|
|
};
|
2022-09-22 10:39:53 +03:00
|
|
|
|
2022-12-30 16:40:15 +03:00
|
|
|
const baseDir = process.env.LOCAL_BLOCK_SUITE ?? '/';
|
2023-02-19 11:40:39 +03:00
|
|
|
const withDebugLocal = debugLocal(
|
2022-12-30 16:40:15 +03:00
|
|
|
{
|
|
|
|
'@blocksuite/editor': path.resolve(baseDir, 'packages', 'editor'),
|
2023-01-01 19:57:08 +03:00
|
|
|
'@blocksuite/blocks/models': path.resolve(
|
|
|
|
baseDir,
|
|
|
|
'packages',
|
|
|
|
'blocks',
|
|
|
|
'src',
|
|
|
|
'models'
|
|
|
|
),
|
|
|
|
'@blocksuite/blocks/std': path.resolve(
|
|
|
|
baseDir,
|
|
|
|
'packages',
|
|
|
|
'blocks',
|
|
|
|
'src',
|
|
|
|
'std'
|
|
|
|
),
|
2023-03-22 08:17:57 +03:00
|
|
|
'@blocksuite/blocks/content-parser': path.resolve(
|
|
|
|
baseDir,
|
|
|
|
'packages',
|
|
|
|
'blocks',
|
|
|
|
'src',
|
|
|
|
'content-parser'
|
|
|
|
),
|
2022-12-30 16:40:15 +03:00
|
|
|
'@blocksuite/blocks': path.resolve(baseDir, 'packages', 'blocks'),
|
|
|
|
'@blocksuite/store': path.resolve(baseDir, 'packages', 'store'),
|
|
|
|
},
|
|
|
|
{
|
2023-01-01 19:57:08 +03:00
|
|
|
enable: enableDebugLocal,
|
2022-12-30 16:40:15 +03:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-02-16 19:51:32 +03:00
|
|
|
const detectFirebaseConfig = () => {
|
|
|
|
if (!process.env.NEXT_PUBLIC_FIREBASE_API_KEY) {
|
2023-04-01 00:43:52 +03:00
|
|
|
console.warn(
|
|
|
|
'NEXT_PUBLIC_FIREBASE_API_KEY not found, affine cloud feature will be disabled.'
|
|
|
|
);
|
2023-02-16 19:51:32 +03:00
|
|
|
} else {
|
2023-04-01 00:43:52 +03:00
|
|
|
console.info('NEXT_PUBLIC_FIREBASE_API_KEY found.');
|
2023-02-16 19:51:32 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
detectFirebaseConfig();
|
2023-01-03 06:43:59 +03:00
|
|
|
|
2023-03-28 22:06:16 +03:00
|
|
|
let config = withDebugLocal(nextConfig);
|
|
|
|
|
|
|
|
if (process.env.SENTRY_AUTH_TOKEN) {
|
|
|
|
config = withSentryConfig(config, {
|
|
|
|
silent: true,
|
|
|
|
});
|
|
|
|
} else {
|
2023-04-01 00:43:52 +03:00
|
|
|
console.log(
|
|
|
|
'SENTRY_AUTH_TOKEN not found, Sentry monitoring feature will be disabled.'
|
|
|
|
);
|
|
|
|
delete config.sentry;
|
2023-03-28 22:06:16 +03:00
|
|
|
}
|
|
|
|
|
2023-04-04 02:40:07 +03:00
|
|
|
if (process.env.PERFSEE_TOKEN) {
|
|
|
|
console.info('perfsee token found.');
|
|
|
|
} else {
|
|
|
|
console.warn(
|
|
|
|
'perfsee token not found. performance monitoring will be disabled.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-04-04 20:46:33 +03:00
|
|
|
export default withVanillaExtract(config);
|