@ecopages/mdx 0.2.0-alpha.13 → 0.2.0-alpha.15
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 +4 -0
- package/package.json +2 -2
- package/src/mdx-renderer.d.ts +8 -28
- package/src/mdx-renderer.js +3 -17
- package/src/mdx.plugin.d.ts +7 -6
- package/src/mdx.plugin.js +11 -3
- package/src/mdx.types.d.ts +27 -0
- package/src/mdx.types.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -18,6 +18,10 @@ All notable changes to `@ecopages/mdx` are documented here.
|
|
|
18
18
|
|
|
19
19
|
- Updated the README for standalone non-React MDX usage, `.md` opt-in handling, and compiler configuration.
|
|
20
20
|
|
|
21
|
+
### Refactoring
|
|
22
|
+
|
|
23
|
+
- Replaced the standalone MDX renderer factory with explicit renderer-owned compiler configuration and collected shared MDX plugin and renderer types into a dedicated module.
|
|
24
|
+
|
|
21
25
|
---
|
|
22
26
|
|
|
23
27
|
## Migration Notes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/mdx",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.15",
|
|
4
4
|
"description": "MDX plugin for Ecopages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecopages",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"directory": "packages/integrations/mdx"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@ecopages/core": "0.2.0-alpha.
|
|
40
|
+
"@ecopages/core": "0.2.0-alpha.15",
|
|
41
41
|
"@kitajs/html": "^4.1.0",
|
|
42
42
|
"@mdx-js/mdx": "^3.1.0"
|
|
43
43
|
},
|
package/src/mdx-renderer.d.ts
CHANGED
|
@@ -2,36 +2,24 @@
|
|
|
2
2
|
* This module contains the MDX renderer
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
|
-
import type { ComponentRenderInput, ComponentRenderResult, EcoComponent,
|
|
5
|
+
import type { ComponentRenderInput, ComponentRenderResult, EcoComponent, EcoPageFile, EcoPagesElement, IntegrationRendererRenderOptions, RouteRendererBody } from '@ecopages/core';
|
|
6
6
|
import { IntegrationRenderer, type RenderToResponseContext } from '@ecopages/core/route-renderer/integration-renderer';
|
|
7
|
-
import type {
|
|
7
|
+
import type { ProcessedAsset } from '@ecopages/core/services/asset-processing-service';
|
|
8
8
|
import type { CompileOptions } from '@mdx-js/mdx';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
export type MDXFile = {
|
|
13
|
-
default: EcoComponent;
|
|
14
|
-
config?: EcoComponentConfig;
|
|
15
|
-
getMetadata: GetMetadata;
|
|
16
|
-
};
|
|
9
|
+
import type { MDXRendererOptions } from './mdx.types.js';
|
|
10
|
+
export type { MDXFile, MDXRendererConfig, MDXRendererOptions } from './mdx.types.js';
|
|
17
11
|
/**
|
|
18
12
|
* Options for the MDX renderer
|
|
19
13
|
*/
|
|
20
|
-
interface
|
|
14
|
+
interface MDXIntegrationRendererOptions<C = EcoPagesElement> extends IntegrationRendererRenderOptions<C> {
|
|
21
15
|
}
|
|
22
16
|
/**
|
|
23
17
|
* A renderer for the MDX integration.
|
|
24
18
|
*/
|
|
25
19
|
export declare class MDXRenderer extends IntegrationRenderer<EcoPagesElement> {
|
|
26
20
|
name: string;
|
|
27
|
-
compilerOptions: CompileOptions;
|
|
28
|
-
constructor({
|
|
29
|
-
appConfig: any;
|
|
30
|
-
assetProcessingService: AssetProcessingService;
|
|
31
|
-
resolvedIntegrationDependencies: ProcessedAsset[];
|
|
32
|
-
runtimeOrigin: string;
|
|
33
|
-
compilerOptions?: CompileOptions;
|
|
34
|
-
});
|
|
21
|
+
readonly compilerOptions: CompileOptions;
|
|
22
|
+
constructor({ mdxConfig, ...options }: MDXRendererOptions);
|
|
35
23
|
buildRouteRenderAssets(pagePath: string): Promise<ProcessedAsset[]>;
|
|
36
24
|
protected normalizeImportedPageFile<TPageModule extends EcoPageFile>(_file: string, pageModule: TPageModule): TPageModule;
|
|
37
25
|
renderComponent(input: ComponentRenderInput): Promise<ComponentRenderResult>;
|
|
@@ -39,14 +27,6 @@ export declare class MDXRenderer extends IntegrationRenderer<EcoPagesElement> {
|
|
|
39
27
|
boundaryInput: ComponentRenderInput;
|
|
40
28
|
rendererCache: Map<string, IntegrationRenderer<any>>;
|
|
41
29
|
}): import("@ecopages/core").ComponentBoundaryRuntime;
|
|
42
|
-
render({ params, query, props, locals, pageLocals, metadata, Page, HtmlTemplate, Layout, pageProps, }:
|
|
30
|
+
render({ params, query, props, locals, pageLocals, metadata, Page, HtmlTemplate, Layout, pageProps, }: MDXIntegrationRendererOptions): Promise<RouteRendererBody>;
|
|
43
31
|
renderToResponse<P = Record<string, unknown>>(view: EcoComponent<P>, props: P, ctx: RenderToResponseContext): Promise<Response>;
|
|
44
32
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Factory function to create an MDX renderer class with specific compiler options.
|
|
47
|
-
*
|
|
48
|
-
* @param compilerOptions - Compiler options for MDX compilation.
|
|
49
|
-
* @returns A new MDXRenderer class extended with the provided context.
|
|
50
|
-
*/
|
|
51
|
-
export declare function createMDXRenderer(compilerOptions: CompileOptions): typeof MDXRenderer;
|
|
52
|
-
export {};
|
package/src/mdx-renderer.js
CHANGED
|
@@ -5,12 +5,9 @@ import { rapidhash } from "@ecopages/core/hash";
|
|
|
5
5
|
class MDXRenderer extends IntegrationRenderer {
|
|
6
6
|
name = PLUGIN_NAME;
|
|
7
7
|
compilerOptions;
|
|
8
|
-
constructor({
|
|
9
|
-
compilerOptions,
|
|
10
|
-
...options
|
|
11
|
-
}) {
|
|
8
|
+
constructor({ mdxConfig, ...options }) {
|
|
12
9
|
super(options);
|
|
13
|
-
this.compilerOptions = compilerOptions
|
|
10
|
+
this.compilerOptions = mdxConfig?.compilerOptions ?? {};
|
|
14
11
|
}
|
|
15
12
|
async buildRouteRenderAssets(pagePath) {
|
|
16
13
|
const { default: pageComponent } = await this.importPageFile(pagePath);
|
|
@@ -108,17 +105,6 @@ class MDXRenderer extends IntegrationRenderer {
|
|
|
108
105
|
}
|
|
109
106
|
}
|
|
110
107
|
}
|
|
111
|
-
function createMDXRenderer(compilerOptions) {
|
|
112
|
-
return class extends MDXRenderer {
|
|
113
|
-
constructor(options) {
|
|
114
|
-
super({
|
|
115
|
-
...options,
|
|
116
|
-
compilerOptions
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
108
|
export {
|
|
122
|
-
MDXRenderer
|
|
123
|
-
createMDXRenderer
|
|
109
|
+
MDXRenderer
|
|
124
110
|
};
|
package/src/mdx.plugin.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import type { EcoBuildPlugin } from '@ecopages/core/build/build-types';
|
|
2
2
|
import type { EcoPagesElement } from '@ecopages/core';
|
|
3
|
-
import { IntegrationPlugin
|
|
4
|
-
import type { CompileOptions } from '@mdx-js/mdx';
|
|
3
|
+
import { IntegrationPlugin } from '@ecopages/core/plugins/integration-plugin';
|
|
5
4
|
import { MDXRenderer } from './mdx-renderer.js';
|
|
5
|
+
import type { MDXPluginConfig } from './mdx.types.js';
|
|
6
|
+
export type { MDXPluginConfig, MDXRendererConfig, MDXRendererOptions } from './mdx.types.js';
|
|
6
7
|
/**
|
|
7
8
|
* The name of the MDX plugin
|
|
8
9
|
*/
|
|
9
10
|
export declare const PLUGIN_NAME = "MDX";
|
|
10
|
-
export type MDXPluginConfig = Partial<Omit<IntegrationPluginConfig, 'name'>> & {
|
|
11
|
-
compilerOptions?: CompileOptions;
|
|
12
|
-
};
|
|
13
11
|
/**
|
|
14
12
|
* The MDX plugin class
|
|
15
13
|
* This plugin provides support for MDX components in Ecopages.
|
|
@@ -20,9 +18,12 @@ export type MDXPluginConfig = Partial<Omit<IntegrationPluginConfig, 'name'>> & {
|
|
|
20
18
|
*/
|
|
21
19
|
export declare class MDXPlugin extends IntegrationPlugin<EcoPagesElement> {
|
|
22
20
|
renderer: typeof MDXRenderer;
|
|
23
|
-
private compilerOptions;
|
|
21
|
+
private readonly compilerOptions;
|
|
24
22
|
private mdxLoaderPlugin;
|
|
25
23
|
constructor({ compilerOptions, ...options }?: MDXPluginConfig);
|
|
24
|
+
initializeRenderer(options?: {
|
|
25
|
+
rendererModules?: unknown;
|
|
26
|
+
}): MDXRenderer;
|
|
26
27
|
get plugins(): EcoBuildPlugin[];
|
|
27
28
|
/**
|
|
28
29
|
* Materializes the MDX loader once so config-time sealing and runtime setup
|
package/src/mdx.plugin.js
CHANGED
|
@@ -2,7 +2,7 @@ import { IntegrationPlugin } from "@ecopages/core/plugins/integration-plugin";
|
|
|
2
2
|
import { deepMerge } from "@ecopages/core/utils/deep-merge";
|
|
3
3
|
import { Logger } from "@ecopages/logger";
|
|
4
4
|
import { createMdxLoaderPlugin } from "./mdx-loader-plugin.js";
|
|
5
|
-
import {
|
|
5
|
+
import { MDXRenderer } from "./mdx-renderer.js";
|
|
6
6
|
const appLogger = new Logger("[MDXPlugin]");
|
|
7
7
|
const PLUGIN_NAME = "MDX";
|
|
8
8
|
const defaultOptions = {
|
|
@@ -25,7 +25,7 @@ function splitMarkdownExtensions(extensions) {
|
|
|
25
25
|
return { mdExtensions, mdxExtensions };
|
|
26
26
|
}
|
|
27
27
|
class MDXPlugin extends IntegrationPlugin {
|
|
28
|
-
renderer;
|
|
28
|
+
renderer = MDXRenderer;
|
|
29
29
|
compilerOptions;
|
|
30
30
|
mdxLoaderPlugin;
|
|
31
31
|
constructor({ compilerOptions, ...options } = { extensions: [".mdx"] }) {
|
|
@@ -50,9 +50,17 @@ class MDXPlugin extends IntegrationPlugin {
|
|
|
50
50
|
);
|
|
51
51
|
}
|
|
52
52
|
this.compilerOptions = finalCompilerOptions;
|
|
53
|
-
this.renderer = createMDXRenderer(finalCompilerOptions);
|
|
54
53
|
appLogger.debug(`MDX plugin configured with jsxImportSource: ${jsxImportSource ?? "default"}`);
|
|
55
54
|
}
|
|
55
|
+
initializeRenderer(options) {
|
|
56
|
+
const renderer = new this.renderer({
|
|
57
|
+
...this.createRendererOptions(options),
|
|
58
|
+
mdxConfig: {
|
|
59
|
+
compilerOptions: this.compilerOptions
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return this.attachRendererRuntimeServices(renderer);
|
|
63
|
+
}
|
|
56
64
|
get plugins() {
|
|
57
65
|
if (this.mdxLoaderPlugin) {
|
|
58
66
|
return [this.mdxLoaderPlugin];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { EcoComponent, EcoComponentConfig, GetMetadata } from '@ecopages/core';
|
|
2
|
+
import type { EcoPagesAppConfig } from '@ecopages/core/internal-types';
|
|
3
|
+
import type { IntegrationPluginConfig } from '@ecopages/core/plugins/integration-plugin';
|
|
4
|
+
import type { AssetProcessingService, ProcessedAsset } from '@ecopages/core/services/asset-processing-service';
|
|
5
|
+
import type { CompileOptions } from '@mdx-js/mdx';
|
|
6
|
+
export type MDXPluginConfig = Partial<Omit<IntegrationPluginConfig, 'name'>> & {
|
|
7
|
+
compilerOptions?: CompileOptions;
|
|
8
|
+
};
|
|
9
|
+
export type MDXRendererConfig = {
|
|
10
|
+
compilerOptions?: CompileOptions;
|
|
11
|
+
};
|
|
12
|
+
export type MDXRendererOptions = {
|
|
13
|
+
appConfig: EcoPagesAppConfig;
|
|
14
|
+
assetProcessingService: AssetProcessingService;
|
|
15
|
+
resolvedIntegrationDependencies: ProcessedAsset[];
|
|
16
|
+
rendererModules?: unknown;
|
|
17
|
+
runtimeOrigin: string;
|
|
18
|
+
mdxConfig?: MDXRendererConfig;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A structure representing an MDX file.
|
|
22
|
+
*/
|
|
23
|
+
export type MDXFile = {
|
|
24
|
+
default: EcoComponent;
|
|
25
|
+
config?: EcoComponentConfig;
|
|
26
|
+
getMetadata: GetMetadata;
|
|
27
|
+
};
|
package/src/mdx.types.js
ADDED
|
File without changes
|