vite-plugin-lib 1.2.3 → 1.3.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/dist/index.cjs +33 -3
- package/dist/index.d.cts +15 -0
- package/dist/index.d.mts +15 -0
- package/dist/index.mjs +34 -4
- package/package.json +15 -10
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ const node_module = require('node:module');
|
|
|
6
6
|
const path = require('node:path');
|
|
7
7
|
const c = require('picocolors');
|
|
8
8
|
const ts = require('typescript');
|
|
9
|
+
const vite = require('vite');
|
|
9
10
|
const dts = require('vite-plugin-dts');
|
|
10
11
|
|
|
11
12
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
@@ -28,6 +29,7 @@ const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
|
|
|
28
29
|
const dts__default = /*#__PURE__*/_interopDefaultCompat(dts);
|
|
29
30
|
const dts__namespace = /*#__PURE__*/_interopNamespaceCompat(dts);
|
|
30
31
|
|
|
32
|
+
const typesDir = "dist/types";
|
|
31
33
|
function log(text) {
|
|
32
34
|
console.log(`${c__default.cyan("[vite:lib]")} ${text}`);
|
|
33
35
|
}
|
|
@@ -175,8 +177,9 @@ function library(options) {
|
|
|
175
177
|
cleanVueFileName: true,
|
|
176
178
|
copyDtsFiles: true,
|
|
177
179
|
include: `${path__default.resolve(options.entry, "..")}/**`,
|
|
178
|
-
outDir:
|
|
179
|
-
staticImport: true
|
|
180
|
+
outDir: typesDir,
|
|
181
|
+
staticImport: true,
|
|
182
|
+
afterBuild: includesESFormat(options.formats) ? () => copyMTSDeclaration(options) : void 0
|
|
180
183
|
})
|
|
181
184
|
];
|
|
182
185
|
}
|
|
@@ -207,11 +210,38 @@ async function readConfig(configPath) {
|
|
|
207
210
|
);
|
|
208
211
|
return options;
|
|
209
212
|
} catch (error) {
|
|
210
|
-
const message =
|
|
213
|
+
const message = getErrorMessage(error);
|
|
211
214
|
logError(`Could not read tsconfig.json: ${message}`);
|
|
212
215
|
throw error;
|
|
213
216
|
}
|
|
214
217
|
}
|
|
218
|
+
function includesESFormat(formats) {
|
|
219
|
+
return formats?.includes("es") ?? true;
|
|
220
|
+
}
|
|
221
|
+
function getErrorMessage(error) {
|
|
222
|
+
const isObject = typeof error === "object" && error !== null && "message" in error;
|
|
223
|
+
return isObject ? error.message : String(error);
|
|
224
|
+
}
|
|
225
|
+
async function copyMTSDeclaration(options) {
|
|
226
|
+
const declarationFile = options.entry.replace(".ts", ".d.ts").substring(options.entry.lastIndexOf("/") + 1);
|
|
227
|
+
const mtsDeclarationFile = declarationFile.replace(".ts", ".mts");
|
|
228
|
+
const sourceDeclaration = vite.normalizePath(
|
|
229
|
+
path__default.resolve(typesDir, declarationFile)
|
|
230
|
+
);
|
|
231
|
+
const targetDeclaration = vite.normalizePath(
|
|
232
|
+
path__default.resolve(typesDir, mtsDeclarationFile)
|
|
233
|
+
);
|
|
234
|
+
log(
|
|
235
|
+
`Creating mts declaration file ${mtsDeclarationFile} based on ${declarationFile}`
|
|
236
|
+
);
|
|
237
|
+
try {
|
|
238
|
+
await promises.copyFile(sourceDeclaration, targetDeclaration);
|
|
239
|
+
} catch (error) {
|
|
240
|
+
const message = getErrorMessage(error);
|
|
241
|
+
logError(`Could not create mts declaration file: ${message}`);
|
|
242
|
+
throw error;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
215
245
|
|
|
216
246
|
exports.dts = dts__namespace;
|
|
217
247
|
exports.library = library;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LibraryFormats, Plugin } from 'vite';
|
|
2
|
+
import * as vitePluginDts from 'vite-plugin-dts';
|
|
3
|
+
export { vitePluginDts as dts };
|
|
4
|
+
|
|
5
|
+
interface Options {
|
|
6
|
+
name: string;
|
|
7
|
+
entry: string;
|
|
8
|
+
formats?: LibraryFormats[];
|
|
9
|
+
externalPackages?: (string | RegExp)[];
|
|
10
|
+
verbose?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare function tsconfigPaths({ verbose }?: Partial<Options>): Plugin;
|
|
13
|
+
declare function library(options: Options): Plugin[];
|
|
14
|
+
|
|
15
|
+
export { Options, library, tsconfigPaths };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LibraryFormats, Plugin } from 'vite';
|
|
2
|
+
import * as vitePluginDts from 'vite-plugin-dts';
|
|
3
|
+
export { vitePluginDts as dts };
|
|
4
|
+
|
|
5
|
+
interface Options {
|
|
6
|
+
name: string;
|
|
7
|
+
entry: string;
|
|
8
|
+
formats?: LibraryFormats[];
|
|
9
|
+
externalPackages?: (string | RegExp)[];
|
|
10
|
+
verbose?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare function tsconfigPaths({ verbose }?: Partial<Options>): Plugin;
|
|
13
|
+
declare function library(options: Options): Plugin[];
|
|
14
|
+
|
|
15
|
+
export { Options, library, tsconfigPaths };
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { readFile, copyFile } from 'node:fs/promises';
|
|
3
3
|
import { builtinModules } from 'node:module';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import c from 'picocolors';
|
|
6
6
|
import ts from 'typescript';
|
|
7
|
+
import { normalizePath } from 'vite';
|
|
7
8
|
import dts__default from 'vite-plugin-dts';
|
|
8
9
|
import * as dts from 'vite-plugin-dts';
|
|
9
10
|
export { dts };
|
|
10
11
|
|
|
12
|
+
const typesDir = "dist/types";
|
|
11
13
|
function log(text) {
|
|
12
14
|
console.log(`${c.cyan("[vite:lib]")} ${text}`);
|
|
13
15
|
}
|
|
@@ -155,8 +157,9 @@ function library(options) {
|
|
|
155
157
|
cleanVueFileName: true,
|
|
156
158
|
copyDtsFiles: true,
|
|
157
159
|
include: `${path.resolve(options.entry, "..")}/**`,
|
|
158
|
-
outDir:
|
|
159
|
-
staticImport: true
|
|
160
|
+
outDir: typesDir,
|
|
161
|
+
staticImport: true,
|
|
162
|
+
afterBuild: includesESFormat(options.formats) ? () => copyMTSDeclaration(options) : void 0
|
|
160
163
|
})
|
|
161
164
|
];
|
|
162
165
|
}
|
|
@@ -187,10 +190,37 @@ async function readConfig(configPath) {
|
|
|
187
190
|
);
|
|
188
191
|
return options;
|
|
189
192
|
} catch (error) {
|
|
190
|
-
const message =
|
|
193
|
+
const message = getErrorMessage(error);
|
|
191
194
|
logError(`Could not read tsconfig.json: ${message}`);
|
|
192
195
|
throw error;
|
|
193
196
|
}
|
|
194
197
|
}
|
|
198
|
+
function includesESFormat(formats) {
|
|
199
|
+
return formats?.includes("es") ?? true;
|
|
200
|
+
}
|
|
201
|
+
function getErrorMessage(error) {
|
|
202
|
+
const isObject = typeof error === "object" && error !== null && "message" in error;
|
|
203
|
+
return isObject ? error.message : String(error);
|
|
204
|
+
}
|
|
205
|
+
async function copyMTSDeclaration(options) {
|
|
206
|
+
const declarationFile = options.entry.replace(".ts", ".d.ts").substring(options.entry.lastIndexOf("/") + 1);
|
|
207
|
+
const mtsDeclarationFile = declarationFile.replace(".ts", ".mts");
|
|
208
|
+
const sourceDeclaration = normalizePath(
|
|
209
|
+
path.resolve(typesDir, declarationFile)
|
|
210
|
+
);
|
|
211
|
+
const targetDeclaration = normalizePath(
|
|
212
|
+
path.resolve(typesDir, mtsDeclarationFile)
|
|
213
|
+
);
|
|
214
|
+
log(
|
|
215
|
+
`Creating mts declaration file ${mtsDeclarationFile} based on ${declarationFile}`
|
|
216
|
+
);
|
|
217
|
+
try {
|
|
218
|
+
await copyFile(sourceDeclaration, targetDeclaration);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
const message = getErrorMessage(error);
|
|
221
|
+
logError(`Could not create mts declaration file: ${message}`);
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
195
225
|
|
|
196
226
|
export { library, tsconfigPaths };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-lib",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Vite plugin for build configuration, automatic aliases, and type declarations.",
|
|
5
5
|
"author": "Jan Müller <janmueller3698@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,9 +18,14 @@
|
|
|
18
18
|
],
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
"require": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"default": "./dist/index.mjs"
|
|
28
|
+
}
|
|
24
29
|
}
|
|
25
30
|
},
|
|
26
31
|
"main": "dist/index.cjs",
|
|
@@ -36,13 +41,13 @@
|
|
|
36
41
|
},
|
|
37
42
|
"dependencies": {
|
|
38
43
|
"picocolors": "1.0.0",
|
|
39
|
-
"vite-plugin-dts": "3.
|
|
44
|
+
"vite-plugin-dts": "3.3.1"
|
|
40
45
|
},
|
|
41
46
|
"devDependencies": {
|
|
42
|
-
"@types/node": "18.
|
|
43
|
-
"typescript": "5.1.
|
|
44
|
-
"unbuild": "
|
|
45
|
-
"vite": "4.
|
|
47
|
+
"@types/node": "18.17.1",
|
|
48
|
+
"typescript": "5.1.6",
|
|
49
|
+
"unbuild": "v2.0.0-rc.0",
|
|
50
|
+
"vite": "4.4.7",
|
|
46
51
|
"@yeger/tsconfig": "1.1.2"
|
|
47
52
|
},
|
|
48
53
|
"publishConfig": {
|
|
@@ -51,7 +56,7 @@
|
|
|
51
56
|
"scripts": {
|
|
52
57
|
"build": "unbuild",
|
|
53
58
|
"check:publish": "publint run --strict",
|
|
54
|
-
"check:tsc": "tsc
|
|
59
|
+
"check:tsc": "tsc",
|
|
55
60
|
"lint": "yeger-lint"
|
|
56
61
|
}
|
|
57
62
|
}
|