@flatjs/evolve 2.1.0-next.12 → 2.1.0-next.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. package/dist/compiler/create-global-compiler.d.ts +2 -0
  2. package/dist/compiler/create-global-compiler.js +1 -0
  3. package/dist/constants.js +1 -36
  4. package/dist/create-webpack/create-externals.js +1 -6
  5. package/dist/create-webpack/create-optimization.js +1 -43
  6. package/dist/create-webpack/create-output.js +1 -35
  7. package/dist/create-webpack/create-performance.js +1 -7
  8. package/dist/create-webpack/create-plugins.js +1 -78
  9. package/dist/create-webpack/create-resolve.js +1 -37
  10. package/dist/create-webpack/create-rule-sets.js +1 -20
  11. package/dist/create-webpack/load-watch-options.d.ts +12 -0
  12. package/dist/create-webpack/load-watch-options.js +1 -0
  13. package/dist/create-webpack/load-webpack-config.js +1 -57
  14. package/dist/create-webpack/resolve-public-path.js +1 -15
  15. package/dist/create-webpack/rule-sets/constants.js +1 -3
  16. package/dist/create-webpack/rule-sets/rule-assets.js +1 -52
  17. package/dist/create-webpack/rule-sets/rule-css.js +1 -111
  18. package/dist/create-webpack/rule-sets/rule-less.js +1 -44
  19. package/dist/create-webpack/rule-sets/rule-scripts.d.ts +2 -0
  20. package/dist/create-webpack/rule-sets/rule-scripts.js +1 -34
  21. package/dist/create-webpack/rule-sets/rule-svg-icon.js +1 -25
  22. package/dist/create-webpack/rule-sets/rule-utils.js +1 -10
  23. package/dist/create-webpack/types.d.ts +1 -1
  24. package/dist/create-webpack/types.js +1 -1
  25. package/dist/default-options.js +1 -83
  26. package/dist/define-config/define-config.d.ts +2 -2
  27. package/dist/define-config/define-config.js +1 -4
  28. package/dist/define-config/index.js +1 -1
  29. package/dist/dev-server/add-compiler-to-dev-server.js +1 -58
  30. package/dist/dev-server/create-app-page-route.js +1 -13
  31. package/dist/dev-server/create-dev-server-compiler-task.js +1 -55
  32. package/dist/dev-server/create-dev-server-entries.js +1 -25
  33. package/dist/dev-server/create-dev-server.js +1 -24
  34. package/dist/dev-server/index.d.ts +3 -3
  35. package/dist/dev-server/index.js +1 -6
  36. package/dist/dev-server/middlewares/create-page-middleware.js +1 -33
  37. package/dist/dev-server/middlewares/create-public-assets-middleware.js +1 -25
  38. package/dist/dev-server/middlewares/get-all-sorted-modules.js +1 -24
  39. package/dist/dev-server/middlewares/get-bundle-asset.js +1 -7
  40. package/dist/dev-server/middlewares/get-dev-server-host-uri.js +1 -5
  41. package/dist/dev-server/middlewares/get-hmr-runtime-chunks.js +1 -14
  42. package/dist/dev-server/middlewares/get-normalized-entry-name.js +1 -14
  43. package/dist/dev-server/middlewares/get-page-main-html.js +1 -49
  44. package/dist/dev-server/middlewares/get-page-module-html.js +1 -123
  45. package/dist/dev-server/middlewares/get-project-virtual-path.js +1 -3
  46. package/dist/dev-server/middlewares/get-runtime-manifest.js +1 -25
  47. package/dist/dev-server/middlewares/index.js +1 -2
  48. package/dist/dev-server/middlewares/types.js +1 -1
  49. package/dist/errors/evolve-build-error.js +1 -10
  50. package/dist/helpers/allow-px2rem-for-module.js +1 -6
  51. package/dist/helpers/assert-group-entry-item.js +1 -19
  52. package/dist/helpers/assert-single-compiler.js +1 -45
  53. package/dist/helpers/chunk-entry-map.js +1 -21
  54. package/dist/helpers/delete-object-keys.js +1 -20
  55. package/dist/helpers/enable-bundle-hashname-for-module.js +1 -6
  56. package/dist/helpers/filter-actived-entries.js +1 -42
  57. package/dist/helpers/flat-entry-map.js +1 -11
  58. package/dist/helpers/get-bundle-file-name.js +1 -23
  59. package/dist/helpers/get-git-root.js +1 -4
  60. package/dist/helpers/get-html-plugin-config.js +1 -47
  61. package/dist/helpers/get-max-process-tasks.js +1 -7
  62. package/dist/helpers/get-pacakge-dir.js +1 -13
  63. package/dist/helpers/get-runtime-cdn-base.d.ts +1 -1
  64. package/dist/helpers/get-runtime-cdn-base.js +1 -21
  65. package/dist/helpers/index.d.ts +11 -11
  66. package/dist/helpers/index.js +1 -27
  67. package/dist/helpers/is-deep-equal.js +1 -67
  68. package/dist/helpers/json-serializer.js +1 -52
  69. package/dist/helpers/merge-babel-options.js +1 -45
  70. package/dist/helpers/normalize-check-entry-options.js +1 -28
  71. package/dist/helpers/normalize-entry-map.js +1 -59
  72. package/dist/helpers/normalize-group-name.js +1 -16
  73. package/dist/helpers/normalize-page-proxy.js +1 -9
  74. package/dist/helpers/normalize-resolve-alias.js +1 -7
  75. package/dist/helpers/normalize-template-inject-tokens.js +1 -22
  76. package/dist/helpers/open-page.js +1 -15
  77. package/dist/helpers/print-log.js +1 -49
  78. package/dist/helpers/refresh-evolve-mock-options.js +1 -34
  79. package/dist/helpers/resolve-entry-map-input-files.js +1 -20
  80. package/dist/helpers/script-injects.d.ts +1 -1
  81. package/dist/helpers/script-injects.js +1 -39
  82. package/dist/helpers/should-enable-react-fast-refresh.js +1 -14
  83. package/dist/helpers/split-to-entry-group.d.ts +1 -1
  84. package/dist/helpers/split-to-entry-group.js +1 -139
  85. package/dist/helpers/verify-group-entry-options.js +1 -21
  86. package/dist/index.d.ts +1 -1
  87. package/dist/index.js +1 -5
  88. package/dist/load-config/index.js +1 -1
  89. package/dist/load-config/load-evolve-config.js +1 -41
  90. package/dist/load-config/types.js +1 -1
  91. package/dist/loaders/loader-icon.cjs +2 -1
  92. package/dist/main/create-thread-worker.js +1 -51
  93. package/dist/main/env-verify.js +1 -21
  94. package/dist/main/get-worker-path.js +1 -5
  95. package/dist/main/index.d.ts +1 -1
  96. package/dist/main/index.js +1 -4
  97. package/dist/main/prepare-build.js +1 -39
  98. package/dist/main/prepare-serve.js +1 -69
  99. package/dist/main/prepare-static.js +1 -30
  100. package/dist/main/start-build-dynamic.js +1 -171
  101. package/dist/main/start-build-worker.js +1 -44
  102. package/dist/main/start-build.js +1 -69
  103. package/dist/main/start-group-entry-build.d.ts +1 -1
  104. package/dist/main/start-group-entry-build.js +1 -32
  105. package/dist/main/start-serve.js +1 -34
  106. package/dist/main/start-static.js +1 -19
  107. package/dist/minimizer/create-minimizers.js +1 -25
  108. package/dist/minimizer/default-options.js +1 -14
  109. package/dist/minimizer/image-minimizer.js +1 -65
  110. package/dist/minimizer/index.js +1 -1
  111. package/dist/minimizer/terser-minimizer.js +3 -15
  112. package/dist/minimizer/types.js +1 -1
  113. package/dist/plugins/circular-dependency/circular-dependency-plugin.js +1 -119
  114. package/dist/plugins/circular-dependency/index.js +1 -15
  115. package/dist/plugins/clean-webpack/clean-webpack-plugin.js +1 -173
  116. package/dist/plugins/clean-webpack/index.js +1 -22
  117. package/dist/plugins/define-variable/define-variable-plugin.js +1 -28
  118. package/dist/plugins/define-variable/index.js +1 -1
  119. package/dist/plugins/html-inject-scripts/plugin-html-inject-script.js +1 -27
  120. package/dist/plugins/module-federation/external-template-remotes.js +1 -92
  121. package/dist/plugins/module-federation/index.js +1 -1
  122. package/dist/plugins/module-federation/module-federation.js +1 -100
  123. package/dist/plugins/multi-html/index.js +1 -16
  124. package/dist/plugins/multi-html/multi-html-cdn-plugin.js +1 -83
  125. package/dist/plugins/multi-html/multi-html-plugin.js +1 -65
  126. package/dist/plugins/ts-checker/ts-checker-guard-plugin.d.ts +13 -0
  127. package/dist/plugins/ts-checker/ts-checker-guard-plugin.js +1 -0
  128. package/dist/plugins/ts-checker/ts-checker-plugin.d.ts +1 -2
  129. package/dist/plugins/ts-checker/ts-checker-plugin.js +1 -24
  130. package/dist/types/index.d.ts +2 -1
  131. package/dist/types/index.js +1 -8
  132. package/dist/types/types-ci.js +1 -1
  133. package/dist/types/types-dev-server.d.ts +5 -6
  134. package/dist/types/types-dev-server.js +1 -1
  135. package/dist/types/types-entry-map.js +1 -1
  136. package/dist/types/types-federation.js +1 -1
  137. package/dist/types/types-global-compiler-options.d.ts +7 -0
  138. package/dist/types/types-global-compiler-options.js +1 -0
  139. package/dist/types/types-loader-options.d.ts +2 -7
  140. package/dist/types/types-loader-options.js +1 -1
  141. package/dist/types/types-modular-import.js +1 -1
  142. package/dist/types/types-multi-html.js +1 -1
  143. package/dist/types/types-options.d.ts +6 -1
  144. package/dist/types/types-options.js +1 -1
  145. package/dist/types/types-plugin-options.js +1 -1
  146. package/dist/types/types-threads-options.js +1 -1
  147. package/dist/types/types-webpack.d.ts +1 -1
  148. package/dist/types/types-webpack.js +1 -1
  149. package/package.json +30 -32
  150. package/dist/plugins/ts-checker/index.d.ts +0 -1
  151. package/dist/plugins/ts-checker/index.js +0 -1
@@ -1,123 +1 @@
1
- import { existsSync, readFileSync } from 'node:fs';
2
- import { isAbsolute, join } from 'node:path';
3
- import { ensureSlash, urlJoin } from '@flatjs/common';
4
- import _ from 'lodash';
5
- import { allowPx2remForModule } from '../../helpers/allow-px2rem-for-module.js';
6
- import { getHtmlPluginConfig, } from '../../helpers/get-html-plugin-config.js';
7
- import { getPackageDir } from '../../helpers/get-pacakge-dir.js';
8
- import { getRuntimeCDNBase } from '../../helpers/get-runtime-cdn-base.js';
9
- import { normalizeEvolveEntryName } from '../../helpers/normalize-entry-map.js';
10
- import { normalizePageProxy } from '../../helpers/normalize-page-proxy.js';
11
- import { normalizeTemplateInjectTokens } from '../../helpers/normalize-template-inject-tokens.js';
12
- import { injectFederationScripts } from '../../helpers/script-injects.js';
13
- import { getBundleAsset } from './get-bundle-asset.js';
14
- import { getDevServerHostUri } from './get-dev-server-host-uri.js';
15
- import { getHmrRuntimeChunks } from './get-hmr-runtime-chunks.js';
16
- import { getNormalizedEntryName } from './get-normalized-entry-name.js';
17
- export const getPageModuleHtml = async (servedDevServerEntries, req, devHostUri, apiContext, evolveOptions
18
- // eslint-disable-next-line sonarjs/cognitive-complexity
19
- ) => {
20
- const { entryMap, projectVirtualPath } = evolveOptions;
21
- // normalize to ['a/b','a/b/c','inn/app/transfer_list','inn/app/transfer']
22
- const entryNames = Object.keys(entryMap).sort((a, b) => b.length - a.length);
23
- const evolveCwd = getPackageDir();
24
- const currEntryName = entryNames.find((entryName) => {
25
- const normalizedEntryName = normalizeEvolveEntryName(entryName, projectVirtualPath);
26
- return ensureSlash(req.path.replace(/^\//, ''), true).startsWith(ensureSlash(normalizedEntryName, true));
27
- });
28
- if (!currEntryName) {
29
- const notFoundTemplateStr = readFileSync(join(evolveCwd, `./templates/module-404.html`), 'utf-8');
30
- return _.template(notFoundTemplateStr)({
31
- title: '404 Not Found',
32
- errorMeta: [
33
- {
34
- name: `@flatjs/evolve workspace`,
35
- value: evolveCwd,
36
- },
37
- {
38
- name: `served entry names`,
39
- value: JSON.stringify(entryNames),
40
- },
41
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
42
- { name: `module path`, value: `${req.path}` },
43
- ],
44
- });
45
- }
46
- const currEntryItem = entryMap[currEntryName];
47
- const currEntryOption = currEntryItem.options;
48
- // currEntry: `home`
49
- const devServerHostUri = getDevServerHostUri(servedDevServerEntries, currEntryName, devHostUri);
50
- const moduleTemplate =
51
- // eslint-disable-next-line sonarjs/no-duplicate-string
52
- currEntryOption?.serveModuleTemplate || './templates/module.html';
53
- const projectHostedModuleTemplate = join(evolveOptions.projectCwd, './templates/module.html');
54
- const templateStr = readFileSync(isAbsolute(moduleTemplate)
55
- ? moduleTemplate
56
- : existsSync(projectHostedModuleTemplate)
57
- ? projectHostedModuleTemplate
58
- : join(evolveCwd, './templates/module.html'), 'utf-8');
59
- const devServer = evolveOptions.devServer;
60
- const defaultGlobalData = devServer?.defaultServeGlobalData
61
- ? await devServer.defaultServeGlobalData(currEntryItem, devHostUri)
62
- : {};
63
- const configData = {
64
- mode: 'development',
65
- // FIXME: always use `devHostUri` as served local `cdn`, if you want to serve `anther` module
66
- // you need to generate cdn path manually.
67
- envCdn: urlJoin(devHostUri, ['public']),
68
- };
69
- // Get normalized entry name
70
- const normalizedEntryName = getNormalizedEntryName(currEntryName, projectVirtualPath, servedDevServerEntries, devServer);
71
- const pageProxy = normalizePageProxy(devServer?.pageProxy || '/pages');
72
- const injectInlineScripts = [
73
- // inject runtime cdn base
74
- getRuntimeCDNBase(evolveOptions.multiHtmlCdn, evolveOptions.multiHtmlCdnEnvResolver ||
75
- function cdnResolver() {
76
- return undefined;
77
- }),
78
- ];
79
- const templateInjectTokens = normalizeTemplateInjectTokens(configData, currEntryOption);
80
- const templateData = {
81
- // title
82
- title: getHtmlPluginConfig('title', configData, currEntryOption?.title),
83
- // favicon
84
- favicon: getHtmlPluginConfig('favicon', configData, currEntryOption?.favicon),
85
- // `allowPx2rem` default is true
86
- viewport: allowPx2remForModule([currEntryName, currEntryItem], evolveOptions)
87
- ? getHtmlPluginConfig('viewport', configData, currEntryOption?.viewport)
88
- : '',
89
- ...templateInjectTokens,
90
- // Allow us customized inline scripts into compiled html template.
91
- inlineScripts: templateInjectTokens.inlineScripts?.concat(injectInlineScripts),
92
- // Module Federation, Only for `static` mode, `serve` mode it will use entryItemConfig.endpoint()
93
- moduleFederationScripts: injectFederationScripts({
94
- me: [urlJoin(devHostUri, ['public'])],
95
- }, evolveOptions.multiHtmlCdnEnvResolver),
96
- // The global data.
97
- global: {
98
- hostUrl: devHostUri,
99
- apiBase: urlJoin(devHostUri, [apiContext]),
100
- virtualPath: join(pageProxy, projectVirtualPath),
101
- moduleName: currEntryName
102
- .replace(projectVirtualPath, '')
103
- .replace(/^\//, ''),
104
- ...defaultGlobalData,
105
- ...(currEntryOption?.serveGlobalData || {}),
106
- },
107
- styles: [getBundleAsset(devServerHostUri, normalizedEntryName, '.css')],
108
- scripts: [getBundleAsset(devServerHostUri, normalizedEntryName, '.js')],
109
- };
110
- if (!templateData.headBeforeHtmlTags) {
111
- templateData.headBeforeHtmlTags = [];
112
- }
113
- else {
114
- // Avoid deep object reference here.
115
- templateData.headBeforeHtmlTags = templateData.headBeforeHtmlTags.slice(0);
116
- }
117
- // Indicates current we use `hot` mode for `webpack-dev-server` hot reload true.
118
- const devRuntimeChunks = getHmrRuntimeChunks(servedDevServerEntries, currEntryName, normalizedEntryName, currEntryItem, evolveOptions, devServerHostUri);
119
- devRuntimeChunks.forEach((runtimeChunk) => {
120
- templateData.headBeforeHtmlTags?.push(`<script src="${runtimeChunk}"></script>`);
121
- });
122
- return _.template(templateStr)(templateData);
123
- };
1
+ import _ from"lodash";import{existsSync,readFileSync}from"node:fs";import{isAbsolute,join}from"node:path";import{ensureSlash,urlJoin}from"@flatjs/common";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";import{getPackageDir}from"../../helpers/get-pacakge-dir.js";import{getRuntimeCDNBase}from"../../helpers/get-runtime-cdn-base.js";import{normalizeEvolveEntryName}from"../../helpers/normalize-entry-map.js";import{normalizePageProxy}from"../../helpers/normalize-page-proxy.js";import{normalizeTemplateInjectTokens}from"../../helpers/normalize-template-inject-tokens.js";import{injectFederationScripts}from"../../helpers/script-injects.js";import{getBundleAsset}from"./get-bundle-asset.js";import{getDevServerHostUri}from"./get-dev-server-host-uri.js";import{getHmrRuntimeChunks}from"./get-hmr-runtime-chunks.js";import{getNormalizedEntryName}from"./get-normalized-entry-name.js";export const getPageModuleHtml=async(e,t,r,o,l)=>{const{entryMap:a,projectVirtualPath:i}=l,n=Object.keys(a).sort(((e,t)=>t.length-e.length)),m=getPackageDir(),s=n.find((e=>{const r=normalizeEvolveEntryName(e,i);return ensureSlash(t.path.replace(/^\//,""),!0).startsWith(ensureSlash(r,!0))}));if(!s){const e=readFileSync(join(m,"./templates/module-404.html"),"utf-8");return _.template(e)({title:"404 Not Found",errorMeta:[{name:"@flatjs/evolve workspace",value:m},{name:"served entry names",value:JSON.stringify(n)},{name:"module path",value:`${t.path}`}]})}const p=a[s],u=p.options,c=getDevServerHostUri(e,s,r),g=u?.serveModuleTemplate||"./templates/module.html",d=join(l.projectCwd,"./templates/module.html"),f=readFileSync(isAbsolute(g)?g:existsSync(d)?d:join(m,"./templates/module.html"),"utf-8"),h=l.devServer,v=h?.defaultServeGlobalData?await h.defaultServeGlobalData(p,r):{},j={mode:"development",envCdn:urlJoin(r,["public"])},y=getNormalizedEntryName(s,i,e,h),S=normalizePageProxy(h?.pageProxy||"/pages"),H=[getRuntimeCDNBase(l.multiHtmlCdn,l.multiHtmlCdnEnvResolver||function cdnResolver(){})],P=normalizeTemplateInjectTokens(j,u),C={title:getHtmlPluginConfig("title",j,u?.title),favicon:getHtmlPluginConfig("favicon",j,u?.favicon),viewport:allowPx2remForModule([s,p],l)?getHtmlPluginConfig("viewport",j,u?.viewport):"",...P,inlineScripts:P.inlineScripts?.concat(H),moduleFederationScripts:injectFederationScripts({me:[urlJoin(r,["public"])]},l.multiHtmlCdnEnvResolver),global:{hostUrl:r,apiBase:urlJoin(r,[o]),virtualPath:join(S,i),moduleName:s.replace(i,"").replace(/^\//,""),...v,...u?.serveGlobalData||{}},styles:[getBundleAsset(c,y,".css")],scripts:[getBundleAsset(c,y,".js")]};C.headBeforeHtmlTags?C.headBeforeHtmlTags=C.headBeforeHtmlTags.slice(0):C.headBeforeHtmlTags=[];return getHmrRuntimeChunks(e,s,y,p,l,c).forEach((e=>{C.headBeforeHtmlTags?.push(`<script src="${e}"><\/script>`)})),_.template(f)(C)};
@@ -1,3 +1 @@
1
- export const getProjectVirtualPath = (evolveOptions) => {
2
- return evolveOptions.projectVirtualPath.replace(/^\//, '');
3
- };
1
+ export const getProjectVirtualPath=t=>t.projectVirtualPath.replace(/^\//,"");
@@ -1,25 +1 @@
1
- import { getSortedModules } from './get-all-sorted-modules.js';
2
- import { getBundleAsset } from './get-bundle-asset.js';
3
- import { getHmrRuntimeChunks } from './get-hmr-runtime-chunks.js';
4
- export const getRuntimeManifest = async (servedDevServerEntries, devHostUri, evolveOptions) => {
5
- const sortedModules = getSortedModules(evolveOptions, servedDevServerEntries, devHostUri);
6
- const runtimeManifest = {};
7
- for (const moduleItem of sortedModules) {
8
- const { entryName, isServedEntry, entryContent, devServerHostUri, normalizedEntryName, } = moduleItem;
9
- const bundleScripts = [
10
- getBundleAsset(devServerHostUri, normalizedEntryName, '.js'),
11
- ];
12
- const bundleStyles = [
13
- getBundleAsset(devServerHostUri, normalizedEntryName, '.css'),
14
- ];
15
- const hmrRuntimeChunks = getHmrRuntimeChunks(servedDevServerEntries, entryName, normalizedEntryName, entryContent, evolveOptions, devServerHostUri);
16
- runtimeManifest[normalizedEntryName] = {
17
- entryName,
18
- styles: bundleStyles,
19
- scripts: bundleScripts,
20
- isServed: isServedEntry,
21
- runtimeChunks: hmrRuntimeChunks,
22
- };
23
- }
24
- return runtimeManifest;
25
- };
1
+ import{getSortedModules}from"./get-all-sorted-modules.js";import{getBundleAsset}from"./get-bundle-asset.js";import{getHmrRuntimeChunks}from"./get-hmr-runtime-chunks.js";export const getRuntimeManifest=async(e,t,s)=>{const r=getSortedModules(s,e,t),n={};for(const t of r){const{entryName:r,isServedEntry:o,entryContent:m,devServerHostUri:u,normalizedEntryName:d}=t,i=[getBundleAsset(u,d,".js")],g=[getBundleAsset(u,d,".css")],l=getHmrRuntimeChunks(e,r,d,m,s,u);n[d]={entryName:r,styles:g,scripts:i,isServed:o,runtimeChunks:l}}return n};
@@ -1,2 +1 @@
1
- export * from './create-page-middleware.js';
2
- export * from './create-public-assets-middleware.js';
1
+ export*from"./create-page-middleware.js";export*from"./create-public-assets-middleware.js";
@@ -1 +1 @@
1
- export {};
1
+ export{};
@@ -1,10 +1 @@
1
- export class EvolveBuildError extends Error {
2
- constructor(code, messages) {
3
- let message = code;
4
- if (messages) {
5
- message += ': ' + JSON.stringify(messages);
6
- }
7
- super(message);
8
- this.code = code;
9
- }
10
- }
1
+ export class EvolveBuildError extends Error{constructor(r,e){let o=r;e&&(o+=": "+JSON.stringify(e)),super(o),this.code=r}}
@@ -1,6 +1 @@
1
- export const allowPx2remForModule = (entryItem, evolveOptions) => {
2
- // Global settings for `AllowPx2Rem`
3
- const globalAllowPx2Rem = evolveOptions?.loaderOptions?.pixelOptions;
4
- const currItemPx2Rem = (entryItem && entryItem[1]?.options?.allowPx2rem) ?? globalAllowPx2Rem;
5
- return !!currItemPx2Rem;
6
- };
1
+ export const allowPx2remForModule=(o,e)=>{const l=e?.loaderOptions?.pixelOptions;return!!((o&&o[1]?.options?.allowPx2rem)??l)};
@@ -1,19 +1 @@
1
- import { normalizeEvolveEntryName } from './normalize-entry-map.js';
2
- /**
3
- * Only fetch group entry map once `serve`,`build` recycle.
4
- * @returns
5
- */
6
- export const assertGroupEntryItem = (entryMap, evolveOptions) => {
7
- const result = [];
8
- for (const [entryChunkName, entryItem] of Object.entries(entryMap)) {
9
- result.push([entryChunkName, entryItem]);
10
- }
11
- if (!result.length) {
12
- throw new Error(`No entry map found while "serve", "build" process!`);
13
- }
14
- return result.map(([entryName, entryConfig]) => {
15
- // Make sure that we have correct `virtualPath` for each webpack `entry`
16
- const normalizedEntryName = normalizeEvolveEntryName(entryName, evolveOptions.projectVirtualPath);
17
- return [normalizedEntryName, entryConfig];
18
- });
19
- };
1
+ import{normalizeEvolveEntryName}from"./normalize-entry-map.js";export const assertGroupEntryItem=(r,e)=>{const o=[];for(const[e,t]of Object.entries(r))o.push([e,t]);if(!o.length)throw new Error('No entry map found while "serve", "build" process!');return o.map((([r,o])=>[normalizeEvolveEntryName(r,e.projectVirtualPath),o]))};
@@ -1,45 +1 @@
1
- import { dirname, join } from 'path';
2
- import { searchPackageDir } from '@armit/package';
3
- import { mergeOptions, requireResolve } from '@flatjs/common';
4
- import { devReactFastRefresh } from '../constants.js';
5
- import { normalizeEvolveEntryName } from './normalize-entry-map.js';
6
- /**
7
- * Asserts a single compiler configuration by generating a new entry object based on the served entries,
8
- * webpack configuration, evolve options, and enabled HMR flag.
9
- *
10
- * @param servedEntries - The served entries object.
11
- * @param webpackConfig `Omit<Configuration, 'entry'>` webpack final configuration
12
- * @param evolveOptions - The flat evolve options object.
13
- * @param enabledHmr - Flag indicating whether Hot Module Replacement (HMR) is enabled. Default is false.
14
- * @returns The merged webpack configuration object with the new entry object.
15
- * @throws Error if the react-refresh-webpack-plugin package directory is not found.
16
- */
17
- export function assertSingleCompiler(servedEntries, webpackConfig, evolveOptions, enabledHmr = false) {
18
- const newEntry = {};
19
- for (const [entryName, entryItem] of Object.entries(servedEntries)) {
20
- // Make sure that we have correct `virtualPath` for each webpack `entry`
21
- const normalizedEntryName = normalizeEvolveEntryName(entryName, evolveOptions.projectVirtualPath);
22
- newEntry[normalizedEntryName] = entryItem.entry;
23
- if (enabledHmr) {
24
- // `${virtualPath}/module/reactRefreshSetup`
25
- const fastRefreshEntryName = join(normalizedEntryName, devReactFastRefresh.reactRefreshSetup);
26
- const reactRefresh = requireResolve(import.meta.url, '@pmmmwh/react-refresh-webpack-plugin');
27
- const reactRefreshPackageDir = searchPackageDir({
28
- cwd: dirname(reactRefresh),
29
- });
30
- // Make sure that we have a correct `react-refresh-webpack-plugin` package directory
31
- // Sometimes the dynamic load package has been deduped and the package directory is not correct
32
- if (!reactRefreshPackageDir) {
33
- throw new Error('react-refresh-webpack-plugin package directory not found');
34
- }
35
- newEntry[fastRefreshEntryName] = [
36
- join(reactRefreshPackageDir, '/client/ReactRefreshEntry.js'),
37
- ];
38
- }
39
- }
40
- const groupName = Object.values(servedEntries)[0].groupName;
41
- return mergeOptions(webpackConfig, {
42
- name: groupName,
43
- entry: newEntry,
44
- });
45
- }
1
+ import{dirname,join}from"path";import{searchPackageDir}from"@armit/package";import{mergeOptions,requireResolve}from"@flatjs/common";import{devReactFastRefresh}from"../constants.js";import{normalizeEvolveEntryName}from"./normalize-entry-map.js";export function assertSingleCompiler(e,r,t,o=!1){const a={};for(const[r,n]of Object.entries(e)){const e=normalizeEvolveEntryName(r,t.projectVirtualPath);if(a[e]=n.entry,o){const r=join(e,devReactFastRefresh.reactRefreshSetup),t=requireResolve(import.meta.url,"@pmmmwh/react-refresh-webpack-plugin"),o=searchPackageDir({cwd:dirname(t)});if(!o)throw new Error("react-refresh-webpack-plugin package directory not found");a[r]=[join(o,"/client/ReactRefreshEntry.js")]}}const n=Object.values(e)[0].groupName;return mergeOptions(r,{name:n,entry:a})}
@@ -1,21 +1 @@
1
- import { arrayChunk } from '@flatjs/common';
2
- /**
3
- * Split entryMap into multi entryMap with a `size`
4
- * @param entryMap
5
- * @param size
6
- */
7
- export const chunkEntryMap = (entryMap, size = 2) => {
8
- const keys = Object.keys(entryMap);
9
- const entryKeyChunks = arrayChunk(keys, size);
10
- const finalEntryMaps = [];
11
- for (const keys of entryKeyChunks) {
12
- const chunkMap = keys.reduce((prev, curr) => {
13
- return {
14
- ...prev,
15
- [curr]: entryMap[curr],
16
- };
17
- }, {});
18
- finalEntryMaps.push(chunkMap);
19
- }
20
- return finalEntryMaps;
21
- };
1
+ import{arrayChunk}from"@flatjs/common";export const chunkEntryMap=(r,o=2)=>{const n=Object.keys(r),t=arrayChunk(n,o),c=[];for(const o of t){const n=o.reduce(((o,n)=>({...o,[n]:r[n]})),{});c.push(n)}return c};
@@ -1,20 +1 @@
1
- /**
2
- * Deletes specified keys from an object and returns a new object without those keys.
3
- * If the input object is undefined, the function returns undefined.
4
- *
5
- * @param obj - The input object.
6
- * @param keys - An array of keys to be deleted from the object.
7
- * @returns A new object without the specified keys, or undefined if the input object is undefined.
8
- *
9
- * @template T - The type of the input object.
10
- */
11
- export const deleteObjectKeys = (obj, keys = []) => {
12
- if (!obj) {
13
- return undefined;
14
- }
15
- const newObj = { ...obj };
16
- keys.forEach((key) => {
17
- delete newObj[key];
18
- });
19
- return newObj;
20
- };
1
+ export const deleteObjectKeys=(e,t=[])=>{if(!e)return;const r={...e};return t.forEach((e=>{delete r[e]})),r};
@@ -1,6 +1 @@
1
- export const enableBundleHashNameForModule = (evolveOptions, entryItemOption) => {
2
- // Global settings for `enableBundleHashName`
3
- const globalEnabledStatus = evolveOptions.webpack?.enableBundleHashName;
4
- const bundleHashNameEnabled = entryItemOption?.enableBundleHashName ?? globalEnabledStatus;
5
- return !!bundleHashNameEnabled;
6
- };
1
+ export const enableBundleHashNameForModule=(e,a)=>{const n=e.webpack?.enableBundleHashName;return!!(a?.enableBundleHashName??n)};
@@ -1,42 +1 @@
1
- import { arraysIntersect, normalizeSemicolonFilterParts } from '@flatjs/common';
2
- import { resolveEntryMapInputFiles } from './resolve-entry-map-input-files.js';
3
- /**
4
- * Filter to find actived entry input by entry name filter.
5
- * @param definedEntries
6
- * @param modules `home;mine;`
7
- * @returns activedEntries
8
- */
9
- export const filterActivedEntriesByModule = (definedEntries, modules) => {
10
- const patterns = normalizeSemicolonFilterParts(modules);
11
- const newActivedEntries = {};
12
- for (const [entryKey, itemConfig] of Object.entries(definedEntries)) {
13
- const matched = patterns.find((m) => {
14
- // Also need to support `numeric` named module.
15
- const testRegExp = typeof m === 'string' || typeof m === 'number' ? new RegExp(`${m}`) : m;
16
- return testRegExp.test(entryKey);
17
- });
18
- if (matched) {
19
- newActivedEntries[entryKey] = itemConfig;
20
- }
21
- }
22
- return newActivedEntries;
23
- };
24
- /**
25
- * Filter to find actived entry input by absolute entry filepath
26
- * @param projectCwd
27
- * @param definedEntries
28
- * @param entryInputs [`/xxxx/x/xxxx/src/home/index.tsx`]
29
- * @returns activedEntries
30
- */
31
- export const filterActivedEntriesByEntryInputs = async (projectCwd, definedEntries, entryInputs) => {
32
- const newActivedEntries = {};
33
- for (const [entryKey, itemConfig] of Object.entries(definedEntries)) {
34
- const entryAbsFiles = await resolveEntryMapInputFiles(projectCwd, {
35
- [entryKey]: itemConfig,
36
- });
37
- if (arraysIntersect(entryAbsFiles, entryInputs)) {
38
- newActivedEntries[entryKey] = itemConfig;
39
- }
40
- }
41
- return newActivedEntries;
42
- };
1
+ import{arraysIntersect,normalizeSemicolonFilterParts}from"@flatjs/common";import{resolveEntryMapInputFiles}from"./resolve-entry-map-input-files.js";export const filterActivedEntriesByModule=(t,e)=>{const r=normalizeSemicolonFilterParts(e),n={};for(const[e,o]of Object.entries(t)){r.find((t=>("string"==typeof t||"number"==typeof t?new RegExp(`${t}`):t).test(e)))&&(n[e]=o)}return n};export const filterActivedEntriesByEntryInputs=async(t,e,r)=>{const n={};for(const[o,s]of Object.entries(e)){const e=await resolveEntryMapInputFiles(t,{[o]:s});arraysIntersect(e,r)&&(n[o]=s)}return n};
@@ -1,11 +1 @@
1
- /**
2
- * Flattens an array of `EvolveDevServerEntryMap` objects into a single `EvolveDevServerEntryMap`.
3
- *
4
- * @param servedDevServerEntryList - The array of `EvolveDevServerEntryMap` objects to flatten.
5
- * @returns The flattened `EvolveDevServerEntryMap`.
6
- */
7
- export const flatEntryMap = (servedDevServerEntryList) => {
8
- return servedDevServerEntryList.reduce((flatMap, servedDevServerEntryMapItem) => {
9
- return Object.assign(flatMap, servedDevServerEntryMapItem);
10
- }, {});
11
- };
1
+ export const flatEntryMap=t=>t.reduce(((t,e)=>Object.assign(t,e)),{});
@@ -1,23 +1 @@
1
- /**
2
- * Get current timestramp as `string`
3
- */
4
- export const currNow = () => Date.now().toString();
5
- /**
6
- * Generate bundle file name from rules
7
- * 1. if `serveMode`, always return `bundle
8
- * 2. else if `enableBundleHashName` always return `bundle[contenthash].{css,js}`
9
- * 3. otherwise return `bundle.{css,js}?${currNow}`
10
- * @param type `js` | `css`
11
- * @param serveMode If we are run `serve` mode
12
- * @param enableBundleHashName If we need to generate bundle file name with `[contenthash]`
13
- */
14
- export const getBundleFileName = (type, serveMode, enableBundleHashName = true) => {
15
- const fileEndFix = type === 'js' ? '.js' : '.css';
16
- if (serveMode) {
17
- return `bundle${fileEndFix}`;
18
- }
19
- if (enableBundleHashName) {
20
- return `bundle[contenthash]${fileEndFix}`;
21
- }
22
- return `bundle${fileEndFix}?${currNow()}`;
23
- };
1
+ export const currNow=()=>Date.now().toString();export const getBundleFileName=(e,n,t=!0)=>{const o="js"===e?".js":".css";return n?`bundle${o}`:t?`bundle[contenthash]${o}`:`bundle${o}?${currNow()}`};
@@ -1,4 +1 @@
1
- import { searchParentDir } from '@armit/package';
2
- export const getGitRoot = (searchFrom) => {
3
- return searchParentDir(searchFrom, '.git');
4
- };
1
+ import{searchParentDir}from"@armit/package";export const getGitRoot=r=>searchParentDir(r,".git");
@@ -1,47 +1 @@
1
- import { polyfill, viewportScripts } from '../constants.js';
2
- import { getPackageDir } from './get-pacakge-dir.js';
3
- export const defaultHtmlPluginConfig = {
4
- // The page title
5
- title: '',
6
- // The page favicon url地址
7
- favicon: '',
8
- // The customized html tags should be inject to `<header />`
9
- headBeforeHtmlTags: [],
10
- // Allow us customized inline scripts into compiled html template.
11
- inlineScripts: [],
12
- // The ordered styles will be injected start of html head.
13
- headBeforeStyles: [],
14
- // The ordered scripts will be injected before html head.
15
- headBeforeScripts: [...polyfill],
16
- // The ordered scripts will be injected end of html body.
17
- bodyAfterScripts: [],
18
- // `allowPx2rem` default is true
19
- viewport: viewportScripts,
20
- // avoid use cdn `me`, `dev`, `ntv`
21
- excludeCdnEnvs: ['me', 'dev', 'ntv'],
22
- // `minify` is true, `dev` always don't minify.
23
- htmlMinify: true,
24
- // Default use It must be an absolute path.
25
- templatePath: getPackageDir('templates/html-plugin/index-{0}.html'),
26
- };
27
- /**
28
- * 获取html plugin 模版相关定义字段.
29
- * @param preferredValue 用户首选的值, 如果返回为undefined, 将使用默认值
30
- * @returns
31
- */
32
- export const getHtmlPluginConfig = (key, configData, preferredValue) => {
33
- let userValue;
34
- if (typeof preferredValue !== 'undefined') {
35
- userValue =
36
- typeof preferredValue === 'function'
37
- ? preferredValue(configData)
38
- : preferredValue;
39
- }
40
- if (typeof userValue === 'undefined') {
41
- const defaultValue = defaultHtmlPluginConfig[key];
42
- return typeof defaultValue === 'function'
43
- ? defaultValue(configData)
44
- : defaultValue;
45
- }
46
- return userValue;
47
- };
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};
@@ -1,7 +1 @@
1
- import { cpus } from 'node:os';
2
- export const getMaxProcessTasks = (totalTasks, maxProcesses) => {
3
- const maxCpu = Math.max(1, typeof maxProcesses === 'string' && maxProcesses.endsWith('%')
4
- ? Math.round((cpus().length * Number(maxProcesses.slice(0, -1))) / 100)
5
- : Number(maxProcesses));
6
- return totalTasks > maxCpu ? maxCpu : Math.max(1, totalTasks);
7
- };
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)};
@@ -1,13 +1 @@
1
- import { join } from 'node:path';
2
- import { getDirname } from '@armit/file-utility';
3
- import { searchPackageDir } from '@armit/package';
4
- export const getPackageDir = (...paths) => {
5
- const dir = getDirname(import.meta.url);
6
- const packageDir = searchPackageDir({
7
- cwd: dir,
8
- });
9
- if (!packageDir) {
10
- throw new Error('Could not resolve package root for `flatjs/evolve`');
11
- }
12
- return join(packageDir, ...paths);
13
- };
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)};
@@ -1,2 +1,2 @@
1
- import type { EvolveMultiCDNEnvResolver, EvolveMultiCDNConfig } from '../types/types-multi-html.js';
1
+ import type { EvolveMultiCDNConfig, EvolveMultiCDNEnvResolver } from '../types/types-multi-html.js';
2
2
  export declare const getRuntimeCDNBase: (config: EvolveMultiCDNConfig, cdnResolver: EvolveMultiCDNEnvResolver, requireFn?: string) => string;
@@ -1,21 +1 @@
1
- import { cdnFinder } from './script-injects.js';
2
- export const getRuntimeCDNBase = (config, cdnResolver, requireFn = '') => {
3
- const result = [
4
- `
5
- (function () {
6
- var flatjsMultiCdn = {
7
- cdnConfig: ${JSON.stringify(config || {})},
8
- cdnResolver: ${cdnResolver.toString()},
9
- cdnFinder: ${cdnFinder.toString()}
10
- };
11
- var runtimeCDNBase = flatjsMultiCdn.cdnFinder(flatjsMultiCdn.cdnConfig, flatjsMultiCdn.cdnResolver);
12
- window.$evolve = window.$evolve || {};
13
- window.$evolve.runtimeCDNBase=runtimeCDNBase;
14
- `,
15
- ];
16
- if (requireFn) {
17
- result.push(`${requireFn} = runtimeCDNBase || ${requireFn};`);
18
- }
19
- result.push('})();');
20
- return result.join('\n');
21
- };
1
+ import{cdnFinder}from"./script-injects.js";export const getRuntimeCDNBase=(n,e,i="")=>{const t=[`\n (function () {\n var flatjsMultiCdn = {\n cdnConfig: ${JSON.stringify(n||{})},\n cdnResolver: ${e.toString()},\n cdnFinder: ${cdnFinder.toString()}\n };\n var runtimeCDNBase = flatjsMultiCdn.cdnFinder(flatjsMultiCdn.cdnConfig, flatjsMultiCdn.cdnResolver);\n window.$evolve = window.$evolve || {};\n window.$evolve.runtimeCDNBase=runtimeCDNBase;\n `];return i&&t.push(`${i} = runtimeCDNBase || ${i};`),t.push("})();"),t.join("\n")};
@@ -1,27 +1,27 @@
1
1
  export * from './allow-px2rem-for-module.js';
2
2
  export * from './assert-group-entry-item.js';
3
+ export * from './assert-single-compiler.js';
3
4
  export * from './chunk-entry-map.js';
5
+ export * from './delete-object-keys.js';
4
6
  export * from './enable-bundle-hashname-for-module.js';
7
+ export * from './flat-entry-map.js';
5
8
  export * from './get-bundle-file-name.js';
6
9
  export * from './get-html-plugin-config.js';
7
10
  export * from './get-pacakge-dir.js';
8
11
  export * from './get-runtime-cdn-base.js';
12
+ export * from './is-deep-equal.js';
13
+ export * from './json-serializer.js';
9
14
  export * from './merge-babel-options.js';
15
+ export * from './normalize-check-entry-options.js';
10
16
  export * from './normalize-entry-map.js';
17
+ export * from './normalize-group-name.js';
18
+ export * from './normalize-page-proxy.js';
19
+ export * from './normalize-resolve-alias.js';
20
+ export * from './normalize-template-inject-tokens.js';
11
21
  export * from './open-page.js';
12
22
  export * from './print-log.js';
13
23
  export * from './refresh-evolve-mock-options.js';
14
24
  export * from './script-injects.js';
15
25
  export * from './should-enable-react-fast-refresh.js';
16
- export * from './json-serializer.js';
17
- export * from './normalize-resolve-alias.js';
18
- export * from './is-deep-equal.js';
19
- export * from './verify-group-entry-options.js';
20
26
  export * from './split-to-entry-group.js';
21
- export * from './delete-object-keys.js';
22
- export * from './normalize-page-proxy.js';
23
- export * from './flat-entry-map.js';
24
- export * from './normalize-template-inject-tokens.js';
25
- export * from './normalize-check-entry-options.js';
26
- export * from './assert-single-compiler.js';
27
- export * from './normalize-group-name.js';
27
+ export * from './verify-group-entry-options.js';
@@ -1,27 +1 @@
1
- export * from './allow-px2rem-for-module.js';
2
- export * from './assert-group-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 './get-runtime-cdn-base.js';
9
- export * from './merge-babel-options.js';
10
- export * from './normalize-entry-map.js';
11
- export * from './open-page.js';
12
- export * from './print-log.js';
13
- export * from './refresh-evolve-mock-options.js';
14
- export * from './script-injects.js';
15
- export * from './should-enable-react-fast-refresh.js';
16
- export * from './json-serializer.js';
17
- export * from './normalize-resolve-alias.js';
18
- export * from './is-deep-equal.js';
19
- export * from './verify-group-entry-options.js';
20
- export * from './split-to-entry-group.js';
21
- export * from './delete-object-keys.js';
22
- export * from './normalize-page-proxy.js';
23
- export * from './flat-entry-map.js';
24
- export * from './normalize-template-inject-tokens.js';
25
- export * from './normalize-check-entry-options.js';
26
- export * from './assert-single-compiler.js';
27
- export * from './normalize-group-name.js';
1
+ export*from"./allow-px2rem-for-module.js";export*from"./assert-group-entry-item.js";export*from"./assert-single-compiler.js";export*from"./chunk-entry-map.js";export*from"./delete-object-keys.js";export*from"./enable-bundle-hashname-for-module.js";export*from"./flat-entry-map.js";export*from"./get-bundle-file-name.js";export*from"./get-html-plugin-config.js";export*from"./get-pacakge-dir.js";export*from"./get-runtime-cdn-base.js";export*from"./is-deep-equal.js";export*from"./json-serializer.js";export*from"./merge-babel-options.js";export*from"./normalize-check-entry-options.js";export*from"./normalize-entry-map.js";export*from"./normalize-group-name.js";export*from"./normalize-page-proxy.js";export*from"./normalize-resolve-alias.js";export*from"./normalize-template-inject-tokens.js";export*from"./open-page.js";export*from"./print-log.js";export*from"./refresh-evolve-mock-options.js";export*from"./script-injects.js";export*from"./should-enable-react-fast-refresh.js";export*from"./split-to-entry-group.js";export*from"./verify-group-entry-options.js";