@flatjs/evolve 2.1.0-next.16 → 2.1.0-next.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- import webpack from"webpack";import{createResolve}from"../create-webpack/create-resolve.js";import{ruleBabel}from"../create-webpack/rule-sets/rule-scripts.js";import{createTsCheckerPlugins}from"../plugins/ts-checker/ts-checker-plugin.js";export const createGlobalCompiler=(e,r)=>{const{projectCwd:t,webpack:c,devServer:o}=r,s=e?"development":"production",l=o?.watchOptions||{},a=[ruleBabel({})],p=[...createTsCheckerPlugins(e,r)],i={context:t,mode:s,watch:e,name:"flat/evolve/global-compiler",entry:["."],resolve:createResolve(t,c),module:{rules:a},plugins:p,watchOptions:l};return new Promise(((e,r)=>{webpack(i,(t=>{if(t)return r(t.message);e(!0)}))}))};
1
+ import webpack from"webpack";import{getDirname}from"@armit/file-utility";import{createExternals}from"../create-webpack/create-externals.js";import{createResolve}from"../create-webpack/create-resolve.js";import{ruleBabel}from"../create-webpack/rule-sets/rule-scripts.js";import{createTsCheckerPlugins}from"../plugins/ts-checker/ts-checker-plugin.js";export const createGlobalCompiler=(e,r)=>{const{projectCwd:t,webpack:o,devServer:a}=r,c=e?"development":"production",l=a?.watchOptions||{},s=[ruleBabel({})],p=[...createTsCheckerPlugins(e,r)],m={context:t,mode:c,watch:e,name:"flat/evolve/global-compiler",entry:{"global-compiler-bundle":["."]},resolve:createResolve(t,o),module:{rules:s},plugins:p,watchOptions:l,devtool:!1,externals:createExternals(o?.externals),cache:{type:"memory"},performance:{},output:{environment:{},path:getDirname(import.meta.url,"./")}};return new Promise(((e,r)=>{webpack(m,(t=>{if(t)return r(t.message);e(!0)}))}))};
@@ -1,4 +1,4 @@
1
1
  import { type Configuration } from 'webpack';
2
2
  import { type EntryMapItem } from '../types/types-entry-map.js';
3
3
  import { type FlatEvolveWebpackOptions } from '../types/types-webpack.js';
4
- export declare const createExternals: (externals: FlatEvolveWebpackOptions['externals'], entryItem: EntryMapItem) => Configuration['externals'];
4
+ export declare const createExternals: (externals?: FlatEvolveWebpackOptions['externals'], entryItem?: EntryMapItem) => Configuration['externals'];
@@ -1 +1 @@
1
- import{mergeOptions}from"@flatjs/common";export const createExternals=(t={},e)=>{const o=e[1],r=o.options?.externals||{};return mergeOptions(t,r)};
1
+ import{mergeOptions}from"@flatjs/common";export const createExternals=(t={},e)=>{const o=e?.[1];return mergeOptions(t,o?.options?.externals||{})};
@@ -0,0 +1,37 @@
1
+ import { ListrTaskObject } from 'listr';
2
+ /**
3
+ * CustomListrRenderer is a class that provides a custom renderer for Listr tasks.
4
+ * It renders the tasks in a specific format and updates the output periodically.
5
+ *
6
+ * @template Ctx - The type of the context object used by the Listr tasks.
7
+ */
8
+ export declare class CustomListrRenderer<Ctx> {
9
+ private _tasks;
10
+ private _id;
11
+ /**
12
+ * Creates an instance of CustomListrRenderer.
13
+ *
14
+ * @param tasks - An array of Listr tasks to be rendered.
15
+ */
16
+ constructor(tasks: ReadonlyArray<ListrTaskObject<Ctx>>);
17
+ /**
18
+ * Indicates whether the renderer supports non-TTY environments.
19
+ */
20
+ static get nonTTY(): boolean;
21
+ /**
22
+ * Renders the Listr tasks.
23
+ * This method is called periodically to update the output.
24
+ */
25
+ render(): void;
26
+ /**
27
+ * Ends the rendering of the Listr tasks.
28
+ * This method clears the interval and updates the final output.
29
+ */
30
+ end(): void;
31
+ formatTextByTemp(title: string, status: 'successfully' | 'failed' | 'skipped' | 'building', temp?: string): string;
32
+ /**
33
+ * Renders an individual Listr task.
34
+ * This method is called by the render() and end() methods.
35
+ */
36
+ renderTask: () => void;
37
+ }
@@ -0,0 +1 @@
1
+ import logUpdate from"log-update";import process from"node:process";import{chalk}from"@flatjs/common";const startFrames="win32"===process.platform?["-","\\","|","/"]:["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];let startIndex=0;export class CustomListrRenderer{constructor(t){this._tasks=[],this.renderTask=()=>{const t=[];startIndex=++startIndex%startFrames.length;const e=startFrames[startIndex];for(const s of this._tasks)s.isCompleted()?t.push(`${chalk(["green"])("✔")} ${this.formatTextByTemp(s.title,"successfully")}`):s.hasFailed()?t.push(`${chalk(["red"])("✘")} ${this.formatTextByTemp(s.title,"failed")}`):s.isSkipped()?t.push(`${chalk(["gray"])("ℹ")} ${this.formatTextByTemp(s.title,"skipped")}`):t.push(`${chalk(["cyan"])(e)} ${this.formatTextByTemp(s.title,"building")}`);logUpdate(t.join("\n"))},this._tasks=t}static get nonTTY(){return!0}render(){this._id||(this._id=setInterval((()=>{this.renderTask()}),100))}end(){this._id&&(clearInterval(this._id),this._id=void 0),this.renderTask(),logUpdate.done()}formatTextByTemp(t,e,s="$STATUS"){const r={successfully:`builded ${chalk(["green"])("successfully")}`,failed:`builded ${chalk(["red"])("failed")}`,skipped:`builded ${chalk(["gray"])("skipped")}`,building:chalk(["white"])("building...")};return t.replace(s,r[e])}}
@@ -2,6 +2,7 @@ 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
4
  export * from './chunk-entry-map.js';
5
+ export * from './custom-listr-renderer.js';
5
6
  export * from './delete-object-keys.js';
6
7
  export * from './enable-bundle-hashname-for-module.js';
7
8
  export * from './flat-entry-map.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"./delete-object-keys.js";export*from"./enable-bundle-hashname-for-module.js";export*from"./flat-entry-map.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"./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"./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 +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{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{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 c=await resolveEntryMapInputFiles(e,s.entryMap),p=await getBuildEntryFiles(e,a,c,s.webpack?.resolve?.alias,s.ci?.graphTreeNodeFilter);logger.debug(`To build entry files: \n${JSON.stringify(p,null,2)}`);return{buildEntries:await filterActivedEntriesByEntryInputs(e,s.entryMap,p),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!"),[];const c=l.map((e=>Object.values(e)?.[0]?.groupName));await createGlobalCompiler(!1,s);const{threads:p={}}=s,d=getMaxProcessTasks(l.length,p?.maxThreads);logger.info(`Start dynamic build with (${chalk(["magenta"])(String(d))}) workers:\n${JSON.stringify({buildEntriesGroup:c},null,2)}`);const m=createThreadWorker({...p,maxThreads:d}),f=new Listr([],{concurrent:d,exitOnError:!0}),g=[];for(const r of l){const t=Object.values(r)?.[0]?.groupName||"",n=Object.keys(r);f.add({title:`Build group ${t}: ${chalk(["magenta"])(`${JSON.stringify(n,null,2)}`)} ...`,task:async()=>{const r=await m.startBuildWorker({projectCwd:e,entryKeys:n,serializedEvolveOptions:jsonSerializer.stringify(o),configLoaderOptions:i});g.push(r)}})}if(f.tasks.length)try{await f.run()}catch(e){throw m.terminate(),e}return m.terminate(),g};
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{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{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 c=await resolveEntryMapInputFiles(e,s.entryMap),p=await getBuildEntryFiles(e,a,c,s.webpack?.resolve?.alias,s.ci?.graphTreeNodeFilter);logger.debug(`To build entry files: \n${JSON.stringify(p,null,2)}`);return{buildEntries:await filterActivedEntriesByEntryInputs(e,s.entryMap,p),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:c={}}=s,p=getMaxProcessTasks(l.length,c?.maxThreads);logger.info(`Start dynamic build with (${chalk(["magenta"])(String(p))}) workers`);const m=createThreadWorker({...c,maxThreads:p}),d=new Listr([],{concurrent:p,exitOnError:!0}),f=[];for(const r of l){const t=Object.values(r)?.[0]?.groupName||"",n=Object.keys(r),s=n.map((e=>` ${chalk(["blue"])("→")} ${e} \n`));d.add({title:`Group ${chalk(["magenta"])(t)} $STATUS \n${s.join("")}`,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 +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{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.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!"),[];const p=l.map((r=>Object.values(r)?.[0]?.groupName));await createGlobalCompiler(!1,s);const{threads:m={}}=s,c=getMaxProcessTasks(l.length,m?.maxThreads);logger.info(`Start standard build with (${chalk(["magenta"])(String(c))}) workers:\n${JSON.stringify({buildEntriesGroup:p},null,2)}`);const d=createThreadWorker({...m,maxThreads:c}),f=new Listr([],{concurrent:c,exitOnError:!0}),g=[];for(const e of l){const i=Object.values(e)?.[0]?.groupName||"",s=Object.keys(e);f.add({title:`Build group ${i}: ${chalk(["magenta"])(`${JSON.stringify(s,null,2)}`)} ...`,task:async()=>{const e=await d.startBuildWorker({projectCwd:r,entryKeys:s,serializedEvolveOptions:jsonSerializer.stringify(t),configLoaderOptions:o});g.push(e)}})}if(f.tasks.length)try{await f.run()}catch(r){throw d.terminate(),r}return d.terminate(),g};
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{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),a=s.map((r=>` ${chalk(["blue"])("→")} ${r} \n`));d.add({title:`Group ${chalk(["magenta"])(i)} $STATUS \n${a.join("")}`,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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatjs/evolve",
3
- "version": "2.1.0-next.16",
3
+ "version": "2.1.0-next.17",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -62,6 +62,7 @@
62
62
  "less-loader": "^12.2.0",
63
63
  "listr": "^0.14.3",
64
64
  "lodash": "^4.17.21",
65
+ "log-update": "^6.0.0",
65
66
  "mini-css-extract-plugin": "^2.9.0",
66
67
  "postcss": "^8.4.38",
67
68
  "postcss-loader": "^8.1.1",