vike 0.4.166-commit-a5e2596 → 0.4.167

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.
Files changed (30) hide show
  1. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
  2. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +2 -4
  3. package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +2 -4
  4. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +3 -3
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +5 -5
  6. package/dist/cjs/node/plugin/shared/isErrorDebug.js +1 -1
  7. package/dist/cjs/node/runtime/html/stream.js +5 -5
  8. package/dist/cjs/shared/page-configs/assertPlusFileExport.js +1 -3
  9. package/dist/cjs/utils/assertIsNotProductionRuntime.js +5 -5
  10. package/dist/cjs/utils/debug.js +48 -14
  11. package/dist/cjs/utils/projectInfo.js +1 -1
  12. package/dist/cjs/utils/trackLogs.js +1 -1
  13. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +31 -24
  14. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
  15. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +3 -5
  16. package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +3 -5
  17. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/debug.d.ts +1 -1
  18. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +4 -4
  19. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +5 -5
  20. package/dist/esm/node/plugin/shared/isErrorDebug.js +2 -2
  21. package/dist/esm/node/runtime/html/stream.js +5 -5
  22. package/dist/esm/shared/page-configs/assertPlusFileExport.js +1 -3
  23. package/dist/esm/utils/assertIsNotProductionRuntime.js +5 -5
  24. package/dist/esm/utils/debug.d.ts +5 -4
  25. package/dist/esm/utils/debug.js +45 -14
  26. package/dist/esm/utils/debugGlob.d.ts +1 -1
  27. package/dist/esm/utils/projectInfo.d.ts +2 -2
  28. package/dist/esm/utils/projectInfo.js +1 -1
  29. package/dist/esm/utils/trackLogs.js +2 -2
  30. package/package.json +1 -1
@@ -25,7 +25,7 @@ async function determineOptimizeDeps(config, isDev) {
25
25
  */
26
26
  config.optimizeDeps.include = [...include, ...normalizeInclude(config.optimizeDeps.include)];
27
27
  config.optimizeDeps.entries = [...entries, ...normalizeEntries(config.optimizeDeps.entries)];
28
- if (debug.isEnabled)
28
+ if (debug.isActivated)
29
29
  debug('config.optimizeDeps', {
30
30
  'config.optimizeDeps.entries': config.optimizeDeps.entries,
31
31
  'config.optimizeDeps.include': config.optimizeDeps.include
@@ -21,9 +21,7 @@ exports.extractAssetsRE = extractAssetsRE;
21
21
  const rawRE = /(\?|&)raw(?:&|$)/;
22
22
  const urlRE = /(\?|&)url(?:&|$)/;
23
23
  const EMPTY_MODULE_ID = 'virtual:vike:empty-module';
24
- const debugNamespace = 'vike:extractAssets';
25
- const debug = (0, utils_js_1.createDebugger)(debugNamespace);
26
- const debugEnabled = (0, utils_js_1.isDebugEnabled)(debugNamespace);
24
+ const debug = (0, utils_js_1.createDebugger)('vike:extractAssets');
27
25
  function extractAssetsPlugin() {
28
26
  let config;
29
27
  let configVike;
@@ -129,7 +127,7 @@ function extractAssetsPlugin() {
129
127
  }
130
128
  },
131
129
  config() {
132
- if (debugEnabled) {
130
+ if (debug.isActivated) {
133
131
  return { logLevel: 'silent' };
134
132
  }
135
133
  }
@@ -6,9 +6,7 @@ const parseEsModule_js_1 = require("../shared/parseEsModule.js");
6
6
  const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
7
7
  const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
8
8
  exports.extractExportNamesRE = extractExportNamesRE;
9
- const debugNamespace = 'vike:extractExportNames';
10
- const debug = (0, utils_js_1.createDebugger)(debugNamespace);
11
- const debugEnabled = (0, utils_js_1.isDebugEnabled)(debugNamespace);
9
+ const debug = (0, utils_js_1.createDebugger)('vike:extractExportNames');
12
10
  const globalObject = (0, utils_js_1.getGlobalObject)('extractExportNamesPlugin.ts', {});
13
11
  function extractExportNamesPlugin() {
14
12
  let isDev = false;
@@ -27,7 +25,7 @@ function extractExportNamesPlugin() {
27
25
  isDev = true;
28
26
  },
29
27
  config() {
30
- if (debugEnabled) {
28
+ if (debug.isActivated) {
31
29
  return { logLevel: 'silent' };
32
30
  }
33
31
  }
@@ -9,9 +9,9 @@ const assertPlusFileExport_js_1 = require("../../../../../shared/page-configs/as
9
9
  const utils_js_1 = require("../../../utils.js");
10
10
  function getConfigFileExport(fileExports, filePathToShowToUser) {
11
11
  (0, assertPlusFileExport_js_1.assertPlusFileExport)(fileExports, filePathToShowToUser, 'config');
12
- const fileExport = fileExports.default || fileExports.config;
13
- (0, utils_js_1.assert)('default' in fileExports !== 'config' in fileExports);
14
- const exportName = picocolors_1.default.cyan('default' in fileExports ? 'export default' : 'export { config }');
12
+ const usesNamedExport = !!fileExports.config;
13
+ const fileExport = usesNamedExport ? fileExports.config : fileExports.default;
14
+ const exportName = picocolors_1.default.cyan(usesNamedExport ? 'export { config }' : 'export default');
15
15
  (0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(fileExport), `The ${exportName} of ${filePathToShowToUser} should be an object (but it's ${picocolors_1.default.cyan(`typeof exportedValue === ${JSON.stringify(typeof fileExport)}`)} instead)`);
16
16
  return fileExport;
17
17
  }
@@ -40,10 +40,10 @@ async function transpileFile(filePath, transformImports, userRootDir) {
40
40
  const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
41
41
  (0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
42
42
  getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
43
- if (debug.isEnabled)
43
+ if (debug.isActivated)
44
44
  debug('transpile', filePathToShowToUserResolved);
45
45
  let { code, pointerImports } = await transpileWithEsbuild(filePath, userRootDir, transformImports);
46
- if (debug.isEnabled)
46
+ if (debug.isActivated)
47
47
  debug(`code, post esbuild (${filePathToShowToUserResolved})`, code);
48
48
  let isImportTransformed = false;
49
49
  if (transformImports) {
@@ -51,12 +51,12 @@ async function transpileFile(filePath, transformImports, userRootDir) {
51
51
  if (codeMod) {
52
52
  code = codeMod;
53
53
  isImportTransformed = true;
54
- if (debug.isEnabled)
54
+ if (debug.isActivated)
55
55
  debug(`code, post transformImports() (${filePathToShowToUserResolved})`, code);
56
56
  }
57
57
  }
58
58
  if (!isImportTransformed) {
59
- if (debug.isEnabled)
59
+ if (debug.isActivated)
60
60
  debug(`code, no transformImports() (${filePathToShowToUserResolved})`);
61
61
  }
62
62
  return code;
@@ -128,7 +128,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
128
128
  const isExternal = isPointerImport ||
129
129
  // npm package imports that aren't pointer imports (e.g. importing a Vite plugin)
130
130
  resolved.path.includes('/node_modules/');
131
- if (debug.isEnabled)
131
+ if (debug.isActivated)
132
132
  debug('onResolved()', { args, resolved, isPointerImport, isExternal });
133
133
  if (isExternal) {
134
134
  return { external: true, path: resolved.path };
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isErrorDebug = void 0;
4
4
  const utils_js_1 = require("../utils.js");
5
5
  function isErrorDebug() {
6
- return (0, utils_js_1.isDebugEnabled)('vike:error');
6
+ return (0, utils_js_1.isDebugActivated)('vike:error');
7
7
  }
8
8
  exports.isErrorDebug = isErrorDebug;
@@ -375,7 +375,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
375
375
  const writeChunk = (chunk) => {
376
376
  (0, utils_js_1.assert)(writableOriginal);
377
377
  writableOriginal.write(chunk);
378
- if (debug.isEnabled) {
378
+ if (debug.isActivated) {
379
379
  debug('data written (Node.js Writable)', String(chunk));
380
380
  }
381
381
  };
@@ -448,7 +448,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
448
448
  const writeChunk = (chunk) => {
449
449
  (0, utils_js_1.assert)(writerOriginal);
450
450
  writerOriginal.write(encodeForWebStream(chunk));
451
- if (debug.isEnabled) {
451
+ if (debug.isActivated) {
452
452
  debug('data written (Web Writable)', String(chunk));
453
453
  }
454
454
  };
@@ -541,12 +541,12 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
541
541
  // If readableOriginal doesn't implement readableOriginal.cancel() then it may still emit data after we close the stream. We therefore need to check whether we closed `controllerProxy`.
542
542
  !controllerProxyIsClosed) {
543
543
  controllerProxy.enqueue(encodeForWebStream(chunk));
544
- if (debug.isEnabled) {
544
+ if (debug.isActivated) {
545
545
  debug('data written (Web Readable)', String(chunk));
546
546
  }
547
547
  }
548
548
  else {
549
- if (debug.isEnabled) {
549
+ if (debug.isActivated) {
550
550
  debug('data emitted but not written (Web Readable)', String(chunk));
551
551
  }
552
552
  }
@@ -568,7 +568,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
568
568
  }
569
569
  const writeChunk = (chunk) => {
570
570
  readableProxy.push(chunk);
571
- if (debug.isEnabled) {
571
+ if (debug.isActivated) {
572
572
  debug('data written (Node.js Readable)', String(chunk));
573
573
  }
574
574
  };
@@ -28,9 +28,7 @@ function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
28
28
  }
29
29
  else {
30
30
  (0, utils_js_1.assert)(exportsAll.length === 2); // because `exportsInvalid.length === 0`
31
- (0, utils_js_1.assertWarning)(false, `${filePathToShowToUser} remove ${exportNamed} or ${exportDefault}`, {
32
- onlyOnce: true
33
- });
31
+ (0, utils_js_1.assertWarning)(false, `The exports of ${filePathToShowToUser} are ambiguous: remove ${exportDefault} or ${exportNamed}`, { onlyOnce: true });
34
32
  }
35
33
  }
36
34
  else {
@@ -14,35 +14,35 @@ exports.vikeVitePluginLoadedInProductionError = vikeVitePluginLoadedInProduction
14
14
  const env = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertIsNotProductionRuntime.ts', {});
15
15
  // Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
16
16
  function assertIsNotProductionRuntime() {
17
- if (debug.isEnabled)
17
+ if (debug.isActivated)
18
18
  debug('assertIsNotProductionRuntime()', new Error().stack);
19
19
  env.shouldNotBeProduction = true;
20
20
  }
21
21
  exports.assertIsNotProductionRuntime = assertIsNotProductionRuntime;
22
22
  // Called by Vite hook configureServer()
23
23
  function markEnvAsViteDev() {
24
- if (debug.isEnabled)
24
+ if (debug.isActivated)
25
25
  debug('markEnvAsViteDev()', new Error().stack);
26
26
  env.isViteDev = true;
27
27
  }
28
28
  exports.markEnvAsViteDev = markEnvAsViteDev;
29
29
  // Called by Vite hook configurePreviewServer()
30
30
  function markEnvAsVitePreview() {
31
- if (debug.isEnabled)
31
+ if (debug.isActivated)
32
32
  debug('markEnvAsVitePreview()', new Error().stack);
33
33
  env.isVitePreview = true;
34
34
  }
35
35
  exports.markEnvAsVitePreview = markEnvAsVitePreview;
36
36
  // Called by ../node/plugin/index.ts
37
37
  function markEnvAsVikePluginLoaded() {
38
- if (debug.isEnabled)
38
+ if (debug.isActivated)
39
39
  debug('markEnvAsVikePluginLoaded()', new Error().stack);
40
40
  env.isVikePluginLoaded = true;
41
41
  }
42
42
  exports.markEnvAsVikePluginLoaded = markEnvAsVikePluginLoaded;
43
43
  // Called by ../node/runtime/index.ts
44
44
  function assertEnv() {
45
- if (debug.isEnabled)
45
+ if (debug.isActivated)
46
46
  debug('assertEnv()', new Error().stack);
47
47
  if ((0, isVitest_js_1.isVitest)())
48
48
  return;
@@ -1,17 +1,39 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDebugEnabled = exports.createDebugger = void 0;
6
+ exports.isDebugActivated = exports.createDebugger = void 0;
4
7
  const isBrowser_js_1 = require("./isBrowser.js");
5
8
  const isCallable_js_1 = require("./isCallable.js");
6
9
  const objectAssign_js_1 = require("./objectAssign.js");
7
10
  const assert_js_1 = require("./assert.js");
8
11
  const checkType_js_1 = require("./checkType.js");
9
12
  const getTerminWidth_js_1 = require("./getTerminWidth.js");
13
+ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
10
14
  // Avoid this to be loaded in the browser. For isomorphic code: instead of `import { createDebugger } from './utils.js'`, use `globalThis.createDebugger()`.
11
15
  (0, assert_js_1.assert)(!(0, isBrowser_js_1.isBrowser)());
12
16
  globalThis.__brillout_debug_createDebugger = createDebugger;
17
+ const flags = [
18
+ 'vike:error',
19
+ 'vike:extractAssets',
20
+ 'vike:extractExportNames',
21
+ 'vike:glob',
22
+ 'vike:log',
23
+ 'vike:optimizeDeps',
24
+ 'vike:outDir',
25
+ 'vike:pageFiles',
26
+ 'vike:pointer-imports',
27
+ 'vike:routing',
28
+ 'vike:setup',
29
+ 'vike:stream',
30
+ 'vike:virtual-files'
31
+ ];
32
+ const flagRegex = /\bvike:[a-zA-Z-]+/g;
33
+ assertDEBUG();
13
34
  function createDebugger(flag, optionsGlobal) {
14
35
  (0, checkType_js_1.checkType)(flag);
36
+ (0, assert_js_1.assert)(flags.includes(flag));
15
37
  const debugWithOptions = (optionsLocal) => {
16
38
  return (...msgs) => {
17
39
  const options = { ...optionsGlobal, ...optionsLocal };
@@ -19,12 +41,12 @@ function createDebugger(flag, optionsGlobal) {
19
41
  };
20
42
  };
21
43
  const debug = (...msgs) => debugWithOptions({})(...msgs);
22
- (0, objectAssign_js_1.objectAssign)(debug, { options: debugWithOptions, isEnabled: isDebugEnabled(flag) });
44
+ (0, objectAssign_js_1.objectAssign)(debug, { options: debugWithOptions, isActivated: isDebugActivated(flag) });
23
45
  return debug;
24
46
  }
25
47
  exports.createDebugger = createDebugger;
26
48
  function debug_(flag, options, ...msgs) {
27
- if (!isDebugEnabled(flag))
49
+ if (!isDebugActivated(flag))
28
50
  return;
29
51
  let [msgFirst, ...msgsRest] = msgs;
30
52
  const padding = ' '.repeat(flag.length + 1);
@@ -49,19 +71,14 @@ function debug_(flag, options, ...msgs) {
49
71
  console.log(msg);
50
72
  });
51
73
  }
52
- function isDebugEnabled(flag) {
74
+ function isDebugActivated(flag) {
53
75
  (0, checkType_js_1.checkType)(flag);
54
- let DEBUG;
55
- // - `process` can be undefined in edge workers
56
- // - We want bundlers to be able to statically replace `process.env.*`
57
- try {
58
- DEBUG = process.env.DEBUG;
59
- }
60
- catch { }
61
- const isEnabled = DEBUG?.includes(flag) ?? false;
62
- return isEnabled;
76
+ (0, assert_js_1.assert)(flags.includes(flag));
77
+ const DEBUG = getDEBUG();
78
+ const isActivated = DEBUG?.includes(flag) ?? false;
79
+ return isActivated;
63
80
  }
64
- exports.isDebugEnabled = isDebugEnabled;
81
+ exports.isDebugActivated = isDebugActivated;
65
82
  function formatMsg(info, options, padding, position) {
66
83
  if (info === undefined) {
67
84
  return undefined;
@@ -122,3 +139,20 @@ function replaceFunctionSerializer(_key, value) {
122
139
  }
123
140
  return value;
124
141
  }
142
+ function assertDEBUG() {
143
+ const DEBUG = getDEBUG() ?? '';
144
+ const flagsActivated = DEBUG.match(flagRegex) ?? [];
145
+ flagsActivated.forEach((flag) => {
146
+ (0, assert_js_1.assertUsage)(flags.includes(flag), `Unknown DEBUG flag ${picocolors_1.default.cyan(flag)}. Valid flags:\n${flags.map((f) => ` ${picocolors_1.default.cyan(f)}`).join('\n')}`);
147
+ });
148
+ }
149
+ function getDEBUG() {
150
+ let DEBUG;
151
+ // - `process` can be undefined in edge workers
152
+ // - We want bundlers to be able to statically replace `process.env.*`
153
+ try {
154
+ DEBUG = process.env.DEBUG;
155
+ }
156
+ catch { }
157
+ return DEBUG;
158
+ }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = exports.projectInfo = void 0;
4
- const PROJECT_VERSION = '0.4.166-commit-a5e2596';
4
+ const PROJECT_VERSION = '0.4.167';
5
5
  exports.PROJECT_VERSION = PROJECT_VERSION;
6
6
  const projectInfo = {
7
7
  projectName: 'Vike',
@@ -7,7 +7,7 @@ const debug_js_1 = require("./debug.js");
7
7
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
8
8
  const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
9
9
  (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
10
- if ((0, debug_js_1.isDebugEnabled)('vike:log')) {
10
+ if ((0, debug_js_1.isDebugActivated)('vike:log')) {
11
11
  trackLogs();
12
12
  }
13
13
  // https://stackoverflow.com/questions/45395369/how-to-get-console-log-line-numbers-shown-in-nodejs/75109905#75109905
@@ -22,7 +22,7 @@ async function renderPageClientSide(renderArgs) {
22
22
  const { scrollTarget, urlOriginal = getCurrentUrl(), overwriteLastHistoryEntry = false, isBackwardNavigation, pageContextsFromRewrite = [], redirectCount = 0, isUserLandPushStateNavigation, isClientSideNavigation = true } = renderArgs;
23
23
  // isHydrationRender <=> the first render attempt
24
24
  const { isRenderOutdated, setHydrationCanBeAborted, isHydrationRender } = getIsRenderOutdated();
25
- assert(isClientSideNavigation === !isHydrationRender);
25
+ assert(isClientSideNavigation === !isHydrationRender); // isHydrationRender === (renderNumber === 1)
26
26
  assertNoInfiniteAbortLoop(pageContextsFromRewrite.length, redirectCount);
27
27
  if (globalObject.clientRoutingIsDisabled) {
28
28
  serverSideRouteTo(urlOriginal);
@@ -37,6 +37,31 @@ async function renderPageClientSide(renderArgs) {
37
37
  const pageContext = await getPageContextBegin();
38
38
  if (isRenderOutdated())
39
39
  return;
40
+ // onPageTransitionStart()
41
+ if (globalObject.isFirstRenderDone) {
42
+ const { previousPageContext } = globalObject;
43
+ assert(previousPageContext);
44
+ // We use the hook of the previous page in order to be able to call onPageTransitionStart() before fetching the files of the next page.
45
+ // https://github.com/vikejs/vike/issues/1560
46
+ assertHook(previousPageContext, 'onPageTransitionStart');
47
+ if (!globalObject.isTransitioning) {
48
+ globalObject.isTransitioning = true;
49
+ const onPageTransitionStartHook = getHook(previousPageContext, 'onPageTransitionStart');
50
+ if (onPageTransitionStartHook) {
51
+ const hook = onPageTransitionStartHook;
52
+ const { hookFn } = hook;
53
+ try {
54
+ await executeHook(() => hookFn(pageContext), hook);
55
+ }
56
+ catch (err) {
57
+ await onError(err);
58
+ return;
59
+ }
60
+ if (isRenderOutdated())
61
+ return;
62
+ }
63
+ }
64
+ }
40
65
  // Route
41
66
  let pageContextRouted;
42
67
  if (isHydrationRender) {
@@ -104,27 +129,6 @@ async function renderPageClientSide(renderArgs) {
104
129
  // There wasn't any `await` but result may change because we just called setHydrationCanBeAborted()
105
130
  if (isRenderOutdated())
106
131
  return;
107
- // onPageTransitionStart()
108
- if (!isHydrationRender) {
109
- assertHook(pageContext, 'onPageTransitionStart');
110
- if (!globalObject.isTransitioning) {
111
- globalObject.isTransitioning = true;
112
- const onPageTransitionStartHook = getHook(pageContext, 'onPageTransitionStart');
113
- if (onPageTransitionStartHook) {
114
- const hook = onPageTransitionStartHook;
115
- const { hookFn } = hook;
116
- try {
117
- await executeHook(() => hookFn(pageContext), hook);
118
- }
119
- catch (err) {
120
- await onError(err);
121
- return;
122
- }
123
- if (isRenderOutdated())
124
- return;
125
- }
126
- }
127
- }
128
132
  // Get pageContext from hooks (fetched from server, and/or directly called on the client-side)
129
133
  if (isHydrationRender) {
130
134
  assert(hasProp(pageContext, '_hasPageContextFromServer', 'true'));
@@ -328,6 +332,7 @@ async function renderPageClientSide(renderArgs) {
328
332
  onRenderClientError = err;
329
333
  }
330
334
  globalObject.onRenderClientPromise = undefined;
335
+ globalObject.isFirstRenderDone = true;
331
336
  return onRenderClientError;
332
337
  })();
333
338
  const onRenderClientError = await globalObject.onRenderClientPromise;
@@ -365,8 +370,10 @@ async function renderPageClientSide(renderArgs) {
365
370
  // onPageTransitionEnd()
366
371
  if (globalObject.isTransitioning) {
367
372
  globalObject.isTransitioning = undefined;
368
- assertHook(pageContext, 'onPageTransitionEnd');
369
- const hook = getHook(pageContext, 'onPageTransitionEnd');
373
+ const { previousPageContext } = globalObject;
374
+ assert(previousPageContext);
375
+ assertHook(previousPageContext, 'onPageTransitionEnd');
376
+ const hook = getHook(previousPageContext, 'onPageTransitionEnd');
370
377
  if (hook) {
371
378
  const { hookFn } = hook;
372
379
  try {
@@ -23,7 +23,7 @@ async function determineOptimizeDeps(config, isDev) {
23
23
  */
24
24
  config.optimizeDeps.include = [...include, ...normalizeInclude(config.optimizeDeps.include)];
25
25
  config.optimizeDeps.entries = [...entries, ...normalizeEntries(config.optimizeDeps.entries)];
26
- if (debug.isEnabled)
26
+ if (debug.isActivated)
27
27
  debug('config.optimizeDeps', {
28
28
  'config.optimizeDeps.entries': config.optimizeDeps.entries,
29
29
  'config.optimizeDeps.include': config.optimizeDeps.include
@@ -6,7 +6,7 @@
6
6
  // - This appraoch supports import path aliases `vite.config.js#resolve.alias` https://vitejs.dev/config/#resolve-alias
7
7
  export { extractAssetsPlugin };
8
8
  export { extractAssetsRE };
9
- import { viteIsSSR_options, assert, assertPosixPath, styleFileRE, createDebugger, isDebugEnabled, isScriptFile, resolveVirtualFileId, isVirtualFileId, getVirtualFileId, assertUsage } from '../utils.js';
9
+ import { viteIsSSR_options, assert, assertPosixPath, styleFileRE, createDebugger, isScriptFile, resolveVirtualFileId, isVirtualFileId, getVirtualFileId, assertUsage } from '../utils.js';
10
10
  import { extractAssetsAddQuery } from '../../shared/extractAssetsQuery.js';
11
11
  import { getConfigVike } from '../../shared/getConfigVike.js';
12
12
  import { isAsset } from '../shared/isAsset.js';
@@ -20,9 +20,7 @@ const extractAssetsRE = /(\?|&)extractAssets(?:&|$)/;
20
20
  const rawRE = /(\?|&)raw(?:&|$)/;
21
21
  const urlRE = /(\?|&)url(?:&|$)/;
22
22
  const EMPTY_MODULE_ID = 'virtual:vike:empty-module';
23
- const debugNamespace = 'vike:extractAssets';
24
- const debug = createDebugger(debugNamespace);
25
- const debugEnabled = isDebugEnabled(debugNamespace);
23
+ const debug = createDebugger('vike:extractAssets');
26
24
  function extractAssetsPlugin() {
27
25
  let config;
28
26
  let configVike;
@@ -128,7 +126,7 @@ function extractAssetsPlugin() {
128
126
  }
129
127
  },
130
128
  config() {
131
- if (debugEnabled) {
129
+ if (debug.isActivated) {
132
130
  return { logLevel: 'silent' };
133
131
  }
134
132
  }
@@ -1,13 +1,11 @@
1
1
  export { extractExportNamesPlugin };
2
2
  export { isUsingClientRouter };
3
3
  export { extractExportNamesRE };
4
- import { assert, getFileExtension, viteIsSSR_options, createDebugger, isDebugEnabled, getGlobalObject, assertUsage } from '../utils.js';
4
+ import { assert, getFileExtension, viteIsSSR_options, createDebugger, getGlobalObject, assertUsage } from '../utils.js';
5
5
  import { getExportNames } from '../shared/parseEsModule.js';
6
6
  import { sourceMapRemove } from '../shared/rollupSourceMap.js';
7
7
  const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
8
- const debugNamespace = 'vike:extractExportNames';
9
- const debug = createDebugger(debugNamespace);
10
- const debugEnabled = isDebugEnabled(debugNamespace);
8
+ const debug = createDebugger('vike:extractExportNames');
11
9
  const globalObject = getGlobalObject('extractExportNamesPlugin.ts', {});
12
10
  function extractExportNamesPlugin() {
13
11
  let isDev = false;
@@ -26,7 +24,7 @@ function extractExportNamesPlugin() {
26
24
  isDev = true;
27
25
  },
28
26
  config() {
29
- if (debugEnabled) {
27
+ if (debug.isActivated) {
30
28
  return { logLevel: 'silent' };
31
29
  }
32
30
  }
@@ -4,5 +4,5 @@ export declare const debug: ((...msgs: unknown[]) => void) & {
4
4
  emptyArray?: string | undefined;
5
5
  } | undefined;
6
6
  }) => (...msgs: unknown[]) => void;
7
- isEnabled: boolean;
7
+ isActivated: boolean;
8
8
  };
@@ -1,12 +1,12 @@
1
1
  export { getConfigFileExport };
2
2
  import pc from '@brillout/picocolors';
3
3
  import { assertPlusFileExport } from '../../../../../shared/page-configs/assertPlusFileExport.js';
4
- import { assert, assertUsage, isObject } from '../../../utils.js';
4
+ import { assertUsage, isObject } from '../../../utils.js';
5
5
  function getConfigFileExport(fileExports, filePathToShowToUser) {
6
6
  assertPlusFileExport(fileExports, filePathToShowToUser, 'config');
7
- const fileExport = fileExports.default || fileExports.config;
8
- assert('default' in fileExports !== 'config' in fileExports);
9
- const exportName = pc.cyan('default' in fileExports ? 'export default' : 'export { config }');
7
+ const usesNamedExport = !!fileExports.config;
8
+ const fileExport = usesNamedExport ? fileExports.config : fileExports.default;
9
+ const exportName = pc.cyan(usesNamedExport ? 'export { config }' : 'export default');
10
10
  assertUsage(isObject(fileExport), `The ${exportName} of ${filePathToShowToUser} should be an object (but it's ${pc.cyan(`typeof exportedValue === ${JSON.stringify(typeof fileExport)}`)} instead)`);
11
11
  return fileExport;
12
12
  }
@@ -37,10 +37,10 @@ async function transpileFile(filePath, transformImports, userRootDir) {
37
37
  const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
38
38
  assertPosixPath(filePathAbsoluteFilesystem);
39
39
  vikeConfigDependencies.add(filePathAbsoluteFilesystem);
40
- if (debug.isEnabled)
40
+ if (debug.isActivated)
41
41
  debug('transpile', filePathToShowToUserResolved);
42
42
  let { code, pointerImports } = await transpileWithEsbuild(filePath, userRootDir, transformImports);
43
- if (debug.isEnabled)
43
+ if (debug.isActivated)
44
44
  debug(`code, post esbuild (${filePathToShowToUserResolved})`, code);
45
45
  let isImportTransformed = false;
46
46
  if (transformImports) {
@@ -48,12 +48,12 @@ async function transpileFile(filePath, transformImports, userRootDir) {
48
48
  if (codeMod) {
49
49
  code = codeMod;
50
50
  isImportTransformed = true;
51
- if (debug.isEnabled)
51
+ if (debug.isActivated)
52
52
  debug(`code, post transformImports() (${filePathToShowToUserResolved})`, code);
53
53
  }
54
54
  }
55
55
  if (!isImportTransformed) {
56
- if (debug.isEnabled)
56
+ if (debug.isActivated)
57
57
  debug(`code, no transformImports() (${filePathToShowToUserResolved})`);
58
58
  }
59
59
  return code;
@@ -125,7 +125,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
125
125
  const isExternal = isPointerImport ||
126
126
  // npm package imports that aren't pointer imports (e.g. importing a Vite plugin)
127
127
  resolved.path.includes('/node_modules/');
128
- if (debug.isEnabled)
128
+ if (debug.isActivated)
129
129
  debug('onResolved()', { args, resolved, isPointerImport, isExternal });
130
130
  if (isExternal) {
131
131
  return { external: true, path: resolved.path };
@@ -1,5 +1,5 @@
1
1
  export { isErrorDebug };
2
- import { isDebugEnabled } from '../utils.js';
2
+ import { isDebugActivated } from '../utils.js';
3
3
  function isErrorDebug() {
4
- return isDebugEnabled('vike:error');
4
+ return isDebugActivated('vike:error');
5
5
  }
@@ -379,7 +379,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
379
379
  const writeChunk = (chunk) => {
380
380
  assert(writableOriginal);
381
381
  writableOriginal.write(chunk);
382
- if (debug.isEnabled) {
382
+ if (debug.isActivated) {
383
383
  debug('data written (Node.js Writable)', String(chunk));
384
384
  }
385
385
  };
@@ -452,7 +452,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
452
452
  const writeChunk = (chunk) => {
453
453
  assert(writerOriginal);
454
454
  writerOriginal.write(encodeForWebStream(chunk));
455
- if (debug.isEnabled) {
455
+ if (debug.isActivated) {
456
456
  debug('data written (Web Writable)', String(chunk));
457
457
  }
458
458
  };
@@ -545,12 +545,12 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
545
545
  // If readableOriginal doesn't implement readableOriginal.cancel() then it may still emit data after we close the stream. We therefore need to check whether we closed `controllerProxy`.
546
546
  !controllerProxyIsClosed) {
547
547
  controllerProxy.enqueue(encodeForWebStream(chunk));
548
- if (debug.isEnabled) {
548
+ if (debug.isActivated) {
549
549
  debug('data written (Web Readable)', String(chunk));
550
550
  }
551
551
  }
552
552
  else {
553
- if (debug.isEnabled) {
553
+ if (debug.isActivated) {
554
554
  debug('data emitted but not written (Web Readable)', String(chunk));
555
555
  }
556
556
  }
@@ -572,7 +572,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
572
572
  }
573
573
  const writeChunk = (chunk) => {
574
574
  readableProxy.push(chunk);
575
- if (debug.isEnabled) {
575
+ if (debug.isActivated) {
576
576
  debug('data written (Node.js Readable)', String(chunk));
577
577
  }
578
578
  };
@@ -23,9 +23,7 @@ function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
23
23
  }
24
24
  else {
25
25
  assert(exportsAll.length === 2); // because `exportsInvalid.length === 0`
26
- assertWarning(false, `${filePathToShowToUser} remove ${exportNamed} or ${exportDefault}`, {
27
- onlyOnce: true
28
- });
26
+ assertWarning(false, `The exports of ${filePathToShowToUser} are ambiguous: remove ${exportDefault} or ${exportNamed}`, { onlyOnce: true });
29
27
  }
30
28
  }
31
29
  else {
@@ -16,31 +16,31 @@ const vikeVitePluginLoadedInProductionError = `Loading Vike's Vite plugin (the v
16
16
  const env = getGlobalObject('utils/assertIsNotProductionRuntime.ts', {});
17
17
  // Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
18
18
  function assertIsNotProductionRuntime() {
19
- if (debug.isEnabled)
19
+ if (debug.isActivated)
20
20
  debug('assertIsNotProductionRuntime()', new Error().stack);
21
21
  env.shouldNotBeProduction = true;
22
22
  }
23
23
  // Called by Vite hook configureServer()
24
24
  function markEnvAsViteDev() {
25
- if (debug.isEnabled)
25
+ if (debug.isActivated)
26
26
  debug('markEnvAsViteDev()', new Error().stack);
27
27
  env.isViteDev = true;
28
28
  }
29
29
  // Called by Vite hook configurePreviewServer()
30
30
  function markEnvAsVitePreview() {
31
- if (debug.isEnabled)
31
+ if (debug.isActivated)
32
32
  debug('markEnvAsVitePreview()', new Error().stack);
33
33
  env.isVitePreview = true;
34
34
  }
35
35
  // Called by ../node/plugin/index.ts
36
36
  function markEnvAsVikePluginLoaded() {
37
- if (debug.isEnabled)
37
+ if (debug.isActivated)
38
38
  debug('markEnvAsVikePluginLoaded()', new Error().stack);
39
39
  env.isVikePluginLoaded = true;
40
40
  }
41
41
  // Called by ../node/runtime/index.ts
42
42
  function assertEnv() {
43
- if (debug.isEnabled)
43
+ if (debug.isActivated)
44
44
  debug('assertEnv()', new Error().stack);
45
45
  if (isVitest())
46
46
  return;
@@ -1,7 +1,8 @@
1
1
  export { createDebugger };
2
- export { isDebugEnabled };
2
+ export { isDebugActivated };
3
3
  export type { Debug };
4
- type Flag = 'vike:routing' | 'vike:error' | 'vike:stream' | 'vike:log' | 'vike:virtual-files' | 'vike:outDir' | 'vike:extractExportNames' | 'vike:extractAssets' | 'vike:glob' | 'vike:pageFiles' | 'vike:setup' | 'vike:pointer-imports' | 'vike:optimizeDeps';
4
+ declare const flags: readonly ["vike:error", "vike:extractAssets", "vike:extractExportNames", "vike:glob", "vike:log", "vike:optimizeDeps", "vike:outDir", "vike:pageFiles", "vike:pointer-imports", "vike:routing", "vike:setup", "vike:stream", "vike:virtual-files"];
5
+ type Flag = (typeof flags)[number];
5
6
  type Debug = ReturnType<typeof createDebugger>;
6
7
  type Options = {
7
8
  serialization?: {
@@ -10,6 +11,6 @@ type Options = {
10
11
  };
11
12
  declare function createDebugger(flag: Flag, optionsGlobal?: Options): ((...msgs: unknown[]) => void) & {
12
13
  options: (optionsLocal: Options) => (...msgs: unknown[]) => void;
13
- isEnabled: boolean;
14
+ isActivated: boolean;
14
15
  };
15
- declare function isDebugEnabled(flag: Flag): boolean;
16
+ declare function isDebugActivated(flag: Flag): boolean;
@@ -1,16 +1,35 @@
1
1
  export { createDebugger };
2
- export { isDebugEnabled };
2
+ export { isDebugActivated };
3
3
  import { isBrowser } from './isBrowser.js';
4
4
  import { isCallable } from './isCallable.js';
5
5
  import { objectAssign } from './objectAssign.js';
6
- import { assert } from './assert.js';
6
+ import { assert, assertUsage } from './assert.js';
7
7
  import { checkType } from './checkType.js';
8
8
  import { getTerminalWidth } from './getTerminWidth.js';
9
+ import pc from '@brillout/picocolors';
9
10
  // Avoid this to be loaded in the browser. For isomorphic code: instead of `import { createDebugger } from './utils.js'`, use `globalThis.createDebugger()`.
10
11
  assert(!isBrowser());
11
12
  globalThis.__brillout_debug_createDebugger = createDebugger;
13
+ const flags = [
14
+ 'vike:error',
15
+ 'vike:extractAssets',
16
+ 'vike:extractExportNames',
17
+ 'vike:glob',
18
+ 'vike:log',
19
+ 'vike:optimizeDeps',
20
+ 'vike:outDir',
21
+ 'vike:pageFiles',
22
+ 'vike:pointer-imports',
23
+ 'vike:routing',
24
+ 'vike:setup',
25
+ 'vike:stream',
26
+ 'vike:virtual-files'
27
+ ];
28
+ const flagRegex = /\bvike:[a-zA-Z-]+/g;
29
+ assertDEBUG();
12
30
  function createDebugger(flag, optionsGlobal) {
13
31
  checkType(flag);
32
+ assert(flags.includes(flag));
14
33
  const debugWithOptions = (optionsLocal) => {
15
34
  return (...msgs) => {
16
35
  const options = { ...optionsGlobal, ...optionsLocal };
@@ -18,11 +37,11 @@ function createDebugger(flag, optionsGlobal) {
18
37
  };
19
38
  };
20
39
  const debug = (...msgs) => debugWithOptions({})(...msgs);
21
- objectAssign(debug, { options: debugWithOptions, isEnabled: isDebugEnabled(flag) });
40
+ objectAssign(debug, { options: debugWithOptions, isActivated: isDebugActivated(flag) });
22
41
  return debug;
23
42
  }
24
43
  function debug_(flag, options, ...msgs) {
25
- if (!isDebugEnabled(flag))
44
+ if (!isDebugActivated(flag))
26
45
  return;
27
46
  let [msgFirst, ...msgsRest] = msgs;
28
47
  const padding = ' '.repeat(flag.length + 1);
@@ -47,17 +66,12 @@ function debug_(flag, options, ...msgs) {
47
66
  console.log(msg);
48
67
  });
49
68
  }
50
- function isDebugEnabled(flag) {
69
+ function isDebugActivated(flag) {
51
70
  checkType(flag);
52
- let DEBUG;
53
- // - `process` can be undefined in edge workers
54
- // - We want bundlers to be able to statically replace `process.env.*`
55
- try {
56
- DEBUG = process.env.DEBUG;
57
- }
58
- catch { }
59
- const isEnabled = DEBUG?.includes(flag) ?? false;
60
- return isEnabled;
71
+ assert(flags.includes(flag));
72
+ const DEBUG = getDEBUG();
73
+ const isActivated = DEBUG?.includes(flag) ?? false;
74
+ return isActivated;
61
75
  }
62
76
  function formatMsg(info, options, padding, position) {
63
77
  if (info === undefined) {
@@ -119,3 +133,20 @@ function replaceFunctionSerializer(_key, value) {
119
133
  }
120
134
  return value;
121
135
  }
136
+ function assertDEBUG() {
137
+ const DEBUG = getDEBUG() ?? '';
138
+ const flagsActivated = DEBUG.match(flagRegex) ?? [];
139
+ flagsActivated.forEach((flag) => {
140
+ assertUsage(flags.includes(flag), `Unknown DEBUG flag ${pc.cyan(flag)}. Valid flags:\n${flags.map((f) => ` ${pc.cyan(f)}`).join('\n')}`);
141
+ });
142
+ }
143
+ function getDEBUG() {
144
+ let DEBUG;
145
+ // - `process` can be undefined in edge workers
146
+ // - We want bundlers to be able to statically replace `process.env.*`
147
+ try {
148
+ DEBUG = process.env.DEBUG;
149
+ }
150
+ catch { }
151
+ return DEBUG;
152
+ }
@@ -4,5 +4,5 @@ export declare const debugGlob: ((...msgs: unknown[]) => void) & {
4
4
  emptyArray?: string | undefined;
5
5
  } | undefined;
6
6
  }) => (...msgs: unknown[]) => void;
7
- isEnabled: boolean;
7
+ isActivated: boolean;
8
8
  };
@@ -1,7 +1,7 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- declare const PROJECT_VERSION: "0.4.166-commit-a5e2596";
3
+ declare const PROJECT_VERSION: "0.4.167";
4
4
  declare const projectInfo: {
5
5
  projectName: "Vike";
6
- projectVersion: "0.4.166-commit-a5e2596";
6
+ projectVersion: "0.4.167";
7
7
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- const PROJECT_VERSION = '0.4.166-commit-a5e2596';
3
+ const PROJECT_VERSION = '0.4.167';
4
4
  const projectInfo = {
5
5
  projectName: 'Vike',
6
6
  projectVersion: PROJECT_VERSION
@@ -1,8 +1,8 @@
1
- import { isDebugEnabled } from './debug.js';
1
+ import { isDebugActivated } from './debug.js';
2
2
  import pc from '@brillout/picocolors';
3
3
  import { assertIsNotBrowser } from './assertIsNotBrowser.js';
4
4
  assertIsNotBrowser();
5
- if (isDebugEnabled('vike:log')) {
5
+ if (isDebugActivated('vike:log')) {
6
6
  trackLogs();
7
7
  }
8
8
  // https://stackoverflow.com/questions/45395369/how-to-get-console-log-line-numbers-shown-in-nodejs/75109905#75109905
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.166-commit-a5e2596",
3
+ "version": "0.4.167",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",