@bleedingdev/modern-js-app-tools-extensions 3.9.0-ultramodern.4 → 3.9.0-ultramodern.5

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.
Files changed (93) hide show
  1. package/dist/cjs/backend-federation-build/codegen.js +256 -0
  2. package/dist/cjs/backend-federation-build/config.js +204 -0
  3. package/dist/cjs/backend-federation-build/emit.js +150 -0
  4. package/dist/cjs/backend-federation-build/index.js +53 -0
  5. package/dist/cjs/build-config/build-environment.js +268 -0
  6. package/dist/cjs/build-config/precompress/plugin.js +124 -0
  7. package/dist/cjs/build-config/precompress/types.js +18 -0
  8. package/dist/cjs/build-config/public.js +46 -0
  9. package/dist/cjs/cloudflare/constants.js +1 -1
  10. package/dist/cjs/cloudflare/delivery-unit.js +9 -9
  11. package/dist/cjs/cloudflare-output-verifier/identity.js +6 -6
  12. package/dist/cjs/config.js +29 -1
  13. package/dist/cjs/deploy-output/npmAliases.js +226 -0
  14. package/dist/cjs/deploy-output/plugin.js +76 -0
  15. package/dist/cjs/deploy-output/target.js +48 -0
  16. package/dist/cjs/native-type-checker.js +6 -3
  17. package/dist/cjs/release-envelope/framework-output.js +27 -27
  18. package/dist/cjs/release-envelope/plugin.js +2 -1
  19. package/dist/esm/backend-federation-build/codegen.mjs +205 -0
  20. package/dist/esm/backend-federation-build/config.mjs +128 -0
  21. package/dist/esm/backend-federation-build/emit.mjs +99 -0
  22. package/dist/esm/backend-federation-build/index.mjs +1 -0
  23. package/dist/esm/build-config/build-environment.mjs +224 -0
  24. package/dist/esm/build-config/precompress/plugin.mjs +76 -0
  25. package/dist/esm/build-config/precompress/types.mjs +0 -0
  26. package/dist/esm/build-config/public.mjs +1 -0
  27. package/dist/esm/cloudflare/constants.mjs +1 -1
  28. package/dist/esm/cloudflare/delivery-unit.mjs +1 -1
  29. package/dist/esm/cloudflare-output-verifier/identity.mjs +1 -1
  30. package/dist/esm/config.mjs +1 -0
  31. package/dist/esm/deploy-output/npmAliases.mjs +174 -0
  32. package/dist/esm/deploy-output/plugin.mjs +28 -0
  33. package/dist/esm/deploy-output/target.mjs +10 -0
  34. package/dist/esm/native-type-checker.mjs +6 -3
  35. package/dist/esm/release-envelope/framework-output.mjs +1 -1
  36. package/dist/esm/release-envelope/plugin.mjs +2 -1
  37. package/dist/esm-node/backend-federation-build/codegen.mjs +206 -0
  38. package/dist/esm-node/backend-federation-build/config.mjs +129 -0
  39. package/dist/esm-node/backend-federation-build/emit.mjs +100 -0
  40. package/dist/esm-node/backend-federation-build/index.mjs +2 -0
  41. package/dist/esm-node/build-config/build-environment.mjs +225 -0
  42. package/dist/esm-node/build-config/precompress/plugin.mjs +77 -0
  43. package/dist/esm-node/build-config/precompress/types.mjs +1 -0
  44. package/dist/esm-node/build-config/public.mjs +2 -0
  45. package/dist/esm-node/cloudflare/constants.mjs +1 -1
  46. package/dist/esm-node/cloudflare/delivery-unit.mjs +1 -1
  47. package/dist/esm-node/cloudflare-output-verifier/identity.mjs +1 -1
  48. package/dist/esm-node/config.mjs +1 -0
  49. package/dist/esm-node/deploy-output/npmAliases.mjs +175 -0
  50. package/dist/esm-node/deploy-output/plugin.mjs +31 -0
  51. package/dist/esm-node/deploy-output/target.mjs +11 -0
  52. package/dist/esm-node/native-type-checker.mjs +6 -3
  53. package/dist/esm-node/release-envelope/framework-output.mjs +1 -1
  54. package/dist/esm-node/release-envelope/plugin.mjs +2 -1
  55. package/dist/types/backend-federation-build/codegen.d.ts +86 -0
  56. package/dist/types/backend-federation-build/config.d.ts +103 -0
  57. package/dist/types/backend-federation-build/emit.d.ts +21 -0
  58. package/dist/types/backend-federation-build/index.d.ts +2 -0
  59. package/dist/types/build-config/build-environment.d.ts +22 -0
  60. package/dist/types/build-config/precompress/plugin.d.ts +4 -0
  61. package/dist/types/build-config/precompress/types.d.ts +19 -0
  62. package/dist/types/build-config/public.d.ts +2 -0
  63. package/dist/types/cloudflare/constants.d.ts +1 -1
  64. package/dist/types/cloudflare/delivery-unit.d.ts +1 -1
  65. package/dist/types/cloudflare/worker-manifest.d.ts +2 -2
  66. package/dist/types/cloudflare-output-verifier/identity.d.ts +1 -1
  67. package/dist/types/config.d.ts +2 -0
  68. package/dist/types/deploy-output/npmAliases.d.ts +14 -0
  69. package/dist/types/deploy-output/plugin.d.ts +15 -0
  70. package/dist/types/deploy-output/target.d.ts +6 -0
  71. package/dist/types/precompress/LICENSE +20 -0
  72. package/dist/types/precompress/index.d.ts +76 -0
  73. package/package.json +50 -8
  74. package/src/backend-federation-build/codegen.ts +245 -0
  75. package/src/backend-federation-build/config.ts +376 -0
  76. package/src/backend-federation-build/emit.ts +205 -0
  77. package/src/backend-federation-build/index.ts +2 -0
  78. package/src/build-config/build-environment.ts +404 -0
  79. package/src/build-config/precompress/plugin.ts +140 -0
  80. package/src/build-config/precompress/types.ts +26 -0
  81. package/src/build-config/public.ts +6 -0
  82. package/src/cloudflare/constants.ts +1 -1
  83. package/src/cloudflare/delivery-unit.ts +2 -2
  84. package/src/cloudflare/worker-manifest.ts +1 -0
  85. package/src/cloudflare-builder.ts +1 -0
  86. package/src/cloudflare-output-verifier/identity.ts +1 -1
  87. package/src/config.ts +7 -0
  88. package/src/deploy-output/npmAliases.ts +333 -0
  89. package/src/deploy-output/plugin.ts +49 -0
  90. package/src/deploy-output/target.ts +23 -0
  91. package/src/native-type-checker.ts +11 -3
  92. package/src/release-envelope/framework-output.ts +1 -1
  93. package/src/release-envelope/plugin.ts +5 -1
@@ -0,0 +1,76 @@
1
+ import { constants } from "node:zlib";
2
+ import compression_webpack_plugin from "compression-webpack-plugin";
3
+ const DEFAULT_PRECOMPRESS_TEST = /\.(js|mjs|cjs|css|html|svg|json|map)$/i;
4
+ const DEFAULT_PRECOMPRESS_THRESHOLD = 10240;
5
+ const DEFAULT_PRECOMPRESS_MIN_RATIO = 0.8;
6
+ const createDefaultGzipOptions = ()=>({
7
+ algorithm: 'gzip',
8
+ filename: '[path][base].gz',
9
+ test: DEFAULT_PRECOMPRESS_TEST,
10
+ threshold: DEFAULT_PRECOMPRESS_THRESHOLD,
11
+ minRatio: DEFAULT_PRECOMPRESS_MIN_RATIO,
12
+ compressionOptions: {
13
+ level: 6
14
+ }
15
+ });
16
+ const createDefaultBrotliOptions = ()=>({
17
+ algorithm: 'brotliCompress',
18
+ filename: '[path][base].br',
19
+ test: DEFAULT_PRECOMPRESS_TEST,
20
+ threshold: DEFAULT_PRECOMPRESS_THRESHOLD,
21
+ minRatio: DEFAULT_PRECOMPRESS_MIN_RATIO,
22
+ compressionOptions: {
23
+ params: {
24
+ [constants.BROTLI_PARAM_QUALITY]: 9
25
+ }
26
+ }
27
+ });
28
+ const mergeCompressionOptions = (base, next)=>{
29
+ const merged = {
30
+ ...base,
31
+ ...next
32
+ };
33
+ if (base.compressionOptions || next.compressionOptions) {
34
+ const baseCompressionOptions = base.compressionOptions;
35
+ const nextCompressionOptions = next.compressionOptions;
36
+ const mergedCompressionOptions = {
37
+ ...baseCompressionOptions,
38
+ ...nextCompressionOptions
39
+ };
40
+ if (baseCompressionOptions?.params || nextCompressionOptions?.params) mergedCompressionOptions.params = {
41
+ ...baseCompressionOptions?.params,
42
+ ...nextCompressionOptions?.params
43
+ };
44
+ merged.compressionOptions = mergedCompressionOptions;
45
+ }
46
+ return merged;
47
+ };
48
+ const resolveCodecOptions = (codecConfig, createDefaultOptions)=>{
49
+ if (false === codecConfig) return null;
50
+ if (void 0 === codecConfig || true === codecConfig) return createDefaultOptions();
51
+ return mergeCompressionOptions(createDefaultOptions(), codecConfig);
52
+ };
53
+ const resolvePrecompressConfig = (precompress)=>{
54
+ if (false === precompress || void 0 === precompress) return false;
55
+ if (true === precompress) return {};
56
+ return precompress;
57
+ };
58
+ const builderPluginAdapterPrecompress = (precompress)=>({
59
+ name: 'builder-plugin-adapter-modern-precompress',
60
+ setup (api) {
61
+ api.modifyBundlerChain((chain, { isProd, target })=>{
62
+ if (!isProd || 'web' !== target) return;
63
+ const precompressConfig = resolvePrecompressConfig(precompress);
64
+ if (false === precompressConfig) return;
65
+ const gzipOptions = resolveCodecOptions(precompressConfig.gzip, createDefaultGzipOptions);
66
+ if (gzipOptions) chain.plugin('modern-precompress-gzip').use(compression_webpack_plugin, [
67
+ gzipOptions
68
+ ]);
69
+ const brotliOptions = resolveCodecOptions(precompressConfig.brotli, createDefaultBrotliOptions);
70
+ if (brotliOptions) chain.plugin('modern-precompress-brotli').use(compression_webpack_plugin, [
71
+ brotliOptions
72
+ ]);
73
+ });
74
+ }
75
+ });
76
+ export { builderPluginAdapterPrecompress };
File without changes
@@ -0,0 +1 @@
1
+ export { getBuildConfigEnvironment, resolveEffectTsgoCompiler, withBuildConfigEnvironment } from "./build-environment.mjs";
@@ -18,7 +18,7 @@ const DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES = [
18
18
  ];
19
19
  const BFF_EFFECT_WORKER_ENTRY = `${WORKER_BUNDLE_DIRECTORY}/__modern_bff_effect.js`;
20
20
  const BFF_EFFECT_WORKER_DISPATCHER_EXPORT = '__modern_create_effect_bff_dispatcher';
21
- 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.';
21
+ 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/bff-effect/effect-edge instead of lambda/Hono server helpers.';
22
22
  const DEFAULT_COMPATIBILITY_DATE = '2026-06-02';
23
23
  const COMPATIBILITY_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/u;
24
24
  const REQUIRED_COMPATIBILITY_FLAGS = CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS;
@@ -1,6 +1,6 @@
1
1
  import node_path from "node:path";
2
+ import { ULTRAMODERN_BUILD_ARTIFACT_PATH, ULTRAMODERN_BUILD_MODULE_PATH, isUltramodernBuildArtifact, nonEmptyString, toDeliveryUnitIdentity } from "@modern-js/backend-federation-contracts";
2
3
  import { fs } from "@modern-js/utils";
3
- import { ULTRAMODERN_BUILD_ARTIFACT_PATH, ULTRAMODERN_BUILD_MODULE_PATH, isUltramodernBuildArtifact, nonEmptyString, toDeliveryUnitIdentity } from "@modern-js/utils/universal";
4
4
  import { resolveUltramodernReleaseIdentity } from "../release-identity.mjs";
5
5
  import { isRecord } from "./utils.mjs";
6
6
  const COMPACT_CONFIG_PATH = '.modernjs/ultramodern.json';
@@ -1,4 +1,4 @@
1
- import { DELIVERY_UNIT_IDENTITY_FIELDS, deliveryUnitIdentityFieldValue } from "@modern-js/utils/universal";
1
+ import { DELIVERY_UNIT_IDENTITY_FIELDS, deliveryUnitIdentityFieldValue } from "@modern-js/backend-federation-contracts";
2
2
  import { addIssue, assertEqual } from "./issues.mjs";
3
3
  const verifyDeliveryUnitIdentity = (issues, manifest, manifestPath, declared)=>{
4
4
  const stamped = manifest?.deliveryUnit;
@@ -0,0 +1 @@
1
+ export { getBuildConfigEnvironment, resolveEffectTsgoCompiler, withBuildConfigEnvironment } from "./build-config/public.mjs";
@@ -0,0 +1,174 @@
1
+ import promises from "node:fs/promises";
2
+ import node_path from "node:path";
3
+ const dependencyKeys = [
4
+ 'dependencies',
5
+ 'optionalDependencies'
6
+ ];
7
+ const exactVersionPattern = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u;
8
+ async function readPackageJson(filePath) {
9
+ return JSON.parse(await promises.readFile(filePath, 'utf8'));
10
+ }
11
+ function parseNpmAlias(aliasName, specifier) {
12
+ if (!specifier.startsWith('npm:')) return;
13
+ const target = specifier.slice(4);
14
+ const versionSeparator = target.lastIndexOf('@');
15
+ if (versionSeparator <= 0 || versionSeparator === target.length - 1) throw new Error(`Invalid npm alias specifier for ${aliasName}: ${specifier}`);
16
+ return {
17
+ aliasName,
18
+ targetName: target.slice(0, versionSeparator),
19
+ targetVersion: target.slice(versionSeparator + 1)
20
+ };
21
+ }
22
+ function aliasesFromPackageJson(packageJson) {
23
+ const aliases = [];
24
+ for (const dependencyKey of dependencyKeys)for (const [aliasName, specifier] of Object.entries(packageJson[dependencyKey] ?? {})){
25
+ const alias = parseNpmAlias(aliasName, specifier);
26
+ if (alias) aliases.push(alias);
27
+ }
28
+ return aliases;
29
+ }
30
+ async function collectPackageRecords(nodeModulesDirectory) {
31
+ const records = [];
32
+ const visitedNodeModules = new Set();
33
+ const visitPackage = async (directory)=>{
34
+ const packageJsonPath = node_path.join(directory, 'package.json');
35
+ try {
36
+ const packageJson = await readPackageJson(packageJsonPath);
37
+ if (packageJson.name && packageJson.version) records.push({
38
+ directory,
39
+ packageJson
40
+ });
41
+ } catch (error) {
42
+ if ('ENOENT' !== error.code) throw error;
43
+ }
44
+ await visitNodeModules(node_path.join(directory, 'node_modules'));
45
+ };
46
+ const visitScope = async (scopeDirectory)=>{
47
+ const entries = await promises.readdir(scopeDirectory, {
48
+ withFileTypes: true
49
+ });
50
+ for (const entry of entries)if (entry.isDirectory()) await visitPackage(node_path.join(scopeDirectory, entry.name));
51
+ };
52
+ const visitNdepeStore = async (storeDirectory)=>{
53
+ const entries = await promises.readdir(storeDirectory, {
54
+ withFileTypes: true
55
+ });
56
+ for (const entry of entries)if (entry.isDirectory()) {
57
+ const entryPath = node_path.join(storeDirectory, entry.name);
58
+ if (entry.name.startsWith('@')) await visitScope(entryPath);
59
+ else await visitNodeModules(node_path.join(entryPath, 'node_modules'));
60
+ }
61
+ };
62
+ const visitNodeModules = async (directory)=>{
63
+ const resolvedDirectory = node_path.resolve(directory);
64
+ if (visitedNodeModules.has(resolvedDirectory)) return;
65
+ visitedNodeModules.add(resolvedDirectory);
66
+ let entries;
67
+ try {
68
+ entries = await promises.readdir(directory, {
69
+ withFileTypes: true
70
+ });
71
+ } catch (error) {
72
+ if ('ENOENT' === error.code) return;
73
+ throw error;
74
+ }
75
+ for (const entry of entries){
76
+ if (!entry.isDirectory()) continue;
77
+ const entryPath = node_path.join(directory, entry.name);
78
+ if ('.ndepe' === entry.name) await visitNdepeStore(entryPath);
79
+ else if (entry.name.startsWith('@')) await visitScope(entryPath);
80
+ else await visitPackage(entryPath);
81
+ }
82
+ };
83
+ await visitNodeModules(nodeModulesDirectory);
84
+ return records;
85
+ }
86
+ async function resolveAliasTarget(ownerDirectory, alias, outputDirectory) {
87
+ let directory = ownerDirectory;
88
+ const outputRoot = node_path.resolve(outputDirectory);
89
+ const resolvedOutputRoot = await promises.realpath(outputRoot);
90
+ while(directory === outputRoot || directory.startsWith(`${outputRoot}${node_path.sep}`)){
91
+ const candidate = node_path.join(directory, 'node_modules', alias.targetName);
92
+ try {
93
+ const resolvedCandidate = await promises.realpath(candidate);
94
+ if (resolvedCandidate !== resolvedOutputRoot && !resolvedCandidate.startsWith(`${resolvedOutputRoot}${node_path.sep}`)) throw new Error(`Cannot preserve npm alias ${alias.aliasName}: emitted target ${candidate} resolves outside deployment output to ${resolvedCandidate}`);
95
+ const packageJson = await readPackageJson(node_path.join(candidate, 'package.json'));
96
+ if (packageJson.name !== alias.targetName || !packageJson.version) throw new Error(`npm alias ${alias.aliasName} resolved ${candidate} to unexpected package ${String(packageJson.name)}`);
97
+ if (exactVersionPattern.test(alias.targetVersion) && packageJson.version !== alias.targetVersion) return;
98
+ return {
99
+ directory: candidate,
100
+ packageJson
101
+ };
102
+ } catch (error) {
103
+ if ('ENOENT' !== error.code) throw error;
104
+ }
105
+ if (directory === outputRoot) break;
106
+ directory = node_path.dirname(directory);
107
+ }
108
+ }
109
+ async function ensureAliasLink(ownerDirectory, alias, target) {
110
+ const aliasPath = node_path.join(ownerDirectory, 'node_modules', alias.aliasName);
111
+ await promises.mkdir(node_path.dirname(aliasPath), {
112
+ recursive: true
113
+ });
114
+ try {
115
+ const [existing, expected] = await Promise.all([
116
+ promises.realpath(aliasPath),
117
+ promises.realpath(target.directory)
118
+ ]);
119
+ if (existing === expected) return;
120
+ throw new Error(`Cannot preserve npm alias ${alias.aliasName}: ${aliasPath} already resolves to ${existing}, expected ${expected}`);
121
+ } catch (error) {
122
+ if ('ENOENT' !== error.code) throw error;
123
+ }
124
+ const linkTarget = node_path.relative(node_path.dirname(aliasPath), target.directory);
125
+ await promises.symlink(linkTarget, aliasPath, 'dir');
126
+ }
127
+ function aliasSpecifier(alias) {
128
+ return `npm:${alias.targetName}@${alias.targetVersion}`;
129
+ }
130
+ async function readPackageIdentity(entryPath) {
131
+ let directory = node_path.dirname(entryPath);
132
+ const root = node_path.parse(directory).root;
133
+ while(directory !== root){
134
+ try {
135
+ const packageJson = await readPackageJson(node_path.join(directory, 'package.json'));
136
+ if (packageJson.name && packageJson.version) return {
137
+ name: packageJson.name,
138
+ version: packageJson.version
139
+ };
140
+ } catch (error) {
141
+ if ('ENOENT' !== error.code) throw error;
142
+ }
143
+ directory = node_path.dirname(directory);
144
+ }
145
+ throw new Error(`Cannot find owning package for deployment entry ${entryPath}`);
146
+ }
147
+ async function preserveNpmAliases({ appDirectory, outputDirectory, implicitAliases = [] }) {
148
+ const records = await collectPackageRecords(node_path.join(outputDirectory, 'node_modules'));
149
+ const appPackageJson = await readPackageJson(node_path.join(appDirectory, 'package.json'));
150
+ const rootAliases = [
151
+ ...aliasesFromPackageJson(appPackageJson),
152
+ ...implicitAliases
153
+ ].filter((alias)=>alias.aliasName !== alias.targetName);
154
+ const emittedRootAliases = [];
155
+ for (const alias of rootAliases){
156
+ const target = await resolveAliasTarget(outputDirectory, alias, outputDirectory);
157
+ if (!target) {
158
+ if (implicitAliases.includes(alias)) throw new Error(`Cannot preserve implicit npm alias ${alias.aliasName}: emitted target ${alias.targetName}@${alias.targetVersion} is missing`);
159
+ continue;
160
+ }
161
+ await ensureAliasLink(outputDirectory, alias, target);
162
+ emittedRootAliases.push(alias);
163
+ }
164
+ for (const record of records)for (const alias of aliasesFromPackageJson(record.packageJson).filter((candidate)=>candidate.aliasName !== candidate.targetName)){
165
+ const target = await resolveAliasTarget(record.directory, alias, outputDirectory);
166
+ if (target) await ensureAliasLink(record.directory, alias, target);
167
+ }
168
+ const outputPackageJsonPath = node_path.join(outputDirectory, 'package.json');
169
+ const outputPackageJson = await readPackageJson(outputPackageJsonPath);
170
+ outputPackageJson.dependencies ??= {};
171
+ for (const alias of emittedRootAliases)outputPackageJson.dependencies[alias.aliasName] = aliasSpecifier(alias);
172
+ await promises.writeFile(outputPackageJsonPath, `${JSON.stringify(outputPackageJson, null, 2)}\n`);
173
+ }
174
+ export { preserveNpmAliases, readPackageIdentity };
@@ -0,0 +1,28 @@
1
+ import { createRequire } from "node:module";
2
+ import node_path from "node:path";
3
+ import { preserveNpmAliases, readPackageIdentity } from "./npmAliases.mjs";
4
+ import { resolveDeployTarget as external_target_mjs_resolveDeployTarget } from "./target.mjs";
5
+ const createDeployOutputAliasesPlugin = ({ resolveDeployTarget = external_target_mjs_resolveDeployTarget } = {})=>({
6
+ name: '@modern-js/deploy-output-aliases',
7
+ setup (api) {
8
+ api.onAfterDeploy(async ()=>{
9
+ const { appDirectory, metaName } = api.getAppContext();
10
+ const config = api.getNormalizedConfig();
11
+ if ('modern-js' !== metaName && !config.deploy?.target && !process.env.MODERNJS_DEPLOY || 'node' !== resolveDeployTarget(config)) return;
12
+ const entry = createRequire(__filename).resolve('@modern-js/prod-server');
13
+ const identity = await readPackageIdentity(entry);
14
+ await preserveNpmAliases({
15
+ appDirectory,
16
+ outputDirectory: node_path.join(appDirectory, '.output'),
17
+ implicitAliases: [
18
+ {
19
+ aliasName: '@modern-js/prod-server',
20
+ targetName: identity.name,
21
+ targetVersion: identity.version
22
+ }
23
+ ]
24
+ });
25
+ });
26
+ }
27
+ });
28
+ export { createDeployOutputAliasesPlugin };
@@ -0,0 +1,10 @@
1
+ import { provider } from "std-env";
2
+ const providerDeployTargets = {
3
+ vercel: 'vercel',
4
+ netlify: 'netlify',
5
+ cloudflare: 'cloudflare',
6
+ cloudflare_pages: 'cloudflare',
7
+ cloudflare_workers: 'cloudflare'
8
+ };
9
+ const resolveDeployTarget = (config, envDeployTarget = process.env.MODERNJS_DEPLOY, detectedProvider = provider)=>config.deploy?.target || envDeployTarget || (detectedProvider ? providerDeployTargets[detectedProvider] : void 0) || 'node';
10
+ export { resolveDeployTarget };
@@ -1,8 +1,10 @@
1
1
  import { execFile } from "node:child_process";
2
+ import { realpathSync } from "node:fs";
2
3
  import node_path from "node:path";
3
4
  import { promisify } from "node:util";
4
5
  const execute = promisify(execFile);
5
6
  const native_type_checker_name = 'UltramodernNativeTypeChecker';
7
+ const watchDependencyPath = (file)=>'win32' === process.platform ? realpathSync.native(file) : file;
6
8
  class UltramodernNativeTypeChecker {
7
9
  async check() {
8
10
  const { configFile, build } = this.options;
@@ -30,7 +32,8 @@ class UltramodernNativeTypeChecker {
30
32
  return result.stdout;
31
33
  } catch (cause) {
32
34
  const output = cause;
33
- throw new Error(`${native_type_checker_name} failed:\n${output.stdout ?? ''}${output.stderr ?? ''}`, {
35
+ const diagnostics = `${output.stdout ?? ''}${output.stderr ?? ''}`;
36
+ throw new Error(`${native_type_checker_name} failed:\n${diagnostics || (cause instanceof Error ? cause.message : String(cause))}`, {
34
37
  cause
35
38
  });
36
39
  }
@@ -61,10 +64,10 @@ class UltramodernNativeTypeChecker {
61
64
  }
62
65
  apply(compiler) {
63
66
  compiler.hooks.thisCompilation.tap(native_type_checker_name, (compilation)=>{
64
- compilation.fileDependencies.add(this.options.configFile);
65
67
  compilation.hooks.processAssets.tapPromise(native_type_checker_name, async ()=>{
66
68
  try {
67
- for (const file of (await this.watchInputs()))compilation.fileDependencies.add(file);
69
+ compilation.fileDependencies.add(watchDependencyPath(this.options.configFile));
70
+ for (const file of (await this.watchInputs()))compilation.fileDependencies.add(watchDependencyPath(file));
68
71
  await this.check();
69
72
  } catch (cause) {
70
73
  compilation.errors.push(new Error(cause instanceof Error ? cause.message : String(cause), {
@@ -1,7 +1,7 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import promises from "node:fs/promises";
3
3
  import node_path from "node:path";
4
- import { BACKEND_FEDERATION_MANIFEST_FILE, BACKEND_FEDERATION_REMOTE_ENTRY_FILE, ULTRAMODERN_BUILD_ARTIFACT_FILE, isUltramodernBuildArtifact } from "@modern-js/utils/universal";
4
+ import { BACKEND_FEDERATION_MANIFEST_FILE, BACKEND_FEDERATION_REMOTE_ENTRY_FILE, ULTRAMODERN_BUILD_ARTIFACT_FILE, isUltramodernBuildArtifact } from "@modern-js/backend-federation-contracts";
5
5
  import { canonicalSerializeMicroVerticalReleaseEnvelope, createMicroVerticalReleaseEnvelope, verifyMicroVerticalReleaseEnvelope } from "./index.mjs";
6
6
  const MICROVERTICAL_RELEASE_ENVELOPE_PATH = 'release/microvertical-release-envelope.json';
7
7
  const MICROVERTICAL_RELEASE_IDENTITY_CARRIERS_PATH = 'release/microvertical-release-identity-carriers.json';
@@ -10,7 +10,8 @@ const createUltramodernReleaseEnvelopePlugin = ({ resolveDeployTarget })=>({
10
10
  name: '@modern-js/ultramodern-release-envelope',
11
11
  pre: [
12
12
  '@modern-js/backend-federation-build',
13
- '@modern-js/plugin-bff'
13
+ '@modern-js/plugin-bff',
14
+ '@modern-js/deploy-output-aliases'
14
15
  ],
15
16
  post: [
16
17
  '@modern-js/plugin-deploy'
@@ -0,0 +1,206 @@
1
+ import "node:module";
2
+ import node_path from "node:path";
3
+ import { BACKEND_FEDERATION_CONTRACT_VERSION, BACKEND_FEDERATION_EFFECT_EXPOSE, BACKEND_FEDERATION_NODE_ADAPTER_VERSION, BACKEND_FEDERATION_REMOTE_ENTRY_FILE, formatBackendFederationValidationErrors, validateBackendFederationManifest } from "@modern-js/backend-federation-contracts";
4
+ import { build } from "esbuild";
5
+ import { normalizeRelativePath } from "./config.mjs";
6
+ const createRelativeImportSpecifier = (fromDirectory, toFile)=>{
7
+ const relativePath = normalizeRelativePath(node_path.relative(fromDirectory, toFile));
8
+ return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
9
+ };
10
+ const createPublicPath = (containerEntry, fallbackPort)=>{
11
+ try {
12
+ return new URL('.', containerEntry).href;
13
+ } catch {
14
+ const slashIndex = containerEntry.lastIndexOf('/');
15
+ if (slashIndex >= 0) return containerEntry.slice(0, slashIndex + 1);
16
+ return `http://localhost:${fallbackPort}/`;
17
+ }
18
+ };
19
+ const createBackendRemoteEntrySource = async (workspaceRoot, app, effectApiPath, entryPath)=>{
20
+ const effectApiSpecifier = createRelativeImportSpecifier(node_path.dirname(effectApiPath), effectApiPath);
21
+ const containerMetadata = {
22
+ buildVersion: app.buildVersion,
23
+ expose: BACKEND_FEDERATION_EFFECT_EXPOSE,
24
+ name: app.backendName,
25
+ packageName: app.packageName,
26
+ remoteType: app.remoteType,
27
+ source: normalizeRelativePath(node_path.relative(workspaceRoot, effectApiPath)),
28
+ version: app.version,
29
+ ...app.unitId ? {
30
+ unitId: app.unitId
31
+ } : {},
32
+ ...app.sourceRevision ? {
33
+ sourceRevision: app.sourceRevision
34
+ } : {}
35
+ };
36
+ const compatibility = {
37
+ build: app.buildVersion,
38
+ contractVersion: BACKEND_FEDERATION_CONTRACT_VERSION,
39
+ nodeAdapterVersion: BACKEND_FEDERATION_NODE_ADAPTER_VERSION,
40
+ packageName: app.packageName,
41
+ ...app.unitId ? {
42
+ unitId: app.unitId
43
+ } : {},
44
+ ...app.sourceRevision ? {
45
+ sourceRevision: app.sourceRevision
46
+ } : {}
47
+ };
48
+ const source = `// Generated by Modern.js backend federation build.
49
+ import * as exposedNamespace from ${JSON.stringify(effectApiSpecifier)};
50
+
51
+ const exposedModule = {
52
+ ...exposedNamespace,
53
+ backendFederationContract: {
54
+ ...(exposedNamespace.backendFederationContract ?? {}),
55
+ compatibility: {
56
+ ...(exposedNamespace.backendFederationContract?.compatibility ?? {}),
57
+ ...${JSON.stringify(compatibility)},
58
+ },
59
+ name: ${JSON.stringify(app.backendName)},
60
+ role: 'microvertical-server',
61
+ runtimeFramework: 'effect',
62
+ strictEffectApproach: true,
63
+ },
64
+ };
65
+ const exposedModules = {
66
+ ${JSON.stringify(BACKEND_FEDERATION_EFFECT_EXPOSE)}: () => Promise.resolve(exposedModule),
67
+ };
68
+ const __modernjsBackendFederation = ${JSON.stringify(containerMetadata)};
69
+
70
+ function init() {}
71
+
72
+ function get(id) {
73
+ const load = exposedModules[id];
74
+ if (!load) {
75
+ throw new Error(\`Unexpected backend federation expose: \${id}\`);
76
+ }
77
+
78
+ return async () => load();
79
+ }
80
+
81
+ module.exports = { __modernjsBackendFederation, get, init };
82
+ `;
83
+ const result = await build({
84
+ absWorkingDir: node_path.dirname(effectApiPath),
85
+ bundle: true,
86
+ format: 'cjs',
87
+ logLevel: 'silent',
88
+ platform: 'node',
89
+ stdin: {
90
+ contents: source,
91
+ loader: 'ts',
92
+ resolveDir: node_path.dirname(effectApiPath),
93
+ sourcefile: node_path.basename(entryPath)
94
+ },
95
+ target: 'node20',
96
+ write: false
97
+ });
98
+ const output = result.outputFiles[0];
99
+ if (!output) throw new Error('[backend-federation-build] CommonJS backend federation container emitted no output.');
100
+ return output.text;
101
+ };
102
+ const createBackendManifest = (workspaceRoot, distDirectory, app, entryIntegrity)=>{
103
+ const sourceModule = `${app.directory}/api/effect-api.ts`;
104
+ const publicPath = createPublicPath(app.containerEntry, app.port);
105
+ const manifest = {
106
+ schemaVersion: 1,
107
+ id: app.backendName,
108
+ name: app.backendName,
109
+ version: app.version,
110
+ buildVersion: app.buildVersion,
111
+ metaData: {
112
+ name: app.backendName,
113
+ type: 'backend',
114
+ buildInfo: {
115
+ buildVersion: app.buildVersion,
116
+ buildName: app.packageName
117
+ },
118
+ remoteEntry: {
119
+ name: BACKEND_FEDERATION_REMOTE_ENTRY_FILE,
120
+ path: '',
121
+ type: app.remoteType
122
+ },
123
+ globalName: app.backendName,
124
+ publicPath,
125
+ ssrRemoteEntry: {
126
+ name: BACKEND_FEDERATION_REMOTE_ENTRY_FILE,
127
+ path: '',
128
+ type: app.remoteType
129
+ },
130
+ ssrPublicPath: publicPath
131
+ },
132
+ entry: {
133
+ ...entryIntegrity,
134
+ file: BACKEND_FEDERATION_REMOTE_ENTRY_FILE,
135
+ path: normalizeRelativePath(node_path.relative(workspaceRoot, node_path.join(distDirectory, BACKEND_FEDERATION_REMOTE_ENTRY_FILE))),
136
+ type: app.remoteType,
137
+ url: app.containerEntry
138
+ },
139
+ exposes: [
140
+ {
141
+ id: `${app.backendName}:${BACKEND_FEDERATION_EFFECT_EXPOSE}`,
142
+ name: BACKEND_FEDERATION_EFFECT_EXPOSE,
143
+ path: '',
144
+ assets: {
145
+ js: {
146
+ async: [],
147
+ sync: [
148
+ BACKEND_FEDERATION_REMOTE_ENTRY_FILE
149
+ ]
150
+ },
151
+ css: {
152
+ async: [],
153
+ sync: []
154
+ }
155
+ }
156
+ }
157
+ ],
158
+ shared: [],
159
+ backendFederation: {
160
+ role: 'microvertical-server',
161
+ appId: app.id,
162
+ name: app.backendName,
163
+ runtimeFramework: 'effect',
164
+ strictEffectApproach: true,
165
+ contractVersion: BACKEND_FEDERATION_CONTRACT_VERSION,
166
+ nodeAdapterVersion: BACKEND_FEDERATION_NODE_ADAPTER_VERSION,
167
+ remoteType: app.remoteType,
168
+ expose: BACKEND_FEDERATION_EFFECT_EXPOSE,
169
+ manifestUrl: app.manifestUrl,
170
+ containerEntry: app.containerEntry,
171
+ source: {
172
+ module: sourceModule
173
+ },
174
+ readinessPath: `${app.apiPrefix}/${app.apiStem}/readiness`,
175
+ openapiPath: `${app.apiPrefix}/openapi.json`,
176
+ ...app.deliveryUnit ? {
177
+ deliveryUnit: app.deliveryUnit
178
+ } : {},
179
+ versionBoundary: {
180
+ invariant: 'web-and-api-same-build',
181
+ packageName: app.packageName,
182
+ version: app.version,
183
+ buildVersion: app.buildVersion,
184
+ ...app.uiManifestUrl ? {
185
+ uiManifestUrl: app.uiManifestUrl
186
+ } : {},
187
+ ...app.deliveryUnit ? {
188
+ deliveryUnit: {
189
+ unitId: app.deliveryUnit.unitId,
190
+ buildMarker: app.deliveryUnit.buildMarker,
191
+ sourceRevision: app.deliveryUnit.sourceRevision
192
+ }
193
+ } : {}
194
+ }
195
+ }
196
+ };
197
+ const validation = validateBackendFederationManifest(manifest, {
198
+ path: 'backendFederationManifest',
199
+ requireEffectExpose: true,
200
+ requireEffectRuntime: true,
201
+ requireVersionFields: true
202
+ });
203
+ if (!validation.ok) throw new Error(`[backend-federation-build] Invalid backend federation manifest: ${formatBackendFederationValidationErrors(validation.errors)}.`);
204
+ return manifest;
205
+ };
206
+ export { createBackendManifest, createBackendRemoteEntrySource };