@ecopages/ecopages-jsx 0.2.0-beta.22 → 0.2.0-beta.24

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.22",
3
+ "version": "0.2.0-beta.24",
4
4
  "description": "JSX integration plugin for Ecopages",
5
5
  "keywords": [
6
6
  "ecopages",
@@ -31,13 +31,13 @@
31
31
  "directory": "packages/integrations/ecopages-jsx"
32
32
  },
33
33
  "dependencies": {
34
- "@ecopages/mdx": "0.2.0-beta.22",
34
+ "@ecopages/mdx": "0.2.0-beta.24",
35
35
  "@mdx-js/mdx": "^3.1.1",
36
36
  "vfile": "^6.0.3"
37
37
  },
38
38
  "peerDependencies": {
39
- "@ecopages/core": "0.2.0-beta.22",
40
- "@ecopages/jsx": "0.3.0-beta.0",
41
- "@ecopages/radiant": "0.3.0-beta.0"
39
+ "@ecopages/core": "0.2.0-beta.24",
40
+ "@ecopages/jsx": "0.3.0-beta.2",
41
+ "@ecopages/radiant": "0.3.0-beta.2"
42
42
  }
43
43
  }
@@ -1,4 +1,5 @@
1
1
  import { IntegrationPlugin, type EcoBuildPlugin } from '@ecopages/core/plugins/integration-plugin';
2
+ import { type AssetDefinition } from '@ecopages/core/services/asset-processing-service';
2
3
  import type { HmrStrategy } from '@ecopages/core/hmr/hmr-strategy';
3
4
  import type { IHmrManager } from '@ecopages/core';
4
5
  import type { JsxRenderable } from '@ecopages/jsx';
@@ -23,6 +24,8 @@ export declare class EcopagesJsxPlugin extends IntegrationPlugin<JsxRenderable>
23
24
  private getDependencies;
24
25
  /** Ensures MDX build hooks are ready before Ecopages collects contributions. */
25
26
  prepareBuildContributions(): Promise<void>;
27
+ /** Assigns grouped-build metadata for page-owned JSX content scripts. */
28
+ prepareAssetDependencies(dependencies: AssetDefinition[]): AssetDefinition[];
26
29
  /** Registers JSX HMR strategy and Radiant SSR invalidation hooks. */
27
30
  setHmrManager(hmrManager: IHmrManager): void;
28
31
  /**
@@ -12,6 +12,7 @@ import {
12
12
  } from "./ecopages-jsx-mdx.js";
13
13
  import { EcopagesJsxRenderer } from "./ecopages-jsx-renderer.js";
14
14
  import { EcopagesJsxHmrStrategy } from "./ecopages-jsx-hmr-strategy.js";
15
+ import { assignPageOwnedContentScriptGroupedBundles } from "./page-owned-content-script-grouping.js";
15
16
  import { invalidateRadiantRegisteredScriptSsrRegistration } from "./radiant-registered-script-ssr-invalidation.js";
16
17
  const RADIANT_HYDRATOR_SCRIPT_ID = "ecopages-jsx-radiant-hydrator";
17
18
  const resolvePluginOptions = (options) => {
@@ -87,6 +88,10 @@ class EcopagesJsxPlugin extends IntegrationPlugin {
87
88
  async prepareBuildContributions() {
88
89
  this.ensureMdxLoaderPlugin();
89
90
  }
91
+ /** Assigns grouped-build metadata for page-owned JSX content scripts. */
92
+ prepareAssetDependencies(dependencies) {
93
+ return assignPageOwnedContentScriptGroupedBundles(dependencies);
94
+ }
90
95
  /** Registers JSX HMR strategy and Radiant SSR invalidation hooks. */
91
96
  setHmrManager(hmrManager) {
92
97
  super.setHmrManager(hmrManager);
@@ -0,0 +1,12 @@
1
+ import type { AssetDefinition } from '@ecopages/core/services/asset-processing-service';
2
+ /** Returns the stable grouped-build id for one integration's page-owned content scripts. */
3
+ export declare function createPageOwnedContentScriptBundleId(integrationName: string): string;
4
+ /**
5
+ * Tags page-owned content scripts in one dependency batch with a shared grouped-build id.
6
+ *
7
+ * @remarks
8
+ * Lazy hydration entries (`excludeFromHtml`), component file scripts, and integration runtime
9
+ * assets stay ungrouped. Integrations that already assign a grouped id (for example React
10
+ * Router pages) are left unchanged.
11
+ */
12
+ export declare function assignPageOwnedContentScriptGroupedBundles(dependencies: AssetDefinition[]): AssetDefinition[];
@@ -0,0 +1,57 @@
1
+ import { rapidhash } from "@ecopages/core/utils/hash";
2
+ import { ECOPAGES_JSX_PLUGIN_NAME } from "./ecopages-jsx.constants.js";
3
+ const PAGE_OWNED_CONTENT_SCRIPT_BUNDLE_PREFIX = "ecopages";
4
+ function createPageOwnedContentScriptBundleId(integrationName) {
5
+ return `${PAGE_OWNED_CONTENT_SCRIPT_BUNDLE_PREFIX}-${integrationName}-page-content-scripts`;
6
+ }
7
+ function isPageOwnedGroupableContentScript(dep) {
8
+ if (dep.kind !== "script" || dep.source !== "content" || dep.inline) {
9
+ return false;
10
+ }
11
+ if (dep.excludeFromHtml) {
12
+ return false;
13
+ }
14
+ if (dep.groupedBundle?.id) {
15
+ return false;
16
+ }
17
+ if (dep.packageRole === "keep-separate" || dep.packageRole === "runtime" || dep.packageRole === "dynamic-chunk") {
18
+ return false;
19
+ }
20
+ return true;
21
+ }
22
+ function createPageOwnedGroupedEntryName(dep, usedEntryNames) {
23
+ const baseName = dep.name ?? `script-${rapidhash(dep.content).toString(16)}`;
24
+ if (!usedEntryNames.has(baseName)) {
25
+ usedEntryNames.add(baseName);
26
+ return baseName;
27
+ }
28
+ let suffix = 2;
29
+ let candidate = `${baseName}-${suffix}`;
30
+ while (usedEntryNames.has(candidate)) {
31
+ suffix += 1;
32
+ candidate = `${baseName}-${suffix}`;
33
+ }
34
+ usedEntryNames.add(candidate);
35
+ return candidate;
36
+ }
37
+ function assignPageOwnedContentScriptGroupedBundles(dependencies) {
38
+ const bundleId = createPageOwnedContentScriptBundleId(ECOPAGES_JSX_PLUGIN_NAME);
39
+ const usedEntryNames = /* @__PURE__ */ new Set();
40
+ for (const dependency of dependencies) {
41
+ if (!isPageOwnedGroupableContentScript(dependency)) {
42
+ continue;
43
+ }
44
+ dependency.groupedBundle = {
45
+ id: bundleId,
46
+ entryName: createPageOwnedGroupedEntryName(dependency, usedEntryNames)
47
+ };
48
+ if (dependency.bundle === false) {
49
+ dependency.bundle = true;
50
+ }
51
+ }
52
+ return dependencies;
53
+ }
54
+ export {
55
+ assignPageOwnedContentScriptGroupedBundles,
56
+ createPageOwnedContentScriptBundleId
57
+ };