@modern-js/module-tools 0.0.0-nightly-20231211170643 → 0.0.0-nightly-20231212170634

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.
@@ -23,6 +23,7 @@ __export(clear_exports, {
23
23
  module.exports = __toCommonJS(clear_exports);
24
24
  var import_utils = require("@modern-js/utils");
25
25
  var import_locale = require("../locale");
26
+ var import_utils2 = require("../utils");
26
27
  const clearBuildConfigPaths = async (configs, projectAbsRootPath) => {
27
28
  for (const config of configs) {
28
29
  if (projectAbsRootPath === config.outDir) {
@@ -30,6 +31,22 @@ const clearBuildConfigPaths = async (configs, projectAbsRootPath) => {
30
31
  } else {
31
32
  await import_utils.fs.remove(config.outDir);
32
33
  }
34
+ if (config.buildType === "bundleless" && config.dts && // keep it same as https://github.com/web-infra-dev/modern.js/blob/main/packages/solutions/module-tools/src/builder/build.ts#L37
35
+ await import_utils.fs.pathExists(config.tsconfig)) {
36
+ const tscBinFile = await (0, import_utils2.getTscBinPath)(projectAbsRootPath);
37
+ const childProgress = (0, import_utils.execa)(tscBinFile, [
38
+ "--build",
39
+ "--clean"
40
+ ], {
41
+ stdio: "pipe",
42
+ cwd: projectAbsRootPath
43
+ });
44
+ try {
45
+ await childProgress;
46
+ } catch (e) {
47
+ import_utils.logger.error(e);
48
+ }
49
+ }
33
50
  }
34
51
  };
35
52
  // Annotate the CommonJS export names for ESM import in node:
@@ -61,18 +61,33 @@ const runTscBin = async (api, config) => {
61
61
  const tscBinFile = await (0, import_utils2.getTscBinPath)(appDirectory);
62
62
  const params = [];
63
63
  if (userTsconfig.references) {
64
- var _userTsconfig;
65
64
  params.push("-b", tsconfigPath);
66
- var _compilerOptions;
67
- (_compilerOptions = (_userTsconfig = userTsconfig).compilerOptions) !== null && _compilerOptions !== void 0 ? _compilerOptions : _userTsconfig.compilerOptions = {};
68
- const { baseUrl = ".", outDir = "dist" } = userTsconfig.compilerOptions;
65
+ var _userTsconfig_compilerOptions;
66
+ const { baseUrl = ".", outDir, emitDeclarationOnly, declaration } = (_userTsconfig_compilerOptions = userTsconfig.compilerOptions) !== null && _userTsconfig_compilerOptions !== void 0 ? _userTsconfig_compilerOptions : {};
69
67
  const abosultBaseUrl = import_path.default.isAbsolute(baseUrl) ? baseUrl : import_path.default.join(import_path.default.dirname(tsconfigPath), baseUrl);
70
- if (import_path.default.resolve(abosultBaseUrl, outDir) !== distPath) {
71
- userTsconfig.compilerOptions.outDir = import_path.default.relative(abosultBaseUrl, distPath);
72
- import_utils.fs.writeFileSync(tsconfigPath, JSON.stringify(userTsconfig, null, 2));
68
+ if (!outDir || import_path.default.resolve(abosultBaseUrl, outDir) !== distPath) {
69
+ const correctOutDir = import_path.default.relative(abosultBaseUrl, distPath);
70
+ throw new Error(`Please set outDir: "${correctOutDir}" in ${import_utils.chalk.underline(tsconfigPath)} to keep it same as buildConfig.`);
71
+ }
72
+ const tsVersion = await (0, import_utils2.detectTSVersion)(appDirectory);
73
+ if (tsVersion !== 5) {
74
+ if (!declaration || !emitDeclarationOnly) {
75
+ throw new Error(`Please set declaration: true and emitDeclaration: true in ${import_utils.chalk.underline(tsconfigPath)}`);
76
+ }
77
+ } else {
78
+ params.push("--declaration", "--emitDeclarationOnly");
73
79
  }
74
80
  } else {
75
- params.push("-p", tsconfigPath, "--outDir", distPath);
81
+ params.push(
82
+ "-p",
83
+ tsconfigPath,
84
+ // Same as dts.distPath
85
+ "--outDir",
86
+ distPath,
87
+ // Only emit d.ts files
88
+ "--declaration",
89
+ "--emitDeclarationOnly"
90
+ );
76
91
  }
77
92
  if (watch) {
78
93
  params.push("-w");
@@ -82,10 +97,7 @@ const runTscBin = async (api, config) => {
82
97
  /* Required parameter, use it stdout have color */
83
98
  "--pretty",
84
99
  // https://github.com/microsoft/TypeScript/issues/21824
85
- "--preserveWatchOutput",
86
- // Only emit d.ts files
87
- "--declaration",
88
- "--emitDeclarationOnly"
100
+ "--preserveWatchOutput"
89
101
  ], {
90
102
  stdio: "pipe",
91
103
  cwd: appDirectory
@@ -1,5 +1,6 @@
1
1
  import type { ITsconfig, GeneratorDtsConfig, BuildType, TsTarget } from '../types';
2
2
  export declare const getProjectTsconfig: (tsconfigPath: string) => Promise<ITsconfig>;
3
+ export declare function detectTSVersion(appDirectory?: string): Promise<number | undefined>;
3
4
  export declare const getTscBinPath: (appDirectory: string) => Promise<string>;
4
5
  export declare const processDtsFilesAfterTsc: (config: GeneratorDtsConfig) => Promise<void>;
5
6
  export declare const printOrThrowDtsErrors: (error: unknown, options: {
package/dist/utils/dts.js CHANGED
@@ -28,6 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var dts_exports = {};
30
30
  __export(dts_exports, {
31
+ detectTSVersion: () => detectTSVersion,
31
32
  getProjectTsconfig: () => getProjectTsconfig,
32
33
  getTscBinPath: () => getTscBinPath,
33
34
  printOrThrowDtsErrors: () => printOrThrowDtsErrors,
@@ -47,6 +48,15 @@ const getProjectTsconfig = async (tsconfigPath) => {
47
48
  }
48
49
  return import_utils.json5.parse(import_utils.fs.readFileSync(tsconfigPath, "utf-8"));
49
50
  };
51
+ async function detectTSVersion(appDirectory) {
52
+ const cwd = appDirectory !== null && appDirectory !== void 0 ? appDirectory : process.cwd();
53
+ const typescriptPath = (0, import_path.join)(cwd, "node_modules", "typescript");
54
+ if (await import_utils.fs.pathExists(typescriptPath)) {
55
+ const typescriptPkg = await import_utils.fs.readJson((0, import_path.join)(typescriptPath, "package.json"));
56
+ const version = Number(typescriptPkg.version.split(".")[0]);
57
+ return version;
58
+ }
59
+ }
50
60
  const getTscBinPath = async (appDirectory) => {
51
61
  const { default: findUp, exists: pathExists } = await Promise.resolve().then(() => __toESM(require("../../compiled/find-up")));
52
62
  const tscBinFile = await findUp(async (directory) => {
@@ -161,6 +171,7 @@ const printOrThrowDtsErrors = async (error, options) => {
161
171
  const tsTargetAtOrAboveES2022 = (target) => target === "es2022" || target === "esnext";
162
172
  // Annotate the CommonJS export names for ESM import in node:
163
173
  0 && (module.exports = {
174
+ detectTSVersion,
164
175
  getProjectTsconfig,
165
176
  getTscBinPath,
166
177
  printOrThrowDtsErrors,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/module-tools",
3
- "version": "0.0.0-nightly-20231211170643",
3
+ "version": "0.0.0-nightly-20231212170634",
4
4
  "description": "Simple, powerful, high-performance modern npm package development solution.",
5
5
  "keywords": [
6
6
  "modern",
@@ -67,24 +67,24 @@
67
67
  "tapable": "2.2.1",
68
68
  "terser": "5.19.2",
69
69
  "tsconfig-paths-webpack-plugin": "4.1.0",
70
- "@modern-js/core": "0.0.0-nightly-20231211170643",
71
- "@modern-js/plugin-changeset": "0.0.0-nightly-20231211170643",
72
- "@modern-js/new-action": "0.0.0-nightly-20231211170643",
73
- "@modern-js/plugin": "0.0.0-nightly-20231211170643",
74
- "@modern-js/plugin-lint": "0.0.0-nightly-20231211170643",
75
- "@modern-js/types": "0.0.0-nightly-20231211170643",
76
- "@modern-js/upgrade": "0.0.0-nightly-20231211170643",
77
- "@modern-js/plugin-i18n": "0.0.0-nightly-20231211170643",
78
- "@modern-js/utils": "0.0.0-nightly-20231211170643"
70
+ "@modern-js/core": "0.0.0-nightly-20231212170634",
71
+ "@modern-js/new-action": "0.0.0-nightly-20231212170634",
72
+ "@modern-js/plugin": "0.0.0-nightly-20231212170634",
73
+ "@modern-js/plugin-i18n": "0.0.0-nightly-20231212170634",
74
+ "@modern-js/plugin-changeset": "0.0.0-nightly-20231212170634",
75
+ "@modern-js/plugin-lint": "0.0.0-nightly-20231212170634",
76
+ "@modern-js/upgrade": "0.0.0-nightly-20231212170634",
77
+ "@modern-js/types": "0.0.0-nightly-20231212170634",
78
+ "@modern-js/utils": "0.0.0-nightly-20231212170634"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@types/convert-source-map": "1.5.2",
82
82
  "@types/node": "^14",
83
83
  "typescript": "^5",
84
- "@modern-js/self": "npm:@modern-js/module-tools@0.0.0-nightly-20231211170643",
85
- "@modern-js/builder-webpack-provider": "0.0.0-nightly-20231211170643",
86
- "@scripts/build": "0.0.0-nightly-20231211170643",
87
- "@scripts/vitest-config": "0.0.0-nightly-20231211170643"
84
+ "@modern-js/builder-webpack-provider": "0.0.0-nightly-20231212170634",
85
+ "@scripts/build": "0.0.0-nightly-20231212170634",
86
+ "@modern-js/self": "npm:@modern-js/module-tools@0.0.0-nightly-20231212170634",
87
+ "@scripts/vitest-config": "0.0.0-nightly-20231212170634"
88
88
  },
89
89
  "peerDependencies": {
90
90
  "typescript": "^4 || ^5"