vike 0.4.153-commit-3e842bb → 0.4.153-commit-e631897
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +15 -7
- package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +2 -1
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +4 -5
- package/dist/cjs/node/plugin/shared/loggerVite.js +3 -0
- package/dist/cjs/node/prerender/runPrerender.js +17 -2
- package/dist/cjs/node/runtime/globalContext/loadImportBuild.js +0 -4
- package/dist/cjs/node/runtime/renderPage/logHintForCjsEsmError/errors.js +20 -0
- package/dist/cjs/node/runtime/renderPage/logHintForCjsEsmError.js +326 -0
- package/dist/cjs/node/runtime/renderPage/loggerProd.js +9 -1
- package/dist/cjs/node/runtime/utils.js +2 -1
- package/dist/cjs/utils/formatHintLog.js +17 -0
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +15 -7
- package/dist/esm/node/plugin/shared/loggerNotProd/log.d.ts +2 -0
- package/dist/esm/node/plugin/shared/loggerNotProd/log.js +1 -0
- package/dist/esm/node/plugin/shared/loggerNotProd.js +6 -7
- package/dist/esm/node/plugin/shared/loggerVite.js +3 -0
- package/dist/esm/node/prerender/runPrerender.js +17 -2
- package/dist/esm/node/runtime/globalContext/loadImportBuild.js +1 -5
- package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError/errors.d.ts +1 -0
- package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError/errors.js +17 -0
- package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +13 -0
- package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.js +321 -0
- package/dist/esm/node/runtime/renderPage/loggerProd.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/loggerProd.js +8 -0
- package/dist/esm/node/runtime/utils.d.ts +2 -1
- package/dist/esm/node/runtime/utils.js +2 -1
- package/dist/esm/utils/formatHintLog.d.ts +2 -0
- package/dist/esm/utils/formatHintLog.js +14 -0
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/utils/autoRetry.js +0 -23
- package/dist/esm/utils/autoRetry.d.ts +0 -2
- package/dist/esm/utils/autoRetry.js +0 -20
|
@@ -14,15 +14,16 @@ export { clearLogs };
|
|
|
14
14
|
import { isAbortError } from '../../../shared/route/abort.js';
|
|
15
15
|
import { getViteConfig } from '../../runtime/globalContext.js';
|
|
16
16
|
import { overwriteRuntimeProductionLogger } from '../../runtime/renderPage/loggerRuntime.js';
|
|
17
|
-
import { assert, assertIsNotProductionRuntime, getAssertErrMsg, isUserHookError, overwriteAssertProductionLogger, stripAnsi, warnIfErrorIsNotObject } from '../utils.js';
|
|
17
|
+
import { assert, assertIsNotProductionRuntime, formatHintLog, getAssertErrMsg, isUserHookError, overwriteAssertProductionLogger, stripAnsi, warnIfErrorIsNotObject } from '../utils.js';
|
|
18
18
|
import { getHttpRequestAsyncStore } from './getHttpRequestAsyncStore.js';
|
|
19
19
|
import { isErrorDebug } from './isErrorDebug.js';
|
|
20
20
|
import { isErrorWithCodeSnippet, getPrettyErrorWithCodeSnippet } from './loggerNotProd/errorWithCodeSnippet.js';
|
|
21
21
|
import { getConfigExecutionErrorIntroMsg, getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/transpileAndExecuteFile.js';
|
|
22
|
-
import { logWithVikeTag, logWithViteTag, logDirectly, isFirstLog, screenHasErrors, clearScreen } from './loggerNotProd/log.js';
|
|
22
|
+
import { logWithVikeTag, logWithViteTag, logDirectly, isFirstLog, screenHasErrors, clearScreen, applyViteSourceMapToStackTrace } from './loggerNotProd/log.js';
|
|
23
23
|
import pc from '@brillout/picocolors';
|
|
24
24
|
import { setAlreadyLogged } from '../../runtime/renderPage/isNewError.js';
|
|
25
25
|
import { isConfigInvalid } from '../../runtime/renderPage/isConfigInvalid.js';
|
|
26
|
+
import { onRuntimeError } from '../../runtime/renderPage/loggerProd.js';
|
|
26
27
|
assertIsNotProductionRuntime();
|
|
27
28
|
overwriteRuntimeProductionLogger(logRuntimeError, logRuntimeInfo);
|
|
28
29
|
overwriteAssertProductionLogger(assertLogger);
|
|
@@ -102,6 +103,7 @@ function logErr(err, httpRequestId = null) {
|
|
|
102
103
|
logFallbackErrIntro(category);
|
|
103
104
|
}
|
|
104
105
|
logDirectly(err, 'error');
|
|
106
|
+
onRuntimeError(err);
|
|
105
107
|
}
|
|
106
108
|
function logConfigError(err) {
|
|
107
109
|
clearLogs({ clearAlsoIfConfigIsInvalid: true });
|
|
@@ -154,6 +156,7 @@ function handleAssertMsg(err, category) {
|
|
|
154
156
|
return true;
|
|
155
157
|
}
|
|
156
158
|
function assertLogger(thing, logType) {
|
|
159
|
+
applyViteSourceMapToStackTrace(thing);
|
|
157
160
|
const category = getCategory();
|
|
158
161
|
const res = getAssertErrMsg(thing);
|
|
159
162
|
/* Risk of infinite loop
|
|
@@ -193,11 +196,7 @@ function logErrorDebugNote() {
|
|
|
193
196
|
return;
|
|
194
197
|
store.errorDebugNoteAlreadyShown = true;
|
|
195
198
|
}
|
|
196
|
-
const msg = pc.dim(
|
|
197
|
-
'┌──────────────────────────────────────────────────────────┐',
|
|
198
|
-
"│ Error isn't helpful? See https://vike.dev/errors#verbose │",
|
|
199
|
-
'└──────────────────────────────────────────────────────────┘'
|
|
200
|
-
].join('\n'));
|
|
199
|
+
const msg = pc.dim(formatHintLog("Error isn't helpful? See https://vike.dev/errors#verbose"));
|
|
201
200
|
logDirectly(msg, 'error');
|
|
202
201
|
}
|
|
203
202
|
function getCategory(httpRequestId = null) {
|
|
@@ -5,6 +5,7 @@ import { isErrorWithCodeSnippet } from './loggerNotProd/errorWithCodeSnippet.js'
|
|
|
5
5
|
import { getHttpRequestAsyncStore } from './getHttpRequestAsyncStore.js';
|
|
6
6
|
import { removeSuperfluousViteLog } from './loggerVite/removeSuperfluousViteLog.js';
|
|
7
7
|
import { isErrorDebug } from './isErrorDebug.js';
|
|
8
|
+
import { onRuntimeError } from '../../runtime/renderPage/loggerProd.js';
|
|
8
9
|
function improveViteLogs(config) {
|
|
9
10
|
intercept('info', config);
|
|
10
11
|
intercept('warn', config);
|
|
@@ -45,6 +46,8 @@ function intercept(logType, config) {
|
|
|
45
46
|
// Vite's default logger preprends the "[vite]" tag if and only if options.timestamp is true
|
|
46
47
|
const prependViteTag = options.timestamp || !!store?.httpRequestId;
|
|
47
48
|
logViteAny(msg, logType, store?.httpRequestId ?? null, prependViteTag);
|
|
49
|
+
if (options.error)
|
|
50
|
+
onRuntimeError(options.error);
|
|
48
51
|
};
|
|
49
52
|
}
|
|
50
53
|
function cleanFirstViteLog(msg) {
|
|
@@ -26,14 +26,29 @@ import { loadUserFilesServerSide } from '../runtime/renderPage/loadUserFilesServ
|
|
|
26
26
|
import { getHookFromPageConfig, getHookFromPageConfigGlobal, getHookTimeoutDefault, setIsPrerenderering } from '../../shared/hooks/getHook.js';
|
|
27
27
|
import { noRouteMatch } from '../../shared/route/noRouteMatch.js';
|
|
28
28
|
import { getVikeConfig } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
|
|
29
|
+
import { logHintForCjsEsmError } from '../runtime/renderPage/logHintForCjsEsmError.js';
|
|
29
30
|
async function runPrerenderFromAPI(options = {}) {
|
|
30
31
|
await runPrerender(options, 'prerender()');
|
|
31
32
|
}
|
|
32
33
|
async function runPrerenderFromCLI(options) {
|
|
33
|
-
|
|
34
|
+
try {
|
|
35
|
+
await runPrerender(options, '$ vike prerender');
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
console.error(err);
|
|
39
|
+
logHintForCjsEsmError(err);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
34
42
|
}
|
|
35
43
|
async function runPrerenderFromAutoFullBuild(options) {
|
|
36
|
-
|
|
44
|
+
try {
|
|
45
|
+
await runPrerender(options, null);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
console.error(err);
|
|
49
|
+
logHintForCjsEsmError(err);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
37
52
|
}
|
|
38
53
|
async function runPrerender(options, manuallyTriggered) {
|
|
39
54
|
checkOutdatedOptions(options);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { loadImportBuild };
|
|
2
2
|
export { setImportBuildGetters };
|
|
3
3
|
import { loadServerBuild } from '@brillout/vite-plugin-import-build/loadServerBuild.js';
|
|
4
|
-
import { assert
|
|
4
|
+
import { assert } from '../utils.js';
|
|
5
5
|
const buildGetters = (globalThis.__vike_buildGetters = globalThis.__vike_buildGetters || {
|
|
6
6
|
getters: null
|
|
7
7
|
});
|
|
@@ -11,10 +11,6 @@ function setImportBuildGetters(getters) {
|
|
|
11
11
|
async function loadImportBuild(outDir) {
|
|
12
12
|
if (!buildGetters.getters) {
|
|
13
13
|
await loadServerBuild(outDir);
|
|
14
|
-
// Await dist/server/importBuild.cjs
|
|
15
|
-
await autoRetry(() => {
|
|
16
|
-
assert(buildGetters.getters);
|
|
17
|
-
}, 2000);
|
|
18
14
|
assert(buildGetters.getters);
|
|
19
15
|
}
|
|
20
16
|
const [pageFiles, clientManifest, pluginManifest] = await Promise.all([
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const errror_cannot_use_import_outside_of_module = "\nimport{useRunner as e}from\"react-runner\";export*from\"react-runner\";import t,{useState as r,useEffect as n,Fragment as a,useCallback as l,useRef as o,useMemo as c,createContext as s,useContext as i}from\"react\";import p from\"react-simple-code-editor\";import m,{Prism as u}from\"prism-react-renderer\";function g(){return g=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},g.apply(this,arguments)}function y(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}const d=[\"initialCode\",\"transformCode\"],h=t=>{let{initialCode:a=\"\",transformCode:l}=t,o=y(t,d);const[c,s]=r(a),{element:i,error:p}=e(g({code:l?l(c):c},o));return n(()=>{s(a)},[a]),{element:i,error:p,code:c,onChange:s}},f={plain:{color:\"#ffffff\",backgroundColor:\"#282c34\"},styles:[{types:[\"comment\",\"block-comment\",\"prolog\",\"doctype\",\"cdata\"],style:{color:\"#b2b2b2\"}},{types:[\"property\",\"number\",\"function-name\",\"constant\",\"symbol\",\"deleted\"],style:{color:\"#5a9bcf\"}},{types:[\"boolean\"],style:{color:\"#ff8b50\"}},{types:[\"tag\"],style:{color:\"#fc929e\"}},{types:[\"string\",\"attr-value\"],style:{color:\"#8dc891\"}},{types:[\"punctuation\"],style:{color:\"#88c6Be\"}},{types:[\"selector\",\"char\",\"builtin\",\"inserted\"],style:{color:\"#d8dee9\"}},{types:[\"function\"],style:{color:\"#79b6f2\"}},{types:[\"operator\",\"entity\",\"url\",\"variable\"],style:{color:\"#d7deea\"}},{types:[\"keyword\"],style:{color:\"#c5a5c5\"}},{types:[\"atrule\",\"class-name\"],style:{color:\"#fac863\"}},{types:[\"important\"],style:{fontWeight:\"400\"}},{types:[\"bold\"],style:{fontWeight:\"700\"}},{types:[\"italic\"],style:{fontStyle:\"italic\"}},{types:[\"entity\"],style:{cursor:\"help\"}},{types:[\"namespace\"],style:{opacity:.7}}]},b=[\"children\",\"language\",\"theme\",\"Prism\",\"padding\",\"noWrapper\",\"noWrap\",\"className\",\"style\"],C=e=>{let{children:r,language:n=\"jsx\",theme:l=f,Prism:o=u,padding:c=10,noWrapper:s,noWrap:i,className:p,style:d}=e,h=y(e,b);/*#__PURE__*/return t.createElement(m,{code:r||\"\",language:n,Prism:o,theme:l},({className:e,style:r,tokens:n,getLineProps:l,getTokenProps:o})=>{const m=n.map((e,r)=>/*#__PURE__*/t.createElement(a,{key:r},/*#__PURE__*/t.createElement(\"span\",l({line:e}),e.map((e,r)=>/*#__PURE__*/t.createElement(\"span\",o({token:e,key:r})))),\"\\n\"));return s?m:/*#__PURE__*/t.createElement(\"pre\",g({className:p?:e,style:g({},r,{margin:0,padding:c,whiteSpace:i?\"pre\":\"pre-wrap\"},d)},h),m)})},v=[\"defaultValue\",\"value\",\"language\",\"theme\",\"Prism\",\"highlight\",\"padding\",\"onChange\"],E=e=>{let{defaultValue:n,value:a,language:s=\"jsx\",theme:i=f,Prism:m,highlight:u,padding:d=10,onChange:h}=e,b=y(e,v);const[E,P]=r(n||\"\"),k=void 0!==a,W=l(e=>/*#__PURE__*/t.createElement(C,{language:s,theme:i,Prism:m,noWrapper:!0},e),[s,i,m]),j=o(h);j.current=h;const x=l(e=>{k||P(e),null==j.current||j.current(e)},[k]),O=c(()=>g({},i.plain,b.style),[i.plain,b.style]);/*#__PURE__*/return t.createElement(p,g({},b,{highlight:u||W,padding:d,value:k?a:E,onValueChange:x,style:O}))},P=s({}),k=()=>i(P),W=[\"children\",\"code\",\"language\",\"theme\"],j=e=>{let{children:r,code:n=\"\",language:a=\"jsx\",theme:l=f}=e,o=y(e,W);const{element:c,error:s,code:i,onChange:p}=h(g({initialCode:n},o));/*#__PURE__*/return t.createElement(P.Provider,{value:{element:c,error:s,code:i,onChange:p,language:a,theme:l}},r)},x=e=>{const{code:r,language:n,theme:a,onChange:l}=k();/*#__PURE__*/return t.createElement(E,g({value:r,language:n,theme:a,onChange:l},e))},O=[\"Component\"],w=e=>{let{Component:r=\"div\"}=e,n=y(e,O);const{element:a}=k();/*#__PURE__*/return t.createElement(r,n,a)},N=e=>{const{error:r}=k();return r?/*#__PURE__*/t.createElement(\"pre\",e,r):/*#__PURE__*/t.createElement(t.Fragment,null)};export{C as CodeBlock,E as CodeEditor,P as LiveContext,x as LiveEditor,N as LiveError,w as LivePreview,j as LiveProvider,f as defaultTheme,k as useLiveContext,h as useLiveRunner};\n^^^^^^\n\n SyntaxError: Cannot use import statement outside a module\n at Object.compileFunction (node:vm:360:18)\n at wrapSafe (node:internal/modules/cjs/loader:1084:15)\n at Module._compile (node:internal/modules/cjs/loader:1119:27)\n at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)\n at Module.load (node:internal/modules/cjs/loader:1033:32)\n at Function.Module._load (node:internal/modules/cjs/loader:868:12)\n at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)\n at ModuleJob.run (node:internal/modules/esm/module_job:193:25)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\n at async Promise.all (index 0)\n";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// https://github.com/vikejs/vike/discussions/571#discussioncomment-6137618
|
|
2
|
+
export const errror_cannot_use_import_outside_of_module = `
|
|
3
|
+
import{useRunner as e}from"react-runner";export*from"react-runner";import t,{useState as r,useEffect as n,Fragment as a,useCallback as l,useRef as o,useMemo as c,createContext as s,useContext as i}from"react";import p from"react-simple-code-editor";import m,{Prism as u}from"prism-react-renderer";function g(){return g=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},g.apply(this,arguments)}function y(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}const d=["initialCode","transformCode"],h=t=>{let{initialCode:a="",transformCode:l}=t,o=y(t,d);const[c,s]=r(a),{element:i,error:p}=e(g({code:l?l(c):c},o));return n(()=>{s(a)},[a]),{element:i,error:p,code:c,onChange:s}},f={plain:{color:"#ffffff",backgroundColor:"#282c34"},styles:[{types:["comment","block-comment","prolog","doctype","cdata"],style:{color:"#b2b2b2"}},{types:["property","number","function-name","constant","symbol","deleted"],style:{color:"#5a9bcf"}},{types:["boolean"],style:{color:"#ff8b50"}},{types:["tag"],style:{color:"#fc929e"}},{types:["string","attr-value"],style:{color:"#8dc891"}},{types:["punctuation"],style:{color:"#88c6Be"}},{types:["selector","char","builtin","inserted"],style:{color:"#d8dee9"}},{types:["function"],style:{color:"#79b6f2"}},{types:["operator","entity","url","variable"],style:{color:"#d7deea"}},{types:["keyword"],style:{color:"#c5a5c5"}},{types:["atrule","class-name"],style:{color:"#fac863"}},{types:["important"],style:{fontWeight:"400"}},{types:["bold"],style:{fontWeight:"700"}},{types:["italic"],style:{fontStyle:"italic"}},{types:["entity"],style:{cursor:"help"}},{types:["namespace"],style:{opacity:.7}}]},b=["children","language","theme","Prism","padding","noWrapper","noWrap","className","style"],C=e=>{let{children:r,language:n="jsx",theme:l=f,Prism:o=u,padding:c=10,noWrapper:s,noWrap:i,className:p,style:d}=e,h=y(e,b);/*#__PURE__*/return t.createElement(m,{code:r||"",language:n,Prism:o,theme:l},({className:e,style:r,tokens:n,getLineProps:l,getTokenProps:o})=>{const m=n.map((e,r)=>/*#__PURE__*/t.createElement(a,{key:r},/*#__PURE__*/t.createElement("span",l({line:e}),e.map((e,r)=>/*#__PURE__*/t.createElement("span",o({token:e,key:r})))),"\\n"));return s?m:/*#__PURE__*/t.createElement("pre",g({className:p?:e,style:g({},r,{margin:0,padding:c,whiteSpace:i?"pre":"pre-wrap"},d)},h),m)})},v=["defaultValue","value","language","theme","Prism","highlight","padding","onChange"],E=e=>{let{defaultValue:n,value:a,language:s="jsx",theme:i=f,Prism:m,highlight:u,padding:d=10,onChange:h}=e,b=y(e,v);const[E,P]=r(n||""),k=void 0!==a,W=l(e=>/*#__PURE__*/t.createElement(C,{language:s,theme:i,Prism:m,noWrapper:!0},e),[s,i,m]),j=o(h);j.current=h;const x=l(e=>{k||P(e),null==j.current||j.current(e)},[k]),O=c(()=>g({},i.plain,b.style),[i.plain,b.style]);/*#__PURE__*/return t.createElement(p,g({},b,{highlight:u||W,padding:d,value:k?a:E,onValueChange:x,style:O}))},P=s({}),k=()=>i(P),W=["children","code","language","theme"],j=e=>{let{children:r,code:n="",language:a="jsx",theme:l=f}=e,o=y(e,W);const{element:c,error:s,code:i,onChange:p}=h(g({initialCode:n},o));/*#__PURE__*/return t.createElement(P.Provider,{value:{element:c,error:s,code:i,onChange:p,language:a,theme:l}},r)},x=e=>{const{code:r,language:n,theme:a,onChange:l}=k();/*#__PURE__*/return t.createElement(E,g({value:r,language:n,theme:a,onChange:l},e))},O=["Component"],w=e=>{let{Component:r="div"}=e,n=y(e,O);const{element:a}=k();/*#__PURE__*/return t.createElement(r,n,a)},N=e=>{const{error:r}=k();return r?/*#__PURE__*/t.createElement("pre",e,r):/*#__PURE__*/t.createElement(t.Fragment,null)};export{C as CodeBlock,E as CodeEditor,P as LiveContext,x as LiveEditor,N as LiveError,w as LivePreview,j as LiveProvider,f as defaultTheme,k as useLiveContext,h as useLiveRunner};
|
|
4
|
+
^^^^^^
|
|
5
|
+
|
|
6
|
+
SyntaxError: Cannot use import statement outside a module
|
|
7
|
+
at Object.compileFunction (node:vm:360:18)
|
|
8
|
+
at wrapSafe (node:internal/modules/cjs/loader:1084:15)
|
|
9
|
+
at Module._compile (node:internal/modules/cjs/loader:1119:27)
|
|
10
|
+
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
|
|
11
|
+
at Module.load (node:internal/modules/cjs/loader:1033:32)
|
|
12
|
+
at Function.Module._load (node:internal/modules/cjs/loader:868:12)
|
|
13
|
+
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
|
|
14
|
+
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
|
|
15
|
+
at processTicksAndRejections (node:internal/process/task_queues:96:5)
|
|
16
|
+
at async Promise.all (index 0)
|
|
17
|
+
`;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { logHintForCjsEsmError };
|
|
2
|
+
export { isCjsEsmError };
|
|
3
|
+
export { isReactInvalidComponentError };
|
|
4
|
+
export { getHint };
|
|
5
|
+
declare function logHintForCjsEsmError(error: unknown): void;
|
|
6
|
+
declare function getHint(error: unknown): null | string;
|
|
7
|
+
declare function isReactInvalidComponentError(error: unknown): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* `false` -> noop
|
|
10
|
+
* `true` -> generic message
|
|
11
|
+
* `'some-npm-package'` -> add some-npm-package to `ssr.noExternal`
|
|
12
|
+
*/
|
|
13
|
+
declare function isCjsEsmError(error: unknown): boolean | string[];
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
export { logHintForCjsEsmError };
|
|
2
|
+
// For ./logHintForCjsEsmError/*.spec.ts
|
|
3
|
+
export { isCjsEsmError };
|
|
4
|
+
export { isReactInvalidComponentError };
|
|
5
|
+
export { getHint };
|
|
6
|
+
import pc from '@brillout/picocolors';
|
|
7
|
+
import { assert, formatHintLog, isNotNullish, isObject, unique, joinEnglish } from '../utils.js';
|
|
8
|
+
function logHintForCjsEsmError(error) {
|
|
9
|
+
/* Collect errors for ./logHintForCjsEsmError.spec.ts
|
|
10
|
+
collectError(error)
|
|
11
|
+
//*/
|
|
12
|
+
const hint = getHint(error);
|
|
13
|
+
if (hint)
|
|
14
|
+
logHint(hint);
|
|
15
|
+
}
|
|
16
|
+
function getHint(error) {
|
|
17
|
+
if (isReactInvalidComponentError(error)) {
|
|
18
|
+
const hint = 'To fix this error, see https://vike.dev/broken-npm-package#react-invalid-component';
|
|
19
|
+
return hint;
|
|
20
|
+
}
|
|
21
|
+
const res = isCjsEsmError(error);
|
|
22
|
+
if (res) {
|
|
23
|
+
const packageNames = res === true ? null : res;
|
|
24
|
+
const hint = [
|
|
25
|
+
'Error could be a CJS/ESM issue, consider ',
|
|
26
|
+
!packageNames || packageNames.length === 0
|
|
27
|
+
? 'using'
|
|
28
|
+
: `adding ${joinEnglish(packageNames.map((p) => pc.cyan(p)), 'or')} to`,
|
|
29
|
+
` ${pc.cyan('ssr.noExternal')}`,
|
|
30
|
+
', see https://vike.dev/broken-npm-package'
|
|
31
|
+
].join('');
|
|
32
|
+
return hint;
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
function logHint(hint) {
|
|
37
|
+
hint = formatHintLog(hint);
|
|
38
|
+
console.error(hint);
|
|
39
|
+
}
|
|
40
|
+
function isReactInvalidComponentError(error) {
|
|
41
|
+
const anywhere = getAnywhere(error);
|
|
42
|
+
return includes(anywhere, 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)');
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* `false` -> noop
|
|
46
|
+
* `true` -> generic message
|
|
47
|
+
* `'some-npm-package'` -> add some-npm-package to `ssr.noExternal`
|
|
48
|
+
*/
|
|
49
|
+
function isCjsEsmError(error) {
|
|
50
|
+
const message = getErrMessage(error);
|
|
51
|
+
const anywhere = getAnywhere(error);
|
|
52
|
+
const packageName_stack1 = getPackageName_stack1(error);
|
|
53
|
+
const packageName_stack2 = getPackageName_stack2(error);
|
|
54
|
+
const isRelatedToNodeModules = !!packageName_stack1 || !!packageName_stack2 || includesNodeModules(message);
|
|
55
|
+
// const relatedNpmPackages = normalize([packageName_stack1, packageName_stack2, extractFromNodeModulesPath(message)])
|
|
56
|
+
// ERR_UNSUPPORTED_DIR_IMPORT
|
|
57
|
+
{
|
|
58
|
+
const packageNames = parseNodeModulesPathMessage('ERR_UNSUPPORTED_DIR_IMPORT', anywhere);
|
|
59
|
+
if (packageNames)
|
|
60
|
+
return packageNames;
|
|
61
|
+
}
|
|
62
|
+
// ERR_UNKNOWN_FILE_EXTENSION
|
|
63
|
+
{
|
|
64
|
+
const packageNames = parseUnkownFileExtensionMessage(anywhere);
|
|
65
|
+
if (packageNames)
|
|
66
|
+
return packageNames;
|
|
67
|
+
}
|
|
68
|
+
{
|
|
69
|
+
const packageNames = parseNodeModulesPathMessage('ERR_UNKNOWN_FILE_EXTENSION', anywhere);
|
|
70
|
+
if (packageNames)
|
|
71
|
+
return packageNames;
|
|
72
|
+
}
|
|
73
|
+
{
|
|
74
|
+
const packageNames = parseNodeModulesPathMessage('is not exported', anywhere);
|
|
75
|
+
if (packageNames)
|
|
76
|
+
return packageNames;
|
|
77
|
+
}
|
|
78
|
+
// Using CJS inside ESM modules.
|
|
79
|
+
if (includes(anywhere, 'require is not a function') ||
|
|
80
|
+
includes(anywhere, 'exports is not defined') ||
|
|
81
|
+
includes(anywhere, 'module is not defined') ||
|
|
82
|
+
includes(anywhere, 'window is not defined') ||
|
|
83
|
+
includes(anywhere, 'not defined in ES')) {
|
|
84
|
+
if (packageName_stack1)
|
|
85
|
+
return packageName_stack1;
|
|
86
|
+
}
|
|
87
|
+
if (includes(anywhere, "Unexpected token 'export'")) {
|
|
88
|
+
if (packageName_stack2)
|
|
89
|
+
return packageName_stack2;
|
|
90
|
+
if (packageName_stack1)
|
|
91
|
+
return packageName_stack1;
|
|
92
|
+
}
|
|
93
|
+
// ERR_REQUIRE_ESM
|
|
94
|
+
if (includes(anywhere, 'ERR_REQUIRE_ESM')) {
|
|
95
|
+
/* The issue is the importer, not the importee.
|
|
96
|
+
if (relatedNpmPackages) return relatedNpmPackages
|
|
97
|
+
*/
|
|
98
|
+
{
|
|
99
|
+
if (packageName_stack1)
|
|
100
|
+
return packageName_stack1;
|
|
101
|
+
}
|
|
102
|
+
if (isRelatedToNodeModules)
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
/* The following two wrongfully match user land errors
|
|
106
|
+
{
|
|
107
|
+
const packageNames = parseNodeModulesPath('ERR_REQUIRE_ESM', anywhere)
|
|
108
|
+
if (packageNames) return packageNames
|
|
109
|
+
}
|
|
110
|
+
{
|
|
111
|
+
const packageNames = parseNodeModulesPath('Must use import', anywhere)
|
|
112
|
+
if (packageNames) return packageNames
|
|
113
|
+
}
|
|
114
|
+
*/
|
|
115
|
+
// `SyntaxError: Named export '${exportName}' not found. The requested module '${packageName}' is a CommonJS module, which may not support all module.exports as named exports.`
|
|
116
|
+
{
|
|
117
|
+
const packageNames = parseImportFrom(anywhere);
|
|
118
|
+
if (packageNames)
|
|
119
|
+
return packageNames;
|
|
120
|
+
}
|
|
121
|
+
if (includes(anywhere, 'Cannot read properties of undefined')) {
|
|
122
|
+
if (isRelatedToNodeModules) {
|
|
123
|
+
/* We return true because relatedNpmPackages points to the importer but the problematic npm package is the importee
|
|
124
|
+
if (relatedNpmPackages) return relatedNpmPackages
|
|
125
|
+
*/
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// ERR_MODULE_NOT_FOUND
|
|
130
|
+
{
|
|
131
|
+
const packageNames = parseCannotFindMessage(anywhere);
|
|
132
|
+
if (packageNames)
|
|
133
|
+
return packageNames;
|
|
134
|
+
}
|
|
135
|
+
if (
|
|
136
|
+
// `SyntaxError: Cannot use import statement outside a module`.
|
|
137
|
+
// Since user code is always ESM, this error must always originate from an npm package.
|
|
138
|
+
includes(anywhere, 'Cannot use import statement') ||
|
|
139
|
+
// `SyntaxError: Named export '${exportName}' not found. The requested module '${packageName}' is a CommonJS module, which may not support all module.exports as named exports.`
|
|
140
|
+
// It seems that this always points to an npm package import.
|
|
141
|
+
/Named export.*not found/i.test(anywhere)) {
|
|
142
|
+
/* We return true even if fromNodeModules is false because the errors always relate to npm packages.
|
|
143
|
+
if (fromNodeModules) return true
|
|
144
|
+
*/
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
function parseCannotFindMessage(str) {
|
|
150
|
+
const match = /Cannot find \S+ '(\S+)' imported from (\S+)/.exec(str);
|
|
151
|
+
if (!match)
|
|
152
|
+
return false;
|
|
153
|
+
// const packageNameCannotFind = extractFromPath(match[1]!)
|
|
154
|
+
const packageNameFrom = extractFromPath(match[2]);
|
|
155
|
+
return normalize([
|
|
156
|
+
// packageNameCannotFind,
|
|
157
|
+
packageNameFrom
|
|
158
|
+
]);
|
|
159
|
+
}
|
|
160
|
+
function parseUnkownFileExtensionMessage(str) {
|
|
161
|
+
const match = /Unknown file extension "\S+" for (\S+)/.exec(str);
|
|
162
|
+
if (!match)
|
|
163
|
+
return false;
|
|
164
|
+
const filePath = match[1];
|
|
165
|
+
const packageName = extractFromPath(filePath);
|
|
166
|
+
return normalize([packageName]);
|
|
167
|
+
}
|
|
168
|
+
function parseImportFrom(str) {
|
|
169
|
+
const match = /\bimport\b.*?\bfrom\b\s*?"(.+?)"/.exec(str);
|
|
170
|
+
if (!match)
|
|
171
|
+
return false;
|
|
172
|
+
const importPath = match[1];
|
|
173
|
+
const packageName = extractFromPath(importPath);
|
|
174
|
+
return normalize([packageName]);
|
|
175
|
+
}
|
|
176
|
+
function parseNodeModulesPathMessage(begin, str) {
|
|
177
|
+
str = str.replaceAll('\\', '/');
|
|
178
|
+
const regex = new RegExp(`${begin}.*(node_modules\\/\\S+)`);
|
|
179
|
+
const match = regex.exec(str);
|
|
180
|
+
if (!match)
|
|
181
|
+
return false;
|
|
182
|
+
const importPath = match[1];
|
|
183
|
+
return extractFromNodeModulesPath(importPath);
|
|
184
|
+
}
|
|
185
|
+
function getPackageName_stack1(err) {
|
|
186
|
+
const errStack = getErrStack(err);
|
|
187
|
+
if (!errStack)
|
|
188
|
+
return false;
|
|
189
|
+
const firstLineStackTrace = errStack.split('\n').filter((line) => line.startsWith(' at '))[0];
|
|
190
|
+
if (!firstLineStackTrace)
|
|
191
|
+
return false;
|
|
192
|
+
return extractFromNodeModulesPath(firstLineStackTrace);
|
|
193
|
+
}
|
|
194
|
+
/** See https://github.com/brillout/repro_node-syntax-error#nodejs-behavior */
|
|
195
|
+
function getPackageName_stack2(err) {
|
|
196
|
+
const errStack = getErrStack(err);
|
|
197
|
+
if (!errStack)
|
|
198
|
+
return false;
|
|
199
|
+
const firstLine = errStack.trim().split('\n')[0];
|
|
200
|
+
return extractFromNodeModulesPath(firstLine);
|
|
201
|
+
}
|
|
202
|
+
function extractFromPath(filePath) {
|
|
203
|
+
assert(filePath);
|
|
204
|
+
filePath = clean(filePath);
|
|
205
|
+
filePath = filePath.replaceAll('\\', '/');
|
|
206
|
+
let packageName;
|
|
207
|
+
if (!filePath.includes('node_modules/')) {
|
|
208
|
+
packageName = filePath;
|
|
209
|
+
if (packageName.startsWith('/'))
|
|
210
|
+
return null;
|
|
211
|
+
if (packageName.startsWith('.'))
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
packageName = filePath.split('node_modules/').pop();
|
|
216
|
+
// This assert is fairly risk, we should eventually remove it
|
|
217
|
+
assert(!packageName.startsWith('.'));
|
|
218
|
+
// This assert is fairly risk, we should eventually remove it
|
|
219
|
+
assert(!packageName.startsWith('/'));
|
|
220
|
+
}
|
|
221
|
+
if (!packageName)
|
|
222
|
+
return null;
|
|
223
|
+
packageName = packageName.split('/').slice(0, 2).join('/');
|
|
224
|
+
if (!packageName.startsWith('@')) {
|
|
225
|
+
packageName = packageName.split('/')[0];
|
|
226
|
+
}
|
|
227
|
+
packageName = clean(packageName);
|
|
228
|
+
assert(!['vite', 'vike'].includes(packageName));
|
|
229
|
+
return packageName;
|
|
230
|
+
}
|
|
231
|
+
function clean(packageName) {
|
|
232
|
+
const b = ['"', "'", '(', ')'];
|
|
233
|
+
if (b.includes(packageName[0])) {
|
|
234
|
+
packageName = packageName.slice(1);
|
|
235
|
+
}
|
|
236
|
+
if (b.includes(packageName[packageName.length - 1])) {
|
|
237
|
+
packageName = packageName.slice(0, -1);
|
|
238
|
+
}
|
|
239
|
+
return packageName;
|
|
240
|
+
}
|
|
241
|
+
function extractFromNodeModulesPath(str) {
|
|
242
|
+
if (!includesNodeModules(str))
|
|
243
|
+
return false;
|
|
244
|
+
const packageName = extractFromPath(str);
|
|
245
|
+
assert(packageName);
|
|
246
|
+
return normalize([packageName]);
|
|
247
|
+
}
|
|
248
|
+
function includes(str1, str2) {
|
|
249
|
+
return !!str1 && str1.toLowerCase().includes(str2.toLowerCase());
|
|
250
|
+
}
|
|
251
|
+
function includesNodeModules(str) {
|
|
252
|
+
if (!str)
|
|
253
|
+
return false;
|
|
254
|
+
str = str.replaceAll('\\', '/');
|
|
255
|
+
if (!str.includes('node_modules/'))
|
|
256
|
+
return false;
|
|
257
|
+
if (str.includes('node_modules/vite/'))
|
|
258
|
+
return false;
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
function normalize(packageNames) {
|
|
262
|
+
const result = unique(packageNames.filter(isNotNullish));
|
|
263
|
+
if (result.length === 0)
|
|
264
|
+
return false;
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
function getErrMessage(err) {
|
|
268
|
+
if (!isObject(err))
|
|
269
|
+
return null;
|
|
270
|
+
if (!err.message)
|
|
271
|
+
return null;
|
|
272
|
+
if (typeof err.message !== 'string')
|
|
273
|
+
return null;
|
|
274
|
+
return err.message;
|
|
275
|
+
}
|
|
276
|
+
function getErrCode(err) {
|
|
277
|
+
if (!isObject(err))
|
|
278
|
+
return null;
|
|
279
|
+
if (!err.code)
|
|
280
|
+
return null;
|
|
281
|
+
if (typeof err.code !== 'string')
|
|
282
|
+
return null;
|
|
283
|
+
return err.code;
|
|
284
|
+
}
|
|
285
|
+
function getErrStack(err) {
|
|
286
|
+
if (!isObject(err))
|
|
287
|
+
return null;
|
|
288
|
+
if (!err.stack)
|
|
289
|
+
return null;
|
|
290
|
+
if (typeof err.stack !== 'string')
|
|
291
|
+
return null;
|
|
292
|
+
return err.stack;
|
|
293
|
+
}
|
|
294
|
+
function getAnywhere(error) {
|
|
295
|
+
const code = getErrCode(error);
|
|
296
|
+
const message = getErrMessage(error);
|
|
297
|
+
const stack = getErrStack(error);
|
|
298
|
+
const anywhere = [code, message, stack].filter(Boolean).join('\n');
|
|
299
|
+
return anywhere;
|
|
300
|
+
}
|
|
301
|
+
function collectError(err) {
|
|
302
|
+
console.log([
|
|
303
|
+
'{',
|
|
304
|
+
` message: ${JSON.stringify(err.message)},`,
|
|
305
|
+
` code: ${JSON.stringify(err.code)},`,
|
|
306
|
+
' stack: `\n' + err.stack + '\n`',
|
|
307
|
+
'}'
|
|
308
|
+
].join('\n'));
|
|
309
|
+
/* For reproductions using older vite-plugin-ssr versions, do one of the following.
|
|
310
|
+
- If upon pre-rendering:https: //github.com/brillout/repro_node-syntax-error#error-catched-by-vite-plugin-ssr
|
|
311
|
+
- Inject the logger inside `catch` in node_modules/vite-plugin-ssr/dist/esm/node/runtime/renderPage.js
|
|
312
|
+
- Inject the following inside `configResolved(config_)` at node_modules/vite-plugin-ssr/dist/cjs/node/plugin/plugins/devConfig/index.js
|
|
313
|
+
```js
|
|
314
|
+
config_.logger.error = (msg, options) => {
|
|
315
|
+
const { error } = options;
|
|
316
|
+
if (error) return;
|
|
317
|
+
console.log(...);
|
|
318
|
+
};
|
|
319
|
+
```
|
|
320
|
+
*/
|
|
321
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// Logger used for the production server.
|
|
2
2
|
// Any other environement (dev, preview, build, and pre-rendering) uses loggerNotProd.ts instead.
|
|
3
3
|
export { logErrorProd };
|
|
4
|
+
export { onRuntimeError };
|
|
4
5
|
import { isAbortError } from '../../../shared/route/abort.js';
|
|
5
6
|
import { setAlreadyLogged } from './isNewError.js';
|
|
6
7
|
import { isObject, warnIfErrorIsNotObject } from '../utils.js';
|
|
7
8
|
import pc from '@brillout/picocolors';
|
|
9
|
+
import { logHintForCjsEsmError } from './logHintForCjsEsmError.js';
|
|
8
10
|
function logErrorProd(err, _httpRquestId) {
|
|
9
11
|
warnIfErrorIsNotObject(err);
|
|
10
12
|
setAlreadyLogged(err);
|
|
@@ -14,4 +16,10 @@ function logErrorProd(err, _httpRquestId) {
|
|
|
14
16
|
// We ensure we print a string; Cloudflare Workers doesn't seem to properly stringify `Error` objects.
|
|
15
17
|
const errStr = isObject(err) && 'stack' in err ? String(err.stack) : String(err);
|
|
16
18
|
console.error(pc.red(errStr));
|
|
19
|
+
onRuntimeError(err);
|
|
20
|
+
}
|
|
21
|
+
// Every server-side runtime error is expected to go through onRuntimeError(). (In principle, any runtime error is (or at least should) be catched by Vike, otherwise Vike couldn't render the error page.)
|
|
22
|
+
function onRuntimeError(err) {
|
|
23
|
+
// The more runtime errors we pass to logHintForCjsEsmError() the better.
|
|
24
|
+
logHintForCjsEsmError(err);
|
|
17
25
|
}
|
|
@@ -48,4 +48,5 @@ export * from '../../utils/warnIfErrorIsNotObject.js';
|
|
|
48
48
|
export * from '../../utils/stripAnsi.js';
|
|
49
49
|
export * from '../../utils/getTerminWidth.js';
|
|
50
50
|
export * from '../../utils/truncateString.js';
|
|
51
|
-
export * from '../../utils/
|
|
51
|
+
export * from '../../utils/formatHintLog.js';
|
|
52
|
+
export * from '../../utils/joinEnglish.js';
|
|
@@ -51,4 +51,5 @@ export * from '../../utils/warnIfErrorIsNotObject.js';
|
|
|
51
51
|
export * from '../../utils/stripAnsi.js';
|
|
52
52
|
export * from '../../utils/getTerminWidth.js';
|
|
53
53
|
export * from '../../utils/truncateString.js';
|
|
54
|
-
export * from '../../utils/
|
|
54
|
+
export * from '../../utils/formatHintLog.js';
|
|
55
|
+
export * from '../../utils/joinEnglish.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { assert } from './assert.js';
|
|
2
|
+
import { stripAnsi } from './stripAnsi.js';
|
|
3
|
+
export { formatHintLog };
|
|
4
|
+
function formatHintLog(msg) {
|
|
5
|
+
assert(msg.length > 0);
|
|
6
|
+
const msgLength = stripAnsi(msg).length;
|
|
7
|
+
const sep = '─'.repeat(msgLength);
|
|
8
|
+
return [
|
|
9
|
+
// prettier-ignore
|
|
10
|
+
`┌─${sep}─┐`,
|
|
11
|
+
`│ ${msg} │`,
|
|
12
|
+
`└─${sep}─┘`
|
|
13
|
+
].join('\n');
|
|
14
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export type { ProjectTag };
|
|
3
3
|
export { PROJECT_VERSION };
|
|
4
|
-
declare const PROJECT_VERSION: "0.4.153-commit-
|
|
4
|
+
declare const PROJECT_VERSION: "0.4.153-commit-e631897";
|
|
5
5
|
type PackageName = typeof projectInfo.npmPackageName;
|
|
6
6
|
type ProjectVersion = typeof projectInfo.projectVersion;
|
|
7
7
|
type ProjectTag = `[${PackageName}]` | `[${PackageName}@${ProjectVersion}]`;
|
|
8
8
|
declare const projectInfo: {
|
|
9
9
|
projectName: "Vike";
|
|
10
|
-
projectVersion: "0.4.153-commit-
|
|
10
|
+
projectVersion: "0.4.153-commit-e631897";
|
|
11
11
|
npmPackageName: "vike";
|
|
12
12
|
githubRepository: "https://github.com/vikejs/vike";
|
|
13
13
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
3
|
import { onProjectInfo } from './assertSingleInstance.js';
|
|
4
|
-
const PROJECT_VERSION = '0.4.153-commit-
|
|
4
|
+
const PROJECT_VERSION = '0.4.153-commit-e631897';
|
|
5
5
|
const projectInfo = {
|
|
6
6
|
projectName: 'Vike',
|
|
7
7
|
projectVersion: PROJECT_VERSION,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.153-commit-
|
|
3
|
+
"version": "0.4.153-commit-e631897",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "tsc --watch",
|
|
6
6
|
"build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@brillout/json-serializer": "^0.5.8",
|
|
17
17
|
"@brillout/picocolors": "^1.0.10",
|
|
18
18
|
"@brillout/require-shim": "^0.1.2",
|
|
19
|
-
"@brillout/vite-plugin-import-build": "^0.3.
|
|
19
|
+
"@brillout/vite-plugin-import-build": "^0.3.3",
|
|
20
20
|
"acorn": "^8.0.0",
|
|
21
21
|
"cac": "^6.0.0",
|
|
22
22
|
"es-module-lexer": "^1.0.0",
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.autoRetry = void 0;
|
|
4
|
-
const sleep_js_1 = require("./sleep.js");
|
|
5
|
-
async function autoRetry(fn, timeout) {
|
|
6
|
-
const interval = 30;
|
|
7
|
-
const numberOfTries = timeout / interval;
|
|
8
|
-
let i = 0;
|
|
9
|
-
while (true) {
|
|
10
|
-
try {
|
|
11
|
-
await fn();
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
catch (err) {
|
|
15
|
-
i = i + 1;
|
|
16
|
-
if (i > numberOfTries) {
|
|
17
|
-
throw err;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
await (0, sleep_js_1.sleep)(interval);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.autoRetry = autoRetry;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export { autoRetry };
|
|
2
|
-
import { sleep } from './sleep.js';
|
|
3
|
-
async function autoRetry(fn, timeout) {
|
|
4
|
-
const interval = 30;
|
|
5
|
-
const numberOfTries = timeout / interval;
|
|
6
|
-
let i = 0;
|
|
7
|
-
while (true) {
|
|
8
|
-
try {
|
|
9
|
-
await fn();
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
catch (err) {
|
|
13
|
-
i = i + 1;
|
|
14
|
-
if (i > numberOfTries) {
|
|
15
|
-
throw err;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
await sleep(interval);
|
|
19
|
-
}
|
|
20
|
-
}
|