@modern-js/module-tools 2.5.2-beta.4 → 2.7.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 (139) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/compiled/rollup-plugin-dts/dist/rollup-plugin-dts.d.ts +106 -3
  3. package/compiled/rollup-plugin-dts/package.json +1 -1
  4. package/dist/build.js +6 -0
  5. package/dist/build.js.map +1 -0
  6. package/dist/builder/build.js +11 -4
  7. package/dist/builder/build.js.map +1 -0
  8. package/dist/builder/clear.js +6 -0
  9. package/dist/builder/clear.js.map +1 -0
  10. package/dist/builder/copy.d.ts +6 -1
  11. package/dist/builder/copy.js +71 -13
  12. package/dist/builder/copy.js.map +1 -0
  13. package/dist/builder/dts/index.js +2 -0
  14. package/dist/builder/dts/index.js.map +1 -0
  15. package/dist/builder/dts/rollup.js +19 -1
  16. package/dist/builder/dts/rollup.js.map +1 -0
  17. package/dist/builder/dts/tsc.js +8 -0
  18. package/dist/builder/dts/tsc.js.map +1 -0
  19. package/dist/builder/index.js +6 -0
  20. package/dist/builder/index.js.map +1 -0
  21. package/dist/builder/platform.js +6 -0
  22. package/dist/builder/platform.js.map +1 -0
  23. package/dist/cli.js +6 -0
  24. package/dist/cli.js.map +1 -0
  25. package/dist/command.js +6 -0
  26. package/dist/command.js.map +1 -0
  27. package/dist/config/defineConfig.js +2 -0
  28. package/dist/config/defineConfig.js.map +1 -0
  29. package/dist/config/{legacy-schema.js → legacySchema.js} +12 -3
  30. package/dist/config/legacySchema.js.map +1 -0
  31. package/dist/config/normalize.js +8 -2
  32. package/dist/config/normalize.js.map +1 -0
  33. package/dist/config/schema.d.ts +1 -1
  34. package/dist/config/schema.js +6 -2
  35. package/dist/config/schema.js.map +1 -0
  36. package/dist/config/{transform-legacy-config.js → transformLegacyConfig.js} +11 -5
  37. package/dist/config/transformLegacyConfig.js.map +1 -0
  38. package/dist/constants/build.js +2 -0
  39. package/dist/constants/build.js.map +1 -0
  40. package/dist/constants/{build-presets.js → buildPresets.js} +5 -3
  41. package/dist/constants/buildPresets.js.map +1 -0
  42. package/dist/constants/colors.js +2 -0
  43. package/dist/constants/colors.js.map +1 -0
  44. package/dist/constants/dts.js +4 -0
  45. package/dist/constants/dts.js.map +1 -0
  46. package/dist/constants/file.js +2 -0
  47. package/dist/constants/file.js.map +1 -0
  48. package/dist/constants/{legacy-build-presets.js → legacyBuildPresets.js} +9 -3
  49. package/dist/constants/legacyBuildPresets.js.map +1 -0
  50. package/dist/constants/log.d.ts +1 -0
  51. package/dist/constants/log.js +5 -0
  52. package/dist/constants/log.js.map +1 -0
  53. package/dist/dev.js +6 -0
  54. package/dist/dev.js.map +1 -0
  55. package/dist/error.js +2 -0
  56. package/dist/error.js.map +1 -0
  57. package/dist/hooks/build.js +2 -0
  58. package/dist/hooks/build.js.map +1 -0
  59. package/dist/hooks/dev.js +3 -0
  60. package/dist/hooks/dev.js.map +1 -0
  61. package/dist/hooks/index.js +2 -0
  62. package/dist/hooks/index.js.map +1 -0
  63. package/dist/hooks/misc.js +2 -0
  64. package/dist/hooks/misc.js.map +1 -0
  65. package/dist/index.d.ts +1 -1
  66. package/dist/index.js +4 -2
  67. package/dist/index.js.map +1 -0
  68. package/dist/locale/en.js +2 -0
  69. package/dist/locale/en.js.map +1 -0
  70. package/dist/locale/index.js +2 -0
  71. package/dist/locale/index.js.map +1 -0
  72. package/dist/locale/zh.js +2 -0
  73. package/dist/locale/zh.js.map +1 -0
  74. package/dist/plugins.js +6 -0
  75. package/dist/plugins.js.map +1 -0
  76. package/dist/types/color.js +2 -0
  77. package/dist/types/color.js.map +1 -0
  78. package/dist/types/command.js +2 -0
  79. package/dist/types/command.js.map +1 -0
  80. package/dist/types/config/index.d.ts +1 -1
  81. package/dist/types/config/index.js +2 -0
  82. package/dist/types/config/index.js.map +1 -0
  83. package/dist/types/config/style.js +2 -0
  84. package/dist/types/config/style.js.map +1 -0
  85. package/dist/types/context.js +2 -0
  86. package/dist/types/context.js.map +1 -0
  87. package/dist/types/copy.js +2 -0
  88. package/dist/types/copy.js.map +1 -0
  89. package/dist/types/dts.js +2 -0
  90. package/dist/types/dts.js.map +1 -0
  91. package/dist/types/hooks.js +2 -0
  92. package/dist/types/hooks.js.map +1 -0
  93. package/dist/types/index.js +2 -0
  94. package/dist/types/index.js.map +1 -0
  95. package/dist/types/legacyConfig/index.js +2 -0
  96. package/dist/types/legacyConfig/index.js.map +1 -0
  97. package/dist/types/legacyConfig/output.js +2 -0
  98. package/dist/types/legacyConfig/output.js.map +1 -0
  99. package/dist/types/legacyConfig/source.js +2 -0
  100. package/dist/types/legacyConfig/source.js.map +1 -0
  101. package/dist/types/legacyConfig/tools.js +2 -0
  102. package/dist/types/legacyConfig/tools.js.map +1 -0
  103. package/dist/types/utils.js +2 -0
  104. package/dist/types/utils.js.map +1 -0
  105. package/dist/utils/builder.js +6 -0
  106. package/dist/utils/builder.js.map +1 -0
  107. package/dist/utils/config.js +6 -0
  108. package/dist/utils/config.js.map +1 -0
  109. package/dist/utils/context.js +6 -0
  110. package/dist/utils/context.js.map +1 -0
  111. package/dist/utils/dts.js +8 -1
  112. package/dist/utils/dts.js.map +1 -0
  113. package/dist/utils/input.js +6 -0
  114. package/dist/utils/input.js.map +1 -0
  115. package/dist/utils/language.js +6 -0
  116. package/dist/utils/language.js.map +1 -0
  117. package/dist/utils/{libuild-plugins.js → libuildPlugins.js} +9 -3
  118. package/dist/utils/libuildPlugins.js.map +1 -0
  119. package/dist/utils/log.d.ts +1 -1
  120. package/dist/utils/log.js +8 -2
  121. package/dist/utils/log.js.map +1 -0
  122. package/dist/utils/onExit.js +6 -0
  123. package/dist/utils/onExit.js.map +1 -0
  124. package/dist/utils/path.js +6 -0
  125. package/dist/utils/path.js.map +1 -0
  126. package/dist/utils/print.js +7 -0
  127. package/dist/utils/print.js.map +1 -0
  128. package/dist/utils/style.js +8 -0
  129. package/dist/utils/style.js.map +1 -0
  130. package/dist/utils/{tspaths-transform.js → tspathsTransform.js} +12 -3
  131. package/dist/utils/tspathsTransform.js.map +1 -0
  132. package/package.json +20 -18
  133. package/scripts/debug-mode.js +49 -0
  134. /package/dist/config/{legacy-schema.d.ts → legacySchema.d.ts} +0 -0
  135. /package/dist/config/{transform-legacy-config.d.ts → transformLegacyConfig.d.ts} +0 -0
  136. /package/dist/constants/{build-presets.d.ts → buildPresets.d.ts} +0 -0
  137. /package/dist/constants/{legacy-build-presets.d.ts → legacyBuildPresets.d.ts} +0 -0
  138. /package/dist/utils/{libuild-plugins.d.ts → libuildPlugins.d.ts} +0 -0
  139. /package/dist/utils/{tspaths-transform.d.ts → tspathsTransform.d.ts} +0 -0
package/dist/utils/dts.js CHANGED
@@ -34,6 +34,10 @@ var __copyProps = (to, from, except, desc) => {
34
34
  return to;
35
35
  };
36
36
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
37
+ // If the importer is in node compatibility mode or this is not an ESM
38
+ // file that has been converted to a CommonJS file using a Babel-
39
+ // compatible transform (i.e. "__esModule" has not been set), then set
40
+ // "default" to the CommonJS "module.exports" for node compatibility.
37
41
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
38
42
  mod
39
43
  ));
@@ -88,6 +92,7 @@ const generatorTsConfig = (config) => __async(void 0, null, function* () {
88
92
  const resetConfig = {
89
93
  extends: extendsPath,
90
94
  compilerOptions: {
95
+ // Ensure that .d.ts files are created by tsc, but not .js files
91
96
  declaration: true,
92
97
  emitDeclarationOnly: true,
93
98
  outDir: tempDistAbsOurDir
@@ -125,7 +130,7 @@ const resolveAlias = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], functio
125
130
  var _a, _b;
126
131
  const { userTsconfig, tempDistAbsSrcPath, tempDistAbsRootPath } = options;
127
132
  const { globby, fs } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
128
- const { transformDtsAlias } = yield Promise.resolve().then(() => __toESM(require("./tspaths-transform")));
133
+ const { transformDtsAlias } = yield Promise.resolve().then(() => __toESM(require("./tspathsTransform")));
129
134
  const { distAbsPath } = config;
130
135
  const dtsDistPath = `${tempDistAbsSrcPath}/**/*.d.ts`;
131
136
  const dtsFilenames = watchFilenames.length > 0 ? watchFilenames : globby.sync(dtsDistPath, { absolute: true });
@@ -159,3 +164,5 @@ const assignTsConfigPath = (config, options) => __async(void 0, null, function*
159
164
  getTscBinPath,
160
165
  resolveAlias
161
166
  });
167
+
168
+ //# sourceMappingURL=dts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAYV,MAAM,oBAAoB,CAC/B,WACG;AACH,QAAM,EAAE,IAAI,OAAO,IAAI,MAAM,6CAAO,kBAAkB;AACtD,QAAM,EAAE,iBAAiB,IAAI,MAAM,6CAAO,kBAAkB;AAE5D,QAAM,EAAE,cAAc,WAAW,cAAc,aAAa,IAAI;AAChE,QAAM,sBAAsB,oBAAK;AAAA,IAC/B;AAAA,IACA,GAAG,oBAAoB,OAAO;AAAA,EAChC;AACA,QAAM,oBAAoB,oBAAK;AAAA,IAC7B;AAAA,IACA,oBAAK,SAAS,cAAc,YAAY;AAAA,EAC1C;AAEA,QAAM,mBAAmB,oBAAK,KAAK,qBAAqB,eAAe;AACvE,KAAG,eAAe,gBAAgB;AAElC,QAAM,cAAc,oBAAK;AAAA,IACvB,oBAAK,SAAS,oBAAK,QAAQ,gBAAgB,GAAG,oBAAK,QAAQ,YAAY,CAAC;AAAA,IACxE,oBAAK,SAAS,gBAAgB;AAAA,EAChC;AAEA,QAAM,cAAyB;AAAA,IAC7B,SAAS;AAAA,IACT,iBAAiB;AAAA;AAAA,MAEf,aAAa;AAAA,MACb,qBAAqB;AAAA,MACrB,QAAQ;A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MAAM,EAAE,OAAO;AAAA,EACpC;AAEA,QAAM,GAAG,KAAK,oBAAoB,WAAW;AAC/C;AAgDO,MAAM,qBAAqB,CAChC,QACA,YACG;AAjKL;AAkKE,QAAM,EAAE,oBAAoB,IAAI,MAAM,6CAAO,kBAAkB;AAG/D,MACE,OAAO,QAAQ,aAAa,YAC5B,QAAQ,aAAa,qBACrB;AACA,WAAO,MAAM;AAAA,MACX,MAAM;AAAA,MACN,UAAU;AAAA,QACN,YAAO,QAAP,YAAc,CAAC,IAHR;AAAA,MAIX,cAAc,QAAQ;AAAA,IACxB;AAAA,EACF;AAEA,SAAO;AACT;;;;;;;;","names":[],"sources":["../../src/utils/dts.ts"],"sourcesContent":["import path from 'path';\n// import type { NodePath } from '../../compiled/@babel/traverse';\n// import type * as tt from '../../compiled/@babel/types';\n// import t from '../../compiled/@babel/types';\nimport type {\n ITsconfig,\n BundlelessGeneratorDtsConfig,\n BuildCommandOptions,\n BaseBuildConfig,\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(tempDistAbsRootPath, `tsconfig.json`);\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 outDir: 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 ...(config.dts ?? {}),\n tsconfigPath: options.tsconfig,\n };\n }\n\n return config;\n};\n"]}
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -109,3 +113,5 @@ const normalizeInput = (baseConfig, options) => __async(void 0, null, function*
109
113
  getDefaultIndexEntry,
110
114
  normalizeIn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J,QAAM,EAAE,GAAG,IAAI,MAAM,6CAAO,kBAAkB;AAC9C,MAAI,QAAQ,cACR,oBAAK,KAAK,cAAc,gBAAgB,IACxC,oBAAK,KAAK,cAAc,gBAAgB;AAC5C,MAAI,GAAG,WAAW,KAAK,GAAG;AACxB,WAAO,CAAC,KAAK,oBAAK,SAAS,cAAc,KAAK,GAAG;AAAA,EACnD;AAEA,UAAQ,cACJ,oBAAK,KAAK,cAAc,iBAAiB,IACzC,oBAAK,KAAK,cAAc,iBAAiB;AAC7C,MAAI,GAAG,WAAW,KAAK,GAAG;AACxB,WAAO,CAAC,KAAK,oBAAK,SAAS,cAAc,KAAK,GAAG;AAAA,EACnD;AAEA,SAAO,CAAC;AACV;AAEO,MAAM,iBAAiB,CAC5B,YACA,YACG;AACH,MAAI,WAAW,cAAc,gBAAgB,CAAC,WAAW,OAAO;AAC9D,UAAM,EAAE,MAAM,IAAI,MAAM,6CAAO,kBAAkB;AACjD,WAAO,CAAC,MAAM,WAAW,SAAS,CAAC;AAAA,EACrC;AACA,SAAO,YAAY,WAAW,OAAO,OAAO;AAC9C;;;;;;;;","names":[],"sources":["../../src/utils/input.ts"],"sourcesContent":["import path from 'path';\nimport { ModuleContext } from '../types';\nimport type {\n Input,\n BaseBuildConfig,\n PartialBuildConfig,\n} from '../types/config';\n\ninterface EntryOptions {\n appDirectory: string;\n}\n\nexport const getAbsInput = async (entry: Input, options: EntryOptions) => {\n const { slash } = await import('@modern-js/utils');\n const { appDirectory } = options;\n\n if (Array.isArray(entry)) {\n return entry.map(p =>\n path.isAbsolute(p) ? slash(p) : slash(path.join(appDirectory, p)),\n );\n }\n\n const newEntry: Record<string, string> = {};\n for (const key of Object.keys(entry)) {\n newEntry[key] = path.isAbsolute(entry[key])\n ? slash(entry[key])\n : slash(path.join(appDirectory, entry[key]));\n }\n return newEntry;\n};\n\nexport const addInputToPreset = async (\n config: PartialBuildConfig,\n context: ModuleContext,\n) => {\n if (Array.isArray(config)) {\n for (const c of config) {\n if (c.buildType === 'bundle') {\n c.input = await getDefaultIndexEntry(context);\n } else if (c.buildType === 'bundleless') {\n c.sourceDir = './src';\n }\n }\n } else if (config.buildType === 'bundle') {\n config.input = await getDefaultIndexEntry(context);\n } else if (config.buildType === 'bundleless') {\n config.sourceDir = './src';\n }\n\n return config;\n};\n\nexport const getDefaultIndexEntry = async ({\n isTsProject,\n appDirectory,\n}: {\n isTsProject: boolean;\n appDirectory: string;\n}) => {\n const { fs } = await import('@modern-js/utils');\n let entry = isTsProject\n ? path.join(appDirectory, './src/index.ts')\n : path.join(appDirectory, './src/index.js');\n if (fs.existsSync(entry)) {\n return [`./${path.relative(appDirectory, entry)}`];\n }\n\n entry = isTsProject\n ? path.join(appDirectory, './src/index.tsx')\n : path.join(appDirectory, './src/index.jsx');\n if (fs.existsSync(entry)) {\n return [`./${path.relative(appDirectory, entry)}`];\n }\n\n return [];\n};\n\nexport const normalizeInput = async (\n baseConfig: BaseBuildConfig,\n options: EntryOptions,\n) => {\n if (baseConfig.buildType === 'bundleless' && !baseConfig.input) {\n const { slash } = await import('@modern-js/utils');\n return [slash(baseConfig.sourceDir)];\n }\n return getAbsInput(baseConfig.input, options);\n};\n"]}
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -64,3 +68,5 @@ const initLocalLanguage = () => __async(void 0, null, function* () {
64
68
  getLocaleLanguage,
65
69
  initLocalLanguage
66
70
  });
71
+
72
+ //# sourceMappingURL=language.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAuB;AAEvB,MAAM,OACJ,oBAAO,KAAK,4CAA4C,OAAO;AAE1D,SAAS,oBAAoB;AAClC,QAAM,WAAW,IAAI,KAAK,uBAAuB;AACjD,SAAO,SAAS,OAAO;AACzB;AAEO,MAAM,oBAAoB,MAAY;AAC3C,QAAM,QAAQ,MAAM,6CAAO,WAAW;AACtC,QAAM,SAAS,kBAAkB;AACjC,QAAM,KAAK,eAAe,EAAE,OAAO,CAAC;AACpC,SAAO;AACT;;;;;;","names":[],"sources":["../../src/utils/language.ts"],"sourcesContent":["import { Import } from '@modern-js/utils';\n\nconst i18n: typeof import('@modern-js/plugin-i18n/language-detector') =\n Import.lazy('@modern-js/plugin-i18n/language-detector', require);\n\nexport function getLocaleLanguage() {\n const detector = new i18n.I18CLILanguageDetector();\n return detector.detect();\n}\n\nexport const initLocalLanguage = async () => {\n const local = await import('../locale');\n const locale = getLocaleLanguage();\n local.i18n.changeLanguage({ locale });\n return local;\n};\n"]}
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -41,12 +45,12 @@ var __async = (__this, __arguments, generator) => {
41
45
  step((generator = generator.apply(__this, __arguments)).next());
42
46
  });
43
47
  };
44
- var libuild_plugins_exports = {};
45
- __export(libuild_plugins_exports, {
48
+ var libuildPlugins_exports = {};
49
+ __export(libuildPlugins_exports, {
46
50
  externalPlugin: () => externalPlugin,
47
51
  watchPlugin: () => watchPlugin
48
52
  });
49
- module.exports = __toCommonJS(libuild_plugins_exports);
53
+ module.exports = __toCommonJS(libuildPlugins_exports);
50
54
  const watchPlugin = (api, config) => {
51
55
  return {
52
56
  name: "watch-plugin",
@@ -81,3 +85,5 @@ const externalPlugin = (config, options) => {
81
85
  externalPlugin,
82
86
  watchPlugin
83
87
  });
88
+
89
+ //# sourceMappingURL=libuildPlugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,cAAc,CACzB,KACA,WACkB;AAClB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,UAAU;AACd,eAAS,MAAM,YAAY,IAAI,gBAAgB,MAAY;AACzD,cAAM,EAAE,kBAAkB,IAAI,MAAM,6CAAO,OAAO;AAClD,cAAM,EAAE,mBAAmB,IAAI,MAAM,6CAAO,kBAAkB;AAC9D,cAAM,YAAY,IAChB,OAAO,cAAc,WAAW,WAAW,gBACzC,OAAO,UAAU,OAAO;AAC5B,gBAAQ;AAAA,UACN,MAAM,kBAAkB,WAAW,mBAAmB,GAAG;AAAA,QAC3D;AACA,cAAM,SAAS,IAAI,eAAe;AAClC,eAAO,aAAa,EAAE,aAAa,OAAO,CAAC;AAAA,MAC7C,EAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,MAAM,iBAAiB,CAC5B,QACA,YACkB;AAClB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,UAAU;AACd,eAAS,MAAM,WAAW,WAAW,mBAAmB,MAAY;AAClE,cAAM,EAAE,kBAAkB,IAAI,MAAM,6CAAO,WAAW;AACtD,cAAM,iBAAiB,MAAM,kBAAkB,QAAQ,OAAO;AAC9D,iBAAS,OAAO,WAAW;AAAA,MAC7B,EAAC;AAAA,IACH;AAAA,EACF;AACF;;;;;;","names":[],"sources":["../../src/utils/libuildPlugins.ts"],"sourcesContent":["import type { LibuildPlugin } from '@modern-js/libuild';\nimport type { BaseBuildConfig, PluginAPI, ModuleTools } from '../types';\n\nexport const watchPlugin = (\n api: PluginAPI<ModuleTools>,\n config: BaseBuildConfig,\n): LibuildPlugin => {\n return {\n name: 'watch-plugin',\n apply(compiler) {\n compiler.hooks.watchChange.tap('watch-plugin', async () => {\n const { watchSectionTitle } = await import('./log');\n const { SectionTitleStatus } = await import('../constants/log');\n const titleText = `[${\n config.buildType === 'bundle' ? 'Bundle' : 'Bundleless'\n }:${config.format}_${config.target}]`;\n console.info(\n await watchSectionTitle(titleText, SectionTitleStatus.Log),\n );\n const runner = api.useHookRunners();\n runner.buildWatchJs({ buildConfig: config });\n });\n },\n };\n};\n\nexport const externalPlugin = (\n config: BaseBuildConfig,\n options: { appDirectory: string },\n): LibuildPlugin => {\n return {\n name: 'external-plugin',\n apply(compiler) {\n compiler.hooks.initialize.tapPromise('external-plugin', async () => {\n const { getFinalExternals } = await import('./builder');\n const finalExternals = await getFinalExternals(config, options);\n compiler.config.external = finalExternals;\n });\n },\n };\n};\n"]}
@@ -1,2 +1,2 @@
1
1
  import { SectionTitleStatus } from '../constants/log';
2
- export declare const watchSectionTitle: (str: string, status: SectionTitleStatus) => Promise<string>;
2
+ export declare const watchSectionTitle: (str: string, status: SectionTitleStatus, detailLog?: string) => Promise<string>;
package/dist/utils/log.js CHANGED
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -47,7 +51,7 @@ __export(log_exports, {
47
51
  });
48
52
  module.exports = __toCommonJS(log_exports);
49
53
  var import_log = require("../constants/log");
50
- const watchSectionTitle = (str, status) => __async(void 0, null, function* () {
54
+ const watchSectionTitle = (str, status, detailLog) => __async(void 0, null, function* () {
51
55
  const { chalk } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
52
56
  if (status === import_log.SectionTitleStatus.Success) {
53
57
  return `${chalk.bgWhite.gray.underline(str)} ${chalk.green.underline(
@@ -58,9 +62,11 @@ const watchSectionTitle = (str, status) => __async(void 0, null, function* () {
58
62
  "Build Failed"
59
63
  )}`;
60
64
  }
61
- return `${chalk.bgWhite.gray.underline(str)} ${chalk.blue.underline("Log")}`;
65
+ return `${chalk.bgWhite.gray.underline(str)} ${detailLog ? detailLog : chalk.blue.underline("Log")}`;
62
66
  });
63
67
  // Annotate the CommonJS export names for ESM import in node:
64
68
  0 && (module.exports = {
65
69
  watchSectionTitle
66
70
  });
71
+
72
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAmC;AAE5B,MAAM,oBAAoB,CAC/B,KACA,QACA,cACG;AACH,QAAM,EAAE,MAAM,IAAI,MAAM,6CAAO,kBAAkB;AACjD,MAAI,WAAW,8BAAmB,SAAS;AACzC,WAAO,GAAG,MAAM,QAAQ,KAAK,UAAU,GAAG,KAAK,MAAM,MAAM;AAAA,MACzD;AAAA,IACF;AAAA,EACF,WAAW,WAAW,8BAAmB,MAAM;AAC7C,WAAO,GAAG,MAAM,QAAQ,KAAK,UAAU,GAAG,KAAK,MAAM,IAAI;AAAA,MACvD;AAAA,IACF;AAAA,EACF;AAEA,SAAO,GAAG,MAAM,QAAQ,KAAK,UAAU,GAAG,KACxC,YAAY,YAAY,MAAM,KAAK,UAAU,KAAK;AAEtD;;;;;","names":[],"sources":["../../src/utils/log.ts"],"sourcesContent":["import { SectionTitleStatus } from '../constants/log';\n\nexport const watchSectionTitle = async (\n str: string,\n status: SectionTitleStatus,\n detailLog?: string,\n) => {\n const { chalk } = await import('@modern-js/utils');\n if (status === SectionTitleStatus.Success) {\n return `${chalk.bgWhite.gray.underline(str)} ${chalk.green.underline(\n 'Successful',\n )}`;\n } else if (status === SectionTitleStatus.Fail) {\n return `${chalk.bgWhite.gray.underline(str)} ${chalk.red.underline(\n 'Build Failed',\n )}`;\n }\n\n return `${chalk.bgWhite.gray.underline(str)} ${\n detailLog ? detailLog : chalk.blue.underline('Log')\n }`;\n};\n"]}
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -59,3 +63,5 @@ const addExitListener = (fn) => __async(void 0, null, function* () {
59
63
  0 && (module.exports = {
60
64
  addExitListener
61
65
  });
66
+
67
+ //# sourceMappingURL=onExit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,kBAAkB,CAAO,OAA4B;AAChE,QAAM,EAAE,SAAS,OAAO,IAAI,MAAM,6CAAO,4BAA4B;AAErE,SAAO,CAAM,SAAQ;AACnB,QAAI,SAAS,GAAG;AACd;AAAA,IACF;AAEA,UAAM,GAAG;AAAA,EACX,EAAC;AACH;;;;;","names":[],"sources":["../../src/utils/onExit.ts"],"sourcesContent":["export const addExitListener = async (fn: () => Promise<void>) => {\n const { default: onExit } = await import('../../compiled/signal-exit');\n\n onExit(async code => {\n if (code === 0) {\n return;\n }\n\n await fn();\n });\n};\n"]}
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -55,3 +59,5 @@ const getCompiledPath = (packageName) => __async(void 0, null, function* () {
55
59
  0 && (module.exports = {
56
60
  getCompiledPath
57
61
  });
62
+
63
+ //# sourceMappingURL=path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAEV,MAAM,kBAAkB,CAAO,gBAAwB;AAC5D,QAAM,EAAE,MAAM,IAAI,MAAM,6CAAO,kBAAkB;AACjD,SAAO,MAAM,oBAAK,KAAK,WAAW,kBAAkB,WAAW,CAAC;AAClE;;;;;","names":[],"sources":["../../src/utils/path.ts"],"sourcesContent":["import path from 'path';\n\nexport const getCompiledPath = async (packageName: string) => {\n const { slash } = await import('@modern-js/utils');\n return slash(path.join(__dirname, '../../compiled', packageName));\n};\n"]}
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -77,6 +81,7 @@ const addRollupChunk = (rollupOutput, appDirectory, distDir) => {
77
81
  ...output.map((o) => {
78
82
  return {
79
83
  name: (0, import_path.relative)(appDirectory, (0, import_path.resolve)(distDir, o.fileName)),
84
+ // only d.ts, is outputChunk not outputAsset
80
85
  size: o.code.length
81
86
  };
82
87
  })
@@ -156,3 +161,5 @@ const printBundlelessInfo = () => {
156
161
  printFileSize,
157
162
  printSucceed
158
163
  });
164
+
165
+ //# sourceMappingURL=print.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAkC;AAElC,mBAA8B;AAK9B,iBAIO;AAOA,MAAM,cAAuB,CAAC;AAE9B,MAAM,kBAA2B,CAAC;AAElC,MAAM,iBAAiB,CAC5B,aACA,cACA,aACG;AACH,QAAM,QAAQ,MAAM,KAAK,WAAW,EAAE,IAAI,SAAO;AAC/C,UAAM,CAAC,MAAM,KAAK,IAAI;AACtB,WAAO;AAAA,MACL,UAAM,sBAAS,cAAc,IAAI;AAAA,MACjC,MAAM,MAAM,SAAS;AAAA,IACvB;AAAA,EACF,CAAC;AACD,MAAI,UAAU;AACZ,gBAAY,KAAK,GAAG,KAAK;AAAA,EAC3B,OAAO;AACL,oBAAgB,KAAK,GAAG,KAAK;AAAA,EAC/B;AACF;AAEO,MAAM,iBAAiB,CAC5B,cACA,cACA,YACG;AACH,QAAM,EAA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AK,QAAQ,KAAK,IAAI,KAAK,IAAI,KAAK,MAAM;AAAA,IAC3C,+BAAoB;AAAA,EACtB;AACA,QAAM,OAAO,oBAAoB,YAAY;AAAA;AAE7C,QAAM,YACJ,iCACA,IAAI,OAAO,oBAAoB,EAAE,IACjC;AAEF,sBAAO,KAAK,mBAAM,KAAK,mBAAM,KAAK,IAAI,CAAC,CAAC;AACxC,sBAAO,IAAI,mBAAM,KAAK,mBAAM,MAAM,SAAS,CAAC,CAAC;AAE7C,cAAY,QAAQ,CAAC,EAAE,MAAM,KAAK,MAAM;AACtC,UAAM,UAAU,GAAG,OAAO,IAAI;AAAA,MAC5B,oBAAoB,KAAK,SAAS;AAAA,IACpC,IAAI,YAAY,IAAI;AACpB,wBAAO,IAAI,OAAO;AAAA,EACpB,CAAC;AACH;AAEA,MAAM,sBAAsB,MAAM;AAChC,MAAI,gBAAgB,WAAW,GAAG;AAChC;AAAA,EACF;AAEA,QAAM,QAAQ,gBAAgB;AAC9B,QAAM,YAAY,gBAAgB,OAAO,CAAC,OAAO,SAAS;AACxD,WAAO,QAAQ,KAAK;AAAA,EACtB,GAAG,CAAC;AACJ,QAAM,OAAO,wBAAwB,kCAAkC;AAAA,IACrE;AAAA,EACF;AACA,sBAAO,KAAK,mBAAM,KAAK,mBAAM,KAAK,IAAI,CAAC,CAAC;AAC1C;;;;;;;;;;;","names":[],"sources":["../../src/utils/print.ts"],"sourcesContent":["import { relative, resolve } from 'path';\nimport type { ILibuilder } from '@modern-js/libuild';\nimport { chalk, logger } from '@modern-js/utils';\nimport type {\n RollupOutput,\n OutputChunk,\n} from '../../compiled/rollup/types/rollup';\nimport {\n buildSuccessText,\n reportFile1LineText,\n reportFile2LineText,\n} from '../constants/log';\n\ntype Files = {\n name: string;\n size: number;\n};\n\nexport const bundleFiles: Files[] = [];\n\nexport const bundlelessFiles: Files[] = [];\n\nexport const addOutputChunk = (\n outputChunk: ILibuilder['outputChunk'],\n appDirectory: string,\n isBundle: boolean,\n) => {\n const files = Array.from(outputChunk).map(val => {\n const [path, chunk] = val;\n return {\n name: relative(appDirectory, path),\n size: chunk.contents.length,\n };\n });\n if (isBundle) {\n bundleFiles.push(...files);\n } else {\n bundlelessFiles.push(...files);\n }\n};\n\nexport const addRollupChunk = (\n rollupOutput: RollupOutput,\n appDirectory: string,\n distDir: string,\n) => {\n const { output } = rollupOutput;\n bundleFiles.push(\n ...output.map(o => {\n return {\n name: relative(appDirectory, resolve(distDir, o.fileName)),\n // only d.ts, is outputChunk not outputAsset\n size: (o as OutputChunk).code.length,\n };\n }),\n );\n};\n\nexport const addDtsFiles = async (distDir: string, appDirectory: string) => {\n const { fastGlob, slash } = await import('@modern-js/utils');\n const files = await fastGlob(`${slash(distDir)}**/*.d.ts`, {\n stats: true,\n });\n bundlelessFiles.push(\n ...files.map(file => {\n return {\n name: relative(appDirectory, file.path),\n size: file.stats.size,\n };\n }),\n );\n};\n\nexport const printFileSize = () => {\n printBundlelessInfo();\n printBundleFiles();\n};\n\nexport const printSucceed = (totalDuration: number) => {\n logger.info(\n chalk.bold(chalk.blue(`${buildSuccessText}: ${totalDuration / 1000}s`)),\n );\n};\n\nconst prettyBytes = (bytes: number) => {\n if (bytes === 0) {\n return '0 B';\n }\n const unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n const exp = Math.floor(Math.log(bytes) / Math.log(1024));\n return `${(bytes / Math.pow(1024, exp)).toFixed(2)} ${unit[exp]}`;\n};\n\nconst printBundleFiles = () => {\n if (bundleFiles.length === 0) {\n return;\n }\n const longestFileLength = bundleFiles.reduce(\n (max, str) => Math.max(max, str.name.length),\n reportFile1LineText.length,\n );\n const info = `Bundle generated ${bundleFiles.length} files\\n`;\n\n const headerRow =\n reportFile1LineText +\n ' '.repeat(longestFileLength - 10) +\n reportFile2LineText;\n\n logger.info(chalk.bold(chalk.blue(info)));\n logger.log(chalk.bold(chalk.green(headerRow)));\n\n bundleFiles.forEach(({ name, size }) => {\n const infoRow = `${name}${' '.repeat(\n longestFileLength - name.length + 2,\n )}${prettyBytes(size)}`;\n logger.log(infoRow);\n });\n};\n\nconst printBundlelessInfo = () => {\n if (bundlelessFiles.length === 0) {\n return;\n }\n\n const count = bundlelessFiles.length;\n const totalSize = bundlelessFiles.reduce((total, file) => {\n return total + file.size;\n }, 0);\n const info = `Bundleless generated ${count} files, the total size is ${prettyBytes(\n totalSize,\n )}`;\n logger.info(chalk.bold(chalk.blue(info)));\n};\n"]}
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -90,6 +94,8 @@ const getPostcssConfig = (config) => __async(void 0, null, function* () {
90
94
  };
91
95
  const mergedConfig = applyOptionsChain(
92
96
  {
97
+ // TODO: when schema support redefine
98
+ // $$tools: 'module-tools',
93
99
  plugins: [
94
100
  require(yield getCompiledPath("postcss-flexbugs-fixes")),
95
101
  require(yield getCompiledPath("postcss-custom-properties")),
@@ -125,3 +131,5 @@ const getStyleConfig = (config) => __async(void 0, null, function* () {
125
131
  getSassConfig,
126
132
  getStyleConfig
127
133
  });
134
+
135
+ //# sourceMappingURL=style.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASO,MAAM,gBAAgB,CAAO,WAAmC;AATvE;AAUE,QAAM,EAAE,kBAAkB,IAAI,MAAM,6CAAO,k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sBAAsB,CAAC;AAAA,QACrD,QAAQ,MAAM,gBAAgB,sBAAsB,CAAC;AAAA,QACrD,QAAQ,MAAM,gBAAgB,iBAAiB,CAAC;AAAA,MAClD,EAAE,OAAO,OAAO;AAAA,IAClB;AAAA,MACA,sCAAQ,UAAR,mBAAe,YAAW,CAAC;AAAA,IAC3B;AAAA,EACF;AACA,MAAI,aAAa,QAAQ;AACvB,iBAAa,QAAS,KAAK,GAAG,YAAY;AAAA,EAC5C;AAEA,SAAO;AACT;AAEO,MAAM,iBAAiB,CAAO,WAAmC;AACtE,QAAM,gBAAgB,MAAM,iBAAiB,MAAM;AACnD,QAAM,aAAa,MAAM,cAAc,MAAM;AAC7C,QAAM,aAAa,MAAM,cAAc,MAAM;AAC7C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AACF;;;;;;;;","names":[],"sources":["../../src/utils/style.ts"],"sourcesContent":["import type { AcceptedPlugin } from 'postcss';\nimport type { PostcssOptions } from '@modern-js/libuild';\nimport type {\n PartialBaseBuildConfig,\n PostCSSConfigUtils,\n LessOptions,\n SassOptions,\n} from '../types';\n\nexport const getLessConfig = async (config: PartialBaseBuildConfig) => {\n const { applyOptionsChain } = await import('@modern-js/utils');\n const { getCompiledPath } = await import('./path');\n\n const mergedOptions = applyOptionsChain<LessOptions, never>(\n {\n lessOptions: { javascriptEnabled: true },\n implementation: await getCompiledPath('less'),\n },\n config?.style?.less || {},\n );\n\n return mergedOptions;\n};\n\nexport const getSassConfig = async (config: PartialBaseBuildConfig) => {\n const { applyOptionsChain } = await import('@modern-js/utils');\n const { getCompiledPath } = await import('./path');\n\n const mergedOptions = applyOptionsChain<SassOptions, never>(\n {\n implementation: await getCompiledPath('sass'),\n },\n config?.style?.sass || {},\n );\n\n return mergedOptions;\n};\n\nexport const getPostcssConfig = async (config: PartialBaseBuildConfig) => {\n const { applyOptionsChain } = await import('@modern-js/utils');\n const { getCompiledPath } = await import('./path');\n const extraPlugins: AcceptedPlugin[] = [];\n\n const utils = {\n addPlugins(plugins: AcceptedPlugin | AcceptedPlugin[]) {\n if (Array.isArray(plugins)) {\n extraPlugins.push(...plugins);\n } else {\n extraPlugins.push(plugins);\n }\n },\n };\n\n const mergedConfig = applyOptionsChain<\n PostcssOptions & { $$tools?: string },\n PostCSSConfigUtils\n >(\n {\n // TODO: when schema support redefine\n // $$tools: 'module-tools',\n plugins: [\n require(await getCompiledPath('postcss-flexbugs-fixes')),\n require(await getCompiledPath('postcss-custom-properties')),\n require(await getCompiledPath('postcss-initial')),\n require(await getCompiledPath('postcss-page-break')),\n require(await getCompiledPath('postcss-font-variant')),\n require(await getCompiledPath('postcss-media-minmax')),\n require(await getCompiledPath('postcss-nesting')),\n ].filter(Boolean),\n },\n config?.style?.postcss || {},\n utils,\n );\n if (extraPlugins.length) {\n mergedConfig.plugins!.push(...extraPlugins);\n }\n\n return mergedConfig;\n};\n\nexport const getStyleConfig = async (config: PartialBaseBuildConfig) => {\n const postcssConfig = await getPostcssConfig(config);\n const lessConfig = await getLessConfig(config);\n const sassConfig = await getSassConfig(config);\n return {\n less: lessConfig,\n sass: sassConfig,\n postcss: postcssConfig,\n };\n};\n"]}
@@ -17,15 +17,19 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
23
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var tspaths_transform_exports = {};
25
- __export(tspaths_transform_exports, {
28
+ var tspathsTransform_exports = {};
29
+ __export(tspathsTransform_exports, {
26
30
  transformDtsAlias: () => transformDtsAlias
27
31
  });
28
- module.exports = __toCommonJS(tspaths_transform_exports);
32
+ module.exports = __toCommonJS(tspathsTransform_exports);
29
33
  var path = __toESM(require("path"));
30
34
  var import_tsconfig_paths = require("@modern-js/utils/tsconfig-paths");
31
35
  var import_utils = require("@modern-js/utils");
@@ -84,9 +88,12 @@ const transformSingleFileAlias = ({
84
88
  const ast = parser.parse(sourceCode, {
85
89
  sourceType: "module",
86
90
  errorRecovery: true,
91
+ // 防止typescript不支持的语法出现而报错
87
92
  plugins: ["typescript"]
88
93
  });
89
94
  (0, import_traverse.default)(ast, {
95
+ // d.ts file content not have callExpression which can be parsed;
96
+ // CallExpression: transformCall({ filename, baseUrl, paths }) as any,
90
97
  ImportDeclaration: transformImport({
91
98
  filename,
92
99
  baseUrl,
@@ -115,3 +122,5 @@ const transformDtsAlias = (option) => {
115
122
  0 && (module.exports = {
116
123
  transformDtsAlias
117
124
  });
125
+
126
+ //# sourceMappingURL=tspathsTransform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,WAAsB;AACtB,4BAAgC;AAChC,mBAAmB;AACnB,aAAwB;AACxB,uBAAsB;AACtB,QAAmB;AACnB,sBAAmC;AACnC,kBAA6B;AAU7B,SAAS,cACP,UACA,EAAE,UAAU,SAAS,MAAM,GAC3B;AACA,MAAI,CAAC,EAAE,gBAAgB,QAAQ,GAAG;AAChC;AAAA,EACF;AAEA,QAAM,aAAa,SAAS,KAAK;AACjC,QAAM,cAAc;AACpB,QAAM,gBAAY;AAAA,IAChB;AAAA,IACA;AAAA,IACA,CAAC,OAAO;AAAA,EACV;AACA,QAAM,SAAS;AAAA,IACb;AAAA,IACA,qBAAmB;AACjB,UAAI,CAAC,gBAAG,WAAW,eAAe,GAAG;AACnC,eAAO;AAAA,MACT;AACA,aAAO,gBAAG,a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C9D,aAAW,YAAY,WAAW;AAChC,oBAAgB,KAAK;AAAA,MACnB,MAAM;AAAA,MACN,SAAS,yBAAyB,EAAE,UAAU,SAAS,MAAM,CAAC;AAAA,IAChE,CAAC;AAAA,EACH;AACA,SAAO;AACT;;;;;","names":[],"sources":["../../src/utils/tspathsTransform.ts"],"sourcesContent":["import * as path from 'path';\nimport { createMatchPath } from '@modern-js/utils/tsconfig-paths';\nimport { fs } from '@modern-js/utils';\nimport * as parser from '../../compiled/@babel/parser';\nimport generator from '../../compiled/@babel/generator';\nimport * as t from '../../compiled/@babel/types';\nimport traverse, { NodePath } from '../../compiled/@babel/traverse';\nimport { dtsAliasExts } from '../constants/file';\n// import { defaultTransformedFunctions } from '../constants/dts';\n// import { matchesPattern, isImportCall } from './dts';\n\nexport interface TransformOption {\n filename: string;\n baseUrl: string;\n paths: Record<string, string[] | string>;\n}\n\nfunction mapPathString(\n nodePath: NodePath<t.StringLiteral>,\n { filename, baseUrl, paths }: TransformOption,\n) {\n if (!t.isStringLiteral(nodePath)) {\n return;\n }\n\n const sourcePath = nodePath.node.value;\n const currentFile = filename;\n const matchPath = createMatchPath(\n baseUrl,\n paths as { [key: string]: Array<string> },\n ['index'],\n );\n const result = matchPath(\n sourcePath,\n packageJsonPath => {\n if (!fs.existsSync(packageJsonPath)) {\n return undefined;\n }\n return fs.readJSONSync(packageJsonPath);\n },\n filePath => fs.existsSync(filePath),\n dtsAliasExts,\n );\n if (result) {\n const relativePath = path.relative(\n path.dirname(currentFile),\n path.dirname(result),\n );\n const fileName = path.basename(result);\n // 如果是同级文件,则返回的是 ''\n const filePath = path.normalize(\n `${relativePath.length === 0 ? '.' : relativePath}/${fileName}`,\n );\n const replaceString = filePath.startsWith('.') ? filePath : `./${filePath}`;\n nodePath.replaceWith(t.stringLiteral(replaceString));\n }\n}\n\n// const transformCall =\n// (option: TransformOption) => (nodePath: NodePath<t.CallExpression>) => {\n// const calleePath = nodePath.get('callee') as NodePath;\n// const isNormalCall = defaultTransformedFunctions.some(pattern =>\n// matchesPattern(calleePath, pattern),\n// );\n// if (isNormalCall || isImportCall(nodePath)) {\n// mapPathString(\n// nodePath.get('arguments.0') as NodePath<t.StringLiteral>,\n// option,\n// );\n// }\n// };\n\nconst transformImport =\n (option: TransformOption) => (nodePath: NodePath<t.ImportDeclaration>) => {\n mapPathString(nodePath.get('source'), option);\n };\n\nconst transformExport =\n (option: TransformOption) => (nodePath: NodePath<t.ExportDeclaration>) => {\n mapPathString(nodePath.get('source') as NodePath<t.StringLiteral>, option);\n };\n\nconst transformSingleFileAlias = ({\n filename,\n baseUrl,\n paths,\n}: TransformOption) => {\n const sourceCode = fs.readFileSync(filename, 'utf-8');\n const ast = parser.parse(sourceCode, {\n sourceType: 'module',\n errorRecovery: true, // 防止typescript不支持的语法出现而报错\n plugins: ['typescript'],\n });\n traverse(ast, {\n // d.ts file content not have callExpression which can be parsed;\n // CallExpression: transformCall({ filename, baseUrl, paths }) as any,\n ImportDeclaration: transformImport({\n filename,\n baseUrl,\n paths,\n }) as any,\n ExportDeclaration: transformExport({\n filename,\n baseUrl,\n paths,\n }) as any,\n });\n return generator(ast).code;\n};\n\ninterface TransformDtsAliasOption {\n filenames?: string[];\n baseUrl: string;\n paths: Record<string, string[] | string>;\n}\nexport const transformDtsAlias = (option: TransformDtsAliasOption) => {\n const { filenames = [], baseUrl, paths } = option;\n const transformResult: { path: string; content: string }[] = [];\n for (const filename of filenames) {\n transformResult.push({\n path: filename,\n content: transformSingleFileAlias({ filename, baseUrl, paths }),\n });\n }\n return transformResult;\n};\n"]}
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "module-tools",
12
12
  "lib-tools"
13
13
  ],
14
- "version": "2.5.2-beta.4",
14
+ "version": "2.7.0",
15
15
  "bin": {
16
16
  "modern": "./bin/modern.js",
17
17
  "modern-module": "./bin/modern.js"
@@ -36,22 +36,23 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
- "@modern-js/libuild": "~0.10.0",
40
- "@modern-js/libuild-plugin-svgr": "~0.10.0",
41
- "@modern-js/libuild-plugin-swc": "~0.10.0",
42
- "@modern-js/core": "2.5.0",
43
- "@modern-js/plugin": "2.5.0",
44
- "@modern-js/new-action": "2.5.0",
45
- "@modern-js/upgrade": "2.5.0",
46
- "@modern-js/utils": "2.5.0",
47
- "@modern-js/plugin-i18n": "2.5.0",
48
- "@modern-js/plugin-changeset": "2.5.0",
49
- "@modern-js/plugin-lint": "2.5.0"
39
+ "@modern-js/libuild": "~0.11.0",
40
+ "@modern-js/libuild-plugin-svgr": "~0.11.0",
41
+ "@modern-js/libuild-plugin-swc": "~0.11.0",
42
+ "@modern-js/core": "2.7.0",
43
+ "@modern-js/new-action": "2.7.0",
44
+ "@modern-js/plugin": "2.7.0",
45
+ "@modern-js/plugin-changeset": "2.7.0",
46
+ "@modern-js/plugin-i18n": "2.7.0",
47
+ "@modern-js/plugin-lint": "2.7.0",
48
+ "@modern-js/upgrade": "2.7.0",
49
+ "@modern-js/utils": "2.7.0"
50
50
  },
51
51
  "devDependencies": {
52
+ "@types/fs-extra": "9.0.13",
52
53
  "@types/jest": "^27",
53
54
  "@types/node": "^14",
54
- "@types/fs-extra": "9.0.13",
55
+ "detect-indent": "6.1.0",
55
56
  "fs-extra": "10.1.0",
56
57
  "jest": "^27",
57
58
  "path-browserify": "1.0.1",
@@ -59,10 +60,10 @@
59
60
  "postcss-alias": "2.0.0",
60
61
  "react": "17",
61
62
  "typescript": "^4",
62
- "@modern-js/self": "npm:@modern-js/module-tools@2.5.2-beta.4",
63
- "@modern-js/builder-webpack-provider": "2.5.0",
64
- "@scripts/build": "2.5.0",
65
- "@scripts/jest-config": "2.5.0"
63
+ "@modern-js/builder-webpack-provider": "2.7.0",
64
+ "@modern-js/self": "npm:@modern-js/module-tools@2.7.0",
65
+ "@scripts/jest-config": "2.7.0",
66
+ "@scripts/build": "2.7.0"
66
67
  },
67
68
  "publishConfig": {
68
69
  "registry": "https://registry.npmjs.org/",
@@ -81,6 +82,7 @@
81
82
  "dev": "modern-lib build --watch",
82
83
  "test": "jest",
83
84
  "test:update": "jest --updateSnapshot",
84
- "new": "modern-lib new"
85
+ "new": "modern-lib new",
86
+ "debug-mode": "node ./scripts/debug-mode.js"
85
87
  }
86
88
  }
@@ -0,0 +1,49 @@
1
+ /* eslint-disable no-console */
2
+ /**
3
+ * 修改 exports.* 配置
4
+ * 将 export.'.': './src/index.ts' 转换为 export.'.': './dist/index.js'
5
+ * 当作为 demo 项目调试的时候使用: pnpm debug-mode
6
+ * 关闭调试模式:pnpm debug-mode off
7
+ */
8
+ const path = require('path');
9
+ const { fs } = require('@modern-js/utils');
10
+ const detectIndent = require('detect-indent');
11
+
12
+ const ON = 'on';
13
+ const OFF = 'off';
14
+ const operation = process.argv[2] === OFF ? OFF : ON;
15
+
16
+ const appDir = path.join(__dirname, '..');
17
+ const pkgPath = path.join(appDir, './package.json');
18
+ const tempPkgPath = path.join(appDir, 'temp-package.json');
19
+
20
+ if (operation === ON) {
21
+ if (!fs.pathExistsSync(tempPkgPath)) {
22
+ fs.copyFileSync(pkgPath, tempPkgPath);
23
+ }
24
+ } else {
25
+ fs.copyFileSync(tempPkgPath, pkgPath);
26
+ fs.removeSync(tempPkgPath);
27
+ }
28
+
29
+ const pkgJson = require(pkgPath);
30
+ const originalExports = {
31
+ '.': './src/index.ts',
32
+ './defineConfig': './src/config/defineConfig.ts',
33
+ };
34
+ const debugExports = {
35
+ '.': './dist/index.js',
36
+ './defineConfig': './dist/config/defineConfig.js',
37
+ };
38
+
39
+ console.debug('operation is', operation);
40
+ if (operation === ON) {
41
+ pkgJson.exports = debugExports;
42
+ } else {
43
+ pkgJson.exports = originalExports;
44
+ }
45
+
46
+ const output = fs.readFileSync(pkgPath, 'utf-8');
47
+ const indent = detectIndent(output);
48
+ fs.writeJSONSync(pkgPath, pkgJson, { spaces: indent.amount });
49
+ /* eslint-enable no-console */