@ecopages/ecopages-jsx 0.2.0-beta.31 → 0.2.0-beta.32
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 +3 -3
- package/src/dev-transform/ecopages-jsx-dev-transform-contributor.d.ts +17 -0
- package/src/dev-transform/ecopages-jsx-dev-transform-contributor.js +21 -0
- package/src/eco-embed.js +8 -10
- package/src/ecopages-jsx-hmr-ownership.js +76 -52
- package/src/ecopages-jsx-hmr-strategy.d.ts +4 -21
- package/src/ecopages-jsx-hmr-strategy.js +60 -56
- package/src/ecopages-jsx-mdx.js +63 -75
- package/src/ecopages-jsx-radiant-ssr-policy.js +104 -97
- package/src/ecopages-jsx-render-session.js +75 -71
- package/src/ecopages-jsx-renderer.js +270 -273
- package/src/ecopages-jsx.constants.js +7 -4
- package/src/ecopages-jsx.plugin.d.ts +1 -1
- package/src/ecopages-jsx.plugin.js +160 -152
- package/src/ecopages-jsx.types.js +1 -0
- package/src/page-owned-content-script-grouping.js +56 -50
- package/src/radiant-registered-script-ssr-invalidation.d.ts +1 -1
- package/src/radiant-registered-script-ssr-invalidation.js +43 -32
- package/src/resolve-radiant-install-hydrator.js +3 -7
|
@@ -1,163 +1,171 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { IntegrationPlugin, } from '@ecopages/core/plugins/integration-plugin';
|
|
2
|
+
import { AssetFactory } from '@ecopages/core/services/asset-processing-service';
|
|
3
|
+
import { ECOPAGES_JSX_PLUGIN_NAME } from './ecopages-jsx.constants.js';
|
|
4
|
+
import { RADIANT_INSTALL_HYDRATOR_FILEPATH } from './resolve-radiant-install-hydrator.js';
|
|
5
|
+
import { appendMdxExtensions, createMdxLoaderPlugin, registerBunMdxPlugin, resolveMdxCompilerOptions, } from './ecopages-jsx-mdx.js';
|
|
6
|
+
import { EcopagesJsxRenderer } from './ecopages-jsx-renderer.js';
|
|
7
|
+
import { EcopagesJsxHmrStrategy } from './ecopages-jsx-hmr-strategy.js';
|
|
8
|
+
import { EcopagesJsxDevTransformContributor } from './dev-transform/ecopages-jsx-dev-transform-contributor.js';
|
|
9
|
+
import { assignPageOwnedContentScriptGroupedBundles } from './page-owned-content-script-grouping.js';
|
|
10
|
+
import { invalidateRadiantRegisteredScriptSsrRegistration } from './radiant-registered-script-ssr-invalidation.js';
|
|
11
|
+
const RADIANT_HYDRATOR_SCRIPT_ID = 'ecopages-jsx-radiant-hydrator';
|
|
12
|
+
/**
|
|
13
|
+
* Resolves user-facing plugin options into a fully-defaulted internal config.
|
|
14
|
+
*
|
|
15
|
+
* Defaults:
|
|
16
|
+
* - `extensions`: `['.tsx']`
|
|
17
|
+
* - `radiant`: `true`
|
|
18
|
+
* - `mdx.enabled`: `false`
|
|
19
|
+
* - `mdx.extensions`: `['.mdx']`
|
|
20
|
+
*/
|
|
18
21
|
const resolvePluginOptions = (options) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
const { extensions: userExtensions, radiant, mdx, ...baseConfig } = options ?? {};
|
|
23
|
+
const extensions = [...(userExtensions ?? ['.tsx'])];
|
|
24
|
+
const mdxExtensions = mdx?.extensions ?? ['.mdx'];
|
|
25
|
+
const mdxEnabled = mdx?.enabled ?? false;
|
|
26
|
+
if (mdxEnabled) {
|
|
27
|
+
appendMdxExtensions(extensions, mdxExtensions);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
...baseConfig,
|
|
31
|
+
extensions,
|
|
32
|
+
includeRadiant: radiant ?? true,
|
|
33
|
+
mdxEnabled,
|
|
34
|
+
mdxExtensions,
|
|
35
|
+
mdxCompilerOptions: mdxEnabled && mdx ? resolveMdxCompilerOptions(mdx) : undefined,
|
|
36
|
+
};
|
|
34
37
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
/** JSX integration plugin for Ecopages, supporting `.tsx` templates and optional Radiant web components. */
|
|
39
|
+
export class EcopagesJsxPlugin extends IntegrationPlugin {
|
|
40
|
+
renderer = EcopagesJsxRenderer;
|
|
41
|
+
includeRadiant;
|
|
42
|
+
mdxEnabled;
|
|
43
|
+
mdxCompilerOptions;
|
|
44
|
+
mdxExtensions;
|
|
45
|
+
mdxLoaderPlugin;
|
|
46
|
+
/** Returns the build plugins required by the JSX integration. */
|
|
47
|
+
get plugins() {
|
|
48
|
+
return [this.mdxLoaderPlugin].filter((plugin) => plugin !== undefined);
|
|
49
|
+
}
|
|
50
|
+
/** Creates the renderer instance with the resolved JSX integration runtime options. */
|
|
51
|
+
initializeRenderer(options) {
|
|
52
|
+
return this.attachRendererRuntimeServices(new this.renderer({
|
|
53
|
+
...this.createRendererOptions(options),
|
|
54
|
+
jsxConfig: {
|
|
55
|
+
mdxExtensions: this.mdxExtensions,
|
|
56
|
+
radiantSsrEnabled: this.includeRadiant,
|
|
57
|
+
},
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
constructor(options) {
|
|
61
|
+
const config = resolvePluginOptions(options);
|
|
62
|
+
const { extensions, includeRadiant, mdxEnabled, mdxExtensions, mdxCompilerOptions, ...baseConfig } = config;
|
|
63
|
+
super({
|
|
64
|
+
name: ECOPAGES_JSX_PLUGIN_NAME,
|
|
65
|
+
extensions,
|
|
66
|
+
jsxImportSource: '@ecopages/jsx',
|
|
67
|
+
...baseConfig,
|
|
68
|
+
});
|
|
69
|
+
this.includeRadiant = includeRadiant;
|
|
70
|
+
this.mdxEnabled = mdxEnabled;
|
|
71
|
+
this.mdxExtensions = mdxExtensions;
|
|
72
|
+
this.mdxCompilerOptions = mdxCompilerOptions;
|
|
73
|
+
if (this.includeRadiant) {
|
|
74
|
+
this.integrationDependencies.unshift(...this.getDependencies());
|
|
54
75
|
}
|
|
55
|
-
})
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
constructor(options) {
|
|
59
|
-
const config = resolvePluginOptions(options);
|
|
60
|
-
const { extensions, includeRadiant, mdxEnabled, mdxExtensions, mdxCompilerOptions, ...baseConfig } = config;
|
|
61
|
-
super({
|
|
62
|
-
name: ECOPAGES_JSX_PLUGIN_NAME,
|
|
63
|
-
extensions,
|
|
64
|
-
jsxImportSource: "@ecopages/jsx",
|
|
65
|
-
...baseConfig
|
|
66
|
-
});
|
|
67
|
-
this.includeRadiant = includeRadiant;
|
|
68
|
-
this.mdxEnabled = mdxEnabled;
|
|
69
|
-
this.mdxExtensions = mdxExtensions;
|
|
70
|
-
this.mdxCompilerOptions = mdxCompilerOptions;
|
|
71
|
-
if (this.includeRadiant) {
|
|
72
|
-
this.integrationDependencies.unshift(...this.getDependencies());
|
|
73
76
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
getDependencies() {
|
|
78
|
+
return [
|
|
79
|
+
AssetFactory.createNodeModuleScript({
|
|
80
|
+
position: 'head',
|
|
81
|
+
importPath: RADIANT_INSTALL_HYDRATOR_FILEPATH,
|
|
82
|
+
bundle: false,
|
|
83
|
+
attributes: {
|
|
84
|
+
'data-eco-script-id': RADIANT_HYDRATOR_SCRIPT_ID,
|
|
85
|
+
},
|
|
86
|
+
}),
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
/** Ensures MDX build hooks are ready before Ecopages collects contributions. */
|
|
90
|
+
async prepareBuildContributions() {
|
|
91
|
+
this.ensureMdxLoaderPlugin();
|
|
92
|
+
}
|
|
93
|
+
/** Assigns grouped-build metadata for page-owned JSX content scripts. */
|
|
94
|
+
prepareAssetDependencies(dependencies) {
|
|
95
|
+
return assignPageOwnedContentScriptGroupedBundles(dependencies);
|
|
96
|
+
}
|
|
97
|
+
/** Registers JSX HMR strategy, dev-transform plugins, and Radiant SSR invalidation hooks. */
|
|
98
|
+
setHmrManager(hmrManager) {
|
|
99
|
+
super.setHmrManager(hmrManager);
|
|
100
|
+
const strategy = this.getHmrStrategy();
|
|
101
|
+
if (strategy) {
|
|
102
|
+
hmrManager.registerDevTransformContributor(new EcopagesJsxDevTransformContributor({
|
|
103
|
+
strategy: strategy,
|
|
104
|
+
getMdxLoaderPlugin: () => this.mdxLoaderPlugin,
|
|
105
|
+
}));
|
|
83
106
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
/** Assigns grouped-build metadata for page-owned JSX content scripts. */
|
|
92
|
-
prepareAssetDependencies(dependencies) {
|
|
93
|
-
return assignPageOwnedContentScriptGroupedBundles(dependencies);
|
|
94
|
-
}
|
|
95
|
-
/** Registers JSX HMR strategy and Radiant SSR invalidation hooks. */
|
|
96
|
-
setHmrManager(hmrManager) {
|
|
97
|
-
super.setHmrManager(hmrManager);
|
|
98
|
-
if (!this.includeRadiant || !this.appConfig) {
|
|
99
|
-
return;
|
|
107
|
+
if (!this.includeRadiant || !this.appConfig) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const runtime = this.appConfig.runtime ?? {};
|
|
111
|
+
this.appConfig.runtime = runtime;
|
|
112
|
+
runtime.registeredScriptEntrypointChangeHandlers ??= [];
|
|
113
|
+
runtime.registeredScriptEntrypointChangeHandlers.push(invalidateRadiantRegisteredScriptSsrRegistration);
|
|
100
114
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Returns the JSX-integration HMR strategy.
|
|
117
|
+
*
|
|
118
|
+
* @remarks
|
|
119
|
+
* The strategy handles `layout-update` broadcasts for page sources, layout
|
|
120
|
+
* sources, and any component file in the active render tree. It defers
|
|
121
|
+
* registered script entrypoints to the generic JS strategy and includes /
|
|
122
|
+
* explicit server views to `ServerRenderedTemplateHmrStrategy`.
|
|
123
|
+
*/
|
|
124
|
+
getHmrStrategy() {
|
|
125
|
+
if (!this.hmrManager || !this.appConfig) {
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
const context = this.hmrManager.getDefaultContext();
|
|
129
|
+
const absolutePaths = this.appConfig.absolutePaths;
|
|
130
|
+
return new EcopagesJsxHmrStrategy({
|
|
131
|
+
getRegisteredEntrypoints: context.getRegisteredEntrypoints,
|
|
132
|
+
getSrcDir: context.getSrcDir,
|
|
133
|
+
getPagesDir: context.getPagesDir,
|
|
134
|
+
getLayoutsDir: context.getLayoutsDir,
|
|
135
|
+
getIncludesDir: () => absolutePaths.includesDir,
|
|
136
|
+
getTemplateExtensions: () => this.extensions,
|
|
137
|
+
});
|
|
118
138
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Registers MDX tooling and completes the base integration setup.
|
|
132
|
-
*/
|
|
133
|
-
async setup() {
|
|
134
|
-
this.ensureMdxLoaderPlugin();
|
|
135
|
-
if (typeof Bun !== "undefined" && this.mdxEnabled && this.mdxCompilerOptions) {
|
|
136
|
-
await this.registerMdxBunPlugin();
|
|
139
|
+
/**
|
|
140
|
+
* Registers MDX tooling and completes the base integration setup.
|
|
141
|
+
*/
|
|
142
|
+
async setup() {
|
|
143
|
+
this.ensureMdxLoaderPlugin();
|
|
144
|
+
if (typeof Bun !== 'undefined' && this.mdxEnabled && this.mdxCompilerOptions) {
|
|
145
|
+
await this.registerMdxBunPlugin();
|
|
146
|
+
}
|
|
147
|
+
await super.setup();
|
|
137
148
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
149
|
+
ensureMdxLoaderPlugin() {
|
|
150
|
+
if (!this.mdxEnabled || !this.mdxCompilerOptions || this.mdxLoaderPlugin) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
this.mdxLoaderPlugin = createMdxLoaderPlugin(this.mdxCompilerOptions, this.mdxExtensions);
|
|
143
154
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
+
/**
|
|
156
|
+
* Registers Bun's MDX loader at runtime setup time.
|
|
157
|
+
*
|
|
158
|
+
* Build-time contribution collection may run where Bun is absent, so
|
|
159
|
+
* this hook stays isolated from manifest preparation.
|
|
160
|
+
*/
|
|
161
|
+
async registerMdxBunPlugin() {
|
|
162
|
+
if (typeof Bun === 'undefined' || !this.mdxCompilerOptions) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
await registerBunMdxPlugin(this.mdxCompilerOptions, this.mdxExtensions);
|
|
155
166
|
}
|
|
156
|
-
await registerBunMdxPlugin(this.mdxCompilerOptions, this.mdxExtensions);
|
|
157
|
-
}
|
|
158
167
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
};
|
|
168
|
+
/**
|
|
169
|
+
* Creates the JSX integration plugin with resolved defaults.
|
|
170
|
+
*/
|
|
171
|
+
export const ecopagesJsxPlugin = (options) => new EcopagesJsxPlugin(options);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,57 +1,63 @@
|
|
|
1
|
-
import { rapidhash } from
|
|
2
|
-
import { ECOPAGES_JSX_PLUGIN_NAME } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { rapidhash } from '@ecopages/core/utils/hash';
|
|
2
|
+
import { ECOPAGES_JSX_PLUGIN_NAME } from './ecopages-jsx.constants.js';
|
|
3
|
+
/** Shared grouped-build id prefix for page-owned content scripts. */
|
|
4
|
+
const PAGE_OWNED_CONTENT_SCRIPT_BUNDLE_PREFIX = 'ecopages';
|
|
5
|
+
/** Returns the stable grouped-build id for one integration's page-owned content scripts. */
|
|
6
|
+
export function createPageOwnedContentScriptBundleId(integrationName) {
|
|
7
|
+
return `${PAGE_OWNED_CONTENT_SCRIPT_BUNDLE_PREFIX}-${integrationName}-page-content-scripts`;
|
|
6
8
|
}
|
|
7
9
|
function isPageOwnedGroupableContentScript(dep) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
if (dep.kind !== 'script' || dep.source !== 'content' || dep.inline) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
if (dep.excludeFromHtml) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (dep.groupedBundle?.id) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (dep.packageRole === 'keep-separate' || dep.packageRole === 'runtime' || dep.packageRole === 'dynamic-chunk') {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
21
23
|
}
|
|
22
24
|
function createPageOwnedGroupedEntryName(dep, usedEntryNames) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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;
|
|
25
|
+
const baseName = dep.name ?? `script-${rapidhash(dep.content).toString(16)}`;
|
|
26
|
+
if (!usedEntryNames.has(baseName)) {
|
|
27
|
+
usedEntryNames.add(baseName);
|
|
28
|
+
return baseName;
|
|
29
|
+
}
|
|
30
|
+
let suffix = 2;
|
|
31
|
+
let candidate = `${baseName}-${suffix}`;
|
|
32
|
+
while (usedEntryNames.has(candidate)) {
|
|
33
|
+
suffix += 1;
|
|
34
|
+
candidate = `${baseName}-${suffix}`;
|
|
43
35
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
36
|
+
usedEntryNames.add(candidate);
|
|
37
|
+
return candidate;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Tags page-owned content scripts in one dependency batch with a shared grouped-build id.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* Lazy hydration entries (`excludeFromHtml`), component file scripts, and integration runtime
|
|
44
|
+
* assets stay ungrouped. Integrations that already assign a grouped id (for example React
|
|
45
|
+
* Router pages) are left unchanged.
|
|
46
|
+
*/
|
|
47
|
+
export function assignPageOwnedContentScriptGroupedBundles(dependencies) {
|
|
48
|
+
const bundleId = createPageOwnedContentScriptBundleId(ECOPAGES_JSX_PLUGIN_NAME);
|
|
49
|
+
const usedEntryNames = new Set();
|
|
50
|
+
for (const dependency of dependencies) {
|
|
51
|
+
if (!isPageOwnedGroupableContentScript(dependency)) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
dependency.groupedBundle = {
|
|
55
|
+
id: bundleId,
|
|
56
|
+
entryName: createPageOwnedGroupedEntryName(dependency, usedEntryNames),
|
|
57
|
+
};
|
|
58
|
+
if (dependency.bundle === false) {
|
|
59
|
+
dependency.bundle = true;
|
|
60
|
+
}
|
|
50
61
|
}
|
|
51
|
-
|
|
52
|
-
return dependencies;
|
|
62
|
+
return dependencies;
|
|
53
63
|
}
|
|
54
|
-
export {
|
|
55
|
-
assignPageOwnedContentScriptGroupedBundles,
|
|
56
|
-
createPageOwnedContentScriptBundleId
|
|
57
|
-
};
|
|
@@ -15,4 +15,4 @@ export declare function clearRadiantCustomElementDefinition(tagName: string): vo
|
|
|
15
15
|
/**
|
|
16
16
|
* Clears the SSR custom-element registry entry for one registered Radiant script module.
|
|
17
17
|
*/
|
|
18
|
-
export declare function invalidateRadiantRegisteredScriptSsrRegistration(scriptPath: string):
|
|
18
|
+
export declare function invalidateRadiantRegisteredScriptSsrRegistration(scriptPath: string): boolean;
|
|
@@ -1,36 +1,47 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
const CUSTOM_ELEMENT_TAG_PATTERN = /@customElement\s*\(\s*['"`]([^'"`]+)['"`]/u;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Reads the custom-element tag name from a registered script module source file.
|
|
5
|
+
*/
|
|
6
|
+
export function resolveRadiantCustomElementTag(scriptPath) {
|
|
7
|
+
if (!existsSync(scriptPath)) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
const content = readFileSync(scriptPath, 'utf8');
|
|
11
|
+
const match = content.match(CUSTOM_ELEMENT_TAG_PATTERN);
|
|
12
|
+
return match?.[1];
|
|
10
13
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Removes one custom-element definition from the active runtime registry.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Radiant's `@customElement` decorator and the SSR light-DOM shim both skip
|
|
19
|
+
* re-registration when a tag is already defined. During dev, server requests
|
|
20
|
+
* reuse the same process-global registry, so script edits would otherwise keep
|
|
21
|
+
* serving stale SSR markup until a full dev-server restart.
|
|
22
|
+
*/
|
|
23
|
+
export function clearRadiantCustomElementDefinition(tagName) {
|
|
24
|
+
const registry = globalThis.customElements;
|
|
25
|
+
if (!registry) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (typeof registry.delete === 'function') {
|
|
29
|
+
registry.delete(tagName);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const definitions = registry.definitions;
|
|
33
|
+
if (definitions instanceof Map && definitions.has(tagName)) {
|
|
34
|
+
definitions.delete(tagName);
|
|
35
|
+
}
|
|
24
36
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Clears the SSR custom-element registry entry for one registered Radiant script module.
|
|
39
|
+
*/
|
|
40
|
+
export function invalidateRadiantRegisteredScriptSsrRegistration(scriptPath) {
|
|
41
|
+
const tagName = resolveRadiantCustomElementTag(scriptPath);
|
|
42
|
+
if (!tagName) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
clearRadiantCustomElementDefinition(tagName);
|
|
46
|
+
return true;
|
|
31
47
|
}
|
|
32
|
-
export {
|
|
33
|
-
clearRadiantCustomElementDefinition,
|
|
34
|
-
invalidateRadiantRegisteredScriptSsrRegistration,
|
|
35
|
-
resolveRadiantCustomElementTag
|
|
36
|
-
};
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { fileURLToPath } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
);
|
|
5
|
-
export {
|
|
6
|
-
RADIANT_INSTALL_HYDRATOR_FILEPATH
|
|
7
|
-
};
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
/** Absolute path to `@ecopages/radiant/client/install-hydrator` from this integration package. */
|
|
3
|
+
export const RADIANT_INSTALL_HYDRATOR_FILEPATH = fileURLToPath(import.meta.resolve('@ecopages/radiant/client/install-hydrator'));
|