static-paths-worker.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.loadStaticPaths = loadStaticPaths;
  6. require("../node-polyfill-fetch");
  7. var _utils = require("../../build/utils");
  8. var _loadComponents = require("../load-components");
  9. var _config = require("../config");
  10. let workerWasUsed = false;
  11. async function loadStaticPaths({ distDir , pathname , serverless , config , httpAgentOptions , locales , defaultLocale , isAppPath , originalAppPath }) {
  12. // we only want to use each worker once to prevent any invalid
  13. // caches
  14. if (workerWasUsed) {
  15. process.exit(1);
  16. }
  17. // update work memory runtime-config
  18. require("../../shared/lib/runtime-config").setConfig(config);
  19. (0, _config).setHttpAgentOptions(httpAgentOptions);
  20. const components = await (0, _loadComponents).loadComponents({
  21. distDir,
  22. pathname: originalAppPath || pathname,
  23. serverless,
  24. hasServerComponents: false,
  25. isAppPath: !!isAppPath
  26. });
  27. if (!components.getStaticPaths && !isAppPath) {
  28. // we shouldn't get to this point since the worker should
  29. // only be called for SSG pages with getStaticPaths
  30. throw new Error(`Invariant: failed to load page with getStaticPaths for ${pathname}`);
  31. }
  32. workerWasUsed = true;
  33. if (isAppPath) {
  34. const generateParams = (0, _utils).collectGenerateParams(components.ComponentMod.tree);
  35. return (0, _utils).buildAppStaticPaths({
  36. page: pathname,
  37. generateParams,
  38. configFileName: config.configFileName
  39. });
  40. }
  41. return (0, _utils).buildStaticPaths({
  42. page: pathname,
  43. getStaticPaths: components.getStaticPaths,
  44. configFileName: config.configFileName,
  45. locales,
  46. defaultLocale
  47. });
  48. }
  49. //# sourceMappingURL=static-paths-worker.js.map