Skip to content

Commit 5f0abf2

Browse files
authored
Various tooling and packaging improvements (mostly) (#259)
1 parent b4fec8c commit 5f0abf2

File tree

13 files changed

+4986
-156
lines changed

13 files changed

+4986
-156
lines changed

Apps/Playground/.eslintrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ module.exports = {
33
extends: '@react-native-community',
44
parser: '@typescript-eslint/parser',
55
plugins: ['@typescript-eslint'],
6+
rules: {
7+
'prettier/prettier': 0,
8+
},
69
};

Apps/Playground/App.tsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const EngineScreen: FunctionComponent<ViewProps> = (props: ViewProps) => {
3636
(scene.activeCamera as ArcRotateCamera).beta -= Math.PI / 8;
3737
setCamera(scene.activeCamera!);
3838
scene.createDefaultLight(true);
39-
const rootNode = new TransformNode("Root Container", scene);
39+
const rootNode = new TransformNode('Root Container', scene);
4040
setRootNode(rootNode);
4141

4242
const deviceSourceManager = new DeviceSourceManager(engine);
@@ -63,7 +63,7 @@ const EngineScreen: FunctionComponent<ViewProps> = (props: ViewProps) => {
6363
}
6464
});
6565

66-
const transformContainer = new TransformNode("Transform Container", scene);
66+
const transformContainer = new TransformNode('Transform Container', scene);
6767
transformContainer.parent = rootNode;
6868
transformContainer.scaling.scaleInPlace(0.2);
6969
transformContainer.position.y -= .2;
@@ -72,7 +72,7 @@ const EngineScreen: FunctionComponent<ViewProps> = (props: ViewProps) => {
7272
transformContainer.rotate(Vector3.Up(), 0.005 * scene.getAnimationRatio());
7373
};
7474

75-
SceneLoader.ImportMeshAsync("", "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/BoxAnimated/glTF-Binary/BoxAnimated.glb").then(result => {
75+
SceneLoader.ImportMeshAsync('', 'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/BoxAnimated/glTF-Binary/BoxAnimated.glb').then(result => {
7676
const mesh = result.meshes[0];
7777
mesh.parent = transformContainer;
7878
});
@@ -86,7 +86,7 @@ const EngineScreen: FunctionComponent<ViewProps> = (props: ViewProps) => {
8686
}, [rootNode, scale]);
8787

8888
const trackingStateToString = (trackingState: WebXRTrackingState | undefined) : string => {
89-
return trackingState === undefined ? "" : WebXRTrackingState[trackingState];
89+
return trackingState === undefined ? '' : WebXRTrackingState[trackingState];
9090
};
9191

9292
const onToggleXr = useCallback(() => {
@@ -96,7 +96,7 @@ const EngineScreen: FunctionComponent<ViewProps> = (props: ViewProps) => {
9696
} else {
9797
if (rootNode !== undefined && scene !== undefined) {
9898
const xr = await scene.createDefaultXRExperienceAsync({ disableDefaultUI: true, disableTeleportation: true })
99-
const session = await xr.baseExperience.enterXRAsync("immersive-ar", "unbounded", xr.renderTarget);
99+
const session = await xr.baseExperience.enterXRAsync('immersive-ar', 'unbounded', xr.renderTarget);
100100
setXrSession(session);
101101
session.onXRSessionEnded.add(() => {
102102
setXrSession(undefined);
@@ -124,24 +124,24 @@ const EngineScreen: FunctionComponent<ViewProps> = (props: ViewProps) => {
124124

125125
const onSnapshot = useCallback(async () => {
126126
if (engineViewCallbacks) {
127-
setSnapshotData("data:image/jpeg;base64," + await engineViewCallbacks.takeSnapshot());
127+
setSnapshotData('data:image/jpeg;base64,' + await engineViewCallbacks.takeSnapshot());
128128
}
129129
}, [engineViewCallbacks]);
130130

131131
return (
132132
<>
133133
<View style={props.style}>
134134
<Button title="Toggle EngineView" onPress={() => { setToggleView(!toggleView) }} />
135-
<Button title={ xrSession ? "Stop XR" : "Start XR"} onPress={onToggleXr} />
135+
<Button title={ xrSession ? 'Stop XR' : 'Start XR'} onPress={onToggleXr} />
136136
{ !toggleView &&
137137
<View style={{flex: 1}}>
138138
{ enableSnapshots &&
139139
<View style ={{flex: 1}}>
140-
<Button title={"Take Snapshot"} onPress={onSnapshot}/>
140+
<Button title={'Take Snapshot'} onPress={onSnapshot}/>
141141
<Image style={{flex: 1}} source={{uri: snapshotData }} />
142142
</View>
143143
}
144-
<EngineView style={props.style} camera={camera} onInitialized={onInitialized} />
144+
<EngineView camera={camera} onInitialized={onInitialized} />
145145
<Slider style={{position: 'absolute', minHeight: 50, margin: 10, left: 0, right: 0, bottom: 0}} minimumValue={0.2} maximumValue={2} step={0.01} value={defaultScale} onValueChange={setScale} />
146146
<Text style={{fontSize: 12, color: 'yellow', position: 'absolute', margin: 10}}>{trackingStateToString(trackingState)}</Text>
147147
</View>
@@ -163,7 +163,7 @@ const App = () => {
163163
return (
164164
<>
165165
<StatusBar barStyle="dark-content" />
166-
<SafeAreaView style={{flex: 1, backgroundColor: "white"}}>
166+
<SafeAreaView style={{flex: 1, backgroundColor: 'white'}}>
167167
{ !toggleScreen &&
168168
<EngineScreen style={{flex: 1}} />
169169
}
@@ -173,7 +173,7 @@ const App = () => {
173173
<Text style={{fontSize: 12}}>Engine has been disposed, and will be recreated.</Text>
174174
</View>
175175
}
176-
<Button title="Toggle EngineScreen" onPress={() => { setToggleScreen(!toggleScreen) }} />
176+
<Button title="Toggle EngineScreen" onPress={() => { setToggleScreen(!toggleScreen); }} />
177177
</SafeAreaView>
178178
</>
179179
);

Apps/Playground/metro.config.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ const path = require('path');
88
const fs = require('fs');
99
const exclusionList = require('metro-config/src/defaults/exclusionList');
1010

11+
// Escape function taken from the MDN documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
12+
function escapeRegExp(string) {
13+
return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
14+
}
15+
1116
// NOTE: The Metro bundler does not support symlinks (see https://github.com/facebook/metro/issues/1), which NPM uses for local packages.
1217
// To work around this, we explicity tell the metro bundler where to find local/linked packages.
1318

1419
// Create a mapping of package ids to linked directories.
15-
function getModuleMappings() {
20+
function processModuleSymLinks() {
1621
const nodeModulesPath = path.resolve(__dirname, 'node_modules');
1722
let moduleMappings = {};
23+
let moduleExclusions = [];
1824

1925
function findPackageDirs(directory) {
2026
fs.readdirSync(directory).forEach(item => {
@@ -32,6 +38,15 @@ function getModuleMappings() {
3238
if (fs.existsSync(packagePath)) {
3339
const packageId = path.relative(nodeModulesPath, itemPath);
3440
moduleMappings[packageId] = linkPath;
41+
42+
const packageInfoData = fs.readFileSync(packagePath);
43+
const packageInfo = JSON.parse(packageInfoData);
44+
45+
// Search for any dev dependencies of the package. They should be excluded from metro so the packages don't get
46+
// imported twice in the bundle
47+
for (const devDependency in packageInfo.devDependencies) {
48+
moduleExclusions.push(new RegExp(escapeRegExp(path.join(linkPath, "node_modules", devDependency)) + "\/.*"));
49+
}
3550
}
3651
}
3752
} else if (itemStat.isDirectory()) {
@@ -42,10 +57,10 @@ function getModuleMappings() {
4257

4358
findPackageDirs(nodeModulesPath);
4459

45-
return moduleMappings;
60+
return [moduleMappings, moduleExclusions];
4661
}
4762

48-
const moduleMappings = getModuleMappings();
63+
const [moduleMappings, moduleExclusions] = processModuleSymLinks();
4964
console.log("Mapping the following sym linked packages:");
5065
console.log(moduleMappings);
5166

@@ -71,15 +86,15 @@ module.exports = {
7186
},
7287
),
7388

74-
blockList: exclusionList([
89+
blockList: exclusionList(moduleExclusions.concat([
7590
// Avoid error EBUSY: resource busy or locked, open 'D:\a\1\s\packages\playground\msbuild.ProjectImports.zip' in pipeline
7691
/.*\.ProjectImports\.zip/,
7792

7893
// This stops "react-native run-windows" from causing the metro server to crash if its already running
7994
new RegExp(
8095
`${path.resolve(__dirname, 'windows').replace(/[/\\]/g, '/')}.*`,
8196
),
82-
]),
97+
])),
8398
},
8499

85100
projectRoot: path.resolve(__dirname),

0 commit comments

Comments
 (0)