@bleedingdev/modern-js-app-tools-extensions 3.8.3-ultramodern.2
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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/cjs/cloudflare/artifacts.js +127 -0
- package/dist/cjs/cloudflare/constants.js +141 -0
- package/dist/cjs/cloudflare/delivery-unit.js +161 -0
- package/dist/cjs/cloudflare/i18n-worker.js +135 -0
- package/dist/cjs/cloudflare/index.js +156 -0
- package/dist/cjs/cloudflare/security-policies.js +205 -0
- package/dist/cjs/cloudflare/types.js +18 -0
- package/dist/cjs/cloudflare/utils.js +66 -0
- package/dist/cjs/cloudflare/worker-manifest.js +239 -0
- package/dist/cjs/cloudflare/wrangler-config.js +205 -0
- package/dist/cjs/cloudflare-builder.js +394 -0
- package/dist/cjs/cloudflare-output-contract.js +108 -0
- package/dist/cjs/cloudflare-output-plan.js +93 -0
- package/dist/cjs/cloudflare-output-verifier/identity.js +92 -0
- package/dist/cjs/cloudflare-output-verifier/index.js +188 -0
- package/dist/cjs/cloudflare-output-verifier/issues.js +54 -0
- package/dist/cjs/cloudflare-output-verifier/manifest.js +89 -0
- package/dist/cjs/cloudflare-output-verifier/mutation-policy.js +151 -0
- package/dist/cjs/cloudflare-output-verifier/worker-bundles.js +378 -0
- package/dist/cjs/config.js +18 -0
- package/dist/cjs/css-extract-runtime-plugin.js +74 -0
- package/dist/cjs/index.js +125 -0
- package/dist/cjs/read-template.js +56 -0
- package/dist/cjs/release-envelope/canonical.js +68 -0
- package/dist/cjs/release-envelope/framework-output.js +649 -0
- package/dist/cjs/release-envelope/index.js +399 -0
- package/dist/cjs/release-envelope/plugin.js +102 -0
- package/dist/cjs/release-envelope/types.js +51 -0
- package/dist/cjs/release-identity.js +110 -0
- package/dist/cjs/templates/cloudflare-entry.001-bootstrap-security.mjs +251 -0
- package/dist/cjs/templates/cloudflare-entry.002-assets-routes.mjs +191 -0
- package/dist/cjs/templates/cloudflare-entry.003-i18n-locales.mjs +514 -0
- package/dist/cjs/templates/cloudflare-entry.004-rendering-css.mjs +1194 -0
- package/dist/cjs/templates/cloudflare-entry.005-worker-dispatch.mjs +421 -0
- package/dist/cjs/templates/cloudflare-entry.006-fetch-handler.mjs +93 -0
- package/dist/cjs/templates/cloudflare-worker-fs-promises.mjs +11 -0
- package/dist/cjs/templates/cloudflare-worker-loadable-server.mjs +281 -0
- package/dist/cjs/templates/cloudflare-worker-mf-ssr-runtime-plugin.mjs +14 -0
- package/dist/cjs/templates/cloudflare-worker-path.mjs +98 -0
- package/dist/esm/cloudflare/artifacts.mjs +64 -0
- package/dist/esm/cloudflare/constants.mjs +34 -0
- package/dist/esm/cloudflare/delivery-unit.mjs +110 -0
- package/dist/esm/cloudflare/i18n-worker.mjs +97 -0
- package/dist/esm/cloudflare/index.mjs +108 -0
- package/dist/esm/cloudflare/security-policies.mjs +167 -0
- package/dist/esm/cloudflare/types.mjs +0 -0
- package/dist/esm/cloudflare/utils.mjs +12 -0
- package/dist/esm/cloudflare/worker-manifest.mjs +179 -0
- package/dist/esm/cloudflare/wrangler-config.mjs +151 -0
- package/dist/esm/cloudflare-builder.mjs +327 -0
- package/dist/esm/cloudflare-output-contract.mjs +31 -0
- package/dist/esm/cloudflare-output-plan.mjs +45 -0
- package/dist/esm/cloudflare-output-verifier/identity.mjs +54 -0
- package/dist/esm/cloudflare-output-verifier/index.mjs +133 -0
- package/dist/esm/cloudflare-output-verifier/issues.mjs +10 -0
- package/dist/esm/cloudflare-output-verifier/manifest.mjs +51 -0
- package/dist/esm/cloudflare-output-verifier/mutation-policy.mjs +99 -0
- package/dist/esm/cloudflare-output-verifier/worker-bundles.mjs +313 -0
- package/dist/esm/config.mjs +0 -0
- package/dist/esm/css-extract-runtime-plugin.mjs +32 -0
- package/dist/esm/index.mjs +10 -0
- package/dist/esm/read-template.mjs +5 -0
- package/dist/esm/release-envelope/canonical.mjs +21 -0
- package/dist/esm/release-envelope/framework-output.mjs +573 -0
- package/dist/esm/release-envelope/index.mjs +335 -0
- package/dist/esm/release-envelope/plugin.mjs +54 -0
- package/dist/esm/release-envelope/types.mjs +7 -0
- package/dist/esm/release-identity.mjs +66 -0
- package/dist/esm/templates/cloudflare-entry.001-bootstrap-security.mjs +251 -0
- package/dist/esm/templates/cloudflare-entry.002-assets-routes.mjs +191 -0
- package/dist/esm/templates/cloudflare-entry.003-i18n-locales.mjs +514 -0
- package/dist/esm/templates/cloudflare-entry.004-rendering-css.mjs +1194 -0
- package/dist/esm/templates/cloudflare-entry.005-worker-dispatch.mjs +421 -0
- package/dist/esm/templates/cloudflare-entry.006-fetch-handler.mjs +93 -0
- package/dist/esm/templates/cloudflare-worker-fs-promises.mjs +11 -0
- package/dist/esm/templates/cloudflare-worker-loadable-server.mjs +281 -0
- package/dist/esm/templates/cloudflare-worker-mf-ssr-runtime-plugin.mjs +14 -0
- package/dist/esm/templates/cloudflare-worker-path.mjs +98 -0
- package/dist/esm-node/cloudflare/artifacts.mjs +65 -0
- package/dist/esm-node/cloudflare/constants.mjs +35 -0
- package/dist/esm-node/cloudflare/delivery-unit.mjs +111 -0
- package/dist/esm-node/cloudflare/i18n-worker.mjs +98 -0
- package/dist/esm-node/cloudflare/index.mjs +109 -0
- package/dist/esm-node/cloudflare/security-policies.mjs +168 -0
- package/dist/esm-node/cloudflare/types.mjs +1 -0
- package/dist/esm-node/cloudflare/utils.mjs +13 -0
- package/dist/esm-node/cloudflare/worker-manifest.mjs +180 -0
- package/dist/esm-node/cloudflare/wrangler-config.mjs +152 -0
- package/dist/esm-node/cloudflare-builder.mjs +328 -0
- package/dist/esm-node/cloudflare-output-contract.mjs +32 -0
- package/dist/esm-node/cloudflare-output-plan.mjs +46 -0
- package/dist/esm-node/cloudflare-output-verifier/identity.mjs +55 -0
- package/dist/esm-node/cloudflare-output-verifier/index.mjs +134 -0
- package/dist/esm-node/cloudflare-output-verifier/issues.mjs +11 -0
- package/dist/esm-node/cloudflare-output-verifier/manifest.mjs +52 -0
- package/dist/esm-node/cloudflare-output-verifier/mutation-policy.mjs +100 -0
- package/dist/esm-node/cloudflare-output-verifier/worker-bundles.mjs +314 -0
- package/dist/esm-node/config.mjs +1 -0
- package/dist/esm-node/css-extract-runtime-plugin.mjs +33 -0
- package/dist/esm-node/index.mjs +11 -0
- package/dist/esm-node/read-template.mjs +9 -0
- package/dist/esm-node/release-envelope/canonical.mjs +22 -0
- package/dist/esm-node/release-envelope/framework-output.mjs +574 -0
- package/dist/esm-node/release-envelope/index.mjs +336 -0
- package/dist/esm-node/release-envelope/plugin.mjs +55 -0
- package/dist/esm-node/release-envelope/types.mjs +8 -0
- package/dist/esm-node/release-identity.mjs +67 -0
- package/dist/esm-node/templates/cloudflare-entry.001-bootstrap-security.mjs +251 -0
- package/dist/esm-node/templates/cloudflare-entry.002-assets-routes.mjs +191 -0
- package/dist/esm-node/templates/cloudflare-entry.003-i18n-locales.mjs +514 -0
- package/dist/esm-node/templates/cloudflare-entry.004-rendering-css.mjs +1194 -0
- package/dist/esm-node/templates/cloudflare-entry.005-worker-dispatch.mjs +421 -0
- package/dist/esm-node/templates/cloudflare-entry.006-fetch-handler.mjs +93 -0
- package/dist/esm-node/templates/cloudflare-worker-fs-promises.mjs +11 -0
- package/dist/esm-node/templates/cloudflare-worker-loadable-server.mjs +281 -0
- package/dist/esm-node/templates/cloudflare-worker-mf-ssr-runtime-plugin.mjs +14 -0
- package/dist/esm-node/templates/cloudflare-worker-path.mjs +98 -0
- package/dist/types/cloudflare/artifacts.d.ts +15 -0
- package/dist/types/cloudflare/constants.d.ts +24 -0
- package/dist/types/cloudflare/delivery-unit.d.ts +23 -0
- package/dist/types/cloudflare/i18n-worker.d.ts +22 -0
- package/dist/types/cloudflare/index.d.ts +2 -0
- package/dist/types/cloudflare/security-policies.d.ts +52 -0
- package/dist/types/cloudflare/types.d.ts +28 -0
- package/dist/types/cloudflare/utils.d.ts +6 -0
- package/dist/types/cloudflare/worker-manifest.d.ts +149 -0
- package/dist/types/cloudflare/wrangler-config.d.ts +51 -0
- package/dist/types/cloudflare-builder.d.ts +59 -0
- package/dist/types/cloudflare-output-contract.d.ts +14 -0
- package/dist/types/cloudflare-output-plan.d.ts +34 -0
- package/dist/types/cloudflare-output-verifier/identity.d.ts +8 -0
- package/dist/types/cloudflare-output-verifier/index.d.ts +18 -0
- package/dist/types/cloudflare-output-verifier/issues.d.ts +14 -0
- package/dist/types/cloudflare-output-verifier/manifest.d.ts +2 -0
- package/dist/types/cloudflare-output-verifier/mutation-policy.d.ts +14 -0
- package/dist/types/cloudflare-output-verifier/worker-bundles.d.ts +20 -0
- package/dist/types/config.d.ts +175 -0
- package/dist/types/css-extract-runtime-plugin.d.ts +6 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/read-template.d.ts +2 -0
- package/dist/types/release-envelope/canonical.d.ts +5 -0
- package/dist/types/release-envelope/framework-output.d.ts +32 -0
- package/dist/types/release-envelope/index.d.ts +6 -0
- package/dist/types/release-envelope/plugin.d.ts +30 -0
- package/dist/types/release-envelope/types.d.ts +62 -0
- package/dist/types/release-identity.d.ts +16 -0
- package/dist/types/templates/cloudflare-entry.001-bootstrap-security.d.mts +1 -0
- package/dist/types/templates/cloudflare-entry.002-assets-routes.d.mts +1 -0
- package/dist/types/templates/cloudflare-entry.003-i18n-locales.d.mts +1 -0
- package/dist/types/templates/cloudflare-entry.004-rendering-css.d.mts +1 -0
- package/dist/types/templates/cloudflare-entry.005-worker-dispatch.d.mts +1 -0
- package/dist/types/templates/cloudflare-entry.006-fetch-handler.d.mts +4 -0
- package/dist/types/templates/cloudflare-worker-fs-promises.d.mts +5 -0
- package/dist/types/templates/cloudflare-worker-loadable-server.d.mts +48 -0
- package/dist/types/templates/cloudflare-worker-mf-ssr-runtime-plugin.d.mts +13 -0
- package/dist/types/templates/cloudflare-worker-path.d.mts +21 -0
- package/package.json +131 -0
- package/src/cloudflare/artifacts.ts +165 -0
- package/src/cloudflare/constants.ts +50 -0
- package/src/cloudflare/delivery-unit.ts +195 -0
- package/src/cloudflare/i18n-worker.ts +197 -0
- package/src/cloudflare/index.ts +259 -0
- package/src/cloudflare/security-policies.ts +194 -0
- package/src/cloudflare/types.ts +33 -0
- package/src/cloudflare/utils.ts +40 -0
- package/src/cloudflare/worker-manifest.ts +313 -0
- package/src/cloudflare/wrangler-config.ts +338 -0
- package/src/cloudflare-builder.ts +653 -0
- package/src/cloudflare-output-contract.ts +30 -0
- package/src/cloudflare-output-plan.ts +108 -0
- package/src/cloudflare-output-verifier/identity.ts +87 -0
- package/src/cloudflare-output-verifier/index.ts +277 -0
- package/src/cloudflare-output-verifier/issues.ts +54 -0
- package/src/cloudflare-output-verifier/manifest.ts +76 -0
- package/src/cloudflare-output-verifier/mutation-policy.ts +159 -0
- package/src/cloudflare-output-verifier/worker-bundles.ts +664 -0
- package/src/config.ts +196 -0
- package/src/css-extract-runtime-plugin.ts +70 -0
- package/src/index.ts +10 -0
- package/src/read-template.ts +8 -0
- package/src/release-envelope/canonical.ts +58 -0
- package/src/release-envelope/framework-output.ts +1121 -0
- package/src/release-envelope/index.ts +656 -0
- package/src/release-envelope/plugin.ts +125 -0
- package/src/release-envelope/types.ts +83 -0
- package/src/release-identity.ts +134 -0
- package/src/templates/cloudflare-entry.001-bootstrap-security.mjs +251 -0
- package/src/templates/cloudflare-entry.002-assets-routes.mjs +191 -0
- package/src/templates/cloudflare-entry.003-i18n-locales.mjs +514 -0
- package/src/templates/cloudflare-entry.004-rendering-css.mjs +1194 -0
- package/src/templates/cloudflare-entry.005-worker-dispatch.mjs +421 -0
- package/src/templates/cloudflare-entry.006-fetch-handler.mjs +93 -0
- package/src/templates/cloudflare-worker-fs-promises.mjs +11 -0
- package/src/templates/cloudflare-worker-loadable-server.mjs +281 -0
- package/src/templates/cloudflare-worker-mf-ssr-runtime-plugin.mjs +14 -0
- package/src/templates/cloudflare-worker-path.mjs +98 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import loadableComponent from '@loadable/component';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
const internals =
|
|
5
|
+
loadableComponent?.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED || {};
|
|
6
|
+
const LoadableContext = internals.Context || React.createContext(null);
|
|
7
|
+
const getRequiredChunkKey =
|
|
8
|
+
internals.getRequiredChunkKey ||
|
|
9
|
+
(namespace => `${namespace}__LOADABLE_REQUIRED_CHUNKS__`);
|
|
10
|
+
|
|
11
|
+
const scriptExtensions = new Set(['.js', '.mjs']);
|
|
12
|
+
const styleExtensions = new Set(['.css']);
|
|
13
|
+
|
|
14
|
+
function uniqByUrl(assets) {
|
|
15
|
+
const seen = new Set();
|
|
16
|
+
|
|
17
|
+
return assets.filter(asset => {
|
|
18
|
+
if (seen.has(asset.url)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
seen.add(asset.url);
|
|
23
|
+
return true;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function extname(filePath) {
|
|
28
|
+
const basename = String(filePath).split('/').pop() || '';
|
|
29
|
+
const index = basename.lastIndexOf('.');
|
|
30
|
+
|
|
31
|
+
return index > 0 ? basename.slice(index) : '';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isAutomaticPublicPath(publicPath) {
|
|
35
|
+
return publicPath === 'auto' || publicPath === 'auto/';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function joinUrl(publicPath, filename) {
|
|
39
|
+
const base =
|
|
40
|
+
!publicPath || isAutomaticPublicPath(publicPath) ? '/' : publicPath;
|
|
41
|
+
|
|
42
|
+
return `${base.replace(/\/+$/u, '')}/${String(filename).replace(/^\/+/u, '')}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function extraPropsToString(extraProps = {}) {
|
|
46
|
+
return Object.entries(extraProps)
|
|
47
|
+
.filter(([, value]) => value !== undefined && value !== false)
|
|
48
|
+
.map(([key, value]) => (value === true ? ` ${key}` : ` ${key}="${value}"`))
|
|
49
|
+
.join('');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function assetScriptType(filename) {
|
|
53
|
+
const extension = extname(filename);
|
|
54
|
+
|
|
55
|
+
if (scriptExtensions.has(extension)) {
|
|
56
|
+
return 'script';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (styleExtensions.has(extension)) {
|
|
60
|
+
return 'style';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getAssetName(asset) {
|
|
65
|
+
return typeof asset === 'object' && asset?.name ? asset.name : asset;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getAssetIntegrity(asset) {
|
|
69
|
+
return typeof asset === 'object' && asset?.integrity ? asset.integrity : null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getChunkGroupAssets(chunkGroup) {
|
|
73
|
+
const assets = chunkGroup?.assets;
|
|
74
|
+
|
|
75
|
+
if (Array.isArray(assets)) {
|
|
76
|
+
return assets;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (assets && typeof assets === 'object') {
|
|
80
|
+
return [...(assets.js || []), ...(assets.css || [])];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getChunkGroupChildAssets(chunkGroup, type) {
|
|
87
|
+
const childAssets = chunkGroup?.childAssets?.[type];
|
|
88
|
+
|
|
89
|
+
return Array.isArray(childAssets) ? childAssets : [];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function chunkIncludesJs(chunkInfo) {
|
|
93
|
+
return (chunkInfo?.files || []).some(file =>
|
|
94
|
+
scriptExtensions.has(extname(file)),
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function ChunkExtractorManager({ extractor, children }) {
|
|
99
|
+
return React.createElement(
|
|
100
|
+
LoadableContext.Provider,
|
|
101
|
+
{ value: extractor },
|
|
102
|
+
children,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export class ChunkExtractor {
|
|
107
|
+
constructor({
|
|
108
|
+
stats,
|
|
109
|
+
entrypoints = ['main'],
|
|
110
|
+
namespace = '',
|
|
111
|
+
outputPath = '/',
|
|
112
|
+
publicPath,
|
|
113
|
+
} = {}) {
|
|
114
|
+
this.namespace = namespace;
|
|
115
|
+
this.stats = stats || {};
|
|
116
|
+
const configuredPublicPath = publicPath || this.stats.publicPath;
|
|
117
|
+
this.publicPath =
|
|
118
|
+
!configuredPublicPath || isAutomaticPublicPath(configuredPublicPath)
|
|
119
|
+
? '/'
|
|
120
|
+
: configuredPublicPath;
|
|
121
|
+
this.outputPath = outputPath || this.stats.outputPath || '/';
|
|
122
|
+
this.entrypoints = Array.isArray(entrypoints) ? entrypoints : [entrypoints];
|
|
123
|
+
this.chunks = [];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
addChunk(chunk) {
|
|
127
|
+
if (!this.chunks.includes(chunk)) {
|
|
128
|
+
this.chunks.push(chunk);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
collectChunks(app) {
|
|
133
|
+
return React.createElement(ChunkExtractorManager, { extractor: this }, app);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
getChunkGroup(chunk) {
|
|
137
|
+
return (
|
|
138
|
+
this.stats.namedChunkGroups?.[chunk] || {
|
|
139
|
+
assets: [],
|
|
140
|
+
childAssets: {},
|
|
141
|
+
chunks: [],
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
getChunkInfo(chunkId) {
|
|
147
|
+
return (this.stats.chunks || []).find(chunk => chunk.id === chunkId);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
resolvePublicUrl(filename) {
|
|
151
|
+
return joinUrl(this.publicPath, filename);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
createChunkAsset({ filename, chunk, type, linkType }) {
|
|
155
|
+
const resolvedFilename = getAssetName(filename);
|
|
156
|
+
const scriptType = assetScriptType(resolvedFilename);
|
|
157
|
+
|
|
158
|
+
if (!scriptType) {
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
filename: resolvedFilename,
|
|
164
|
+
integrity: getAssetIntegrity(filename),
|
|
165
|
+
scriptType,
|
|
166
|
+
chunk,
|
|
167
|
+
url: this.resolvePublicUrl(resolvedFilename),
|
|
168
|
+
path: String(resolvedFilename).replace(/^\/+/u, ''),
|
|
169
|
+
type,
|
|
170
|
+
linkType,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
getChunkAssets(chunks) {
|
|
175
|
+
const one = chunk =>
|
|
176
|
+
getChunkGroupAssets(this.getChunkGroup(chunk))
|
|
177
|
+
.map(filename =>
|
|
178
|
+
this.createChunkAsset({
|
|
179
|
+
filename,
|
|
180
|
+
chunk,
|
|
181
|
+
type: 'mainAsset',
|
|
182
|
+
linkType: 'preload',
|
|
183
|
+
}),
|
|
184
|
+
)
|
|
185
|
+
.filter(Boolean);
|
|
186
|
+
|
|
187
|
+
return Array.isArray(chunks) ? uniqByUrl(chunks.flatMap(one)) : one(chunks);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
getChunkChildAssets(chunks, type) {
|
|
191
|
+
const one = chunk =>
|
|
192
|
+
getChunkGroupChildAssets(this.getChunkGroup(chunk), type)
|
|
193
|
+
.map(filename =>
|
|
194
|
+
this.createChunkAsset({
|
|
195
|
+
filename,
|
|
196
|
+
chunk,
|
|
197
|
+
type: 'childAsset',
|
|
198
|
+
linkType: type,
|
|
199
|
+
}),
|
|
200
|
+
)
|
|
201
|
+
.filter(Boolean);
|
|
202
|
+
|
|
203
|
+
return Array.isArray(chunks) ? uniqByUrl(chunks.flatMap(one)) : one(chunks);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
getChunkDependencies(chunks) {
|
|
207
|
+
const one = chunk =>
|
|
208
|
+
(this.getChunkGroup(chunk).chunks || []).filter(chunkId =>
|
|
209
|
+
chunkIncludesJs(this.getChunkInfo(chunkId)),
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
return Array.isArray(chunks)
|
|
213
|
+
? [...new Set(chunks.flatMap(one))]
|
|
214
|
+
: one(chunks);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
getRequiredChunksScriptContent() {
|
|
218
|
+
return JSON.stringify(this.getChunkDependencies(this.chunks));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
getRequiredChunksNamesScriptContent() {
|
|
222
|
+
return JSON.stringify({ namedChunks: this.chunks });
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
getRequiredChunksScriptTag(extraProps = {}) {
|
|
226
|
+
const id = getRequiredChunkKey(this.namespace);
|
|
227
|
+
const props = `type="application/json"${extraPropsToString(extraProps)}`;
|
|
228
|
+
|
|
229
|
+
return [
|
|
230
|
+
`<script id="${id}" ${props}>${this.getRequiredChunksScriptContent()}</script>`,
|
|
231
|
+
`<script id="${id}_ext" ${props}>${this.getRequiredChunksNamesScriptContent()}</script>`,
|
|
232
|
+
].join('');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
getMainAssets(scriptType) {
|
|
236
|
+
const assets = this.getChunkAssets([...this.entrypoints, ...this.chunks]);
|
|
237
|
+
|
|
238
|
+
return scriptType
|
|
239
|
+
? assets.filter(asset => asset.scriptType === scriptType)
|
|
240
|
+
: assets;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
getScriptTags(extraProps = {}) {
|
|
244
|
+
const scripts = this.getMainAssets('script').map(
|
|
245
|
+
asset =>
|
|
246
|
+
`<script async data-chunk="${asset.chunk}" src="${asset.url}"${extraPropsToString(extraProps)}></script>`,
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
return [this.getRequiredChunksScriptTag(extraProps), ...scripts].join('');
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
getStyleTags(extraProps = {}) {
|
|
253
|
+
return this.getMainAssets('style')
|
|
254
|
+
.map(
|
|
255
|
+
asset =>
|
|
256
|
+
`<link data-chunk="${asset.chunk}" rel="stylesheet" href="${asset.url}"${extraPropsToString(extraProps)}>`,
|
|
257
|
+
)
|
|
258
|
+
.join('');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
getLinkTags(extraProps = {}) {
|
|
262
|
+
const assets = [
|
|
263
|
+
...this.getMainAssets(),
|
|
264
|
+
...this.getChunkChildAssets(
|
|
265
|
+
[...this.entrypoints, ...this.chunks],
|
|
266
|
+
'preload',
|
|
267
|
+
),
|
|
268
|
+
...this.getChunkChildAssets(
|
|
269
|
+
[...this.entrypoints, ...this.chunks],
|
|
270
|
+
'prefetch',
|
|
271
|
+
),
|
|
272
|
+
];
|
|
273
|
+
|
|
274
|
+
return uniqByUrl(assets)
|
|
275
|
+
.map(
|
|
276
|
+
asset =>
|
|
277
|
+
`<link data-chunk="${asset.chunk}" rel="${asset.linkType}" as="${asset.scriptType}" href="${asset.url}"${extraPropsToString(extraProps)}>`,
|
|
278
|
+
)
|
|
279
|
+
.join('');
|
|
280
|
+
}
|
|
281
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workerd cannot initialize Module Federation's Node-oriented SSR data-fetch
|
|
3
|
+
* runtime. Cloudflare workers do not load native MF remotes, so retain the
|
|
4
|
+
* runtime-plugin contract without installing its server data-fetch hooks.
|
|
5
|
+
*/
|
|
6
|
+
export const injectDataFetchFunctionPlugin = () => ({
|
|
7
|
+
name: '@module-federation/inject-data-fetch-function-plugin',
|
|
8
|
+
setup() {},
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const mfSSRDevPlugin = () => ({
|
|
12
|
+
name: '@module-federation/modern-js-v3',
|
|
13
|
+
setup() {},
|
|
14
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const trimSlashes = value => String(value).replace(/^\/+|\/+$/gu, '');
|
|
2
|
+
const normalizeSeparators = value => String(value).replace(/\\+/gu, '/');
|
|
3
|
+
|
|
4
|
+
export const sep = '/';
|
|
5
|
+
export const delimiter = ':';
|
|
6
|
+
|
|
7
|
+
export function isAbsolute(filePath) {
|
|
8
|
+
return normalizeSeparators(filePath).startsWith('/');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function normalize(filePath) {
|
|
12
|
+
const normalized = normalizeSeparators(filePath);
|
|
13
|
+
const absolute = isAbsolute(normalized);
|
|
14
|
+
const parts = [];
|
|
15
|
+
|
|
16
|
+
for (const part of normalized.split('/')) {
|
|
17
|
+
if (!part || part === '.') {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (part === '..') {
|
|
22
|
+
if (parts.length > 0 && parts[parts.length - 1] !== '..') {
|
|
23
|
+
parts.pop();
|
|
24
|
+
} else if (!absolute) {
|
|
25
|
+
parts.push(part);
|
|
26
|
+
}
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
parts.push(part);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const joined = parts.join('/');
|
|
34
|
+
|
|
35
|
+
if (absolute) {
|
|
36
|
+
return joined ? `/${joined}` : '/';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return joined || '.';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function join(...segments) {
|
|
43
|
+
const joined = segments
|
|
44
|
+
.map(normalizeSeparators)
|
|
45
|
+
.filter(Boolean)
|
|
46
|
+
.map((segment, index) => (index === 0 ? segment : trimSlashes(segment)))
|
|
47
|
+
.filter(Boolean)
|
|
48
|
+
.join('/');
|
|
49
|
+
|
|
50
|
+
return joined ? normalize(joined) : '.';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function resolve(...segments) {
|
|
54
|
+
const joined = join(...segments);
|
|
55
|
+
|
|
56
|
+
return joined.startsWith('/') ? joined : `/${joined}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function dirname(filePath) {
|
|
60
|
+
const normalized = normalizeSeparators(filePath).replace(/\/+$/u, '');
|
|
61
|
+
const index = normalized.lastIndexOf('/');
|
|
62
|
+
|
|
63
|
+
if (index <= 0) {
|
|
64
|
+
return '/';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return normalized.slice(0, index);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function basename(filePath, suffix = '') {
|
|
71
|
+
const normalized = normalizeSeparators(filePath).replace(/\/+$/u, '');
|
|
72
|
+
const base = normalized.slice(normalized.lastIndexOf('/') + 1);
|
|
73
|
+
|
|
74
|
+
return suffix && base.endsWith(suffix) ? base.slice(0, -suffix.length) : base;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function extname(filePath) {
|
|
78
|
+
const base = basename(filePath);
|
|
79
|
+
const index = base.lastIndexOf('.');
|
|
80
|
+
|
|
81
|
+
if (index <= 0) {
|
|
82
|
+
return '';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return base.slice(index);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export default {
|
|
89
|
+
basename,
|
|
90
|
+
delimiter,
|
|
91
|
+
dirname,
|
|
92
|
+
extname,
|
|
93
|
+
isAbsolute,
|
|
94
|
+
join,
|
|
95
|
+
normalize,
|
|
96
|
+
resolve,
|
|
97
|
+
sep,
|
|
98
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CloudflareModernConfig } from './types';
|
|
2
|
+
export declare const getCloudflareArtifacts: (modernConfig: CloudflareModernConfig) => {
|
|
3
|
+
from: string;
|
|
4
|
+
to: string;
|
|
5
|
+
index: number;
|
|
6
|
+
}[];
|
|
7
|
+
export declare const getCloudflarePublicAssets: (modernConfig: CloudflareModernConfig) => {
|
|
8
|
+
from: string;
|
|
9
|
+
to: string;
|
|
10
|
+
index: number;
|
|
11
|
+
}[];
|
|
12
|
+
export declare const copyCloudflareArtifacts: (appDirectory: string, outputDirectory: string, artifacts: ReturnType<typeof getCloudflareArtifacts>) => Promise<void>;
|
|
13
|
+
export declare const copyCloudflarePublicAssets: (appDirectory: string, publicDirectory: string, publicAssets: ReturnType<typeof getCloudflarePublicAssets>) => Promise<void>;
|
|
14
|
+
export declare const copyCloudflareD1Migrations: (appDirectory: string, outputDirectory: string, modernConfig: CloudflareModernConfig) => Promise<void>;
|
|
15
|
+
export declare const readRouteSpec: (outputDirectory: string) => Promise<any>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CLOUDFLARE_RUNTIME_TYPE, CLOUDFLARE_WORKER_BUNDLE_FORMAT } from '../cloudflare-output-contract';
|
|
2
|
+
export { CLOUDFLARE_RUNTIME_TYPE, CLOUDFLARE_WORKER_BUNDLE_FORMAT };
|
|
3
|
+
export declare const WORKER_ENTRY = "server/index.mjs";
|
|
4
|
+
export declare const WORKER_MANIFEST = "server/modern-worker-manifest.json";
|
|
5
|
+
export declare const WRANGLER_CONFIG_FILE = "wrangler.json";
|
|
6
|
+
export declare const OUTPUT_PACKAGE_FILE = "package.json";
|
|
7
|
+
export declare const ASSETS_BINDING = "ASSETS";
|
|
8
|
+
export declare const ROUTE_SPEC_FILE = "route.json";
|
|
9
|
+
export declare const ROUTE_SPEC_OUTPUT = "server/route.json";
|
|
10
|
+
export declare const LOADABLE_STATS_FILE = "loadable-stats.json";
|
|
11
|
+
export declare const ROUTE_MANIFEST_FILE = "routes-manifest.json";
|
|
12
|
+
export declare const PUBLIC_ASSETS_DIRECTORY = "public";
|
|
13
|
+
export declare const WORKER_BUNDLE_DIRECTORY = "worker";
|
|
14
|
+
export declare const SERVER_BUNDLE_DIRECTORY = "bundles";
|
|
15
|
+
export declare const SERVER_OUTPUT_DIRECTORY = "server";
|
|
16
|
+
export declare const DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES: readonly ['api', 'shared'];
|
|
17
|
+
export declare const BFF_EFFECT_WORKER_ENTRY = "worker/__modern_bff_effect.js";
|
|
18
|
+
export declare const BFF_EFFECT_WORKER_DISPATCHER_EXPORT = "__modern_create_effect_bff_dispatcher";
|
|
19
|
+
export declare const EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE = "Ensure the Effect API entry exists at api/index.ts or bff.effect.entry, and import Cloudflare edge handlers from @modern-js/plugin-bff/effect-edge instead of lambda/Hono server helpers.";
|
|
20
|
+
export declare const DEFAULT_COMPATIBILITY_DATE = "2026-06-02";
|
|
21
|
+
export declare const COMPATIBILITY_DATE_PATTERN: RegExp;
|
|
22
|
+
export declare const REQUIRED_COMPATIBILITY_FLAGS: readonly ["nodejs_compat", "global_fetch_strictly_public"];
|
|
23
|
+
export declare const RESERVED_ARTIFACT_DESTINATION_FILES: Set<string>;
|
|
24
|
+
export declare const RESERVED_ARTIFACT_DESTINATION_DIRECTORIES: Set<string>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type DeliveryUnitIdentity } from '@modern-js/utils/universal';
|
|
2
|
+
export type DeliveryUnitStamp = DeliveryUnitIdentity & {
|
|
3
|
+
surfaces: {
|
|
4
|
+
ui?: DeliveryUnitIdentity & {
|
|
5
|
+
surface: 'ui';
|
|
6
|
+
};
|
|
7
|
+
api?: DeliveryUnitIdentity & {
|
|
8
|
+
surface: 'api';
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the delivery-unit record declared for this app by the workspace
|
|
14
|
+
* compact config (`.modernjs/ultramodern.json`). This is the topology source
|
|
15
|
+
* of truth the Cloudflare worker snapshot is verified against.
|
|
16
|
+
*/
|
|
17
|
+
export declare const resolveTopologyDeliveryUnit: (appDirectory: string) => Promise<DeliveryUnitStamp | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* Resolve the delivery-unit identity actually bundled into the worker by
|
|
20
|
+
* parsing the generated `shared/ultramodern-build.ts` module. This is the
|
|
21
|
+
* worker snapshot / declared surface source that gets stamped into the manifest.
|
|
22
|
+
*/
|
|
23
|
+
export declare const resolveWorkerDeliveryUnitStamp: (appDirectory: string) => Promise<DeliveryUnitStamp | undefined>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CloudflareAppContext } from './types';
|
|
2
|
+
type WorkerI18nDetection = {
|
|
3
|
+
order: string[];
|
|
4
|
+
lookupQuerystring: string;
|
|
5
|
+
lookupCookie: string;
|
|
6
|
+
lookupHeader: string;
|
|
7
|
+
};
|
|
8
|
+
type WorkerI18nEntry = {
|
|
9
|
+
i18nextDetector: boolean;
|
|
10
|
+
languages: string[];
|
|
11
|
+
fallbackLanguage: string;
|
|
12
|
+
detection: WorkerI18nDetection;
|
|
13
|
+
ignoreRedirectRoutes: string[];
|
|
14
|
+
staticRoutePrefixes: string[];
|
|
15
|
+
localisedUrls?: Record<string, Record<string, string>>;
|
|
16
|
+
};
|
|
17
|
+
export declare const createI18nWorkerManifest: (routeSpec: {
|
|
18
|
+
routes: Array<Record<string, unknown>>;
|
|
19
|
+
}, appContext: CloudflareAppContext) => {
|
|
20
|
+
entries: Record<string, WorkerI18nEntry>;
|
|
21
|
+
} | undefined;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { CloudflareModernConfig } from './types';
|
|
2
|
+
export declare const createCloudflareWorkerSecurityPolicy: (modernConfig: CloudflareModernConfig) => {
|
|
3
|
+
enabled: boolean;
|
|
4
|
+
cors: {
|
|
5
|
+
assets: boolean;
|
|
6
|
+
allowedOrigins: string[];
|
|
7
|
+
allowedMethods: string[];
|
|
8
|
+
allowedHeaders: string[];
|
|
9
|
+
reason: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
reason: string | undefined;
|
|
12
|
+
headers?: undefined;
|
|
13
|
+
contentSecurityPolicy?: undefined;
|
|
14
|
+
noindex?: undefined;
|
|
15
|
+
} | {
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
headers: {
|
|
18
|
+
referrerPolicy: string | false;
|
|
19
|
+
contentTypeOptions: "nosniff" | false;
|
|
20
|
+
permissionsPolicy: string | false;
|
|
21
|
+
};
|
|
22
|
+
contentSecurityPolicy: {
|
|
23
|
+
mode: "off";
|
|
24
|
+
directives: {};
|
|
25
|
+
reason: string | undefined;
|
|
26
|
+
} | {
|
|
27
|
+
mode: "enforce" | "report-only";
|
|
28
|
+
directives: {
|
|
29
|
+
[k: string]: string[];
|
|
30
|
+
};
|
|
31
|
+
reason: string | undefined;
|
|
32
|
+
};
|
|
33
|
+
noindex: {
|
|
34
|
+
workersDev: boolean;
|
|
35
|
+
localhost: boolean;
|
|
36
|
+
previewHostnames: never[];
|
|
37
|
+
reason?: undefined;
|
|
38
|
+
} | {
|
|
39
|
+
workersDev: boolean;
|
|
40
|
+
localhost: boolean;
|
|
41
|
+
previewHostnames: string[];
|
|
42
|
+
reason: string | undefined;
|
|
43
|
+
};
|
|
44
|
+
cors: {
|
|
45
|
+
assets: boolean;
|
|
46
|
+
allowedOrigins: string[];
|
|
47
|
+
allowedMethods: string[];
|
|
48
|
+
allowedHeaders: string[];
|
|
49
|
+
reason: string | undefined;
|
|
50
|
+
};
|
|
51
|
+
reason: string | undefined;
|
|
52
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { BffUserConfig } from '@modern-js/server-core';
|
|
2
|
+
import type { ServerPlugin } from '@modern-js/types';
|
|
3
|
+
import type { CloudflareDeployConfig } from '../config';
|
|
4
|
+
export interface CloudflareAppContext {
|
|
5
|
+
apiOnly: boolean;
|
|
6
|
+
appDirectory: string;
|
|
7
|
+
distDirectory: string;
|
|
8
|
+
serverPlugins: ServerPlugin[];
|
|
9
|
+
}
|
|
10
|
+
export interface CloudflareModernConfig {
|
|
11
|
+
bff?: BffUserConfig;
|
|
12
|
+
deploy?: CloudflareDeployConfig;
|
|
13
|
+
}
|
|
14
|
+
export interface CloudflarePresetApi {
|
|
15
|
+
isPluginExists(name: string): boolean;
|
|
16
|
+
}
|
|
17
|
+
export type CloudflareDeployPreset = {
|
|
18
|
+
prepare?: () => Promise<void>;
|
|
19
|
+
writeOutput?: () => Promise<void>;
|
|
20
|
+
genEntry?: () => Promise<void>;
|
|
21
|
+
end?: () => Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
export type CreateCloudflarePreset = (params: {
|
|
24
|
+
appContext: CloudflareAppContext;
|
|
25
|
+
modernConfig: CloudflareModernConfig;
|
|
26
|
+
api: CloudflarePresetApi;
|
|
27
|
+
needModernServer?: boolean;
|
|
28
|
+
}) => CloudflareDeployPreset;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { JsonValue } from '../config';
|
|
2
|
+
export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
|
|
3
|
+
export declare const normalizeRelativePath: (value: unknown, label: string, scope?: string, options?: {
|
|
4
|
+
allowRoot?: boolean;
|
|
5
|
+
}) => string;
|
|
6
|
+
export declare const isJsonRecord: (value: unknown) => value is Record<string, JsonValue>;
|