@flatjs/evolve 2.1.1 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/main/start-build-dynamic.js +1 -1
- package/dist/plugins/multi-html/multi-html-cdn-plugin.js +1 -1
- package/dist/plugins/multi-html/multi-html-modify-plugin.d.ts +12 -0
- package/dist/plugins/multi-html/multi-html-modify-plugin.js +1 -0
- package/dist/plugins/multi-html/multi-html-plugin.js +1 -1
- package/package.json +29 -29
@@ -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{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
|
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}" ...`)}logger.info(`diffCommits: \n${JSON.stringify({earlyCommit:r,lastCommit:t},null,2)}`,moduleName);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 m=await resolveEntryMapInputFiles(e,s.entryMap),p=await getBuildEntryFiles(e,a,m,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:m={}}=s,p=getMaxProcessTasks(l.length,m?.maxThreads);logger.info(`Start dynamic 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 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 c.startBuildWorker({projectCwd:e,entryKeys:n,serializedEvolveOptions:jsonSerializer.stringify(o),configLoaderOptions:i,groupName:t});d.push(r)}})}if(f.tasks.length)try{await f.run()}catch(e){throw c.terminate(),e}return c.terminate(),d};
|
@@ -1 +1 @@
|
|
1
|
-
import HtmlWebpackPlugin from"html-webpack-plugin";import{basename}from"node:path";import webpack from"webpack";import{getRuntimeCDNBase}from"../../helpers/get-runtime-cdn-base.js";import{findEnvCdn,httpUrlJoin}from"../../helpers/script-injects.js";export class FlatEvolveMultiCdnPlugin{constructor(e){if(this.pluginName="FlatEvolveMultiCdnPlugin",this.requireFn=webpack.RuntimeGlobals.publicPath,this.config=e.multiHtmlCdn,this.cdnResolver=e.multiHtmlCdnEnvResolver||function cdnResolver(){},!this.config?.prod)throw new Error("We must setup `prod` for each CDN config node!")}apply(e){e.hooks.thisCompilation.tap(this.pluginName,(e=>{e.mainTemplate.hooks.requireExtensions.tap(this.pluginName,((t,n)=>{const
|
1
|
+
import HtmlWebpackPlugin from"html-webpack-plugin";import{basename}from"node:path";import webpack from"webpack";import{ensureSlash}from"@flatjs/common";import{getRuntimeCDNBase}from"../../helpers/get-runtime-cdn-base.js";import{findEnvCdn,httpUrlJoin}from"../../helpers/script-injects.js";export class FlatEvolveMultiCdnPlugin{constructor(e){if(this.pluginName="FlatEvolveMultiCdnPlugin",this.requireFn=webpack.RuntimeGlobals.publicPath,this.config=e.multiHtmlCdn,this.cdnResolver=e.multiHtmlCdnEnvResolver||function cdnResolver(){},!this.config?.prod)throw new Error("We must setup `prod` for each CDN config node!")}apply(e){e.hooks.thisCompilation.tap(this.pluginName,(e=>{e.mainTemplate.hooks.requireExtensions.tap(this.pluginName,((t,n)=>{const s=[];s.push("// Dynamic assets path override(`@flatjs/evolve`) plugin-multi-html-cdn`)");const i=e.chunkGraph?.getTreeRuntimeRequirements(n);return i&&i.has(webpack.RuntimeGlobals.requireScope)&&s.push(webpack.Template.indent(getRuntimeCDNBase(this.config,this.cdnResolver,this.requireFn))),webpack.Template.asString(s)}))})),e.hooks.compilation.tap(this.pluginName,(e=>{HtmlWebpackPlugin.getHooks(e).beforeAssetTagGeneration.tap(this.pluginName,(e=>{const{assets:t,plugin:n,outputName:s}=e,i=n?.options?.chunks||[],r=Array.isArray(i)?i.find((e=>s.includes(ensureSlash(e,!0)))):i,{userOptions:o}=e.plugin;if(!r)throw new Error("We must have current chunk!");const a=t.js.filter((e=>e.includes(ensureSlash(r,!0)))),l=t.css.filter((e=>e.includes(ensureSlash(r,!0)))),p=o.multiCdn,u=t.publicPath,m=a.map((e=>{if(p.disabled)return basename(e);const t=findEnvCdn(this.config,p.env);return httpUrlJoin(t,e.replace(u,""))})),c=l.map((e=>{if(p.disabled)return basename(e);const t=findEnvCdn(this.config,p.env);return httpUrlJoin(t,e.replace(u,""))}));return e.assets.js=m,e.assets.css=c,e}))}))}}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Compiler } from 'webpack';
|
2
|
+
import { EntryMapItem } from '../../types/types-entry-map.js';
|
3
|
+
/**
|
4
|
+
* The MultiHtmlModifyPlugin class is responsible for modifying the HTML output of the webpack compiler.
|
5
|
+
* It hooks into the compilation process and replaces occurrences of "<%= title %>" with the title specified in the options.
|
6
|
+
*/
|
7
|
+
export declare class MultiHtmlModifyPlugin {
|
8
|
+
private pluginName;
|
9
|
+
private entryMapItemList;
|
10
|
+
constructor(list: EntryMapItem[]);
|
11
|
+
apply(compiler: Compiler): void;
|
12
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
import HtmlWebpackPlugin from"html-webpack-plugin";import{ensureSlash}from"@flatjs/common";const getCurrentEntryOptions=(t=[],i)=>{const e=t.find((t=>i.includes(ensureSlash(t[0],!0))));return e?e[1]?.options:void 0};export class MultiHtmlModifyPlugin{constructor(t){this.pluginName="MultiHtmlModifyPlugin",this.entryMapItemList=t}apply(t){t.hooks.compilation.tap(this.pluginName,(t=>{HtmlWebpackPlugin.getHooks(t).beforeEmit.tapAsync(this.pluginName,((t,i)=>{const e=getCurrentEntryOptions(this.entryMapItemList,t.outputName);/<%= title %>/.test(t.html)&&(t.html=t.html.replace(/<%= title %>/g,e?.title||"")),i(null,t)}))}))}}
|
@@ -1 +1 @@
|
|
1
|
-
import HtmlWebpackPlugin from"html-webpack-plugin";import{existsSync}from"node:fs";import{logger}from"@flatjs/common";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";import{normalizeTemplateInjectTokens}from"../../helpers/normalize-template-inject-tokens.js";import{findEnvCdn}from"../../helpers/script-injects.js";const minifyOpts={minifyJS:!0,removeComments:!0,collapseWhitespace:!0,collapseBooleanAttributes:!1};export const createMultiHtmlWebpackPlugin=(e,t,l,i)=>{const n=l[0],[,o]=n,m=[],{options:r}=o,p=e?"development":"production",s=l.map((e=>e[0]));for(const e of i){const l={mode:p,envCdn:findEnvCdn(t.multiHtmlCdn,e)},i=normalizeTemplateInjectTokens(l,r);let o=getHtmlPluginConfig("templatePath",l,r?.templatePath).replace("{0}",e.trim());existsSync(o)||(logger.warn(`The template file ${o} is not exists, use \`prod\` instead!`),o=getHtmlPluginConfig("templatePath",l,r?.templatePath).replace("{0}","prod")),m.push(new HtmlWebpackPlugin({inject:"body",title:getHtmlPluginConfig("title",l,r?.title),chunks:s,minify:!1!==r?.htmlMinify&&!["me","dev"].includes(e)&&minifyOpts,filename:t=>`${t}/index${"prod"===e?"":`-${e}`}.html`,template:o,templateParameters:{title:
|
1
|
+
import HtmlWebpackPlugin from"html-webpack-plugin";import{existsSync}from"node:fs";import{logger}from"@flatjs/common";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";import{normalizeTemplateInjectTokens}from"../../helpers/normalize-template-inject-tokens.js";import{findEnvCdn}from"../../helpers/script-injects.js";import{MultiHtmlModifyPlugin}from"./multi-html-modify-plugin.js";const minifyOpts={minifyJS:!0,removeComments:!0,collapseWhitespace:!0,collapseBooleanAttributes:!1};export const createMultiHtmlWebpackPlugin=(e,t,l,i)=>{const n=l[0],[,o]=n,m=[new MultiHtmlModifyPlugin(l)],{options:r}=o,p=e?"development":"production",s=l.map((e=>e[0]));for(const e of i){const l={mode:p,envCdn:findEnvCdn(t.multiHtmlCdn,e)},i=normalizeTemplateInjectTokens(l,r);let o=getHtmlPluginConfig("templatePath",l,r?.templatePath).replace("{0}",e.trim());existsSync(o)||(logger.warn(`The template file ${o} is not exists, use \`prod\` instead!`),o=getHtmlPluginConfig("templatePath",l,r?.templatePath).replace("{0}","prod")),m.push(new HtmlWebpackPlugin({inject:"body",title:getHtmlPluginConfig("title",l,r?.title),chunks:s,minify:!1!==r?.htmlMinify&&!["me","dev"].includes(e)&&minifyOpts,filename:t=>`${t}/index${"prod"===e?"":`-${e}`}.html`,template:o,templateParameters:{title:"<%= title %>",favicon:getHtmlPluginConfig("favicon",l,r?.favicon),viewport:allowPx2remForModule(n,t)?getHtmlPluginConfig("viewport",l,r?.viewport):"",...i},multiCdn:{env:e,disabled:(r?.excludeCdnEnvs||["me","dev","ntv"]).includes(e)}}))}return m};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@flatjs/evolve",
|
3
|
-
"version": "2.1.
|
3
|
+
"version": "2.1.3",
|
4
4
|
"license": "MIT",
|
5
5
|
"type": "module",
|
6
6
|
"exports": {
|
@@ -35,20 +35,20 @@
|
|
35
35
|
"typecheck": "tsc --project ./tsconfig.json --noEmit"
|
36
36
|
},
|
37
37
|
"dependencies": {
|
38
|
-
"@armit/babel-merge": "^0.2.
|
39
|
-
"@armit/config-loader": "^0.2.
|
40
|
-
"@armit/file-utility": "^0.2.
|
41
|
-
"@armit/git": "^0.2.
|
42
|
-
"@armit/package": "^0.2.
|
43
|
-
"@babel/core": "^7.
|
38
|
+
"@armit/babel-merge": "^0.2.5",
|
39
|
+
"@armit/config-loader": "^0.2.9",
|
40
|
+
"@armit/file-utility": "^0.2.5",
|
41
|
+
"@armit/git": "^0.2.5",
|
42
|
+
"@armit/package": "^0.2.9",
|
43
|
+
"@babel/core": "^7.25.2",
|
44
44
|
"@clack/prompts": "^0.7.0",
|
45
|
-
"@discoveryjs/json-ext": "0.6.
|
46
|
-
"@flatjs/babel-plugin-import": "2.1.
|
47
|
-
"@flatjs/common": "2.1.
|
48
|
-
"@flatjs/evolve-preset-babel": "2.1.
|
49
|
-
"@flatjs/forge-postcss-plugin-pixel": "2.1.
|
50
|
-
"@flatjs/graph": "2.1.
|
51
|
-
"@flatjs/mock": "2.1.
|
45
|
+
"@discoveryjs/json-ext": "0.6.1",
|
46
|
+
"@flatjs/babel-plugin-import": "2.1.3",
|
47
|
+
"@flatjs/common": "2.1.3",
|
48
|
+
"@flatjs/evolve-preset-babel": "2.1.3",
|
49
|
+
"@flatjs/forge-postcss-plugin-pixel": "2.1.3",
|
50
|
+
"@flatjs/graph": "2.1.3",
|
51
|
+
"@flatjs/mock": "2.1.3",
|
52
52
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
|
53
53
|
"@types/babel__core": "^7.20.5",
|
54
54
|
"babel-loader": "^9.1.3",
|
@@ -56,10 +56,10 @@
|
|
56
56
|
"case-sensitive-paths-webpack-plugin": "^2.4.0",
|
57
57
|
"ci-info": "^4.0.0",
|
58
58
|
"css-loader": "^7.1.2",
|
59
|
-
"cssnano": "^7.0.
|
59
|
+
"cssnano": "^7.0.6",
|
60
60
|
"express": "^4.19.2",
|
61
61
|
"fork-ts-checker-webpack-plugin": "^9.0.2",
|
62
|
-
"happy-dom": "^
|
62
|
+
"happy-dom": "^15.7.3",
|
63
63
|
"html-webpack-plugin": "^5.6.0",
|
64
64
|
"image-minimizer-webpack-plugin": "^4.1.0",
|
65
65
|
"less": "^4.2.0",
|
@@ -67,20 +67,20 @@
|
|
67
67
|
"listr": "^0.14.3",
|
68
68
|
"lodash": "^4.17.21",
|
69
69
|
"log-update": "^6.1.0",
|
70
|
-
"mini-css-extract-plugin": "^2.9.
|
71
|
-
"postcss": "^8.4.
|
70
|
+
"mini-css-extract-plugin": "^2.9.1",
|
71
|
+
"postcss": "^8.4.45",
|
72
72
|
"postcss-loader": "^8.1.1",
|
73
73
|
"react-refresh": "^0.14.2",
|
74
74
|
"svgo": "^3.3.2",
|
75
75
|
"tarjan-graph": "^3.0.0",
|
76
76
|
"terser-webpack-plugin": "^5.3.10",
|
77
|
-
"tinypool": "^1.0.
|
77
|
+
"tinypool": "^1.0.1",
|
78
78
|
"tsconfig-paths-webpack-plugin": "^4.1.0",
|
79
|
-
"type-fest": "^4.
|
79
|
+
"type-fest": "^4.26.0",
|
80
80
|
"typescript": "^5.5.4",
|
81
|
-
"webpack": "^5.
|
81
|
+
"webpack": "^5.94.0",
|
82
82
|
"webpack-bundle-analyzer": "^4.10.2",
|
83
|
-
"webpack-dev-server": "^5.0
|
83
|
+
"webpack-dev-server": "^5.1.0",
|
84
84
|
"webpack-sources": "^3.2.3"
|
85
85
|
},
|
86
86
|
"devDependencies": {
|
@@ -88,13 +88,13 @@
|
|
88
88
|
"@dimjs/model": "2.0.1",
|
89
89
|
"@dimjs/model-react": "2.0.1",
|
90
90
|
"@dimjs/utils": "2.0.1",
|
91
|
-
"@flatjs/testing": "2.1.
|
92
|
-
"@hyperse/eslint-config-hyperse": "^1.
|
93
|
-
"@swc/core": "1.7.
|
91
|
+
"@flatjs/testing": "2.1.3",
|
92
|
+
"@hyperse/eslint-config-hyperse": "^1.1.3",
|
93
|
+
"@swc/core": "1.7.23",
|
94
94
|
"@types/express": "4.17.21",
|
95
95
|
"@types/listr": "0.14.9",
|
96
|
-
"@types/node": "
|
97
|
-
"eslint": "^9.
|
96
|
+
"@types/node": "22.5.4",
|
97
|
+
"eslint": "^9.9.1",
|
98
98
|
"imagemin-gifsicle": "7.0.0",
|
99
99
|
"imagemin-jpegtran": "7.0.0",
|
100
100
|
"imagemin-pngquant": "10.0.0",
|
@@ -102,8 +102,8 @@
|
|
102
102
|
"npm-run-all": "4.1.5",
|
103
103
|
"react": "18.3.1",
|
104
104
|
"rimraf": "6.0.1",
|
105
|
-
"vite-tsconfig-paths": "
|
106
|
-
"vitest": "2.0.
|
105
|
+
"vite-tsconfig-paths": "5.0.1",
|
106
|
+
"vitest": "2.0.5",
|
107
107
|
"vue-loader": "17.4.2"
|
108
108
|
},
|
109
109
|
"peerDependencies": {
|