"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "default", { enumerable: true, get: function() { return DevServer; } }); const _requestmeta = require("../request-meta"); const _react = /*#__PURE__*/ _interop_require_wildcard(require("react")); const _fs = /*#__PURE__*/ _interop_require_default(require("fs")); const _jestworker = require("next/dist/compiled/jest-worker"); const _path = require("path"); const _output = require("../../build/output"); const _constants = require("../../lib/constants"); const _findpagesdir = require("../../lib/find-pages-dir"); const _constants1 = require("../../shared/lib/constants"); const _nextserver = /*#__PURE__*/ _interop_require_wildcard(require("../next-server")); const _normalizepagepath = require("../../shared/lib/page-path/normalize-page-path"); const _pathhasprefix = require("../../shared/lib/router/utils/path-has-prefix"); const _removepathprefix = require("../../shared/lib/router/utils/remove-path-prefix"); const _storage = require("../../telemetry/storage"); const _trace = require("../../trace"); const _findpagefile = require("../lib/find-page-file"); const _utils = require("../lib/utils"); const _coalescedfunction = require("../../lib/coalesced-function"); const _loaddefaulterrorcomponents = require("../load-default-error-components"); const _utils1 = require("../../shared/lib/utils"); const _log = /*#__PURE__*/ _interop_require_wildcard(require("../../build/output/log")); const _iserror = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/is-error")); const _utils2 = require("../../build/utils"); const _formatservererror = require("../../lib/format-server-error"); const _devroutematchermanager = require("../route-matcher-managers/dev-route-matcher-manager"); const _devpagesroutematcherprovider = require("../route-matcher-providers/dev/dev-pages-route-matcher-provider"); const _devpagesapiroutematcherprovider = require("../route-matcher-providers/dev/dev-pages-api-route-matcher-provider"); const _devapppageroutematcherprovider = require("../route-matcher-providers/dev/dev-app-page-route-matcher-provider"); const _devapprouteroutematcherprovider = require("../route-matcher-providers/dev/dev-app-route-route-matcher-provider"); const _nodemanifestloader = require("../route-matcher-providers/helpers/manifest-loaders/node-manifest-loader"); const _batchedfilereader = require("../route-matcher-providers/dev/helpers/file-reader/batched-file-reader"); const _defaultfilereader = require("../route-matcher-providers/dev/helpers/file-reader/default-file-reader"); const _lrucache = require("../lib/lru-cache"); const _middlewareroutematcher = require("../../shared/lib/router/utils/middleware-route-matcher"); const _detachedpromise = require("../../lib/detached-promise"); const _ispostpone = require("../lib/router-utils/is-postpone"); const _generateinterceptionroutesrewrites = require("../../lib/generate-interception-routes-rewrites"); const _buildcustomroute = require("../../lib/build-custom-route"); const _errorsource = require("../../shared/lib/error-source"); const _logrequests = require("./log-requests"); const _fallback = require("../../lib/fallback"); const _instrumentationglobalsexternal = require("../lib/router-utils/instrumentation-globals.external"); const _routeregex = require("../../shared/lib/router/utils/route-regex"); function _interop_require_default(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interop_require_wildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = { __proto__: null }; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for(var key in obj){ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } // Load ReactDevOverlay only when needed let PagesDevOverlayBridgeImpl; const ReactDevOverlay = (props)=>{ if (PagesDevOverlayBridgeImpl === undefined) { PagesDevOverlayBridgeImpl = require('../../next-devtools/userspace/pages/pages-dev-overlay-setup').PagesDevOverlayBridge; } return _react.createElement(PagesDevOverlayBridgeImpl, props); }; class DevServer extends _nextserver.default { getStaticPathsWorker() { const worker = new _jestworker.Worker(require.resolve('./static-paths-worker'), { maxRetries: 1, // For dev server, it's not necessary to spin up too many workers as long as you are not doing a load test. // This helps reusing the memory a lot. numWorkers: 1, enableWorkerThreads: this.nextConfig.experimental.workerThreads, forkOptions: { env: { ...process.env, // discard --inspect/--inspect-brk flags from process.env.NODE_OPTIONS. Otherwise multiple Node.js debuggers // would be started if user launch Next.js in debugging mode. The number of debuggers is linked to // the number of workers Next.js tries to launch. The only worker users are interested in debugging // is the main Next.js one NODE_OPTIONS: (0, _utils.getFormattedNodeOptionsWithoutInspect)() } } }); worker.getStdout().pipe(process.stdout); worker.getStderr().pipe(process.stderr); return worker; } constructor(options){ var _this_nextConfig_experimental_amp, _this_nextConfig_experimental; try { // Increase the number of stack frames on the server Error.stackTraceLimit = 50; } catch {} super({ ...options, dev: true }), /** * The promise that resolves when the server is ready. When this is unset * the server is ready. */ this.ready = new _detachedpromise.DetachedPromise(); this.bundlerService = options.bundlerService; this.startServerSpan = options.startServerSpan ?? (0, _trace.trace)('start-next-dev-server'); this.renderOpts.dev = true; this.renderOpts.ErrorDebug = ReactDevOverlay; this.staticPathsCache = new _lrucache.LRUCache(// 5MB 5 * 1024 * 1024, function length(value) { var _JSON_stringify; return ((_JSON_stringify = JSON.stringify(value.staticPaths)) == null ? void 0 : _JSON_stringify.length) ?? 0; }); this.renderOpts.ampSkipValidation = ((_this_nextConfig_experimental = this.nextConfig.experimental) == null ? void 0 : (_this_nextConfig_experimental_amp = _this_nextConfig_experimental.amp) == null ? void 0 : _this_nextConfig_experimental_amp.skipValidation) ?? false; this.renderOpts.ampValidator = async (html, pathname)=>{ var _this_nextConfig_experimental_amp, _this_nextConfig_experimental; const { getAmpValidatorInstance, getBundledAmpValidatorFilepath } = require('../../export/helpers/get-amp-html-validator'); const validatorPath = ((_this_nextConfig_experimental = this.nextConfig.experimental) == null ? void 0 : (_this_nextConfig_experimental_amp = _this_nextConfig_experimental.amp) == null ? void 0 : _this_nextConfig_experimental_amp.validator) || getBundledAmpValidatorFilepath(); const validator = await getAmpValidatorInstance(validatorPath); const result = validator.validateString(html); (0, _output.ampValidation)(pathname, result.errors.filter((error)=>{ if (error.severity === 'ERROR') { // Unclear yet if these actually prevent the page from being indexed by the AMP cache. // These are coming from React so all we can do is ignore them for now. // // https://github.com/ampproject/amphtml/issues/40279 if (error.code === 'DISALLOWED_ATTR' && error.params[0] === 'blocking' && error.params[1] === 'link') { return false; } //