added fonts
This commit is contained in:
1 parent
4134e3a234
commit
142d2986b6
9079 files changed
+1498421
-2
No files matched your search
+16
@@ -0,0 +1,16 @@
|
||||
export function css(strings) {
|
||||
for(var _len = arguments.length, keys = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
||||
keys[_key - 1] = arguments[_key];
|
||||
}
|
||||
const lastIndex = strings.length - 1;
|
||||
const str = // Convert template literal into a single line string
|
||||
strings.slice(0, lastIndex).reduce((p, s, i)=>p + s + keys[i], '') + strings[lastIndex];
|
||||
return str// Remove comments
|
||||
.replace(/\/\*[\s\S]*?\*\//g, '')// Remove whitespace, tabs, and newlines
|
||||
.replace(/\s+/g, ' ')// Remove spaces before and after semicolons, and spaces after commas
|
||||
.replace(/\s*([:;,{}])\s*/g, '$1')// Remove extra semicolons
|
||||
.replace(/;+}/g, '}')// Trim leading and trailing whitespaces
|
||||
.trim();
|
||||
}
|
||||
|
||||
//# sourceMappingURL=css.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/utils/css.ts"],"sourcesContent":["export function css(\n strings: TemplateStringsArray,\n ...keys: readonly string[]\n): string {\n const lastIndex = strings.length - 1\n const str =\n // Convert template literal into a single line string\n strings.slice(0, lastIndex).reduce((p, s, i) => p + s + keys[i], '') +\n strings[lastIndex]\n\n return (\n str\n // Remove comments\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n // Remove whitespace, tabs, and newlines\n .replace(/\\s+/g, ' ')\n // Remove spaces before and after semicolons, and spaces after commas\n .replace(/\\s*([:;,{}])\\s*/g, '$1')\n // Remove extra semicolons\n .replace(/;+}/g, '}')\n // Trim leading and trailing whitespaces\n .trim()\n )\n}\n"],"names":["css","strings","keys","lastIndex","length","str","slice","reduce","p","s","i","replace","trim"],"mappings":"AAAA,OAAO,SAASA,IACdC,OAA6B;IAC7B,IAAA,IAAA,OAAA,UAAA,QAAA,AAAGC,OAAH,UAAA,OAAA,IAAA,OAAA,QAAA,OAAA,GAAA,OAAA,MAAA;QAAGA,KAAH,OAAA,KAAA,SAAA,CAAA,KAA0B;;IAE1B,MAAMC,YAAYF,QAAQG,MAAM,GAAG;IACnC,MAAMC,MACJ,qDAAqD;IACrDJ,QAAQK,KAAK,CAAC,GAAGH,WAAWI,MAAM,CAAC,CAACC,GAAGC,GAAGC,IAAMF,IAAIC,IAAIP,IAAI,CAACQ,EAAE,EAAE,MACjET,OAAO,CAACE,UAAU;IAEpB,OACEE,GACE,kBAAkB;KACjBM,OAAO,CAAC,qBAAqB,GAC9B,wCAAwC;KACvCA,OAAO,CAAC,QAAQ,IACjB,qEAAqE;KACpEA,OAAO,CAAC,oBAAoB,KAC7B,0BAA0B;KACzBA,OAAO,CAAC,QAAQ,IACjB,wCAAwC;KACvCC,IAAI;AAEX"}
|
||||
Generated
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Singleton store to track whether the app is currently being rendered
|
||||
* Used by the dev tools indicator to show render status
|
||||
*/ import { useSyncExternalStore } from 'react';
|
||||
let isVisible = false;
|
||||
let listeners = [];
|
||||
const subscribe = (listener)=>{
|
||||
listeners.push(listener);
|
||||
return ()=>{
|
||||
listeners = listeners.filter((l)=>l !== listener);
|
||||
};
|
||||
};
|
||||
const getSnapshot = ()=>isVisible;
|
||||
const show = ()=>{
|
||||
isVisible = true;
|
||||
listeners.forEach((listener)=>listener());
|
||||
};
|
||||
const hide = ()=>{
|
||||
isVisible = false;
|
||||
listeners.forEach((listener)=>listener());
|
||||
};
|
||||
export function useIsDevRendering() {
|
||||
return useSyncExternalStore(subscribe, getSnapshot);
|
||||
}
|
||||
export const devRenderIndicator = {
|
||||
show,
|
||||
hide
|
||||
};
|
||||
|
||||
//# sourceMappingURL=dev-render-indicator.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../../src/client/components/react-dev-overlay/utils/dev-indicator/dev-render-indicator.tsx"],"sourcesContent":["/*\n * Singleton store to track whether the app is currently being rendered\n * Used by the dev tools indicator to show render status\n */\n\nimport { useSyncExternalStore } from 'react'\n\nlet isVisible = false\nlet listeners: Array<() => void> = []\n\nconst subscribe = (listener: () => void) => {\n listeners.push(listener)\n return () => {\n listeners = listeners.filter((l) => l !== listener)\n }\n}\n\nconst getSnapshot = () => isVisible\n\nconst show = () => {\n isVisible = true\n listeners.forEach((listener) => listener())\n}\n\nconst hide = () => {\n isVisible = false\n listeners.forEach((listener) => listener())\n}\n\nexport function useIsDevRendering() {\n return useSyncExternalStore(subscribe, getSnapshot)\n}\n\nexport const devRenderIndicator = {\n show,\n hide,\n}\n"],"names":["useSyncExternalStore","isVisible","listeners","subscribe","listener","push","filter","l","getSnapshot","show","forEach","hide","useIsDevRendering","devRenderIndicator"],"mappings":"AAAA;;;CAGC,GAED,SAASA,oBAAoB,QAAQ,QAAO;AAE5C,IAAIC,YAAY;AAChB,IAAIC,YAA+B,EAAE;AAErC,MAAMC,YAAY,CAACC;IACjBF,UAAUG,IAAI,CAACD;IACf,OAAO;QACLF,YAAYA,UAAUI,MAAM,CAAC,CAACC,IAAMA,MAAMH;IAC5C;AACF;AAEA,MAAMI,cAAc,IAAMP;AAE1B,MAAMQ,OAAO;IACXR,YAAY;IACZC,UAAUQ,OAAO,CAAC,CAACN,WAAaA;AAClC;AAEA,MAAMO,OAAO;IACXV,YAAY;IACZC,UAAUQ,OAAO,CAAC,CAACN,WAAaA;AAClC;AAEA,OAAO,SAASQ;IACd,OAAOZ,qBAAqBG,WAAWK;AACzC;AAEA,OAAO,MAAMK,qBAAqB;IAChCJ;IACAE;AACF,EAAC"}
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
import { useEffect, useTransition } from 'react';
|
||||
import { devRenderIndicator } from './dev-render-indicator';
|
||||
export const useSyncDevRenderIndicator = ()=>{
|
||||
const [isPending, startTransition] = useTransition();
|
||||
useEffect(()=>{
|
||||
if (isPending) {
|
||||
devRenderIndicator.show();
|
||||
} else {
|
||||
devRenderIndicator.hide();
|
||||
}
|
||||
}, [
|
||||
isPending
|
||||
]);
|
||||
return startTransition;
|
||||
};
|
||||
|
||||
//# sourceMappingURL=use-sync-dev-render-indicator.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../../src/client/components/react-dev-overlay/utils/dev-indicator/use-sync-dev-render-indicator.tsx"],"sourcesContent":["import { useEffect, useTransition } from 'react'\nimport { devRenderIndicator } from './dev-render-indicator'\n\nexport const useSyncDevRenderIndicator = () => {\n const [isPending, startTransition] = useTransition()\n\n useEffect(() => {\n if (isPending) {\n devRenderIndicator.show()\n } else {\n devRenderIndicator.hide()\n }\n }, [isPending])\n\n return startTransition\n}\n"],"names":["useEffect","useTransition","devRenderIndicator","useSyncDevRenderIndicator","isPending","startTransition","show","hide"],"mappings":"AAAA,SAASA,SAAS,EAAEC,aAAa,QAAQ,QAAO;AAChD,SAASC,kBAAkB,QAAQ,yBAAwB;AAE3D,OAAO,MAAMC,4BAA4B;IACvC,MAAM,CAACC,WAAWC,gBAAgB,GAAGJ;IAErCD,UAAU;QACR,IAAII,WAAW;YACbF,mBAAmBI,IAAI;QACzB,OAAO;YACLJ,mBAAmBK,IAAI;QACzB;IACF,GAAG;QAACH;KAAU;IAEd,OAAOC;AACT,EAAC"}
|
||||
Generated
Vendored
+147
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2015-present, Facebook, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/ import stripAnsi from 'next/dist/compiled/strip-ansi';
|
||||
// This file is based on https://github.com/facebook/create-react-app/blob/7b1a32be6ec9f99a6c9a3c66813f3ac09c4736b9/packages/react-dev-utils/formatWebpackMessages.js
|
||||
// It's been edited to remove chalk and CRA-specific logic
|
||||
const friendlySyntaxErrorLabel = 'Syntax error:';
|
||||
const WEBPACK_BREAKING_CHANGE_POLYFILLS = '\n\nBREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.';
|
||||
function isLikelyASyntaxError(message) {
|
||||
return stripAnsi(message).includes(friendlySyntaxErrorLabel);
|
||||
}
|
||||
let hadMissingSassError = false;
|
||||
// Cleans up webpack error messages.
|
||||
function formatMessage(message, verbose, importTraceNote) {
|
||||
// TODO: Replace this once webpack 5 is stable
|
||||
if (typeof message === 'object' && message.message) {
|
||||
const filteredModuleTrace = message.moduleTrace && message.moduleTrace.filter((trace)=>!/next-(middleware|client-pages|route|edge-function)-loader\.js/.test(trace.originName));
|
||||
let body = message.message;
|
||||
const breakingChangeIndex = body.indexOf(WEBPACK_BREAKING_CHANGE_POLYFILLS);
|
||||
if (breakingChangeIndex >= 0) {
|
||||
body = body.slice(0, breakingChangeIndex);
|
||||
}
|
||||
message = (message.moduleName ? stripAnsi(message.moduleName) + '\n' : '') + (message.file ? stripAnsi(message.file) + '\n' : '') + body + (message.details && verbose ? '\n' + message.details : '') + (filteredModuleTrace && filteredModuleTrace.length ? (importTraceNote || '\n\nImport trace for requested module:') + filteredModuleTrace.map((trace)=>"\n" + trace.moduleName).join('') : '') + (message.stack && verbose ? '\n' + message.stack : '');
|
||||
}
|
||||
let lines = message.split('\n');
|
||||
// Strip Webpack-added headers off errors/warnings
|
||||
// https://github.com/webpack/webpack/blob/master/lib/ModuleError.js
|
||||
lines = lines.filter((line)=>!/Module [A-z ]+\(from/.test(line));
|
||||
// Transform parsing error into syntax error
|
||||
// TODO: move this to our ESLint formatter?
|
||||
lines = lines.map((line)=>{
|
||||
const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
|
||||
if (!parsingError) {
|
||||
return line;
|
||||
}
|
||||
const [, errorLine, errorColumn, errorMessage] = parsingError;
|
||||
return friendlySyntaxErrorLabel + " " + errorMessage + " (" + errorLine + ":" + errorColumn + ")";
|
||||
});
|
||||
message = lines.join('\n');
|
||||
// Smoosh syntax errors (commonly found in CSS)
|
||||
message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, "" + friendlySyntaxErrorLabel + " $3 ($1:$2)\n");
|
||||
// Clean up export errors
|
||||
message = message.replace(/^.*export '(.+?)' was not found in '(.+?)'.*$/gm, "Attempted import error: '$1' is not exported from '$2'.");
|
||||
message = message.replace(/^.*export 'default' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm, "Attempted import error: '$2' does not contain a default export (imported as '$1').");
|
||||
message = message.replace(/^.*export '(.+?)' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm, "Attempted import error: '$1' is not exported from '$3' (imported as '$2').");
|
||||
lines = message.split('\n');
|
||||
// Remove leading newline
|
||||
if (lines.length > 2 && lines[1].trim() === '') {
|
||||
lines.splice(1, 1);
|
||||
}
|
||||
// Cleans up verbose "module not found" messages for files and packages.
|
||||
if (lines[1] && lines[1].startsWith('Module not found: ')) {
|
||||
lines = [
|
||||
lines[0],
|
||||
lines[1].replace('Error: ', '').replace('Module not found: Cannot find file:', 'Cannot find file:'),
|
||||
...lines.slice(2)
|
||||
];
|
||||
}
|
||||
// Add helpful message for users trying to use Sass for the first time
|
||||
if (lines[1] && lines[1].match(/Cannot find module.+sass/)) {
|
||||
// ./file.module.scss (<<loader info>>) => ./file.module.scss
|
||||
const firstLine = lines[0].split('!');
|
||||
lines[0] = firstLine[firstLine.length - 1];
|
||||
lines[1] = "To use Next.js' built-in Sass support, you first need to install `sass`.\n";
|
||||
lines[1] += 'Run `npm i sass` or `yarn add sass` inside your workspace.\n';
|
||||
lines[1] += '\nLearn more: https://nextjs.org/docs/messages/install-sass';
|
||||
// dispose of unhelpful stack trace
|
||||
lines = lines.slice(0, 2);
|
||||
hadMissingSassError = true;
|
||||
} else if (hadMissingSassError && message.match(/(sass-loader|resolve-url-loader: CSS error)/)) {
|
||||
// dispose of unhelpful stack trace following missing sass module
|
||||
lines = [];
|
||||
}
|
||||
if (!verbose) {
|
||||
message = lines.join('\n');
|
||||
// Internal stacks are generally useless so we strip them... with the
|
||||
// exception of stacks containing `webpack:` because they're normally
|
||||
// from user code generated by Webpack. For more information see
|
||||
// https://github.com/facebook/create-react-app/pull/1050
|
||||
message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, '') // at ... ...:x:y
|
||||
;
|
||||
message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, '') // at <anonymous>
|
||||
;
|
||||
message = message.replace(/File was processed with these loaders:\n(.+[\\/](next[\\/]dist[\\/].+|@next[\\/]react-refresh-utils[\\/]loader)\.js\n)*You may need an additional loader to handle the result of these loaders.\n/g, '');
|
||||
lines = message.split('\n');
|
||||
}
|
||||
// Remove duplicated newlines
|
||||
lines = lines.filter((line, index, arr)=>index === 0 || line.trim() !== '' || line.trim() !== arr[index - 1].trim());
|
||||
// Reassemble the message
|
||||
message = lines.join('\n');
|
||||
return message.trim();
|
||||
}
|
||||
export default function formatWebpackMessages(json, verbose) {
|
||||
const formattedErrors = json.errors.map((message)=>{
|
||||
const isUnknownNextFontError = message.message.includes('An error occurred in `next/font`.');
|
||||
return formatMessage(message, isUnknownNextFontError || verbose);
|
||||
});
|
||||
const formattedWarnings = json.warnings.map((message)=>{
|
||||
return formatMessage(message, verbose);
|
||||
});
|
||||
// Reorder errors to put the most relevant ones first.
|
||||
let reactServerComponentsError = -1;
|
||||
for(let i = 0; i < formattedErrors.length; i++){
|
||||
const error = formattedErrors[i];
|
||||
if (error.includes('ReactServerComponentsError')) {
|
||||
reactServerComponentsError = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Move the reactServerComponentsError to the top if it exists
|
||||
if (reactServerComponentsError !== -1) {
|
||||
const error = formattedErrors.splice(reactServerComponentsError, 1);
|
||||
formattedErrors.unshift(error[0]);
|
||||
}
|
||||
const result = {
|
||||
...json,
|
||||
errors: formattedErrors,
|
||||
warnings: formattedWarnings
|
||||
};
|
||||
if (!verbose && result.errors.some(isLikelyASyntaxError)) {
|
||||
// If there are any syntax errors, show just them.
|
||||
result.errors = result.errors.filter(isLikelyASyntaxError);
|
||||
result.warnings = [];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=format-webpack-messages.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/utils/format-webpack-messages.ts"],"sourcesContent":["/**\nMIT License\n\nCopyright (c) 2015-present, Facebook, Inc.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n*/\nimport stripAnsi from 'next/dist/compiled/strip-ansi'\n// This file is based on https://github.com/facebook/create-react-app/blob/7b1a32be6ec9f99a6c9a3c66813f3ac09c4736b9/packages/react-dev-utils/formatWebpackMessages.js\n// It's been edited to remove chalk and CRA-specific logic\n\nconst friendlySyntaxErrorLabel = 'Syntax error:'\n\nconst WEBPACK_BREAKING_CHANGE_POLYFILLS =\n '\\n\\nBREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.'\n\nfunction isLikelyASyntaxError(message: string) {\n return stripAnsi(message).includes(friendlySyntaxErrorLabel)\n}\n\nlet hadMissingSassError = false\n\n// Cleans up webpack error messages.\nfunction formatMessage(\n message: any,\n verbose?: boolean,\n importTraceNote?: boolean\n) {\n // TODO: Replace this once webpack 5 is stable\n if (typeof message === 'object' && message.message) {\n const filteredModuleTrace =\n message.moduleTrace &&\n message.moduleTrace.filter(\n (trace: any) =>\n !/next-(middleware|client-pages|route|edge-function)-loader\\.js/.test(\n trace.originName\n )\n )\n\n let body = message.message\n const breakingChangeIndex = body.indexOf(WEBPACK_BREAKING_CHANGE_POLYFILLS)\n if (breakingChangeIndex >= 0) {\n body = body.slice(0, breakingChangeIndex)\n }\n\n message =\n (message.moduleName ? stripAnsi(message.moduleName) + '\\n' : '') +\n (message.file ? stripAnsi(message.file) + '\\n' : '') +\n body +\n (message.details && verbose ? '\\n' + message.details : '') +\n (filteredModuleTrace && filteredModuleTrace.length\n ? (importTraceNote || '\\n\\nImport trace for requested module:') +\n filteredModuleTrace\n .map((trace: any) => `\\n${trace.moduleName}`)\n .join('')\n : '') +\n (message.stack && verbose ? '\\n' + message.stack : '')\n }\n let lines = message.split('\\n')\n\n // Strip Webpack-added headers off errors/warnings\n // https://github.com/webpack/webpack/blob/master/lib/ModuleError.js\n lines = lines.filter((line: string) => !/Module [A-z ]+\\(from/.test(line))\n\n // Transform parsing error into syntax error\n // TODO: move this to our ESLint formatter?\n lines = lines.map((line: string) => {\n const parsingError = /Line (\\d+):(?:(\\d+):)?\\s*Parsing error: (.+)$/.exec(\n line\n )\n if (!parsingError) {\n return line\n }\n const [, errorLine, errorColumn, errorMessage] = parsingError\n return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`\n })\n\n message = lines.join('\\n')\n // Smoosh syntax errors (commonly found in CSS)\n message = message.replace(\n /SyntaxError\\s+\\((\\d+):(\\d+)\\)\\s*(.+?)\\n/g,\n `${friendlySyntaxErrorLabel} $3 ($1:$2)\\n`\n )\n // Clean up export errors\n message = message.replace(\n /^.*export '(.+?)' was not found in '(.+?)'.*$/gm,\n `Attempted import error: '$1' is not exported from '$2'.`\n )\n message = message.replace(\n /^.*export 'default' \\(imported as '(.+?)'\\) was not found in '(.+?)'.*$/gm,\n `Attempted import error: '$2' does not contain a default export (imported as '$1').`\n )\n message = message.replace(\n /^.*export '(.+?)' \\(imported as '(.+?)'\\) was not found in '(.+?)'.*$/gm,\n `Attempted import error: '$1' is not exported from '$3' (imported as '$2').`\n )\n lines = message.split('\\n')\n\n // Remove leading newline\n if (lines.length > 2 && lines[1].trim() === '') {\n lines.splice(1, 1)\n }\n\n // Cleans up verbose \"module not found\" messages for files and packages.\n if (lines[1] && lines[1].startsWith('Module not found: ')) {\n lines = [\n lines[0],\nLine truncated
|
||||
Generated
Vendored
+82
@@ -0,0 +1,82 @@
|
||||
import { ACTION_UNHANDLED_ERROR, ACTION_UNHANDLED_REJECTION } from '../shared';
|
||||
import { getOriginalStackFrames } from './stack-frame';
|
||||
import { getErrorSource } from '../../../../shared/lib/error-source';
|
||||
import React from 'react';
|
||||
export const useFrames = (error)=>{
|
||||
if ('use' in React) {
|
||||
const frames = error.frames;
|
||||
if (typeof frames !== 'function') {
|
||||
throw Object.defineProperty(new Error('Invariant: frames must be a function when the React version has React.use. This is a bug in Next.js.'), "__NEXT_ERROR_CODE", {
|
||||
value: "E636",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
return React.use(frames());
|
||||
} else {
|
||||
if (!Array.isArray(error.frames)) {
|
||||
throw Object.defineProperty(new Error('Invariant: frames must be an array when the React version does not have React.use. This is a bug in Next.js.'), "__NEXT_ERROR_CODE", {
|
||||
value: "E637",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
return error.frames;
|
||||
}
|
||||
};
|
||||
export async function getErrorByType(ev, isAppDir) {
|
||||
const { id, event } = ev;
|
||||
switch(event.type){
|
||||
case ACTION_UNHANDLED_ERROR:
|
||||
case ACTION_UNHANDLED_REJECTION:
|
||||
{
|
||||
const baseError = {
|
||||
id,
|
||||
runtime: true,
|
||||
error: event.reason
|
||||
};
|
||||
if ('use' in React) {
|
||||
const readyRuntimeError = {
|
||||
...baseError,
|
||||
// createMemoizedPromise dedups calls to getOriginalStackFrames
|
||||
frames: createMemoizedPromise(async ()=>{
|
||||
return await getOriginalStackFrames(event.frames, getErrorSource(event.reason), isAppDir);
|
||||
})
|
||||
};
|
||||
if (event.type === ACTION_UNHANDLED_ERROR) {
|
||||
readyRuntimeError.componentStackFrames = event.componentStackFrames;
|
||||
}
|
||||
return readyRuntimeError;
|
||||
} else {
|
||||
const readyRuntimeError = {
|
||||
...baseError,
|
||||
// createMemoizedPromise dedups calls to getOriginalStackFrames
|
||||
frames: await getOriginalStackFrames(event.frames, getErrorSource(event.reason), isAppDir)
|
||||
};
|
||||
if (event.type === ACTION_UNHANDLED_ERROR) {
|
||||
readyRuntimeError.componentStackFrames = event.componentStackFrames;
|
||||
}
|
||||
return readyRuntimeError;
|
||||
}
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const _ = event;
|
||||
throw Object.defineProperty(new Error('type system invariant violation'), "__NEXT_ERROR_CODE", {
|
||||
value: "E335",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
function createMemoizedPromise(promiseFactory) {
|
||||
const cachedPromise = promiseFactory();
|
||||
return function() {
|
||||
return cachedPromise;
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=get-error-by-type.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/utils/get-error-by-type.ts"],"sourcesContent":["import { ACTION_UNHANDLED_ERROR, ACTION_UNHANDLED_REJECTION } from '../shared'\nimport type { SupportedErrorEvent } from '../ui/container/runtime-error/render-error'\nimport { getOriginalStackFrames } from './stack-frame'\nimport type { OriginalStackFrame } from './stack-frame'\nimport type { ComponentStackFrame } from './parse-component-stack'\nimport { getErrorSource } from '../../../../shared/lib/error-source'\nimport React from 'react'\n\nexport type ReadyRuntimeError = {\n id: number\n runtime: true\n error: Error & { environmentName?: string }\n frames: OriginalStackFrame[] | (() => Promise<OriginalStackFrame[]>)\n componentStackFrames?: ComponentStackFrame[]\n}\n\nexport const useFrames = (error: ReadyRuntimeError): OriginalStackFrame[] => {\n if ('use' in React) {\n const frames = error.frames\n\n if (typeof frames !== 'function') {\n throw new Error(\n 'Invariant: frames must be a function when the React version has React.use. This is a bug in Next.js.'\n )\n }\n\n return React.use((frames as () => Promise<OriginalStackFrame[]>)())\n } else {\n if (!Array.isArray(error.frames)) {\n throw new Error(\n 'Invariant: frames must be an array when the React version does not have React.use. This is a bug in Next.js.'\n )\n }\n\n return error.frames\n }\n}\n\nexport async function getErrorByType(\n ev: SupportedErrorEvent,\n isAppDir: boolean\n): Promise<ReadyRuntimeError> {\n const { id, event } = ev\n switch (event.type) {\n case ACTION_UNHANDLED_ERROR:\n case ACTION_UNHANDLED_REJECTION: {\n const baseError = {\n id,\n runtime: true,\n error: event.reason,\n } as const\n\n if ('use' in React) {\n const readyRuntimeError: ReadyRuntimeError = {\n ...baseError,\n // createMemoizedPromise dedups calls to getOriginalStackFrames\n frames: createMemoizedPromise(async () => {\n return await getOriginalStackFrames(\n event.frames,\n getErrorSource(event.reason),\n isAppDir\n )\n }),\n }\n if (event.type === ACTION_UNHANDLED_ERROR) {\n readyRuntimeError.componentStackFrames = event.componentStackFrames\n }\n return readyRuntimeError\n } else {\n const readyRuntimeError: ReadyRuntimeError = {\n ...baseError,\n // createMemoizedPromise dedups calls to getOriginalStackFrames\n frames: await getOriginalStackFrames(\n event.frames,\n getErrorSource(event.reason),\n isAppDir\n ),\n }\n if (event.type === ACTION_UNHANDLED_ERROR) {\n readyRuntimeError.componentStackFrames = event.componentStackFrames\n }\n return readyRuntimeError\n }\n }\n default: {\n break\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const _: never = event\n throw new Error('type system invariant violation')\n}\n\nfunction createMemoizedPromise<T>(\n promiseFactory: () => Promise<T>\n): () => Promise<T> {\n const cachedPromise = promiseFactory()\n return function (): Promise<T> {\n return cachedPromise\n }\n}\n"],"names":["ACTION_UNHANDLED_ERROR","ACTION_UNHANDLED_REJECTION","getOriginalStackFrames","getErrorSource","React","useFrames","error","frames","Error","use","Array","isArray","getErrorByType","ev","isAppDir","id","event","type","baseError","runtime","reason","readyRuntimeError","createMemoizedPromise","componentStackFrames","_","promiseFactory","cachedPromise"],"mappings":"AAAA,SAASA,sBAAsB,EAAEC,0BAA0B,QAAQ,YAAW;AAE9E,SAASC,sBAAsB,QAAQ,gBAAe;AAGtD,SAASC,cAAc,QAAQ,sCAAqC;AACpE,OAAOC,WAAW,QAAO;AAUzB,OAAO,MAAMC,YAAY,CAACC;IACxB,IAAI,SAASF,OAAO;QAClB,MAAMG,SAASD,MAAMC,MAAM;QAE3B,IAAI,OAAOA,WAAW,YAAY;YAChC,MAAM,qBAEL,CAFK,IAAIC,MACR,yGADI,qBAAA;uBAAA;4BAAA;8BAAA;YAEN;QACF;QAEA,OAAOJ,MAAMK,GAAG,CAAC,AAACF;IACpB,OAAO;QACL,IAAI,CAACG,MAAMC,OAAO,CAACL,MAAMC,MAAM,GAAG;YAChC,MAAM,qBAEL,CAFK,IAAIC,MACR,iHADI,qBAAA;uBAAA;4BAAA;8BAAA;YAEN;QACF;QAEA,OAAOF,MAAMC,MAAM;IACrB;AACF,EAAC;AAED,OAAO,eAAeK,eACpBC,EAAuB,EACvBC,QAAiB;IAEjB,MAAM,EAAEC,EAAE,EAAEC,KAAK,EAAE,GAAGH;IACtB,OAAQG,MAAMC,IAAI;QAChB,KAAKjB;QACL,KAAKC;YAA4B;gBAC/B,MAAMiB,YAAY;oBAChBH;oBACAI,SAAS;oBACTb,OAAOU,MAAMI,MAAM;gBACrB;gBAEA,IAAI,SAAShB,OAAO;oBAClB,MAAMiB,oBAAuC;wBAC3C,GAAGH,SAAS;wBACZ,+DAA+D;wBAC/DX,QAAQe,sBAAsB;4BAC5B,OAAO,MAAMpB,uBACXc,MAAMT,MAAM,EACZJ,eAAea,MAAMI,MAAM,GAC3BN;wBAEJ;oBACF;oBACA,IAAIE,MAAMC,IAAI,KAAKjB,wBAAwB;wBACzCqB,kBAAkBE,oBAAoB,GAAGP,MAAMO,oBAAoB;oBACrE;oBACA,OAAOF;gBACT,OAAO;oBACL,MAAMA,oBAAuC;wBAC3C,GAAGH,SAAS;wBACZ,+DAA+D;wBAC/DX,QAAQ,MAAML,uBACZc,MAAMT,MAAM,EACZJ,eAAea,MAAMI,MAAM,GAC3BN;oBAEJ;oBACA,IAAIE,MAAMC,IAAI,KAAKjB,wBAAwB;wBACzCqB,kBAAkBE,oBAAoB,GAAGP,MAAMO,oBAAoB;oBACrE;oBACA,OAAOF;gBACT;YACF;QACA;YAAS;gBACP;YACLine truncated
|
||||
Generated
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
import { normalizedAssetPrefix } from '../../../../shared/lib/normalized-asset-prefix';
|
||||
function getSocketProtocol(assetPrefix) {
|
||||
let protocol = window.location.protocol;
|
||||
try {
|
||||
// assetPrefix is a url
|
||||
protocol = new URL(assetPrefix).protocol;
|
||||
} catch (e) {}
|
||||
return protocol === 'http:' ? 'ws:' : 'wss:';
|
||||
}
|
||||
export function getSocketUrl(assetPrefix) {
|
||||
const prefix = normalizedAssetPrefix(assetPrefix);
|
||||
const protocol = getSocketProtocol(assetPrefix || '');
|
||||
if (URL.canParse(prefix)) {
|
||||
// since normalized asset prefix is ensured to be a URL format,
|
||||
// we can safely replace the protocol
|
||||
return prefix.replace(/^http/, 'ws');
|
||||
}
|
||||
const { hostname, port } = window.location;
|
||||
return protocol + "//" + hostname + (port ? ":" + port : '') + prefix;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=get-socket-url.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/utils/get-socket-url.ts"],"sourcesContent":["import { normalizedAssetPrefix } from '../../../../shared/lib/normalized-asset-prefix'\n\nfunction getSocketProtocol(assetPrefix: string): string {\n let protocol = window.location.protocol\n\n try {\n // assetPrefix is a url\n protocol = new URL(assetPrefix).protocol\n } catch {}\n\n return protocol === 'http:' ? 'ws:' : 'wss:'\n}\n\nexport function getSocketUrl(assetPrefix: string | undefined): string {\n const prefix = normalizedAssetPrefix(assetPrefix)\n const protocol = getSocketProtocol(assetPrefix || '')\n\n if (URL.canParse(prefix)) {\n // since normalized asset prefix is ensured to be a URL format,\n // we can safely replace the protocol\n return prefix.replace(/^http/, 'ws')\n }\n\n const { hostname, port } = window.location\n return `${protocol}//${hostname}${port ? `:${port}` : ''}${prefix}`\n}\n"],"names":["normalizedAssetPrefix","getSocketProtocol","assetPrefix","protocol","window","location","URL","getSocketUrl","prefix","canParse","replace","hostname","port"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,iDAAgD;AAEtF,SAASC,kBAAkBC,WAAmB;IAC5C,IAAIC,WAAWC,OAAOC,QAAQ,CAACF,QAAQ;IAEvC,IAAI;QACF,uBAAuB;QACvBA,WAAW,IAAIG,IAAIJ,aAAaC,QAAQ;IAC1C,EAAE,UAAM,CAAC;IAET,OAAOA,aAAa,UAAU,QAAQ;AACxC;AAEA,OAAO,SAASI,aAAaL,WAA+B;IAC1D,MAAMM,SAASR,sBAAsBE;IACrC,MAAMC,WAAWF,kBAAkBC,eAAe;IAElD,IAAII,IAAIG,QAAQ,CAACD,SAAS;QACxB,+DAA+D;QAC/D,qCAAqC;QACrC,OAAOA,OAAOE,OAAO,CAAC,SAAS;IACjC;IAEA,MAAM,EAAEC,QAAQ,EAAEC,IAAI,EAAE,GAAGR,OAAOC,QAAQ;IAC1C,OAAO,AAAGF,WAAS,OAAIQ,WAAWC,CAAAA,OAAO,AAAC,MAAGA,OAAS,EAAC,IAAIJ;AAC7D"}
|
||||
Generated
Vendored
+71
@@ -0,0 +1,71 @@
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
import url from 'url';
|
||||
import dataUriToBuffer from 'next/dist/compiled/data-uri-to-buffer';
|
||||
import { getSourceMapUrl } from './get-source-map-url';
|
||||
export async function getSourceMapFromFile(filename) {
|
||||
filename = filename.startsWith('file://') ? url.fileURLToPath(filename) : filename;
|
||||
let fileContents;
|
||||
try {
|
||||
fileContents = await fs.readFile(filename, 'utf-8');
|
||||
} catch (error) {
|
||||
throw Object.defineProperty(new Error("Failed to read file contents of " + filename + ".", {
|
||||
cause: error
|
||||
}), "__NEXT_ERROR_CODE", {
|
||||
value: "E466",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
const sourceUrl = getSourceMapUrl(fileContents);
|
||||
if (!sourceUrl) {
|
||||
return undefined;
|
||||
}
|
||||
if (sourceUrl.startsWith('data:')) {
|
||||
let buffer;
|
||||
try {
|
||||
buffer = dataUriToBuffer(sourceUrl);
|
||||
} catch (error) {
|
||||
throw Object.defineProperty(new Error("Failed to parse source map URL for " + filename + ".", {
|
||||
cause: error
|
||||
}), "__NEXT_ERROR_CODE", {
|
||||
value: "E199",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
if (buffer.type !== 'application/json') {
|
||||
throw Object.defineProperty(new Error("Unknown source map type for " + filename + ": " + buffer.typeFull + "."), "__NEXT_ERROR_CODE", {
|
||||
value: "E113",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
try {
|
||||
return JSON.parse(buffer.toString());
|
||||
} catch (error) {
|
||||
throw Object.defineProperty(new Error("Failed to parse source map for " + filename + ".", {
|
||||
cause: error
|
||||
}), "__NEXT_ERROR_CODE", {
|
||||
value: "E318",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
}
|
||||
const sourceMapFilename = path.resolve(path.dirname(filename), decodeURIComponent(sourceUrl));
|
||||
try {
|
||||
const sourceMapContents = await fs.readFile(sourceMapFilename, 'utf-8');
|
||||
return JSON.parse(sourceMapContents.toString());
|
||||
} catch (error) {
|
||||
throw Object.defineProperty(new Error("Failed to parse source map " + sourceMapFilename + ".", {
|
||||
cause: error
|
||||
}), "__NEXT_ERROR_CODE", {
|
||||
value: "E220",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=get-source-map-from-file.js.map
|
||||
node_modules/next/dist/esm/client/components/react-dev-overlay/utils/get-source-map-from-file.js.map
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/utils/get-source-map-from-file.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'path'\nimport url from 'url'\nimport type { RawSourceMap } from 'next/dist/compiled/source-map08'\nimport dataUriToBuffer from 'next/dist/compiled/data-uri-to-buffer'\nimport { getSourceMapUrl } from './get-source-map-url'\n\nexport async function getSourceMapFromFile(\n filename: string\n): Promise<RawSourceMap | undefined> {\n filename = filename.startsWith('file://')\n ? url.fileURLToPath(filename)\n : filename\n\n let fileContents: string\n\n try {\n fileContents = await fs.readFile(filename, 'utf-8')\n } catch (error) {\n throw new Error(`Failed to read file contents of ${filename}.`, {\n cause: error,\n })\n }\n\n const sourceUrl = getSourceMapUrl(fileContents)\n\n if (!sourceUrl) {\n return undefined\n }\n\n if (sourceUrl.startsWith('data:')) {\n let buffer: dataUriToBuffer.MimeBuffer\n\n try {\n buffer = dataUriToBuffer(sourceUrl)\n } catch (error) {\n throw new Error(`Failed to parse source map URL for ${filename}.`, {\n cause: error,\n })\n }\n\n if (buffer.type !== 'application/json') {\n throw new Error(\n `Unknown source map type for ${filename}: ${buffer.typeFull}.`\n )\n }\n\n try {\n return JSON.parse(buffer.toString())\n } catch (error) {\n throw new Error(`Failed to parse source map for ${filename}.`, {\n cause: error,\n })\n }\n }\n\n const sourceMapFilename = path.resolve(\n path.dirname(filename),\n decodeURIComponent(sourceUrl)\n )\n\n try {\n const sourceMapContents = await fs.readFile(sourceMapFilename, 'utf-8')\n\n return JSON.parse(sourceMapContents.toString())\n } catch (error) {\n throw new Error(`Failed to parse source map ${sourceMapFilename}.`, {\n cause: error,\n })\n }\n}\n"],"names":["fs","path","url","dataUriToBuffer","getSourceMapUrl","getSourceMapFromFile","filename","startsWith","fileURLToPath","fileContents","readFile","error","Error","cause","sourceUrl","undefined","buffer","type","typeFull","JSON","parse","toString","sourceMapFilename","resolve","dirname","decodeURIComponent","sourceMapContents"],"mappings":"AAAA,OAAOA,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AACvB,OAAOC,SAAS,MAAK;AAErB,OAAOC,qBAAqB,wCAAuC;AACnE,SAASC,eAAe,QAAQ,uBAAsB;AAEtD,OAAO,eAAeC,qBACpBC,QAAgB;IAEhBA,WAAWA,SAASC,UAAU,CAAC,aAC3BL,IAAIM,aAAa,CAACF,YAClBA;IAEJ,IAAIG;IAEJ,IAAI;QACFA,eAAe,MAAMT,GAAGU,QAAQ,CAACJ,UAAU;IAC7C,EAAE,OAAOK,OAAO;QACd,MAAM,qBAEJ,CAFI,IAAIC,MAAM,AAAC,qCAAkCN,WAAS,KAAI;YAC9DO,OAAOF;QACT,IAFM,qBAAA;mBAAA;wBAAA;0BAAA;QAEL;IACH;IAEA,MAAMG,YAAYV,gBAAgBK;IAElC,IAAI,CAACK,WAAW;QACd,OAAOC;IACT;IAEA,IAAID,UAAUP,UAAU,CAAC,UAAU;QACjC,IAAIS;QAEJ,IAAI;YACFA,SAASb,gBAAgBW;QAC3B,EAAE,OAAOH,OAAO;YACd,MAAM,qBAEJ,CAFI,IAAIC,MAAM,AAAC,wCAAqCN,WAAS,KAAI;gBACjEO,OAAOF;YACT,IAFM,qBAAA;uBAAA;4BAAA;8BAAA;YAEL;QACH;QAEA,IAAIK,OAAOC,IAAI,KAAK,oBAAoB;YACtC,MAAM,qBAEL,CAFK,IAAIL,MACR,AAAC,iCAA8BN,WAAS,OAAIU,OAAOE,QAAQ,GAAC,MADxD,qBAAA;uBAAA;4BAAA;8BAAA;YAEN;QACF;QAEA,IAAI;YACF,OAAOC,KAAKC,KAAK,CAACJ,OAAOK,QAAQ;QACnC,EAAE,OAAOV,OAAO;YACd,MAAM,qBAEJ,CAFI,IAAIC,MAAM,AAAC,oCAAiCN,WAAS,KAAI;gBAC7DO,OAAOF;YACT,IAFM,qBAAA;uBAAA;4BAAA;8BAAA;YAEL;QACH;IACF;IAEA,MAAMW,oBAAoBrB,KAAKsB,OAAO,CACpCtB,KAAKuB,OAAO,CAAClB,WACbmB,mBAAmBX;IAGrB,IAAI;QACF,MAAMY,oBAAoB,MAAM1B,GAAGU,QAAQ,CAACY,mBAAmB;QAE/D,OAAOH,KAAKC,KAAK,CAACM,kBAAkBL,QAAQ;IAC9C,EAAE,OAAOV,OAAO;QACd,MAAM,qBAEJ,CAFI,IAAIC,MAAM,AAAC,gCAA6BU,oBAAkB,KAAI;YAClET,OAAOF;QACT,IAFM,qBAAA;mBAAA;wBAAA;0BAAA;QAEL;IACH;AACF"}
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
export function getSourceMapUrl(fileContents) {
|
||||
const regex = /\/\/[#@] ?sourceMappingURL=([^\s'"]+)\s*$/gm;
|
||||
let match = null;
|
||||
for(;;){
|
||||
let next = regex.exec(fileContents);
|
||||
if (next == null) {
|
||||
break;
|
||||
}
|
||||
match = next;
|
||||
}
|
||||
if (!(match && match[1])) {
|
||||
return null;
|
||||
}
|
||||
return match[1].toString();
|
||||
}
|
||||
|
||||
//# sourceMappingURL=get-source-map-url.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/utils/get-source-map-url.ts"],"sourcesContent":["export function getSourceMapUrl(fileContents: string): string | null {\n const regex = /\\/\\/[#@] ?sourceMappingURL=([^\\s'\"]+)\\s*$/gm\n let match = null\n for (;;) {\n let next = regex.exec(fileContents)\n if (next == null) {\n break\n }\n match = next\n }\n if (!(match && match[1])) {\n return null\n }\n return match[1].toString()\n}\n"],"names":["getSourceMapUrl","fileContents","regex","match","next","exec","toString"],"mappings":"AAAA,OAAO,SAASA,gBAAgBC,YAAoB;IAClD,MAAMC,QAAQ;IACd,IAAIC,QAAQ;IACZ,OAAS;QACP,IAAIC,OAAOF,MAAMG,IAAI,CAACJ;QACtB,IAAIG,QAAQ,MAAM;YAChB;QACF;QACAD,QAAQC;IACV;IACA,IAAI,CAAED,CAAAA,SAASA,KAAK,CAAC,EAAE,AAAD,GAAI;QACxB,OAAO;IACT;IACA,OAAOA,KAAK,CAAC,EAAE,CAACG,QAAQ;AAC1B"}
|
||||
Generated
Vendored
+403
@@ -0,0 +1,403 @@
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/ import { cyan, green, red } from '../../../../lib/picocolors';
|
||||
import child_process from 'child_process';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import shellQuote from 'next/dist/compiled/shell-quote';
|
||||
function isTerminalEditor(editor) {
|
||||
switch(editor){
|
||||
case 'vi':
|
||||
case 'vim':
|
||||
case 'nvim':
|
||||
case 'emacs':
|
||||
case 'nano':
|
||||
{
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
{}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// Map from full process name to binary that starts the process
|
||||
// We can't just re-use full process name, because it will spawn a new instance
|
||||
// of the app every time
|
||||
const COMMON_EDITORS_MACOS = {
|
||||
'/Applications/Atom.app/Contents/MacOS/Atom': 'atom',
|
||||
'/Applications/Atom Beta.app/Contents/MacOS/Atom Beta': '/Applications/Atom Beta.app/Contents/MacOS/Atom Beta',
|
||||
'/Applications/Brackets.app/Contents/MacOS/Brackets': 'brackets',
|
||||
'/Applications/Sublime Text.app/Contents/MacOS/Sublime Text': '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl',
|
||||
'/Applications/Sublime Text Dev.app/Contents/MacOS/Sublime Text': '/Applications/Sublime Text Dev.app/Contents/SharedSupport/bin/subl',
|
||||
'/Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2': '/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl',
|
||||
'/Applications/Visual Studio Code.app/Contents/MacOS/Electron': '/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code',
|
||||
'/Applications/Visual Studio Code - Insiders.app/Contents/MacOS/Electron': '/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code',
|
||||
'/Applications/VSCodium.app/Contents/MacOS/Electron': '/Applications/VSCodium.app/Contents/Resources/app/bin/code',
|
||||
'/Applications/AppCode.app/Contents/MacOS/appcode': '/Applications/AppCode.app/Contents/MacOS/appcode',
|
||||
'/Applications/CLion.app/Contents/MacOS/clion': '/Applications/CLion.app/Contents/MacOS/clion',
|
||||
'/Applications/IntelliJ IDEA.app/Contents/MacOS/idea': '/Applications/IntelliJ IDEA.app/Contents/MacOS/idea',
|
||||
'/Applications/PhpStorm.app/Contents/MacOS/phpstorm': '/Applications/PhpStorm.app/Contents/MacOS/phpstorm',
|
||||
'/Applications/PyCharm.app/Contents/MacOS/pycharm': '/Applications/PyCharm.app/Contents/MacOS/pycharm',
|
||||
'/Applications/PyCharm CE.app/Contents/MacOS/pycharm': '/Applications/PyCharm CE.app/Contents/MacOS/pycharm',
|
||||
'/Applications/RubyMine.app/Contents/MacOS/rubymine': '/Applications/RubyMine.app/Contents/MacOS/rubymine',
|
||||
'/Applications/WebStorm.app/Contents/MacOS/webstorm': '/Applications/WebStorm.app/Contents/MacOS/webstorm',
|
||||
'/Applications/MacVim.app/Contents/MacOS/MacVim': 'mvim',
|
||||
'/Applications/GoLand.app/Contents/MacOS/goland': '/Applications/GoLand.app/Contents/MacOS/goland',
|
||||
'/Applications/Rider.app/Contents/MacOS/rider': '/Applications/Rider.app/Contents/MacOS/rider',
|
||||
'/Applications/Cursor.app/Contents/MacOS/Cursor': '/Applications/Cursor.app/Contents/MacOS/Cursor'
|
||||
};
|
||||
const COMMON_EDITORS_LINUX = {
|
||||
atom: 'atom',
|
||||
Brackets: 'brackets',
|
||||
code: 'code',
|
||||
'code-insiders': 'code-insiders',
|
||||
vscodium: 'vscodium',
|
||||
emacs: 'emacs',
|
||||
gvim: 'gvim',
|
||||
'idea.sh': 'idea',
|
||||
'phpstorm.sh': 'phpstorm',
|
||||
'pycharm.sh': 'pycharm',
|
||||
'rubymine.sh': 'rubymine',
|
||||
sublime_text: 'sublime_text',
|
||||
vim: 'vim',
|
||||
nvim: 'nvim',
|
||||
'webstorm.sh': 'webstorm',
|
||||
'goland.sh': 'goland',
|
||||
'rider.sh': 'rider'
|
||||
};
|
||||
const COMMON_EDITORS_WIN = [
|
||||
'Brackets.exe',
|
||||
'Code.exe',
|
||||
'Code - Insiders.exe',
|
||||
'VSCodium.exe',
|
||||
'atom.exe',
|
||||
'sublime_text.exe',
|
||||
'notepad++.exe',
|
||||
'clion.exe',
|
||||
'clion64.exe',
|
||||
'idea.exe',
|
||||
'idea64.exe',
|
||||
'phpstorm.exe',
|
||||
'phpstorm64.exe',
|
||||
'pycharm.exe',
|
||||
'pycharm64.exe',
|
||||
'rubymine.exe',
|
||||
'rubymine64.exe',
|
||||
'webstorm.exe',
|
||||
'webstorm64.exe',
|
||||
'goland.exe',
|
||||
'goland64.exe',
|
||||
'rider.exe',
|
||||
'rider64.exe'
|
||||
];
|
||||
// Transpiled version of: /^([A-Za-z]:[/\\])?[\p{L}0-9/.\-_\\]+$/u
|
||||
// Non-transpiled version requires support for Unicode property regex. Allows
|
||||
// alphanumeric characters, periods, dashes, slashes, and underscores.
|
||||
const WINDOWS_FILE_NAME_ACCESS_LIST = /^([A-Za-z]:[/\\])?(?:[\x2D-9A-Z\\_a-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEF\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7B9\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-Line truncated
|
||||
function getArgumentsForLineNumber(editor, fileName, lineNumber, colNumber) {
|
||||
const editorBasename = path.basename(editor).replace(/\.(exe|cmd|bat)$/i, '');
|
||||
switch(editorBasename){
|
||||
case 'atom':
|
||||
case 'Atom':
|
||||
case 'Atom Beta':
|
||||
case 'subl':
|
||||
case 'sublime':
|
||||
case 'sublime_text':
|
||||
{
|
||||
return [
|
||||
fileName + ':' + lineNumber + ':' + colNumber
|
||||
];
|
||||
}
|
||||
case 'wstorm':
|
||||
case 'charm':
|
||||
{
|
||||
return [
|
||||
fileName + ':' + lineNumber
|
||||
];
|
||||
}
|
||||
case 'notepad++':
|
||||
{
|
||||
return [
|
||||
'-n' + lineNumber,
|
||||
'-c' + colNumber,
|
||||
fileName
|
||||
];
|
||||
}
|
||||
case 'vim':
|
||||
case 'nvim':
|
||||
case 'mvim':
|
||||
case 'joe':
|
||||
case 'gvim':
|
||||
{
|
||||
return [
|
||||
'+' + lineNumber,
|
||||
fileName
|
||||
];
|
||||
}
|
||||
case 'emacs':
|
||||
case 'emacsclient':
|
||||
{
|
||||
return [
|
||||
'+' + lineNumber + ':' + colNumber,
|
||||
fileName
|
||||
];
|
||||
}
|
||||
case 'rmate':
|
||||
case 'mate':
|
||||
case 'mine':
|
||||
{
|
||||
return [
|
||||
'--line',
|
||||
lineNumber.toString(),
|
||||
fileName
|
||||
];
|
||||
}
|
||||
case 'code':
|
||||
case 'Code':
|
||||
case 'Cursor':
|
||||
case 'code-insiders':
|
||||
case 'Code - Insiders':
|
||||
case 'vscodium':
|
||||
case 'VSCodium':
|
||||
{
|
||||
return [
|
||||
'-g',
|
||||
fileName + ':' + lineNumber + ':' + colNumber
|
||||
];
|
||||
}
|
||||
case 'appcode':
|
||||
case 'clion':
|
||||
case 'clion64':
|
||||
case 'idea':
|
||||
case 'idea64':
|
||||
case 'phpstorm':
|
||||
case 'phpstorm64':
|
||||
case 'pycharm':
|
||||
case 'pycharm64':
|
||||
case 'rubymine':
|
||||
case 'rubymine64':
|
||||
case 'webstorm':
|
||||
case 'webstorm64':
|
||||
case 'goland':
|
||||
case 'goland64':
|
||||
case 'rider':
|
||||
case 'rider64':
|
||||
{
|
||||
return [
|
||||
'--line',
|
||||
lineNumber.toString(),
|
||||
fileName
|
||||
];
|
||||
}
|
||||
default:
|
||||
{
|
||||
// For all others, drop the lineNumber until we have
|
||||
// a mapping above, since providing the lineNumber incorrectly
|
||||
// can result in errors or confusing behavior.
|
||||
return [
|
||||
fileName
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
function guessEditor() {
|
||||
// Explicit config always wins
|
||||
if (process.env.REACT_EDITOR) {
|
||||
return shellQuote.parse(process.env.REACT_EDITOR);
|
||||
}
|
||||
// We can find out which editor is currently running by:
|
||||
// `ps x` on macOS and Linux
|
||||
// `Get-Process` on Windows
|
||||
try {
|
||||
if (process.platform === 'darwin') {
|
||||
const output = child_process.execSync('ps x').toString();
|
||||
const processNames = Object.keys(COMMON_EDITORS_MACOS);
|
||||
for(let i = 0; i < processNames.length; i++){
|
||||
const processName = processNames[i];
|
||||
if (output.indexOf(processName) !== -1) {
|
||||
return [
|
||||
COMMON_EDITORS_MACOS[processName]
|
||||
];
|
||||
}
|
||||
}
|
||||
} else if (process.platform === 'win32') {
|
||||
// Some processes need elevated rights to get its executable path.
|
||||
// Just filter them out upfront. This also saves 10-20ms on the command.
|
||||
const output = child_process.execSync('wmic process where "executablepath is not null" get executablepath').toString();
|
||||
const runningProcesses = output.split('\r\n');
|
||||
for(let i = 0; i < runningProcesses.length; i++){
|
||||
const processPath = runningProcesses[i].trim();
|
||||
const processName = path.basename(processPath);
|
||||
if (COMMON_EDITORS_WIN.indexOf(processName) !== -1) {
|
||||
return [
|
||||
processPath
|
||||
];
|
||||
}
|
||||
}
|
||||
} else if (process.platform === 'linux') {
|
||||
// --no-heading No header line
|
||||
// x List all processes owned by you
|
||||
// -o comm Need only names column
|
||||
const output = child_process.execSync('ps x --no-heading -o comm --sort=comm').toString();
|
||||
const processNames = Object.keys(COMMON_EDITORS_LINUX);
|
||||
for(let i = 0; i < processNames.length; i++){
|
||||
const processName = processNames[i];
|
||||
if (output.indexOf(processName) !== -1) {
|
||||
return [
|
||||
COMMON_EDITORS_LINUX[processName]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// Ignore...
|
||||
}
|
||||
// Last resort, use old skool env vars
|
||||
if (process.env.VISUAL) {
|
||||
return [
|
||||
process.env.VISUAL
|
||||
];
|
||||
} else if (process.env.EDITOR) {
|
||||
return [
|
||||
process.env.EDITOR
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
function printInstructions(fileName, errorMessage) {
|
||||
console.log();
|
||||
console.log(red('Could not open ' + path.basename(fileName) + ' in the editor.'));
|
||||
if (errorMessage) {
|
||||
if (errorMessage[errorMessage.length - 1] !== '.') {
|
||||
errorMessage += '.';
|
||||
}
|
||||
console.log(red('The editor process exited with an error: ' + errorMessage));
|
||||
}
|
||||
console.log();
|
||||
console.log('To set up the editor integration, add something like ' + cyan('REACT_EDITOR=atom') + ' to the ' + green('.env.local') + ' file in your project folder ' + 'and restart the development server.');
|
||||
console.log();
|
||||
}
|
||||
export function escapeApplescriptStringFragment(input) {
|
||||
// The only two special characters in a quoted applescript string are
|
||||
// backslash and double quote. Both are escaped with a preceeding backslash.
|
||||
//
|
||||
// Some whitespace characters (like newlines) can be escaped (as `\n`), but
|
||||
// aren't required to be escaped (so we're not bothering to do that).
|
||||
//
|
||||
// https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_classes.html#//apple_ref/doc/uid/TP40000983-CH1g-BBCIAHJF:~:text=Special%20String%20Characters
|
||||
return input.replaceAll(/[\\"]/g, (original)=>"\\" + original);
|
||||
}
|
||||
export function launchEditor(fileName, lineNumber, colNumber) {
|
||||
if (!fs.existsSync(fileName)) {
|
||||
return;
|
||||
}
|
||||
// Sanitize lineNumber to prevent malicious use on win32
|
||||
// via: https://github.com/nodejs/node/blob/c3bb4b1aa5e907d489619fb43d233c3336bfc03d/lib/child_process.js#L333
|
||||
// and it should be a positive integer
|
||||
if (!(Number.isInteger(lineNumber) && lineNumber > 0)) {
|
||||
return;
|
||||
}
|
||||
// colNumber is optional, but should be a positive integer too
|
||||
// default is 1
|
||||
if (!(Number.isInteger(colNumber) && colNumber > 0)) {
|
||||
colNumber = 1;
|
||||
}
|
||||
let [editor, ...args] = guessEditor();
|
||||
if (!editor) {
|
||||
printInstructions(fileName, null);
|
||||
return;
|
||||
}
|
||||
if (editor.toLowerCase() === 'none') {
|
||||
return;
|
||||
}
|
||||
if (process.platform === 'linux' && fileName.startsWith('/mnt/') && /Microsoft/i.test(os.release())) {
|
||||
// Assume WSL / "Bash on Ubuntu on Windows" is being used, and
|
||||
// that the file exists on the Windows file system.
|
||||
// `os.release()` is "4.4.0-43-Microsoft" in the current release
|
||||
// build of WSL, see: https://github.com/Microsoft/BashOnWindows/issues/423#issuecomment-221627364
|
||||
// When a Windows editor is specified, interop functionality can
|
||||
// handle the path translation, but only if a relative path is used.
|
||||
fileName = path.relative('', fileName);
|
||||
}
|
||||
// cmd.exe on Windows is vulnerable to RCE attacks given a file name of the
|
||||
// form "C:\Users\myusername\Downloads\& curl 172.21.93.52". Use an access list
|
||||
// to validate user-provided file names. This doesn't cover the entire range
|
||||
// of valid file names but should cover almost all of them in practice.
|
||||
if (process.platform === 'win32' && !WINDOWS_FILE_NAME_ACCESS_LIST.test(fileName.trim())) {
|
||||
console.log();
|
||||
console.log(red('Could not open ' + path.basename(fileName) + ' in the editor.'));
|
||||
console.log();
|
||||
console.log('When running on Windows, file names are checked against an access list ' + 'to protect against remote code execution attacks. File names may ' + 'consist only of alphanumeric characters (all languages), periods, ' + 'dashes, slashes, and underscores.');
|
||||
console.log();
|
||||
return;
|
||||
}
|
||||
if (lineNumber) {
|
||||
args = args.concat(getArgumentsForLineNumber(editor, fileName, lineNumber, colNumber));
|
||||
} else {
|
||||
args.push(fileName);
|
||||
}
|
||||
let p = undefined;
|
||||
if (process.platform === 'win32') {
|
||||
// On Windows, launch the editor in a shell because spawn can only
|
||||
// launch .exe files.
|
||||
p = child_process.spawn('cmd.exe', [
|
||||
'/C',
|
||||
editor
|
||||
].concat(args), {
|
||||
stdio: 'inherit',
|
||||
detached: true
|
||||
});
|
||||
} else if (isTerminalEditor(editor)) {
|
||||
if (process.platform === 'darwin') {
|
||||
const escapedScript = escapeApplescriptStringFragment(shellQuote.quote([
|
||||
editor,
|
||||
...args
|
||||
]));
|
||||
p = child_process.spawn('osascript', [
|
||||
'-e',
|
||||
'tell application "Terminal" to do script "' + escapedScript + '"'
|
||||
], {
|
||||
stdio: 'ignore'
|
||||
});
|
||||
} else {
|
||||
printInstructions(fileName, 'Terminal editors can only be used on macOS.');
|
||||
}
|
||||
} else {
|
||||
p = child_process.spawn(editor, args, {
|
||||
stdio: 'inherit'
|
||||
});
|
||||
}
|
||||
if (p) {
|
||||
p.on('exit', function(errorCode) {
|
||||
if (errorCode) {
|
||||
printInstructions(fileName, '(code ' + errorCode + ')');
|
||||
}
|
||||
});
|
||||
p.on('error', function(error) {
|
||||
printInstructions(fileName, error.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=launch-editor.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/utils/launch-editor.ts"],"sourcesContent":["/**\n * MIT License\n *\n * Copyright (c) 2015-present, Facebook, Inc.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\nimport { cyan, green, red } from '../../../../lib/picocolors'\nimport child_process from 'child_process'\nimport fs from 'fs'\nimport os from 'os'\nimport path from 'path'\nimport shellQuote from 'next/dist/compiled/shell-quote'\n\nfunction isTerminalEditor(editor: string) {\n switch (editor) {\n case 'vi':\n case 'vim':\n case 'nvim':\n case 'emacs':\n case 'nano': {\n return true\n }\n default: {\n }\n }\n return false\n}\n\n// Map from full process name to binary that starts the process\n// We can't just re-use full process name, because it will spawn a new instance\n// of the app every time\nconst COMMON_EDITORS_MACOS = {\n '/Applications/Atom.app/Contents/MacOS/Atom': 'atom',\n '/Applications/Atom Beta.app/Contents/MacOS/Atom Beta':\n '/Applications/Atom Beta.app/Contents/MacOS/Atom Beta',\n '/Applications/Brackets.app/Contents/MacOS/Brackets': 'brackets',\n '/Applications/Sublime Text.app/Contents/MacOS/Sublime Text':\n '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl',\n '/Applications/Sublime Text Dev.app/Contents/MacOS/Sublime Text':\n '/Applications/Sublime Text Dev.app/Contents/SharedSupport/bin/subl',\n '/Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2':\n '/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl',\n '/Applications/Visual Studio Code.app/Contents/MacOS/Electron':\n '/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code',\n '/Applications/Visual Studio Code - Insiders.app/Contents/MacOS/Electron':\n '/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code',\n '/Applications/VSCodium.app/Contents/MacOS/Electron':\n '/Applications/VSCodium.app/Contents/Resources/app/bin/code',\n '/Applications/AppCode.app/Contents/MacOS/appcode':\n '/Applications/AppCode.app/Contents/MacOS/appcode',\n '/Applications/CLion.app/Contents/MacOS/clion':\n '/Applications/CLion.app/Contents/MacOS/clion',\n '/Applications/IntelliJ IDEA.app/Contents/MacOS/idea':\n '/Applications/IntelliJ IDEA.app/Contents/MacOS/idea',\n '/Applications/PhpStorm.app/Contents/MacOS/phpstorm':\n '/Applications/PhpStorm.app/Contents/MacOS/phpstorm',\n '/Applications/PyCharm.app/Contents/MacOS/pycharm':\n '/Applications/PyCharm.app/Contents/MacOS/pycharm',\n '/Applications/PyCharm CE.app/Contents/MacOS/pycharm':\n '/Applications/PyCharm CE.app/Contents/MacOS/pycharm',\n '/Applications/RubyMine.app/Contents/MacOS/rubymine':\n '/Applications/RubyMine.app/Contents/MacOS/rubymine',\n '/Applications/WebStorm.app/Contents/MacOS/webstorm':\n '/Applications/WebStorm.app/Contents/MacOS/webstorm',\n '/Applications/MacVim.app/Contents/MacOS/MacVim': 'mvim',\n '/Applications/GoLand.app/Contents/MacOS/goland':\n '/Applications/GoLand.app/Contents/MacOS/goland',\n '/Applications/Rider.app/Contents/MacOS/rider':\n '/Applications/Rider.app/Contents/MacOS/rider',\n '/Applications/Cursor.app/Contents/MacOS/Cursor':\n '/Applications/Cursor.app/Contents/MacOS/Cursor',\n}\n\nconst COMMON_EDITORS_LINUX = {\n atom: 'atom',\n Brackets: 'brackets',\n code: 'code',\n 'code-insiders': 'code-insiders',\n vscodium: 'vscodium',\n emacs: 'emacs',\n gvim: 'gvim',\n 'idea.sh': 'idea',\n 'phpstorm.sh': 'phpstorm',\n 'pycharm.sh': 'pycharm',\n 'rubymine.sh': 'rubymine',\n sublime_text: 'sublime_text',\n vim: 'vim',\n nvim: 'nvim',\n 'webstorm.sh': 'webstorm',\n 'goland.sh': 'goland',\n 'rider.sh': 'rider',\n}\n\nconst COMMON_EDITORS_WIN = [\n 'Brackets.exe',\n 'Code.exe',\n 'Code - Insiders.exe',\n 'VSCodium.exe',\n 'atom.exe',\n 'sublime_text.exe',\n 'notepad++.exe',\n 'clion.exe',\n Line truncated
|
||||
Generated
Vendored
+62
@@ -0,0 +1,62 @@
|
||||
import { parse } from 'next/dist/compiled/stacktrace-parser';
|
||||
import { decorateServerError } from '../../../../shared/lib/error-source';
|
||||
export function getFilesystemFrame(frame) {
|
||||
const f = {
|
||||
...frame
|
||||
};
|
||||
if (typeof f.file === 'string') {
|
||||
if (// Posix:
|
||||
f.file.startsWith('/') || // Win32:
|
||||
/^[a-z]:\\/i.test(f.file) || // Win32 UNC:
|
||||
f.file.startsWith('\\\\')) {
|
||||
f.file = "file://" + f.file;
|
||||
}
|
||||
}
|
||||
return f;
|
||||
}
|
||||
export function getServerError(error, type) {
|
||||
if (error.name === 'TurbopackInternalError') {
|
||||
// If this is an internal Turbopack error we shouldn't show internal details
|
||||
// to the user. These are written to a log file instead.
|
||||
const turbopackInternalError = Object.defineProperty(new Error('An unexpected Turbopack error occurred. Please see the output of `next dev` for more details.'), "__NEXT_ERROR_CODE", {
|
||||
value: "E167",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
decorateServerError(turbopackInternalError, type);
|
||||
return turbopackInternalError;
|
||||
}
|
||||
let n;
|
||||
try {
|
||||
throw Object.defineProperty(new Error(error.message), "__NEXT_ERROR_CODE", {
|
||||
value: "E394",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
} catch (e) {
|
||||
n = e;
|
||||
}
|
||||
n.name = error.name;
|
||||
try {
|
||||
n.stack = n.toString() + "\n" + parse(error.stack).map(getFilesystemFrame).map((f)=>{
|
||||
let str = " at " + f.methodName;
|
||||
if (f.file) {
|
||||
let loc = f.file;
|
||||
if (f.lineNumber) {
|
||||
loc += ":" + f.lineNumber;
|
||||
if (f.column) {
|
||||
loc += ":" + f.column;
|
||||
}
|
||||
}
|
||||
str += " (" + loc + ")";
|
||||
}
|
||||
return str;
|
||||
}).join('\n');
|
||||
} catch (e) {
|
||||
n.stack = error.stack;
|
||||
}
|
||||
decorateServerError(n, type);
|
||||
return n;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=node-stack-frames.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/utils/node-stack-frames.ts"],"sourcesContent":["import { parse } from 'next/dist/compiled/stacktrace-parser'\nimport type { StackFrame } from 'next/dist/compiled/stacktrace-parser'\nimport {\n decorateServerError,\n type ErrorSourceType,\n} from '../../../../shared/lib/error-source'\n\nexport function getFilesystemFrame(frame: StackFrame): StackFrame {\n const f: StackFrame = { ...frame }\n\n if (typeof f.file === 'string') {\n if (\n // Posix:\n f.file.startsWith('/') ||\n // Win32:\n /^[a-z]:\\\\/i.test(f.file) ||\n // Win32 UNC:\n f.file.startsWith('\\\\\\\\')\n ) {\n f.file = `file://${f.file}`\n }\n }\n\n return f\n}\n\nexport function getServerError(error: Error, type: ErrorSourceType): Error {\n if (error.name === 'TurbopackInternalError') {\n // If this is an internal Turbopack error we shouldn't show internal details\n // to the user. These are written to a log file instead.\n const turbopackInternalError = new Error(\n 'An unexpected Turbopack error occurred. Please see the output of `next dev` for more details.'\n )\n decorateServerError(turbopackInternalError, type)\n return turbopackInternalError\n }\n\n let n: Error\n try {\n throw new Error(error.message)\n } catch (e) {\n n = e as Error\n }\n\n n.name = error.name\n try {\n n.stack = `${n.toString()}\\n${parse(error.stack!)\n .map(getFilesystemFrame)\n .map((f) => {\n let str = ` at ${f.methodName}`\n if (f.file) {\n let loc = f.file\n if (f.lineNumber) {\n loc += `:${f.lineNumber}`\n if (f.column) {\n loc += `:${f.column}`\n }\n }\n str += ` (${loc})`\n }\n return str\n })\n .join('\\n')}`\n } catch {\n n.stack = error.stack\n }\n\n decorateServerError(n, type)\n return n\n}\n"],"names":["parse","decorateServerError","getFilesystemFrame","frame","f","file","startsWith","test","getServerError","error","type","name","turbopackInternalError","Error","n","message","e","stack","toString","map","str","methodName","loc","lineNumber","column","join"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uCAAsC;AAE5D,SACEC,mBAAmB,QAEd,sCAAqC;AAE5C,OAAO,SAASC,mBAAmBC,KAAiB;IAClD,MAAMC,IAAgB;QAAE,GAAGD,KAAK;IAAC;IAEjC,IAAI,OAAOC,EAAEC,IAAI,KAAK,UAAU;QAC9B,IACE,SAAS;QACTD,EAAEC,IAAI,CAACC,UAAU,CAAC,QAClB,SAAS;QACT,aAAaC,IAAI,CAACH,EAAEC,IAAI,KACxB,aAAa;QACbD,EAAEC,IAAI,CAACC,UAAU,CAAC,SAClB;YACAF,EAAEC,IAAI,GAAG,AAAC,YAASD,EAAEC,IAAI;QAC3B;IACF;IAEA,OAAOD;AACT;AAEA,OAAO,SAASI,eAAeC,KAAY,EAAEC,IAAqB;IAChE,IAAID,MAAME,IAAI,KAAK,0BAA0B;QAC3C,4EAA4E;QAC5E,wDAAwD;QACxD,MAAMC,yBAAyB,qBAE9B,CAF8B,IAAIC,MACjC,kGAD6B,qBAAA;mBAAA;wBAAA;0BAAA;QAE/B;QACAZ,oBAAoBW,wBAAwBF;QAC5C,OAAOE;IACT;IAEA,IAAIE;IACJ,IAAI;QACF,MAAM,qBAAwB,CAAxB,IAAID,MAAMJ,MAAMM,OAAO,GAAvB,qBAAA;mBAAA;wBAAA;0BAAA;QAAuB;IAC/B,EAAE,OAAOC,GAAG;QACVF,IAAIE;IACN;IAEAF,EAAEH,IAAI,GAAGF,MAAME,IAAI;IACnB,IAAI;QACFG,EAAEG,KAAK,GAAG,AAAGH,EAAEI,QAAQ,KAAG,OAAIlB,MAAMS,MAAMQ,KAAK,EAC5CE,GAAG,CAACjB,oBACJiB,GAAG,CAAC,CAACf;YACJ,IAAIgB,MAAM,AAAC,YAAShB,EAAEiB,UAAU;YAChC,IAAIjB,EAAEC,IAAI,EAAE;gBACV,IAAIiB,MAAMlB,EAAEC,IAAI;gBAChB,IAAID,EAAEmB,UAAU,EAAE;oBAChBD,OAAO,AAAC,MAAGlB,EAAEmB,UAAU;oBACvB,IAAInB,EAAEoB,MAAM,EAAE;wBACZF,OAAO,AAAC,MAAGlB,EAAEoB,MAAM;oBACrB;gBACF;gBACAJ,OAAO,AAAC,OAAIE,MAAI;YAClB;YACA,OAAOF;QACT,GACCK,IAAI,CAAC;IACV,EAAE,UAAM;QACNX,EAAEG,KAAK,GAAGR,MAAMQ,KAAK;IACvB;IAEAhB,oBAAoBa,GAAGJ;IACvB,OAAOI;AACT"}
|
||||
Generated
Vendored
+83
@@ -0,0 +1,83 @@
|
||||
var LocationType = /*#__PURE__*/ function(LocationType) {
|
||||
LocationType["FILE"] = "file";
|
||||
LocationType["WEBPACK_INTERNAL"] = "webpack-internal";
|
||||
LocationType["HTTP"] = "http";
|
||||
LocationType["PROTOCOL_RELATIVE"] = "protocol-relative";
|
||||
LocationType["UNKNOWN"] = "unknown";
|
||||
return LocationType;
|
||||
}(LocationType || {});
|
||||
/**
|
||||
* Get the type of frame line based on the location
|
||||
*/ function getLocationType(location) {
|
||||
if (location.startsWith('file://')) {
|
||||
return "file";
|
||||
}
|
||||
if (location.includes('webpack-internal://')) {
|
||||
return "webpack-internal";
|
||||
}
|
||||
if (location.startsWith('http://') || location.startsWith('https://')) {
|
||||
return "http";
|
||||
}
|
||||
if (location.startsWith('//')) {
|
||||
return "protocol-relative";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
function parseStackFrameLocation(location) {
|
||||
const locationType = getLocationType(location);
|
||||
const modulePath = location == null ? void 0 : location.replace(/^(webpack-internal:\/\/\/|file:\/\/)(\(.*\)\/)?/, '');
|
||||
var _modulePath_match;
|
||||
const [, file, lineNumber, column] = (_modulePath_match = modulePath == null ? void 0 : modulePath.match(/^(.+):(\d+):(\d+)/)) != null ? _modulePath_match : [];
|
||||
switch(locationType){
|
||||
case "file":
|
||||
case "webpack-internal":
|
||||
return {
|
||||
canOpenInEditor: true,
|
||||
file,
|
||||
lineNumber: lineNumber ? Number(lineNumber) : undefined,
|
||||
column: column ? Number(column) : undefined
|
||||
};
|
||||
// When the location is a URL we only show the file
|
||||
// TODO: Resolve http(s) URLs through sourcemaps
|
||||
case "http":
|
||||
case "protocol-relative":
|
||||
case "unknown":
|
||||
default:
|
||||
{
|
||||
return {
|
||||
canOpenInEditor: false
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
export function parseComponentStack(componentStack) {
|
||||
const componentStackFrames = [];
|
||||
for (const line of componentStack.trim().split('\n')){
|
||||
// TODO: support safari stack trace
|
||||
// Get component and file from the component stack line
|
||||
const match = /at ([^ ]+)( \((.*)\))?/.exec(line);
|
||||
if (match == null ? void 0 : match[1]) {
|
||||
const component = match[1];
|
||||
const location = match[3];
|
||||
if (!location) {
|
||||
componentStackFrames.push({
|
||||
canOpenInEditor: false,
|
||||
component
|
||||
});
|
||||
continue;
|
||||
}
|
||||
// Stop parsing the component stack if we reach a Next.js component
|
||||
if (location == null ? void 0 : location.includes('next/dist')) {
|
||||
break;
|
||||
}
|
||||
const frameLocation = parseStackFrameLocation(location);
|
||||
componentStackFrames.push({
|
||||
component,
|
||||
...frameLocation
|
||||
});
|
||||
}
|
||||
}
|
||||
return componentStackFrames;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=parse-component-stack.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/utils/parse-component-stack.ts"],"sourcesContent":["export type ComponentStackFrame = {\n canOpenInEditor: boolean\n component: string\n file?: string\n lineNumber?: number\n column?: number\n}\n\nenum LocationType {\n FILE = 'file',\n WEBPACK_INTERNAL = 'webpack-internal',\n HTTP = 'http',\n PROTOCOL_RELATIVE = 'protocol-relative',\n UNKNOWN = 'unknown',\n}\n\n/**\n * Get the type of frame line based on the location\n */\nfunction getLocationType(location: string): LocationType {\n if (location.startsWith('file://')) {\n return LocationType.FILE\n }\n if (location.includes('webpack-internal://')) {\n return LocationType.WEBPACK_INTERNAL\n }\n if (location.startsWith('http://') || location.startsWith('https://')) {\n return LocationType.HTTP\n }\n if (location.startsWith('//')) {\n return LocationType.PROTOCOL_RELATIVE\n }\n return LocationType.UNKNOWN\n}\n\nfunction parseStackFrameLocation(\n location: string\n): Omit<ComponentStackFrame, 'component'> {\n const locationType = getLocationType(location)\n\n const modulePath = location?.replace(\n /^(webpack-internal:\\/\\/\\/|file:\\/\\/)(\\(.*\\)\\/)?/,\n ''\n )\n const [, file, lineNumber, column] =\n modulePath?.match(/^(.+):(\\d+):(\\d+)/) ?? []\n\n switch (locationType) {\n case LocationType.FILE:\n case LocationType.WEBPACK_INTERNAL:\n return {\n canOpenInEditor: true,\n file,\n lineNumber: lineNumber ? Number(lineNumber) : undefined,\n column: column ? Number(column) : undefined,\n }\n // When the location is a URL we only show the file\n // TODO: Resolve http(s) URLs through sourcemaps\n case LocationType.HTTP:\n case LocationType.PROTOCOL_RELATIVE:\n case LocationType.UNKNOWN:\n default: {\n return {\n canOpenInEditor: false,\n }\n }\n }\n}\n\nexport function parseComponentStack(\n componentStack: string\n): ComponentStackFrame[] {\n const componentStackFrames: ComponentStackFrame[] = []\n for (const line of componentStack.trim().split('\\n')) {\n // TODO: support safari stack trace\n // Get component and file from the component stack line\n const match = /at ([^ ]+)( \\((.*)\\))?/.exec(line)\n if (match?.[1]) {\n const component = match[1]\n const location = match[3]\n\n if (!location) {\n componentStackFrames.push({\n canOpenInEditor: false,\n component,\n })\n continue\n }\n\n // Stop parsing the component stack if we reach a Next.js component\n if (location?.includes('next/dist')) {\n break\n }\n\n const frameLocation = parseStackFrameLocation(location)\n componentStackFrames.push({\n component,\n ...frameLocation,\n })\n }\n }\n\n return componentStackFrames\n}\n"],"names":["LocationType","getLocationType","location","startsWith","includes","parseStackFrameLocation","locationType","modulePath","replace","file","lineNumber","column","match","canOpenInEditor","Number","undefined","parseComponentStack","componentStack","componentStackFrames","line","trim","split","exec","component","push","frameLocation"],"mappings":"AAQA,IAAA,AAAKA,sCAAAA;;;;;;WAAAA;EAAAA;AAQL;;CAEC,GACD,SAASC,gBAAgBC,QAAgB;IACvC,IAAIA,SAASC,UAAU,CAAC,YAAY;QAClC;IACF;IACA,IAAID,SAASE,QAAQ,CAAC,wBAAwB;QAC5C;IACF;IACA,IAAIF,SAASC,UAAU,CAAC,cAAcD,SAASC,UAAU,CAAC,aAAa;QACrE;IACF;IACA,IAAID,SAASC,UAAU,CAAC,OAAO;QAC7B;IACF;IACA;AACF;AAEA,SAASE,wBACPH,QAAgB;IAEhB,MAAMI,eAAeL,gBAAgBC;IAErC,MAAMK,aAAaL,4BAAAA,SAAUM,OAAO,CAClC,mDACA;QAGAD;IADF,MAAM,GAAGE,MAAMC,YAAYC,OAAO,GAChCJ,CAAAA,oBAAAA,8BAAAA,WAAYK,KAAK,CAAC,gCAAlBL,oBAA0C,EAAE;IAE9C,OAAQD;QACN;QACA;YACE,OAAO;gBACLO,iBAAiB;gBACjBJ;gBACAC,YAAYA,aAAaI,OAAOJ,cAAcK;gBAC9CJ,QAAQA,SAASG,OAAOH,UAAUI;YACpC;QACF,mDAAmD;QACnD,gDAAgD;QAChD;QACA;QACA;QACA;YAAS;gBACP,OAAO;oBACLF,iBAAiB;gBACnB;YACF;IACF;AACF;AAEA,OAAO,SAASG,oBACdC,cAAsB;IAEtB,MAAMC,uBAA8C,EAAE;IACtD,KAAK,MAAMC,QAAQF,eAAeG,IAAI,GAAGC,KAAK,CAAC,MAAO;QACpD,mCAAmC;QACnC,uDAAuD;QACvD,MAAMT,QAAQ,yBAAyBU,IAAI,CAACH;QAC5C,IAAIP,yBAAAA,KAAO,CAAC,EAAE,EAAE;YACd,MAAMW,YAAYX,KAAK,CAAC,EAAE;YAC1B,MAAMV,WAAWU,KAAK,CAAC,EAAE;YAEzB,IAAI,CAACV,UAAU;gBACbgB,qBAAqBM,IAAI,CAAC;oBACxBX,iBAAiB;oBACjBU;gBACF;gBACA;YACF;YAEA,mEAAmE;YACnE,IAAIrB,4BAAAA,SAAUE,QAAQ,CAAC,cAAc;gBACnC;YACF;YAEA,MAAMqB,gBAAgBpB,wBAAwBH;YAC9CgB,qBAAqBM,IAAI,CAAC;gBACxBD;gBACA,GAAGE,aAAa;YAClB;QACF;IACF;IAEA,OAAOP;AACT"}
|
||||
Generated
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
import { parse } from 'next/dist/compiled/stacktrace-parser';
|
||||
import { getHydrationErrorStackInfo, isReactHydrationErrorMessage } from '../../is-hydration-error';
|
||||
const regexNextStatic = /\/_next(\/static\/.+)/;
|
||||
export function parseStack(stack) {
|
||||
if (!stack) return [];
|
||||
const messageAndStack = stack.replace(/^Error: /, '');
|
||||
if (isReactHydrationErrorMessage(messageAndStack)) {
|
||||
const { stack: parsedStack } = getHydrationErrorStackInfo(messageAndStack);
|
||||
if (parsedStack) {
|
||||
stack = parsedStack;
|
||||
}
|
||||
}
|
||||
// throw away eval information that stacktrace-parser doesn't support
|
||||
// adapted from https://github.com/stacktracejs/error-stack-parser/blob/9f33c224b5d7b607755eb277f9d51fcdb7287e24/error-stack-parser.js#L59C33-L59C62
|
||||
stack = stack.split('\n').map((line)=>{
|
||||
if (line.includes('(eval ')) {
|
||||
line = line.replace(/eval code/g, 'eval').replace(/\(eval at [^()]* \(/, '(file://').replace(/\),.*$/g, ')');
|
||||
}
|
||||
return line;
|
||||
}).join('\n');
|
||||
const frames = parse(stack);
|
||||
return frames.map((frame)=>{
|
||||
try {
|
||||
const url = new URL(frame.file);
|
||||
const res = regexNextStatic.exec(url.pathname);
|
||||
if (res) {
|
||||
var _process_env___NEXT_DIST_DIR_replace, _process_env___NEXT_DIST_DIR;
|
||||
const distDir = (_process_env___NEXT_DIST_DIR = process.env.__NEXT_DIST_DIR) == null ? void 0 : (_process_env___NEXT_DIST_DIR_replace = _process_env___NEXT_DIST_DIR.replace(/\\/g, '/')) == null ? void 0 : _process_env___NEXT_DIST_DIR_replace.replace(/\/$/, '');
|
||||
if (distDir) {
|
||||
frame.file = 'file://' + distDir.concat(res.pop()) + url.search;
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
return frame;
|
||||
});
|
||||
}
|
||||
|
||||
//# sourceMappingURL=parse-stack.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/utils/parse-stack.ts"],"sourcesContent":["import { parse } from 'next/dist/compiled/stacktrace-parser'\nimport type { StackFrame } from 'next/dist/compiled/stacktrace-parser'\nimport {\n getHydrationErrorStackInfo,\n isReactHydrationErrorMessage,\n} from '../../is-hydration-error'\n\nconst regexNextStatic = /\\/_next(\\/static\\/.+)/\n\nexport function parseStack(stack: string | undefined): StackFrame[] {\n if (!stack) return []\n const messageAndStack = stack.replace(/^Error: /, '')\n if (isReactHydrationErrorMessage(messageAndStack)) {\n const { stack: parsedStack } = getHydrationErrorStackInfo(messageAndStack)\n if (parsedStack) {\n stack = parsedStack\n }\n }\n\n // throw away eval information that stacktrace-parser doesn't support\n // adapted from https://github.com/stacktracejs/error-stack-parser/blob/9f33c224b5d7b607755eb277f9d51fcdb7287e24/error-stack-parser.js#L59C33-L59C62\n stack = stack\n .split('\\n')\n .map((line) => {\n if (line.includes('(eval ')) {\n line = line\n .replace(/eval code/g, 'eval')\n .replace(/\\(eval at [^()]* \\(/, '(file://')\n .replace(/\\),.*$/g, ')')\n }\n\n return line\n })\n .join('\\n')\n\n const frames = parse(stack)\n return frames.map((frame) => {\n try {\n const url = new URL(frame.file!)\n const res = regexNextStatic.exec(url.pathname)\n if (res) {\n const distDir = process.env.__NEXT_DIST_DIR\n ?.replace(/\\\\/g, '/')\n ?.replace(/\\/$/, '')\n if (distDir) {\n frame.file = 'file://' + distDir.concat(res.pop()!) + url.search\n }\n }\n } catch {}\n return frame\n })\n}\n"],"names":["parse","getHydrationErrorStackInfo","isReactHydrationErrorMessage","regexNextStatic","parseStack","stack","messageAndStack","replace","parsedStack","split","map","line","includes","join","frames","frame","url","URL","file","res","exec","pathname","process","distDir","env","__NEXT_DIST_DIR","concat","pop","search"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uCAAsC;AAE5D,SACEC,0BAA0B,EAC1BC,4BAA4B,QACvB,2BAA0B;AAEjC,MAAMC,kBAAkB;AAExB,OAAO,SAASC,WAAWC,KAAyB;IAClD,IAAI,CAACA,OAAO,OAAO,EAAE;IACrB,MAAMC,kBAAkBD,MAAME,OAAO,CAAC,YAAY;IAClD,IAAIL,6BAA6BI,kBAAkB;QACjD,MAAM,EAAED,OAAOG,WAAW,EAAE,GAAGP,2BAA2BK;QAC1D,IAAIE,aAAa;YACfH,QAAQG;QACV;IACF;IAEA,qEAAqE;IACrE,oJAAoJ;IACpJH,QAAQA,MACLI,KAAK,CAAC,MACNC,GAAG,CAAC,CAACC;QACJ,IAAIA,KAAKC,QAAQ,CAAC,WAAW;YAC3BD,OAAOA,KACJJ,OAAO,CAAC,cAAc,QACtBA,OAAO,CAAC,uBAAuB,YAC/BA,OAAO,CAAC,WAAW;QACxB;QAEA,OAAOI;IACT,GACCE,IAAI,CAAC;IAER,MAAMC,SAASd,MAAMK;IACrB,OAAOS,OAAOJ,GAAG,CAAC,CAACK;QACjB,IAAI;YACF,MAAMC,MAAM,IAAIC,IAAIF,MAAMG,IAAI;YAC9B,MAAMC,MAAMhB,gBAAgBiB,IAAI,CAACJ,IAAIK,QAAQ;YAC7C,IAAIF,KAAK;oBACSG,sCAAAA;gBAAhB,MAAMC,WAAUD,+BAAAA,QAAQE,GAAG,CAACC,eAAe,sBAA3BH,uCAAAA,6BACZf,OAAO,CAAC,OAAO,yBADHe,qCAEZf,OAAO,CAAC,OAAO;gBACnB,IAAIgB,SAAS;oBACXR,MAAMG,IAAI,GAAG,YAAYK,QAAQG,MAAM,CAACP,IAAIQ,GAAG,MAAOX,IAAIY,MAAM;gBAClE;YACF;QACF,EAAE,UAAM,CAAC;QACT,OAAOb;IACT;AACF"}
|
||||
Generated
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Logs information about a completed HMR to the console, the server (via a
|
||||
* `client-hmr-latency` event), and to `self.__NEXT_HMR_LATENCY_CB` (a debugging
|
||||
* hook).
|
||||
*
|
||||
* @param hasUpdate Set this to `false` to avoid reporting the HMR event via a
|
||||
* `client-hmr-latency` event or to `self.__NEXT_HMR_LATENCY_CB`. Used by
|
||||
* turbopack when we must report a message to the browser console (because we
|
||||
* already logged a "rebuilding" message), but it's not a real HMR, so we
|
||||
* don't want to impact our telemetry.
|
||||
*/ export default function reportHmrLatency(sendMessage, updatedModules, startMsSinceEpoch, endMsSinceEpoch, hasUpdate) {
|
||||
if (hasUpdate === void 0) hasUpdate = true;
|
||||
const latencyMs = endMsSinceEpoch - startMsSinceEpoch;
|
||||
console.log("[Fast Refresh] done in " + latencyMs + "ms");
|
||||
if (!hasUpdate) {
|
||||
return;
|
||||
}
|
||||
sendMessage(JSON.stringify({
|
||||
event: 'client-hmr-latency',
|
||||
id: window.__nextDevClientId,
|
||||
startTime: startMsSinceEpoch,
|
||||
endTime: endMsSinceEpoch,
|
||||
page: window.location.pathname,
|
||||
updatedModules,
|
||||
// Whether the page (tab) was hidden at the time the event occurred.
|
||||
// This can impact the accuracy of the event's timing.
|
||||
isPageHidden: document.visibilityState === 'hidden'
|
||||
}));
|
||||
if (self.__NEXT_HMR_LATENCY_CB) {
|
||||
self.__NEXT_HMR_LATENCY_CB(latencyMs);
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=report-hmr-latency.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/utils/report-hmr-latency.ts"],"sourcesContent":["declare global {\n interface Window {\n __NEXT_HMR_LATENCY_CB: ((latencyMs: number) => void) | undefined\n }\n}\n\n/**\n * Logs information about a completed HMR to the console, the server (via a\n * `client-hmr-latency` event), and to `self.__NEXT_HMR_LATENCY_CB` (a debugging\n * hook).\n *\n * @param hasUpdate Set this to `false` to avoid reporting the HMR event via a\n * `client-hmr-latency` event or to `self.__NEXT_HMR_LATENCY_CB`. Used by\n * turbopack when we must report a message to the browser console (because we\n * already logged a \"rebuilding\" message), but it's not a real HMR, so we\n * don't want to impact our telemetry.\n */\nexport default function reportHmrLatency(\n sendMessage: (message: string) => void,\n updatedModules: ReadonlyArray<string | number>,\n startMsSinceEpoch: number,\n endMsSinceEpoch: number,\n hasUpdate: boolean = true\n) {\n const latencyMs = endMsSinceEpoch - startMsSinceEpoch\n console.log(`[Fast Refresh] done in ${latencyMs}ms`)\n if (!hasUpdate) {\n return\n }\n sendMessage(\n JSON.stringify({\n event: 'client-hmr-latency',\n id: window.__nextDevClientId,\n startTime: startMsSinceEpoch,\n endTime: endMsSinceEpoch,\n page: window.location.pathname,\n updatedModules,\n // Whether the page (tab) was hidden at the time the event occurred.\n // This can impact the accuracy of the event's timing.\n isPageHidden: document.visibilityState === 'hidden',\n })\n )\n if (self.__NEXT_HMR_LATENCY_CB) {\n self.__NEXT_HMR_LATENCY_CB(latencyMs)\n }\n}\n"],"names":["reportHmrLatency","sendMessage","updatedModules","startMsSinceEpoch","endMsSinceEpoch","hasUpdate","latencyMs","console","log","JSON","stringify","event","id","window","__nextDevClientId","startTime","endTime","page","location","pathname","isPageHidden","document","visibilityState","self","__NEXT_HMR_LATENCY_CB"],"mappings":"AAMA;;;;;;;;;;CAUC,GACD,eAAe,SAASA,iBACtBC,WAAsC,EACtCC,cAA8C,EAC9CC,iBAAyB,EACzBC,eAAuB,EACvBC,SAAyB;IAAzBA,IAAAA,sBAAAA,YAAqB;IAErB,MAAMC,YAAYF,kBAAkBD;IACpCI,QAAQC,GAAG,CAAC,AAAC,4BAAyBF,YAAU;IAChD,IAAI,CAACD,WAAW;QACd;IACF;IACAJ,YACEQ,KAAKC,SAAS,CAAC;QACbC,OAAO;QACPC,IAAIC,OAAOC,iBAAiB;QAC5BC,WAAWZ;QACXa,SAASZ;QACTa,MAAMJ,OAAOK,QAAQ,CAACC,QAAQ;QAC9BjB;QACA,oEAAoE;QACpE,sDAAsD;QACtDkB,cAAcC,SAASC,eAAe,KAAK;IAC7C;IAEF,IAAIC,KAAKC,qBAAqB,EAAE;QAC9BD,KAAKC,qBAAqB,CAAClB;IAC7B;AACF"}
|
||||
Generated
Vendored
+124
@@ -0,0 +1,124 @@
|
||||
import { isWebpackInternalResource, formatFrameSourceFile } from './webpack-module-path';
|
||||
function getOriginalStackFrame(source, response) {
|
||||
var _source_file;
|
||||
async function _getOriginalStackFrame() {
|
||||
var _body_originalStackFrame;
|
||||
if (response.status === 'rejected') {
|
||||
throw Object.defineProperty(new Error(response.reason), "__NEXT_ERROR_CODE", {
|
||||
value: "E394",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
const body = response.value;
|
||||
return {
|
||||
error: false,
|
||||
reason: null,
|
||||
external: false,
|
||||
sourceStackFrame: source,
|
||||
originalStackFrame: body.originalStackFrame,
|
||||
originalCodeFrame: body.originalCodeFrame || null,
|
||||
ignored: ((_body_originalStackFrame = body.originalStackFrame) == null ? void 0 : _body_originalStackFrame.ignored) || false
|
||||
};
|
||||
}
|
||||
// TODO: merge this section into ignoredList handling
|
||||
if (source.file === 'file://' || ((_source_file = source.file) == null ? void 0 : _source_file.match(/https?:\/\//))) {
|
||||
return Promise.resolve({
|
||||
error: false,
|
||||
reason: null,
|
||||
external: true,
|
||||
sourceStackFrame: source,
|
||||
originalStackFrame: null,
|
||||
originalCodeFrame: null,
|
||||
ignored: true
|
||||
});
|
||||
}
|
||||
return _getOriginalStackFrame().catch((err)=>{
|
||||
var _err_message, _ref;
|
||||
return {
|
||||
error: true,
|
||||
reason: (_ref = (_err_message = err == null ? void 0 : err.message) != null ? _err_message : err == null ? void 0 : err.toString()) != null ? _ref : 'Unknown Error',
|
||||
external: false,
|
||||
sourceStackFrame: source,
|
||||
originalStackFrame: null,
|
||||
originalCodeFrame: null,
|
||||
ignored: false
|
||||
};
|
||||
});
|
||||
}
|
||||
export async function getOriginalStackFrames(frames, type, isAppDir) {
|
||||
const req = {
|
||||
frames,
|
||||
isServer: type === 'server',
|
||||
isEdgeServer: type === 'edge-server',
|
||||
isAppDirectory: isAppDir
|
||||
};
|
||||
let res = undefined;
|
||||
let reason = undefined;
|
||||
try {
|
||||
res = await fetch('/__nextjs_original-stack-frames', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(req)
|
||||
});
|
||||
} catch (e) {
|
||||
reason = e + '';
|
||||
}
|
||||
// When fails to fetch the original stack frames, we reject here to be
|
||||
// caught at `_getOriginalStackFrame()` and return the stack frames so
|
||||
// that the error overlay can render.
|
||||
if (res && res.ok && res.status !== 204) {
|
||||
const data = await res.json();
|
||||
return Promise.all(frames.map((frame, index)=>getOriginalStackFrame(frame, data[index])));
|
||||
} else {
|
||||
if (res) {
|
||||
reason = await res.text();
|
||||
}
|
||||
}
|
||||
return Promise.all(frames.map((frame)=>getOriginalStackFrame(frame, {
|
||||
status: 'rejected',
|
||||
reason: "Failed to fetch the original stack frames " + (reason ? ": " + reason : '')
|
||||
})));
|
||||
}
|
||||
export function getFrameSource(frame) {
|
||||
if (!frame.file) return '';
|
||||
const isWebpackFrame = isWebpackInternalResource(frame.file);
|
||||
let str = '';
|
||||
// Skip URL parsing for webpack internal file paths.
|
||||
if (isWebpackFrame) {
|
||||
str = formatFrameSourceFile(frame.file);
|
||||
} else {
|
||||
try {
|
||||
var _globalThis_location;
|
||||
const u = new URL(frame.file);
|
||||
let parsedPath = '';
|
||||
// Strip the origin for same-origin scripts.
|
||||
if (((_globalThis_location = globalThis.location) == null ? void 0 : _globalThis_location.origin) !== u.origin) {
|
||||
// URLs can be valid without an `origin`, so long as they have a
|
||||
// `protocol`. However, `origin` is preferred.
|
||||
if (u.origin === 'null') {
|
||||
parsedPath += u.protocol;
|
||||
} else {
|
||||
parsedPath += u.origin;
|
||||
}
|
||||
}
|
||||
// Strip query string information as it's typically too verbose to be
|
||||
// meaningful.
|
||||
parsedPath += u.pathname;
|
||||
str = formatFrameSourceFile(parsedPath);
|
||||
} catch (e) {
|
||||
str = formatFrameSourceFile(frame.file);
|
||||
}
|
||||
}
|
||||
if (!isWebpackInternalResource(frame.file) && frame.lineNumber != null) {
|
||||
if (str) {
|
||||
if (frame.column != null) {
|
||||
str += " (" + frame.lineNumber + ":" + frame.column + ")";
|
||||
} else {
|
||||
str += " (" + frame.lineNumber + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=stack-frame.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/utils/stack-frame.ts"],"sourcesContent":["import type { StackFrame } from 'next/dist/compiled/stacktrace-parser'\nimport type {\n OriginalStackFrameResponse,\n OriginalStackFrameResponseResult,\n OriginalStackFramesRequest,\n} from '../server/shared'\nimport {\n isWebpackInternalResource,\n formatFrameSourceFile,\n} from './webpack-module-path'\n\nexport interface ResolvedOriginalStackFrame extends OriginalStackFrameResponse {\n error: false\n reason: null\n external: boolean\n ignored: boolean\n sourceStackFrame: StackFrame\n}\n\nexport interface RejectedOriginalStackFrame extends OriginalStackFrameResponse {\n error: true\n reason: string\n external: boolean\n ignored: boolean\n sourceStackFrame: StackFrame\n}\n\nexport type OriginalStackFrame =\n | ResolvedOriginalStackFrame\n | RejectedOriginalStackFrame\n\nfunction getOriginalStackFrame(\n source: StackFrame,\n response: OriginalStackFrameResponseResult\n): Promise<OriginalStackFrame> {\n async function _getOriginalStackFrame(): Promise<ResolvedOriginalStackFrame> {\n if (response.status === 'rejected') {\n throw new Error(response.reason)\n }\n\n const body: OriginalStackFrameResponse = response.value\n\n return {\n error: false,\n reason: null,\n external: false,\n sourceStackFrame: source,\n originalStackFrame: body.originalStackFrame,\n originalCodeFrame: body.originalCodeFrame || null,\n ignored: body.originalStackFrame?.ignored || false,\n }\n }\n\n // TODO: merge this section into ignoredList handling\n if (source.file === 'file://' || source.file?.match(/https?:\\/\\//)) {\n return Promise.resolve({\n error: false,\n reason: null,\n external: true,\n sourceStackFrame: source,\n originalStackFrame: null,\n originalCodeFrame: null,\n ignored: true,\n })\n }\n\n return _getOriginalStackFrame().catch(\n (err: Error): RejectedOriginalStackFrame => ({\n error: true,\n reason: err?.message ?? err?.toString() ?? 'Unknown Error',\n external: false,\n sourceStackFrame: source,\n originalStackFrame: null,\n originalCodeFrame: null,\n ignored: false,\n })\n )\n}\n\nexport async function getOriginalStackFrames(\n frames: StackFrame[],\n type: 'server' | 'edge-server' | null,\n isAppDir: boolean\n): Promise<OriginalStackFrame[]> {\n const req: OriginalStackFramesRequest = {\n frames,\n isServer: type === 'server',\n isEdgeServer: type === 'edge-server',\n isAppDirectory: isAppDir,\n }\n\n let res: Response | undefined = undefined\n let reason: string | undefined = undefined\n try {\n res = await fetch('/__nextjs_original-stack-frames', {\n method: 'POST',\n body: JSON.stringify(req),\n })\n } catch (e) {\n reason = e + ''\n }\n\n // When fails to fetch the original stack frames, we reject here to be\n // caught at `_getOriginalStackFrame()` and return the stack frames so\n // that the error overlay can render.\n if (res && res.ok && res.status !== 204) {\n const data = await res.json()\n return Promise.all(\n frames.map((frame, index) => getOriginalStackFrame(frame, data[index]))\n )\n } else {\n if (res) {\n reason = await res.text()\n }\n }\n return Promise.all(\n frames.map((frame) =>\n getOriginalStackFrame(frame, {\n status: 'rejected',\n reason: `Failed to fetch the original stack frames ${reason ? `: ${reason}` : ''}`,\n })\n )\n )\n}\n\nexport function getFrameSource(frame: StackFrame): string {\n if (!frame.file) return ''\n\n const isWebpackFrame = isWebpackInternalResource(frame.file)\n\n let str = ''\n // Skip URL parsing for webpack internal file paths.\n if (isWebpackFrame) {\n str = formatFrameSourceFile(frame.file)\n } else {\n try {\n const u = new URL(frame.file)\n\n let parsedPath = ''\n // Strip the origin for same-origin scripts.\n if (globalThis.location?.origin !== u.origin) {\n // URLs can be valid without an `origin`, so long as they have a\n // `protocol`. However, `origin` is preferred.\n if (u.origin === 'null') {\n parsedPath += u.protocol\n } else {\n parsedPath += u.origin\n }\n }\n\n // Strip query string information as it's typically too verbose to be\n // meaningful.\n parsedPath += u.pathname\n str = formatFrameSourceFile(parsedPath)\n } catch {\n str = formatFrameSourceFile(frame.file)\n }\n }\n\n if (!isWebpackInternalResource(frame.file) && frame.lineNumber != null) {\n if (str) {\n if (frame.column != null) {\n str += ` (${frame.lineNumber}:${frame.column})`\n } else {\n str += ` (${frame.lineNumber})`\n }\n }\n }\n return str\n}\n"],"names":["isWebpackInternalResource","formatFrameSourceFile","getOriginalStackFrame","souLine truncated
|
||||
Generated
Vendored
+134
@@ -0,0 +1,134 @@
|
||||
import { _ as _class_private_field_loose_base } from "@swc/helpers/_/_class_private_field_loose_base";
|
||||
import { _ as _class_private_field_loose_key } from "@swc/helpers/_/_class_private_field_loose_key";
|
||||
// How long to wait before reporting the HMR start, used to suppress irrelevant
|
||||
// `BUILDING` events. Does not impact reported latency.
|
||||
const TURBOPACK_HMR_START_DELAY_MS = 100;
|
||||
var _updatedModules = /*#__PURE__*/ _class_private_field_loose_key("_updatedModules"), _startMsSinceEpoch = /*#__PURE__*/ _class_private_field_loose_key("_startMsSinceEpoch"), _lastUpdateMsSinceEpoch = /*#__PURE__*/ _class_private_field_loose_key("_lastUpdateMsSinceEpoch"), _deferredReportHmrStartId = /*#__PURE__*/ _class_private_field_loose_key("_deferredReportHmrStartId"), // HACK: Turbopack tends to generate a lot of irrelevant "BUILDING" actions,
|
||||
// as it reports *any* compilation, including fully no-op/cached compilations
|
||||
// and those unrelated to HMR. Fixing this would require significant
|
||||
// architectural changes.
|
||||
//
|
||||
// Work around this by deferring any "rebuilding" message by 100ms. If we get
|
||||
// a BUILT event within that threshold and nothing has changed, just suppress
|
||||
// the message entirely.
|
||||
_runDeferredReportHmrStart = /*#__PURE__*/ _class_private_field_loose_key("_runDeferredReportHmrStart"), _cancelDeferredReportHmrStart = /*#__PURE__*/ _class_private_field_loose_key("_cancelDeferredReportHmrStart"), /** Helper for other `onEvent` methods. */ _onUpdate = /*#__PURE__*/ _class_private_field_loose_key("_onUpdate");
|
||||
export class TurbopackHmr {
|
||||
onBuilding() {
|
||||
_class_private_field_loose_base(this, _lastUpdateMsSinceEpoch)[_lastUpdateMsSinceEpoch] = undefined;
|
||||
_class_private_field_loose_base(this, _cancelDeferredReportHmrStart)[_cancelDeferredReportHmrStart]();
|
||||
_class_private_field_loose_base(this, _startMsSinceEpoch)[_startMsSinceEpoch] = Date.now();
|
||||
// report the HMR start after a short delay
|
||||
_class_private_field_loose_base(this, _deferredReportHmrStartId)[_deferredReportHmrStartId] = setTimeout(()=>_class_private_field_loose_base(this, _runDeferredReportHmrStart)[_runDeferredReportHmrStart](), // debugging feature: don't defer/suppress noisy no-op HMR update messages
|
||||
self.__NEXT_HMR_TURBOPACK_REPORT_NOISY_NOOP_EVENTS ? 0 : TURBOPACK_HMR_START_DELAY_MS);
|
||||
}
|
||||
onTurbopackMessage(msg) {
|
||||
_class_private_field_loose_base(this, _onUpdate)[_onUpdate]();
|
||||
const updatedModules = extractModulesFromTurbopackMessage(msg.data);
|
||||
for (const module of updatedModules){
|
||||
_class_private_field_loose_base(this, _updatedModules)[_updatedModules].add(module);
|
||||
}
|
||||
}
|
||||
onServerComponentChanges() {
|
||||
_class_private_field_loose_base(this, _onUpdate)[_onUpdate]();
|
||||
}
|
||||
onReloadPage() {
|
||||
_class_private_field_loose_base(this, _onUpdate)[_onUpdate]();
|
||||
}
|
||||
onPageAddRemove() {
|
||||
_class_private_field_loose_base(this, _onUpdate)[_onUpdate]();
|
||||
}
|
||||
/**
|
||||
* @returns `null` if the caller should ignore the update entirely. Returns an
|
||||
* object with `hasUpdates: false` if the caller should report the end of
|
||||
* the HMR in the browser console, but the HMR was a no-op.
|
||||
*/ onBuilt() {
|
||||
// Check that we got *any* `TurbopackMessageAction`, even if
|
||||
// `updatedModules` is empty (not everything gets recorded there).
|
||||
//
|
||||
// There's also a case where `onBuilt` gets called before `onBuilding`,
|
||||
// which can happen during initial page load. Ignore that too!
|
||||
const hasUpdates = _class_private_field_loose_base(this, _lastUpdateMsSinceEpoch)[_lastUpdateMsSinceEpoch] != null && _class_private_field_loose_base(this, _startMsSinceEpoch)[_startMsSinceEpoch] != null;
|
||||
if (!hasUpdates && _class_private_field_loose_base(this, _deferredReportHmrStartId)[_deferredReportHmrStartId] != null) {
|
||||
// suppress the update entirely
|
||||
_class_private_field_loose_base(this, _cancelDeferredReportHmrStart)[_cancelDeferredReportHmrStart]();
|
||||
return null;
|
||||
}
|
||||
_class_private_field_loose_base(this, _runDeferredReportHmrStart)[_runDeferredReportHmrStart]();
|
||||
var _class_private_field_loose_base__lastUpdateMsSinceEpoch;
|
||||
const result = {
|
||||
hasUpdates,
|
||||
updatedModules: _class_private_field_loose_base(this, _updatedModules)[_updatedModules],
|
||||
startMsSinceEpoch: _class_private_field_loose_base(this, _startMsSinceEpoch)[_startMsSinceEpoch],
|
||||
endMsSinceEpoch: (_class_private_field_loose_base__lastUpdateMsSinceEpoch = _class_private_field_loose_base(this, _lastUpdateMsSinceEpoch)[_lastUpdateMsSinceEpoch]) != null ? _class_private_field_loose_base__lastUpdateMsSinceEpoch : Date.now()
|
||||
};
|
||||
_class_private_field_loose_base(this, _updatedModules)[_updatedModules] = new Set();
|
||||
return result;
|
||||
}
|
||||
constructor(){
|
||||
Object.defineProperty(this, _runDeferredReportHmrStart, {
|
||||
value: runDeferredReportHmrStart
|
||||
});
|
||||
Object.defineProperty(this, _cancelDeferredReportHmrStart, {
|
||||
value: cancelDeferredReportHmrStart
|
||||
});
|
||||
Object.defineProperty(this, _onUpdate, {
|
||||
value: onUpdate
|
||||
});
|
||||
Object.defineProperty(this, _updatedModules, {
|
||||
writable: true,
|
||||
value: void 0
|
||||
});
|
||||
Object.defineProperty(this, _startMsSinceEpoch, {
|
||||
writable: true,
|
||||
value: void 0
|
||||
});
|
||||
Object.defineProperty(this, _lastUpdateMsSinceEpoch, {
|
||||
writable: true,
|
||||
value: void 0
|
||||
});
|
||||
Object.defineProperty(this, _deferredReportHmrStartId, {
|
||||
writable: true,
|
||||
value: void 0
|
||||
});
|
||||
_class_private_field_loose_base(this, _updatedModules)[_updatedModules] = new Set();
|
||||
}
|
||||
}
|
||||
function runDeferredReportHmrStart() {
|
||||
if (_class_private_field_loose_base(this, _deferredReportHmrStartId)[_deferredReportHmrStartId] != null) {
|
||||
console.log('[Fast Refresh] rebuilding');
|
||||
_class_private_field_loose_base(this, _cancelDeferredReportHmrStart)[_cancelDeferredReportHmrStart]();
|
||||
}
|
||||
}
|
||||
function cancelDeferredReportHmrStart() {
|
||||
clearTimeout(_class_private_field_loose_base(this, _deferredReportHmrStartId)[_deferredReportHmrStartId]);
|
||||
_class_private_field_loose_base(this, _deferredReportHmrStartId)[_deferredReportHmrStartId] = undefined;
|
||||
}
|
||||
function onUpdate() {
|
||||
_class_private_field_loose_base(this, _runDeferredReportHmrStart)[_runDeferredReportHmrStart]();
|
||||
_class_private_field_loose_base(this, _lastUpdateMsSinceEpoch)[_lastUpdateMsSinceEpoch] = Date.now();
|
||||
}
|
||||
function extractModulesFromTurbopackMessage(data) {
|
||||
const updatedModules = new Set();
|
||||
const updates = Array.isArray(data) ? data : [
|
||||
data
|
||||
];
|
||||
for (const update of updates){
|
||||
// TODO this won't capture changes to CSS since they don't result in a "merged" update
|
||||
if (update.type !== 'partial' || update.instruction.type !== 'ChunkListUpdate' || update.instruction.merged === undefined) {
|
||||
continue;
|
||||
}
|
||||
for (const mergedUpdate of update.instruction.merged){
|
||||
for (const name of Object.keys(mergedUpdate.entries)){
|
||||
const res = /(.*)\s+\[.*/.exec(name);
|
||||
if (res === null) {
|
||||
console.error('[Turbopack HMR] Expected module to match pattern: ' + name);
|
||||
continue;
|
||||
}
|
||||
updatedModules.add(res[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return updatedModules;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=turbopack-hot-reloader-common.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/utils/turbopack-hot-reloader-common.ts"],"sourcesContent":["import type { TurbopackMessageAction } from '../../../../server/dev/hot-reloader-types'\nimport type { Update as TurbopackUpdate } from '../../../../build/swc/types'\n\ndeclare global {\n interface Window {\n __NEXT_HMR_TURBOPACK_REPORT_NOISY_NOOP_EVENTS: boolean | undefined\n }\n}\n\n// How long to wait before reporting the HMR start, used to suppress irrelevant\n// `BUILDING` events. Does not impact reported latency.\nconst TURBOPACK_HMR_START_DELAY_MS = 100\n\ninterface HmrUpdate {\n hasUpdates: boolean\n updatedModules: Set<string>\n startMsSinceEpoch: number\n endMsSinceEpoch: number\n}\n\nexport class TurbopackHmr {\n #updatedModules: Set<string>\n #startMsSinceEpoch: number | undefined\n #lastUpdateMsSinceEpoch: number | undefined\n #deferredReportHmrStartId: ReturnType<typeof setTimeout> | undefined\n\n constructor() {\n this.#updatedModules = new Set()\n }\n\n // HACK: Turbopack tends to generate a lot of irrelevant \"BUILDING\" actions,\n // as it reports *any* compilation, including fully no-op/cached compilations\n // and those unrelated to HMR. Fixing this would require significant\n // architectural changes.\n //\n // Work around this by deferring any \"rebuilding\" message by 100ms. If we get\n // a BUILT event within that threshold and nothing has changed, just suppress\n // the message entirely.\n #runDeferredReportHmrStart() {\n if (this.#deferredReportHmrStartId != null) {\n console.log('[Fast Refresh] rebuilding')\n this.#cancelDeferredReportHmrStart()\n }\n }\n\n #cancelDeferredReportHmrStart() {\n clearTimeout(this.#deferredReportHmrStartId)\n this.#deferredReportHmrStartId = undefined\n }\n\n onBuilding() {\n this.#lastUpdateMsSinceEpoch = undefined\n this.#cancelDeferredReportHmrStart()\n this.#startMsSinceEpoch = Date.now()\n\n // report the HMR start after a short delay\n this.#deferredReportHmrStartId = setTimeout(\n () => this.#runDeferredReportHmrStart(),\n // debugging feature: don't defer/suppress noisy no-op HMR update messages\n self.__NEXT_HMR_TURBOPACK_REPORT_NOISY_NOOP_EVENTS\n ? 0\n : TURBOPACK_HMR_START_DELAY_MS\n )\n }\n\n /** Helper for other `onEvent` methods. */\n #onUpdate() {\n this.#runDeferredReportHmrStart()\n this.#lastUpdateMsSinceEpoch = Date.now()\n }\n\n onTurbopackMessage(msg: TurbopackMessageAction) {\n this.#onUpdate()\n const updatedModules = extractModulesFromTurbopackMessage(msg.data)\n for (const module of updatedModules) {\n this.#updatedModules.add(module)\n }\n }\n\n onServerComponentChanges() {\n this.#onUpdate()\n }\n\n onReloadPage() {\n this.#onUpdate()\n }\n\n onPageAddRemove() {\n this.#onUpdate()\n }\n\n /**\n * @returns `null` if the caller should ignore the update entirely. Returns an\n * object with `hasUpdates: false` if the caller should report the end of\n * the HMR in the browser console, but the HMR was a no-op.\n */\n onBuilt(): HmrUpdate | null {\n // Check that we got *any* `TurbopackMessageAction`, even if\n // `updatedModules` is empty (not everything gets recorded there).\n //\n // There's also a case where `onBuilt` gets called before `onBuilding`,\n // which can happen during initial page load. Ignore that too!\n const hasUpdates =\n this.#lastUpdateMsSinceEpoch != null && this.#startMsSinceEpoch != null\n if (!hasUpdates && this.#deferredReportHmrStartId != null) {\n // suppress the update entirely\n this.#cancelDeferredReportHmrStart()\n return null\n }\n this.#runDeferredReportHmrStart()\n\n const result = {\n hasUpdates,\n updatedModules: this.#updatedModules,\n startMsSinceEpoch: this.#startMsSinceEpoch!,\n endMsSinceEpoch: this.#lastUpdateMsSinceEpoch ?? Date.now(),\n }\n this.#updatedModules = new Set()\n return result\n }\n}\n\nfunction extractModulesFromTurbopackMessage(\n data: TurbopackUpdate | TurbopackUpdate[]\n): Set<string> {\n const updatedModules: Set<string> = new Set()\n\n const updates = Array.isArray(data) ? data : [data]\n for (const update of updates) {\n // TODO this won't capture changes to CSS since they don't result in a \"merged\" update\n if (\n update.type !== 'partial' ||\n update.instruction.type !== 'ChunkListUpdate' ||\n update.instruction.merged === undefined\n ) {\n continue\n }\n\n for (const mergedUpdate of update.instruction.merged) {\n for (const name of Object.keys(mergedUpdate.entries)) {\n const res = /(.*)\\s+\\[.*/.exec(name)\n if (res === null) {\n console.error(\n '[Turbopack HMR] Expected module to match pattern: ' + name\n )\n continue\n }\n\n updatedModules.add(res[1])\n }\n }\n }\n\n Line truncated
|
||||
Generated
Vendored
+98
@@ -0,0 +1,98 @@
|
||||
import { useCallback, useContext, useEffect, useRef } from 'react';
|
||||
import { GlobalLayoutRouterContext } from '../../../../shared/lib/app-router-context.shared-runtime';
|
||||
import { getSocketUrl } from './get-socket-url';
|
||||
export function useWebsocket(assetPrefix) {
|
||||
const webSocketRef = useRef(undefined);
|
||||
useEffect(()=>{
|
||||
if (webSocketRef.current) {
|
||||
return;
|
||||
}
|
||||
const url = getSocketUrl(assetPrefix);
|
||||
webSocketRef.current = new window.WebSocket("" + url + "/_next/webpack-hmr");
|
||||
}, [
|
||||
assetPrefix
|
||||
]);
|
||||
return webSocketRef;
|
||||
}
|
||||
export function useSendMessage(webSocketRef) {
|
||||
const sendMessage = useCallback((data)=>{
|
||||
const socket = webSocketRef.current;
|
||||
if (!socket || socket.readyState !== socket.OPEN) {
|
||||
return;
|
||||
}
|
||||
return socket.send(data);
|
||||
}, [
|
||||
webSocketRef
|
||||
]);
|
||||
return sendMessage;
|
||||
}
|
||||
export function useTurbopack(sendMessage, onUpdateError) {
|
||||
const turbopackState = useRef({
|
||||
init: false,
|
||||
// Until the dynamic import resolves, queue any turbopack messages which will be replayed.
|
||||
queue: [],
|
||||
callback: undefined
|
||||
});
|
||||
const processTurbopackMessage = useCallback((msg)=>{
|
||||
const { callback, queue } = turbopackState.current;
|
||||
if (callback) {
|
||||
callback(msg);
|
||||
} else {
|
||||
queue.push(msg);
|
||||
}
|
||||
}, []);
|
||||
useEffect(()=>{
|
||||
const { current: initCurrent } = turbopackState;
|
||||
// TODO(WEB-1589): only install if `process.turbopack` set.
|
||||
if (initCurrent.init) {
|
||||
return;
|
||||
}
|
||||
initCurrent.init = true;
|
||||
import(// @ts-expect-error requires "moduleResolution": "node16" in tsconfig.json and not .ts extension
|
||||
'@vercel/turbopack-ecmascript-runtime/browser/dev/hmr-client/hmr-client.ts').then((param)=>{
|
||||
let { connect } = param;
|
||||
const { current } = turbopackState;
|
||||
connect({
|
||||
addMessageListener (cb) {
|
||||
current.callback = cb;
|
||||
// Replay all Turbopack messages before we were able to establish the HMR client.
|
||||
for (const msg of current.queue){
|
||||
cb(msg);
|
||||
}
|
||||
current.queue = undefined;
|
||||
},
|
||||
sendMessage,
|
||||
onUpdateError
|
||||
});
|
||||
});
|
||||
}, [
|
||||
sendMessage,
|
||||
onUpdateError
|
||||
]);
|
||||
return processTurbopackMessage;
|
||||
}
|
||||
export function useWebsocketPing(websocketRef) {
|
||||
const sendMessage = useSendMessage(websocketRef);
|
||||
const { tree } = useContext(GlobalLayoutRouterContext);
|
||||
useEffect(()=>{
|
||||
// Never send pings when using Turbopack as it's not used.
|
||||
// Pings were originally used to keep track of active routes in on-demand-entries with webpack.
|
||||
if (process.env.TURBOPACK) {
|
||||
return;
|
||||
}
|
||||
// Taken from on-demand-entries-client.js
|
||||
const interval = setInterval(()=>{
|
||||
sendMessage(JSON.stringify({
|
||||
event: 'ping',
|
||||
tree,
|
||||
appDirRoute: true
|
||||
}));
|
||||
}, 2500);
|
||||
return ()=>clearInterval(interval);
|
||||
}, [
|
||||
tree,
|
||||
sendMessage
|
||||
]);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=use-websocket.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/utils/use-websocket.ts"],"sourcesContent":["import { useCallback, useContext, useEffect, useRef } from 'react'\nimport { GlobalLayoutRouterContext } from '../../../../shared/lib/app-router-context.shared-runtime'\nimport { getSocketUrl } from './get-socket-url'\nimport type { TurbopackMsgToBrowser } from '../../../../server/dev/hot-reloader-types'\n\nexport function useWebsocket(assetPrefix: string) {\n const webSocketRef = useRef<WebSocket>(undefined)\n\n useEffect(() => {\n if (webSocketRef.current) {\n return\n }\n\n const url = getSocketUrl(assetPrefix)\n\n webSocketRef.current = new window.WebSocket(`${url}/_next/webpack-hmr`)\n }, [assetPrefix])\n\n return webSocketRef\n}\n\nexport function useSendMessage(webSocketRef: ReturnType<typeof useWebsocket>) {\n const sendMessage = useCallback(\n (data: string) => {\n const socket = webSocketRef.current\n if (!socket || socket.readyState !== socket.OPEN) {\n return\n }\n return socket.send(data)\n },\n [webSocketRef]\n )\n return sendMessage\n}\n\nexport function useTurbopack(\n sendMessage: ReturnType<typeof useSendMessage>,\n onUpdateError: (err: unknown) => void\n) {\n const turbopackState = useRef<{\n init: boolean\n queue: Array<TurbopackMsgToBrowser> | undefined\n callback: ((msg: TurbopackMsgToBrowser) => void) | undefined\n }>({\n init: false,\n // Until the dynamic import resolves, queue any turbopack messages which will be replayed.\n queue: [],\n callback: undefined,\n })\n\n const processTurbopackMessage = useCallback((msg: TurbopackMsgToBrowser) => {\n const { callback, queue } = turbopackState.current\n if (callback) {\n callback(msg)\n } else {\n queue!.push(msg)\n }\n }, [])\n\n useEffect(() => {\n const { current: initCurrent } = turbopackState\n // TODO(WEB-1589): only install if `process.turbopack` set.\n if (initCurrent.init) {\n return\n }\n initCurrent.init = true\n\n import(\n // @ts-expect-error requires \"moduleResolution\": \"node16\" in tsconfig.json and not .ts extension\n '@vercel/turbopack-ecmascript-runtime/browser/dev/hmr-client/hmr-client.ts'\n ).then(({ connect }) => {\n const { current } = turbopackState\n connect({\n addMessageListener(cb: (msg: TurbopackMsgToBrowser) => void) {\n current.callback = cb\n\n // Replay all Turbopack messages before we were able to establish the HMR client.\n for (const msg of current.queue!) {\n cb(msg)\n }\n current.queue = undefined\n },\n sendMessage,\n onUpdateError,\n })\n })\n }, [sendMessage, onUpdateError])\n\n return processTurbopackMessage\n}\n\nexport function useWebsocketPing(\n websocketRef: ReturnType<typeof useWebsocket>\n) {\n const sendMessage = useSendMessage(websocketRef)\n const { tree } = useContext(GlobalLayoutRouterContext)\n\n useEffect(() => {\n // Never send pings when using Turbopack as it's not used.\n // Pings were originally used to keep track of active routes in on-demand-entries with webpack.\n if (process.env.TURBOPACK) {\n return\n }\n\n // Taken from on-demand-entries-client.js\n const interval = setInterval(() => {\n sendMessage(\n JSON.stringify({\n event: 'ping',\n tree,\n appDirRoute: true,\n })\n )\n }, 2500)\n return () => clearInterval(interval)\n }, [tree, sendMessage])\n}\n"],"names":["useCallback","useContext","useEffect","useRef","GlobalLayoutRouterContext","getSocketUrl","useWebsocket","assetPrefix","webSocketRef","undefined","current","url","window","WebSocket","useSendMessage","sendMessage","data","socket","readyState","OPEN","send","useTurbopack","onUpdateError","turbopackState","init","queue","callback","processTurbopackMessage","msg","push","initCurrent","then","connect","addMessageListener","cb","useWebsocketPing","websocketRef","tree","process","env","TURBOPACK","interval","setInterval","JSON","stringify","event","appDirRoute","clearInterval"],"mappings":"AAAA,SAASA,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,QAAQ,QAAO;AAClE,SAASC,yBAAyB,QAAQ,2DAA0D;AACpG,SAASC,YAAY,QAAQ,mBAAkB;AAG/C,OAAO,SAASC,aAAaC,WAAmB;IAC9C,MAAMC,eAAeL,OAAkBM;IAEvCP,UAAU;QACR,IAAIM,aAAaE,OAAO,EAAE;YACxB;QACF;QAEA,MAAMC,MAAMN,aAAaE;QAEzBC,aAAaE,OAAO,GAAG,IAAIE,OAAOC,SAAS,CAAC,AAAC,KAAEF,MAAI;IACrD,GAAG;QAACJ;KAAY;IAEhB,OAAOC;AACT;AAEA,OAAO,SAASM,eAAeN,YAA6C;IAC1E,MAAMO,cAAcf,YAClB,CAACgB;QACC,MAAMC,SAAST,aAAaE,OAAO;QACnC,IAAI,CAACO,UAAUA,OAAOC,UAAU,KAAKD,OAAOE,IAAI,EAAE;YAChD;QACF;QACA,OAAOF,OAAOG,IAAI,CAACJ;IACrB,GACA;QAACR;KAAa;IAEhB,OAAOO;AACT;AAEA,OAAO,SAASM,aACdN,WAA8C,EAC9CO,aAAqC;IAErC,MAAMC,iBAAiBpB,OAIpB;QACDqB,MAAM;QACN,0FAA0F;QAC1FC,OAAO,EAAE;QACTC,UAAUjB;IACZ;IAEA,MAAMkB,0BAA0B3B,YAAY,CAAC4B;QAC3C,MAAM,EAAEF,QAAQ,EAAED,KAAK,EAAE,GAAGF,eAAeb,OAAO;QAClD,IALine truncated
|
||||
Generated
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
const replacementRegExes = [
|
||||
/^webpack-internal:\/\/\/(\([\w-]+\)\/)?/,
|
||||
/^(webpack:\/\/\/|webpack:\/\/(_N_E\/)?)(\([\w-]+\)\/)?/
|
||||
];
|
||||
export function isWebpackInternalResource(file) {
|
||||
for (const regex of replacementRegExes){
|
||||
if (regex.test(file)) return true;
|
||||
file = file.replace(regex, '');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Format the webpack internal id to original file path
|
||||
*
|
||||
* webpack-internal:///./src/hello.tsx => ./src/hello.tsx
|
||||
* webpack://_N_E/./src/hello.tsx => ./src/hello.tsx
|
||||
* webpack://./src/hello.tsx => ./src/hello.tsx
|
||||
* webpack:///./src/hello.tsx => ./src/hello.tsx
|
||||
*/ export function formatFrameSourceFile(file) {
|
||||
for (const regex of replacementRegExes){
|
||||
file = file.replace(regex, '');
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=webpack-module-path.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/utils/webpack-module-path.ts"],"sourcesContent":["const replacementRegExes = [\n /^webpack-internal:\\/\\/\\/(\\([\\w-]+\\)\\/)?/,\n /^(webpack:\\/\\/\\/|webpack:\\/\\/(_N_E\\/)?)(\\([\\w-]+\\)\\/)?/,\n]\n\nexport function isWebpackInternalResource(file: string) {\n for (const regex of replacementRegExes) {\n if (regex.test(file)) return true\n\n file = file.replace(regex, '')\n }\n\n return false\n}\n\n/**\n * Format the webpack internal id to original file path\n *\n * webpack-internal:///./src/hello.tsx => ./src/hello.tsx\n * webpack://_N_E/./src/hello.tsx => ./src/hello.tsx\n * webpack://./src/hello.tsx => ./src/hello.tsx\n * webpack:///./src/hello.tsx => ./src/hello.tsx\n */\nexport function formatFrameSourceFile(file: string) {\n for (const regex of replacementRegExes) {\n file = file.replace(regex, '')\n }\n\n return file\n}\n"],"names":["replacementRegExes","isWebpackInternalResource","file","regex","test","replace","formatFrameSourceFile"],"mappings":"AAAA,MAAMA,qBAAqB;IACzB;IACA;CACD;AAED,OAAO,SAASC,0BAA0BC,IAAY;IACpD,KAAK,MAAMC,SAASH,mBAAoB;QACtC,IAAIG,MAAMC,IAAI,CAACF,OAAO,OAAO;QAE7BA,OAAOA,KAAKG,OAAO,CAACF,OAAO;IAC7B;IAEA,OAAO;AACT;AAEA;;;;;;;CAOC,GACD,OAAO,SAASG,sBAAsBJ,IAAY;IAChD,KAAK,MAAMC,SAASH,mBAAoB;QACtCE,OAAOA,KAAKG,OAAO,CAACF,OAAO;IAC7B;IAEA,OAAOD;AACT"}
|
||||
Reference in new issue
Block a user