.
This commit is contained in:
+3
@@ -0,0 +1,3 @@
|
||||
import type { CacheControl } from '../../server/lib/cache-control';
|
||||
export declare function formatRevalidate(cacheControl: CacheControl): string;
|
||||
export declare function formatExpire(cacheControl: CacheControl): string;
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
0 && (module.exports = {
|
||||
formatExpire: null,
|
||||
formatRevalidate: null
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
formatExpire: function() {
|
||||
return formatExpire;
|
||||
},
|
||||
formatRevalidate: function() {
|
||||
return formatRevalidate;
|
||||
}
|
||||
});
|
||||
const timeUnits = [
|
||||
{
|
||||
label: 'y',
|
||||
seconds: 31536000
|
||||
},
|
||||
{
|
||||
label: 'w',
|
||||
seconds: 604800
|
||||
},
|
||||
{
|
||||
label: 'd',
|
||||
seconds: 86400
|
||||
},
|
||||
{
|
||||
label: 'h',
|
||||
seconds: 3600
|
||||
},
|
||||
{
|
||||
label: 'm',
|
||||
seconds: 60
|
||||
},
|
||||
{
|
||||
label: 's',
|
||||
seconds: 1
|
||||
}
|
||||
];
|
||||
function humanReadableTimeRounded(seconds) {
|
||||
// Find the largest fitting unit.
|
||||
let candidateIndex = timeUnits.length - 1;
|
||||
for(let i = 0; i < timeUnits.length; i++){
|
||||
if (seconds >= timeUnits[i].seconds) {
|
||||
candidateIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const candidate = timeUnits[candidateIndex];
|
||||
const value = seconds / candidate.seconds;
|
||||
const isExact = Number.isInteger(value);
|
||||
// For days and weeks only, check if using the next smaller unit yields an
|
||||
// exact result.
|
||||
if (!isExact && (candidate.label === 'd' || candidate.label === 'w')) {
|
||||
const nextUnit = timeUnits[candidateIndex + 1];
|
||||
const nextValue = seconds / nextUnit.seconds;
|
||||
if (Number.isInteger(nextValue)) {
|
||||
return `${nextValue}${nextUnit.label}`;
|
||||
}
|
||||
}
|
||||
if (isExact) {
|
||||
return `${value}${candidate.label}`;
|
||||
}
|
||||
return `≈${Math.round(value)}${candidate.label}`;
|
||||
}
|
||||
function formatRevalidate(cacheControl) {
|
||||
const { revalidate } = cacheControl;
|
||||
return revalidate ? humanReadableTimeRounded(revalidate) : '';
|
||||
}
|
||||
function formatExpire(cacheControl) {
|
||||
const { expire } = cacheControl;
|
||||
return expire ? humanReadableTimeRounded(expire) : '';
|
||||
}
|
||||
|
||||
//# sourceMappingURL=format.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/build/output/format.ts"],"sourcesContent":["import type { CacheControl } from '../../server/lib/cache-control'\n\nconst timeUnits = [\n { label: 'y', seconds: 31536000 },\n { label: 'w', seconds: 604800 },\n { label: 'd', seconds: 86400 },\n { label: 'h', seconds: 3600 },\n { label: 'm', seconds: 60 },\n { label: 's', seconds: 1 },\n]\n\nfunction humanReadableTimeRounded(seconds: number): string {\n // Find the largest fitting unit.\n let candidateIndex = timeUnits.length - 1\n for (let i = 0; i < timeUnits.length; i++) {\n if (seconds >= timeUnits[i].seconds) {\n candidateIndex = i\n break\n }\n }\n\n const candidate = timeUnits[candidateIndex]\n const value = seconds / candidate.seconds\n const isExact = Number.isInteger(value)\n\n // For days and weeks only, check if using the next smaller unit yields an\n // exact result.\n if (!isExact && (candidate.label === 'd' || candidate.label === 'w')) {\n const nextUnit = timeUnits[candidateIndex + 1]\n const nextValue = seconds / nextUnit.seconds\n\n if (Number.isInteger(nextValue)) {\n return `${nextValue}${nextUnit.label}`\n }\n }\n\n if (isExact) {\n return `${value}${candidate.label}`\n }\n\n return `≈${Math.round(value)}${candidate.label}`\n}\n\nexport function formatRevalidate(cacheControl: CacheControl): string {\n const { revalidate } = cacheControl\n\n return revalidate ? humanReadableTimeRounded(revalidate) : ''\n}\n\nexport function formatExpire(cacheControl: CacheControl): string {\n const { expire } = cacheControl\n\n return expire ? humanReadableTimeRounded(expire) : ''\n}\n"],"names":["formatExpire","formatRevalidate","timeUnits","label","seconds","humanReadableTimeRounded","candidateIndex","length","i","candidate","value","isExact","Number","isInteger","nextUnit","nextValue","Math","round","cacheControl","revalidate","expire"],"mappings":";;;;;;;;;;;;;;;IAiDgBA,YAAY;eAAZA;;IANAC,gBAAgB;eAAhBA;;;AAzChB,MAAMC,YAAY;IAChB;QAAEC,OAAO;QAAKC,SAAS;IAAS;IAChC;QAAED,OAAO;QAAKC,SAAS;IAAO;IAC9B;QAAED,OAAO;QAAKC,SAAS;IAAM;IAC7B;QAAED,OAAO;QAAKC,SAAS;IAAK;IAC5B;QAAED,OAAO;QAAKC,SAAS;IAAG;IAC1B;QAAED,OAAO;QAAKC,SAAS;IAAE;CAC1B;AAED,SAASC,yBAAyBD,OAAe;IAC/C,iCAAiC;IACjC,IAAIE,iBAAiBJ,UAAUK,MAAM,GAAG;IACxC,IAAK,IAAIC,IAAI,GAAGA,IAAIN,UAAUK,MAAM,EAAEC,IAAK;QACzC,IAAIJ,WAAWF,SAAS,CAACM,EAAE,CAACJ,OAAO,EAAE;YACnCE,iBAAiBE;YACjB;QACF;IACF;IAEA,MAAMC,YAAYP,SAAS,CAACI,eAAe;IAC3C,MAAMI,QAAQN,UAAUK,UAAUL,OAAO;IACzC,MAAMO,UAAUC,OAAOC,SAAS,CAACH;IAEjC,0EAA0E;IAC1E,gBAAgB;IAChB,IAAI,CAACC,WAAYF,CAAAA,UAAUN,KAAK,KAAK,OAAOM,UAAUN,KAAK,KAAK,GAAE,GAAI;QACpE,MAAMW,WAAWZ,SAAS,CAACI,iBAAiB,EAAE;QAC9C,MAAMS,YAAYX,UAAUU,SAASV,OAAO;QAE5C,IAAIQ,OAAOC,SAAS,CAACE,YAAY;YAC/B,OAAO,GAAGA,YAAYD,SAASX,KAAK,EAAE;QACxC;IACF;IAEA,IAAIQ,SAAS;QACX,OAAO,GAAGD,QAAQD,UAAUN,KAAK,EAAE;IACrC;IAEA,OAAO,CAAC,CAAC,EAAEa,KAAKC,KAAK,CAACP,SAASD,UAAUN,KAAK,EAAE;AAClD;AAEO,SAASF,iBAAiBiB,YAA0B;IACzD,MAAM,EAAEC,UAAU,EAAE,GAAGD;IAEvB,OAAOC,aAAad,yBAAyBc,cAAc;AAC7D;AAEO,SAASnB,aAAakB,YAA0B;IACrD,MAAM,EAAEE,MAAM,EAAE,GAAGF;IAEnB,OAAOE,SAASf,yBAAyBe,UAAU;AACrD","ignoreList":[0]}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import type { webpack } from 'next/dist/compiled/webpack/webpack';
|
||||
export declare function watchCompilers(client: webpack.Compiler, server: webpack.Compiler, edgeServer: webpack.Compiler): void;
|
||||
export declare function reportTrigger(trigger: string, url?: string): void;
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
0 && (module.exports = {
|
||||
reportTrigger: null,
|
||||
watchCompilers: null
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
reportTrigger: function() {
|
||||
return reportTrigger;
|
||||
},
|
||||
watchCompilers: function() {
|
||||
return watchCompilers;
|
||||
}
|
||||
});
|
||||
const _unistore = /*#__PURE__*/ _interop_require_default(require("next/dist/compiled/unistore"));
|
||||
const _formatwebpackmessages = /*#__PURE__*/ _interop_require_default(require("../../shared/lib/format-webpack-messages"));
|
||||
const _store = require("./store");
|
||||
const _constants = require("../../shared/lib/constants");
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
const buildStore = (0, _unistore.default)({
|
||||
// @ts-expect-error initial value
|
||||
client: {},
|
||||
// @ts-expect-error initial value
|
||||
server: {},
|
||||
// @ts-expect-error initial value
|
||||
edgeServer: {}
|
||||
});
|
||||
let buildWasDone = false;
|
||||
let clientWasLoading = true;
|
||||
let serverWasLoading = true;
|
||||
let edgeServerWasLoading = false;
|
||||
buildStore.subscribe((state)=>{
|
||||
const { client, server, edgeServer, trigger, url } = state;
|
||||
const { appUrl } = _store.store.getState();
|
||||
if (client.loading || server.loading || (edgeServer == null ? void 0 : edgeServer.loading)) {
|
||||
_store.store.setState({
|
||||
bootstrap: false,
|
||||
appUrl: appUrl,
|
||||
// If it takes more than 3 seconds to compile, mark it as loading status
|
||||
loading: true,
|
||||
trigger,
|
||||
url
|
||||
}, true);
|
||||
clientWasLoading = !buildWasDone && clientWasLoading || client.loading;
|
||||
serverWasLoading = !buildWasDone && serverWasLoading || server.loading;
|
||||
edgeServerWasLoading = !buildWasDone && edgeServerWasLoading || edgeServer.loading;
|
||||
buildWasDone = false;
|
||||
return;
|
||||
}
|
||||
buildWasDone = true;
|
||||
let partialState = {
|
||||
bootstrap: false,
|
||||
appUrl: appUrl,
|
||||
loading: false,
|
||||
typeChecking: false,
|
||||
totalModulesCount: (clientWasLoading ? client.totalModulesCount : 0) + (serverWasLoading ? server.totalModulesCount : 0) + (edgeServerWasLoading ? (edgeServer == null ? void 0 : edgeServer.totalModulesCount) || 0 : 0),
|
||||
hasEdgeServer: !!edgeServer
|
||||
};
|
||||
if (client.errors && clientWasLoading) {
|
||||
// Show only client errors
|
||||
_store.store.setState({
|
||||
...partialState,
|
||||
errors: client.errors,
|
||||
warnings: null
|
||||
}, true);
|
||||
} else if (server.errors && serverWasLoading) {
|
||||
_store.store.setState({
|
||||
...partialState,
|
||||
errors: server.errors,
|
||||
warnings: null
|
||||
}, true);
|
||||
} else if (edgeServer.errors && edgeServerWasLoading) {
|
||||
_store.store.setState({
|
||||
...partialState,
|
||||
errors: edgeServer.errors,
|
||||
warnings: null
|
||||
}, true);
|
||||
} else {
|
||||
// Show warnings from all of them
|
||||
const warnings = [
|
||||
...client.warnings || [],
|
||||
...server.warnings || [],
|
||||
...edgeServer.warnings || []
|
||||
];
|
||||
_store.store.setState({
|
||||
...partialState,
|
||||
errors: null,
|
||||
warnings: warnings.length === 0 ? null : warnings
|
||||
}, true);
|
||||
}
|
||||
});
|
||||
function watchCompilers(client, server, edgeServer) {
|
||||
buildStore.setState({
|
||||
client: {
|
||||
loading: true
|
||||
},
|
||||
server: {
|
||||
loading: true
|
||||
},
|
||||
edgeServer: {
|
||||
loading: true
|
||||
},
|
||||
trigger: 'initial',
|
||||
url: undefined
|
||||
});
|
||||
function tapCompiler(key, compiler, onEvent) {
|
||||
compiler.hooks.invalid.tap(`NextJsInvalid-${key}`, ()=>{
|
||||
onEvent({
|
||||
loading: true
|
||||
});
|
||||
});
|
||||
compiler.hooks.done.tap(`NextJsDone-${key}`, (stats)=>{
|
||||
const { errors, warnings } = (0, _formatwebpackmessages.default)(stats.toJson({
|
||||
preset: 'errors-warnings',
|
||||
moduleTrace: true
|
||||
}));
|
||||
const hasErrors = !!(errors == null ? void 0 : errors.length);
|
||||
const hasWarnings = !!(warnings == null ? void 0 : warnings.length);
|
||||
onEvent({
|
||||
loading: false,
|
||||
totalModulesCount: stats.compilation.modules.size,
|
||||
errors: hasErrors ? errors : null,
|
||||
warnings: hasWarnings ? warnings : null
|
||||
});
|
||||
});
|
||||
}
|
||||
tapCompiler(_constants.COMPILER_NAMES.client, client, (status)=>{
|
||||
if (!status.loading && !buildStore.getState().server.loading && !buildStore.getState().edgeServer.loading && status.totalModulesCount > 0) {
|
||||
buildStore.setState({
|
||||
client: status,
|
||||
trigger: undefined,
|
||||
url: undefined
|
||||
});
|
||||
} else {
|
||||
buildStore.setState({
|
||||
client: status
|
||||
});
|
||||
}
|
||||
});
|
||||
tapCompiler(_constants.COMPILER_NAMES.server, server, (status)=>{
|
||||
if (!status.loading && !buildStore.getState().client.loading && !buildStore.getState().edgeServer.loading && status.totalModulesCount > 0) {
|
||||
buildStore.setState({
|
||||
server: status,
|
||||
trigger: undefined,
|
||||
url: undefined
|
||||
});
|
||||
} else {
|
||||
buildStore.setState({
|
||||
server: status
|
||||
});
|
||||
}
|
||||
});
|
||||
tapCompiler(_constants.COMPILER_NAMES.edgeServer, edgeServer, (status)=>{
|
||||
if (!status.loading && !buildStore.getState().client.loading && !buildStore.getState().server.loading && status.totalModulesCount > 0) {
|
||||
buildStore.setState({
|
||||
edgeServer: status,
|
||||
trigger: undefined,
|
||||
url: undefined
|
||||
});
|
||||
} else {
|
||||
buildStore.setState({
|
||||
edgeServer: status
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
function reportTrigger(trigger, url) {
|
||||
buildStore.setState({
|
||||
trigger,
|
||||
url
|
||||
});
|
||||
}
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+19
@@ -0,0 +1,19 @@
|
||||
export declare const prefixes: {
|
||||
readonly wait: string;
|
||||
readonly error: string;
|
||||
readonly warn: string;
|
||||
readonly ready: "▲";
|
||||
readonly info: string;
|
||||
readonly event: string;
|
||||
readonly trace: string;
|
||||
};
|
||||
export declare function bootstrap(message: string): void;
|
||||
export declare function wait(...message: any[]): void;
|
||||
export declare function error(...message: any[]): void;
|
||||
export declare function warn(...message: any[]): void;
|
||||
export declare function ready(...message: any[]): void;
|
||||
export declare function info(...message: any[]): void;
|
||||
export declare function event(...message: any[]): void;
|
||||
export declare function trace(...message: any[]): void;
|
||||
export declare function warnOnce(...message: any[]): void;
|
||||
export declare function errorOnce(...message: any[]): void;
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
0 && (module.exports = {
|
||||
bootstrap: null,
|
||||
error: null,
|
||||
errorOnce: null,
|
||||
event: null,
|
||||
info: null,
|
||||
prefixes: null,
|
||||
ready: null,
|
||||
trace: null,
|
||||
wait: null,
|
||||
warn: null,
|
||||
warnOnce: null
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
bootstrap: function() {
|
||||
return bootstrap;
|
||||
},
|
||||
error: function() {
|
||||
return error;
|
||||
},
|
||||
errorOnce: function() {
|
||||
return errorOnce;
|
||||
},
|
||||
event: function() {
|
||||
return event;
|
||||
},
|
||||
info: function() {
|
||||
return info;
|
||||
},
|
||||
prefixes: function() {
|
||||
return prefixes;
|
||||
},
|
||||
ready: function() {
|
||||
return ready;
|
||||
},
|
||||
trace: function() {
|
||||
return trace;
|
||||
},
|
||||
wait: function() {
|
||||
return wait;
|
||||
},
|
||||
warn: function() {
|
||||
return warn;
|
||||
},
|
||||
warnOnce: function() {
|
||||
return warnOnce;
|
||||
}
|
||||
});
|
||||
const _picocolors = require("../../lib/picocolors");
|
||||
const _lrucache = require("../../server/lib/lru-cache");
|
||||
const prefixes = {
|
||||
wait: (0, _picocolors.white)((0, _picocolors.bold)('○')),
|
||||
error: (0, _picocolors.red)((0, _picocolors.bold)('⨯')),
|
||||
warn: (0, _picocolors.yellow)((0, _picocolors.bold)('⚠')),
|
||||
ready: '▲',
|
||||
info: (0, _picocolors.white)((0, _picocolors.bold)(' ')),
|
||||
event: (0, _picocolors.green)((0, _picocolors.bold)('✓')),
|
||||
trace: (0, _picocolors.magenta)((0, _picocolors.bold)('»'))
|
||||
};
|
||||
const LOGGING_METHOD = {
|
||||
log: 'log',
|
||||
warn: 'warn',
|
||||
error: 'error'
|
||||
};
|
||||
function prefixedLog(prefixType, ...message) {
|
||||
if ((message[0] === '' || message[0] === undefined) && message.length === 1) {
|
||||
message.shift();
|
||||
}
|
||||
const consoleMethod = prefixType in LOGGING_METHOD ? LOGGING_METHOD[prefixType] : 'log';
|
||||
const prefix = prefixes[prefixType];
|
||||
// If there's no message, don't print the prefix but a new line
|
||||
if (message.length === 0) {
|
||||
console[consoleMethod]('');
|
||||
} else {
|
||||
// Ensure if there's ANSI escape codes it's concatenated into one string.
|
||||
// Chrome DevTool can only handle color if it's in one string.
|
||||
if (message.length === 1 && typeof message[0] === 'string') {
|
||||
console[consoleMethod](prefix + ' ' + message[0]);
|
||||
} else {
|
||||
console[consoleMethod](prefix, ...message);
|
||||
}
|
||||
}
|
||||
}
|
||||
function bootstrap(message) {
|
||||
console.log(message);
|
||||
}
|
||||
function wait(...message) {
|
||||
prefixedLog('wait', ...message);
|
||||
}
|
||||
function error(...message) {
|
||||
prefixedLog('error', ...message);
|
||||
}
|
||||
function warn(...message) {
|
||||
prefixedLog('warn', ...message);
|
||||
}
|
||||
function ready(...message) {
|
||||
prefixedLog('ready', ...message);
|
||||
}
|
||||
function info(...message) {
|
||||
prefixedLog('info', ...message);
|
||||
}
|
||||
function event(...message) {
|
||||
prefixedLog('event', ...message);
|
||||
}
|
||||
function trace(...message) {
|
||||
prefixedLog('trace', ...message);
|
||||
}
|
||||
const warnOnceCache = new _lrucache.LRUCache(10000, (value)=>value.length);
|
||||
function warnOnce(...message) {
|
||||
const key = message.join(' ');
|
||||
if (!warnOnceCache.has(key)) {
|
||||
warnOnceCache.set(key, key);
|
||||
warn(...message);
|
||||
}
|
||||
}
|
||||
const errorOnceCache = new _lrucache.LRUCache(10000, (value)=>value.length);
|
||||
function errorOnce(...message) {
|
||||
const key = message.join(' ');
|
||||
if (!errorOnceCache.has(key)) {
|
||||
errorOnceCache.set(key, key);
|
||||
error(...message);
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=log.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+24
@@ -0,0 +1,24 @@
|
||||
export type OutputState = {
|
||||
bootstrap: true;
|
||||
appUrl: string | null;
|
||||
bindAddr: string | null;
|
||||
logging: boolean;
|
||||
} | ({
|
||||
bootstrap: false;
|
||||
appUrl: string | null;
|
||||
bindAddr: string | null;
|
||||
logging: boolean;
|
||||
} & ({
|
||||
loading: true;
|
||||
trigger: string | undefined;
|
||||
url: string | undefined;
|
||||
} | {
|
||||
loading: false;
|
||||
typeChecking: boolean;
|
||||
totalModulesCount: number;
|
||||
errors: string[] | null;
|
||||
warnings: string[] | null;
|
||||
hasEdgeServer: boolean;
|
||||
}));
|
||||
export declare function formatTrigger(trigger: string): string;
|
||||
export declare const store: import("unistore").Store<OutputState>;
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
0 && (module.exports = {
|
||||
formatTrigger: null,
|
||||
store: null
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
formatTrigger: function() {
|
||||
return formatTrigger;
|
||||
},
|
||||
store: function() {
|
||||
return store;
|
||||
}
|
||||
});
|
||||
const _unistore = /*#__PURE__*/ _interop_require_default(require("next/dist/compiled/unistore"));
|
||||
const _trace = require("../../trace");
|
||||
const _swc = require("../swc");
|
||||
const _log = /*#__PURE__*/ _interop_require_wildcard(require("./log"));
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
function _getRequireWildcardCache(nodeInterop) {
|
||||
if (typeof WeakMap !== "function") return null;
|
||||
var cacheBabelInterop = new WeakMap();
|
||||
var cacheNodeInterop = new WeakMap();
|
||||
return (_getRequireWildcardCache = function(nodeInterop) {
|
||||
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
||||
})(nodeInterop);
|
||||
}
|
||||
function _interop_require_wildcard(obj, nodeInterop) {
|
||||
if (!nodeInterop && obj && obj.__esModule) {
|
||||
return obj;
|
||||
}
|
||||
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
||||
return {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
var cache = _getRequireWildcardCache(nodeInterop);
|
||||
if (cache && cache.has(obj)) {
|
||||
return cache.get(obj);
|
||||
}
|
||||
var newObj = {
|
||||
__proto__: null
|
||||
};
|
||||
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||
for(var key in obj){
|
||||
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
||||
if (desc && (desc.get || desc.set)) {
|
||||
Object.defineProperty(newObj, key, desc);
|
||||
} else {
|
||||
newObj[key] = obj[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
newObj.default = obj;
|
||||
if (cache) {
|
||||
cache.set(obj, newObj);
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
const MAX_LOG_SKIP_DURATION_MS = 3000;
|
||||
function formatTrigger(trigger) {
|
||||
// Format dynamic sitemap routes to simpler file path
|
||||
// e.g., /sitemap.xml[] -> /sitemap.xml
|
||||
if (trigger.includes('[__metadata_id__]')) {
|
||||
trigger = trigger.replace('/[__metadata_id__]', '/[id]');
|
||||
}
|
||||
if (trigger.length > 1 && trigger.endsWith('/')) {
|
||||
trigger = trigger.slice(0, -1);
|
||||
}
|
||||
return trigger;
|
||||
}
|
||||
const store = (0, _unistore.default)({
|
||||
appUrl: null,
|
||||
bindAddr: null,
|
||||
bootstrap: true,
|
||||
logging: true
|
||||
});
|
||||
let lastStore = {
|
||||
appUrl: null,
|
||||
bindAddr: null,
|
||||
bootstrap: true,
|
||||
logging: true
|
||||
};
|
||||
function hasStoreChanged(nextStore) {
|
||||
if ([
|
||||
...new Set([
|
||||
...Object.keys(lastStore),
|
||||
...Object.keys(nextStore)
|
||||
])
|
||||
].every((key)=>Object.is(lastStore[key], nextStore[key]))) {
|
||||
return false;
|
||||
}
|
||||
lastStore = nextStore;
|
||||
return true;
|
||||
}
|
||||
let startTime = 0;
|
||||
let trigger = '' // default, use empty string for trigger
|
||||
;
|
||||
let triggerUrl = undefined;
|
||||
let loadingLogTimer = null;
|
||||
let traceSpan = null;
|
||||
let logging = true;
|
||||
store.subscribe((state)=>{
|
||||
// Update persisted logging state
|
||||
if ('logging' in state) {
|
||||
logging = state.logging;
|
||||
}
|
||||
// If logging is disabled, do not log
|
||||
if (!logging) {
|
||||
return;
|
||||
}
|
||||
if (!hasStoreChanged(state)) {
|
||||
return;
|
||||
}
|
||||
if (state.bootstrap) {
|
||||
return;
|
||||
}
|
||||
if (state.loading) {
|
||||
if (state.trigger) {
|
||||
trigger = formatTrigger(state.trigger);
|
||||
triggerUrl = state.url;
|
||||
if (trigger !== 'initial') {
|
||||
traceSpan = (0, _trace.trace)('compile-path', undefined, {
|
||||
trigger: trigger
|
||||
});
|
||||
if (!loadingLogTimer) {
|
||||
// Only log compiling if compiled is not finished quickly
|
||||
loadingLogTimer = setTimeout(()=>{
|
||||
if (triggerUrl && triggerUrl !== trigger && process.env.NEXT_TRIGGER_URL) {
|
||||
_log.wait(`Compiling ${trigger} (${triggerUrl}) ...`);
|
||||
} else {
|
||||
_log.wait(`Compiling ${trigger} ...`);
|
||||
}
|
||||
}, MAX_LOG_SKIP_DURATION_MS);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (startTime === 0) {
|
||||
startTime = Date.now();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (state.errors) {
|
||||
// Log compilation errors
|
||||
_log.error(state.errors[0]);
|
||||
startTime = 0;
|
||||
// Ensure traces are flushed after each compile in development mode
|
||||
(0, _trace.flushAllTraces)();
|
||||
(0, _swc.teardownTraceSubscriber)();
|
||||
return;
|
||||
}
|
||||
let timeMessage = '';
|
||||
if (startTime) {
|
||||
const time = Date.now() - startTime;
|
||||
startTime = 0;
|
||||
timeMessage = ' ' + (time > 2000 ? `in ${Math.round(time / 100) / 10}s` : `in ${time}ms`);
|
||||
}
|
||||
let modulesMessage = '';
|
||||
if (state.totalModulesCount) {
|
||||
modulesMessage = ` (${state.totalModulesCount} modules)`;
|
||||
}
|
||||
if (state.warnings) {
|
||||
_log.warn(state.warnings.join('\n\n'));
|
||||
// Ensure traces are flushed after each compile in development mode
|
||||
(0, _trace.flushAllTraces)();
|
||||
(0, _swc.teardownTraceSubscriber)();
|
||||
return;
|
||||
}
|
||||
if (state.typeChecking) {
|
||||
_log.info(`bundled ${trigger}${timeMessage}${modulesMessage}, type checking...`);
|
||||
return;
|
||||
}
|
||||
if (trigger === 'initial') {
|
||||
trigger = '';
|
||||
} else {
|
||||
if (loadingLogTimer) {
|
||||
clearTimeout(loadingLogTimer);
|
||||
loadingLogTimer = null;
|
||||
}
|
||||
if (traceSpan) {
|
||||
traceSpan.stop();
|
||||
traceSpan = null;
|
||||
}
|
||||
trigger = '';
|
||||
}
|
||||
// Ensure traces are flushed after each compile in development mode
|
||||
(0, _trace.flushAllTraces)();
|
||||
(0, _swc.teardownTraceSubscriber)();
|
||||
});
|
||||
|
||||
//# sourceMappingURL=store.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user