Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
config.entry = async () => {
const entries = await resolveEntryAsync(expoEntry);
const swPath = join(locations.production.registerServiceWorker);
if (entries.app && !entries.app.includes(swPath) && autoRegister) {
let content = readFileSync(require.resolve(locations.template.registerServiceWorker), 'utf8');
if (content) {
content = content
.replace('SW_PUBLIC_URL', publicUrl)
.replace('SW_PUBLIC_SCOPE', ensureSlash(scope || publicUrl, true));
ensureDirSync(locations.production.folder);
} else {
content = `
console.warn("failed to load service-worker in @expo/webpack-config -> withWorkbox. This can be due to the environment the project was built in. Please try again with a globally installed instance of expo-cli. If you continue to run into problems open an issue in https://github.com/expo/expo-cli")
`;
}
writeFileSync(swPath, content, 'utf8');
if (!Array.isArray(entries.app)) {
entries.app = [entries.app];
}
entries.app.unshift(swPath);
}
return entries;
};