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.
Files changed (52) hide show
  1. package/commands/build.js +2 -2
  2. package/commands/dev.js +1 -1
  3. package/commands/init.js +1 -1
  4. package/commands/upgrade.js +1 -1
  5. package/config.d.ts +3 -1
  6. package/config.js +12 -5
  7. package/constants.d.ts +4 -0
  8. package/constants.js +4 -0
  9. package/{context/types.d.ts → contexts/globalContext.d.ts} +23 -17
  10. package/contexts/globalContext.js +7 -0
  11. package/contexts/index.d.ts +6 -0
  12. package/contexts/index.js +5 -0
  13. package/{pageContext/index.d.ts → contexts/pageContext.d.ts} +43 -19
  14. package/{pageContext/index.js → contexts/pageContext.js} +53 -21
  15. package/hooks/index.d.ts +1 -0
  16. package/hooks/index.js +1 -0
  17. package/hooks/useGlobalContext.d.ts +5 -0
  18. package/hooks/useGlobalContext.js +8 -0
  19. package/index.d.ts +2 -5
  20. package/index.js +2 -5
  21. package/package.json +1 -3
  22. package/packageConfig.d.ts +30 -1
  23. package/packageConfig.js +9 -5
  24. package/plugins/chunkNamingPlugin/index.js +10 -5
  25. package/plugins/contextPlugin/index.js +4 -3
  26. package/preload/index.js +5 -5
  27. package/server/index.js +407 -6725
  28. package/server/types.d.ts +9 -0
  29. package/server/types.js +6 -1
  30. package/server/zubyDevRenderer.d.ts +8 -1
  31. package/server/zubyDevRenderer.js +66 -9
  32. package/server/zubyDevServer.js +9 -5
  33. package/server/zubyRenderer.d.ts +15 -11
  34. package/server/zubyRenderer.js +146 -98
  35. package/server/zubyServer.d.ts +6 -2
  36. package/server/zubyServer.js +65 -16
  37. package/templates/index.js +4 -2
  38. package/types.d.ts +26 -0
  39. package/utils/brandingUtils.d.ts +11 -0
  40. package/{branding.js → utils/brandingUtils.js} +10 -1
  41. package/utils/consoleUtils.d.ts +5 -0
  42. package/utils/consoleUtils.js +7 -0
  43. package/utils/pathUtils.d.ts +1 -0
  44. package/utils/pathUtils.js +1 -0
  45. package/branding.d.ts +0 -2
  46. package/context/index.d.ts +0 -28
  47. package/context/index.js +0 -47
  48. package/context/types.js +0 -1
  49. package/plugins/compileTimePlugin/index.d.ts +0 -25
  50. package/plugins/compileTimePlugin/index.js +0 -101
  51. package/utils/buildIdUtils.d.ts +0 -1
  52. 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 packageJson;
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 && packageJson)
7
- return packageJson;
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
- packageJson = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf-8'));
12
- return packageJson;
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
- const folder = 'chunks/';
25
- const prefix = chunkInfo.isEntry ? 'entry' : 'chunk';
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}[name]-[hash].js`;
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.ZubyRawContext = {
31
- ...(globalThis.ZubyRawContext || {}),
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 { getContext } from '../context/index.js';
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 = getContext();
52
- const pages = context.templates?.pages || [];
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 } = getContext();
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
  }