zuby 1.0.61 → 1.0.63
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/commands/build.js +2 -2
- package/commands/dev.js +1 -1
- package/commands/init.js +1 -1
- package/commands/upgrade.js +1 -1
- package/config.d.ts +3 -1
- package/config.js +12 -5
- package/constants.d.ts +4 -0
- package/constants.js +4 -0
- package/{context/types.d.ts → contexts/globalContext.d.ts} +23 -17
- package/contexts/globalContext.js +7 -0
- package/contexts/index.d.ts +6 -0
- package/contexts/index.js +5 -0
- package/{pageContext/index.d.ts → contexts/pageContext.d.ts} +43 -19
- package/{pageContext/index.js → contexts/pageContext.js} +53 -21
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useGlobalContext.d.ts +5 -0
- package/hooks/useGlobalContext.js +8 -0
- package/index.d.ts +2 -5
- package/index.js +2 -5
- package/package.json +1 -3
- package/packageConfig.d.ts +30 -1
- package/packageConfig.js +9 -5
- package/plugins/chunkNamingPlugin/index.js +10 -5
- package/plugins/contextPlugin/index.js +4 -3
- package/preload/index.js +5 -5
- package/server/index.js +407 -6725
- package/server/types.d.ts +9 -0
- package/server/types.js +6 -1
- package/server/zubyDevRenderer.d.ts +8 -1
- package/server/zubyDevRenderer.js +66 -9
- package/server/zubyDevServer.js +9 -5
- package/server/zubyRenderer.d.ts +15 -11
- package/server/zubyRenderer.js +146 -98
- package/server/zubyServer.d.ts +6 -2
- package/server/zubyServer.js +65 -16
- package/templates/index.js +4 -2
- package/types.d.ts +26 -0
- package/utils/brandingUtils.d.ts +11 -0
- package/{branding.js → utils/brandingUtils.js} +10 -1
- package/utils/consoleUtils.d.ts +5 -0
- package/utils/consoleUtils.js +7 -0
- package/utils/pathUtils.d.ts +1 -0
- package/utils/pathUtils.js +1 -0
- package/branding.d.ts +0 -2
- package/context/index.d.ts +0 -28
- package/context/index.js +0 -47
- package/context/types.js +0 -1
- package/plugins/compileTimePlugin/index.d.ts +0 -25
- package/plugins/compileTimePlugin/index.js +0 -101
- package/utils/buildIdUtils.d.ts +0 -1
- package/utils/buildIdUtils.js +0 -4
package/packageConfig.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { fileURLToPath } from 'url';
|
|
2
2
|
import { dirname, resolve } from 'path';
|
|
3
3
|
import { readFileSync } from 'fs';
|
|
4
|
-
let
|
|
4
|
+
let packageConfigCache;
|
|
5
|
+
/**
|
|
6
|
+
* Returns the package.json content of the current package.
|
|
7
|
+
* @param cache - If true, the package.json content will be cached.
|
|
8
|
+
*/
|
|
5
9
|
export const getZubyPackageConfig = (cache = true) => {
|
|
6
|
-
if (cache &&
|
|
7
|
-
return
|
|
10
|
+
if (cache && packageConfigCache)
|
|
11
|
+
return packageConfigCache;
|
|
8
12
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
13
|
const __dirname = dirname(__filename);
|
|
10
14
|
// Cache the package.json content
|
|
11
|
-
|
|
12
|
-
return
|
|
15
|
+
packageConfigCache = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf-8'));
|
|
16
|
+
return packageConfigCache;
|
|
13
17
|
};
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { MODES } from '../../types.js';
|
|
2
|
+
import { getZubyInternalConfig } from '../../config.js';
|
|
2
3
|
/**
|
|
3
4
|
* This is internal plugin
|
|
4
5
|
* which configure a custom chunk naming for the build.
|
|
5
6
|
*/
|
|
6
7
|
export default function chunkNamingPlugin() {
|
|
8
|
+
let buildId;
|
|
7
9
|
return {
|
|
8
10
|
name: 'zuby-chunk-naming-plugin',
|
|
9
11
|
enforce: 'pre',
|
|
12
|
+
async configResolved() {
|
|
13
|
+
buildId = (await getZubyInternalConfig()).buildId;
|
|
14
|
+
},
|
|
10
15
|
config(config) {
|
|
11
16
|
if (!config.build)
|
|
12
17
|
config.build = {};
|
|
@@ -18,15 +23,15 @@ export default function chunkNamingPlugin() {
|
|
|
18
23
|
return;
|
|
19
24
|
}
|
|
20
25
|
const transformJsFileName = (chunkInfo) => {
|
|
26
|
+
const folder = 'chunks/';
|
|
27
|
+
const name = config?.mode === MODES.production ? 'chunk' : '[name]';
|
|
21
28
|
if (config.build?.ssr && chunkInfo.isEntry) {
|
|
22
29
|
return `[name].js`;
|
|
23
30
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (config?.mode === MODES.production) {
|
|
27
|
-
return `${folder}${prefix}-[hash].js`;
|
|
31
|
+
if (chunkInfo.isEntry) {
|
|
32
|
+
return `${folder}entry-${buildId}.js`;
|
|
28
33
|
}
|
|
29
|
-
return `${folder}
|
|
34
|
+
return `${folder}${name}-[hash].js`;
|
|
30
35
|
};
|
|
31
36
|
const transformAssetFileName = (_chunkInfo) => {
|
|
32
37
|
if (config?.mode === MODES.production) {
|
|
@@ -25,10 +25,10 @@ export default function index() {
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
export async function generateCompileTimeContextCode(ssr) {
|
|
28
|
-
const { site, i18n, buildId, props, serverProps, headElements } = await getZubyInternalConfig();
|
|
28
|
+
const { site, i18n, buildId, props, serverProps, headElements, bodyElements } = await getZubyInternalConfig();
|
|
29
29
|
const { version } = await getZubyPackageConfig();
|
|
30
|
-
return `globalThis.
|
|
31
|
-
...(globalThis.
|
|
30
|
+
return `globalThis._zubyGlobalContext = {
|
|
31
|
+
...(globalThis._zubyGlobalContext || {}),
|
|
32
32
|
templates: ${await generateTemplatesCode(ssr)},
|
|
33
33
|
render: ${await generateRenderCode(ssr)},
|
|
34
34
|
site: '${site || ''}',
|
|
@@ -38,6 +38,7 @@ export async function generateCompileTimeContextCode(ssr) {
|
|
|
38
38
|
props: ${JSON.stringify(props)},
|
|
39
39
|
serverProps: ${JSON.stringify(ssr ? serverProps : {})},
|
|
40
40
|
headElements: ${JSON.stringify(ssr ? headElements : [])},
|
|
41
|
+
bodyElements: ${JSON.stringify(ssr ? bodyElements : [])},
|
|
41
42
|
i18n: ${JSON.stringify(i18n)},
|
|
42
43
|
};`;
|
|
43
44
|
}
|
package/preload/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getGlobalContext } from '../contexts/index.js';
|
|
2
2
|
import { PREALOD_MANIFEST } from '../constants.js';
|
|
3
3
|
/**
|
|
4
4
|
* The set of links that were already preloaded.
|
|
@@ -48,8 +48,8 @@ export function preloadPage(href, onHandle = () => { }) {
|
|
|
48
48
|
// Do nothing on server
|
|
49
49
|
if (typeof window === 'undefined')
|
|
50
50
|
return;
|
|
51
|
-
const context =
|
|
52
|
-
const pages = context.templates
|
|
51
|
+
const context = getGlobalContext();
|
|
52
|
+
const pages = context.templates.pages || [];
|
|
53
53
|
const page = pages.find(({ pathRegex }) => {
|
|
54
54
|
return pathRegex.test(href);
|
|
55
55
|
});
|
|
@@ -87,8 +87,8 @@ async function getPreloadManifest() {
|
|
|
87
87
|
return (preloadManifest =
|
|
88
88
|
preloadManifest ||
|
|
89
89
|
(async () => {
|
|
90
|
-
const { buildId } =
|
|
91
|
-
const res = await fetch(`/${PREALOD_MANIFEST}?${buildId}`);
|
|
90
|
+
const { buildId } = getGlobalContext();
|
|
91
|
+
const res = await fetch(`/${PREALOD_MANIFEST}?${encodeURIComponent(buildId)}`);
|
|
92
92
|
return res.json();
|
|
93
93
|
})());
|
|
94
94
|
}
|