Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix react runtime for addons in manager #19226

Merged
merged 8 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions code/lib/builder-manager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { globalExternals } from '@fal-works/esbuild-plugin-global-externals';
import { pnpPlugin } from '@yarnpkg/esbuild-plugin-pnp';
import aliasPlugin from 'esbuild-plugin-alias';

import { renderHTML } from './utils/template';
import { getTemplatePath, renderHTML } from './utils/template';
import { definitions } from './utils/globals';
import {
BuilderBuildResult,
Expand All @@ -28,9 +28,10 @@ export let compilation: Compilation;
let asyncIterator: ReturnType<StarterFunction> | ReturnType<BuilderFunction>;

export const getConfig: ManagerBuilder['getConfig'] = async (options) => {
const [addonsEntryPoints, customManagerEntryPoint] = await Promise.all([
const [addonsEntryPoints, customManagerEntryPoint, tsconfigPath] = await Promise.all([
options.presets.apply('managerEntries', []),
safeResolve(join(options.configDir, 'manager')),
getTemplatePath('addon.tsconfig.json'),
]);

return {
Expand All @@ -57,6 +58,13 @@ export const getConfig: ManagerBuilder['getConfig'] = async (options) => {
minify: false,
sourcemap: true,

jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
jsx: 'transform',
jsxImportSource: 'react',

tsconfig: tsconfigPath,

legalComments: 'external',
plugins: [
aliasPlugin({
Expand Down
6 changes: 6 additions & 0 deletions code/lib/builder-manager/templates/addon.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"jsx": "react",
"jsxImportSource": "react"
}
}
5 changes: 2 additions & 3 deletions code/lib/ui/scripts/generate-exports-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import path from 'path';
import shelljs from 'shelljs';
import { dedent } from 'ts-dedent';

const remove = (regex?: RegExp) => (input: string) =>
!(input === 'default' || (regex && regex.test(input)));
const remove = () => (input: string) => input !== 'default';

const location = path.join(__dirname, '..', 'src', 'globals', 'exports.ts');

const run = async () => {
const { values } = await import('../src/globals/runtime');
const data = Object.entries(values).reduce<Record<string, string[]>>((acc, [key, value]) => {
acc[key] = Object.keys(value).filter(remove(/^__/));
acc[key] = Object.keys(value).filter(remove());
return acc;
}, {});

Expand Down
2 changes: 2 additions & 0 deletions code/lib/ui/src/globals/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default {
'PureComponent',
'StrictMode',
'Suspense',
'__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED',
'cloneElement',
'createContext',
'createElement',
Expand All @@ -33,6 +34,7 @@ export default {
'version',
],
'react-dom': [
'__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED',
'createPortal',
'findDOMNode',
'flushSync',
Expand Down
Loading