@ecopages/ecopages-jsx 0.2.0-beta.1 → 0.2.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/ecopages-jsx",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.10",
|
|
4
4
|
"description": "JSX integration plugin for Ecopages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecopages",
|
|
@@ -27,15 +27,16 @@
|
|
|
27
27
|
},
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|
|
30
|
-
"url": "https://github.com/ecopages/ecopages.git",
|
|
30
|
+
"url": "git+https://github.com/ecopages/ecopages.git",
|
|
31
31
|
"directory": "packages/integrations/ecopages-jsx"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"@ecopages/mdx-core": "0.2.0-beta.10",
|
|
34
35
|
"@mdx-js/mdx": "^3.1.1",
|
|
35
36
|
"vfile": "^6.0.3"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
38
|
-
"@ecopages/core": "0.2.0-beta.
|
|
39
|
+
"@ecopages/core": "0.2.0-beta.10",
|
|
39
40
|
"@ecopages/jsx": "0.3.0-alpha.25",
|
|
40
41
|
"@ecopages/radiant": "0.3.0-alpha.25"
|
|
41
42
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CompileOptions } from '@mdx-js/mdx';
|
|
2
2
|
import type { EcoComponent, EcoComponentConfig, EcoFunctionComponent, EcoPageFile, GetMetadata } from '@ecopages/core';
|
|
3
3
|
import type { EcoBuildPlugin } from '@ecopages/core/plugins/integration-plugin';
|
|
4
|
+
import { appendMdxExtensions, createMdxExtensionFilter } from '@ecopages/mdx-core';
|
|
4
5
|
import type { JsxRenderable } from '@ecopages/jsx';
|
|
5
6
|
import type { EcopagesJsxMdxCompileOptions, EcopagesJsxMdxOptions } from './ecopages-jsx.types.js';
|
|
6
7
|
export type ResolvedMdxCompileOptions = EcopagesJsxMdxCompileOptions & Pick<CompileOptions, 'jsxImportSource' | 'jsxRuntime'>;
|
|
@@ -10,10 +11,7 @@ export type EcopagesJsxMdxPageModule = EcoPageFile<{
|
|
|
10
11
|
layout?: EcoComponent;
|
|
11
12
|
getMetadata?: GetMetadata;
|
|
12
13
|
}>;
|
|
13
|
-
export
|
|
14
|
-
allowQueryString?: boolean;
|
|
15
|
-
}) => RegExp;
|
|
16
|
-
export declare const appendMdxExtensions: (target: string[], mdxExtensions: string[]) => void;
|
|
14
|
+
export { appendMdxExtensions, createMdxExtensionFilter };
|
|
17
15
|
export declare const resolveMdxCompilerOptions: (mdxOptions: EcopagesJsxMdxOptions) => ResolvedMdxCompileOptions;
|
|
18
16
|
export declare const createMdxLoaderPlugin: (compilerOptions: ResolvedMdxCompileOptions, extensions: string[]) => EcoBuildPlugin;
|
|
19
17
|
export declare const registerBunMdxPlugin: (compilerOptions: ResolvedMdxCompileOptions, extensions: string[]) => Promise<void>;
|
package/src/ecopages-jsx-mdx.js
CHANGED
|
@@ -1,62 +1,27 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
2
|
import { rapidhash } from "@ecopages/core/hash";
|
|
3
|
+
import {
|
|
4
|
+
appendMdxExtensions,
|
|
5
|
+
createMdxExtensionFilter,
|
|
6
|
+
createMdxLoaderPlugin as createMdxLoaderPluginCore,
|
|
7
|
+
resolveMdxCompilerOptions as resolveMdxCompilerOptionsCore
|
|
8
|
+
} from "@ecopages/mdx-core";
|
|
4
9
|
import { VFile } from "vfile";
|
|
5
10
|
import { ECOPAGES_JSX_PLUGIN_NAME } from "./ecopages-jsx.constants.js";
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return merged.length > 0 ? merged : void 0;
|
|
10
|
-
};
|
|
11
|
-
const createMdxExtensionFilter = (extensions, options) => {
|
|
12
|
-
const escaped = extensions.map(escapeRegex);
|
|
13
|
-
const suffix = options?.allowQueryString ? "(\\?.*)?$" : "$";
|
|
14
|
-
return new RegExp(`(${escaped.join("|")})${suffix}`);
|
|
15
|
-
};
|
|
16
|
-
const appendMdxExtensions = (target, mdxExtensions) => {
|
|
17
|
-
for (const ext of mdxExtensions) {
|
|
18
|
-
if (!target.includes(ext)) {
|
|
19
|
-
target.push(ext);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const resolveMdxCompilerOptions = (mdxOptions) => {
|
|
24
|
-
const { compilerOptions, remarkPlugins, rehypePlugins, recmaPlugins } = mdxOptions;
|
|
25
|
-
const resolved = {
|
|
11
|
+
const resolveMdxCompilerOptions = (mdxOptions) => resolveMdxCompilerOptionsCore(mdxOptions, {
|
|
12
|
+
jsxImportSource: "@ecopages/jsx",
|
|
13
|
+
defaults: {
|
|
26
14
|
format: "detect",
|
|
27
|
-
outputFormat: "program"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (mergedRehype) resolved.rehypePlugins = mergedRehype;
|
|
38
|
-
if (mergedRecma) resolved.recmaPlugins = mergedRecma;
|
|
39
|
-
return resolved;
|
|
40
|
-
};
|
|
41
|
-
const createMdxLoaderPlugin = (compilerOptions, extensions) => {
|
|
42
|
-
const filter = createMdxExtensionFilter(extensions, { allowQueryString: true });
|
|
43
|
-
return {
|
|
44
|
-
name: "ecopages-jsx-mdx-loader",
|
|
45
|
-
setup(build) {
|
|
46
|
-
build.onLoad({ filter }, async (args) => {
|
|
47
|
-
const { compile } = await import("@mdx-js/mdx");
|
|
48
|
-
const filePath = args.path.includes("?") ? args.path.split("?")[0] : args.path;
|
|
49
|
-
const source = await readFile(filePath, "utf-8");
|
|
50
|
-
const compiled = await compile(new VFile({ value: source, path: filePath }), compilerOptions);
|
|
51
|
-
return {
|
|
52
|
-
contents: String(compiled.value),
|
|
53
|
-
loader: "js",
|
|
54
|
-
resolveDir: path.dirname(filePath)
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
};
|
|
15
|
+
outputFormat: "program"
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const createMdxLoaderPlugin = (compilerOptions, extensions) => createMdxLoaderPluginCore({
|
|
19
|
+
name: "ecopages-jsx-mdx-loader",
|
|
20
|
+
compilerOptions,
|
|
21
|
+
extensions,
|
|
22
|
+
includeSourceMap: false,
|
|
23
|
+
loader: "js"
|
|
24
|
+
});
|
|
60
25
|
const registerBunMdxPlugin = async (compilerOptions, extensions) => {
|
|
61
26
|
if (typeof Bun === "undefined") {
|
|
62
27
|
return;
|
|
@@ -22,13 +22,6 @@ export declare class EcopagesJsxRenderer extends IntegrationRenderer<JsxRenderab
|
|
|
22
22
|
* elements and queued foreign subtrees contribute assets to the same frame.
|
|
23
23
|
*/
|
|
24
24
|
private renderQueuedForeignSubtreeChildren;
|
|
25
|
-
/**
|
|
26
|
-
* Resolves queued foreign subtrees after JSX has been stringified.
|
|
27
|
-
*
|
|
28
|
-
* JSX content needs one extra render pass because child foreign subtrees may emit
|
|
29
|
-
* additional browser assets while also replacing placeholder tokens.
|
|
30
|
-
*/
|
|
31
|
-
private resolveOwnedForeignSubtreeHtml;
|
|
32
25
|
protected createForeignChildRuntime(options: {
|
|
33
26
|
renderInput: ComponentRenderInput;
|
|
34
27
|
rendererCache: Map<string, IntegrationRenderer<any>>;
|
|
@@ -61,24 +61,6 @@ class EcopagesJsxRenderer extends IntegrationRenderer {
|
|
|
61
61
|
html
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Resolves queued foreign subtrees after JSX has been stringified.
|
|
66
|
-
*
|
|
67
|
-
* JSX content needs one extra render pass because child foreign subtrees may emit
|
|
68
|
-
* additional browser assets while also replacing placeholder tokens.
|
|
69
|
-
*/
|
|
70
|
-
async resolveOwnedForeignSubtreeHtml(html, runtimeContext) {
|
|
71
|
-
return this.foreignSubtreeExecutionService.resolveQueuedHtml({
|
|
72
|
-
currentIntegrationName: this.name,
|
|
73
|
-
html,
|
|
74
|
-
runtimeContext,
|
|
75
|
-
queueLabel: "Ecopages JSX",
|
|
76
|
-
getOwningRenderer: (integrationName, rendererCache) => this.getIntegrationRendererForName(integrationName, rendererCache),
|
|
77
|
-
applyAttributesToFirstElement: (resolvedHtml, attributes) => this.htmlTransformer.applyAttributesToFirstElement(resolvedHtml, attributes),
|
|
78
|
-
dedupeProcessedAssets: (assets) => this.htmlTransformer.dedupeProcessedAssets(assets),
|
|
79
|
-
renderQueuedChildren: async (children, _runtimeContext, queuedResolutionsByToken, resolveToken) => this.renderQueuedForeignSubtreeChildren(children, queuedResolutionsByToken, resolveToken)
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
64
|
createForeignChildRuntime(options) {
|
|
83
65
|
const runtime = super.createForeignChildRuntime(options);
|
|
84
66
|
const interceptForeignChild = runtime.interceptForeignChild;
|
|
@@ -165,11 +147,11 @@ class EcopagesJsxRenderer extends IntegrationRenderer {
|
|
|
165
147
|
};
|
|
166
148
|
const content = await this.withCustomElementRenderHook(() => component(componentProps));
|
|
167
149
|
const rendered = await this.renderJsx(content);
|
|
168
|
-
const queuedForeignSubtreeResolution = await this.
|
|
150
|
+
const queuedForeignSubtreeResolution = await this.resolveQueuedForeignSubtreeHtml(
|
|
169
151
|
rendered.html,
|
|
170
|
-
this.getQueuedForeignSubtreeResolutionContext(
|
|
171
|
-
|
|
172
|
-
|
|
152
|
+
this.getQueuedForeignSubtreeResolutionContext(input),
|
|
153
|
+
(children, _runtimeContext, queuedResolutionsByToken, resolveToken) => this.renderQueuedForeignSubtreeChildren(children, queuedResolutionsByToken, resolveToken),
|
|
154
|
+
"Ecopages JSX"
|
|
173
155
|
);
|
|
174
156
|
const componentAssets = input.component.config?.dependencies && typeof this.assetProcessingService?.processDependencies === "function" ? await this.processComponentDependencies([input.component]) : [];
|
|
175
157
|
const assets = this.htmlTransformer.dedupeProcessedAssets([
|