Skip to content

Commit

Permalink
chore(runtime): fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Jan 4, 2024
1 parent 6169b3b commit fe16a23
Show file tree
Hide file tree
Showing 21 changed files with 94 additions and 91 deletions.
8 changes: 4 additions & 4 deletions runtime/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export default class App extends React.Component<object, State> {
};

_handleAppStateChange = (
appState: 'active' | 'inactive' | 'background' | 'unknown' | 'extension'
appState: 'active' | 'inactive' | 'background' | 'unknown' | 'extension',
) => {
const foreground = appState === 'active';

Expand Down Expand Up @@ -232,7 +232,7 @@ export default class App extends React.Component<object, State> {

if (!parsedUrl) {
Logger.warn(
`Snack URL didn't have either the format 'https://exp.host/@snack/SAVE_UUID+CHANNEL_UUID' or 'https://exp.host/@snack/sdk.14.0.0-UUID'`
`Snack URL didn't have either the format 'https://exp.host/@snack/SAVE_UUID+CHANNEL_UUID' or 'https://exp.host/@snack/sdk.14.0.0-UUID'`,
);
return false;
}
Expand Down Expand Up @@ -278,7 +278,7 @@ export default class App extends React.Component<object, State> {
JSON.stringify({
url,
timestamp: Date.now(),
})
}),
);

await Updates.reloadAsync();
Expand Down Expand Up @@ -352,7 +352,7 @@ export default class App extends React.Component<object, State> {
this._lastCodeUpdatePromise = this._handleCodeUpdate(
message,
this._lastCodeUpdatePromise,
deviceId
deviceId,
);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/src/Console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ export const initialize = (callback: (method: string, payload: unknown[]) => voi
'%c APP %c ERROR ',
'background: #01FFA2;',
'background: #f44336; color: #fff;',
...args
...args,
);
break;
case 'warn':
originalConsole.log(
'%c APP %c WARN ',
'background: #01FFA2;',
'background: #FF9800; color: #fff;',
...args
...args,
);
break;
}
}

if (
ignoredWarnings.some(
(warning) => typeof args[0] === 'string' && (args[0] as string).startsWith(warning)
(warning) => typeof args[0] === 'string' && (args[0] as string).startsWith(warning),
)
) {
return;
Expand Down
8 changes: 4 additions & 4 deletions runtime/src/Errors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function prettyStack(error: Error) {
? // Avoid adding the `column`, `[email protected]` does not properly resolve the column. It uses the generated column number.
u.path + (u.line !== null && u.column !== null ? `:${u.line})\n` : '\n')
: match.replace(/module:\/+/, '').replace(/.([a-z]+).js/g, '.$1');
}
},
);

if (!sourceUnmappedStack) {
Expand Down Expand Up @@ -222,7 +222,7 @@ export class ErrorBoundary extends React.Component<Props, State> {
children.push(
<Text key={children.length + ''} style={styles.plain}>
{text}
</Text>
</Text>,
);
text = '';
}
Expand All @@ -231,7 +231,7 @@ export class ErrorBoundary extends React.Component<Props, State> {
children.push(
<Text key={children.length + ''} style={styles.code}>
{text}
</Text>
</Text>,
);
isCode = false;
text = '';
Expand All @@ -246,7 +246,7 @@ export class ErrorBoundary extends React.Component<Props, State> {
children.push(
<Text key={children.length + ''} style={isCode ? styles.code : styles.plain}>
{text}
</Text>
</Text>,
);
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/src/Files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const update = async ({ message }: { message: Message }) => {
changedPaths.push(path);
}
}
})
}),
);

for (const path in files) {
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/LoadingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class LoadingView extends React.PureComponent<Props, State> {
duration: (inputRange.length - 1) * 1000,
useNativeDriver: true,
}),
])
]),
).start();
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/src/Logger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const logger =
originalConsole.log(
`%c ${type.toUpperCase()} `,
`background: ${color}; color: ${textColor ?? '#fff'}`,
...messages
...messages,
);
}
};
Expand Down
105 changes: 54 additions & 51 deletions runtime/src/Modules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import * as context from 'snack-require-context';
// web-assembly which is not yet supported on react-native.
import { SourceMapConsumer, RawSourceMap } from 'source-map';

import ReanimatedPlugin from '../vendor/reanimated-plugin';
import System from '../vendor/system.src';
import * as Files from './Files';
import * as Logger from './Logger';
import AssetRegistry from './NativeModules/AssetRegistry';
import FileSystem from './NativeModules/FileSystem';
import * as Profiling from './Profiling';
import aliases from './aliases';
import ReanimatedPlugin from '../vendor/reanimated-plugin';
import System from '../vendor/system.src';

type Dependencies = {
[key: string]: { resolved?: string; version: string; handle?: string };
Expand Down Expand Up @@ -97,10 +97,10 @@ export const updateProjectDependencies = async (newProjectDependencies: Dependen
const removedOrChangedDependencies = Object.keys(projectDependencies).filter(
(name) =>
!newProjectDependencies[name] ||
newProjectDependencies[name].resolved !== projectDependencies[name].resolved
newProjectDependencies[name].resolved !== projectDependencies[name].resolved,
);
const addedDependencies = Object.keys(newProjectDependencies).filter(
(name) => !projectDependencies[name]
(name) => !projectDependencies[name],
);
const changedDependencies = removedOrChangedDependencies.concat(addedDependencies);
if (changedDependencies.length) {
Expand All @@ -114,8 +114,8 @@ export const updateProjectDependencies = async (newProjectDependencies: Dependen
? `${projectDependencies[name].resolved} -> ${newProjectDependencies[name].resolved}`
: newProjectDependencies[name].resolved
: 'removed'
})`
)
})`,
),
);
}
const removedOrChangedUris = removedOrChangedDependencies.map((name) => `module://${name}`);
Expand Down Expand Up @@ -199,7 +199,7 @@ const fetchPipeline = async (load: Load) => {
Logger.module(
'Loaded asset metadata',
s3Url,
`from cache ${contents ? contents.length : undefined} bytes`
`from cache ${contents ? contents.length : undefined} bytes`,
);
} else {
Logger.module('Fetching asset metadata', s3Url, '...');
Expand Down Expand Up @@ -230,7 +230,7 @@ const fetchPipeline = async (load: Load) => {
undefined,
(error) => {
Logger.error('Failed to store asset metadata in cache', error);
}
},
);
}
}
Expand Down Expand Up @@ -308,7 +308,7 @@ const fetchPipeline = async (load: Load) => {
Logger.module(
'Loaded dependency',
cacheHandle,
`from cache ${bundle ? bundle.length : undefined} bytes`
`from cache ${bundle ? bundle.length : undefined} bytes`,
);
} else {
// In development, try fetching from staging cloudfront first
Expand Down Expand Up @@ -336,7 +336,7 @@ const fetchPipeline = async (load: Load) => {
} else {
Logger.warn(
'Dependency could not be loaded from staging, trying production ...',
handle
handle,
);
}
}
Expand All @@ -345,7 +345,7 @@ const fetchPipeline = async (load: Load) => {
Logger.module(
'Fetched dependency',
fetchFrom,
`storing in cache ${bundle.length} bytes`
`storing in cache ${bundle.length} bytes`,
);
break;
}
Expand Down Expand Up @@ -441,11 +441,11 @@ const translatePipeline = async (load: Load) => {
Logger.module(
'Transpiled',
sanitizeModule(filename),
`${result?.code ? result.code.length : '???'} bytes`
`${result?.code ? result.code.length : '???'} bytes`,
);

return result;
}
},
);
// @ts-ignore
load.metadata.sourceMap = transformed.map;
Expand All @@ -454,8 +454,8 @@ const translatePipeline = async (load: Load) => {
async () =>
await new SourceMapConsumer(
// @ts-ignore
transformed.map
)
transformed.map,
),
);
return transformed!.code;
} catch (e) {
Expand Down Expand Up @@ -532,7 +532,7 @@ const _initialize = async () => {
// and tracing (makes SystemJS collect dependency info).
await System.set(
'systemjs-expo-snack-plugin',
System.newModule({ translate: translatePipeline, fetch: fetchPipeline })
System.newModule({ translate: translatePipeline, fetch: fetchPipeline }),
);
await System.config({
packages: {
Expand All @@ -554,8 +554,8 @@ const _initialize = async () => {
await Promise.all(
Object.keys(aliases).map(
async (key) =>
await System.set(key, System.newModule({ default: aliases[key], __useDefault: true }))
)
await System.set(key, System.newModule({ default: aliases[key], __useDefault: true })),
),
);

// Special handling for vector-icons to allow deep imports
Expand All @@ -573,7 +573,7 @@ const _initialize = async () => {

await System.set(`@expo/vector-icons/${name}`, iconSetModule);
await System.set(`react-native-vector-icons/${name}`, iconSetModule);
})
}),
);

// Fix SystemJS path normalization to handle Snack-related special cases
Expand Down Expand Up @@ -622,7 +622,7 @@ const _initialize = async () => {
const regex = new RegExp(
`^${escapeStringRegexp(filename.replace(/\.[^.]+$/i, ''))}(${
isImage ? '@\\d+(\\.\\d+)?x' : '()'
})?(\\.([a-z]+(\.expo)?))?\\.${ext}$` // eslint-disable-line no-useless-escape
})?(\\.([a-z]+(\.expo)?))?\\.${ext}$`, // eslint-disable-line no-useless-escape
);

// Build a map of files according to the scale and platform
Expand All @@ -632,37 +632,40 @@ const _initialize = async () => {
// 1.5: { path: image@1.5x.png, platform: 'android' },
// 2: { path: image@2x.png, platform: 'android' },
// }
const map = Files.list().reduce((acc, curr) => {
const match = curr.match(regex);
const map = Files.list().reduce(
(acc, curr) => {
const match = curr.match(regex);

if (match) {
// eslint-disable-next-line no-unused-vars
const [, scaleString, , , platform] = match;
if (match) {
// eslint-disable-next-line no-unused-vars
const [, scaleString, , , platform] = match;

// If file doesn't have a scale, default to 1
// This can happen for asset files without scale, or JS files
const scale = scaleString ? parseFloat(scaleString.substr(1)) : 1;
// If file doesn't have a scale, default to 1
// This can happen for asset files without scale, or JS files
const scale = scaleString ? parseFloat(scaleString.substr(1)) : 1;

if (platform && !platforms.includes(platform)) {
// If the file has a platform, but it's not the current platform,
// return what we had
return acc;
}
if (platform && !platforms.includes(platform)) {
// If the file has a platform, but it's not the current platform,
// return what we had
return acc;
}

if (
acc[scale] &&
platforms.indexOf(acc[scale].platform) > platforms.indexOf(platform)
) {
// If we have already found the platform with a higher priority than current platform,
// return what we had
return acc;
}
if (
acc[scale] &&
platforms.indexOf(acc[scale].platform) > platforms.indexOf(platform)
) {
// If we have already found the platform with a higher priority than current platform,
// return what we had
return acc;
}

return { ...acc, [scale]: { path: curr, platform } };
}
return { ...acc, [scale]: { path: curr, platform } };
}

return acc;
}, {} as { [key: string]: { path: string; platform: string } });
return acc;
},
{} as { [key: string]: { path: string; platform: string } },
);

if (Object.keys(map).length) {
// Get the device's pixel density and find the closest bigger matching scale
Expand Down Expand Up @@ -696,7 +699,7 @@ const _initialize = async () => {
if (Files.get(basename + '/package.json')) {
try {
const pack = JSON.parse(
(Files.get(basename + '/package.json') ?? { contents: '' }).contents || '{}' // eslint-disable-line @typescript-eslint/prefer-nullish-coalescing
(Files.get(basename + '/package.json') ?? { contents: '' }).contents || '{}', // eslint-disable-line @typescript-eslint/prefer-nullish-coalescing
);
index = pack['react-native'] || pack['main'] || 'index';
ext = index.split('.').pop()!;
Expand Down Expand Up @@ -781,9 +784,9 @@ const _initialize = async () => {
Object.keys(this.loads).map((url) => {
dependsOn[url] = {};
return this.loads[url].deps.map(
async (dep: string) => (dependsOn[url][await this.resolve(dep, url)] = true)
async (dep: string) => (dependsOn[url][await this.resolve(dep, url)] = true),
);
})
}),
);

// Visit immediate dependents of `rootModuleNames` by post-order DFS, skipping modules that
Expand Down Expand Up @@ -820,7 +823,7 @@ const _initialize = async () => {
export function sanitizeModule(moduleName: string): string {
return moduleName.substring(
moduleName.startsWith('module://') ? 9 : 0,
moduleName.endsWith('.js.js') ? moduleName.length - 3 : moduleName.length
moduleName.endsWith('.js.js') ? moduleName.length - 3 : moduleName.length,
);
}

Expand Down Expand Up @@ -867,7 +870,7 @@ export const flush = async ({
modules.forEach((dep: string) => System.delete(dep));

changedPaths.forEach(
(path) => delete transformCache[`module://${path}${path.endsWith('.js') ? '' : '.js'}`]
(path) => delete transformCache[`module://${path}${path.endsWith('.js') ? '' : '.js'}`],
);
});

Expand Down Expand Up @@ -896,7 +899,7 @@ export const load = async (name: string, relativeTo?: string) => {
'Loaded modules',
Array.from<string>(System.keys())
.filter((name) => name.toLowerCase().indexOf('app.js') >= 0 || name.indexOf('module://') >= 0)
.map(sanitizeModule)
.map(sanitizeModule),
);
return res;
};
Loading

0 comments on commit fe16a23

Please sign in to comment.