rsbuild-plugin-dts 0.6.6 → 0.6.7
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/apiExtractor.js +11 -11
- package/dist/dts.js +19 -19
- package/dist/index.js +23 -23
- package/dist/tsc.js +39 -39
- package/dist/utils.js +66 -66
- package/package.json +1 -1
package/dist/apiExtractor.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
const logPrefixApiExtractor =
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__ from "./utils.js";
|
|
5
|
+
const logPrefixApiExtractor = __WEBPACK_EXTERNAL_MODULE_picocolors__["default"].dim('[api-extractor]');
|
|
6
6
|
async function bundleDts(options) {
|
|
7
7
|
let apiExtractor;
|
|
8
8
|
try {
|
|
9
9
|
apiExtractor = await import("@microsoft/api-extractor");
|
|
10
10
|
} catch {
|
|
11
|
-
throw new Error(`${
|
|
11
|
+
throw new Error(`${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan('@microsoft/api-extractor')} is required when ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan('dts.bundle')} is set to ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan('true')}, please make sure it is installed. You could check https://lib.rsbuild.dev/guide/advanced/dts#how-to-generate-declaration-files-in-rslib for more details.`);
|
|
12
12
|
}
|
|
13
13
|
const { Extractor, ExtractorConfig, ExtractorLogLevel } = apiExtractor;
|
|
14
14
|
const { name, cwd, distPath, dtsExtension, banner, footer, dtsEntry, tsconfigPath = 'tsconfig.json', bundledPackages = [] } = options;
|
|
15
15
|
try {
|
|
16
16
|
await Promise.all(dtsEntry.map(async (entry)=>{
|
|
17
17
|
const start = Date.now();
|
|
18
|
-
const untrimmedFilePath = join(cwd, relative(cwd, distPath), `${entry.name}${dtsExtension}`);
|
|
18
|
+
const untrimmedFilePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.relative)(cwd, distPath), `${entry.name}${dtsExtension}`);
|
|
19
19
|
const mainEntryPointFilePath = entry.path.replace(/\?.*$/, '');
|
|
20
20
|
const internalConfig = {
|
|
21
21
|
mainEntryPointFilePath,
|
|
@@ -32,7 +32,7 @@ async function bundleDts(options) {
|
|
|
32
32
|
const extractorConfig = ExtractorConfig.prepare({
|
|
33
33
|
configObject: internalConfig,
|
|
34
34
|
configObjectFullPath: void 0,
|
|
35
|
-
packageJsonFullPath: join(cwd, 'package.json')
|
|
35
|
+
packageJsonFullPath: (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, 'package.json')
|
|
36
36
|
});
|
|
37
37
|
const extractorResult = Extractor.invoke(extractorConfig, {
|
|
38
38
|
localBuild: true,
|
|
@@ -40,9 +40,9 @@ async function bundleDts(options) {
|
|
|
40
40
|
if ('console-compiler-version-notice' === message.messageId || 'console-preamble' === message.messageId) message.logLevel = ExtractorLogLevel.None;
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
|
-
if (!extractorResult.succeeded) throw new Error(`API Extractor error. ${
|
|
44
|
-
await addBannerAndFooter(untrimmedFilePath, banner, footer);
|
|
45
|
-
logger.ready(`declaration files bundled successfully: ${
|
|
43
|
+
if (!extractorResult.succeeded) throw new Error(`API Extractor error. ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
|
|
44
|
+
await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.addBannerAndFooter)(untrimmedFilePath, banner, footer);
|
|
45
|
+
__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.ready(`declaration files bundled successfully: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.relative)(cwd, untrimmedFilePath))} in ${(0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.getTimeCost)(start)} ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
|
|
46
46
|
}));
|
|
47
47
|
} catch (e) {
|
|
48
48
|
throw new Error(`${logPrefixApiExtractor} ${e}`);
|
package/dist/dts.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__tsc_js_1050029c__ from "./tsc.js";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__ from "./utils.js";
|
|
7
7
|
const isObject = (obj)=>'[object Object]' === Object.prototype.toString.call(obj);
|
|
8
8
|
const calcBundledPackages = (options)=>{
|
|
9
9
|
const { autoExternal, cwd, userExternals } = options;
|
|
10
10
|
let pkgJson;
|
|
11
11
|
try {
|
|
12
|
-
const content =
|
|
12
|
+
const content = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, 'package.json'), 'utf-8');
|
|
13
13
|
pkgJson = JSON.parse(content);
|
|
14
14
|
} catch (err) {
|
|
15
|
-
logger.warn('The type of third-party packages will not be bundled due to read package.json failed');
|
|
15
|
+
__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.warn('The type of third-party packages will not be bundled due to read package.json failed');
|
|
16
16
|
return [];
|
|
17
17
|
}
|
|
18
18
|
const externalOptions = autoExternal ? {
|
|
@@ -56,25 +56,25 @@ async function generateDts(data) {
|
|
|
56
56
|
path: true,
|
|
57
57
|
extension: false
|
|
58
58
|
} } = data;
|
|
59
|
-
if (!isWatch) logger.start(`generating declaration files... ${
|
|
59
|
+
if (!isWatch) __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.start(`generating declaration files... ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
|
|
60
60
|
const { options: rawCompilerOptions, fileNames } = tsConfigResult;
|
|
61
|
-
const rootDir = rawCompilerOptions.rootDir ?? (rawCompilerOptions.composite ? dirname(tsconfigPath) : await calcLongestCommonPath(fileNames.filter((fileName)=>!/\.d\.(ts|mts|cts)$/.test(fileName)))) ?? dirname(tsconfigPath);
|
|
62
|
-
const resolvedDtsEmitPath = normalize(resolve(dirname(tsconfigPath), dtsEmitPath));
|
|
61
|
+
const rootDir = rawCompilerOptions.rootDir ?? (rawCompilerOptions.composite ? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(tsconfigPath) : await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.calcLongestCommonPath)(fileNames.filter((fileName)=>!/\.d\.(ts|mts|cts)$/.test(fileName)))) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(tsconfigPath);
|
|
62
|
+
const resolvedDtsEmitPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.normalize)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.resolve)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(tsconfigPath), dtsEmitPath));
|
|
63
63
|
if (build) {
|
|
64
64
|
if (bundle) throw Error('Can not set "dts.bundle: true" when "dts.build: true"');
|
|
65
|
-
if ((!rawCompilerOptions.outDir || normalize(rawCompilerOptions.outDir) !== resolvedDtsEmitPath) && (!rawCompilerOptions.declarationDir || normalize(rawCompilerOptions.declarationDir) !== resolvedDtsEmitPath)) {
|
|
65
|
+
if ((!rawCompilerOptions.outDir || (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.normalize)(rawCompilerOptions.outDir) !== resolvedDtsEmitPath) && (!rawCompilerOptions.declarationDir || (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.normalize)(rawCompilerOptions.declarationDir) !== resolvedDtsEmitPath)) {
|
|
66
66
|
const info = rawCompilerOptions.outDir && !rawCompilerOptions.declarationDir ? 'outDir' : 'declarationDir';
|
|
67
|
-
throw Error(`Please set ${info}: "${dtsEmitPath}" in ${
|
|
67
|
+
throw Error(`Please set ${info}: "${dtsEmitPath}" in ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].underline(tsconfigPath)} to keep it same as "dts.distPath" or "output.distPath.root" field in lib config.`);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
const declarationDir = bundle ? ensureTempDeclarationDir(cwd, name) : dtsEmitPath;
|
|
70
|
+
const declarationDir = bundle ? (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.ensureTempDeclarationDir)(cwd, name) : dtsEmitPath;
|
|
71
71
|
let dtsEntries = [];
|
|
72
72
|
if (true === bundle) dtsEntries = dtsEntry.map((entryObj)=>{
|
|
73
73
|
const { name: entryName, path: entryPath } = entryObj;
|
|
74
74
|
if (!entryPath) return null;
|
|
75
|
-
const entrySourcePath = isAbsolute(entryPath) ? entryPath : join(cwd, entryPath);
|
|
76
|
-
const relativePath = relative(rootDir, dirname(entrySourcePath));
|
|
77
|
-
const newPath = join(declarationDir, relativePath, basename(entrySourcePath)).replace(/\.(js|mjs|jsx|ts|mts|tsx|cjs|cts|cjsx|ctsx|mjsx|mtsx)$/, '.d.ts');
|
|
75
|
+
const entrySourcePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.isAbsolute)(entryPath) ? entryPath : (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, entryPath);
|
|
76
|
+
const relativePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.relative)(rootDir, (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(entrySourcePath));
|
|
77
|
+
const newPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(declarationDir, relativePath, (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.basename)(entrySourcePath)).replace(/\.(js|mjs|jsx|ts|mts|tsx|cjs|cts|cjsx|ctsx|mjsx|mtsx)$/, '.d.ts');
|
|
78
78
|
return {
|
|
79
79
|
name: entryName,
|
|
80
80
|
path: newPath
|
|
@@ -103,7 +103,7 @@ async function generateDts(data) {
|
|
|
103
103
|
const onComplete = async (isSuccess)=>{
|
|
104
104
|
if (isSuccess) await bundleDtsIfNeeded();
|
|
105
105
|
};
|
|
106
|
-
await emitDts({
|
|
106
|
+
await (0, __WEBPACK_EXTERNAL_MODULE__tsc_js_1050029c__.emitDts)({
|
|
107
107
|
name,
|
|
108
108
|
cwd,
|
|
109
109
|
configPath: tsconfigPath,
|
|
@@ -122,7 +122,7 @@ process.on('message', async (data)=>{
|
|
|
122
122
|
try {
|
|
123
123
|
await generateDts(data);
|
|
124
124
|
} catch (e) {
|
|
125
|
-
logger.error(e);
|
|
125
|
+
__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(e);
|
|
126
126
|
process.send('error');
|
|
127
127
|
process.exit(1);
|
|
128
128
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
const src_filename = fileURLToPath(import.meta.url);
|
|
9
|
-
const src_dirname = dirname(src_filename);
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__ from "node:child_process";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE_typescript__ from "typescript";
|
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__ from "./utils.js";
|
|
8
|
+
const src_filename = (0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(import.meta.url);
|
|
9
|
+
const src_dirname = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(src_filename);
|
|
10
10
|
const PLUGIN_DTS_NAME = 'rsbuild:dts';
|
|
11
11
|
const pluginDts = (options = {})=>({
|
|
12
12
|
name: PLUGIN_DTS_NAME,
|
|
@@ -23,24 +23,24 @@ const pluginDts = (options = {})=>({
|
|
|
23
23
|
api.onBeforeEnvironmentCompile(async ({ isWatch, isFirstCompile, environment })=>{
|
|
24
24
|
if (!isFirstCompile) return;
|
|
25
25
|
const { config } = environment;
|
|
26
|
-
const dtsEntry = processSourceEntry(options.bundle, config.source?.entry);
|
|
26
|
+
const dtsEntry = (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.processSourceEntry)(options.bundle, config.source?.entry);
|
|
27
27
|
const cwd = api.context.rootPath;
|
|
28
|
-
const tsconfigPath =
|
|
28
|
+
const tsconfigPath = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].findConfigFile(cwd, __WEBPACK_EXTERNAL_MODULE_typescript__["default"].sys.fileExists, config.source.tsconfigPath);
|
|
29
29
|
if (!tsconfigPath) {
|
|
30
|
-
logger.error(`Failed to resolve tsconfig file ${
|
|
30
|
+
__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(`Failed to resolve tsconfig file ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan(`"${config.source.tsconfigPath}"`)} from ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan(cwd)}. Please ensure that the file exists.`);
|
|
31
31
|
throw new Error();
|
|
32
32
|
}
|
|
33
|
-
const tsConfigResult = loadTsconfig(tsconfigPath);
|
|
33
|
+
const tsConfigResult = (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.loadTsconfig)(tsconfigPath);
|
|
34
34
|
const { options: rawCompilerOptions } = tsConfigResult;
|
|
35
35
|
const { declarationDir, outDir, composite, incremental } = rawCompilerOptions;
|
|
36
|
-
const dtsEmitPath = getDtsEmitPath(options.distPath, declarationDir, config.output?.distPath?.root);
|
|
37
|
-
warnIfOutside(cwd, declarationDir, 'declarationDir');
|
|
38
|
-
warnIfOutside(cwd, outDir, 'outDir');
|
|
39
|
-
if (false !== config.output.cleanDistPath) await cleanDtsFiles(dtsEmitPath);
|
|
40
|
-
if (options.bundle) await clearTempDeclarationDir(cwd);
|
|
41
|
-
if (composite || incremental || options.build) await cleanTsBuildInfoFile(tsconfigPath, rawCompilerOptions);
|
|
42
|
-
const jsExtension = extname(src_filename);
|
|
43
|
-
const childProcess = fork(join(src_dirname, `./dts${jsExtension}`), [], {
|
|
36
|
+
const dtsEmitPath = (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.getDtsEmitPath)(options.distPath, declarationDir, config.output?.distPath?.root);
|
|
37
|
+
(0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.warnIfOutside)(cwd, declarationDir, 'declarationDir');
|
|
38
|
+
(0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.warnIfOutside)(cwd, outDir, 'outDir');
|
|
39
|
+
if (false !== config.output.cleanDistPath) await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.cleanDtsFiles)(dtsEmitPath);
|
|
40
|
+
if (options.bundle) await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.clearTempDeclarationDir)(cwd);
|
|
41
|
+
if (composite || incremental || options.build) await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.cleanTsBuildInfoFile)(tsconfigPath, rawCompilerOptions);
|
|
42
|
+
const jsExtension = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.extname)(src_filename);
|
|
43
|
+
const childProcess = (0, __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__.fork)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(src_dirname, `./dts${jsExtension}`), [], {
|
|
44
44
|
stdio: 'inherit'
|
|
45
45
|
});
|
|
46
46
|
childProcesses.push(childProcess);
|
|
@@ -79,8 +79,8 @@ const pluginDts = (options = {})=>({
|
|
|
79
79
|
if (!isFirstCompile) return;
|
|
80
80
|
for (const result of promisesResult)if ('error' === result.status) {
|
|
81
81
|
if (options.abortOnError) throw new Error(result.errorMessage);
|
|
82
|
-
result.errorMessage && logger.error(result.errorMessage);
|
|
83
|
-
logger.warn('With `abortOnError` configuration currently disabled, type errors will not fail the build, but proper type declaration output cannot be guaranteed.');
|
|
82
|
+
result.errorMessage && __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(result.errorMessage);
|
|
83
|
+
__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.warn('With `abortOnError` configuration currently disabled, type errors will not fail the build, but proper type declaration output cannot be guaranteed.');
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
86
|
const killProcesses = ()=>{
|
package/dist/tsc.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
const logPrefixTsc =
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_typescript__ from "typescript";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__ from "./utils.js";
|
|
5
|
+
const logPrefixTsc = __WEBPACK_EXTERNAL_MODULE_picocolors__["default"].dim('[tsc]');
|
|
6
6
|
const formatHost = {
|
|
7
7
|
getCanonicalFileName: (path)=>path,
|
|
8
|
-
getCurrentDirectory:
|
|
9
|
-
getNewLine: ()=>
|
|
8
|
+
getCurrentDirectory: __WEBPACK_EXTERNAL_MODULE_typescript__["default"].sys.getCurrentDirectory,
|
|
9
|
+
getNewLine: ()=>__WEBPACK_EXTERNAL_MODULE_typescript__["default"].sys.newLine
|
|
10
10
|
};
|
|
11
11
|
async function handleDiagnosticsAndProcessFiles(diagnostics, configPath, bundle, declarationDir, dtsExtension, redirect, rootDir, banner, footer, name) {
|
|
12
12
|
const diagnosticMessages = [];
|
|
13
13
|
for (const diagnostic of diagnostics){
|
|
14
|
-
const message =
|
|
14
|
+
const message = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].formatDiagnosticsWithColorAndContext([
|
|
15
15
|
diagnostic
|
|
16
16
|
], formatHost);
|
|
17
17
|
diagnosticMessages.push(message);
|
|
18
18
|
}
|
|
19
|
-
await processDtsFiles(bundle, declarationDir, dtsExtension, redirect, configPath, rootDir, banner, footer);
|
|
19
|
+
await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.processDtsFiles)(bundle, declarationDir, dtsExtension, redirect, configPath, rootDir, banner, footer);
|
|
20
20
|
if (diagnosticMessages.length) {
|
|
21
|
-
for (const message of diagnosticMessages)logger.error(logPrefixTsc, message);
|
|
22
|
-
throw new Error(`Failed to generate declaration files. ${
|
|
21
|
+
for (const message of diagnosticMessages)__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(logPrefixTsc, message);
|
|
22
|
+
throw new Error(`Failed to generate declaration files. ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
async function emitDts(options, onComplete, bundle = false, isWatch = false, build = false) {
|
|
@@ -34,26 +34,26 @@ async function emitDts(options, onComplete, bundle = false, isWatch = false, bui
|
|
|
34
34
|
declarationDir,
|
|
35
35
|
emitDeclarationOnly: true
|
|
36
36
|
};
|
|
37
|
-
const createProgram =
|
|
37
|
+
const createProgram = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createSemanticDiagnosticsBuilderProgram;
|
|
38
38
|
const reportDiagnostic = (diagnostic)=>{
|
|
39
|
-
logger.error(logPrefixTsc,
|
|
39
|
+
__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(logPrefixTsc, __WEBPACK_EXTERNAL_MODULE_typescript__["default"].formatDiagnosticsWithColorAndContext([
|
|
40
40
|
diagnostic
|
|
41
41
|
], formatHost));
|
|
42
42
|
};
|
|
43
43
|
const reportWatchStatusChanged = async (diagnostic, _newLine, _options, errorCount)=>{
|
|
44
|
-
const message = `${
|
|
45
|
-
if (6031 === diagnostic.code || 6032 === diagnostic.code) logger.info(logPrefixTsc, message);
|
|
44
|
+
const message = `${__WEBPACK_EXTERNAL_MODULE_typescript__["default"].flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine())} ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`;
|
|
45
|
+
if (6031 === diagnostic.code || 6032 === diagnostic.code) __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.info(logPrefixTsc, message);
|
|
46
46
|
if (6194 === diagnostic.code) {
|
|
47
|
-
if (0 !== errorCount && errorCount) logger.error(logPrefixTsc, message);
|
|
47
|
+
if (0 !== errorCount && errorCount) __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(logPrefixTsc, message);
|
|
48
48
|
else {
|
|
49
|
-
logger.info(logPrefixTsc, message);
|
|
49
|
+
__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.info(logPrefixTsc, message);
|
|
50
50
|
onComplete(true);
|
|
51
51
|
}
|
|
52
|
-
await processDtsFiles(bundle, declarationDir, dtsExtension, redirect, configPath, rootDir, banner, footer);
|
|
52
|
+
await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.processDtsFiles)(bundle, declarationDir, dtsExtension, redirect, configPath, rootDir, banner, footer);
|
|
53
53
|
}
|
|
54
54
|
if (6193 === diagnostic.code) {
|
|
55
|
-
logger.error(logPrefixTsc, message);
|
|
56
|
-
await processDtsFiles(bundle, declarationDir, dtsExtension, redirect, configPath, rootDir, banner, footer);
|
|
55
|
+
__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(logPrefixTsc, message);
|
|
56
|
+
await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.processDtsFiles)(bundle, declarationDir, dtsExtension, redirect, configPath, rootDir, banner, footer);
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
59
|
const renameDtsFile = (fileName)=>{
|
|
@@ -61,36 +61,36 @@ async function emitDts(options, onComplete, bundle = false, isWatch = false, bui
|
|
|
61
61
|
return fileName.replace(/\.d\.ts$/, dtsExtension);
|
|
62
62
|
};
|
|
63
63
|
const system = {
|
|
64
|
-
...
|
|
64
|
+
...__WEBPACK_EXTERNAL_MODULE_typescript__["default"].sys,
|
|
65
65
|
writeFile: (fileName, contents, writeByteOrderMark)=>{
|
|
66
|
-
|
|
66
|
+
__WEBPACK_EXTERNAL_MODULE_typescript__["default"].sys.writeFile(renameDtsFile(fileName), contents, writeByteOrderMark);
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
if (isWatch) if (build) {
|
|
70
|
-
const host =
|
|
71
|
-
const solutionBuilder =
|
|
70
|
+
const host = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createSolutionBuilderWithWatchHost(system, createProgram, reportDiagnostic, void 0, reportWatchStatusChanged);
|
|
71
|
+
const solutionBuilder = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createSolutionBuilderWithWatch(host, [
|
|
72
72
|
configPath
|
|
73
73
|
], compilerOptions, {
|
|
74
74
|
watch: true
|
|
75
75
|
});
|
|
76
76
|
solutionBuilder.build();
|
|
77
77
|
} else {
|
|
78
|
-
const host =
|
|
79
|
-
|
|
78
|
+
const host = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createWatchCompilerHost(configPath, compilerOptions, system, createProgram, reportDiagnostic, reportWatchStatusChanged);
|
|
79
|
+
__WEBPACK_EXTERNAL_MODULE_typescript__["default"].createWatchProgram(host);
|
|
80
80
|
}
|
|
81
81
|
else {
|
|
82
82
|
if (build || compilerOptions.composite) if (!build && compilerOptions.composite) {
|
|
83
|
-
const originHost =
|
|
83
|
+
const originHost = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createIncrementalCompilerHost(compilerOptions);
|
|
84
84
|
const host = {
|
|
85
85
|
...originHost,
|
|
86
86
|
writeFile: (fileName, contents, writeByteOrderMark, onError, sourceFiles)=>{
|
|
87
87
|
originHost.writeFile(renameDtsFile(fileName), contents, writeByteOrderMark, onError, sourceFiles);
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
|
-
const program =
|
|
90
|
+
const program = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createIncrementalProgram({
|
|
91
91
|
rootNames: fileNames,
|
|
92
92
|
options: compilerOptions,
|
|
93
|
-
configFileParsingDiagnostics:
|
|
93
|
+
configFileParsingDiagnostics: __WEBPACK_EXTERNAL_MODULE_typescript__["default"].getConfigFileParsingDiagnostics(tsConfigResult),
|
|
94
94
|
projectReferences,
|
|
95
95
|
host,
|
|
96
96
|
createProgram
|
|
@@ -103,35 +103,35 @@ async function emitDts(options, onComplete, bundle = false, isWatch = false, bui
|
|
|
103
103
|
const reportErrorSummary = (errorCount)=>{
|
|
104
104
|
errorNumber = errorCount;
|
|
105
105
|
};
|
|
106
|
-
const host =
|
|
107
|
-
const solutionBuilder =
|
|
106
|
+
const host = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createSolutionBuilderHost(system, createProgram, reportDiagnostic, void 0, reportErrorSummary);
|
|
107
|
+
const solutionBuilder = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createSolutionBuilder(host, [
|
|
108
108
|
configPath
|
|
109
109
|
], compilerOptions);
|
|
110
110
|
solutionBuilder.build();
|
|
111
|
-
await processDtsFiles(bundle, declarationDir, dtsExtension, redirect, configPath, rootDir, banner, footer);
|
|
112
|
-
if (errorNumber > 0) throw new Error(`Failed to generate declaration files. ${
|
|
111
|
+
await (0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.processDtsFiles)(bundle, declarationDir, dtsExtension, redirect, configPath, rootDir, banner, footer);
|
|
112
|
+
if (errorNumber > 0) throw new Error(`Failed to generate declaration files. ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
|
|
113
113
|
}
|
|
114
114
|
else {
|
|
115
|
-
const originHost =
|
|
115
|
+
const originHost = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createCompilerHost(compilerOptions);
|
|
116
116
|
const host = {
|
|
117
117
|
...originHost,
|
|
118
118
|
writeFile: (fileName, contents, writeByteOrderMark, onError, sourceFiles)=>{
|
|
119
119
|
originHost.writeFile(renameDtsFile(fileName), contents, writeByteOrderMark, onError, sourceFiles);
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
|
-
const program =
|
|
122
|
+
const program = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].createProgram({
|
|
123
123
|
rootNames: fileNames,
|
|
124
124
|
options: compilerOptions,
|
|
125
125
|
projectReferences,
|
|
126
126
|
host,
|
|
127
|
-
configFileParsingDiagnostics:
|
|
127
|
+
configFileParsingDiagnostics: __WEBPACK_EXTERNAL_MODULE_typescript__["default"].getConfigFileParsingDiagnostics(tsConfigResult)
|
|
128
128
|
});
|
|
129
129
|
const emitResult = program.emit();
|
|
130
|
-
const allDiagnostics =
|
|
130
|
+
const allDiagnostics = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
131
131
|
await handleDiagnosticsAndProcessFiles(allDiagnostics, configPath, bundle, declarationDir, dtsExtension, redirect, rootDir, banner, footer, name);
|
|
132
132
|
}
|
|
133
|
-
if (bundle) logger.info(`declaration files prepared in ${getTimeCost(start)} ${
|
|
134
|
-
else logger.ready(`declaration files generated in ${getTimeCost(start)} ${
|
|
133
|
+
if (bundle) __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.info(`declaration files prepared in ${(0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.getTimeCost)(start)} ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
|
|
134
|
+
else __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.ready(`declaration files generated in ${(0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.getTimeCost)(start)} ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(`(${name})`)}`);
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
export { emitDts };
|
package/dist/utils.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__ from "node:fs/promises";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__ast_grep_napi_5dd5d9b1__ from "@ast-grep/napi";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE_magic_string_758c1a52__ from "magic-string";
|
|
8
|
+
import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
|
|
9
|
+
import * as __WEBPACK_EXTERNAL_MODULE_tinyglobby__ from "tinyglobby";
|
|
10
|
+
import * as __WEBPACK_EXTERNAL_MODULE_tsconfig_paths_df62e9eb__ from "tsconfig-paths";
|
|
11
|
+
import * as __WEBPACK_EXTERNAL_MODULE_typescript__ from "typescript";
|
|
12
12
|
const JS_EXTENSIONS = [
|
|
13
13
|
'js',
|
|
14
14
|
'mjs',
|
|
@@ -25,28 +25,28 @@ const JS_EXTENSIONS = [
|
|
|
25
25
|
];
|
|
26
26
|
const JS_EXTENSIONS_PATTERN = new RegExp(`\\.(${JS_EXTENSIONS.join('|')})$`);
|
|
27
27
|
function loadTsconfig(tsconfigPath) {
|
|
28
|
-
const configFile =
|
|
29
|
-
const configFileContent =
|
|
28
|
+
const configFile = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].readConfigFile(tsconfigPath, __WEBPACK_EXTERNAL_MODULE_typescript__["default"].sys.readFile);
|
|
29
|
+
const configFileContent = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].parseJsonConfigFileContent(configFile.config, __WEBPACK_EXTERNAL_MODULE_typescript__["default"].sys, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(tsconfigPath));
|
|
30
30
|
return configFileContent;
|
|
31
31
|
}
|
|
32
32
|
const TEMP_FOLDER = '.rslib';
|
|
33
33
|
const TEMP_DTS_DIR = `${TEMP_FOLDER}/declarations`;
|
|
34
34
|
function ensureTempDeclarationDir(cwd, name) {
|
|
35
|
-
const dirPath =
|
|
36
|
-
if (
|
|
37
|
-
|
|
35
|
+
const dirPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(cwd, TEMP_DTS_DIR, name);
|
|
36
|
+
if (__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(dirPath)) return dirPath;
|
|
37
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].mkdirSync(dirPath, {
|
|
38
38
|
recursive: true
|
|
39
39
|
});
|
|
40
|
-
const gitIgnorePath =
|
|
41
|
-
|
|
40
|
+
const gitIgnorePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(cwd, TEMP_FOLDER, '.gitignore');
|
|
41
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].writeFileSync(gitIgnorePath, '**/*\n');
|
|
42
42
|
return dirPath;
|
|
43
43
|
}
|
|
44
44
|
async function pathExists(path) {
|
|
45
|
-
return
|
|
45
|
+
return __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].promises.access(path).then(()=>true).catch(()=>false);
|
|
46
46
|
}
|
|
47
47
|
async function isDirectory(filePath) {
|
|
48
48
|
try {
|
|
49
|
-
const stat = await
|
|
49
|
+
const stat = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].stat(filePath);
|
|
50
50
|
return stat.isDirectory();
|
|
51
51
|
} catch {
|
|
52
52
|
return false;
|
|
@@ -55,28 +55,28 @@ async function isDirectory(filePath) {
|
|
|
55
55
|
async function emptyDir(dir) {
|
|
56
56
|
if (!await pathExists(dir)) return;
|
|
57
57
|
try {
|
|
58
|
-
for (const file of (await
|
|
58
|
+
for (const file of (await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].promises.readdir(dir)))await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].promises.rm(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(dir, file), {
|
|
59
59
|
recursive: true,
|
|
60
60
|
force: true
|
|
61
61
|
});
|
|
62
62
|
} catch (err) {
|
|
63
|
-
logger.warn(`Failed to empty dir: ${dir}`);
|
|
64
|
-
logger.warn(err);
|
|
63
|
+
__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.warn(`Failed to empty dir: ${dir}`);
|
|
64
|
+
__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.warn(err);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
async function clearTempDeclarationDir(cwd) {
|
|
68
|
-
const dirPath =
|
|
68
|
+
const dirPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(cwd, TEMP_DTS_DIR);
|
|
69
69
|
await emptyDir(dirPath);
|
|
70
70
|
}
|
|
71
71
|
function getFileLoc(diagnostic, configPath) {
|
|
72
72
|
if (diagnostic.file) {
|
|
73
|
-
const { line, character } =
|
|
74
|
-
return `${
|
|
73
|
+
const { line, character } = __WEBPACK_EXTERNAL_MODULE_typescript__["default"].getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
|
74
|
+
return `${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan(diagnostic.file.fileName)}:${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(line + 1)}:${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(character + 1)}`;
|
|
75
75
|
}
|
|
76
|
-
return `${
|
|
76
|
+
return `${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan(configPath)}`;
|
|
77
77
|
}
|
|
78
78
|
const prettyTime = (seconds)=>{
|
|
79
|
-
const format = (time)=>
|
|
79
|
+
const format = (time)=>__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].bold(time);
|
|
80
80
|
if (seconds < 10) {
|
|
81
81
|
const digits = seconds >= 0.01 ? 2 : 3;
|
|
82
82
|
return `${format(seconds.toFixed(digits))} s`;
|
|
@@ -86,7 +86,7 @@ const prettyTime = (seconds)=>{
|
|
|
86
86
|
return `${format(minutes.toFixed(2))} m`;
|
|
87
87
|
};
|
|
88
88
|
const convertPath = (path)=>{
|
|
89
|
-
if ('win32' === platform()) return convertPathToPattern(path);
|
|
89
|
+
if ('win32' === (0, __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__.platform)()) return (0, __WEBPACK_EXTERNAL_MODULE_tinyglobby__.convertPathToPattern)(path);
|
|
90
90
|
return path;
|
|
91
91
|
};
|
|
92
92
|
function getTimeCost(start) {
|
|
@@ -94,23 +94,23 @@ function getTimeCost(start) {
|
|
|
94
94
|
return prettyTime(second);
|
|
95
95
|
}
|
|
96
96
|
async function addBannerAndFooter(dtsFile, banner, footer) {
|
|
97
|
-
const content = await
|
|
98
|
-
const code = new
|
|
97
|
+
const content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(dtsFile, 'utf-8');
|
|
98
|
+
const code = new __WEBPACK_EXTERNAL_MODULE_magic_string_758c1a52__["default"](content);
|
|
99
99
|
if (banner && !content.trimStart().startsWith(banner.trim())) code.prepend(`${banner}\n`);
|
|
100
100
|
if (footer && !content.trimEnd().endsWith(footer.trim())) code.append(`\n${footer}\n`);
|
|
101
|
-
if (code.hasChanged()) await
|
|
101
|
+
if (code.hasChanged()) await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(dtsFile, code.toString());
|
|
102
102
|
}
|
|
103
103
|
async function addExtension(redirect, dtsFile, path, extension) {
|
|
104
104
|
if (!redirect.extension) return path;
|
|
105
105
|
let redirectPath = path;
|
|
106
|
-
if (!isAbsolute(redirectPath) && !redirectPath.startsWith('.')) return redirectPath;
|
|
107
|
-
if (await isDirectory(join(dirname(dtsFile), redirectPath))) redirectPath = `${redirectPath.replace(/\/+$/, '')}/index`;
|
|
106
|
+
if (!(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.isAbsolute)(redirectPath) && !redirectPath.startsWith('.')) return redirectPath;
|
|
107
|
+
if (await isDirectory((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(dtsFile), redirectPath))) redirectPath = `${redirectPath.replace(/\/+$/, '')}/index`;
|
|
108
108
|
return `${redirectPath}${extension}`;
|
|
109
109
|
}
|
|
110
110
|
async function redirectDtsImports(dtsFile, dtsExtension, redirect, matchPath, outDir, rootDir) {
|
|
111
|
-
const content = await
|
|
112
|
-
const code = new
|
|
113
|
-
const sgNode = (await parseAsync("typescript", content)).root();
|
|
111
|
+
const content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(dtsFile, 'utf-8');
|
|
112
|
+
const code = new __WEBPACK_EXTERNAL_MODULE_magic_string_758c1a52__["default"](content);
|
|
113
|
+
const sgNode = (await (0, __WEBPACK_EXTERNAL_MODULE__ast_grep_napi_5dd5d9b1__.parseAsync)("typescript", content)).root();
|
|
114
114
|
const matcher = {
|
|
115
115
|
rule: {
|
|
116
116
|
any: [
|
|
@@ -193,43 +193,43 @@ async function redirectDtsImports(dtsFile, dtsExtension, redirect, matchPath, ou
|
|
|
193
193
|
]);
|
|
194
194
|
let redirectImportPath = importPath;
|
|
195
195
|
if (absoluteImportPath && redirect.path) {
|
|
196
|
-
const relativeRootDir =
|
|
197
|
-
const isOutsideRootdir = relativeRootDir.startsWith('..') ||
|
|
196
|
+
const relativeRootDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.normalize)(rootDir), (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.normalize)(absoluteImportPath));
|
|
197
|
+
const isOutsideRootdir = relativeRootDir.startsWith('..') || __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].isAbsolute(relativeRootDir);
|
|
198
198
|
if (isOutsideRootdir) {
|
|
199
|
-
const relativePath = relative(dirname(dtsFile), absoluteImportPath);
|
|
199
|
+
const relativePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.relative)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(dtsFile), absoluteImportPath);
|
|
200
200
|
redirectImportPath = relativePath.startsWith('..') ? relativePath : `./${relativePath}`;
|
|
201
201
|
} else {
|
|
202
|
-
const originalFilePath = resolve(rootDir, relative(outDir, dtsFile));
|
|
203
|
-
const originalSourceDir = dirname(originalFilePath);
|
|
204
|
-
const relativePath = relative(originalSourceDir, absoluteImportPath);
|
|
202
|
+
const originalFilePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.resolve)(rootDir, (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.relative)(outDir, dtsFile));
|
|
203
|
+
const originalSourceDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(originalFilePath);
|
|
204
|
+
const relativePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.relative)(originalSourceDir, absoluteImportPath);
|
|
205
205
|
redirectImportPath = relativePath.startsWith('..') ? relativePath : `./${relativePath}`;
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
-
const ext = extname(redirectImportPath);
|
|
208
|
+
const ext = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.extname)(redirectImportPath);
|
|
209
209
|
if (ext) {
|
|
210
210
|
if (JS_EXTENSIONS_PATTERN.test(redirectImportPath)) {
|
|
211
211
|
if (redirect.extension) redirectImportPath = redirectImportPath.replace(/\.[^.]+$/, extension);
|
|
212
212
|
}
|
|
213
213
|
} else {
|
|
214
|
-
if (absoluteImportPath && normalize(absoluteImportPath).startsWith(normalize(rootDir))) redirectImportPath = await addExtension(redirect, dtsFile, redirectImportPath, extension);
|
|
214
|
+
if (absoluteImportPath && (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.normalize)(absoluteImportPath).startsWith((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.normalize)(rootDir))) redirectImportPath = await addExtension(redirect, dtsFile, redirectImportPath, extension);
|
|
215
215
|
if (!absoluteImportPath && importPath.startsWith('.')) redirectImportPath = await addExtension(redirect, dtsFile, redirectImportPath, extension);
|
|
216
216
|
}
|
|
217
|
-
const normalizedRedirectImportPath = redirectImportPath.split(
|
|
217
|
+
const normalizedRedirectImportPath = redirectImportPath.split(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].sep).join('/');
|
|
218
218
|
code.overwrite(start, end, normalizedRedirectImportPath);
|
|
219
219
|
} catch (err) {
|
|
220
|
-
logger.warn(err);
|
|
220
|
+
__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.warn(err);
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
|
-
if (code.hasChanged()) await
|
|
223
|
+
if (code.hasChanged()) await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(dtsFile, code.toString());
|
|
224
224
|
}
|
|
225
225
|
async function processDtsFiles(bundle, dir, dtsExtension, redirect, tsconfigPath, rootDir, banner, footer) {
|
|
226
226
|
if (bundle) return;
|
|
227
227
|
let matchPath;
|
|
228
228
|
if (redirect.path || redirect.extension) {
|
|
229
|
-
const result = loadConfig(tsconfigPath);
|
|
230
|
-
if ('failed' === result.resultType) return void logger.error(result.message);
|
|
229
|
+
const result = (0, __WEBPACK_EXTERNAL_MODULE_tsconfig_paths_df62e9eb__.loadConfig)(tsconfigPath);
|
|
230
|
+
if ('failed' === result.resultType) return void __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(result.message);
|
|
231
231
|
const { absoluteBaseUrl, paths, mainFields, addMatchAll } = result;
|
|
232
|
-
matchPath = createMatchPath(absoluteBaseUrl, paths, mainFields, addMatchAll);
|
|
232
|
+
matchPath = (0, __WEBPACK_EXTERNAL_MODULE_tsconfig_paths_df62e9eb__.createMatchPath)(absoluteBaseUrl, paths, mainFields, addMatchAll);
|
|
233
233
|
}
|
|
234
234
|
const dtsFiles = await globDtsFiles(dir, [
|
|
235
235
|
`/**/*${dtsExtension}`
|
|
@@ -239,7 +239,7 @@ async function processDtsFiles(bundle, dir, dtsExtension, redirect, tsconfigPath
|
|
|
239
239
|
if (banner || footer) await addBannerAndFooter(file, banner, footer);
|
|
240
240
|
if ((redirect.path || redirect.extension) && matchPath) await redirectDtsImports(file, dtsExtension, redirect, matchPath, dir, rootDir);
|
|
241
241
|
} catch (error) {
|
|
242
|
-
logger.error(`Failed to rename declaration file ${file}: ${error}`);
|
|
242
|
+
__WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.error(`Failed to rename declaration file ${file}: ${error}`);
|
|
243
243
|
}
|
|
244
244
|
}));
|
|
245
245
|
}
|
|
@@ -250,14 +250,14 @@ function processSourceEntry(bundle, entryConfig) {
|
|
|
250
250
|
name,
|
|
251
251
|
path
|
|
252
252
|
}));
|
|
253
|
-
if (0 === entries.length) throw new Error(`Can not find a valid entry for ${
|
|
253
|
+
if (0 === entries.length) throw new Error(`Can not find a valid entry for ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan('dts.bundle')} option, please check your entry config.`);
|
|
254
254
|
return entries;
|
|
255
255
|
}
|
|
256
256
|
throw new Error('@microsoft/api-extractor only support entry of Record<string, string> type to bundle declaration files, please check your entry config.');
|
|
257
257
|
}
|
|
258
258
|
async function calcLongestCommonPath(absPaths) {
|
|
259
259
|
if (0 === absPaths.length) return null;
|
|
260
|
-
const sep =
|
|
260
|
+
const sep = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].posix.sep;
|
|
261
261
|
const splitPaths = absPaths.map((p)=>p.split(sep));
|
|
262
262
|
let lcaFragments = splitPaths[0];
|
|
263
263
|
for(let i = 1; i < splitPaths.length; i++){
|
|
@@ -268,12 +268,12 @@ async function calcLongestCommonPath(absPaths) {
|
|
|
268
268
|
lcaFragments = lcaFragments.slice(0, j);
|
|
269
269
|
}
|
|
270
270
|
let lca = lcaFragments.length > 0 ? lcaFragments.join(sep) : sep;
|
|
271
|
-
const stats = await
|
|
272
|
-
if (stats?.isFile()) lca =
|
|
271
|
+
const stats = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].stat(lca);
|
|
272
|
+
if (stats?.isFile()) lca = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(lca);
|
|
273
273
|
return lca;
|
|
274
274
|
}
|
|
275
275
|
const globDtsFiles = async (dir, patterns)=>{
|
|
276
|
-
const dtsFiles = await Promise.all(patterns.map((pattern)=>glob(convertPath(join(dir, pattern)), {
|
|
276
|
+
const dtsFiles = await Promise.all(patterns.map((pattern)=>(0, __WEBPACK_EXTERNAL_MODULE_tinyglobby__.glob)(convertPath((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(dir, pattern)), {
|
|
277
277
|
absolute: true
|
|
278
278
|
})));
|
|
279
279
|
return dtsFiles.flat();
|
|
@@ -285,16 +285,16 @@ async function cleanDtsFiles(dir) {
|
|
|
285
285
|
'/**/*.d.mts'
|
|
286
286
|
];
|
|
287
287
|
const allFiles = await globDtsFiles(dir, patterns);
|
|
288
|
-
await Promise.all(allFiles.map((file)=>
|
|
288
|
+
await Promise.all(allFiles.map((file)=>__WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].rm(file, {
|
|
289
289
|
force: true
|
|
290
290
|
})));
|
|
291
291
|
}
|
|
292
292
|
async function cleanTsBuildInfoFile(tsconfigPath, compilerOptions) {
|
|
293
|
-
const tsconfigDir = dirname(tsconfigPath);
|
|
293
|
+
const tsconfigDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(tsconfigPath);
|
|
294
294
|
const { outDir, rootDir, tsBuildInfoFile } = compilerOptions;
|
|
295
|
-
let tsbuildInfoFilePath = `${basename(tsconfigPath, '.json')}${tsBuildInfoFile ?? '.tsbuildinfo'}`;
|
|
296
|
-
if (outDir) tsbuildInfoFilePath = rootDir ? join(outDir, relative(resolve(tsconfigDir, rootDir), tsconfigDir), tsbuildInfoFilePath) : join(outDir, tsbuildInfoFilePath);
|
|
297
|
-
if (await pathExists(tsbuildInfoFilePath)) await
|
|
295
|
+
let tsbuildInfoFilePath = `${(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.basename)(tsconfigPath, '.json')}${tsBuildInfoFile ?? '.tsbuildinfo'}`;
|
|
296
|
+
if (outDir) tsbuildInfoFilePath = rootDir ? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outDir, (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.relative)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.resolve)(tsconfigDir, rootDir), tsconfigDir), tsbuildInfoFilePath) : (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outDir, tsbuildInfoFilePath);
|
|
297
|
+
if (await pathExists(tsbuildInfoFilePath)) await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].rm(tsbuildInfoFilePath, {
|
|
298
298
|
force: true
|
|
299
299
|
});
|
|
300
300
|
}
|
|
@@ -303,10 +303,10 @@ function getDtsEmitPath(pathFromPlugin, declarationDir, distPath) {
|
|
|
303
303
|
}
|
|
304
304
|
function warnIfOutside(cwd, dir, label) {
|
|
305
305
|
if (dir) {
|
|
306
|
-
const normalizedCwd = normalize(cwd);
|
|
307
|
-
const normalizedDir = normalize(dir);
|
|
308
|
-
const relDir = relative(normalizedCwd, normalizedDir);
|
|
309
|
-
if (relDir.startsWith('..')) logger.warn(`The resolved ${label} ${
|
|
306
|
+
const normalizedCwd = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.normalize)(cwd);
|
|
307
|
+
const normalizedDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.normalize)(dir);
|
|
308
|
+
const relDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.relative)(normalizedCwd, normalizedDir);
|
|
309
|
+
if (relDir.startsWith('..')) __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.warn(`The resolved ${label} ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan(normalizedDir)} is outside the project root ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].cyan(normalizedCwd)}, please check your tsconfig file.`);
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
312
|
export { JS_EXTENSIONS_PATTERN, TEMP_DTS_DIR, TEMP_FOLDER, addBannerAndFooter, calcLongestCommonPath, cleanDtsFiles, cleanTsBuildInfoFile, clearTempDeclarationDir, emptyDir, ensureTempDeclarationDir, getDtsEmitPath, getFileLoc, getTimeCost, globDtsFiles, isDirectory, loadTsconfig, pathExists, prettyTime, processDtsFiles, processSourceEntry, redirectDtsImports, warnIfOutside };
|