Skip to content

Commit

Permalink
feature: add preliminary support for dom components (#75)
Browse files Browse the repository at this point in the history
* feature: add `dom` environment based on `web` + `customTransformOptions.dom` existence

* feature: add basic `dom` environment ui

* refactor(ui): replace globe with panel-top to emphasize "embedded webview"
  • Loading branch information
byCedric authored Sep 4, 2024
1 parent 1853973 commit 5a87db5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/expo-atlas-ui/components/BundleTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const bundleTagVariants = cva('', {
} satisfies Record<AtlasBundle['platform'], string>,
environment: {
client: '',
dom: 'bg-palette-blue3',
node: 'bg-palette-orange3',
'react-server': 'bg-palette-orange3',
} satisfies Record<AtlasBundle['environment'], string>,
Expand Down Expand Up @@ -72,6 +73,9 @@ export function BundleTag({ className, platform, environment, ...props }: Bundel
<EnvironmentIcon environment="client" size={14} /> Client — Bundles that run on
device.
</li>
<li className="inline-flex items-center gap-1">
<EnvironmentIcon environment="dom" size={14} /> DOM — Webview embedded components.
</li>
<li className="inline-flex items-center gap-1">
<EnvironmentIcon environment="node" size={14} /> SSR — Bundles that only run on
server.
Expand Down
1 change: 1 addition & 0 deletions packages/expo-atlas-ui/components/EnvironmentIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type EnvironmentIconProps = Omit<

const iconsByEnvironment: Record<AtlasBundle['environment'], any> = {
client: require('lucide-react/dist/esm/icons/tablet-smartphone').default,
dom: require('lucide-react/dist/esm/icons/panel-top').default,
node: require('lucide-react/dist/esm/icons/hexagon').default,
'react-server': require('lucide-react/dist/esm/icons/server').default,
};
Expand Down
1 change: 1 addition & 0 deletions packages/expo-atlas-ui/components/EnvironmentName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type EnvironmentNameProps = PropsWithChildren<{

export const environmentNames: Record<AtlasBundle['environment'], string> = {
client: 'Client',
dom: 'DOM',
node: 'SSR',
'react-server': 'RSC',
};
Expand Down
45 changes: 41 additions & 4 deletions packages/expo-atlas/src/data/MetroGraphSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,17 @@ export function convertGraph(options: ConvertGraphToAtlasOptions): AtlasBundle {
const environment = getEnvironment(options) ?? 'client';
const serializeOptions = convertSerializeOptions(options);
const transformOptions = convertTransformOptions(options);
const entryPoint = getEntryPoint(options, environment);

return {
id: Buffer.from(
`${path.relative(sharedRoot, options.entryPoint)}+${platform}+${environment}`
).toString('base64url'),
id: Buffer.from(`${path.relative(sharedRoot, entryPoint)}+${platform}+${environment}`).toString(
'base64url'
),
platform,
environment,
projectRoot: options.projectRoot,
sharedRoot,
entryPoint: options.entryPoint,
entryPoint,
runtimeModules: options.preModules.map((module) => convertModule(options, module, sharedRoot)),
modules: collectEntryPointModules(options, sharedRoot),
serializeOptions,
Expand Down Expand Up @@ -253,6 +254,15 @@ function moduleIsVirtual(module: MetroModule) {
function getEnvironment(options: Pick<ConvertGraphToAtlasOptions, 'graph'>) {
const environment = options.graph.transformOptions?.customTransformOptions?.environment;

// Check if this graph is related to a DOM component
// NOTE(cedric): this is early/alpha support and may change in the future
if (
options.graph.transformOptions.platform === 'web' &&
!!options.graph.transformOptions.customTransformOptions?.dom
) {
return 'dom' as AtlasBundle['environment'];
}

if (typeof environment === 'string') {
return environment as AtlasBundle['environment'];
}
Expand All @@ -270,3 +280,30 @@ function getPlatform(options: Pick<ConvertGraphToAtlasOptions, 'graph'>) {

return null;
}

/**
* Determine if this graph is related to a DOM component, using the (custom) transform options.
* @remarks - This is preliminary support, and may change in the future
*/
function getEntryPoint(
options: ConvertGraphToAtlasOptions,
environment: AtlasBundle['environment'] = 'client'
) {
if (environment === 'dom') {
console.log({
entryPoint: options.entryPoint,
dom: options.graph.transformOptions.customTransformOptions?.dom,
_result: path.join(
options.entryPoint,
options.graph.transformOptions.customTransformOptions!.dom as string
),
});
}

return environment !== 'dom'
? options.entryPoint
: path.join(
options.entryPoint,
options.graph.transformOptions.customTransformOptions!.dom as string
);
}
2 changes: 1 addition & 1 deletion packages/expo-atlas/src/data/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type AtlasBundle = {
/** The platform for which the bundle was created */
platform: 'android' | 'ios' | 'web' | 'unknown';
/** The environment this bundle is compiled for */
environment: 'client' | 'node' | 'react-server';
environment: 'client' | 'dom' | 'node' | 'react-server';
/** The absolute path to the root of the project */
projectRoot: string;
/** The absolute path to the shared root of all imported modules */
Expand Down

0 comments on commit 5a87db5

Please sign in to comment.