@bleedingdev/modern-js-app-tools 3.2.0-ultramodern.12 → 3.2.0-ultramodern.121
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/bin/modern.js +0 -0
- package/dist/cjs/baseline.js +12 -50
- package/dist/cjs/builder/builder-rspack/index.js +9 -5
- package/dist/cjs/builder/generator/adapterCopy.js +9 -5
- package/dist/cjs/builder/generator/createBuilderProviderConfig.js +9 -5
- package/dist/cjs/builder/generator/createCopyPattern.js +9 -5
- package/dist/cjs/builder/generator/getBuilderEnvironments.js +199 -12
- package/dist/cjs/builder/generator/index.js +9 -5
- package/dist/cjs/builder/index.js +9 -5
- package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +50 -10
- package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +10 -6
- package/dist/cjs/builder/shared/builderPlugins/adapterPrecompress.js +9 -5
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +12 -6
- package/dist/cjs/builder/shared/builderPlugins/builderHooks.js +12 -8
- package/dist/cjs/builder/shared/builderPlugins/index.js +9 -5
- package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +9 -5
- package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +12 -8
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +9 -5
- package/dist/cjs/builder/shared/bundlerPlugins/index.js +9 -5
- package/dist/cjs/builder/shared/createCopyInfo.js +9 -5
- package/dist/cjs/builder/shared/index.js +9 -5
- package/dist/cjs/builder/shared/loaders/serverModuleLoader.js +12 -8
- package/dist/cjs/commands/build.js +9 -5
- package/dist/cjs/commands/deploy.js +9 -5
- package/dist/cjs/commands/dev.js +9 -5
- package/dist/cjs/commands/index.js +12 -11
- package/dist/cjs/commands/info.js +9 -5
- package/dist/cjs/commands/inspect.js +12 -8
- package/dist/cjs/commands/runtime.js +50 -13
- package/dist/cjs/commands/serve.js +9 -5
- package/dist/cjs/compat/hooks.js +9 -5
- package/dist/cjs/compat/index.js +9 -5
- package/dist/cjs/compat/utils.js +9 -5
- package/dist/cjs/config/default.js +9 -5
- package/dist/cjs/config/index.js +9 -5
- package/dist/cjs/config/initialize/index.js +9 -5
- package/dist/cjs/config/initialize/inits.js +9 -5
- package/dist/cjs/constants.js +13 -9
- package/dist/cjs/defineConfig.js +12 -8
- package/dist/cjs/esm/register-esm.js +12 -8
- package/dist/cjs/esm/ts-paths-loader.js +9 -5
- package/dist/cjs/index.js +22 -17
- package/dist/cjs/locale/en.js +12 -8
- package/dist/cjs/locale/index.js +9 -5
- package/dist/cjs/locale/zh.js +12 -8
- package/dist/cjs/plugins/analyze/constants.js +14 -10
- package/dist/cjs/plugins/analyze/getBundleEntry.js +9 -5
- package/dist/cjs/plugins/analyze/getFileSystemEntry.js +9 -5
- package/dist/cjs/plugins/analyze/getHtmlTemplate.js +9 -5
- package/dist/cjs/plugins/analyze/getServerRoutes.js +9 -5
- package/dist/cjs/plugins/analyze/index.js +9 -5
- package/dist/cjs/plugins/analyze/isDefaultExportFunction.js +9 -5
- package/dist/cjs/plugins/analyze/templates.js +12 -8
- package/dist/cjs/plugins/analyze/utils.js +9 -5
- package/dist/cjs/plugins/deploy/index.js +26 -11
- package/dist/cjs/plugins/deploy/platforms/cloudflare.js +400 -0
- package/dist/cjs/plugins/deploy/platforms/gh-pages.js +9 -5
- package/dist/cjs/plugins/deploy/platforms/netlify.js +9 -5
- package/dist/cjs/plugins/deploy/platforms/node.js +9 -5
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +563 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-worker-fs-promises.mjs +7 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-worker-loadable-server.mjs +185 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-worker-path.mjs +59 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +9 -5
- package/dist/cjs/plugins/deploy/utils/generator.js +9 -5
- package/dist/cjs/plugins/deploy/utils/index.js +19 -40
- package/dist/cjs/plugins/initialize/index.js +9 -5
- package/dist/cjs/plugins/serverBuild.js +9 -5
- package/dist/cjs/plugins/serverRuntime.js +12 -8
- package/dist/cjs/presetUltramodern.js +95 -7
- package/dist/cjs/rsbuild.js +55 -64
- package/dist/cjs/run/index.js +9 -5
- package/dist/cjs/types/config/cloudflareDeploy.js +18 -0
- package/dist/cjs/types/config/index.js +9 -5
- package/dist/cjs/types/config/precompress.js +18 -0
- package/dist/cjs/types/index.js +9 -5
- package/dist/cjs/ultramodern/designSystem.js +16 -12
- package/dist/cjs/utils/config.js +9 -5
- package/dist/cjs/utils/createServer.js +14 -10
- package/dist/cjs/utils/env.js +9 -5
- package/dist/cjs/utils/generateWatchFiles.js +9 -5
- package/dist/cjs/utils/getConfigFile.js +9 -5
- package/dist/cjs/utils/getSelectedEntries.js +9 -5
- package/dist/cjs/utils/initAppContext.js +9 -5
- package/dist/cjs/utils/loadPlugins.js +9 -5
- package/dist/cjs/utils/printInstructions.js +9 -5
- package/dist/cjs/utils/register.js +9 -5
- package/dist/cjs/utils/restart.js +9 -5
- package/dist/cjs/utils/routes.js +9 -5
- package/dist/esm/baseline.mjs +3 -45
- package/dist/esm/builder/generator/getBuilderEnvironments.mjs +180 -8
- package/dist/esm/builder/shared/builderPlugins/adapterBasic.mjs +41 -5
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.mjs +1 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +3 -1
- package/dist/esm/commands/index.mjs +2 -5
- package/dist/esm/commands/runtime.mjs +33 -3
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/plugins/deploy/index.mjs +10 -4
- package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +352 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +563 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-worker-fs-promises.mjs +7 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-worker-loadable-server.mjs +185 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-worker-path.mjs +59 -0
- package/dist/esm/plugins/deploy/utils/index.mjs +11 -36
- package/dist/esm/presetUltramodern.mjs +77 -3
- package/dist/esm/rsbuild.mjs +4 -8
- package/dist/esm/types/config/cloudflareDeploy.mjs +0 -0
- package/dist/esm/types/config/precompress.mjs +0 -0
- package/dist/esm-node/baseline.mjs +3 -45
- package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +185 -9
- package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.mjs +41 -5
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.mjs +1 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +3 -1
- package/dist/esm-node/commands/index.mjs +2 -5
- package/dist/esm-node/commands/runtime.mjs +33 -3
- package/dist/esm-node/index.mjs +2 -2
- package/dist/esm-node/plugins/deploy/index.mjs +10 -4
- package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +353 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +563 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-worker-fs-promises.mjs +7 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-worker-loadable-server.mjs +185 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-worker-path.mjs +59 -0
- package/dist/esm-node/plugins/deploy/utils/index.mjs +12 -36
- package/dist/esm-node/presetUltramodern.mjs +77 -3
- package/dist/esm-node/rsbuild.mjs +4 -8
- package/dist/esm-node/types/config/cloudflareDeploy.mjs +1 -0
- package/dist/esm-node/types/config/precompress.mjs +1 -0
- package/dist/types/baseline.d.ts +16 -46
- package/dist/types/builder/builder-rspack/index.d.ts +1 -1
- package/dist/types/builder/generator/index.d.ts +1 -1
- package/dist/types/builder/shared/createCopyInfo.d.ts +1 -1
- package/dist/types/commands/index.d.ts +1 -1
- package/dist/types/commands/inspect.d.ts +1 -1
- package/dist/types/commands/runtime.d.ts +1 -0
- package/dist/types/locale/en.d.ts +1 -1
- package/dist/types/locale/index.d.ts +89 -2
- package/dist/types/locale/zh.d.ts +1 -1
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +2 -2
- package/dist/types/plugins/analyze/utils.d.ts +1 -1
- package/dist/types/plugins/deploy/index.d.ts +4 -1
- package/dist/types/plugins/deploy/platforms/cloudflare.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.d.mts +4 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-worker-fs-promises.d.mts +5 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-worker-loadable-server.d.mts +48 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-worker-path.d.mts +21 -0
- package/dist/types/plugins/deploy/utils/generator.d.ts +2 -2
- package/dist/types/plugins/deploy/utils/index.d.ts +1 -1
- package/dist/types/presetUltramodern.d.ts +52 -2
- package/dist/types/rsbuild.d.ts +1 -1
- package/dist/types/run/index.d.ts +1 -1
- package/dist/types/types/config/cloudflareDeploy.d.ts +79 -0
- package/dist/types/types/config/deploy.d.ts +16 -14
- package/dist/types/types/config/output.d.ts +4 -20
- package/dist/types/types/config/precompress.d.ts +20 -0
- package/dist/types/utils/getConfigFile.d.ts +1 -1
- package/dist/types/utils/loadPlugins.d.ts +2 -2
- package/package.json +21 -22
- package/dist/esm/rslib-runtime.mjs +0 -18
- package/dist/esm-node/rslib-runtime.mjs +0 -19
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -24,9 +28,12 @@ var __webpack_require__ = {};
|
|
|
24
28
|
var __webpack_exports__ = {};
|
|
25
29
|
__webpack_require__.r(__webpack_exports__);
|
|
26
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
default: ()=>deploy
|
|
31
|
+
default: ()=>deploy,
|
|
32
|
+
getSupportedDeployTargets: ()=>getSupportedDeployTargets,
|
|
33
|
+
resolveDeployTarget: ()=>resolveDeployTarget
|
|
28
34
|
});
|
|
29
35
|
const external_std_env_namespaceObject = require("std-env");
|
|
36
|
+
const cloudflare_js_namespaceObject = require("./platforms/cloudflare.js");
|
|
30
37
|
const gh_pages_js_namespaceObject = require("./platforms/gh-pages.js");
|
|
31
38
|
const netlify_js_namespaceObject = require("./platforms/netlify.js");
|
|
32
39
|
const node_js_namespaceObject = require("./platforms/node.js");
|
|
@@ -36,14 +43,18 @@ const deployPresets = {
|
|
|
36
43
|
node: node_js_namespaceObject.createNodePreset,
|
|
37
44
|
vercel: vercel_js_namespaceObject.createVercelPreset,
|
|
38
45
|
netlify: netlify_js_namespaceObject.createNetlifyPreset,
|
|
39
|
-
ghPages: gh_pages_js_namespaceObject.createGhPagesPreset
|
|
46
|
+
ghPages: gh_pages_js_namespaceObject.createGhPagesPreset,
|
|
47
|
+
cloudflare: cloudflare_js_namespaceObject.createCloudflarePreset
|
|
40
48
|
};
|
|
49
|
+
const getSupportedDeployTargets = ()=>Object.keys(deployPresets);
|
|
50
|
+
const isDeployTarget = (target)=>Object.prototype.hasOwnProperty.call(deployPresets, target);
|
|
51
|
+
const resolveDeployTarget = (modernConfig, envDeployTarget = process.env.MODERNJS_DEPLOY, detectedProvider = external_std_env_namespaceObject.provider)=>modernConfig.deploy?.target || envDeployTarget || detectedProvider || 'node';
|
|
41
52
|
async function getDeployPreset(appContext, modernConfig, deployTarget, api) {
|
|
42
53
|
const { appDirectory, distDirectory, metaName } = appContext;
|
|
43
54
|
const { useSSR, useAPI, useWebServer } = (0, index_js_namespaceObject.getProjectUsage)(appDirectory, distDirectory, metaName);
|
|
44
55
|
const needModernServer = useSSR || useAPI || useWebServer;
|
|
56
|
+
if (!isDeployTarget(deployTarget)) throw new Error(`Unknown deploy target: '${deployTarget}'. deploy.target or MODERNJS_DEPLOY should be one of: ${getSupportedDeployTargets().join(', ')}.`);
|
|
45
57
|
const createPreset = deployPresets[deployTarget];
|
|
46
|
-
if (!createPreset) throw new Error(`Unknown deploy target: '${deployTarget}'. MODERNJS_DEPLOY should be 'node', 'vercel', or 'netlify'.`);
|
|
47
58
|
return createPreset({
|
|
48
59
|
appContext,
|
|
49
60
|
modernConfig,
|
|
@@ -54,12 +65,12 @@ async function getDeployPreset(appContext, modernConfig, deployTarget, api) {
|
|
|
54
65
|
const deploy = ()=>({
|
|
55
66
|
name: '@modern-js/plugin-deploy',
|
|
56
67
|
setup: (api)=>{
|
|
57
|
-
const deployTarget = process.env.MODERNJS_DEPLOY || external_std_env_namespaceObject.provider || 'node';
|
|
58
68
|
api.deploy(async ()=>{
|
|
59
69
|
const appContext = api.getAppContext();
|
|
60
70
|
const { metaName } = appContext;
|
|
61
|
-
if ('modern-js' !== metaName && !process.env.MODERNJS_DEPLOY) return;
|
|
62
71
|
const modernConfig = api.getNormalizedConfig();
|
|
72
|
+
const deployTarget = resolveDeployTarget(modernConfig);
|
|
73
|
+
if ('modern-js' !== metaName && !modernConfig.deploy?.target && !process.env.MODERNJS_DEPLOY) return;
|
|
63
74
|
const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget, api);
|
|
64
75
|
deployPreset?.prepare && await deployPreset?.prepare();
|
|
65
76
|
deployPreset?.writeOutput && await deployPreset?.writeOutput();
|
|
@@ -69,8 +80,12 @@ const deploy = ()=>({
|
|
|
69
80
|
}
|
|
70
81
|
});
|
|
71
82
|
exports["default"] = __webpack_exports__["default"];
|
|
83
|
+
exports.getSupportedDeployTargets = __webpack_exports__.getSupportedDeployTargets;
|
|
84
|
+
exports.resolveDeployTarget = __webpack_exports__.resolveDeployTarget;
|
|
72
85
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
73
|
-
"default"
|
|
86
|
+
"default",
|
|
87
|
+
"getSupportedDeployTargets",
|
|
88
|
+
"resolveDeployTarget"
|
|
74
89
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
75
90
|
Object.defineProperty(exports, '__esModule', {
|
|
76
91
|
value: true
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
(()=>{
|
|
25
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
26
|
+
})();
|
|
27
|
+
(()=>{
|
|
28
|
+
__webpack_require__.r = (exports1)=>{
|
|
29
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
30
|
+
value: 'Module'
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
33
|
+
value: true
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
var __webpack_exports__ = {};
|
|
38
|
+
__webpack_require__.r(__webpack_exports__);
|
|
39
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
+
createCloudflarePreset: ()=>createCloudflarePreset
|
|
41
|
+
});
|
|
42
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
43
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
44
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
45
|
+
const index_js_namespaceObject = require("../utils/index.js");
|
|
46
|
+
const WORKER_ENTRY = 'server/index.mjs';
|
|
47
|
+
const WORKER_MANIFEST = 'server/modern-worker-manifest.json';
|
|
48
|
+
const ASSETS_BINDING = 'ASSETS';
|
|
49
|
+
const ROUTE_SPEC_FILE = 'route.json';
|
|
50
|
+
const ROUTE_SPEC_OUTPUT = `server/${ROUTE_SPEC_FILE}`;
|
|
51
|
+
const LOADABLE_STATS_FILE = 'loadable-stats.json';
|
|
52
|
+
const ROUTE_MANIFEST_FILE = 'routes-manifest.json';
|
|
53
|
+
const PUBLIC_ASSETS_DIRECTORY = 'public';
|
|
54
|
+
const WORKER_BUNDLE_DIRECTORY = 'worker';
|
|
55
|
+
const SERVER_BUNDLE_DIRECTORY = 'bundles';
|
|
56
|
+
const BFF_EFFECT_WORKER_ENTRY = `${WORKER_BUNDLE_DIRECTORY}/__modern_bff_effect.js`;
|
|
57
|
+
const DEFAULT_COMPATIBILITY_DATE = '2026-06-02';
|
|
58
|
+
const COMPATIBILITY_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/u;
|
|
59
|
+
const DEFAULT_SECURITY_HEADERS = {
|
|
60
|
+
referrerPolicy: 'strict-origin-when-cross-origin',
|
|
61
|
+
contentTypeOptions: 'nosniff',
|
|
62
|
+
permissionsPolicy: 'camera=(), geolocation=(), microphone=(), payment=(), usb=()'
|
|
63
|
+
};
|
|
64
|
+
const DEFAULT_CORS_ALLOWED_METHODS = [
|
|
65
|
+
'GET',
|
|
66
|
+
'HEAD',
|
|
67
|
+
'POST',
|
|
68
|
+
'PUT',
|
|
69
|
+
'PATCH',
|
|
70
|
+
'DELETE',
|
|
71
|
+
'OPTIONS'
|
|
72
|
+
];
|
|
73
|
+
const DEFAULT_CSP_DIRECTIVES = {
|
|
74
|
+
'base-uri': [
|
|
75
|
+
"'self'"
|
|
76
|
+
],
|
|
77
|
+
'connect-src': [
|
|
78
|
+
"'self'",
|
|
79
|
+
'https:',
|
|
80
|
+
'http:',
|
|
81
|
+
'wss:',
|
|
82
|
+
'ws:'
|
|
83
|
+
],
|
|
84
|
+
'default-src': [
|
|
85
|
+
"'self'"
|
|
86
|
+
],
|
|
87
|
+
'font-src': [
|
|
88
|
+
"'self'",
|
|
89
|
+
'data:',
|
|
90
|
+
'https:',
|
|
91
|
+
'http:'
|
|
92
|
+
],
|
|
93
|
+
'form-action': [
|
|
94
|
+
"'self'"
|
|
95
|
+
],
|
|
96
|
+
'frame-ancestors': [
|
|
97
|
+
"'self'"
|
|
98
|
+
],
|
|
99
|
+
'img-src': [
|
|
100
|
+
"'self'",
|
|
101
|
+
'data:',
|
|
102
|
+
'blob:',
|
|
103
|
+
'https:',
|
|
104
|
+
'http:'
|
|
105
|
+
],
|
|
106
|
+
'manifest-src': [
|
|
107
|
+
"'self'",
|
|
108
|
+
'https:',
|
|
109
|
+
'http:'
|
|
110
|
+
],
|
|
111
|
+
'object-src': [
|
|
112
|
+
"'none'"
|
|
113
|
+
],
|
|
114
|
+
"script-src": [
|
|
115
|
+
"'self'",
|
|
116
|
+
"'unsafe-inline'",
|
|
117
|
+
"'unsafe-eval'",
|
|
118
|
+
'https:',
|
|
119
|
+
'http:',
|
|
120
|
+
'blob:'
|
|
121
|
+
],
|
|
122
|
+
'style-src': [
|
|
123
|
+
"'self'",
|
|
124
|
+
"'unsafe-inline'",
|
|
125
|
+
'https:',
|
|
126
|
+
'http:'
|
|
127
|
+
],
|
|
128
|
+
'worker-src': [
|
|
129
|
+
"'self'",
|
|
130
|
+
'blob:'
|
|
131
|
+
]
|
|
132
|
+
};
|
|
133
|
+
const getCompatibilityDate = (modernConfig)=>{
|
|
134
|
+
const configuredDate = modernConfig.deploy?.worker?.compatibilityDate?.trim();
|
|
135
|
+
const compatibilityDate = configuredDate || DEFAULT_COMPATIBILITY_DATE;
|
|
136
|
+
if (!COMPATIBILITY_DATE_PATTERN.test(compatibilityDate)) throw new Error(`deploy.worker.compatibilityDate must use YYYY-MM-DD, received ${JSON.stringify(compatibilityDate)}.`);
|
|
137
|
+
return compatibilityDate;
|
|
138
|
+
};
|
|
139
|
+
const getWorkerName = (appDirectory)=>{
|
|
140
|
+
const basename = external_node_path_default().basename(appDirectory);
|
|
141
|
+
return basename.replace(/[^a-zA-Z0-9-_]/g, '-') || 'modern-cloudflare-worker';
|
|
142
|
+
};
|
|
143
|
+
const getConfiguredWorkerName = (appDirectory, modernConfig)=>{
|
|
144
|
+
const configuredName = modernConfig.deploy?.worker?.name?.trim();
|
|
145
|
+
return configuredName || getWorkerName(appDirectory);
|
|
146
|
+
};
|
|
147
|
+
const normalizeDirectiveValues = (value)=>{
|
|
148
|
+
const values = Array.isArray(value) ? value : [
|
|
149
|
+
value
|
|
150
|
+
];
|
|
151
|
+
return [
|
|
152
|
+
...new Set(values.map((entry)=>entry.trim()).filter(Boolean))
|
|
153
|
+
];
|
|
154
|
+
};
|
|
155
|
+
const appendDirectiveValues = (directives, name, values)=>{
|
|
156
|
+
if (!values?.length) return;
|
|
157
|
+
directives[name] = normalizeDirectiveValues([
|
|
158
|
+
...directives[name] ?? [],
|
|
159
|
+
...values
|
|
160
|
+
]);
|
|
161
|
+
};
|
|
162
|
+
const createContentSecurityPolicy = (config)=>{
|
|
163
|
+
const mode = config?.mode ?? 'report-only';
|
|
164
|
+
if ('off' === mode) return {
|
|
165
|
+
mode,
|
|
166
|
+
directives: {},
|
|
167
|
+
reason: config?.reason
|
|
168
|
+
};
|
|
169
|
+
const directives = Object.fromEntries(Object.entries(DEFAULT_CSP_DIRECTIVES).map(([name, values])=>[
|
|
170
|
+
name,
|
|
171
|
+
[
|
|
172
|
+
...values
|
|
173
|
+
]
|
|
174
|
+
]));
|
|
175
|
+
for (const [name, value] of Object.entries(config?.directives ?? {}))if (false === value) delete directives[name];
|
|
176
|
+
else directives[name] = normalizeDirectiveValues(value);
|
|
177
|
+
if (config?.frameAncestors === false) delete directives['frame-ancestors'];
|
|
178
|
+
else if (config?.frameAncestors) directives['frame-ancestors'] = normalizeDirectiveValues(config.frameAncestors);
|
|
179
|
+
appendDirectiveValues(directives, "script-src", config?.additionalScriptSrc);
|
|
180
|
+
appendDirectiveValues(directives, 'style-src', config?.additionalStyleSrc);
|
|
181
|
+
appendDirectiveValues(directives, 'connect-src', config?.additionalConnectSrc);
|
|
182
|
+
appendDirectiveValues(directives, 'img-src', config?.additionalImgSrc);
|
|
183
|
+
if (config?.reportUri) directives['report-uri'] = [
|
|
184
|
+
config.reportUri
|
|
185
|
+
];
|
|
186
|
+
return {
|
|
187
|
+
mode,
|
|
188
|
+
directives,
|
|
189
|
+
reason: config?.reason
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
const createNoindexPolicy = (noindex)=>{
|
|
193
|
+
if (false === noindex) return {
|
|
194
|
+
workersDev: false,
|
|
195
|
+
localhost: false,
|
|
196
|
+
previewHostnames: []
|
|
197
|
+
};
|
|
198
|
+
if (true === noindex || void 0 === noindex) return {
|
|
199
|
+
workersDev: true,
|
|
200
|
+
localhost: true,
|
|
201
|
+
previewHostnames: []
|
|
202
|
+
};
|
|
203
|
+
return {
|
|
204
|
+
workersDev: noindex.workersDev ?? true,
|
|
205
|
+
localhost: noindex.localhost ?? true,
|
|
206
|
+
previewHostnames: noindex.previewHostnames ?? [],
|
|
207
|
+
reason: noindex.reason
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
const createCloudflareWorkerCorsPolicy = (cors)=>({
|
|
211
|
+
assets: cors?.assets ?? true,
|
|
212
|
+
allowedOrigins: normalizeDirectiveValues(cors?.allowedOrigins ?? []),
|
|
213
|
+
allowedMethods: cors?.allowedMethods?.length ? normalizeDirectiveValues(cors.allowedMethods.map((method)=>method.toUpperCase())) : DEFAULT_CORS_ALLOWED_METHODS,
|
|
214
|
+
allowedHeaders: cors?.allowedHeaders?.length ? normalizeDirectiveValues(cors.allowedHeaders) : [
|
|
215
|
+
'*'
|
|
216
|
+
],
|
|
217
|
+
reason: cors?.reason
|
|
218
|
+
});
|
|
219
|
+
const createCloudflareWorkerSecurityPolicy = (modernConfig)=>{
|
|
220
|
+
const security = modernConfig.deploy?.worker?.security;
|
|
221
|
+
if (security?.enabled === false) return {
|
|
222
|
+
enabled: false,
|
|
223
|
+
cors: createCloudflareWorkerCorsPolicy(security.cors),
|
|
224
|
+
reason: security.reason
|
|
225
|
+
};
|
|
226
|
+
return {
|
|
227
|
+
enabled: true,
|
|
228
|
+
headers: {
|
|
229
|
+
referrerPolicy: security?.headers?.referrerPolicy ?? DEFAULT_SECURITY_HEADERS.referrerPolicy,
|
|
230
|
+
contentTypeOptions: security?.headers?.contentTypeOptions ?? DEFAULT_SECURITY_HEADERS.contentTypeOptions,
|
|
231
|
+
permissionsPolicy: security?.headers?.permissionsPolicy ?? DEFAULT_SECURITY_HEADERS.permissionsPolicy
|
|
232
|
+
},
|
|
233
|
+
contentSecurityPolicy: createContentSecurityPolicy(security?.contentSecurityPolicy),
|
|
234
|
+
noindex: createNoindexPolicy(security?.noindex),
|
|
235
|
+
cors: createCloudflareWorkerCorsPolicy(security?.cors),
|
|
236
|
+
reason: security?.reason
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
const readRouteSpec = async (outputDirectory)=>{
|
|
240
|
+
const routeSpecPath = external_node_path_default().join(outputDirectory, ROUTE_SPEC_OUTPUT);
|
|
241
|
+
if (!await utils_namespaceObject.fs.pathExists(routeSpecPath)) return {
|
|
242
|
+
routes: []
|
|
243
|
+
};
|
|
244
|
+
const routeSpec = await utils_namespaceObject.fs.readJSON(routeSpecPath);
|
|
245
|
+
return {
|
|
246
|
+
...routeSpec,
|
|
247
|
+
routes: Array.isArray(routeSpec.routes) ? routeSpec.routes : []
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
const createWorkerManifest = async (outputDirectory, modernConfig)=>{
|
|
251
|
+
const routeSpec = await readRouteSpec(outputDirectory);
|
|
252
|
+
const routes = await Promise.all(routeSpec.routes.map(async (route)=>{
|
|
253
|
+
const worker = 'string' == typeof route.worker ? route.worker : void 0;
|
|
254
|
+
return {
|
|
255
|
+
urlPath: route.urlPath,
|
|
256
|
+
entryName: route.entryName,
|
|
257
|
+
entryPath: route.entryPath,
|
|
258
|
+
isSSR: Boolean(route.isSSR),
|
|
259
|
+
worker,
|
|
260
|
+
workerExists: worker ? await utils_namespaceObject.fs.pathExists(external_node_path_default().join(outputDirectory, worker)) : false
|
|
261
|
+
};
|
|
262
|
+
}));
|
|
263
|
+
const bffPrefix = modernConfig.bff?.prefix;
|
|
264
|
+
const primaryBffPrefix = Array.isArray(bffPrefix) ? bffPrefix[0] : bffPrefix;
|
|
265
|
+
const isEffectBff = Boolean(modernConfig.bff) && modernConfig.bff?.runtimeFramework !== 'hono';
|
|
266
|
+
const effectBffWorkerExists = await utils_namespaceObject.fs.pathExists(external_node_path_default().join(outputDirectory, BFF_EFFECT_WORKER_ENTRY));
|
|
267
|
+
return {
|
|
268
|
+
version: 1,
|
|
269
|
+
runtime: {
|
|
270
|
+
type: 'cloudflare-module-worker',
|
|
271
|
+
entry: WORKER_ENTRY,
|
|
272
|
+
fetchExport: true,
|
|
273
|
+
nodeListen: false
|
|
274
|
+
},
|
|
275
|
+
assets: {
|
|
276
|
+
binding: ASSETS_BINDING,
|
|
277
|
+
directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
|
|
278
|
+
runWorkerFirst: true
|
|
279
|
+
},
|
|
280
|
+
routeSpec: {
|
|
281
|
+
file: ROUTE_SPEC_OUTPUT,
|
|
282
|
+
routes
|
|
283
|
+
},
|
|
284
|
+
workerBundles: {
|
|
285
|
+
directory: WORKER_BUNDLE_DIRECTORY,
|
|
286
|
+
format: 'commonjs',
|
|
287
|
+
importableFromModuleWorker: true,
|
|
288
|
+
requestHandlerExport: 'requestHandler'
|
|
289
|
+
},
|
|
290
|
+
resources: {
|
|
291
|
+
loadableStats: LOADABLE_STATS_FILE,
|
|
292
|
+
routeManifest: ROUTE_MANIFEST_FILE
|
|
293
|
+
},
|
|
294
|
+
security: createCloudflareWorkerSecurityPolicy(modernConfig),
|
|
295
|
+
bff: isEffectBff && primaryBffPrefix && effectBffWorkerExists ? {
|
|
296
|
+
runtimeFramework: 'effect',
|
|
297
|
+
prefix: primaryBffPrefix,
|
|
298
|
+
worker: BFF_EFFECT_WORKER_ENTRY
|
|
299
|
+
} : void 0
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
const createWorkerModuleLoaders = (manifest)=>{
|
|
303
|
+
const imports = new Map();
|
|
304
|
+
for (const route of manifest.routeSpec.routes)if (route.worker && route.workerExists) {
|
|
305
|
+
const importPath = `../${String(route.worker).replace(/^\/+/u, '')}`;
|
|
306
|
+
imports.set(route.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
307
|
+
}
|
|
308
|
+
if (manifest.bff?.worker) {
|
|
309
|
+
const importPath = `../${String(manifest.bff.worker).replace(/^\/+/u, '')}`;
|
|
310
|
+
imports.set(manifest.bff.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
311
|
+
}
|
|
312
|
+
if (0 === imports.size) return '{}';
|
|
313
|
+
const loaders = [
|
|
314
|
+
...imports.entries()
|
|
315
|
+
].map(([worker, loader])=>`${JSON.stringify(worker)}: ${loader}`);
|
|
316
|
+
return `{\n${loaders.join(',\n')}\n}`;
|
|
317
|
+
};
|
|
318
|
+
const shouldCopyToPublicAssets = (src, distDirectory)=>{
|
|
319
|
+
const relativePath = external_node_path_default().relative(distDirectory, src);
|
|
320
|
+
if (!relativePath) return true;
|
|
321
|
+
const normalizedRelativePath = relativePath.replace(/\\/g, '/');
|
|
322
|
+
const [topLevelDirectory] = normalizedRelativePath.split('/');
|
|
323
|
+
return normalizedRelativePath !== ROUTE_SPEC_FILE && topLevelDirectory !== WORKER_BUNDLE_DIRECTORY && topLevelDirectory !== SERVER_BUNDLE_DIRECTORY;
|
|
324
|
+
};
|
|
325
|
+
const shouldCopyToWorkerBundle = (src, workerBundleDirectory)=>{
|
|
326
|
+
const relativePath = external_node_path_default().relative(workerBundleDirectory, src);
|
|
327
|
+
if (!relativePath) return true;
|
|
328
|
+
const normalizedRelativePath = relativePath.replace(/\\/g, '/');
|
|
329
|
+
const basename = external_node_path_default().basename(normalizedRelativePath);
|
|
330
|
+
if (basename.startsWith('.') || normalizedRelativePath.includes('/.')) return false;
|
|
331
|
+
if (utils_namespaceObject.fs.statSync(src).isDirectory()) return true;
|
|
332
|
+
return [
|
|
333
|
+
'.cjs',
|
|
334
|
+
'.js',
|
|
335
|
+
'.mjs'
|
|
336
|
+
].includes(external_node_path_default().extname(normalizedRelativePath));
|
|
337
|
+
};
|
|
338
|
+
const createCloudflarePreset = ({ appContext, modernConfig })=>{
|
|
339
|
+
const { appDirectory, distDirectory } = appContext;
|
|
340
|
+
const outputDirectory = external_node_path_default().join(appDirectory, '.output');
|
|
341
|
+
const publicDirectory = external_node_path_default().join(outputDirectory, PUBLIC_ASSETS_DIRECTORY);
|
|
342
|
+
const workerEntryPath = external_node_path_default().join(outputDirectory, WORKER_ENTRY);
|
|
343
|
+
const workerManifestPath = external_node_path_default().join(outputDirectory, WORKER_MANIFEST);
|
|
344
|
+
const routeSpecOutputPath = external_node_path_default().join(outputDirectory, ROUTE_SPEC_OUTPUT);
|
|
345
|
+
const wranglerConfigPath = external_node_path_default().join(outputDirectory, 'wrangler.json');
|
|
346
|
+
const workerName = getConfiguredWorkerName(appDirectory, modernConfig);
|
|
347
|
+
return {
|
|
348
|
+
async prepare () {
|
|
349
|
+
await utils_namespaceObject.fs.remove(outputDirectory);
|
|
350
|
+
},
|
|
351
|
+
async writeOutput () {
|
|
352
|
+
await utils_namespaceObject.fs.copy(distDirectory, publicDirectory, {
|
|
353
|
+
filter: (src)=>shouldCopyToPublicAssets(src, distDirectory)
|
|
354
|
+
});
|
|
355
|
+
await utils_namespaceObject.fs.ensureDir(external_node_path_default().dirname(workerEntryPath));
|
|
356
|
+
await utils_namespaceObject.fs.ensureDir(external_node_path_default().dirname(workerManifestPath));
|
|
357
|
+
const routeSpecSourcePath = external_node_path_default().join(distDirectory, ROUTE_SPEC_FILE);
|
|
358
|
+
if (await utils_namespaceObject.fs.pathExists(routeSpecSourcePath)) await utils_namespaceObject.fs.copy(routeSpecSourcePath, routeSpecOutputPath);
|
|
359
|
+
const workerBundleSourceDirectory = external_node_path_default().join(distDirectory, WORKER_BUNDLE_DIRECTORY);
|
|
360
|
+
if (await utils_namespaceObject.fs.pathExists(workerBundleSourceDirectory)) await utils_namespaceObject.fs.copy(workerBundleSourceDirectory, external_node_path_default().join(outputDirectory, WORKER_BUNDLE_DIRECTORY), {
|
|
361
|
+
filter: (src)=>shouldCopyToWorkerBundle(src, workerBundleSourceDirectory)
|
|
362
|
+
});
|
|
363
|
+
await utils_namespaceObject.fs.writeJSON(wranglerConfigPath, {
|
|
364
|
+
$schema: 'node_modules/wrangler/config-schema.json',
|
|
365
|
+
name: workerName,
|
|
366
|
+
main: WORKER_ENTRY,
|
|
367
|
+
compatibility_date: getCompatibilityDate(modernConfig),
|
|
368
|
+
compatibility_flags: [
|
|
369
|
+
'nodejs_compat',
|
|
370
|
+
'global_fetch_strictly_public'
|
|
371
|
+
],
|
|
372
|
+
assets: {
|
|
373
|
+
directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
|
|
374
|
+
binding: ASSETS_BINDING,
|
|
375
|
+
run_worker_first: true
|
|
376
|
+
}
|
|
377
|
+
}, {
|
|
378
|
+
spaces: 2
|
|
379
|
+
});
|
|
380
|
+
await utils_namespaceObject.fs.writeJSON(workerManifestPath, await createWorkerManifest(outputDirectory, modernConfig), {
|
|
381
|
+
spaces: 2
|
|
382
|
+
});
|
|
383
|
+
await utils_namespaceObject.fs.writeJSON(external_node_path_default().join(outputDirectory, 'package.json'), {
|
|
384
|
+
type: 'commonjs'
|
|
385
|
+
});
|
|
386
|
+
},
|
|
387
|
+
async genEntry () {
|
|
388
|
+
const template = await (0, index_js_namespaceObject.readTemplate)('cloudflare-entry.mjs');
|
|
389
|
+
const manifest = await utils_namespaceObject.fs.readJSON(workerManifestPath);
|
|
390
|
+
await utils_namespaceObject.fs.writeFile(workerEntryPath, template.replace('p_workerManifest', JSON.stringify(manifest, null, 2)).replace('p_workerModuleLoaders', createWorkerModuleLoaders(manifest)));
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
};
|
|
394
|
+
exports.createCloudflarePreset = __webpack_exports__.createCloudflarePreset;
|
|
395
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
396
|
+
"createCloudflarePreset"
|
|
397
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
398
|
+
Object.defineProperty(exports, '__esModule', {
|
|
399
|
+
value: true
|
|
400
|
+
});
|
|
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
|
|
|
10
10
|
};
|
|
11
11
|
})();
|
|
12
12
|
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
18
22
|
};
|
|
19
23
|
})();
|
|
20
24
|
(()=>{
|
|
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
|
|
|
10
10
|
};
|
|
11
11
|
})();
|
|
12
12
|
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
18
22
|
};
|
|
19
23
|
})();
|
|
20
24
|
(()=>{
|
|
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
|
|
|
10
10
|
};
|
|
11
11
|
})();
|
|
12
12
|
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
18
22
|
};
|
|
19
23
|
})();
|
|
20
24
|
(()=>{
|