@bleedingdev/modern-js-app-tools 3.9.0-ultramodern.4 → 3.9.0-ultramodern.6
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/dist/cjs/builder/generator/index.js +0 -1
- package/dist/cjs/builder/shared/builderPlugins/index.js +4 -11
- package/dist/cjs/config/index.js +4 -11
- package/dist/cjs/index.js +80 -111
- package/dist/cjs/plugins/deploy/platforms/node.js +0 -13
- package/dist/cjs/plugins/serverBuild.js +2 -1
- package/dist/esm/builder/generator/index.mjs +1 -2
- package/dist/esm/builder/shared/builderPlugins/index.mjs +0 -1
- package/dist/esm/config/index.mjs +0 -1
- package/dist/esm/index.mjs +1 -6
- package/dist/esm/plugins/deploy/platforms/node.mjs +0 -13
- package/dist/esm/plugins/serverBuild.mjs +2 -1
- package/dist/esm-node/builder/generator/index.mjs +1 -2
- package/dist/esm-node/builder/shared/builderPlugins/index.mjs +0 -1
- package/dist/esm-node/config/index.mjs +0 -1
- package/dist/esm-node/index.mjs +1 -6
- package/dist/esm-node/plugins/deploy/platforms/node.mjs +0 -13
- package/dist/esm-node/plugins/serverBuild.mjs +2 -1
- package/dist/types/builder/shared/builderPlugins/index.d.ts +0 -1
- package/dist/types/config/index.d.ts +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/plugins/deploy/utils/generator.d.ts +1 -1
- package/dist/types/types/config/output.d.ts +0 -9
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/plugin.d.ts +56 -2
- package/dist/types/utils/initAppContext.d.ts +3 -2
- package/docs/configure/app/bff/effect.md +29 -24
- package/docs/guides/advanced-features/bff/data-platform.md +2 -2
- package/docs/guides/advanced-features/bff/frameworks.md +36 -24
- package/docs/guides/advanced-features/bff/function.md +2 -2
- package/docs/guides/advanced-features/bff/operators.md +17 -17
- package/docs/guides/get-started/quick-start.md +1 -5
- package/docs/guides/get-started/ultramodern.md +5 -86
- package/docs/llms.txt +2 -2
- package/package.json +14 -30
- package/rslib.config.mts +0 -5
- package/dist/cjs/builder/shared/builderPlugins/adapterPrecompress.js +0 -125
- package/dist/cjs/config/build-environment.js +0 -268
- package/dist/cjs/config/public.js +0 -46
- package/dist/cjs/plugins/backend-federation/codegen.js +0 -256
- package/dist/cjs/plugins/backend-federation/config.js +0 -204
- package/dist/cjs/plugins/backend-federation/emit.js +0 -150
- package/dist/cjs/plugins/backendFederationBuild.js +0 -53
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/index.js +0 -62
- package/dist/cjs/plugins/deploy/utils/npmAliases.js +0 -226
- package/dist/cjs/plugins/ultramodernReleaseEnvelope.js +0 -44
- package/dist/cjs/presetUltramodern.js +0 -175
- package/dist/cjs/types/config/precompress.js +0 -18
- package/dist/esm/builder/shared/builderPlugins/adapterPrecompress.mjs +0 -77
- package/dist/esm/config/build-environment.mjs +0 -224
- package/dist/esm/config/public.mjs +0 -1
- package/dist/esm/plugins/backend-federation/codegen.mjs +0 -205
- package/dist/esm/plugins/backend-federation/config.mjs +0 -128
- package/dist/esm/plugins/backend-federation/emit.mjs +0 -99
- package/dist/esm/plugins/backendFederationBuild.mjs +0 -1
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +0 -1
- package/dist/esm/plugins/deploy/utils/npmAliases.mjs +0 -174
- package/dist/esm/plugins/ultramodernReleaseEnvelope.mjs +0 -6
- package/dist/esm/presetUltramodern.mjs +0 -119
- package/dist/esm/types/config/precompress.mjs +0 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterPrecompress.mjs +0 -78
- package/dist/esm-node/config/build-environment.mjs +0 -225
- package/dist/esm-node/config/public.mjs +0 -2
- package/dist/esm-node/plugins/backend-federation/codegen.mjs +0 -206
- package/dist/esm-node/plugins/backend-federation/config.mjs +0 -129
- package/dist/esm-node/plugins/backend-federation/emit.mjs +0 -100
- package/dist/esm-node/plugins/backendFederationBuild.mjs +0 -2
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +0 -2
- package/dist/esm-node/plugins/deploy/utils/npmAliases.mjs +0 -175
- package/dist/esm-node/plugins/ultramodernReleaseEnvelope.mjs +0 -7
- package/dist/esm-node/presetUltramodern.mjs +0 -120
- package/dist/esm-node/types/config/precompress.mjs +0 -1
- package/dist/types/builder/shared/builderPlugins/adapterPrecompress.d.ts +0 -3
- package/dist/types/config/build-environment.d.ts +0 -22
- package/dist/types/config/public.d.ts +0 -2
- package/dist/types/plugins/backend-federation/codegen.d.ts +0 -86
- package/dist/types/plugins/backend-federation/config.d.ts +0 -103
- package/dist/types/plugins/backend-federation/emit.d.ts +0 -13
- package/dist/types/plugins/backendFederationBuild.d.ts +0 -2
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/index.d.ts +0 -1
- package/dist/types/plugins/deploy/utils/npmAliases.d.ts +0 -14
- package/dist/types/plugins/ultramodernReleaseEnvelope.d.ts +0 -3
- package/dist/types/precompress/LICENSE +0 -20
- package/dist/types/precompress/index.d.ts +0 -76
- package/dist/types/presetUltramodern.d.ts +0 -87
- package/dist/types/types/config/precompress.d.ts +0 -19
|
@@ -1,174 +0,0 @@
|
|
|
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 };
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { createUltramodernReleaseEnvelopePlugin } from "@modern-js/app-tools-extensions/release-envelope/plugin";
|
|
2
|
-
import { resolveDeployTarget } from "./deploy/index.mjs";
|
|
3
|
-
const ultramodernReleaseEnvelope = ()=>createUltramodernReleaseEnvelopePlugin({
|
|
4
|
-
resolveDeployTarget: resolveDeployTarget
|
|
5
|
-
});
|
|
6
|
-
export default ultramodernReleaseEnvelope;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import node_fs from "node:fs";
|
|
2
|
-
import node_path from "node:path";
|
|
3
|
-
import { configureUltramodernTypeChecker } from "@modern-js/app-tools-extensions/native-type-checker";
|
|
4
|
-
import { resolveUltramodernReleaseIdentity } from "@modern-js/app-tools-extensions/release-identity";
|
|
5
|
-
import { mergeConfig } from "@modern-js/plugin/cli";
|
|
6
|
-
import { rspack } from "@rsbuild/core";
|
|
7
|
-
import { resolveEffectTsgoCompiler } from "./config/build-environment.mjs";
|
|
8
|
-
const DEFAULT_OTLP_ENDPOINT = 'http://127.0.0.1:4318/v1/logs';
|
|
9
|
-
const DEFAULT_VICTORIA_METRICS_ENDPOINT = 'http://127.0.0.1:8428/api/v1/import/prometheus';
|
|
10
|
-
const resolveReactRouterPackageDir = (appDirectory)=>{
|
|
11
|
-
const resolveNodeModulePackageJson = (packageName, fromDirectory)=>{
|
|
12
|
-
let currentDirectory = node_path.resolve(fromDirectory);
|
|
13
|
-
while(true){
|
|
14
|
-
const packageJson = node_path.join(currentDirectory, 'node_modules', packageName, 'package.json');
|
|
15
|
-
if (node_fs.existsSync(packageJson)) return node_fs.realpathSync(packageJson);
|
|
16
|
-
const parentDirectory = node_path.dirname(currentDirectory);
|
|
17
|
-
if (parentDirectory === currentDirectory) return;
|
|
18
|
-
currentDirectory = parentDirectory;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const reactRouterPackageJson = resolveNodeModulePackageJson('react-router', appDirectory);
|
|
22
|
-
if (reactRouterPackageJson) return node_path.dirname(reactRouterPackageJson);
|
|
23
|
-
const reactRouterDomPackageJson = resolveNodeModulePackageJson('react-router-dom', appDirectory);
|
|
24
|
-
if (!reactRouterDomPackageJson) return;
|
|
25
|
-
const nestedReactRouterPackageJson = resolveNodeModulePackageJson('react-router', node_path.dirname(reactRouterDomPackageJson));
|
|
26
|
-
if (nestedReactRouterPackageJson) return node_path.dirname(nestedReactRouterPackageJson);
|
|
27
|
-
};
|
|
28
|
-
const setReactRouterBridgeSafeAliases = (chain, { isProd })=>{
|
|
29
|
-
const chainContext = chain.get('context');
|
|
30
|
-
const appDirectory = 'string' == typeof chainContext && chainContext.length > 0 ? chainContext : process.cwd();
|
|
31
|
-
const reactRouterPackageDir = resolveReactRouterPackageDir(appDirectory);
|
|
32
|
-
if (!reactRouterPackageDir) return;
|
|
33
|
-
const productionEntry = node_path.join(reactRouterPackageDir, 'dist/production/index.mjs');
|
|
34
|
-
const developmentEntry = node_path.join(reactRouterPackageDir, 'dist/development/index.mjs');
|
|
35
|
-
chain.resolve.alias.set('react-router$', isProd ? productionEntry : developmentEntry);
|
|
36
|
-
chain.resolve.alias.set('react-router/dist/production/index.js', productionEntry);
|
|
37
|
-
chain.resolve.alias.set('react-router/dist/development/index.js', developmentEntry);
|
|
38
|
-
};
|
|
39
|
-
const createPresetUltramodernConfig = (options = {})=>{
|
|
40
|
-
const { appId = 'app', deliveryUnit, enableBffRequestId = true, enableTelemetry = true, enableTelemetryExporters, otlpEndpoint = process.env.MODERN_TELEMETRY_OTLP_ENDPOINT, victoriaMetricsEndpoint = process.env.MODERN_TELEMETRY_VICTORIA_ENDPOINT, telemetryFailLoudStartup = false, enableModuleFederationSSR = true } = options;
|
|
41
|
-
const server = {};
|
|
42
|
-
const releaseIdentity = deliveryUnit ? resolveUltramodernReleaseIdentity({
|
|
43
|
-
generationBuildMarker: deliveryUnit.buildMarker,
|
|
44
|
-
unitId: deliveryUnit.unitId
|
|
45
|
-
}) : void 0;
|
|
46
|
-
const bundledReleaseIdentity = releaseIdentity ? {
|
|
47
|
-
...releaseIdentity,
|
|
48
|
-
releaseVersion: deliveryUnit.version
|
|
49
|
-
} : void 0;
|
|
50
|
-
if (enableTelemetry) {
|
|
51
|
-
server.telemetry = {
|
|
52
|
-
enabled: true,
|
|
53
|
-
failLoudStartup: telemetryFailLoudStartup
|
|
54
|
-
};
|
|
55
|
-
if (false !== enableTelemetryExporters) {
|
|
56
|
-
const exporters = {};
|
|
57
|
-
if (true === enableTelemetryExporters || otlpEndpoint) exporters.otlp = {
|
|
58
|
-
enabled: true,
|
|
59
|
-
endpoint: otlpEndpoint || DEFAULT_OTLP_ENDPOINT
|
|
60
|
-
};
|
|
61
|
-
if (true === enableTelemetryExporters || victoriaMetricsEndpoint) exporters.victoriaMetrics = {
|
|
62
|
-
enabled: true,
|
|
63
|
-
endpoint: victoriaMetricsEndpoint || DEFAULT_VICTORIA_METRICS_ENDPOINT
|
|
64
|
-
};
|
|
65
|
-
if (Object.keys(exporters).length > 0) server.telemetry.exporters = exporters;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (enableModuleFederationSSR) server.ssr = {
|
|
69
|
-
mode: 'stream',
|
|
70
|
-
moduleFederationAppSSR: true
|
|
71
|
-
};
|
|
72
|
-
const presetConfig = {
|
|
73
|
-
output: {
|
|
74
|
-
precompress: true
|
|
75
|
-
},
|
|
76
|
-
server,
|
|
77
|
-
source: {
|
|
78
|
-
reactCompiler: true,
|
|
79
|
-
...deliveryUnit ? {
|
|
80
|
-
globalVars: {
|
|
81
|
-
ULTRAMODERN_BUILD_MARKER: releaseIdentity?.buildMarker,
|
|
82
|
-
ULTRAMODERN_RELEASE_VERSION: deliveryUnit.version,
|
|
83
|
-
ULTRAMODERN_SOURCE_REVISION: releaseIdentity?.sourceRevision
|
|
84
|
-
}
|
|
85
|
-
} : {}
|
|
86
|
-
},
|
|
87
|
-
tools: {
|
|
88
|
-
bundlerChain: (chain, utils)=>{
|
|
89
|
-
setReactRouterBridgeSafeAliases(chain, utils);
|
|
90
|
-
configureUltramodernTypeChecker(chain, utils.CHAIN_ID.PLUGIN.TS_CHECKER, (from)=>resolveEffectTsgoCompiler({
|
|
91
|
-
from
|
|
92
|
-
}));
|
|
93
|
-
},
|
|
94
|
-
lightningcssLoader: true,
|
|
95
|
-
...bundledReleaseIdentity ? {
|
|
96
|
-
rspack: (config)=>{
|
|
97
|
-
config.plugins ??= [];
|
|
98
|
-
config.plugins.push(new rspack.BannerPlugin({
|
|
99
|
-
banner: `void ${JSON.stringify(bundledReleaseIdentity.buildMarker)};void ${JSON.stringify(bundledReleaseIdentity.sourceRevision)};void ${JSON.stringify(bundledReleaseIdentity.releaseVersion)};`,
|
|
100
|
-
raw: true,
|
|
101
|
-
stage: rspack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE,
|
|
102
|
-
test: /\.(?:c|m)?js$/u
|
|
103
|
-
}));
|
|
104
|
-
return config;
|
|
105
|
-
}
|
|
106
|
-
} : {}
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
if (enableBffRequestId) presetConfig.bff = {
|
|
110
|
-
requestId: appId
|
|
111
|
-
};
|
|
112
|
-
return presetConfig;
|
|
113
|
-
};
|
|
114
|
-
const presetUltramodern = (config, options = {})=>mergeConfig([
|
|
115
|
-
createPresetUltramodernConfig(options),
|
|
116
|
-
config
|
|
117
|
-
]);
|
|
118
|
-
export { default as ultramodernReleaseEnvelopePlugin } from "./plugins/ultramodernReleaseEnvelope.mjs";
|
|
119
|
-
export { createPresetUltramodernConfig, presetUltramodern };
|
|
File without changes
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { constants } from "node:zlib";
|
|
3
|
-
import compression_webpack_plugin from "compression-webpack-plugin";
|
|
4
|
-
const DEFAULT_PRECOMPRESS_TEST = /\.(js|mjs|cjs|css|html|svg|json|map)$/i;
|
|
5
|
-
const DEFAULT_PRECOMPRESS_THRESHOLD = 10240;
|
|
6
|
-
const DEFAULT_PRECOMPRESS_MIN_RATIO = 0.8;
|
|
7
|
-
const createDefaultGzipOptions = ()=>({
|
|
8
|
-
algorithm: 'gzip',
|
|
9
|
-
filename: '[path][base].gz',
|
|
10
|
-
test: DEFAULT_PRECOMPRESS_TEST,
|
|
11
|
-
threshold: DEFAULT_PRECOMPRESS_THRESHOLD,
|
|
12
|
-
minRatio: DEFAULT_PRECOMPRESS_MIN_RATIO,
|
|
13
|
-
compressionOptions: {
|
|
14
|
-
level: 6
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
const createDefaultBrotliOptions = ()=>({
|
|
18
|
-
algorithm: 'brotliCompress',
|
|
19
|
-
filename: '[path][base].br',
|
|
20
|
-
test: DEFAULT_PRECOMPRESS_TEST,
|
|
21
|
-
threshold: DEFAULT_PRECOMPRESS_THRESHOLD,
|
|
22
|
-
minRatio: DEFAULT_PRECOMPRESS_MIN_RATIO,
|
|
23
|
-
compressionOptions: {
|
|
24
|
-
params: {
|
|
25
|
-
[constants.BROTLI_PARAM_QUALITY]: 9
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
const mergeCompressionOptions = (base, next)=>{
|
|
30
|
-
const merged = {
|
|
31
|
-
...base,
|
|
32
|
-
...next
|
|
33
|
-
};
|
|
34
|
-
if (base.compressionOptions || next.compressionOptions) {
|
|
35
|
-
const baseCompressionOptions = base.compressionOptions;
|
|
36
|
-
const nextCompressionOptions = next.compressionOptions;
|
|
37
|
-
const mergedCompressionOptions = {
|
|
38
|
-
...baseCompressionOptions,
|
|
39
|
-
...nextCompressionOptions
|
|
40
|
-
};
|
|
41
|
-
if (baseCompressionOptions?.params || nextCompressionOptions?.params) mergedCompressionOptions.params = {
|
|
42
|
-
...baseCompressionOptions?.params,
|
|
43
|
-
...nextCompressionOptions?.params
|
|
44
|
-
};
|
|
45
|
-
merged.compressionOptions = mergedCompressionOptions;
|
|
46
|
-
}
|
|
47
|
-
return merged;
|
|
48
|
-
};
|
|
49
|
-
const resolveCodecOptions = (codecConfig, createDefaultOptions)=>{
|
|
50
|
-
if (false === codecConfig) return null;
|
|
51
|
-
if (void 0 === codecConfig || true === codecConfig) return createDefaultOptions();
|
|
52
|
-
return mergeCompressionOptions(createDefaultOptions(), codecConfig);
|
|
53
|
-
};
|
|
54
|
-
const resolvePrecompressConfig = (normalizedConfig)=>{
|
|
55
|
-
const precompress = normalizedConfig.output.precompress;
|
|
56
|
-
if (false === precompress || void 0 === precompress) return false;
|
|
57
|
-
if (true === precompress) return {};
|
|
58
|
-
return precompress;
|
|
59
|
-
};
|
|
60
|
-
const builderPluginAdapterPrecompress = (options)=>({
|
|
61
|
-
name: 'builder-plugin-adapter-modern-precompress',
|
|
62
|
-
setup (api) {
|
|
63
|
-
api.modifyBundlerChain((chain, { isProd, target })=>{
|
|
64
|
-
if (!isProd || 'web' !== target) return;
|
|
65
|
-
const precompressConfig = resolvePrecompressConfig(options.normalizedConfig);
|
|
66
|
-
if (false === precompressConfig) return;
|
|
67
|
-
const gzipOptions = resolveCodecOptions(precompressConfig.gzip, createDefaultGzipOptions);
|
|
68
|
-
if (gzipOptions) chain.plugin('modern-precompress-gzip').use(compression_webpack_plugin, [
|
|
69
|
-
gzipOptions
|
|
70
|
-
]);
|
|
71
|
-
const brotliOptions = resolveCodecOptions(precompressConfig.brotli, createDefaultBrotliOptions);
|
|
72
|
-
if (brotliOptions) chain.plugin('modern-precompress-brotli').use(compression_webpack_plugin, [
|
|
73
|
-
brotliOptions
|
|
74
|
-
]);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
export { builderPluginAdapterPrecompress };
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { execFileSync } from "node:child_process";
|
|
3
|
-
import { createHash } from "node:crypto";
|
|
4
|
-
import { accessSync, chmodSync, constants, lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { createRequire } from "node:module";
|
|
6
|
-
import { tmpdir } from "node:os";
|
|
7
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
8
|
-
const EFFECT_TSGO_PACKAGE = '@effect/tsgo';
|
|
9
|
-
const EFFECT_TSGO_BIN = 'effect-tsgo';
|
|
10
|
-
const EFFECT_TSGO_RESOLUTION_ERROR = 'Unable to resolve the Effect TS-Go compiler. Install "@effect/tsgo" and a native TypeScript backend for this build config, or set EFFECT_TSGO_BIN.';
|
|
11
|
-
const executableEffectTsgoCompilers = new Map();
|
|
12
|
-
const BUILD_CONFIG_ENVIRONMENT_PLUGIN = 'ModernJsBuildConfigEnvironmentLeasePlugin';
|
|
13
|
-
const ENVIRONMENT_LEASE_REGISTRY_KEY = Symbol.for('@modern-js/app-tools/build-config-environment-lease-registry/v1');
|
|
14
|
-
const ENVIRONMENT_LEASE_REGISTRY_BRAND = Symbol.for('@modern-js/app-tools/build-config-environment-lease-registry-brand/v1');
|
|
15
|
-
const LIFECYCLE_HOOK_NAMES = [
|
|
16
|
-
'run',
|
|
17
|
-
'watchRun',
|
|
18
|
-
'afterDone',
|
|
19
|
-
'failed',
|
|
20
|
-
'shutdown',
|
|
21
|
-
'watchClose'
|
|
22
|
-
];
|
|
23
|
-
function restoreEnvironment(name, value) {
|
|
24
|
-
if (void 0 === value) delete process.env[name];
|
|
25
|
-
else process.env[name] = value;
|
|
26
|
-
}
|
|
27
|
-
function createEnvironmentLeaseRegistry() {
|
|
28
|
-
const environmentLeases = new Map();
|
|
29
|
-
return Object.freeze({
|
|
30
|
-
acquire (name, value) {
|
|
31
|
-
let lease = environmentLeases.get(name);
|
|
32
|
-
if (lease) {
|
|
33
|
-
if (lease.value !== value) throw new Error(`Build config environment "${name}" already has an active lease for a different value.`);
|
|
34
|
-
if (process.env[name] !== lease.value) throw new Error(`Build config environment lease for "${name}" lost ownership before another lease was acquired.`);
|
|
35
|
-
} else {
|
|
36
|
-
lease = {
|
|
37
|
-
originalValue: process.env[name],
|
|
38
|
-
owners: new Set(),
|
|
39
|
-
value
|
|
40
|
-
};
|
|
41
|
-
process.env[name] = value;
|
|
42
|
-
environmentLeases.set(name, lease);
|
|
43
|
-
}
|
|
44
|
-
const owner = Symbol(name);
|
|
45
|
-
lease.owners.add(owner);
|
|
46
|
-
let released = false;
|
|
47
|
-
return ()=>{
|
|
48
|
-
if (released) return;
|
|
49
|
-
if (environmentLeases.get(name) !== lease || !lease.owners.has(owner)) throw new Error(`Build config environment lease for "${name}" cannot be restored because its ownership record was lost.`);
|
|
50
|
-
released = true;
|
|
51
|
-
const lostOwnership = process.env[name] !== lease.value;
|
|
52
|
-
lease.owners.delete(owner);
|
|
53
|
-
if (0 === lease.owners.size) {
|
|
54
|
-
environmentLeases.delete(name);
|
|
55
|
-
restoreEnvironment(name, lease.originalValue);
|
|
56
|
-
} else if (lostOwnership) process.env[name] = lease.value;
|
|
57
|
-
if (lostOwnership) throw new Error(`Build config environment lease for "${name}" lost ownership before restoration.`);
|
|
58
|
-
};
|
|
59
|
-
},
|
|
60
|
-
brand: ENVIRONMENT_LEASE_REGISTRY_BRAND
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
function getEnvironmentLeaseRegistry() {
|
|
64
|
-
const descriptor = Object.getOwnPropertyDescriptor(process, ENVIRONMENT_LEASE_REGISTRY_KEY);
|
|
65
|
-
if (descriptor) {
|
|
66
|
-
const registry = descriptor.value;
|
|
67
|
-
if (descriptor.configurable || descriptor.enumerable || descriptor.writable || registry?.brand !== ENVIRONMENT_LEASE_REGISTRY_BRAND || 'function' != typeof registry.acquire) throw new Error('The process-global build config environment lease registry is occupied by an incompatible value.');
|
|
68
|
-
return registry;
|
|
69
|
-
}
|
|
70
|
-
const registry = createEnvironmentLeaseRegistry();
|
|
71
|
-
Object.defineProperty(process, ENVIRONMENT_LEASE_REGISTRY_KEY, {
|
|
72
|
-
configurable: false,
|
|
73
|
-
enumerable: false,
|
|
74
|
-
value: registry,
|
|
75
|
-
writable: false
|
|
76
|
-
});
|
|
77
|
-
return registry;
|
|
78
|
-
}
|
|
79
|
-
function acquireEnvironmentLease(name, value) {
|
|
80
|
-
return getEnvironmentLeaseRegistry().acquire(name, value);
|
|
81
|
-
}
|
|
82
|
-
function releaseAfterFailure(release, originalError) {
|
|
83
|
-
try {
|
|
84
|
-
release();
|
|
85
|
-
} catch (restorationError) {
|
|
86
|
-
throw new AggregateError([
|
|
87
|
-
originalError,
|
|
88
|
-
restorationError
|
|
89
|
-
], 'Build config environment setup and restoration both failed.');
|
|
90
|
-
}
|
|
91
|
-
throw originalError;
|
|
92
|
-
}
|
|
93
|
-
class BuildConfigEnvironmentLeasePlugin {
|
|
94
|
-
apply(compiler) {
|
|
95
|
-
const hooks = compiler.hooks;
|
|
96
|
-
try {
|
|
97
|
-
const lifecycleHooks = {};
|
|
98
|
-
for (const hookName of LIFECYCLE_HOOK_NAMES){
|
|
99
|
-
const hook = hooks[hookName];
|
|
100
|
-
if (!hook || 'function' != typeof hook.tap) throw new Error(`Rspack does not expose the "${hookName}" lifecycle hook required to restore build config environment leases.`);
|
|
101
|
-
lifecycleHooks[hookName] = hook;
|
|
102
|
-
}
|
|
103
|
-
let mode = 'pending';
|
|
104
|
-
const modeTap = {
|
|
105
|
-
name: BUILD_CONFIG_ENVIRONMENT_PLUGIN,
|
|
106
|
-
stage: Number.MIN_SAFE_INTEGER
|
|
107
|
-
};
|
|
108
|
-
const releaseTap = {
|
|
109
|
-
name: BUILD_CONFIG_ENVIRONMENT_PLUGIN,
|
|
110
|
-
stage: Number.MAX_SAFE_INTEGER
|
|
111
|
-
};
|
|
112
|
-
const releaseAfterOneShot = ()=>{
|
|
113
|
-
if ('watch' !== mode && true !== compiler.watchMode) this.release();
|
|
114
|
-
};
|
|
115
|
-
lifecycleHooks.run.tap(modeTap, ()=>{
|
|
116
|
-
mode = 'run';
|
|
117
|
-
});
|
|
118
|
-
lifecycleHooks.watchRun.tap(modeTap, ()=>{
|
|
119
|
-
mode = 'watch';
|
|
120
|
-
});
|
|
121
|
-
lifecycleHooks.afterDone.tap(releaseTap, releaseAfterOneShot);
|
|
122
|
-
lifecycleHooks.failed.tap(releaseTap, releaseAfterOneShot);
|
|
123
|
-
lifecycleHooks.shutdown.tap(releaseTap, this.release);
|
|
124
|
-
lifecycleHooks.watchClose.tap(releaseTap, this.release);
|
|
125
|
-
} catch (error) {
|
|
126
|
-
releaseAfterFailure(this.release, error);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
constructor(release){
|
|
130
|
-
this.release = release;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
function resolveEffectTsgoCli(from) {
|
|
134
|
-
const projectRequire = createRequire(from);
|
|
135
|
-
const packageJsonPath = projectRequire.resolve(`${EFFECT_TSGO_PACKAGE}/package.json`);
|
|
136
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
137
|
-
const bin = 'string' == typeof packageJson.bin ? packageJson.bin : packageJson.bin?.[EFFECT_TSGO_BIN];
|
|
138
|
-
if (!bin) throw new Error(EFFECT_TSGO_RESOLUTION_ERROR);
|
|
139
|
-
return resolve(dirname(packageJsonPath), bin);
|
|
140
|
-
}
|
|
141
|
-
function resolveExecutableEffectTsgoCompiler(compilerPath) {
|
|
142
|
-
if ('win32' === process.platform) return compilerPath;
|
|
143
|
-
const sourcePath = realpathSync(compilerPath);
|
|
144
|
-
const source = lstatSync(sourcePath);
|
|
145
|
-
if (!source.isFile()) throw new Error(EFFECT_TSGO_RESOLUTION_ERROR);
|
|
146
|
-
try {
|
|
147
|
-
accessSync(sourcePath, constants.X_OK);
|
|
148
|
-
return compilerPath;
|
|
149
|
-
} catch {}
|
|
150
|
-
const cachedCompiler = executableEffectTsgoCompilers.get(sourcePath);
|
|
151
|
-
if (cachedCompiler) try {
|
|
152
|
-
accessSync(cachedCompiler, constants.X_OK);
|
|
153
|
-
return cachedCompiler;
|
|
154
|
-
} catch {
|
|
155
|
-
executableEffectTsgoCompilers.delete(sourcePath);
|
|
156
|
-
}
|
|
157
|
-
const compilerBytes = readFileSync(sourcePath);
|
|
158
|
-
const compilerDigest = createHash('sha256').update(compilerBytes).digest('hex');
|
|
159
|
-
const compilerDirectory = join(tmpdir(), 'modern-js', 'effect-tsgo', compilerDigest);
|
|
160
|
-
mkdirSync(compilerDirectory, {
|
|
161
|
-
recursive: true,
|
|
162
|
-
mode: 448
|
|
163
|
-
});
|
|
164
|
-
const executableCompiler = join(compilerDirectory, basename(sourcePath));
|
|
165
|
-
try {
|
|
166
|
-
accessSync(executableCompiler, constants.X_OK);
|
|
167
|
-
} catch {
|
|
168
|
-
const temporaryCompiler = join(compilerDirectory, `.${basename(sourcePath)}.${process.pid}.tmp`);
|
|
169
|
-
rmSync(temporaryCompiler, {
|
|
170
|
-
force: true
|
|
171
|
-
});
|
|
172
|
-
try {
|
|
173
|
-
writeFileSync(temporaryCompiler, compilerBytes, {
|
|
174
|
-
flag: 'wx',
|
|
175
|
-
mode: 448
|
|
176
|
-
});
|
|
177
|
-
chmodSync(temporaryCompiler, 448);
|
|
178
|
-
renameSync(temporaryCompiler, executableCompiler);
|
|
179
|
-
} finally{
|
|
180
|
-
rmSync(temporaryCompiler, {
|
|
181
|
-
force: true
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
accessSync(executableCompiler, constants.X_OK);
|
|
186
|
-
executableEffectTsgoCompilers.set(sourcePath, executableCompiler);
|
|
187
|
-
return executableCompiler;
|
|
188
|
-
}
|
|
189
|
-
function getBuildConfigEnvironment(name) {
|
|
190
|
-
return process.env[name];
|
|
191
|
-
}
|
|
192
|
-
function withBuildConfigEnvironment(name, value, setup) {
|
|
193
|
-
return async (config, ...args)=>{
|
|
194
|
-
const release = acquireEnvironmentLease(name, value);
|
|
195
|
-
try {
|
|
196
|
-
const configured = await setup(config, ...args) ?? config;
|
|
197
|
-
configured.plugins = [
|
|
198
|
-
...configured.plugins ?? [],
|
|
199
|
-
new BuildConfigEnvironmentLeasePlugin(release)
|
|
200
|
-
];
|
|
201
|
-
return configured;
|
|
202
|
-
} catch (error) {
|
|
203
|
-
releaseAfterFailure(release, error);
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
function resolveEffectTsgoCompiler(options) {
|
|
208
|
-
const configuredCompiler = getBuildConfigEnvironment('EFFECT_TSGO_BIN')?.trim();
|
|
209
|
-
if (configuredCompiler) try {
|
|
210
|
-
return resolveExecutableEffectTsgoCompiler(configuredCompiler);
|
|
211
|
-
} catch {
|
|
212
|
-
throw new Error(EFFECT_TSGO_RESOLUTION_ERROR);
|
|
213
|
-
}
|
|
214
|
-
try {
|
|
215
|
-
const compiler = execFileSync(process.execPath, [
|
|
216
|
-
resolveEffectTsgoCli(options.from),
|
|
217
|
-
'get-exe-path'
|
|
218
|
-
], {
|
|
219
|
-
encoding: 'utf-8'
|
|
220
|
-
}).trim();
|
|
221
|
-
if (compiler) return resolveExecutableEffectTsgoCompiler(compiler);
|
|
222
|
-
} catch {}
|
|
223
|
-
throw new Error(EFFECT_TSGO_RESOLUTION_ERROR);
|
|
224
|
-
}
|
|
225
|
-
export { getBuildConfigEnvironment, resolveEffectTsgoCompiler, withBuildConfigEnvironment };
|