@flatjs/evolve 2.1.0-next.3 → 2.1.0-next.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. package/dist/compiler/create-global-compiler.d.ts +2 -0
  2. package/dist/compiler/create-global-compiler.js +1 -0
  3. package/dist/constants.d.ts +9 -0
  4. package/dist/constants.js +1 -1
  5. package/dist/create-webpack/create-externals.d.ts +1 -1
  6. package/dist/create-webpack/create-externals.js +1 -1
  7. package/dist/create-webpack/create-optimization.d.ts +1 -1
  8. package/dist/create-webpack/create-optimization.js +1 -1
  9. package/dist/create-webpack/create-output.d.ts +1 -1
  10. package/dist/create-webpack/create-performance.d.ts +1 -1
  11. package/dist/create-webpack/create-plugins.d.ts +2 -1
  12. package/dist/create-webpack/create-plugins.js +1 -1
  13. package/dist/create-webpack/create-resolve.js +1 -1
  14. package/dist/create-webpack/create-rule-sets.d.ts +1 -1
  15. package/dist/create-webpack/create-rule-sets.js +1 -1
  16. package/dist/create-webpack/load-watch-options.d.ts +12 -0
  17. package/dist/create-webpack/load-watch-options.js +1 -0
  18. package/dist/create-webpack/load-webpack-config.d.ts +2 -1
  19. package/dist/create-webpack/load-webpack-config.js +1 -1
  20. package/dist/create-webpack/rule-sets/rule-assets.d.ts +2 -2
  21. package/dist/create-webpack/rule-sets/rule-assets.js +1 -1
  22. package/dist/create-webpack/rule-sets/rule-css.js +1 -1
  23. package/dist/create-webpack/rule-sets/rule-scripts.d.ts +2 -0
  24. package/dist/create-webpack/rule-sets/rule-scripts.js +1 -1
  25. package/dist/create-webpack/types.d.ts +1 -1
  26. package/dist/default-options.js +1 -1
  27. package/dist/define-config/define-config.d.ts +2 -2
  28. package/dist/dev-server/add-compiler-to-dev-server.js +1 -1
  29. package/dist/dev-server/create-dev-server-compiler-task.d.ts +3 -0
  30. package/dist/dev-server/create-dev-server-compiler-task.js +1 -0
  31. package/dist/dev-server/create-dev-server-entries.d.ts +1 -1
  32. package/dist/dev-server/create-dev-server-entries.js +1 -1
  33. package/dist/dev-server/create-dev-server.js +1 -1
  34. package/dist/dev-server/index.d.ts +3 -3
  35. package/dist/dev-server/index.js +1 -1
  36. package/dist/dev-server/middlewares/get-bundle-asset.d.ts +1 -1
  37. package/dist/dev-server/middlewares/get-page-main-html.js +1 -1
  38. package/dist/dev-server/middlewares/get-page-module-html.js +1 -1
  39. package/dist/helpers/assert-group-entry-item.d.ts +7 -0
  40. package/dist/helpers/assert-group-entry-item.js +1 -0
  41. package/dist/helpers/assert-single-compiler.d.ts +15 -0
  42. package/dist/helpers/assert-single-compiler.js +1 -0
  43. package/dist/helpers/check-runtime-env.d.ts +4 -0
  44. package/dist/helpers/check-runtime-env.js +1 -0
  45. package/dist/helpers/custom-listr-renderer.d.ts +41 -0
  46. package/dist/helpers/custom-listr-renderer.js +1 -0
  47. package/dist/helpers/custom-message-channel.d.ts +17 -0
  48. package/dist/helpers/custom-message-channel.js +1 -0
  49. package/dist/helpers/delete-object-keys.d.ts +11 -0
  50. package/dist/helpers/delete-object-keys.js +1 -0
  51. package/dist/helpers/flat-entry-map.d.ts +8 -0
  52. package/dist/helpers/flat-entry-map.js +1 -0
  53. package/dist/helpers/format-spinner-text.d.ts +8 -0
  54. package/dist/helpers/format-spinner-text.js +1 -0
  55. package/dist/helpers/get-bundle-file-name.d.ts +1 -1
  56. package/dist/helpers/get-runtime-cdn-base.d.ts +2 -0
  57. package/dist/helpers/get-runtime-cdn-base.js +1 -0
  58. package/dist/helpers/get-stats-file-name.d.ts +2 -0
  59. package/dist/helpers/get-stats-file-name.js +1 -0
  60. package/dist/helpers/index.d.ts +18 -4
  61. package/dist/helpers/index.js +1 -1
  62. package/dist/helpers/is-deep-equal.d.ts +9 -0
  63. package/dist/helpers/is-deep-equal.js +1 -0
  64. package/dist/helpers/json-serializer.js +1 -1
  65. package/dist/helpers/merge-babel-options.d.ts +1 -1
  66. package/dist/helpers/merge-babel-options.js +1 -1
  67. package/dist/helpers/normalize-check-entry-options.d.ts +10 -0
  68. package/dist/helpers/normalize-check-entry-options.js +1 -0
  69. package/dist/helpers/normalize-entry-map.d.ts +1 -0
  70. package/dist/helpers/normalize-entry-map.js +1 -1
  71. package/dist/helpers/normalize-entry-module-absolute-path.d.ts +10 -0
  72. package/dist/helpers/normalize-entry-module-absolute-path.js +1 -0
  73. package/dist/helpers/normalize-group-name.d.ts +8 -0
  74. package/dist/helpers/normalize-group-name.js +1 -0
  75. package/dist/helpers/normalize-template-inject-tokens.d.ts +16 -0
  76. package/dist/helpers/normalize-template-inject-tokens.js +1 -0
  77. package/dist/helpers/open-page.js +1 -1
  78. package/dist/helpers/refresh-evolve-mock-options.js +1 -1
  79. package/dist/helpers/script-injects.d.ts +1 -1
  80. package/dist/helpers/should-enable-react-fast-refresh.js +1 -1
  81. package/dist/helpers/split-to-entry-group.d.ts +52 -0
  82. package/dist/helpers/split-to-entry-group.js +1 -0
  83. package/dist/helpers/verify-group-entry-options.d.ts +9 -0
  84. package/dist/helpers/verify-group-entry-options.js +1 -0
  85. package/dist/index.d.ts +1 -1
  86. package/dist/index.js +1 -1
  87. package/dist/load-config/load-evolve-config.js +1 -1
  88. package/dist/loaders/loader-icon.cjs +2 -1
  89. package/dist/main/create-thread-worker.d.ts +29 -14
  90. package/dist/main/create-thread-worker.js +1 -1
  91. package/dist/main/index.d.ts +1 -1
  92. package/dist/main/index.js +1 -1
  93. package/dist/main/prepare-analyzer.d.ts +9 -0
  94. package/dist/main/prepare-analyzer.js +1 -0
  95. package/dist/main/prepare-build.d.ts +4 -3
  96. package/dist/main/prepare-build.js +1 -1
  97. package/dist/main/prepare-serve.d.ts +1 -1
  98. package/dist/main/prepare-serve.js +1 -1
  99. package/dist/main/start-analyzer.d.ts +10 -0
  100. package/dist/main/start-analyzer.js +1 -0
  101. package/dist/main/start-build-dynamic.d.ts +2 -2
  102. package/dist/main/start-build-dynamic.js +1 -1
  103. package/dist/main/start-build-worker.d.ts +17 -6
  104. package/dist/main/start-build-worker.js +1 -1
  105. package/dist/main/start-build.d.ts +3 -2
  106. package/dist/main/start-build.js +1 -1
  107. package/dist/main/start-group-entry-build.d.ts +15 -0
  108. package/dist/main/start-group-entry-build.js +1 -0
  109. package/dist/main/start-serve.d.ts +1 -1
  110. package/dist/main/start-serve.js +1 -1
  111. package/dist/minimizer/create-minimizers.js +1 -1
  112. package/dist/minimizer/image-minimizer.js +1 -1
  113. package/dist/minimizer/terser-minimizer.js +1 -1
  114. package/dist/plugins/circular-dependency/circular-dependency-plugin.js +1 -1
  115. package/dist/plugins/clean-webpack/index.d.ts +1 -1
  116. package/dist/plugins/clean-webpack/index.js +1 -1
  117. package/dist/plugins/define-variable/define-variable-plugin.js +1 -1
  118. package/dist/plugins/module-federation/module-federation.d.ts +1 -1
  119. package/dist/plugins/module-federation/module-federation.js +1 -1
  120. package/dist/plugins/multi-html/index.d.ts +1 -1
  121. package/dist/plugins/multi-html/index.js +1 -1
  122. package/dist/plugins/multi-html/multi-html-cdn-plugin.js +1 -1
  123. package/dist/plugins/multi-html/multi-html-plugin.d.ts +1 -1
  124. package/dist/plugins/multi-html/multi-html-plugin.js +1 -1
  125. package/dist/plugins/stats-webpack/helper-write-stats.d.ts +28 -0
  126. package/dist/plugins/stats-webpack/helper-write-stats.js +1 -0
  127. package/dist/plugins/stats-webpack/index.d.ts +12 -0
  128. package/dist/plugins/stats-webpack/index.js +1 -0
  129. package/dist/plugins/stats-webpack/stats-webpack-plugin.d.ts +25 -0
  130. package/dist/plugins/stats-webpack/stats-webpack-plugin.js +1 -0
  131. package/dist/plugins/ts-checker/ts-checker-guard-plugin.d.ts +13 -0
  132. package/dist/plugins/ts-checker/ts-checker-guard-plugin.js +1 -0
  133. package/dist/plugins/ts-checker/ts-checker-plugin.d.ts +3 -0
  134. package/dist/plugins/ts-checker/ts-checker-plugin.js +1 -0
  135. package/dist/types/index.d.ts +3 -1
  136. package/dist/types/index.js +1 -1
  137. package/dist/types/types-analyzer.d.ts +70 -0
  138. package/dist/types/types-analyzer.js +1 -0
  139. package/dist/types/types-cli-options.d.ts +12 -0
  140. package/dist/types/types-cli-options.js +1 -0
  141. package/dist/types/types-dev-server.d.ts +17 -6
  142. package/dist/types/types-entry-map.d.ts +21 -3
  143. package/dist/types/types-global-compiler-options.d.ts +7 -0
  144. package/dist/types/types-global-compiler-options.js +1 -0
  145. package/dist/types/types-loader-options.d.ts +31 -9
  146. package/dist/types/types-options.d.ts +30 -15
  147. package/dist/types/types-threads-options.d.ts +18 -0
  148. package/dist/types/types-threads-options.js +1 -0
  149. package/dist/types/types-webpack.d.ts +5 -2
  150. package/package.json +69 -61
  151. package/templates/html-plugin/index-dev.html +2 -2
  152. package/templates/html-plugin/index-inte.html +2 -2
  153. package/templates/html-plugin/index-inte2.html +2 -2
  154. package/templates/html-plugin/index-inte3.html +2 -2
  155. package/templates/html-plugin/index-inte4.html +2 -2
  156. package/templates/html-plugin/index-me.html +2 -2
  157. package/templates/html-plugin/index-ntv.html +61 -0
  158. package/templates/html-plugin/index-prod.html +2 -2
  159. package/templates/html-plugin/index-rc.html +2 -2
  160. package/templates/html-plugin/index-uat.html +2 -2
  161. package/templates/module.html +2 -2
  162. package/dist/dev-server/create-dev-server-compiler-tasks.d.ts +0 -3
  163. package/dist/dev-server/create-dev-server-compiler-tasks.js +0 -1
  164. package/dist/helpers/assert-only-single-entry-item.d.ts +0 -7
  165. package/dist/helpers/assert-only-single-entry-item.js +0 -1
  166. package/dist/helpers/split-to-multi-compiler.d.ts +0 -8
  167. package/dist/helpers/split-to-multi-compiler.js +0 -1
  168. package/dist/main/start-one-entry-build.d.ts +0 -13
  169. package/dist/main/start-one-entry-build.js +0 -1
@@ -1 +1 @@
1
- function stringifyWithFns(n){return JSON.stringify(n,(function(n,t){if("function"==typeof t)try{return makeFunctionFromString(t),t.toString()}catch(n){return`function ${t.toString()}`}return t}))}function looksLikeAFunctionString(n){return!![/^function[^(]*\(([^()]*)\)\s*\{[\s\S]*\}$/m,/^(\s*async\s*)?(\w*\s*)\(([^)]*)\)\s*=>\s*(.*)$/m,/^\s*\w+\s*=>/m].find((t=>t.test(n)))}function makeFunctionFromString(funcString){return eval("("+funcString+")")}function parseWithFns(n){try{return JSON.parse(n,(function(n,t){return looksLikeAFunctionString(t)?makeFunctionFromString(t):t}))}catch(n){return{}}}export const jsonSerializer={stringify:stringifyWithFns,parse:parseWithFns};
1
+ import vm from"node:vm";function stringifyWithFns(n){return JSON.stringify(n,(function(n,t){if("function"==typeof t)try{return makeFunctionFromString(t),t.toString()}catch{return`function ${t.toString()}`}return t}))}function looksLikeAFunctionString(n){return!![/^function[^(]*\(([^()]*)\)\s*\{[\s\S]*\}$/m,/^(\s*async\s*)?(\w*\s*)\(([^)]*)\)\s*=>\s*(.*)$/m,/^\s*\w+\s*=>/m].find((t=>t.test(n)))}function makeFunctionFromString(n){return vm.runInNewContext("("+n+")")}function parseWithFns(n){try{return JSON.parse(n,(function(n,t){return looksLikeAFunctionString(t)?makeFunctionFromString(t):t}))}catch{return{}}}export const jsonSerializer={stringify:stringifyWithFns,parse:parseWithFns};
@@ -1,4 +1,4 @@
1
1
  import { type TransformOptions } from '@babel/core';
2
2
  import { type BuiltinBabelOptions } from '../types/types-loader-options.js';
3
3
  import { type ModularImportOption } from '../types/types-modular-import.js';
4
- export declare const mergeBabelOption: (modularImports?: ModularImportOption[], options?: BuiltinBabelOptions) => TransformOptions;
4
+ export declare const mergeBabelOption: (serveMode: boolean, modularImports?: ModularImportOption[], options?: BuiltinBabelOptions) => TransformOptions;
@@ -1 +1 @@
1
- import{babelMerge}from"@armit/babel-merge";import babelPluginImport from"@flatjs/babel-plugin-import";import{logger}from"@flatjs/common";import{reactBabelPreset,vueBabelPreset}from"@flatjs/evolve-preset-babel";import{moduleName}from"../constants.js";export const mergeBabelOption=(e=[],r={usePreset:"react"})=>{const t=e.map((e=>[babelPluginImport,{transformToDefaultImport:!1,libraryDirectory:"dist",...e},e.libraryName])),{usePreset:a="react",...l}=r,o="react"===a?reactBabelPreset():"vue"===a?vueBabelPreset():reactBabelPreset();let m={};try{m=babelMerge(o,l),m.plugins?m.plugins.unshift(...t):m.plugins=t}catch(e){logger.error(e,moduleName)}return{...m,babelrc:!1,compact:!1}};
1
+ import{babelMerge}from"@armit/babel-merge";import babelPluginImport from"@flatjs/babel-plugin-import";import{logger}from"@flatjs/common";import{reactBabelPreset,vueBabelPreset}from"@flatjs/evolve-preset-babel";import{moduleName}from"../constants.js";export const mergeBabelOption=(e,r=[],t={usePreset:"react"})=>{const a=r.map((e=>[babelPluginImport,{transformToDefaultImport:!1,libraryDirectory:"dist",...e},e.libraryName])),{usePreset:l="react",...o}=t,m="react"===l?reactBabelPreset(e):"vue"===l?vueBabelPreset():reactBabelPreset();let b={};try{b=babelMerge(m,o),b.plugins?b.plugins.unshift(...a):b.plugins=a}catch(e){logger.error(e,moduleName)}return{...b,babelrc:!1,compact:!1}};
@@ -0,0 +1,10 @@
1
+ import { type EvolveEntryItemOption } from '../types/types-entry-map.js';
2
+ /**
3
+ * Normalizes the check entry options.
4
+ *
5
+ * @param serveMode - A boolean indicating whether the serve mode is enabled.
6
+ * @param currEntryOption - The current entry option.
7
+ * @param ignoreOptionKeys - An array of keys to ignore in the entry option.
8
+ * @returns The normalized entry options.
9
+ */
10
+ export declare const normalizeCheckEntryOptions: (serveMode: boolean, currEntryOption?: EvolveEntryItemOption, ignoreOptionKeys?: Array<keyof EvolveEntryItemOption>) => Partial<EvolveEntryItemOption> | undefined;
@@ -0,0 +1 @@
1
+ import{urlJoin}from"@flatjs/common";import{ignoreEntryOptionKeys}from"../constants.js";import{deleteObjectKeys}from"./delete-object-keys.js";import{normalizeTemplateInjectTokens}from"./normalize-template-inject-tokens.js";export const normalizeCheckEntryOptions=(e,t,o=ignoreEntryOptionKeys)=>{const n={mode:e?"development":"production",envCdn:urlJoin(e?"http://dev.flatjs.com":"https://file.40017.cn/jinfu",["public"])},r=normalizeTemplateInjectTokens(n,t),i={...t,...r};return deleteObjectKeys(i,o)};
@@ -11,5 +11,6 @@ export declare const normalizeEvolveEntryName: (entryName: string, projectVirtua
11
11
  * Merge default entry item configuration values.
12
12
  * @param activedEntryMap actived entries
13
13
  * @param definedEntryMap defined entries in flatjs.evolve.js
14
+ * @param projectVirtualPath virtual path for current `project`
14
15
  */
15
16
  export declare const normalizeEvolveEntryMap: (activedEntryMap?: EvolveEntryMap, definedEntryMap?: EvolveEntryMap) => EvolveEntryMap;
@@ -1 +1 @@
1
- import{join}from"node:path";import _ from"lodash";export const normalizeEvolveEntryName=(o,e)=>{const r=o.replace(/^\//,""),t=e.replace(/^\//,"");return(r.startsWith(t)?r:join(t,r)).replace(/\/$/,"")};export const normalizeEvolveEntryMap=(o={},e={})=>{const r={};for(const[t,n]of Object.entries(e)){const e={options:{}};o[t]&&(r[t]=_.merge({},e,n,o[t])),_.merge(n,e)}return r};
1
+ import _ from"lodash";import{join}from"node:path";const normalizeEntryGroupOptions=o=>o&&o.groupName?{groupName:o.groupName,groupingSource:"manual"}:{groupingSource:"auto"};export const normalizeEvolveEntryName=(o,r)=>{const e=o.replace(/^\//,""),n=r.replace(/^\//,"");return(e.startsWith(n)?e:join(n,e)).replace(/\/$/,"")};export const normalizeEvolveEntryMap=(o={},r={})=>{const e={};for(const[n,t]of Object.entries(r)){const r={options:{}};if(o[n]){const p=normalizeEntryGroupOptions(t);e[n]=_.merge({},r,t,o[n],p)}}return e};
@@ -0,0 +1,10 @@
1
+ import { EvolveEntryMap } from '../types/types-entry-map.js';
2
+ import { FlatEvolveOptions } from '../types/types-options.js';
3
+ /**
4
+ * Normalizes the absolute paths of entry modules based on the provided evolve options and entry map.
5
+ *
6
+ * @param evolveOptions - The options for the evolve process.
7
+ * @param evolveEntryMap - The map of evolve entries.
8
+ * @returns An array of normalized entry module paths.
9
+ */
10
+ export declare const normalizeEntryModuleAbsolutePath: (evolveOptions: FlatEvolveOptions, evolveEntryMap: EvolveEntryMap) => string[];
@@ -0,0 +1 @@
1
+ import{resolve}from"node:path";import{ensureSlash}from"@flatjs/common";export const normalizeEntryModuleAbsolutePath=(e,o)=>{const{projectCwd:s}=e,t=[];for(const[,e]of Object.entries(o)){const{entryModuleBase:o,entry:r}=e;if(o)for(const e of o){const o=ensureSlash(resolve(s,e),!0);t.push(o)}else for(const e of r){let o=resolve(s,e);(/\.(ts|tsx|js|jsx)$/.test(o)||o.endsWith("/index"))&&(o=o.replace(/\/[^/]*$/,""));const r=ensureSlash(o,!0);t.push(r)}}return Array.from(new Set(t))};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Normalizes the group name based on the project virtual path and index.
3
+ *
4
+ * @param projectVirtualPath - The virtual path of the project.
5
+ * @param index - The index used to generate the group name.
6
+ * @returns The normalized group name.
7
+ */
8
+ export declare const normalizeGroupName: (projectVirtualPath: string, index: number) => string;
@@ -0,0 +1 @@
1
+ import{normalizeEvolveEntryName}from"./normalize-entry-map.js";export const normalizeGroupName=(r,o)=>{const e=Array.from({length:26},((r,o)=>String.fromCharCode(65+o))),m=[...Array.from({length:26},((r,o)=>String.fromCharCode(97+o))),...e],n=Math.floor(o/52);return normalizeEvolveEntryName(`${m[o%52]}${n||""}`,r)};
@@ -0,0 +1,16 @@
1
+ import { type EvolveEntryItemOption } from '../types/types-entry-map.js';
2
+ import { type HtmlPluginConfigConfigData } from './get-html-plugin-config.js';
3
+ /**
4
+ * Normalizes the template inject tokens based on the provided configuration data and entry options.
5
+ *
6
+ * @param configData - The configuration data for the HTML plugin.
7
+ * @param currEntryOption - The current entry option for the evolve item.
8
+ * @returns An object containing the normalized template inject tokens.
9
+ */
10
+ export declare const normalizeTemplateInjectTokens: (configData: HtmlPluginConfigConfigData, currEntryOption?: EvolveEntryItemOption) => {
11
+ headBeforeHtmlTags?: string[];
12
+ inlineScripts?: string[];
13
+ headBeforeStyles?: string[];
14
+ headBeforeScripts: string[];
15
+ bodyAfterScripts: string[];
16
+ };
@@ -0,0 +1 @@
1
+ import{getHtmlPluginConfig}from"./get-html-plugin-config.js";export const normalizeTemplateInjectTokens=(e,t)=>({headBeforeHtmlTags:getHtmlPluginConfig("headBeforeHtmlTags",e,t?.headBeforeHtmlTags),inlineScripts:getHtmlPluginConfig("inlineScripts",e,t?.inlineScripts),headBeforeStyles:getHtmlPluginConfig("headBeforeStyles",e,t?.headBeforeStyles),headBeforeScripts:getHtmlPluginConfig("headBeforeScripts",e,t?.headBeforeScripts),bodyAfterScripts:getHtmlPluginConfig("bodyAfterScripts",e,t?.bodyAfterScripts)});
@@ -1 +1 @@
1
- import opn from"better-opn";export const openPage=n=>{try{opn(n)}catch(n){console.warn("Unable to open browser. If you are running in a headless environment\n")}};
1
+ import opn from"better-opn";export const openPage=n=>{try{opn(n)}catch{console.warn("Unable to open browser. If you are running in a headless environment\n")}};
@@ -1 +1 @@
1
- import{requireResolve}from"@flatjs/common";import{loadMockConfig,getMockCwd}from"@flatjs/mock";import _ from"lodash";export const refreshEvolveMockOptions=async(o,t,e)=>{const s=t.devServer,r=e?.esmLoaderOptions,i=r?.externals||[],n={projectCwd:o,resolve:requireResolve},c=await loadMockConfig(n,o,s?.mockOptions||{},_.merge({},e,{configFile:"flatjs-mock",esmLoaderOptions:{externals:[...i,"@flatjs/mock"]}}));if(s){s.mockOptions=c||{},s.mockOptions&&!s.mockOptions.https&&(s.mockOptions.https=s?.https);const o=getMockCwd(c);Array.isArray(s?.watchOptions?.ignored)&&s?.watchOptions?.ignored.push(o)}return t};
1
+ import _ from"lodash";import{requireResolve}from"@flatjs/common";import{getMockCwd,loadMockConfig}from"@flatjs/mock";export const refreshEvolveMockOptions=async(o,t,e)=>{const s=t.devServer,r=e?.esmLoaderOptions,i=r?.externals||[],n={projectCwd:o,resolve:requireResolve},c=await loadMockConfig(n,o,s?.mockOptions||{},_.merge({},e,{configFile:"flatjs-mock",esmLoaderOptions:{externals:[...i,"@flatjs/mock"]}}));if(s){s.mockOptions=c||{},s.mockOptions&&!s.mockOptions.https&&(s.mockOptions.https=s?.https);const o=getMockCwd(c);Array.isArray(s?.watchOptions?.ignored)&&s?.watchOptions?.ignored.push(o)}return t};
@@ -1,4 +1,4 @@
1
- import { type EvolveMultiCdnEnvType, type EvolveMultiCDNConfig, type EvolveMultiCDNEnvResolver } from '../types/types-multi-html.js';
1
+ import { type EvolveMultiCDNConfig, type EvolveMultiCDNEnvResolver, type EvolveMultiCdnEnvType } from '../types/types-multi-html.js';
2
2
  export declare function httpUrlJoin(first?: string, second?: string): string;
3
3
  /**
4
4
  * To extract the best matched CDN configuration url address, either use URL `query.env` or customize the `envRresolver`
@@ -1 +1 @@
1
- export const shouldEnableReactFastRefresh=(e,o,t)=>{const r=o[1],s=!!r.options?.moduleFederation;return e&&"react"===t.loaderOptions.babelOptions?.usePreset&&!s&&!0!==t.devServer?.liveReload};
1
+ export const shouldEnableReactFastRefresh=(e,o,t)=>{const r=o[1],s=!!r.options?.moduleFederation,a=!!r.options?.output?.library;return e&&"react"===t.loaderOptions.babelOptions?.usePreset&&!s&&!a&&!0!==t.devServer?.liveReload};
@@ -0,0 +1,52 @@
1
+ import { type EvolveEntryItemOption, type EvolveEntryMap, type EvolveEntryMapContent } from '../types/types-entry-map.js';
2
+ import { type FlatEvolveOptions } from '../types/types-options.js';
3
+ /**
4
+ * Groups the manual entries based on their group names.
5
+ * @param manualEntries - The map of manual entries.
6
+ * @returns An array of grouped manual entries.
7
+ */
8
+ export declare const manualGrouping: (manualEntries: (EvolveEntryMapContent & {
9
+ entryName: string;
10
+ })[]) => Array<EvolveEntryMap>;
11
+ /**
12
+ * Reduces an array of autoEntries into groups based on their options.
13
+ * Each group is represented by a groupKey and contains an EvolveEntryMap.
14
+ *
15
+ * @param evolveOptions - The FlatEvolveOptions object.
16
+ * @param autoEntries - An array of EvolveEntryMapContent objects with an additional entryName property.
17
+ * @param ignoreOptionKeys - An array of keys to ignore when comparing entry options.
18
+ * @param serveMode - A boolean indicating whether the function is running in serve mode.
19
+ * @returns An object where each key represents a groupKey and its value is an EvolveEntryMap.
20
+ */
21
+ export declare const autoGroupingReduce: (autoEntries: (EvolveEntryMapContent & {
22
+ entryName: string;
23
+ })[], ignoreOptionKeys: Array<keyof EvolveEntryItemOption> | undefined, serveMode: boolean) => Record<string, EvolveEntryMap>;
24
+ /**
25
+ * Assigns a group name to each entry in the evolveEntryMapList based on the projectVirtualPath.
26
+ *
27
+ * @param evolveOptions - The options for the evolve process.
28
+ * @param evolveEntryMapList - The list of evolve entry maps.
29
+ * @returns The updated list of evolve entry maps with group names assigned.
30
+ */
31
+ export declare const autoAssignGroupName: (evolveOptions: FlatEvolveOptions, evolveEntryMapList: Array<EvolveEntryMap>) => Array<EvolveEntryMap>;
32
+ /**
33
+ * Groups the given autoEntries into multiple EvolveEntryMap based on their options.
34
+ * If the group size exceeds the maximum group size, it will be sliced into smaller groups.
35
+ *
36
+ * @param evolveOptions - The FlatEvolveOptions object.
37
+ * @param autoEntries - An array of EvolveEntryMapContent objects with an additional entryName property.
38
+ * @param ignoreOptionKeys - An array of keys to ignore in the EvolveEntryItemOption object.
39
+ * @param serveMode - A boolean indicating whether the serve mode is enabled.
40
+ * @returns An array of EvolveEntryMap representing the grouped entries.
41
+ */
42
+ export declare const autoGrouping: (evolveOptions: FlatEvolveOptions, autoEntries: (EvolveEntryMapContent & {
43
+ entryName: string;
44
+ })[], ignoreOptionKeys: Array<keyof EvolveEntryItemOption> | undefined, serveMode: boolean) => Array<EvolveEntryMap>;
45
+ /**
46
+ * Splits the served entries into groups based on the given options.
47
+ *
48
+ * @param evolveEntries - The map of served entries.
49
+ * @param ignoreOptionKeys - The list of option keys to ignore.
50
+ * @returns An array of evolve entry maps representing the groups.
51
+ */
52
+ export declare const splitToEntryGroup: (evolveEntries: EvolveEntryMap, evolveOptions: FlatEvolveOptions, ignoreOptionKeys: Array<keyof EvolveEntryItemOption> | undefined, serveMode: boolean) => Array<EvolveEntryMap>;
@@ -0,0 +1 @@
1
+ import _ from"lodash";import{ignoreEntryOptionKeys}from"../constants.js";import{isDeepEqual}from"./is-deep-equal.js";import{normalizeCheckEntryOptions}from"./normalize-check-entry-options.js";import{normalizeGroupName}from"./normalize-group-name.js";export const manualGrouping=o=>{const e=_.groupBy(o,(o=>o.groupName)),t=[];for(const[,o]of Object.entries(e)){const e=o.reduce(((o,e)=>(o[e.entryName]=_.omitBy(e,"entryName"),o)),{});t.push(e)}return t};export const autoGroupingReduce=(o,e=[],t)=>_.reduce(o,((o,r,n)=>{let s=`auto_grouping_reduce-${n}`;const u=normalizeCheckEntryOptions(t,r.options,e);for(const[r,n]of Object.entries(o)){const o=Object.values(n)[0],i=normalizeCheckEntryOptions(t,o.options,e);if(isDeepEqual(u,i)){s=r;break}}return o[s]=_.merge(o[s],{[r.entryName]:_.omitBy(r,"entryName")}),o}),{});export const autoAssignGroupName=(o,e)=>{const{projectVirtualPath:t}=o,r=[];let n=0;for(const o of e){const e={},s=normalizeGroupName(t,n++);for(const[t,r]of Object.entries(o))r.groupName=s,e[t]=r;r.push(e)}return r};export const autoGrouping=(o,e,t=[],r)=>{const{maxEntryGroupSize:n=10}=o,s=autoGroupingReduce(e,t,r),u=[];for(const[,o]of Object.entries(s)){const e=Object.keys(o);if(e.length>n)for(let t=0;t<e.length;t+=n){const r=e.slice(t,t+n).reduce(((e,t)=>(e[t]=o[t],e)),{});u.push(r)}else u.push(o)}return autoAssignGroupName(o,u)};export const splitToEntryGroup=(o,e,t=ignoreEntryOptionKeys,r)=>{const{isolation:n=!1}=e;if(n){const e=[];for(const[t,r]of Object.entries(o))r.groupName=t,e.push({[t]:r});return e}const s=_.flatMap(o,((o,e)=>({...o,entryName:e}))),u=_.groupBy(s,(o=>o.groupingSource));return[...manualGrouping(u.manual),...autoGrouping(e,u.auto,t,r)]};
@@ -0,0 +1,9 @@
1
+ import { type EvolveEntryItemOption, type EvolveEntryMap } from '../types/types-entry-map.js';
2
+ /**
3
+ * Verifies if the options of all entries in a group are equal, excluding specified keys.
4
+ *
5
+ * @param groupEvolveEntryMap - The map of group entries.
6
+ * @param ignoreOptionKeys - The keys to be ignored when comparing options.
7
+ * @returns A boolean indicating if the options of all entries are equal.
8
+ */
9
+ export declare const verifyGroupEntryOptions: (groupEvolveEntryMap: EvolveEntryMap, ignoreOptionKeys: Array<keyof EvolveEntryItemOption> | undefined, serveMode: boolean) => boolean;
@@ -0,0 +1 @@
1
+ import{ignoreEntryOptionKeys}from"../constants.js";import{isDeepEqual}from"./is-deep-equal.js";import{normalizeCheckEntryOptions}from"./normalize-check-entry-options.js";export const verifyGroupEntryOptions=(n,o=ignoreEntryOptionKeys,t)=>{const e=Object.values(n);if(1===e.length)return!0;const r=e.shift(),i=normalizeCheckEntryOptions(t,r?.options,o);return e.every((n=>isDeepEqual(i,normalizeCheckEntryOptions(t,n.options,o))))};
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './define-config/index.js';
2
2
  export * from './load-config/index.js';
3
3
  export * from './main/index.js';
4
- export * from './types/types-options.js';
5
4
  export * from './types/types-entry-map.js';
5
+ export * from './types/types-options.js';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export*from"./define-config/index.js";export*from"./load-config/index.js";export*from"./main/index.js";export*from"./types/types-options.js";export*from"./types/types-entry-map.js";
1
+ export*from"./define-config/index.js";export*from"./load-config/index.js";export*from"./main/index.js";export*from"./types/types-entry-map.js";export*from"./types/types-options.js";
@@ -1 +1 @@
1
- import{searchConfig}from"@armit/config-loader";import{mergeOptions,logger}from"@flatjs/common";import{configFileName,moduleName}from"../constants.js";import{defaultEvolveOptions}from"../default-options.js";import{normalizeResolveAlias}from"../helpers/normalize-resolve-alias.js";import{refreshEvolveMockOptions}from"../helpers/refresh-evolve-mock-options.js";export const loadEvolveConfig=async(o,e,i={},s={configFile:configFileName,esmLoaderOptions:{externals:[/^@flatjs\/.*/]}})=>{const{configFile:r,esmLoaderOptions:l}=s,a=await searchConfig(r,e,{esm:{...l,projectCwd:e}});let n={};n="function"==typeof a?.config?await(a?.config(o)):a?.config||{};const t=mergeOptions(defaultEvolveOptions,n),m=mergeOptions(t,i),f=mergeOptions(m,{projectCwd:e}),c="build"===o.command?f:await refreshEvolveMockOptions(e,f,s);return logger.debug(`Load evolve config:\n${JSON.stringify(c,null,2)}`,moduleName),c.webpack?.resolve?.alias&&(c.webpack.resolve.alias=normalizeResolveAlias(e,c.webpack?.resolve?.alias)),c};
1
+ import{searchConfig}from"@armit/config-loader";import{logger,mergeOptions}from"@flatjs/common";import{configFileName,moduleName}from"../constants.js";import{defaultEvolveOptions}from"../default-options.js";import{normalizeResolveAlias}from"../helpers/normalize-resolve-alias.js";import{refreshEvolveMockOptions}from"../helpers/refresh-evolve-mock-options.js";export const loadEvolveConfig=async(o,e,i={},s={configFile:configFileName,esmLoaderOptions:{externals:[/^@flatjs\/.*/]}})=>{const{configFile:r,esmLoaderOptions:l}=s,a=await searchConfig(r,e,{esm:{...l,projectCwd:e}});let n={};n="function"==typeof a?.config?await(a?.config(o)):a?.config||{};const t=mergeOptions(defaultEvolveOptions,n),m=mergeOptions(t,i),f=mergeOptions(m,{projectCwd:e}),c="build"===o.command?f:await refreshEvolveMockOptions(e,f,s);return logger.debug(`Load evolve config:\n${JSON.stringify(c,null,2)}`,moduleName),c.webpack?.resolve?.alias&&(c.webpack.resolve.alias=normalizeResolveAlias(e,c.webpack?.resolve?.alias)),c};
@@ -9,7 +9,8 @@ const svgOptimize = (buffer, svgoOption) => {
9
9
  return data;
10
10
  };
11
11
  const iconLoader = function iconLoader(source) {
12
- this.cacheable && this.cacheable(true);
12
+ if (this.cacheable)
13
+ this.cacheable(true);
13
14
  const options = this.getOptions();
14
15
  const callback = this.async();
15
16
  try {
@@ -1,16 +1,31 @@
1
- import { type PoolInterface, type BaseWorker } from '@armit/worker-threads';
2
- import { startBuildWorker } from './start-build-worker.js';
3
- declare class ThreadPoolForUnittest implements BaseWorker {
4
- private workerSize;
5
- constructor(workerSize: number);
6
- startBuildWorker(...args: Parameters<typeof startBuildWorker>): Promise<import("src/main/start-one-entry-build.js").EvolveBuildResult>;
7
- get pool(): PoolInterface;
1
+ import Tinypool from 'tinypool';
2
+ import { type ThreadsOptions } from '../types/types-threads-options.js';
3
+ import startBuildWorker from './start-build-worker.js';
4
+ interface BaseThreadPool {
5
+ startBuildWorker: (options: Parameters<typeof startBuildWorker>[0]) => ReturnType<typeof startBuildWorker>;
6
+ terminate(): void;
8
7
  }
9
- export declare const createThreadWorker: (workerSize: number) => Promise<ThreadPoolForUnittest | (BaseWorker & {
10
- all: {
11
- readonly startBuildWorker: (projectCwd: string, entryKey: string, serializedEvolveOptions: string, configLoaderOptions?: import("src/load-config/types.js").ConfigLoaderOptions | undefined) => Promise<import("src/main/start-one-entry-build.js").EvolveBuildResult>;
12
- };
13
- } & {
14
- readonly startBuildWorker: (projectCwd: string, entryKey: string, serializedEvolveOptions: string, configLoaderOptions?: import("src/load-config/types.js").ConfigLoaderOptions | undefined) => Promise<import("src/main/start-one-entry-build.js").EvolveBuildResult>;
15
- })>;
8
+ /**
9
+ * Represents a thread pool for unit testing.
10
+ */
11
+ declare class ThreadPoolForUnittest implements BaseThreadPool {
12
+ startBuildWorker(options: Parameters<typeof startBuildWorker>[0]): Promise<import("./start-group-entry-build.js").EvolveBuildResult>;
13
+ terminate(): void;
14
+ }
15
+ /**
16
+ * Represents a thread pool for executing tasks using the TinyPool library.
17
+ */
18
+ declare class ThreadPoolForTinyPool implements BaseThreadPool {
19
+ pool: Tinypool;
20
+ /**
21
+ * Creates a new instance of the `ThreadPoolForTinyPool` class.
22
+ * @param workerPath The path to the worker file.
23
+ * @param workerSize The number of worker threads to create.
24
+ * @param options Optional configuration options for the worker pool.
25
+ */
26
+ constructor(workerPath: string, options?: ThreadsOptions);
27
+ startBuildWorker(options: Parameters<typeof startBuildWorker>[0]): ReturnType<typeof startBuildWorker>;
28
+ terminate(): void;
29
+ }
30
+ export declare const createThreadWorker: (options?: ThreadsOptions) => ThreadPoolForUnittest | ThreadPoolForTinyPool;
16
31
  export {};
@@ -1 +1 @@
1
- import EventEmitter from"events";import{createThreadPool}from"@armit/worker-threads";import{getWorkerPath}from"./get-worker-path.js";import{startBuildWorker}from"./start-build-worker.js";class ThreadPoolForUnittest{constructor(r){this.workerSize=r}startBuildWorker(...r){return startBuildWorker(...r)}get pool(){const r=new EventEmitter,e={terminate(){console.warn('[WARNING] Using fake "terminate" for unittest!')},refill(){console.warn('[WARNING] Using fake "refill" for unittest!')},async drain(){console.warn('[WARNING] Using fake "drain" for unittest!')},size:this.workerSize,isTerminated:!1,threads:new Map};return Object.assign(r,e)}}export const createThreadWorker=async r=>{const e=getWorkerPath();return"test"===process.env.NODE_ENV?(console.warn("[WARNING] Using fake thread pool worker for unittest!"),new ThreadPoolForUnittest(r)):await createThreadPool(e,{size:r})};
1
+ import Tinypool from"tinypool";import{mergeOptions}from"@flatjs/common";import{customMessageChannel}from"../helpers/custom-message-channel.js";import{getWorkerPath}from"./get-worker-path.js";import startBuildWorker from"./start-build-worker.js";class ThreadPoolForUnittest{startBuildWorker(e){return startBuildWorker(e)}terminate(){console.warn('[WARNING] Using fake "terminate" for unittest!')}}class ThreadPoolForTinyPool{constructor(e,r){const{idleTimeout:o=6e4,minThreads:t=1,maxThreads:s}=r||{};this.pool=new Tinypool({runtime:"worker_threads",filename:e,minThreads:t,maxThreads:s,idleTimeout:o})}startBuildWorker(e){const{port1:r}=customMessageChannel.createMessageChannel(),o=mergeOptions(e,{messagePort:r});return this.pool.run(o,{transferList:[r]})}terminate(){this.pool.destroy(),customMessageChannel.dispose()}}export const createThreadWorker=e=>{const r=getWorkerPath();return"test"===process.env.NODE_ENV?(console.warn("[WARNING] Using fake thread pool worker for unittest!"),new ThreadPoolForUnittest):new ThreadPoolForTinyPool(r,e)};
@@ -1,4 +1,4 @@
1
1
  export * from './start-build.js';
2
+ export * from './start-build-dynamic.js';
2
3
  export * from './start-serve.js';
3
4
  export * from './start-static.js';
4
- export * from './start-build-dynamic.js';
@@ -1 +1 @@
1
- export*from"./start-build.js";export*from"./start-serve.js";export*from"./start-static.js";export*from"./start-build-dynamic.js";
1
+ export*from"./start-build.js";export*from"./start-build-dynamic.js";export*from"./start-serve.js";export*from"./start-static.js";
@@ -0,0 +1,9 @@
1
+ import { type AnalyzeServeOptions } from '../types/types-analyzer.js';
2
+ /**
3
+ * Prepares and analyzes webpack bundle stats.
4
+ *
5
+ * @param statsPaths - An array of paths to the webpack bundle stats files.
6
+ * @param options - Options for analyzing the webpack bundle stats.
7
+ * @returns A promise that resolves to a boolean indicating whether the analysis was successful.
8
+ */
9
+ export declare const prepareAnalyzer: (statsPaths: string[], options: AnalyzeServeOptions) => Promise<boolean>;
@@ -0,0 +1 @@
1
+ import _ from"lodash";import{createReadStream}from"node:fs";import{start}from"webpack-bundle-analyzer";import{cancel,confirm,intro,isCancel,multiselect,outro}from"@clack/prompts";import{parseChunked}from"@discoveryjs/json-ext";import{chalk,logger}from"@flatjs/common";import{moduleName}from"../constants.js";import{formatSpinnerText}from"../helpers/format-spinner-text.js";import{getStatsFileName}from"../helpers/get-stats-file-name.js";const readStatsFromFile=async e=>parseChunked(createReadStream(e,{encoding:"utf8"})),getStatsFilenames=async e=>{const t=[];for(const[r,a]of Object.entries(e)){const e=_.flattenDeep(Object.values(a.assetsByChunkName||{})).filter((e=>e.endsWith(".js"))),s=`Group ${chalk(["magenta"])(a.name||"")} \n${formatSpinnerText(e,`${chalk(["cyan"])("◆ ")}`)}`;t.push({value:r,label:s})}intro("Webpack bundle analyzer");const r=await multiselect({message:"Select entry groups to analyze",required:!0,options:t});if(isCancel(r))return cancel("The process has exited"),process.exit(0);const a=await confirm({message:"Are you sure to perform the analysis?"});return isCancel(a)?(cancel("The process has exited"),process.exit(0)):a?(outro("You're all set!"),r):getStatsFilenames(e)},startServer=async(e,t)=>{try{return await start(e,t),!0}catch(e){return logger.error(`Failed to start the analyzer serve ${e}`,moduleName),!1}};export const prepareAnalyzer=async(e,t)=>{const r={};for(const t of e){const e=await readStatsFromFile(t);r[getStatsFileName(e)]=e}const a=[],s=await getStatsFilenames(r);for(const e of s)a.push(startServer(r[e],t));return Promise.all(a).then((()=>!0))};
@@ -1,9 +1,10 @@
1
- import { type EntryMapItem } from '../types/types-entry-map.js';
1
+ import { FlatCliOptions } from '../types/types-cli-options.js';
2
+ import { type EvolveEntryMap } from '../types/types-entry-map.js';
2
3
  import { type FlatEvolveOptions } from '../types/types-options.js';
3
- import { type EvolveBuildResult } from './start-one-entry-build.js';
4
+ import { type EvolveBuildResult } from './start-group-entry-build.js';
4
5
  /**
5
6
  * The main entry to start an evolve `build`
6
7
  * @param entryMapItem The `entryMapItem` for one entry build task
7
8
  * @param evolveOptions FlatEvolveOptions
8
9
  */
9
- export declare const prepareBuild: (entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => Promise<EvolveBuildResult>;
10
+ export declare const prepareBuild: (groupEntries: EvolveEntryMap, evolveOptions: FlatEvolveOptions, cliOptions?: FlatCliOptions) => Promise<EvolveBuildResult>;
@@ -1 +1 @@
1
- import{ensureSlash,mergeOptions}from"@flatjs/common";import{EvolveBuildError}from"../errors/evolve-build-error.js";import{printCompilerError}from"../helpers/print-log.js";import{startOneEntryBuild}from"./start-one-entry-build.js";export const prepareBuild=async(r,o)=>{const[t,e]=r,n=o.multiHtmlCdn?.prod||[];if(!n.length)throw new Error(`No CDN config for env:"prod", moduleName: ${t}`);const i=ensureSlash(n[Math.floor(Math.random()*n.length)],!0),l={[t]:e};try{const r=e.options?.useRelativeAssetPath,t=mergeOptions(o,{webpack:{publicPath:r?"auto":i}});return await startOneEntryBuild(l,t)}catch(r){const o=printCompilerError(r);throw new EvolveBuildError("BUILD_ERROR",o)}};
1
+ import{ensureSlash,mergeOptions}from"@flatjs/common";import{ignoreEntryOptionKeys}from"../constants.js";import{EvolveBuildError}from"../errors/evolve-build-error.js";import{printCompilerError}from"../helpers/print-log.js";import{verifyGroupEntryOptions}from"../helpers/verify-group-entry-options.js";import{startGroupEntryBuild}from"./start-group-entry-build.js";export const prepareBuild=async(r,o,t)=>{const e=Object.values(r)[0];if(!verifyGroupEntryOptions(r,ignoreEntryOptionKeys,!0))throw new Error("The entry options in a group must be the same.");const n=o.multiHtmlCdn?.prod||[];if(!n.length)throw new Error(`No CDN config for env:"prod", groupName: ${e.groupName}`);const i=ensureSlash(n[Math.floor(Math.random()*n.length)],!0);try{const n=e.options?.useRelativeAssetPath,s=mergeOptions(o,{webpack:{publicPath:n?"auto":i}});return await startGroupEntryBuild(r,s,t)}catch(r){const o=printCompilerError(r);throw new EvolveBuildError("BUILD_ERROR",o)}};
@@ -6,4 +6,4 @@ import { type FlatEvolveOptions } from '../types/types-options.js';
6
6
  * @param servedEntries All normalized webpack entries we have served.
7
7
  * @param evolveOptions FlatEvolveOptions
8
8
  */
9
- export declare const prepareServe: (projectCwd: string, servedEntries: EvolveEntryMap, evolveOptions: FlatEvolveOptions) => Promise<import("express-serve-static-core").Express>;
9
+ export declare const prepareServe: (projectCwd: string, servedEntries: EvolveEntryMap, evolveOptions: FlatEvolveOptions) => Promise<import("express-serve-static-core").Express | undefined>;
@@ -1 +1 @@
1
- import{arrayUnique,urlJoin}from"@flatjs/common";import{attachMockMiddlewares}from"@flatjs/mock";import{createAppPageRoute,createDevServer,createDevServerCompilerTasks,createDevServerEntries}from"../dev-server/index.js";import{openPage}from"../helpers/index.js";import{normalizePageProxy}from"../helpers/normalize-page-proxy.js";import{envVerify}from"./env-verify.js";export const prepareServe=async(e,r,o)=>{await envVerify(e,o);const{app:t,devPort:a,devHostUri:i,publicIp:s}=await createDevServer(o),p=o.devServer?.mockOptions?.mockFilters||[];for(const[,e]of Object.entries(r))p.push(...e.options?.mockFilters||[]);await attachMockMiddlewares(t,{...o.devServer?.mockOptions,mockFilters:arrayUnique(p),projectCwd:e});const n=await createDevServerEntries(a,r,o);createAppPageRoute(e,t,i,n,o);const c=normalizePageProxy(o.devServer?.pageProxy||"/pages"),v=urlJoin(i,[c]);o.devServer?.autoOpen&&openPage(v);const m=await createDevServerCompilerTasks(e,v,s,n,o);return Promise.all(m).then((()=>t))};
1
+ import{arrayUnique,chalk,logger,urlJoin}from"@flatjs/common";import{attachMockMiddlewares}from"@flatjs/mock";import{ignoreEntryOptionKeys,moduleName}from"../constants.js";import{createAppPageRoute,createDevServer,createDevServerCompilerTask,createDevServerEntries}from"../dev-server/index.js";import{flatEntryMap,openPage}from"../helpers/index.js";import{normalizePageProxy}from"../helpers/normalize-page-proxy.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{verifyGroupEntryOptions}from"../helpers/verify-group-entry-options.js";import{envVerify}from"./env-verify.js";export const prepareServe=async(e,r,o)=>{await envVerify(e,o);const t=splitToEntryGroup(r,o,ignoreEntryOptionKeys,!0);if(!t.length)return void logger.warn("No served entries provided!");const n=[],{app:i,devPort:a,devHostUri:p,publicIp:s}=await createDevServer(o),c=o.devServer?.mockOptions?.mockFilters||[];for(const[,e]of Object.entries(r))c.push(...e.options?.mockFilters||[]);await attachMockMiddlewares(i,{...o.devServer?.mockOptions,mockFilters:arrayUnique(c),projectCwd:e});let m=a;const l=[];for(const e of t){if(!verifyGroupEntryOptions(e,ignoreEntryOptionKeys,!0))throw new Error("The entry options in a group must be the same.");m++;const r=await createDevServerEntries(m,e,o);l.push(r)}const v=flatEntryMap(l);createAppPageRoute(e,i,p,v,o);const y=normalizePageProxy(o.devServer?.pageProxy||"/pages"),f=urlJoin(p,[y]);o.devServer?.autoOpen&&openPage(f);for(const e of l){const r=createDevServerCompilerTask(s,e,l,o);n.push(r)}return Promise.all(n).then((()=>(logger.info(`debug page ➩ ${chalk(["cyan"])(f)}`,moduleName),i)))};
@@ -0,0 +1,10 @@
1
+ import { type AnalyzeServeOptions } from '../types/types-analyzer.js';
2
+ import { FlatEvolveOptions } from '../types/types-options.js';
3
+ /**
4
+ * Starts the analysis process for the given evolve options and analyze options.
5
+ *
6
+ * @param evolveOptions - The options for the evolve process.
7
+ * @param analyzeOptions - The options for the analyze process (optional).
8
+ * @returns A promise that resolves when the analysis process is complete.
9
+ */
10
+ export declare const startAnalyzer: (evolveOptions: FlatEvolveOptions, analyzeOptions?: AnalyzeServeOptions) => Promise<boolean | undefined>;
@@ -0,0 +1 @@
1
+ import{join}from"node:path";import{fileWalkSync}from"@armit/file-utility";import{logger,mergeOptions}from"@flatjs/common";import{webpackStatsDir}from"../constants.js";import{prepareAnalyzer}from"./prepare-analyzer.js";export const startAnalyzer=async(t,r={})=>{const{projectCwd:o,webpack:e}=t,n="function"==typeof e?.outputDir?await e.outputDir():e?.outputDir||"public",a=join(o,webpackStatsDir),i=fileWalkSync(["*.json"],{cwd:a});if(!i.length)return void logger.warn(`No stats files found in ${o}. skipping analyze.`);const p={openBrowser:!0,reportTitle:"flatjs_evolve_analyzer",port:0,host:"127.0.0.1",bundleDir:join(o,n),analyzerUrl:t=>{const{listenHost:r,boundAddress:o}=t;return`http://${r}:${o.port}`}},s=mergeOptions(p,r);return await prepareAnalyzer(i,s)};
@@ -1,14 +1,14 @@
1
1
  import { type PartialDeep } from 'type-fest';
2
2
  import { type ConfigLoaderOptions } from '../load-config/types.js';
3
3
  import { type FlatEvolveOptions } from '../types/types-options.js';
4
- import { type EvolveBuildResult } from './start-one-entry-build.js';
4
+ import { type EvolveBuildResult } from './start-group-entry-build.js';
5
5
  export declare function getBuildEntryFiles(projectCwd: string, diffFiles: string[], allEntryInputs: string[], resolveAlias?: Record<string, string>, graphTreeNodeFilter?: (moduleId: string) => boolean): Promise<string[]>;
6
6
  /**
7
7
  * Dynamic check which entry modules need to build.
8
8
  * @returns
9
9
  */
10
10
  export declare function dynamicCheckBuildEntryMap(projectCwd: string, earlyCommit?: string | null, lastCommit?: string, overrideEvolveOptions?: PartialDeep<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions): Promise<{
11
- buildEntries: import("src/index.js").EvolveEntryMap;
11
+ buildEntries: import("../index.js").EvolveEntryMap;
12
12
  newEvolveOptions: FlatEvolveOptions;
13
13
  }>;
14
14
  /**
@@ -1 +1 @@
1
- import{isAbsolute,join}from"node:path";import{getDiffFiles,getCommitIdOfBranch}from"@armit/git";import{arraysIntersect,chalk,logger,requireResolve}from"@flatjs/common";import{traverseGraph}from"@flatjs/graph";import Listr from"listr";import{moduleName}from"../constants.js";import{filterActivedEntriesByEntryInputs,filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{getGitRoot}from"../helpers/get-git-root.js";import{getMaxProcessTasks}from"../helpers/get-max-process-tasks.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{resolveEntryMapInputFiles}from"../helpers/resolve-entry-map-input-files.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{createThreadWorker}from"./create-thread-worker.js";import{envVerify}from"./env-verify.js";export async function getBuildEntryFiles(e,r,t,i,o){const n=[],s=[];for(const e of t)r.includes(e)?n.push(e):s.push(e);if(o&&logger.info("Use custom graph traverse filter",moduleName),s.length){const t=await traverseGraph({input:s,projectCwd:e,treeNodeFilter:o||(()=>!0),lessImportOptions:{projectCwd:e,aliases:i}});if(!t)return n;logger.debug(`DependencyGraph:\n${JSON.stringify(t,null,2)}`);for(const e of s){const i=t[e]||[];arraysIntersect(i,r)&&n.push(e)}}return n}export async function dynamicCheckBuildEntryMap(e,r,t,i,o){const n={projectCwd:e,command:"build",resolve:requireResolve},s=await loadEvolveConfig(n,e,i,o);if(s.ci?.fixedBuildModules&&s.ci?.fixedBuildModules.length){logger.info("Use `fixedBuildModules` configuration to build...");return{buildEntries:filterActivedEntriesByModule(s.entryMap,s.ci?.fixedBuildModules),newEvolveOptions:s}}if(logger.info("Dynamicly checking code changed modules ..."),!r){const e=s.ci?.basedBranch||"origin/master";r=await getCommitIdOfBranch(e),logger.info(`Resolving base branch "${e}" commit hash "${r}" ...`)}let a=r?await getDiffFiles(r,t):[];const l=getGitRoot(e);if(!l)throw new Error(`No .git root (${e}) found`);if(a=a.map((e=>isAbsolute(e)?e:join(l,e))),logger.debug(`Diff files: \n${JSON.stringify(a,null,2)}`),!a.length)return logger.warn("It seems that there are no code files changed."),{buildEntries:{},newEvolveOptions:s};const c=await resolveEntryMapInputFiles(e,s.entryMap),d=await getBuildEntryFiles(e,a,c,s.webpack?.resolve?.alias,s.ci?.graphTreeNodeFilter);logger.debug(`To build entry files: \n${JSON.stringify(d,null,2)}`);return{buildEntries:await filterActivedEntriesByEntryInputs(e,s.entryMap,d),newEvolveOptions:s}}export const startDynamicBuild=async(e,r,t,i={},o)=>{const{buildEntries:n,newEvolveOptions:s}=await dynamicCheckBuildEntryMap(e,r,t,i,o);await envVerify(e,s);const a=Object.keys(n);if(!a.length)return logger.warn("No build entries providered!"),[];const l=getMaxProcessTasks(a.length,s.maxProcesses);logger.info(`Start dynamic build with (${chalk(["magenta"])(String(l))}) workers:\n${JSON.stringify({buildEntries:a},null,2)}`);const c=await createThreadWorker(l),d=new Listr([],{concurrent:l,exitOnError:!0}),f=[];for(const[r]of Object.entries(n))d.add({title:`Build module ${chalk(["magenta"])(r)} ...`,task:async()=>{const t=await c.startBuildWorker(e,r,jsonSerializer.stringify(i),o);f.push(t)}});return d.tasks.length&&await d.run(),c.pool.terminate(),f};
1
+ import Listr from"listr";import{isAbsolute,join}from"node:path";import{getCommitIdOfBranch,getDiffFiles}from"@armit/git";import{arraysIntersect,chalk,logger,requireResolve}from"@flatjs/common";import{traverseGraph}from"@flatjs/graph";import{createGlobalCompiler}from"../compiler/create-global-compiler.js";import{ignoreEntryOptionKeys,moduleName}from"../constants.js";import{isCI}from"../helpers/check-runtime-env.js";import{CustomListrRenderer}from"../helpers/custom-listr-renderer.js";import{filterActivedEntriesByEntryInputs,filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{formatSpinnerText}from"../helpers/format-spinner-text.js";import{getGitRoot}from"../helpers/get-git-root.js";import{getMaxProcessTasks}from"../helpers/get-max-process-tasks.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{resolveEntryMapInputFiles}from"../helpers/resolve-entry-map-input-files.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{createThreadWorker}from"./create-thread-worker.js";import{envVerify}from"./env-verify.js";export async function getBuildEntryFiles(e,r,t,o,i){const n=[],s=[];for(const e of t)r.includes(e)?n.push(e):s.push(e);if(i&&logger.info("Use custom graph traverse filter",moduleName),s.length){const t=await traverseGraph({input:s,projectCwd:e,treeNodeFilter:i||(()=>!0),lessImportOptions:{projectCwd:e,aliases:o}});if(!t)return n;logger.debug(`DependencyGraph:\n${JSON.stringify(t,null,2)}`);for(const e of s){const o=t[e]||[];arraysIntersect(o,r)&&n.push(e)}}return n}export async function dynamicCheckBuildEntryMap(e,r,t,o,i){const n={projectCwd:e,command:"build",resolve:requireResolve},s=await loadEvolveConfig(n,e,o,i);if(s.ci?.fixedBuildModules&&s.ci?.fixedBuildModules.length){logger.info("Use `fixedBuildModules` configuration to build...");return{buildEntries:filterActivedEntriesByModule(s.entryMap,s.ci?.fixedBuildModules),newEvolveOptions:s}}if(logger.info("Dynamicly checking code changed modules ..."),!r){const e=s.ci?.basedBranch||"origin/master";r=await getCommitIdOfBranch(e),logger.info(`Resolving base branch "${e}" commit hash "${r}" ...`)}let a=r?await getDiffFiles(r,t):[];const l=getGitRoot(e);if(!l)throw new Error(`No .git root (${e}) found`);if(a=a.map((e=>isAbsolute(e)?e:join(l,e))),logger.debug(`Diff files: \n${JSON.stringify(a,null,2)}`),!a.length)return logger.warn("It seems that there are no code files changed."),{buildEntries:{},newEvolveOptions:s};const p=await resolveEntryMapInputFiles(e,s.entryMap),m=await getBuildEntryFiles(e,a,p,s.webpack?.resolve?.alias,s.ci?.graphTreeNodeFilter);logger.debug(`To build entry files: \n${JSON.stringify(m,null,2)}`);return{buildEntries:await filterActivedEntriesByEntryInputs(e,s.entryMap,m),newEvolveOptions:s}}export const startDynamicBuild=async(e,r,t,o={},i)=>{const{buildEntries:n,newEvolveOptions:s}=await dynamicCheckBuildEntryMap(e,r,t,o,i);await envVerify(e,s);const a=normalizeEvolveEntryMap(n,s.entryMap),l=splitToEntryGroup(a,s,ignoreEntryOptionKeys,!1);if(!l.length)return logger.warn("No build entries provided!"),[];await createGlobalCompiler(!1,s);const{threads:p={}}=s,m=getMaxProcessTasks(l.length,p?.maxThreads);logger.info(`Start dynamic build with (${chalk(["magenta"])(String(m))}) workers`);const c=createThreadWorker({...p,maxThreads:m}),f=new Listr([],{concurrent:m,exitOnError:!0,renderer:isCI()?void 0:CustomListrRenderer}),d=[];for(const r of l){const t=Object.values(r)?.[0]?.groupName||"",n=Object.keys(r);let s=`Group ${chalk(["magenta"])(t)} $STATUS \n${formatSpinnerText(n)}`;isCI()&&(s=`Group ${chalk(["magenta"])(t)} compiling... \n${formatSpinnerText(n)}`),f.add({title:s,task:async()=>{const r=await c.startBuildWorker({projectCwd:e,entryKeys:n,serializedEvolveOptions:jsonSerializer.stringify(o),configLoaderOptions:i,groupName:t});d.push(r)}})}if(f.tasks.length)try{await f.run()}catch(e){throw c.terminate(),e}return c.terminate(),d};
@@ -1,12 +1,23 @@
1
+ import { MessageChannel } from 'node:worker_threads';
1
2
  import { type ConfigLoaderOptions } from '../load-config/types.js';
2
- import { type EvolveBuildResult } from './start-one-entry-build.js';
3
+ import { FlatCliOptions } from '../types/types-cli-options.js';
4
+ import { type EvolveBuildResult } from './start-group-entry-build.js';
3
5
  /**
4
6
  * FIXME: The main entry to start an evolve `build`, NOTE: avoid pass configuration with `function` here.
5
7
  * If you need to call build api avoid `worker` you can directly call `prepareBuild`
6
8
  * @internal
7
- * @param projectCwd The Root directory (workspace) of this project.
8
- * @param entryKey The `entryKey` for one entry build task
9
- * @param serializedEvolveOptions The overrided evolve options, NOTE: we will serialize `function` property here first
10
- * @param configLoaderOptions Evolve config loader options, NOTE: avoid pass configuration with `function` here.
9
+ * @param options.projectCwd The Root directory (workspace) of this project.
10
+ * @param options.entryKey The `entryKey` for one entry build task
11
+ * @param options.serializedEvolveOptions The overrided evolve options, NOTE: we will serialize `function` property here first
12
+ * @param options.configLoaderOptions Evolve config loader options, NOTE: avoid pass configuration with `function` here.
11
13
  */
12
- export declare const startBuildWorker: (projectCwd: string, entryKey: string, serializedEvolveOptions: string, configLoaderOptions?: ConfigLoaderOptions) => Promise<EvolveBuildResult>;
14
+ declare const _default: (options: {
15
+ projectCwd: string;
16
+ entryKeys: string[];
17
+ serializedEvolveOptions: string;
18
+ configLoaderOptions?: ConfigLoaderOptions;
19
+ messagePort?: MessageChannel["port1"];
20
+ groupName?: string;
21
+ cliOptions?: FlatCliOptions;
22
+ }) => Promise<EvolveBuildResult>;
23
+ export default _default;
@@ -1 +1 @@
1
- import{requireResolve}from"@flatjs/common";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareBuild}from"./prepare-build.js";export const startBuildWorker=async(e,r,o,i)=>{const l={projectCwd:e,command:"build",resolve:requireResolve},t=jsonSerializer.parse(o)||{},n=await loadEvolveConfig(l,e,t,i),a=filterActivedEntriesByModule(n.entryMap,[new RegExp(`^${r}$`)]);if(!Object.keys(a).length)throw new Error(`No build entry resolved via "${r}" on "startBuildWorker"!`);const s=normalizeEvolveEntryMap(a,n.entryMap)[r];return prepareBuild([r,s],n)};
1
+ import{configLoggerStdWriteSteam,loggerSimpleStdWriteSteam,requireResolve}from"@flatjs/common";import{ignoreEntryOptionKeys}from"../constants.js";import{isCI}from"../helpers/check-runtime-env.js";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareBuild}from"./prepare-build.js";export default async e=>{isCI()||configLoggerStdWriteSteam();const{projectCwd:r,entryKeys:o,serializedEvolveOptions:t,configLoaderOptions:i,messagePort:s,groupName:p="flatjs_evolve_group",cliOptions:n}=e,l={projectCwd:r,command:"build",resolve:requireResolve},a=jsonSerializer.parse(t)||{},m=await loadEvolveConfig(l,r,a,i),f=o.map((e=>new RegExp(`^${e}$`))),g=filterActivedEntriesByModule(m.entryMap,f),d=normalizeEvolveEntryMap(g,m.entryMap),v=splitToEntryGroup(d,m,ignoreEntryOptionKeys,!1)[0];for(const[,e]of Object.entries(v))e.groupName=p;return prepareBuild(v,m,n).then((e=>(isCI()||loggerSimpleStdWriteSteam.postMessage(s),e)))};
@@ -1,5 +1,6 @@
1
1
  import { type PartialDeep } from 'type-fest';
2
2
  import { type ConfigLoaderOptions } from '../load-config/types.js';
3
+ import { FlatCliOptions } from '../types/types-cli-options.js';
3
4
  import { type FlatEvolveOptions } from '../types/types-options.js';
4
- import { type EvolveBuildResult } from './start-one-entry-build.js';
5
- export declare const startBuild: (projectCwd: string, buildModules: string[], overrideEvolveOptions?: PartialDeep<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions) => Promise<EvolveBuildResult[]>;
5
+ import { type EvolveBuildResult } from './start-group-entry-build.js';
6
+ export declare const startBuild: (projectCwd: string, buildModules: string[], overrideEvolveOptions?: PartialDeep<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions, cliOptions?: FlatCliOptions) => Promise<EvolveBuildResult[]>;
@@ -1 +1 @@
1
- import{chalk,logger,requireResolve}from"@flatjs/common";import Listr from"listr";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{getMaxProcessTasks}from"../helpers/get-max-process-tasks.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{createThreadWorker}from"./create-thread-worker.js";import{envVerify}from"./env-verify.js";export const startBuild=async(e,r,t={},o)=>{const i={projectCwd:e,command:"build",resolve:requireResolve},s=await loadEvolveConfig(i,e,t,o);await envVerify(e,s);const a=filterActivedEntriesByModule(s.entryMap,r),n=Object.keys(a);if(!n.length)return logger.warn("No build entries providered!"),[];const l=getMaxProcessTasks(n.length,s.maxProcesses);logger.info(`Start standard build with (${chalk(["magenta"])(String(l))}) workers:\n${JSON.stringify({buildEntries:n},null,2)}`);const c=await createThreadWorker(l),d=new Listr([],{concurrent:l,exitOnError:!0}),m=[];for(const[r]of Object.entries(a))d.add({title:`Build module ${chalk(["magenta"])(r)} ...`,task:async()=>{const i=await c.startBuildWorker(e,r,jsonSerializer.stringify(t),o);m.push(i)}});return d.tasks.length&&await d.run(),c.pool.terminate(),m};
1
+ import Listr from"listr";import{chalk,logger,requireResolve}from"@flatjs/common";import{createGlobalCompiler}from"../compiler/create-global-compiler.js";import{ignoreEntryOptionKeys}from"../constants.js";import{isCI}from"../helpers/check-runtime-env.js";import{CustomListrRenderer}from"../helpers/custom-listr-renderer.js";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{formatSpinnerText}from"../helpers/format-spinner-text.js";import{getMaxProcessTasks}from"../helpers/get-max-process-tasks.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{createThreadWorker}from"./create-thread-worker.js";import{envVerify}from"./env-verify.js";import{startAnalyzer}from"./start-analyzer.js";export const startBuild=async(r,e,t={},o,i={})=>{const{analyzer:s=!1}=i,a={projectCwd:r,command:"build",resolve:requireResolve},n=await loadEvolveConfig(a,r,t,o);await envVerify(r,n);const l=filterActivedEntriesByModule(n.entryMap,e),m=normalizeEvolveEntryMap(l,n.entryMap),p=splitToEntryGroup(m,n,ignoreEntryOptionKeys,!1);if(!p.length)return logger.warn("No build entries provided!"),[];await createGlobalCompiler(!1,n);const{threads:c={}}=n,f=getMaxProcessTasks(p.length,c?.maxThreads);logger.info(`Start standard build with (${chalk(["magenta"])(String(f))}) workers`);const d=createThreadWorker({...c,maxThreads:f}),g=new Listr([],{concurrent:f,exitOnError:!0,renderer:isCI()?void 0:CustomListrRenderer}),y=[];for(const e of p){const s=Object.values(e)?.[0]?.groupName||"",a=Object.keys(e);let n=`Group ${chalk(["magenta"])(s)} $STATUS \n${formatSpinnerText(a)}`;isCI()&&(n=`Group ${chalk(["magenta"])(s)} compiling... \n${formatSpinnerText(a)}`),g.add({title:n,task:async()=>{const e=await d.startBuildWorker({projectCwd:r,entryKeys:a,groupName:s,serializedEvolveOptions:jsonSerializer.stringify(t),configLoaderOptions:o,cliOptions:i});y.push(e)}})}if(g.tasks.length)try{await g.run()}catch(r){throw d.terminate(),r}return d.terminate(),s&&startAnalyzer(n),y};
@@ -0,0 +1,15 @@
1
+ import { FlatCliOptions } from '../types/types-cli-options.js';
2
+ import { type EvolveEntryMap } from '../types/types-entry-map.js';
3
+ import { type FlatEvolveOptions } from '../types/types-options.js';
4
+ export type EvolveBuildResult = {
5
+ name?: string[];
6
+ warningStats?: unknown;
7
+ };
8
+ /**
9
+ * Starts the build process for a group of entry files.
10
+ *
11
+ * @param groupBuildEntry - The map of entry files to be built.
12
+ * @param evolveOptions - The options for the build process.
13
+ * @returns A promise that resolves to the build result.
14
+ */
15
+ export declare const startGroupEntryBuild: (groupBuildEntry: EvolveEntryMap, evolveOptions: FlatEvolveOptions, cliOptions?: FlatCliOptions) => Promise<EvolveBuildResult>;
@@ -0,0 +1 @@
1
+ import webpack from"webpack";import{loadWebpackConfig}from"../create-webpack/load-webpack-config.js";import{assertSingleCompiler}from"../helpers/assert-single-compiler.js";import{normalizeEvolveEntryName}from"../helpers/normalize-entry-map.js";export const startGroupEntryBuild=async(r,e,n)=>{const o=await loadWebpackConfig("production",r,e,n),t=assertSingleCompiler(r,o,e,!1);return new Promise(((n,o)=>{webpack(t,((t,a)=>{if(t)return o(t);const i=a?.toJson();if(i?.errors?.length)return o(i.errors);if(e.rejectWarnings&&i?.warnings?.length)return o(i.warnings);const{projectVirtualPath:s}=e,p=Object.keys(r).map((r=>normalizeEvolveEntryName(r,s)));n({name:p,warningStats:i?.warnings})}))}))};
@@ -8,4 +8,4 @@ import { type FlatEvolveOptions } from '../types/types-options.js';
8
8
  * @param overrideEvolveOptions The overrided evolve options
9
9
  * @param configLoaderOptions Evolve config loader options
10
10
  */
11
- export declare const startServe: (projectCwd: string, serveModules: string[], overrideEvolveOptions?: PartialDeep<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions) => Promise<never[] | import("express-serve-static-core").Express>;
11
+ export declare const startServe: (projectCwd: string, serveModules: string[], overrideEvolveOptions?: PartialDeep<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions) => Promise<never[] | import("express-serve-static-core").Express | undefined>;
@@ -1 +1 @@
1
- import{logger,requireResolve}from"@flatjs/common";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareServe}from"./prepare-serve.js";export const startServe=async(e,r,o={},t)=>{const i={projectCwd:e,command:"serve",resolve:requireResolve},n=await loadEvolveConfig(i,e,o,t),l=filterActivedEntriesByModule(n.entryMap,r),s=Object.keys(l);if(!s.length)return logger.warn("No served entries providered!"),[];logger.info({servedEntries:s});const v=normalizeEvolveEntryMap(l,n.entryMap);return prepareServe(e,v,n)};
1
+ import{logger,requireResolve}from"@flatjs/common";import{createGlobalCompiler}from"../compiler/create-global-compiler.js";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareServe}from"./prepare-serve.js";export const startServe=async(e,r,o={},t)=>{const l={projectCwd:e,command:"serve",resolve:requireResolve},i=await loadEvolveConfig(l,e,o,t),a=filterActivedEntriesByModule(i.entryMap,r),n=Object.keys(a);if(!n.length)return logger.warn("No served entries providered!"),[];logger.info({servedEntries:n});const p=normalizeEvolveEntryMap(a,i.entryMap);return await createGlobalCompiler(!0,i),prepareServe(e,p,i)};
@@ -1 +1 @@
1
- import{logger}from"@flatjs/common";import{moduleName}from"../constants.js";import{printInfo}from"../helpers/print-log.js";import{imageMinimizer}from"./image-minimizer.js";import{terserMinimizer}from"./terser-minimizer.js";export const createMinimizers=(i,r)=>{const e=[];if(i)return logger.debug("Ignore minimizer plugin for `serve` mode",moduleName),e;if(!1===r?.minimizer)return printInfo("Note `minimizer` has been disabled for now"),e;if(r?.minimizer?.imageMin){const i=imageMinimizer();i&&e.push(i)}const m=terserMinimizer(r?.minimizer?.terserOptions||{});return e.push(m),e};
1
+ import{logger}from"@flatjs/common";import{moduleName}from"../constants.js";import{printInfo}from"../helpers/print-log.js";import{imageMinimizer}from"./image-minimizer.js";import{terserMinimizer}from"./terser-minimizer.js";export const createMinimizers=(i,r)=>{const e=[];if(i)return logger.debug("Ignore minimizer plugin for `serve` mode",moduleName),e;if(!1===r?.minimizer)return printInfo("Note `minimizer` has been disabled for now"),e;if(r?.minimizer?.imageMin){const i=imageMinimizer();i&&e.push(i)}if(!1===r?.minimizer?.terserOptions)return e;const m=terserMinimizer(r?.minimizer?.terserOptions||{});return e.push(m),e};
@@ -1 +1 @@
1
- import{projectHasYarn}from"@armit/package";import{chalk,logger,requireResolve}from"@flatjs/common";import ImageMinimizerPlugin from"image-minimizer-webpack-plugin";import{moduleName}from"../constants.js";const logs=new Map;export const imageMinimizer=()=>{const e=[],i=[["svgo",{}],["gifsicle",{}],["jpegtran",{}],["pngquant",{}]].map((i=>{const n=i[0];try{return requireResolve(import.meta.url,`imagemin-${n}`),i}catch(i){if(!logs.get(n)){logs.set(n,!0);const i=chalk(["magenta"])(`"${projectHasYarn()?"yarn add":"npm install"} imagemin-${n} -D"`);e.push(`Execute ${i} for assets optimization`)}return null}})).filter(Boolean);if(e.length)for(const i of e)logger.warn(i,moduleName);return i.length?new ImageMinimizerPlugin({minimizer:{implementation:ImageMinimizerPlugin.imageminMinify,options:{plugins:i}}}):null};
1
+ import ImageMinimizerPlugin from"image-minimizer-webpack-plugin";import{projectHasYarn}from"@armit/package";import{chalk,logger,requireResolve}from"@flatjs/common";import{moduleName}from"../constants.js";const logs=new Map;export const imageMinimizer=()=>{const e=[],i=[["svgo",{}],["gifsicle",{}],["jpegtran",{}],["pngquant",{}]].map((i=>{const n=i[0];try{return requireResolve(import.meta.url,`imagemin-${n}`),i}catch{if(!logs.get(n)){logs.set(n,!0);const i=chalk(["magenta"])(`"${projectHasYarn()?"yarn add":"npm install"} imagemin-${n} -D"`);e.push(`Execute ${i} for assets optimization`)}return null}})).filter(Boolean);if(e.length)for(const i of e)logger.warn(i,moduleName);return i.length?new ImageMinimizerPlugin({minimizer:{implementation:ImageMinimizerPlugin.imageminMinify,options:{plugins:i}}}):null};
@@ -1,3 +1,3 @@
1
- import{mergeOptions}from"@flatjs/common";import TerserPlugin from"terser-webpack-plugin";import{defaultTerserOptions}from"./default-options.js";export const terserMinimizer=e=>new TerserPlugin({parallel:!0,
1
+ import TerserPlugin from"terser-webpack-plugin";import{mergeOptions}from"@flatjs/common";import{defaultTerserOptions}from"./default-options.js";export const terserMinimizer=e=>new TerserPlugin({parallel:!0,
2
2
  // Disable Extract all or some (use /^\**!|@preserve|@license|@cc_on/i RegExp) comments.
3
3
  extractComments:!1,terserOptions:mergeOptions(defaultTerserOptions,e)});
@@ -1 +1 @@
1
- import{relative}from"node:path";import{mergeOptions}from"@flatjs/common";import Graph from"tarjan-graph";import webpack from"webpack";const BASE_ERROR="Circular dependency detected:\r\n",PLUGIN_TITLE="CircularDependencyPlugin";export class CircularDependencyPlugin{constructor(o={}){this.options=mergeOptions({exclude:/node_modules/,include:/.*/,failOnError:!1,allowAsyncCycles:!1,projectCwd:process.cwd()},o)}apply(o){const e=this.options.projectCwd;o.hooks.compilation.tap(PLUGIN_TITLE,(o=>{o.hooks.optimizeModules.tap(PLUGIN_TITLE,(t=>{this.options.onStart&&this.options.onStart({compilation:o});const n=new(Graph.default||Graph);for(const e of t){const t=[];for(const n of e.dependencies){if(n.constructor&&"CommonJsSelfReferenceDependency"===n.constructor.name)continue;let r=null;r=o.moduleGraph?o.moduleGraph.getModule(n):n.module,r&&(r instanceof webpack.NormalModule&&r.resource&&(this.options.allowAsyncCycles&&n.weak||e!==r&&t.push(r.identifier())))}n.add(e.identifier(),t)}const r=n.getCycles();this.isCyclic(r,o,e),this.options.onEnd&&this.options.onEnd({compilation:o})}))}))}isCyclic(o,e,t){o.forEach((o=>{const n=o.slice().reverse().map((o=>{const t=e.findModule(o.name);return t instanceof webpack.NormalModule&&t.resource||null}));if(n.every((o=>!o||this.options.exclude.test(o)||!this.options.include.test(o))))return;const r=n.map((o=>relative(t,o)));if(this.options.onDetected){try{this.options.onDetected({paths:r.concat([r[0]]),compilation:e})}catch(o){e.errors.push(o)}return}const s=new Error(BASE_ERROR.concat(r.concat([r[0]]).join(" -> ")));this.options.failOnError?e.errors.push(s):e.warnings.push(s)}))}}
1
+ import{relative}from"node:path";import Graph from"tarjan-graph";import webpack from"webpack";import{mergeOptions}from"@flatjs/common";const BASE_ERROR="Circular dependency detected:\r\n",PLUGIN_TITLE="CircularDependencyPlugin";export class CircularDependencyPlugin{constructor(o={}){this.options=mergeOptions({exclude:/node_modules/,include:/.*/,failOnError:!1,allowAsyncCycles:!1,projectCwd:process.cwd()},o)}apply(o){const e=this.options.projectCwd;o.hooks.compilation.tap(PLUGIN_TITLE,(o=>{o.hooks.optimizeModules.tap(PLUGIN_TITLE,(t=>{this.options.onStart&&this.options.onStart({compilation:o});const n=new(Graph.default||Graph);for(const e of t){const t=[];for(const n of e.dependencies){if(n.constructor&&"CommonJsSelfReferenceDependency"===n.constructor.name)continue;let r=null;r=o.moduleGraph?o.moduleGraph.getModule(n):n.module,r&&(r instanceof webpack.NormalModule&&r.resource&&(this.options.allowAsyncCycles&&n.weak||e!==r&&t.push(r.identifier())))}n.add(e.identifier(),t)}const r=n.getCycles();this.isCyclic(r,o,e),this.options.onEnd&&this.options.onEnd({compilation:o})}))}))}isCyclic(o,e,t){o.forEach((o=>{const n=o.slice().reverse().map((o=>{const t=e.findModule(o.name);return t instanceof webpack.NormalModule&&t.resource||null}));if(n.every((o=>!o||this.options.exclude.test(o)||!this.options.include.test(o))))return;const r=n.map((o=>relative(t,o)));if(this.options.onDetected){try{this.options.onDetected({paths:r.concat([r[0]]),compilation:e})}catch(o){e.errors.push(o)}return}const s=new Error(BASE_ERROR.concat(r.concat([r[0]]).join(" -> ")));this.options.failOnError?e.errors.push(s):e.warnings.push(s)}))}}
@@ -6,4 +6,4 @@ import { type FlatEvolveOptions } from '../../types/types-options.js';
6
6
  * @param singleEntryItem
7
7
  * @returns
8
8
  */
9
- export declare const createCleanWebpackPlugin: (serveMode: boolean, entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => WebpackPlugin[];
9
+ export declare const createCleanWebpackPlugin: (serveMode: boolean, entryMapItemList: EntryMapItem[], evolveOptions: FlatEvolveOptions) => WebpackPlugin[];
@@ -1 +1 @@
1
- import{join}from"node:path";import{ensureSlash}from"@flatjs/common";import{CleanWebpackPlugin}from"./clean-webpack-plugin.js";export const createCleanWebpackPlugin=(e,n,o)=>e?[]:[new CleanWebpackPlugin({verbose:!0,projectCwd:o.projectCwd,cleanOnceBeforeBuildPatterns:[`${join(ensureSlash(n[0],!0),"**/*")}`]})];
1
+ import{join}from"node:path";import{ensureSlash}from"@flatjs/common";import{CleanWebpackPlugin}from"./clean-webpack-plugin.js";export const createCleanWebpackPlugin=(e,n,o)=>e?[]:[new CleanWebpackPlugin({verbose:!0,projectCwd:o.projectCwd,cleanOnceBeforeBuildPatterns:n.map((e=>`${join(ensureSlash(e[0],!0),"**/*")}`))})];
@@ -1 +1 @@
1
- import{getLastCommitHash,gitBranchName}from"@armit/git";import webpack from"webpack";export const createBuiltinDefineVariables=async(e,i)=>{const t=await getLastCommitHash(),n=await gitBranchName();return[new webpack.DefinePlugin({__SENTRY_DEBUG__:e,"process.env.FLAT_BUILD_DATE":JSON.stringify((new Date).toISOString()),"process.env.FLAT_COMMIT_HASH":JSON.stringify(t),"process.env.FLAT_BRANCH_NAME":JSON.stringify(n),"process.env.FLAT_RELEASE_VERSION":JSON.stringify(i.ci?.releaseVersion||t),...i.pluginOptions.definePlugin})]};
1
+ import webpack from"webpack";import{getLastCommitHash,gitBranchName}from"@armit/git";export const createBuiltinDefineVariables=async(e,i)=>{const t=await getLastCommitHash(),n=await gitBranchName();return[new webpack.DefinePlugin({__SENTRY_DEBUG__:e,"process.env.FLAT_BUILD_DATE":JSON.stringify((new Date).toISOString()),"process.env.FLAT_COMMIT_HASH":JSON.stringify(t),"process.env.FLAT_BRANCH_NAME":JSON.stringify(n),"process.env.FLAT_RELEASE_VERSION":JSON.stringify(i.ci?.releaseVersion||t),...i.pluginOptions.definePlugin})]};