vite-plugin-lib 2.0.5 → 2.0.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/README.md CHANGED
@@ -24,7 +24,6 @@ This highly opinionated all-in one Vite plugin enables automatic alias configura
24
24
 
25
25
  ```ts
26
26
  import { defineConfig } from 'vite'
27
-
28
27
  import { tsconfigPaths } from 'vite-plugin-lib'
29
28
 
30
29
  export default defineConfig({
@@ -38,7 +37,6 @@ The `library` plugin includes the `alias` plugin, configures build settings, and
38
37
 
39
38
  ```ts
40
39
  import { defineConfig } from 'vite'
41
-
42
40
  import { library } from 'vite-plugin-lib'
43
41
 
44
42
  export default defineConfig({
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,21 @@ 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 (
54
+ // eslint-disable-next-line style/quotes
55
+ transformStaticImport(file, line, "'", verbose) ?? transformStaticImport(file, line, '"', verbose) ?? // eslint-disable-next-line style/quotes
56
+ transformExport(file, line, "'", verbose) ?? transformExport(file, line, '"', verbose) ?? line
57
+ );
54
58
  }
55
- function transformStaticImport(file, line, quote) {
59
+ function transformStaticImport(file, line, quote, verbose) {
56
60
  const importPathMarker = `from ${quote}`;
57
61
  const isStaticImport = line.includes("import ") && line.includes(`${importPathMarker}.`);
58
62
  if (!isStaticImport) {
@@ -65,12 +69,14 @@ function transformStaticImport(file, line, quote) {
65
69
  );
66
70
  const resolvedImport = path.resolve(path.dirname(file), importPath);
67
71
  if (existsSync(resolvedImport)) {
68
- log(`got index import ${resolvedImport}`);
72
+ if (verbose) {
73
+ log(`got index import ${resolvedImport}`);
74
+ }
69
75
  return `${line.substring(0, line.length - 2)}/index.mjs${quote};`;
70
76
  }
71
77
  return `${line.substring(0, line.length - 2)}.mjs${quote};`;
72
78
  }
73
- function transformExport(file, line, quote) {
79
+ function transformExport(file, line, quote, verbose) {
74
80
  const exportPathMarker = ` from ${quote}`;
75
81
  const isStaticExport = line.includes("export ") && line.includes(`${exportPathMarker}.`);
76
82
  if (!isStaticExport) {
@@ -83,7 +89,9 @@ function transformExport(file, line, quote) {
83
89
  );
84
90
  const resolvedExport = path.resolve(path.dirname(file), exportPath);
85
91
  if (existsSync(resolvedExport)) {
86
- log(`got index export ${resolvedExport}`);
92
+ if (verbose) {
93
+ log(`got index export ${resolvedExport}`);
94
+ }
87
95
  return `${line.substring(0, line.length - 2)}/index.mjs${quote};`;
88
96
  }
89
97
  return `${line.substring(0, line.length - 2)}.mjs${quote};`;
@@ -268,7 +276,8 @@ function library(options = {}) {
268
276
  staticImport: true,
269
277
  afterBuild: includesESFormat(mergedOptions.formats) ? () => generateMTSDeclarations(
270
278
  typesDir,
271
- mergedOptions.formats?.length === 1
279
+ mergedOptions.formats?.length === 1,
280
+ options.verbose
272
281
  ) : void 0
273
282
  })
274
283
  ];
@@ -294,7 +303,6 @@ async function readConfig(configPath) {
294
303
  }
295
304
  const { options } = ts.parseJsonConfigFileContent(
296
305
  config,
297
- // eslint-disable-next-line import/no-named-as-default-member
298
306
  ts.sys,
299
307
  path.dirname(configPath)
300
308
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-lib",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
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",
@@ -26,8 +26,8 @@
26
26
  },
27
27
  "types": "dist/index.d.mts",
28
28
  "files": [
29
- "dist",
30
- "LICENSE"
29
+ "LICENSE",
30
+ "dist"
31
31
  ],
32
32
  "peerDependencies": {
33
33
  "typescript": "*",
@@ -35,14 +35,14 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "picocolors": "1.0.0",
38
- "vite-plugin-dts": "3.7.0"
38
+ "vite-plugin-dts": "3.7.2"
39
39
  },
40
40
  "devDependencies": {
41
- "@types/node": "20.11.1",
41
+ "@types/node": "20.11.17",
42
42
  "typescript": "5.3.3",
43
43
  "unbuild": "2.0.0",
44
- "vite": "5.0.11",
45
- "@yeger/tsconfig": "2.0.2"
44
+ "vite": "5.1.0",
45
+ "@yeger/tsconfig": "2.0.4"
46
46
  },
47
47
  "publishConfig": {
48
48
  "access": "public"