zuby 1.0.62 → 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 (47) 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 +6 -3
  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/contextPlugin/index.js +4 -3
  25. package/preload/index.js +5 -5
  26. package/server/index.js +160 -120
  27. package/server/types.d.ts +9 -0
  28. package/server/types.js +6 -1
  29. package/server/zubyDevRenderer.js +9 -9
  30. package/server/zubyDevServer.js +3 -4
  31. package/server/zubyRenderer.d.ts +7 -8
  32. package/server/zubyRenderer.js +33 -32
  33. package/server/zubyServer.d.ts +6 -2
  34. package/server/zubyServer.js +65 -16
  35. package/types.d.ts +22 -0
  36. package/utils/brandingUtils.d.ts +11 -0
  37. package/{branding.js → utils/brandingUtils.js} +10 -1
  38. package/utils/consoleUtils.d.ts +4 -0
  39. package/utils/consoleUtils.js +4 -0
  40. package/utils/pathUtils.d.ts +1 -0
  41. package/utils/pathUtils.js +1 -0
  42. package/branding.d.ts +0 -2
  43. package/context/index.d.ts +0 -28
  44. package/context/index.js +0 -47
  45. package/context/types.js +0 -1
  46. package/plugins/compileTimePlugin/index.d.ts +0 -25
  47. package/plugins/compileTimePlugin/index.js +0 -101
package/commands/build.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { MODES, PLUGIN_HOOKS } from '../types.js';
2
2
  import { executePlugins, getZubyInternalConfig } from '../config.js';
3
3
  import chalk from 'chalk';
4
- import { getTitle } from '../branding.js';
4
+ import { getTitle } from '../utils/brandingUtils.js';
5
5
  import { build as viteBuild } from 'vite';
6
6
  import { dirname, join, resolve } from 'path';
7
7
  import { normalizePath } from '../utils/pathUtils.js';
@@ -22,7 +22,7 @@ export default async function build(options) {
22
22
  const nextBuildStep = (description) => {
23
23
  logger?.info(`${chalk.bgYellow.bold.whiteBright(` Step ${buildStep++}/${buildSteps} `)} ${chalk.gray(description)}`);
24
24
  };
25
- process.env.NODE_ENV = MODES.production;
25
+ zubyInternalConfig.mode = process.env.NODE_ENV = MODES.production;
26
26
  logger?.info(getTitle(chalk.gray(`building for production...`)));
27
27
  // Load templates from the project directory
28
28
  const templates = await getTemplates();
package/commands/dev.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PLUGIN_HOOKS } from '../types.js';
2
2
  import { executePlugins, getZubyInternalConfig } from '../config.js';
3
3
  import { performance } from 'node:perf_hooks';
4
- import { getTitle } from '../branding.js';
4
+ import { getTitle } from '../utils/brandingUtils.js';
5
5
  import chalk from 'chalk';
6
6
  import ZubyDevServer from '../server/zubyDevServer.js';
7
7
  export default async function dev(options) {
package/commands/init.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import inquirer from 'inquirer';
2
2
  import { createLogger } from '../logger/index.js';
3
- import { getTitle } from '../branding.js';
3
+ import { getTitle } from '../utils/brandingUtils.js';
4
4
  import chalk from 'chalk';
5
5
  import { existsSync, readdirSync, cpSync, statSync } from 'fs';
6
6
  import { readFile, writeFile } from 'fs/promises';
@@ -3,7 +3,7 @@ import { existsSync, readFileSync, writeFileSync } from 'fs';
3
3
  import { resolve } from 'path';
4
4
  import { execSync } from 'child_process';
5
5
  import { getZubyPackageConfig } from '../packageConfig.js';
6
- import { getTitle } from '../branding.js';
6
+ import { getTitle } from '../utils/brandingUtils.js';
7
7
  import chalk from 'chalk';
8
8
  export default async function upgrade({ configFile, tag }) {
9
9
  const { customLogger: logger } = await getZubyInternalConfig(configFile);
package/config.d.ts CHANGED
@@ -49,6 +49,8 @@ export type ExecutePluginsParams = Omit<ZubyHookParams, 'command' | 'logger' | '
49
49
  */
50
50
  export declare const normalizePlugins: (plugins: (ZubyPlugin | ZubyPlugin[] | VitePluginOption | VitePluginOption[])[]) => Promise<(ZubyPlugin | VitePlugin)[]>;
51
51
  /**
52
- * Returns random build ID.
52
+ * Returns random base32 like build ID
53
+ * without special characters
54
+ * that can be used directly in URLs.
53
55
  */
54
56
  export declare const generateDefaultBuildId: () => string;
package/config.js CHANGED
@@ -7,7 +7,6 @@ import { createLogger } from './logger/index.js';
7
7
  import { TEMPLATES } from './templates/types.js';
8
8
  // Plugins
9
9
  import contextPlugin from './plugins/contextPlugin/index.js';
10
- import compileTimePlugin from './plugins/compileTimePlugin/index.js';
11
10
  import chunkNamingPlugin from './plugins/chunkNamingPlugin/index.js';
12
11
  import manifestPlugin from './plugins/manifestPlugin/index.js';
13
12
  import prerenderPlugin from './plugins/prerenderPlugin/index.js';
@@ -62,6 +61,7 @@ export const getZubyInternalConfig = async (configFilePath, cache = true) => {
62
61
  zubyConfig.configFilePath = configFilePath;
63
62
  zubyConfig.templateFiles = zubyConfig.templateFiles || [];
64
63
  zubyConfig.headElements = zubyConfig.headElements || [];
64
+ zubyConfig.bodyElements = zubyConfig.bodyElements || [];
65
65
  // Run config setup hook
66
66
  await executePlugins(zubyConfig, PLUGIN_HOOKS.ZubyConfigSetup, {
67
67
  addEntryTemplate: (filename) => zubyConfig.templateFiles?.push({
@@ -161,6 +161,8 @@ export const mergeDefaultConfig = async (config) => {
161
161
  config.minifyCSS = config.minifyCSS ?? true;
162
162
  config.minifyHTML = config.minifyHTML ?? true;
163
163
  config.minifyJS = config.minifyJS ?? true;
164
+ config.compress = config.compress ?? true;
165
+ config.poweredByHeader = config.poweredByHeader ?? true;
164
166
  // Build ID generator
165
167
  config.generateBuildId = config.generateBuildId ?? generateDefaultBuildId;
166
168
  // Global props
@@ -217,7 +219,6 @@ export const getBuiltInPlugins = () => {
217
219
  return [
218
220
  injectPlugin(),
219
221
  contextPlugin(),
220
- compileTimePlugin(),
221
222
  chunkNamingPlugin(),
222
223
  manifestPlugin(),
223
224
  prerenderPlugin(),
@@ -280,7 +281,9 @@ export const normalizePlugins = async (plugins) => {
280
281
  .filter(plugin => !!plugin);
281
282
  };
282
283
  /**
283
- * Returns random build ID.
284
+ * Returns random base32 like build ID
285
+ * without special characters
286
+ * that can be used directly in URLs.
284
287
  */
285
288
  export const generateDefaultBuildId = () => {
286
289
  return randomBytes(8).toString('base64').substring(0, 8);
package/constants.d.ts CHANGED
@@ -9,13 +9,17 @@ export declare const HTTP_HEADERS: {
9
9
  Host: string;
10
10
  Server: string;
11
11
  UserAgent: string;
12
+ Location: string;
12
13
  ContentType: string;
13
14
  ContentLength: string;
14
15
  ContentRange: string;
15
16
  ContentEncoding: string;
16
17
  ContentLanguage: string;
17
18
  AcceptRanges: string;
19
+ AcceptEncoding: string;
18
20
  CacheControl: string;
21
+ LastModified: string;
22
+ XForwardedFor: string;
19
23
  XForwardedProto: string;
20
24
  XForwardedHost: string;
21
25
  XPoweredBy: string;
package/constants.js CHANGED
@@ -11,13 +11,17 @@ export const HTTP_HEADERS = {
11
11
  Host: 'Host',
12
12
  Server: 'Server',
13
13
  UserAgent: 'User-Agent',
14
+ Location: 'Location',
14
15
  ContentType: 'Content-Type',
15
16
  ContentLength: 'Content-Length',
16
17
  ContentRange: 'Content-Range',
17
18
  ContentEncoding: 'Content-Encoding',
18
19
  ContentLanguage: 'Content-Language',
19
20
  AcceptRanges: 'Accept-Ranges',
21
+ AcceptEncoding: 'Accept-Encoding',
20
22
  CacheControl: 'Cache-Control',
23
+ LastModified: 'Last-Modified',
24
+ XForwardedFor: 'X-Forwarded-For',
21
25
  XForwardedProto: 'X-Forwarded-Proto',
22
26
  XForwardedHost: 'X-Forwarded-Host',
23
27
  XPoweredBy: 'X-Powered-By',
@@ -1,22 +1,22 @@
1
1
  import { LazyTemplate } from '../templates/types.js';
2
2
  import { RenderToStream, RenderToString } from '../types.js';
3
- export interface ZubyRawContext {
3
+ export interface GlobalContext {
4
4
  /**
5
5
  * The array with templates.
6
6
  */
7
- templates?: {
8
- pages?: LazyTemplate[];
9
- apps?: LazyTemplate[];
10
- errors?: LazyTemplate[];
11
- layouts?: LazyTemplate[];
12
- innerLayouts?: LazyTemplate[];
13
- handlers?: LazyTemplate[];
14
- loaders?: LazyTemplate[];
7
+ templates: {
8
+ pages: LazyTemplate[];
9
+ apps: LazyTemplate[];
10
+ errors: LazyTemplate[];
11
+ layouts: LazyTemplate[];
12
+ innerLayouts: LazyTemplate[];
13
+ handlers: LazyTemplate[];
14
+ loaders: LazyTemplate[];
15
15
  };
16
16
  /**
17
17
  * The render module from JsxProvider.
18
18
  */
19
- render?: {
19
+ render: {
20
20
  renderToString?: RenderToString;
21
21
  renderToStream?: RenderToStream;
22
22
  };
@@ -24,21 +24,21 @@ export interface ZubyRawContext {
24
24
  * The URL of the site
25
25
  * @example https://example.com
26
26
  */
27
- site?: string;
27
+ site: string;
28
28
  /**
29
29
  * The name of the generator together with its version number
30
30
  * @example Zuby.js 1.0.0
31
31
  */
32
- generator?: string;
32
+ generator: string;
33
33
  /**
34
34
  * The version of used Zuby.js
35
35
  * @example 1.0.0
36
36
  */
37
- version?: string;
37
+ version: string;
38
38
  /**
39
39
  * The build ID of the site.
40
40
  */
41
- buildId?: string;
41
+ buildId: string;
42
42
  /**
43
43
  * The internalization config from ZubyConfig.
44
44
  * @example {
@@ -55,16 +55,22 @@ export interface ZubyRawContext {
55
55
  * that will be passed to all pages
56
56
  * on both client and server side.
57
57
  */
58
- props?: Record<string, any>;
58
+ props: Record<string, any>;
59
59
  /**
60
60
  * The global server props for the site
61
61
  * that will be passed to all pages
62
62
  * only on server side.
63
63
  */
64
- serverProps?: Record<string, any>;
64
+ serverProps: Record<string, any>;
65
65
  /**
66
66
  * Additional elements that should be added
67
67
  * to the head of the page.
68
68
  */
69
- headElements?: string[];
69
+ headElements: string[];
70
+ /**
71
+ * Additional elements that should be added
72
+ * to the body of the page.
73
+ */
74
+ bodyElements: string[];
70
75
  }
76
+ export declare const getGlobalContext: () => GlobalContext;
@@ -0,0 +1,7 @@
1
+ export const getGlobalContext = () => {
2
+ const globalContext = globalThis._zubyGlobalContext;
3
+ if (!globalContext) {
4
+ globalThis._zubyGlobalContext = {};
5
+ }
6
+ return globalContext;
7
+ };
@@ -0,0 +1,6 @@
1
+ export * from './globalContext.js';
2
+ export * from './pageContext.js';
3
+ export { PageContext as HandlerContext } from './pageContext.js';
4
+ export { PageContext as ZubyPageContext } from './pageContext.js';
5
+ export { PageContext as ZubyHandlerContext } from './pageContext.js';
6
+ export { GlobalContext as ZubyGlobalContext } from './globalContext.js';
@@ -0,0 +1,5 @@
1
+ export * from './globalContext.js';
2
+ export * from './pageContext.js';
3
+ export { PageContext as HandlerContext } from './pageContext.js';
4
+ export { PageContext as ZubyPageContext } from './pageContext.js';
5
+ export { PageContext as ZubyHandlerContext } from './pageContext.js';
@@ -1,5 +1,5 @@
1
- import { ZubyContext } from '../context/index.js';
2
- export declare class ZubyPageContext {
1
+ import { GlobalContext } from './globalContext.js';
2
+ export declare class PageContext {
3
3
  protected _url: URL;
4
4
  protected _initialPath: string;
5
5
  protected _title: string;
@@ -12,7 +12,8 @@ export declare class ZubyPageContext {
12
12
  protected _props: Record<string, any>;
13
13
  protected _serverProps: Record<string, any>;
14
14
  protected _headElements: (string | (() => any))[];
15
- protected _zubyContext: ZubyContext;
15
+ protected _bodyElements: (string | (() => any))[];
16
+ protected _globalContext: GlobalContext;
16
17
  constructor(options: {
17
18
  url?: URL;
18
19
  initialPath?: string;
@@ -22,7 +23,7 @@ export declare class ZubyPageContext {
22
23
  statusCode?: number;
23
24
  props?: Record<string, any>;
24
25
  headers?: Headers;
25
- zubyContext?: ZubyContext;
26
+ globalContext?: GlobalContext;
26
27
  });
27
28
  /**
28
29
  * The current URL of the page.
@@ -61,31 +62,31 @@ export declare class ZubyPageContext {
61
62
  * The value of 'site' property from the ZubyConfig.
62
63
  * @example https://example.com
63
64
  */
64
- get site(): string | undefined;
65
+ get site(): string;
65
66
  /**
66
67
  * The generator name
67
68
  * tha can be used in the meta tag.
68
69
  * @example Zuby.js v1.0.0
69
70
  */
70
- get generator(): string | undefined;
71
+ get generator(): string;
71
72
  /**
72
73
  * The used Zuby version.
73
74
  * @example 1.0.0
74
75
  */
75
- get version(): string | undefined;
76
+ get version(): string;
76
77
  /**
77
78
  * The object with all parsed templates.
78
79
  * The available templates differ in browser and server env.
79
80
  */
80
81
  get templates(): {
81
- pages?: import("../templates/types.js").LazyTemplate[] | undefined;
82
- apps?: import("../templates/types.js").LazyTemplate[] | undefined;
83
- errors?: import("../templates/types.js").LazyTemplate[] | undefined;
84
- layouts?: import("../templates/types.js").LazyTemplate[] | undefined;
85
- innerLayouts?: import("../templates/types.js").LazyTemplate[] | undefined;
86
- handlers?: import("../templates/types.js").LazyTemplate[] | undefined;
87
- loaders?: import("../templates/types.js").LazyTemplate[] | undefined;
88
- } | undefined;
82
+ pages: import("../templates/types.js").LazyTemplate[];
83
+ apps: import("../templates/types.js").LazyTemplate[];
84
+ errors: import("../templates/types.js").LazyTemplate[];
85
+ layouts: import("../templates/types.js").LazyTemplate[];
86
+ innerLayouts: import("../templates/types.js").LazyTemplate[];
87
+ handlers: import("../templates/types.js").LazyTemplate[];
88
+ loaders: import("../templates/types.js").LazyTemplate[];
89
+ };
89
90
  /**
90
91
  * The object with props that should be passed to the page component.
91
92
  * The props are shared between page and handlers on given path.
@@ -109,11 +110,11 @@ export declare class ZubyPageContext {
109
110
  /**
110
111
  * The global props from the ZubyConfig
111
112
  */
112
- get globalProps(): Record<string, any> | undefined;
113
+ get globalProps(): Record<string, any>;
113
114
  /**
114
115
  * The global server props from the ZubyConfig
115
116
  */
116
- get globalServerProps(): Record<string, any> | undefined;
117
+ get globalServerProps(): Record<string, any>;
117
118
  /**
118
119
  * The current status code that will be returned to the client.
119
120
  * This property has only effect in server-side.
@@ -196,17 +197,40 @@ export declare class ZubyPageContext {
196
197
  * The current build ID of the site.
197
198
  * @example ecdf1a94cc9b4f4c
198
199
  */
199
- get buildId(): string | undefined;
200
+ get buildId(): string;
200
201
  /**
201
202
  * Adds the given HTML string
202
203
  * or Jsx Component to the head of the page
203
204
  * when it's rendered on the server.
205
+ * @param element The HTML string
206
+ * @param front If true, the element is added to the beginning of the head tag
204
207
  */
205
- addToHead(element: string | (() => any)): void;
208
+ addToHead(element: string | (() => any), front?: boolean): number | undefined;
209
+ /**
210
+ * Adds the given HTML string
211
+ * or Jsx Component to the body of the page
212
+ * when it's rendered on the server.
213
+ * @param element The HTML string
214
+ * @param front If true, the element is added to the end of the body tag
215
+ */
216
+ addToBody(element: string | (() => any), front?: boolean): number | undefined;
206
217
  /**
207
218
  * Returns array of all elements as string
208
219
  * that should be added to the head of the page.
209
220
  * @private
210
221
  */
211
222
  getHeadElements(): Promise<string[]>;
223
+ /**
224
+ * Returns array of all elements as string
225
+ * that should be added to the body of the page.
226
+ * @private
227
+ */
228
+ getBodyElements(): Promise<string[]>;
229
+ /**
230
+ * Renders the given HTML element
231
+ * or function component to string
232
+ * @param element The HTML string or function component
233
+ * @private
234
+ */
235
+ protected getElement(element: string | (() => any)): Promise<string>;
212
236
  }
@@ -1,5 +1,5 @@
1
- import { getContext } from '../context/index.js';
2
- export class ZubyPageContext {
1
+ import { getGlobalContext } from './globalContext.js';
2
+ export class PageContext {
3
3
  constructor(options) {
4
4
  this._request = options?.request;
5
5
  this._url = options?.url || new URL(options?.request?.url || '/', 'http://localhost/');
@@ -12,8 +12,9 @@ export class ZubyPageContext {
12
12
  this._serverProps = {};
13
13
  this._cache = 0;
14
14
  this._headers = options?.headers || new Headers();
15
- this._zubyContext = options?.zubyContext || getContext();
16
- this._headElements = [...(this._zubyContext.headElements || [])];
15
+ this._globalContext = options?.globalContext || getGlobalContext();
16
+ this._headElements = [...(this._globalContext.headElements || [])];
17
+ this._bodyElements = [...(this._globalContext.bodyElements || [])];
17
18
  }
18
19
  /**
19
20
  * The current URL of the page.
@@ -78,7 +79,7 @@ export class ZubyPageContext {
78
79
  * @example https://example.com
79
80
  */
80
81
  get site() {
81
- return this._zubyContext.site;
82
+ return this._globalContext.site;
82
83
  }
83
84
  /**
84
85
  * The generator name
@@ -86,21 +87,21 @@ export class ZubyPageContext {
86
87
  * @example Zuby.js v1.0.0
87
88
  */
88
89
  get generator() {
89
- return this._zubyContext.generator;
90
+ return this._globalContext.generator;
90
91
  }
91
92
  /**
92
93
  * The used Zuby version.
93
94
  * @example 1.0.0
94
95
  */
95
96
  get version() {
96
- return this._zubyContext.version;
97
+ return this._globalContext.version;
97
98
  }
98
99
  /**
99
100
  * The object with all parsed templates.
100
101
  * The available templates differ in browser and server env.
101
102
  */
102
103
  get templates() {
103
- return this._zubyContext.templates;
104
+ return this._globalContext.templates;
104
105
  }
105
106
  /**
106
107
  * The object with props that should be passed to the page component.
@@ -126,7 +127,7 @@ export class ZubyPageContext {
126
127
  */
127
128
  get serverProps() {
128
129
  return {
129
- ...(this._zubyContext.serverProps || {}),
130
+ ...(this._globalContext.serverProps || {}),
130
131
  ...(this._serverProps || {}),
131
132
  };
132
133
  }
@@ -137,13 +138,13 @@ export class ZubyPageContext {
137
138
  * The global props from the ZubyConfig
138
139
  */
139
140
  get globalProps() {
140
- return this._zubyContext.props;
141
+ return this._globalContext.props;
141
142
  }
142
143
  /**
143
144
  * The global server props from the ZubyConfig
144
145
  */
145
146
  get globalServerProps() {
146
- return this._zubyContext.serverProps;
147
+ return this._globalContext.serverProps;
147
148
  }
148
149
  /**
149
150
  * The current status code that will be returned to the client.
@@ -215,7 +216,7 @@ export class ZubyPageContext {
215
216
  * @example ['en', 'de', 'cs', 'pl']
216
217
  */
217
218
  get locales() {
218
- return this._zubyContext.i18n?.locales || [];
219
+ return this._globalContext.i18n?.locales || [];
219
220
  }
220
221
  /**
221
222
  * The default locale
@@ -225,7 +226,7 @@ export class ZubyPageContext {
225
226
  * @example 'en'
226
227
  */
227
228
  get defaultLocale() {
228
- return this._zubyContext.i18n?.defaultLocale;
229
+ return this._globalContext.i18n?.defaultLocale;
229
230
  }
230
231
  /**
231
232
  * The current active locale matched from the URL.
@@ -261,27 +262,58 @@ export class ZubyPageContext {
261
262
  * @example ecdf1a94cc9b4f4c
262
263
  */
263
264
  get buildId() {
264
- return this._zubyContext.buildId;
265
+ return this._globalContext.buildId;
265
266
  }
266
267
  /**
267
268
  * Adds the given HTML string
268
269
  * or Jsx Component to the head of the page
269
270
  * when it's rendered on the server.
271
+ * @param element The HTML string
272
+ * @param front If true, the element is added to the beginning of the head tag
270
273
  */
271
- addToHead(element) {
274
+ addToHead(element, front = false) {
275
+ if (front)
276
+ return this._headElements.unshift(element);
272
277
  this._headElements.push(element);
273
278
  }
279
+ /**
280
+ * Adds the given HTML string
281
+ * or Jsx Component to the body of the page
282
+ * when it's rendered on the server.
283
+ * @param element The HTML string
284
+ * @param front If true, the element is added to the end of the body tag
285
+ */
286
+ addToBody(element, front = false) {
287
+ if (front)
288
+ return this._bodyElements.unshift(element);
289
+ this._bodyElements.push(element);
290
+ }
274
291
  /**
275
292
  * Returns array of all elements as string
276
293
  * that should be added to the head of the page.
277
294
  * @private
278
295
  */
279
296
  async getHeadElements() {
280
- return Promise.all(this._headElements.map(element => {
281
- if (typeof element === 'function') {
282
- return this._zubyContext?.renderToString?.(element()) || '';
283
- }
284
- return element;
285
- }));
297
+ return Promise.all(this._headElements.map(element => this.getElement(element)));
298
+ }
299
+ /**
300
+ * Returns array of all elements as string
301
+ * that should be added to the body of the page.
302
+ * @private
303
+ */
304
+ async getBodyElements() {
305
+ return Promise.all(this._bodyElements.map(element => this.getElement(element)));
306
+ }
307
+ /**
308
+ * Renders the given HTML element
309
+ * or function component to string
310
+ * @param element The HTML string or function component
311
+ * @private
312
+ */
313
+ async getElement(element) {
314
+ if (typeof element === 'function') {
315
+ return this._globalContext?.render?.renderToString?.(element()) || '';
316
+ }
317
+ return element;
286
318
  }
287
319
  }
@@ -0,0 +1 @@
1
+ export * from './useGlobalContext.js';
package/hooks/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './useGlobalContext.js';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Returns the global context of the application.
3
+ * @returns GlobalContext
4
+ */
5
+ export declare function useGlobalContext(): import("../contexts/globalContext.js").GlobalContext;
@@ -0,0 +1,8 @@
1
+ import { getGlobalContext } from '../contexts/index.js';
2
+ /**
3
+ * Returns the global context of the application.
4
+ * @returns GlobalContext
5
+ */
6
+ export function useGlobalContext() {
7
+ return getGlobalContext();
8
+ }
package/index.d.ts CHANGED
@@ -1,7 +1,4 @@
1
1
  export * from './types.js';
2
2
  export * from './defineConfig.js';
3
- export * from './context/index.js';
4
- export * from './pageContext/index.js';
5
- export { ZubyContext as Context } from './context/index.js';
6
- export { ZubyPageContext as PageContext } from './pageContext/index.js';
7
- export { ZubyPageContext as HandlerContext } from './pageContext/index.js';
3
+ export * from './contexts/index.js';
4
+ export * from './hooks/index.js';
package/index.js CHANGED
@@ -1,7 +1,4 @@
1
1
  export * from './types.js';
2
2
  export * from './defineConfig.js';
3
- export * from './context/index.js';
4
- export * from './pageContext/index.js';
5
- export { ZubyContext as Context } from './context/index.js';
6
- export { ZubyPageContext as PageContext } from './pageContext/index.js';
7
- export { ZubyPageContext as HandlerContext } from './pageContext/index.js';
3
+ export * from './contexts/index.js';
4
+ export * from './hooks/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zuby",
3
- "version": "1.0.62",
3
+ "version": "1.0.63",
4
4
  "description": "Zuby.js is a framework for building modern apps using Preact or React.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -22,11 +22,9 @@
22
22
  "chalk": "^5.3.0",
23
23
  "chokidar": "^3.5.3",
24
24
  "commander": "^11.0.0",
25
- "devalue": "^4.3.2",
26
25
  "esbuild": "^0.19.11",
27
26
  "glob": "^10.3.10",
28
27
  "inquirer": "^9.2.12",
29
- "magic-string": "^0.30.5",
30
28
  "rollup": "^4.9.5",
31
29
  "vite": "^5.0.11"
32
30
  },
@@ -1 +1,30 @@
1
- export declare const getZubyPackageConfig: (cache?: boolean) => any;
1
+ export interface ZubyPackageConfig {
2
+ name: string;
3
+ version: string;
4
+ description: string;
5
+ type?: string;
6
+ private?: boolean;
7
+ publishConfig?: {
8
+ directory?: string;
9
+ linkDirectory?: boolean;
10
+ };
11
+ main?: string;
12
+ scripts?: Record<string, string>;
13
+ keywords?: string[];
14
+ devDependencies?: Record<string, string>;
15
+ dependencies?: Record<string, string>;
16
+ peerDependencies?: Record<string, string>;
17
+ bin?: Record<string, string>;
18
+ license?: string;
19
+ author?: string;
20
+ homepage?: string;
21
+ repository?: {
22
+ type: string;
23
+ url: string;
24
+ };
25
+ }
26
+ /**
27
+ * Returns the package.json content of the current package.
28
+ * @param cache - If true, the package.json content will be cached.
29
+ */
30
+ export declare const getZubyPackageConfig: (cache?: boolean) => ZubyPackageConfig;
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
  };