@bleedingdev/modern-js-app-tools 3.9.0-ultramodern.2 → 3.9.0-ultramodern.21

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