@flatjs/evolve 2.1.0-next.5 → 2.1.0-next.7
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/constants.js +1 -26
- package/dist/create-webpack/create-externals.js +1 -6
- package/dist/create-webpack/create-optimization.js +1 -41
- package/dist/create-webpack/create-output.js +1 -35
- package/dist/create-webpack/create-performance.js +1 -7
- package/dist/create-webpack/create-plugins.js +1 -77
- package/dist/create-webpack/create-resolve.js +1 -37
- package/dist/create-webpack/create-rule-sets.js +1 -19
- package/dist/create-webpack/load-webpack-config.js +1 -56
- package/dist/create-webpack/resolve-public-path.js +1 -15
- package/dist/create-webpack/rule-sets/constants.js +1 -3
- package/dist/create-webpack/rule-sets/rule-assets.js +1 -50
- package/dist/create-webpack/rule-sets/rule-css.js +1 -101
- package/dist/create-webpack/rule-sets/rule-less.js +1 -44
- package/dist/create-webpack/rule-sets/rule-scripts.js +1 -34
- package/dist/create-webpack/rule-sets/rule-svg-icon.js +1 -25
- package/dist/create-webpack/rule-sets/rule-utils.js +1 -10
- package/dist/create-webpack/types.js +1 -1
- package/dist/default-options.js +1 -84
- package/dist/define-config/define-config.js +1 -4
- package/dist/define-config/index.js +1 -1
- package/dist/dev-server/add-compiler-to-dev-server.js +1 -58
- package/dist/dev-server/create-app-page-route.js +1 -13
- package/dist/dev-server/create-dev-server-compiler-tasks.js +1 -52
- package/dist/dev-server/create-dev-server-entries.js +1 -27
- package/dist/dev-server/create-dev-server.js +1 -24
- package/dist/dev-server/index.js +1 -6
- package/dist/dev-server/middlewares/create-page-middleware.js +1 -33
- package/dist/dev-server/middlewares/create-public-assets-middleware.js +1 -25
- package/dist/dev-server/middlewares/get-all-sorted-modules.js +1 -24
- package/dist/dev-server/middlewares/get-bundle-asset.js +1 -7
- package/dist/dev-server/middlewares/get-dev-server-host-uri.js +1 -5
- package/dist/dev-server/middlewares/get-hmr-runtime-chunks.js +1 -14
- package/dist/dev-server/middlewares/get-normalized-entry-name.js +1 -14
- package/dist/dev-server/middlewares/get-page-main-html.js +1 -42
- package/dist/dev-server/middlewares/get-page-module-html.js +1 -120
- package/dist/dev-server/middlewares/get-project-virtual-path.js +1 -3
- package/dist/dev-server/middlewares/get-runtime-manifest.js +1 -25
- package/dist/dev-server/middlewares/index.js +1 -2
- package/dist/dev-server/middlewares/types.js +1 -1
- package/dist/errors/evolve-build-error.js +1 -10
- package/dist/helpers/allow-px2rem-for-module.js +1 -6
- package/dist/helpers/assert-only-single-entry-item.js +1 -23
- package/dist/helpers/chunk-entry-map.js +1 -21
- package/dist/helpers/enable-bundle-hashname-for-module.js +1 -6
- package/dist/helpers/filter-actived-entries.js +1 -42
- package/dist/helpers/get-bundle-file-name.js +1 -23
- package/dist/helpers/get-git-root.js +1 -4
- package/dist/helpers/get-html-plugin-config.js +1 -47
- package/dist/helpers/get-max-process-tasks.js +1 -7
- package/dist/helpers/get-pacakge-dir.js +1 -13
- package/dist/helpers/index.js +1 -17
- package/dist/helpers/json-serializer.js +1 -52
- package/dist/helpers/merge-babel-options.js +1 -45
- package/dist/helpers/normalize-entry-map.js +1 -38
- package/dist/helpers/normalize-page-proxy.js +1 -9
- package/dist/helpers/normalize-resolve-alias.js +1 -7
- package/dist/helpers/open-page.js +1 -15
- package/dist/helpers/print-log.js +1 -49
- package/dist/helpers/refresh-evolve-mock-options.js +1 -34
- package/dist/helpers/resolve-entry-map-input-files.js +1 -20
- package/dist/helpers/script-injects.js +1 -39
- package/dist/helpers/should-enable-react-fast-refresh.js +1 -10
- package/dist/helpers/split-to-multi-compiler.js +1 -32
- package/dist/index.js +1 -5
- package/dist/load-config/index.js +1 -1
- package/dist/load-config/load-evolve-config.js +1 -41
- package/dist/load-config/types.js +1 -1
- package/dist/main/create-thread-worker.js +1 -42
- package/dist/main/env-verify.js +1 -21
- package/dist/main/get-worker-path.js +1 -5
- package/dist/main/index.js +1 -4
- package/dist/main/prepare-build.js +1 -38
- package/dist/main/prepare-serve.js +1 -45
- package/dist/main/prepare-static.js +1 -30
- package/dist/main/start-build-dynamic.js +1 -157
- package/dist/main/start-build-worker.js +1 -46
- package/dist/main/start-build.js +1 -53
- package/dist/main/start-one-entry-build.js +1 -35
- package/dist/main/start-serve.js +1 -34
- package/dist/main/start-static.js +1 -19
- package/dist/minimizer/create-minimizers.js +1 -25
- package/dist/minimizer/default-options.js +1 -14
- package/dist/minimizer/image-minimizer.js +1 -65
- package/dist/minimizer/index.js +1 -1
- package/dist/minimizer/terser-minimizer.js +3 -15
- package/dist/minimizer/types.js +1 -1
- package/dist/plugins/circular-dependency/circular-dependency-plugin.js +1 -119
- package/dist/plugins/circular-dependency/index.js +1 -15
- package/dist/plugins/clean-webpack/clean-webpack-plugin.js +1 -173
- package/dist/plugins/clean-webpack/index.js +1 -22
- package/dist/plugins/define-variable/define-variable-plugin.js +1 -28
- package/dist/plugins/define-variable/index.js +1 -1
- package/dist/plugins/html-inject-scripts/plugin-html-inject-script.js +1 -27
- package/dist/plugins/module-federation/external-template-remotes.js +1 -92
- package/dist/plugins/module-federation/index.js +1 -1
- package/dist/plugins/module-federation/module-federation.js +1 -98
- package/dist/plugins/multi-html/index.js +1 -15
- package/dist/plugins/multi-html/multi-html-cdn-plugin.js +1 -84
- package/dist/plugins/multi-html/multi-html-plugin.js +1 -70
- package/dist/plugins/ts-checker/index.js +1 -1
- package/dist/plugins/ts-checker/ts-checker-plugin.js +1 -18
- package/dist/types/index.js +1 -8
- package/dist/types/types-ci.js +1 -1
- package/dist/types/types-dev-server.js +1 -1
- package/dist/types/types-entry-map.d.ts +2 -2
- package/dist/types/types-entry-map.js +1 -1
- package/dist/types/types-federation.js +1 -1
- package/dist/types/types-loader-options.js +1 -1
- package/dist/types/types-modular-import.js +1 -1
- package/dist/types/types-multi-html.js +1 -1
- package/dist/types/types-options.js +1 -1
- package/dist/types/types-plugin-options.js +1 -1
- package/dist/types/types-webpack.js +1 -1
- package/package.json +2 -2
@@ -1,32 +1 @@
|
|
1
|
-
import {
|
2
|
-
import { mergeOptions } from '@flatjs/common';
|
3
|
-
import { devReactFastRefresh } from '../constants.js';
|
4
|
-
import { normalizeEvolveEntryName } from './normalize-entry-map.js';
|
5
|
-
/**
|
6
|
-
* Split the `webpack` to make sure that we have separated compiler process for each module
|
7
|
-
* @param webpackConfig `Omit<Configuration, 'entry'>` webpack final configuration
|
8
|
-
*/
|
9
|
-
export function splitToMultiCompilerConfigs(servedEntries, webpackConfig, evolveOptions, enabledHmr = false) {
|
10
|
-
const result = [];
|
11
|
-
for (const [entryName, entryItem] of Object.entries(servedEntries)) {
|
12
|
-
// Make sure that we have correct `virtualPath` for each webpack `entry`
|
13
|
-
const normalizedEntryName = normalizeEvolveEntryName(entryName, evolveOptions.projectVirtualPath);
|
14
|
-
result.push({
|
15
|
-
[normalizedEntryName]: entryItem.entry,
|
16
|
-
});
|
17
|
-
}
|
18
|
-
return result.map((newEntry) => {
|
19
|
-
const entryName = Object.keys(newEntry)[0];
|
20
|
-
if (enabledHmr) {
|
21
|
-
// `${virtualPath}/module/reactRefreshSetup`
|
22
|
-
const fastRefreshEntryName = join(entryName, devReactFastRefresh.reactRefreshSetup);
|
23
|
-
newEntry[fastRefreshEntryName] = [
|
24
|
-
'@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js',
|
25
|
-
];
|
26
|
-
}
|
27
|
-
return mergeOptions(webpackConfig, {
|
28
|
-
name: entryName,
|
29
|
-
entry: newEntry,
|
30
|
-
});
|
31
|
-
});
|
32
|
-
}
|
1
|
+
import{join}from"path";import{mergeOptions}from"@flatjs/common";import{devReactFastRefresh}from"../constants.js";import{normalizeEvolveEntryName}from"./normalize-entry-map.js";export function splitToMultiCompilerConfigs(e,t,r,o=!1){const n=[];for(const[t,o]of Object.entries(e)){const e=normalizeEvolveEntryName(t,r.projectVirtualPath);n.push({[e]:o.entry})}return n.map((e=>{const r=Object.keys(e)[0];if(o){e[join(r,devReactFastRefresh.reactRefreshSetup)]=["@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js"]}return mergeOptions(t,{name:r,entry:e})}))}
|
package/dist/index.js
CHANGED
@@ -1,5 +1 @@
|
|
1
|
-
export
|
2
|
-
export * from './load-config/index.js';
|
3
|
-
export * from './main/index.js';
|
4
|
-
export * from './types/types-options.js';
|
5
|
-
export * from './types/types-entry-map.js';
|
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";
|
@@ -1 +1 @@
|
|
1
|
-
export
|
1
|
+
export*from"./load-evolve-config.js";
|
@@ -1,41 +1 @@
|
|
1
|
-
import
|
2
|
-
import { mergeOptions, logger } from '@flatjs/common';
|
3
|
-
import { configFileName, moduleName } from '../constants.js';
|
4
|
-
import { defaultEvolveOptions } from '../default-options.js';
|
5
|
-
import { normalizeResolveAlias } from '../helpers/normalize-resolve-alias.js';
|
6
|
-
import { refreshEvolveMockOptions } from '../helpers/refresh-evolve-mock-options.js';
|
7
|
-
export const loadEvolveConfig = async (configEnv, projectCwd, overrideOptions = {}, configLoaderOptions = {
|
8
|
-
configFile: configFileName,
|
9
|
-
esmLoaderOptions: {
|
10
|
-
externals: [/^@flatjs\/.*/],
|
11
|
-
},
|
12
|
-
}) => {
|
13
|
-
const { configFile, esmLoaderOptions } = configLoaderOptions;
|
14
|
-
const data = await searchConfig(configFile, projectCwd, {
|
15
|
-
esm: {
|
16
|
-
...esmLoaderOptions,
|
17
|
-
projectCwd,
|
18
|
-
},
|
19
|
-
});
|
20
|
-
let localData = {};
|
21
|
-
if (typeof data?.config === 'function') {
|
22
|
-
localData = await data?.config(configEnv);
|
23
|
-
}
|
24
|
-
else {
|
25
|
-
localData = data?.config || {};
|
26
|
-
}
|
27
|
-
// Merge user local config with default configure options.
|
28
|
-
const localConfigOptions = mergeOptions(defaultEvolveOptions, localData);
|
29
|
-
const mergedConfigOptions = mergeOptions(localConfigOptions, overrideOptions);
|
30
|
-
const finalData = mergeOptions(mergedConfigOptions, { projectCwd });
|
31
|
-
// We don't need to load mocks configuration from `flatjs-mock.config.js` while `build` phase.
|
32
|
-
const latestEvolveOptions = configEnv.command === 'build'
|
33
|
-
? finalData
|
34
|
-
: await refreshEvolveMockOptions(projectCwd, finalData, configLoaderOptions);
|
35
|
-
logger.debug(`Load evolve config:\n${JSON.stringify(latestEvolveOptions, null, 2)}`, moduleName);
|
36
|
-
// Normalize webpack.resolve.alias to make sure convert `alias` to absolute path.
|
37
|
-
if (latestEvolveOptions.webpack?.resolve?.alias) {
|
38
|
-
latestEvolveOptions.webpack.resolve.alias = normalizeResolveAlias(projectCwd, latestEvolveOptions.webpack?.resolve?.alias);
|
39
|
-
}
|
40
|
-
return latestEvolveOptions;
|
41
|
-
};
|
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\/.*/]}})=>{const{configFile:r,esmLoaderOptions:l}=s,a=await searchConfig(r,e,{esm:{...l,projectCwd:e}});let n={};n="function"==typeof a?.config?await(a?.config(o)):a?.config||{};const t=mergeOptions(defaultEvolveOptions,n),m=mergeOptions(t,i),f=mergeOptions(m,{projectCwd:e}),c="build"===o.command?f:await refreshEvolveMockOptions(e,f,s);return logger.debug(`Load evolve config:\n${JSON.stringify(c,null,2)}`,moduleName),c.webpack?.resolve?.alias&&(c.webpack.resolve.alias=normalizeResolveAlias(e,c.webpack?.resolve?.alias)),c};
|
@@ -1 +1 @@
|
|
1
|
-
export
|
1
|
+
export{};
|
@@ -1,42 +1 @@
|
|
1
|
-
import EventEmitter from '
|
2
|
-
import { createThreadPool, } from '@armit/worker-threads';
|
3
|
-
import { getWorkerPath } from './get-worker-path.js';
|
4
|
-
import { startBuildWorker } from './start-build-worker.js';
|
5
|
-
class ThreadPoolForUnittest {
|
6
|
-
constructor(workerSize) {
|
7
|
-
this.workerSize = workerSize;
|
8
|
-
}
|
9
|
-
startBuildWorker(...args) {
|
10
|
-
return startBuildWorker(...args);
|
11
|
-
}
|
12
|
-
get pool() {
|
13
|
-
const puddleInterface = new EventEmitter();
|
14
|
-
const pool = {
|
15
|
-
terminate() {
|
16
|
-
console.warn(`[WARNING] Using fake "terminate" for unittest!`);
|
17
|
-
},
|
18
|
-
refill() {
|
19
|
-
console.warn(`[WARNING] Using fake "refill" for unittest!`);
|
20
|
-
},
|
21
|
-
async drain() {
|
22
|
-
console.warn(`[WARNING] Using fake "drain" for unittest!`);
|
23
|
-
},
|
24
|
-
size: this.workerSize,
|
25
|
-
isTerminated: false,
|
26
|
-
threads: new Map(),
|
27
|
-
};
|
28
|
-
return Object.assign(puddleInterface, pool);
|
29
|
-
}
|
30
|
-
}
|
31
|
-
export const createThreadWorker = async (workerSize) => {
|
32
|
-
const workerPath = getWorkerPath();
|
33
|
-
// FIXME: Is safe to remove `worker thread` while `test` environment, cause of we need to run UT using `source code`
|
34
|
-
const isTestEnv = process.env.NODE_ENV === 'test';
|
35
|
-
if (isTestEnv) {
|
36
|
-
console.warn(`[WARNING] Using fake thread pool worker for unittest!`);
|
37
|
-
return new ThreadPoolForUnittest(workerSize);
|
38
|
-
}
|
39
|
-
return await createThreadPool(workerPath, {
|
40
|
-
size: workerSize,
|
41
|
-
});
|
42
|
-
};
|
1
|
+
import EventEmitter from"events";import{createThreadPool}from"@armit/worker-threads";import{getWorkerPath}from"./get-worker-path.js";import{startBuildWorker}from"./start-build-worker.js";class ThreadPoolForUnittest{constructor(r){this.workerSize=r}startBuildWorker(...r){return startBuildWorker(...r)}get pool(){const r=new EventEmitter,e={terminate(){console.warn('[WARNING] Using fake "terminate" for unittest!')},refill(){console.warn('[WARNING] Using fake "refill" for unittest!')},async drain(){console.warn('[WARNING] Using fake "drain" for unittest!')},size:this.workerSize,isTerminated:!1,threads:new Map};return Object.assign(r,e)}}export const createThreadWorker=async r=>{const e=getWorkerPath();return"test"===process.env.NODE_ENV?(console.warn("[WARNING] Using fake thread pool worker for unittest!"),new ThreadPoolForUnittest(r)):await createThreadPool(e,{size:r})};
|
package/dist/main/env-verify.js
CHANGED
@@ -1,21 +1 @@
|
|
1
|
-
import
|
2
|
-
export const envVerify = async (projectCwd, evolveOptions) => {
|
3
|
-
const { packageInstallChecker, needVerifyPackages } = evolveOptions;
|
4
|
-
if (packageInstallChecker !== false && packageInstallChecker?.enabled) {
|
5
|
-
// Verify local install node modules
|
6
|
-
await illegalPackageChecker({
|
7
|
-
cwd: projectCwd,
|
8
|
-
modules: packageInstallChecker?.detectModules,
|
9
|
-
throwError: packageInstallChecker?.throwError,
|
10
|
-
showAllInstalledGraph: packageInstallChecker?.showAllInstalledGraph,
|
11
|
-
});
|
12
|
-
}
|
13
|
-
if (needVerifyPackages !== false) {
|
14
|
-
// Keep package deps up to date for non-monorepo
|
15
|
-
await keepPackageDepsUpToDateForNonMonoRepo({
|
16
|
-
cwd: projectCwd,
|
17
|
-
autoUpgrade: true,
|
18
|
-
needVerifyPackages: needVerifyPackages || {},
|
19
|
-
});
|
20
|
-
}
|
21
|
-
};
|
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||{}})};
|
@@ -1,5 +1 @@
|
|
1
|
-
import
|
2
|
-
import { getDirname } from '@armit/file-utility';
|
3
|
-
export const getWorkerPath = () => {
|
4
|
-
return pathToFileURL(getDirname(import.meta.url, './start-build-worker.js')).toString();
|
5
|
-
};
|
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();
|
package/dist/main/index.js
CHANGED
@@ -1,4 +1 @@
|
|
1
|
-
export
|
2
|
-
export * from './start-serve.js';
|
3
|
-
export * from './start-static.js';
|
4
|
-
export * from './start-build-dynamic.js';
|
1
|
+
export*from"./start-build.js";export*from"./start-serve.js";export*from"./start-static.js";export*from"./start-build-dynamic.js";
|
@@ -1,38 +1 @@
|
|
1
|
-
import { ensureSlash, mergeOptions }
|
2
|
-
import { EvolveBuildError } from '../errors/evolve-build-error.js';
|
3
|
-
import { printCompilerError } from '../helpers/print-log.js';
|
4
|
-
import { startOneEntryBuild, } from './start-one-entry-build.js';
|
5
|
-
/**
|
6
|
-
* The main entry to start an evolve `build`
|
7
|
-
* @param entryMapItem The `entryMapItem` for one entry build task
|
8
|
-
* @param evolveOptions FlatEvolveOptions
|
9
|
-
*/
|
10
|
-
export const prepareBuild = async (entryMapItem, evolveOptions) => {
|
11
|
-
const [entryKey, entryConfig] = entryMapItem;
|
12
|
-
// Fetch all configuration cdn
|
13
|
-
const cdnPath = evolveOptions.multiHtmlCdn?.prod || [];
|
14
|
-
if (!cdnPath.length) {
|
15
|
-
throw new Error(`No CDN config for env:"prod", moduleName: ${entryKey}`);
|
16
|
-
}
|
17
|
-
// Random choose one to publicPath
|
18
|
-
const cdnPublicPath = ensureSlash(cdnPath[Math.floor(Math.random() * cdnPath.length)], true);
|
19
|
-
// Construct single entry map item to build.
|
20
|
-
const toBuildEntryMapItem = {
|
21
|
-
[entryKey]: entryConfig,
|
22
|
-
};
|
23
|
-
try {
|
24
|
-
const useRelativeAssetPath = entryConfig.options?.useRelativeAssetPath;
|
25
|
-
const buildEvolveOptions = mergeOptions(evolveOptions, {
|
26
|
-
webpack: {
|
27
|
-
// Only for `assets` used at styling files (e.g.`xxx.less`)
|
28
|
-
publicPath: useRelativeAssetPath ? 'auto' : cdnPublicPath,
|
29
|
-
},
|
30
|
-
});
|
31
|
-
return await startOneEntryBuild(toBuildEntryMapItem, buildEvolveOptions);
|
32
|
-
}
|
33
|
-
catch (err) {
|
34
|
-
const formattedErrors = printCompilerError(err);
|
35
|
-
// Need re-throw error, in order to third API can capture this error.
|
36
|
-
throw new EvolveBuildError(`BUILD_ERROR`, formattedErrors);
|
37
|
-
}
|
38
|
-
};
|
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)}};
|
@@ -1,45 +1 @@
|
|
1
|
-
import
|
2
|
-
import { attachMockMiddlewares } from '@flatjs/mock';
|
3
|
-
import { createAppPageRoute, createDevServer, createDevServerCompilerTasks, createDevServerEntries, } from '../dev-server/index.js';
|
4
|
-
import { openPage } from '../helpers/index.js';
|
5
|
-
import { normalizePageProxy } from '../helpers/normalize-page-proxy.js';
|
6
|
-
import { envVerify } from './env-verify.js';
|
7
|
-
/**
|
8
|
-
* The main entry to start evolve serve
|
9
|
-
* @param projectCwd The Root directory (workspace) of this project.
|
10
|
-
* @param servedEntries All normalized webpack entries we have served.
|
11
|
-
* @param evolveOptions FlatEvolveOptions
|
12
|
-
*/
|
13
|
-
export const prepareServe = async (projectCwd, servedEntries, evolveOptions) => {
|
14
|
-
// Verify if we have an correct project local environment.
|
15
|
-
await envVerify(projectCwd, evolveOptions);
|
16
|
-
// Create pure dev server.
|
17
|
-
const { app, devPort, devHostUri, publicIp } = await createDevServer(evolveOptions);
|
18
|
-
// Extract all the mock filters of served entries.
|
19
|
-
const mockFilters = evolveOptions.devServer?.mockOptions?.mockFilters || [];
|
20
|
-
// Loop all entries gather all mock files definition from each entry item.
|
21
|
-
for (const [, value] of Object.entries(servedEntries)) {
|
22
|
-
mockFilters.push(...(value.options?.mockFilters || []));
|
23
|
-
}
|
24
|
-
// Attach core handlers for mock
|
25
|
-
await attachMockMiddlewares(app, {
|
26
|
-
...evolveOptions.devServer?.mockOptions,
|
27
|
-
mockFilters: arrayUnique(mockFilters),
|
28
|
-
projectCwd,
|
29
|
-
});
|
30
|
-
// Create dev-server configurationn for all servedEntries.
|
31
|
-
const servedDevServerEntries = await createDevServerEntries(devPort, servedEntries, evolveOptions);
|
32
|
-
// Create new route `/pages*`,`*` to pure dev server
|
33
|
-
createAppPageRoute(projectCwd, app, devHostUri, servedDevServerEntries, evolveOptions);
|
34
|
-
const pageProxy = normalizePageProxy(evolveOptions.devServer?.pageProxy || '/pages');
|
35
|
-
const mainPage = urlJoin(devHostUri, [pageProxy]);
|
36
|
-
// Open page via browser
|
37
|
-
if (evolveOptions.devServer?.autoOpen) {
|
38
|
-
openPage(mainPage);
|
39
|
-
}
|
40
|
-
// Create dev-server compiler tasks
|
41
|
-
const serveTasks = await createDevServerCompilerTasks(projectCwd, mainPage, publicIp, servedDevServerEntries, evolveOptions);
|
42
|
-
return Promise.all(serveTasks).then(() => {
|
43
|
-
return app;
|
44
|
-
});
|
45
|
-
};
|
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{normalizePageProxy}from"../helpers/normalize-page-proxy.js";import{envVerify}from"./env-verify.js";export const prepareServe=async(e,r,o)=>{await envVerify(e,o);const{app:t,devPort:a,devHostUri:i,publicIp:s}=await createDevServer(o),p=o.devServer?.mockOptions?.mockFilters||[];for(const[,e]of Object.entries(r))p.push(...e.options?.mockFilters||[]);await attachMockMiddlewares(t,{...o.devServer?.mockOptions,mockFilters:arrayUnique(p),projectCwd:e});const n=await createDevServerEntries(a,r,o);createAppPageRoute(e,t,i,n,o);const c=normalizePageProxy(o.devServer?.pageProxy||"/pages"),v=urlJoin(i,[c]);o.devServer?.autoOpen&&openPage(v);const m=await createDevServerCompilerTasks(e,v,s,n,o);return Promise.all(m).then((()=>t))};
|
@@ -1,30 +1 @@
|
|
1
|
-
import
|
2
|
-
import { attachMockMiddlewares } from '@flatjs/mock';
|
3
|
-
import { createAppPageRoute } from '../dev-server/create-app-page-route.js';
|
4
|
-
import { createDevServer } from '../dev-server/create-dev-server.js';
|
5
|
-
import { normalizePageProxy } from '../helpers/normalize-page-proxy.js';
|
6
|
-
import { openPage } from '../helpers/open-page.js';
|
7
|
-
/**
|
8
|
-
* The main entry to start evolve serve
|
9
|
-
* @param projectCwd The Root directory (workspace) of this project.
|
10
|
-
* @param evolveOptions FlatEvolveOptions
|
11
|
-
*/
|
12
|
-
export const prepareStatic = async (projectCwd, evolveOptions) => {
|
13
|
-
// Create pure dev server.
|
14
|
-
const { app, devHostUri } = await createDevServer(evolveOptions);
|
15
|
-
// Attach core handlers for mock
|
16
|
-
await attachMockMiddlewares(app, {
|
17
|
-
...evolveOptions.devServer?.mockOptions,
|
18
|
-
projectCwd,
|
19
|
-
});
|
20
|
-
// Create new route `/pages*`,`*` to pure dev server
|
21
|
-
createAppPageRoute(projectCwd, app, devHostUri, {}, evolveOptions);
|
22
|
-
const pageProxy = normalizePageProxy(evolveOptions.devServer?.pageProxy || '/pages');
|
23
|
-
const mainPage = urlJoin(devHostUri, [pageProxy]);
|
24
|
-
// Open page via browser
|
25
|
-
if (evolveOptions.devServer?.autoOpen) {
|
26
|
-
openPage(mainPage);
|
27
|
-
}
|
28
|
-
logger.info(`${'static page'.padEnd(12, ' ')} ➩ ${chalk(['cyan'])(mainPage)}`);
|
29
|
-
};
|
30
|
-
// Start up main page proxy server.
|
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{normalizePageProxy}from"../helpers/normalize-page-proxy.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=normalizePageProxy(r.devServer?.pageProxy||"/pages"),p=urlJoin(o,[t]);r.devServer?.autoOpen&&openPage(p),logger.info(`${"static page".padEnd(12," ")} ➩ ${chalk(["cyan"])(p)}`)};
|
@@ -1,157 +1 @@
|
|
1
|
-
import {
|
2
|
-
import { getDiffFiles, getCommitIdOfBranch } from '@armit/git';
|
3
|
-
import { arraysIntersect, chalk, logger, requireResolve } from '@flatjs/common';
|
4
|
-
import { traverseGraph } from '@flatjs/graph';
|
5
|
-
import Listr from 'listr';
|
6
|
-
import { moduleName } from '../constants.js';
|
7
|
-
import { filterActivedEntriesByEntryInputs, filterActivedEntriesByModule, } from '../helpers/filter-actived-entries.js';
|
8
|
-
import { getGitRoot } from '../helpers/get-git-root.js';
|
9
|
-
import { getMaxProcessTasks } from '../helpers/get-max-process-tasks.js';
|
10
|
-
import { jsonSerializer } from '../helpers/json-serializer.js';
|
11
|
-
import { resolveEntryMapInputFiles } from '../helpers/resolve-entry-map-input-files.js';
|
12
|
-
import { loadEvolveConfig } from '../load-config/load-evolve-config.js';
|
13
|
-
import { createThreadWorker } from './create-thread-worker.js';
|
14
|
-
import { envVerify } from './env-verify.js';
|
15
|
-
export async function getBuildEntryFiles(projectCwd, diffFiles, allEntryInputs, resolveAlias, graphTreeNodeFilter) {
|
16
|
-
const toBuildEntryFiles = [];
|
17
|
-
const entryInputsPendingToCheck = [];
|
18
|
-
for (const entryInput of allEntryInputs) {
|
19
|
-
// If entry have been existed in diff files, need to rebuild.
|
20
|
-
if (diffFiles.includes(entryInput)) {
|
21
|
-
toBuildEntryFiles.push(entryInput);
|
22
|
-
}
|
23
|
-
else {
|
24
|
-
entryInputsPendingToCheck.push(entryInput);
|
25
|
-
}
|
26
|
-
}
|
27
|
-
if (graphTreeNodeFilter) {
|
28
|
-
logger.info(`Use custom graph traverse filter`, moduleName);
|
29
|
-
}
|
30
|
-
// If there has pedding entry inputs to check.
|
31
|
-
if (entryInputsPendingToCheck.length) {
|
32
|
-
const graphDeps = await traverseGraph({
|
33
|
-
input: entryInputsPendingToCheck,
|
34
|
-
projectCwd,
|
35
|
-
treeNodeFilter: graphTreeNodeFilter || (() => true),
|
36
|
-
lessImportOptions: {
|
37
|
-
projectCwd,
|
38
|
-
aliases: resolveAlias,
|
39
|
-
},
|
40
|
-
});
|
41
|
-
if (!graphDeps) {
|
42
|
-
return toBuildEntryFiles;
|
43
|
-
}
|
44
|
-
logger.debug(`DependencyGraph:\n${JSON.stringify(graphDeps, null, 2)}`);
|
45
|
-
for (const entryInputToCheck of entryInputsPendingToCheck) {
|
46
|
-
const dependsFiles = graphDeps[entryInputToCheck] || [];
|
47
|
-
if (arraysIntersect(dependsFiles, diffFiles)) {
|
48
|
-
toBuildEntryFiles.push(entryInputToCheck);
|
49
|
-
}
|
50
|
-
}
|
51
|
-
}
|
52
|
-
return toBuildEntryFiles;
|
53
|
-
}
|
54
|
-
/**
|
55
|
-
* Dynamic check which entry modules need to build.
|
56
|
-
* @returns
|
57
|
-
*/
|
58
|
-
export async function dynamicCheckBuildEntryMap(projectCwd, earlyCommit, lastCommit, overrideEvolveOptions, configLoaderOptions) {
|
59
|
-
const command = {
|
60
|
-
projectCwd,
|
61
|
-
command: 'build',
|
62
|
-
resolve: requireResolve,
|
63
|
-
};
|
64
|
-
// 1. Try to load evolve configuration from `flatjs-evolve.config.ts`
|
65
|
-
const newEvolveOptions = await loadEvolveConfig(command, projectCwd, overrideEvolveOptions, configLoaderOptions);
|
66
|
-
// 2. Check if we have fixed build modules.
|
67
|
-
if (newEvolveOptions.ci?.fixedBuildModules &&
|
68
|
-
newEvolveOptions.ci?.fixedBuildModules.length) {
|
69
|
-
logger.info('Use `fixedBuildModules` configuration to build...');
|
70
|
-
const buildEntries = filterActivedEntriesByModule(newEvolveOptions.entryMap, newEvolveOptions.ci?.fixedBuildModules);
|
71
|
-
return { buildEntries, newEvolveOptions };
|
72
|
-
}
|
73
|
-
logger.info('Dynamicly checking code changed modules ...');
|
74
|
-
// 3. Resolve diff files based on specificed branch.
|
75
|
-
// Check if we have fixed `early commit` if no resolve based on `Branch` from evolve config file.
|
76
|
-
if (!earlyCommit) {
|
77
|
-
const basedBranch = newEvolveOptions.ci?.basedBranch || 'origin/master';
|
78
|
-
earlyCommit = await getCommitIdOfBranch(basedBranch);
|
79
|
-
// Try resolve based branch commit hash.
|
80
|
-
logger.info(`Resolving base branch "${basedBranch}" commit hash "${earlyCommit}" ...`);
|
81
|
-
}
|
82
|
-
// `packages/evolve/tests/main/fixtures/src/home/index.ts` without repo cwd.
|
83
|
-
let diffFiles = earlyCommit
|
84
|
-
? await getDiffFiles(earlyCommit, lastCommit)
|
85
|
-
: [];
|
86
|
-
const gitRoot = getGitRoot(projectCwd);
|
87
|
-
if (!gitRoot) {
|
88
|
-
throw new Error(`No .git root (${projectCwd}) found`);
|
89
|
-
}
|
90
|
-
// Hack diff files with git repo root dir.
|
91
|
-
diffFiles = diffFiles.map((diffFile) => {
|
92
|
-
return isAbsolute(diffFile) ? diffFile : join(gitRoot, diffFile);
|
93
|
-
});
|
94
|
-
logger.debug(`Diff files: \n${JSON.stringify(diffFiles, null, 2)}`);
|
95
|
-
// No code changed here.
|
96
|
-
if (!diffFiles.length) {
|
97
|
-
logger.warn('It seems that there are no code files changed.');
|
98
|
-
return {
|
99
|
-
buildEntries: {},
|
100
|
-
newEvolveOptions,
|
101
|
-
};
|
102
|
-
}
|
103
|
-
// 4. Resolve entry input files.
|
104
|
-
const allEntryInputs = await resolveEntryMapInputFiles(projectCwd, newEvolveOptions.entryMap);
|
105
|
-
// 5. Flag changed entries (with absolute filepath)
|
106
|
-
const toBuildEntryFiles = await getBuildEntryFiles(projectCwd, diffFiles, allEntryInputs, newEvolveOptions.webpack?.resolve?.alias, newEvolveOptions.ci?.graphTreeNodeFilter);
|
107
|
-
logger.debug(`To build entry files: \n${JSON.stringify(toBuildEntryFiles, null, 2)}`);
|
108
|
-
// 6. Filter entry map items which need to build.
|
109
|
-
const buildEntries = await filterActivedEntriesByEntryInputs(projectCwd, newEvolveOptions.entryMap, toBuildEntryFiles);
|
110
|
-
return { buildEntries, newEvolveOptions };
|
111
|
-
}
|
112
|
-
/**
|
113
|
-
* The main entry to start an evolve `build` with automatically detect modules which have been changed between two commits.
|
114
|
-
* @param projectCwd The Root directory (workspace) of this project.
|
115
|
-
* @param earlyCommit The diff based earlier commit hash
|
116
|
-
* @param lastCommit If is omitted, it will have the same effect as using HEAD instead.
|
117
|
-
*/
|
118
|
-
export const startDynamicBuild = async (projectCwd, earlyCommit, lastCommit, overrideEvolveOptions = {}, configLoaderOptions) => {
|
119
|
-
// 1. Fetch all changed files betwwen two `commit`
|
120
|
-
const { buildEntries, newEvolveOptions } = await dynamicCheckBuildEntryMap(projectCwd, earlyCommit, lastCommit, overrideEvolveOptions, configLoaderOptions);
|
121
|
-
await envVerify(projectCwd, newEvolveOptions);
|
122
|
-
const buildEntryKeys = Object.keys(buildEntries);
|
123
|
-
// Make sure that we have at least one build entry module.
|
124
|
-
if (!buildEntryKeys.length) {
|
125
|
-
logger.warn(`No build entries providered!`);
|
126
|
-
return [];
|
127
|
-
}
|
128
|
-
const workerSize = getMaxProcessTasks(buildEntryKeys.length, newEvolveOptions.maxProcesses);
|
129
|
-
logger.info(`Start dynamic build with (${chalk(['magenta'])(String(workerSize))}) workers:\n${JSON.stringify({ buildEntries: buildEntryKeys }, null, 2)}`);
|
130
|
-
const worker = await createThreadWorker(workerSize);
|
131
|
-
const buildTasks = new Listr([], {
|
132
|
-
concurrent: workerSize,
|
133
|
-
exitOnError: true,
|
134
|
-
});
|
135
|
-
const buildResults = [];
|
136
|
-
for (const [entryKey] of Object.entries(buildEntries)) {
|
137
|
-
buildTasks.add({
|
138
|
-
title: `Build module ${chalk(['magenta'])(entryKey)} ...`,
|
139
|
-
task: async () => {
|
140
|
-
const buildResult = await worker.startBuildWorker(projectCwd, entryKey, jsonSerializer.stringify(overrideEvolveOptions), configLoaderOptions);
|
141
|
-
buildResults.push(buildResult);
|
142
|
-
},
|
143
|
-
});
|
144
|
-
}
|
145
|
-
if (buildTasks.tasks.length) {
|
146
|
-
try {
|
147
|
-
await buildTasks.run();
|
148
|
-
}
|
149
|
-
catch (err) {
|
150
|
-
worker.pool.terminate();
|
151
|
-
// we need to catch the error here, makesure the `worker` can be terminated.
|
152
|
-
throw err;
|
153
|
-
}
|
154
|
-
}
|
155
|
-
worker.pool.terminate();
|
156
|
-
return buildResults;
|
157
|
-
};
|
1
|
+
import{isAbsolute,join}from"node:path";import{getDiffFiles,getCommitIdOfBranch}from"@armit/git";import{arraysIntersect,chalk,logger,requireResolve}from"@flatjs/common";import{traverseGraph}from"@flatjs/graph";import Listr from"listr";import{moduleName}from"../constants.js";import{filterActivedEntriesByEntryInputs,filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{getGitRoot}from"../helpers/get-git-root.js";import{getMaxProcessTasks}from"../helpers/get-max-process-tasks.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{resolveEntryMapInputFiles}from"../helpers/resolve-entry-map-input-files.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{createThreadWorker}from"./create-thread-worker.js";import{envVerify}from"./env-verify.js";export async function getBuildEntryFiles(e,r,t,i,o){const n=[],s=[];for(const e of t)r.includes(e)?n.push(e):s.push(e);if(o&&logger.info("Use custom graph traverse filter",moduleName),s.length){const t=await traverseGraph({input:s,projectCwd:e,treeNodeFilter:o||(()=>!0),lessImportOptions:{projectCwd:e,aliases:i}});if(!t)return n;logger.debug(`DependencyGraph:\n${JSON.stringify(t,null,2)}`);for(const e of s){const i=t[e]||[];arraysIntersect(i,r)&&n.push(e)}}return n}export async function dynamicCheckBuildEntryMap(e,r,t,i,o){const n={projectCwd:e,command:"build",resolve:requireResolve},s=await loadEvolveConfig(n,e,i,o);if(s.ci?.fixedBuildModules&&s.ci?.fixedBuildModules.length){logger.info("Use `fixedBuildModules` configuration to build...");return{buildEntries:filterActivedEntriesByModule(s.entryMap,s.ci?.fixedBuildModules),newEvolveOptions:s}}if(logger.info("Dynamicly checking code changed modules ..."),!r){const e=s.ci?.basedBranch||"origin/master";r=await getCommitIdOfBranch(e),logger.info(`Resolving base branch "${e}" commit hash "${r}" ...`)}let a=r?await getDiffFiles(r,t):[];const l=getGitRoot(e);if(!l)throw new Error(`No .git root (${e}) found`);if(a=a.map((e=>isAbsolute(e)?e:join(l,e))),logger.debug(`Diff files: \n${JSON.stringify(a,null,2)}`),!a.length)return logger.warn("It seems that there are no code files changed."),{buildEntries:{},newEvolveOptions:s};const c=await resolveEntryMapInputFiles(e,s.entryMap),d=await getBuildEntryFiles(e,a,c,s.webpack?.resolve?.alias,s.ci?.graphTreeNodeFilter);logger.debug(`To build entry files: \n${JSON.stringify(d,null,2)}`);return{buildEntries:await filterActivedEntriesByEntryInputs(e,s.entryMap,d),newEvolveOptions:s}}export const startDynamicBuild=async(e,r,t,i={},o)=>{const{buildEntries:n,newEvolveOptions:s}=await dynamicCheckBuildEntryMap(e,r,t,i,o);await envVerify(e,s);const a=Object.keys(n);if(!a.length)return logger.warn("No build entries providered!"),[];const l=getMaxProcessTasks(a.length,s.maxProcesses);logger.info(`Start dynamic build with (${chalk(["magenta"])(String(l))}) workers:\n${JSON.stringify({buildEntries:a},null,2)}`);const c=await createThreadWorker(l),d=new Listr([],{concurrent:l,exitOnError:!0}),f=[];for(const[r]of Object.entries(n))d.add({title:`Build module ${chalk(["magenta"])(r)} ...`,task:async()=>{const t=await c.startBuildWorker(e,r,jsonSerializer.stringify(i),o);f.push(t)}});if(d.tasks.length)try{await d.run()}catch(e){throw c.pool.terminate(),e}return c.pool.terminate(),f};
|
@@ -1,46 +1 @@
|
|
1
|
-
import
|
2
|
-
import { filterActivedEntriesByModule } from '../helpers/filter-actived-entries.js';
|
3
|
-
import { jsonSerializer } from '../helpers/json-serializer.js';
|
4
|
-
import { normalizeEvolveEntryMap } from '../helpers/normalize-entry-map.js';
|
5
|
-
import { loadEvolveConfig } from '../load-config/load-evolve-config.js';
|
6
|
-
import { prepareBuild } from './prepare-build.js';
|
7
|
-
/**
|
8
|
-
* FIXME: The main entry to start an evolve `build`, NOTE: avoid pass configuration with `function` here.
|
9
|
-
* If you need to call build api avoid `worker` you can directly call `prepareBuild`
|
10
|
-
* @internal
|
11
|
-
* @param projectCwd The Root directory (workspace) of this project.
|
12
|
-
* @param entryKey The `entryKey` for one entry build task
|
13
|
-
* @param serializedEvolveOptions The overrided evolve options, NOTE: we will serialize `function` property here first
|
14
|
-
* @param configLoaderOptions Evolve config loader options, NOTE: avoid pass configuration with `function` here.
|
15
|
-
*/
|
16
|
-
export const startBuildWorker = async (projectCwd, entryKey, serializedEvolveOptions, configLoaderOptions) => {
|
17
|
-
const command = {
|
18
|
-
projectCwd,
|
19
|
-
command: 'build',
|
20
|
-
resolve: requireResolve,
|
21
|
-
};
|
22
|
-
const overrideEvolveOptions = jsonSerializer.parse(serializedEvolveOptions) || {};
|
23
|
-
// Try to load evolve configuration from `flatjs-evolve.config.ts`
|
24
|
-
// FIXME: Cause of `worker-theads` do not support pass configuration with `function` reference.
|
25
|
-
const newEvolveOptions = await loadEvolveConfig(command, projectCwd, overrideEvolveOptions, configLoaderOptions);
|
26
|
-
// FIXME: Cause of `worker threads` we need avoid pass entryItem config directly
|
27
|
-
// because we have some config node item with `function`
|
28
|
-
// It will break `worker threads` comunication, e.g below shown.
|
29
|
-
// DataCloneError: function (url) {
|
30
|
-
// if (url.indexOf('dev.flatjs.com') > 0) return 'me';
|
31
|
-
// if (url.indexOf('.qa.') > 0) retur...<omitted>... } could not be cloned.
|
32
|
-
// at new DOMException (node:internal/per_context/domexception:53:5)
|
33
|
-
// So we need to re cacalculate the build entry via `entryKey`
|
34
|
-
const buildOneEntry = filterActivedEntriesByModule(newEvolveOptions.entryMap, [
|
35
|
-
// Make sure that the entryKey is correct match.
|
36
|
-
new RegExp(`^${entryKey}$`),
|
37
|
-
]);
|
38
|
-
const buildEntryKeys = Object.keys(buildOneEntry);
|
39
|
-
// Make sure that we have at least one build entry module.
|
40
|
-
if (!buildEntryKeys.length) {
|
41
|
-
throw new Error(`No build entry resolved via "${entryKey}" on "startBuildWorker"!`);
|
42
|
-
}
|
43
|
-
const normalizedBuildOneEntry = normalizeEvolveEntryMap(buildOneEntry, newEvolveOptions.entryMap);
|
44
|
-
const buildEntryConfig = normalizedBuildOneEntry[entryKey];
|
45
|
-
return prepareBuild([entryKey, buildEntryConfig], newEvolveOptions);
|
46
|
-
};
|
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={projectCwd:e,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)};
|
package/dist/main/start-build.js
CHANGED
@@ -1,53 +1 @@
|
|
1
|
-
import
|
2
|
-
import Listr from 'listr';
|
3
|
-
import { filterActivedEntriesByModule } from '../helpers/filter-actived-entries.js';
|
4
|
-
import { getMaxProcessTasks } from '../helpers/get-max-process-tasks.js';
|
5
|
-
import { jsonSerializer } from '../helpers/json-serializer.js';
|
6
|
-
import { loadEvolveConfig } from '../load-config/load-evolve-config.js';
|
7
|
-
import { createThreadWorker } from './create-thread-worker.js';
|
8
|
-
import { envVerify } from './env-verify.js';
|
9
|
-
export const startBuild = async (projectCwd, buildModules, overrideEvolveOptions = {}, configLoaderOptions) => {
|
10
|
-
const command = {
|
11
|
-
projectCwd,
|
12
|
-
command: 'build',
|
13
|
-
resolve: requireResolve,
|
14
|
-
};
|
15
|
-
// Try to load evolve configuration from `flatjs-evolve.config.ts`
|
16
|
-
const newEvolveOptions = await loadEvolveConfig(command, projectCwd, overrideEvolveOptions, configLoaderOptions);
|
17
|
-
await envVerify(projectCwd, newEvolveOptions);
|
18
|
-
const buildEntries = filterActivedEntriesByModule(newEvolveOptions.entryMap, buildModules);
|
19
|
-
const buildEntryKeys = Object.keys(buildEntries);
|
20
|
-
// Make sure that we have at least one build entry module.
|
21
|
-
if (!buildEntryKeys.length) {
|
22
|
-
logger.warn(`No build entries providered!`);
|
23
|
-
return [];
|
24
|
-
}
|
25
|
-
const workerSize = getMaxProcessTasks(buildEntryKeys.length, newEvolveOptions.maxProcesses);
|
26
|
-
logger.info(`Start standard build with (${chalk(['magenta'])(String(workerSize))}) workers:\n${JSON.stringify({ buildEntries: buildEntryKeys }, null, 2)}`);
|
27
|
-
const worker = await createThreadWorker(workerSize);
|
28
|
-
const buildTasks = new Listr([], {
|
29
|
-
concurrent: workerSize,
|
30
|
-
exitOnError: true,
|
31
|
-
});
|
32
|
-
const buildResults = [];
|
33
|
-
for (const [entryKey] of Object.entries(buildEntries)) {
|
34
|
-
buildTasks.add({
|
35
|
-
title: `Build module ${chalk(['magenta'])(entryKey)} ...`,
|
36
|
-
task: async () => {
|
37
|
-
const buildResult = await worker.startBuildWorker(projectCwd, entryKey, jsonSerializer.stringify(overrideEvolveOptions), configLoaderOptions);
|
38
|
-
buildResults.push(buildResult);
|
39
|
-
},
|
40
|
-
});
|
41
|
-
}
|
42
|
-
if (buildTasks.tasks.length) {
|
43
|
-
try {
|
44
|
-
await buildTasks.run();
|
45
|
-
}
|
46
|
-
catch (err) {
|
47
|
-
worker.pool.terminate();
|
48
|
-
// we need to catch the error here, makesure the `worker` can be terminated.
|
49
|
-
throw err;
|
50
|
-
}
|
51
|
-
}
|
52
|
-
return buildResults;
|
53
|
-
};
|
1
|
+
import{chalk,logger,requireResolve}from"@flatjs/common";import Listr from"listr";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{getMaxProcessTasks}from"../helpers/get-max-process-tasks.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{createThreadWorker}from"./create-thread-worker.js";import{envVerify}from"./env-verify.js";export const startBuild=async(e,r,t={},o)=>{const i={projectCwd:e,command:"build",resolve:requireResolve},s=await loadEvolveConfig(i,e,t,o);await envVerify(e,s);const a=filterActivedEntriesByModule(s.entryMap,r),n=Object.keys(a);if(!n.length)return logger.warn("No build entries providered!"),[];const l=getMaxProcessTasks(n.length,s.maxProcesses);logger.info(`Start standard build with (${chalk(["magenta"])(String(l))}) workers:\n${JSON.stringify({buildEntries:n},null,2)}`);const c=await createThreadWorker(l),d=new Listr([],{concurrent:l,exitOnError:!0}),m=[];for(const[r]of Object.entries(a))d.add({title:`Build module ${chalk(["magenta"])(r)} ...`,task:async()=>{const i=await c.startBuildWorker(e,r,jsonSerializer.stringify(t),o);m.push(i)}});if(d.tasks.length)try{await d.run()}catch(e){throw c.pool.terminate(),e}return c.pool.terminate(),m};
|
@@ -1,35 +1 @@
|
|
1
|
-
import webpack from
|
2
|
-
import { loadWebpackConfig } from '../create-webpack/load-webpack-config.js';
|
3
|
-
import { splitToMultiCompilerConfigs } from '../helpers/split-to-multi-compiler.js';
|
4
|
-
/**
|
5
|
-
* The helpers to build one entry at a time
|
6
|
-
* @param singleBuildEntry The single entry
|
7
|
-
* @param buildPublicPath
|
8
|
-
* @param evolveOptions
|
9
|
-
*/
|
10
|
-
export const startOneEntryBuild = async (singleBuildEntry, evolveOptions) => {
|
11
|
-
// Try to load webpack configuration
|
12
|
-
const webpackConfig = await loadWebpackConfig('production', singleBuildEntry, evolveOptions);
|
13
|
-
const compilerConfigs = splitToMultiCompilerConfigs(singleBuildEntry, webpackConfig, evolveOptions, false);
|
14
|
-
if (compilerConfigs.length > 1) {
|
15
|
-
throw new Error('startOneEntryBuild() only support `compiler` at a time');
|
16
|
-
}
|
17
|
-
const currCompiler = compilerConfigs[0];
|
18
|
-
// Run the single build.
|
19
|
-
return new Promise((resolve, reject) => {
|
20
|
-
webpack(currCompiler, (err, stats) => {
|
21
|
-
if (err) {
|
22
|
-
// Handle errors here
|
23
|
-
return reject(err);
|
24
|
-
}
|
25
|
-
const statsJson = stats?.toJson();
|
26
|
-
if (statsJson?.errors?.length) {
|
27
|
-
return reject(statsJson.errors);
|
28
|
-
}
|
29
|
-
if (evolveOptions.rejectWarnings && statsJson?.warnings?.length) {
|
30
|
-
return reject(statsJson.warnings);
|
31
|
-
}
|
32
|
-
resolve({ name: currCompiler.name, warningStats: statsJson?.warnings });
|
33
|
-
});
|
34
|
-
});
|
35
|
-
};
|
1
|
+
import webpack from"webpack";import{loadWebpackConfig}from"../create-webpack/load-webpack-config.js";import{splitToMultiCompilerConfigs}from"../helpers/split-to-multi-compiler.js";export const startOneEntryBuild=async(r,o)=>{const t=await loadWebpackConfig("production",r,o),n=splitToMultiCompilerConfigs(r,t,o,!1);if(n.length>1)throw new Error("startOneEntryBuild() only support `compiler` at a time");const e=n[0];return new Promise(((r,t)=>{webpack(e,((n,i)=>{if(n)return t(n);const a=i?.toJson();return a?.errors?.length?t(a.errors):o.rejectWarnings&&a?.warnings?.length?t(a.warnings):void r({name:e.name,warningStats:a?.warnings})}))}))};
|