vite-plugin-dts 1.6.6 → 1.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.
- package/README.md +214 -214
- package/README.zh-CN.md +213 -213
- package/dist/index.cjs +104 -64
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +85 -34
- package/package.json +19 -20
package/dist/index.cjs
CHANGED
|
@@ -21,17 +21,6 @@ const SourceMapper_js = require('@microsoft/api-extractor/lib/collector/SourceMa
|
|
|
21
21
|
const DtsRollupGenerator_js = require('@microsoft/api-extractor/lib/generators/DtsRollupGenerator.js');
|
|
22
22
|
const nodeCoreLibrary = require('@rushstack/node-core-library');
|
|
23
23
|
|
|
24
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
25
|
-
|
|
26
|
-
const fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
27
|
-
const os__default = /*#__PURE__*/_interopDefaultLegacy(os);
|
|
28
|
-
const glob__default = /*#__PURE__*/_interopDefaultLegacy(glob);
|
|
29
|
-
const debug__default = /*#__PURE__*/_interopDefaultLegacy(debug);
|
|
30
|
-
const require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
31
|
-
const require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
32
|
-
const require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
33
|
-
const require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7);
|
|
34
|
-
|
|
35
24
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
36
25
|
|
|
37
26
|
function getDefaultExportFromCjs (x) {
|
|
@@ -3370,7 +3359,7 @@ function requireSourceMapSupport () {
|
|
|
3370
3359
|
hasRequiredSourceMapSupport = 1;
|
|
3371
3360
|
(function (module, exports) {
|
|
3372
3361
|
var SourceMapConsumer = requireSourceMap().SourceMapConsumer;
|
|
3373
|
-
var path = require$$
|
|
3362
|
+
var path = require$$1;
|
|
3374
3363
|
|
|
3375
3364
|
var fs;
|
|
3376
3365
|
try {
|
|
@@ -11055,9 +11044,9 @@ and limitations under the License.
|
|
|
11055
11044
|
var byteOrderMarkIndicator = "\uFEFF";
|
|
11056
11045
|
function getNodeSystem() {
|
|
11057
11046
|
var nativePattern = /^native |^\([^)]+\)$|^(internal[\\/]|[a-zA-Z0-9_\s]+(\.js)?$)/;
|
|
11058
|
-
var _fs = require$$
|
|
11059
|
-
var _path = require$$
|
|
11060
|
-
var _os =
|
|
11047
|
+
var _fs = require$$1$1;
|
|
11048
|
+
var _path = require$$1;
|
|
11049
|
+
var _os = os;
|
|
11061
11050
|
// crypto can be absent on reduced node installations
|
|
11062
11051
|
var _crypto;
|
|
11063
11052
|
try {
|
|
@@ -11068,7 +11057,7 @@ and limitations under the License.
|
|
|
11068
11057
|
}
|
|
11069
11058
|
var activeSession;
|
|
11070
11059
|
var profilePath = "./profile.cpuprofile";
|
|
11071
|
-
var Buffer = require$$
|
|
11060
|
+
var Buffer = require$$5.Buffer;
|
|
11072
11061
|
var nodeVersion = getNodeMajorVersion();
|
|
11073
11062
|
var isNode4OrLater = nodeVersion >= 4;
|
|
11074
11063
|
var isLinuxOrMacOs = process.platform === "linux" || process.platform === "darwin";
|
|
@@ -11221,7 +11210,7 @@ and limitations under the License.
|
|
|
11221
11210
|
cb();
|
|
11222
11211
|
return false;
|
|
11223
11212
|
}
|
|
11224
|
-
var inspector = require$$
|
|
11213
|
+
var inspector = require$$7;
|
|
11225
11214
|
if (!inspector || !inspector.Session) {
|
|
11226
11215
|
cb();
|
|
11227
11216
|
return false;
|
|
@@ -176693,6 +176682,10 @@ function requireCompiler() {
|
|
|
176693
176682
|
try {
|
|
176694
176683
|
compiler = _require(_require.resolve("vue/compiler-sfc", { paths: [compileRoot] }));
|
|
176695
176684
|
} catch (e) {
|
|
176685
|
+
try {
|
|
176686
|
+
compiler = _require(_require.resolve("@vue/compiler-sfc", { paths: [compileRoot] }));
|
|
176687
|
+
} catch (e2) {
|
|
176688
|
+
}
|
|
176696
176689
|
}
|
|
176697
176690
|
}
|
|
176698
176691
|
if (!compiler) {
|
|
@@ -176776,7 +176769,7 @@ const _sfc_main = ${classMatch[1]}`;
|
|
|
176776
176769
|
content = rewriteDefault(
|
|
176777
176770
|
script.content,
|
|
176778
176771
|
"_sfc_main",
|
|
176779
|
-
script.lang === "ts" ? ["typescript"] : void 0
|
|
176772
|
+
script.lang === "ts" ? ["typescript", "decorators-legacy"] : void 0
|
|
176780
176773
|
);
|
|
176781
176774
|
content += "\nexport default _sfc_main\n";
|
|
176782
176775
|
ext = script.lang || "js";
|
|
@@ -176883,7 +176876,7 @@ const defaultIndex = "index.d.ts";
|
|
|
176883
176876
|
const noop = () => {
|
|
176884
176877
|
};
|
|
176885
176878
|
const logPrefix = kolorist.cyan("[vite:dts]");
|
|
176886
|
-
const bundleDebug =
|
|
176879
|
+
const bundleDebug = debug("vite-plugin-dts:bundle");
|
|
176887
176880
|
function dtsPlugin(options = {}) {
|
|
176888
176881
|
const {
|
|
176889
176882
|
tsConfigFilePath = "tsconfig.json",
|
|
@@ -176894,9 +176887,10 @@ function dtsPlugin(options = {}) {
|
|
|
176894
176887
|
insertTypesEntry = false,
|
|
176895
176888
|
rollupTypes = false,
|
|
176896
176889
|
noEmitOnError = false,
|
|
176897
|
-
skipDiagnostics =
|
|
176898
|
-
logDiagnostics =
|
|
176890
|
+
skipDiagnostics = false,
|
|
176891
|
+
logDiagnostics = void 0,
|
|
176899
176892
|
copyDtsFiles = true,
|
|
176893
|
+
libFolderPath = void 0,
|
|
176900
176894
|
afterDiagnostic = noop,
|
|
176901
176895
|
beforeWriteFile = noop,
|
|
176902
176896
|
afterBuild = noop
|
|
@@ -176943,6 +176937,17 @@ function dtsPlugin(options = {}) {
|
|
|
176943
176937
|
if (isBundle)
|
|
176944
176938
|
return;
|
|
176945
176939
|
logger = config.logger;
|
|
176940
|
+
if (logDiagnostics != null) {
|
|
176941
|
+
logger.warn(
|
|
176942
|
+
kolorist.yellow(
|
|
176943
|
+
`
|
|
176944
|
+
${kolorist.cyan(
|
|
176945
|
+
"[vite:dts]"
|
|
176946
|
+
)} 'logDiagnostics' has been deprecated, the original feature now following 'skipDiagnostics'.
|
|
176947
|
+
`
|
|
176948
|
+
)
|
|
176949
|
+
);
|
|
176950
|
+
}
|
|
176946
176951
|
if (!config.build.lib) {
|
|
176947
176952
|
logger.warn(
|
|
176948
176953
|
kolorist.yellow(
|
|
@@ -176957,8 +176962,9 @@ ${kolorist.cyan(
|
|
|
176957
176962
|
indexName = defaultIndex;
|
|
176958
176963
|
} else {
|
|
176959
176964
|
const filename = config.build.lib.fileName ?? defaultIndex;
|
|
176965
|
+
const entry = typeof config.build.lib.entry === "string" ? config.build.lib.entry : Object.values(config.build.lib.entry)[0];
|
|
176960
176966
|
libName = config.build.lib.name || "_default";
|
|
176961
|
-
indexName = typeof filename === "string" ? filename : filename("es");
|
|
176967
|
+
indexName = typeof filename === "string" ? filename : filename("es", entry);
|
|
176962
176968
|
if (!dtsRE.test(indexName)) {
|
|
176963
176969
|
indexName = `${tjsRE.test(indexName) ? indexName.replace(tjsRE, "") : indexName}.d.ts`;
|
|
176964
176970
|
}
|
|
@@ -176991,13 +176997,19 @@ ${kolorist.cyan(
|
|
|
176991
176997
|
emitDeclarationOnly: true
|
|
176992
176998
|
}),
|
|
176993
176999
|
tsConfigFilePath: tsConfigPath,
|
|
176994
|
-
skipAddingFilesFromTsConfig: true
|
|
177000
|
+
skipAddingFilesFromTsConfig: true,
|
|
177001
|
+
libFolderPath: libFolderPath ? ensureAbsolute(libFolderPath, root) : void 0
|
|
176995
177002
|
});
|
|
176996
177003
|
allowJs = project.getCompilerOptions().allowJs ?? false;
|
|
176997
177004
|
},
|
|
176998
177005
|
buildStart(inputOptions) {
|
|
176999
|
-
if (
|
|
177000
|
-
entries =
|
|
177006
|
+
if (Array.isArray(inputOptions.input)) {
|
|
177007
|
+
entries = inputOptions.input.reduce((prev, current) => {
|
|
177008
|
+
prev[node_path.basename(current)] = current;
|
|
177009
|
+
return prev;
|
|
177010
|
+
}, {});
|
|
177011
|
+
} else {
|
|
177012
|
+
entries = { ...inputOptions.input };
|
|
177001
177013
|
}
|
|
177002
177014
|
},
|
|
177003
177015
|
transform(code, id) {
|
|
@@ -177042,7 +177054,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
177042
177054
|
bundleDebug("read config");
|
|
177043
177055
|
const includedFileSet = /* @__PURE__ */ new Set();
|
|
177044
177056
|
if (include && include.length) {
|
|
177045
|
-
const files = await
|
|
177057
|
+
const files = await glob(ensureArray(include).map(normalizeGlob), {
|
|
177046
177058
|
cwd: root,
|
|
177047
177059
|
absolute: true,
|
|
177048
177060
|
ignore: ensureArray(exclude).map(normalizeGlob)
|
|
@@ -177076,7 +177088,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
177076
177088
|
bundleDebug("resolve");
|
|
177077
177089
|
if (!skipDiagnostics) {
|
|
177078
177090
|
const diagnostics = project.getPreEmitDiagnostics();
|
|
177079
|
-
if (diagnostics?.length
|
|
177091
|
+
if (diagnostics?.length) {
|
|
177080
177092
|
logger.warn(project.formatDiagnosticsWithColorAndContext(diagnostics));
|
|
177081
177093
|
}
|
|
177082
177094
|
if (typeof afterDiagnostic === "function") {
|
|
@@ -177103,7 +177115,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
177103
177115
|
entryRoot = ensureAbsolute(entryRoot, root);
|
|
177104
177116
|
const wroteFiles = /* @__PURE__ */ new Set();
|
|
177105
177117
|
const outputDir = outputDirs[0];
|
|
177106
|
-
await runParallel(
|
|
177118
|
+
await runParallel(os.cpus().length, outputFiles, async (outputFile) => {
|
|
177107
177119
|
let filePath = outputFile.path;
|
|
177108
177120
|
let content = outputFile.content;
|
|
177109
177121
|
const isMapFile = filePath.endsWith(".map");
|
|
@@ -177128,8 +177140,8 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
177128
177140
|
content = result.content ?? content;
|
|
177129
177141
|
}
|
|
177130
177142
|
}
|
|
177131
|
-
await
|
|
177132
|
-
await
|
|
177143
|
+
await fs.mkdir(node_path.dirname(filePath), { recursive: true });
|
|
177144
|
+
await fs.writeFile(
|
|
177133
177145
|
filePath,
|
|
177134
177146
|
cleanVueFileName ? content.replace(/['"](.+)\.vue['"]/g, '"$1"') : content,
|
|
177135
177147
|
"utf-8"
|
|
@@ -177139,59 +177151,87 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
177139
177151
|
bundleDebug("output");
|
|
177140
177152
|
if (insertTypesEntry || rollupTypes) {
|
|
177141
177153
|
const pkgPath = node_path.resolve(root, "package.json");
|
|
177142
|
-
const pkg =
|
|
177154
|
+
const pkg = fs.existsSync(pkgPath) ? JSON.parse(await fs.readFile(pkgPath, "utf-8")) : {};
|
|
177155
|
+
const entryNames = Object.keys(entries);
|
|
177143
177156
|
const types = pkg.types || pkg.typings;
|
|
177144
|
-
|
|
177145
|
-
|
|
177146
|
-
|
|
177147
|
-
|
|
177148
|
-
|
|
177149
|
-
|
|
177150
|
-
|
|
177151
|
-
|
|
177157
|
+
const multiple = entryNames.length > 1;
|
|
177158
|
+
const typesPath = types ? node_path.resolve(root, types) : node_path.resolve(outputDir, indexName);
|
|
177159
|
+
for (const name of entryNames) {
|
|
177160
|
+
let filePath = multiple ? node_path.resolve(outputDir, name.replace(tsRE, ".d.ts")) : typesPath;
|
|
177161
|
+
if (fs.existsSync(filePath))
|
|
177162
|
+
continue;
|
|
177163
|
+
const index = node_path.resolve(
|
|
177164
|
+
outputDir,
|
|
177165
|
+
node_path.relative(entryRoot, entries[name].replace(tsRE, ".d.ts"))
|
|
177166
|
+
);
|
|
177167
|
+
let fromPath = vite.normalizePath(node_path.relative(node_path.dirname(filePath), index));
|
|
177168
|
+
fromPath = fromPath.replace(dtsRE, "");
|
|
177169
|
+
fromPath = fullRelativeRE.test(fromPath) ? fromPath : `./${fromPath}`;
|
|
177170
|
+
let content = `export * from '${fromPath}'
|
|
177152
177171
|
`;
|
|
177153
|
-
if (
|
|
177154
|
-
const entryCodes = await
|
|
177172
|
+
if (fs.existsSync(index)) {
|
|
177173
|
+
const entryCodes = await fs.readFile(index, "utf-8");
|
|
177155
177174
|
if (entryCodes.includes("export default")) {
|
|
177156
|
-
content += `import ${libName} from '${
|
|
177175
|
+
content += `import ${libName} from '${fromPath}'
|
|
177157
177176
|
export default ${libName}
|
|
177158
177177
|
`;
|
|
177159
177178
|
}
|
|
177160
177179
|
}
|
|
177161
177180
|
let result;
|
|
177162
177181
|
if (typeof beforeWriteFile === "function") {
|
|
177163
|
-
result = beforeWriteFile(
|
|
177182
|
+
result = beforeWriteFile(filePath, content);
|
|
177164
177183
|
if (result && isNativeObj(result)) {
|
|
177165
|
-
|
|
177184
|
+
filePath = result.filePath ?? filePath;
|
|
177166
177185
|
content = result.content ?? content;
|
|
177167
177186
|
}
|
|
177168
177187
|
}
|
|
177169
177188
|
if (result !== false) {
|
|
177170
|
-
await
|
|
177171
|
-
wroteFiles.add(vite.normalizePath(
|
|
177189
|
+
await fs.writeFile(filePath, content, "utf-8");
|
|
177190
|
+
wroteFiles.add(vite.normalizePath(filePath));
|
|
177172
177191
|
}
|
|
177173
177192
|
}
|
|
177174
177193
|
bundleDebug("insert index");
|
|
177175
177194
|
if (rollupTypes) {
|
|
177176
177195
|
logger.info(kolorist.green(`${logPrefix} Start rollup declaration files...`));
|
|
177177
|
-
|
|
177178
|
-
|
|
177179
|
-
|
|
177180
|
-
|
|
177181
|
-
|
|
177182
|
-
|
|
177183
|
-
|
|
177184
|
-
|
|
177185
|
-
|
|
177186
|
-
|
|
177187
|
-
|
|
177196
|
+
const rollupFiles = /* @__PURE__ */ new Set();
|
|
177197
|
+
if (multiple) {
|
|
177198
|
+
for (const name of entryNames) {
|
|
177199
|
+
const path = node_path.resolve(outputDir, name.replace(tsRE, ".d.ts"));
|
|
177200
|
+
rollupDeclarationFiles({
|
|
177201
|
+
root,
|
|
177202
|
+
tsConfigPath,
|
|
177203
|
+
compilerOptions,
|
|
177204
|
+
outputDir,
|
|
177205
|
+
entryPath: path,
|
|
177206
|
+
fileName: node_path.basename(path)
|
|
177207
|
+
});
|
|
177208
|
+
const wroteFile = vite.normalizePath(path);
|
|
177209
|
+
wroteFiles.delete(wroteFile);
|
|
177210
|
+
rollupFiles.add(wroteFile);
|
|
177211
|
+
}
|
|
177212
|
+
} else {
|
|
177213
|
+
rollupDeclarationFiles({
|
|
177214
|
+
root,
|
|
177215
|
+
tsConfigPath,
|
|
177216
|
+
compilerOptions,
|
|
177217
|
+
outputDir,
|
|
177218
|
+
entryPath: typesPath,
|
|
177219
|
+
fileName: node_path.basename(typesPath)
|
|
177220
|
+
});
|
|
177221
|
+
const wroteFile = vite.normalizePath(typesPath);
|
|
177222
|
+
wroteFiles.delete(wroteFile);
|
|
177223
|
+
rollupFiles.add(wroteFile);
|
|
177224
|
+
}
|
|
177225
|
+
await runParallel(os.cpus().length, Array.from(wroteFiles), (f) => fs.unlink(f));
|
|
177188
177226
|
removeDirIfEmpty(outputDir);
|
|
177189
177227
|
wroteFiles.clear();
|
|
177190
|
-
|
|
177228
|
+
for (const file of rollupFiles) {
|
|
177229
|
+
wroteFiles.add(file);
|
|
177230
|
+
}
|
|
177191
177231
|
if (copyDtsFiles) {
|
|
177192
|
-
await runParallel(
|
|
177232
|
+
await runParallel(os.cpus().length, dtsOutputFiles, async ({ path, content }) => {
|
|
177193
177233
|
const filePath = node_path.resolve(outputDir, node_path.basename(path));
|
|
177194
|
-
await
|
|
177234
|
+
await fs.writeFile(filePath, content, "utf-8");
|
|
177195
177235
|
wroteFiles.add(vite.normalizePath(filePath));
|
|
177196
177236
|
});
|
|
177197
177237
|
}
|
|
@@ -177200,14 +177240,14 @@ export default ${libName}
|
|
|
177200
177240
|
}
|
|
177201
177241
|
if (outputDirs.length > 1) {
|
|
177202
177242
|
const dirs = outputDirs.slice(1);
|
|
177203
|
-
await runParallel(
|
|
177243
|
+
await runParallel(os.cpus().length, Array.from(wroteFiles), async (wroteFile) => {
|
|
177204
177244
|
const relativePath = node_path.relative(outputDir, wroteFile);
|
|
177205
|
-
const content = await
|
|
177245
|
+
const content = await fs.readFile(wroteFile, "utf-8");
|
|
177206
177246
|
await Promise.all(
|
|
177207
177247
|
dirs.map(async (dir) => {
|
|
177208
177248
|
const filePath = node_path.resolve(dir, relativePath);
|
|
177209
|
-
await
|
|
177210
|
-
await
|
|
177249
|
+
await fs.mkdir(node_path.dirname(filePath), { recursive: true });
|
|
177250
|
+
await fs.writeFile(filePath, content, "utf-8");
|
|
177211
177251
|
})
|
|
177212
177252
|
);
|
|
177213
177253
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ interface PluginOptions {
|
|
|
23
23
|
noEmitOnError?: boolean;
|
|
24
24
|
skipDiagnostics?: boolean;
|
|
25
25
|
logDiagnostics?: boolean;
|
|
26
|
+
libFolderPath?: string;
|
|
26
27
|
afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>;
|
|
27
28
|
beforeWriteFile?: (filePath: string, content: string) => void | false | TransformWriteFile;
|
|
28
29
|
afterBuild?: () => void | Promise<void>;
|
package/dist/index.mjs
CHANGED
|
@@ -176687,6 +176687,10 @@ function requireCompiler() {
|
|
|
176687
176687
|
try {
|
|
176688
176688
|
compiler = _require(_require.resolve("vue/compiler-sfc", { paths: [compileRoot] }));
|
|
176689
176689
|
} catch (e) {
|
|
176690
|
+
try {
|
|
176691
|
+
compiler = _require(_require.resolve("@vue/compiler-sfc", { paths: [compileRoot] }));
|
|
176692
|
+
} catch (e2) {
|
|
176693
|
+
}
|
|
176690
176694
|
}
|
|
176691
176695
|
}
|
|
176692
176696
|
if (!compiler) {
|
|
@@ -176770,7 +176774,7 @@ const _sfc_main = ${classMatch[1]}`;
|
|
|
176770
176774
|
content = rewriteDefault(
|
|
176771
176775
|
script.content,
|
|
176772
176776
|
"_sfc_main",
|
|
176773
|
-
script.lang === "ts" ? ["typescript"] : void 0
|
|
176777
|
+
script.lang === "ts" ? ["typescript", "decorators-legacy"] : void 0
|
|
176774
176778
|
);
|
|
176775
176779
|
content += "\nexport default _sfc_main\n";
|
|
176776
176780
|
ext = script.lang || "js";
|
|
@@ -176888,9 +176892,10 @@ function dtsPlugin(options = {}) {
|
|
|
176888
176892
|
insertTypesEntry = false,
|
|
176889
176893
|
rollupTypes = false,
|
|
176890
176894
|
noEmitOnError = false,
|
|
176891
|
-
skipDiagnostics =
|
|
176892
|
-
logDiagnostics =
|
|
176895
|
+
skipDiagnostics = false,
|
|
176896
|
+
logDiagnostics = void 0,
|
|
176893
176897
|
copyDtsFiles = true,
|
|
176898
|
+
libFolderPath = void 0,
|
|
176894
176899
|
afterDiagnostic = noop,
|
|
176895
176900
|
beforeWriteFile = noop,
|
|
176896
176901
|
afterBuild = noop
|
|
@@ -176937,6 +176942,17 @@ function dtsPlugin(options = {}) {
|
|
|
176937
176942
|
if (isBundle)
|
|
176938
176943
|
return;
|
|
176939
176944
|
logger = config.logger;
|
|
176945
|
+
if (logDiagnostics != null) {
|
|
176946
|
+
logger.warn(
|
|
176947
|
+
yellow(
|
|
176948
|
+
`
|
|
176949
|
+
${cyan(
|
|
176950
|
+
"[vite:dts]"
|
|
176951
|
+
)} 'logDiagnostics' has been deprecated, the original feature now following 'skipDiagnostics'.
|
|
176952
|
+
`
|
|
176953
|
+
)
|
|
176954
|
+
);
|
|
176955
|
+
}
|
|
176940
176956
|
if (!config.build.lib) {
|
|
176941
176957
|
logger.warn(
|
|
176942
176958
|
yellow(
|
|
@@ -176951,8 +176967,9 @@ ${cyan(
|
|
|
176951
176967
|
indexName = defaultIndex;
|
|
176952
176968
|
} else {
|
|
176953
176969
|
const filename = config.build.lib.fileName ?? defaultIndex;
|
|
176970
|
+
const entry = typeof config.build.lib.entry === "string" ? config.build.lib.entry : Object.values(config.build.lib.entry)[0];
|
|
176954
176971
|
libName = config.build.lib.name || "_default";
|
|
176955
|
-
indexName = typeof filename === "string" ? filename : filename("es");
|
|
176972
|
+
indexName = typeof filename === "string" ? filename : filename("es", entry);
|
|
176956
176973
|
if (!dtsRE.test(indexName)) {
|
|
176957
176974
|
indexName = `${tjsRE.test(indexName) ? indexName.replace(tjsRE, "") : indexName}.d.ts`;
|
|
176958
176975
|
}
|
|
@@ -176985,13 +177002,19 @@ ${cyan(
|
|
|
176985
177002
|
emitDeclarationOnly: true
|
|
176986
177003
|
}),
|
|
176987
177004
|
tsConfigFilePath: tsConfigPath,
|
|
176988
|
-
skipAddingFilesFromTsConfig: true
|
|
177005
|
+
skipAddingFilesFromTsConfig: true,
|
|
177006
|
+
libFolderPath: libFolderPath ? ensureAbsolute(libFolderPath, root) : void 0
|
|
176989
177007
|
});
|
|
176990
177008
|
allowJs = project.getCompilerOptions().allowJs ?? false;
|
|
176991
177009
|
},
|
|
176992
177010
|
buildStart(inputOptions) {
|
|
176993
|
-
if (
|
|
176994
|
-
entries =
|
|
177011
|
+
if (Array.isArray(inputOptions.input)) {
|
|
177012
|
+
entries = inputOptions.input.reduce((prev, current) => {
|
|
177013
|
+
prev[basename(current)] = current;
|
|
177014
|
+
return prev;
|
|
177015
|
+
}, {});
|
|
177016
|
+
} else {
|
|
177017
|
+
entries = { ...inputOptions.input };
|
|
176995
177018
|
}
|
|
176996
177019
|
},
|
|
176997
177020
|
transform(code, id) {
|
|
@@ -177070,7 +177093,7 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
177070
177093
|
bundleDebug("resolve");
|
|
177071
177094
|
if (!skipDiagnostics) {
|
|
177072
177095
|
const diagnostics = project.getPreEmitDiagnostics();
|
|
177073
|
-
if (diagnostics?.length
|
|
177096
|
+
if (diagnostics?.length) {
|
|
177074
177097
|
logger.warn(project.formatDiagnosticsWithColorAndContext(diagnostics));
|
|
177075
177098
|
}
|
|
177076
177099
|
if (typeof afterDiagnostic === "function") {
|
|
@@ -177134,54 +177157,82 @@ ${logPrefix} Start generate declaration files...`));
|
|
|
177134
177157
|
if (insertTypesEntry || rollupTypes) {
|
|
177135
177158
|
const pkgPath = resolve(root, "package.json");
|
|
177136
177159
|
const pkg = fs.existsSync(pkgPath) ? JSON.parse(await fs.readFile(pkgPath, "utf-8")) : {};
|
|
177160
|
+
const entryNames = Object.keys(entries);
|
|
177137
177161
|
const types = pkg.types || pkg.typings;
|
|
177138
|
-
|
|
177139
|
-
|
|
177140
|
-
|
|
177141
|
-
|
|
177142
|
-
|
|
177143
|
-
|
|
177144
|
-
|
|
177145
|
-
|
|
177162
|
+
const multiple = entryNames.length > 1;
|
|
177163
|
+
const typesPath = types ? resolve(root, types) : resolve(outputDir, indexName);
|
|
177164
|
+
for (const name of entryNames) {
|
|
177165
|
+
let filePath = multiple ? resolve(outputDir, name.replace(tsRE, ".d.ts")) : typesPath;
|
|
177166
|
+
if (fs.existsSync(filePath))
|
|
177167
|
+
continue;
|
|
177168
|
+
const index = resolve(
|
|
177169
|
+
outputDir,
|
|
177170
|
+
relative(entryRoot, entries[name].replace(tsRE, ".d.ts"))
|
|
177171
|
+
);
|
|
177172
|
+
let fromPath = normalizePath(relative(dirname(filePath), index));
|
|
177173
|
+
fromPath = fromPath.replace(dtsRE, "");
|
|
177174
|
+
fromPath = fullRelativeRE.test(fromPath) ? fromPath : `./${fromPath}`;
|
|
177175
|
+
let content = `export * from '${fromPath}'
|
|
177146
177176
|
`;
|
|
177147
|
-
if (fs.existsSync(
|
|
177148
|
-
const entryCodes = await fs.readFile(
|
|
177177
|
+
if (fs.existsSync(index)) {
|
|
177178
|
+
const entryCodes = await fs.readFile(index, "utf-8");
|
|
177149
177179
|
if (entryCodes.includes("export default")) {
|
|
177150
|
-
content += `import ${libName} from '${
|
|
177180
|
+
content += `import ${libName} from '${fromPath}'
|
|
177151
177181
|
export default ${libName}
|
|
177152
177182
|
`;
|
|
177153
177183
|
}
|
|
177154
177184
|
}
|
|
177155
177185
|
let result;
|
|
177156
177186
|
if (typeof beforeWriteFile === "function") {
|
|
177157
|
-
result = beforeWriteFile(
|
|
177187
|
+
result = beforeWriteFile(filePath, content);
|
|
177158
177188
|
if (result && isNativeObj(result)) {
|
|
177159
|
-
|
|
177189
|
+
filePath = result.filePath ?? filePath;
|
|
177160
177190
|
content = result.content ?? content;
|
|
177161
177191
|
}
|
|
177162
177192
|
}
|
|
177163
177193
|
if (result !== false) {
|
|
177164
|
-
await fs.writeFile(
|
|
177165
|
-
wroteFiles.add(normalizePath(
|
|
177194
|
+
await fs.writeFile(filePath, content, "utf-8");
|
|
177195
|
+
wroteFiles.add(normalizePath(filePath));
|
|
177166
177196
|
}
|
|
177167
177197
|
}
|
|
177168
177198
|
bundleDebug("insert index");
|
|
177169
177199
|
if (rollupTypes) {
|
|
177170
177200
|
logger.info(green(`${logPrefix} Start rollup declaration files...`));
|
|
177171
|
-
|
|
177172
|
-
|
|
177173
|
-
|
|
177174
|
-
|
|
177175
|
-
|
|
177176
|
-
|
|
177177
|
-
|
|
177178
|
-
|
|
177179
|
-
|
|
177180
|
-
|
|
177201
|
+
const rollupFiles = /* @__PURE__ */ new Set();
|
|
177202
|
+
if (multiple) {
|
|
177203
|
+
for (const name of entryNames) {
|
|
177204
|
+
const path = resolve(outputDir, name.replace(tsRE, ".d.ts"));
|
|
177205
|
+
rollupDeclarationFiles({
|
|
177206
|
+
root,
|
|
177207
|
+
tsConfigPath,
|
|
177208
|
+
compilerOptions,
|
|
177209
|
+
outputDir,
|
|
177210
|
+
entryPath: path,
|
|
177211
|
+
fileName: basename(path)
|
|
177212
|
+
});
|
|
177213
|
+
const wroteFile = normalizePath(path);
|
|
177214
|
+
wroteFiles.delete(wroteFile);
|
|
177215
|
+
rollupFiles.add(wroteFile);
|
|
177216
|
+
}
|
|
177217
|
+
} else {
|
|
177218
|
+
rollupDeclarationFiles({
|
|
177219
|
+
root,
|
|
177220
|
+
tsConfigPath,
|
|
177221
|
+
compilerOptions,
|
|
177222
|
+
outputDir,
|
|
177223
|
+
entryPath: typesPath,
|
|
177224
|
+
fileName: basename(typesPath)
|
|
177225
|
+
});
|
|
177226
|
+
const wroteFile = normalizePath(typesPath);
|
|
177227
|
+
wroteFiles.delete(wroteFile);
|
|
177228
|
+
rollupFiles.add(wroteFile);
|
|
177229
|
+
}
|
|
177181
177230
|
await runParallel(os.cpus().length, Array.from(wroteFiles), (f) => fs.unlink(f));
|
|
177182
177231
|
removeDirIfEmpty(outputDir);
|
|
177183
177232
|
wroteFiles.clear();
|
|
177184
|
-
|
|
177233
|
+
for (const file of rollupFiles) {
|
|
177234
|
+
wroteFiles.add(file);
|
|
177235
|
+
}
|
|
177185
177236
|
if (copyDtsFiles) {
|
|
177186
177237
|
await runParallel(os.cpus().length, dtsOutputFiles, async ({ path, content }) => {
|
|
177187
177238
|
const filePath = resolve(outputDir, basename(path));
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"url": "https://github.com/qmhc/vite-plugin-dts/issues"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@microsoft/api-extractor": "^7.33.
|
|
9
|
+
"@microsoft/api-extractor": "^7.33.5",
|
|
10
10
|
"@rushstack/node-core-library": "^3.53.2",
|
|
11
11
|
"debug": "^4.3.4",
|
|
12
12
|
"fast-glob": "^3.2.12",
|
|
@@ -20,20 +20,20 @@
|
|
|
20
20
|
"@types/debug": "^4.1.7",
|
|
21
21
|
"@types/fs-extra": "^9.0.13",
|
|
22
22
|
"@types/minimist": "^1.2.2",
|
|
23
|
-
"@types/node": "^18.
|
|
23
|
+
"@types/node": "^18.11.7",
|
|
24
24
|
"@types/prompts": "^2.4.1",
|
|
25
|
-
"@types/semver": "^7.3.
|
|
26
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
27
|
-
"@typescript-eslint/parser": "^5.
|
|
28
|
-
"@vitejs/plugin-vue": "^3.
|
|
25
|
+
"@types/semver": "^7.3.13",
|
|
26
|
+
"@typescript-eslint/eslint-plugin": "^5.41.0",
|
|
27
|
+
"@typescript-eslint/parser": "^5.41.0",
|
|
28
|
+
"@vitejs/plugin-vue": "^3.2.0",
|
|
29
29
|
"@vue/eslint-config-standard": "^8.0.1",
|
|
30
30
|
"@vue/eslint-config-typescript": "^11.0.2",
|
|
31
31
|
"conventional-changelog-cli": "^2.2.2",
|
|
32
32
|
"cross-env": "^7.0.3",
|
|
33
|
-
"eslint": "^8.
|
|
33
|
+
"eslint": "^8.26.0",
|
|
34
34
|
"eslint-plugin-import": "^2.26.0",
|
|
35
35
|
"eslint-plugin-node": "^11.1.0",
|
|
36
|
-
"eslint-plugin-promise": "^6.1.
|
|
36
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
37
37
|
"eslint-plugin-vue": "^9.6.0",
|
|
38
38
|
"execa": "^6.1.0",
|
|
39
39
|
"husky": "^8.0.1",
|
|
@@ -46,18 +46,19 @@
|
|
|
46
46
|
"prompts": "^2.4.2",
|
|
47
47
|
"rimraf": "^3.0.2",
|
|
48
48
|
"semver": "^7.3.8",
|
|
49
|
-
"tsx": "^3.
|
|
49
|
+
"tsx": "^3.11.0",
|
|
50
50
|
"typescript": "4.8.4",
|
|
51
|
-
"unbuild": "^0.
|
|
52
|
-
"vite": "^3.1
|
|
53
|
-
"vitest": "^0.24.
|
|
54
|
-
"vue": "3.2.
|
|
51
|
+
"unbuild": "^0.9.4",
|
|
52
|
+
"vite": "^3.2.1",
|
|
53
|
+
"vitest": "^0.24.3",
|
|
54
|
+
"vue": "3.2.41"
|
|
55
55
|
},
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": "^14.18.0 || >=16.0.0"
|
|
58
58
|
},
|
|
59
59
|
"exports": {
|
|
60
60
|
".": {
|
|
61
|
+
"types": "./dist/index.d.ts",
|
|
61
62
|
"require": "./dist/index.cjs",
|
|
62
63
|
"import": "./dist/index.mjs"
|
|
63
64
|
}
|
|
@@ -83,6 +84,9 @@
|
|
|
83
84
|
"type": "git",
|
|
84
85
|
"url": "git+https://github.com/qmhc/vite-plugin-dts.git"
|
|
85
86
|
},
|
|
87
|
+
"type": "module",
|
|
88
|
+
"types": "dist/index.d.ts",
|
|
89
|
+
"version": "1.7.0",
|
|
86
90
|
"scripts": {
|
|
87
91
|
"build": "tsx scripts/build.ts",
|
|
88
92
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path .",
|
|
@@ -91,15 +95,10 @@
|
|
|
91
95
|
"lint:src": "eslint --fix --ext .js,.jsx,.ts,.tsx,.vue src/**",
|
|
92
96
|
"lint:example": "eslint --fix --ext .js,.jsx,.ts,.tsx,.vue example/{src,components}/**",
|
|
93
97
|
"_postinstall": "is-ci || husky install",
|
|
94
|
-
"postpublish": "pinst --enable",
|
|
95
98
|
"precommit": "lint-staged -c ./.husky/.lintstagedrc -q",
|
|
96
|
-
"prepublishOnly": "pinst --disable",
|
|
97
99
|
"prettier": "pretty-quick --staged",
|
|
98
100
|
"release": "tsx scripts/release.ts",
|
|
99
101
|
"test": "vitest run",
|
|
100
102
|
"test:e2e": "pnpm -C example build"
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
"types": "dist/index.d.ts",
|
|
104
|
-
"version": "1.6.6"
|
|
105
|
-
}
|
|
103
|
+
}
|
|
104
|
+
}
|