@bleedingdev/modern-js-app-tools 3.8.3-ultramodern.1 → 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/bin/modern-bundle-docs.js +11 -0
- package/bin/modern.js +11 -0
- package/dist/cjs/builder/generator/getBuilderEnvironments.js +13 -241
- package/dist/cjs/builder/generator/index.js +0 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +37 -9
- package/dist/cjs/builder/shared/builderPlugins/index.js +6 -13
- package/dist/cjs/builder/shared/bundlerPlugins/index.js +6 -13
- package/dist/cjs/builder/shared/lazyCompilation.js +9 -9
- package/dist/cjs/bundleDocs.js +1 -1
- package/dist/cjs/index.js +59 -60
- package/dist/cjs/plugins/analyze/getServerRoutes.js +1 -1
- package/dist/cjs/plugins/analyze/isDefaultExportFunction.js +1 -9
- package/dist/cjs/plugins/backend-federation/codegen.js +2 -1
- package/dist/cjs/plugins/backend-federation/config.js +2 -2
- package/dist/cjs/plugins/backend-federation/emit.js +6 -4
- package/dist/cjs/plugins/deploy/index.js +4 -4
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/index.js +23 -149
- package/dist/cjs/plugins/deploy/platforms/templates/netlify-entry.cjs +41 -62
- package/dist/cjs/plugins/deploy/platforms/templates/netlify-entry.mjs +41 -63
- package/dist/cjs/plugins/deploy/platforms/templates/node-entry.cjs +35 -52
- package/dist/cjs/plugins/deploy/platforms/templates/node-entry.mjs +35 -53
- package/dist/cjs/plugins/deploy/platforms/templates/vercel-entry.cjs +41 -61
- package/dist/cjs/plugins/deploy/platforms/templates/vercel-entry.mjs +40 -61
- package/dist/cjs/plugins/ultramodernReleaseEnvelope.js +3 -59
- package/dist/cjs/presetUltramodern.js +9 -4
- package/dist/cjs/run/index.js +9 -9
- package/dist/cjs/utils/register.js +6 -3
- package/dist/esm/builder/generator/getBuilderEnvironments.mjs +12 -231
- package/dist/esm/builder/generator/index.mjs +1 -2
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +34 -9
- package/dist/esm/builder/shared/builderPlugins/index.mjs +0 -1
- package/dist/esm/builder/shared/bundlerPlugins/index.mjs +0 -1
- package/dist/esm/builder/shared/lazyCompilation.mjs +4 -4
- package/dist/esm/bundleDocs.mjs +1 -1
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/plugins/analyze/getServerRoutes.mjs +1 -1
- package/dist/esm/plugins/analyze/isDefaultExportFunction.mjs +1 -9
- package/dist/esm/plugins/backend-federation/codegen.mjs +2 -1
- package/dist/esm/plugins/backend-federation/config.mjs +1 -1
- package/dist/esm/plugins/backend-federation/emit.mjs +5 -3
- package/dist/esm/plugins/deploy/index.mjs +1 -1
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +1 -133
- package/dist/esm/plugins/deploy/platforms/templates/netlify-entry.cjs +41 -62
- package/dist/esm/plugins/deploy/platforms/templates/netlify-entry.mjs +41 -63
- package/dist/esm/plugins/deploy/platforms/templates/node-entry.cjs +35 -52
- package/dist/esm/plugins/deploy/platforms/templates/node-entry.mjs +35 -53
- package/dist/esm/plugins/deploy/platforms/templates/vercel-entry.cjs +41 -61
- package/dist/esm/plugins/deploy/platforms/templates/vercel-entry.mjs +40 -61
- package/dist/esm/plugins/ultramodernReleaseEnvelope.mjs +3 -49
- package/dist/esm/presetUltramodern.mjs +2 -1
- package/dist/esm/run/index.mjs +9 -9
- package/dist/esm/utils/register.mjs +6 -3
- package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +12 -234
- package/dist/esm-node/builder/generator/index.mjs +1 -2
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +34 -9
- package/dist/esm-node/builder/shared/builderPlugins/index.mjs +0 -1
- package/dist/esm-node/builder/shared/bundlerPlugins/index.mjs +0 -1
- package/dist/esm-node/builder/shared/lazyCompilation.mjs +4 -4
- package/dist/esm-node/bundleDocs.mjs +1 -1
- package/dist/esm-node/index.mjs +3 -3
- package/dist/esm-node/plugins/analyze/getServerRoutes.mjs +1 -1
- package/dist/esm-node/plugins/analyze/isDefaultExportFunction.mjs +1 -9
- package/dist/esm-node/plugins/backend-federation/codegen.mjs +2 -1
- package/dist/esm-node/plugins/backend-federation/config.mjs +1 -1
- package/dist/esm-node/plugins/backend-federation/emit.mjs +5 -3
- package/dist/esm-node/plugins/deploy/index.mjs +1 -1
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +1 -133
- package/dist/esm-node/plugins/deploy/platforms/templates/netlify-entry.cjs +41 -62
- package/dist/esm-node/plugins/deploy/platforms/templates/netlify-entry.mjs +41 -63
- package/dist/esm-node/plugins/deploy/platforms/templates/node-entry.cjs +35 -52
- package/dist/esm-node/plugins/deploy/platforms/templates/node-entry.mjs +35 -53
- package/dist/esm-node/plugins/deploy/platforms/templates/vercel-entry.cjs +41 -61
- package/dist/esm-node/plugins/deploy/platforms/templates/vercel-entry.mjs +40 -61
- package/dist/esm-node/plugins/ultramodernReleaseEnvelope.mjs +3 -49
- package/dist/esm-node/presetUltramodern.mjs +2 -1
- package/dist/esm-node/run/index.mjs +9 -9
- package/dist/esm-node/utils/register.mjs +6 -3
- package/dist/types/builder/generator/getBuilderEnvironments.d.ts +0 -29
- package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +11 -0
- package/dist/types/builder/shared/builderPlugins/index.d.ts +0 -1
- package/dist/types/builder/shared/bundlerPlugins/index.d.ts +0 -1
- package/dist/types/builder/shared/lazyCompilation.d.ts +7 -7
- package/dist/types/plugins/analyze/getServerRoutes.d.ts +1 -1
- package/dist/types/plugins/backend-federation/codegen.d.ts +4 -1
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/index.d.ts +1 -18
- package/dist/types/presetUltramodern.d.ts +1 -0
- package/dist/types/types/config/deploy.d.ts +2 -2
- package/docs/community/showcase.md +3 -5
- package/docs/guides/advanced-features/bff/frameworks.md +1 -1
- package/docs/guides/basic-features/deploy.md +2 -2
- package/docs/guides/get-started/quick-start.md +9 -8
- package/docs/guides/get-started/tech-stack.md +1 -1
- package/docs/guides/get-started/ultramodern.md +18 -18
- package/docs/guides/troubleshooting/cli.md +1 -1
- package/docs/llms.txt +2 -2
- package/docs/tutorials/examples/csr-auth.md +1 -1
- package/package.json +15 -27
- package/rslib.config.mts +4 -7
- package/dist/cjs/builder/shared/builderPlugins/adapterLazyCompilation.js +0 -74
- package/dist/cjs/builder/shared/bundlerPlugins/CssExtractRuntimePlugin.js +0 -72
- package/dist/cjs/plugins/deploy/platforms/cloudflare/artifacts.js +0 -127
- package/dist/cjs/plugins/deploy/platforms/cloudflare/constants.js +0 -141
- package/dist/cjs/plugins/deploy/platforms/cloudflare/delivery-unit.js +0 -139
- package/dist/cjs/plugins/deploy/platforms/cloudflare/i18n-worker.js +0 -135
- package/dist/cjs/plugins/deploy/platforms/cloudflare/index.js +0 -150
- package/dist/cjs/plugins/deploy/platforms/cloudflare/security-policies.js +0 -205
- package/dist/cjs/plugins/deploy/platforms/cloudflare/types.js +0 -18
- package/dist/cjs/plugins/deploy/platforms/cloudflare/utils.js +0 -66
- package/dist/cjs/plugins/deploy/platforms/cloudflare/worker-manifest.js +0 -208
- package/dist/cjs/plugins/deploy/platforms/cloudflare/wrangler-config.js +0 -204
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-contract.js +0 -108
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-plan.js +0 -93
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/identity.js +0 -83
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/issues.js +0 -54
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/manifest.js +0 -89
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.js +0 -151
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.js +0 -378
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +0 -251
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -191
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -514
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -1012
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -363
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +0 -93
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-worker-fs-promises.mjs +0 -11
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-worker-loadable-server.mjs +0 -281
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-worker-mf-ssr-runtime-plugin.mjs +0 -14
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-worker-path.mjs +0 -98
- package/dist/cjs/types/config/cloudflareDeploy.js +0 -18
- package/dist/cjs/ultramodern-release-envelope/canonical.js +0 -68
- package/dist/cjs/ultramodern-release-envelope/framework-output.js +0 -649
- package/dist/cjs/ultramodern-release-envelope/index.js +0 -399
- package/dist/cjs/ultramodern-release-envelope/types.js +0 -51
- package/dist/cjs/ultramodern-release-identity.js +0 -110
- package/dist/esm/builder/shared/builderPlugins/adapterLazyCompilation.mjs +0 -36
- package/dist/esm/builder/shared/bundlerPlugins/CssExtractRuntimePlugin.mjs +0 -30
- package/dist/esm/plugins/deploy/platforms/cloudflare/artifacts.mjs +0 -64
- package/dist/esm/plugins/deploy/platforms/cloudflare/constants.mjs +0 -34
- package/dist/esm/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +0 -88
- package/dist/esm/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +0 -97
- package/dist/esm/plugins/deploy/platforms/cloudflare/index.mjs +0 -102
- package/dist/esm/plugins/deploy/platforms/cloudflare/security-policies.mjs +0 -167
- package/dist/esm/plugins/deploy/platforms/cloudflare/types.mjs +0 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/utils.mjs +0 -12
- package/dist/esm/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +0 -148
- package/dist/esm/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +0 -150
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-contract.mjs +0 -31
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-plan.mjs +0 -45
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +0 -45
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +0 -10
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +0 -51
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +0 -99
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +0 -313
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +0 -251
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -191
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -514
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -1012
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -363
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +0 -93
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-worker-fs-promises.mjs +0 -11
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-worker-loadable-server.mjs +0 -281
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-worker-mf-ssr-runtime-plugin.mjs +0 -14
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-worker-path.mjs +0 -98
- package/dist/esm/types/config/cloudflareDeploy.mjs +0 -0
- package/dist/esm/ultramodern-release-envelope/canonical.mjs +0 -21
- package/dist/esm/ultramodern-release-envelope/framework-output.mjs +0 -573
- package/dist/esm/ultramodern-release-envelope/index.mjs +0 -335
- package/dist/esm/ultramodern-release-envelope/types.mjs +0 -7
- package/dist/esm/ultramodern-release-identity.mjs +0 -66
- package/dist/esm-node/builder/shared/builderPlugins/adapterLazyCompilation.mjs +0 -37
- package/dist/esm-node/builder/shared/bundlerPlugins/CssExtractRuntimePlugin.mjs +0 -31
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/artifacts.mjs +0 -65
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/constants.mjs +0 -35
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +0 -89
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +0 -98
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/index.mjs +0 -103
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/security-policies.mjs +0 -168
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/types.mjs +0 -1
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/utils.mjs +0 -13
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +0 -149
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +0 -151
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-contract.mjs +0 -32
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-plan.mjs +0 -46
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +0 -46
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +0 -11
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +0 -52
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +0 -100
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +0 -314
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +0 -251
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -191
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -514
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -1012
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -363
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +0 -93
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-worker-fs-promises.mjs +0 -11
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-worker-loadable-server.mjs +0 -281
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-worker-mf-ssr-runtime-plugin.mjs +0 -14
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-worker-path.mjs +0 -98
- package/dist/esm-node/types/config/cloudflareDeploy.mjs +0 -1
- package/dist/esm-node/ultramodern-release-envelope/canonical.mjs +0 -22
- package/dist/esm-node/ultramodern-release-envelope/framework-output.mjs +0 -574
- package/dist/esm-node/ultramodern-release-envelope/index.mjs +0 -336
- package/dist/esm-node/ultramodern-release-envelope/types.mjs +0 -8
- package/dist/esm-node/ultramodern-release-identity.mjs +0 -67
- package/dist/types/builder/shared/builderPlugins/adapterLazyCompilation.d.ts +0 -3
- package/dist/types/builder/shared/bundlerPlugins/CssExtractRuntimePlugin.d.ts +0 -6
- package/dist/types/plugins/deploy/platforms/cloudflare/artifacts.d.ts +0 -15
- package/dist/types/plugins/deploy/platforms/cloudflare/constants.d.ts +0 -24
- package/dist/types/plugins/deploy/platforms/cloudflare/delivery-unit.d.ts +0 -23
- package/dist/types/plugins/deploy/platforms/cloudflare/i18n-worker.d.ts +0 -22
- package/dist/types/plugins/deploy/platforms/cloudflare/index.d.ts +0 -2
- package/dist/types/plugins/deploy/platforms/cloudflare/security-policies.d.ts +0 -51
- package/dist/types/plugins/deploy/platforms/cloudflare/types.d.ts +0 -5
- package/dist/types/plugins/deploy/platforms/cloudflare/utils.d.ts +0 -6
- package/dist/types/plugins/deploy/platforms/cloudflare/worker-manifest.d.ts +0 -122
- package/dist/types/plugins/deploy/platforms/cloudflare/wrangler-config.d.ts +0 -46
- package/dist/types/plugins/deploy/platforms/cloudflare-output-contract.d.ts +0 -14
- package/dist/types/plugins/deploy/platforms/cloudflare-output-plan.d.ts +0 -34
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/identity.d.ts +0 -4
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/issues.d.ts +0 -14
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/manifest.d.ts +0 -2
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.d.ts +0 -14
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.d.ts +0 -20
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.d.mts +0 -1
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.d.mts +0 -1
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.d.mts +0 -1
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.d.mts +0 -1
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.d.mts +0 -1
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.d.mts +0 -4
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-worker-fs-promises.d.mts +0 -5
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-worker-loadable-server.d.mts +0 -48
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-worker-mf-ssr-runtime-plugin.d.mts +0 -13
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-worker-path.d.mts +0 -21
- package/dist/types/types/config/cloudflareDeploy.d.ts +0 -161
- package/dist/types/ultramodern-release-envelope/canonical.d.ts +0 -5
- package/dist/types/ultramodern-release-envelope/framework-output.d.ts +0 -32
- package/dist/types/ultramodern-release-envelope/index.d.ts +0 -6
- package/dist/types/ultramodern-release-envelope/types.d.ts +0 -62
- package/dist/types/ultramodern-release-identity.d.ts +0 -16
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
import promises from "node:fs/promises";
|
|
2
|
-
import node_path from "node:path";
|
|
3
|
-
import { pathToFileURL } from "node:url";
|
|
4
|
-
import { isDeepStrictEqual } from "node:util";
|
|
5
|
-
import { parse } from "@babel/parser";
|
|
6
|
-
import traverse from "@babel/traverse";
|
|
7
|
-
import { CLOUDFLARE_WORKER_BUNDLE_DIRECTORY, CLOUDFLARE_WORKER_NODE_BUILTINS } from "../cloudflare-output-contract.mjs";
|
|
8
|
-
import { addIssue } from "./issues.mjs";
|
|
9
|
-
const getReferencedRouteWorkers = (manifest)=>Array.isArray(manifest?.routeSpec?.routes) ? manifest.routeSpec.routes.map((route)=>'string' == typeof route?.worker && route.worker.length > 0 ? route.worker : void 0).filter((worker)=>'string' == typeof worker) : [];
|
|
10
|
-
const getEffectBffWorker = (manifest)=>manifest?.bff?.runtimeFramework === 'effect' && 'string' == typeof manifest.bff.worker ? manifest.bff.worker : void 0;
|
|
11
|
-
const getWorkerBundleReferences = (manifest)=>{
|
|
12
|
-
const effectBffWorker = getEffectBffWorker(manifest);
|
|
13
|
-
return [
|
|
14
|
-
...effectBffWorker ? [
|
|
15
|
-
{
|
|
16
|
-
dispatcherExport: 'string' == typeof manifest.bff?.dispatcherExport ? manifest.bff.dispatcherExport : void 0,
|
|
17
|
-
kind: 'effect-bff',
|
|
18
|
-
reference: effectBffWorker
|
|
19
|
-
}
|
|
20
|
-
] : [],
|
|
21
|
-
...getReferencedRouteWorkers(manifest).map((reference)=>({
|
|
22
|
-
kind: 'route',
|
|
23
|
-
reference
|
|
24
|
-
}))
|
|
25
|
-
];
|
|
26
|
-
};
|
|
27
|
-
const resolveWorkerBundleReference = (issues, outputDirectory, reference, manifestPath)=>{
|
|
28
|
-
const workerRoot = node_path.resolve(outputDirectory, CLOUDFLARE_WORKER_BUNDLE_DIRECTORY);
|
|
29
|
-
const workerPath = node_path.resolve(outputDirectory, reference.reference);
|
|
30
|
-
const relativeToWorkerRoot = node_path.relative(workerRoot, workerPath);
|
|
31
|
-
if (node_path.isAbsolute(reference.reference) || relativeToWorkerRoot.startsWith('..') || node_path.isAbsolute(relativeToWorkerRoot)) {
|
|
32
|
-
addIssue(issues, {
|
|
33
|
-
code: 'invalid-manifest',
|
|
34
|
-
message: 'Cloudflare output manifest worker bundle references must stay under worker/.',
|
|
35
|
-
path: manifestPath
|
|
36
|
-
});
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
...reference,
|
|
41
|
-
path: workerPath
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
const missingWorkerBundleMessage = (reference)=>'effect-bff' === reference.kind ? 'Cloudflare Effect BFF manifest points to a missing worker bundle.' : 'Cloudflare route worker manifest points to a missing worker bundle.';
|
|
45
|
-
const isAstNode = (value)=>null !== value && 'object' == typeof value && 'type' in value && 'string' == typeof value.type;
|
|
46
|
-
const getNodeName = (node)=>{
|
|
47
|
-
if (!isAstNode(node)) return;
|
|
48
|
-
return 'Identifier' === node.type && 'string' == typeof node.name ? node.name : 'StringLiteral' === node.type && 'string' == typeof node.value ? node.value : void 0;
|
|
49
|
-
};
|
|
50
|
-
const getStringLiteralValue = (node)=>isAstNode(node) && 'StringLiteral' === node.type && 'string' == typeof node.value ? node.value : void 0;
|
|
51
|
-
const collectBindingNames = (node, names)=>{
|
|
52
|
-
if (!isAstNode(node)) return;
|
|
53
|
-
const name = getNodeName(node);
|
|
54
|
-
if (name) return void names.add(name);
|
|
55
|
-
if ('ObjectPattern' === node.type && Array.isArray(node.properties)) {
|
|
56
|
-
for (const property of node.properties)if (isAstNode(property)) collectBindingNames('RestElement' === property.type ? property.argument : property.value, names);
|
|
57
|
-
} else if ('ArrayPattern' === node.type && Array.isArray(node.elements)) for (const element of node.elements)collectBindingNames(element, names);
|
|
58
|
-
else if ('AssignmentPattern' === node.type || 'RestElement' === node.type) collectBindingNames('AssignmentPattern' === node.type ? node.left : node.argument, names);
|
|
59
|
-
};
|
|
60
|
-
const getMemberPropertyName = (node)=>{
|
|
61
|
-
if ('MemberExpression' !== node.type) return;
|
|
62
|
-
return true === node.computed ? getStringLiteralValue(node.property) : getNodeName(node.property);
|
|
63
|
-
};
|
|
64
|
-
const isAmbientModuleRequire = (node, modulePath)=>isAstNode(node) && 'MemberExpression' === node.type && isAstNode(node.object) && 'Identifier' === node.object.type && 'module' === node.object.name && void 0 === modulePath.scope.getBinding('module') && 'require' === getMemberPropertyName(node);
|
|
65
|
-
const isModuleExports = (node)=>isAstNode(node) && 'MemberExpression' === node.type && isAstNode(node.object) && 'Identifier' === node.object.type && 'module' === node.object.name && 'exports' === getMemberPropertyName(node);
|
|
66
|
-
const collectCommonJsExports = (statement, exports)=>{
|
|
67
|
-
if ('ExpressionStatement' !== statement.type || !isAstNode(statement.expression) || 'AssignmentExpression' !== statement.expression.type) return;
|
|
68
|
-
const { left, right } = statement.expression;
|
|
69
|
-
if (isAstNode(left) && 'MemberExpression' === left.type && (isAstNode(left.object) && 'Identifier' === left.object.type && 'exports' === left.object.name || isModuleExports(left.object))) {
|
|
70
|
-
const exportName = getMemberPropertyName(left);
|
|
71
|
-
if (exportName) exports.add(exportName);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (isModuleExports(left) && isAstNode(right) && 'ObjectExpression' === right.type && Array.isArray(right.properties)) {
|
|
75
|
-
for (const property of right.properties)if (isAstNode(property)) {
|
|
76
|
-
const exportName = getNodeName(property.key);
|
|
77
|
-
if (exportName) exports.add(exportName);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
const collectEsmExports = (statement, exports)=>{
|
|
82
|
-
if ('ExportDefaultDeclaration' === statement.type) return void exports.add('default');
|
|
83
|
-
if ('ExportNamedDeclaration' !== statement.type) return;
|
|
84
|
-
if (isAstNode(statement.declaration)) {
|
|
85
|
-
const declaration = statement.declaration;
|
|
86
|
-
const declarationName = getNodeName(declaration.id);
|
|
87
|
-
if (declarationName) exports.add(declarationName);
|
|
88
|
-
if ('VariableDeclaration' === declaration.type && Array.isArray(declaration.declarations)) {
|
|
89
|
-
for (const declarator of declaration.declarations)if (isAstNode(declarator)) collectBindingNames(declarator.id, exports);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (Array.isArray(statement.specifiers)) {
|
|
93
|
-
for (const specifier of statement.specifiers)if (isAstNode(specifier)) {
|
|
94
|
-
const exportName = getNodeName(specifier.exported);
|
|
95
|
-
if (exportName) exports.add(exportName);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const getStaticImport = (modulePath)=>{
|
|
100
|
-
const node = modulePath.node;
|
|
101
|
-
if (('ImportDeclaration' === node.type || 'ExportNamedDeclaration' === node.type || 'ExportAllDeclaration' === node.type) && isAstNode(node.source)) return getStringLiteralValue(node.source);
|
|
102
|
-
if ('ImportExpression' === node.type && isAstNode(node.source)) return getStringLiteralValue(node.source);
|
|
103
|
-
if ('CallExpression' === node.type && Array.isArray(node.arguments) && 1 === node.arguments.length && isAstNode(node.callee) && ('Identifier' === node.callee.type && 'require' === node.callee.name && void 0 === modulePath.scope.getBinding('require') || isAmbientModuleRequire(node.callee, modulePath) || 'Import' === node.callee.type)) return getStringLiteralValue(node.arguments[0]);
|
|
104
|
-
};
|
|
105
|
-
const isAmbientLoaderWrite = (modulePath)=>{
|
|
106
|
-
let targetPath = modulePath;
|
|
107
|
-
while(targetPath.parentPath){
|
|
108
|
-
const parentPath = targetPath.parentPath;
|
|
109
|
-
if (parentPath.isAssignmentExpression()) return 'left' === targetPath.key;
|
|
110
|
-
if (parentPath.isUpdateExpression()) return 'argument' === targetPath.key;
|
|
111
|
-
if (parentPath.isForInStatement() || parentPath.isForOfStatement()) return 'left' === targetPath.key;
|
|
112
|
-
if (parentPath.isObjectProperty()) {
|
|
113
|
-
if ('value' !== targetPath.key) return false;
|
|
114
|
-
targetPath = parentPath;
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
if (parentPath.isObjectPattern() || parentPath.isArrayPattern() || parentPath.isRestElement() || parentPath.isAssignmentPattern()) {
|
|
118
|
-
targetPath = parentPath;
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
return false;
|
|
124
|
-
};
|
|
125
|
-
const analyzeWorkerModule = (source)=>{
|
|
126
|
-
const ast = parse(source, {
|
|
127
|
-
sourceType: 'unambiguous'
|
|
128
|
-
});
|
|
129
|
-
const exports = new Set();
|
|
130
|
-
const imports = new Set();
|
|
131
|
-
let unsafeCommonJsLoaderUsage = false;
|
|
132
|
-
let unsafeDynamicImport = false;
|
|
133
|
-
for (const statement of ast.program.body){
|
|
134
|
-
collectEsmExports(statement, exports);
|
|
135
|
-
collectCommonJsExports(statement, exports);
|
|
136
|
-
}
|
|
137
|
-
traverse(ast, {
|
|
138
|
-
enter (modulePath) {
|
|
139
|
-
const node = modulePath.node;
|
|
140
|
-
if (('ImportExpression' === node.type || 'CallExpression' === node.type && isAstNode(node.callee) && 'Import' === node.callee.type) && void 0 === getStaticImport(modulePath)) unsafeDynamicImport = true;
|
|
141
|
-
if (modulePath.isReferencedIdentifier({
|
|
142
|
-
name: 'require'
|
|
143
|
-
}) && void 0 === modulePath.scope.getBinding('require')) {
|
|
144
|
-
const parentPath = modulePath.parentPath;
|
|
145
|
-
const isStaticRequireCall = parentPath?.isCallExpression() && 'callee' === modulePath.key && void 0 !== getStaticImport(parentPath);
|
|
146
|
-
const isAvailabilityCheck = parentPath?.isUnaryExpression({
|
|
147
|
-
operator: 'typeof'
|
|
148
|
-
});
|
|
149
|
-
if (!isStaticRequireCall && !isAvailabilityCheck) unsafeCommonJsLoaderUsage = true;
|
|
150
|
-
}
|
|
151
|
-
if ('Identifier' === node.type && isAmbientLoaderWrite(modulePath) && ('require' === node.name || 'module' === node.name) && void 0 === modulePath.scope.getBinding(node.name)) unsafeCommonJsLoaderUsage = true;
|
|
152
|
-
if (modulePath.isReferencedIdentifier({
|
|
153
|
-
name: 'module'
|
|
154
|
-
}) && void 0 === modulePath.scope.getBinding('module')) {
|
|
155
|
-
const parentPath = modulePath.parentPath;
|
|
156
|
-
const isExportsAccess = null !== parentPath && isModuleExports(parentPath.node);
|
|
157
|
-
const isStaticModuleRequireCall = null !== parentPath && isAmbientModuleRequire(parentPath.node, parentPath) && parentPath.parentPath?.isCallExpression() === true && 'callee' === parentPath.key && void 0 !== getStaticImport(parentPath.parentPath);
|
|
158
|
-
if (!isExportsAccess && !isStaticModuleRequireCall) unsafeCommonJsLoaderUsage = true;
|
|
159
|
-
}
|
|
160
|
-
if (isAmbientModuleRequire(node, modulePath)) {
|
|
161
|
-
const parentPath = modulePath.parentPath;
|
|
162
|
-
const isStaticRequireCall = parentPath?.isCallExpression() && 'callee' === modulePath.key && void 0 !== getStaticImport(parentPath);
|
|
163
|
-
if (!isStaticRequireCall) unsafeCommonJsLoaderUsage = true;
|
|
164
|
-
}
|
|
165
|
-
const specifier = getStaticImport(modulePath);
|
|
166
|
-
if (void 0 !== specifier) imports.add(specifier);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
return {
|
|
170
|
-
exports,
|
|
171
|
-
imports,
|
|
172
|
-
unsafeCommonJsLoaderUsage,
|
|
173
|
-
unsafeDynamicImport
|
|
174
|
-
};
|
|
175
|
-
};
|
|
176
|
-
const getPackageName = (specifier)=>specifier.startsWith('@') ? specifier.split('/').slice(0, 2).join('/') : specifier.split('/')[0];
|
|
177
|
-
const CLOUDFLARE_WORKER_NODE_BUILTIN_SPECIFIERS = new Set(CLOUDFLARE_WORKER_NODE_BUILTINS.map((builtin)=>`node:${builtin}`));
|
|
178
|
-
const isInsideDirectory = (directory, filePath)=>{
|
|
179
|
-
const relative = node_path.relative(directory, filePath);
|
|
180
|
-
return 0 === relative.length || !relative.startsWith('..') && !node_path.isAbsolute(relative);
|
|
181
|
-
};
|
|
182
|
-
const resolveWorkerModule = async (importer, specifier)=>{
|
|
183
|
-
const unresolvedPath = node_path.resolve(node_path.dirname(importer), specifier);
|
|
184
|
-
const candidates = [
|
|
185
|
-
unresolvedPath,
|
|
186
|
-
`${unresolvedPath}.js`,
|
|
187
|
-
`${unresolvedPath}.mjs`,
|
|
188
|
-
`${unresolvedPath}.cjs`,
|
|
189
|
-
node_path.join(unresolvedPath, 'index.js'),
|
|
190
|
-
node_path.join(unresolvedPath, 'index.mjs'),
|
|
191
|
-
node_path.join(unresolvedPath, 'index.cjs')
|
|
192
|
-
];
|
|
193
|
-
for (const candidate of candidates)try {
|
|
194
|
-
if ((await promises.stat(candidate)).isFile()) return await promises.realpath(candidate);
|
|
195
|
-
} catch {}
|
|
196
|
-
};
|
|
197
|
-
const verifyWorkerModuleClosure = async (issues, entryPath, entrySource, contract)=>{
|
|
198
|
-
const visited = new Set();
|
|
199
|
-
let entryAnalysis;
|
|
200
|
-
const [realWorkerRoot, realEntryPath] = await Promise.all([
|
|
201
|
-
promises.realpath(contract.workerRoot),
|
|
202
|
-
promises.realpath(entryPath)
|
|
203
|
-
]);
|
|
204
|
-
if (!isInsideDirectory(realWorkerRoot, realEntryPath)) return void addIssue(issues, {
|
|
205
|
-
code: 'invalid-worker-bundle',
|
|
206
|
-
message: 'Cloudflare worker bundles must not resolve outside the staged worker directory.',
|
|
207
|
-
path: entryPath
|
|
208
|
-
});
|
|
209
|
-
const visitModule = async (modulePath, source, isEntry = false)=>{
|
|
210
|
-
if (visited.has(modulePath)) return;
|
|
211
|
-
visited.add(modulePath);
|
|
212
|
-
let analysis;
|
|
213
|
-
try {
|
|
214
|
-
analysis = analyzeWorkerModule(source ?? await promises.readFile(modulePath, 'utf-8'));
|
|
215
|
-
} catch (error) {
|
|
216
|
-
addIssue(issues, {
|
|
217
|
-
code: 'invalid-worker-bundle',
|
|
218
|
-
message: `Cloudflare worker bundle module could not be parsed: ${error instanceof Error ? error.message : String(error)}`,
|
|
219
|
-
path: modulePath
|
|
220
|
-
});
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
if (isEntry) entryAnalysis = analysis;
|
|
224
|
-
if (analysis.unsafeCommonJsLoaderUsage) addIssue(issues, {
|
|
225
|
-
code: 'invalid-worker-bundle',
|
|
226
|
-
message: 'Cloudflare worker bundles must use exactly one string-literal specifier in ambient CommonJS loader calls and must not pass or alias the loader.',
|
|
227
|
-
path: modulePath
|
|
228
|
-
});
|
|
229
|
-
if (analysis.unsafeDynamicImport) addIssue(issues, {
|
|
230
|
-
code: 'invalid-worker-bundle',
|
|
231
|
-
message: 'Cloudflare worker bundles must not contain non-static dynamic module imports.',
|
|
232
|
-
path: modulePath
|
|
233
|
-
});
|
|
234
|
-
for (const specifier of analysis.imports){
|
|
235
|
-
if (0 === specifier.length) {
|
|
236
|
-
addIssue(issues, {
|
|
237
|
-
code: 'invalid-worker-bundle',
|
|
238
|
-
message: 'Cloudflare worker bundle module specifiers must not be empty.',
|
|
239
|
-
path: modulePath
|
|
240
|
-
});
|
|
241
|
-
continue;
|
|
242
|
-
}
|
|
243
|
-
if (!specifier.startsWith('.') && !node_path.isAbsolute(specifier)) {
|
|
244
|
-
if (CLOUDFLARE_WORKER_NODE_BUILTIN_SPECIFIERS.has(specifier)) continue;
|
|
245
|
-
if (specifier.startsWith('node:')) {
|
|
246
|
-
addIssue(issues, {
|
|
247
|
-
code: 'invalid-worker-bundle',
|
|
248
|
-
message: `Cloudflare worker bundle import "${specifier}" is not a supported Worker node: builtin.`,
|
|
249
|
-
path: modulePath
|
|
250
|
-
});
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
if (!contract.providedPackages.has(getPackageName(specifier))) addIssue(issues, {
|
|
254
|
-
code: 'invalid-worker-bundle',
|
|
255
|
-
message: `Cloudflare worker bundle import "${specifier}" is not provided by worker/package.json dependencies.`,
|
|
256
|
-
path: modulePath
|
|
257
|
-
});
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
const resolved = await resolveWorkerModule(modulePath, specifier);
|
|
261
|
-
if (resolved && !isInsideDirectory(realWorkerRoot, resolved)) {
|
|
262
|
-
addIssue(issues, {
|
|
263
|
-
code: 'invalid-worker-bundle',
|
|
264
|
-
message: 'Cloudflare worker bundles must not resolve outside the staged worker directory.',
|
|
265
|
-
path: modulePath
|
|
266
|
-
});
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
if (!resolved) {
|
|
270
|
-
addIssue(issues, {
|
|
271
|
-
code: 'invalid-worker-bundle',
|
|
272
|
-
message: `Cloudflare worker bundle import "${specifier}" does not resolve inside worker/.`,
|
|
273
|
-
path: modulePath
|
|
274
|
-
});
|
|
275
|
-
continue;
|
|
276
|
-
}
|
|
277
|
-
await visitModule(resolved);
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
|
-
await visitModule(realEntryPath, entrySource, true);
|
|
281
|
-
return entryAnalysis;
|
|
282
|
-
};
|
|
283
|
-
const verifyWorkerBundleReferences = async (issues, worker, source, contract)=>{
|
|
284
|
-
const entryAnalysis = await verifyWorkerModuleClosure(issues, worker.path, source, contract);
|
|
285
|
-
if ('effect-bff' === worker.kind && 'string' == typeof worker.dispatcherExport && !entryAnalysis?.exports.has(worker.dispatcherExport)) addIssue(issues, {
|
|
286
|
-
code: 'invalid-worker-bundle',
|
|
287
|
-
message: 'Cloudflare Effect BFF worker bundle must expose its manifest dispatcherExport.',
|
|
288
|
-
path: worker.path
|
|
289
|
-
});
|
|
290
|
-
};
|
|
291
|
-
const verifyWorkerImport = async (issues, entryPath, expectedManifest)=>{
|
|
292
|
-
try {
|
|
293
|
-
const workerModule = await import(`${pathToFileURL(entryPath).href}?t=${Date.now()}`);
|
|
294
|
-
const worker = workerModule.default;
|
|
295
|
-
if (!worker || 'function' != typeof worker.fetch) addIssue(issues, {
|
|
296
|
-
code: 'worker-import-failed',
|
|
297
|
-
message: 'Cloudflare server entry must default-export a Worker with fetch.',
|
|
298
|
-
path: entryPath
|
|
299
|
-
});
|
|
300
|
-
if (void 0 !== expectedManifest && !isDeepStrictEqual(workerModule.modernWorkerManifest, expectedManifest)) addIssue(issues, {
|
|
301
|
-
code: 'worker-import-failed',
|
|
302
|
-
message: 'Cloudflare server entry runtime manifest must exactly match modern-worker-manifest.json.',
|
|
303
|
-
path: entryPath
|
|
304
|
-
});
|
|
305
|
-
} catch (error) {
|
|
306
|
-
addIssue(issues, {
|
|
307
|
-
code: 'worker-import-failed',
|
|
308
|
-
message: `Cloudflare server entry could not be imported: ${error instanceof Error ? error.message : String(error)}`,
|
|
309
|
-
path: entryPath
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
export { getEffectBffWorker, getWorkerBundleReferences, missingWorkerBundleMessage, resolveWorkerBundleReference, verifyWorkerBundleReferences, verifyWorkerImport };
|
package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
const ASSETS_BINDING = 'ASSETS';
|
|
2
|
-
const MODERN_WORKER_MANIFEST = p_workerManifest;
|
|
3
|
-
export const modernWorkerManifest = MODERN_WORKER_MANIFEST;
|
|
4
|
-
const WORKER_MODULE_LOADERS = p_workerModuleLoaders;
|
|
5
|
-
const workerModulePromises = new Map();
|
|
6
|
-
const effectBffDispatcherPromises = new Map();
|
|
7
|
-
const remoteJsonPromises = new Map();
|
|
8
|
-
const CORS_POLICY = MODERN_WORKER_MANIFEST.security?.cors || {};
|
|
9
|
-
const ASSET_CORS_ENABLED = CORS_POLICY.assets !== false;
|
|
10
|
-
const APP_CORS_ALLOWED_ORIGINS = (CORS_POLICY.allowedOrigins || []).map(
|
|
11
|
-
origin => String(origin).toLowerCase(),
|
|
12
|
-
);
|
|
13
|
-
const APP_CORS_ALLOWED_METHODS = (
|
|
14
|
-
CORS_POLICY.allowedMethods?.length
|
|
15
|
-
? CORS_POLICY.allowedMethods
|
|
16
|
-
: ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']
|
|
17
|
-
).join(', ');
|
|
18
|
-
const APP_CORS_ALLOWED_HEADERS = (
|
|
19
|
-
CORS_POLICY.allowedHeaders?.length ? CORS_POLICY.allowedHeaders : ['*']
|
|
20
|
-
).join(', ');
|
|
21
|
-
const ASSET_CORS_HEADERS = {
|
|
22
|
-
'access-control-allow-headers': '*',
|
|
23
|
-
'access-control-allow-methods': 'GET, HEAD, OPTIONS',
|
|
24
|
-
'access-control-allow-origin': '*',
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
globalThis.__dirname ??= '/';
|
|
28
|
-
globalThis.__filename ??= '/index.js';
|
|
29
|
-
|
|
30
|
-
function getAllowedAppCorsOrigin(request) {
|
|
31
|
-
if (APP_CORS_ALLOWED_ORIGINS.length === 0) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const origin = request.headers.get('origin');
|
|
36
|
-
|
|
37
|
-
if (!origin) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (APP_CORS_ALLOWED_ORIGINS.includes('*')) {
|
|
42
|
-
return '*';
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return APP_CORS_ALLOWED_ORIGINS.includes(origin.toLowerCase())
|
|
46
|
-
? origin
|
|
47
|
-
: null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function appendVaryOrigin(headers) {
|
|
51
|
-
const vary = headers.get('vary');
|
|
52
|
-
|
|
53
|
-
if (!vary) {
|
|
54
|
-
headers.set('vary', 'origin');
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const varyValues = vary.split(',').map(value => value.trim().toLowerCase());
|
|
59
|
-
|
|
60
|
-
if (!varyValues.includes('origin')) {
|
|
61
|
-
headers.set('vary', `${vary}, origin`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function withAppCorsHeaders(response, request) {
|
|
66
|
-
const allowedOrigin = getAllowedAppCorsOrigin(request);
|
|
67
|
-
|
|
68
|
-
if (!allowedOrigin) {
|
|
69
|
-
return response;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const headers = new Headers(response.headers);
|
|
73
|
-
|
|
74
|
-
if (!headers.has('access-control-allow-origin')) {
|
|
75
|
-
headers.set('access-control-allow-origin', allowedOrigin);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (allowedOrigin !== '*') {
|
|
79
|
-
appendVaryOrigin(headers);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return new Response(response.body, {
|
|
83
|
-
headers,
|
|
84
|
-
status: response.status,
|
|
85
|
-
statusText: response.statusText,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function withAssetCorsHeaders(response) {
|
|
90
|
-
if (!ASSET_CORS_ENABLED) {
|
|
91
|
-
return response;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const headers = new Headers(response.headers);
|
|
95
|
-
|
|
96
|
-
for (const [name, value] of Object.entries(ASSET_CORS_HEADERS)) {
|
|
97
|
-
if (!headers.has(name)) {
|
|
98
|
-
headers.set(name, value);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return new Response(response.body, {
|
|
103
|
-
headers,
|
|
104
|
-
status: response.status,
|
|
105
|
-
statusText: response.statusText,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function setHeaderIfEnabled(headers, name, value) {
|
|
110
|
-
if (value === false || typeof value !== 'string' || value.trim() === '') {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (!headers.has(name)) {
|
|
115
|
-
headers.set(name, value);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function renderContentSecurityPolicy(directives) {
|
|
120
|
-
return Object.entries(directives || {})
|
|
121
|
-
.filter(([, values]) => Array.isArray(values) && values.length > 0)
|
|
122
|
-
.sort(([left], [right]) => left.localeCompare(right))
|
|
123
|
-
.map(([name, values]) => `${name} ${values.join(' ')}`)
|
|
124
|
-
.join('; ');
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function isHtmlResponse(response) {
|
|
128
|
-
return (response.headers.get('content-type') || '').includes('text/html');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function matchesPreviewHostname(hostname, pattern) {
|
|
132
|
-
const normalizedHostname = hostname.toLowerCase();
|
|
133
|
-
const normalizedPattern = String(pattern || '').toLowerCase();
|
|
134
|
-
|
|
135
|
-
if (!normalizedPattern) {
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (normalizedPattern.startsWith('*.')) {
|
|
140
|
-
return normalizedHostname.endsWith(normalizedPattern.slice(1));
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return normalizedHostname === normalizedPattern;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function shouldNoindex(request, noindex) {
|
|
147
|
-
if (!noindex || noindex === false) {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const { hostname } = new URL(request.url);
|
|
152
|
-
const normalizedHostname = hostname.toLowerCase();
|
|
153
|
-
|
|
154
|
-
if (
|
|
155
|
-
noindex.localhost !== false &&
|
|
156
|
-
(normalizedHostname === 'localhost' ||
|
|
157
|
-
normalizedHostname === '127.0.0.1' ||
|
|
158
|
-
normalizedHostname === '[::1]')
|
|
159
|
-
) {
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (
|
|
164
|
-
noindex.workersDev !== false &&
|
|
165
|
-
normalizedHostname.endsWith('.workers.dev')
|
|
166
|
-
) {
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return (noindex.previewHostnames || []).some(pattern =>
|
|
171
|
-
matchesPreviewHostname(normalizedHostname, pattern),
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function withCloudflareSecurityHeaders(response, request) {
|
|
176
|
-
const security = MODERN_WORKER_MANIFEST.security;
|
|
177
|
-
|
|
178
|
-
if (!security || security.enabled === false) {
|
|
179
|
-
return response;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const headers = new Headers(response.headers);
|
|
183
|
-
const configuredHeaders = security.headers || {};
|
|
184
|
-
|
|
185
|
-
setHeaderIfEnabled(
|
|
186
|
-
headers,
|
|
187
|
-
'referrer-policy',
|
|
188
|
-
configuredHeaders.referrerPolicy,
|
|
189
|
-
);
|
|
190
|
-
setHeaderIfEnabled(
|
|
191
|
-
headers,
|
|
192
|
-
'x-content-type-options',
|
|
193
|
-
configuredHeaders.contentTypeOptions,
|
|
194
|
-
);
|
|
195
|
-
setHeaderIfEnabled(
|
|
196
|
-
headers,
|
|
197
|
-
'permissions-policy',
|
|
198
|
-
configuredHeaders.permissionsPolicy,
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
const csp = security.contentSecurityPolicy;
|
|
202
|
-
const cspHeader =
|
|
203
|
-
csp?.mode === 'enforce'
|
|
204
|
-
? 'content-security-policy'
|
|
205
|
-
: 'content-security-policy-report-only';
|
|
206
|
-
const cspValue = renderContentSecurityPolicy(csp?.directives);
|
|
207
|
-
|
|
208
|
-
if (
|
|
209
|
-
isHtmlResponse(response) &&
|
|
210
|
-
csp?.mode !== 'off' &&
|
|
211
|
-
cspValue &&
|
|
212
|
-
!headers.has(cspHeader)
|
|
213
|
-
) {
|
|
214
|
-
headers.set(cspHeader, cspValue);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (shouldNoindex(request, security.noindex)) {
|
|
218
|
-
headers.set('x-robots-tag', 'noindex, nofollow');
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return new Response(response.body, {
|
|
222
|
-
headers,
|
|
223
|
-
status: response.status,
|
|
224
|
-
statusText: response.statusText,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function createRenderableRequest(request) {
|
|
229
|
-
if (request.method !== 'HEAD') {
|
|
230
|
-
return request;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return new Request(request, { method: 'GET' });
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function finalizeResponseForRequest(response, request) {
|
|
237
|
-
const securedResponse = withCloudflareSecurityHeaders(response, request);
|
|
238
|
-
|
|
239
|
-
if (request.method !== 'HEAD') {
|
|
240
|
-
return securedResponse;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const headers = new Headers(securedResponse.headers);
|
|
244
|
-
headers.delete('content-length');
|
|
245
|
-
|
|
246
|
-
return new Response(null, {
|
|
247
|
-
headers,
|
|
248
|
-
status: securedResponse.status,
|
|
249
|
-
statusText: securedResponse.statusText,
|
|
250
|
-
});
|
|
251
|
-
}
|