vike 0.4.178 → 0.4.179

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.
@@ -5,6 +5,10 @@ const vite_1 = require("vite");
5
5
  const utils_js_1 = require("../utils.js");
6
6
  const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
7
7
  const getFilePath_js_1 = require("../shared/getFilePath.js");
8
+ // TODO/enventually: (after we implemented vike.config.js)
9
+ // - Make import.meta.env work inside +config.js
10
+ // - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
11
+ // - Or stop using Vite's `mode` implemention and have Vike implement its own `mode` feature? (So that the only dependencies are `$ vike build --mode staging` and `$ MODE=staging vike build`.)
8
12
  const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
9
13
  const PUBLIC_ENV_WHITELIST = [
10
14
  // https://github.com/vikejs/vike/issues/1724
@@ -28,6 +28,7 @@ function inferAssetTag(pageAsset) {
28
28
  return `<script src="${src}" ${scriptAttrs}></script>`;
29
29
  }
30
30
  if (assetType === 'style') {
31
+ // WARNING: if changing following line, then also update https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/client/shared/removeFoucBuster.ts#L29
31
32
  return `<link rel="stylesheet" type="text/css" href="${src}">`;
32
33
  }
33
34
  (0, utils_js_1.assert)(false, { pageAsset });
@@ -11,12 +11,12 @@ function injectHtmlTags(htmlString, htmlTags, position) {
11
11
  return htmlString;
12
12
  }
13
13
  exports.injectHtmlTags = injectHtmlTags;
14
- async function injectHtmlTagsUsingStream(htmlTags, streamFromReactStreamingPackage) {
14
+ function injectHtmlTagsUsingStream(htmlTags, streamFromReactStreamingPackage) {
15
15
  const htmlFragment = joinHtmlTags(htmlTags.filter((h) => h.position === 'STREAM'));
16
16
  if (htmlFragment) {
17
17
  (0, utils_js_1.assert)(streamFromReactStreamingPackage);
18
18
  (0, utils_js_1.assert)(!streamFromReactStreamingPackage.hasStreamEnded());
19
- await streamFromReactStreamingPackage.injectToStream(htmlFragment, { flush: true });
19
+ streamFromReactStreamingPackage.injectToStream(htmlFragment, { flush: true });
20
20
  }
21
21
  }
22
22
  exports.injectHtmlTagsUsingStream = injectHtmlTagsUsingStream;
@@ -29,7 +29,7 @@ function injectHtmlTagsToStream(pageContext, streamFromReactStreamingPackage, in
29
29
  htmlTags = (0, getHtmlTags_js_1.getHtmlTags)(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript);
30
30
  let htmlBegin = htmlPartsToString(htmlPartsBegin, pageAssets);
31
31
  htmlBegin = injectToHtmlBegin(htmlBegin, htmlTags);
32
- await (0, injectHtmlTags_js_1.injectHtmlTagsUsingStream)(htmlTags, streamFromReactStreamingPackage);
32
+ (0, injectHtmlTags_js_1.injectHtmlTagsUsingStream)(htmlTags, streamFromReactStreamingPackage);
33
33
  return htmlBegin;
34
34
  }
35
35
  async function injectAtStreamEnd(htmlPartsEnd) {
@@ -35,6 +35,7 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
35
35
  return;
36
36
  }
37
37
  // https://github.com/vikejs/vike/issues/401
38
+ // WARNING: if changing following line, then also update https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/client/shared/removeFoucBuster.ts#L28
38
39
  src = src + '?direct';
39
40
  }
40
41
  const isEntry = clientEntriesSrc.includes(src) ||
@@ -23,7 +23,7 @@ const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/assert.ts'
23
23
  },
24
24
  showStackTraceList: new WeakSet()
25
25
  });
26
- (0, assertSingleInstance_js_1.onAssertModuleLoad)();
26
+ (0, assertSingleInstance_js_1.assertSingleInstance_onAssertModuleLoad)();
27
27
  const projectTag = `[vike]`;
28
28
  const projectTagWithVersion = `[vike@${projectInfo_js_1.projectInfo.projectVersion}]`;
29
29
  const numberOfStackTraceLinesToRemove = 2;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.onAssertModuleLoad = exports.onClientEntry_ClientRouting = exports.onClientEntry_ServerRouting = void 0;
6
+ exports.assertSingleInstance_onAssertModuleLoad = exports.assertSingleInstance_onClientEntryClientRouting = exports.assertSingleInstance_onClientEntryServerRouting = void 0;
7
7
  // - Throw error if there are two different versions of vike loaded
8
8
  // - Show warning if entry of Client Routing and entry of Server Routing are both loaded
9
9
  // - Show warning if vike is loaded twice
@@ -35,7 +35,7 @@ function assertSingleInstance() {
35
35
  //*/
36
36
  }
37
37
  }
38
- function onClientEntry_ServerRouting(isProduction) {
38
+ function assertSingleInstance_onClientEntryServerRouting(isProduction) {
39
39
  assertWarning(globalObject.isClientRouting !== true, clientRuntimesClonflict, {
40
40
  onlyOnce: true,
41
41
  showStackTrace: true
@@ -49,8 +49,8 @@ function onClientEntry_ServerRouting(isProduction) {
49
49
  globalObject.checkSingleInstance = true;
50
50
  assertSingleInstance();
51
51
  }
52
- exports.onClientEntry_ServerRouting = onClientEntry_ServerRouting;
53
- function onClientEntry_ClientRouting(isProduction) {
52
+ exports.assertSingleInstance_onClientEntryServerRouting = assertSingleInstance_onClientEntryServerRouting;
53
+ function assertSingleInstance_onClientEntryClientRouting(isProduction) {
54
54
  assertWarning(globalObject.isClientRouting !== false, clientRuntimesClonflict, {
55
55
  onlyOnce: true,
56
56
  showStackTrace: true
@@ -64,13 +64,13 @@ function onClientEntry_ClientRouting(isProduction) {
64
64
  globalObject.checkSingleInstance = true;
65
65
  assertSingleInstance();
66
66
  }
67
- exports.onClientEntry_ClientRouting = onClientEntry_ClientRouting;
67
+ exports.assertSingleInstance_onClientEntryClientRouting = assertSingleInstance_onClientEntryClientRouting;
68
68
  // Called by utils/assert.ts which is (most certainly) loaded by all entries. That way we don't have to call a callback for every entry. (There are a lot of entries: `client/router/`, `client/`, `node/runtime/`, `node/plugin/`, `node/cli`.)
69
- function onAssertModuleLoad() {
69
+ function assertSingleInstance_onAssertModuleLoad() {
70
70
  globalObject.instances.push(projectInfo_js_1.projectInfo.projectVersion);
71
71
  assertSingleInstance();
72
72
  }
73
- exports.onAssertModuleLoad = onAssertModuleLoad;
73
+ exports.assertSingleInstance_onAssertModuleLoad = assertSingleInstance_onAssertModuleLoad;
74
74
  function assertUsage(condition, errorMessage) {
75
75
  if (condition) {
76
76
  return;
@@ -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.178';
4
+ const PROJECT_VERSION = '0.4.179';
5
5
  exports.PROJECT_VERSION = PROJECT_VERSION;
6
6
  const projectInfo = {
7
7
  projectName: 'Vike',
@@ -2,8 +2,11 @@ import { assertClientRouting } from '../../utils/assertRoutingType.js';
2
2
  assertClientRouting();
3
3
  import './pageFiles';
4
4
  import { installClientRouter } from './installClientRouter.js';
5
- import { onClientEntry_ClientRouting } from './utils.js';
5
+ import { assertSingleInstance_onClientEntryClientRouting } from './utils.js';
6
+ import { removeFoucBuster } from '../shared/removeFoucBuster.js';
6
7
  // @ts-ignore Since dist/cjs/client/ is never used, we can ignore this error.
7
8
  const isProd = import.meta.env.PROD;
8
- onClientEntry_ClientRouting(isProd);
9
+ assertSingleInstance_onClientEntryClientRouting(isProd);
10
+ if (import.meta.env.DEV)
11
+ removeFoucBuster();
9
12
  installClientRouter();
@@ -4,10 +4,13 @@ import './pageFiles';
4
4
  import { getPageContext } from './getPageContext.js';
5
5
  import { executeOnRenderClientHook } from '../shared/executeOnRenderClientHook.js';
6
6
  import { assertHook } from '../../shared/hooks/getHook.js';
7
- import { onClientEntry_ServerRouting } from './utils.js';
7
+ import { assertSingleInstance_onClientEntryServerRouting } from './utils.js';
8
+ import { removeFoucBuster } from '../shared/removeFoucBuster.js';
8
9
  // @ts-ignore Since dist/cjs/client/ is never used, we can ignore this error.
9
10
  const isProd = import.meta.env.PROD;
10
- onClientEntry_ServerRouting(isProd);
11
+ assertSingleInstance_onClientEntryServerRouting(isProd);
12
+ if (import.meta.env.DEV)
13
+ removeFoucBuster();
11
14
  hydrate();
12
15
  async function hydrate() {
13
16
  const pageContext = await getPageContext();
@@ -0,0 +1,2 @@
1
+ export { removeFoucBuster };
2
+ declare function removeFoucBuster(): void;
@@ -0,0 +1,44 @@
1
+ export { removeFoucBuster };
2
+ import { assert } from './utils.js';
3
+ // See also:
4
+ // - Alternative approach of exactly injecting what Vite injects:
5
+ // - https://github.com/remix-run/remix/issues/8830#issuecomment-1968368351
6
+ // - https://github.com/rakkasjs/rakkasjs/blob/7d75ccc915e93bca04e6bab37dc6abdb68a85e4a/packages/rakkasjs/src/features/pages/middleware.tsx#L701
7
+ // - https://github.com/remix-run/remix/issues/8830
8
+ function removeFoucBuster() {
9
+ assert(import.meta.env.DEV);
10
+ let sleep = 2;
11
+ const runClean = () => {
12
+ const isClean = clean();
13
+ if (!isClean) {
14
+ if (sleep < 1000)
15
+ sleep = 2 * sleep;
16
+ setTimeout(runClean, sleep);
17
+ }
18
+ };
19
+ setTimeout(runClean, sleep);
20
+ }
21
+ function clean() {
22
+ const VITE_ID = 'data-vite-dev-id';
23
+ const injectedByVite = [...document.querySelectorAll(`style[${VITE_ID}]`)].map((style) => style.getAttribute(VITE_ID));
24
+ // ```
25
+ // <link rel="stylesheet" type="text/css" href="/renderer/css/index.css?direct">
26
+ // <link rel="stylesheet" type="text/css" href="/renderer/Layout.css?direct">
27
+ // ```
28
+ const suffix = '?direct';
29
+ // <link> defined by:
30
+ // - https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/node/runtime/html/injectAssets/inferHtmlTags.ts#L35
31
+ // - https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/node/runtime/renderPage/getPageAssets.ts#L68
32
+ const injectedByVike = [...document.querySelectorAll(`link[rel="stylesheet"][type="text/css"][href$="${suffix}"]`)];
33
+ let isClean = true;
34
+ injectedByVike.forEach((link) => {
35
+ const filePathAbsoluteUserRootDir = link.getAttribute('href').slice(0, -suffix.length);
36
+ if (injectedByVite.some((filePathAbsoluteFilesystem) => filePathAbsoluteFilesystem.endsWith(filePathAbsoluteUserRootDir))) {
37
+ link.remove();
38
+ }
39
+ else {
40
+ isClean = false;
41
+ }
42
+ });
43
+ return isClean;
44
+ }
@@ -0,0 +1 @@
1
+ export * from '../../utils/assert.js';
@@ -0,0 +1 @@
1
+ export * from '../../utils/assert.js';
@@ -5,6 +5,10 @@ import { loadEnv } from 'vite';
5
5
  import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArray, lowerFirst } from '../utils.js';
6
6
  import { sourceMapPassthrough } from '../shared/rollupSourceMap.js';
7
7
  import { getModuleFilePath } from '../shared/getFilePath.js';
8
+ // TODO/enventually: (after we implemented vike.config.js)
9
+ // - Make import.meta.env work inside +config.js
10
+ // - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
11
+ // - Or stop using Vite's `mode` implemention and have Vike implement its own `mode` feature? (So that the only dependencies are `$ vike build --mode staging` and `$ MODE=staging vike build`.)
8
12
  const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
9
13
  const PUBLIC_ENV_WHITELIST = [
10
14
  // https://github.com/vikejs/vike/issues/1724
@@ -27,6 +27,7 @@ function inferAssetTag(pageAsset) {
27
27
  return `<script src="${src}" ${scriptAttrs}></script>`;
28
28
  }
29
29
  if (assetType === 'style') {
30
+ // WARNING: if changing following line, then also update https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/client/shared/removeFoucBuster.ts#L29
30
31
  return `<link rel="stylesheet" type="text/css" href="${src}">`;
31
32
  }
32
33
  assert(false, { pageAsset });
@@ -7,7 +7,7 @@ import type { StreamFromReactStreamingPackage } from '../stream/react-streaming.
7
7
  import type { HtmlTag } from './getHtmlTags.js';
8
8
  type Position = 'HTML_BEGIN' | 'HTML_END';
9
9
  declare function injectHtmlTags(htmlString: string, htmlTags: HtmlTag[], position: Position): string;
10
- declare function injectHtmlTagsUsingStream(htmlTags: HtmlTag[], streamFromReactStreamingPackage: null | StreamFromReactStreamingPackage): Promise<void>;
10
+ declare function injectHtmlTagsUsingStream(htmlTags: HtmlTag[], streamFromReactStreamingPackage: null | StreamFromReactStreamingPackage): void;
11
11
  declare function injectAtOpeningTag(tag: 'head' | 'html' | '!doctype', htmlString: string, htmlFragment: string): string;
12
12
  declare function injectAtClosingTag(tag: 'body' | 'html', htmlString: string, htmlFragment: string): string;
13
13
  declare function createHtmlHeadIfMissing(htmlString: string): string;
@@ -13,12 +13,12 @@ function injectHtmlTags(htmlString, htmlTags, position) {
13
13
  }
14
14
  return htmlString;
15
15
  }
16
- async function injectHtmlTagsUsingStream(htmlTags, streamFromReactStreamingPackage) {
16
+ function injectHtmlTagsUsingStream(htmlTags, streamFromReactStreamingPackage) {
17
17
  const htmlFragment = joinHtmlTags(htmlTags.filter((h) => h.position === 'STREAM'));
18
18
  if (htmlFragment) {
19
19
  assert(streamFromReactStreamingPackage);
20
20
  assert(!streamFromReactStreamingPackage.hasStreamEnded());
21
- await streamFromReactStreamingPackage.injectToStream(htmlFragment, { flush: true });
21
+ streamFromReactStreamingPackage.injectToStream(htmlFragment, { flush: true });
22
22
  }
23
23
  }
24
24
  function joinHtmlTags(htmlTags) {
@@ -27,7 +27,7 @@ function injectHtmlTagsToStream(pageContext, streamFromReactStreamingPackage, in
27
27
  htmlTags = getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript);
28
28
  let htmlBegin = htmlPartsToString(htmlPartsBegin, pageAssets);
29
29
  htmlBegin = injectToHtmlBegin(htmlBegin, htmlTags);
30
- await injectHtmlTagsUsingStream(htmlTags, streamFromReactStreamingPackage);
30
+ injectHtmlTagsUsingStream(htmlTags, streamFromReactStreamingPackage);
31
31
  return htmlBegin;
32
32
  }
33
33
  async function injectAtStreamEnd(htmlPartsEnd) {
@@ -34,6 +34,7 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
34
34
  return;
35
35
  }
36
36
  // https://github.com/vikejs/vike/issues/401
37
+ // WARNING: if changing following line, then also update https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/client/shared/removeFoucBuster.ts#L28
37
38
  src = src + '?direct';
38
39
  }
39
40
  const isEntry = clientEntriesSrc.includes(src) ||
@@ -8,7 +8,7 @@ export { getAssertErrMsg };
8
8
  export { overwriteAssertProductionLogger };
9
9
  export { isBug };
10
10
  export { setAlwaysShowStackTrace };
11
- import { onAssertModuleLoad } from './assertSingleInstance.js';
11
+ import { assertSingleInstance_onAssertModuleLoad } from './assertSingleInstance.js';
12
12
  import { createErrorWithCleanStackTrace } from './createErrorWithCleanStackTrace.js';
13
13
  import { getGlobalObject } from './getGlobalObject.js';
14
14
  import { isObject } from './isObject.js';
@@ -27,7 +27,7 @@ const globalObject = getGlobalObject('utils/assert.ts', {
27
27
  },
28
28
  showStackTraceList: new WeakSet()
29
29
  });
30
- onAssertModuleLoad();
30
+ assertSingleInstance_onAssertModuleLoad();
31
31
  const projectTag = `[vike]`;
32
32
  const projectTagWithVersion = `[vike@${projectInfo.projectVersion}]`;
33
33
  const numberOfStackTraceLinesToRemove = 2;
@@ -1,6 +1,6 @@
1
- export { onClientEntry_ServerRouting };
2
- export { onClientEntry_ClientRouting };
3
- export { onAssertModuleLoad };
4
- declare function onClientEntry_ServerRouting(isProduction: boolean): void;
5
- declare function onClientEntry_ClientRouting(isProduction: boolean): void;
6
- declare function onAssertModuleLoad(): void;
1
+ export { assertSingleInstance_onClientEntryServerRouting };
2
+ export { assertSingleInstance_onClientEntryClientRouting };
3
+ export { assertSingleInstance_onAssertModuleLoad };
4
+ declare function assertSingleInstance_onClientEntryServerRouting(isProduction: boolean): void;
5
+ declare function assertSingleInstance_onClientEntryClientRouting(isProduction: boolean): void;
6
+ declare function assertSingleInstance_onAssertModuleLoad(): void;
@@ -1,6 +1,6 @@
1
- export { onClientEntry_ServerRouting };
2
- export { onClientEntry_ClientRouting };
3
- export { onAssertModuleLoad };
1
+ export { assertSingleInstance_onClientEntryServerRouting };
2
+ export { assertSingleInstance_onClientEntryClientRouting };
3
+ export { assertSingleInstance_onAssertModuleLoad };
4
4
  // - Throw error if there are two different versions of vike loaded
5
5
  // - Show warning if entry of Client Routing and entry of Server Routing are both loaded
6
6
  // - Show warning if vike is loaded twice
@@ -32,7 +32,7 @@ function assertSingleInstance() {
32
32
  //*/
33
33
  }
34
34
  }
35
- function onClientEntry_ServerRouting(isProduction) {
35
+ function assertSingleInstance_onClientEntryServerRouting(isProduction) {
36
36
  assertWarning(globalObject.isClientRouting !== true, clientRuntimesClonflict, {
37
37
  onlyOnce: true,
38
38
  showStackTrace: true
@@ -46,7 +46,7 @@ function onClientEntry_ServerRouting(isProduction) {
46
46
  globalObject.checkSingleInstance = true;
47
47
  assertSingleInstance();
48
48
  }
49
- function onClientEntry_ClientRouting(isProduction) {
49
+ function assertSingleInstance_onClientEntryClientRouting(isProduction) {
50
50
  assertWarning(globalObject.isClientRouting !== false, clientRuntimesClonflict, {
51
51
  onlyOnce: true,
52
52
  showStackTrace: true
@@ -61,7 +61,7 @@ function onClientEntry_ClientRouting(isProduction) {
61
61
  assertSingleInstance();
62
62
  }
63
63
  // Called by utils/assert.ts which is (most certainly) loaded by all entries. That way we don't have to call a callback for every entry. (There are a lot of entries: `client/router/`, `client/`, `node/runtime/`, `node/plugin/`, `node/cli`.)
64
- function onAssertModuleLoad() {
64
+ function assertSingleInstance_onAssertModuleLoad() {
65
65
  globalObject.instances.push(projectInfo.projectVersion);
66
66
  assertSingleInstance();
67
67
  }
@@ -1,7 +1,7 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- declare const PROJECT_VERSION: "0.4.178";
3
+ declare const PROJECT_VERSION: "0.4.179";
4
4
  declare const projectInfo: {
5
5
  projectName: "Vike";
6
- projectVersion: "0.4.178";
6
+ projectVersion: "0.4.179";
7
7
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- const PROJECT_VERSION = '0.4.178';
3
+ const PROJECT_VERSION = '0.4.179';
4
4
  const projectInfo = {
5
5
  projectName: 'Vike',
6
6
  projectVersion: PROJECT_VERSION
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.178",
3
+ "version": "0.4.179",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
@@ -138,7 +138,7 @@
138
138
  }
139
139
  },
140
140
  "peerDependencies": {
141
- "react-streaming": ">=0.3.36",
141
+ "react-streaming": ">=0.3.41",
142
142
  "vite": ">=4.4.0"
143
143
  },
144
144
  "peerDependenciesMeta": {
@@ -209,7 +209,7 @@
209
209
  "es-module-lexer": "^1.4.1",
210
210
  "esbuild": "^0.19.10",
211
211
  "fast-glob": "^3.3.2",
212
- "react-streaming": "^0.3.36",
212
+ "react-streaming": "^0.3.41",
213
213
  "rimraf": "^5.0.5",
214
214
  "sirv": "^2.0.4",
215
215
  "source-map-support": "^0.5.21",