@flatjs/evolve 2.1.0-next.12 → 2.1.0-next.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) 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.js +1 -36
  4. package/dist/create-webpack/create-externals.js +1 -6
  5. package/dist/create-webpack/create-optimization.js +1 -43
  6. package/dist/create-webpack/create-output.js +1 -35
  7. package/dist/create-webpack/create-performance.js +1 -7
  8. package/dist/create-webpack/create-plugins.js +1 -78
  9. package/dist/create-webpack/create-resolve.js +1 -37
  10. package/dist/create-webpack/create-rule-sets.js +1 -20
  11. package/dist/create-webpack/load-watch-options.d.ts +12 -0
  12. package/dist/create-webpack/load-watch-options.js +1 -0
  13. package/dist/create-webpack/load-webpack-config.js +1 -57
  14. package/dist/create-webpack/resolve-public-path.js +1 -15
  15. package/dist/create-webpack/rule-sets/constants.js +1 -3
  16. package/dist/create-webpack/rule-sets/rule-assets.js +1 -52
  17. package/dist/create-webpack/rule-sets/rule-css.js +1 -111
  18. package/dist/create-webpack/rule-sets/rule-less.js +1 -44
  19. package/dist/create-webpack/rule-sets/rule-scripts.d.ts +2 -0
  20. package/dist/create-webpack/rule-sets/rule-scripts.js +1 -34
  21. package/dist/create-webpack/rule-sets/rule-svg-icon.js +1 -25
  22. package/dist/create-webpack/rule-sets/rule-utils.js +1 -10
  23. package/dist/create-webpack/types.d.ts +1 -1
  24. package/dist/create-webpack/types.js +1 -1
  25. package/dist/default-options.js +1 -83
  26. package/dist/define-config/define-config.d.ts +2 -2
  27. package/dist/define-config/define-config.js +1 -4
  28. package/dist/define-config/index.js +1 -1
  29. package/dist/dev-server/add-compiler-to-dev-server.js +1 -58
  30. package/dist/dev-server/create-app-page-route.js +1 -13
  31. package/dist/dev-server/create-dev-server-compiler-task.js +1 -55
  32. package/dist/dev-server/create-dev-server-entries.js +1 -25
  33. package/dist/dev-server/create-dev-server.js +1 -24
  34. package/dist/dev-server/index.d.ts +3 -3
  35. package/dist/dev-server/index.js +1 -6
  36. package/dist/dev-server/middlewares/create-page-middleware.js +1 -33
  37. package/dist/dev-server/middlewares/create-public-assets-middleware.js +1 -25
  38. package/dist/dev-server/middlewares/get-all-sorted-modules.js +1 -24
  39. package/dist/dev-server/middlewares/get-bundle-asset.js +1 -7
  40. package/dist/dev-server/middlewares/get-dev-server-host-uri.js +1 -5
  41. package/dist/dev-server/middlewares/get-hmr-runtime-chunks.js +1 -14
  42. package/dist/dev-server/middlewares/get-normalized-entry-name.js +1 -14
  43. package/dist/dev-server/middlewares/get-page-main-html.js +1 -49
  44. package/dist/dev-server/middlewares/get-page-module-html.js +1 -123
  45. package/dist/dev-server/middlewares/get-project-virtual-path.js +1 -3
  46. package/dist/dev-server/middlewares/get-runtime-manifest.js +1 -25
  47. package/dist/dev-server/middlewares/index.js +1 -2
  48. package/dist/dev-server/middlewares/types.js +1 -1
  49. package/dist/errors/evolve-build-error.js +1 -10
  50. package/dist/helpers/allow-px2rem-for-module.js +1 -6
  51. package/dist/helpers/assert-group-entry-item.js +1 -19
  52. package/dist/helpers/assert-single-compiler.js +1 -45
  53. package/dist/helpers/chunk-entry-map.js +1 -21
  54. package/dist/helpers/delete-object-keys.js +1 -20
  55. package/dist/helpers/enable-bundle-hashname-for-module.js +1 -6
  56. package/dist/helpers/filter-actived-entries.js +1 -42
  57. package/dist/helpers/flat-entry-map.js +1 -11
  58. package/dist/helpers/get-bundle-file-name.js +1 -23
  59. package/dist/helpers/get-git-root.js +1 -4
  60. package/dist/helpers/get-html-plugin-config.js +1 -47
  61. package/dist/helpers/get-max-process-tasks.js +1 -7
  62. package/dist/helpers/get-pacakge-dir.js +1 -13
  63. package/dist/helpers/get-runtime-cdn-base.d.ts +1 -1
  64. package/dist/helpers/get-runtime-cdn-base.js +1 -21
  65. package/dist/helpers/index.d.ts +11 -11
  66. package/dist/helpers/index.js +1 -27
  67. package/dist/helpers/is-deep-equal.js +1 -67
  68. package/dist/helpers/json-serializer.js +1 -52
  69. package/dist/helpers/merge-babel-options.js +1 -45
  70. package/dist/helpers/normalize-check-entry-options.js +1 -28
  71. package/dist/helpers/normalize-entry-map.js +1 -59
  72. package/dist/helpers/normalize-group-name.js +1 -16
  73. package/dist/helpers/normalize-page-proxy.js +1 -9
  74. package/dist/helpers/normalize-resolve-alias.js +1 -7
  75. package/dist/helpers/normalize-template-inject-tokens.js +1 -22
  76. package/dist/helpers/open-page.js +1 -15
  77. package/dist/helpers/print-log.js +1 -49
  78. package/dist/helpers/refresh-evolve-mock-options.js +1 -34
  79. package/dist/helpers/resolve-entry-map-input-files.js +1 -20
  80. package/dist/helpers/script-injects.d.ts +1 -1
  81. package/dist/helpers/script-injects.js +1 -39
  82. package/dist/helpers/should-enable-react-fast-refresh.js +1 -14
  83. package/dist/helpers/split-to-entry-group.d.ts +1 -1
  84. package/dist/helpers/split-to-entry-group.js +1 -139
  85. package/dist/helpers/verify-group-entry-options.js +1 -21
  86. package/dist/index.d.ts +1 -1
  87. package/dist/index.js +1 -5
  88. package/dist/load-config/index.js +1 -1
  89. package/dist/load-config/load-evolve-config.js +1 -41
  90. package/dist/load-config/types.js +1 -1
  91. package/dist/loaders/loader-icon.cjs +2 -1
  92. package/dist/main/create-thread-worker.js +1 -51
  93. package/dist/main/env-verify.js +1 -21
  94. package/dist/main/get-worker-path.js +1 -5
  95. package/dist/main/index.d.ts +1 -1
  96. package/dist/main/index.js +1 -4
  97. package/dist/main/prepare-build.js +1 -39
  98. package/dist/main/prepare-serve.js +1 -69
  99. package/dist/main/prepare-static.js +1 -30
  100. package/dist/main/start-build-dynamic.js +1 -171
  101. package/dist/main/start-build-worker.js +1 -44
  102. package/dist/main/start-build.js +1 -69
  103. package/dist/main/start-group-entry-build.d.ts +1 -1
  104. package/dist/main/start-group-entry-build.js +1 -32
  105. package/dist/main/start-serve.js +1 -34
  106. package/dist/main/start-static.js +1 -19
  107. package/dist/minimizer/create-minimizers.js +1 -25
  108. package/dist/minimizer/default-options.js +1 -14
  109. package/dist/minimizer/image-minimizer.js +1 -65
  110. package/dist/minimizer/index.js +1 -1
  111. package/dist/minimizer/terser-minimizer.js +3 -15
  112. package/dist/minimizer/types.js +1 -1
  113. package/dist/plugins/circular-dependency/circular-dependency-plugin.js +1 -119
  114. package/dist/plugins/circular-dependency/index.js +1 -15
  115. package/dist/plugins/clean-webpack/clean-webpack-plugin.js +1 -173
  116. package/dist/plugins/clean-webpack/index.js +1 -22
  117. package/dist/plugins/define-variable/define-variable-plugin.js +1 -28
  118. package/dist/plugins/define-variable/index.js +1 -1
  119. package/dist/plugins/html-inject-scripts/plugin-html-inject-script.js +1 -27
  120. package/dist/plugins/module-federation/external-template-remotes.js +1 -92
  121. package/dist/plugins/module-federation/index.js +1 -1
  122. package/dist/plugins/module-federation/module-federation.js +1 -100
  123. package/dist/plugins/multi-html/index.js +1 -16
  124. package/dist/plugins/multi-html/multi-html-cdn-plugin.js +1 -83
  125. package/dist/plugins/multi-html/multi-html-plugin.js +1 -65
  126. package/dist/plugins/ts-checker/ts-checker-guard-plugin.d.ts +13 -0
  127. package/dist/plugins/ts-checker/ts-checker-guard-plugin.js +1 -0
  128. package/dist/plugins/ts-checker/ts-checker-plugin.d.ts +1 -2
  129. package/dist/plugins/ts-checker/ts-checker-plugin.js +1 -24
  130. package/dist/types/index.d.ts +2 -1
  131. package/dist/types/index.js +1 -8
  132. package/dist/types/types-ci.js +1 -1
  133. package/dist/types/types-dev-server.d.ts +5 -6
  134. package/dist/types/types-dev-server.js +1 -1
  135. package/dist/types/types-entry-map.js +1 -1
  136. package/dist/types/types-federation.js +1 -1
  137. package/dist/types/types-global-compiler-options.d.ts +7 -0
  138. package/dist/types/types-global-compiler-options.js +1 -0
  139. package/dist/types/types-loader-options.d.ts +2 -7
  140. package/dist/types/types-loader-options.js +1 -1
  141. package/dist/types/types-modular-import.js +1 -1
  142. package/dist/types/types-multi-html.js +1 -1
  143. package/dist/types/types-options.d.ts +6 -1
  144. package/dist/types/types-options.js +1 -1
  145. package/dist/types/types-plugin-options.js +1 -1
  146. package/dist/types/types-threads-options.js +1 -1
  147. package/dist/types/types-webpack.d.ts +1 -1
  148. package/dist/types/types-webpack.js +1 -1
  149. package/package.json +30 -32
  150. package/dist/plugins/ts-checker/index.d.ts +0 -1
  151. package/dist/plugins/ts-checker/index.js +0 -1
@@ -1,139 +1 @@
1
- import _ from 'lodash';
2
- import { ignoreEntryOptionKeys, maxEntryGroupSize } from '../constants.js';
3
- import { isDeepEqual } from './is-deep-equal.js';
4
- import { normalizeCheckEntryOptions } from './normalize-check-entry-options.js';
5
- import { normalizeGroupName } from './normalize-group-name.js';
6
- /**
7
- * Groups the manual entries based on their group names.
8
- * @param manualEntries - The map of manual entries.
9
- * @returns An array of grouped manual entries.
10
- */
11
- export const manualGrouping = (manualEntries) => {
12
- const manualGroupEntryMap = _.groupBy(manualEntries, (entry) => {
13
- return entry['groupName'];
14
- });
15
- const evolveEntryMapList = [];
16
- for (const [, groupItem] of Object.entries(manualGroupEntryMap)) {
17
- const evolveEntryMapItem = groupItem.reduce((prev, curr) => {
18
- prev[curr.entryName] = _.omitBy(curr, 'entryName');
19
- return prev;
20
- }, {});
21
- evolveEntryMapList.push(evolveEntryMapItem);
22
- }
23
- return evolveEntryMapList;
24
- };
25
- /**
26
- * Reduces an array of autoEntries into groups based on their options.
27
- * Each group is represented by a groupKey and contains an EvolveEntryMap.
28
- *
29
- * @param evolveOptions - The FlatEvolveOptions object.
30
- * @param autoEntries - An array of EvolveEntryMapContent objects with an additional entryName property.
31
- * @param ignoreOptionKeys - An array of keys to ignore when comparing entry options.
32
- * @param serveMode - A boolean indicating whether the function is running in serve mode.
33
- * @returns An object where each key represents a groupKey and its value is an EvolveEntryMap.
34
- */
35
- export const autoGroupingReduce = (autoEntries, ignoreOptionKeys = [], serveMode) => {
36
- return _.reduce(autoEntries, (prev, curr, index) => {
37
- let lastGroupingKey = `auto_grouping_reduce-${index}`;
38
- const currEntryOptions = normalizeCheckEntryOptions(serveMode, curr.options, ignoreOptionKeys);
39
- for (const [groupingKey, groupEntryMap] of Object.entries(prev)) {
40
- const firsEntryMap = Object.values(groupEntryMap)[0];
41
- const firstEntryOptions = normalizeCheckEntryOptions(serveMode, firsEntryMap.options, ignoreOptionKeys);
42
- if (isDeepEqual(currEntryOptions, firstEntryOptions)) {
43
- lastGroupingKey = groupingKey;
44
- break;
45
- }
46
- }
47
- prev[lastGroupingKey] = _.merge(prev[lastGroupingKey], {
48
- [curr.entryName]: _.omitBy(curr, 'entryName'),
49
- });
50
- return prev;
51
- }, {});
52
- };
53
- /**
54
- * Assigns a group name to each entry in the evolveEntryMapList based on the projectVirtualPath.
55
- *
56
- * @param evolveOptions - The options for the evolve process.
57
- * @param evolveEntryMapList - The list of evolve entry maps.
58
- * @returns The updated list of evolve entry maps with group names assigned.
59
- */
60
- export const autoAssignGroupName = (evolveOptions, evolveEntryMapList) => {
61
- const { projectVirtualPath } = evolveOptions;
62
- const evolveEntryMapItemList = [];
63
- let index = 0;
64
- for (const evolveEntryMap of evolveEntryMapList) {
65
- const evolveEntryMapItem = {};
66
- const groupName = normalizeGroupName(projectVirtualPath, index++);
67
- for (const [entryName, entryContent] of Object.entries(evolveEntryMap)) {
68
- entryContent.groupName = groupName;
69
- evolveEntryMapItem[entryName] = entryContent;
70
- }
71
- evolveEntryMapItemList.push(evolveEntryMapItem);
72
- }
73
- return evolveEntryMapItemList;
74
- };
75
- /**
76
- * Groups the given autoEntries into multiple EvolveEntryMap based on their options.
77
- * If the group size exceeds the maximum group size, it will be sliced into smaller groups.
78
- *
79
- * @param evolveOptions - The FlatEvolveOptions object.
80
- * @param autoEntries - An array of EvolveEntryMapContent objects with an additional entryName property.
81
- * @param ignoreOptionKeys - An array of keys to ignore in the EvolveEntryItemOption object.
82
- * @param maxGroupSize - The maximum size of each group. Defaults to maxEntryGroupSize.
83
- * @param serveMode - A boolean indicating whether the serve mode is enabled.
84
- * @returns An array of EvolveEntryMap representing the grouped entries.
85
- */
86
- export const autoGrouping = (evolveOptions, autoEntries, ignoreOptionKeys = [], maxGroupSize = maxEntryGroupSize, serveMode) => {
87
- const autoGroupingReduceMap = autoGroupingReduce(autoEntries, ignoreOptionKeys, serveMode);
88
- const autoGroupEntryMapList = [];
89
- // slice each group
90
- for (const [, groupItem] of Object.entries(autoGroupingReduceMap)) {
91
- const groupKeys = Object.keys(groupItem);
92
- if (groupKeys.length > maxGroupSize) {
93
- for (let i = 0; i < groupKeys.length; i += maxGroupSize) {
94
- const sliceGroupKeys = groupKeys.slice(i, i + maxGroupSize);
95
- const sliceEvolveEntryMap = sliceGroupKeys.reduce((prev, curr) => {
96
- prev[curr] = groupItem[curr];
97
- return prev;
98
- }, {});
99
- autoGroupEntryMapList.push(sliceEvolveEntryMap);
100
- }
101
- }
102
- else {
103
- autoGroupEntryMapList.push(groupItem);
104
- }
105
- }
106
- return autoAssignGroupName(evolveOptions, autoGroupEntryMapList);
107
- };
108
- /**
109
- * Splits the served entries into groups based on the given options.
110
- *
111
- * @param evolveEntries - The map of served entries.
112
- * @param ignoreOptionKeys - The list of option keys to ignore.
113
- * @returns An array of evolve entry maps representing the groups.
114
- */
115
- export const splitToEntryGroup = (evolveEntries, evolveOptions, ignoreOptionKeys = ignoreEntryOptionKeys, serveMode) => {
116
- const { isolation = false } = evolveOptions;
117
- if (isolation) {
118
- const evolveEntryMapList = [];
119
- for (const [entryName, entryContent] of Object.entries(evolveEntries)) {
120
- entryContent.groupName = entryName;
121
- evolveEntryMapList.push({
122
- [entryName]: entryContent,
123
- });
124
- }
125
- return evolveEntryMapList;
126
- }
127
- const evolveEntryFlatList = _.flatMap(evolveEntries, (entryOption, entryName) => {
128
- return {
129
- ...entryOption,
130
- entryName,
131
- };
132
- });
133
- const evolveEntryGroupMap = _.groupBy(evolveEntryFlatList, (entry) => {
134
- return entry.groupingSource;
135
- });
136
- const manualEvolveEntryMapList = manualGrouping(evolveEntryGroupMap['manual']);
137
- const autoEvolveEntryMapList = autoGrouping(evolveOptions, evolveEntryGroupMap['auto'], ignoreOptionKeys, maxEntryGroupSize, serveMode);
138
- return [...manualEvolveEntryMapList, ...autoEvolveEntryMapList];
139
- };
1
+ import _ from"lodash";import{ignoreEntryOptionKeys,maxEntryGroupSize}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=maxEntryGroupSize,n)=>{const s=autoGroupingReduce(e,t,n),u=[];for(const[,o]of Object.entries(s)){const e=Object.keys(o);if(e.length>r)for(let t=0;t<e.length;t+=r){const n=e.slice(t,t+r).reduce(((e,t)=>(e[t]=o[t],e)),{});u.push(n)}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,maxEntryGroupSize,r)]};
@@ -1,21 +1 @@
1
- import { ignoreEntryOptionKeys } from '../constants.js';
2
- import { isDeepEqual } from './is-deep-equal.js';
3
- import { normalizeCheckEntryOptions } from './normalize-check-entry-options.js';
4
- /**
5
- * Verifies if the options of all entries in a group are equal, excluding specified keys.
6
- *
7
- * @param groupEvolveEntryMap - The map of group entries.
8
- * @param ignoreOptionKeys - The keys to be ignored when comparing options.
9
- * @returns A boolean indicating if the options of all entries are equal.
10
- */
11
- export const verifyGroupEntryOptions = (groupEvolveEntryMap, ignoreOptionKeys = ignoreEntryOptionKeys, serveMode) => {
12
- const groupEvolveEntryMapValues = Object.values(groupEvolveEntryMap);
13
- if (groupEvolveEntryMapValues.length === 1) {
14
- return true;
15
- }
16
- const firstEntryMap = groupEvolveEntryMapValues.shift();
17
- const firstEntryOptions = normalizeCheckEntryOptions(serveMode, firstEntryMap?.options, ignoreOptionKeys);
18
- return groupEvolveEntryMapValues.every((entryOption) => {
19
- return isDeepEqual(firstEntryOptions, normalizeCheckEntryOptions(serveMode, entryOption.options, ignoreOptionKeys));
20
- });
21
- };
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,5 +1 @@
1
- export * from './define-config/index.js';
2
- export * from './load-config/index.js';
3
- export * from './main/index.js';
4
- export * from './types/types-options.js';
5
- 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
- export * from './load-evolve-config.js';
1
+ export*from"./load-evolve-config.js";
@@ -1,41 +1 @@
1
- import { searchConfig } from '@armit/config-loader';
2
- import { mergeOptions, logger } from '@flatjs/common';
3
- import { configFileName, moduleName } from '../constants.js';
4
- import { defaultEvolveOptions } from '../default-options.js';
5
- import { normalizeResolveAlias } from '../helpers/normalize-resolve-alias.js';
6
- import { refreshEvolveMockOptions } from '../helpers/refresh-evolve-mock-options.js';
7
- export const loadEvolveConfig = async (configEnv, projectCwd, overrideOptions = {}, configLoaderOptions = {
8
- configFile: configFileName,
9
- esmLoaderOptions: {
10
- externals: [/^@flatjs\/.*/],
11
- },
12
- }) => {
13
- const { configFile, esmLoaderOptions } = configLoaderOptions;
14
- const data = await searchConfig(configFile, projectCwd, {
15
- esm: {
16
- ...esmLoaderOptions,
17
- projectCwd,
18
- },
19
- });
20
- let localData = {};
21
- if (typeof data?.config === 'function') {
22
- localData = await data?.config(configEnv);
23
- }
24
- else {
25
- localData = data?.config || {};
26
- }
27
- // Merge user local config with default configure options.
28
- const localConfigOptions = mergeOptions(defaultEvolveOptions, localData);
29
- const mergedConfigOptions = mergeOptions(localConfigOptions, overrideOptions);
30
- const finalData = mergeOptions(mergedConfigOptions, { projectCwd });
31
- // We don't need to load mocks configuration from `flatjs-mock.config.js` while `build` phase.
32
- const latestEvolveOptions = configEnv.command === 'build'
33
- ? finalData
34
- : await refreshEvolveMockOptions(projectCwd, finalData, configLoaderOptions);
35
- logger.debug(`Load evolve config:\n${JSON.stringify(latestEvolveOptions, null, 2)}`, moduleName);
36
- // Normalize webpack.resolve.alias to make sure convert `alias` to absolute path.
37
- if (latestEvolveOptions.webpack?.resolve?.alias) {
38
- latestEvolveOptions.webpack.resolve.alias = normalizeResolveAlias(projectCwd, latestEvolveOptions.webpack?.resolve?.alias);
39
- }
40
- return latestEvolveOptions;
41
- };
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};
@@ -1 +1 @@
1
- export {};
1
+ export{};
@@ -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,51 +1 @@
1
- import Tinypool from 'tinypool';
2
- import { getWorkerPath } from './get-worker-path.js';
3
- import startBuildWorker from './start-build-worker.js';
4
- /**
5
- * Represents a thread pool for unit testing.
6
- */
7
- class ThreadPoolForUnittest {
8
- startBuildWorker(options) {
9
- return startBuildWorker(options);
10
- }
11
- terminate() {
12
- console.warn(`[WARNING] Using fake "terminate" for unittest!`);
13
- }
14
- }
15
- /**
16
- * Represents a thread pool for executing tasks using the TinyPool library.
17
- */
18
- class ThreadPoolForTinyPool {
19
- /**
20
- * Creates a new instance of the `ThreadPoolForTinyPool` class.
21
- * @param workerPath The path to the worker file.
22
- * @param workerSize The number of worker threads to create.
23
- * @param options Optional configuration options for the worker pool.
24
- */
25
- constructor(workerPath, options) {
26
- const { runtime = 'worker_threads', idleTimeout = 60000, minThreads = 1, maxThreads, } = options || {};
27
- this.pool = new Tinypool({
28
- filename: workerPath,
29
- minThreads,
30
- maxThreads,
31
- runtime,
32
- idleTimeout,
33
- });
34
- }
35
- startBuildWorker(options) {
36
- return this.pool.run(options);
37
- }
38
- terminate() {
39
- this.pool.destroy();
40
- }
41
- }
42
- export const createThreadWorker = (options) => {
43
- const workerPath = getWorkerPath();
44
- // FIXME: Is safe to remove `worker thread` while `test` environment, cause of we need to run UT using `source code`
45
- const isTestEnv = process.env.NODE_ENV === 'test';
46
- if (isTestEnv) {
47
- console.warn(`[WARNING] Using fake thread pool worker for unittest!`);
48
- return new ThreadPoolForUnittest();
49
- }
50
- return new ThreadPoolForTinyPool(workerPath, options);
51
- };
1
+ import Tinypool from"tinypool";import{getWorkerPath}from"./get-worker-path.js";import startBuildWorker from"./start-build-worker.js";class ThreadPoolForUnittest{startBuildWorker(r){return startBuildWorker(r)}terminate(){console.warn('[WARNING] Using fake "terminate" for unittest!')}}class ThreadPoolForTinyPool{constructor(r,o){const{runtime:e="worker_threads",idleTimeout:t=6e4,minThreads:n=1,maxThreads:s}=o||{};this.pool=new Tinypool({filename:r,minThreads:n,maxThreads:s,runtime:e,idleTimeout:t})}startBuildWorker(r){return this.pool.run(r)}terminate(){this.pool.destroy()}}export const createThreadWorker=r=>{const o=getWorkerPath();return"test"===process.env.NODE_ENV?(console.warn("[WARNING] Using fake thread pool worker for unittest!"),new ThreadPoolForUnittest):new ThreadPoolForTinyPool(o,r)};
@@ -1,21 +1 @@
1
- import { illegalPackageChecker, keepPackageDepsUpToDateForNonMonoRepo, } from '@armit/package';
2
- export const envVerify = async (projectCwd, evolveOptions) => {
3
- const { packageInstallChecker, needVerifyPackages } = evolveOptions;
4
- if (packageInstallChecker !== false && packageInstallChecker?.enabled) {
5
- // Verify local install node modules
6
- await illegalPackageChecker({
7
- cwd: projectCwd,
8
- modules: packageInstallChecker?.detectModules,
9
- throwError: packageInstallChecker?.throwError,
10
- showAllInstalledGraph: packageInstallChecker?.showAllInstalledGraph,
11
- });
12
- }
13
- if (needVerifyPackages !== false) {
14
- // Keep package deps up to date for non-monorepo
15
- await keepPackageDepsUpToDateForNonMonoRepo({
16
- cwd: projectCwd,
17
- autoUpgrade: true,
18
- needVerifyPackages: needVerifyPackages || {},
19
- });
20
- }
21
- };
1
+ import{illegalPackageChecker,keepPackageDepsUpToDateForNonMonoRepo}from"@armit/package";export const envVerify=async(e,a)=>{const{packageInstallChecker:o,needVerifyPackages:r}=a;!1!==o&&o?.enabled&&await illegalPackageChecker({cwd:e,modules:o?.detectModules,throwError:o?.throwError,showAllInstalledGraph:o?.showAllInstalledGraph}),!1!==r&&await keepPackageDepsUpToDateForNonMonoRepo({cwd:e,autoUpgrade:!0,needVerifyPackages:r||{}})};
@@ -1,5 +1 @@
1
- import { pathToFileURL } from 'node:url';
2
- import { getDirname } from '@armit/file-utility';
3
- export const getWorkerPath = () => {
4
- return pathToFileURL(getDirname(import.meta.url, './start-build-worker.js')).toString();
5
- };
1
+ import{pathToFileURL}from"node:url";import{getDirname}from"@armit/file-utility";export const getWorkerPath=()=>pathToFileURL(getDirname(import.meta.url,"./start-build-worker.js")).toString();
@@ -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,4 +1 @@
1
- export * from './start-build.js';
2
- export * from './start-serve.js';
3
- export * from './start-static.js';
4
- 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,39 +1 @@
1
- import { ensureSlash, mergeOptions } from '@flatjs/common';
2
- import { ignoreEntryOptionKeys } from '../constants.js';
3
- import { EvolveBuildError } from '../errors/evolve-build-error.js';
4
- import { printCompilerError } from '../helpers/print-log.js';
5
- import { verifyGroupEntryOptions } from '../helpers/verify-group-entry-options.js';
6
- import { startGroupEntryBuild, } from './start-group-entry-build.js';
7
- /**
8
- * The main entry to start an evolve `build`
9
- * @param entryMapItem The `entryMapItem` for one entry build task
10
- * @param evolveOptions FlatEvolveOptions
11
- */
12
- export const prepareBuild = async (groupEntries, evolveOptions) => {
13
- const firstGroupEntryItem = Object.values(groupEntries)[0];
14
- if (!verifyGroupEntryOptions(groupEntries, ignoreEntryOptionKeys, true)) {
15
- throw new Error('The entry options in a group must be the same.');
16
- }
17
- // Fetch all configuration cdn
18
- const cdnPath = evolveOptions.multiHtmlCdn?.prod || [];
19
- if (!cdnPath.length) {
20
- throw new Error(`No CDN config for env:"prod", groupName: ${firstGroupEntryItem.groupName}`);
21
- }
22
- // Random choose one to publicPath
23
- const cdnPublicPath = ensureSlash(cdnPath[Math.floor(Math.random() * cdnPath.length)], true);
24
- try {
25
- const useRelativeAssetPath = firstGroupEntryItem.options?.useRelativeAssetPath;
26
- const buildEvolveOptions = mergeOptions(evolveOptions, {
27
- webpack: {
28
- // Only for `assets` used at styling files (e.g.`xxx.less`)
29
- publicPath: useRelativeAssetPath ? 'auto' : cdnPublicPath,
30
- },
31
- });
32
- return await startGroupEntryBuild(groupEntries, buildEvolveOptions);
33
- }
34
- catch (err) {
35
- const formattedErrors = printCompilerError(err);
36
- // Need re-throw error, in order to third API can capture this error.
37
- throw new EvolveBuildError(`BUILD_ERROR`, formattedErrors);
38
- }
39
- };
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)}};
@@ -1,69 +1 @@
1
- import { arrayUnique, logger, urlJoin } from '@flatjs/common';
2
- import { attachMockMiddlewares } from '@flatjs/mock';
3
- import { ignoreEntryOptionKeys } from '../constants.js';
4
- import { createAppPageRoute, createDevServer, createDevServerCompilerTask, createDevServerEntries, } from '../dev-server/index.js';
5
- import { flatEntryMap, openPage } from '../helpers/index.js';
6
- import { normalizePageProxy } from '../helpers/normalize-page-proxy.js';
7
- import { splitToEntryGroup } from '../helpers/split-to-entry-group.js';
8
- import { verifyGroupEntryOptions } from '../helpers/verify-group-entry-options.js';
9
- import { envVerify } from './env-verify.js';
10
- /**
11
- * The main entry to start evolve serve
12
- * @param projectCwd The Root directory (workspace) of this project.
13
- * @param servedEntries All normalized webpack entries we have served.
14
- * @param evolveOptions FlatEvolveOptions
15
- */
16
- export const prepareServe = async (projectCwd, servedEntries, evolveOptions) => {
17
- // Verify if we have an correct project local environment.
18
- await envVerify(projectCwd, evolveOptions);
19
- // Group by entry group name
20
- const entryMapGroupList = splitToEntryGroup(servedEntries, evolveOptions, ignoreEntryOptionKeys, true);
21
- if (!entryMapGroupList.length) {
22
- logger.warn(`No served entries provided!`);
23
- return;
24
- }
25
- const serveTasks = [];
26
- // Create pure dev server.
27
- const { app, devPort, devHostUri, publicIp } = await createDevServer(evolveOptions);
28
- // Extract all the mock filters of served entries.
29
- const mockFilters = evolveOptions.devServer?.mockOptions?.mockFilters || [];
30
- // Loop all entries gather all mock files definition from each entry item.
31
- for (const [, value] of Object.entries(servedEntries)) {
32
- mockFilters.push(...(value.options?.mockFilters || []));
33
- }
34
- // Attach core handlers for mock
35
- await attachMockMiddlewares(app, {
36
- ...evolveOptions.devServer?.mockOptions,
37
- mockFilters: arrayUnique(mockFilters),
38
- projectCwd,
39
- });
40
- let lastPort = devPort;
41
- const servedDevServerEntryList = [];
42
- for (const entryMapGroup of entryMapGroupList) {
43
- // Verify that each entry option is the same in a group
44
- if (!verifyGroupEntryOptions(entryMapGroup, ignoreEntryOptionKeys, true)) {
45
- throw new Error('The entry options in a group must be the same.');
46
- }
47
- // Create dev-server configuration for all servedEntries.
48
- lastPort++;
49
- const servedDevServerEntries = await createDevServerEntries(lastPort, entryMapGroup, evolveOptions);
50
- servedDevServerEntryList.push(servedDevServerEntries);
51
- }
52
- // Create new route `/pages*`,`*` to pure dev server
53
- const flatServedDevServerEntries = flatEntryMap(servedDevServerEntryList);
54
- createAppPageRoute(projectCwd, app, devHostUri, flatServedDevServerEntries, evolveOptions);
55
- const pageProxy = normalizePageProxy(evolveOptions.devServer?.pageProxy || '/pages');
56
- const mainPage = urlJoin(devHostUri, [pageProxy]);
57
- // Open page via browser
58
- if (evolveOptions.devServer?.autoOpen) {
59
- openPage(mainPage);
60
- }
61
- for (const servedDevServerEntryItem of servedDevServerEntryList) {
62
- // Create dev-server compiler tasks
63
- const task = createDevServerCompilerTask(projectCwd, mainPage, publicIp, servedDevServerEntryItem, servedDevServerEntryList, evolveOptions);
64
- serveTasks.push(task);
65
- }
66
- return Promise.all(serveTasks).then(() => {
67
- return app;
68
- });
69
- };
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,30 +1 @@
1
- import { chalk, logger, urlJoin } from '@flatjs/common';
2
- import { attachMockMiddlewares } from '@flatjs/mock';
3
- import { createAppPageRoute } from '../dev-server/create-app-page-route.js';
4
- import { createDevServer } from '../dev-server/create-dev-server.js';
5
- import { normalizePageProxy } from '../helpers/normalize-page-proxy.js';
6
- import { openPage } from '../helpers/open-page.js';
7
- /**
8
- * The main entry to start evolve serve
9
- * @param projectCwd The Root directory (workspace) of this project.
10
- * @param evolveOptions FlatEvolveOptions
11
- */
12
- export const prepareStatic = async (projectCwd, evolveOptions) => {
13
- // Create pure dev server.
14
- const { app, devHostUri } = await createDevServer(evolveOptions);
15
- // Attach core handlers for mock
16
- await attachMockMiddlewares(app, {
17
- ...evolveOptions.devServer?.mockOptions,
18
- projectCwd,
19
- });
20
- // Create new route `/pages*`,`*` to pure dev server
21
- createAppPageRoute(projectCwd, app, devHostUri, {}, evolveOptions);
22
- const pageProxy = normalizePageProxy(evolveOptions.devServer?.pageProxy || '/pages');
23
- const mainPage = urlJoin(devHostUri, [pageProxy]);
24
- // Open page via browser
25
- if (evolveOptions.devServer?.autoOpen) {
26
- openPage(mainPage);
27
- }
28
- logger.info(`${'static page'.padEnd(12, ' ')} ➩ ${chalk(['cyan'])(mainPage)}`);
29
- };
30
- // Start up main page proxy server.
1
+ import{chalk,logger,urlJoin}from"@flatjs/common";import{attachMockMiddlewares}from"@flatjs/mock";import{createAppPageRoute}from"../dev-server/create-app-page-route.js";import{createDevServer}from"../dev-server/create-dev-server.js";import{normalizePageProxy}from"../helpers/normalize-page-proxy.js";import{openPage}from"../helpers/open-page.js";export const prepareStatic=async(e,r)=>{const{app:a,devHostUri:o}=await createDevServer(r);await attachMockMiddlewares(a,{...r.devServer?.mockOptions,projectCwd:e}),createAppPageRoute(e,a,o,{},r);const t=normalizePageProxy(r.devServer?.pageProxy||"/pages"),p=urlJoin(o,[t]);r.devServer?.autoOpen&&openPage(p),logger.info(`${"static page".padEnd(12," ")} ➩ ${chalk(["cyan"])(p)}`)};