vite-plugin-lib 1.2.0 → 1.2.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.
package/dist/index.cjs CHANGED
@@ -1,14 +1,17 @@
1
1
  'use strict';
2
2
 
3
- const fs = require('fs');
4
- const promises = require('fs/promises');
5
- const module$1 = require('module');
6
- const path = require('path');
3
+ const node_fs = require('node:fs');
4
+ const promises = require('node:fs/promises');
5
+ const node_module = require('node:module');
6
+ const path = require('node:path');
7
7
  const c = require('picocolors');
8
- const typescript = require('typescript');
8
+ const ts = require('typescript');
9
9
  const dts = require('vite-plugin-dts');
10
10
 
11
- function _interopNamespaceDefault(e) {
11
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
12
+
13
+ function _interopNamespaceCompat(e) {
14
+ if (e && typeof e === 'object' && 'default' in e) return e;
12
15
  const n = Object.create(null);
13
16
  if (e) {
14
17
  for (const k in e) {
@@ -19,23 +22,27 @@ function _interopNamespaceDefault(e) {
19
22
  return n;
20
23
  }
21
24
 
22
- const dts__namespace = /*#__PURE__*/_interopNamespaceDefault(dts);
25
+ const path__default = /*#__PURE__*/_interopDefaultCompat(path);
26
+ const c__default = /*#__PURE__*/_interopDefaultCompat(c);
27
+ const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
28
+ const dts__default = /*#__PURE__*/_interopDefaultCompat(dts);
29
+ const dts__namespace = /*#__PURE__*/_interopNamespaceCompat(dts);
23
30
 
24
31
  function log(text) {
25
- console.log(`${c.cyan("[vite:lib]")} ${text}`);
32
+ console.log(`${c__default.cyan("[vite:lib]")} ${text}`);
26
33
  }
27
34
  function logWarn(text) {
28
- console.warn(`${c.yellow("[vite:lib]")} ${text}`);
35
+ console.warn(`${c__default.yellow("[vite:lib]")} ${text}`);
29
36
  }
30
37
  function logError(text) {
31
- console.error(`${c.red("[vite:lib]")} ${text}`);
38
+ console.error(`${c__default.red("[vite:lib]")} ${text}`);
32
39
  }
33
- const tsconfigPaths = ({ verbose } = {}) => {
40
+ function tsconfigPaths({ verbose } = {}) {
34
41
  return {
35
42
  name: "vite-plugin-lib:alias",
36
43
  enforce: "pre",
37
44
  config: async (config) => {
38
- const tsconfigPath = path.resolve(config.root ?? ".", "tsconfig.json");
45
+ const tsconfigPath = path__default.resolve(config.root ?? ".", "tsconfig.json");
39
46
  const { baseUrl, paths } = await readConfig(tsconfigPath);
40
47
  if (!baseUrl || !paths) {
41
48
  log("No paths found in tsconfig.json.");
@@ -56,13 +63,13 @@ const tsconfigPaths = ({ verbose } = {}) => {
56
63
  };
57
64
  }
58
65
  };
59
- };
60
- const buildConfig = ({
66
+ }
67
+ function buildConfig({
61
68
  entry,
62
69
  formats,
63
70
  name,
64
71
  externalPackages
65
- }) => {
72
+ }) {
66
73
  if (!externalPackages) {
67
74
  log("Externalized all packages.");
68
75
  }
@@ -76,41 +83,41 @@ const buildConfig = ({
76
83
  ...config.build,
77
84
  lib: {
78
85
  ...config.build?.lib,
79
- entry: path.resolve(config.root ?? ".", entry),
86
+ entry: path__default.resolve(config.root ?? ".", entry),
80
87
  formats,
81
88
  name,
82
89
  fileName: (format) => formatToFileName(entry, format)
83
90
  },
84
91
  rollupOptions: {
85
- external: externalPackages ?? [/node_modules/, ...module$1.builtinModules]
92
+ external: externalPackages ?? [/node_modules/, ...node_module.builtinModules]
86
93
  }
87
94
  }
88
95
  };
89
96
  }
90
97
  };
91
- };
98
+ }
92
99
  function logInjectedAliases(aliasOptions, config, verbose) {
93
- log(`Injected ${c.green(aliasOptions.length)} aliases.`);
100
+ log(`Injected ${c__default.green(aliasOptions.length)} aliases.`);
94
101
  if (!verbose) {
95
102
  return;
96
103
  }
97
- const base = `${path.resolve(config.root ?? ".")}/`;
104
+ const base = `${path__default.resolve(config.root ?? ".")}/`;
98
105
  aliasOptions.map(
99
- ({ find, replacement }) => `${c.gray(">")} ${c.green(find.toString())} ${c.gray(
100
- c.bold("->")
101
- )} ${c.green(replacement.replace(base, ""))}`
106
+ ({ find, replacement }) => `${c__default.gray(">")} ${c__default.green(find.toString())} ${c__default.gray(
107
+ c__default.bold("->")
108
+ )} ${c__default.green(replacement.replace(base, ""))}`
102
109
  ).forEach(log);
103
110
  }
104
111
  function pathToAliasFactory(tsconfigPath, baseUrl, verbose) {
105
112
  return ([alias, replacements]) => {
106
113
  if (replacements.length === 0) {
107
114
  if (verbose) {
108
- logWarn(`No replacements for alias ${c.green(alias)}.`);
115
+ logWarn(`No replacements for alias ${c__default.green(alias)}.`);
109
116
  }
110
117
  return void 0;
111
118
  }
112
119
  if (verbose && replacements.length > 1) {
113
- logWarn(`Found more than one replacement for alias ${c.green(alias)}.`);
120
+ logWarn(`Found more than one replacement for alias ${c__default.green(alias)}.`);
114
121
  logWarn("Using the first existing replacement.");
115
122
  }
116
123
  const find = alias.replace("/*", "");
@@ -122,7 +129,7 @@ function pathToAliasFactory(tsconfigPath, baseUrl, verbose) {
122
129
  );
123
130
  if (!replacement) {
124
131
  if (verbose) {
125
- logWarn(`No replacement found for alias ${c.green(alias)}.`);
132
+ logWarn(`No replacement found for alias ${c__default.green(alias)}.`);
126
133
  }
127
134
  return void 0;
128
135
  }
@@ -134,15 +141,15 @@ function pathToAliasFactory(tsconfigPath, baseUrl, verbose) {
134
141
  }
135
142
  function getFirstExistingReplacement(tsconfigPath, baseUrl, replacements, find, verbose) {
136
143
  for (const replacement of replacements) {
137
- const resolvedReplacement = path.resolve(
144
+ const resolvedReplacement = path__default.resolve(
138
145
  tsconfigPath,
139
146
  baseUrl,
140
147
  replacement.replace("/*", "") ?? find
141
148
  );
142
- if (fs.existsSync(resolvedReplacement)) {
149
+ if (node_fs.existsSync(resolvedReplacement)) {
143
150
  return resolvedReplacement;
144
151
  } else if (verbose) {
145
- logWarn(`Path ${c.green(replacement)} does not exist.`);
152
+ logWarn(`Path ${c__default.green(replacement)} does not exist.`);
146
153
  }
147
154
  }
148
155
  return void 0;
@@ -164,9 +171,10 @@ function library(options) {
164
171
  return [
165
172
  tsconfigPaths(),
166
173
  buildConfig(options),
167
- dts({
174
+ dts__default({
168
175
  cleanVueFileName: true,
169
- include: `${path.resolve(options.entry, "..")}**`,
176
+ copyDtsFiles: true,
177
+ include: `${path__default.resolve(options.entry, "..")}**`,
170
178
  outputDir: "dist/types",
171
179
  staticImport: true
172
180
  })
@@ -187,14 +195,15 @@ function transformExistingAlias(alias) {
187
195
  async function readConfig(configPath) {
188
196
  try {
189
197
  const configFileText = await promises.readFile(configPath, { encoding: "utf-8" });
190
- const { config } = typescript.parseConfigFileTextToJson(configPath, configFileText);
198
+ const { config } = ts__default.parseConfigFileTextToJson(configPath, configFileText);
191
199
  if (!("baseUrl" in config?.compilerOptions)) {
192
200
  throw new Error("No baseUrl provided in tsconfig.json.");
193
201
  }
194
- const { options } = typescript.parseJsonConfigFileContent(
202
+ const { options } = ts__default.parseJsonConfigFileContent(
195
203
  config,
196
- typescript.sys,
197
- path.dirname(configPath)
204
+ // eslint-disable-next-line import/no-named-as-default-member
205
+ ts__default.sys,
206
+ path__default.dirname(configPath)
198
207
  );
199
208
  return options;
200
209
  } catch (error) {
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ interface Options {
9
9
  externalPackages?: (string | RegExp)[];
10
10
  verbose?: boolean;
11
11
  }
12
- declare const tsconfigPaths: ({ verbose }?: Partial<Options>) => Plugin;
12
+ declare function tsconfigPaths({ verbose }?: Partial<Options>): Plugin;
13
13
  declare function library(options: Options): Plugin[];
14
14
 
15
15
  export { Options, library, tsconfigPaths };
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import { existsSync } from 'fs';
2
- import { readFile } from 'fs/promises';
3
- import { builtinModules } from 'module';
4
- import path from 'path';
1
+ import { existsSync } from 'node:fs';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { builtinModules } from 'node:module';
4
+ import path from 'node:path';
5
5
  import c from 'picocolors';
6
- import { parseConfigFileTextToJson, parseJsonConfigFileContent, sys } from 'typescript';
6
+ import ts from 'typescript';
7
7
  import dts__default from 'vite-plugin-dts';
8
8
  import * as dts from 'vite-plugin-dts';
9
9
  export { dts };
@@ -17,7 +17,7 @@ function logWarn(text) {
17
17
  function logError(text) {
18
18
  console.error(`${c.red("[vite:lib]")} ${text}`);
19
19
  }
20
- const tsconfigPaths = ({ verbose } = {}) => {
20
+ function tsconfigPaths({ verbose } = {}) {
21
21
  return {
22
22
  name: "vite-plugin-lib:alias",
23
23
  enforce: "pre",
@@ -43,13 +43,13 @@ const tsconfigPaths = ({ verbose } = {}) => {
43
43
  };
44
44
  }
45
45
  };
46
- };
47
- const buildConfig = ({
46
+ }
47
+ function buildConfig({
48
48
  entry,
49
49
  formats,
50
50
  name,
51
51
  externalPackages
52
- }) => {
52
+ }) {
53
53
  if (!externalPackages) {
54
54
  log("Externalized all packages.");
55
55
  }
@@ -75,7 +75,7 @@ const buildConfig = ({
75
75
  };
76
76
  }
77
77
  };
78
- };
78
+ }
79
79
  function logInjectedAliases(aliasOptions, config, verbose) {
80
80
  log(`Injected ${c.green(aliasOptions.length)} aliases.`);
81
81
  if (!verbose) {
@@ -153,6 +153,7 @@ function library(options) {
153
153
  buildConfig(options),
154
154
  dts__default({
155
155
  cleanVueFileName: true,
156
+ copyDtsFiles: true,
156
157
  include: `${path.resolve(options.entry, "..")}**`,
157
158
  outputDir: "dist/types",
158
159
  staticImport: true
@@ -174,13 +175,14 @@ function transformExistingAlias(alias) {
174
175
  async function readConfig(configPath) {
175
176
  try {
176
177
  const configFileText = await readFile(configPath, { encoding: "utf-8" });
177
- const { config } = parseConfigFileTextToJson(configPath, configFileText);
178
+ const { config } = ts.parseConfigFileTextToJson(configPath, configFileText);
178
179
  if (!("baseUrl" in config?.compilerOptions)) {
179
180
  throw new Error("No baseUrl provided in tsconfig.json.");
180
181
  }
181
- const { options } = parseJsonConfigFileContent(
182
+ const { options } = ts.parseJsonConfigFileContent(
182
183
  config,
183
- sys,
184
+ // eslint-disable-next-line import/no-named-as-default-member
185
+ ts.sys,
184
186
  path.dirname(configPath)
185
187
  );
186
188
  return options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-lib",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
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",
@@ -36,15 +36,14 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "picocolors": "1.0.0",
39
- "vite-plugin-dts": "1.7.1"
39
+ "vite-plugin-dts": "2.2.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@types/node": "18.11.13",
43
- "@vitest/ui": "0.26.3",
44
- "typescript": "4.9.4",
45
- "unbuild": "1.0.2",
46
- "vite": "4.0.0",
47
- "@yeger/tsconfig": "1.1.1"
42
+ "@types/node": "18.15.11",
43
+ "typescript": "5.0.4",
44
+ "unbuild": "1.2.0",
45
+ "vite": "4.2.1",
46
+ "@yeger/tsconfig": "1.1.2"
48
47
  },
49
48
  "publishConfig": {
50
49
  "access": "public"