Skip to content

Commit

Permalink
Use more precompiled deps in react-dev-overlay (#60959)
Browse files Browse the repository at this point in the history
## What?

Follow-up to #60932, adds all other precompiled dependencies.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->


Closes NEXT-2178
  • Loading branch information
timneutkens authored Jan 22, 2024
1 parent 4125069 commit 0f044d0
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 72 deletions.
11 changes: 11 additions & 0 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export async function ncc_node_fetch(task, opts) {
}

externals['anser'] = 'next/dist/compiled/anser'
externals['next/dist/compiled/anser'] = 'next/dist/compiled/anser'
export async function ncc_node_anser(task, opts) {
await task
.source(relative(__dirname, require.resolve('anser')))
Expand All @@ -257,6 +258,8 @@ export async function ncc_node_anser(task, opts) {
}

externals['stacktrace-parser'] = 'next/dist/compiled/stacktrace-parser'
externals['next/dist/compiled/stacktrace-parser'] =
'next/dist/compiled/stacktrace-parser'
export async function ncc_node_stacktrace_parser(task, opts) {
await task
.source(relative(__dirname, require.resolve('stacktrace-parser')))
Expand All @@ -265,6 +268,8 @@ export async function ncc_node_stacktrace_parser(task, opts) {
}

externals['data-uri-to-buffer'] = 'next/dist/compiled/data-uri-to-buffer'
externals['next/dist/compiled/data-uri-to-buffer'] =
'next/dist/compiled/data-uri-to-buffer'
export async function ncc_node_data_uri_to_buffer(task, opts) {
await task
.source(relative(__dirname, require.resolve('data-uri-to-buffer')))
Expand All @@ -273,6 +278,7 @@ export async function ncc_node_data_uri_to_buffer(task, opts) {
}

externals['css.escape'] = 'next/dist/compiled/css.escape'
externals['next/dist/compiled/css.escape'] = 'next/dist/compiled/css.escape'
export async function ncc_node_cssescape(task, opts) {
await task
.source(relative(__dirname, require.resolve('css.escape')))
Expand All @@ -281,6 +287,7 @@ export async function ncc_node_cssescape(task, opts) {
}

externals['shell-quote'] = 'next/dist/compiled/shell-quote'
externals['next/dist/compiled/shell-quote'] = 'next/dist/compiled/shell-quote'
export async function ncc_node_shell_quote(task, opts) {
await task
.source(relative(__dirname, require.resolve('shell-quote')))
Expand All @@ -289,6 +296,7 @@ export async function ncc_node_shell_quote(task, opts) {
}

externals['platform'] = 'next/dist/compiled/platform'
externals['next/dist/compiled/platform'] = 'next/dist/compiled/platform'
export async function ncc_node_platform(task, opts) {
await task
.source(relative(__dirname, require.resolve('platform')))
Expand Down Expand Up @@ -1133,6 +1141,8 @@ const babelCorePackages = {
'@babel/core/lib/transformation/plugin-pass':
'next/dist/compiled/babel/core-lib-plugin-pass',
}
externals['next/dist/compiled/babel/code-frame'] =
'next/dist/compiled/babel/code-frame'

Object.assign(externals, babelCorePackages)

Expand Down Expand Up @@ -1942,6 +1952,7 @@ export async function ncc_string_hash(task, opts) {
}
// eslint-disable-next-line camelcase
externals['strip-ansi'] = 'next/dist/compiled/strip-ansi'
externals['next/dist/compiled/strip-ansi'] = 'next/dist/compiled/strip-ansi'
export async function ncc_strip_ansi(task, opts) {
await task
.source(relative(__dirname, require.resolve('strip-ansi')))
Expand Down
13 changes: 1 addition & 12 deletions packages/react-dev-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,7 @@
"dev": "tsc -d -w -p tsconfig.json",
"typescript": "tsec --noEmit -p tsconfig.json"
},
"dependencies": {
"@babel/code-frame": "7.22.5",
"@types/babel__code-frame": "7.0.3",
"anser": "1.4.9",
"css.escape": "1.5.1",
"data-uri-to-buffer": "3.0.1",
"picocolors": "1.0.0",
"platform": "1.3.6",
"shell-quote": "1.7.3",
"stacktrace-parser": "0.1.10",
"strip-ansi": "6.0.1"
},
"dependencies": {},
"peerDependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dev-overlay/src/internal/bus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { StackFrame } from 'stacktrace-parser'
// @ts-ignore Package Exists
import type { StackFrame } from 'next/dist/compiled/stacktrace-parser'

export const TYPE_BUILD_OK = 'build-ok'
export const TYPE_BUILD_ERROR = 'build-error'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Anser from 'anser'
// @ts-ignore Package exists
import Anser from 'next/dist/compiled/anser'
import * as React from 'react'
import type { StackFrame } from 'stacktrace-parser'
import stripAnsi from 'strip-ansi'
// @ts-ignore Package Exists
import type { StackFrame } from 'next/dist/compiled/stacktrace-parser'
// @ts-ignore Package Exists
import stripAnsi from 'next/dist/compiled/strip-ansi'
import { getFrameSource } from '../../helpers/stack-frame'

export type CodeFrameProps = { stackFrame: StackFrame; codeFrame: string }
Expand Down Expand Up @@ -93,7 +96,7 @@ export const CodeFrame: React.FC<CodeFrameProps> = function CodeFrame({
</p>
</div>
<pre>
{decoded.map((entry, index) => (
{decoded.map((entry: any, index: any) => (
<span
key={`frame-${index}`}
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
// Entrypoint: ally.js/maintain/tab-focus

import _platform from 'platform'
import cssEscape from 'css.escape'
import _platform from 'next/dist/compiled/platform'
import cssEscape from 'next/dist/compiled/css.escape'

// input may be undefined, selector-tring, Node, NodeList, HTMLCollection, array of Nodes
// yes, to some extent this is a bad replica of jQuery's constructor function
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Anser from 'anser'
// @ts-ignore Package exists
import Anser from 'next/dist/compiled/anser'
import * as React from 'react'

export type TerminalProps = { content: string }
Expand All @@ -17,7 +18,7 @@ export const Terminal: React.FC<TerminalProps> = function Terminal({
return (
<div data-nextjs-terminal>
<pre>
{decoded.map((entry, index) => (
{decoded.map((entry: any, index: any) => (
<span
key={`terminal-entry-${index}`}
style={{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import type { StackFrame } from 'stacktrace-parser'
// @ts-ignore Package Exists
import type { StackFrame } from 'next/dist/compiled/stacktrace-parser'
import { CodeFrame } from '../components/CodeFrame'
import type { ReadyRuntimeError } from '../helpers/getErrorByType'
import { noop as css } from '../helpers/noop-template'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { MimeBuffer } from 'data-uri-to-buffer'
import dataUriToBuffer from 'data-uri-to-buffer'
// @ts-ignore Package Exists
import dataUriToBuffer from 'next/dist/compiled/data-uri-to-buffer'
import { getSourceMapUrl } from './getSourceMapUrl'

export function getRawSourceMap(fileContents: string): unknown | null {
Expand All @@ -8,7 +8,7 @@ export function getRawSourceMap(fileContents: string): unknown | null {
return null
}

let buffer: MimeBuffer
let buffer
try {
buffer = dataUriToBuffer(sourceUrl)
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import pc from 'picocolors'
// @ts-ignore Package Exists
import pc from 'next/dist/lib/picocolors'
import child_process from 'child_process'
import fs from 'fs'
import os from 'os'
import path from 'path'
// @ts-ignore
import shellQuote from 'shell-quote'
import shellQuote from 'next/dist/compiled/shell-quote'

function isTerminalEditor(editor: string) {
switch (editor) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { StackFrame } from 'stacktrace-parser'
import { parse } from 'stacktrace-parser'
// @ts-ignore Package Exists
import type { StackFrame } from 'next/dist/compiled/stacktrace-parser'
// @ts-ignore Package Exists
import { parse } from 'next/dist/compiled/stacktrace-parser'

export function getFilesystemFrame(frame: StackFrame): StackFrame {
const f: StackFrame = { ...frame }
Expand Down Expand Up @@ -49,7 +51,7 @@ export function getServerError(error: Error, type: ErrorType): Error {
try {
n.stack = `${n.toString()}\n${parse(error.stack!)
.map(getFilesystemFrame)
.map((f) => {
.map((f: any) => {
let str = ` at ${f.methodName}`
if (f.file) {
let loc = f.file
Expand Down
8 changes: 5 additions & 3 deletions packages/react-dev-overlay/src/internal/helpers/parseStack.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { StackFrame } from 'stacktrace-parser'
import { parse } from 'stacktrace-parser'
// @ts-ignore Package Exists
import type { StackFrame } from 'next/dist/compiled/stacktrace-parser'
// @ts-ignore Package Exists
import { parse } from 'next/dist/compiled/stacktrace-parser'

const regexNextStatic = /\/_next(\/static\/.+)/

export function parseStack(stack: string): StackFrame[] {
const frames = parse(stack)
return frames.map((frame) => {
return frames.map((frame: any) => {
try {
const url = new URL(frame.file!)
const res = regexNextStatic.exec(url.pathname)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { StackFrame } from 'stacktrace-parser'
// @ts-ignore Package Exists
import type { StackFrame } from 'next/dist/compiled/stacktrace-parser'
import type { OriginalStackFrameResponse } from '../../middleware'

export type OriginalStackFrame =
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dev-overlay/src/middleware-turbopack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type { OriginalStackFrameResponse } from './middleware'

import fs, { constants as FS } from 'fs/promises'
import url from 'url'
import { codeFrameColumns } from '@babel/code-frame'
// @ts-ignore Package exists
import { codeFrameColumns } from 'next/dist/compiled/babel/code-frame'
import { launchEditor } from './internal/helpers/launchEditor'

interface Project {
Expand Down
6 changes: 4 additions & 2 deletions packages/react-dev-overlay/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { codeFrameColumns } from '@babel/code-frame'
// @ts-ignore Package exists
import { codeFrameColumns } from 'next/dist/compiled/babel/code-frame'
import { constants as FS, promises as fs } from 'fs'
import type { IncomingMessage, ServerResponse } from 'http'
import path from 'path'
// @ts-ignore Package exists
import { SourceMapConsumer } from 'next/dist/compiled/source-map08'
import type { StackFrame } from 'stacktrace-parser'
// @ts-ignore Package exists
import type { StackFrame } from 'next/dist/compiled/stacktrace-parser'
import url from 'url'
// @ts-ignore
// eslint-disable-next-line import/no-extraneous-dependencies
Expand Down
43 changes: 8 additions & 35 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0f044d0

Please sign in to comment.