@flatjs/evolve 1.8.1-next.82 → 1.8.1-next.84

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @flatjs/evolve
2
2
 
3
+ ## 1.8.1-next.84
4
+
5
+ ### Patch Changes
6
+
7
+ - 7f272e9: refactor `alias` to absolute, update testcases
8
+ - ec06cbe: refactor to support `alias` `paths` from tsconfig.json for `.less`
9
+ - Updated dependencies [942780c]
10
+ - Updated dependencies [ec06cbe]
11
+ - @flatjs/graph@1.8.1-next.43
12
+
13
+ ## 1.8.1-next.83
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [ae930d6]
18
+ - @flatjs/mock@1.8.1-next.67
19
+ - @flatjs/graph@1.8.1-next.42
20
+
3
21
  ## 1.8.1-next.82
4
22
 
5
23
  ### Patch Changes
@@ -1 +1 @@
1
- import{join}from"node:path";import{mergeOptions}from"@flatjs/common";import{TsconfigPathsPlugin}from"tsconfig-paths-webpack-plugin";export const createResolve=(s,o)=>{const n={mainFields:["browser","module","main"],extensions:[".ts",".tsx",".js",".json"],extensionAlias:{".js":[".js",".ts"],".cjs":[".cjs",".cts"],".mjs":[".mjs",".mts"],".jsx":[".jsx",".tsx"]},plugins:[new TsconfigPathsPlugin({configFile:join(s,"tsconfig.json"),extensions:[".ts",".tsx",".js"]})]};return mergeOptions(n,o?.resolve||{})};
1
+ import{join}from"node:path";import{mergeOptions}from"@flatjs/common";import{TsconfigPathsPlugin}from"tsconfig-paths-webpack-plugin";export const createResolve=(s,o)=>{const n={mainFields:["browser","module","main"],extensions:[".ts",".tsx",".js",".json"],extensionAlias:{".js":[".js",".ts"],".cjs":[".cjs",".cts"],".mjs":[".mjs",".mts"],".jsx":[".jsx",".tsx"]},plugins:[new TsconfigPathsPlugin({configFile:join(s,"tsconfig.json"),extensions:[".ts",".tsx",".js",".jsx"]})]};return mergeOptions(n,o?.resolve||{})};
@@ -15,12 +15,11 @@ import { type FlatEvolveOptions } from '../../types/types-options.js';
15
15
  * },
16
16
  * resolve: {
17
17
  * alias: {
18
- * style: resolve(projectCwd, './src/style'),
19
- * theme: resolve(projectCwd, './src/layout/theme'),
18
+ * '@': resolve(projectCwd, './src'),
20
19
  * },
21
20
  * },
22
21
  * },
23
- * `@import '~theme/default.less';` at `style.less`
22
+ * `@import '~@/theme/default.less';` at `src/theme/default.less`
24
23
  *
25
24
  * ```
26
25
  */
@@ -1 +1 @@
1
- export const defaultEvolveOptions={projectCwd:process.cwd(),projectVirtualPath:"flatjs/evolve",rejectWarnings:!1,devServer:{autoOpen:!0,mockOptions:{mockBaseDir:"mocks"},clientOverlay:{errors:!0,warnings:!1},middlewares:[],watchOptions:{poll:1e3,ignored:["**/node_modules","**/mocks"],aggregateTimeout:500},defaultServeGlobalData:()=>Promise.resolve({})},webpack:{target:["web","es5"],plugins:[],ruleSets:[],publicPath:"auto",externals:{vue:"Vue",react:"React","react-dom":"ReactDOM"},outputDir:"public",enableBundleHashName:!0},pluginOptions:{},loaderOptions:{assetDataUrlMaxSize:4096,babelOptions:{usePreset:"react",plugins:[],presets:[]},runTsChecker:!0,lessOptions:{},postcssOptions:{cssnanoOptions:{}},pixelOptions:{rootValue:{px:100,rpx:1},outputUnit:"rem"},modularImports:[]},entryMap:{},multiHtmlCdn:{},multiHtmlCdnEnvResolver:function cdnResolver(){},needVerifyPackages:{},packageInstallChecker:{enabled:!1,detectModules:["@dimjs/*"],throwError:!1,showAllInstalledGraph:!0},maxProcesses:"50%",ci:{basedBranch:"master"}};
1
+ export const defaultEvolveOptions={projectCwd:process.cwd(),projectVirtualPath:"flatjs/evolve",rejectWarnings:!1,devServer:{autoOpen:!0,mockOptions:{mockBaseDir:"mocks"},clientOverlay:{errors:!0,warnings:!1},middlewares:[],watchOptions:{poll:1e3,ignored:["**/node_modules","**/mocks"],aggregateTimeout:500},defaultServeGlobalData:()=>Promise.resolve({})},webpack:{target:["web","es5"],plugins:[],ruleSets:[],publicPath:"auto",resolve:{},externals:{vue:"Vue",react:"React","react-dom":"ReactDOM"},outputDir:"public",enableBundleHashName:!0},pluginOptions:{},loaderOptions:{assetDataUrlMaxSize:4096,babelOptions:{usePreset:"react",plugins:[],presets:[]},runTsChecker:!0,lessOptions:{},postcssOptions:{cssnanoOptions:{}},pixelOptions:{rootValue:{px:100,rpx:1},outputUnit:"rem"},modularImports:[]},entryMap:{},multiHtmlCdn:{},multiHtmlCdnEnvResolver:function cdnResolver(){},needVerifyPackages:{},packageInstallChecker:{enabled:!1,detectModules:["@dimjs/*"],throwError:!1,showAllInstalledGraph:!0},maxProcesses:"50%",ci:{basedBranch:"master"}};
@@ -14,3 +14,4 @@ export * from './script-injects.js';
14
14
  export * from './should-enable-react-fast-refresh.js';
15
15
  export * from './split-to-multi-compiler.js';
16
16
  export * from './json-serializer.js';
17
+ export * from './normalize-resolve-alias.js';
@@ -1 +1 @@
1
- export*from"./allow-px2rem-for-module.js";export*from"./assert-only-single-entry-item.js";export*from"./chunk-entry-map.js";export*from"./enable-bundle-hashname-for-module.js";export*from"./get-bundle-file-name.js";export*from"./get-html-plugin-config.js";export*from"./get-pacakge-dir.js";export*from"./merge-babel-options.js";export*from"./normalize-entry-map.js";export*from"./open-page.js";export*from"./print-log.js";export*from"./refresh-evolve-mock-options.js";export*from"./script-injects.js";export*from"./should-enable-react-fast-refresh.js";export*from"./split-to-multi-compiler.js";export*from"./json-serializer.js";
1
+ export*from"./allow-px2rem-for-module.js";export*from"./assert-only-single-entry-item.js";export*from"./chunk-entry-map.js";export*from"./enable-bundle-hashname-for-module.js";export*from"./get-bundle-file-name.js";export*from"./get-html-plugin-config.js";export*from"./get-pacakge-dir.js";export*from"./merge-babel-options.js";export*from"./normalize-entry-map.js";export*from"./open-page.js";export*from"./print-log.js";export*from"./refresh-evolve-mock-options.js";export*from"./script-injects.js";export*from"./should-enable-react-fast-refresh.js";export*from"./split-to-multi-compiler.js";export*from"./json-serializer.js";export*from"./normalize-resolve-alias.js";
@@ -0,0 +1 @@
1
+ export declare const normalizeResolveAlias: (projectCwd: string, alias?: Record<string, string>) => Record<string, string>;
@@ -0,0 +1 @@
1
+ import{resolve}from"node:path";export const normalizeResolveAlias=(e,o={})=>{for(const[r,t]of Object.entries(o))o[r]=resolve(e,t);return o};
@@ -1 +1 @@
1
- import{searchConfig}from"@armit/config-loader";import{mergeOptions,logger}from"@flatjs/common";import{configFileName,moduleName}from"../constants.js";import{defaultEvolveOptions}from"../default-options.js";import{refreshEvolveMockOptions}from"../helpers/refresh-evolve-mock-options.js";export const loadEvolveConfig=async(o,e,i={},t={configFile:configFileName,esmLoaderOptions:{externals:["@flatjs/evolve","@flatjs/mock"]}})=>{const{configFile:n,esmLoaderOptions:r}=t,s=await searchConfig(n,e,{esm:{...r,projectCwd:e}});let l={};l="function"==typeof s?.config?s?.config(o):s?.config||{};const m=mergeOptions(defaultEvolveOptions,l),f=mergeOptions(m,i),a=mergeOptions(f,{projectCwd:e}),c="build"===o.command?a:await refreshEvolveMockOptions(e,a,t);return logger.debug(`Load evolve config:\n${JSON.stringify(c,null,2)}`,moduleName),c};
1
+ import{searchConfig}from"@armit/config-loader";import{mergeOptions,logger}from"@flatjs/common";import{configFileName,moduleName}from"../constants.js";import{defaultEvolveOptions}from"../default-options.js";import{normalizeResolveAlias}from"../helpers/normalize-resolve-alias.js";import{refreshEvolveMockOptions}from"../helpers/refresh-evolve-mock-options.js";export const loadEvolveConfig=async(o,e,i={},s={configFile:configFileName,esmLoaderOptions:{externals:["@flatjs/evolve","@flatjs/mock"]}})=>{const{configFile:l,esmLoaderOptions:r}=s,a=await searchConfig(l,e,{esm:{...r,projectCwd:e}});let n={};n="function"==typeof a?.config?a?.config(o):a?.config||{};const t=mergeOptions(defaultEvolveOptions,n),m=mergeOptions(t,i),f=mergeOptions(m,{projectCwd:e}),c="build"===o.command?f:await refreshEvolveMockOptions(e,f,s);return logger.debug(`Load evolve config:\n${JSON.stringify(c,null,2)}`,moduleName),c.webpack?.resolve?.alias&&(c.webpack.resolve.alias=normalizeResolveAlias(e,c.webpack?.resolve?.alias)),c};
@@ -2,7 +2,7 @@ import { type PartialDeep } from 'type-fest';
2
2
  import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
3
3
  import { type FlatEvolveOptions } from '../types/types-options.js';
4
4
  import { type EvolveBuildResult } from './start-one-entry-build.js';
5
- export declare function getBuildEntryFiles(projectCwd: string, diffFiles: string[], allEntryInputs: string[]): Promise<string[]>;
5
+ export declare function getBuildEntryFiles(projectCwd: string, diffFiles: string[], allEntryInputs: string[], resolveAlias?: Record<string, string>): Promise<string[]>;
6
6
  /**
7
7
  * Dynamic check which entry modules need to build.
8
8
  * @returns
@@ -1 +1 @@
1
- import{isAbsolute,join}from"node:path";import{getDiffFiles,getCommitIdOfBranch}from"@armit/git";import{createThreadPool}from"@armit/worker-threads";import{arraysIntersect,chalk,logger}from"@flatjs/common";import{traverseGraph}from"@flatjs/graph";import Listr from"listr";import{filterActivedEntriesByEntryInputs,filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{getGitRoot}from"../helpers/get-git-root.js";import{getMaxProcessTasks}from"../helpers/get-max-process-tasks.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{resolveEntryMapInputFiles}from"../helpers/resolve-entry-map-input-files.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{envVerify}from"./env-verify.js";import{getWorkerPath}from"./get-worker-path.js";export async function getBuildEntryFiles(e,t,r){const i=[],o=[];for(const e of r)t.includes(e)?i.push(e):o.push(e);if(o.length){const r=await traverseGraph({input:o,projectCwd:e,treeNodeFilter:()=>!0});if(!r)return i;logger.debug(`DependencyGraph:\n${JSON.stringify(r,null,2)}`);for(const e of o){const o=r[e]||[];arraysIntersect(o,t)&&i.push(e)}}return i}export async function dynamicCheckBuildEntryMap(e,t,r,i,o){const n=await loadEvolveConfig({command:"build"},e,i,o);if(n.ci?.fixedBuildModules&&n.ci?.fixedBuildModules.length){logger.info("Use `fixedBuildModules` configuration to build...");return{buildEntries:filterActivedEntriesByModule(n.entryMap,n.ci?.fixedBuildModules),newEvolveOptions:n}}if(logger.info("Dynamicly checking code changed modules ..."),!t){const e=n.ci?.basedBranch||"master";logger.info(`Resolving base branch "${e}" commit hash ...`),t=await getCommitIdOfBranch(e)}let s=t?await getDiffFiles(t,r):[];const a=getGitRoot(e);if(!a)throw new Error(`No .git root (${e}) found`);if(s=s.map((e=>isAbsolute(e)?e:join(a,e))),logger.debug(`Diff files: \n${JSON.stringify(s,null,2)}`),!s.length)return logger.warn("It seems that there are no code files changed."),{buildEntries:{},newEvolveOptions:n};const l=await resolveEntryMapInputFiles(e,n.entryMap),c=await getBuildEntryFiles(e,s,l);logger.debug(`To build entry files: \n${JSON.stringify(c,null,2)}`);return{buildEntries:await filterActivedEntriesByEntryInputs(e,n.entryMap,c),newEvolveOptions:n}}export const startDynamicBuild=async(e,t,r,i={},o)=>{const{buildEntries:n,newEvolveOptions:s}=await dynamicCheckBuildEntryMap(e,t,r,i,o);await envVerify(e,s);const a=Object.keys(n);if(!a.length)return logger.warn("No build entries providered!"),[];const l=getMaxProcessTasks(a.length,s.maxProcesses);logger.info(`Start dynamic build with (${chalk(["magenta"])(String(l))}) workers:\n${JSON.stringify({buildEntries:a},null,2)}`);const c=getWorkerPath(),f=await createThreadPool(c,{size:l}),d=new Listr([],{concurrent:l,exitOnError:!0}),g=[];for(const[t]of Object.entries(n))d.add({title:`Build module ${chalk(["magenta"])(t)} ...`,task:async()=>{const r=await f.startBuildWorker(e,t,jsonSerializer.stringify(i),o);g.push(r)}});return d.tasks.length&&await d.run(),f.pool.terminate(),g};
1
+ import{isAbsolute,join}from"node:path";import{getDiffFiles,getCommitIdOfBranch}from"@armit/git";import{createThreadPool}from"@armit/worker-threads";import{arraysIntersect,chalk,logger}from"@flatjs/common";import{traverseGraph}from"@flatjs/graph";import Listr from"listr";import{filterActivedEntriesByEntryInputs,filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{getGitRoot}from"../helpers/get-git-root.js";import{getMaxProcessTasks}from"../helpers/get-max-process-tasks.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{resolveEntryMapInputFiles}from"../helpers/resolve-entry-map-input-files.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{envVerify}from"./env-verify.js";import{getWorkerPath}from"./get-worker-path.js";export async function getBuildEntryFiles(e,t,r,i){const o=[],n=[];for(const e of r)t.includes(e)?o.push(e):n.push(e);if(n.length){const r=await traverseGraph({input:n,projectCwd:e,treeNodeFilter:()=>!0,lessImportOptions:{projectCwd:e,aliases:i}});if(!r)return o;logger.debug(`DependencyGraph:\n${JSON.stringify(r,null,2)}`);for(const e of n){const i=r[e]||[];arraysIntersect(i,t)&&o.push(e)}}return o}export async function dynamicCheckBuildEntryMap(e,t,r,i,o){const n=await loadEvolveConfig({command:"build"},e,i,o);if(n.ci?.fixedBuildModules&&n.ci?.fixedBuildModules.length){logger.info("Use `fixedBuildModules` configuration to build...");return{buildEntries:filterActivedEntriesByModule(n.entryMap,n.ci?.fixedBuildModules),newEvolveOptions:n}}if(logger.info("Dynamicly checking code changed modules ..."),!t){const e=n.ci?.basedBranch||"master";logger.info(`Resolving base branch "${e}" commit hash ...`),t=await getCommitIdOfBranch(e)}let s=t?await getDiffFiles(t,r):[];const a=getGitRoot(e);if(!a)throw new Error(`No .git root (${e}) found`);if(s=s.map((e=>isAbsolute(e)?e:join(a,e))),logger.debug(`Diff files: \n${JSON.stringify(s,null,2)}`),!s.length)return logger.warn("It seems that there are no code files changed."),{buildEntries:{},newEvolveOptions:n};const l=await resolveEntryMapInputFiles(e,n.entryMap),c=await getBuildEntryFiles(e,s,l,n.webpack?.resolve?.alias);logger.debug(`To build entry files: \n${JSON.stringify(c,null,2)}`);return{buildEntries:await filterActivedEntriesByEntryInputs(e,n.entryMap,c),newEvolveOptions:n}}export const startDynamicBuild=async(e,t,r,i={},o)=>{const{buildEntries:n,newEvolveOptions:s}=await dynamicCheckBuildEntryMap(e,t,r,i,o);await envVerify(e,s);const a=Object.keys(n);if(!a.length)return logger.warn("No build entries providered!"),[];const l=getMaxProcessTasks(a.length,s.maxProcesses);logger.info(`Start dynamic build with (${chalk(["magenta"])(String(l))}) workers:\n${JSON.stringify({buildEntries:a},null,2)}`);const c=getWorkerPath(),d=await createThreadPool(c,{size:l}),f=new Listr([],{concurrent:l,exitOnError:!0}),g=[];for(const[t]of Object.entries(n))f.add({title:`Build module ${chalk(["magenta"])(t)} ...`,task:async()=>{const r=await d.startBuildWorker(e,t,jsonSerializer.stringify(i),o);g.push(r)}});return f.tasks.length&&await f.run(),d.pool.terminate(),g};
@@ -7,7 +7,26 @@ import { type TerserMinimizerOptions } from '../minimizer/types.js';
7
7
  export interface WebpackEntryObject {
8
8
  [index: string]: string | [string, ...string[]];
9
9
  }
10
- export interface FlatEvolveWebpackOptions extends Pick<Configuration, 'performance' | 'stats' | 'infrastructureLogging' | 'resolve'> {
10
+ export interface FlatEvolveWebpackOptions extends Pick<Configuration, 'performance' | 'stats' | 'infrastructureLogging'> {
11
+ /**
12
+ * These options change how modules are resolved.
13
+ */
14
+ resolve?: Configuration['resolve'] & {
15
+ /**
16
+ * Only allow pass `key:value` alias `{'@xxx':'./src/xxx'}`
17
+ * Note: Usually you don't need to specify an alias, the framework will auto support `paths` alias of tsconfig.json
18
+ * less `@import` is also supported via `paths` of tsconfig.json only need to with prefix `~`
19
+ * @example
20
+ * ```less
21
+ * //@import '~@/utils/xxx.less'`
22
+ * //@import url('./child.less');`
23
+ * //@import url('~@/react/less/alias.less');
24
+ * //@import '~@/react/less/alias2.less';
25
+ * //@import '~@/utils/shared.less';
26
+ * ```
27
+ */
28
+ alias?: Record<string, string>;
29
+ };
11
30
  /**
12
31
  * @default
13
32
  * ```json
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatjs/evolve",
3
- "version": "1.8.1-next.82",
3
+ "version": "1.8.1-next.84",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -46,8 +46,8 @@
46
46
  "@flatjs/common": "1.8.1-next.31",
47
47
  "@flatjs/evolve-preset-babel": "1.8.1-next.15",
48
48
  "@flatjs/forge-postcss-plugin-pixel": "1.8.1-next.31",
49
- "@flatjs/graph": "1.8.1-next.41",
50
- "@flatjs/mock": "1.8.1-next.66",
49
+ "@flatjs/graph": "1.8.1-next.43",
50
+ "@flatjs/mock": "1.8.1-next.67",
51
51
  "@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
52
52
  "@types/babel__core": "7.20.1",
53
53
  "babel-loader": "9.1.2",