@flatjs/evolve 2.1.0-next.2 → 2.1.0-next.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) 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 +5 -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 +1 -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 +1 -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/create-dev-server-compiler-task.d.ts +3 -0
  29. package/dist/dev-server/create-dev-server-compiler-task.js +1 -0
  30. package/dist/dev-server/create-dev-server-entries.d.ts +1 -1
  31. package/dist/dev-server/create-dev-server-entries.js +1 -1
  32. package/dist/dev-server/create-dev-server.js +1 -1
  33. package/dist/dev-server/index.d.ts +3 -3
  34. package/dist/dev-server/index.js +1 -1
  35. package/dist/dev-server/middlewares/get-bundle-asset.d.ts +1 -1
  36. package/dist/dev-server/middlewares/get-page-main-html.js +1 -1
  37. package/dist/dev-server/middlewares/get-page-module-html.js +1 -1
  38. package/dist/helpers/assert-group-entry-item.d.ts +7 -0
  39. package/dist/helpers/assert-group-entry-item.js +1 -0
  40. package/dist/helpers/assert-single-compiler.d.ts +15 -0
  41. package/dist/helpers/assert-single-compiler.js +1 -0
  42. package/dist/helpers/custom-listr-renderer.d.ts +41 -0
  43. package/dist/helpers/custom-listr-renderer.js +1 -0
  44. package/dist/helpers/custom-message-channel.d.ts +17 -0
  45. package/dist/helpers/custom-message-channel.js +1 -0
  46. package/dist/helpers/delete-object-keys.d.ts +11 -0
  47. package/dist/helpers/delete-object-keys.js +1 -0
  48. package/dist/helpers/flat-entry-map.d.ts +8 -0
  49. package/dist/helpers/flat-entry-map.js +1 -0
  50. package/dist/helpers/format-spinner-text.d.ts +7 -0
  51. package/dist/helpers/format-spinner-text.js +1 -0
  52. package/dist/helpers/get-bundle-file-name.d.ts +1 -1
  53. package/dist/helpers/get-runtime-cdn-base.d.ts +2 -0
  54. package/dist/helpers/get-runtime-cdn-base.js +1 -0
  55. package/dist/helpers/index.d.ts +16 -4
  56. package/dist/helpers/index.js +1 -1
  57. package/dist/helpers/is-deep-equal.d.ts +9 -0
  58. package/dist/helpers/is-deep-equal.js +1 -0
  59. package/dist/helpers/json-serializer.js +1 -1
  60. package/dist/helpers/normalize-check-entry-options.d.ts +10 -0
  61. package/dist/helpers/normalize-check-entry-options.js +1 -0
  62. package/dist/helpers/normalize-entry-map.d.ts +1 -0
  63. package/dist/helpers/normalize-entry-map.js +1 -1
  64. package/dist/helpers/normalize-group-name.d.ts +8 -0
  65. package/dist/helpers/normalize-group-name.js +1 -0
  66. package/dist/helpers/normalize-template-inject-tokens.d.ts +16 -0
  67. package/dist/helpers/normalize-template-inject-tokens.js +1 -0
  68. package/dist/helpers/open-page.js +1 -1
  69. package/dist/helpers/refresh-evolve-mock-options.js +1 -1
  70. package/dist/helpers/script-injects.d.ts +1 -1
  71. package/dist/helpers/should-enable-react-fast-refresh.js +1 -1
  72. package/dist/helpers/split-to-entry-group.d.ts +52 -0
  73. package/dist/helpers/split-to-entry-group.js +1 -0
  74. package/dist/helpers/verify-group-entry-options.d.ts +9 -0
  75. package/dist/helpers/verify-group-entry-options.js +1 -0
  76. package/dist/index.d.ts +1 -1
  77. package/dist/index.js +1 -1
  78. package/dist/load-config/load-evolve-config.js +1 -1
  79. package/dist/loaders/loader-icon.cjs +2 -1
  80. package/dist/main/create-thread-worker.d.ts +29 -14
  81. package/dist/main/create-thread-worker.js +1 -1
  82. package/dist/main/index.d.ts +1 -1
  83. package/dist/main/index.js +1 -1
  84. package/dist/main/prepare-build.d.ts +3 -3
  85. package/dist/main/prepare-build.js +1 -1
  86. package/dist/main/prepare-serve.d.ts +1 -1
  87. package/dist/main/prepare-serve.js +1 -1
  88. package/dist/main/start-build-dynamic.d.ts +2 -2
  89. package/dist/main/start-build-dynamic.js +1 -1
  90. package/dist/main/start-build-worker.d.ts +14 -6
  91. package/dist/main/start-build-worker.js +1 -1
  92. package/dist/main/start-build.d.ts +1 -1
  93. package/dist/main/start-build.js +1 -1
  94. package/dist/main/start-group-entry-build.d.ts +14 -0
  95. package/dist/main/start-group-entry-build.js +1 -0
  96. package/dist/main/start-serve.d.ts +1 -1
  97. package/dist/main/start-serve.js +1 -1
  98. package/dist/minimizer/image-minimizer.js +1 -1
  99. package/dist/minimizer/terser-minimizer.js +1 -1
  100. package/dist/plugins/circular-dependency/circular-dependency-plugin.js +1 -1
  101. package/dist/plugins/clean-webpack/index.d.ts +1 -1
  102. package/dist/plugins/clean-webpack/index.js +1 -1
  103. package/dist/plugins/define-variable/define-variable-plugin.js +1 -1
  104. package/dist/plugins/module-federation/module-federation.d.ts +1 -1
  105. package/dist/plugins/module-federation/module-federation.js +1 -1
  106. package/dist/plugins/multi-html/index.d.ts +1 -1
  107. package/dist/plugins/multi-html/index.js +1 -1
  108. package/dist/plugins/multi-html/multi-html-cdn-plugin.js +1 -1
  109. package/dist/plugins/multi-html/multi-html-plugin.d.ts +1 -1
  110. package/dist/plugins/multi-html/multi-html-plugin.js +1 -1
  111. package/dist/plugins/ts-checker/ts-checker-guard-plugin.d.ts +13 -0
  112. package/dist/plugins/ts-checker/ts-checker-guard-plugin.js +1 -0
  113. package/dist/plugins/ts-checker/ts-checker-plugin.d.ts +3 -0
  114. package/dist/plugins/ts-checker/ts-checker-plugin.js +1 -0
  115. package/dist/types/index.d.ts +2 -1
  116. package/dist/types/index.js +1 -1
  117. package/dist/types/types-dev-server.d.ts +5 -6
  118. package/dist/types/types-entry-map.d.ts +16 -2
  119. package/dist/types/types-global-compiler-options.d.ts +7 -0
  120. package/dist/types/types-global-compiler-options.js +1 -0
  121. package/dist/types/types-loader-options.d.ts +31 -9
  122. package/dist/types/types-options.d.ts +30 -11
  123. package/dist/types/types-threads-options.d.ts +18 -0
  124. package/dist/types/types-threads-options.js +1 -0
  125. package/dist/types/types-webpack.d.ts +1 -1
  126. package/package.json +65 -61
  127. package/templates/html-plugin/index-dev.html +2 -2
  128. package/templates/html-plugin/index-inte.html +2 -2
  129. package/templates/html-plugin/index-inte2.html +2 -2
  130. package/templates/html-plugin/index-inte3.html +2 -2
  131. package/templates/html-plugin/index-inte4.html +2 -2
  132. package/templates/html-plugin/index-me.html +2 -2
  133. package/templates/html-plugin/index-ntv.html +61 -0
  134. package/templates/html-plugin/index-prod.html +2 -2
  135. package/templates/html-plugin/index-rc.html +2 -2
  136. package/templates/html-plugin/index-uat.html +2 -2
  137. package/templates/module.html +2 -2
  138. package/dist/dev-server/create-dev-server-compiler-tasks.d.ts +0 -3
  139. package/dist/dev-server/create-dev-server-compiler-tasks.js +0 -1
  140. package/dist/helpers/assert-only-single-entry-item.d.ts +0 -7
  141. package/dist/helpers/assert-only-single-entry-item.js +0 -1
  142. package/dist/helpers/split-to-multi-compiler.d.ts +0 -8
  143. package/dist/helpers/split-to-multi-compiler.js +0 -1
  144. package/dist/main/start-one-entry-build.d.ts +0 -13
  145. package/dist/main/start-one-entry-build.js +0 -1
@@ -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";
@@ -1,9 +1,9 @@
1
- import { type EntryMapItem } from '../types/types-entry-map.js';
1
+ import { type EvolveEntryMap } from '../types/types-entry-map.js';
2
2
  import { type FlatEvolveOptions } from '../types/types-options.js';
3
- import { type EvolveBuildResult } from './start-one-entry-build.js';
3
+ import { type EvolveBuildResult } from './start-group-entry-build.js';
4
4
  /**
5
5
  * The main entry to start an evolve `build`
6
6
  * @param entryMapItem The `entryMapItem` for one entry build task
7
7
  * @param evolveOptions FlatEvolveOptions
8
8
  */
9
- export declare const prepareBuild: (entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => Promise<EvolveBuildResult>;
9
+ export declare const prepareBuild: (groupEntries: EvolveEntryMap, evolveOptions: FlatEvolveOptions) => 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)=>{const t=Object.values(r)[0];if(!verifyGroupEntryOptions(r,ignoreEntryOptionKeys,!0))throw new Error("The entry options in a group must be the same.");const e=o.multiHtmlCdn?.prod||[];if(!e.length)throw new Error(`No CDN config for env:"prod", groupName: ${t.groupName}`);const n=ensureSlash(e[Math.floor(Math.random()*e.length)],!0);try{const e=t.options?.useRelativeAssetPath,i=mergeOptions(o,{webpack:{publicPath:e?"auto":n}});return await startGroupEntryBuild(r,i)}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,logger,urlJoin}from"@flatjs/common";import{attachMockMiddlewares}from"@flatjs/mock";import{ignoreEntryOptionKeys}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:s,devHostUri:p,publicIp:a}=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 v=s;const m=[];for(const e of t){if(!verifyGroupEntryOptions(e,ignoreEntryOptionKeys,!0))throw new Error("The entry options in a group must be the same.");v++;const r=await createDevServerEntries(v,e,o);m.push(r)}const l=flatEntryMap(m);createAppPageRoute(e,i,p,l,o);const y=normalizePageProxy(o.devServer?.pageProxy||"/pages"),f=urlJoin(p,[y]);o.devServer?.autoOpen&&openPage(f);for(const r of m){const t=createDevServerCompilerTask(e,f,a,r,m,o);n.push(t)}return Promise.all(n).then((()=>i))};
@@ -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{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),c=await getBuildEntryFiles(e,a,p,s.webpack?.resolve?.alias,s.ci?.graphTreeNodeFilter);logger.debug(`To build entry files: \n${JSON.stringify(c,null,2)}`);return{buildEntries:await filterActivedEntriesByEntryInputs(e,s.entryMap,c),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,c=getMaxProcessTasks(l.length,p?.maxThreads);logger.info(`Start dynamic build with (${chalk(["magenta"])(String(c))}) workers`);const m=createThreadWorker({...p,maxThreads:c}),d=new Listr([],{concurrent:c,exitOnError:!0,renderer:CustomListrRenderer}),f=[];for(const r of l){const t=Object.values(r)?.[0]?.groupName||"",n=Object.keys(r);d.add({title:`Group ${chalk(["magenta"])(t)} $STATUS \n${formatSpinnerText(n)}`,task:async()=>{const r=await m.startBuildWorker({projectCwd:e,entryKeys:n,serializedEvolveOptions:jsonSerializer.stringify(o),configLoaderOptions:i});f.push(r)}})}if(d.tasks.length)try{await d.run()}catch(e){throw m.terminate(),e}return m.terminate(),f};
@@ -1,12 +1,20 @@
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 { type EvolveBuildResult } from './start-group-entry-build.js';
3
4
  /**
4
5
  * FIXME: The main entry to start an evolve `build`, NOTE: avoid pass configuration with `function` here.
5
6
  * If you need to call build api avoid `worker` you can directly call `prepareBuild`
6
7
  * @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.
8
+ * @param options.projectCwd The Root directory (workspace) of this project.
9
+ * @param options.entryKey The `entryKey` for one entry build task
10
+ * @param options.serializedEvolveOptions The overrided evolve options, NOTE: we will serialize `function` property here first
11
+ * @param options.configLoaderOptions Evolve config loader options, NOTE: avoid pass configuration with `function` here.
11
12
  */
12
- export declare const startBuildWorker: (projectCwd: string, entryKey: string, serializedEvolveOptions: string, configLoaderOptions?: ConfigLoaderOptions) => Promise<EvolveBuildResult>;
13
+ declare const _default: (options: {
14
+ projectCwd: string;
15
+ entryKeys: string[];
16
+ serializedEvolveOptions: string;
17
+ configLoaderOptions?: ConfigLoaderOptions;
18
+ messagePort?: MessageChannel["port1"];
19
+ }) => Promise<EvolveBuildResult>;
20
+ 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{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=>{configLoggerStdWriteSteam();const{projectCwd:r,entryKeys:o,serializedEvolveOptions:t,configLoaderOptions:i,messagePort:l}=e,n={projectCwd:r,command:"build",resolve:requireResolve},p=jsonSerializer.parse(t)||{},s=await loadEvolveConfig(n,r,p,i),a=o.map((e=>new RegExp(`^${e}$`))),m=filterActivedEntriesByModule(s.entryMap,a),d=normalizeEvolveEntryMap(m,s.entryMap),g=splitToEntryGroup(d,s,ignoreEntryOptionKeys,!1);return prepareBuild(g[0],s).then((e=>(loggerSimpleStdWriteSteam.postMessage(l),e)))};
@@ -1,5 +1,5 @@
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 const startBuild: (projectCwd: string, buildModules: string[], overrideEvolveOptions?: PartialDeep<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions) => 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{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";export const startBuild=async(r,e,t={},o)=>{const i={projectCwd:r,command:"build",resolve:requireResolve},s=await loadEvolveConfig(i,r,t,o);await envVerify(r,s);const a=filterActivedEntriesByModule(s.entryMap,e),n=normalizeEvolveEntryMap(a,s.entryMap),l=splitToEntryGroup(n,s,ignoreEntryOptionKeys,!1);if(!l.length)return logger.warn("No build entries provided!"),[];await createGlobalCompiler(!1,s);const{threads:m={}}=s,p=getMaxProcessTasks(l.length,m?.maxThreads);logger.info(`Start standard build with (${chalk(["magenta"])(String(p))}) workers`);const c=createThreadWorker({...m,maxThreads:p}),d=new Listr([],{concurrent:p,exitOnError:!0,renderer:CustomListrRenderer}),f=[];for(const e of l){const i=Object.values(e)?.[0]?.groupName||"",s=Object.keys(e);d.add({title:`Group ${chalk(["magenta"])(i)} $STATUS \n${formatSpinnerText(s)}`,task:async()=>{const e=await c.startBuildWorker({projectCwd:r,entryKeys:s,serializedEvolveOptions:jsonSerializer.stringify(t),configLoaderOptions:o});f.push(e)}})}if(d.tasks.length)try{await d.run()}catch(r){throw c.terminate(),r}return c.terminate(),f};
@@ -0,0 +1,14 @@
1
+ import { type EvolveEntryMap } from '../types/types-entry-map.js';
2
+ import { type FlatEvolveOptions } from '../types/types-options.js';
3
+ export type EvolveBuildResult = {
4
+ name?: string[];
5
+ warningStats?: unknown;
6
+ };
7
+ /**
8
+ * Starts the build process for a group of entry files.
9
+ *
10
+ * @param groupBuildEntry - The map of entry files to be built.
11
+ * @param evolveOptions - The options for the build process.
12
+ * @returns A promise that resolves to the build result.
13
+ */
14
+ export declare const startGroupEntryBuild: (groupBuildEntry: EvolveEntryMap, evolveOptions: FlatEvolveOptions) => 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)=>{const n=await loadWebpackConfig("production",r,e),o=assertSingleCompiler(r,n,e,!1);return new Promise(((n,t)=>{webpack(o,((o,a)=>{if(o)return t(o);const i=a?.toJson();if(i?.errors?.length)return t(i.errors);if(e.rejectWarnings&&i?.warnings?.length)return t(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{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})]};
@@ -1,4 +1,4 @@
1
1
  import { type WebpackPluginInstance } from 'webpack';
2
2
  import { type EntryMapItem } from '../../types/types-entry-map.js';
3
3
  import { type FlatEvolveOptions } from '../../types/types-options.js';
4
- export declare const createModuleFederationPlugin: (serveMode: boolean, entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => WebpackPluginInstance[];
4
+ export declare const createModuleFederationPlugin: (serveMode: boolean, entryMapItemList: EntryMapItem[], evolveOptions: FlatEvolveOptions) => WebpackPluginInstance[];
@@ -1 +1 @@
1
- import{join}from"node:path";import{ensureSlash}from"@flatjs/common";import webpack from"webpack";import{normalizeEvolveEntryName}from"../../helpers/normalize-entry-map.js";import{injectFederationScripts}from"../../helpers/script-injects.js";import{HtmlInjectScriptPlugin}from"../html-inject-scripts/plugin-html-inject-script.js";import{ExternalTemplateRemotesPlugin}from"./external-template-remotes.js";const normalizeWidgetName=(e="")=>e.replace(/[/-]/g,"_").toLowerCase(),remoteFileName=e=>join(e,"micro-remote-module.js");export const createModuleFederationPlugin=(e,t,r)=>{const o=r.projectVirtualPath,[n,i]=t,m=r.multiHtmlCdn,a=r.multiHtmlCdnEnvResolver,l=i.options?.moduleFederation,s=[];if(l){const{remotes:t,exposes:r,...i}=l,p=remoteFileName(n),c=normalizeWidgetName(n),u=(r?Array.isArray(r)?r:[r]:[]).map((e=>{const t={};for(const[r,o]of Object.entries(e))t[r]={...o,name:join(n,o.name.replace(/^\//,""))};return t})),d=(t||[]).map((({name:e,endpoint:t})=>{const r=normalizeEvolveEntryName(e,o),n=normalizeWidgetName(r),i=remoteFileName(r);return{[n]:`${n}@${t?ensureSlash(t(e,r),!1):"[window.evolveFetchMicroWidgets()]"}/${i}`}}));s.push(new webpack.container.ModuleFederationPlugin({...i,name:c,filename:p,remotes:d,exposes:u}),new ExternalTemplateRemotesPlugin),e||s.unshift(new HtmlInjectScriptPlugin([injectFederationScripts(m,a)]))}return s};
1
+ import{join}from"node:path";import webpack from"webpack";import{ensureSlash}from"@flatjs/common";import{normalizeEvolveEntryName}from"../../helpers/normalize-entry-map.js";import{injectFederationScripts}from"../../helpers/script-injects.js";import{HtmlInjectScriptPlugin}from"../html-inject-scripts/plugin-html-inject-script.js";import{ExternalTemplateRemotesPlugin}from"./external-template-remotes.js";const normalizeWidgetName=(e="")=>e.replace(/[/-]/g,"_").toLowerCase(),remoteFileName=e=>join(e,"micro-remote-module.js");export const createModuleFederationPlugin=(e,t,o)=>{const r=o.projectVirtualPath,n=o.multiHtmlCdn,i=o.multiHtmlCdnEnvResolver,m=[];for(const o of t){const[t,a]=o,l=a.options?.moduleFederation;if(l){const{remotes:o,exposes:a,...s}=l,c=remoteFileName(t),p=normalizeWidgetName(t),u=(a?Array.isArray(a)?a:[a]:[]).map((e=>{const o={};for(const[r,n]of Object.entries(e))o[r]={...n,name:join(t,n.name.replace(/^\//,""))};return o})),d=(o||[]).map((({name:e,endpoint:t})=>{const o=normalizeEvolveEntryName(e,r),n=normalizeWidgetName(o),i=remoteFileName(o),m=t?ensureSlash(t(e,o),!1):"[window.evolveFetchMicroWidgets()]";return{[n]:`${n}@${m}/${i}`}}));m.push(new webpack.container.ModuleFederationPlugin({...s,name:p,filename:c,remotes:d,exposes:u}),new ExternalTemplateRemotesPlugin),e||m.unshift(new HtmlInjectScriptPlugin([injectFederationScripts(n,i)]))}}return m};
@@ -1,4 +1,4 @@
1
1
  import { type WebpackPlugin } from '../../create-webpack/types.js';
2
2
  import { type EntryMapItem } from '../../types/types-entry-map.js';
3
3
  import { type FlatEvolveOptions } from '../../types/types-options.js';
4
- export declare const createHtmlPlugins: (serveMode: boolean, entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => WebpackPlugin[];
4
+ export declare const createHtmlPlugins: (serveMode: boolean, entryMapItemList: EntryMapItem[], evolveOptions: FlatEvolveOptions) => WebpackPlugin[];
@@ -1 +1 @@
1
- import{FlatEvolveMultiCdnPlugin}from"./multi-html-cdn-plugin.js";import{createMultiHtmlWebpackPlugin}from"./multi-html-plugin.js";export const createHtmlPlugins=(t,l,u)=>{const i=[];if(t||l[1]?.options?.output?.library)return i;const n=Object.keys(u.multiHtmlCdn);return i.push(...createMultiHtmlWebpackPlugin(t,u,l,n)),i.push(new FlatEvolveMultiCdnPlugin(u)),i};
1
+ import{FlatEvolveMultiCdnPlugin}from"./multi-html-cdn-plugin.js";import{createMultiHtmlWebpackPlugin}from"./multi-html-plugin.js";export const createHtmlPlugins=(t,l,u)=>{const i=[],n=l[0];if(t||n[1]?.options?.output?.library)return i;const e=Object.keys(u.multiHtmlCdn);return i.push(...createMultiHtmlWebpackPlugin(t,u,l,e)),i.push(new FlatEvolveMultiCdnPlugin(u)),i};
@@ -1 +1 @@
1
- import{basename}from"node:path";import HtmlWebpackPlugin from"html-webpack-plugin";import webpack from"webpack";import{cdnFinder,findEnvCdn,httpUrlJoin}from"../../helpers/script-injects.js";export class FlatEvolveMultiCdnPlugin{constructor(e){if(this.pluginName="FlatEvolveMultiCdnPlugin",this.requireFn=webpack.RuntimeGlobals.publicPath,this.config=e.multiHtmlCdn,this.cdnResolver=e.multiHtmlCdnEnvResolver||function cdnResolver(){},!this.config?.prod)throw new Error("We must setup `prod` for each CDN config node!")}apply(e){e.hooks.thisCompilation.tap(this.pluginName,(e=>{e.mainTemplate.hooks.requireExtensions.tap(this.pluginName,((n,t)=>{const i=[];i.push("// Dynamic assets path override(`@flatjs/evolve`) plugin-multi-html-cdn`)");const s=e.chunkGraph?.getTreeRuntimeRequirements(t);return s&&s.has(webpack.RuntimeGlobals.requireScope)&&(i.push("(function () {"),i.push(webpack.Template.indent("var flatjsMultiCdn = {")),i.push(webpack.Template.indent(webpack.Template.indent([`cdnConfig: ${JSON.stringify(this.config||{})},`]))),i.push(webpack.Template.indent(webpack.Template.indent([`cdnResolver: ${this.cdnResolver.toString()},`]))),i.push(webpack.Template.indent(webpack.Template.indent([`cdnFinder: ${cdnFinder.toString()}`]))),i.push(webpack.Template.indent("};")),i.push(webpack.Template.indent(`${this.requireFn} = flatjsMultiCdn.cdnFinder(flatjsMultiCdn.cdnConfig, flatjsMultiCdn.cdnResolver) || ${this.requireFn};`)),i.push("})();")),webpack.Template.asString(i)}))})),e.hooks.compilation.tap(this.pluginName,(e=>{HtmlWebpackPlugin.getHooks(e).beforeAssetTagGeneration.tap(this.pluginName,(e=>{const{assets:n}=e,{userOptions:t}=e.plugin,i=t.multiCdn,s=n.publicPath,a=n.js.map((e=>{if(i.disabled)return basename(e);const n=findEnvCdn(this.config,i.env);return httpUrlJoin(n,e.replace(s,""))})),p=n.css.map((e=>{if(i.disabled)return basename(e);const n=findEnvCdn(this.config,i.env);return httpUrlJoin(n,e.replace(s,""))}));return e.assets.js=a,e.assets.css=p,e}))}))}}
1
+ import HtmlWebpackPlugin from"html-webpack-plugin";import{basename}from"node:path";import webpack from"webpack";import{getRuntimeCDNBase}from"../../helpers/get-runtime-cdn-base.js";import{findEnvCdn,httpUrlJoin}from"../../helpers/script-injects.js";export class FlatEvolveMultiCdnPlugin{constructor(e){if(this.pluginName="FlatEvolveMultiCdnPlugin",this.requireFn=webpack.RuntimeGlobals.publicPath,this.config=e.multiHtmlCdn,this.cdnResolver=e.multiHtmlCdnEnvResolver||function cdnResolver(){},!this.config?.prod)throw new Error("We must setup `prod` for each CDN config node!")}apply(e){e.hooks.thisCompilation.tap(this.pluginName,(e=>{e.mainTemplate.hooks.requireExtensions.tap(this.pluginName,((t,n)=>{const i=[];i.push("// Dynamic assets path override(`@flatjs/evolve`) plugin-multi-html-cdn`)");const s=e.chunkGraph?.getTreeRuntimeRequirements(n);return s&&s.has(webpack.RuntimeGlobals.requireScope)&&i.push(webpack.Template.indent(getRuntimeCDNBase(this.config,this.cdnResolver,this.requireFn))),webpack.Template.asString(i)}))})),e.hooks.compilation.tap(this.pluginName,(e=>{HtmlWebpackPlugin.getHooks(e).beforeAssetTagGeneration.tap(this.pluginName,(e=>{const{assets:t,plugin:n,outputName:i}=e,s=n?.options?.chunks||[],r=Array.isArray(s)?s.find((e=>i.includes(e))):s,{userOptions:o}=e.plugin;if(!r)throw new Error("We must have current chunk!");const a=t.js.filter((e=>e.includes(r))),l=t.css.filter((e=>e.includes(r))),p=o.multiCdn,u=t.publicPath,c=a.map((e=>{if(p.disabled)return basename(e);const t=findEnvCdn(this.config,p.env);return httpUrlJoin(t,e.replace(u,""))})),m=l.map((e=>{if(p.disabled)return basename(e);const t=findEnvCdn(this.config,p.env);return httpUrlJoin(t,e.replace(u,""))}));return e.assets.js=c,e.assets.css=m,e}))}))}}
@@ -8,4 +8,4 @@ import { type FlatEvolveOptions } from '../../types/types-options.js';
8
8
  * @param buildEntryItem the entries for this `build`
9
9
  * @param allEnv
10
10
  */
11
- export declare const createMultiHtmlWebpackPlugin: (serveMode: boolean, evolveOptions: FlatEvolveOptions, entryMapItem: EntryMapItem, allEnv: Array<EvolveMultiCdnEnvType>) => WebpackPlugin[];
11
+ export declare const createMultiHtmlWebpackPlugin: (serveMode: boolean, evolveOptions: FlatEvolveOptions, entryMapItemList: EntryMapItem[], allEnv: Array<EvolveMultiCdnEnvType>) => WebpackPlugin[];
@@ -1 +1 @@
1
- import HtmlWebpackPlugin from"html-webpack-plugin";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";import{findEnvCdn}from"../../helpers/script-injects.js";const minifyOpts={minifyJS:!0,removeComments:!0,collapseWhitespace:!0,collapseBooleanAttributes:!1};export const createMultiHtmlWebpackPlugin=(e,t,i,l)=>{const[n,o]=i,r=[],{options:m}=o,g=e?"development":"production";for(const e of l){const l={mode:g,envCdn:findEnvCdn(t.multiHtmlCdn,e)};r.push(new HtmlWebpackPlugin({inject:"body",title:getHtmlPluginConfig("title",l,m?.title),chunks:[n],minify:!1!==m?.htmlMinify&&!["me","dev"].includes(e)&&minifyOpts,filename:`${n}/index${"prod"===e?"":`-${e}`}.html`,template:getHtmlPluginConfig("templatePath",l,m?.templatePath).replace("{0}",e),templateParameters:{title:getHtmlPluginConfig("title",l,m?.title),favicon:getHtmlPluginConfig("favicon",l,m?.favicon),headBeforeHtmlTags:getHtmlPluginConfig("headBeforeHtmlTags",l,m?.headBeforeHtmlTags),inlineScripts:getHtmlPluginConfig("inlineScripts",l,m?.inlineScripts),headBeforeStyles:getHtmlPluginConfig("headBeforeStyles",l,m?.headBeforeStyles),headBeforeScripts:getHtmlPluginConfig("headBeforeScripts",l,m?.headBeforeScripts),bodyAfterScripts:getHtmlPluginConfig("bodyAfterScripts",l,m?.bodyAfterScripts),viewport:allowPx2remForModule(i,t)?getHtmlPluginConfig("viewport",l,m?.viewport):""},multiCdn:{env:e,disabled:(m?.excludeCdnEnvs||["me","dev","ntv"]).includes(e)}}))}return r};
1
+ import HtmlWebpackPlugin from"html-webpack-plugin";import{existsSync}from"node:fs";import{logger}from"@flatjs/common";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";import{normalizeTemplateInjectTokens}from"../../helpers/normalize-template-inject-tokens.js";import{findEnvCdn}from"../../helpers/script-injects.js";const minifyOpts={minifyJS:!0,removeComments:!0,collapseWhitespace:!0,collapseBooleanAttributes:!1};export const createMultiHtmlWebpackPlugin=(e,t,l,i)=>{const n=l[0],[,o]=n,m=[],{options:r}=o,p=e?"development":"production",s=l.map((e=>e[0]));for(const e of i){const l={mode:p,envCdn:findEnvCdn(t.multiHtmlCdn,e)},i=normalizeTemplateInjectTokens(l,r);let o=getHtmlPluginConfig("templatePath",l,r?.templatePath).replace("{0}",e.trim());existsSync(o)||(logger.warn(`The template file ${o} is not exists, use \`prod\` instead!`),o=getHtmlPluginConfig("templatePath",l,r?.templatePath).replace("{0}","prod")),m.push(new HtmlWebpackPlugin({inject:"body",title:getHtmlPluginConfig("title",l,r?.title),chunks:s,minify:!1!==r?.htmlMinify&&!["me","dev"].includes(e)&&minifyOpts,filename:t=>`${t}/index${"prod"===e?"":`-${e}`}.html`,template:o,templateParameters:{title:getHtmlPluginConfig("title",l,r?.title),favicon:getHtmlPluginConfig("favicon",l,r?.favicon),viewport:allowPx2remForModule(n,t)?getHtmlPluginConfig("viewport",l,r?.viewport):"",...i},multiCdn:{env:e,disabled:(r?.excludeCdnEnvs||["me","dev","ntv"]).includes(e)}}))}return m};
@@ -0,0 +1,13 @@
1
+ import { type Compiler } from 'webpack';
2
+ export interface TsCheckerGuardPluginOption {
3
+ /**
4
+ * Whether to exit the process when issues is not empty
5
+ * @default false
6
+ */
7
+ autoExit?: boolean;
8
+ }
9
+ export declare class TsCheckerGuardPlugin {
10
+ private options;
11
+ constructor(option?: TsCheckerGuardPluginOption);
12
+ apply(compiler: Compiler): void;
13
+ }
@@ -0,0 +1 @@
1
+ import ForkTsCheckerWebpackPlugin from"fork-ts-checker-webpack-plugin";import{mergeOptions}from"@flatjs/common";export class TsCheckerGuardPlugin{constructor(r={}){this.options=mergeOptions({autoExit:!1},r)}apply(r){ForkTsCheckerWebpackPlugin.getCompilerHooks(r).issues.tap("issues",(r=>{const{autoExit:e}=this.options,o=r.filter((r=>"error"===r.severity));if(e&&o?.length>0)throw new Error(`TS_CHECKER_ERROR: \n ${JSON.stringify(o,null,2)}`);return r}))}}
@@ -0,0 +1,3 @@
1
+ import { type WebpackPlugin } from '../../create-webpack/types.js';
2
+ import { type FlatEvolveOptions } from '../../types/types-options.js';
3
+ export declare const createTsCheckerPlugins: (serveMode: boolean, evolveOptions: FlatEvolveOptions) => WebpackPlugin[];
@@ -0,0 +1 @@
1
+ import ForkTsCheckerWebpackPlugin from"fork-ts-checker-webpack-plugin";import{TsCheckerGuardPlugin}from"./ts-checker-guard-plugin.js";export const createTsCheckerPlugins=(e,r)=>{const{entryMap:t,globalCompilerOptions:c}=r,s=[];let n=!1;for(const[,e]of Object.entries(t)){if((e.entry||[]).find((e=>/.vue$/.test(e)))){n=!0;break}}if(c?.runTsChecker&&!n){const t=new ForkTsCheckerWebpackPlugin({async:e,devServer:!1,issue:{},typescript:{context:r.projectCwd,memoryLimit:8192}});s.push(t),s.push(new TsCheckerGuardPlugin({autoExit:!e}))}return s};
@@ -1,8 +1,9 @@
1
1
  export * from './types-dev-server.js';
2
2
  export * from './types-entry-map.js';
3
3
  export * from './types-federation.js';
4
+ export * from './types-global-compiler-options.js';
5
+ export * from './types-loader-options.js';
4
6
  export * from './types-modular-import.js';
5
7
  export * from './types-multi-html.js';
6
8
  export * from './types-options.js';
7
- export * from './types-loader-options.js';
8
9
  export * from './types-webpack.js';
@@ -1 +1 @@
1
- export*from"./types-dev-server.js";export*from"./types-entry-map.js";export*from"./types-federation.js";export*from"./types-modular-import.js";export*from"./types-multi-html.js";export*from"./types-options.js";export*from"./types-loader-options.js";export*from"./types-webpack.js";
1
+ export*from"./types-dev-server.js";export*from"./types-entry-map.js";export*from"./types-federation.js";export*from"./types-global-compiler-options.js";export*from"./types-loader-options.js";export*from"./types-modular-import.js";export*from"./types-multi-html.js";export*from"./types-options.js";export*from"./types-webpack.js";