@openuiai/next 16.2.0 → 16.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/next +2 -2
- package/dist/build/get-babel-loader-config.js +1 -1
- package/dist/build/get-babel-loader-config.js.map +1 -1
- package/dist/build/index.js +3 -3
- package/dist/build/webpack-config.js +6 -4
- package/dist/build/webpack-config.js.map +1 -1
- package/dist/cache/cache-control.js +22 -0
- package/dist/cache/cache-control.js.map +1 -0
- package/dist/cache/clone-response.js +77 -0
- package/dist/cache/clone-response.js.map +1 -0
- package/dist/cache/dedupe-fetch.js +123 -0
- package/dist/cache/dedupe-fetch.js.map +1 -0
- package/dist/cache/lazy-result.js +46 -0
- package/dist/cache/lazy-result.js.map +1 -0
- package/dist/cache/lru-cache.js +177 -0
- package/dist/cache/lru-cache.js.map +1 -0
- package/dist/client/app-bootstrap.js +1 -1
- package/dist/client/index.js +1 -1
- package/dist/compiled/next-server/server.runtime.prod.js.map +1 -1
- package/dist/concurrency/batcher.js +65 -0
- package/dist/concurrency/batcher.js.map +1 -0
- package/dist/concurrency/coalesced-function.js +39 -0
- package/dist/concurrency/coalesced-function.js.map +1 -0
- package/dist/concurrency/scheduler.js +64 -0
- package/dist/concurrency/scheduler.js.map +1 -0
- package/dist/concurrency/wait.js +19 -0
- package/dist/concurrency/wait.js.map +1 -0
- package/dist/concurrency/with-promise-cache.js +24 -0
- package/dist/concurrency/with-promise-cache.js.map +1 -0
- package/dist/config/detect-typo.js +51 -0
- package/dist/config/detect-typo.js.map +1 -0
- package/dist/config/find-config.js +102 -0
- package/dist/config/find-config.js.map +1 -0
- package/dist/config/get-package-version.js +118 -0
- package/dist/config/get-package-version.js.map +1 -0
- package/dist/config/get-project-dir.js +51 -0
- package/dist/config/get-project-dir.js.map +1 -0
- package/dist/config/install-dependencies.js +40 -0
- package/dist/config/install-dependencies.js.map +1 -0
- package/dist/config/needs-experimental-react.js +16 -0
- package/dist/config/needs-experimental-react.js.map +1 -0
- package/dist/config/static-env.js +92 -0
- package/dist/config/static-env.js.map +1 -0
- package/dist/constants/constants.js +397 -0
- package/dist/constants/constants.js.map +1 -0
- package/dist/errors/compile-error.js +14 -0
- package/dist/errors/compile-error.js.map +1 -0
- package/dist/errors/error-source.js +36 -0
- package/dist/errors/error-source.js.map +1 -0
- package/dist/errors/error-telemetry-utils.js +42 -0
- package/dist/errors/error-telemetry-utils.js.map +1 -0
- package/dist/errors/fatal-error.js +14 -0
- package/dist/errors/fatal-error.js.map +1 -0
- package/dist/errors/format-server-error.js +74 -0
- package/dist/errors/format-server-error.js.map +1 -0
- package/dist/errors/invariant-error.js +18 -0
- package/dist/errors/invariant-error.js.map +1 -0
- package/dist/errors/is-error.js +65 -0
- package/dist/errors/is-error.js.map +1 -0
- package/dist/errors/no-fallback-error.js +18 -0
- package/dist/errors/no-fallback-error.js.map +1 -0
- package/dist/esm/build/get-babel-loader-config.js +1 -1
- package/dist/esm/build/get-babel-loader-config.js.map +1 -1
- package/dist/esm/build/index.js +3 -3
- package/dist/esm/build/webpack-config.js +6 -4
- package/dist/esm/build/webpack-config.js.map +1 -1
- package/dist/esm/client/app-bootstrap.js +1 -1
- package/dist/esm/client/index.js +1 -1
- package/dist/esm/lib/metadata/resolvers/resolve-url.js +1 -1
- package/dist/esm/lib/metadata/resolvers/resolve-url.js.map +1 -1
- package/dist/esm/lib/worker.js +1 -1
- package/dist/esm/lib/worker.js.map +1 -1
- package/dist/esm/server/dev/hot-reloader-webpack.js +1 -1
- package/dist/esm/server/lib/app-info-log.js +1 -1
- package/dist/esm/server/lib/start-server.js +1 -1
- package/dist/esm/server/websocket/setup.js +1 -1
- package/dist/esm/server/websocket/setup.js.map +1 -1
- package/dist/esm/server/websocket/types.js +1 -1
- package/dist/esm/server/websocket/types.js.map +1 -1
- package/dist/esm/shared/lib/errors/canary-only-config-error.js +1 -1
- package/dist/filesystem/file-exists.js +53 -0
- package/dist/filesystem/file-exists.js.map +1 -0
- package/dist/filesystem/find-pages-dir.js +65 -0
- package/dist/filesystem/find-pages-dir.js.map +1 -0
- package/dist/filesystem/find-root.js +118 -0
- package/dist/filesystem/find-root.js.map +1 -0
- package/dist/filesystem/get-files-in-dir.js +33 -0
- package/dist/filesystem/get-files-in-dir.js.map +1 -0
- package/dist/filesystem/multi-file-writer.js +75 -0
- package/dist/filesystem/multi-file-writer.js.map +1 -0
- package/dist/filesystem/realpath.js +20 -0
- package/dist/filesystem/realpath.js.map +1 -0
- package/dist/filesystem/recursive-copy.js +76 -0
- package/dist/filesystem/recursive-copy.js.map +1 -0
- package/dist/filesystem/recursive-delete.js +137 -0
- package/dist/filesystem/recursive-delete.js.map +1 -0
- package/dist/filesystem/recursive-readdir.js +124 -0
- package/dist/filesystem/recursive-readdir.js.map +1 -0
- package/dist/filesystem/rename.js +87 -0
- package/dist/filesystem/rename.js.map +1 -0
- package/dist/filesystem/write-atomic.js +28 -0
- package/dist/filesystem/write-atomic.js.map +1 -0
- package/dist/fonts/font-utils.js +43 -0
- package/dist/fonts/font-utils.js.map +1 -0
- package/dist/fonts/get-preloadable-fonts.js +39 -0
- package/dist/fonts/get-preloadable-fonts.js.map +1 -0
- package/dist/hash/bloom-filter.js +85 -0
- package/dist/hash/bloom-filter.js.map +1 -0
- package/dist/hash/etag.js +56 -0
- package/dist/hash/etag.js.map +1 -0
- package/dist/hash/fnv1a.js +56 -0
- package/dist/hash/fnv1a.js.map +1 -0
- package/dist/hash/hash.js +39 -0
- package/dist/hash/hash.js.map +1 -0
- package/dist/hostname/format-hostname.js +16 -0
- package/dist/hostname/format-hostname.js.map +1 -0
- package/dist/hostname/get-hostname.js +23 -0
- package/dist/hostname/get-hostname.js.map +1 -0
- package/dist/hostname/get-network-host.js +44 -0
- package/dist/hostname/get-network-host.js.map +1 -0
- package/dist/hostname/is-ipv6.js +41 -0
- package/dist/hostname/is-ipv6.js.map +1 -0
- package/dist/image/find-closest-quality.js +19 -0
- package/dist/image/find-closest-quality.js.map +1 -0
- package/dist/image/get-img-props.js +573 -0
- package/dist/image/get-img-props.js.map +1 -0
- package/dist/image/image-blur-svg.js +22 -0
- package/dist/image/image-blur-svg.js.map +1 -0
- package/dist/image/image-config-context.shared-runtime.js +19 -0
- package/dist/image/image-config-context.shared-runtime.js.map +1 -0
- package/dist/image/image-config.js +74 -0
- package/dist/image/image-config.js.map +1 -0
- package/dist/image/image-loader.js +91 -0
- package/dist/image/image-loader.js.map +1 -0
- package/dist/image/image-optimizer.js +1019 -0
- package/dist/image/image-optimizer.js.map +1 -0
- package/dist/image/match-local-pattern.js +46 -0
- package/dist/image/match-local-pattern.js.map +1 -0
- package/dist/image/match-remote-pattern.js +63 -0
- package/dist/image/match-remote-pattern.js.map +1 -0
- package/dist/image/mime-type.js +20 -0
- package/dist/image/mime-type.js.map +1 -0
- package/dist/lib/metadata/resolvers/resolve-url.js +1 -1
- package/dist/lib/metadata/resolvers/resolve-url.js.map +1 -1
- package/dist/lib/worker.js +1 -1
- package/dist/lib/worker.js.map +1 -1
- package/dist/memory/gc-observer.js +53 -0
- package/dist/memory/gc-observer.js.map +1 -0
- package/dist/memory/shutdown.js +29 -0
- package/dist/memory/shutdown.js.map +1 -0
- package/dist/memory/startup.js +47 -0
- package/dist/memory/startup.js.map +1 -0
- package/dist/memory/trace.js +109 -0
- package/dist/memory/trace.js.map +1 -0
- package/dist/module/client-and-server-references.js +54 -0
- package/dist/module/client-and-server-references.js.map +1 -0
- package/dist/module/format-dynamic-import-path.js +24 -0
- package/dist/module/format-dynamic-import-path.js.map +1 -0
- package/dist/module/interop-default.js +15 -0
- package/dist/module/interop-default.js.map +1 -0
- package/dist/module/resolve-from.js +79 -0
- package/dist/module/resolve-from.js.map +1 -0
- package/dist/module/semver-noop.js +18 -0
- package/dist/module/semver-noop.js.map +1 -0
- package/dist/object/deep-freeze.js +30 -0
- package/dist/object/deep-freeze.js.map +1 -0
- package/dist/object/deep-readonly.js +10 -0
- package/dist/object/deep-readonly.js.map +1 -0
- package/dist/object/is-plain-object.js +42 -0
- package/dist/object/is-plain-object.js.map +1 -0
- package/dist/object/non-nullable.js +15 -0
- package/dist/object/non-nullable.js.map +1 -0
- package/dist/object/pick.js +19 -0
- package/dist/object/pick.js.map +1 -0
- package/dist/process/setup-exception-listeners.js +11 -0
- package/dist/process/setup-exception-listeners.js.map +1 -0
- package/dist/promise/detached-promise.js +32 -0
- package/dist/promise/detached-promise.js.map +1 -0
- package/dist/promise/is-thenable.js +20 -0
- package/dist/promise/is-thenable.js.map +1 -0
- package/dist/promise/promise-with-resolvers.js +26 -0
- package/dist/promise/promise-with-resolvers.js.map +1 -0
- package/dist/server/dev/hot-reloader-webpack.js +1 -1
- package/dist/server/lib/app-info-log.js +1 -1
- package/dist/server/lib/start-server.js +1 -1
- package/dist/server/websocket/setup.js +1 -1
- package/dist/server/websocket/setup.js.map +1 -1
- package/dist/server/websocket/types.js +1 -1
- package/dist/server/websocket/types.js.map +1 -1
- package/dist/shared/lib/errors/canary-only-config-error.js +1 -1
- package/dist/string/encode-uri-path.js +15 -0
- package/dist/string/encode-uri-path.js.map +1 -0
- package/dist/string/escape-regexp.js +22 -0
- package/dist/string/escape-regexp.js.map +1 -0
- package/dist/string/normalize-path.js +21 -0
- package/dist/string/normalize-path.js.map +1 -0
- package/dist/string/oxford-comma-list.js +15 -0
- package/dist/string/oxford-comma-list.js.map +1 -0
- package/dist/string/pretty-bytes.js +74 -0
- package/dist/string/pretty-bytes.js.map +1 -0
- package/dist/telemetry/anonymous-meta.js +1 -1
- package/dist/telemetry/events/session-stopped.js +2 -2
- package/dist/telemetry/events/version.js +2 -2
- package/dist/typescript/diagnosticFormatter.js +240 -0
- package/dist/typescript/diagnosticFormatter.js.map +1 -0
- package/dist/typescript/getTypeScriptConfiguration.js +73 -0
- package/dist/typescript/getTypeScriptConfiguration.js.map +1 -0
- package/dist/typescript/getTypeScriptIntent.js +52 -0
- package/dist/typescript/getTypeScriptIntent.js.map +1 -0
- package/dist/typescript/missingDependencyError.js +27 -0
- package/dist/typescript/missingDependencyError.js.map +1 -0
- package/dist/typescript/runTypeCheck.js +95 -0
- package/dist/typescript/runTypeCheck.js.map +1 -0
- package/dist/typescript/writeAppTypeDeclarations.js +65 -0
- package/dist/typescript/writeAppTypeDeclarations.js.map +1 -0
- package/dist/typescript/writeConfigurationDefaults.js +403 -0
- package/dist/typescript/writeConfigurationDefaults.js.map +1 -0
- package/dist/validation/is-serializable-props.js +106 -0
- package/dist/validation/is-serializable-props.js.map +1 -0
- package/index.d.ts +2 -2
- package/package.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../typescript/diagnosticFormatter.ts"],"sourcesContent":["import { bold, cyan, red, yellow } from '../lib/picocolors'\nimport path from 'path'\n\nfunction getFormattedLinkDiagnosticMessageText(\n diagnostic: import('typescript').Diagnostic\n) {\n const message = diagnostic.messageText\n if (typeof message === 'string' && diagnostic.code === 2322) {\n const match =\n message.match(\n /Type '\"(.+)\"' is not assignable to type 'RouteImpl<.+> \\| UrlObject'\\./\n ) ||\n message.match(\n /Type '\"(.+)\"' is not assignable to type 'UrlObject \\| RouteImpl<.+>'\\./\n )\n\n if (match) {\n const [, href] = match\n return `\"${bold(\n href\n )}\" is not an existing route. If it is intentional, please type it explicitly with \\`as Route\\`.`\n } else if (\n message === \"Type 'string' is not assignable to type 'UrlObject'.\"\n ) {\n const relatedMessage = diagnostic.relatedInformation?.[0]?.messageText\n if (\n typeof relatedMessage === 'string' &&\n relatedMessage.match(\n /The expected type comes from property 'href' which is declared here on type 'IntrinsicAttributes & /\n )\n ) {\n return `Invalid \\`href\\` property of \\`Link\\`: the route does not exist. If it is intentional, please type it explicitly with \\`as Route\\`.`\n }\n }\n } else if (typeof message === 'string' && diagnostic.code === 2820) {\n const match =\n message.match(\n /Type '\"(.+)\"' is not assignable to type 'RouteImpl<.+> \\| UrlObject'\\. Did you mean '\"(.+)\"'?/\n ) ||\n message.match(\n /Type '\"(.+)\"' is not assignable to type 'UrlObject \\| RouteImpl<.+>'\\. Did you mean '\"(.+)\"'?/\n )\n\n if (match) {\n const [, href, suggestion] = match\n return `\"${bold(href)}\" is not an existing route. Did you mean \"${bold(\n suggestion\n )}\" instead? If it is intentional, please type it explicitly with \\`as Route\\`.`\n }\n }\n}\n\nfunction getFormattedLayoutAndPageDiagnosticMessageText(\n relativeSourceFilepath: string,\n diagnostic: import('typescript').Diagnostic\n) {\n const message =\n typeof diagnostic.messageText === 'string'\n ? diagnostic\n : diagnostic.messageText\n const messageText = message.messageText\n\n if (typeof messageText === 'string') {\n const type = /page\\.[^.]+$/.test(relativeSourceFilepath)\n ? 'Page'\n : /route\\.[^.]+$/.test(relativeSourceFilepath)\n ? 'Route'\n : 'Layout'\n\n // Reference of error codes:\n // https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json\n switch (message.code) {\n case 2344:\n const filepathAndType = messageText.match(/typeof import\\(\"(.+)\"\\)/)\n if (filepathAndType) {\n let main = `${type} \"${bold(\n relativeSourceFilepath\n )}\" does not match the required types of a Next.js ${type}.`\n\n function processNext(\n indent: number,\n next?: import('typescript').DiagnosticMessageChain[]\n ) {\n if (!next) return\n\n for (const item of next) {\n switch (item.code) {\n case 2200:\n const mismatchedField =\n item.messageText.match(/The types of '(.+)'/)\n if (mismatchedField) {\n main += '\\n' + ' '.repeat(indent * 2)\n main += `\"${bold(mismatchedField[1])}\" has the wrong type:`\n }\n break\n case 2322:\n const types = item.messageText.match(\n /Type '(.+)' is not assignable to type '(.+)'./\n )\n if (types) {\n main += '\\n' + ' '.repeat(indent * 2)\n\n if (\n types[2] === 'PageComponent' ||\n types[2] === 'LayoutComponent'\n ) {\n main += `The exported ${type} component isn't correctly typed.`\n } else {\n main += `Expected \"${bold(\n types[2].replace(\n '\"__invalid_negative_number__\"',\n 'number (>= 0)'\n )\n )}\", got \"${bold(types[1])}\".`\n }\n }\n break\n case 2326:\n const invalidConfig = item.messageText.match(\n /Types of property '(.+)' are incompatible\\./\n )\n main += '\\n' + ' '.repeat(indent * 2)\n main += `Invalid configuration${\n invalidConfig ? ` \"${bold(invalidConfig[1])}\"` : ''\n }:`\n break\n case 2530:\n const invalidField = item.messageText.match(\n /Property '(.+)' is incompatible with index signature/\n )\n if (invalidField) {\n main += '\\n' + ' '.repeat(indent * 2)\n main += `\"${bold(\n invalidField[1]\n )}\" is not a valid ${type} export field.`\n }\n return\n case 2739:\n const invalidProp = item.messageText.match(\n /Type '(.+)' is missing the following properties from type '(.+)'/\n )\n if (invalidProp) {\n if (\n invalidProp[1] === 'LayoutProps' ||\n invalidProp[1] === 'PageProps'\n ) {\n main += '\\n' + ' '.repeat(indent * 2)\n main += `Prop \"${invalidProp[2]}\" is incompatible with the ${type}.`\n }\n }\n break\n case 2559:\n const invalid = item.messageText.match(/Type '(.+)' has/)\n if (invalid) {\n main += '\\n' + ' '.repeat(indent * 2)\n main += `Type \"${bold(invalid[1])}\" isn't allowed.`\n }\n break\n case 2741:\n const incompatPageProp = item.messageText.match(\n /Property '(.+)' is missing in type 'PageProps'/\n )\n if (incompatPageProp) {\n main += '\\n' + ' '.repeat(indent * 2)\n main += `Prop \"${bold(\n incompatPageProp[1]\n )}\" will never be passed. Remove it from the component's props.`\n } else {\n const extraLayoutProp = item.messageText.match(\n /Property '(.+)' is missing in type 'LayoutProps' but required in type '(.+)'/\n )\n if (extraLayoutProp) {\n main += '\\n' + ' '.repeat(indent * 2)\n main += `Prop \"${bold(\n extraLayoutProp[1]\n )}\" is not valid for this Layout, remove it to fix.`\n }\n }\n break\n default:\n }\n\n processNext(indent + 1, item.next)\n }\n }\n\n if ('next' in message) processNext(1, message.next)\n return main\n }\n\n const invalidExportFnArg = messageText.match(\n /Type 'OmitWithTag<(.+), .+, \"(.+)\">' does not satisfy the constraint/\n )\n if (invalidExportFnArg) {\n const main = `${type} \"${bold(\n relativeSourceFilepath\n )}\" has an invalid \"${bold(\n invalidExportFnArg[2]\n )}\" export:\\n Type \"${bold(invalidExportFnArg[1])}\" is not valid.`\n return main\n }\n\n function processNextItems(\n indent: number,\n next?: import('typescript').DiagnosticMessageChain[]\n ) {\n if (!next) return ''\n\n let result = ''\n\n for (const item of next) {\n switch (item.code) {\n case 2322:\n const types = item.messageText.match(\n /Type '(.+)' is not assignable to type '(.+)'./\n )\n if (types) {\n result += '\\n' + ' '.repeat(indent * 2)\n result += `Expected \"${bold(types[2])}\", got \"${bold(\n types[1]\n )}\".`\n }\n break\n default:\n }\n\n result += processNextItems(indent + 1, item.next)\n }\n\n return result\n }\n\n const invalidParamFn = messageText.match(\n /Type '{ __tag__: (.+); __param_position__: \"(.*)\"; __param_type__: (.+); }' does not satisfy/\n )\n if (invalidParamFn) {\n let main = `${type} \"${bold(\n relativeSourceFilepath\n )}\" has an invalid ${invalidParamFn[1]} export:\\n Type \"${bold(\n invalidParamFn[3]\n )}\" is not a valid type for the function's ${\n invalidParamFn[2]\n } argument.`\n\n if ('next' in message) main += processNextItems(1, message.next)\n return main\n }\n\n const invalidExportFnReturn = messageText.match(\n /Type '{ __tag__: \"(.+)\"; __return_type__: (.+); }' does not satisfy/\n )\n if (invalidExportFnReturn) {\n let main = `${type} \"${bold(\n relativeSourceFilepath\n )}\" has an invalid export:\\n \"${bold(\n invalidExportFnReturn[2]\n )}\" is not a valid ${invalidExportFnReturn[1]} return type:`\n\n if ('next' in message) main += processNextItems(1, message.next)\n return main\n }\n\n break\n case 2345:\n const filepathAndInvalidExport = messageText.match(\n /'typeof import\\(\"(.+)\"\\)'.+Impossible<\"(.+)\">/\n )\n if (filepathAndInvalidExport) {\n const main = `${type} \"${bold(\n relativeSourceFilepath\n )}\" exports an invalid \"${bold(\n filepathAndInvalidExport[2]\n )}\" field. ${type} should only export a default React component and configuration options. Learn more: https://nextjs.org/docs/messages/invalid-segment-export`\n return main\n }\n break\n case 2559:\n const invalid = messageText.match(\n /Type '(.+)' has no properties in common with type '(.+)'/\n )\n if (invalid) {\n const main = `${type} \"${bold(\n relativeSourceFilepath\n )}\" contains an invalid type \"${bold(invalid[1])}\" as ${invalid[2]}.`\n return main\n }\n break\n default:\n }\n }\n}\n\nfunction getAppEntrySourceFilePath(\n baseDir: string,\n diagnostic: import('typescript').Diagnostic\n) {\n const sourceFilepath =\n diagnostic.file?.text.trim().match(/^\\/\\/ File: (.+)\\n/)?.[1] || ''\n\n return path.relative(baseDir, sourceFilepath)\n}\n\nexport function getFormattedDiagnostic(\n ts: typeof import('typescript'),\n baseDir: string,\n distDir: string,\n diagnostic: import('typescript').Diagnostic,\n isAppDirEnabled?: boolean\n): string {\n // If the error comes from .next/types/, we handle it specially.\n const isLayoutOrPageError =\n isAppDirEnabled &&\n diagnostic.file?.fileName.startsWith(path.join(baseDir, distDir, 'types'))\n\n let message = ''\n\n const appPath = isLayoutOrPageError\n ? getAppEntrySourceFilePath(baseDir, diagnostic)\n : null\n const linkReason = getFormattedLinkDiagnosticMessageText(diagnostic)\n const appReason =\n !linkReason && isLayoutOrPageError && appPath\n ? getFormattedLayoutAndPageDiagnosticMessageText(appPath, diagnostic)\n : null\n\n const reason =\n linkReason ||\n appReason ||\n ts.flattenDiagnosticMessageText(diagnostic.messageText, '\\n')\n const category = diagnostic.category\n switch (category) {\n // Warning\n case ts.DiagnosticCategory.Warning: {\n message += yellow(bold('Type warning')) + ': '\n break\n }\n // Error\n case ts.DiagnosticCategory.Error: {\n message += red(bold('Type error')) + ': '\n break\n }\n // 2 = Suggestion, 3 = Message\n case ts.DiagnosticCategory.Suggestion:\n case ts.DiagnosticCategory.Message:\n message += cyan(bold(category === 2 ? 'Suggestion' : 'Info')) + ': '\n break\n default: {\n category satisfies never\n }\n }\n\n message += reason + '\\n'\n\n if (!isLayoutOrPageError && diagnostic.file) {\n const { codeFrameColumns } =\n require('next/dist/compiled/babel/code-frame') as typeof import('next/dist/compiled/babel/code-frame')\n const pos = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!)\n const line = pos.line + 1\n const character = pos.character + 1\n\n let fileName = path.posix.normalize(\n path.relative(baseDir, diagnostic.file.fileName).replace(/\\\\/g, '/')\n )\n if (!fileName.startsWith('.')) {\n fileName = './' + fileName\n }\n\n message =\n cyan(fileName) +\n ':' +\n yellow(line.toString()) +\n ':' +\n yellow(character.toString()) +\n '\\n' +\n message\n\n message +=\n '\\n' +\n codeFrameColumns(\n diagnostic.file.getFullText(diagnostic.file.getSourceFile()),\n {\n start: { line: line, column: character },\n },\n { forceColor: true }\n )\n } else if (isLayoutOrPageError && appPath) {\n message = cyan(appPath) + '\\n' + message\n }\n\n return message\n}\n"],"names":["getFormattedDiagnostic","getFormattedLinkDiagnosticMessageText","diagnostic","message","messageText","code","match","href","bold","relatedMessage","relatedInformation","suggestion","getFormattedLayoutAndPageDiagnosticMessageText","relativeSourceFilepath","type","test","filepathAndType","main","processNext","indent","next","item","mismatchedField","repeat","types","replace","invalidConfig","invalidField","invalidProp","invalid","incompatPageProp","extraLayoutProp","invalidExportFnArg","processNextItems","result","invalidParamFn","invalidExportFnReturn","filepathAndInvalidExport","getAppEntrySourceFilePath","baseDir","sourceFilepath","file","text","trim","path","relative","ts","distDir","isAppDirEnabled","isLayoutOrPageError","fileName","startsWith","join","appPath","linkReason","appReason","reason","flattenDiagnosticMessageText","category","DiagnosticCategory","Warning","yellow","Error","red","Suggestion","Message","cyan","codeFrameColumns","require","pos","getLineAndCharacterOfPosition","start","line","character","posix","normalize","toString","getFullText","getSourceFile","column","forceColor"],"mappings":";;;;+BA8SgBA;;;eAAAA;;;4BA9SwB;6DACvB;;;;;;AAEjB,SAASC,sCACPC,UAA2C;IAE3C,MAAMC,UAAUD,WAAWE,WAAW;IACtC,IAAI,OAAOD,YAAY,YAAYD,WAAWG,IAAI,KAAK,MAAM;QAC3D,MAAMC,QACJH,QAAQG,KAAK,CACX,6EAEFH,QAAQG,KAAK,CACX;QAGJ,IAAIA,OAAO;YACT,MAAM,GAAGC,KAAK,GAAGD;YACjB,OAAO,CAAC,CAAC,EAAEE,IAAAA,gBAAI,EACbD,MACA,8FAA8F,CAAC;Q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,KAAK;QAC1E,MAAMC,OAAOH,IAAIG,IAAI,GAAG;QACxB,MAAMC,YAAYJ,IAAII,SAAS,GAAG;QAElC,IAAIvB,WAAWN,aAAI,CAAC8B,KAAK,CAACC,SAAS,CACjC/B,aAAI,CAACC,QAAQ,CAACN,SAASrC,WAAWuC,IAAI,CAACS,QAAQ,EAAEzB,OAAO,CAAC,OAAO;QAElE,IAAI,CAACyB,SAASC,UAAU,CAAC,MAAM;YAC7BD,WAAW,OAAOA;QACpB;QAEA/C,UACE+D,IAAAA,gBAAI,EAAChB,YACL,MACAW,IAAAA,kBAAM,EAACW,KAAKI,QAAQ,MACpB,MACAf,IAAAA,kBAAM,EAACY,UAAUG,QAAQ,MACzB,OACAzE;QAEFA,WACE,OACAgE,iBACEjE,WAAWuC,IAAI,CAACoC,WAAW,CAAC3E,WAAWuC,IAAI,CAACqC,aAAa,KACzD;YACEP,OAAO;gBAAEC,MAAMA;gBAAMO,QAAQN;YAAU;QACzC,GACA;YAAEO,YAAY;QAAK;IAEzB,OAAO,IAAI/B,uBAAuBI,SAAS;QACzClD,UAAU+D,IAAAA,gBAAI,EAACb,WAAW,OAAOlD;IACnC;IAEA,OAAOA;AACT","ignoreList":[0]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getTypeScriptConfiguration", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getTypeScriptConfiguration;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _picocolors = require("../lib/picocolors");
|
|
12
|
+
const _os = /*#__PURE__*/ _interop_require_default(require("os"));
|
|
13
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
14
|
+
const _fatalerror = require("../errors/fatal-error");
|
|
15
|
+
const _iserror = /*#__PURE__*/ _interop_require_default(require("../errors/is-error"));
|
|
16
|
+
function _interop_require_default(obj) {
|
|
17
|
+
return obj && obj.__esModule ? obj : {
|
|
18
|
+
default: obj
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async function getTypeScriptConfiguration(typescript, tsConfigPath, metaOnly) {
|
|
22
|
+
try {
|
|
23
|
+
var _result_errors;
|
|
24
|
+
const formatDiagnosticsHost = {
|
|
25
|
+
getCanonicalFileName: (fileName)=>fileName,
|
|
26
|
+
getCurrentDirectory: typescript.sys.getCurrentDirectory,
|
|
27
|
+
getNewLine: ()=>_os.default.EOL
|
|
28
|
+
};
|
|
29
|
+
const { config, error } = typescript.readConfigFile(tsConfigPath, typescript.sys.readFile);
|
|
30
|
+
if (error) {
|
|
31
|
+
throw Object.defineProperty(new _fatalerror.FatalError(typescript.formatDiagnostic(error, formatDiagnosticsHost)), "__NEXT_ERROR_CODE", {
|
|
32
|
+
value: "E394",
|
|
33
|
+
enumerable: false,
|
|
34
|
+
configurable: true
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
let configToParse = config;
|
|
38
|
+
const result = typescript.parseJsonConfigFileContent(configToParse, // When only interested in meta info,
|
|
39
|
+
// avoid enumerating all files (for performance reasons)
|
|
40
|
+
metaOnly ? {
|
|
41
|
+
...typescript.sys,
|
|
42
|
+
readDirectory (_path, extensions, _excludes, _includes, _depth) {
|
|
43
|
+
return [
|
|
44
|
+
extensions ? `file${extensions[0]}` : `file.ts`
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
} : typescript.sys, _path.default.dirname(tsConfigPath));
|
|
48
|
+
if (result.errors) {
|
|
49
|
+
result.errors = result.errors.filter(({ code })=>// No inputs were found in config file
|
|
50
|
+
code !== 18003);
|
|
51
|
+
}
|
|
52
|
+
if ((_result_errors = result.errors) == null ? void 0 : _result_errors.length) {
|
|
53
|
+
throw Object.defineProperty(new _fatalerror.FatalError(typescript.formatDiagnostic(result.errors[0], formatDiagnosticsHost)), "__NEXT_ERROR_CODE", {
|
|
54
|
+
value: "E394",
|
|
55
|
+
enumerable: false,
|
|
56
|
+
configurable: true
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
} catch (err) {
|
|
61
|
+
if ((0, _iserror.default)(err) && err.name === 'SyntaxError') {
|
|
62
|
+
const reason = '\n' + (err.message ?? '');
|
|
63
|
+
throw Object.defineProperty(new _fatalerror.FatalError((0, _picocolors.bold)('Could not parse' + (0, _picocolors.cyan)('tsconfig.json') + '.' + ' Please make sure it contains syntactically correct JSON.') + reason), "__NEXT_ERROR_CODE", {
|
|
64
|
+
value: "E339",
|
|
65
|
+
enumerable: false,
|
|
66
|
+
configurable: true
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=getTypeScriptConfiguration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../typescript/getTypeScriptConfiguration.ts"],"sourcesContent":["import { bold, cyan } from '../lib/picocolors'\nimport os from 'os'\nimport path from 'path'\n\nimport { FatalError } from '../errors/fatal-error'\nimport isError from '../errors/is-error'\n\nexport async function getTypeScriptConfiguration(\n typescript: typeof import('typescript'),\n tsConfigPath: string,\n metaOnly?: boolean\n): Promise<import('typescript').ParsedCommandLine> {\n try {\n const formatDiagnosticsHost: import('typescript').FormatDiagnosticsHost = {\n getCanonicalFileName: (fileName: string) => fileName,\n getCurrentDirectory: typescript.sys.getCurrentDirectory,\n getNewLine: () => os.EOL,\n }\n\n const { config, error } = typescript.readConfigFile(\n tsConfigPath,\n typescript.sys.readFile\n )\n if (error) {\n throw new FatalError(\n typescript.formatDiagnostic(error, formatDiagnosticsHost)\n )\n }\n\n let configToParse: any = config\n\n const result = typescript.parseJsonConfigFileContent(\n configToParse,\n // When only interested in meta info,\n // avoid enumerating all files (for performance reasons)\n metaOnly\n ? {\n ...typescript.sys,\n readDirectory(_path, extensions, _excludes, _includes, _depth) {\n return [extensions ? `file${extensions[0]}` : `file.ts`]\n },\n }\n : typescript.sys,\n path.dirname(tsConfigPath)\n )\n\n if (result.errors) {\n result.errors = result.errors.filter(\n ({ code }) =>\n // No inputs were found in config file\n code !== 18003\n )\n }\n\n if (result.errors?.length) {\n throw new FatalError(\n typescript.formatDiagnostic(result.errors[0], formatDiagnosticsHost)\n )\n }\n\n return result\n } catch (err) {\n if (isError(err) && err.name === 'SyntaxError') {\n const reason = '\\n' + (err.message ?? '')\n throw new FatalError(\n bold(\n 'Could not parse' +\n cyan('tsconfig.json') +\n '.' +\n ' Please make sure it contains syntactically correct JSON.'\n ) + reason\n )\n }\n throw err\n }\n}\n"],"names":["getTypeScriptConfiguration","typescript","tsConfigPath","metaOnly","result","formatDiagnosticsHost","getCanonicalFileName","fileName","getCurrentDirectory","sys","getNewLine","os","EOL","config","error","readConfigFile","readFile","FatalError","formatDiagnostic","configToParse","parseJsonConfigFileContent","readDirectory","_path","extensions","_excludes","_includes","_depth","path","dirname","errors","filter","code","length","err","isError","name","reason","message","bold","cyan"],"mappings":";;;;+BAOsBA;;;eAAAA;;;4BAPK;2DACZ;6DACE;4BAEU;gEACP;;;;;;AAEb,eAAeA,2BACpBC,UAAuC,EACvCC,YAAoB,EACpBC,QAAkB;IAElB,IAAI;YA0CEC;QAzCJ,MAAMC,wBAAoE;YACxEC,sBAAsB,CAACC,WAAqBA;YAC5CC,qBAAqBP,WAAWQ,GAAG,CAACD,mBAAmB;YACvDE,YAAY,IAAMC,WAAE,CAACC,GAAG;QAC1B;QAEA,MAAM,EAAEC,MAAM,EAAEC,KAAK,EAAE,GAAGb,WAAWc,cAAc,CACjDb,cACAD,WAAWQ,GAAG,CAACO,QAAQ;QAEzB,IAAIF,OAAO;YACT,MAAM,qBAEL,CAFK,IAAIG,sBAAU,CAClBhB,WAAWiB,gBAAgB,CAACJ,OAAOT,yBAD/B,qBAAA;uBAAA;4BAAA;8BAAA;YAEN;QACF;QAEA,IAAIc,gBAAqBN;QAEzB,MAAMT,SAASH,WAAWmB,0BAA0B,CAClDD,eACA,qCAAqC;QACrC,wDAAwD;QACxDhB,WACI;YACE,GAAGF,WAAWQ,GAAG;YACjBY,eAAcC,KAAK,EAAEC,UAAU,EAAEC,SAAS,EAAEC,SAAS,EAAEC,MAAM;gBAC3D,OAAO;oBAACH,aAAa,CAAC,IAAI,EAAEA,UAAU,CAAC,EAAE,EAAE,GAAG,CAAC,OAAO,CAAC;iBAAC;YAC1D;QACF,IACAtB,WAAWQ,GAAG,EAClBkB,aAAI,CAACC,OAAO,CAAC1B;QAGf,IAAIE,OAAOyB,MAAM,EAAE;YACjBzB,OAAOyB,MAAM,GAAGzB,OAAOyB,MAAM,CAACC,MAAM,CAClC,CAAC,EAAEC,IAAI,EAAE,GACP,sCAAsC;gBACtCA,SAAS;QAEf;QAEA,KAAI3B,iBAAAA,OAAOyB,MAAM,qBAAbzB,eAAe4B,MAAM,EAAE;YACzB,MAAM,qBAEL,CAFK,IAAIf,sBAAU,CAClBhB,WAAWiB,gBAAgB,CAACd,OAAOyB,MAAM,CAAC,EAAE,EAAExB,yBAD1C,qBAAA;uBAAA;4BAAA;8BAAA;YAEN;QACF;QAEA,OAAOD;IACT,EAAE,OAAO6B,KAAK;QACZ,IAAIC,IAAAA,gBAAO,EAACD,QAAQA,IAAIE,IAAI,KAAK,eAAe;YAC9C,MAAMC,SAAS,OAAQH,CAAAA,IAAII,OAAO,IAAI,EAAC;YACvC,MAAM,qBAOL,CAPK,IAAIpB,sBAAU,CAClBqB,IAAAA,gBAAI,EACF,oBACEC,IAAAA,gBAAI,EAAC,mBACL,MACA,+DACAH,SANA,qBAAA;uBAAA;4BAAA;8BAAA;YAON;QACF;QACA,MAAMH;IACR;AACF","ignoreList":[0]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getTypeScriptIntent", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getTypeScriptIntent;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _fs = require("fs");
|
|
12
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
+
const _recursivereaddir = require("../lib/recursive-readdir");
|
|
14
|
+
function _interop_require_default(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async function getTypeScriptIntent(baseDir, intentDirs, tsconfigPath) {
|
|
20
|
+
const resolvedTsConfigPath = _path.default.join(baseDir, tsconfigPath);
|
|
21
|
+
// The integration turns on if we find a `tsconfig.json` in the user's
|
|
22
|
+
// project.
|
|
23
|
+
const hasTypeScriptConfiguration = (0, _fs.existsSync)(resolvedTsConfigPath);
|
|
24
|
+
if (hasTypeScriptConfiguration) {
|
|
25
|
+
const content = (0, _fs.readFileSync)(resolvedTsConfigPath, {
|
|
26
|
+
encoding: 'utf8'
|
|
27
|
+
}).trim();
|
|
28
|
+
return {
|
|
29
|
+
firstTimeSetup: content === '' || content === '{}'
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// Next.js also offers a friendly setup mode that bootstraps a TypeScript
|
|
33
|
+
// project for the user when we detect TypeScript files. So, we need to check
|
|
34
|
+
// the `pages/` directory for a TypeScript file.
|
|
35
|
+
// Checking all directories is too slow, so this is a happy medium.
|
|
36
|
+
const tsFilesRegex = /.*\.(ts|tsx)$/;
|
|
37
|
+
const excludedRegex = /(node_modules|.*\.d\.ts$)/;
|
|
38
|
+
for (const dir of intentDirs){
|
|
39
|
+
const typescriptFiles = await (0, _recursivereaddir.recursiveReadDir)(dir, {
|
|
40
|
+
pathnameFilter: (name)=>tsFilesRegex.test(name),
|
|
41
|
+
ignoreFilter: (name)=>excludedRegex.test(name)
|
|
42
|
+
});
|
|
43
|
+
if (typescriptFiles.length) {
|
|
44
|
+
return {
|
|
45
|
+
firstTimeSetup: true
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=getTypeScriptIntent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../typescript/getTypeScriptIntent.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'fs'\nimport path from 'path'\nimport { recursiveReadDir } from '../lib/recursive-readdir'\n\nexport type TypeScriptIntent = { firstTimeSetup: boolean }\n\nexport async function getTypeScriptIntent(\n baseDir: string,\n intentDirs: string[],\n tsconfigPath: string\n): Promise<TypeScriptIntent | false> {\n const resolvedTsConfigPath = path.join(baseDir, tsconfigPath)\n\n // The integration turns on if we find a `tsconfig.json` in the user's\n // project.\n const hasTypeScriptConfiguration = existsSync(resolvedTsConfigPath)\n if (hasTypeScriptConfiguration) {\n const content = readFileSync(resolvedTsConfigPath, {\n encoding: 'utf8',\n }).trim()\n\n return { firstTimeSetup: content === '' || content === '{}' }\n }\n\n // Next.js also offers a friendly setup mode that bootstraps a TypeScript\n // project for the user when we detect TypeScript files. So, we need to check\n // the `pages/` directory for a TypeScript file.\n // Checking all directories is too slow, so this is a happy medium.\n const tsFilesRegex = /.*\\.(ts|tsx)$/\n const excludedRegex = /(node_modules|.*\\.d\\.ts$)/\n for (const dir of intentDirs) {\n const typescriptFiles = await recursiveReadDir(dir, {\n pathnameFilter: (name) => tsFilesRegex.test(name),\n ignoreFilter: (name) => excludedRegex.test(name),\n })\n if (typescriptFiles.length) {\n return { firstTimeSetup: true }\n }\n }\n\n return false\n}\n"],"names":["getTypeScriptIntent","baseDir","intentDirs","tsconfigPath","resolvedTsConfigPath","path","join","hasTypeScriptConfiguration","existsSync","content","readFileSync","encoding","trim","firstTimeSetup","tsFilesRegex","excludedRegex","dir","typescriptFiles","recursiveReadDir","pathnameFilter","name","test","ignoreFilter","length"],"mappings":";;;;+BAMsBA;;;eAAAA;;;oBANmB;6DACxB;kCACgB;;;;;;AAI1B,eAAeA,oBACpBC,OAAe,EACfC,UAAoB,EACpBC,YAAoB;IAEpB,MAAMC,uBAAuBC,aAAI,CAACC,IAAI,CAACL,SAASE;IAEhD,sEAAsE;IACtE,WAAW;IACX,MAAMI,6BAA6BC,IAAAA,cAAU,EAACJ;IAC9C,IAAIG,4BAA4B;QAC9B,MAAME,UAAUC,IAAAA,gBAAY,EAACN,sBAAsB;YACjDO,UAAU;QACZ,GAAGC,IAAI;QAEP,OAAO;YAAEC,gBAAgBJ,YAAY,MAAMA,YAAY;QAAK;IAC9D;IAEA,yEAAyE;IACzE,6EAA6E;IAC7E,gDAAgD;IAChD,mEAAmE;IACnE,MAAMK,eAAe;IACrB,MAAMC,gBAAgB;IACtB,KAAK,MAAMC,OAAOd,WAAY;QAC5B,MAAMe,kBAAkB,MAAMC,IAAAA,kCAAgB,EAACF,KAAK;YAClDG,gBAAgB,CAACC,OAASN,aAAaO,IAAI,CAACD;YAC5CE,cAAc,CAACF,OAASL,cAAcM,IAAI,CAACD;QAC7C;QACA,IAAIH,gBAAgBM,MAAM,EAAE;YAC1B,OAAO;gBAAEV,gBAAgB;YAAK;QAChC;IACF;IAEA,OAAO;AACT","ignoreList":[0]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "missingDepsError", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return missingDepsError;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _picocolors = require("../lib/picocolors");
|
|
12
|
+
const _oxfordcommalist = require("../lib/oxford-comma-list");
|
|
13
|
+
const _fatalerror = require("../errors/fatal-error");
|
|
14
|
+
const _getpkgmanager = require("../lib/helpers/get-pkg-manager");
|
|
15
|
+
function missingDepsError(dir, missingPackages) {
|
|
16
|
+
const packagesHuman = (0, _oxfordcommalist.getOxfordCommaList)(missingPackages.map((p)=>p.pkg));
|
|
17
|
+
const packagesCli = missingPackages.map((p)=>p.pkg).join(' ');
|
|
18
|
+
const packageManager = (0, _getpkgmanager.getPkgManager)(dir);
|
|
19
|
+
const removalMsg = '\n\n' + (0, _picocolors.bold)('If you are not trying to use TypeScript, please remove the ' + (0, _picocolors.cyan)('tsconfig.json') + ' file from your package root (and any TypeScript files in your app and pages directories).');
|
|
20
|
+
throw Object.defineProperty(new _fatalerror.FatalError((0, _picocolors.bold)((0, _picocolors.red)(`It looks like you're trying to use TypeScript but do not have the required package(s) installed.`)) + '\n\n' + (0, _picocolors.bold)(`Please install ${(0, _picocolors.bold)(packagesHuman)} by running:`) + '\n\n' + `\t${(0, _picocolors.bold)((0, _picocolors.cyan)((packageManager === 'yarn' ? 'yarn add --dev' : packageManager === 'pnpm' ? 'pnpm install --save-dev' : 'npm install --save-dev') + ' ' + packagesCli))}` + removalMsg + '\n'), "__NEXT_ERROR_CODE", {
|
|
21
|
+
value: "E532",
|
|
22
|
+
enumerable: false,
|
|
23
|
+
configurable: true
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=missingDependencyError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../typescript/missingDependencyError.ts"],"sourcesContent":["import { bold, cyan, red } from '../lib/picocolors'\n\nimport { getOxfordCommaList } from '../lib/oxford-comma-list'\nimport type { MissingDependency } from '../lib/has-necessary-dependencies'\nimport { FatalError } from '../errors/fatal-error'\nimport { getPkgManager } from '../lib/helpers/get-pkg-manager'\n\nexport function missingDepsError(\n dir: string,\n missingPackages: MissingDependency[]\n): never {\n const packagesHuman = getOxfordCommaList(missingPackages.map((p) => p.pkg))\n const packagesCli = missingPackages.map((p) => p.pkg).join(' ')\n const packageManager = getPkgManager(dir)\n\n const removalMsg =\n '\\n\\n' +\n bold(\n 'If you are not trying to use TypeScript, please remove the ' +\n cyan('tsconfig.json') +\n ' file from your package root (and any TypeScript files in your app and pages directories).'\n )\n\n throw new FatalError(\n bold(\n red(\n `It looks like you're trying to use TypeScript but do not have the required package(s) installed.`\n )\n ) +\n '\\n\\n' +\n bold(`Please install ${bold(packagesHuman)} by running:`) +\n '\\n\\n' +\n `\\t${bold(\n cyan(\n (packageManager === 'yarn'\n ? 'yarn add --dev'\n : packageManager === 'pnpm'\n ? 'pnpm install --save-dev'\n : 'npm install --save-dev') +\n ' ' +\n packagesCli\n )\n )}` +\n removalMsg +\n '\\n'\n )\n}\n"],"names":["missingDepsError","dir","missingPackages","packagesHuman","getOxfordCommaList","map","p","pkg","packagesCli","join","packageManager","getPkgManager","removalMsg","bold","cyan","FatalError","red"],"mappings":";;;;+BAOgBA;;;eAAAA;;;4BAPgB;iCAEG;4BAER;+BACG;AAEvB,SAASA,iBACdC,GAAW,EACXC,eAAoC;IAEpC,MAAMC,gBAAgBC,IAAAA,mCAAkB,EAACF,gBAAgBG,GAAG,CAAC,CAACC,IAAMA,EAAEC,GAAG;IACzE,MAAMC,cAAcN,gBAAgBG,GAAG,CAAC,CAACC,IAAMA,EAAEC,GAAG,EAAEE,IAAI,CAAC;IAC3D,MAAMC,iBAAiBC,IAAAA,4BAAa,EAACV;IAErC,MAAMW,aACJ,SACAC,IAAAA,gBAAI,EACF,gEACEC,IAAAA,gBAAI,EAAC,mBACL;IAGN,MAAM,qBAsBL,CAtBK,IAAIC,sBAAU,CAClBF,IAAAA,gBAAI,EACFG,IAAAA,eAAG,EACD,CAAC,gGAAgG,CAAC,KAGpG,SACAH,IAAAA,gBAAI,EAAC,CAAC,eAAe,EAAEA,IAAAA,gBAAI,EAACV,eAAe,YAAY,CAAC,IACxD,SACA,CAAC,EAAE,EAAEU,IAAAA,gBAAI,EACPC,IAAAA,gBAAI,EACF,AAACJ,CAAAA,mBAAmB,SAChB,mBACAA,mBAAmB,SACjB,4BACA,wBAAuB,IAC3B,MACAF,eAEH,GACHI,aACA,OArBE,qBAAA;eAAA;oBAAA;sBAAA;IAsBN;AACF","ignoreList":[0]}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "runTypeCheck", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return runTypeCheck;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
12
|
+
const _diagnosticFormatter = require("./diagnosticFormatter");
|
|
13
|
+
const _getTypeScriptConfiguration = require("./getTypeScriptConfiguration");
|
|
14
|
+
const _writeConfigurationDefaults = require("./writeConfigurationDefaults");
|
|
15
|
+
const _compileerror = require("../errors/compile-error");
|
|
16
|
+
const _log = require("../build/output/log");
|
|
17
|
+
function _interop_require_default(obj) {
|
|
18
|
+
return obj && obj.__esModule ? obj : {
|
|
19
|
+
default: obj
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async function runTypeCheck(typescript, baseDir, distDir, tsConfigPath, cacheDir, isAppDirEnabled) {
|
|
23
|
+
const effectiveConfiguration = await (0, _getTypeScriptConfiguration.getTypeScriptConfiguration)(typescript, tsConfigPath);
|
|
24
|
+
if (effectiveConfiguration.fileNames.length < 1) {
|
|
25
|
+
return {
|
|
26
|
+
hasWarnings: false,
|
|
27
|
+
inputFilesCount: 0,
|
|
28
|
+
totalFilesCount: 0,
|
|
29
|
+
incremental: false
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const requiredConfig = (0, _writeConfigurationDefaults.getRequiredConfiguration)(typescript);
|
|
33
|
+
const options = {
|
|
34
|
+
...requiredConfig,
|
|
35
|
+
...effectiveConfiguration.options,
|
|
36
|
+
declarationMap: false,
|
|
37
|
+
emitDeclarationOnly: false,
|
|
38
|
+
noEmit: true
|
|
39
|
+
};
|
|
40
|
+
let program;
|
|
41
|
+
let incremental = false;
|
|
42
|
+
if ((options.incremental || options.composite) && cacheDir) {
|
|
43
|
+
if (options.composite) {
|
|
44
|
+
(0, _log.warn)('TypeScript project references are not fully supported. Attempting to build in incremental mode.');
|
|
45
|
+
}
|
|
46
|
+
incremental = true;
|
|
47
|
+
program = typescript.createIncrementalProgram({
|
|
48
|
+
rootNames: effectiveConfiguration.fileNames,
|
|
49
|
+
options: {
|
|
50
|
+
...options,
|
|
51
|
+
composite: false,
|
|
52
|
+
incremental: true,
|
|
53
|
+
tsBuildInfoFile: _path.default.join(cacheDir, '.tsbuildinfo')
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
program = typescript.createProgram(effectiveConfiguration.fileNames, options);
|
|
58
|
+
}
|
|
59
|
+
const result = program.emit();
|
|
60
|
+
const ignoreRegex = [
|
|
61
|
+
// matches **/__(tests|mocks)__/**
|
|
62
|
+
/[\\/]__(?:tests|mocks)__[\\/]/,
|
|
63
|
+
// matches **/*.(spec|test).*
|
|
64
|
+
/(?<=[\\/.])(?:spec|test)\.[^\\/]+$/
|
|
65
|
+
];
|
|
66
|
+
const regexIgnoredFile = new RegExp(ignoreRegex.map((r)=>r.source).join('|'));
|
|
67
|
+
const allDiagnostics = typescript.getPreEmitDiagnostics(program).concat(result.diagnostics).filter((d)=>!(d.file && regexIgnoredFile.test(d.file.fileName)));
|
|
68
|
+
const firstError = allDiagnostics.find((d)=>d.category === typescript.DiagnosticCategory.Error && Boolean(d.file)) ?? allDiagnostics.find((d)=>d.category === typescript.DiagnosticCategory.Error);
|
|
69
|
+
// In test mode, we want to check all diagnostics, not just the first one.
|
|
70
|
+
if (process.env.__NEXT_TEST_MODE) {
|
|
71
|
+
if (firstError) {
|
|
72
|
+
const allErrors = allDiagnostics.filter((d)=>d.category === typescript.DiagnosticCategory.Error).map((d)=>'[Test Mode] ' + (0, _diagnosticFormatter.getFormattedDiagnostic)(typescript, baseDir, distDir, d, isAppDirEnabled));
|
|
73
|
+
console.error('\n\n===== TS errors =====\n\n' + allErrors.join('\n\n') + '\n\n===== TS errors =====\n\n');
|
|
74
|
+
// Make sure all stdout is flushed before we exit.
|
|
75
|
+
await new Promise((resolve)=>setTimeout(resolve, 100));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (firstError) {
|
|
79
|
+
throw Object.defineProperty(new _compileerror.CompileError((0, _diagnosticFormatter.getFormattedDiagnostic)(typescript, baseDir, distDir, firstError, isAppDirEnabled)), "__NEXT_ERROR_CODE", {
|
|
80
|
+
value: "E394",
|
|
81
|
+
enumerable: false,
|
|
82
|
+
configurable: true
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const warnings = allDiagnostics.filter((d)=>d.category === typescript.DiagnosticCategory.Warning).map((d)=>(0, _diagnosticFormatter.getFormattedDiagnostic)(typescript, baseDir, distDir, d, isAppDirEnabled));
|
|
86
|
+
return {
|
|
87
|
+
hasWarnings: true,
|
|
88
|
+
warnings,
|
|
89
|
+
inputFilesCount: effectiveConfiguration.fileNames.length,
|
|
90
|
+
totalFilesCount: program.getSourceFiles().length,
|
|
91
|
+
incremental
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=runTypeCheck.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../typescript/runTypeCheck.ts"],"sourcesContent":["import path from 'path'\nimport { getFormattedDiagnostic } from './diagnosticFormatter'\nimport { getTypeScriptConfiguration } from './getTypeScriptConfiguration'\nimport { getRequiredConfiguration } from './writeConfigurationDefaults'\n\nimport { CompileError } from '../errors/compile-error'\nimport { warn } from '../build/output/log'\n\nexport interface TypeCheckResult {\n hasWarnings: boolean\n warnings?: string[]\n inputFilesCount: number\n totalFilesCount: number\n incremental: boolean\n}\n\nexport async function runTypeCheck(\n typescript: typeof import('typescript'),\n baseDir: string,\n distDir: string,\n tsConfigPath: string,\n cacheDir?: string,\n isAppDirEnabled?: boolean\n): Promise<TypeCheckResult> {\n const effectiveConfiguration = await getTypeScriptConfiguration(\n typescript,\n tsConfigPath\n )\n\n if (effectiveConfiguration.fileNames.length < 1) {\n return {\n hasWarnings: false,\n inputFilesCount: 0,\n totalFilesCount: 0,\n incremental: false,\n }\n }\n const requiredConfig = getRequiredConfiguration(typescript)\n\n const options = {\n ...requiredConfig,\n ...effectiveConfiguration.options,\n declarationMap: false,\n emitDeclarationOnly: false,\n noEmit: true,\n }\n\n let program:\n | import('typescript').Program\n | import('typescript').BuilderProgram\n let incremental = false\n if ((options.incremental || options.composite) && cacheDir) {\n if (options.composite) {\n warn(\n 'TypeScript project references are not fully supported. Attempting to build in incremental mode.'\n )\n }\n incremental = true\n program = typescript.createIncrementalProgram({\n rootNames: effectiveConfiguration.fileNames,\n options: {\n ...options,\n composite: false,\n incremental: true,\n tsBuildInfoFile: path.join(cacheDir, '.tsbuildinfo'),\n },\n })\n } else {\n program = typescript.createProgram(\n effectiveConfiguration.fileNames,\n options\n )\n }\n\n const result = program.emit()\n\n const ignoreRegex = [\n // matches **/__(tests|mocks)__/**\n /[\\\\/]__(?:tests|mocks)__[\\\\/]/,\n // matches **/*.(spec|test).*\n /(?<=[\\\\/.])(?:spec|test)\\.[^\\\\/]+$/,\n ]\n const regexIgnoredFile = new RegExp(\n ignoreRegex.map((r) => r.source).join('|')\n )\n\n const allDiagnostics = typescript\n .getPreEmitDiagnostics(program as import('typescript').Program)\n .concat(result.diagnostics)\n .filter((d) => !(d.file && regexIgnoredFile.test(d.file.fileName)))\n\n const firstError =\n allDiagnostics.find(\n (d) =>\n d.category === typescript.DiagnosticCategory.Error && Boolean(d.file)\n ) ??\n allDiagnostics.find(\n (d) => d.category === typescript.DiagnosticCategory.Error\n )\n\n // In test mode, we want to check all diagnostics, not just the first one.\n if (process.env.__NEXT_TEST_MODE) {\n if (firstError) {\n const allErrors = allDiagnostics\n .filter((d) => d.category === typescript.DiagnosticCategory.Error)\n .map(\n (d) =>\n '[Test Mode] ' +\n getFormattedDiagnostic(\n typescript,\n baseDir,\n distDir,\n d,\n isAppDirEnabled\n )\n )\n\n console.error(\n '\\n\\n===== TS errors =====\\n\\n' +\n allErrors.join('\\n\\n') +\n '\\n\\n===== TS errors =====\\n\\n'\n )\n\n // Make sure all stdout is flushed before we exit.\n await new Promise((resolve) => setTimeout(resolve, 100))\n }\n }\n\n if (firstError) {\n throw new CompileError(\n getFormattedDiagnostic(\n typescript,\n baseDir,\n distDir,\n firstError,\n isAppDirEnabled\n )\n )\n }\n\n const warnings = allDiagnostics\n .filter((d) => d.category === typescript.DiagnosticCategory.Warning)\n .map((d) =>\n getFormattedDiagnostic(typescript, baseDir, distDir, d, isAppDirEnabled)\n )\n\n return {\n hasWarnings: true,\n warnings,\n inputFilesCount: effectiveConfiguration.fileNames.length,\n totalFilesCount: program.getSourceFiles().length,\n incremental,\n }\n}\n"],"names":["runTypeCheck","typescript","baseDir","distDir","tsConfigPath","cacheDir","isAppDirEnabled","effectiveConfiguration","getTypeScriptConfiguration","fileNames","length","hasWarnings","inputFilesCount","totalFilesCount","incremental","requiredConfig","getRequiredConfiguration","options","declarationMap","emitDeclarationOnly","noEmit","program","composite","warn","createIncrementalProgram","rootNames","tsBuildInfoFile","path","join","createProgram","result","emit","ignoreRegex","regexIgnoredFile","RegExp","map","r","source","allDiagnostics","getPreEmitDiagnostics","concat","diagnostics","filter","d","file","test","fileName","firstError","find","category","DiagnosticCategory","Error","Boolean","process","env","__NEXT_TEST_MODE","allErrors","getFormattedDiagnostic","console","error","Promise","resolve","setTimeout","CompileError","warnings","Warning","getSourceFiles"],"mappings":";;;;+BAgBsBA;;;eAAAA;;;6DAhBL;qCACsB;4CACI;4CACF;8BAEZ;qBACR;;;;;;AAUd,eAAeA,aACpBC,UAAuC,EACvCC,OAAe,EACfC,OAAe,EACfC,YAAoB,EACpBC,QAAiB,EACjBC,eAAyB;IAEzB,MAAMC,yBAAyB,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,CAACL,IACCA,EAAEM,QAAQ,KAAKhD,WAAWiD,kBAAkB,CAACC,KAAK,IAAIC,QAAQT,EAAEC,IAAI,MAExEN,eAAeU,IAAI,CACjB,CAACL,IAAMA,EAAEM,QAAQ,KAAKhD,WAAWiD,kBAAkB,CAACC,KAAK;IAG7D,0EAA0E;IAC1E,IAAIE,QAAQC,GAAG,CAACC,gBAAgB,EAAE;QAChC,IAAIR,YAAY;YACd,MAAMS,YAAYlB,eACfI,MAAM,CAAC,CAACC,IAAMA,EAAEM,QAAQ,KAAKhD,WAAWiD,kBAAkB,CAACC,KAAK,EAChEhB,GAAG,CACF,CAACQ,IACC,iBACAc,IAAAA,2CAAsB,EACpBxD,YACAC,SACAC,SACAwC,GACArC;YAIRoD,QAAQC,KAAK,CACX,kCACEH,UAAU5B,IAAI,CAAC,UACf;YAGJ,kDAAkD;YAClD,MAAM,IAAIgC,QAAQ,CAACC,UAAYC,WAAWD,SAAS;QACrD;IACF;IAEA,IAAId,YAAY;QACd,MAAM,qBAQL,CARK,IAAIgB,0BAAY,CACpBN,IAAAA,2CAAsB,EACpBxD,YACAC,SACAC,SACA4C,YACAzC,mBANE,qBAAA;mBAAA;wBAAA;0BAAA;QAQN;IACF;IAEA,MAAM0D,WAAW1B,eACdI,MAAM,CAAC,CAACC,IAAMA,EAAEM,QAAQ,KAAKhD,WAAWiD,kBAAkB,CAACe,OAAO,EAClE9B,GAAG,CAAC,CAACQ,IACJc,IAAAA,2CAAsB,EAACxD,YAAYC,SAASC,SAASwC,GAAGrC;IAG5D,OAAO;QACLK,aAAa;QACbqD;QACApD,iBAAiBL,uBAAuBE,SAAS,CAACC,MAAM;QACxDG,iBAAiBQ,QAAQ6C,cAAc,GAAGxD,MAAM;QAChDI;IACF;AACF","ignoreList":[0]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "writeAppTypeDeclarations", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return writeAppTypeDeclarations;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _os = /*#__PURE__*/ _interop_require_default(require("os"));
|
|
12
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
+
const _fs = require("fs");
|
|
14
|
+
function _interop_require_default(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async function writeAppTypeDeclarations({ baseDir, distDir, imageImportsEnabled, hasPagesDir, hasAppDir }) {
|
|
20
|
+
// Reference `next` types
|
|
21
|
+
const appTypeDeclarations = _path.default.join(baseDir, 'next-env.d.ts');
|
|
22
|
+
// Defaults EOL to system default
|
|
23
|
+
let eol = _os.default.EOL;
|
|
24
|
+
let currentContent;
|
|
25
|
+
try {
|
|
26
|
+
currentContent = await _fs.promises.readFile(appTypeDeclarations, 'utf8');
|
|
27
|
+
// If file already exists then preserve its line ending
|
|
28
|
+
const lf = currentContent.indexOf('\n', /* skip first so we can lf - 1 */ 1);
|
|
29
|
+
if (lf !== -1) {
|
|
30
|
+
if (currentContent[lf - 1] === '\r') {
|
|
31
|
+
eol = '\r\n';
|
|
32
|
+
} else {
|
|
33
|
+
eol = '\n';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} catch {}
|
|
37
|
+
/**
|
|
38
|
+
* "Triple-slash directives" used to create typings files for Next.js projects
|
|
39
|
+
* using Typescript .
|
|
40
|
+
*
|
|
41
|
+
* @see https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html
|
|
42
|
+
*/ const directives = [
|
|
43
|
+
// Include the core Next.js typings.
|
|
44
|
+
'/// <reference types="next" />'
|
|
45
|
+
];
|
|
46
|
+
if (imageImportsEnabled) {
|
|
47
|
+
directives.push('/// <reference types="next/image-types/global" />');
|
|
48
|
+
}
|
|
49
|
+
if (hasAppDir && hasPagesDir) {
|
|
50
|
+
directives.push('/// <reference types="next/navigation-types/compat/navigation" />');
|
|
51
|
+
}
|
|
52
|
+
const routeTypesPath = _path.default.posix.join(distDir.replaceAll(_path.default.win32.sep, _path.default.posix.sep), 'types/routes.d.ts');
|
|
53
|
+
// Use ESM import instead of triple-slash reference for better ESLint compatibility
|
|
54
|
+
directives.push(`import "./${routeTypesPath}";`);
|
|
55
|
+
// Push the notice in.
|
|
56
|
+
directives.push('', '// NOTE: This file should not be edited', `// see https://nextjs.org/docs/${hasAppDir ? 'app' : 'pages'}/api-reference/config/typescript for more information.`);
|
|
57
|
+
const content = directives.join(eol) + eol;
|
|
58
|
+
// Avoids an un-necessary write on read-only fs
|
|
59
|
+
if (currentContent === content) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
await _fs.promises.writeFile(appTypeDeclarations, content);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=writeAppTypeDeclarations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../typescript/writeAppTypeDeclarations.ts"],"sourcesContent":["import os from 'os'\nimport path from 'path'\nimport { promises as fs } from 'fs'\n\nexport async function writeAppTypeDeclarations({\n baseDir,\n distDir,\n imageImportsEnabled,\n hasPagesDir,\n hasAppDir,\n}: {\n baseDir: string\n distDir: string\n imageImportsEnabled: boolean\n hasPagesDir: boolean\n hasAppDir: boolean\n}): Promise<void> {\n // Reference `next` types\n const appTypeDeclarations = path.join(baseDir, 'next-env.d.ts')\n\n // Defaults EOL to system default\n let eol = os.EOL\n let currentContent: string | undefined\n\n try {\n currentContent = await fs.readFile(appTypeDeclarations, 'utf8')\n // If file already exists then preserve its line ending\n const lf = currentContent.indexOf('\\n', /* skip first so we can lf - 1 */ 1)\n\n if (lf !== -1) {\n if (currentContent[lf - 1] === '\\r') {\n eol = '\\r\\n'\n } else {\n eol = '\\n'\n }\n }\n } catch {}\n\n /**\n * \"Triple-slash directives\" used to create typings files for Next.js projects\n * using Typescript .\n *\n * @see https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html\n */\n const directives: string[] = [\n // Include the core Next.js typings.\n '/// <reference types=\"next\" />',\n ]\n\n if (imageImportsEnabled) {\n directives.push('/// <reference types=\"next/image-types/global\" />')\n }\n\n if (hasAppDir && hasPagesDir) {\n directives.push(\n '/// <reference types=\"next/navigation-types/compat/navigation\" />'\n )\n }\n\n const routeTypesPath = path.posix.join(\n distDir.replaceAll(path.win32.sep, path.posix.sep),\n 'types/routes.d.ts'\n )\n\n // Use ESM import instead of triple-slash reference for better ESLint compatibility\n directives.push(`import \"./${routeTypesPath}\";`)\n\n // Push the notice in.\n directives.push(\n '',\n '// NOTE: This file should not be edited',\n `// see https://nextjs.org/docs/${hasAppDir ? 'app' : 'pages'}/api-reference/config/typescript for more information.`\n )\n\n const content = directives.join(eol) + eol\n\n // Avoids an un-necessary write on read-only fs\n if (currentContent === content) {\n return\n }\n await fs.writeFile(appTypeDeclarations, content)\n}\n"],"names":["writeAppTypeDeclarations","baseDir","distDir","imageImportsEnabled","hasPagesDir","hasAppDir","appTypeDeclarations","path","join","eol","os","EOL","currentContent","fs","readFile","lf","indexOf","directives","push","routeTypesPath","posix","replaceAll","win32","sep","content","writeFile"],"mappings":";;;;+BAIsBA;;;eAAAA;;;2DAJP;6DACE;oBACc;;;;;;AAExB,eAAeA,yBAAyB,EAC7CC,OAAO,EACPC,OAAO,EACPC,mBAAmB,EACnBC,WAAW,EACXC,SAAS,EAOV;IACC,yBAAyB;IACzB,MAAMC,sBAAsBC,aAAI,CAACC,IAAI,CAACP,SAAS;IAE/C,iCAAiC;IACjC,IAAIQ,MAAMC,WAAE,CAACC,GAAG;IAChB,IAAIC;IAEJ,IAAI;QACFA,iBAAiB,MAAMC,YAAE,CAACC,QAAQ,CAACR,qBAAqB;QACxD,uDAAuD;QACvD,MAAMS,KAAKH,eAAeI,OAAO,CAAC,MAAM,+BA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