-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add dedicated Expo CLI entrypoint (#22)
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './build/src/cli'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./build/src/cli'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { ConfigT as MetroConfig } from 'metro-config'; | ||
|
||
import { MetroGraphSource } from './data/MetroGraphSource'; | ||
import { createAtlasMiddleware } from './utils/middleware'; | ||
|
||
/** | ||
* Iniitalize Expo Atlas to gather statistics from Metro when exporting bundles. | ||
* This function adds the required Metro config, and should be used inside the Expo CLI. | ||
* | ||
* @example ```js | ||
* const atlasFromProject = requireFrom(projectRoot, 'expo-atlas/cli'); | ||
* | ||
* if (atlasFromProject) { | ||
* middleware.use('/_expo/atlas', atlasFromProject.middleware); | ||
* } | ||
* ``` | ||
*/ | ||
export function createExpoAtlasMiddleware(config: MetroConfig) { | ||
const projectRoot = config.projectRoot; | ||
|
||
const source = new MetroGraphSource(); | ||
const middleware = createAtlasMiddleware(source); | ||
|
||
const metroCustomSerializer = config.serializer?.customSerializer ?? (() => {}); | ||
const metroExtensions = { | ||
source: config.resolver?.sourceExts, | ||
asset: config.resolver?.assetExts, | ||
}; | ||
|
||
// @ts-expect-error Should still be writable at this stage | ||
config.serializer.customSerializer = (entryPoint, preModules, graph, options) => { | ||
source.onSerializeGraph({ | ||
projectRoot, | ||
entryPoint, | ||
preModules, | ||
graph, | ||
options, | ||
extensions: metroExtensions, | ||
}); | ||
|
||
return metroCustomSerializer(entryPoint, preModules, graph, options); | ||
}; | ||
|
||
return { source, middleware }; | ||
} |