@modern-js/module-tools 2.31.2 → 2.32.0

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.
Files changed (95) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE +1 -1
  3. package/dist/builder/build.js +18 -23
  4. package/dist/builder/build.js.map +1 -1
  5. package/dist/builder/clear.js +6 -9
  6. package/dist/builder/clear.js.map +1 -1
  7. package/dist/builder/copy.d.ts +2 -1
  8. package/dist/builder/copy.js +19 -22
  9. package/dist/builder/copy.js.map +1 -1
  10. package/dist/builder/dts/rollup.d.ts +3 -1
  11. package/dist/builder/dts/rollup.js +14 -13
  12. package/dist/builder/dts/rollup.js.map +1 -1
  13. package/dist/builder/dts/tsc.js +16 -22
  14. package/dist/builder/dts/tsc.js.map +1 -1
  15. package/dist/builder/index.js +14 -14
  16. package/dist/builder/index.js.map +1 -1
  17. package/dist/builder/platform.js +14 -16
  18. package/dist/builder/platform.js.map +1 -1
  19. package/dist/cli.js +16 -16
  20. package/dist/cli.js.map +1 -1
  21. package/dist/command.js +9 -16
  22. package/dist/command.js.map +1 -1
  23. package/dist/config/merge.d.ts +9 -0
  24. package/dist/{utils/config.js → config/merge.js} +45 -53
  25. package/dist/config/merge.js.map +1 -0
  26. package/dist/config/normalize.d.ts +5 -13
  27. package/dist/config/normalize.js +54 -90
  28. package/dist/config/normalize.js.map +1 -1
  29. package/dist/config/schema.d.ts +12 -0
  30. package/dist/config/schema.js +3 -0
  31. package/dist/config/schema.js.map +1 -1
  32. package/dist/config/transformLegacyConfig.js +13 -16
  33. package/dist/config/transformLegacyConfig.js.map +1 -1
  34. package/dist/config/valid.d.ts +3 -0
  35. package/dist/config/valid.js +39 -0
  36. package/dist/config/valid.js.map +1 -0
  37. package/dist/constants/build.d.ts +1 -1
  38. package/dist/constants/build.js +61 -58
  39. package/dist/constants/build.js.map +1 -1
  40. package/dist/constants/{colors.js → color.js} +1 -1
  41. package/dist/constants/{colors.js.map → color.js.map} +1 -1
  42. package/dist/constants/dts.d.ts +0 -1
  43. package/dist/constants/dts.js +0 -4
  44. package/dist/constants/dts.js.map +1 -1
  45. package/dist/constants/{legacyBuildPresets.js → legacy-preset.js} +1 -1
  46. package/dist/constants/legacy-preset.js.map +1 -0
  47. package/dist/constants/preset.d.ts +26 -0
  48. package/dist/constants/{buildPresets.js → preset.js} +4 -18
  49. package/dist/constants/preset.js.map +1 -0
  50. package/dist/dev.js +6 -8
  51. package/dist/dev.js.map +1 -1
  52. package/dist/index.d.ts +1 -1
  53. package/dist/index.js +2 -2
  54. package/dist/index.js.map +1 -1
  55. package/dist/types/command.d.ts +2 -2
  56. package/dist/types/config/copy.js.map +1 -0
  57. package/dist/types/config/dev.d.ts +8 -0
  58. package/dist/types/config/dev.js +6 -0
  59. package/dist/types/config/dev.js.map +1 -0
  60. package/dist/types/config/index.d.ts +6 -5
  61. package/dist/types/config/index.js.map +1 -1
  62. package/dist/types/index.d.ts +3 -3
  63. package/dist/types/index.js.map +1 -1
  64. package/dist/utils/builder.d.ts +1 -4
  65. package/dist/utils/builder.js +3 -29
  66. package/dist/utils/builder.js.map +1 -1
  67. package/dist/utils/common.d.ts +2 -1
  68. package/dist/utils/common.js +18 -3
  69. package/dist/utils/common.js.map +1 -1
  70. package/dist/utils/dts.d.ts +1 -2
  71. package/dist/utils/dts.js +11 -32
  72. package/dist/utils/dts.js.map +1 -1
  73. package/dist/utils/input.d.ts +4 -10
  74. package/dist/utils/input.js +36 -60
  75. package/dist/utils/input.js.map +1 -1
  76. package/dist/utils/{libuildPlugins.d.ts → libuild-plugin.d.ts} +1 -4
  77. package/dist/utils/{libuildPlugins.js → libuild-plugin.js} +4 -25
  78. package/dist/utils/libuild-plugin.js.map +1 -0
  79. package/dist/utils/print.js +1 -3
  80. package/dist/utils/print.js.map +1 -1
  81. package/dist/utils/style.js +14 -19
  82. package/dist/utils/style.js.map +1 -1
  83. package/package.json +20 -17
  84. package/dist/constants/buildPresets.d.ts +0 -91
  85. package/dist/constants/buildPresets.js.map +0 -1
  86. package/dist/constants/legacyBuildPresets.js.map +0 -1
  87. package/dist/types/copy.js.map +0 -1
  88. package/dist/utils/config.d.ts +0 -9
  89. package/dist/utils/config.js.map +0 -1
  90. package/dist/utils/libuildPlugins.js.map +0 -1
  91. package/scripts/debug-mode.js +0 -48
  92. /package/dist/constants/{colors.d.ts → color.d.ts} +0 -0
  93. /package/dist/constants/{legacyBuildPresets.d.ts → legacy-preset.d.ts} +0 -0
  94. /package/dist/types/{copy.d.ts → config/copy.d.ts} +0 -0
  95. /package/dist/types/{copy.js → config/copy.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # @modern-js/module-tools
2
2
 
3
+ ## 2.32.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8d22b87: feat: add transformLodash option to enable or disable lodash feature
8
+ feat: 添加 transformLodash 选项控制 lodash 功能的开启或关闭
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [e5a3fb4]
13
+ - Updated dependencies [6076166]
14
+ - Updated dependencies [a030aff]
15
+ - Updated dependencies [8d22b87]
16
+ - Updated dependencies [4323e68]
17
+ - Updated dependencies [3c91100]
18
+ - Updated dependencies [5255eba]
19
+ - @modern-js/utils@2.32.0
20
+ - @modern-js/plugin@2.32.0
21
+ - @modern-js/types@2.32.0
22
+ - @modern-js/core@2.32.0
23
+ - @modern-js/libuild-plugin-swc@2.32.0
24
+ - @modern-js/plugin-changeset@2.32.0
25
+ - @modern-js/plugin-i18n@2.32.0
26
+ - @modern-js/plugin-lint@2.32.0
27
+ - @modern-js/new-action@2.32.0
28
+ - @modern-js/upgrade@2.32.0
29
+ - @modern-js/libuild-plugin-svgr@2.32.0
30
+ - @modern-js/libuild@2.32.0
31
+
3
32
  ## 2.31.2
4
33
 
5
34
  ### Patch Changes
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Modern.js
3
+ Copyright (c) 2021-present Modern.js
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -26,14 +26,16 @@ _export(exports, {
26
26
  return buildLib;
27
27
  }
28
28
  });
29
+ const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
29
30
  const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
30
31
  const _path = require("path");
31
- const _logger = require("@modern-js/utils/logger");
32
+ const _utils = require("@modern-js/utils");
33
+ const _pmap = /* @__PURE__ */ _interop_require_default._(require("../../compiled/p-map"));
34
+ const _copy = require("./copy");
32
35
  const runBuildTask = async (options, api) => {
33
36
  const { buildConfig, context, buildCmdOptions } = options;
34
37
  const { appDirectory, isTsProject } = context;
35
- const { copyTask } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./copy")));
36
- await copyTask(buildConfig, {
38
+ await (0, _copy.copyTask)(buildConfig, {
37
39
  appDirectory,
38
40
  watch: buildCmdOptions.watch
39
41
  });
@@ -60,8 +62,7 @@ const buildInTsProject = async (options, api) => {
60
62
  buildLib,
61
63
  generatorDts
62
64
  ];
63
- const { default: pMap } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../compiled/p-map")));
64
- await pMap(tasks, async (task) => {
65
+ await (0, _pmap.default)(tasks, async (task) => {
65
66
  await task(buildConfig, api, {
66
67
  watch,
67
68
  dts
@@ -84,22 +85,19 @@ const buildInJsProject = async (options, api) => {
84
85
  const generatorDts = async (config, api, options) => {
85
86
  const { runRollup, runTsc } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./dts")));
86
87
  const { watch, dts } = options;
87
- const { buildType, input, sourceDir, alias } = config;
88
+ const { buildType, input, sourceDir, alias, externals } = config;
88
89
  const { appDirectory } = api.useAppContext();
89
90
  const { tsconfigPath, distPath, abortOnError, respectExternal } = dts;
90
91
  if (buildType === "bundle") {
91
- const { getFinalExternals } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/builder")));
92
- const finalExternals = await getFinalExternals(config, {
93
- appDirectory
94
- });
95
92
  await runRollup(api, {
96
93
  distDir: distPath,
97
94
  watch,
98
- externals: finalExternals,
95
+ externals,
99
96
  input,
100
97
  tsconfigPath,
101
98
  abortOnError,
102
- respectExternal
99
+ respectExternal,
100
+ appDirectory
103
101
  });
104
102
  } else {
105
103
  await runTsc(api, {
@@ -115,17 +113,16 @@ const generatorDts = async (config, api, options) => {
115
113
  };
116
114
  const buildLib = async (config, api, options) => {
117
115
  const { watch } = options;
118
- const { target, buildType, sourceMap, format, outDir: distPath, asset, jsx, input, platform, splitting, minify, sourceDir, umdGlobals, umdModuleName, define, alias, style, externals, autoExternal, dts, metafile, sideEffects, redirect, esbuildOptions, externalHelpers, transformImport, sourceType, disableSwcTransform } = config;
116
+ const { target, buildType, sourceMap, format, outDir: distPath, asset, jsx, input, platform, splitting, minify, sourceDir, umdGlobals, umdModuleName, define, alias, style, externals, autoExternal, dts, metafile, sideEffects, redirect, esbuildOptions, externalHelpers, transformImport, transformLodash, sourceType, disableSwcTransform } = config;
119
117
  const { appDirectory } = api.useAppContext();
120
- const { slash } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
121
- const root = slash(appDirectory);
122
- const outdir = slash(distPath);
123
- const assetOutDir = asset.path ? slash(asset.path) : asset.path;
118
+ const root = (0, _utils.slash)(appDirectory);
119
+ const outdir = (0, _utils.slash)(distPath);
120
+ const assetOutDir = asset.path ? (0, _utils.slash)(asset.path) : asset.path;
124
121
  const { less, sass, postcss, inject, modules, autoModules } = style;
125
122
  const { umdPlugin, swcTransformPlugin, transformPlugin: legacyTransformPlugin, es5Plugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/libuild-plugin-swc")));
126
123
  const { checkSwcHelpers, matchEs5PluginCondition, matchSwcTransformCondition } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/builder")));
127
124
  const { getProjectTsconfig } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./dts/tsc")));
128
- const tsconfigPath = dts ? dts.tsconfigPath : (0, _path.join)(appDirectory, "./tsconfig.json");
125
+ const tsconfigPath = dts ? dts.tsconfigPath : (0, _path.resolve)(appDirectory, "tsconfig.json");
129
126
  const userTsconfig = await getProjectTsconfig(tsconfigPath);
130
127
  const plugins = [];
131
128
  if (matchSwcTransformCondition({
@@ -149,6 +146,7 @@ const buildLib = async (config, api, options) => {
149
146
  }
150
147
  plugins.push(swcTransformPlugin({
151
148
  pluginImport: transformImport,
149
+ transformLodash,
152
150
  externalHelpers: Boolean(externalHelpers),
153
151
  emitDecoratorMetadata: (_userTsconfig2 = userTsconfig) === null || _userTsconfig2 === void 0 ? void 0 : (_userTsconfig_compilerOptions2 = _userTsconfig2.compilerOptions) === null || _userTsconfig_compilerOptions2 === void 0 ? void 0 : _userTsconfig_compilerOptions2.emitDecoratorMetadata,
154
152
  useDefineForClassFields
@@ -187,11 +185,8 @@ const buildLib = async (config, api, options) => {
187
185
  const options2 = typeof asset.svgr === "boolean" ? {} : asset.svgr;
188
186
  plugins.push(svgrPlugin(options2));
189
187
  }
190
- const { watchPlugin, externalPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/libuildPlugins")));
188
+ const { watchPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/libuild-plugin")));
191
189
  plugins.push(watchPlugin(api, config));
192
- plugins.push(externalPlugin(config, {
193
- appDirectory
194
- }));
195
190
  const buildConfig = {
196
191
  root,
197
192
  watch,
@@ -247,7 +242,7 @@ const buildLib = async (config, api, options) => {
247
242
  const { watchSectionTitle } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/log")));
248
243
  const { SectionTitleStatus } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../constants/log")));
249
244
  const titleText = `[${buildType === "bundle" ? "Bundle" : "Bundleless"}: ${format}_${target}]`;
250
- _logger.logger.info(await watchSectionTitle(titleText, SectionTitleStatus.Success));
245
+ _utils.logger.info(await watchSectionTitle(titleText, SectionTitleStatus.Success));
251
246
  }
252
247
  } catch (e) {
253
248
  const { InternalBuildError } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../error")));
@@ -1 +1 @@
1
- {"version":3,"file":null,"mappings":";;;;;;;;;;;;EAaaA,cAAY;WAAZA;;EAqBAC,kBAAgB;WAAhBA;;EAyBAC,kBAAgB;WAAhBA;;EAmBAC,cAAY;WAAZA;;EAuCAC,UAAQ;WAARA;;;;sBArHQ;wBACE;AAYhB,MAAMJ,eAAe,OAC1BK,SAKAC;AAEA,QAAM,EAAEC,aAAaC,SAASC,gBAAe,IAAKJ;AAClD,QAAM,EAAEK,cAAcC,YAAW,IAAKH;AAEtC,QAAM,EAAEI,SAAQ,IAAK,MAAM,iFAAO;AAClC,QAAMA,SAASL,aAAa;IAAEG;IAAcG,OAAOJ,gBAAgBI;EAAM;AAEzE,MAAIF,aAAa;AACf,UAAMV,iBAAiBI,SAASC;EAClC,OAAO;AACL,UAAMJ,iBAAiBG,SAASC;EAClC;AACF;AAEO,MAAML,mBAAmB,OAC9BI,SAKAC;AAEA,QAAM,EAAEC,aAAaE,gBAAe,IAAKJ;AACzC,QAAMS,MAAML,gBAAgBK,MAAMP,YAAYO,MAAM;AACpD,QAAMC,eAAeR,YAAYO,MAAMP,YAAYO,IAAIE,OAAO;MAChDP;AAAd,QAAMI,SAAQJ,yCAAgBI,WAAK,QAArBJ,6DAAyB;AAEvC,MAAIK,QAAQ,OAAO;AAEjB,KAACC,gBAAiB,MAAMX,SAASG,aAAaD,KAAK;MAAEO;IAAM;EAC7D,OAAO;AACL,UAAMI,QAAQH,IAAIE,OAAO;MAACb;QAAgB;MAACC;MAAUD;;AACrD,UAAM,EAAEe,SAASC,KA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AM,EAAEC,eAAc,IAAK,MAAM,iFAAO;AACxC,UAAMC,SAASvG,IAAIwG,eAAc;AACjC,UAAMC,sBAAsB,MAAMF,OAAOG,cAAczG,aAAa;MAClE0G,QAAQC,OAAKA;IACf;AAEA,UAAMC,UAAU,MAAMR,UAAUS,OAAOL;AACvC,UAAMI,QAAQE,MAAK;AACnBT,mBAAeO,QAAQG,aAAazD,MAAMrC,cAAc;AAExD,QAAIX,OAAO;AACT,YAAM,EAAE0G,kBAAiB,IAAK,MAAM,iFAAO;AAC3C,YAAM,EAAEC,mBAAkB,IAAK,MAAM,iFAAO;AAC5C,YAAMC,YAAY,IAChBjG,cAAc,WAAW,WAAW,iBACjCgB,UAAUF;AAEfoF,qBAAOC,KACL,MAAMJ,kBAAkBE,WAAWD,mBAAmBI,OAAO;IAEjE;EACF,SAASC,GAAP;AACA,UAAM,EAAEC,mBAAkB,IAAK,MAAM,iFAAO;AAC5C,UAAM,IAAIA,mBAAmBD,GAAG;MAC9BvF;MACAE;MACAhB;IACF;EACF;AACF;","names":["runBuildTask","buildInTsProject","buildInJsProject","generatorDts","buildLib","options","api","buildConfig","context","buildCmdOptions","appDirectory","isTsProject","copyTask","watch","dts","skipBuildLib","only","tasks","default","pMap","task","config","runRollup","runTsc","buildType","input","sourceDir","alias","useAppContext","tsconfigPath","distPath","abortOnError","respectExternal","getFinalExternals","finalExternals","distDir","externals","distAbsPath","target","sourceMap","format","outDir","asset","jsx","platform","splitting","minify","umdGlobals","umdModuleName","define","style","autoExternal","metafile","sideEffects","redirect","esbuildOptions","externalHelpers","transformImport","sourceType","disableSwcTransform","slash","root","outdir","assetOutDir","path","less","sass","postcss","inject","modules","autoModules","umdPlugin","swcTransformPlugin","transformPlugin","legacyTransformPlugin","es5Plugin","checkSwcHelpers","matchEs5PluginCondition","matchSwcTransformCondition","getProjectTsconfig","join","userTsconfig","plugins","tsTargetAtOrAboveES2022","tsUseDefineForClassFields","compilerOptions","useDefineForClassFields","tsTarget","toLowerCase","undefined","push","pluginImport","Boolean","emitDecoratorMetadata","jsc","transform","legacyDecorator","decoratorMetadata","svgr","svgrPlugin","watchPlugin","externalPlugin","resolve","globals","external","bundle","outbase","Libuilder","addOutputChunk","runner","useHookRunners","modifiedBuildConfig","modifyLibuild","onLast","c","builder","create","build","outputChunk","watchSectionTitle","SectionTitleStatus","titleText","logger","info","Success","e","InternalBuildError"],"sources":["../../src/builder/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/builder/build.ts"],"sourcesContent":["import { join } from 'path';\nimport { logger } from '@modern-js/utils/logger';\nimport type { CLIConfig } from '@modern-js/libuild';\nimport type {\n BuildCommandOptions,\n BaseBuildConfig,\n ModuleTools,\n PluginAPI,\n DTSOptions,\n ModuleContext,\n TsTarget,\n} from '../types';\n\nexport const runBuildTask = async (\n options: {\n buildConfig: BaseBuildConfig;\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { buildConfig, context, buildCmdOptions } = options;\n const { appDirectory, isTsProject } = context;\n\n const { copyTask } = await import('./copy');\n await copyTask(buildConfig, { appDirectory, watch: buildCmdOptions.watch });\n\n if (isTsProject) {\n await buildInTsProject(options, api);\n } else {\n await buildInJsProject(options, api);\n }\n};\n\nexport const buildInTsProject = async (\n options: {\n buildConfig: BaseBuildConfig;\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { buildConfig, buildCmdOptions } = options;\n const dts = buildCmdOptions.dts ? buildConfig.dts : false;\n const skipBuildLib = buildConfig.dts ? buildConfig.dts.only : false;\n const watch = buildCmdOptions.watch ?? false;\n\n if (dts === false) {\n // --no-dts and buildConfig is `{ dts: { only: true } }`, then skip.\n !skipBuildLib && (await buildLib(buildConfig, api, { watch }));\n } else {\n const tasks = dts.only ? [generatorDts] : [buildLib, generatorDts];\n const { default: pMap } = await import('../../compiled/p-map');\n await pMap(tasks, async task => {\n await task(buildConfig, api as any, { watch, dts });\n });\n }\n};\n\nexport const buildInJsProject = async (\n options: {\n buildConfig: BaseBuildConfig;\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { buildConfig, buildCmdOptions } = options;\n const dts = buildCmdOptions.dts ? buildConfig.dts : false;\n const watch = buildCmdOptions.watch ?? false;\n\n if (dts !== false && dts.only) {\n return;\n }\n\n await buildLib(buildConfig, api, { watch });\n};\n\nexport const generatorDts = async (\n config: BaseBuildConfig,\n api: PluginAPI<ModuleTools>,\n options: {\n watch: boolean;\n dts: DTSOptions;\n },\n) => {\n const { runRollup, runTsc } = await import('./dts');\n const { watch, dts } = options;\n const { buildType, input, sourceDir, alias } = config;\n const { appDirectory } = api.useAppContext();\n const { tsconfigPath, distPath, abortOnError, respectExternal } = dts;\n if (buildType === 'bundle') {\n const { getFinalExternals } = await import('../utils/builder');\n const finalExternals = await getFinalExternals(config, { appDirectory });\n\n await runRollup(api, {\n distDir: distPath,\n watch,\n externals: finalExternals,\n input,\n tsconfigPath,\n abortOnError,\n respectExternal,\n });\n } else {\n await runTsc(api, {\n appDirectory,\n alias,\n distAbsPath: distPath,\n watch,\n tsconfigPath,\n sourceDir,\n abortOnError,\n });\n }\n};\n\nexport const buildLib = async (\n config: BaseBuildConfig,\n api: PluginAPI<ModuleTools>,\n options: {\n watch: boolean;\n },\n) => {\n const { watch } = options;\n const {\n target,\n buildType,\n sourceMap,\n format,\n outDir: distPath,\n asset,\n jsx,\n input,\n platform,\n splitting,\n minify,\n sourceDir,\n umdGlobals,\n umdModuleName,\n define,\n alias,\n style,\n externals,\n autoExternal,\n dts,\n metafile,\n sideEffects,\n redirect,\n esbuildOptions,\n externalHelpers,\n transformImport,\n sourceType,\n disableSwcTransform,\n } = config;\n const { appDirectory } = api.useAppContext();\n const { slash } = await import('@modern-js/utils');\n const root = slash(appDirectory);\n const outdir = slash(distPath);\n const assetOutDir = asset.path ? slash(asset.path) : asset.path;\n const { less, sass, postcss, inject, modules, autoModules } = style;\n\n // support swc-transform, umd and emitDecoratorMetadata by swc\n const {\n umdPlugin,\n swcTransformPlugin,\n transformPlugin: legacyTransformPlugin,\n es5Plugin,\n } = await import('@modern-js/libuild-plugin-swc');\n const {\n checkSwcHelpers,\n matchEs5PluginCondition,\n matchSwcTransformCondition,\n } = await import('../utils/builder');\n\n const { getProjectTsconfig } = await import('./dts/tsc');\n const tsconfigPath = dts\n ? dts.tsconfigPath\n : join(appDirectory, './tsconfig.json');\n const userTsconfig = await getProjectTsconfig(tsconfigPath);\n\n const plugins = [];\n\n if (\n matchSwcTransformCondition({\n sourceType,\n buildType,\n format,\n disableSwcTransform,\n })\n ) {\n // TODO: refactor config plugins logic\n\n const { tsTargetAtOrAboveES2022 } = await import('../utils/dts');\n const tsUseDefineForClassFields =\n userTsconfig?.compilerOptions?.useDefineForClassFields;\n let tsTarget = userTsconfig?.compilerOptions?.target;\n tsTarget = tsTarget ? (tsTarget.toLowerCase() as TsTarget) : undefined;\n let useDefineForClassFields: boolean;\n if (tsUseDefineForClassFields !== undefined) {\n useDefineForClassFields = tsUseDefineForClassFields;\n } else if (tsTarget !== undefined) {\n useDefineForClassFields = tsTargetAtOrAboveES2022(tsTarget);\n } else {\n useDefineForClassFields = true;\n }\n\n plugins.push(\n swcTransformPlugin({\n pluginImport: transformImport,\n externalHelpers: Boolean(externalHelpers),\n emitDecoratorMetadata:\n userTsconfig?.compilerOptions?.emitDecoratorMetadata,\n useDefineForClassFields,\n }),\n );\n } else {\n if (\n matchEs5PluginCondition({\n sourceType,\n buildType,\n format,\n target,\n disableSwcTransform,\n })\n ) {\n plugins.push(es5Plugin());\n }\n\n if (userTsconfig?.compilerOptions?.emitDecoratorMetadata) {\n plugins.push(\n legacyTransformPlugin({\n jsc: {\n transform: {\n legacyDecorator: true,\n decoratorMetadata: true,\n },\n },\n }),\n );\n }\n }\n\n if (format === 'umd') {\n plugins.push(umdPlugin(umdModuleName));\n }\n\n await checkSwcHelpers({ appDirectory, externalHelpers });\n\n // support svgr\n if (asset.svgr) {\n const { svgrPlugin } = await import('@modern-js/libuild-plugin-svgr');\n const options = typeof asset.svgr === 'boolean' ? {} : asset.svgr;\n plugins.push(svgrPlugin(options));\n }\n\n // adapt module tools\n const { watchPlugin, externalPlugin } = await import(\n '../utils/libuildPlugins'\n );\n plugins.push(watchPlugin(api, config));\n plugins.push(externalPlugin(config, { appDirectory }));\n\n const buildConfig: CLIConfig = {\n root,\n watch,\n target,\n sourceMap,\n format,\n outdir,\n define,\n style: {\n less,\n sass,\n postcss,\n inject,\n modules,\n autoModules,\n },\n resolve: {\n alias,\n },\n asset: {\n ...asset,\n outdir: assetOutDir,\n },\n plugins,\n jsx,\n input,\n platform,\n splitting,\n minify,\n sourceDir,\n metafile: metafile && buildType === 'bundle',\n globals: umdGlobals,\n external: externals,\n autoExternal,\n redirect,\n bundle: buildType === 'bundle',\n sideEffects,\n // outbase for [dir]/[name]\n outbase: sourceDir,\n esbuildOptions,\n };\n\n try {\n const { Libuilder } = await import('@modern-js/libuild');\n const { addOutputChunk } = await import('../utils/print');\n const runner = api.useHookRunners();\n const modifiedBuildConfig = await runner.modifyLibuild(buildConfig, {\n onLast: c => c,\n });\n\n const builder = await Libuilder.create(modifiedBuildConfig);\n await builder.build();\n addOutputChunk(builder.outputChunk, root, buildType === 'bundle');\n\n if (watch) {\n const { watchSectionTitle } = await import('../utils/log');\n const { SectionTitleStatus } = await import('../constants/log');\n const titleText = `[${\n buildType === 'bundle' ? 'Bundle' : 'Bundleless'\n }: ${format}_${target}]`;\n\n logger.info(\n await watchSectionTitle(titleText, SectionTitleStatus.Success),\n );\n }\n } catch (e: any) {\n const { InternalBuildError } = await import('../error');\n throw new InternalBuildError(e, {\n target,\n format,\n buildType,\n });\n }\n};\n"]}
1
+ {"version":3,"file":null,"mappings":";;;;;;;;;;;;EAeaA,cAAY;WAAZA;;EAoBAC,kBAAgB;WAAhBA;;EAwBAC,kBAAgB;WAAhBA;;EAmBAC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InJsProject","generatorDts","buildLib","options","api","buildConfig","context","buildCmdOptions","appDirectory","isTsProject","copyTask","watch","dts","skipBuildLib","only","tasks","pMap","task","config","runRollup","runTsc","buildType","input","sourceDir","alias","externals","useAppContext","tsconfigPath","distPath","abortOnError","respectExternal","distDir","distAbsPath","target","sourceMap","format","outDir","asset","jsx","platform","splitting","minify","umdGlobals","umdModuleName","define","style","autoExternal","metafile","sideEffects","redirect","esbuildOptions","externalHelpers","transformImport","transformLodash","sourceType","disableSwcTransform","root","slash","outdir","assetOutDir","path","less","sass","postcss","inject","modules","autoModules","umdPlugin","swcTransformPlugin","transformPlugin","legacyTransformPlugin","es5Plugin","checkSwcHelpers","matchEs5PluginCondition","matchSwcTransformCondition","getProjectTsconfig","resolve","userTsconfig","plugins","tsTargetAtOrAboveES2022","tsUseDefineForClassFields","compilerOptions","useDefineForClassFields","tsTarget","toLowerCase","undefined","push","pluginImport","Boolean","emitDecoratorMetadata","jsc","transform","legacyDecorator","decoratorMetadata","svgr","svgrPlugin","watchPlugin","globals","external","bundle","outbase","Libuilder","addOutputChunk","runner","useHookRunners","modifiedBuildConfig","modifyLibuild","onLast","c","builder","create","build","outputChunk","watchSectionTitle","SectionTitleStatus","titleText","logger","info","Success","e","InternalBuildError"],"sources":["../../src/builder/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/builder/build.ts"],"sourcesContent":["import { resolve } from 'path';\nimport type { CLIConfig } from '@modern-js/libuild';\nimport { slash, logger } from '@modern-js/utils';\nimport type {\n BuildCommandOptions,\n BaseBuildConfig,\n ModuleTools,\n PluginAPI,\n DTSOptions,\n ModuleContext,\n TsTarget,\n} from '../types';\nimport pMap from '../../compiled/p-map';\nimport { copyTask } from './copy';\n\nexport const runBuildTask = async (\n options: {\n buildConfig: BaseBuildConfig;\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { buildConfig, context, buildCmdOptions } = options;\n const { appDirectory, isTsProject } = context;\n\n await copyTask(buildConfig, { appDirectory, watch: buildCmdOptions.watch });\n\n if (isTsProject) {\n await buildInTsProject(options, api);\n } else {\n await buildInJsProject(options, api);\n }\n};\n\nexport const buildInTsProject = async (\n options: {\n buildConfig: BaseBuildConfig;\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { buildConfig, buildCmdOptions } = options;\n const dts = buildCmdOptions.dts ? buildConfig.dts : false;\n const skipBuildLib = buildConfig.dts ? buildConfig.dts.only : false;\n const watch = buildCmdOptions.watch ?? false;\n\n if (dts === false) {\n // --no-dts and buildConfig is `{ dts: { only: true } }`, then skip.\n !skipBuildLib && (await buildLib(buildConfig, api, { watch }));\n } else {\n const tasks = dts.only ? [generatorDts] : [buildLib, generatorDts];\n await pMap(tasks, async task => {\n await task(buildConfig, api as any, { watch, dts });\n });\n }\n};\n\nexport const buildInJsProject = async (\n options: {\n buildConfig: BaseBuildConfig;\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { buildConfig, buildCmdOptions } = options;\n const dts = buildCmdOptions.dts ? buildConfig.dts : false;\n const watch = buildCmdOptions.watch ?? false;\n\n if (dts !== false && dts.only) {\n return;\n }\n\n await buildLib(buildConfig, api, { watch });\n};\n\nexport const generatorDts = async (\n config: BaseBuildConfig,\n api: PluginAPI<ModuleTools>,\n options: {\n watch: boolean;\n dts: DTSOptions;\n },\n) => {\n const { runRollup, runTsc } = await import('./dts');\n const { watch, dts } = options;\n const { buildType, input, sourceDir, alias, externals } = config;\n const { appDirectory } = api.useAppContext();\n const { tsconfigPath, distPath, abortOnError, respectExternal } = dts;\n if (buildType === 'bundle') {\n await runRollup(api, {\n distDir: distPath,\n watch,\n externals,\n input,\n tsconfigPath,\n abortOnError,\n respectExternal,\n appDirectory,\n });\n } else {\n await runTsc(api, {\n appDirectory,\n alias,\n distAbsPath: distPath,\n watch,\n tsconfigPath,\n sourceDir,\n abortOnError,\n });\n }\n};\n\nexport const buildLib = async (\n config: BaseBuildConfig,\n api: PluginAPI<ModuleTools>,\n options: {\n watch: boolean;\n },\n) => {\n const { watch } = options;\n const {\n target,\n buildType,\n sourceMap,\n format,\n outDir: distPath,\n asset,\n jsx,\n input,\n platform,\n splitting,\n minify,\n sourceDir,\n umdGlobals,\n umdModuleName,\n define,\n alias,\n style,\n externals,\n autoExternal,\n dts,\n metafile,\n sideEffects,\n redirect,\n esbuildOptions,\n externalHelpers,\n transformImport,\n transformLodash,\n sourceType,\n disableSwcTransform,\n } = config;\n const { appDirectory } = api.useAppContext();\n const root = slash(appDirectory);\n const outdir = slash(distPath);\n const assetOutDir = asset.path ? slash(asset.path) : asset.path;\n const { less, sass, postcss, inject, modules, autoModules } = style;\n\n // support swc-transform, umd and emitDecoratorMetadata by swc\n const {\n umdPlugin,\n swcTransformPlugin,\n transformPlugin: legacyTransformPlugin,\n es5Plugin,\n } = await import('@modern-js/libuild-plugin-swc');\n const {\n checkSwcHelpers,\n matchEs5PluginCondition,\n matchSwcTransformCondition,\n } = await import('../utils/builder');\n\n const { getProjectTsconfig } = await import('./dts/tsc');\n const tsconfigPath = dts\n ? dts.tsconfigPath\n : resolve(appDirectory, 'tsconfig.json');\n const userTsconfig = await getProjectTsconfig(tsconfigPath);\n\n const plugins = [];\n\n if (\n matchSwcTransformCondition({\n sourceType,\n buildType,\n format,\n disableSwcTransform,\n })\n ) {\n // TODO: refactor config plugins logic\n\n const { tsTargetAtOrAboveES2022 } = await import('../utils/dts');\n const tsUseDefineForClassFields =\n userTsconfig?.compilerOptions?.useDefineForClassFields;\n let tsTarget = userTsconfig?.compilerOptions?.target;\n tsTarget = tsTarget ? (tsTarget.toLowerCase() as TsTarget) : undefined;\n let useDefineForClassFields: boolean;\n if (tsUseDefineForClassFields !== undefined) {\n useDefineForClassFields = tsUseDefineForClassFields;\n } else if (tsTarget !== undefined) {\n useDefineForClassFields = tsTargetAtOrAboveES2022(tsTarget);\n } else {\n useDefineForClassFields = true;\n }\n\n plugins.push(\n swcTransformPlugin({\n pluginImport: transformImport,\n transformLodash,\n externalHelpers: Boolean(externalHelpers),\n emitDecoratorMetadata:\n userTsconfig?.compilerOptions?.emitDecoratorMetadata,\n useDefineForClassFields,\n }),\n );\n } else {\n if (\n matchEs5PluginCondition({\n sourceType,\n buildType,\n format,\n target,\n disableSwcTransform,\n })\n ) {\n plugins.push(es5Plugin());\n }\n\n if (userTsconfig?.compilerOptions?.emitDecoratorMetadata) {\n plugins.push(\n legacyTransformPlugin({\n jsc: {\n transform: {\n legacyDecorator: true,\n decoratorMetadata: true,\n },\n },\n }),\n );\n }\n }\n\n if (format === 'umd') {\n plugins.push(umdPlugin(umdModuleName));\n }\n\n await checkSwcHelpers({ appDirectory, externalHelpers });\n\n // support svgr\n if (asset.svgr) {\n const { svgrPlugin } = await import('@modern-js/libuild-plugin-svgr');\n const options = typeof asset.svgr === 'boolean' ? {} : asset.svgr;\n plugins.push(svgrPlugin(options));\n }\n\n // adapt module tools\n const { watchPlugin } = await import('../utils/libuild-plugin');\n plugins.push(watchPlugin(api, config));\n\n const buildConfig: CLIConfig = {\n root,\n watch,\n target,\n sourceMap,\n format,\n outdir,\n define,\n style: {\n less,\n sass,\n postcss,\n inject,\n modules,\n autoModules,\n },\n resolve: {\n alias,\n },\n asset: {\n ...asset,\n outdir: assetOutDir,\n },\n plugins,\n jsx,\n input,\n platform,\n splitting,\n minify,\n sourceDir,\n metafile: metafile && buildType === 'bundle',\n globals: umdGlobals,\n external: externals,\n autoExternal,\n redirect,\n bundle: buildType === 'bundle',\n sideEffects,\n // outbase for [dir]/[name]\n outbase: sourceDir,\n esbuildOptions,\n };\n\n try {\n const { Libuilder } = await import('@modern-js/libuild');\n const { addOutputChunk } = await import('../utils/print');\n const runner = api.useHookRunners();\n const modifiedBuildConfig = await runner.modifyLibuild(buildConfig, {\n onLast: c => c,\n });\n\n const builder = await Libuilder.create(modifiedBuildConfig);\n await builder.build();\n addOutputChunk(builder.outputChunk, root, buildType === 'bundle');\n\n if (watch) {\n const { watchSectionTitle } = await import('../utils/log');\n const { SectionTitleStatus } = await import('../constants/log');\n const titleText = `[${\n buildType === 'bundle' ? 'Bundle' : 'Bundleless'\n }: ${format}_${target}]`;\n\n logger.info(\n await watchSectionTitle(titleText, SectionTitleStatus.Success),\n );\n }\n } catch (e: any) {\n const { InternalBuildError } = await import('../error');\n throw new InternalBuildError(e, {\n target,\n format,\n buildType,\n });\n }\n};\n"]}
@@ -17,25 +17,22 @@ _export(exports, {
17
17
  return clearBuildConfigPaths;
18
18
  }
19
19
  });
20
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
20
+ const _utils = require("@modern-js/utils");
21
+ const _locale = require("../locale");
22
+ const _dts = require("../constants/dts");
21
23
  const clearDtsTemp = async () => {
22
- const { fs } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
23
- const { dtsTempDirectory } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../constants/dts")));
24
- await fs.remove(dtsTempDirectory);
24
+ await _utils.fs.remove(_dts.dtsTempDirectory);
25
25
  };
26
26
  const clearBuildConfigPaths = async (configs, options) => {
27
27
  const { noClear = false, projectAbsRootPath = process.cwd() } = options !== null && options !== void 0 ? options : {};
28
- const { fs } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
29
28
  if (noClear) {
30
29
  return;
31
30
  }
32
31
  for (const config of configs) {
33
32
  if (projectAbsRootPath === config.outDir) {
34
- const { logger, chalk } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
35
- const local = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../locale")));
36
- logger.warn(chalk.bgYellowBright(local.i18n.t(local.localeKeys.warns.clearRootPath)));
33
+ _utils.logger.warn(_utils.chalk.bgYellowBright(_locale.i18n.t(_locale.localeKeys.warns.clearRootPath)));
37
34
  } else {
38
- await fs.remove(config.outDir);
35
+ await _utils.fs.remove(config.outDir);
39
36
  }
40
37
  }
41
38
  };
@@ -1 +1 @@
1
- {"version":3,"file":null,"mappings":";;;;;;;;;;;;EAEaA,cAAY;WAAZA;;EAMAC,uBAAqB;WAArBA;;;;AANN,MAAMD,eAAe;AAC1B,QAAM,EAAEE,GAAE,IAAK,MAAM,iFAAO;AAC5B,QAAM,EAAEC,iBAAgB,IAAK,MAAM,iFAAO;AAC1C,QAAMD,GAAGE,OAAOD;AAClB;AAEO,MAAMF,wBAAwB,OACnCI,SACAC;AAKA,QAAM,EAAEC,UAAU,OAAOC,qBAAqBC,QAAQC,IAAG,EAAE,IAAKJ,mDAAW,CAAC;AAC5E,QAAM,EAAEJ,GAAE,IAAK,MAAM,iFAAO;AAE5B,MAAIK,SAAS;AACX;EACF;AAEA,aAAWI,UAAUN,SAAS;AAC5B,QAAIG,uBAAuBG,OAAOC,QAAQ;AACxC,YAAM,EAAEC,QAAQC,MAAK,IAAK,MAAM,iFAAO;AACvC,YAAMC,QAAQ,MAAM,iFAAO;AAC3BF,aAAOG,KACLF,MAAMG,eACJF,MAAMG,KAAKC,EAAEJ,MAAMK,WAAWC,MAAMC,aAAa;IAGvD,OAAO;AACL,YAAMpB,GAAGE,OAAOO,OAAOC,MAAM;IAC/B;EACF;AACF;","names":["clearDtsTemp","clearBuildConfigPaths","fs","dtsTempDirectory","remove","configs","options","noClear","projectAbsRootPath","process","cwd","config","outDir","logger","chalk","local","warn","bgYellowBright","i18n","t","localeKeys","warns","clearRootPath"],"sources":["../../src/builder/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/builder/clear.ts"],"sourcesContent":["import type { BaseBuildConfig } from '../types';\n\nexport const clearDtsTemp = async () => {\n const { fs } = await import('@modern-js/utils');\n const { dtsTempDirectory } = await import('../constants/dts');\n await fs.remove(dtsTempDirectory);\n};\n\nexport const clearBuildConfigPaths = async (\n configs: BaseBuildConfig[],\n options?: {\n noClear?: boolean;\n projectAbsRootPath?: string;\n },\n) => {\n const { noClear = false, projectAbsRootPath = process.cwd() } = options ?? {};\n const { fs } = await import('@modern-js/utils');\n\n if (noClear) {\n return;\n }\n\n for (const config of configs) {\n if (projectAbsRootPath === config.outDir) {\n const { logger, chalk } = await import('@modern-js/utils');\n const local = await import('../locale');\n logger.warn(\n chalk.bgYellowBright(\n local.i18n.t(local.localeKeys.warns.clearRootPath),\n ),\n );\n } else {\n await fs.remove(config.outDir);\n }\n }\n};\n"]}
1
+ {"version":3,"file":null,"mappings":";;;;;;;;;;;;EAKaA,cAAY;WAAZA;;EAIAC,uBAAqB;WAArBA;;;uBATqB;wBAED;qBACA;AAE1B,MAAMD,eAAe;AAC1B,QAAME,UAAGC,OAAOC,qBAAgB;AAClC;AAEO,MAAMH,wBAAwB,OACnCI,SACAC;AAKA,QAAM,EAAEC,UAAU,OAAOC,qBAAqBC,QAAQC,IAAG,EAAE,IAAKJ,mDAAW,CAAC;AAE5E,MAAIC,SAAS;AACX;EACF;AAEA,aAAWI,UAAUN,SAAS;AAC5B,QAAIG,uBAAuBG,OAAOC,QAAQ;AACxCC,oBAAOC,KAAKC,aAAMC,eAAeC,aAAKC,EAAEC,mBAAWC,MAAMC,aAAa;IACxE,OAAO;AACL,YAAMnB,UAAGC,OAAOQ,OAAOC,MAAM;IAC/B;EACF;AACF;","names":["clearDtsTemp","clearBuildConfigPaths","fs","remove","dtsTempDirectory","configs","options","noClear","projectAbsRootPath","process","cwd","config","outDir","logger","warn","chalk","bgYellowBright","i18n","t","localeKeys","warns","clearRootPath"],"sources":["../../src/builder/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/builder/clear.ts"],"sourcesContent":["import { fs, logger, chalk } from '@modern-js/utils';\nimport type { BaseBuildConfig } from '../types';\nimport { i18n, localeKeys } from '../locale';\nimport { dtsTempDirectory } from '../constants/dts';\n\nexport const clearDtsTemp = async () => {\n await fs.remove(dtsTempDirectory);\n};\n\nexport const clearBuildConfigPaths = async (\n configs: BaseBuildConfig[],\n options?: {\n noClear?: boolean;\n projectAbsRootPath?: string;\n },\n) => {\n const { noClear = false, projectAbsRootPath = process.cwd() } = options ?? {};\n\n if (noClear) {\n return;\n }\n\n for (const config of configs) {\n if (projectAbsRootPath === config.outDir) {\n logger.warn(chalk.bgYellowBright(i18n.t(localeKeys.warns.clearRootPath)));\n } else {\n await fs.remove(config.outDir);\n }\n }\n};\n"]}
@@ -1,4 +1,5 @@
1
- import type { CopyOptions, CopyPattern } from '../types/copy';
1
+ import { watch } from '@modern-js/utils';
2
+ import type { CopyOptions, CopyPattern } from '../types/config/copy';
2
3
  import type { BaseBuildConfig } from '../types/config';
3
4
  export declare const runPatterns: (pattern: CopyPattern, options: {
4
5
  appDirectory: string;
@@ -23,10 +23,10 @@ _export(exports, {
23
23
  const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
24
24
  const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
25
25
  const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
26
- const _logger = require("@modern-js/utils/logger");
26
+ const _utils = require("@modern-js/utils");
27
+ const _pmap = /* @__PURE__ */ _interop_require_default._(require("../../compiled/p-map"));
27
28
  const watchMap = /* @__PURE__ */ new Map();
28
29
  const runPatterns = async (pattern, options) => {
29
- const { fs, fastGlob, globby } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
30
30
  const { default: normalizePath } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../compiled/normalize-path")));
31
31
  const { appDirectory, enableCopySync = false } = options;
32
32
  const { from, globOptions = {} } = pattern;
@@ -48,7 +48,7 @@ const runPatterns = async (pattern, options) => {
48
48
  }
49
49
  let stats;
50
50
  try {
51
- stats = await fs.stat(absoluteFrom);
51
+ stats = await _utils.fs.stat(absoluteFrom);
52
52
  } catch (error) {
53
53
  }
54
54
  let fromType;
@@ -67,7 +67,7 @@ const runPatterns = async (pattern, options) => {
67
67
  switch (fromType) {
68
68
  case "dir":
69
69
  targetPattern.context = absoluteFrom;
70
- glob = _path.default.posix.join(fastGlob.escapePath(normalizePath(_path.default.resolve(absoluteFrom))), "**/*");
70
+ glob = _path.default.posix.join(_utils.fastGlob.escapePath(normalizePath(_path.default.resolve(absoluteFrom))), "**/*");
71
71
  absoluteFrom = _path.default.join(absoluteFrom, "**/*");
72
72
  if (typeof globOptions.dot === "undefined") {
73
73
  globOptions.dot = true;
@@ -75,7 +75,7 @@ const runPatterns = async (pattern, options) => {
75
75
  break;
76
76
  case "file":
77
77
  targetPattern.context = _path.default.dirname(absoluteFrom);
78
- glob = fastGlob.escapePath(normalizePath(_path.default.resolve(absoluteFrom)));
78
+ glob = _utils.fastGlob.escapePath(normalizePath(_path.default.resolve(absoluteFrom)));
79
79
  if (typeof globOptions.dot === "undefined") {
80
80
  globOptions.dot = true;
81
81
  }
@@ -83,10 +83,10 @@ const runPatterns = async (pattern, options) => {
83
83
  case "glob":
84
84
  default: {
85
85
  var _targetPattern_context;
86
- glob = _path.default.isAbsolute(from) ? from : _path.default.posix.join(fastGlob.escapePath(normalizePath(_path.default.resolve((_targetPattern_context = targetPattern.context) !== null && _targetPattern_context !== void 0 ? _targetPattern_context : appDirectory))), from);
86
+ glob = _path.default.isAbsolute(from) ? from : _path.default.posix.join(_utils.fastGlob.escapePath(normalizePath(_path.default.resolve((_targetPattern_context = targetPattern.context) !== null && _targetPattern_context !== void 0 ? _targetPattern_context : appDirectory))), from);
87
87
  }
88
88
  }
89
- const globEntries = await globby(glob, {
89
+ const globEntries = await (0, _utils.globby)(glob, {
90
90
  ...{
91
91
  followSymbolicLinks: true
92
92
  },
@@ -94,8 +94,7 @@ const runPatterns = async (pattern, options) => {
94
94
  cwd: targetPattern.context,
95
95
  objectMode: true
96
96
  });
97
- const { default: pMap } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../compiled/p-map")));
98
- pMap(globEntries, async (globEntry) => {
97
+ (0, _pmap.default)(globEntries, async (globEntry) => {
99
98
  if (!globEntry.dirent.isFile()) {
100
99
  return;
101
100
  }
@@ -111,21 +110,20 @@ const runPatterns = async (pattern, options) => {
111
110
  watchMap.set(absoluteFrom2, absoluteTo);
112
111
  }
113
112
  if (enableCopySync) {
114
- fs.copySync(absoluteFrom2, absoluteTo);
113
+ _utils.fs.copySync(absoluteFrom2, absoluteTo);
115
114
  } else {
116
- await fs.copy(absoluteFrom2, absoluteTo);
115
+ await _utils.fs.copy(absoluteFrom2, absoluteTo);
117
116
  }
118
117
  });
119
118
  };
120
119
  const watchCopyFiles = async (options, copyConfig) => {
121
- const { watch, fs, logger, createDebugger } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
122
- const debug = createDebugger("module-tools:copy-watch");
120
+ const debug = (0, _utils.createDebugger)("module-tools:copy-watch");
123
121
  debug("watchMap", watchMap);
124
122
  const { SectionTitleStatus, CopyLogPrefix } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../constants/log")));
125
123
  const { watchSectionTitle } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/log")));
126
124
  const watchList = Array.from(watchMap.keys());
127
125
  debug("watchList", watchList);
128
- watch(watchList, async ({ changedFilePath, changeType }) => {
126
+ (0, _utils.watch)(watchList, async ({ changedFilePath, changeType }) => {
129
127
  var _copyConfig_options, _copyConfig;
130
128
  const result = watchMap.get(changedFilePath);
131
129
  if (!result) {
@@ -133,16 +131,16 @@ const watchCopyFiles = async (options, copyConfig) => {
133
131
  }
134
132
  const formatFilePath = _path.default.relative(options.appDirectory, changedFilePath);
135
133
  if (changeType === "unlink") {
136
- fs.remove(result);
137
- logger.log(await watchSectionTitle(CopyLogPrefix, SectionTitleStatus.Log, `${formatFilePath} removed`));
134
+ _utils.fs.remove(result);
135
+ _utils.logger.log(await watchSectionTitle(CopyLogPrefix, SectionTitleStatus.Log, `${formatFilePath} removed`));
138
136
  return;
139
137
  }
140
138
  if ((_copyConfig = copyConfig) === null || _copyConfig === void 0 ? void 0 : (_copyConfig_options = _copyConfig.options) === null || _copyConfig_options === void 0 ? void 0 : _copyConfig_options.enableCopySync) {
141
- fs.copySync(changedFilePath, result);
139
+ _utils.fs.copySync(changedFilePath, result);
142
140
  } else {
143
- await fs.copy(changedFilePath, result);
141
+ await _utils.fs.copy(changedFilePath, result);
144
142
  }
145
- logger.log(await watchSectionTitle(CopyLogPrefix, SectionTitleStatus.Log, `${formatFilePath} changed`));
143
+ _utils.logger.log(await watchSectionTitle(CopyLogPrefix, SectionTitleStatus.Log, `${formatFilePath} changed`));
146
144
  });
147
145
  };
148
146
  const copyTask = async (buildConfig, options) => {
@@ -151,10 +149,9 @@ const copyTask = async (buildConfig, options) => {
151
149
  if (!copyConfig.patterns || copyConfig.patterns.length === 0) {
152
150
  return;
153
151
  }
154
- const { default: pMap } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../compiled/p-map")));
155
152
  const concurrency = ((_copyConfig = copyConfig) === null || _copyConfig === void 0 ? void 0 : (_copyConfig_options = _copyConfig.options) === null || _copyConfig_options === void 0 ? void 0 : _copyConfig_options.concurrency) || 100;
156
153
  try {
157
- await pMap(copyConfig.patterns, async (copyOption) => {
154
+ await (0, _pmap.default)(copyConfig.patterns, async (copyOption) => {
158
155
  var _copyConfig_options2;
159
156
  await runPatterns(copyOption, {
160
157
  ...options,
@@ -167,7 +164,7 @@ const copyTask = async (buildConfig, options) => {
167
164
  });
168
165
  } catch (e) {
169
166
  if (e instanceof Error) {
170
- _logger.logger.error(`copy error: ${e.message}`);
167
+ _utils.logger.error(`copy error: ${e.message}`);
171
168
  }
172
169
  }
173
170
  if (options.watch) {
@@ -1 +1 @@
1
- {"version":3,"file":null,"mappings":";;;;;;;;;;;;EAOaA,aAAW;WAAXA;;EAyIAC,gBAAc;WAAdA;;EAyDAC,UAAQ;WAARA;;;;;iEAzMI;wBACM;AAIvB,M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QAAMsC,gBAAcrB,2GAAYrD,aAAO,QAAnBqD,8DAAqBqB,gBAAe;AACxD,MAAI;AACF,UAAMtC,KACJiB,WAAWmB,UACX,OAAMG;UAGctB;AAFlB,YAAM3D,YAAYiF,YAAY;QAC5B,GAAG3E;QACHO,iBAAgB8C,kCAAWrD,aAAO,QAAlBqD,gEAAoB9C;QACpCyC,QAAQuB,YAAYvB;QACpBjC,gBAAgBwD,YAAYK;MAC9B;IACF,GACA;MAAEF;IAAY;EAElB,SAASG,GAAP;AACA,QAAIA,aAAaC,OAAO;AACtBxB,qBAAO/B,MAAM,eAAesD,EAAEE,SAAS;IACzC;EACF;AACA,MAAI/E,QAAQiD,OAAO;AACjB,UAAMtD,eAAeK,SAASqD;EAChC;AACF;","names":["runPatterns","watchCopyFiles","copyTask","watchMap","Map","pattern","options","fs","fastGlob","globby","default","normalizePath","appDirectory","enableCopySync","from","globOptions","targetPattern","normalizedFrom","path","normalize","defaultAbsContext","defaultContext","context","isAbsolute","join","absoluteFrom","resolve","stats","stat","error","fromType","isDirectory","isFile","glob","posix","escapePath","dot","dirname","globEntries","followSymbolicLinks","cwd","objectMode","pMap","globEntry","dirent","to","toType","extname","slice","sep","relativeFrom","relative","filename","absoluteTo","outDir","watch","set","copySync","copy","copyConfig","logger","createDebugger","debug","SectionTitleStatus","CopyLogPrefix","watchSectionTitle","watchList","Array","keys","changedFilePath","changeType","result","get","formatFilePath","remove","log","Log","buildConfig","patterns","length","concurrency","copyOption","sourceDir","e","Error","message"],"sources":["../../src/builder/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/builder/copy.ts"],"sourcesContent":["import path from 'path';\nimport { logger } from '@modern-js/utils/logger';\nimport type { CopyOptions, CopyPattern } from '../types/copy';\nimport type { BaseBuildConfig } from '../types/config';\n\nconst watchMap = new Map<string, string>();\n\nexport const runPatterns = async (\n pattern: CopyPattern,\n options: {\n appDirectory: string;\n enableCopySync?: boolean;\n outDir: string;\n defaultContext: string;\n watch?: boolean;\n },\n) => {\n const { fs, fastGlob, globby } = await import('@modern-js/utils');\n const { default: normalizePath } = await import(\n '../../compiled/normalize-path'\n );\n const { appDirectory, enableCopySync = false } = options;\n const { from, globOptions = {} } = pattern;\n const targetPattern: CopyPattern = { ...pattern };\n const normalizedFrom = path.normalize(from);\n const defaultAbsContext = options.defaultContext;\n\n // when context is relative path\n if (typeof pattern.context === 'string') {\n targetPattern.context = path.isAbsolute(pattern.context)\n ? pattern.context\n : path.join(appDirectory, pattern.context);\n } else {\n targetPattern.context = defaultAbsContext;\n }\n\n let absoluteFrom;\n if (path.isAbsolute(normalizedFrom)) {\n absoluteFrom = normalizedFrom;\n } else {\n absoluteFrom = path.resolve(targetPattern.context, normalizedFrom);\n }\n\n let stats;\n try {\n stats = await fs.stat(absoluteFrom);\n } catch (error) {\n // Do Nothing\n }\n\n let fromType: 'file' | 'dir' | 'glob';\n if (stats) {\n if (stats.isDirectory()) {\n fromType = 'dir';\n } else if (stats.isFile()) {\n fromType = 'file';\n } else {\n fromType = 'glob';\n }\n } else {\n fromType = 'glob';\n }\n\n let glob;\n\n switch (fromType) {\n case 'dir':\n targetPattern.context = absoluteFrom;\n glob = path.posix.join(\n fastGlob.escapePath(normalizePath(path.resolve(absoluteFrom))),\n '**/*',\n );\n absoluteFrom = path.join(absoluteFrom, '**/*');\n\n if (typeof globOptions.dot === 'undefined') {\n globOptions.dot = true;\n }\n break;\n case 'file':\n targetPattern.context = path.dirname(absoluteFrom);\n glob = fastGlob.escapePath(normalizePath(path.resolve(absoluteFrom)));\n\n if (typeof globOptions.dot === 'undefined') {\n globOptions.dot = true;\n }\n break;\n case 'glob':\n default: {\n glob = path.isAbsolute(from)\n ? from\n : path.posix.join(\n fastGlob.escapePath(\n normalizePath(\n path.resolve(targetPattern.context ?? appDirectory),\n ),\n ),\n from,\n );\n }\n }\n\n const globEntries = await globby(glob, {\n ...{ followSymbolicLinks: true },\n ...(targetPattern.globOptions || {}),\n cwd: targetPattern.context,\n objectMode: true,\n });\n const { default: pMap } = await import('../../compiled/p-map');\n pMap(globEntries, async globEntry => {\n if (!globEntry.dirent.isFile()) {\n return;\n }\n\n const from = globEntry.path;\n const absoluteFrom = path.resolve(targetPattern.context!, from);\n const to = path.normalize(\n typeof targetPattern.to !== 'undefined' ? targetPattern.to : '',\n );\n const toType =\n path.extname(to) === '' || to.slice(-1) === path.sep ? 'dir' : 'file';\n\n const relativeFrom = path.relative(\n targetPattern.context ?? defaultAbsContext,\n absoluteFrom,\n );\n\n const filename = toType === 'dir' ? path.join(to, relativeFrom) : to;\n\n const absoluteTo = path.isAbsolute(filename)\n ? filename\n : path.join(options.outDir, filename);\n\n if (options.watch) {\n watchMap.set(absoluteFrom, absoluteTo);\n }\n\n if (enableCopySync) {\n fs.copySync(absoluteFrom, absoluteTo);\n } else {\n await fs.copy(absoluteFrom, absoluteTo);\n }\n });\n};\n\nexport const watchCopyFiles = async (\n options: {\n appDirectory: string;\n },\n copyConfig: CopyOptions,\n) => {\n const { watch, fs, logger, createDebugger } = await import(\n '@modern-js/utils'\n );\n const debug = createDebugger('module-tools:copy-watch');\n\n debug('watchMap', watchMap);\n\n const { SectionTitleStatus, CopyLogPrefix } = await import(\n '../constants/log'\n );\n const { watchSectionTitle } = await import('../utils/log');\n const watchList = Array.from(watchMap.keys());\n\n debug('watchList', watchList);\n\n watch(watchList, async ({ changedFilePath, changeType }) => {\n const result = watchMap.get(changedFilePath);\n if (!result) {\n return;\n }\n\n const formatFilePath = path.relative(options.appDirectory, changedFilePath);\n\n if (changeType === 'unlink') {\n fs.remove(result);\n logger.log(\n await watchSectionTitle(\n CopyLogPrefix,\n SectionTitleStatus.Log,\n `${formatFilePath} removed`,\n ),\n );\n return;\n }\n\n if (copyConfig?.options?.enableCopySync) {\n fs.copySync(changedFilePath, result);\n } else {\n await fs.copy(changedFilePath, result);\n }\n\n logger.log(\n await watchSectionTitle(\n CopyLogPrefix,\n SectionTitleStatus.Log,\n `${formatFilePath} changed`,\n ),\n );\n });\n};\n\nexport const copyTask = async (\n buildConfig: BaseBuildConfig,\n options: {\n appDirectory: string;\n watch?: boolean;\n },\n) => {\n const copyConfig = buildConfig.copy;\n\n if (!copyConfig.patterns || copyConfig.patterns.length === 0) {\n return;\n }\n\n const { default: pMap } = await import('../../compiled/p-map');\n const concurrency = copyConfig?.options?.concurrency || 100;\n try {\n await pMap(\n copyConfig.patterns,\n async copyOption => {\n await runPatterns(copyOption, {\n ...options,\n enableCopySync: copyConfig.options?.enableCopySync,\n outDir: buildConfig.outDir,\n defaultContext: buildConfig.sourceDir,\n });\n },\n { concurrency },\n );\n } catch (e) {\n if (e instanceof Error) {\n logger.error(`copy error: ${e.message}`);\n }\n }\n if (options.watch) {\n await watchCopyFiles(options, copyConfig);\n }\n};\n"]}
1
+ {"version":3,"file":null,"mappings":";;;;;;;;;;;;EAeaA,aAAW;WAAXA;;EAwIAC,gBAAc;WAAdA;;EAsDAC,UAAQ;WAARA;;;;;iEA7MI;uBAQV;iEAGU;AAEjB,MAAMC,WAAW,oBAAIC;AAEd,MAAMJ,cAAc,OACzBK,SACAC;AAQA,QAAM,EAAEC,SAASC,cAAa,IAAK,MAAM,iFACvC;AAEF,QAAM,EAAEC,cAAcC,iBAAiB,MAAK,IAAKJ;AACjD,QAAM,EAAEK,MAAMC,cAAc,CAAC,EAAC,IAAKP;AACnC,QAAMQ,gBAA6B;IAAE,GAAGR;EAAQ;AAChD,QAAMS,iBAAiBC,cAAKC,UAAUL;AACtC,QAAMM,oBAAoBX,QAAQY;AAGlC,MAAI,OAAOb,QAAQc,YAAY,UAAU;AACvCN,kBAAcM,UAAUJ,cAAKK,WAAWf,QAAQc,OAAO,IACnDd,QAAQc,UACRJ,cAAKM,KAAKZ,cAAcJ,QAAQc,OAAO;EAC7C,OAAO;AACLN,kBAAcM,UAAUF;EAC1B;AAEA,MAAIK;AACJ,MAAIP,cAAKK,WAAWN,iBAAiB;AACnCQ,mBAAeR;EACjB,OAAO;AACLQ,mBAAeP,cAAKQ,QAAQ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,2GAAYrD,aAAO,QAAnBqD,8DAAqBjD,gBAAgB;AACvCe,gBAAGgC,SAASW,iBAAiBE;IAC/B,OAAO;AACL,YAAM7C,UAAGiC,KAAKU,iBAAiBE;IACjC;AAEAI,kBAAOC,IACL,MAAMX,kBACJD,eACAD,mBAAmBc,KACnB,GAAGJ,wBAAwB;EAGjC;AACF;AAEO,MAAMtE,WAAW,OACtB2E,aACAvE;MAWoBqD;AANpB,QAAMA,aAAakB,YAAYnB;AAE/B,MAAI,CAACC,WAAWmB,YAAYnB,WAAWmB,SAASC,WAAW,GAAG;AAC5D;EACF;AAEA,QAAMC,gBAAcrB,2GAAYrD,aAAO,QAAnBqD,8DAAqBqB,gBAAe;AACxD,MAAI;AACF,WAAMtC,kBACJiB,WAAWmB,UACX,OAAMG;UAGctB;AAFlB,YAAM3D,YAAYiF,YAAY;QAC5B,GAAG3E;QACHI,iBAAgBiD,kCAAWrD,aAAO,QAAlBqD,gEAAoBjD;QACpC4C,QAAQuB,YAAYvB;QACpBpC,gBAAgB2D,YAAYK;MAC9B;IACF,GACA;MAAEF;IAAY;EAElB,SAASG,GAAP;AACA,QAAIA,aAAaC,OAAO;AACtBV,oBAAO/C,MAAM,eAAewD,EAAEE,SAAS;IACzC;EACF;AACA,MAAI/E,QAAQiD,OAAO;AACjB,UAAMtD,eAAeK,SAASqD;EAChC;AACF;","names":["runPatterns","watchCopyFiles","copyTask","watchMap","Map","pattern","options","default","normalizePath","appDirectory","enableCopySync","from","globOptions","targetPattern","normalizedFrom","path","normalize","defaultAbsContext","defaultContext","context","isAbsolute","join","absoluteFrom","resolve","stats","fs","stat","error","fromType","isDirectory","isFile","glob","posix","fastGlob","escapePath","dot","dirname","globEntries","globby","followSymbolicLinks","cwd","objectMode","pMap","globEntry","dirent","to","toType","extname","slice","sep","relativeFrom","relative","filename","absoluteTo","outDir","watch","set","copySync","copy","copyConfig","debug","createDebugger","SectionTitleStatus","CopyLogPrefix","watchSectionTitle","watchList","Array","keys","changedFilePath","changeType","result","get","formatFilePath","remove","logger","log","Log","buildConfig","patterns","length","concurrency","copyOption","sourceDir","e","Error","message"],"sources":["../../src/builder/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/builder/copy.ts"],"sourcesContent":["import path from 'path';\nimport {\n watch,\n fs,\n logger,\n createDebugger,\n globby,\n fastGlob,\n} from '@modern-js/utils';\nimport type { CopyOptions, CopyPattern } from '../types/config/copy';\nimport type { BaseBuildConfig } from '../types/config';\nimport pMap from '../../compiled/p-map';\n\nconst watchMap = new Map<string, string>();\n\nexport const runPatterns = async (\n pattern: CopyPattern,\n options: {\n appDirectory: string;\n enableCopySync?: boolean;\n outDir: string;\n defaultContext: string;\n watch?: boolean;\n },\n) => {\n const { default: normalizePath } = await import(\n '../../compiled/normalize-path'\n );\n const { appDirectory, enableCopySync = false } = options;\n const { from, globOptions = {} } = pattern;\n const targetPattern: CopyPattern = { ...pattern };\n const normalizedFrom = path.normalize(from);\n const defaultAbsContext = options.defaultContext;\n\n // when context is relative path\n if (typeof pattern.context === 'string') {\n targetPattern.context = path.isAbsolute(pattern.context)\n ? pattern.context\n : path.join(appDirectory, pattern.context);\n } else {\n targetPattern.context = defaultAbsContext;\n }\n\n let absoluteFrom;\n if (path.isAbsolute(normalizedFrom)) {\n absoluteFrom = normalizedFrom;\n } else {\n absoluteFrom = path.resolve(targetPattern.context, normalizedFrom);\n }\n\n let stats;\n try {\n stats = await fs.stat(absoluteFrom);\n } catch (error) {\n // Do Nothing\n }\n\n let fromType: 'file' | 'dir' | 'glob';\n if (stats) {\n if (stats.isDirectory()) {\n fromType = 'dir';\n } else if (stats.isFile()) {\n fromType = 'file';\n } else {\n fromType = 'glob';\n }\n } else {\n fromType = 'glob';\n }\n\n let glob;\n\n switch (fromType) {\n case 'dir':\n targetPattern.context = absoluteFrom;\n glob = path.posix.join(\n fastGlob.escapePath(normalizePath(path.resolve(absoluteFrom))),\n '**/*',\n );\n absoluteFrom = path.join(absoluteFrom, '**/*');\n\n if (typeof globOptions.dot === 'undefined') {\n globOptions.dot = true;\n }\n break;\n case 'file':\n targetPattern.context = path.dirname(absoluteFrom);\n glob = fastGlob.escapePath(normalizePath(path.resolve(absoluteFrom)));\n\n if (typeof globOptions.dot === 'undefined') {\n globOptions.dot = true;\n }\n break;\n case 'glob':\n default: {\n glob = path.isAbsolute(from)\n ? from\n : path.posix.join(\n fastGlob.escapePath(\n normalizePath(\n path.resolve(targetPattern.context ?? appDirectory),\n ),\n ),\n from,\n );\n }\n }\n\n const globEntries = await globby(glob, {\n ...{ followSymbolicLinks: true },\n ...(targetPattern.globOptions || {}),\n cwd: targetPattern.context,\n objectMode: true,\n });\n\n pMap(globEntries, async globEntry => {\n if (!globEntry.dirent.isFile()) {\n return;\n }\n\n const from = globEntry.path;\n const absoluteFrom = path.resolve(targetPattern.context!, from);\n const to = path.normalize(\n typeof targetPattern.to !== 'undefined' ? targetPattern.to : '',\n );\n const toType =\n path.extname(to) === '' || to.slice(-1) === path.sep ? 'dir' : 'file';\n\n const relativeFrom = path.relative(\n targetPattern.context ?? defaultAbsContext,\n absoluteFrom,\n );\n\n const filename = toType === 'dir' ? path.join(to, relativeFrom) : to;\n\n const absoluteTo = path.isAbsolute(filename)\n ? filename\n : path.join(options.outDir, filename);\n\n if (options.watch) {\n watchMap.set(absoluteFrom, absoluteTo);\n }\n\n if (enableCopySync) {\n fs.copySync(absoluteFrom, absoluteTo);\n } else {\n await fs.copy(absoluteFrom, absoluteTo);\n }\n });\n};\n\nexport const watchCopyFiles = async (\n options: {\n appDirectory: string;\n },\n copyConfig: CopyOptions,\n) => {\n const debug = createDebugger('module-tools:copy-watch');\n\n debug('watchMap', watchMap);\n\n const { SectionTitleStatus, CopyLogPrefix } = await import(\n '../constants/log'\n );\n const { watchSectionTitle } = await import('../utils/log');\n const watchList = Array.from(watchMap.keys());\n\n debug('watchList', watchList);\n\n watch(watchList, async ({ changedFilePath, changeType }) => {\n const result = watchMap.get(changedFilePath);\n if (!result) {\n return;\n }\n\n const formatFilePath = path.relative(options.appDirectory, changedFilePath);\n\n if (changeType === 'unlink') {\n fs.remove(result);\n logger.log(\n await watchSectionTitle(\n CopyLogPrefix,\n SectionTitleStatus.Log,\n `${formatFilePath} removed`,\n ),\n );\n return;\n }\n\n if (copyConfig?.options?.enableCopySync) {\n fs.copySync(changedFilePath, result);\n } else {\n await fs.copy(changedFilePath, result);\n }\n\n logger.log(\n await watchSectionTitle(\n CopyLogPrefix,\n SectionTitleStatus.Log,\n `${formatFilePath} changed`,\n ),\n );\n });\n};\n\nexport const copyTask = async (\n buildConfig: BaseBuildConfig,\n options: {\n appDirectory: string;\n watch?: boolean;\n },\n) => {\n const copyConfig = buildConfig.copy;\n\n if (!copyConfig.patterns || copyConfig.patterns.length === 0) {\n return;\n }\n\n const concurrency = copyConfig?.options?.concurrency || 100;\n try {\n await pMap(\n copyConfig.patterns,\n async copyOption => {\n await runPatterns(copyOption, {\n ...options,\n enableCopySync: copyConfig.options?.enableCopySync,\n outDir: buildConfig.outDir,\n defaultContext: buildConfig.sourceDir,\n });\n },\n { concurrency },\n );\n } catch (e) {\n if (e instanceof Error) {\n logger.error(`copy error: ${e.message}`);\n }\n }\n if (options.watch) {\n await watchCopyFiles(options, copyConfig);\n }\n};\n"]}
@@ -9,6 +9,7 @@ type Config = {
9
9
  watch: boolean;
10
10
  abortOnError: boolean;
11
11
  respectExternal: boolean;
12
+ appDirectory: string;
12
13
  };
13
14
  export declare const runRollup: (api: PluginAPI<ModuleTools>, {
14
15
  distDir,
@@ -17,5 +18,6 @@ export declare const runRollup: (api: PluginAPI<ModuleTools>, {
17
18
  input,
18
19
  watch,
19
20
  abortOnError,
20
- respectExternal
21
+ respectExternal,
22
+ appDirectory
21
23
  }: Config) => Promise<RollupWatcher | import("../../../compiled/rollup").RollupBuild | null>;
@@ -12,7 +12,11 @@ const _interop_require_default = require("@swc/helpers/_/_interop_require_defaul
12
12
  const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
13
13
  const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
14
14
  const _logger = require("@modern-js/utils/logger");
15
- const runRollup = async (api, { distDir, tsconfigPath, externals, input, watch, abortOnError, respectExternal }) => {
15
+ const _typescript = /* @__PURE__ */ _interop_require_default._(require("typescript"));
16
+ const _pluginjson = /* @__PURE__ */ _interop_require_default._(require("../../../compiled/@rollup/plugin-json"));
17
+ const _rollupplugindts = /* @__PURE__ */ _interop_require_default._(require("../../../compiled/rollup-plugin-dts"));
18
+ const _common = require("../../utils/common");
19
+ const runRollup = async (api, { distDir, tsconfigPath, externals, input, watch, abortOnError, respectExternal, appDirectory }) => {
16
20
  const ignoreFiles = {
17
21
  name: "ignore-files",
18
22
  load(id) {
@@ -22,12 +26,8 @@ const runRollup = async (api, { distDir, tsconfigPath, externals, input, watch,
22
26
  return null;
23
27
  }
24
28
  };
25
- const ts = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("typescript")));
26
- const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
27
- const { options } = ts.parseJsonConfigFileContent(configFile.config, ts.sys, "./");
28
- const { default: jsonPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../../compiled/@rollup/plugin-json")));
29
- const { default: dtsPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../../compiled/rollup-plugin-dts")));
30
- const { transformUndefineObject } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/common")));
29
+ const configFile = _typescript.default.readConfigFile(tsconfigPath, _typescript.default.sys.readFile);
30
+ const { options } = _typescript.default.parseJsonConfigFileContent(configFile.config, _typescript.default.sys, "./");
31
31
  const baseUrl = _path.default.isAbsolute(options.baseUrl || ".") ? options.baseUrl : _path.default.join(_path.default.dirname(tsconfigPath), options.baseUrl || ".");
32
32
  const ignoreCompileOptions = [
33
33
  "incremental",
@@ -35,13 +35,15 @@ const runRollup = async (api, { distDir, tsconfigPath, externals, input, watch,
35
35
  "sourceMap",
36
36
  "inlineSources"
37
37
  ];
38
+ const resolveRelative = (p) => _path.default.resolve(appDirectory, p);
39
+ const dtsInput = Array.isArray(input) ? input.map(resolveRelative) : (0, _common.mapValue)(input, resolveRelative);
38
40
  const inputConfig = {
39
- input,
41
+ input: dtsInput,
40
42
  external: externals,
41
43
  plugins: [
42
- jsonPlugin(),
44
+ (0, _pluginjson.default)(),
43
45
  ignoreFiles,
44
- dtsPlugin({
46
+ (0, _rollupplugindts.default)({
45
47
  respectExternal,
46
48
  compilerOptions: {
47
49
  skipLibCheck: true,
@@ -65,8 +67,8 @@ const runRollup = async (api, { distDir, tsconfigPath, externals, input, watch,
65
67
  // Avoid extra work
66
68
  checkJs: false,
67
69
  // Ensure we can parse the latest code
68
- target: ts.ScriptTarget.ESNext,
69
- ...transformUndefineObject(ignoreCompileOptions)
70
+ target: _typescript.default.ScriptTarget.ESNext,
71
+ ...(0, _common.transformUndefineObject)(ignoreCompileOptions)
70
72
  },
71
73
  tsconfig: tsconfigPath
72
74
  })
@@ -104,7 +106,6 @@ const runRollup = async (api, { distDir, tsconfigPath, externals, input, watch,
104
106
  const { addRollupChunk } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/print")));
105
107
  const bundle = await rollup(inputConfig);
106
108
  const rollupOutput = await bundle.write(outputConfig);
107
- const { appDirectory } = api.useAppContext();
108
109
  addRollupChunk(rollupOutput, appDirectory, outputConfig.dir);
109
110
  return bundle;
110
111
  } catch (e) {
@@ -1 +1 @@
1
- {"version":3,"file":null,"mappings":";;;;+BA2BaA;;;WAAAA;;;;;iEA3BI;wBACM;AA0BhB,MAAMA,YAAY,OACvBC,KACA,EACEC,SACAC,cACAC,WACAC,OACAC,OACAC,cACAC,gBAAe,MACR;AAET,QAAMC,cAAsB;IAC1BC,MAAM;IACNC,KAAKC,IAAE;AACL,UAAI,CAAC,kCAAkCC,KAAKD,KAAK;AAC/C,eAAO;MACT;AACA,aAAO;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,OAAMC;AACnB,UAAIA,MAAMC,SAAS,SAAS;AAC1BC,uBAAOC,KACL,MAAMX,kBAAkBE,oBAAoBD,mBAAmBW,GAAG;MAEtE,WAAWJ,MAAMC,SAAS,cAAc;AACtCC,uBAAOC,KACL,MAAMX,kBACJE,oBACAD,mBAAmBY,OAAO;AAG9BV,eAAOW,cAAc;UAAEC,WAAW;QAAS;MAC7C,WAAWP,MAAMC,SAAS,SAAS;MAEnC;IACF;AACA,WAAOJ;EACT,OAAO;AACL,QAAI;AACF,YAAM,EAAEW,OAAM,IAAK,MAAM,iFAAO;AAChC,YAAM,EAAEC,eAAc,IAAK,MAAM,iFAAO;AACxC,YAAMC,SAAS,MAAMF,OAAOvC;AAC5B,YAAM0C,eAAe,MAAMD,OAAOE,MAAMxB;AACxC,YAAM,EAAEyB,aAAY,IAAK3E,IAAI4E,cAAa;AAC1CL,qBAAeE,cAAcE,cAAczB,aAAaC,GAAG;AAC3D,aAAOqB;IACT,SAASK,GAAP;AACA,YAAM,EAAEC,sBAAqB,IAAK,MAAM,iFAAO;AAC/C,YAAMA,sBAAsBD,GAAG;QAAEvE;QAAc+D,WAAW;MAAS;AACnE,aAAO;IACT;EACF;AACF;","names":["runRollup","api","distDir","tsconfigPath","externals","input","watch","abortOnError","respectExternal","ignoreFiles","name","load","id","test","ts","configFile","readConfigFile","sys","readFile","options","parseJsonConfigFileContent","config","default","jsonPlugin","dtsPlugin","transformUndefineObject","baseUrl","path","isAbsolute","join","dirname","ignoreCompileOptions","inputConfig","external","plugins","compilerOptions","skipLibCheck","preserveSymlinks","composite","declarationMap","declaration","noEmit","emitDeclarationOnly","noEmitOnError","checkJs","target","ScriptTarget","ESNext","tsconfig","filter","Boolean","outputConfig","dir","format","exports","watchSectionTitle","SectionTitleStatus","BundleDtsLogPrefix","runner","useHookRunners","watcher","output","on","event","code","logger","info","Log","Success","buildWatchDts","buildType","rollup","addRollupChunk","bundle","rollupOutput","write","appDirectory","useAppContext","e","printOrThrowDtsErrors"],"sources":["../../../src/builder/dts/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/builder/dts/rollup.ts"],"sourcesContent":["import path from 'path';\nimport { logger } from '@modern-js/utils/logger';\nimport type {\n InputOptions,\n OutputOptions,\n Plugin,\n RollupWatcher,\n} from '../../../compiled/rollup';\nimport type {\n BaseBuildConfig,\n Input,\n PluginAPI,\n ModuleTools,\n} from '../../types';\n\nexport type { RollupWatcher };\n\ntype Config = {\n distDir: string;\n tsconfigPath: string;\n externals: BaseBuildConfig['externals'];\n input: Input;\n watch: boolean;\n abortOnError: boolean;\n respectExternal: boolean;\n};\n\nexport const runRollup = async (\n api: PluginAPI<ModuleTools>,\n {\n distDir,\n tsconfigPath,\n externals,\n input,\n watch,\n abortOnError,\n respectExternal,\n }: Config,\n) => {\n const ignoreFiles: Plugin = {\n name: 'ignore-files',\n load(id) {\n if (!/\\.(js|jsx|ts|tsx|json|cts|mts)$/.test(id)) {\n return '';\n }\n return null;\n },\n };\n const ts = await import('typescript');\n const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n const { options } = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n './',\n );\n\n const { default: jsonPlugin } = await import(\n '../../../compiled/@rollup/plugin-json'\n );\n const { default: dtsPlugin } = await import(\n '../../../compiled/rollup-plugin-dts'\n );\n const { transformUndefineObject } = await import('../../utils/common');\n\n const baseUrl = path.isAbsolute(options.baseUrl || '.')\n ? options.baseUrl\n : path.join(path.dirname(tsconfigPath), options.baseUrl || '.');\n const ignoreCompileOptions = [\n 'incremental',\n 'tsBuildInfoFile',\n 'sourceMap',\n 'inlineSources',\n ];\n\n const inputConfig: InputOptions = {\n input,\n external: externals,\n plugins: [\n jsonPlugin(),\n ignoreFiles,\n dtsPlugin({\n respectExternal,\n compilerOptions: {\n skipLibCheck: true,\n // https://github.com/Swatinem/rollup-plugin-dts/issues/143,\n // but it will cause error when bundle ts which import another ts file.\n preserveSymlinks: false,\n ...options,\n // https://github.com/Swatinem/rollup-plugin-dts/issues/127\n composite: false,\n // https://github.com/Swatinem/rollup-plugin-dts/issues/113\n declarationMap: false,\n // isAbsolute\n baseUrl,\n // Ensure \".d.ts\" modules are generated\n declaration: true,\n // Skip \".js\" generation\n noEmit: false,\n emitDeclarationOnly: true,\n // Skip code generation when error occurs\n noEmitOnError: true,\n // Avoid extra work\n checkJs: false,\n // Ensure we can parse the latest code\n target: ts.ScriptTarget.ESNext,\n ...transformUndefineObject(ignoreCompileOptions),\n },\n tsconfig: tsconfigPath,\n }),\n ].filter(Boolean),\n };\n const outputConfig: OutputOptions = {\n dir: distDir,\n format: 'esm',\n exports: 'named',\n };\n if (watch) {\n const { watch } = await import('../../../compiled/rollup');\n const { watchSectionTitle } = await import('../../utils/log');\n const { SectionTitleStatus, BundleDtsLogPrefix } = await import(\n '../../constants/log'\n );\n const runner = api.useHookRunners();\n const watcher = watch({\n ...inputConfig,\n plugins: inputConfig.plugins,\n output: outputConfig,\n }).on('event', async event => {\n if (event.code === 'START') {\n logger.info(\n await watchSectionTitle(BundleDtsLogPrefix, SectionTitleStatus.Log),\n );\n } else if (event.code === 'BUNDLE_END') {\n logger.info(\n await watchSectionTitle(\n BundleDtsLogPrefix,\n SectionTitleStatus.Success,\n ),\n );\n runner.buildWatchDts({ buildType: 'bundle' });\n } else if (event.code === 'ERROR') {\n // this is dts rollup plugin bug, error not complete message\n }\n });\n return watcher;\n } else {\n try {\n const { rollup } = await import('../../../compiled/rollup');\n const { addRollupChunk } = await import('../../utils/print');\n const bundle = await rollup(inputConfig);\n const rollupOutput = await bundle.write(outputConfig);\n const { appDirectory } = api.useAppContext();\n addRollupChunk(rollupOutput, appDirectory, outputConfig.dir!);\n return bundle;\n } catch (e) {\n const { printOrThrowDtsErrors } = await import('../../utils/dts');\n await printOrThrowDtsErrors(e, { abortOnError, buildType: 'bundle' });\n return null;\n }\n }\n};\n"]}
1
+ {"version":3,"file":null,"mappings":";;;;+BAgCaA;;;WAAAA;;;;;iEAhCI;w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/B,UAAM,EAAEyD,kBAAiB,IAAK,MAAM,iFAAO;AAC3C,UAAM,EAAEC,oBAAoBC,mBAAkB,IAAK,MAAM,iFACvD;AAEF,UAAMC,SAASjE,IAAIkE,eAAc;AACjC,UAAMC,UAAU9D,OAAM;MACpB,GAAG+B;MACHE,SAASF,YAAYE;MACrB8B,QAAQV;IACV,GAAGW,GAAG,SAAS,OAAMC;AACnB,UAAIA,MAAMC,SAAS,SAAS;AAC1BC,uBAAOC,KACL,MAAMX,kBAAkBE,oBAAoBD,mBAAmBW,GAAG;MAEtE,WAAWJ,MAAMC,SAAS,cAAc;AACtCC,uBAAOC,KACL,MAAMX,kBACJE,oBACAD,mBAAmBY,OAAO;AAG9BV,eAAOW,cAAc;UAAEC,WAAW;QAAS;MAC7C,WAAWP,MAAMC,SAAS,SAAS;MAEnC;IACF;AACA,WAAOJ;EACT,OAAO;AACL,QAAI;AACF,YAAM,EAAEW,OAAM,IAAK,MAAM,iFAAO;AAChC,YAAM,EAAEC,eAAc,IAAK,MAAM,iFAAO;AACxC,YAAMC,SAAS,MAAMF,OAAO1C;AAC5B,YAAM6C,eAAe,MAAMD,OAAOE,MAAMxB;AACxCqB,qBAAeE,cAAczE,cAAckD,aAAaC,GAAG;AAC3D,aAAOqB;IACT,SAASG,GAAP;AACA,YAAM,EAAEC,sBAAqB,IAAK,MAAM,iFAAO;AAC/C,YAAMA,sBAAsBD,GAAG;QAAE7E;QAAcuE,WAAW;MAAS;AACnE,aAAO;IACT;EACF;AACF;","names":["runRollup","api","distDir","tsconfigPath","externals","input","watch","abortOnError","respectExternal","appDirectory","ignoreFiles","name","load","id","test","configFile","ts","readConfigFile","sys","readFile","options","parseJsonConfigFileContent","config","baseUrl","path","isAbsolute","join","dirname","ignoreCompileOptions","resolveRelative","p","resolve","dtsInput","Array","isArray","map","mapValue","inputConfig","external","plugins","jsonPlugin","dtsPlugin","compilerOptions","skipLibCheck","preserveSymlinks","composite","declarationMap","declaration","noEmit","emitDeclarationOnly","noEmitOnError","checkJs","target","ScriptTarget","ESNext","transformUndefineObject","tsconfig","filter","Boolean","outputConfig","dir","format","exports","watchSectionTitle","SectionTitleStatus","BundleDtsLogPrefix","runner","useHookRunners","watcher","output","on","event","code","logger","info","Log","Success","buildWatchDts","buildType","rollup","addRollupChunk","bundle","rollupOutput","write","e","printOrThrowDtsErrors"],"sources":["../../../src/builder/dts/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/builder/dts/rollup.ts"],"sourcesContent":["import path from 'path';\nimport { logger } from '@modern-js/utils/logger';\nimport ts from 'typescript';\nimport type {\n InputOptions,\n OutputOptions,\n Plugin,\n RollupWatcher,\n} from '../../../compiled/rollup';\nimport type {\n BaseBuildConfig,\n Input,\n PluginAPI,\n ModuleTools,\n} from '../../types';\nimport jsonPlugin from '../../../compiled/@rollup/plugin-json';\nimport dtsPlugin from '../../../compiled/rollup-plugin-dts';\nimport { mapValue, transformUndefineObject } from '../../utils/common';\n\nexport type { RollupWatcher };\n\ntype Config = {\n distDir: string;\n tsconfigPath: string;\n externals: BaseBuildConfig['externals'];\n input: Input;\n watch: boolean;\n abortOnError: boolean;\n respectExternal: boolean;\n appDirectory: string;\n};\n\nexport const runRollup = async (\n api: PluginAPI<ModuleTools>,\n {\n distDir,\n tsconfigPath,\n externals,\n input,\n watch,\n abortOnError,\n respectExternal,\n appDirectory,\n }: Config,\n) => {\n const ignoreFiles: Plugin = {\n name: 'ignore-files',\n load(id) {\n if (!/\\.(js|jsx|ts|tsx|json|cts|mts)$/.test(id)) {\n return '';\n }\n return null;\n },\n };\n const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n const { options } = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n './',\n );\n\n const baseUrl = path.isAbsolute(options.baseUrl || '.')\n ? options.baseUrl\n : path.join(path.dirname(tsconfigPath), options.baseUrl || '.');\n const ignoreCompileOptions = [\n 'incremental',\n 'tsBuildInfoFile',\n 'sourceMap',\n 'inlineSources',\n ];\n const resolveRelative = (p: string) => path.resolve(appDirectory, p);\n\n // rollup don't have working directory option like esbuild,\n // so we need to resolve relative path.\n const dtsInput: Input = Array.isArray(input)\n ? input.map(resolveRelative)\n : mapValue(input, resolveRelative);\n\n const inputConfig: InputOptions = {\n input: dtsInput,\n external: externals,\n plugins: [\n jsonPlugin(),\n ignoreFiles,\n dtsPlugin({\n respectExternal,\n compilerOptions: {\n skipLibCheck: true,\n // https://github.com/Swatinem/rollup-plugin-dts/issues/143,\n // but it will cause error when bundle ts which import another ts file.\n preserveSymlinks: false,\n ...options,\n // https://github.com/Swatinem/rollup-plugin-dts/issues/127\n composite: false,\n // https://github.com/Swatinem/rollup-plugin-dts/issues/113\n declarationMap: false,\n // isAbsolute\n baseUrl,\n // Ensure \".d.ts\" modules are generated\n declaration: true,\n // Skip \".js\" generation\n noEmit: false,\n emitDeclarationOnly: true,\n // Skip code generation when error occurs\n noEmitOnError: true,\n // Avoid extra work\n checkJs: false,\n // Ensure we can parse the latest code\n target: ts.ScriptTarget.ESNext,\n ...transformUndefineObject(ignoreCompileOptions),\n },\n tsconfig: tsconfigPath,\n }),\n ].filter(Boolean),\n };\n const outputConfig: OutputOptions = {\n dir: distDir,\n format: 'esm',\n exports: 'named',\n };\n if (watch) {\n const { watch } = await import('../../../compiled/rollup');\n const { watchSectionTitle } = await import('../../utils/log');\n const { SectionTitleStatus, BundleDtsLogPrefix } = await import(\n '../../constants/log'\n );\n const runner = api.useHookRunners();\n const watcher = watch({\n ...inputConfig,\n plugins: inputConfig.plugins,\n output: outputConfig,\n }).on('event', async event => {\n if (event.code === 'START') {\n logger.info(\n await watchSectionTitle(BundleDtsLogPrefix, SectionTitleStatus.Log),\n );\n } else if (event.code === 'BUNDLE_END') {\n logger.info(\n await watchSectionTitle(\n BundleDtsLogPrefix,\n SectionTitleStatus.Success,\n ),\n );\n runner.buildWatchDts({ buildType: 'bundle' });\n } else if (event.code === 'ERROR') {\n // this is dts rollup plugin bug, error not complete message\n }\n });\n return watcher;\n } else {\n try {\n const { rollup } = await import('../../../compiled/rollup');\n const { addRollupChunk } = await import('../../utils/print');\n const bundle = await rollup(inputConfig);\n const rollupOutput = await bundle.write(outputConfig);\n addRollupChunk(rollupOutput, appDirectory, outputConfig.dir!);\n return bundle;\n } catch (e) {\n const { printOrThrowDtsErrors } = await import('../../utils/dts');\n await printOrThrowDtsErrors(e, { abortOnError, buildType: 'bundle' });\n return null;\n }\n }\n};\n"]}