fix: lockdown (#3336)

This commit is contained in:
Alex Yang 2023-07-21 00:04:26 +08:00 committed by GitHub
parent 19055baa49
commit e3a6204f2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 13 deletions

View File

@ -106,8 +106,8 @@ export const createConfiguration: (
devtool:
buildFlags.mode === 'production'
? buildFlags.distribution === 'desktop'
? 'inline-source-map'
: 'hidden-nosources-source-map'
? 'inline-cheap-source-map'
: 'source-map'
: 'eval-cheap-module-source-map',
resolve: {
@ -199,7 +199,7 @@ export const createConfiguration: (
type: 'asset/resource',
},
{
test: /\.(ttf|eot|woff|woff2)$/i,
test: /\.(ttf|eot|woff|woff2)$/,
type: 'asset/resource',
},
{
@ -262,6 +262,7 @@ export const createConfiguration: (
new VanillaExtractPlugin(),
new webpack.DefinePlugin({
'process.env': JSON.stringify({}),
'process.env.COVERAGE': JSON.stringify(!!buildFlags.coverage),
'process.env.NODE_ENV': JSON.stringify(buildFlags.mode),
runtimeConfig: JSON.stringify(runtimeConfig),
}),

View File

@ -27,6 +27,17 @@ import * as ReactJSXRuntime from 'react/jsx-runtime';
import * as ReactDom from 'react-dom';
import * as ReactDomClient from 'react-dom/client';
if (!process.env.COVERAGE) {
lockdown({
evalTaming: 'unsafeEval',
overrideTaming: 'severe',
consoleTaming: 'unsafe',
errorTaming: 'unsafe',
errorTrapping: 'platform',
unhandledRejectionTrapping: 'report',
});
}
const PluginProvider = ({ children }: PropsWithChildren) =>
React.createElement(
Provider,
@ -36,11 +47,9 @@ const PluginProvider = ({ children }: PropsWithChildren) =>
children
);
console.log('JotaiUtils', JotaiUtils);
const customRequire = (id: string) => {
if (id === '@toeverything/plugin-infra/manager') {
return harden(Manager);
return Manager;
}
if (id === 'react') {
return React;
@ -55,22 +64,22 @@ const customRequire = (id: string) => {
return ReactDomClient;
}
if (id === '@blocksuite/icons') {
return harden(Icons);
return Icons;
}
if (id === '@affine/component') {
return harden(AFFiNEComponent);
return AFFiNEComponent;
}
if (id === '@blocksuite/blocks/std') {
return harden(BlockSuiteBlocksStd);
return BlockSuiteBlocksStd;
}
if (id === '@blocksuite/global/utils') {
return harden(BlockSuiteGlobalUtils);
return BlockSuiteGlobalUtils;
}
if (id === 'jotai') {
return harden(Jotai);
return Jotai;
}
if (id === 'jotai/utils') {
return harden(JotaiUtils);
return JotaiUtils;
}
if (id === '../plugin.js') {
return entryCompartment.evaluate('exports');
@ -80,7 +89,7 @@ const customRequire = (id: string) => {
const createGlobalThis = () => {
return {
process: harden({
process: Object.freeze({
env: {
NODE_ENV: process.env.NODE_ENV,
},