@flatjs/evolve 1.8.1-next.99 → 2.0.0-next.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. package/CHANGELOG.md +148 -0
  2. package/dist/constants.d.ts +9 -0
  3. package/dist/constants.js +1 -1
  4. package/dist/create-webpack/create-optimization.d.ts +2 -1
  5. package/dist/create-webpack/create-optimization.js +1 -1
  6. package/dist/create-webpack/load-webpack-config.js +1 -1
  7. package/dist/define-config/define-config.d.ts +3 -1
  8. package/dist/dev-server/add-compiler-to-dev-server.d.ts +2 -1
  9. package/dist/dev-server/add-compiler-to-dev-server.js +1 -1
  10. package/dist/dev-server/create-dev-server-compiler-tasks.d.ts +1 -1
  11. package/dist/dev-server/create-dev-server-compiler-tasks.js +1 -1
  12. package/dist/dev-server/create-dev-server.d.ts +1 -0
  13. package/dist/dev-server/create-dev-server.js +1 -1
  14. package/dist/dev-server/middlewares/create-page-middleware.js +1 -1
  15. package/dist/helpers/get-bundle-file-name.js +1 -1
  16. package/dist/helpers/json-serializer.js +1 -1
  17. package/dist/helpers/refresh-evolve-mock-options.d.ts +1 -1
  18. package/dist/helpers/split-to-multi-compiler.d.ts +1 -1
  19. package/dist/helpers/split-to-multi-compiler.js +1 -1
  20. package/dist/load-config/load-evolve-config.d.ts +1 -7
  21. package/dist/load-config/load-evolve-config.js +1 -1
  22. package/dist/load-config/types.d.ts +7 -0
  23. package/dist/load-config/types.js +1 -0
  24. package/dist/main/create-thread-worker.d.ts +16 -0
  25. package/dist/main/create-thread-worker.js +1 -0
  26. package/dist/main/prepare-serve.js +1 -1
  27. package/dist/main/start-build-dynamic.d.ts +2 -2
  28. package/dist/main/start-build-dynamic.js +1 -1
  29. package/dist/main/start-build-worker.d.ts +1 -1
  30. package/dist/main/start-build.d.ts +1 -1
  31. package/dist/main/start-build.js +1 -1
  32. package/dist/main/start-one-entry-build.js +1 -1
  33. package/dist/main/start-serve.d.ts +1 -1
  34. package/dist/main/start-static.d.ts +1 -1
  35. package/dist/plugins/circular-dependency/circular-dependency-plugin.d.ts +1 -1
  36. package/dist/plugins/circular-dependency/circular-dependency-plugin.js +1 -1
  37. package/dist/types/types-ci.d.ts +7 -0
  38. package/dist/types/types-multi-html.d.ts +2 -0
  39. package/package.json +38 -36
  40. package/templates/html-plugin/index-dev.html +28 -24
  41. package/templates/html-plugin/index-inte.html +28 -24
  42. package/templates/html-plugin/index-inte2.html +28 -24
  43. package/templates/html-plugin/index-inte3.html +28 -24
  44. package/templates/html-plugin/index-inte4.html +28 -24
  45. package/templates/html-plugin/index-me.html +28 -24
  46. package/templates/html-plugin/index-prod.html +28 -24
  47. package/templates/html-plugin/index-rc.html +28 -24
  48. package/templates/html-plugin/index-uat.html +28 -24
  49. package/templates/module.html +47 -37
package/CHANGELOG.md CHANGED
@@ -1,5 +1,153 @@
1
1
  # @flatjs/evolve
2
2
 
3
+ ## 2.0.0-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 869441e: Fix load-config to support promise
8
+ - ff99133: refactor typings
9
+ - e029540: refactor test-utils for evolve to mock thead-pool worker
10
+ - 99e8ba4: bump version
11
+ - 394d703: add missed package dependency `typescript`
12
+ - 6979b1f: fix correct `exclude` of tsconfig.json
13
+ - ae04118: update `engine` to node 18 & npm 8
14
+ - Updated dependencies [99e8ba4]
15
+ - Updated dependencies [394d703]
16
+ - Updated dependencies [6979b1f]
17
+ - Updated dependencies [ae04118]
18
+ - @flatjs/forge-postcss-plugin-pixel@2.0.0-next.1
19
+ - @flatjs/evolve-preset-babel@2.0.0-next.1
20
+ - @flatjs/common@2.0.0-next.1
21
+ - @flatjs/graph@2.0.0-next.1
22
+ - @flatjs/mock@2.0.0-next.1
23
+
24
+ ## 1.8.1-next.112
25
+
26
+ ### Patch Changes
27
+
28
+ - 62047a2: bump version
29
+ - Updated dependencies [62047a2]
30
+ - @flatjs/forge-postcss-plugin-pixel@1.8.1-next.40
31
+ - @flatjs/evolve-preset-babel@1.8.1-next.25
32
+ - @flatjs/common@1.8.1-next.40
33
+ - @flatjs/graph@1.8.1-next.59
34
+ - @flatjs/mock@1.8.1-next.85
35
+
36
+ ## 1.8.1-next.111
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [f5d60b9]
41
+ - @flatjs/mock@1.8.1-next.84
42
+
43
+ ## 1.8.1-next.110
44
+
45
+ ### Patch Changes
46
+
47
+ - 0508747: Force client websocketURL hostname to local publicIp for `webpack-dev-server`
48
+ - Updated dependencies [0508747]
49
+ - @flatjs/mock@1.8.1-next.83
50
+
51
+ ## 1.8.1-next.109
52
+
53
+ ### Patch Changes
54
+
55
+ - a5e6989: formating templates
56
+ - 9760f0a: Make `react-fast-refresh` works correct on iframe and no `devtool` environment
57
+
58
+ ## 1.8.1-next.108
59
+
60
+ ### Patch Changes
61
+
62
+ - 75e16ab: change `circle-dependency` error to waring as default
63
+ - 7941f1e: bump version
64
+ - Updated dependencies [891a384]
65
+ - Updated dependencies [7941f1e]
66
+ - @flatjs/evolve-preset-babel@1.8.1-next.24
67
+ - @flatjs/forge-postcss-plugin-pixel@1.8.1-next.39
68
+ - @flatjs/common@1.8.1-next.39
69
+ - @flatjs/graph@1.8.1-next.58
70
+ - @flatjs/mock@1.8.1-next.82
71
+
72
+ ## 1.8.1-next.107
73
+
74
+ ### Patch Changes
75
+
76
+ - Updated dependencies [6a2ee9f]
77
+ - @flatjs/common@1.8.1-next.38
78
+ - @flatjs/graph@1.8.1-next.57
79
+ - @flatjs/evolve-preset-babel@1.8.1-next.23
80
+ - @flatjs/forge-postcss-plugin-pixel@1.8.1-next.38
81
+ - @flatjs/mock@1.8.1-next.81
82
+
83
+ ## 1.8.1-next.106
84
+
85
+ ### Patch Changes
86
+
87
+ - @flatjs/graph@1.8.1-next.56
88
+ - @flatjs/mock@1.8.1-next.80
89
+ - @flatjs/common@1.8.1-next.37
90
+ - @flatjs/evolve-preset-babel@1.8.1-next.22
91
+
92
+ ## 1.8.1-next.105
93
+
94
+ ### Patch Changes
95
+
96
+ - 9be1d2d: expose `defineConfig` with correct typings export
97
+ - Updated dependencies [9be1d2d]
98
+ - @flatjs/mock@1.8.1-next.79
99
+ - @flatjs/graph@1.8.1-next.55
100
+
101
+ ## 1.8.1-next.104
102
+
103
+ ### Patch Changes
104
+
105
+ - 3a8aa0b: Add `graphTreeNodeFilter` allow customized filter wihile dynamic build
106
+ - 9f098ad: Bump version
107
+ - Updated dependencies [9f098ad]
108
+ - @flatjs/forge-postcss-plugin-pixel@1.8.1-next.37
109
+ - @flatjs/evolve-preset-babel@1.8.1-next.22
110
+ - @flatjs/common@1.8.1-next.37
111
+ - @flatjs/graph@1.8.1-next.54
112
+ - @flatjs/mock@1.8.1-next.78
113
+
114
+ ## 1.8.1-next.103
115
+
116
+ ### Patch Changes
117
+
118
+ - 663e3c4: bump version
119
+ - Updated dependencies [663e3c4]
120
+ - @flatjs/forge-postcss-plugin-pixel@1.8.1-next.36
121
+ - @flatjs/evolve-preset-babel@1.8.1-next.21
122
+ - @flatjs/common@1.8.1-next.36
123
+ - @flatjs/graph@1.8.1-next.53
124
+ - @flatjs/mock@1.8.1-next.77
125
+
126
+ ## 1.8.1-next.102
127
+
128
+ ### Patch Changes
129
+
130
+ - Updated dependencies [e068977]
131
+ - @flatjs/evolve-preset-babel@1.8.1-next.20
132
+ - @flatjs/graph@1.8.1-next.52
133
+ - @flatjs/mock@1.8.1-next.76
134
+
135
+ ## 1.8.1-next.101
136
+
137
+ ### Patch Changes
138
+
139
+ - Updated dependencies [9e3beae]
140
+ - @flatjs/evolve-preset-babel@1.8.1-next.19
141
+
142
+ ## 1.8.1-next.100
143
+
144
+ ### Patch Changes
145
+
146
+ - Updated dependencies [e02903b]
147
+ - @flatjs/evolve-preset-babel@1.8.1-next.18
148
+ - @flatjs/graph@1.8.1-next.51
149
+ - @flatjs/mock@1.8.1-next.75
150
+
3
151
  ## 1.8.1-next.99
4
152
 
5
153
  ### Patch Changes
@@ -13,3 +13,12 @@ export declare const viewportScripts = "(function(d){var j;var b=1;var i=1;var h
13
13
  * https://polyfill.io
14
14
  */
15
15
  export declare const polyfill: string[];
16
+ /**
17
+ * Applies the react-refresh Babel plugin on non-production modes only
18
+ * Ensure `react-refresh/runtime` is hoisted and shared
19
+ * https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md#externalising-react
20
+ */
21
+ export declare const devReactFastRefresh: {
22
+ runtime: string;
23
+ reactRefreshSetup: string;
24
+ };
package/dist/constants.js CHANGED
@@ -1 +1 @@
1
- export const moduleName="@flatjs/evolve";export const configFileName="flatjs-evolve";export const viewportScripts='(function(d){var j;var b=1;var i=1;var h=750;var c=100;function e(s,o){var q=d.document;var l=q.documentElement;var k=navigator.userAgent;var m=k.toLowerCase().indexOf("android")>-1;i=d.devicePixelRatio||1;if(i>3){i=3}if(m){i=1}console.log("current devicePixelRatio:",i);l.setAttribute("data-dpr",i.toString());var p=q.querySelector(\'meta[name="viewport"]\');if(!p){b=1/i;p=q.createElement("meta");p.setAttribute("name","viewport");q.head.appendChild(p);p.setAttribute(["content","width=device-width,user-scalable=no,initial-scale=",b,",maximum-scale=",b,",minimum-scale=",b].join(""))}function n(){var t=document.documentElement.clientWidth;j=t/o*(s/i)*i;q.documentElement.style.fontSize=String(j)+"px"}var r;d.addEventListener("resize",function(){clearTimeout(r);r=setTimeout(n,300)},false);d.addEventListener("onload",n,false);n()}e(c,h);window.fabricViewport={currRem:j,currDpr:i,currScale:b,dpiPX2px:function f(k){return parseFloat(k.toString())/j*100+"px"},px2DPIpx:function a(k){return parseFloat(k.toString())/100*j+"px"},px2rem:function g(k){return parseFloat(k.toString())/100+"rem"}}})(window);';export const polyfill=["https://polyfill.io/v3/polyfill.min.js?features=Array.from%2CArray.isArray%2CArray.of%2CArray.prototype.entries%2CArray.prototype.every%2CArray.prototype.fill%2CArray.prototype.filter%2CArray.prototype.find%2CArray.prototype.findIndex%2CArray.prototype.flat%2CArray.prototype.forEach%2CArray.prototype.flatMap%2CArray.prototype.keys%2CArray.prototype.indexOf%2CArray.prototype.includes%2CArray.prototype.lastIndexOf%2CArray.prototype.map%2CArray.prototype.reduce%2CArray.prototype.reduceRight%2CArray.prototype.some%2CArray.prototype.sort%2CArray.prototype.values%2CArrayBuffer%2CBlob%2CDataView%2CDate.now%2CObject.assign%2CObject.create%2CObject.defineProperties%2CObject.defineProperty%2CObject.entries%2CObject.freeze%2CObject.fromEntries%2CObject.getOwnPropertySymbols%2CObject.getOwnPropertyNames%2CObject.getOwnPropertyDescriptors%2CObject.getOwnPropertyDescriptor%2CObject.getPrototypeOf%2CObject.is%2CObject.isExtensible%2CObject.isFrozen%2CObject.isSealed%2CObject.keys%2CObject.values%2CObject.setPrototypeOf%2CPromise%2CPromise.prototype.finally%2CReflect%2CReflect.apply%2CReflect.construct%2CReflect.defineProperty%2CReflect.deleteProperty%2CReflect.getPrototypeOf%2CReflect.getOwnPropertyDescriptor%2CReflect.get%2CReflect.ownKeys%2CReflect.isExtensible%2CReflect.has%2CReflect.preventExtensions%2CReflect.set%2CReflect.setPrototypeOf%2CSet%2CString.prototype.trimStart%2CString.prototype.trimEnd%2CString.prototype.trim%2CString.prototype.startsWith%2CString.prototype.repeat%2CString.prototype.replaceAll%2CString.prototype.padStart%2CString.prototype.padEnd%2CMap%2CObject.seal%2Cconsole.groupEnd%2Cconsole.group"];
1
+ export const moduleName="@flatjs/evolve";export const configFileName="flatjs-evolve";export const viewportScripts='(function(d){var j;var b=1;var i=1;var h=750;var c=100;function e(s,o){var q=d.document;var l=q.documentElement;var k=navigator.userAgent;var m=k.toLowerCase().indexOf("android")>-1;i=d.devicePixelRatio||1;if(i>3){i=3}if(m){i=1}console.log("current devicePixelRatio:",i);l.setAttribute("data-dpr",i.toString());var p=q.querySelector(\'meta[name="viewport"]\');if(!p){b=1/i;p=q.createElement("meta");p.setAttribute("name","viewport");q.head.appendChild(p);p.setAttribute(["content","width=device-width,user-scalable=no,initial-scale=",b,",maximum-scale=",b,",minimum-scale=",b].join(""))}function n(){var t=document.documentElement.clientWidth;j=t/o*(s/i)*i;q.documentElement.style.fontSize=String(j)+"px"}var r;d.addEventListener("resize",function(){clearTimeout(r);r=setTimeout(n,300)},false);d.addEventListener("onload",n,false);n()}e(c,h);window.fabricViewport={currRem:j,currDpr:i,currScale:b,dpiPX2px:function f(k){return parseFloat(k.toString())/j*100+"px"},px2DPIpx:function a(k){return parseFloat(k.toString())/100*j+"px"},px2rem:function g(k){return parseFloat(k.toString())/100+"rem"}}})(window);';export const polyfill=["https://polyfill.io/v3/polyfill.min.js?features=Array.from%2CArray.isArray%2CArray.of%2CArray.prototype.entries%2CArray.prototype.every%2CArray.prototype.fill%2CArray.prototype.filter%2CArray.prototype.find%2CArray.prototype.findIndex%2CArray.prototype.flat%2CArray.prototype.forEach%2CArray.prototype.flatMap%2CArray.prototype.keys%2CArray.prototype.indexOf%2CArray.prototype.includes%2CArray.prototype.lastIndexOf%2CArray.prototype.map%2CArray.prototype.reduce%2CArray.prototype.reduceRight%2CArray.prototype.some%2CArray.prototype.sort%2CArray.prototype.values%2CArrayBuffer%2CBlob%2CDataView%2CDate.now%2CObject.assign%2CObject.create%2CObject.defineProperties%2CObject.defineProperty%2CObject.entries%2CObject.freeze%2CObject.fromEntries%2CObject.getOwnPropertySymbols%2CObject.getOwnPropertyNames%2CObject.getOwnPropertyDescriptors%2CObject.getOwnPropertyDescriptor%2CObject.getPrototypeOf%2CObject.is%2CObject.isExtensible%2CObject.isFrozen%2CObject.isSealed%2CObject.keys%2CObject.values%2CObject.setPrototypeOf%2CPromise%2CPromise.prototype.finally%2CReflect%2CReflect.apply%2CReflect.construct%2CReflect.defineProperty%2CReflect.deleteProperty%2CReflect.getPrototypeOf%2CReflect.getOwnPropertyDescriptor%2CReflect.get%2CReflect.ownKeys%2CReflect.isExtensible%2CReflect.has%2CReflect.preventExtensions%2CReflect.set%2CReflect.setPrototypeOf%2CSet%2CString.prototype.trimStart%2CString.prototype.trimEnd%2CString.prototype.trim%2CString.prototype.startsWith%2CString.prototype.repeat%2CString.prototype.replaceAll%2CString.prototype.padStart%2CString.prototype.padEnd%2CMap%2CObject.seal%2Cconsole.groupEnd%2Cconsole.group"];export const devReactFastRefresh={runtime:"runtime",reactRefreshSetup:"reactRefreshSetup"};
@@ -1,3 +1,4 @@
1
1
  import { type Configuration } from 'webpack';
2
+ import { type EntryMapItem } from '../types/types-entry-map.js';
2
3
  import { type FlatEvolveWebpackOptions } from '../types/types-webpack.js';
3
- export declare const createOptimization: (serveMode: boolean, webpackOptions?: FlatEvolveWebpackOptions) => Configuration['optimization'];
4
+ export declare const createOptimization: (serveMode: boolean, webpackOptions: FlatEvolveWebpackOptions | undefined, entryItem: EntryMapItem) => Configuration['optimization'];
@@ -1 +1 @@
1
- import{createMinimizers}from"../minimizer/index.js";export const createOptimization=(e,i)=>({nodeEnv:e?"development":"production",chunkIds:"named",moduleIds:"named",minimize:!1!==i?.minimizer&&!e,minimizer:createMinimizers(e,i),splitChunks:{name:!1,chunks:"all",minSize:25e5,cacheGroups:{default:!1,defaultVendors:!1}}});
1
+ import{join}from"node:path";import{devReactFastRefresh}from"../constants.js";import{createMinimizers}from"../minimizer/index.js";export const createOptimization=(e,i={},n)=>({nodeEnv:e?"development":"production",chunkIds:"named",moduleIds:"named",runtimeChunk:!!e&&{name:()=>join(n[0],devReactFastRefresh.runtime)},minimize:!1!==i?.minimizer&&!e,minimizer:createMinimizers(e,i),splitChunks:{name:!1,chunks:"all",minSize:25e5,cacheGroups:{default:!1,defaultVendors:!1}}});
@@ -1 +1 @@
1
- import{assertOnlySingleEntryItem}from"../helpers/assert-only-single-entry-item.js";import{createExternals}from"./create-externals.js";import{createOptimization}from"./create-optimization.js";import{createOutput}from"./create-output.js";import{createPerformance}from"./create-performance.js";import{createPlugins}from"./create-plugins.js";import{createResolve}from"./create-resolve.js";import{createRuleSets}from"./create-rule-sets.js";export const loadWebpackConfig=async(e,t,r)=>{const a="development"===e,{projectCwd:o,webpack:s,devServer:n}=r,c=n?.watchOptions,i=assertOnlySingleEntryItem(t,r),m=createRuleSets(a,i,r);return{mode:e,plugins:await createPlugins(a,i,r),watchOptions:c,output:await createOutput(a,r),context:o,target:s?.target??["web","es5"],resolve:createResolve(o,s),module:{rules:m},devtool:a?"eval-source-map":s?.sourceMap||!1,externals:createExternals(s?.externals,i),performance:createPerformance(a,s?.performance),optimization:createOptimization(a,s),infrastructureLogging:s?.infrastructureLogging??{level:"warn"},stats:s?.stats??{preset:"minimal"},cache:{type:"memory"}}};
1
+ import{assertOnlySingleEntryItem}from"../helpers/assert-only-single-entry-item.js";import{createExternals}from"./create-externals.js";import{createOptimization}from"./create-optimization.js";import{createOutput}from"./create-output.js";import{createPerformance}from"./create-performance.js";import{createPlugins}from"./create-plugins.js";import{createResolve}from"./create-resolve.js";import{createRuleSets}from"./create-rule-sets.js";export const loadWebpackConfig=async(e,t,r)=>{const a="development"===e,{projectCwd:o,webpack:s,devServer:n}=r,c=n?.watchOptions,i=assertOnlySingleEntryItem(t,r),m=createRuleSets(a,i,r);return{mode:e,plugins:await createPlugins(a,i,r),watchOptions:c,output:await createOutput(a,r),context:o,target:s?.target??["web","es5"],resolve:createResolve(o,s),module:{rules:m},devtool:a?"eval-source-map":s?.sourceMap||!1,externals:createExternals(s?.externals,i),performance:createPerformance(a,s?.performance),optimization:createOptimization(a,s,i),infrastructureLogging:s?.infrastructureLogging??{level:"warn"},stats:s?.stats??{preset:"minimal"},cache:{type:"memory"}}};
@@ -21,4 +21,6 @@ export interface EvolveConfigBase extends ConfigEnvBase {
21
21
  */
22
22
  resolve: typeof requireResolve;
23
23
  }
24
- export declare const defineConfig: (userConfig: UserConfigExport<PartialDeep<FlatEvolveOptions>, EvolveConfigBase>) => UserConfigExport<import("type-fest/source/partial-deep.js").PartialObjectDeep<FlatEvolveOptions, {}>, EvolveConfigBase>;
24
+ type DefineConfigFn = (userConfig: UserConfigExport<PartialDeep<FlatEvolveOptions>, EvolveConfigBase>) => UserConfigExport<PartialDeep<FlatEvolveOptions>, EvolveConfigBase>;
25
+ export declare const defineConfig: DefineConfigFn;
26
+ export {};
@@ -5,6 +5,7 @@ import { type FlatEvolveOptions } from '../types/types-options.js';
5
5
  * @param compiler Webpack compiler(s)
6
6
  * @param enableHmr Value indicates if we need to liveReload or `HMR`
7
7
  * @param devPort The port number of `@flatjs/mock`
8
+ * @param publicIp The public ip address of local server
8
9
  * @param evolveOptions The configuration of `@flatjs/evolve` (FlatEvolveOptions)
9
10
  */
10
- export declare const addCompilerToDevServer: (compiler: Compiler, enableHmr: boolean, devPort: number, evolveOptions: FlatEvolveOptions) => Promise<boolean>;
11
+ export declare const addCompilerToDevServer: (compiler: Compiler, enableHmr: boolean, devPort: number, publicIp: string, evolveOptions: FlatEvolveOptions) => Promise<boolean>;
@@ -1 +1 @@
1
- import{join}from"node:path";import WebpackDevServer from"webpack-dev-server";export const addCompilerToDevServer=(e,r,t,o)=>{const{projectCwd:p,devServer:s}=o,l=new WebpackDevServer({server:{type:s?.https?"https":"http",options:{...s?.https}},open:!1,compress:!0,port:t,hot:r,liveReload:!r,allowedHosts:"all",static:{directory:`${join(p,"/public")}`},headers:{"Access-Control-Allow-Origin":"*"},client:{progress:!0,overlay:s?.clientOverlay}},e);return new Promise(((e,r)=>{l.startCallback((t=>{if(t)return r(t);e(!0)}))}))};
1
+ import{join}from"node:path";import WebpackDevServer from"webpack-dev-server";export const addCompilerToDevServer=(e,r,o,t,s)=>{const{projectCwd:p,devServer:i}=s,l=new WebpackDevServer({server:{type:i?.https?"https":"http",options:{...i?.https}},open:!1,compress:!0,port:o,hot:r,liveReload:!r,allowedHosts:"all",static:{directory:`${join(p,"/public")}`},headers:{"Access-Control-Allow-Origin":"*"},client:{progress:!0,overlay:i?.clientOverlay,webSocketURL:{hostname:t||void 0}}},e);return new Promise(((e,r)=>{l.startCallback((o=>{if(o)return r(o);e(!0)}))}))};
@@ -1,3 +1,3 @@
1
1
  import { type FlatEvolveOptions } from '../types/types-options.js';
2
2
  import { type EvolveDevServerEntryMap } from './middlewares/create-page-middleware.js';
3
- export declare const createDevServerCompilerTasks: (projectCwd: string, mainPage: string, servedDevServerEntries: EvolveDevServerEntryMap, evolveOptions: FlatEvolveOptions) => Promise<Promise<boolean>[]>;
3
+ export declare const createDevServerCompilerTasks: (projectCwd: string, mainPage: string, publicIp: string, servedDevServerEntries: EvolveDevServerEntryMap, evolveOptions: FlatEvolveOptions) => Promise<Promise<boolean>[]>;
@@ -1 +1 @@
1
- import{relative}from"node:path";import{chalk,logger,mergeOptions,urlJoin}from"@flatjs/common";import webpack from"webpack";import{loadWebpackConfig}from"../create-webpack/load-webpack-config.js";import{shouldEnableReactFastRefresh}from"../helpers/should-enable-react-fast-refresh.js";import{splitToMultiCompilerConfigs}from"../helpers/split-to-multi-compiler.js";import{addCompilerToDevServer}from"./add-compiler-to-dev-server.js";export const createDevServerCompilerTasks=async(e,o,r,t)=>{const i=[];for(const[a,n]of Object.entries(r)){const l=n.entryConfig,s=l.options?.moduleFederation,p=shouldEnableReactFastRefresh(!0,[a,l],t);(s?.remotes||[]).forEach((e=>{e.endpoint=e=>{const o=r[e];if(!o)throw new Error(`No servedDevServerEntry found via "${e}"`);return urlJoin(o?.devServerHostUri,["/public"])}}));const{devServerPort:c,devServerHostUri:m}=r[a],f={[a]:l},d=urlJoin(m,["public"]),v=await loadWebpackConfig("development",f,mergeOptions(t,{webpack:{publicPath:d}})),h=webpack(splitToMultiCompilerConfigs(f,v,t)[0]);i.push(addCompilerToDevServer(h,p,c,t));const g=h.name||"";h.hooks.invalid.tap("fileChange",(o=>{const r=relative(e,o||"");logger.info(`file change ➩ ${chalk(["cyan"])(r)}`,g)})),h.hooks.done.tap("compileDone",(()=>{logger.info(`debug page ➩ ${chalk(["cyan"])(o)}`,g)}))}return i};
1
+ import{relative}from"node:path";import{chalk,logger,mergeOptions,urlJoin}from"@flatjs/common";import webpack from"webpack";import{loadWebpackConfig}from"../create-webpack/load-webpack-config.js";import{shouldEnableReactFastRefresh}from"../helpers/should-enable-react-fast-refresh.js";import{splitToMultiCompilerConfigs}from"../helpers/split-to-multi-compiler.js";import{addCompilerToDevServer}from"./add-compiler-to-dev-server.js";export const createDevServerCompilerTasks=async(e,o,r,t,a)=>{const i=[];for(const[n,l]of Object.entries(t)){const s=l.entryConfig,p=s.options?.moduleFederation,c=shouldEnableReactFastRefresh(!0,[n,s],a);(p?.remotes||[]).forEach((e=>{e.endpoint=e=>{const o=t[e];if(!o)throw new Error(`No servedDevServerEntry found via "${e}"`);return urlJoin(o?.devServerHostUri,["/public"])}}));const{devServerPort:m,devServerHostUri:f}=t[n],d={[n]:s},h=urlJoin(f,["public"]),v=await loadWebpackConfig("development",d,mergeOptions(a,{webpack:{publicPath:h}})),u=shouldEnableReactFastRefresh(!0,[n,s],a),g=webpack(splitToMultiCompilerConfigs(d,v,a,u)[0]);i.push(addCompilerToDevServer(g,c,m,r,a));const b=g.name||"";g.hooks.invalid.tap("fileChange",(o=>{const r=relative(e,o||"");logger.info(`file change ➩ ${chalk(["cyan"])(r)}`,b)})),g.hooks.done.tap("compileDone",(()=>{logger.info(`debug page ➩ ${chalk(["cyan"])(o)}`,b)}))}return i};
@@ -2,5 +2,6 @@ import { type FlatEvolveOptions } from '../types/index.js';
2
2
  export declare const createDevServer: (evolveOptions: FlatEvolveOptions) => Promise<{
3
3
  devPort: number;
4
4
  devHostUri: string;
5
+ publicIp: string;
5
6
  app: import("express-serve-static-core").Express;
6
7
  }>;
@@ -1 +1 @@
1
- import https from"node:https";import{prepareMockDomain}from"@flatjs/mock";import express from"express";export const createDevServer=async e=>{const r=express(),t=e.devServer?.mockOptions,{mockPort:o,hostUri:s}=await prepareMockDomain(t||{});return new Promise((t=>{const p=e.devServer?.https?https.createServer(e.devServer?.https,r):r;r.set("hostUri",s),p.listen(o,(()=>{t({app:r,devHostUri:s,devPort:o})}))}))};
1
+ import https from"node:https";import{prepareMockDomain}from"@flatjs/mock";import express from"express";export const createDevServer=async e=>{const r=express(),t=e.devServer?.mockOptions,{mockPort:o,hostUri:p,publicIp:s}=await prepareMockDomain(t||{});return new Promise((t=>{const i=e.devServer?.https?https.createServer(e.devServer?.https,r):r;r.set("hostUri",p),i.listen(o,(()=>{t({app:r,publicIp:s,devHostUri:p,devPort:o})}))}))};
@@ -1 +1 @@
1
- import{existsSync,readFileSync}from"node:fs";import{isAbsolute,join}from"node:path";import{ensureSlash,urlJoin}from"@flatjs/common";import _ from"lodash";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";import{getPackageDir}from"../../helpers/get-pacakge-dir.js";import{normalizeEvolveEntryName}from"../../helpers/normalize-entry-map.js";import{injectFederationScripts}from"../../helpers/script-injects.js";const getPageMainHtml=async(e,t,l)=>{const r=getPackageDir(),o=readFileSync(join(r,"./templates/main.html"),"utf-8"),a=[],i=l.projectVirtualPath.replace(/^\//,"");for(const[r,o]of Object.entries(l.entryMap)){const l=o.options?.servePageMainLinkFn||(e=>e),n=Object.keys(e).includes(r),s=normalizeEvolveEntryName(r,i),m=urlJoin(t,["pages",s],{env:"me"});a.push({name:r.replace(i,"").replace(/^\//,""),link:l(m,{hostUri:t,entryName:r,virtualPath:i}),flagText:n?"serve":"static",isServed:n?1:0})}const n={title:"@flatjs/evolve",modules:a.sort(((e,t)=>t.isServed-e.isServed))};return _.template(o)(n)},getPageModuleHtml=async(e,t,l,r,o)=>{const{entryMap:a,projectVirtualPath:i}=o,n=Object.keys(a).sort(((e,t)=>t.length-e.length)),s=getPackageDir(),m=n.find((e=>{const l=normalizeEvolveEntryName(e,i);return ensureSlash(t.path.replace(/^\//,""),!0).startsWith(ensureSlash(l,!0))}));if(!m){const e=readFileSync(join(s,"./templates/module-404.html"),"utf-8");return _.template(e)({title:"404 Not Found",errorMeta:[{name:"@flatjs/evolve workspace",value:s},{name:"served entry names",value:JSON.stringify(n)},{name:"module path",value:`${t.path}`}]})}const p=normalizeEvolveEntryName(m,i),c=a[m],u=c.options,d=e[m],g=d?.devServerHostUri||l,f=u?.serveModuleTemplate||"./templates/module.html",v=join(o.projectCwd,"./templates/module.html"),h=readFileSync(isAbsolute(f)?f:existsSync(v)?v:join(s,"./templates/module.html"),"utf-8"),S=o.devServer,y=S?.defaultServeGlobalData?await S.defaultServeGlobalData(c,l):{},j={mode:"development",envCdn:urlJoin(l,["public"])},P={title:getHtmlPluginConfig("title",j,u?.title),favicon:getHtmlPluginConfig("favicon",j,u?.favicon),viewport:allowPx2remForModule([m,c],o)?getHtmlPluginConfig("viewport",j,u?.viewport):"",headBeforeHtmlTags:getHtmlPluginConfig("headBeforeHtmlTags",j,u?.headBeforeHtmlTags),inlineScripts:getHtmlPluginConfig("inlineScripts",j,u?.inlineScripts),headBeforeStyles:getHtmlPluginConfig("headBeforeStyles",j,u?.headBeforeStyles),headBeforeScripts:getHtmlPluginConfig("headBeforeScripts",j,u?.headBeforeScripts),bodyAfterScripts:getHtmlPluginConfig("bodyAfterScripts",j,u?.bodyAfterScripts),moduleFederationScripts:injectFederationScripts({me:[urlJoin(l,["public"])]},o.multiHtmlCdnEnvResolver),global:{hostUrl:l,apiBase:urlJoin(l,[r]),virtualPath:join("/pages",i),moduleName:m.replace(i,"").replace(/^\//,""),...y,...u?.serveGlobalData||{}},styles:[urlJoin(g,[join("public",p,"bundle.css")])],scripts:[urlJoin(g,[join("public",p,"bundle.js")])]};return _.template(h)(P)};export const createPageMiddleware=(e,t,l,r)=>(r.devServer?.middlewares||[]).concat((async(o,a)=>{let i;i="/"===o.path?await getPageMainHtml(l,e,r):await getPageModuleHtml(l,o,e,t,r),a.send(i)}));
1
+ import{existsSync,readFileSync}from"node:fs";import{isAbsolute,join}from"node:path";import{ensureSlash,urlJoin}from"@flatjs/common";import _ from"lodash";import{devReactFastRefresh}from"../../constants.js";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";import{getPackageDir}from"../../helpers/get-pacakge-dir.js";import{normalizeEvolveEntryName}from"../../helpers/normalize-entry-map.js";import{injectFederationScripts}from"../../helpers/script-injects.js";import{shouldEnableReactFastRefresh}from"../../helpers/should-enable-react-fast-refresh.js";const getPageMainHtml=async(e,t,r)=>{const l=getPackageDir(),a=readFileSync(join(l,"./templates/main.html"),"utf-8"),o=[],i=r.projectVirtualPath.replace(/^\//,"");for(const[l,a]of Object.entries(r.entryMap)){const r=a.options?.servePageMainLinkFn||(e=>e),s=Object.keys(e).includes(l),n=normalizeEvolveEntryName(l,i),m=urlJoin(t,["pages",n],{env:"me"});o.push({name:l.replace(i,"").replace(/^\//,""),link:r(m,{hostUri:t,entryName:l,virtualPath:i}),flagText:s?"serve":"static",isServed:s?1:0})}const s={title:"@flatjs/evolve",modules:o.sort(((e,t)=>t.isServed-e.isServed))};return _.template(a)(s)},getPageModuleHtml=async(e,t,r,l,a)=>{const{entryMap:o,projectVirtualPath:i}=a,s=Object.keys(o).sort(((e,t)=>t.length-e.length)),n=getPackageDir(),m=s.find((e=>{const r=normalizeEvolveEntryName(e,i);return ensureSlash(t.path.replace(/^\//,""),!0).startsWith(ensureSlash(r,!0))}));if(!m){const e=readFileSync(join(n,"./templates/module-404.html"),"utf-8");return _.template(e)({title:"404 Not Found",errorMeta:[{name:"@flatjs/evolve workspace",value:n},{name:"served entry names",value:JSON.stringify(s)},{name:"module path",value:`${t.path}`}]})}const c=normalizeEvolveEntryName(m,i),p=o[m],d=p.options,u=e[m],f=u?.devServerHostUri||r,g=d?.serveModuleTemplate||"./templates/module.html",h=join(a.projectCwd,"./templates/module.html"),v=readFileSync(isAbsolute(g)?g:existsSync(h)?h:join(n,"./templates/module.html"),"utf-8"),S=a.devServer,j=S?.defaultServeGlobalData?await S.defaultServeGlobalData(p,r):{},y={mode:"development",envCdn:urlJoin(r,["public"])},P={title:getHtmlPluginConfig("title",y,d?.title),favicon:getHtmlPluginConfig("favicon",y,d?.favicon),viewport:allowPx2remForModule([m,p],a)?getHtmlPluginConfig("viewport",y,d?.viewport):"",headBeforeHtmlTags:getHtmlPluginConfig("headBeforeHtmlTags",y,d?.headBeforeHtmlTags),inlineScripts:getHtmlPluginConfig("inlineScripts",y,d?.inlineScripts),headBeforeStyles:getHtmlPluginConfig("headBeforeStyles",y,d?.headBeforeStyles),headBeforeScripts:getHtmlPluginConfig("headBeforeScripts",y,d?.headBeforeScripts),bodyAfterScripts:getHtmlPluginConfig("bodyAfterScripts",y,d?.bodyAfterScripts),moduleFederationScripts:injectFederationScripts({me:[urlJoin(r,["public"])]},a.multiHtmlCdnEnvResolver),global:{hostUrl:r,apiBase:urlJoin(r,[l]),virtualPath:join("/pages",i),moduleName:m.replace(i,"").replace(/^\//,""),...j,...d?.serveGlobalData||{}},styles:[urlJoin(f,[join("public",c,"bundle.css")])],scripts:[urlJoin(f,[join("public",c,"bundle.js")])]};if(e[m]&&shouldEnableReactFastRefresh(!0,[c,p],a)){const e=[devReactFastRefresh.runtime,devReactFastRefresh.reactRefreshSetup];P.headBeforeHtmlTags?P.headBeforeHtmlTags=P.headBeforeHtmlTags.slice(0):P.headBeforeHtmlTags=[],e.forEach((e=>{const t=urlJoin(f,[join("public",join(c,e),"bundle.js")]);P.headBeforeHtmlTags?.push(`<script src="${t}"><\/script>`)}))}return _.template(v)(P)};export const createPageMiddleware=(e,t,r,l)=>(l.devServer?.middlewares||[]).concat((async(a,o)=>{let i;i="/"===a.path?await getPageMainHtml(r,e,l):await getPageModuleHtml(r,a,e,t,l),o.send(i)}));
@@ -1 +1 @@
1
- export const currNow=()=>Date.now().toString();export const getBundleFileName=(t,n,e=!0)=>{const o="js"===t?".js":".css";return n?`bundle${o}`:e?`bundle[contenthash]${o}`:`bundle${o}?${Date.now().toString()}`};
1
+ export const currNow=()=>Date.now().toString();export const getBundleFileName=(e,n,t=!0)=>{const o="js"===e?".js":".css";return n?`bundle${o}`:t?`bundle[contenthash]${o}`:`bundle${o}?${currNow()}`};
@@ -1 +1 @@
1
- function stringifyWithFns(n){return JSON.stringify(n,(function(n,t){return"function"==typeof t?t.toString():t}))}function looksLikeAFunctionString(n){return!![/^function[^(]*\(\s*\)\s*\{[\s\S]*\}$/,/^(\s*async\s*)?(\w*\s*)\(([^)]*)\)\s*=>\s*(.*)$/,/^\s*\w+\s*=>/].find((t=>t.test(n)))}function makeFunctionFromString(funcString){return eval("("+funcString+")")}function parseWithFns(n){try{return JSON.parse(n,(function(n,t){return looksLikeAFunctionString(t)?makeFunctionFromString(t):t}))}catch(n){return{}}}export const jsonSerializer={stringify:stringifyWithFns,parse:parseWithFns};
1
+ function stringifyWithFns(n){return JSON.stringify(n,(function(n,t){return"function"==typeof t?t.toString():t}))}function looksLikeAFunctionString(n){return!![/^function[^(]*\(\s*\)\s*\{[\s\S]*\}$/m,/^(\s*async\s*)?(\w*\s*)\(([^)]*)\)\s*=>\s*(.*)$/m,/^\s*\w+\s*=>/m].find((t=>t.test(n)))}function makeFunctionFromString(funcString){return eval("("+funcString+")")}function parseWithFns(n){try{return JSON.parse(n,(function(n,t){return looksLikeAFunctionString(t)?makeFunctionFromString(t):t}))}catch(n){return{}}}export const jsonSerializer={stringify:stringifyWithFns,parse:parseWithFns};
@@ -1,3 +1,3 @@
1
- import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
1
+ import { type ConfigLoaderOptions } from '../load-config/types.js';
2
2
  import { type FlatEvolveOptions } from '../types/types-options.js';
3
3
  export declare const refreshEvolveMockOptions: (projectCwd: string, evolveOptions: FlatEvolveOptions, configLoaderOptions?: ConfigLoaderOptions) => Promise<FlatEvolveOptions>;
@@ -5,4 +5,4 @@ import { type FlatEvolveOptions } from '../types/types-options.js';
5
5
  * Split the `webpack` to make sure that we have separated compiler process for each module
6
6
  * @param webpackConfig `Omit<Configuration, 'entry'>` webpack final configuration
7
7
  */
8
- export declare function splitToMultiCompilerConfigs(servedEntries: EvolveEntryMap, webpackConfig: Omit<Configuration, 'entry'>, evolveOptions: FlatEvolveOptions): Configuration[];
8
+ export declare function splitToMultiCompilerConfigs(servedEntries: EvolveEntryMap, webpackConfig: Omit<Configuration, 'entry'>, evolveOptions: FlatEvolveOptions, enableHmr?: boolean): Configuration[];
@@ -1 +1 @@
1
- import{mergeOptions}from"@flatjs/common";import{normalizeEvolveEntryName}from"./normalize-entry-map.js";export function splitToMultiCompilerConfigs(e,o,t){const r=[];for(const[o,n]of Object.entries(e)){const e=normalizeEvolveEntryName(o,t.projectVirtualPath);r.push({[e]:n.entry})}return r.map((e=>mergeOptions(o,{name:Object.keys(e)[0],entry:e})))}
1
+ import{join}from"path";import{mergeOptions}from"@flatjs/common";import{devReactFastRefresh}from"../constants.js";import{normalizeEvolveEntryName}from"./normalize-entry-map.js";export function splitToMultiCompilerConfigs(e,t,r,o=!1){const n=[];for(const[t,o]of Object.entries(e)){const e=normalizeEvolveEntryName(t,r.projectVirtualPath);n.push({[e]:o.entry})}return n.map((e=>{const r=Object.keys(e)[0];if(o){e[join(r,devReactFastRefresh.reactRefreshSetup)]=["@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js"]}return mergeOptions(t,{name:r,entry:e})}))}
@@ -1,11 +1,5 @@
1
1
  import { type PartialDeep } from 'type-fest';
2
2
  import { type EvolveConfigBase } from '../define-config/define-config.js';
3
3
  import { type FlatEvolveOptions } from '../types/types-options.js';
4
- export type ConfigLoaderOptions = {
5
- configFile: string;
6
- esmLoaderOptions: {
7
- externals: string[];
8
- projectCwd?: string;
9
- };
10
- };
4
+ import { type ConfigLoaderOptions } from './types.js';
11
5
  export declare const loadEvolveConfig: (configEnv: EvolveConfigBase, projectCwd: string, overrideOptions?: PartialDeep<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions) => Promise<FlatEvolveOptions>;
@@ -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/evolve","@flatjs/mock"]}})=>{const{configFile:l,esmLoaderOptions:r}=s,a=await searchConfig(l,e,{esm:{...r,projectCwd:e}});let n={};n="function"==typeof a?.config?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{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/evolve","@flatjs/mock"]}})=>{const{configFile:l,esmLoaderOptions:r}=s,a=await searchConfig(l,e,{esm:{...r,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};
@@ -0,0 +1,7 @@
1
+ export type ConfigLoaderOptions = {
2
+ configFile: string;
3
+ esmLoaderOptions: {
4
+ externals: string[];
5
+ projectCwd?: string;
6
+ };
7
+ };
@@ -0,0 +1 @@
1
+ export{};
@@ -0,0 +1,16 @@
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("./start-one-entry-build.js").EvolveBuildResult>;
7
+ get pool(): PoolInterface;
8
+ }
9
+ export declare const createThreadWorker: (workerSize: number) => Promise<ThreadPoolForUnittest | (BaseWorker & {
10
+ all: {
11
+ readonly startBuildWorker: (projectCwd: string, entryKey: string, serializedEvolveOptions: string, configLoaderOptions?: import("../load-config/types.js").ConfigLoaderOptions | undefined) => Promise<import("./start-one-entry-build.js").EvolveBuildResult>;
12
+ };
13
+ } & {
14
+ readonly startBuildWorker: (projectCwd: string, entryKey: string, serializedEvolveOptions: string, configLoaderOptions?: import("../load-config/types.js").ConfigLoaderOptions | undefined) => Promise<import("./start-one-entry-build.js").EvolveBuildResult>;
15
+ })>;
16
+ export {};
@@ -0,0 +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 +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{envVerify}from"./env-verify.js";export const prepareServe=async(e,r,t)=>{await envVerify(e,t);const{app:o,devPort:a,devHostUri:i}=await createDevServer(t),s=t.devServer?.mockOptions?.mockFilters||[];for(const[,e]of Object.entries(r))s.push(...e.options?.mockFilters||[]);await attachMockMiddlewares(o,{...t.devServer?.mockOptions,mockFilters:arrayUnique(s),projectCwd:e});const c=await createDevServerEntries(a,r,t);createAppPageRoute(e,o,i,c,t);const n=urlJoin(i,["/pages"]);t.devServer?.autoOpen&&openPage(n);const v=await createDevServerCompilerTasks(e,n,c,t);return Promise.all(v).then((()=>o))};
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{envVerify}from"./env-verify.js";export const prepareServe=async(e,r,t)=>{await envVerify(e,t);const{app:o,devPort:a,devHostUri:i,publicIp:s}=await createDevServer(t),c=t.devServer?.mockOptions?.mockFilters||[];for(const[,e]of Object.entries(r))c.push(...e.options?.mockFilters||[]);await attachMockMiddlewares(o,{...t.devServer?.mockOptions,mockFilters:arrayUnique(c),projectCwd:e});const n=await createDevServerEntries(a,r,t);createAppPageRoute(e,o,i,n,t);const p=urlJoin(i,["/pages"]);t.devServer?.autoOpen&&openPage(p);const v=await createDevServerCompilerTasks(e,p,s,n,t);return Promise.all(v).then((()=>o))};
@@ -1,8 +1,8 @@
1
1
  import { type PartialDeep } from 'type-fest';
2
- import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
2
+ import { type ConfigLoaderOptions } from '../load-config/types.js';
3
3
  import { type FlatEvolveOptions } from '../types/types-options.js';
4
4
  import { type EvolveBuildResult } from './start-one-entry-build.js';
5
- export declare function getBuildEntryFiles(projectCwd: string, diffFiles: string[], allEntryInputs: string[], resolveAlias?: Record<string, string>): Promise<string[]>;
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
@@ -1 +1 @@
1
- import{isAbsolute,join}from"node:path";import{getDiffFiles,getCommitIdOfBranch}from"@armit/git";import{createThreadPool}from"@armit/worker-threads";import{arraysIntersect,chalk,logger,requireResolve}from"@flatjs/common";import{traverseGraph}from"@flatjs/graph";import Listr from"listr";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{envVerify}from"./env-verify.js";import{getWorkerPath}from"./get-worker-path.js";export async function getBuildEntryFiles(e,t,r,i){const o=[],n=[];for(const e of r)t.includes(e)?o.push(e):n.push(e);if(n.length){const r=await traverseGraph({input:n,projectCwd:e,treeNodeFilter:()=>!0,lessImportOptions:{projectCwd:e,aliases:i}});if(!r)return o;logger.debug(`DependencyGraph:\n${JSON.stringify(r,null,2)}`);for(const e of n){const i=r[e]||[];arraysIntersect(i,t)&&o.push(e)}}return o}export async function dynamicCheckBuildEntryMap(e,t,r,i,o){const n={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 ..."),!t){const e=s.ci?.basedBranch||"origin/master";t=await getCommitIdOfBranch(e),logger.info(`Resolving base branch "${e}" commit hash "${t}" ...`)}let a=t?await getDiffFiles(t,r):[];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);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,t,r,i={},o)=>{const{buildEntries:n,newEvolveOptions:s}=await dynamicCheckBuildEntryMap(e,t,r,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=getWorkerPath(),d=await createThreadPool(c,{size:l}),f=new Listr([],{concurrent:l,exitOnError:!0}),g=[];for(const[t]of Object.entries(n))f.add({title:`Build module ${chalk(["magenta"])(t)} ...`,task:async()=>{const r=await d.startBuildWorker(e,t,jsonSerializer.stringify(i),o);g.push(r)}});return f.tasks.length&&await f.run(),d.pool.terminate(),g};
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={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,4 +1,4 @@
1
- import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
1
+ import { type ConfigLoaderOptions } from '../load-config/types.js';
2
2
  import { type EvolveBuildResult } from './start-one-entry-build.js';
3
3
  /**
4
4
  * FIXME: The main entry to start an evolve `build`, NOTE: avoid pass configuration with `function` here.
@@ -1,5 +1,5 @@
1
1
  import { type PartialDeep } from 'type-fest';
2
- import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
2
+ import { type ConfigLoaderOptions } from '../load-config/types.js';
3
3
  import { type FlatEvolveOptions } from '../types/types-options.js';
4
4
  import { type EvolveBuildResult } from './start-one-entry-build.js';
5
5
  export declare const startBuild: (projectCwd: string, buildModules: string[], overrideEvolveOptions?: PartialDeep<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions) => Promise<EvolveBuildResult[]>;
@@ -1 +1 @@
1
- import{createThreadPool}from"@armit/worker-threads";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{envVerify}from"./env-verify.js";import{getWorkerPath}from"./get-worker-path.js";export const startBuild=async(e,r,t={},o)=>{const i={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=getWorkerPath(),m=await createThreadPool(c,{size:l}),d=new Listr([],{concurrent:l,exitOnError:!0}),f=[];for(const[r]of Object.entries(a))d.add({title:`Build module ${chalk(["magenta"])(r)} ...`,task:async()=>{const i=await m.startBuildWorker(e,r,jsonSerializer.stringify(t),o);f.push(i)}});return d.tasks.length&&await d.run(),m.pool.terminate(),f};
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={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 +1 @@
1
- import webpack from"webpack";import{loadWebpackConfig}from"../create-webpack/load-webpack-config.js";import{splitToMultiCompilerConfigs}from"../helpers/split-to-multi-compiler.js";export const startOneEntryBuild=async(r,o)=>{const t=await loadWebpackConfig("production",r,o),n=splitToMultiCompilerConfigs(r,t,o);if(n.length>1)throw new Error("startOneEntryBuild() only support `compiler` at a time");const e=n[0];return new Promise(((r,t)=>{webpack(e,((n,i)=>{if(n)return t(n);const a=i?.toJson();return a?.errors?.length?t(a.errors):o.rejectWarnings&&a?.warnings?.length?t(a.warnings):void r({name:e.name,warningStats:a?.warnings})}))}))};
1
+ import webpack from"webpack";import{loadWebpackConfig}from"../create-webpack/load-webpack-config.js";import{splitToMultiCompilerConfigs}from"../helpers/split-to-multi-compiler.js";export const startOneEntryBuild=async(r,o)=>{const t=await loadWebpackConfig("production",r,o),n=splitToMultiCompilerConfigs(r,t,o,!1);if(n.length>1)throw new Error("startOneEntryBuild() only support `compiler` at a time");const e=n[0];return new Promise(((r,t)=>{webpack(e,((n,i)=>{if(n)return t(n);const a=i?.toJson();return a?.errors?.length?t(a.errors):o.rejectWarnings&&a?.warnings?.length?t(a.warnings):void r({name:e.name,warningStats:a?.warnings})}))}))};
@@ -1,5 +1,5 @@
1
1
  import { type PartialDeep } from 'type-fest';
2
- import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
2
+ import { type ConfigLoaderOptions } from '../load-config/types.js';
3
3
  import { type FlatEvolveOptions } from '../types/types-options.js';
4
4
  /**
5
5
  * The main entry to start evolve serve
@@ -1,5 +1,5 @@
1
1
  import { type PartialDeep } from 'type-fest';
2
- import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
2
+ import { type ConfigLoaderOptions } from '../load-config/types.js';
3
3
  import { type FlatEvolveOptions } from '../types/types-options.js';
4
4
  /**
5
5
  * The main entry to start evolve static server to proxy all modules of `production` build
@@ -16,7 +16,7 @@ export interface Options {
16
16
  include?: RegExp;
17
17
  /**
18
18
  * add errors to webpack instead of warnings
19
- * @default true
19
+ * @default false
20
20
  */
21
21
  failOnError?: boolean;
22
22
  /**
@@ -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:!0,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{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)}))}}
@@ -5,6 +5,13 @@
5
5
  * 3. Normally build manually using (`flat build evolve -m "a;b"`)
6
6
  */
7
7
  export type FlatEvolveCI = {
8
+ /**
9
+ * A function used to determine if a module (also include root node) should be included in the dependency tree
10
+ * it should not work if you have `fixedBuildModules` definition.
11
+ * @param moduleId The imported module
12
+ * @default `() => true`
13
+ */
14
+ graphTreeNodeFilter?: (moduleId: string) => boolean;
8
15
  /**
9
16
  * The build module patterns, `Highest Priority First`
10
17
  * Support "a;b;c" RegExp pattern; `new RegExp(`${pattern}`).test(entryKey)`
@@ -53,6 +53,8 @@ export declare type MultiHtmlCDNEntryItem = {
53
53
  headBeforeStyles?: HtmlPluginConfigTokenType<string[]>;
54
54
  /**
55
55
  * The ordered scripts will be injected before html head.
56
+ * Note in `serve` mode we will auto remove `react`,`react-dom`('react.development.js', 'react-dom.development.js') from CDN, and use internal inject to enable `HMR`
57
+ * Or you must use `react devTool` chrome extension.
56
58
  * @default [
57
59
  * `https://polyfill.io/v3/polyfill.min.js?features=Array.from%2CArray.isArray%2CArray.of%2CArray.prototype.entries%2CArray.prototype.every%2CArray.prototype.fill%2CArray.prototype.filter%2CArray.prototype.find%2CArray.prototype.findIndex%2CArray.prototype.flat%2CArray.prototype.forEach%2CArray.prototype.flatMap%2CArray.prototype.keys%2CArray.prototype.indexOf%2CArray.prototype.includes%2CArray.prototype.lastIndexOf%2CArray.prototype.map%2CArray.prototype.reduce%2CArray.prototype.reduceRight%2CArray.prototype.some%2CArray.prototype.sort%2CArray.prototype.values%2CArrayBuffer%2CBlob%2CDataView%2CDate.now%2CObject.assign%2CObject.create%2CObject.defineProperties%2CObject.defineProperty%2CObject.entries%2CObject.freeze%2CObject.fromEntries%2CObject.getOwnPropertySymbols%2CObject.getOwnPropertyNames%2CObject.getOwnPropertyDescriptors%2CObject.getOwnPropertyDescriptor%2CObject.getPrototypeOf%2CObject.is%2CObject.isExtensible%2CObject.isFrozen%2CObject.isSealed%2CObject.keys%2CObject.values%2CObject.setPrototypeOf%2CPromise%2CPromise.prototype.finally%2CReflect%2CReflect.apply%2CReflect.construct%2CReflect.defineProperty%2CReflect.deleteProperty%2CReflect.getPrototypeOf%2CReflect.getOwnPropertyDescriptor%2CReflect.get%2CReflect.ownKeys%2CReflect.isExtensible%2CReflect.has%2CReflect.preventExtensions%2CReflect.set%2CReflect.setPrototypeOf%2CSet%2CString.prototype.trimStart%2CString.prototype.trimEnd%2CString.prototype.trim%2CString.prototype.startsWith%2CString.prototype.repeat%2CString.prototype.replaceAll%2CString.prototype.padStart%2CString.prototype.padEnd%2CMap%2CObject.seal%2Cconsole.groupEnd%2Cconsole.group`,
58
60
  * `https://unpkg.com/react@17.0.2/umd/react.production.min.js`,