vite-plugin-lib 2.0.4 → 2.0.6
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.mjs +16 -11
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -20,10 +20,10 @@ function logError(text) {
|
|
|
20
20
|
console.error(`${c.red("[vite:lib]")} ${text}`);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
async function generateMTSDeclarations(typesDir, deleteSourceFiles) {
|
|
23
|
+
async function generateMTSDeclarations(typesDir, deleteSourceFiles, verbose) {
|
|
24
24
|
const files = await collectFiles(typesDir);
|
|
25
25
|
for (const file of files) {
|
|
26
|
-
await createMTSImports(file);
|
|
26
|
+
await createMTSImports(file, verbose);
|
|
27
27
|
if (deleteSourceFiles) {
|
|
28
28
|
unlink(file);
|
|
29
29
|
}
|
|
@@ -42,17 +42,17 @@ async function collectFiles(dir) {
|
|
|
42
42
|
);
|
|
43
43
|
return files.map((file) => normalizePath(path.join(dir, file.name))).concat(...nestedFiles);
|
|
44
44
|
}
|
|
45
|
-
async function createMTSImports(file) {
|
|
45
|
+
async function createMTSImports(file, verbose) {
|
|
46
46
|
const content = await readFile(file, "utf-8");
|
|
47
47
|
const lines = content.split("\n");
|
|
48
|
-
const modified = lines.map((line) => transformLine(file, line));
|
|
48
|
+
const modified = lines.map((line) => transformLine(file, line, verbose));
|
|
49
49
|
const targetFile = file.replace(".d.ts", ".d.mts");
|
|
50
50
|
await writeFile(targetFile, modified.join("\n"));
|
|
51
51
|
}
|
|
52
|
-
function transformLine(file, line) {
|
|
53
|
-
return transformStaticImport(file, line, "'") ?? transformStaticImport(file, line, '"') ?? transformExport(file, line, "'") ?? transformExport(file, line, '"') ?? line;
|
|
52
|
+
function transformLine(file, line, verbose) {
|
|
53
|
+
return transformStaticImport(file, line, "'", verbose) ?? transformStaticImport(file, line, '"', verbose) ?? transformExport(file, line, "'", verbose) ?? transformExport(file, line, '"', verbose) ?? line;
|
|
54
54
|
}
|
|
55
|
-
function transformStaticImport(file, line, quote) {
|
|
55
|
+
function transformStaticImport(file, line, quote, verbose) {
|
|
56
56
|
const importPathMarker = `from ${quote}`;
|
|
57
57
|
const isStaticImport = line.includes("import ") && line.includes(`${importPathMarker}.`);
|
|
58
58
|
if (!isStaticImport) {
|
|
@@ -65,12 +65,14 @@ function transformStaticImport(file, line, quote) {
|
|
|
65
65
|
);
|
|
66
66
|
const resolvedImport = path.resolve(path.dirname(file), importPath);
|
|
67
67
|
if (existsSync(resolvedImport)) {
|
|
68
|
-
|
|
68
|
+
if (verbose) {
|
|
69
|
+
log(`got index import ${resolvedImport}`);
|
|
70
|
+
}
|
|
69
71
|
return `${line.substring(0, line.length - 2)}/index.mjs${quote};`;
|
|
70
72
|
}
|
|
71
73
|
return `${line.substring(0, line.length - 2)}.mjs${quote};`;
|
|
72
74
|
}
|
|
73
|
-
function transformExport(file, line, quote) {
|
|
75
|
+
function transformExport(file, line, quote, verbose) {
|
|
74
76
|
const exportPathMarker = ` from ${quote}`;
|
|
75
77
|
const isStaticExport = line.includes("export ") && line.includes(`${exportPathMarker}.`);
|
|
76
78
|
if (!isStaticExport) {
|
|
@@ -83,7 +85,9 @@ function transformExport(file, line, quote) {
|
|
|
83
85
|
);
|
|
84
86
|
const resolvedExport = path.resolve(path.dirname(file), exportPath);
|
|
85
87
|
if (existsSync(resolvedExport)) {
|
|
86
|
-
|
|
88
|
+
if (verbose) {
|
|
89
|
+
log(`got index export ${resolvedExport}`);
|
|
90
|
+
}
|
|
87
91
|
return `${line.substring(0, line.length - 2)}/index.mjs${quote};`;
|
|
88
92
|
}
|
|
89
93
|
return `${line.substring(0, line.length - 2)}.mjs${quote};`;
|
|
@@ -268,7 +272,8 @@ function library(options = {}) {
|
|
|
268
272
|
staticImport: true,
|
|
269
273
|
afterBuild: includesESFormat(mergedOptions.formats) ? () => generateMTSDeclarations(
|
|
270
274
|
typesDir,
|
|
271
|
-
mergedOptions.formats?.length === 1
|
|
275
|
+
mergedOptions.formats?.length === 1,
|
|
276
|
+
options.verbose
|
|
272
277
|
) : void 0
|
|
273
278
|
})
|
|
274
279
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-lib",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
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",
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"picocolors": "1.0.0",
|
|
38
|
-
"vite-plugin-dts": "3.7.
|
|
38
|
+
"vite-plugin-dts": "3.7.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@types/node": "20.11.
|
|
41
|
+
"@types/node": "20.11.5",
|
|
42
42
|
"typescript": "5.3.3",
|
|
43
43
|
"unbuild": "2.0.0",
|
|
44
|
-
"vite": "5.0.
|
|
45
|
-
"@yeger/tsconfig": "2.0.
|
|
44
|
+
"vite": "5.0.12",
|
|
45
|
+
"@yeger/tsconfig": "2.0.3"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|