vite-plugin-lib 1.0.0 → 1.1.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 CHANGED
@@ -23,7 +23,10 @@ const dts__namespace = /*#__PURE__*/_interopNamespaceDefault(dts);
23
23
  function log(text) {
24
24
  console.log(`${c.cyan("[vite:lib]")} ${text}`);
25
25
  }
26
- const tsconfigPaths = ({ verbose } = {}) => {
26
+ function logError(text) {
27
+ console.error(`${c.red("[vite:lib]")} ${text}`);
28
+ }
29
+ const tsconfigPaths = () => {
27
30
  return {
28
31
  name: "vite-plugin-lib:alias",
29
32
  enforce: "pre",
@@ -45,15 +48,12 @@ const tsconfigPaths = ({ verbose } = {}) => {
45
48
  );
46
49
  if (aliasOptions.length > 0) {
47
50
  log(`Injected ${c.green(aliasOptions.length)} aliases.`);
48
- }
49
- if (verbose) {
50
- aliasOptions.forEach(
51
- (alias) => log(
52
- `Alias ${c.green(alias.find.toString())} -> ${c.green(
53
- alias.replacement
54
- )} configured`
55
- )
56
- );
51
+ const base = `${path.resolve(config.root ?? ".")}/`;
52
+ aliasOptions.map(
53
+ ({ find, replacement }) => `${c.gray(">")} ${c.green(find.toString())} ${c.gray(
54
+ c.bold("->")
55
+ )} ${c.green(replacement.replace(base, ""))}`
56
+ ).forEach(log);
57
57
  }
58
58
  const existingAlias = transformExistingAlias(config.resolve?.alias);
59
59
  return {
@@ -73,7 +73,7 @@ const buildConfig = ({
73
73
  externalPackages
74
74
  }) => {
75
75
  if (!externalPackages) {
76
- log("Externalizing all packages.");
76
+ log("Externalized all packages.");
77
77
  }
78
78
  return {
79
79
  name: "vite-plugin-lib:build",
@@ -113,7 +113,7 @@ function formatToFileName(entry, format) {
113
113
  }
114
114
  function library(options) {
115
115
  return [
116
- tsconfigPaths(options),
116
+ tsconfigPaths(),
117
117
  buildConfig(options),
118
118
  dts({
119
119
  cleanVueFileName: true,
@@ -136,14 +136,23 @@ function transformExistingAlias(alias) {
136
136
  }));
137
137
  }
138
138
  async function readConfig(configPath) {
139
- const configFileText = await promises.readFile(configPath, { encoding: "utf-8" });
140
- const { config } = typescript.parseConfigFileTextToJson(configPath, configFileText);
141
- const { options } = typescript.parseJsonConfigFileContent(
142
- config,
143
- typescript.sys,
144
- path.dirname(configPath)
145
- );
146
- return options;
139
+ try {
140
+ const configFileText = await promises.readFile(configPath, { encoding: "utf-8" });
141
+ const { config } = typescript.parseConfigFileTextToJson(configPath, configFileText);
142
+ if (!("baseUrl" in config?.compilerOptions)) {
143
+ throw new Error("No baseUrl provided in tsconfig.json.");
144
+ }
145
+ const { options } = typescript.parseJsonConfigFileContent(
146
+ config,
147
+ typescript.sys,
148
+ path.dirname(configPath)
149
+ );
150
+ return options;
151
+ } catch (error) {
152
+ const message = "message" in error ? error.message : error;
153
+ logError(`Could not read tsconfig.json: ${message}`);
154
+ throw error;
155
+ }
147
156
  }
148
157
 
149
158
  exports.dts = dts__namespace;
package/dist/index.d.ts CHANGED
@@ -7,9 +7,8 @@ interface Options {
7
7
  entry: string;
8
8
  formats?: LibraryFormats[];
9
9
  externalPackages?: (string | RegExp)[];
10
- verbose?: boolean;
11
10
  }
12
- declare const tsconfigPaths: ({ verbose }?: Partial<Options>) => Plugin;
11
+ declare const tsconfigPaths: () => Plugin;
13
12
  declare function library(options: Options): Plugin[];
14
13
 
15
14
  export { Options, library, tsconfigPaths };
package/dist/index.mjs CHANGED
@@ -10,7 +10,10 @@ export { dts };
10
10
  function log(text) {
11
11
  console.log(`${c.cyan("[vite:lib]")} ${text}`);
12
12
  }
13
- const tsconfigPaths = ({ verbose } = {}) => {
13
+ function logError(text) {
14
+ console.error(`${c.red("[vite:lib]")} ${text}`);
15
+ }
16
+ const tsconfigPaths = () => {
14
17
  return {
15
18
  name: "vite-plugin-lib:alias",
16
19
  enforce: "pre",
@@ -32,15 +35,12 @@ const tsconfigPaths = ({ verbose } = {}) => {
32
35
  );
33
36
  if (aliasOptions.length > 0) {
34
37
  log(`Injected ${c.green(aliasOptions.length)} aliases.`);
35
- }
36
- if (verbose) {
37
- aliasOptions.forEach(
38
- (alias) => log(
39
- `Alias ${c.green(alias.find.toString())} -> ${c.green(
40
- alias.replacement
41
- )} configured`
42
- )
43
- );
38
+ const base = `${path.resolve(config.root ?? ".")}/`;
39
+ aliasOptions.map(
40
+ ({ find, replacement }) => `${c.gray(">")} ${c.green(find.toString())} ${c.gray(
41
+ c.bold("->")
42
+ )} ${c.green(replacement.replace(base, ""))}`
43
+ ).forEach(log);
44
44
  }
45
45
  const existingAlias = transformExistingAlias(config.resolve?.alias);
46
46
  return {
@@ -60,7 +60,7 @@ const buildConfig = ({
60
60
  externalPackages
61
61
  }) => {
62
62
  if (!externalPackages) {
63
- log("Externalizing all packages.");
63
+ log("Externalized all packages.");
64
64
  }
65
65
  return {
66
66
  name: "vite-plugin-lib:build",
@@ -100,7 +100,7 @@ function formatToFileName(entry, format) {
100
100
  }
101
101
  function library(options) {
102
102
  return [
103
- tsconfigPaths(options),
103
+ tsconfigPaths(),
104
104
  buildConfig(options),
105
105
  dts__default({
106
106
  cleanVueFileName: true,
@@ -123,14 +123,23 @@ function transformExistingAlias(alias) {
123
123
  }));
124
124
  }
125
125
  async function readConfig(configPath) {
126
- const configFileText = await readFile(configPath, { encoding: "utf-8" });
127
- const { config } = parseConfigFileTextToJson(configPath, configFileText);
128
- const { options } = parseJsonConfigFileContent(
129
- config,
130
- sys,
131
- path.dirname(configPath)
132
- );
133
- return options;
126
+ try {
127
+ const configFileText = await readFile(configPath, { encoding: "utf-8" });
128
+ const { config } = parseConfigFileTextToJson(configPath, configFileText);
129
+ if (!("baseUrl" in config?.compilerOptions)) {
130
+ throw new Error("No baseUrl provided in tsconfig.json.");
131
+ }
132
+ const { options } = parseJsonConfigFileContent(
133
+ config,
134
+ sys,
135
+ path.dirname(configPath)
136
+ );
137
+ return options;
138
+ } catch (error) {
139
+ const message = "message" in error ? error.message : error;
140
+ logError(`Could not read tsconfig.json: ${message}`);
141
+ throw error;
142
+ }
134
143
  }
135
144
 
136
145
  export { library, tsconfigPaths };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-lib",
3
- "version": "1.0.0",
3
+ "version": "1.1.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",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "18.11.13",
43
- "@vitest/ui": "0.26.2",
43
+ "@vitest/ui": "0.26.3",
44
44
  "typescript": "4.9.4",
45
45
  "unbuild": "1.0.2",
46
46
  "vite": "4.0.0",