@modern-js/module-tools 2.42.1 → 2.42.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builder/clear.js +17 -0
- package/dist/builder/dts/tsc.js +24 -12
- package/dist/builder/feature/swc.js +5 -1
- package/dist/command.js +1 -1
- package/dist/utils/dts.d.ts +1 -0
- package/dist/utils/dts.js +11 -0
- package/dist/utils/map.d.ts +1 -1
- package/package.json +15 -15
package/dist/builder/clear.js
CHANGED
|
@@ -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:
|
package/dist/builder/dts/tsc.js
CHANGED
|
@@ -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
|
|
67
|
-
|
|
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
|
-
|
|
72
|
-
import_utils.
|
|
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(
|
|
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
|
|
@@ -150,7 +150,11 @@ const swcRenderChunk = {
|
|
|
150
150
|
module: format === "umd" ? {
|
|
151
151
|
type: "umd"
|
|
152
152
|
} : void 0,
|
|
153
|
-
|
|
153
|
+
// If `chunk.contents` is recognized as [Script](https://swc.rs/docs/configuration/compilation#ismodule),
|
|
154
|
+
// then it will not be converted to umd format content.
|
|
155
|
+
// so we need to set `isModule` to `true`.
|
|
156
|
+
// eg: when `autoExternal` is false, then chunk.contents will be recognized as [Script]
|
|
157
|
+
isModule: format === "umd" ? true : "unknown"
|
|
154
158
|
});
|
|
155
159
|
const result = await swcCompiler.transform(name2, chunk.contents.toString());
|
|
156
160
|
return {
|
package/dist/command.js
CHANGED
|
@@ -56,7 +56,7 @@ const devCommand = async (program, api) => {
|
|
|
56
56
|
const runner = api.useHookRunners();
|
|
57
57
|
const devToolMetas = await runner.registerDev();
|
|
58
58
|
await runner.beforeDev(devToolMetas);
|
|
59
|
-
const devProgram = program.command("dev").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.dev.describe)).option("--tsconfig [tsconfig]", import_locale.i18n.t(import_locale.localeKeys.command.dev.tsconfig)).action(async (options) => {
|
|
59
|
+
const devProgram = program.command("dev").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.dev.describe)).option("--tsconfig [tsconfig]", import_locale.i18n.t(import_locale.localeKeys.command.dev.tsconfig)).option("-c, --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).action(async (options) => {
|
|
60
60
|
const context = await initModuleContext(api);
|
|
61
61
|
const { dev } = await Promise.resolve().then(() => __toESM(require("./dev")));
|
|
62
62
|
await dev(options, devToolMetas, api, context);
|
package/dist/utils/dts.d.ts
CHANGED
|
@@ -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/dist/utils/map.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/module-tools",
|
|
3
|
-
"version": "2.42.
|
|
3
|
+
"version": "2.42.2",
|
|
4
4
|
"description": "Simple, powerful, high-performance modern npm package development solution.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"modern",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"modern-module": "./bin/modern.js"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@ampproject/remapping": "
|
|
49
|
+
"@ampproject/remapping": "^2.2.1",
|
|
50
50
|
"@ast-grep/napi": "0.12.0",
|
|
51
51
|
"@modern-js/swc-plugins": "0.6.5",
|
|
52
52
|
"@rollup/pluginutils": "4.1.1",
|
|
@@ -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": "2.42.
|
|
71
|
-
"@modern-js/
|
|
72
|
-
"@modern-js/plugin": "2.42.
|
|
73
|
-
"@modern-js/plugin-i18n": "2.42.
|
|
74
|
-
"@modern-js/
|
|
75
|
-
"@modern-js/
|
|
76
|
-
"@modern-js/
|
|
77
|
-
"@modern-js/utils": "2.42.
|
|
78
|
-
"@modern-js/
|
|
70
|
+
"@modern-js/core": "2.42.2",
|
|
71
|
+
"@modern-js/plugin": "2.42.2",
|
|
72
|
+
"@modern-js/plugin-changeset": "2.42.2",
|
|
73
|
+
"@modern-js/plugin-i18n": "2.42.2",
|
|
74
|
+
"@modern-js/new-action": "2.42.2",
|
|
75
|
+
"@modern-js/plugin-lint": "2.42.2",
|
|
76
|
+
"@modern-js/types": "2.42.2",
|
|
77
|
+
"@modern-js/utils": "2.42.2",
|
|
78
|
+
"@modern-js/upgrade": "2.42.2"
|
|
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/
|
|
85
|
-
"@modern-js/
|
|
86
|
-
"@scripts/build": "2.42.
|
|
87
|
-
"@scripts/vitest-config": "2.42.
|
|
84
|
+
"@modern-js/builder-webpack-provider": "2.42.2",
|
|
85
|
+
"@modern-js/self": "npm:@modern-js/module-tools@2.42.2",
|
|
86
|
+
"@scripts/build": "2.42.2",
|
|
87
|
+
"@scripts/vitest-config": "2.42.2"
|
|
88
88
|
},
|
|
89
89
|
"peerDependencies": {
|
|
90
90
|
"typescript": "^4 || ^5"
|