vite-plugin-dts 4.0.0-beta.1 → 4.0.0-beta.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.
Files changed (3) hide show
  1. package/dist/index.cjs +57 -27
  2. package/dist/index.mjs +58 -28
  3. package/package.json +21 -21
package/dist/index.cjs CHANGED
@@ -9,8 +9,8 @@ const node_os = require('node:os');
9
9
  const languageCore = require('@vue/language-core');
10
10
  const typescript = require('@volar/typescript');
11
11
  const ts = require('typescript');
12
- const pluginutils = require('@rollup/pluginutils');
13
12
  const vueTsc = require('vue-tsc');
13
+ const pluginutils = require('@rollup/pluginutils');
14
14
  const debug = require('debug');
15
15
  const kolorist = require('kolorist');
16
16
  const apiExtractor = require('@microsoft/api-extractor');
@@ -24,6 +24,29 @@ const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
24
24
  const debug__default = /*#__PURE__*/_interopDefaultCompat(debug);
25
25
  const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
26
26
 
27
+ const createProgram = typescript.proxyCreateProgram(ts__default, ts__default.createProgram, (ts2, options) => {
28
+ const { configFilePath } = options.options;
29
+ const vueOptions = typeof configFilePath === "string" ? languageCore.createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : languageCore.resolveVueCompilerOptions({});
30
+ if (options.host) {
31
+ const writeFile = options.host.writeFile.bind(options.host);
32
+ options.host.writeFile = (fileName, contents, ...args) => {
33
+ return writeFile(fileName, vueTsc.removeEmitGlobalTypes(contents), ...args);
34
+ };
35
+ }
36
+ const vueLanguagePlugin = languageCore.createVueLanguagePlugin2(
37
+ ts2,
38
+ (id) => id,
39
+ languageCore.createRootFileChecker(
40
+ void 0,
41
+ () => options.rootNames.map((rootName) => rootName.replace(/\\/g, "/")),
42
+ options.host?.useCaseSensitiveFileNames?.() ?? false
43
+ ),
44
+ options.options,
45
+ vueOptions
46
+ );
47
+ return [vueLanguagePlugin];
48
+ });
49
+
27
50
  const windowsSlashRE = /\\+/g;
28
51
  function slash(p) {
29
52
  return p.replace(windowsSlashRE, "/");
@@ -565,7 +588,7 @@ function transformCode(options) {
565
588
  return false;
566
589
  }
567
590
  if (ts__default.isModuleDeclaration(node)) {
568
- if (node.body && ts__default.isModuleBlock(node.body) && !node.body.statements.some(
591
+ if (node.modifiers?.[0] && node.modifiers[0].kind === ts__default.SyntaxKind.DeclareKeyword && node.body && ts__default.isModuleBlock(node.body) && !node.body.statements.some(
569
592
  (s2) => ts__default.isExportAssignment(s2) || ts__default.isExportDeclaration(s2) || ts__default.isImportDeclaration(s2)
570
593
  )) {
571
594
  declareModules.push(s.slice(node.pos, node.end + 1));
@@ -584,6 +607,29 @@ function transformCode(options) {
584
607
  declareModules
585
608
  };
586
609
  }
610
+ function hasNamedExport(content) {
611
+ const ast = ts__default.createSourceFile("a.ts", content, ts__default.ScriptTarget.Latest);
612
+ let has = false;
613
+ walkSourceFile(ast, (node) => {
614
+ if (ts__default.isExportDeclaration(node) && node.exportClause && ts__default.isNamedExports(node.exportClause)) {
615
+ for (const element of node.exportClause.elements) {
616
+ if (element.name.escapedText !== "default") {
617
+ has = true;
618
+ break;
619
+ }
620
+ }
621
+ } else if ("modifiers" in node && Array.isArray(node.modifiers) && node.modifiers.length > 1) {
622
+ for (let i = 0, len = node.modifiers.length; i < len; ++i) {
623
+ if (node.modifiers[i].kind === ts__default.SyntaxKind.ExportKeyword && node.modifiers[i + 1]?.kind !== ts__default.SyntaxKind.DefaultKeyword) {
624
+ has = true;
625
+ break;
626
+ }
627
+ }
628
+ }
629
+ return false;
630
+ });
631
+ return has;
632
+ }
587
633
  function hasExportDefault(content) {
588
634
  const ast = ts__default.createSourceFile("a.ts", content, ts__default.ScriptTarget.Latest);
589
635
  let has = false;
@@ -610,26 +656,6 @@ function hasExportDefault(content) {
610
656
  return has;
611
657
  }
612
658
 
613
- const createProgram = typescript.proxyCreateProgram(ts__default, ts__default.createProgram, (ts2, options) => {
614
- const { configFilePath } = options.options;
615
- const vueOptions = typeof configFilePath === "string" ? languageCore.createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : languageCore.resolveVueCompilerOptions({});
616
- if (options.host) {
617
- const writeFile2 = options.host.writeFile.bind(options.host);
618
- options.host.writeFile = (fileName, contents, ...args) => {
619
- return writeFile2(fileName, vueTsc.removeEmitGlobalTypes(contents), ...args);
620
- };
621
- }
622
- const vueLanguagePlugin = languageCore.createVueLanguagePlugin(
623
- ts2,
624
- (id) => id,
625
- options.host?.useCaseSensitiveFileNames?.() ?? false,
626
- () => "",
627
- () => options.rootNames.map((rootName) => rootName.replace(/\\/g, "/")),
628
- options.options,
629
- vueOptions
630
- );
631
- return [vueLanguagePlugin];
632
- });
633
659
  const jsRE = /\.(m|c)?jsx?$/;
634
660
  const tsRE = /\.(m|c)?tsx?$/;
635
661
  const dtsRE = /\.d\.(m|c)?tsx?$/;
@@ -1074,12 +1100,17 @@ ${logPrefix} ${kolorist.yellow(
1074
1100
  let fromPath = normalizePath(node_path.relative(node_path.dirname(entryDtsPath), sourceEntry));
1075
1101
  fromPath = fromPath.replace(dtsRE, "");
1076
1102
  fromPath = fullRelativeRE.test(fromPath) ? fromPath : `./${fromPath}`;
1077
- let content = `export * from '${fromPath}'
1103
+ let content = "";
1104
+ if (emittedFiles.has(sourceEntry)) {
1105
+ if (hasNamedExport(emittedFiles.get(sourceEntry))) {
1106
+ content += `export * from '${fromPath}'
1078
1107
  `;
1079
- if (emittedFiles.has(sourceEntry) && hasExportDefault(emittedFiles.get(sourceEntry))) {
1080
- content += `import ${libName} from '${fromPath}'
1108
+ }
1109
+ if (hasExportDefault(emittedFiles.get(sourceEntry))) {
1110
+ content += `import ${libName} from '${fromPath}'
1081
1111
  export default ${libName}
1082
1112
  `;
1113
+ }
1083
1114
  }
1084
1115
  await writeOutput(cleanPath(entryDtsPath), content, outDir);
1085
1116
  }
@@ -1130,8 +1161,7 @@ export default ${libName}
1130
1161
  await writeOutput(
1131
1162
  filePath,
1132
1163
  await promises.readFile(filePath, "utf-8") + (declared ? `
1133
- ${declared}
1134
- ` : ""),
1164
+ ${declared}` : ""),
1135
1165
  node_path.dirname(filePath)
1136
1166
  );
1137
1167
  });
package/dist/index.mjs CHANGED
@@ -9,11 +9,11 @@ import { relative, posix, resolve as resolve$1, isAbsolute, dirname, normalize,
9
9
  import { existsSync, readdirSync, lstatSync, rmdirSync } from 'node:fs';
10
10
  import { readFile, mkdir, writeFile, unlink } from 'node:fs/promises';
11
11
  import { cpus } from 'node:os';
12
- import { createParsedCommandLine, resolveVueCompilerOptions, createVueLanguagePlugin } from '@vue/language-core';
12
+ import { createParsedCommandLine, resolveVueCompilerOptions, createVueLanguagePlugin2, createRootFileChecker } from '@vue/language-core';
13
13
  import { proxyCreateProgram } from '@volar/typescript';
14
14
  import ts from 'typescript';
15
- import { createFilter } from '@rollup/pluginutils';
16
15
  import { removeEmitGlobalTypes } from 'vue-tsc';
16
+ import { createFilter } from '@rollup/pluginutils';
17
17
  import debug from 'debug';
18
18
  import { cyan, yellow, green } from 'kolorist';
19
19
  import { ExtractorConfig, Extractor } from '@microsoft/api-extractor';
@@ -21,6 +21,29 @@ import { getPackageInfoSync, resolveModule } from 'local-pkg';
21
21
  import { compare } from 'compare-versions';
22
22
  import MagicString from 'magic-string';
23
23
 
24
+ const createProgram = proxyCreateProgram(ts, ts.createProgram, (ts2, options) => {
25
+ const { configFilePath } = options.options;
26
+ const vueOptions = typeof configFilePath === "string" ? createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : resolveVueCompilerOptions({});
27
+ if (options.host) {
28
+ const writeFile = options.host.writeFile.bind(options.host);
29
+ options.host.writeFile = (fileName, contents, ...args) => {
30
+ return writeFile(fileName, removeEmitGlobalTypes(contents), ...args);
31
+ };
32
+ }
33
+ const vueLanguagePlugin = createVueLanguagePlugin2(
34
+ ts2,
35
+ (id) => id,
36
+ createRootFileChecker(
37
+ void 0,
38
+ () => options.rootNames.map((rootName) => rootName.replace(/\\/g, "/")),
39
+ options.host?.useCaseSensitiveFileNames?.() ?? false
40
+ ),
41
+ options.options,
42
+ vueOptions
43
+ );
44
+ return [vueLanguagePlugin];
45
+ });
46
+
24
47
  const windowsSlashRE = /\\+/g;
25
48
  function slash(p) {
26
49
  return p.replace(windowsSlashRE, "/");
@@ -562,7 +585,7 @@ function transformCode(options) {
562
585
  return false;
563
586
  }
564
587
  if (ts.isModuleDeclaration(node)) {
565
- if (node.body && ts.isModuleBlock(node.body) && !node.body.statements.some(
588
+ if (node.modifiers?.[0] && node.modifiers[0].kind === ts.SyntaxKind.DeclareKeyword && node.body && ts.isModuleBlock(node.body) && !node.body.statements.some(
566
589
  (s2) => ts.isExportAssignment(s2) || ts.isExportDeclaration(s2) || ts.isImportDeclaration(s2)
567
590
  )) {
568
591
  declareModules.push(s.slice(node.pos, node.end + 1));
@@ -581,6 +604,29 @@ function transformCode(options) {
581
604
  declareModules
582
605
  };
583
606
  }
607
+ function hasNamedExport(content) {
608
+ const ast = ts.createSourceFile("a.ts", content, ts.ScriptTarget.Latest);
609
+ let has = false;
610
+ walkSourceFile(ast, (node) => {
611
+ if (ts.isExportDeclaration(node) && node.exportClause && ts.isNamedExports(node.exportClause)) {
612
+ for (const element of node.exportClause.elements) {
613
+ if (element.name.escapedText !== "default") {
614
+ has = true;
615
+ break;
616
+ }
617
+ }
618
+ } else if ("modifiers" in node && Array.isArray(node.modifiers) && node.modifiers.length > 1) {
619
+ for (let i = 0, len = node.modifiers.length; i < len; ++i) {
620
+ if (node.modifiers[i].kind === ts.SyntaxKind.ExportKeyword && node.modifiers[i + 1]?.kind !== ts.SyntaxKind.DefaultKeyword) {
621
+ has = true;
622
+ break;
623
+ }
624
+ }
625
+ }
626
+ return false;
627
+ });
628
+ return has;
629
+ }
584
630
  function hasExportDefault(content) {
585
631
  const ast = ts.createSourceFile("a.ts", content, ts.ScriptTarget.Latest);
586
632
  let has = false;
@@ -607,26 +653,6 @@ function hasExportDefault(content) {
607
653
  return has;
608
654
  }
609
655
 
610
- const createProgram = proxyCreateProgram(ts, ts.createProgram, (ts2, options) => {
611
- const { configFilePath } = options.options;
612
- const vueOptions = typeof configFilePath === "string" ? createParsedCommandLine(ts2, ts2.sys, configFilePath.replace(/\\/g, "/")).vueOptions : resolveVueCompilerOptions({});
613
- if (options.host) {
614
- const writeFile2 = options.host.writeFile.bind(options.host);
615
- options.host.writeFile = (fileName, contents, ...args) => {
616
- return writeFile2(fileName, removeEmitGlobalTypes(contents), ...args);
617
- };
618
- }
619
- const vueLanguagePlugin = createVueLanguagePlugin(
620
- ts2,
621
- (id) => id,
622
- options.host?.useCaseSensitiveFileNames?.() ?? false,
623
- () => "",
624
- () => options.rootNames.map((rootName) => rootName.replace(/\\/g, "/")),
625
- options.options,
626
- vueOptions
627
- );
628
- return [vueLanguagePlugin];
629
- });
630
656
  const jsRE = /\.(m|c)?jsx?$/;
631
657
  const tsRE = /\.(m|c)?tsx?$/;
632
658
  const dtsRE = /\.d\.(m|c)?tsx?$/;
@@ -1071,12 +1097,17 @@ ${logPrefix} ${yellow(
1071
1097
  let fromPath = normalizePath(relative(dirname(entryDtsPath), sourceEntry));
1072
1098
  fromPath = fromPath.replace(dtsRE, "");
1073
1099
  fromPath = fullRelativeRE.test(fromPath) ? fromPath : `./${fromPath}`;
1074
- let content = `export * from '${fromPath}'
1100
+ let content = "";
1101
+ if (emittedFiles.has(sourceEntry)) {
1102
+ if (hasNamedExport(emittedFiles.get(sourceEntry))) {
1103
+ content += `export * from '${fromPath}'
1075
1104
  `;
1076
- if (emittedFiles.has(sourceEntry) && hasExportDefault(emittedFiles.get(sourceEntry))) {
1077
- content += `import ${libName} from '${fromPath}'
1105
+ }
1106
+ if (hasExportDefault(emittedFiles.get(sourceEntry))) {
1107
+ content += `import ${libName} from '${fromPath}'
1078
1108
  export default ${libName}
1079
1109
  `;
1110
+ }
1080
1111
  }
1081
1112
  await writeOutput(cleanPath(entryDtsPath), content, outDir);
1082
1113
  }
@@ -1127,8 +1158,7 @@ export default ${libName}
1127
1158
  await writeOutput(
1128
1159
  filePath,
1129
1160
  await readFile(filePath, "utf-8") + (declared ? `
1130
- ${declared}
1131
- ` : ""),
1161
+ ${declared}` : ""),
1132
1162
  dirname(filePath)
1133
1163
  );
1134
1164
  });
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "vite-plugin-dts",
3
- "version": "4.0.0-beta.1",
3
+ "version": "4.0.0-beta.2",
4
4
  "type": "module",
5
+ "packageManager": "pnpm@8.3.0",
5
6
  "license": "MIT",
6
7
  "author": "qmhc",
7
- "packageManager": "pnpm@8.3.0",
8
8
  "scripts": {
9
9
  "build": "tsx scripts/build.ts",
10
10
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path .",
11
11
  "dev": "unbuild --stub",
12
- "lint": "eslint --ext .js,.jsx,.ts,.tsx \"{src,tests}/**\"",
13
12
  "_postinstall": "is-ci || husky install",
14
- "postpublish": "pinst --enable",
13
+ "lint": "eslint --ext .js,.jsx,.ts,.tsx \"{src,tests}/**\"",
15
14
  "precommit": "lint-staged -c ./.husky/.lintstagedrc -q",
16
15
  "prepublishOnly": "pinst --disable",
17
16
  "prettier": "pretty-quick --staged && pnpm run lint",
17
+ "postpublish": "pinst --enable",
18
18
  "release": "tsx scripts/release.ts",
19
19
  "test": "vitest run",
20
20
  "test:dev": "vitest",
@@ -39,13 +39,6 @@
39
39
  "engines": {
40
40
  "node": "^14.18.0 || >=16.0.0"
41
41
  },
42
- "repository": {
43
- "type": "git",
44
- "url": "git+https://github.com/qmhc/vite-plugin-dts.git"
45
- },
46
- "bugs": {
47
- "url": "https://github.com/qmhc/vite-plugin-dts/issues"
48
- },
49
42
  "keywords": [
50
43
  "vite",
51
44
  "vite-plugin",
@@ -57,17 +50,24 @@
57
50
  "vue-tsc",
58
51
  "volar"
59
52
  ],
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "git+https://github.com/qmhc/vite-plugin-dts.git"
56
+ },
57
+ "bugs": {
58
+ "url": "https://github.com/qmhc/vite-plugin-dts/issues"
59
+ },
60
60
  "dependencies": {
61
- "@microsoft/api-extractor": "7.47.2",
61
+ "@microsoft/api-extractor": "7.47.4",
62
62
  "@rollup/pluginutils": "^5.1.0",
63
63
  "@volar/typescript": "^2.3.4",
64
- "@vue/language-core": "2.0.19",
64
+ "@vue/language-core": "2.0.29",
65
65
  "compare-versions": "^6.1.1",
66
- "debug": "^4.3.5",
66
+ "debug": "^4.3.6",
67
67
  "kolorist": "^1.8.0",
68
68
  "local-pkg": "^0.5.0",
69
- "magic-string": "^0.30.10",
70
- "vue-tsc": "2.0.19"
69
+ "magic-string": "^0.30.11",
70
+ "vue-tsc": "2.0.29"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@commitlint/cli": "^19.3.0",
@@ -78,7 +78,7 @@
78
78
  "@types/semver": "^7.5.8",
79
79
  "@vexip-ui/commitlint-config": "^0.5.0",
80
80
  "@vexip-ui/eslint-config": "^0.12.1",
81
- "@vexip-ui/prettier-config": "^0.2.0",
81
+ "@vexip-ui/prettier-config": "^1.0.0",
82
82
  "@vue/eslint-config-standard": "^8.0.1",
83
83
  "@vue/eslint-config-typescript": "^13.0.0",
84
84
  "conventional-changelog-cli": "^5.0.0",
@@ -95,10 +95,10 @@
95
95
  "rimraf": "^6.0.1",
96
96
  "semver": "^7.6.3",
97
97
  "tsx": "^4.16.2",
98
- "typescript": "5.5.3",
98
+ "typescript": "5.5.4",
99
99
  "unbuild": "^2.0.0",
100
- "vite": "^5.3.4",
101
- "vitest": "^2.0.3"
100
+ "vite": "^5.3.5",
101
+ "vitest": "^2.0.4"
102
102
  },
103
103
  "peerDependencies": {
104
104
  "typescript": "*",
@@ -111,7 +111,7 @@
111
111
  },
112
112
  "pnpm": {
113
113
  "patchedDependencies": {
114
- "@microsoft/api-extractor@7.47.2": "patches/@microsoft__api-extractor@7.47.2.patch"
114
+ "@microsoft/api-extractor@7.47.4": "patches/@microsoft__api-extractor@7.47.4.patch"
115
115
  }
116
116
  }
117
117
  }