@modern-js/module-tools 2.25.0 → 2.25.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # @modern-js/module-tools
2
2
 
3
+ ## 2.25.2
4
+
5
+ ### Patch Changes
6
+
7
+ - a2a5bcd: fix(module-tools): fix error in concurrent copy when generate dts files.
8
+ fix(module-tools): 修复在生成类型文件的时候并发复制产生的错误
9
+ - Updated dependencies [63d8247]
10
+ - Updated dependencies [6651684]
11
+ - Updated dependencies [272646c]
12
+ - Updated dependencies [358ed24]
13
+ - @modern-js/utils@2.25.2
14
+ - @modern-js/core@2.25.2
15
+ - @modern-js/plugin-changeset@2.25.2
16
+ - @modern-js/plugin-i18n@2.25.2
17
+ - @modern-js/plugin-lint@2.25.2
18
+ - @modern-js/new-action@2.25.2
19
+ - @modern-js/plugin@2.25.2
20
+ - @modern-js/upgrade@2.25.2
21
+
22
+ ## 2.25.1
23
+
24
+ ### Patch Changes
25
+
26
+ - 273e3cd: chore: update libuild version to 0.13.2
27
+ chore: 升级 libuild 版本至 0.13.2
28
+ - Updated dependencies [9f78d0c]
29
+ - @modern-js/utils@2.25.1
30
+ - @modern-js/core@2.25.1
31
+ - @modern-js/plugin-changeset@2.25.1
32
+ - @modern-js/plugin-i18n@2.25.1
33
+ - @modern-js/plugin-lint@2.25.1
34
+ - @modern-js/new-action@2.25.1
35
+ - @modern-js/plugin@2.25.1
36
+ - @modern-js/upgrade@2.25.1
37
+
3
38
  ## 2.25.0
4
39
 
5
40
  ### Patch Changes
@@ -33,7 +68,7 @@
33
68
 
34
69
  - 53ba418: chore: upgrade libuild and libuild plugins version to 0.13.1
35
70
  chore: 升级 libuild 和 libuild 插件版本到 0.13.1
36
- - 3b82675: feat: Auto delete build product by checking if outdir is project root path
71
+ - 3b82675: feat: Auto delete build artifacts by checking if outdir is project root path
37
72
  feat: 根据 outDir 是否是项目根目录决定是否自动删除产物目录
38
73
  - 7073297: fix: close declarationMap when bundle dts
39
74
  fix: 打包 dts 时关闭 declarationMap
package/dist/utils/dts.js CHANGED
@@ -99,6 +99,7 @@ const resolveAlias = async (config, options, watchFilenames = []) => {
99
99
  for (const r of result) {
100
100
  fs.writeFileSync(r.path, r.content);
101
101
  }
102
+ await fs.ensureDir(distAbsPath);
102
103
  await fs.copy(tempDistAbsSrcPath, distAbsPath);
103
104
  };
104
105
  const assignTsConfigPath = async (config, options) => {
@@ -1 +1 @@
1
- {"version":3,"file":null,"mappings":";;;;;;;;;;;;EAWaA,mBAAiB;WAAjBA;;EAmDAC,eAAa;WAAbA;;EA0BAC,cAAY;WAAZA;;EA6EAC,oBAAkB;WAAlBA;;EAwBAC,uBAAqB;WAArBA;;EA4BAC,yBAAuB;WAAvBA;;;;;iEAzNI;AAWV,MAAML,oBAAoB,OAC/BM,WACG;AACH,QAAM,EAAEC,IAAIC,OAAM,IAAK,MAAM,iFAAO;AACpC,QAAM,EAAEC,iBAAgB,IAAK,MAAM,iFAAO;AAE1C,QAAM,EAAEC,cAAcC,WAAWC,cAAcC,aAAY,IAAKP;AAChE,QAAMQ,sBAAsBC,cAAKC,KAC/BN,cACA,GAAGD,oBAAoBD,UAAU;AAEnC,QAAMS,oBAAoBF,cAAKC,KAC7BF,qBACAC,cAAKG,SAASR,cAAcE;AAG9B,QAAMO,mBAAmBJ,cAAKC,KAC5BF,qBACAC,cAAKK,SAASP;AAEhBN,KAAGc,eAAeF;AAElB,QAAMG,cAAcP,cAAKC,KACvBD,cAAKG,SAASH,cAAKQ,QAAQJ,mBAAmBJ,cAAKQ,QAAQV,gBAC3DE,cAAKK,SAASD;AAGhB,QAAMK,cAAyB;IAC7BC,SAASH;IACTI,iBAAiB;;MAEfC,aAAa;MACbC,qBAAqB;;;;;;MAMrBC,gBAAgBZ;IAClB;EACF;AAEAV,KAAGuB,cAAcX,kBAAkBK;AAEnC,SAAO;IACLL;IACAL;IACAiB,oBAAoBd;E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;AAG7C,MACE,OAAOnB,QAAQoB,aAAa,YAC5BpB,QAAQoB,aAAaD,qBACrB;QAMMzD;AALNA,WAAO2D,MAAM;MACXC,MAAM;MACNC,UAAU;MACVC,cAAc;MACdC,iBAAiB;MACjB,IAAI/D,qBAAO2D,SAAG,QAAV3D,uCAAc,CAAC;MACnBO,cAAc+B,QAAQoB;IACxB;EACF;AAEA,SAAO1D;AACT;AAEO,MAAMF,wBAAwB,OACnCkE,OACA1B,YACG;AACH,QAAM,EAAE2B,QAAQC,MAAK,IAAK,MAAM,iFAAO;AACvC,QAAM,EAAEC,iBAAgB,IAAK,MAAM,iFAAO;AAC1C,QAAMC,QAAQ,MAAM,iFAAO;AAC3B,QAAM,EAAEN,cAAcO,UAAS,IAAK/B,mDAAW,CAAC;AAChD,MAAI0B,iBAAiB3B,OAAO;AAC1B,QAAIyB,cAAc;AAChB,YAAM,IAAIK,iBAAiBH,OAAO;QAChCK;MACF;IACF,OAAO;AACLJ,aAAOK,KACLJ,MAAMK,eACJH,MAAMI,KAAKC,EAAEL,MAAMM,WAAWC,MAAMhB,IAAIG,YAAY;AAGxDG,aAAOD,MACL,IAAIG,iBAAiBH,OAAO;QAC1BK;MACF;IAEJ;EACF;AACF;AAEO,MAAMtE,0BAA0B,CAAC6E,WACtCA,WAAW,YAAYA,WAAW;","names":["generatorTsConfig","getTscBinPath","resolveAlias","assignTsConfigPath","printOrThrowDtsErrors","tsTargetAtOrAboveES2022","config","fs","nanoid","dtsTempDirectory","appDirectory","sourceDir","absSourceDir","tsconfigPath","tempDistAbsRootPath","path","join","tempDistAbsOurDir","relative","tempTsconfigPath","basename","ensureFileSync","extendsPath","dirname","resetConfig","extends","compilerOptions","declaration","emitDeclarationOnly","declarationDir","writeJSONSync","tempDistAbsSrcPath","default","findUp","exists","pathExists","tscBinFile","directory","targetFilePath","hasTscBinFile","undefined","cwd","existsSync","Error","options","watchFilenames","userTsconfig","globby","transformDtsAlias","distAbsPath","dtsDistPath","dtsFilenames","length","sync","absolute","result","filenames","baseUrl","paths","r","writeFileSync","content","copy","defaultTsConfigPath","tsconfig","dts","only","distPath","abortOnError","respectExternal","error","logger","chalk","InternalDTSError","local","buildType","warn","bgYellowBright","i18n","t","localeKeys","warns","target"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/dts.ts"],"sourcesContent":["import path from 'path';\nimport type {\n ITsconfig,\n BundlelessGeneratorDtsConfig,\n BuildCommandOptions,\n BaseBuildConfig,\n BuildType,\n TsTarget,\n // AliasOption,\n} from '../types';\n\nexport const generatorTsConfig = async (\n config: BundlelessGeneratorDtsConfig,\n) => {\n const { fs, nanoid } = await import('@modern-js/utils');\n const { dtsTempDirectory } = await import('../constants/dts');\n\n const { appDirectory, sourceDir: absSourceDir, tsconfigPath } = config;\n const tempDistAbsRootPath = path.join(\n appDirectory,\n `${dtsTempDirectory}/${nanoid()}`,\n );\n const tempDistAbsOurDir = path.join(\n tempDistAbsRootPath,\n path.relative(appDirectory, absSourceDir),\n );\n\n const tempTsconfigPath = path.join(\n tempDistAbsRootPath,\n path.basename(tsconfigPath),\n );\n fs.ensureFileSync(tempTsconfigPath);\n\n const extendsPath = path.join(\n path.relative(path.dirname(tempTsconfigPath), path.dirname(tsconfigPath)),\n path.basename(tempTsconfigPath),\n );\n\n const resetConfig: ITsconfig = {\n extends: extendsPath,\n compilerOptions: {\n // Ensure that .d.ts files are created by tsc, but not .js files\n declaration: true,\n emitDeclarationOnly: true,\n // when `outDir` is './dist', `declarationDir` is `./types`\n // tsc will emit:\n // - ./dist/index.js\n // - ./types/index.d.ts\n // we only want to emit declarations\n declarationDir: tempDistAbsOurDir,\n },\n };\n\n fs.writeJSONSync(tempTsconfigPath, resetConfig);\n\n return {\n tempTsconfigPath,\n tempDistAbsRootPath,\n tempDistAbsSrcPath: tempDistAbsOurDir,\n };\n};\n\nexport const getTscBinPath = async (appDirectory: string) => {\n const { fs } = await import('@modern-js/utils');\n const { default: findUp, exists: pathExists } = await import(\n '../../compiled/find-up'\n );\n const tscBinFile = await findUp(\n async (directory: string) => {\n const targetFilePath = path.join(directory, './node_modules/.bin/tsc');\n const hasTscBinFile = await pathExists(targetFilePath);\n if (hasTscBinFile) {\n return targetFilePath;\n }\n return undefined;\n },\n { cwd: appDirectory },\n );\n\n if (!tscBinFile || !fs.existsSync(tscBinFile)) {\n throw new Error(\n 'Failed to excute the `tsc` command, please check if `typescript` is installed correctly in the current directory.',\n );\n }\n\n return tscBinFile;\n};\n\nexport const resolveAlias = async (\n config: BundlelessGeneratorDtsConfig,\n options: {\n userTsconfig: ITsconfig;\n tempTsconfigPath: string;\n tempDistAbsRootPath: string;\n tempDistAbsSrcPath: string;\n },\n watchFilenames: string[] = [],\n) => {\n const { userTsconfig, tempDistAbsSrcPath, tempDistAbsRootPath } = options;\n const { globby, fs } = await import('@modern-js/utils');\n const { transformDtsAlias } = await import('./tspathsTransform');\n const { distAbsPath } = config;\n const dtsDistPath = `${tempDistAbsSrcPath}/**/*.d.ts`;\n const dtsFilenames =\n watchFilenames.length > 0\n ? watchFilenames\n : globby.sync(dtsDistPath, { absolute: true });\n const result = transformDtsAlias({\n filenames: dtsFilenames,\n baseUrl: tempDistAbsRootPath,\n paths: userTsconfig.compilerOptions?.paths ?? {},\n });\n for (const r of result) {\n fs.writeFileSync(r.path, r.content);\n }\n\n await fs.copy(tempDistAbsSrcPath, distAbsPath);\n};\n\n// export const matchesPattern = (calleePath: NodePath, pattern: string) => {\n// const { node } = calleePath;\n\n// if (t.isMemberExpression(node)) {\n// return calleePath.matchesPattern(pattern);\n// }\n\n// if (!t.isIdentifier(node) || pattern.includes('.')) {\n// return false;\n// }\n\n// const name = pattern.split('.')[0];\n\n// return node.name === name;\n// };\n\n// export const isImportCall = (calleePath: NodePath<tt.CallExpression>) => {\n// return t.isImport(calleePath.node.callee);\n// };\n\n// export const verifyTsConfigPaths = async (\n// tsconfigAbsPath: string,\n// userAliases?: AliasOption,\n// ) => {\n// const { readTsConfigByFile, chalk } = await import('@modern-js/utils');\n// if (!userAliases) {\n// return;\n// }\n\n// const paths = Object.keys(\n// readTsConfigByFile(tsconfigAbsPath).compilerOptions?.paths || {},\n// ).map(key => key.replace(/\\/\\*$/, ''));\n\n// Object.keys(userAliases).forEach(name => {\n// if (paths.includes(name)) {\n// throw new Error(\n// chalk.red(\n// `It looks like you have configured the alias ${chalk.bold(\n// name,\n// )} in both the modern.config file and tsconfig.json.\\n Please remove the configuration in modern.config file and just keep the configuration in tsconfig.json.`,\n// ),\n// );\n// }\n// });\n// };\n\nexport const assignTsConfigPath = async (\n config: BaseBuildConfig,\n options: BuildCommandOptions,\n) => {\n const { defaultTsConfigPath } = await import('../constants/dts');\n\n // user run `build --tsconfig './tsconfig.build.json'`\n if (\n typeof options.tsconfig === 'string' &&\n options.tsconfig !== defaultTsConfigPath\n ) {\n config.dts = {\n only: false,\n distPath: './',\n abortOnError: true,\n respectExternal: true,\n ...(config.dts ?? {}),\n tsconfigPath: options.tsconfig,\n };\n }\n\n return config;\n};\n\nexport const printOrThrowDtsErrors = async (\n error: unknown,\n options: { abortOnError?: boolean; buildType: BuildType },\n) => {\n const { logger, chalk } = await import('@modern-js/utils');\n const { InternalDTSError } = await import('../error');\n const local = await import('../locale');\n const { abortOnError, buildType } = options ?? {};\n if (error instanceof Error) {\n if (abortOnError) {\n throw new InternalDTSError(error, {\n buildType,\n });\n } else {\n logger.warn(\n chalk.bgYellowBright(\n local.i18n.t(local.localeKeys.warns.dts.abortOnError),\n ),\n );\n logger.error(\n new InternalDTSError(error, {\n buildType,\n }),\n );\n }\n }\n};\n\nexport const tsTargetAtOrAboveES2022 = (target: TsTarget) =>\n target === 'es2022' || target === 'esnext';\n"]}
1
+ {"version":3,"file":null,"mappings":";;;;;;;;;;;;EAWaA,mBAAiB;WAAjBA;;EAmDAC,eAAa;WAAbA;;EA0BAC,cAAY;WAAZA;;EA+EAC,oBAAkB;WAAlBA;;EAwBAC,uBAAqB;WAArBA;;EA4BAC,yBAAu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KhC,mDAAW,CAAC;AAChD,MAAI2B,iBAAiB5B,OAAO;AAC1B,QAAI0B,cAAc;AAChB,YAAM,IAAIK,iBAAiBH,OAAO;QAChCK;MACF;IACF,OAAO;AACLJ,aAAOK,KACLJ,MAAMK,eACJH,MAAMI,KAAKC,EAAEL,MAAMM,WAAWC,MAAMhB,IAAIG,YAAY;AAGxDG,aAAOD,MACL,IAAIG,iBAAiBH,OAAO;QAC1BK;MACF;IAEJ;EACF;AACF;AAEO,MAAMvE,0BAA0B,CAAC8E,WACtCA,WAAW,YAAYA,WAAW;","names":["generatorTsConfig","getTscBinPath","resolveAlias","assignTsConfigPath","printOrThrowDtsErrors","tsTargetAtOrAboveES2022","config","fs","nanoid","dtsTempDirectory","appDirectory","sourceDir","absSourceDir","tsconfigPath","tempDistAbsRootPath","path","join","tempDistAbsOurDir","relative","tempTsconfigPath","basename","ensureFileSync","extendsPath","dirname","resetConfig","extends","compilerOptions","declaration","emitDeclarationOnly","declarationDir","writeJSONSync","tempDistAbsSrcPath","default","findUp","exists","pathExists","tscBinFile","directory","targetFilePath","hasTscBinFile","undefined","cwd","existsSync","Error","options","watchFilenames","userTsconfig","globby","transformDtsAlias","distAbsPath","dtsDistPath","dtsFilenames","length","sync","absolute","result","filenames","baseUrl","paths","r","writeFileSync","content","ensureDir","copy","defaultTsConfigPath","tsconfig","dts","only","distPath","abortOnError","respectExternal","error","logger","chalk","InternalDTSError","local","buildType","warn","bgYellowBright","i18n","t","localeKeys","warns","target"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/dts.ts"],"sourcesContent":["import path from 'path';\nimport type {\n ITsconfig,\n BundlelessGeneratorDtsConfig,\n BuildCommandOptions,\n BaseBuildConfig,\n BuildType,\n TsTarget,\n // AliasOption,\n} from '../types';\n\nexport const generatorTsConfig = async (\n config: BundlelessGeneratorDtsConfig,\n) => {\n const { fs, nanoid } = await import('@modern-js/utils');\n const { dtsTempDirectory } = await import('../constants/dts');\n\n const { appDirectory, sourceDir: absSourceDir, tsconfigPath } = config;\n const tempDistAbsRootPath = path.join(\n appDirectory,\n `${dtsTempDirectory}/${nanoid()}`,\n );\n const tempDistAbsOurDir = path.join(\n tempDistAbsRootPath,\n path.relative(appDirectory, absSourceDir),\n );\n\n const tempTsconfigPath = path.join(\n tempDistAbsRootPath,\n path.basename(tsconfigPath),\n );\n fs.ensureFileSync(tempTsconfigPath);\n\n const extendsPath = path.join(\n path.relative(path.dirname(tempTsconfigPath), path.dirname(tsconfigPath)),\n path.basename(tempTsconfigPath),\n );\n\n const resetConfig: ITsconfig = {\n extends: extendsPath,\n compilerOptions: {\n // Ensure that .d.ts files are created by tsc, but not .js files\n declaration: true,\n emitDeclarationOnly: true,\n // when `outDir` is './dist', `declarationDir` is `./types`\n // tsc will emit:\n // - ./dist/index.js\n // - ./types/index.d.ts\n // we only want to emit declarations\n declarationDir: tempDistAbsOurDir,\n },\n };\n\n fs.writeJSONSync(tempTsconfigPath, resetConfig);\n\n return {\n tempTsconfigPath,\n tempDistAbsRootPath,\n tempDistAbsSrcPath: tempDistAbsOurDir,\n };\n};\n\nexport const getTscBinPath = async (appDirectory: string) => {\n const { fs } = await import('@modern-js/utils');\n const { default: findUp, exists: pathExists } = await import(\n '../../compiled/find-up'\n );\n const tscBinFile = await findUp(\n async (directory: string) => {\n const targetFilePath = path.join(directory, './node_modules/.bin/tsc');\n const hasTscBinFile = await pathExists(targetFilePath);\n if (hasTscBinFile) {\n return targetFilePath;\n }\n return undefined;\n },\n { cwd: appDirectory },\n );\n\n if (!tscBinFile || !fs.existsSync(tscBinFile)) {\n throw new Error(\n 'Failed to excute the `tsc` command, please check if `typescript` is installed correctly in the current directory.',\n );\n }\n\n return tscBinFile;\n};\n\nexport const resolveAlias = async (\n config: BundlelessGeneratorDtsConfig,\n options: {\n userTsconfig: ITsconfig;\n tempTsconfigPath: string;\n tempDistAbsRootPath: string;\n tempDistAbsSrcPath: string;\n },\n watchFilenames: string[] = [],\n) => {\n const { userTsconfig, tempDistAbsSrcPath, tempDistAbsRootPath } = options;\n const { globby, fs } = await import('@modern-js/utils');\n const { transformDtsAlias } = await import('./tspathsTransform');\n const { distAbsPath } = config;\n const dtsDistPath = `${tempDistAbsSrcPath}/**/*.d.ts`;\n const dtsFilenames =\n watchFilenames.length > 0\n ? watchFilenames\n : globby.sync(dtsDistPath, { absolute: true });\n const result = transformDtsAlias({\n filenames: dtsFilenames,\n baseUrl: tempDistAbsRootPath,\n paths: userTsconfig.compilerOptions?.paths ?? {},\n });\n for (const r of result) {\n fs.writeFileSync(r.path, r.content);\n }\n\n // why use `ensureDir` before copy? look this: https://github.com/jprichardson/node-fs-extra/issues/957\n await fs.ensureDir(distAbsPath);\n await fs.copy(tempDistAbsSrcPath, distAbsPath);\n};\n\n// export const matchesPattern = (calleePath: NodePath, pattern: string) => {\n// const { node } = calleePath;\n\n// if (t.isMemberExpression(node)) {\n// return calleePath.matchesPattern(pattern);\n// }\n\n// if (!t.isIdentifier(node) || pattern.includes('.')) {\n// return false;\n// }\n\n// const name = pattern.split('.')[0];\n\n// return node.name === name;\n// };\n\n// export const isImportCall = (calleePath: NodePath<tt.CallExpression>) => {\n// return t.isImport(calleePath.node.callee);\n// };\n\n// export const verifyTsConfigPaths = async (\n// tsconfigAbsPath: string,\n// userAliases?: AliasOption,\n// ) => {\n// const { readTsConfigByFile, chalk } = await import('@modern-js/utils');\n// if (!userAliases) {\n// return;\n// }\n\n// const paths = Object.keys(\n// readTsConfigByFile(tsconfigAbsPath).compilerOptions?.paths || {},\n// ).map(key => key.replace(/\\/\\*$/, ''));\n\n// Object.keys(userAliases).forEach(name => {\n// if (paths.includes(name)) {\n// throw new Error(\n// chalk.red(\n// `It looks like you have configured the alias ${chalk.bold(\n// name,\n// )} in both the modern.config file and tsconfig.json.\\n Please remove the configuration in modern.config file and just keep the configuration in tsconfig.json.`,\n// ),\n// );\n// }\n// });\n// };\n\nexport const assignTsConfigPath = async (\n config: BaseBuildConfig,\n options: BuildCommandOptions,\n) => {\n const { defaultTsConfigPath } = await import('../constants/dts');\n\n // user run `build --tsconfig './tsconfig.build.json'`\n if (\n typeof options.tsconfig === 'string' &&\n options.tsconfig !== defaultTsConfigPath\n ) {\n config.dts = {\n only: false,\n distPath: './',\n abortOnError: true,\n respectExternal: true,\n ...(config.dts ?? {}),\n tsconfigPath: options.tsconfig,\n };\n }\n\n return config;\n};\n\nexport const printOrThrowDtsErrors = async (\n error: unknown,\n options: { abortOnError?: boolean; buildType: BuildType },\n) => {\n const { logger, chalk } = await import('@modern-js/utils');\n const { InternalDTSError } = await import('../error');\n const local = await import('../locale');\n const { abortOnError, buildType } = options ?? {};\n if (error instanceof Error) {\n if (abortOnError) {\n throw new InternalDTSError(error, {\n buildType,\n });\n } else {\n logger.warn(\n chalk.bgYellowBright(\n local.i18n.t(local.localeKeys.warns.dts.abortOnError),\n ),\n );\n logger.error(\n new InternalDTSError(error, {\n buildType,\n }),\n );\n }\n }\n};\n\nexport const tsTargetAtOrAboveES2022 = (target: TsTarget) =>\n target === 'es2022' || target === 'esnext';\n"]}
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "module-tools",
16
16
  "lib-tools"
17
17
  ],
18
- "version": "2.25.0",
18
+ "version": "2.25.2",
19
19
  "bin": {
20
20
  "modern": "./bin/modern.js",
21
21
  "modern-module": "./bin/modern.js"
@@ -49,14 +49,14 @@
49
49
  "@modern-js/libuild-plugin-swc": "0.13.2",
50
50
  "postcss": "8.4.6",
51
51
  "@swc/helpers": "0.5.1",
52
- "@modern-js/core": "2.25.0",
53
- "@modern-js/new-action": "2.25.0",
54
- "@modern-js/plugin-changeset": "2.25.0",
55
- "@modern-js/plugin-i18n": "2.25.0",
56
- "@modern-js/plugin-lint": "2.25.0",
57
- "@modern-js/upgrade": "2.25.0",
58
- "@modern-js/utils": "2.25.0",
59
- "@modern-js/plugin": "2.25.0"
52
+ "@modern-js/core": "2.25.2",
53
+ "@modern-js/plugin": "2.25.2",
54
+ "@modern-js/new-action": "2.25.2",
55
+ "@modern-js/plugin-changeset": "2.25.2",
56
+ "@modern-js/plugin-i18n": "2.25.2",
57
+ "@modern-js/plugin-lint": "2.25.2",
58
+ "@modern-js/upgrade": "2.25.2",
59
+ "@modern-js/utils": "2.25.2"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/babel__generator": "7.6.4",
@@ -71,10 +71,10 @@
71
71
  "postcss-alias": "2.0.0",
72
72
  "react": "17",
73
73
  "typescript": "^5",
74
- "@modern-js/builder-webpack-provider": "2.25.0",
75
- "@modern-js/self": "npm:@modern-js/module-tools@2.25.0",
76
- "@scripts/build": "2.25.0",
77
- "@scripts/jest-config": "2.25.0"
74
+ "@modern-js/builder-webpack-provider": "2.25.2",
75
+ "@modern-js/self": "npm:@modern-js/module-tools@2.25.2",
76
+ "@scripts/build": "2.25.2",
77
+ "@scripts/jest-config": "2.25.2"
78
78
  },
79
79
  "publishConfig": {
80
80
  "registry": "https://registry.npmjs.org/",