@flatjs/evolve 1.7.4 → 1.8.1-next.100
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +774 -0
- package/LICENSE +21 -0
- package/README.md +10 -46
- package/dist/constants.d.ts +15 -0
- package/dist/constants.js +1 -0
- package/dist/create-webpack/create-externals.d.ts +4 -0
- package/dist/create-webpack/create-externals.js +1 -0
- package/dist/create-webpack/create-optimization.d.ts +3 -0
- package/dist/create-webpack/create-optimization.js +1 -0
- package/dist/create-webpack/create-output.d.ts +3 -0
- package/dist/create-webpack/create-output.js +1 -0
- package/dist/create-webpack/create-performance.d.ts +2 -0
- package/dist/create-webpack/create-performance.js +1 -0
- package/dist/create-webpack/create-plugins.d.ts +4 -0
- package/dist/create-webpack/create-plugins.js +1 -0
- package/dist/create-webpack/create-resolve.d.ts +2 -0
- package/dist/create-webpack/create-resolve.js +1 -0
- package/dist/create-webpack/create-rule-sets.d.ts +4 -0
- package/dist/create-webpack/create-rule-sets.js +1 -0
- package/dist/create-webpack/load-webpack-config.d.ts +10 -0
- package/dist/create-webpack/load-webpack-config.js +1 -0
- package/dist/create-webpack/rule-sets/constants.d.ts +3 -0
- package/dist/create-webpack/rule-sets/constants.js +1 -0
- package/dist/create-webpack/rule-sets/rule-assets.d.ts +10 -0
- package/dist/create-webpack/rule-sets/rule-assets.js +1 -0
- package/dist/create-webpack/rule-sets/rule-css.d.ts +11 -0
- package/dist/create-webpack/rule-sets/rule-css.js +1 -0
- package/dist/create-webpack/rule-sets/rule-less.d.ts +26 -0
- package/dist/create-webpack/rule-sets/rule-less.js +1 -0
- package/dist/create-webpack/rule-sets/rule-scripts.d.ts +3 -0
- package/dist/create-webpack/rule-sets/rule-scripts.js +1 -0
- package/dist/create-webpack/rule-sets/rule-svg-icon.d.ts +6 -0
- package/dist/create-webpack/rule-sets/rule-svg-icon.js +1 -0
- package/dist/create-webpack/rule-sets/rule-utils.d.ts +7 -0
- package/dist/create-webpack/rule-sets/rule-utils.js +1 -0
- package/dist/create-webpack/types.d.ts +2 -0
- package/dist/create-webpack/types.js +1 -0
- package/dist/default-options.d.ts +2 -0
- package/dist/default-options.js +1 -0
- package/dist/define-config/define-config.d.ts +24 -0
- package/dist/define-config/define-config.js +1 -0
- package/dist/define-config/index.d.ts +1 -0
- package/dist/define-config/index.js +1 -0
- package/dist/dev-server/add-compiler-to-dev-server.d.ts +10 -0
- package/dist/dev-server/add-compiler-to-dev-server.js +1 -0
- package/dist/dev-server/create-app-page-route.d.ts +7 -0
- package/dist/dev-server/create-app-page-route.js +1 -0
- package/dist/dev-server/create-dev-server-compiler-tasks.d.ts +3 -0
- package/dist/dev-server/create-dev-server-compiler-tasks.js +1 -0
- package/dist/dev-server/create-dev-server-entries.d.ts +4 -0
- package/dist/dev-server/create-dev-server-entries.js +1 -0
- package/dist/dev-server/create-dev-server.d.ts +6 -0
- package/dist/dev-server/create-dev-server.js +1 -0
- package/dist/dev-server/index.d.ts +6 -0
- package/dist/dev-server/index.js +1 -0
- package/dist/dev-server/middlewares/create-page-middleware.d.ts +37 -0
- package/dist/dev-server/middlewares/create-page-middleware.js +1 -0
- package/dist/dev-server/middlewares/create-public-assets-middleware.d.ts +2 -0
- package/dist/dev-server/middlewares/create-public-assets-middleware.js +1 -0
- package/dist/dev-server/middlewares/index.d.ts +2 -0
- package/dist/dev-server/middlewares/index.js +1 -0
- package/dist/errors/evolve-build-error.d.ts +4 -0
- package/dist/errors/evolve-build-error.js +1 -0
- package/dist/helpers/allow-px2rem-for-module.d.ts +3 -0
- package/dist/helpers/allow-px2rem-for-module.js +1 -0
- package/dist/helpers/assert-only-single-entry-item.d.ts +7 -0
- package/dist/helpers/assert-only-single-entry-item.js +1 -0
- package/dist/helpers/chunk-entry-map.d.ts +7 -0
- package/dist/helpers/chunk-entry-map.js +1 -0
- package/dist/helpers/enable-bundle-hashname-for-module.d.ts +3 -0
- package/dist/helpers/enable-bundle-hashname-for-module.js +1 -0
- package/dist/helpers/filter-actived-entries.d.ts +16 -0
- package/dist/helpers/filter-actived-entries.js +1 -0
- package/dist/helpers/get-bundle-file-name.d.ts +14 -0
- package/dist/helpers/get-bundle-file-name.js +1 -0
- package/dist/helpers/get-git-root.d.ts +1 -0
- package/dist/helpers/get-git-root.js +1 -0
- package/dist/helpers/get-html-plugin-config.d.ts +20 -0
- package/dist/helpers/get-html-plugin-config.js +1 -0
- package/dist/helpers/get-max-process-tasks.d.ts +1 -0
- package/dist/helpers/get-max-process-tasks.js +1 -0
- package/dist/helpers/get-pacakge-dir.d.ts +1 -0
- package/dist/helpers/get-pacakge-dir.js +1 -0
- package/dist/helpers/index.d.ts +17 -0
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/json-serializer.d.ts +7 -0
- package/dist/helpers/json-serializer.js +1 -0
- package/dist/helpers/merge-babel-options.d.ts +4 -0
- package/dist/helpers/merge-babel-options.js +1 -0
- package/dist/helpers/normalize-entry-map.d.ts +15 -0
- package/dist/helpers/normalize-entry-map.js +1 -0
- package/dist/helpers/normalize-resolve-alias.d.ts +1 -0
- package/dist/helpers/normalize-resolve-alias.js +1 -0
- package/dist/helpers/open-page.d.ts +7 -0
- package/dist/helpers/open-page.js +1 -0
- package/dist/helpers/print-log.d.ts +8 -0
- package/dist/helpers/print-log.js +1 -0
- package/dist/helpers/refresh-evolve-mock-options.d.ts +3 -0
- package/dist/helpers/refresh-evolve-mock-options.js +1 -0
- package/dist/helpers/resolve-entry-map-input-files.d.ts +8 -0
- package/dist/helpers/resolve-entry-map-input-files.js +1 -0
- package/dist/helpers/script-injects.d.ts +11 -0
- package/dist/helpers/script-injects.js +1 -0
- package/dist/helpers/should-enable-react-fast-refresh.d.ts +3 -0
- package/dist/helpers/should-enable-react-fast-refresh.js +1 -0
- package/dist/helpers/split-to-multi-compiler.d.ts +8 -0
- package/dist/helpers/split-to-multi-compiler.js +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1 -0
- package/dist/load-config/index.d.ts +1 -0
- package/dist/load-config/index.js +1 -0
- package/dist/load-config/load-evolve-config.d.ts +11 -0
- package/dist/load-config/load-evolve-config.js +1 -0
- package/dist/loaders/loader-icon.cjs +33 -0
- package/dist/loaders/loader-icon.d.cts +1 -0
- package/dist/main/env-verify.d.ts +2 -0
- package/dist/main/env-verify.js +1 -0
- package/dist/main/get-worker-path.d.ts +1 -0
- package/dist/main/get-worker-path.js +1 -0
- package/dist/main/index.d.ts +4 -0
- package/dist/main/index.js +1 -0
- package/dist/main/prepare-build.d.ts +9 -0
- package/dist/main/prepare-build.js +1 -0
- package/dist/main/prepare-serve.d.ts +9 -0
- package/dist/main/prepare-serve.js +1 -0
- package/dist/main/prepare-static.d.ts +7 -0
- package/dist/main/prepare-static.js +1 -0
- package/dist/main/start-build-dynamic.d.ts +20 -0
- package/dist/main/start-build-dynamic.js +1 -0
- package/dist/main/start-build-worker.d.ts +12 -0
- package/dist/main/start-build-worker.js +1 -0
- package/dist/main/start-build.d.ts +5 -0
- package/dist/main/start-build.js +1 -0
- package/dist/main/start-one-entry-build.d.ts +13 -0
- package/dist/main/start-one-entry-build.js +1 -0
- package/dist/main/start-serve.d.ts +11 -0
- package/dist/main/start-serve.js +1 -0
- package/dist/main/start-static.d.ts +10 -0
- package/dist/main/start-static.js +1 -0
- package/dist/minimizer/create-minimizers.d.ts +3 -0
- package/dist/minimizer/create-minimizers.js +1 -0
- package/dist/minimizer/default-options.d.ts +2 -0
- package/dist/minimizer/default-options.js +1 -0
- package/dist/minimizer/image-minimizer.d.ts +16 -0
- package/dist/minimizer/image-minimizer.js +1 -0
- package/dist/minimizer/index.d.ts +1 -0
- package/dist/minimizer/index.js +1 -0
- package/dist/minimizer/terser-minimizer.d.ts +6 -0
- package/dist/minimizer/terser-minimizer.js +3 -0
- package/dist/minimizer/types.d.ts +2 -0
- package/dist/minimizer/types.js +1 -0
- package/dist/plugins/circular-dependency/circular-dependency-plugin.d.ts +54 -0
- package/dist/plugins/circular-dependency/circular-dependency-plugin.js +1 -0
- package/dist/plugins/circular-dependency/index.d.ts +7 -0
- package/dist/plugins/circular-dependency/index.js +1 -0
- package/dist/plugins/clean-webpack/clean-webpack-plugin.d.ts +67 -0
- package/dist/plugins/clean-webpack/clean-webpack-plugin.js +1 -0
- package/dist/plugins/clean-webpack/index.d.ts +9 -0
- package/dist/plugins/clean-webpack/index.js +1 -0
- package/dist/plugins/define-variable/define-variable-plugin.d.ts +14 -0
- package/dist/plugins/define-variable/define-variable-plugin.js +1 -0
- package/dist/plugins/define-variable/index.d.ts +1 -0
- package/dist/plugins/define-variable/index.js +1 -0
- package/dist/plugins/html-inject-scripts/plugin-html-inject-script.d.ts +8 -0
- package/dist/plugins/html-inject-scripts/plugin-html-inject-script.js +1 -0
- package/dist/plugins/module-federation/external-template-remotes.d.ts +4 -0
- package/dist/plugins/module-federation/external-template-remotes.js +1 -0
- package/dist/plugins/module-federation/index.d.ts +1 -0
- package/dist/plugins/module-federation/index.js +1 -0
- package/dist/plugins/module-federation/module-federation.d.ts +4 -0
- package/dist/plugins/module-federation/module-federation.js +1 -0
- package/dist/plugins/multi-html/index.d.ts +4 -0
- package/dist/plugins/multi-html/index.js +1 -0
- package/dist/plugins/multi-html/multi-html-cdn-plugin.d.ts +17 -0
- package/dist/plugins/multi-html/multi-html-cdn-plugin.js +1 -0
- package/dist/plugins/multi-html/multi-html-plugin.d.ts +11 -0
- package/dist/plugins/multi-html/multi-html-plugin.js +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.js +1 -0
- package/dist/types/types-ci.d.ts +23 -0
- package/dist/types/types-ci.js +1 -0
- package/dist/types/types-dev-server.d.ts +65 -0
- package/dist/types/types-dev-server.js +1 -0
- package/dist/types/types-entry-map.d.ts +71 -0
- package/dist/types/types-entry-map.js +1 -0
- package/dist/types/types-federation.d.ts +120 -0
- package/dist/types/types-federation.js +1 -0
- package/dist/types/types-loader-options.d.ts +76 -0
- package/dist/types/types-loader-options.js +1 -0
- package/dist/types/types-modular-import.d.ts +38 -0
- package/dist/types/types-modular-import.js +1 -0
- package/dist/types/types-multi-html.d.ts +75 -0
- package/dist/types/types-multi-html.js +1 -0
- package/dist/types/types-options.d.ts +117 -0
- package/dist/types/types-options.js +1 -0
- package/dist/types/types-plugin-options.d.ts +7 -0
- package/dist/types/types-plugin-options.js +1 -0
- package/dist/types/types-webpack.d.ts +96 -0
- package/dist/types/types-webpack.js +1 -0
- package/index.js +1 -4
- package/package.json +118 -61
- package/templates/html-plugin/index-dev.html +23 -46
- package/templates/html-plugin/index-inte.html +23 -46
- package/templates/html-plugin/index-inte2.html +23 -46
- package/templates/html-plugin/index-inte3.html +23 -46
- package/templates/html-plugin/index-inte4.html +23 -46
- package/templates/html-plugin/index-me.html +23 -46
- package/templates/html-plugin/index-prod.html +23 -46
- package/templates/html-plugin/index-rc.html +22 -46
- package/templates/html-plugin/index-uat.html +23 -46
- package/templates/main.html +2 -2
- package/templates/module-404.html +4 -2
- package/templates/module.html +31 -61
- package/cjs/index.js +0 -4
- package/cjs/loader-icon.js +0 -2
- package/index.d.ts +0 -721
@@ -0,0 +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()}`};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const getGitRoot: (searchFrom: string) => string | null;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{searchParentDir}from"@armit/package";export const getGitRoot=r=>searchParentDir(r,".git");
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { type MultiHtmlCDNEntryItem } from '../types/types-multi-html.js';
|
2
|
+
export declare const defaultHtmlPluginConfig: Required<MultiHtmlCDNEntryItem>;
|
3
|
+
type Json = undefined | null | boolean | number | string | Json[] | {
|
4
|
+
[prop: string]: Json;
|
5
|
+
};
|
6
|
+
export type HtmlPluginConfigConfigData = {
|
7
|
+
mode: 'development' | 'production';
|
8
|
+
/**
|
9
|
+
* The random `cdn` for config via `env` template
|
10
|
+
*/
|
11
|
+
envCdn: string;
|
12
|
+
};
|
13
|
+
export type HtmlPluginConfigTokenType<T extends Json> = T | ((configData: HtmlPluginConfigConfigData) => T);
|
14
|
+
/**
|
15
|
+
* 获取html plugin 模版相关定义字段.
|
16
|
+
* @param preferredValue 用户首选的值, 如果返回为undefined, 将使用默认值
|
17
|
+
* @returns
|
18
|
+
*/
|
19
|
+
export declare const getHtmlPluginConfig: <T extends Json>(key: keyof typeof defaultHtmlPluginConfig, configData: HtmlPluginConfigConfigData, preferredValue?: HtmlPluginConfigTokenType<T> | undefined) => T;
|
20
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{polyfill,viewportScripts}from"../constants.js";import{getPackageDir}from"./get-pacakge-dir.js";export const defaultHtmlPluginConfig={title:"",favicon:"",headBeforeHtmlTags:[],inlineScripts:[],headBeforeStyles:[],headBeforeScripts:[...polyfill],bodyAfterScripts:[],viewport:viewportScripts,excludeCdnEnvs:["me","dev","ntv"],htmlMinify:!0,templatePath:getPackageDir("templates/html-plugin/index-{0}.html")};export const getHtmlPluginConfig=(t,e,i)=>{let o;if(void 0!==i&&(o="function"==typeof i?i(e):i),void 0===o){const i=defaultHtmlPluginConfig[t];return"function"==typeof i?i(e):i}return o};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const getMaxProcessTasks: (totalTasks: number, maxProcesses?: string | number) => number;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{cpus}from"node:os";export const getMaxProcessTasks=(t,s)=>{const e=Math.max(1,"string"==typeof s&&s.endsWith("%")?Math.round(cpus().length*Number(s.slice(0,-1))/100):Number(s));return t>e?e:Math.max(1,t)};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const getPackageDir: (...paths: string[]) => string;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{join}from"node:path";import{getDirname}from"@armit/file-utility";import{searchPackageDir}from"@armit/package";export const getPackageDir=(...r)=>{const e=getDirname(import.meta.url),o=searchPackageDir({cwd:e});if(!o)throw new Error("Could not resolve package root for `flatjs/evolve`");return join(o,...r)};
|
@@ -0,0 +1,17 @@
|
|
1
|
+
export * from './allow-px2rem-for-module.js';
|
2
|
+
export * from './assert-only-single-entry-item.js';
|
3
|
+
export * from './chunk-entry-map.js';
|
4
|
+
export * from './enable-bundle-hashname-for-module.js';
|
5
|
+
export * from './get-bundle-file-name.js';
|
6
|
+
export * from './get-html-plugin-config.js';
|
7
|
+
export * from './get-pacakge-dir.js';
|
8
|
+
export * from './merge-babel-options.js';
|
9
|
+
export * from './normalize-entry-map.js';
|
10
|
+
export * from './open-page.js';
|
11
|
+
export * from './print-log.js';
|
12
|
+
export * from './refresh-evolve-mock-options.js';
|
13
|
+
export * from './script-injects.js';
|
14
|
+
export * from './should-enable-react-fast-refresh.js';
|
15
|
+
export * from './split-to-multi-compiler.js';
|
16
|
+
export * from './json-serializer.js';
|
17
|
+
export * from './normalize-resolve-alias.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export*from"./allow-px2rem-for-module.js";export*from"./assert-only-single-entry-item.js";export*from"./chunk-entry-map.js";export*from"./enable-bundle-hashname-for-module.js";export*from"./get-bundle-file-name.js";export*from"./get-html-plugin-config.js";export*from"./get-pacakge-dir.js";export*from"./merge-babel-options.js";export*from"./normalize-entry-map.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-multi-compiler.js";export*from"./json-serializer.js";export*from"./normalize-resolve-alias.js";
|
@@ -0,0 +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};
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { type TransformOptions } from '@babel/core';
|
2
|
+
import { type BuiltinBabelOptions } from '../types/types-loader-options.js';
|
3
|
+
import { type ModularImportOption } from '../types/types-modular-import.js';
|
4
|
+
export declare const mergeBabelOption: (modularImports?: ModularImportOption[], options?: BuiltinBabelOptions) => TransformOptions;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{logger,requireResolve}from"@flatjs/common";import{reactBabelPreset,vueBabelPreset}from"@flatjs/evolve-preset-babel";import babelMerge from"babel-merge";import{moduleName}from"../constants.js";export const mergeBabelOption=(e=[],r={usePreset:"react"})=>{const t=e.map((e=>[requireResolve(import.meta.url,"babel-plugin-import"),{transformToDefaultImport:!1,libraryDirectory:"dist",...e},e.libraryName])),{usePreset:a="react",...l}=r,o="react"===a?reactBabelPreset():"vue"===a?vueBabelPreset():reactBabelPreset();let s={};try{s=babelMerge(o,l),s.plugins?s.plugins.unshift(...t):s.plugins=t}catch(e){logger.error(e,moduleName)}return{...s,babelrc:!1,compact:!1}};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { type EvolveEntryMap } from '../types/types-entry-map.js';
|
2
|
+
/**
|
3
|
+
* Make sure that we have correct `virtualPath` for each webpack `entry`
|
4
|
+
* @param entryName the entryName defined via `flatjs-evolve.config.ts`.
|
5
|
+
* @param evolveOptions
|
6
|
+
* @returns
|
7
|
+
*/
|
8
|
+
export declare const normalizeEvolveEntryName: (entryName: string, projectVirtualPath: string) => string;
|
9
|
+
/**
|
10
|
+
* Normalize flatjs.evolve entry map definition data.
|
11
|
+
* Merge default entry item configuration values.
|
12
|
+
* @param activedEntryMap actived entries
|
13
|
+
* @param definedEntryMap defined entries in flatjs.evolve.js
|
14
|
+
*/
|
15
|
+
export declare const normalizeEvolveEntryMap: (activedEntryMap?: EvolveEntryMap, definedEntryMap?: EvolveEntryMap) => EvolveEntryMap;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{join}from"node:path";import _ from"lodash";export const normalizeEvolveEntryName=(o,e)=>{const r=o.replace(/^\//,""),t=e.replace(/^\//,"");return(r.startsWith(t)?r:join(t,r)).replace(/\/$/,"")};export const normalizeEvolveEntryMap=(o={},e={})=>{const r={};for(const[t,n]of Object.entries(e)){const e={options:{}};o[t]&&(r[t]=_.merge({},e,n,o[t])),_.merge(n,e)}return r};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const normalizeResolveAlias: (projectCwd: string, alias?: Record<string, string>) => Record<string, string>;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{resolve}from"node:path";export const normalizeResolveAlias=(e,o={})=>{for(const[r,t]of Object.entries(o))o[r]=resolve(e,t);return o};
|
@@ -0,0 +1 @@
|
|
1
|
+
import opn from"better-opn";export const openPage=n=>{try{opn(n)}catch(n){console.warn("Unable to open browser. If you are running in a headless environment\n")}};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
export declare const printInfo: (message: string, silent?: boolean) => void;
|
2
|
+
export declare const printError: (message: string | Error) => void;
|
3
|
+
/**
|
4
|
+
* Do not use `logger` to print webpack compiler error, cause of it may have it's message formatting.
|
5
|
+
* @param errors
|
6
|
+
* @returns
|
7
|
+
*/
|
8
|
+
export declare const printCompilerError: (errors: any) => string[];
|
@@ -0,0 +1 @@
|
|
1
|
+
import{logger}from"@flatjs/common";import{moduleName}from"../constants.js";export const printInfo=(r,o=!1)=>{o||logger.info(r,moduleName)};export const printError=r=>{logger.error(r,moduleName)};const formatCompilerError=(r,o=[])=>{if(!r)return o;if("string"==typeof r)o.push(r);else if(Array.isArray(r))for(const e of r)formatCompilerError(e,o);else if("object"==typeof r){const e=r.stack||r.message;delete r.stack,delete r.message;const t={...r,_newMsg:e};for(const[,r]of Object.entries(t))formatCompilerError(r,o)}return o};export const printCompilerError=r=>{const o=formatCompilerError(r,[]);for(const r of o)console.log(r);return o};
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
|
2
|
+
import { type FlatEvolveOptions } from '../types/types-options.js';
|
3
|
+
export declare const refreshEvolveMockOptions: (projectCwd: string, evolveOptions: FlatEvolveOptions, configLoaderOptions?: ConfigLoaderOptions) => Promise<FlatEvolveOptions>;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{loadMockConfig,getMockCwd}from"@flatjs/mock";import _ from"lodash";export const refreshEvolveMockOptions=async(o,t,s)=>{const e=t.devServer,n=s?.esmLoaderOptions,r=n?.externals||[],i=await loadMockConfig(o,e?.mockOptions||{},_.merge({},s,{configFile:"flatjs-mock",esmLoaderOptions:{externals:[...r,"@flatjs/mock"]}}));if(e){e.mockOptions=i||{},e.mockOptions&&!e.mockOptions.https&&(e.mockOptions.https=e?.https);const o=getMockCwd(i);Array.isArray(e?.watchOptions?.ignored)&&e?.watchOptions?.ignored.push(o)}return t};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { type EvolveEntryMap } from '../types/types-entry-map.js';
|
2
|
+
/**
|
3
|
+
* Transform all entry files via `entryMap`
|
4
|
+
* @param projectCwd The project root directory
|
5
|
+
* @param entryMap The evolve entryMap definition
|
6
|
+
* @returns The absolute entry input files.
|
7
|
+
*/
|
8
|
+
export declare const resolveEntryMapInputFiles: (projectCwd: string, entryMap: EvolveEntryMap) => Promise<string[]>;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{fileWalk}from"@armit/file-utility";import{arrayUnique}from"@flatjs/common";export const resolveEntryMapInputFiles=async(t,r)=>{const e=[];for(const[,t]of Object.entries(r)){const r=t.entry.map((t=>t.replace(/.(?:js|jsx|tsx|ts)$/,"")+".*"));e.push(...r)}const o=arrayUnique(e);return await fileWalk(o,{cwd:t,absolute:!0})};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { type EvolveMultiCdnEnvType, type EvolveMultiCDNConfig, type EvolveMultiCDNEnvResolver } from '../types/types-multi-html.js';
|
2
|
+
export declare function httpUrlJoin(first?: string, second?: string): string;
|
3
|
+
/**
|
4
|
+
* To extract the best matched CDN configuration url address, either use URL `query.env` or customize the `envRresolver`
|
5
|
+
* @param cdnConfig List of pre-configured cdn urls for each environment
|
6
|
+
* @param envResolver Get the specific environment variable by the currently requested host url address.
|
7
|
+
* @returns Returns the best matching address with a suffix (`/`)
|
8
|
+
*/
|
9
|
+
export declare function cdnFinder(cdnConfig: EvolveMultiCDNConfig, envResolver?: EvolveMultiCDNEnvResolver): string;
|
10
|
+
export declare function findEnvCdn(cdnConfig?: EvolveMultiCDNConfig, env?: EvolveMultiCdnEnvType): string;
|
11
|
+
export declare function injectFederationScripts(cdnConfig: EvolveMultiCDNConfig, cdnResolver?: EvolveMultiCDNEnvResolver): string;
|
@@ -0,0 +1 @@
|
|
1
|
+
export function httpUrlJoin(n="",e=""){return n.replace(/\/$/,"")+"/"+e.replace(/^\//,"")}export function cdnFinder(n,e){const r=window.location.href,o=/[?&]env(=([^&#]*)|&|#|$)/.exec(r);let t=o&&o[2]?decodeURIComponent(o[2].replace(/\+/g," ")):"prod";t=e&&e(r)||t;const c=n[t]||n.prod||[];return c[Math.floor(Math.random()*c.length)].replace(/\/$/,"")+"/"}export function findEnvCdn(n={},e="prod"){const r=n[e]||n.prod||[];return r[Math.floor(Math.random()*r.length)]}export function injectFederationScripts(n,e=function cdnResolver(){}){return`window.evolveFetchMicroWidgets = function () {\n var cdnConfig = ${JSON.stringify(n)};\n var cdnResolver = ${e.toString()};\n var cdnFinder = ${cdnFinder.toString()};\n return (cdnFinder(cdnConfig, cdnResolver) || '').replace(/\\/$/, '');\n }\n `}
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { type EntryMapItem } from '../types/types-entry-map.js';
|
2
|
+
import { type FlatEvolveOptions } from '../types/types-options.js';
|
3
|
+
export declare const shouldEnableReactFastRefresh: (serveMode: boolean, entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => boolean;
|
@@ -0,0 +1 @@
|
|
1
|
+
export const shouldEnableReactFastRefresh=(e,o,t)=>{const r=o[1],s=!!r.options?.moduleFederation;return e&&"react"===t.loaderOptions.babelOptions?.usePreset&&!s&&!0!==t.devServer?.liveReload};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { type Configuration } from 'webpack';
|
2
|
+
import { type EvolveEntryMap } from '../types/types-entry-map.js';
|
3
|
+
import { type FlatEvolveOptions } from '../types/types-options.js';
|
4
|
+
/**
|
5
|
+
* Split the `webpack` to make sure that we have separated compiler process for each module
|
6
|
+
* @param webpackConfig `Omit<Configuration, 'entry'>` webpack final configuration
|
7
|
+
*/
|
8
|
+
export declare function splitToMultiCompilerConfigs(servedEntries: EvolveEntryMap, webpackConfig: Omit<Configuration, 'entry'>, evolveOptions: FlatEvolveOptions): Configuration[];
|
@@ -0,0 +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})))}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export*from"./define-config/index.js";export*from"./load-config/index.js";export*from"./main/index.js";export*from"./types/types-options.js";export*from"./types/types-entry-map.js";
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './load-evolve-config.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export*from"./load-evolve-config.js";
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { type PartialDeep } from 'type-fest';
|
2
|
+
import { type EvolveConfigBase } from '../define-config/define-config.js';
|
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
|
+
};
|
11
|
+
export declare const loadEvolveConfig: (configEnv: EvolveConfigBase, projectCwd: string, overrideOptions?: PartialDeep<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions) => Promise<FlatEvolveOptions>;
|
@@ -0,0 +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};
|
@@ -0,0 +1,33 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const svgo_1 = require("svgo");
|
4
|
+
const VIEWBOX_REGEX = /viewBox="([^"]*)"/;
|
5
|
+
const SVG_REGEX = /<svg[^>]*>|<\/svg>/g;
|
6
|
+
const FILL_REGEX = /fill="[^"]*"/g;
|
7
|
+
const svgOptimize = (buffer, svgoOption) => {
|
8
|
+
const { data } = (0, svgo_1.optimize)(buffer, svgoOption);
|
9
|
+
return data;
|
10
|
+
};
|
11
|
+
const iconLoader = function iconLoader(source) {
|
12
|
+
this.cacheable && this.cacheable(true);
|
13
|
+
const options = this.getOptions();
|
14
|
+
const callback = this.async();
|
15
|
+
try {
|
16
|
+
const optimizedSource = svgOptimize(source, options.svgo);
|
17
|
+
const finalSource = optimizedSource.replace(FILL_REGEX, (fill) => {
|
18
|
+
return fill.includes('#FFF') ? 'fill="currentColor"' : '';
|
19
|
+
});
|
20
|
+
// Issue with ESLint recognizing this as needing an object destructure
|
21
|
+
const viewBoxMatch = VIEWBOX_REGEX.exec(finalSource);
|
22
|
+
const viewBox = viewBoxMatch ? viewBoxMatch[1] : '';
|
23
|
+
const svgExport = JSON.stringify({
|
24
|
+
viewBox,
|
25
|
+
body: finalSource.replace(SVG_REGEX, ''),
|
26
|
+
});
|
27
|
+
callback(null, `module.exports.default = module.exports = ${svgExport}`);
|
28
|
+
}
|
29
|
+
catch (err) {
|
30
|
+
callback(err);
|
31
|
+
}
|
32
|
+
};
|
33
|
+
module.exports = iconLoader;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{illegalPackageChecker,keepPackageDepsUpToDateForNonMonoRepo}from"@armit/package";export const envVerify=async(e,a)=>{const{packageInstallChecker:o,needVerifyPackages:r}=a;!1!==o&&o?.enabled&&await illegalPackageChecker({cwd:e,modules:o?.detectModules,throwError:o?.throwError,showAllInstalledGraph:o?.showAllInstalledGraph}),!1!==r&&await keepPackageDepsUpToDateForNonMonoRepo({cwd:e,autoUpgrade:!0,needVerifyPackages:r||{}})};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const getWorkerPath: () => string;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{pathToFileURL}from"node:url";import{getDirname}from"@armit/file-utility";export const getWorkerPath=()=>pathToFileURL(getDirname(import.meta.url,"./start-build-worker.js")).toString();
|
@@ -0,0 +1 @@
|
|
1
|
+
export*from"./start-build.js";export*from"./start-serve.js";export*from"./start-static.js";export*from"./start-build-dynamic.js";
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { type EntryMapItem } from '../types/types-entry-map.js';
|
2
|
+
import { type FlatEvolveOptions } from '../types/types-options.js';
|
3
|
+
import { type EvolveBuildResult } from './start-one-entry-build.js';
|
4
|
+
/**
|
5
|
+
* The main entry to start an evolve `build`
|
6
|
+
* @param entryMapItem The `entryMapItem` for one entry build task
|
7
|
+
* @param evolveOptions FlatEvolveOptions
|
8
|
+
*/
|
9
|
+
export declare const prepareBuild: (entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => Promise<EvolveBuildResult>;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{ensureSlash,mergeOptions}from"@flatjs/common";import{EvolveBuildError}from"../errors/evolve-build-error.js";import{printCompilerError}from"../helpers/print-log.js";import{startOneEntryBuild}from"./start-one-entry-build.js";export const prepareBuild=async(r,o)=>{const[t,e]=r,n=o.multiHtmlCdn?.prod||[];if(!n.length)throw new Error(`No CDN config for env:"prod", moduleName: ${t}`);const i=ensureSlash(n[Math.floor(Math.random()*n.length)],!0),l={[t]:e};try{const r=e.options?.useRelativeAssetPath,t=mergeOptions(o,{webpack:{publicPath:r?"auto":i}});return await startOneEntryBuild(l,t)}catch(r){const o=printCompilerError(r);throw new EvolveBuildError("BUILD_ERROR",o)}};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { type EvolveEntryMap } from '../types/types-entry-map.js';
|
2
|
+
import { type FlatEvolveOptions } from '../types/types-options.js';
|
3
|
+
/**
|
4
|
+
* The main entry to start evolve serve
|
5
|
+
* @param projectCwd The Root directory (workspace) of this project.
|
6
|
+
* @param servedEntries All normalized webpack entries we have served.
|
7
|
+
* @param evolveOptions FlatEvolveOptions
|
8
|
+
*/
|
9
|
+
export declare const prepareServe: (projectCwd: string, servedEntries: EvolveEntryMap, evolveOptions: FlatEvolveOptions) => Promise<import("express-serve-static-core").Express>;
|
@@ -0,0 +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))};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { type FlatEvolveOptions } from '../types/index.js';
|
2
|
+
/**
|
3
|
+
* The main entry to start evolve serve
|
4
|
+
* @param projectCwd The Root directory (workspace) of this project.
|
5
|
+
* @param evolveOptions FlatEvolveOptions
|
6
|
+
*/
|
7
|
+
export declare const prepareStatic: (projectCwd: string, evolveOptions: FlatEvolveOptions) => Promise<void>;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{chalk,logger,urlJoin}from"@flatjs/common";import{attachMockMiddlewares}from"@flatjs/mock";import{createAppPageRoute}from"../dev-server/create-app-page-route.js";import{createDevServer}from"../dev-server/create-dev-server.js";import{openPage}from"../helpers/open-page.js";export const prepareStatic=async(e,r)=>{const{app:a,devHostUri:o}=await createDevServer(r);await attachMockMiddlewares(a,{...r.devServer?.mockOptions,projectCwd:e}),createAppPageRoute(e,a,o,{},r);const t=urlJoin(o,["/pages"]);r.devServer?.autoOpen&&openPage(t),logger.info(`${"static page".padEnd(12," ")} ➩ ${chalk(["cyan"])(t)}`)};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { type PartialDeep } from 'type-fest';
|
2
|
+
import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
|
3
|
+
import { type FlatEvolveOptions } from '../types/types-options.js';
|
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[]>;
|
6
|
+
/**
|
7
|
+
* Dynamic check which entry modules need to build.
|
8
|
+
* @returns
|
9
|
+
*/
|
10
|
+
export declare function dynamicCheckBuildEntryMap(projectCwd: string, earlyCommit?: string | null, lastCommit?: string, overrideEvolveOptions?: PartialDeep<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions): Promise<{
|
11
|
+
buildEntries: import("../index.js").EvolveEntryMap;
|
12
|
+
newEvolveOptions: FlatEvolveOptions;
|
13
|
+
}>;
|
14
|
+
/**
|
15
|
+
* The main entry to start an evolve `build` with automatically detect modules which have been changed between two commits.
|
16
|
+
* @param projectCwd The Root directory (workspace) of this project.
|
17
|
+
* @param earlyCommit The diff based earlier commit hash
|
18
|
+
* @param lastCommit If is omitted, it will have the same effect as using HEAD instead.
|
19
|
+
*/
|
20
|
+
export declare const startDynamicBuild: (projectCwd: string, earlyCommit?: string, lastCommit?: string, overrideEvolveOptions?: PartialDeep<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions) => Promise<EvolveBuildResult[]>;
|
@@ -0,0 +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};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
|
2
|
+
import { type EvolveBuildResult } from './start-one-entry-build.js';
|
3
|
+
/**
|
4
|
+
* FIXME: The main entry to start an evolve `build`, NOTE: avoid pass configuration with `function` here.
|
5
|
+
* If you need to call build api avoid `worker` you can directly call `prepareBuild`
|
6
|
+
* @internal
|
7
|
+
* @param projectCwd The Root directory (workspace) of this project.
|
8
|
+
* @param entryKey The `entryKey` for one entry build task
|
9
|
+
* @param serializedEvolveOptions The overrided evolve options, NOTE: we will serialize `function` property here first
|
10
|
+
* @param configLoaderOptions Evolve config loader options, NOTE: avoid pass configuration with `function` here.
|
11
|
+
*/
|
12
|
+
export declare const startBuildWorker: (projectCwd: string, entryKey: string, serializedEvolveOptions: string, configLoaderOptions?: ConfigLoaderOptions) => Promise<EvolveBuildResult>;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{requireResolve}from"@flatjs/common";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareBuild}from"./prepare-build.js";export const startBuildWorker=async(e,r,o,i)=>{const l={command:"build",resolve:requireResolve},t=jsonSerializer.parse(o)||{},n=await loadEvolveConfig(l,e,t,i),a=filterActivedEntriesByModule(n.entryMap,[new RegExp(`^${r}$`)]);if(!Object.keys(a).length)throw new Error(`No build entry resolved via "${r}" on "startBuildWorker"!`);const s=normalizeEvolveEntryMap(a,n.entryMap)[r];return prepareBuild([r,s],n)};
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { type PartialDeep } from 'type-fest';
|
2
|
+
import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
|
3
|
+
import { type FlatEvolveOptions } from '../types/types-options.js';
|
4
|
+
import { type EvolveBuildResult } from './start-one-entry-build.js';
|
5
|
+
export declare const startBuild: (projectCwd: string, buildModules: string[], overrideEvolveOptions?: PartialDeep<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions) => Promise<EvolveBuildResult[]>;
|
@@ -0,0 +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};
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { type EvolveEntryMap } from '../types/types-entry-map.js';
|
2
|
+
import { type FlatEvolveOptions } from '../types/types-options.js';
|
3
|
+
export type EvolveBuildResult = {
|
4
|
+
name?: string;
|
5
|
+
warningStats?: unknown;
|
6
|
+
};
|
7
|
+
/**
|
8
|
+
* The helpers to build one entry at a time
|
9
|
+
* @param singleBuildEntry The single entry
|
10
|
+
* @param buildPublicPath
|
11
|
+
* @param evolveOptions
|
12
|
+
*/
|
13
|
+
export declare const startOneEntryBuild: (singleBuildEntry: EvolveEntryMap, evolveOptions: FlatEvolveOptions) => Promise<EvolveBuildResult>;
|
@@ -0,0 +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})}))}))};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { type PartialDeep } from 'type-fest';
|
2
|
+
import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
|
3
|
+
import { type FlatEvolveOptions } from '../types/types-options.js';
|
4
|
+
/**
|
5
|
+
* The main entry to start evolve serve
|
6
|
+
* @param projectCwd The Root directory (workspace) of this project.
|
7
|
+
* @param serveModules The filter pattern to detect modules we want to serve.
|
8
|
+
* @param overrideEvolveOptions The overrided evolve options
|
9
|
+
* @param configLoaderOptions Evolve config loader options
|
10
|
+
*/
|
11
|
+
export declare const startServe: (projectCwd: string, serveModules: string[], overrideEvolveOptions?: PartialDeep<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions) => Promise<never[] | import("express-serve-static-core").Express>;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{logger,requireResolve}from"@flatjs/common";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareServe}from"./prepare-serve.js";export const startServe=async(e,r,o={},t)=>{const i={command:"serve",resolve:requireResolve},n=await loadEvolveConfig(i,e,o,t),l=filterActivedEntriesByModule(n.entryMap,r),s=Object.keys(l);if(!s.length)return logger.warn("No served entries providered!"),[];logger.info({servedEntries:s});const v=normalizeEvolveEntryMap(l,n.entryMap);return prepareServe(e,v,n)};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { type PartialDeep } from 'type-fest';
|
2
|
+
import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
|
3
|
+
import { type FlatEvolveOptions } from '../types/types-options.js';
|
4
|
+
/**
|
5
|
+
* The main entry to start evolve static server to proxy all modules of `production` build
|
6
|
+
* @param projectCwd The Root directory (workspace) of this project.
|
7
|
+
* @param overrideEvolveOptions The overrided evolve options
|
8
|
+
* @param configLoaderOptions Evolve config loader options
|
9
|
+
*/
|
10
|
+
export declare const startStatic: (projectCwd: string, overrideEvolveOptions?: PartialDeep<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions) => Promise<void>;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{requireResolve}from"@flatjs/common";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareStatic}from"./prepare-static.js";export const startStatic=async(o,e={},r)=>{const t={command:"static",resolve:requireResolve},a=await loadEvolveConfig(t,o,e,r);return prepareStatic(o,a)};
|
@@ -0,0 +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};
|
@@ -0,0 +1 @@
|
|
1
|
+
export const defaultTerserOptions={ecma:void 0,parse:{},compress:{},mangle:!0,module:!1,output:void 0,toplevel:!1,ie8:!1,keep_classnames:void 0,keep_fnames:!1,safari10:!1};
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import ImageMinimizerPlugin from 'image-minimizer-webpack-plugin';
|
2
|
+
/**
|
3
|
+
* Install libpng library & gifsicle tool
|
4
|
+
* macos
|
5
|
+
* =====================
|
6
|
+
* brew install libpng
|
7
|
+
* brew install gifsicle
|
8
|
+
*
|
9
|
+
* centos
|
10
|
+
* =====================
|
11
|
+
* sudo yum install libpng
|
12
|
+
* sudo yum install epel-release
|
13
|
+
* sudo yum install gifsicle
|
14
|
+
* @returns
|
15
|
+
*/
|
16
|
+
export declare const imageMinimizer: () => ImageMinimizerPlugin<unknown, unknown> | null;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{projectHasYarn}from"@armit/package";import{chalk,logger,requireResolve}from"@flatjs/common";import ImageMinimizerPlugin from"image-minimizer-webpack-plugin";import{moduleName}from"../constants.js";const logs=new Map;export const imageMinimizer=()=>{const e=[],i=[["svgo",{}],["gifsicle",{}],["jpegtran",{}],["pngquant",{}]].map((i=>{const n=i[0];try{return requireResolve(import.meta.url,`imagemin-${n}`),i}catch(i){if(!logs.get(n)){logs.set(n,!0);const i=chalk(["magenta"])(`"${projectHasYarn()?"yarn add":"npm install"} imagemin-${n} -D"`);e.push(`Execute ${i} for assets optimization`)}return null}})).filter(Boolean);if(e.length)for(const i of e)logger.warn(i,moduleName);return i.length?new ImageMinimizerPlugin({minimizer:{implementation:ImageMinimizerPlugin.imageminMinify,options:{plugins:i}}}):null};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './create-minimizers.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export*from"./create-minimizers.js";
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { type WebpackPlugin } from '../create-webpack/types.js';
|
2
|
+
import { type TerserMinimizerOptions } from './types.js';
|
3
|
+
/**
|
4
|
+
* https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
|
5
|
+
*/
|
6
|
+
export declare const terserMinimizer: (terserOptions: TerserMinimizerOptions) => WebpackPlugin;
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import{mergeOptions}from"@flatjs/common";import TerserPlugin from"terser-webpack-plugin";import{defaultTerserOptions}from"./default-options.js";export const terserMinimizer=e=>new TerserPlugin({parallel:!0,
|
2
|
+
// Disable Extract all or some (use /^\**!|@preserve|@license|@cc_on/i RegExp) comments.
|
3
|
+
extractComments:!1,terserOptions:mergeOptions(defaultTerserOptions,e)});
|
@@ -0,0 +1 @@
|
|
1
|
+
export{};
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import { type Compilation, type Compiler } from 'webpack';
|
2
|
+
export interface Options {
|
3
|
+
/**
|
4
|
+
* The project root.
|
5
|
+
*/
|
6
|
+
projectCwd?: string;
|
7
|
+
/**
|
8
|
+
* exclude detection of files based on a RegExp
|
9
|
+
* @default /node_modules/
|
10
|
+
*/
|
11
|
+
exclude?: RegExp;
|
12
|
+
/**
|
13
|
+
* include specific files based on a RegExp
|
14
|
+
* @default `new RegExp('.*')`
|
15
|
+
*/
|
16
|
+
include?: RegExp;
|
17
|
+
/**
|
18
|
+
* add errors to webpack instead of warnings
|
19
|
+
* @default true
|
20
|
+
*/
|
21
|
+
failOnError?: boolean;
|
22
|
+
/**
|
23
|
+
* allow import cycles that include an asynchronous import,
|
24
|
+
* e.g. via via import(/* webpackMode: "weak" *\/ './file.js')
|
25
|
+
* @default false
|
26
|
+
*/
|
27
|
+
allowAsyncCycles?: boolean;
|
28
|
+
/**
|
29
|
+
* `onStart` is called before the cycle detection starts
|
30
|
+
*/
|
31
|
+
onStart?: (options: {
|
32
|
+
compilation: Compilation;
|
33
|
+
}) => void;
|
34
|
+
/**
|
35
|
+
* `onDetected` is called for each module that is cyclical
|
36
|
+
* `paths` will be an Array of the relative module paths that make up the cycle
|
37
|
+
*/
|
38
|
+
onDetected?: (options: {
|
39
|
+
paths: string[];
|
40
|
+
compilation: Compilation;
|
41
|
+
}) => void;
|
42
|
+
/**
|
43
|
+
* `onEnd` is called before the cycle detection ends
|
44
|
+
*/
|
45
|
+
onEnd?: (options: {
|
46
|
+
compilation: Compilation;
|
47
|
+
}) => void;
|
48
|
+
}
|
49
|
+
export declare class CircularDependencyPlugin {
|
50
|
+
private options;
|
51
|
+
constructor(options?: Options);
|
52
|
+
apply(compiler: Compiler): void;
|
53
|
+
private isCyclic;
|
54
|
+
}
|