@withstudiocms/component-registry 0.1.0-beta.2 → 0.1.0-beta.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @withstudiocms/component-registry
2
2
 
3
+ ## 0.1.0-beta.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#956](https://github.com/withstudiocms/studiocms/pull/956) [`1d26adb`](https://github.com/withstudiocms/studiocms/commit/1d26adbce761f8856d4282d7d1b81d9570df32ac) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update dependency ts-morph to ^27.0.2
8
+
9
+ - Updated dependencies [[`d3123fe`](https://github.com/withstudiocms/studiocms/commit/d3123febbb0acdfb8d79629e9c2b101dff8a2bc7), [`58e8d06`](https://github.com/withstudiocms/studiocms/commit/58e8d0629ce039be239f17ef616256f53570901f), [`0f924e7`](https://github.com/withstudiocms/studiocms/commit/0f924e7a27f0e7480afe4f58061451499a5f6913)]:
10
+ - @withstudiocms/effect@0.1.0-beta.4
11
+
12
+ ## 0.1.0-beta.3
13
+
14
+ ### Patch Changes
15
+
16
+ - [#788](https://github.com/withstudiocms/studiocms/pull/788) [`9d3784c`](https://github.com/withstudiocms/studiocms/commit/9d3784c1de98a4bc7bb913742c3977e16c87cc1b) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Convert tests to vitest
17
+
18
+ - [#780](https://github.com/withstudiocms/studiocms/pull/780) [`627119b`](https://github.com/withstudiocms/studiocms/commit/627119bfde88e9c2ea74a29817d91fb6afbab33d) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update dependency ts-morph to v27
19
+
20
+ - [#798](https://github.com/withstudiocms/studiocms/pull/798) [`55885eb`](https://github.com/withstudiocms/studiocms/commit/55885eba617d8ec790e68ed0985f8530628140d8) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Add tests for `@withstudiocms/component-registry`
21
+
22
+ - Updated dependencies [[`9d3784c`](https://github.com/withstudiocms/studiocms/commit/9d3784c1de98a4bc7bb913742c3977e16c87cc1b), [`bf15ff6`](https://github.com/withstudiocms/studiocms/commit/bf15ff65a5f4ba6c2e4cd616d3c45ba0da784a1a), [`3b59fcf`](https://github.com/withstudiocms/studiocms/commit/3b59fcf7885d5c4952bd30279fa8ea2e2f0f5eaa), [`3d3612d`](https://github.com/withstudiocms/studiocms/commit/3d3612d510f4827acfb4de364d39e835a693818f), [`c2c2b73`](https://github.com/withstudiocms/studiocms/commit/c2c2b73a71009769e38ea4b30ae4010f6f0fdd14), [`47a2fed`](https://github.com/withstudiocms/studiocms/commit/47a2fedd8ed1c751def929058772ea78532e8d7d), [`fbb9ad1`](https://github.com/withstudiocms/studiocms/commit/fbb9ad10555f26c8e6261cd71a7650ab4aeb64f9), [`faf2a70`](https://github.com/withstudiocms/studiocms/commit/faf2a70ae57d136a9ccbbdebad70897e42c14c64), [`0e8e280`](https://github.com/withstudiocms/studiocms/commit/0e8e280c4a2a7552d3b78b370600019e49f5a459), [`9b85861`](https://github.com/withstudiocms/studiocms/commit/9b85861b20ca9eb2aa2c434b225ff85399bb04f0)]:
23
+ - @withstudiocms/effect@0.1.0-beta.3
24
+
3
25
  ## 0.1.0-beta.2
4
26
 
5
27
  ### Patch Changes
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @withstudiocms/component-registry
2
2
 
3
+ [![codecov](https://codecov.io/github/withstudiocms/studiocms/graph/badge.svg?token=RN8LT1O5E2&component=withstudiocms_component_registry)](https://codecov.io/github/withstudiocms/studiocms)
4
+
3
5
  Create a virtual Astro Component registry with ease.
4
6
 
5
7
  ## Install
@@ -31,7 +31,8 @@ const decodeMap = /* @__PURE__ */ new Map([
31
31
  ]);
32
32
  const fromCodePoint = (
33
33
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, n/no-unsupported-features/es-builtins
34
- String.fromCodePoint ?? ((codePoint) => {
34
+ String.fromCodePoint ?? /* v8 ignore start */
35
+ ((codePoint) => {
35
36
  let output = "";
36
37
  if (codePoint > 65535) {
37
38
  codePoint -= 65536;
@@ -103,6 +103,7 @@ class EntityDecoder {
103
103
  this.state = 4 /* NamedEntity */;
104
104
  return this.stateNamedEntity(input, offset);
105
105
  }
106
+ /* v8 ignore start */
106
107
  case 1 /* NumericStart */: {
107
108
  return this.stateNumericStart(input, offset);
108
109
  }
@@ -297,6 +298,7 @@ class EntityDecoder {
297
298
  }
298
299
  return consumed;
299
300
  }
301
+ /* v8 ignore start */
300
302
  /**
301
303
  * Signal to the parser that the end of the input was reached.
302
304
  *
@@ -325,6 +327,7 @@ class EntityDecoder {
325
327
  }
326
328
  }
327
329
  }
330
+ /* v8 ignore stop */
328
331
  }
329
332
  function getDecoder(decodeTree) {
330
333
  let returnValue = "";
@@ -1,6 +1,14 @@
1
1
  import type { SSRResult } from 'astro';
2
+ import { jsx } from 'astro/jsx-runtime';
3
+ import { renderJSX } from 'astro/runtime/server/jsx.js';
4
+ import { __unsafeHTML } from 'ultrahtml';
2
5
  import type { ComponentType } from '../types.js';
3
6
  export * from './decoder/index.js';
7
+ interface TestProps {
8
+ renderJSX: typeof renderJSX;
9
+ jsx: typeof jsx;
10
+ __unsafeHTML: typeof __unsafeHTML;
11
+ }
4
12
  /**
5
13
  * Creates a proxy for components that can either be strings or functions.
6
14
  * If the component is a string, it is directly assigned to the proxy.
@@ -11,4 +19,4 @@ export * from './decoder/index.js';
11
19
  * @param _components - An optional record of components to be proxied. Defaults to an empty object.
12
20
  * @returns A record of proxied components.
13
21
  */
14
- export declare function createComponentProxy(result: SSRResult, _components?: ComponentType): ComponentType;
22
+ export declare function createComponentProxy(result: SSRResult, _components?: ComponentType, _testProps?: TestProps): ComponentType;
@@ -3,7 +3,7 @@ import { renderJSX } from "astro/runtime/server/jsx.js";
3
3
  import { __unsafeHTML } from "ultrahtml";
4
4
  import { decode } from "./decoder/index.js";
5
5
  export * from "./decoder/index.js";
6
- function createComponentProxy(result, _components = {}) {
6
+ function createComponentProxy(result, _components = {}, _testProps = { jsx, __unsafeHTML, renderJSX }) {
7
7
  const components = /* @__PURE__ */ Object.create(null);
8
8
  for (const [rawKey, value] of Object.entries(_components)) {
9
9
  const lowerKey = rawKey.toLowerCase();
@@ -24,11 +24,11 @@ function createComponentProxy(result, _components = {}) {
24
24
  props = { ...props, code: decode(safe) };
25
25
  }
26
26
  }
27
- const output = await renderJSX(
27
+ const output = await _testProps.renderJSX(
28
28
  result,
29
- jsx(value, { ...props, "set:html": children?.value })
29
+ _testProps.jsx(value, { ...props, "set:html": children?.value })
30
30
  );
31
- return __unsafeHTML(output);
31
+ return _testProps.__unsafeHTML(output);
32
32
  };
33
33
  }
34
34
  }
@@ -22,6 +22,7 @@ class PropsParser extends Effect.Service()("PropsParser", {
22
22
  const tagName = tag.getTagName();
23
23
  const commentText = tag.getCommentText();
24
24
  switch (tagName) {
25
+ /* v8 ignore start */
25
26
  case "param": {
26
27
  const paramInfo = tag.getStructure();
27
28
  jsDocTags.push({
@@ -32,6 +33,7 @@ class PropsParser extends Effect.Service()("PropsParser", {
32
33
  });
33
34
  break;
34
35
  }
36
+ /* v8 ignore stop */
35
37
  case "default": {
36
38
  defaultValue = commentText;
37
39
  jsDocTags.push({
@@ -52,6 +54,7 @@ class PropsParser extends Effect.Service()("PropsParser", {
52
54
  case "internal":
53
55
  case "beta":
54
56
  case "alpha":
57
+ /* v8 ignore start */
55
58
  case "experimental": {
56
59
  jsDocTags.push({
57
60
  tagName,
@@ -126,6 +129,7 @@ class PropsParser extends Effect.Service()("PropsParser", {
126
129
  }
127
130
  return results;
128
131
  },
132
+ /* v8 ignore start */
129
133
  catch: (error) => {
130
134
  console.error("Error parsing component props:", error);
131
135
  return new ComponentRegistryError({
@@ -133,6 +137,7 @@ class PropsParser extends Effect.Service()("PropsParser", {
133
137
  cause: error
134
138
  });
135
139
  }
140
+ /* v8 ignore stop */
136
141
  }),
137
142
  extractPropsFromAstroFile: (astroFileContent) => Effect.try({
138
143
  try: () => {
@@ -28,10 +28,14 @@ class ComponentRegistry extends Effect.Service()("ComponentRegistry", {
28
28
  const name = componentName || path.basename(filePath, path.extname(filePath));
29
29
  const parsed = yield* parser.parseComponentProps(propsDefinition).pipe(
30
30
  Effect.mapError(
31
- (error) => new ComponentRegistryError({
32
- message: `Failed to register component ${name}`,
33
- cause: error
34
- })
31
+ (error) => (
32
+ /* v8 ignore start */
33
+ new ComponentRegistryError({
34
+ message: `Failed to register component ${name}`,
35
+ cause: error
36
+ })
37
+ )
38
+ /* v8 ignore stop */
35
39
  )
36
40
  );
37
41
  if (parsed.length > 0) {
@@ -1,4 +1,5 @@
1
1
  /// <reference types="../virtual.d.ts" preserve="true" />
2
+ import { Effect } from '@withstudiocms/effect';
2
3
  import { z } from 'astro/zod';
3
4
  export declare const ComponentRegistryHandlerOptionSchema: z.ZodObject<{
4
5
  config: z.ZodObject<{
@@ -51,6 +52,19 @@ export declare const ComponentRegistryHandlerOptionSchema: z.ZodObject<{
51
52
  builtInComponents?: Record<string, string> | undefined;
52
53
  }>;
53
54
  export type ComponentRegistryHandlerOptions = z.infer<typeof ComponentRegistryHandlerOptionSchema>;
55
+ /**
56
+ * Creates an Effect-based resolver function for resolving component paths.
57
+ *
58
+ * @param base - The base path used to initialize the resolver.
59
+ * @returns An Effect-wrapped function that accepts a callback. The callback receives a `resolve` function,
60
+ * which can be used to resolve component paths relative to the base. If an error occurs during resolution,
61
+ * it is caught, logged to the console, and an Error object is returned with the original error as its cause.
62
+ *
63
+ * @example
64
+ * const resolveEffect = resolver('/components');
65
+ * const result = yield* resolveEffect((resolve) => resolve('Button'));
66
+ */
67
+ export declare const resolver: (base: string) => Effect.Effect<(fn: (resolve: (...path: Array<string>) => string) => string) => Effect.Effect.AsEffect<Effect.Effect<string, Error, never>>, never, never>;
54
68
  /**
55
69
  * Handles the setup and registration of components in the component registry during the Astro config setup phase.
56
70
  *
@@ -157,5 +157,6 @@ ${JSON.stringify(componentProps, null, 2)}`
157
157
  );
158
158
  export {
159
159
  ComponentRegistryHandlerOptionSchema,
160
- componentRegistryHandler
160
+ componentRegistryHandler,
161
+ resolver
161
162
  };
package/dist/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const integrationLogger = async (opts, message) => {
2
- const { logLevel, logger, verbose } = opts;
2
+ const { logLevel, logger, verbose = false } = opts;
3
3
  switch (verbose) {
4
4
  case true:
5
5
  logger[logLevel](message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withstudiocms/component-registry",
3
- "version": "0.1.0-beta.2",
3
+ "version": "0.1.0-beta.4",
4
4
  "description": "Component Registry Utilities for Astro",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -69,14 +69,14 @@
69
69
  },
70
70
  "type": "module",
71
71
  "dependencies": {
72
- "astro-integration-kit": "^0.19.0",
73
- "ts-morph": "^26.0.0",
72
+ "astro-integration-kit": "^0.19.1",
73
+ "ts-morph": "^27.0.2",
74
74
  "ultrahtml": "1.6.0",
75
- "@withstudiocms/effect": "0.1.0-beta.2"
75
+ "@withstudiocms/effect": "0.1.0-beta.4"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@types/node": "^22.0.0",
79
- "typescript": "^5.9.2"
79
+ "typescript": "^5.9.3"
80
80
  },
81
81
  "peerDependencies": {
82
82
  "astro": "^5.12.9"
@@ -84,7 +84,7 @@
84
84
  "scripts": {
85
85
  "build": "buildkit build 'src/**/*.{ts,d.ts}'",
86
86
  "dev": "buildkit dev 'src/**/*.{ts,d.ts}'",
87
- "test": "buildkit test 'test/**/*.test.js'",
87
+ "test": "vitest",
88
88
  "typecheck": "tspc -p tsconfig.tspc.json"
89
89
  }
90
90
  }