How to use the @expo/config/paths.ensureSlash function in @expo/config

To help you get started, we’ve selected a few @expo/config examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github expo / expo-cli / packages / webpack-config / src / addons / withWorkbox.ts View on Github external
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;
  };