@flatjs/evolve 2.1.0-next.5 → 2.1.0-next.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. package/dist/constants.js +1 -26
  2. package/dist/create-webpack/create-externals.js +1 -6
  3. package/dist/create-webpack/create-optimization.js +1 -41
  4. package/dist/create-webpack/create-output.js +1 -35
  5. package/dist/create-webpack/create-performance.js +1 -7
  6. package/dist/create-webpack/create-plugins.js +1 -77
  7. package/dist/create-webpack/create-resolve.js +1 -37
  8. package/dist/create-webpack/create-rule-sets.js +1 -19
  9. package/dist/create-webpack/load-webpack-config.js +1 -56
  10. package/dist/create-webpack/resolve-public-path.js +1 -15
  11. package/dist/create-webpack/rule-sets/constants.js +1 -3
  12. package/dist/create-webpack/rule-sets/rule-assets.js +1 -50
  13. package/dist/create-webpack/rule-sets/rule-css.js +1 -101
  14. package/dist/create-webpack/rule-sets/rule-less.js +1 -44
  15. package/dist/create-webpack/rule-sets/rule-scripts.js +1 -34
  16. package/dist/create-webpack/rule-sets/rule-svg-icon.js +1 -25
  17. package/dist/create-webpack/rule-sets/rule-utils.js +1 -10
  18. package/dist/create-webpack/types.js +1 -1
  19. package/dist/default-options.js +1 -84
  20. package/dist/define-config/define-config.js +1 -4
  21. package/dist/define-config/index.js +1 -1
  22. package/dist/dev-server/add-compiler-to-dev-server.js +1 -58
  23. package/dist/dev-server/create-app-page-route.js +1 -13
  24. package/dist/dev-server/create-dev-server-compiler-tasks.js +1 -52
  25. package/dist/dev-server/create-dev-server-entries.js +1 -27
  26. package/dist/dev-server/create-dev-server.js +1 -24
  27. package/dist/dev-server/index.js +1 -6
  28. package/dist/dev-server/middlewares/create-page-middleware.js +1 -33
  29. package/dist/dev-server/middlewares/create-public-assets-middleware.js +1 -25
  30. package/dist/dev-server/middlewares/get-all-sorted-modules.js +1 -24
  31. package/dist/dev-server/middlewares/get-bundle-asset.js +1 -7
  32. package/dist/dev-server/middlewares/get-dev-server-host-uri.js +1 -5
  33. package/dist/dev-server/middlewares/get-hmr-runtime-chunks.js +1 -14
  34. package/dist/dev-server/middlewares/get-normalized-entry-name.js +1 -14
  35. package/dist/dev-server/middlewares/get-page-main-html.js +1 -42
  36. package/dist/dev-server/middlewares/get-page-module-html.js +1 -120
  37. package/dist/dev-server/middlewares/get-project-virtual-path.js +1 -3
  38. package/dist/dev-server/middlewares/get-runtime-manifest.js +1 -25
  39. package/dist/dev-server/middlewares/index.js +1 -2
  40. package/dist/dev-server/middlewares/types.js +1 -1
  41. package/dist/errors/evolve-build-error.js +1 -10
  42. package/dist/helpers/allow-px2rem-for-module.js +1 -6
  43. package/dist/helpers/assert-only-single-entry-item.js +1 -23
  44. package/dist/helpers/chunk-entry-map.js +1 -21
  45. package/dist/helpers/enable-bundle-hashname-for-module.js +1 -6
  46. package/dist/helpers/filter-actived-entries.js +1 -42
  47. package/dist/helpers/get-bundle-file-name.js +1 -23
  48. package/dist/helpers/get-git-root.js +1 -4
  49. package/dist/helpers/get-html-plugin-config.js +1 -47
  50. package/dist/helpers/get-max-process-tasks.js +1 -7
  51. package/dist/helpers/get-pacakge-dir.js +1 -13
  52. package/dist/helpers/index.js +1 -17
  53. package/dist/helpers/json-serializer.js +1 -52
  54. package/dist/helpers/merge-babel-options.js +1 -45
  55. package/dist/helpers/normalize-entry-map.js +1 -38
  56. package/dist/helpers/normalize-page-proxy.js +1 -9
  57. package/dist/helpers/normalize-resolve-alias.js +1 -7
  58. package/dist/helpers/open-page.js +1 -15
  59. package/dist/helpers/print-log.js +1 -49
  60. package/dist/helpers/refresh-evolve-mock-options.js +1 -34
  61. package/dist/helpers/resolve-entry-map-input-files.js +1 -20
  62. package/dist/helpers/script-injects.js +1 -39
  63. package/dist/helpers/should-enable-react-fast-refresh.js +1 -10
  64. package/dist/helpers/split-to-multi-compiler.js +1 -32
  65. package/dist/index.js +1 -5
  66. package/dist/load-config/index.js +1 -1
  67. package/dist/load-config/load-evolve-config.js +1 -41
  68. package/dist/load-config/types.js +1 -1
  69. package/dist/main/create-thread-worker.js +1 -42
  70. package/dist/main/env-verify.js +1 -21
  71. package/dist/main/get-worker-path.js +1 -5
  72. package/dist/main/index.js +1 -4
  73. package/dist/main/prepare-build.js +1 -38
  74. package/dist/main/prepare-serve.js +1 -45
  75. package/dist/main/prepare-static.js +1 -30
  76. package/dist/main/start-build-dynamic.js +1 -157
  77. package/dist/main/start-build-worker.js +1 -46
  78. package/dist/main/start-build.js +1 -53
  79. package/dist/main/start-one-entry-build.js +1 -35
  80. package/dist/main/start-serve.js +1 -34
  81. package/dist/main/start-static.js +1 -19
  82. package/dist/minimizer/create-minimizers.js +1 -25
  83. package/dist/minimizer/default-options.js +1 -14
  84. package/dist/minimizer/image-minimizer.js +1 -65
  85. package/dist/minimizer/index.js +1 -1
  86. package/dist/minimizer/terser-minimizer.js +3 -15
  87. package/dist/minimizer/types.js +1 -1
  88. package/dist/plugins/circular-dependency/circular-dependency-plugin.js +1 -119
  89. package/dist/plugins/circular-dependency/index.js +1 -15
  90. package/dist/plugins/clean-webpack/clean-webpack-plugin.js +1 -173
  91. package/dist/plugins/clean-webpack/index.js +1 -22
  92. package/dist/plugins/define-variable/define-variable-plugin.js +1 -28
  93. package/dist/plugins/define-variable/index.js +1 -1
  94. package/dist/plugins/html-inject-scripts/plugin-html-inject-script.js +1 -27
  95. package/dist/plugins/module-federation/external-template-remotes.js +1 -92
  96. package/dist/plugins/module-federation/index.js +1 -1
  97. package/dist/plugins/module-federation/module-federation.js +1 -98
  98. package/dist/plugins/multi-html/index.js +1 -15
  99. package/dist/plugins/multi-html/multi-html-cdn-plugin.js +1 -84
  100. package/dist/plugins/multi-html/multi-html-plugin.js +1 -70
  101. package/dist/plugins/ts-checker/index.js +1 -1
  102. package/dist/plugins/ts-checker/ts-checker-plugin.js +1 -18
  103. package/dist/types/index.js +1 -8
  104. package/dist/types/types-ci.js +1 -1
  105. package/dist/types/types-dev-server.js +1 -1
  106. package/dist/types/types-entry-map.js +1 -1
  107. package/dist/types/types-federation.js +1 -1
  108. package/dist/types/types-loader-options.js +1 -1
  109. package/dist/types/types-modular-import.js +1 -1
  110. package/dist/types/types-multi-html.js +1 -1
  111. package/dist/types/types-options.js +1 -1
  112. package/dist/types/types-plugin-options.js +1 -1
  113. package/dist/types/types-webpack.js +1 -1
  114. package/package.json +2 -2
@@ -1,32 +1 @@
1
- import { join } from 'path';
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 * from './define-config/index.js';
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 * from './load-evolve-config.js';
1
+ export*from"./load-evolve-config.js";
@@ -1,41 +1 @@
1
- import { searchConfig } from '@armit/config-loader';
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 'events';
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})};
@@ -1,21 +1 @@
1
- import { illegalPackageChecker, keepPackageDepsUpToDateForNonMonoRepo, } from '@armit/package';
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 { pathToFileURL } from 'node:url';
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();
@@ -1,4 +1 @@
1
- export * from './start-build.js';
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 } from '@flatjs/common';
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 { arrayUnique, urlJoin } from '@flatjs/common';
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 { chalk, logger, urlJoin } from '@flatjs/common';
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 { isAbsolute, join } from 'node:path';
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 { requireResolve } from '@flatjs/common';
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)};
@@ -1,53 +1 @@
1
- import { chalk, logger, requireResolve } from '@flatjs/common';
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 'webpack';
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})}))}))};