@blinkk/root 1.0.0-beta.0 → 1.0.0-beta.10

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.
@@ -1,6 +1,6 @@
1
1
  import { Express, Request as Request$1, Response as Response$1, NextFunction as NextFunction$1 } from 'express';
2
2
  import { ComponentType } from 'preact';
3
- import { ViteDevServer, PluginOption, UserConfig } from 'vite';
3
+ import { PluginOption, UserConfig, ViteDevServer } from 'vite';
4
4
  import { Options } from 'html-minifier-terser';
5
5
  import { HTMLBeautifyOptions } from 'js-beautify';
6
6
 
@@ -30,6 +30,136 @@ interface AssetMap {
30
30
  get: (src: string) => Promise<Asset | null>;
31
31
  }
32
32
 
33
+ declare type MaybePromise<T> = T | Promise<T>;
34
+ declare type ConfigureServerHook = (server: Server, options: ConfigureServerOptions) => MaybePromise<void> | MaybePromise<() => void>;
35
+ interface ConfigureServerOptions {
36
+ type: 'dev' | 'preview' | 'prod';
37
+ rootConfig: RootConfig;
38
+ }
39
+ interface Plugin {
40
+ [key: string]: any;
41
+ /** The name of the plugin. */
42
+ name?: string;
43
+ /**
44
+ * Configures the root.js express server. Any middleware defined by the plugin
45
+ * will be added to the server first. If a callback fn is returned, it will
46
+ * be called after the root.js middlewares are added.
47
+ */
48
+ configureServer?: ConfigureServerHook;
49
+ /**
50
+ * Returns a list of deps to bundle for ssr. The files will be bundled and
51
+ * output to `dist/server/`. The return value should be a map of
52
+ * `{output filename => input filepath}`.
53
+ *
54
+ * E.g. a value of `{foo: 'path/to/bar.js'}` will output `dist/server/foo.js`.
55
+ *
56
+ * @experimental This config is subject to change to be incorporated into a
57
+ * broader config option called "ssr" or "ssrOptions".
58
+ */
59
+ ssrInput?: () => {
60
+ [entryAlias: string]: string;
61
+ };
62
+ /** Adds vite plugins. */
63
+ vitePlugins?: PluginOption[];
64
+ }
65
+ /**
66
+ * Runs the pre-hook configureServer method of every plugin, calls a callback
67
+ * function, and then runs the configureServer's post-hook if provided. Plugins
68
+ * provide a post-hook by returning a callback function from configureServer.
69
+ */
70
+ declare function configureServerPlugins(server: Server, callback: () => Promise<void>, plugins: Plugin[], options: ConfigureServerOptions): Promise<void>;
71
+ declare function getVitePlugins(plugins: Plugin[]): PluginOption[];
72
+
73
+ declare type HtmlMinifyOptions = Options;
74
+
75
+ declare type HtmlPrettyOptions = HTMLBeautifyOptions;
76
+
77
+ interface RootUserConfig {
78
+ /**
79
+ * Canonical domain the website will serve on. Useful for things like the
80
+ * sitemap, SEO tags, etc.
81
+ */
82
+ domain?: string;
83
+ /**
84
+ * Config for auto-injecting custom element dependencies.
85
+ */
86
+ elements?: {
87
+ /**
88
+ * A list of directories to use to look for custom elements. The dir path
89
+ * should be relative to the project dir, e.g. "path/to/elements".
90
+ */
91
+ include?: string[];
92
+ /**
93
+ * A list of RegEx patterns to exclude. The string passed to the RegEx is
94
+ * the file URL relative to the project root, e.g. "/elements/foo/foo.ts".
95
+ */
96
+ exclude?: RegExp[];
97
+ };
98
+ /**
99
+ * Config options for localization and internationalization.
100
+ */
101
+ i18n?: RootI18nConfig;
102
+ /**
103
+ * Config options for the Root.js express server.
104
+ */
105
+ server?: RootServerConfig;
106
+ /**
107
+ * Vite config.
108
+ * @see {@link https://vitejs.dev/config/} for more information.
109
+ */
110
+ vite?: UserConfig;
111
+ /**
112
+ * Whether to automatically minify HTML output. This is enabled by default,
113
+ * in order to disable, pass `minifyHtml: false` to root.config.ts.
114
+ */
115
+ minifyHtml?: boolean;
116
+ /**
117
+ * Options to pass to html-minifier-terser.
118
+ */
119
+ minifyHtmlOptions?: HtmlMinifyOptions;
120
+ /**
121
+ * Whether to pretty print HTML output.
122
+ */
123
+ prettyHtml?: boolean;
124
+ /**
125
+ * Options to pass to js-beautify.
126
+ */
127
+ prettyHtmlOptions?: HtmlPrettyOptions;
128
+ /**
129
+ * Whether to include a sitemap.xml file to the build output.
130
+ */
131
+ sitemap?: boolean;
132
+ /**
133
+ * Plugins.
134
+ */
135
+ plugins?: Plugin[];
136
+ }
137
+ declare type RootConfig = RootUserConfig & {
138
+ rootDir: string;
139
+ };
140
+ interface RootI18nConfig {
141
+ /**
142
+ * Locales enabled for the site.
143
+ */
144
+ locales?: string[];
145
+ /**
146
+ * The default locale to use. Defaults is `en`.
147
+ */
148
+ defaultLocale?: string;
149
+ /**
150
+ * URL format for localized content. Default is `/{locale}/{path}`.
151
+ */
152
+ urlFormat?: string;
153
+ }
154
+ interface RootServerConfig {
155
+ /**
156
+ * An array of middleware to add to the express server. These middleware are
157
+ * added to the beginning of the express app.
158
+ */
159
+ middlewares?: Array<(req: Request, res: Response, next: NextFunction) => void | Promise<void>>;
160
+ }
161
+ declare function defineConfig(config: RootUserConfig): RootUserConfig;
162
+
33
163
  interface ElementSourceFile {
34
164
  /** Full file path. */
35
165
  filePath: string;
@@ -54,6 +184,16 @@ declare class ElementGraph {
54
184
  constructor(sourceFiles: {
55
185
  [tagName: string]: ElementSourceFile;
56
186
  });
187
+ toJson(): {
188
+ sourceFiles: {
189
+ [tagName: string]: ElementSourceFile;
190
+ };
191
+ deps: Record<string, string[]>;
192
+ };
193
+ static fromJson(data: {
194
+ deps: any;
195
+ sourceFiles: any;
196
+ }): ElementGraph;
57
197
  getDeps(tagName: string, visited?: Set<string>): string[];
58
198
  /**
59
199
  * Parses an element's source file for usage of other custom elements.
@@ -210,134 +350,4 @@ interface Route {
210
350
  localeRoutePath: string;
211
351
  }
212
352
 
213
- declare type MaybePromise<T> = T | Promise<T>;
214
- declare type ConfigureServerHook = (server: Server, options: ConfigureServerOptions) => MaybePromise<void> | MaybePromise<() => void>;
215
- interface ConfigureServerOptions {
216
- type: 'dev' | 'preview' | 'prod';
217
- rootConfig: RootConfig;
218
- }
219
- interface Plugin {
220
- [key: string]: any;
221
- /** The name of the plugin. */
222
- name?: string;
223
- /**
224
- * Configures the root.js express server. Any middleware defined by the plugin
225
- * will be added to the server first. If a callback fn is returned, it will
226
- * be called after the root.js middlewares are added.
227
- */
228
- configureServer?: ConfigureServerHook;
229
- /**
230
- * Returns a list of deps to bundle for ssr. The files will be bundled and
231
- * output to `dist/server/`. The return value should be a map of
232
- * `{output filename => input filepath}`.
233
- *
234
- * E.g. a value of `{foo: 'path/to/bar.js'}` will output `dist/server/foo.js`.
235
- *
236
- * @experimental This config is subject to change to be incorporated into a
237
- * broader config option called "ssr" or "ssrOptions".
238
- */
239
- ssrInput?: () => {
240
- [entryAlias: string]: string;
241
- };
242
- /** Adds vite plugins. */
243
- vitePlugins?: PluginOption[];
244
- }
245
- /**
246
- * Runs the pre-hook configureServer method of every plugin, calls a callback
247
- * function, and then runs the configureServer's post-hook if provided. Plugins
248
- * provide a post-hook by returning a callback function from configureServer.
249
- */
250
- declare function configureServerPlugins(server: Server, callback: () => Promise<void>, plugins: Plugin[], options: ConfigureServerOptions): Promise<void>;
251
- declare function getVitePlugins(plugins: Plugin[]): PluginOption[];
252
-
253
- declare type HtmlMinifyOptions = Options;
254
-
255
- declare type HtmlPrettyOptions = HTMLBeautifyOptions;
256
-
257
- interface RootUserConfig {
258
- /**
259
- * Canonical domain the website will serve on. Useful for things like the
260
- * sitemap, SEO tags, etc.
261
- */
262
- domain?: string;
263
- /**
264
- * Config for auto-injecting custom element dependencies.
265
- */
266
- elements?: {
267
- /**
268
- * A list of directories to use to look for custom elements. The dir path
269
- * should be relative to the project dir, e.g. "path/to/elements".
270
- */
271
- include?: string[];
272
- /**
273
- * A list of RegEx patterns to exclude. The string passed to the RegEx is
274
- * the file URL relative to the project root, e.g. "/elements/foo/foo.ts".
275
- */
276
- exclude?: RegExp[];
277
- };
278
- /**
279
- * Config options for localization and internationalization.
280
- */
281
- i18n?: RootI18nConfig;
282
- /**
283
- * Config options for the Root.js express server.
284
- */
285
- server?: RootServerConfig;
286
- /**
287
- * Vite config.
288
- * @see {@link https://vitejs.dev/config/} for more information.
289
- */
290
- vite?: UserConfig;
291
- /**
292
- * Whether to automatically minify HTML output. This is enabled by default,
293
- * in order to disable, pass `minifyHtml: false` to root.config.ts.
294
- */
295
- minifyHtml?: boolean;
296
- /**
297
- * Options to pass to html-minifier-terser.
298
- */
299
- minifyHtmlOptions?: HtmlMinifyOptions;
300
- /**
301
- * Whether to pretty print HTML output.
302
- */
303
- prettyHtml?: boolean;
304
- /**
305
- * Options to pass to js-beautify.
306
- */
307
- prettyHtmlOptions?: HtmlPrettyOptions;
308
- /**
309
- * Whether to include a sitemap.xml file to the build output.
310
- */
311
- sitemap?: boolean;
312
- /**
313
- * Plugins.
314
- */
315
- plugins?: Plugin[];
316
- }
317
- declare type RootConfig = RootUserConfig & {
318
- rootDir: string;
319
- };
320
- interface RootI18nConfig {
321
- /**
322
- * Locales enabled for the site.
323
- */
324
- locales?: string[];
325
- /**
326
- * The default locale to use. Defaults is `en`.
327
- */
328
- defaultLocale?: string;
329
- /**
330
- * URL format for localized content. Default is `/{locale}/{path}`.
331
- */
332
- urlFormat?: string;
333
- }
334
- interface RootServerConfig {
335
- /**
336
- * An array of middleware to add to the express server. These middleware are
337
- * added to the beginning of the express app.
338
- */
339
- middlewares?: Array<(req: Request, res: Response, next: NextFunction) => void | Promise<void>>;
340
- }
341
- declare function defineConfig(config: RootUserConfig): RootUserConfig;
342
-
343
353
  export { ConfigureServerHook as C, GetStaticProps as G, HandlerContext as H, NextFunction as N, Plugin as P, Route as R, Server as S, RootUserConfig as a, RootConfig as b, RootI18nConfig as c, RootServerConfig as d, defineConfig as e, ConfigureServerOptions as f, configureServerPlugins as g, getVitePlugins as h, RouteParams as i, GetStaticPaths as j, Request as k, Response as l, Handler as m, RouteModule as n, Renderer as o };
package/package.json CHANGED
@@ -1,14 +1,20 @@
1
1
  {
2
2
  "name": "@blinkk/root",
3
- "version": "1.0.0-beta.0",
3
+ "version": "1.0.0-beta.10",
4
4
  "author": "s@blinkk.com",
5
5
  "license": "MIT",
6
6
  "engines": {
7
- "node": ">=18.0.0"
7
+ "node": ">=16.0.0"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/blinkk/rootjs.git",
12
+ "directory": "packages/root"
8
13
  },
9
14
  "files": [
10
15
  "bin/*",
11
- "dist/**/*"
16
+ "dist/**/*",
17
+ "client.d.ts"
12
18
  ],
13
19
  "bin": {
14
20
  "root": "./bin/root.js"
@@ -21,6 +27,7 @@
21
27
  "types": "./dist/core.d.ts",
22
28
  "import": "./dist/core.js"
23
29
  },
30
+ "./client": "./client.d.ts",
24
31
  "./*": {
25
32
  "types": "./dist/*.d.ts",
26
33
  "import": "./dist/*.js"
@@ -34,7 +41,6 @@
34
41
  "express": "^4.18.1",
35
42
  "fs-extra": "^10.1.0",
36
43
  "html-minifier-terser": "^7.0.0",
37
- "joycon": "^3.1.1",
38
44
  "js-beautify": "^1.14.7",
39
45
  "kleur": "^4.1.5",
40
46
  "sass": "^1.49.9",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/elements.ts","../src/render/html-minify.ts","../src/render/html-pretty.ts"],"sourcesContent":["export const ELEMENT_RE = /^[a-z][\\w-]*-[\\w-]*$/;\nexport const HTML_ELEMENTS_REGEX = /<([a-z][\\w-]*-[\\w-]*)/g;\n\n/**\n * Returns true if the tagName is a valid custom element tag.\n */\nexport function isValidTagName(tagName: string) {\n return ELEMENT_RE.test(tagName);\n}\n\n/**\n * Returns a list of custom elements used in a src string (e.g. HTML, jsx, lit).\n * NOTE: the impl uses a simple regex, so tagNames used in comments and attr\n * values may be included.\n */\nexport function parseTagNames(src: string): string[] {\n const tagNames = new Set<string>();\n const matches = Array.from(src.matchAll(HTML_ELEMENTS_REGEX));\n for (const match of matches) {\n const tagName = match[1];\n tagNames.add(tagName);\n }\n return Array.from(tagNames);\n}\n","import {createRequire} from 'module';\nconst require = createRequire(import.meta.url);\nconst {minify} = require('html-minifier-terser');\nimport type {Options} from 'html-minifier-terser';\n\nexport type HtmlMinifyOptions = Options;\n\nexport async function htmlMinify(\n html: string,\n options?: HtmlMinifyOptions\n): Promise<string> {\n const minifyOptions = options || {\n collapseWhitespace: true,\n removeComments: true,\n preserveLineBreaks: true,\n };\n try {\n const min = await minify(html, minifyOptions);\n return min.trimStart();\n } catch (e) {\n console.error('failed to minify html:', e);\n return html;\n }\n}\n","import {createRequire} from 'module';\nconst require = createRequire(import.meta.url);\nconst beautify = require('js-beautify');\nimport type {HTMLBeautifyOptions} from 'js-beautify';\n\nexport type HtmlPrettyOptions = HTMLBeautifyOptions;\n\nexport async function htmlPretty(\n html: string,\n options?: HtmlPrettyOptions\n): Promise<string> {\n const prettyOptions = options || {\n indent_size: 0,\n end_with_newline: true,\n extra_liners: [],\n };\n try {\n const output = beautify.html(html, prettyOptions);\n return output.trimStart();\n } catch (e) {\n console.error('failed to pretty html:', e);\n return html;\n }\n}\n"],"mappings":";AAAO,IAAM,aAAa;AACnB,IAAM,sBAAsB;AAK5B,SAAS,eAAe,SAAiB;AAC9C,SAAO,WAAW,KAAK,OAAO;AAChC;AAOO,SAAS,cAAc,KAAuB;AACnD,QAAM,WAAW,oBAAI,IAAY;AACjC,QAAM,UAAU,MAAM,KAAK,IAAI,SAAS,mBAAmB,CAAC;AAC5D,aAAW,SAAS,SAAS;AAC3B,UAAM,UAAU,MAAM;AACtB,aAAS,IAAI,OAAO;AAAA,EACtB;AACA,SAAO,MAAM,KAAK,QAAQ;AAC5B;;;ACvBA,SAAQ,qBAAoB;AAC5B,IAAMA,WAAU,cAAc,YAAY,GAAG;AAC7C,IAAM,EAAC,OAAM,IAAIA,SAAQ,sBAAsB;AAK/C,eAAsB,WACpB,MACA,SACiB;AACjB,QAAM,gBAAgB,WAAW;AAAA,IAC/B,oBAAoB;AAAA,IACpB,gBAAgB;AAAA,IAChB,oBAAoB;AAAA,EACtB;AACA,MAAI;AACF,UAAM,MAAM,MAAM,OAAO,MAAM,aAAa;AAC5C,WAAO,IAAI,UAAU;AAAA,EACvB,SAAS,GAAP;AACA,YAAQ,MAAM,0BAA0B,CAAC;AACzC,WAAO;AAAA,EACT;AACF;;;ACvBA,SAAQ,iBAAAC,sBAAoB;AAC5B,IAAMC,WAAUD,eAAc,YAAY,GAAG;AAC7C,IAAM,WAAWC,SAAQ,aAAa;AAKtC,eAAsB,WACpB,MACA,SACiB;AACjB,QAAM,gBAAgB,WAAW;AAAA,IAC/B,aAAa;AAAA,IACb,kBAAkB;AAAA,IAClB,cAAc,CAAC;AAAA,EACjB;AACA,MAAI;AACF,UAAM,SAAS,SAAS,KAAK,MAAM,aAAa;AAChD,WAAO,OAAO,UAAU;AAAA,EAC1B,SAAS,GAAP;AACA,YAAQ,MAAM,0BAA0B,CAAC;AACzC,WAAO;AAAA,EACT;AACF;","names":["require","createRequire","require"]}