revojs 0.2.26 → 0.2.28

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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { mimeType, mimeTypes } from "./assets/index.js";
2
- import { STATE_CONTEXT, VARIABLE_CONTEXT, createRegisterHooks, createScope, defineContext, defineHook, definePlugin, dispatchHook, dispatchHookSingle, getContext, registerHook, setContext, useVariables } from "./scope/index.js";
3
- import { GROUP_MATCH, HOOK_MATCH, OPTIONAL_PARAMETER_MATCH, OPTIONAL_WILDCARD_MATCH, PARAMETER_MATCH, ROUTE_CONTEXT, ROUTE_RESOLVER_CONTEXT, Router, WILDCARD_MATCH, fillSegments, toSegments, useRoute } from "./router/index.js";
4
- export { GROUP_MATCH, HOOK_MATCH, OPTIONAL_PARAMETER_MATCH, OPTIONAL_WILDCARD_MATCH, PARAMETER_MATCH, ROUTE_CONTEXT, ROUTE_RESOLVER_CONTEXT, Router, STATE_CONTEXT, VARIABLE_CONTEXT, WILDCARD_MATCH, createRegisterHooks, createScope, defineContext, defineHook, definePlugin, dispatchHook, dispatchHookSingle, fillSegments, getContext, mimeType, mimeTypes, registerHook, setContext, toSegments, useRoute, useVariables };
2
+ import { STATE_CONTEXT, VARIABLE_CONTEXT, createRegisterHooks, createScope, defineContext, defineHook, definePlugin, dispatchHook, dispatchHookSingle, getContext, registerHook, setContext, useVariableContext, useVariables } from "./scope/index.js";
3
+ import { GROUP_MATCH, HOOK_MATCH, OPTIONAL_PARAMETER_MATCH, OPTIONAL_WILDCARD_MATCH, PARAMETER_MATCH, ROUTE_CONTEXT, ROUTE_RESOLVER_CONTEXT, Router, WILDCARD_MATCH, fillSegments, toSegments, useRoute, useRouteResolverContext } from "./router/index.js";
4
+ export { GROUP_MATCH, HOOK_MATCH, OPTIONAL_PARAMETER_MATCH, OPTIONAL_WILDCARD_MATCH, PARAMETER_MATCH, ROUTE_CONTEXT, ROUTE_RESOLVER_CONTEXT, Router, STATE_CONTEXT, VARIABLE_CONTEXT, WILDCARD_MATCH, createRegisterHooks, createScope, defineContext, defineHook, definePlugin, dispatchHook, dispatchHookSingle, fillSegments, getContext, mimeType, mimeTypes, registerHook, setContext, toSegments, useRoute, useRouteResolverContext, useVariableContext, useVariables };
@@ -102,6 +102,7 @@ export declare function addTypes(config: Config, name: string, types: Template):
102
102
  export declare function posixPath(path: string): string;
103
103
  export declare function resolvePattern(pattern: string, cwd?: string): string[];
104
104
  export declare function resolvePaths(patterns: string | ArrayLike<string>, cwd?: string): string[];
105
+ export declare function matchesConsumer(path: string, consumer: Consumer): boolean;
105
106
  export declare function resolveSource(source: Source): Map<string, Map<string, string>>;
106
107
  export declare function useModule(source: string | URL): {
107
108
  fromModule: (...paths: Array<string>) => string;
@@ -54,6 +54,10 @@ function resolvePaths(patterns, cwd) {
54
54
  }
55
55
  return [...entries];
56
56
  }
57
+ function matchesConsumer(path, consumer) {
58
+ const marker = /\.(client|server)\.[^./]+$/.exec(path)?.[1];
59
+ return marker === void 0 || marker === consumer;
60
+ }
57
61
  function resolveSource(source) {
58
62
  const scopes = /* @__PURE__ */ new Map();
59
63
  for (const directory of source.from) {
@@ -163,11 +167,15 @@ async function core(config) {
163
167
  addVirtual(config, name, (consumer) => {
164
168
  if (!source.consumers.includes(consumer)) return "export {};";
165
169
  const cwd = posixPath(resolve("."));
166
- const lines = entries.map(([, path], index) => {
167
- const entry = posixPath(relative(cwd, path));
168
- return `export { default as ${names[index]} } from "${entry.startsWith(".") ? entry : "./" + entry}";`;
169
- });
170
- return lines.length > 0 ? lines.join("\n") : "export {};";
170
+ const lines = new Array();
171
+ for (const [index, [, path]] of entries.entries()) {
172
+ if (!matchesConsumer(path, consumer)) continue;
173
+ let entry = posixPath(relative(cwd, path));
174
+ if (!entry.startsWith(".")) entry = "./" + entry;
175
+ lines.push(`export { default as ${names[index]} } from "${entry}";`);
176
+ }
177
+ if (lines.length === 0) return "export {};";
178
+ return lines.join("\n");
171
179
  });
172
180
  addTypes(config, name, () => {
173
181
  const declarations = entries.map(([, path], index) => `export const ${names[index]}: typeof import("${posixPath(path)}").default;`);
@@ -177,12 +185,18 @@ async function core(config) {
177
185
  addVirtual(config, name, (consumer) => {
178
186
  if (!source.consumers.includes(consumer)) return "export default {};";
179
187
  const cwd = posixPath(resolve("."));
180
- return `export default { ${[...resolved].map(([scope, files]) => {
181
- return `"${scope}": { ${[...files].map(([key, path]) => {
182
- const entry = posixPath(relative(cwd, path));
183
- return `"${key}": () => import("${entry.startsWith(".") ? entry : "./" + entry}").then((module) => module.default)`;
184
- }).join(",")} }`;
185
- }).join(",")} }`;
188
+ const result = new Array();
189
+ for (const [scope, files] of resolved) {
190
+ const entries = new Array();
191
+ for (const [key, path] of files) {
192
+ if (!matchesConsumer(path, consumer)) continue;
193
+ let entry = posixPath(relative(cwd, path));
194
+ if (!entry.startsWith(".")) entry = "./" + entry;
195
+ entries.push(`"${key}": () => import("${entry}").then((module) => module.default)`);
196
+ }
197
+ result.push(`"${scope}": { ${entries.join(",")} }`);
198
+ }
199
+ return `export default { ${result.join(",")} }`;
186
200
  });
187
201
  addTypes(config, name, () => {
188
202
  const scopes = [...resolved].map(([scope, files]) => {
@@ -328,4 +342,4 @@ async function revojs(inputConfig) {
328
342
  }
329
343
  var PACKAGE_CACHE = /* @__PURE__ */ new Map();
330
344
  //#endregion
331
- export { addTemplate, addTypes, addVirtual, core, createConfig, defineCommand, defineModule, module, posixPath, resolvePaths, resolvePattern, resolveSource, revojs, useModule };
345
+ export { addTemplate, addTypes, addVirtual, core, createConfig, defineCommand, defineModule, matchesConsumer, module, posixPath, resolvePaths, resolvePattern, resolveSource, revojs, useModule };
package/dist/package.js CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region package.json
2
2
  var name = "revojs";
3
- var version = "0.2.26";
3
+ var version = "0.2.28";
4
4
  var repository = {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/tellua/revojs.git"
@@ -33,6 +33,7 @@ export declare class Router<T> {
33
33
  export declare function toSegments(route: string): string[];
34
34
  export declare function fillSegments(segments: Array<string>, parameters: Record<string, string>): string[];
35
35
  export declare function useRoute(scope: Scope): RouteContext;
36
+ export declare function useRouteResolverContext(scope: Scope): RouteResolver;
36
37
  export declare const ROUTE_CONTEXT: import("..").Descriptor<RouteContext>;
37
38
  export declare const ROUTE_RESOLVER_CONTEXT: import("..").Descriptor<RouteResolver>;
38
39
  export declare const WILDCARD_MATCH: RegExp;
@@ -109,7 +109,7 @@ var Router = class {
109
109
  return context;
110
110
  }
111
111
  async resolve(scope, segments) {
112
- const resolver = getContext(scope, ROUTE_RESOLVER_CONTEXT);
112
+ const resolver = useRouteResolverContext(scope);
113
113
  const result = typeof resolver === "function" ? await resolver(segments) : segments;
114
114
  return setContext(scope, ROUTE_CONTEXT, result ? this.match(result) : {
115
115
  segments,
@@ -172,6 +172,9 @@ function fillSegments(segments, parameters) {
172
172
  function useRoute(scope) {
173
173
  return getContext(scope, ROUTE_CONTEXT);
174
174
  }
175
+ function useRouteResolverContext(scope) {
176
+ return getContext(scope, ROUTE_RESOLVER_CONTEXT);
177
+ }
175
178
  var ROUTE_CONTEXT = defineContext("ROUTE_CONTEXT");
176
179
  var ROUTE_RESOLVER_CONTEXT = defineContext("ROUTE_RESOLVER_CONTEXT");
177
180
  var WILDCARD_MATCH = /^\[\.\.\.(.*)\]$/;
@@ -181,4 +184,4 @@ var OPTIONAL_PARAMETER_MATCH = /^\[\[(.*)\]\]$/;
181
184
  var GROUP_MATCH = /^\((.*)\)$/;
182
185
  var HOOK_MATCH = /^\+(.+)$/;
183
186
  //#endregion
184
- export { GROUP_MATCH, HOOK_MATCH, OPTIONAL_PARAMETER_MATCH, OPTIONAL_WILDCARD_MATCH, PARAMETER_MATCH, ROUTE_CONTEXT, ROUTE_RESOLVER_CONTEXT, Router, WILDCARD_MATCH, fillSegments, toSegments, useRoute };
187
+ export { GROUP_MATCH, HOOK_MATCH, OPTIONAL_PARAMETER_MATCH, OPTIONAL_WILDCARD_MATCH, PARAMETER_MATCH, ROUTE_CONTEXT, ROUTE_RESOLVER_CONTEXT, Router, WILDCARD_MATCH, fillSegments, toSegments, useRoute, useRouteResolverContext };
@@ -38,6 +38,7 @@ export declare function createScope(inputScope?: Mergeable<Scope>): Promise<{
38
38
  [x: string]: {} | undefined;
39
39
  } | undefined;
40
40
  } & Scope>;
41
+ export declare function useVariableContext(scope: Scope): unknown;
41
42
  export declare function useVariables<T = typeof import("#variables")>(scope: Scope): T;
42
43
  export declare function definePlugin<T extends Plugin>(plugin: T): T;
43
44
  export declare function defineHook<T extends Hook>(name: string): Descriptor<T>;
@@ -41,15 +41,18 @@ async function createScope(inputScope) {
41
41
  hooks: {},
42
42
  context: {}
43
43
  });
44
- for (const source of Object.values(plugins)) for (const resolve of Object.values(source)) {
45
- const plugin = await resolve();
46
- if (plugin) await plugin.setup(scope);
47
- }
44
+ const pending = new Array();
45
+ for (const source of Object.values(plugins)) for (const resolve of Object.values(source)) pending.push(resolve());
46
+ for (const plugin of await Promise.all(pending)) if (plugin) await plugin.setup(scope);
48
47
  return scope;
49
48
  }
49
+ function useVariableContext(scope) {
50
+ return getContext(scope, VARIABLE_CONTEXT);
51
+ }
50
52
  function useVariables(scope) {
51
53
  const normalize = (name) => name.toLowerCase().replace(/[^a-z0-9]/g, "");
52
- const entries = new Map(Object.entries(getContext(scope, VARIABLE_CONTEXT)).map(([name, value]) => [normalize(name), [name, value]]));
54
+ const entries = /* @__PURE__ */ new Map();
55
+ for (const [name, value] of Object.entries(useVariableContext(scope))) entries.set(normalize(name), [name, value]);
53
56
  for (const [name, variable] of Object.entries(variables)) {
54
57
  const key = normalize(name);
55
58
  let value = entries.get(key)?.[1] ?? variable.default;
@@ -74,4 +77,4 @@ function defineContext(name) {
74
77
  var VARIABLE_CONTEXT = defineContext("VARIABLE_CONTEXT");
75
78
  var STATE_CONTEXT = defineContext("STATE_CONTEXT");
76
79
  //#endregion
77
- export { STATE_CONTEXT, VARIABLE_CONTEXT, createRegisterHooks, createScope, defineContext, defineHook, definePlugin, dispatchHook, dispatchHookSingle, getContext, registerHook, setContext, useVariables };
80
+ export { STATE_CONTEXT, VARIABLE_CONTEXT, createRegisterHooks, createScope, defineContext, defineHook, definePlugin, dispatchHook, dispatchHookSingle, getContext, registerHook, setContext, useVariableContext, useVariables };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.2.26",
3
+ "version": "0.2.28",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",