@flatjs/evolve 2.1.0-next.23 → 2.1.0-next.25

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- import{join}from"node:path";import{TsconfigPathsPlugin}from"tsconfig-paths-webpack-plugin";import{mergeOptions}from"@flatjs/common";export const createResolve=(s,o)=>{const n={mainFields:["browser","module","main"],extensions:[".ts",".tsx",".js",".json"],extensionAlias:{".js":[".js",".ts"],".cjs":[".cjs",".cts"],".mjs":[".mjs",".mts"],".jsx":[".jsx",".tsx"]},plugins:[new TsconfigPathsPlugin({configFile:join(s,"tsconfig.json"),extensions:[".ts",".tsx",".js",".jsx"]})]};return mergeOptions(n,o?.resolve||{})};
1
+ import{join}from"node:path";import{TsconfigPathsPlugin}from"tsconfig-paths-webpack-plugin";import{mergeOptions}from"@flatjs/common";export const createResolve=(s,o)=>{const t={mainFields:["browser","module","main"],extensions:[".ts",".tsx",".js",".jsx",".mjs",".cjs",".mts",".cts",".json"],extensionAlias:{".js":[".js",".ts"],".cjs":[".cjs",".cts"],".mjs":[".mjs",".mts"],".jsx":[".jsx",".tsx"]},plugins:[new TsconfigPathsPlugin({configFile:join(s,"tsconfig.json"),extensions:[".ts",".tsx",".js",".jsx",".mjs"]})]};return mergeOptions(t,o?.resolve||{})};
@@ -1,12 +1,12 @@
1
1
  import { type FlatEvolveDevServerOptions } from '../types/types-dev-server.js';
2
- import { EntryMapItem } from '../types/types-entry-map.js';
2
+ import { EvolveEntryMap } from '../types/types-entry-map.js';
3
3
  import { type FlatEvolveOptions } from '../types/types-options.js';
4
4
  /**
5
5
  * Loads the watch options for webpack configuration.
6
6
  *
7
- * @param entryMapItemList - The list of entry map items.
7
+ * @param groupEntryMap - The map of entry.
8
8
  * @param evolveOptions - The options for the evolve process.
9
9
  * @param originalOptions - The original watch options to be merged with.
10
10
  * @returns The updated watch options for webpack configuration.
11
11
  */
12
- export declare const loadWatchOptions: (entryMapItemList: EntryMapItem[], evolveOptions: FlatEvolveOptions, originalOptions?: FlatEvolveDevServerOptions["watchOptions"]) => FlatEvolveDevServerOptions["watchOptions"];
12
+ export declare const loadWatchOptions: (groupEntryMap: EvolveEntryMap, evolveOptions: FlatEvolveOptions, originalOptions?: FlatEvolveDevServerOptions["watchOptions"]) => FlatEvolveDevServerOptions["watchOptions"];
@@ -1 +1 @@
1
- import{normalizeEvolveEntryName}from"../helpers/normalize-entry-map.js";export const loadWatchOptions=(e,o,r={})=>{const{ignored:n=[]}=r,{entryMap:t,projectVirtualPath:a}=o;for(const[o]of Object.entries(t)){const r=normalizeEvolveEntryName(o,a);e.findIndex((e=>e[0]===r))<0&&n.push(`**/${r}/**/*`)}return{...r,ignored:n}};
1
+ import{existsSync}from"node:fs";import{logger}from"@flatjs/common";import{normalizeEntryModuleAbsolutePath}from"../helpers/normalize-entry-module-absolute-path.js";export const loadWatchOptions=(o,e,t={})=>{const{ignored:r=[]}=t,{entryMap:n}=e,s=normalizeEntryModuleAbsolutePath(e,o),l=normalizeEntryModuleAbsolutePath(e,n);for(const o of l){existsSync(o)||logger.warn(`The module path does not exist. Check ${o}`);s.findIndex((e=>e===o))<0&&r.push(`**${o}**/*`)}return{...t,ignored:r}};
@@ -1 +1 @@
1
- import{assertGroupEntryItem}from"../helpers/assert-group-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";import{loadWatchOptions}from"./load-watch-options.js";export const loadWebpackConfig=async(e,t,r)=>{const a="development"===e,{projectCwd:o,webpack:s,devServer:c}=r,p=assertGroupEntryItem(t,r),n=loadWatchOptions(p,r,c?.watchOptions),i=createRuleSets(a,p,r),m=await createPlugins(a,p,r),l=p[0];return{mode:e,plugins:m,watchOptions:n,output:await createOutput(a,r,l),context:o,target:s?.target??["web","es5"],resolve:createResolve(o,s),module:{rules:i},devtool:a?"eval-source-map":s?.sourceMap||!1,externalsType:s?.externalsType,externals:createExternals(s?.externals,l),performance:createPerformance(a,s?.performance),optimization:createOptimization(a,r,l),infrastructureLogging:s?.infrastructureLogging??{level:"warn"},stats:s?.stats??{preset:"minimal"},cache:{type:"memory"}}};
1
+ import{assertGroupEntryItem}from"../helpers/assert-group-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";import{loadWatchOptions}from"./load-watch-options.js";export const loadWebpackConfig=async(e,t,r)=>{const a="development"===e,{projectCwd:o,webpack:s,devServer:c}=r,n=loadWatchOptions(t,r,c?.watchOptions),p=assertGroupEntryItem(t,r),i=createRuleSets(a,p,r),m=await createPlugins(a,p,r),l=p[0];return{mode:e,plugins:m,watchOptions:n,output:await createOutput(a,r,l),context:o,target:s?.target??["web","es5"],resolve:createResolve(o,s),module:{rules:i},devtool:a?"eval-source-map":s?.sourceMap||!1,externalsType:s?.externalsType,externals:createExternals(s?.externals,l),performance:createPerformance(a,s?.performance),optimization:createOptimization(a,r,l),infrastructureLogging:s?.infrastructureLogging??{level:"warn"},stats:s?.stats??{preset:"errors-warnings"},cache:{type:"memory"}}};
@@ -1 +1 @@
1
- import{requireResolve}from"@flatjs/common";import{mergeBabelOption}from"../../helpers/merge-babel-options.js";import{shouldEnableReactFastRefresh}from"../../helpers/should-enable-react-fast-refresh.js";export const ruleBabel=e=>({test:/\.(tsx|ts|js|jsx)$/,use:[{loader:requireResolve(import.meta.url,"babel-loader"),options:e}]});export const ruleScripts=(e,r,s)=>{const{babelOptions:o={},modularImports:t=[]}=s.loaderOptions,l=mergeBabelOption(t,o);return shouldEnableReactFastRefresh(e,r,s)&&(l.plugins?l.plugins.push(requireResolve(import.meta.url,"react-refresh/babel")):l.plugins=[requireResolve(import.meta.url,"react-refresh/babel")]),ruleBabel(l)};
1
+ import{requireResolve}from"@flatjs/common";import{mergeBabelOption}from"../../helpers/merge-babel-options.js";import{shouldEnableReactFastRefresh}from"../../helpers/should-enable-react-fast-refresh.js";export const ruleBabel=e=>({test:/\.(tsx|ts|js|jsx|mjs|cjs|mts|cts)$/,use:[{loader:requireResolve(import.meta.url,"babel-loader"),options:e}]});export const ruleScripts=(e,r,s)=>{const{babelOptions:t={},modularImports:o=[]}=s.loaderOptions,l=mergeBabelOption(o,t);return shouldEnableReactFastRefresh(e,r,s)&&(l.plugins?l.plugins.push(requireResolve(import.meta.url,"react-refresh/babel")):l.plugins=[requireResolve(import.meta.url,"react-refresh/babel")]),ruleBabel(l)};
@@ -1,3 +1,3 @@
1
1
  import { type FlatEvolveOptions } from '../types/types-options.js';
2
2
  import { type EvolveDevServerEntryMap } from './middlewares/types.js';
3
- export declare const createDevServerCompilerTask: (projectCwd: string, mainPage: string, publicIp: string, servedDevServerEntries: EvolveDevServerEntryMap, servedDevServerEntryList: Array<EvolveDevServerEntryMap>, evolveOptions: FlatEvolveOptions) => Promise<boolean>;
3
+ export declare const createDevServerCompilerTask: (publicIp: string, servedDevServerEntries: EvolveDevServerEntryMap, servedDevServerEntryList: Array<EvolveDevServerEntryMap>, evolveOptions: FlatEvolveOptions) => Promise<boolean>;
@@ -1 +1 @@
1
- import{relative}from"node:path";import webpack from"webpack";import{chalk,logger,mergeOptions,urlJoin}from"@flatjs/common";import{loadWebpackConfig}from"../create-webpack/load-webpack-config.js";import{assertSingleCompiler}from"../helpers/assert-single-compiler.js";import{flatEntryMap}from"../helpers/flat-entry-map.js";import{shouldEnableReactFastRefresh}from"../helpers/should-enable-react-fast-refresh.js";import{addCompilerToDevServer}from"./add-compiler-to-dev-server.js";export const createDevServerCompilerTask=async(e,r,o,t,a,n)=>{const[i,s]=Object.entries(t)[0],{devServerPort:l,devServerHostUri:p}=s;for(const[,e]of Object.entries(t)){const r=e.entryConfig,o=r.options?.moduleFederation,t=o?.remotes||[],n=flatEntryMap(a);t.forEach((e=>{e.endpoint=e=>{const r=n[e];if(!r)throw new Error(`No servedDevServerEntry found via "${e}"`);return urlJoin(r?.devServerHostUri,["/public"])}}))}const c=Object.keys(t).reduce(((e,r)=>(e[r]=t[r].entryConfig,e)),{}),m=urlJoin(p,["public"]),f=await loadWebpackConfig("development",c,mergeOptions(n,{webpack:{publicPath:m}})),d=shouldEnableReactFastRefresh(!0,[i,s.entryConfig],n),v=assertSingleCompiler(c,f,n,d),g=webpack(v),h=addCompilerToDevServer(g,d,l,o,n),b=g.name||"";return g.hooks.invalid.tap("fileChange",(r=>{const o=relative(e,r||"");logger.info(`file change ➩ ${chalk(["cyan"])(o)}`,b)})),g.hooks.done.tap("compileDone",(()=>{logger.info(`debug page ➩ ${chalk(["cyan"])(r)}`,b)})),h};
1
+ import{relative}from"node:path";import webpack from"webpack";import{chalk,logger,mergeOptions,urlJoin}from"@flatjs/common";import{loadWebpackConfig}from"../create-webpack/load-webpack-config.js";import{assertSingleCompiler}from"../helpers/assert-single-compiler.js";import{flatEntryMap}from"../helpers/flat-entry-map.js";import{shouldEnableReactFastRefresh}from"../helpers/should-enable-react-fast-refresh.js";import{addCompilerToDevServer}from"./add-compiler-to-dev-server.js";export const createDevServerCompilerTask=async(e,r,o,t)=>{const{projectCwd:a}=t,[n,i]=Object.entries(r)[0],{devServerPort:s,devServerHostUri:l}=i;for(const[,e]of Object.entries(r)){const r=e.entryConfig,t=r.options?.moduleFederation,a=t?.remotes||[],n=flatEntryMap(o);a.forEach((e=>{e.endpoint=e=>{const r=n[e];if(!r)throw new Error(`No servedDevServerEntry found via "${e}"`);return urlJoin(r?.devServerHostUri,["/public"])}}))}const p=Object.keys(r).reduce(((e,o)=>(e[o]=r[o].entryConfig,e)),{}),c=urlJoin(l,["public"]),m=await loadWebpackConfig("development",p,mergeOptions(t,{webpack:{publicPath:c}})),f=shouldEnableReactFastRefresh(!0,[n,i.entryConfig],t),d=assertSingleCompiler(p,m,t,f),v=webpack(d),h=addCompilerToDevServer(v,f,s,e,t),b=v.name||"";return v.hooks.invalid.tap("fileChange",(e=>{const r=relative(a,e||"");logger.info(`file change ➩ ${chalk(["cyan"])(r||"")}`,b)})),h};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Check if the current environment is a CI environment.
3
+ */
4
+ export declare const isCI: () => boolean;
@@ -0,0 +1 @@
1
+ import ci from"ci-info";export const isCI=()=>ci.isCI;
@@ -1,6 +1,7 @@
1
1
  export * from './allow-px2rem-for-module.js';
2
2
  export * from './assert-group-entry-item.js';
3
3
  export * from './assert-single-compiler.js';
4
+ export * from './check-runtime-env.js';
4
5
  export * from './chunk-entry-map.js';
5
6
  export * from './custom-listr-renderer.js';
6
7
  export * from './delete-object-keys.js';
@@ -1 +1 @@
1
- export*from"./allow-px2rem-for-module.js";export*from"./assert-group-entry-item.js";export*from"./assert-single-compiler.js";export*from"./chunk-entry-map.js";export*from"./custom-listr-renderer.js";export*from"./delete-object-keys.js";export*from"./enable-bundle-hashname-for-module.js";export*from"./flat-entry-map.js";export*from"./format-spinner-text.js";export*from"./get-bundle-file-name.js";export*from"./get-html-plugin-config.js";export*from"./get-pacakge-dir.js";export*from"./get-runtime-cdn-base.js";export*from"./is-deep-equal.js";export*from"./json-serializer.js";export*from"./merge-babel-options.js";export*from"./normalize-check-entry-options.js";export*from"./normalize-entry-map.js";export*from"./normalize-group-name.js";export*from"./normalize-page-proxy.js";export*from"./normalize-resolve-alias.js";export*from"./normalize-template-inject-tokens.js";export*from"./open-page.js";export*from"./print-log.js";export*from"./refresh-evolve-mock-options.js";export*from"./script-injects.js";export*from"./should-enable-react-fast-refresh.js";export*from"./split-to-entry-group.js";export*from"./verify-group-entry-options.js";
1
+ export*from"./allow-px2rem-for-module.js";export*from"./assert-group-entry-item.js";export*from"./assert-single-compiler.js";export*from"./check-runtime-env.js";export*from"./chunk-entry-map.js";export*from"./custom-listr-renderer.js";export*from"./delete-object-keys.js";export*from"./enable-bundle-hashname-for-module.js";export*from"./flat-entry-map.js";export*from"./format-spinner-text.js";export*from"./get-bundle-file-name.js";export*from"./get-html-plugin-config.js";export*from"./get-pacakge-dir.js";export*from"./get-runtime-cdn-base.js";export*from"./is-deep-equal.js";export*from"./json-serializer.js";export*from"./merge-babel-options.js";export*from"./normalize-check-entry-options.js";export*from"./normalize-entry-map.js";export*from"./normalize-group-name.js";export*from"./normalize-page-proxy.js";export*from"./normalize-resolve-alias.js";export*from"./normalize-template-inject-tokens.js";export*from"./open-page.js";export*from"./print-log.js";export*from"./refresh-evolve-mock-options.js";export*from"./script-injects.js";export*from"./should-enable-react-fast-refresh.js";export*from"./split-to-entry-group.js";export*from"./verify-group-entry-options.js";
@@ -0,0 +1,10 @@
1
+ import { EvolveEntryMap } from '../types/types-entry-map.js';
2
+ import { FlatEvolveOptions } from '../types/types-options.js';
3
+ /**
4
+ * Normalizes the absolute paths of entry modules based on the provided evolve options and entry map.
5
+ *
6
+ * @param evolveOptions - The options for the evolve process.
7
+ * @param evolveEntryMap - The map of evolve entries.
8
+ * @returns An array of normalized entry module paths.
9
+ */
10
+ export declare const normalizeEntryModuleAbsolutePath: (evolveOptions: FlatEvolveOptions, evolveEntryMap: EvolveEntryMap) => string[];
@@ -0,0 +1 @@
1
+ import{resolve}from"node:path";import{ensureSlash}from"@flatjs/common";export const normalizeEntryModuleAbsolutePath=(e,o)=>{const{projectCwd:s}=e,t=[];for(const[,e]of Object.entries(o)){const{entryModuleBase:o,entry:r}=e;if(o)for(const e of o){const o=ensureSlash(resolve(s,e),!0);t.push(o)}else for(const e of r){let o=resolve(s,e);/\.(ts|tsx|js|jsx)$/.test(o)&&(o=o.replace(/\/[^/]*$/,""));const r=ensureSlash(o,!0);t.push(r)}}return Array.from(new Set(t))};
@@ -1 +1 @@
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
+ import{arrayUnique,chalk,logger,urlJoin}from"@flatjs/common";import{attachMockMiddlewares}from"@flatjs/mock";import{ignoreEntryOptionKeys,moduleName}from"../constants.js";import{createAppPageRoute,createDevServer,createDevServerCompilerTask,createDevServerEntries}from"../dev-server/index.js";import{flatEntryMap,openPage}from"../helpers/index.js";import{normalizePageProxy}from"../helpers/normalize-page-proxy.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{verifyGroupEntryOptions}from"../helpers/verify-group-entry-options.js";import{envVerify}from"./env-verify.js";export const prepareServe=async(e,r,o)=>{await envVerify(e,o);const t=splitToEntryGroup(r,o,ignoreEntryOptionKeys,!0);if(!t.length)return void logger.warn("No served entries provided!");const n=[],{app:i,devPort:a,devHostUri:p,publicIp:s}=await createDevServer(o),c=o.devServer?.mockOptions?.mockFilters||[];for(const[,e]of Object.entries(r))c.push(...e.options?.mockFilters||[]);await attachMockMiddlewares(i,{...o.devServer?.mockOptions,mockFilters:arrayUnique(c),projectCwd:e});let m=a;const l=[];for(const e of t){if(!verifyGroupEntryOptions(e,ignoreEntryOptionKeys,!0))throw new Error("The entry options in a group must be the same.");m++;const r=await createDevServerEntries(m,e,o);l.push(r)}const v=flatEntryMap(l);createAppPageRoute(e,i,p,v,o);const y=normalizePageProxy(o.devServer?.pageProxy||"/pages"),f=urlJoin(p,[y]);o.devServer?.autoOpen&&openPage(f);for(const e of l){const r=createDevServerCompilerTask(s,e,l,o);n.push(r)}return Promise.all(n).then((()=>(logger.info(`debug page ➩ ${chalk(["cyan"])(f)}`,moduleName),i)))};
@@ -1 +1 @@
1
- import Listr from"listr";import{isAbsolute,join}from"node:path";import{getCommitIdOfBranch,getDiffFiles}from"@armit/git";import{arraysIntersect,chalk,logger,requireResolve}from"@flatjs/common";import{traverseGraph}from"@flatjs/graph";import{createGlobalCompiler}from"../compiler/create-global-compiler.js";import{ignoreEntryOptionKeys,moduleName}from"../constants.js";import{CustomListrRenderer}from"../helpers/custom-listr-renderer.js";import{filterActivedEntriesByEntryInputs,filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{formatSpinnerText}from"../helpers/format-spinner-text.js";import{getGitRoot}from"../helpers/get-git-root.js";import{getMaxProcessTasks}from"../helpers/get-max-process-tasks.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{resolveEntryMapInputFiles}from"../helpers/resolve-entry-map-input-files.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{createThreadWorker}from"./create-thread-worker.js";import{envVerify}from"./env-verify.js";export async function getBuildEntryFiles(e,r,t,o,i){const n=[],s=[];for(const e of t)r.includes(e)?n.push(e):s.push(e);if(i&&logger.info("Use custom graph traverse filter",moduleName),s.length){const t=await traverseGraph({input:s,projectCwd:e,treeNodeFilter:i||(()=>!0),lessImportOptions:{projectCwd:e,aliases:o}});if(!t)return n;logger.debug(`DependencyGraph:\n${JSON.stringify(t,null,2)}`);for(const e of s){const o=t[e]||[];arraysIntersect(o,r)&&n.push(e)}}return n}export async function dynamicCheckBuildEntryMap(e,r,t,o,i){const n={projectCwd:e,command:"build",resolve:requireResolve},s=await loadEvolveConfig(n,e,o,i);if(s.ci?.fixedBuildModules&&s.ci?.fixedBuildModules.length){logger.info("Use `fixedBuildModules` configuration to build...");return{buildEntries:filterActivedEntriesByModule(s.entryMap,s.ci?.fixedBuildModules),newEvolveOptions:s}}if(logger.info("Dynamicly checking code changed modules ..."),!r){const e=s.ci?.basedBranch||"origin/master";r=await getCommitIdOfBranch(e),logger.info(`Resolving base branch "${e}" commit hash "${r}" ...`)}let a=r?await getDiffFiles(r,t):[];const l=getGitRoot(e);if(!l)throw new Error(`No .git root (${e}) found`);if(a=a.map((e=>isAbsolute(e)?e:join(l,e))),logger.debug(`Diff files: \n${JSON.stringify(a,null,2)}`),!a.length)return logger.warn("It seems that there are no code files changed."),{buildEntries:{},newEvolveOptions:s};const p=await resolveEntryMapInputFiles(e,s.entryMap),c=await getBuildEntryFiles(e,a,p,s.webpack?.resolve?.alias,s.ci?.graphTreeNodeFilter);logger.debug(`To build entry files: \n${JSON.stringify(c,null,2)}`);return{buildEntries:await filterActivedEntriesByEntryInputs(e,s.entryMap,c),newEvolveOptions:s}}export const startDynamicBuild=async(e,r,t,o={},i)=>{const{buildEntries:n,newEvolveOptions:s}=await dynamicCheckBuildEntryMap(e,r,t,o,i);await envVerify(e,s);const a=normalizeEvolveEntryMap(n,s.entryMap),l=splitToEntryGroup(a,s,ignoreEntryOptionKeys,!1);if(!l.length)return logger.warn("No build entries provided!"),[];await createGlobalCompiler(!1,s);const{threads:p={}}=s,c=getMaxProcessTasks(l.length,p?.maxThreads);logger.info(`Start dynamic build with (${chalk(["magenta"])(String(c))}) workers`);const m=createThreadWorker({...p,maxThreads:c}),d=new Listr([],{concurrent:c,exitOnError:!0,renderer:CustomListrRenderer}),f=[];for(const r of l){const t=Object.values(r)?.[0]?.groupName||"",n=Object.keys(r);d.add({title:`Group ${chalk(["magenta"])(t)} $STATUS \n${formatSpinnerText(n)}`,task:async()=>{const r=await m.startBuildWorker({projectCwd:e,entryKeys:n,serializedEvolveOptions:jsonSerializer.stringify(o),configLoaderOptions:i});f.push(r)}})}if(d.tasks.length)try{await d.run()}catch(e){throw m.terminate(),e}return m.terminate(),f};
1
+ import Listr from"listr";import{isAbsolute,join}from"node:path";import{getCommitIdOfBranch,getDiffFiles}from"@armit/git";import{arraysIntersect,chalk,logger,requireResolve}from"@flatjs/common";import{traverseGraph}from"@flatjs/graph";import{createGlobalCompiler}from"../compiler/create-global-compiler.js";import{ignoreEntryOptionKeys,moduleName}from"../constants.js";import{isCI}from"../helpers/check-runtime-env.js";import{CustomListrRenderer}from"../helpers/custom-listr-renderer.js";import{filterActivedEntriesByEntryInputs,filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{formatSpinnerText}from"../helpers/format-spinner-text.js";import{getGitRoot}from"../helpers/get-git-root.js";import{getMaxProcessTasks}from"../helpers/get-max-process-tasks.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{resolveEntryMapInputFiles}from"../helpers/resolve-entry-map-input-files.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{createThreadWorker}from"./create-thread-worker.js";import{envVerify}from"./env-verify.js";export async function getBuildEntryFiles(e,r,t,o,i){const n=[],s=[];for(const e of t)r.includes(e)?n.push(e):s.push(e);if(i&&logger.info("Use custom graph traverse filter",moduleName),s.length){const t=await traverseGraph({input:s,projectCwd:e,treeNodeFilter:i||(()=>!0),lessImportOptions:{projectCwd:e,aliases:o}});if(!t)return n;logger.debug(`DependencyGraph:\n${JSON.stringify(t,null,2)}`);for(const e of s){const o=t[e]||[];arraysIntersect(o,r)&&n.push(e)}}return n}export async function dynamicCheckBuildEntryMap(e,r,t,o,i){const n={projectCwd:e,command:"build",resolve:requireResolve},s=await loadEvolveConfig(n,e,o,i);if(s.ci?.fixedBuildModules&&s.ci?.fixedBuildModules.length){logger.info("Use `fixedBuildModules` configuration to build...");return{buildEntries:filterActivedEntriesByModule(s.entryMap,s.ci?.fixedBuildModules),newEvolveOptions:s}}if(logger.info("Dynamicly checking code changed modules ..."),!r){const e=s.ci?.basedBranch||"origin/master";r=await getCommitIdOfBranch(e),logger.info(`Resolving base branch "${e}" commit hash "${r}" ...`)}let a=r?await getDiffFiles(r,t):[];const l=getGitRoot(e);if(!l)throw new Error(`No .git root (${e}) found`);if(a=a.map((e=>isAbsolute(e)?e:join(l,e))),logger.debug(`Diff files: \n${JSON.stringify(a,null,2)}`),!a.length)return logger.warn("It seems that there are no code files changed."),{buildEntries:{},newEvolveOptions:s};const p=await resolveEntryMapInputFiles(e,s.entryMap),c=await getBuildEntryFiles(e,a,p,s.webpack?.resolve?.alias,s.ci?.graphTreeNodeFilter);logger.debug(`To build entry files: \n${JSON.stringify(c,null,2)}`);return{buildEntries:await filterActivedEntriesByEntryInputs(e,s.entryMap,c),newEvolveOptions:s}}export const startDynamicBuild=async(e,r,t,o={},i)=>{const{buildEntries:n,newEvolveOptions:s}=await dynamicCheckBuildEntryMap(e,r,t,o,i);await envVerify(e,s);const a=normalizeEvolveEntryMap(n,s.entryMap),l=splitToEntryGroup(a,s,ignoreEntryOptionKeys,!1);if(!l.length)return logger.warn("No build entries provided!"),[];await createGlobalCompiler(!1,s);const{threads:p={}}=s,c=getMaxProcessTasks(l.length,p?.maxThreads);logger.info(`Start dynamic build with (${chalk(["magenta"])(String(c))}) workers`);const m=createThreadWorker({...p,maxThreads:c}),f=new Listr([],{concurrent:c,exitOnError:!0,renderer:isCI()?void 0:CustomListrRenderer}),d=[];for(const r of l){const t=Object.values(r)?.[0]?.groupName||"",n=Object.keys(r);let s=`Group ${chalk(["magenta"])(t)} $STATUS \n${formatSpinnerText(n)}`;isCI()&&(s=`Group ${chalk(["magenta"])(t)} compiling... \n${formatSpinnerText(n)}`),f.add({title:s,task:async()=>{const r=await m.startBuildWorker({projectCwd:e,entryKeys:n,serializedEvolveOptions:jsonSerializer.stringify(o),configLoaderOptions:i});d.push(r)}})}if(f.tasks.length)try{await f.run()}catch(e){throw m.terminate(),e}return m.terminate(),d};
@@ -1 +1 @@
1
- import{configLoggerStdWriteSteam,loggerSimpleStdWriteSteam,requireResolve}from"@flatjs/common";import{ignoreEntryOptionKeys}from"../constants.js";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareBuild}from"./prepare-build.js";export default async e=>{configLoggerStdWriteSteam();const{projectCwd:r,entryKeys:o,serializedEvolveOptions:t,configLoaderOptions:i,messagePort:l}=e,n={projectCwd:r,command:"build",resolve:requireResolve},p=jsonSerializer.parse(t)||{},s=await loadEvolveConfig(n,r,p,i),a=o.map((e=>new RegExp(`^${e}$`))),m=filterActivedEntriesByModule(s.entryMap,a),d=normalizeEvolveEntryMap(m,s.entryMap),g=splitToEntryGroup(d,s,ignoreEntryOptionKeys,!1);return prepareBuild(g[0],s).then((e=>(loggerSimpleStdWriteSteam.postMessage(l),e)))};
1
+ import{configLoggerStdWriteSteam,loggerSimpleStdWriteSteam,requireResolve}from"@flatjs/common";import{ignoreEntryOptionKeys}from"../constants.js";import{isCI}from"../helpers/check-runtime-env.js";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareBuild}from"./prepare-build.js";export default async e=>{isCI()||configLoggerStdWriteSteam();const{projectCwd:r,entryKeys:o,serializedEvolveOptions:t,configLoaderOptions:i,messagePort:s}=e,n={projectCwd:r,command:"build",resolve:requireResolve},p=jsonSerializer.parse(t)||{},l=await loadEvolveConfig(n,r,p,i),a=o.map((e=>new RegExp(`^${e}$`))),m=filterActivedEntriesByModule(l.entryMap,a),d=normalizeEvolveEntryMap(m,l.entryMap),f=splitToEntryGroup(d,l,ignoreEntryOptionKeys,!1);return prepareBuild(f[0],l).then((e=>(isCI()||loggerSimpleStdWriteSteam.postMessage(s),e)))};
@@ -1 +1 @@
1
- import Listr from"listr";import{chalk,logger,requireResolve}from"@flatjs/common";import{createGlobalCompiler}from"../compiler/create-global-compiler.js";import{ignoreEntryOptionKeys}from"../constants.js";import{CustomListrRenderer}from"../helpers/custom-listr-renderer.js";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{formatSpinnerText}from"../helpers/format-spinner-text.js";import{getMaxProcessTasks}from"../helpers/get-max-process-tasks.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{createThreadWorker}from"./create-thread-worker.js";import{envVerify}from"./env-verify.js";export const startBuild=async(r,e,t={},o)=>{const i={projectCwd:r,command:"build",resolve:requireResolve},s=await loadEvolveConfig(i,r,t,o);await envVerify(r,s);const a=filterActivedEntriesByModule(s.entryMap,e),n=normalizeEvolveEntryMap(a,s.entryMap),l=splitToEntryGroup(n,s,ignoreEntryOptionKeys,!1);if(!l.length)return logger.warn("No build entries provided!"),[];await createGlobalCompiler(!1,s);const{threads:m={}}=s,p=getMaxProcessTasks(l.length,m?.maxThreads);logger.info(`Start standard build with (${chalk(["magenta"])(String(p))}) workers`);const c=createThreadWorker({...m,maxThreads:p}),d=new Listr([],{concurrent:p,exitOnError:!0,renderer:CustomListrRenderer}),f=[];for(const e of l){const i=Object.values(e)?.[0]?.groupName||"",s=Object.keys(e);d.add({title:`Group ${chalk(["magenta"])(i)} $STATUS \n${formatSpinnerText(s)}`,task:async()=>{const e=await c.startBuildWorker({projectCwd:r,entryKeys:s,serializedEvolveOptions:jsonSerializer.stringify(t),configLoaderOptions:o});f.push(e)}})}if(d.tasks.length)try{await d.run()}catch(r){throw c.terminate(),r}return c.terminate(),f};
1
+ import Listr from"listr";import{chalk,logger,requireResolve}from"@flatjs/common";import{createGlobalCompiler}from"../compiler/create-global-compiler.js";import{ignoreEntryOptionKeys}from"../constants.js";import{isCI}from"../helpers/check-runtime-env.js";import{CustomListrRenderer}from"../helpers/custom-listr-renderer.js";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{formatSpinnerText}from"../helpers/format-spinner-text.js";import{getMaxProcessTasks}from"../helpers/get-max-process-tasks.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{createThreadWorker}from"./create-thread-worker.js";import{envVerify}from"./env-verify.js";export const startBuild=async(r,e,t={},o)=>{const i={projectCwd:r,command:"build",resolve:requireResolve},s=await loadEvolveConfig(i,r,t,o);await envVerify(r,s);const n=filterActivedEntriesByModule(s.entryMap,e),a=normalizeEvolveEntryMap(n,s.entryMap),l=splitToEntryGroup(a,s,ignoreEntryOptionKeys,!1);if(!l.length)return logger.warn("No build entries provided!"),[];await createGlobalCompiler(!1,s);const{threads:m={}}=s,p=getMaxProcessTasks(l.length,m?.maxThreads);logger.info(`Start standard build with (${chalk(["magenta"])(String(p))}) workers`);const c=createThreadWorker({...m,maxThreads:p}),f=new Listr([],{concurrent:p,exitOnError:!0,renderer:isCI()?void 0:CustomListrRenderer}),d=[];for(const e of l){const i=Object.values(e)?.[0]?.groupName||"",s=Object.keys(e);let n=`Group ${chalk(["magenta"])(i)} $STATUS \n${formatSpinnerText(s)}`;isCI()&&(n=`Group ${chalk(["magenta"])(i)} compiling... \n${formatSpinnerText(s)}`),f.add({title:n,task:async()=>{const e=await c.startBuildWorker({projectCwd:r,entryKeys:s,serializedEvolveOptions:jsonSerializer.stringify(t),configLoaderOptions:o});d.push(e)}})}if(f.tasks.length)try{await f.run()}catch(r){throw c.terminate(),r}return c.terminate(),d};
@@ -1 +1 @@
1
- import{logger}from"@flatjs/common";import{moduleName}from"../constants.js";import{printInfo}from"../helpers/print-log.js";import{imageMinimizer}from"./image-minimizer.js";import{terserMinimizer}from"./terser-minimizer.js";export const createMinimizers=(i,r)=>{const e=[];if(i)return logger.debug("Ignore minimizer plugin for `serve` mode",moduleName),e;if(!1===r?.minimizer)return printInfo("Note `minimizer` has been disabled for now"),e;if(r?.minimizer?.imageMin){const i=imageMinimizer();i&&e.push(i)}const m=terserMinimizer(r?.minimizer?.terserOptions||{});return e.push(m),e};
1
+ import{logger}from"@flatjs/common";import{moduleName}from"../constants.js";import{printInfo}from"../helpers/print-log.js";import{imageMinimizer}from"./image-minimizer.js";import{terserMinimizer}from"./terser-minimizer.js";export const createMinimizers=(i,r)=>{const e=[];if(i)return logger.debug("Ignore minimizer plugin for `serve` mode",moduleName),e;if(!1===r?.minimizer)return printInfo("Note `minimizer` has been disabled for now"),e;if(r?.minimizer?.imageMin){const i=imageMinimizer();i&&e.push(i)}if(!1===r?.minimizer?.terserOptions)return e;const m=terserMinimizer(r?.minimizer?.terserOptions||{});return e.push(m),e};
@@ -97,6 +97,10 @@ export type EvolveEntryMapContent = {
97
97
  * @default 'auto'
98
98
  */
99
99
  groupingSource?: 'auto' | 'manual';
100
+ /**
101
+ * The base path of the entry module
102
+ */
103
+ entryModuleBase?: string[];
100
104
  };
101
105
  export interface EvolveEntryMap {
102
106
  /**
@@ -62,7 +62,10 @@ export interface FlatEvolveWebpackOptions extends Pick<Configuration, 'performan
62
62
  * @default `terser` minimizer has been enabled fro `production`
63
63
  */
64
64
  minimizer?: false | {
65
- terserOptions?: TerserMinimizerOptions;
65
+ /**
66
+ * Allow to disable terser minimizer. or customized terser options.
67
+ */
68
+ terserOptions?: false | TerserMinimizerOptions;
66
69
  /**
67
70
  * @default false
68
71
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatjs/evolve",
3
- "version": "2.1.0-next.23",
3
+ "version": "2.1.0-next.25",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -44,13 +44,14 @@
44
44
  "@flatjs/common": "2.1.0-next.8",
45
45
  "@flatjs/evolve-preset-babel": "2.1.0-next.8",
46
46
  "@flatjs/forge-postcss-plugin-pixel": "2.1.0-next.8",
47
- "@flatjs/graph": "2.1.0-next.10",
48
- "@flatjs/mock": "2.1.0-next.11",
47
+ "@flatjs/graph": "2.1.0-next.11",
48
+ "@flatjs/mock": "2.1.0-next.12",
49
49
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
50
50
  "@types/babel__core": "^7.20.5",
51
51
  "babel-loader": "^9.1.3",
52
52
  "better-opn": "^3.0.2",
53
53
  "case-sensitive-paths-webpack-plugin": "^2.4.0",
54
+ "ci-info": "^4.0.0",
54
55
  "css-loader": "^7.1.2",
55
56
  "cssnano": "^7.0.3",
56
57
  "express": "^4.19.2",
@@ -84,7 +85,7 @@
84
85
  "@dimjs/model": "1.2.3",
85
86
  "@dimjs/model-react": "1.2.3",
86
87
  "@dimjs/utils": "1.5.1",
87
- "@flatjs/testing": "2.1.0-next.8",
88
+ "@flatjs/testing": "2.1.0-next.9",
88
89
  "@hyperse/eslint-config-hyperse": "^1.0.10",
89
90
  "@swc/core": "1.6.6",
90
91
  "@types/express": "4.17.21",