vite-plugin-lib 1.0.1 → 1.1.1
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 +24 -20
- package/dist/index.d.ts +1 -2
- package/dist/index.mjs +24 -20
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -26,7 +26,7 @@ function log(text) {
|
|
|
26
26
|
function logError(text) {
|
|
27
27
|
console.error(`${c.red("[vite:lib]")} ${text}`);
|
|
28
28
|
}
|
|
29
|
-
const tsconfigPaths = (
|
|
29
|
+
const tsconfigPaths = () => {
|
|
30
30
|
return {
|
|
31
31
|
name: "vite-plugin-lib:alias",
|
|
32
32
|
enforce: "pre",
|
|
@@ -37,26 +37,27 @@ const tsconfigPaths = ({ verbose } = {}) => {
|
|
|
37
37
|
return config;
|
|
38
38
|
}
|
|
39
39
|
const aliasOptions = Object.entries(paths).map(
|
|
40
|
-
([alias,
|
|
41
|
-
find
|
|
42
|
-
replacement
|
|
40
|
+
([alias, replacements]) => {
|
|
41
|
+
const find = alias.replace("/*", "");
|
|
42
|
+
const replacement = path.resolve(
|
|
43
43
|
tsconfigPath,
|
|
44
44
|
baseUrl,
|
|
45
|
-
|
|
46
|
-
)
|
|
47
|
-
|
|
45
|
+
replacements[0]?.replace("/*", "") ?? find
|
|
46
|
+
);
|
|
47
|
+
return {
|
|
48
|
+
find,
|
|
49
|
+
replacement
|
|
50
|
+
};
|
|
51
|
+
}
|
|
48
52
|
);
|
|
49
53
|
if (aliasOptions.length > 0) {
|
|
50
54
|
log(`Injected ${c.green(aliasOptions.length)} aliases.`);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
)} configured`
|
|
58
|
-
)
|
|
59
|
-
);
|
|
55
|
+
const base = `${path.resolve(config.root ?? ".")}/`;
|
|
56
|
+
aliasOptions.map(
|
|
57
|
+
({ find, replacement }) => `${c.gray(">")} ${c.green(find.toString())} ${c.gray(
|
|
58
|
+
c.bold("->")
|
|
59
|
+
)} ${c.green(replacement.replace(base, ""))}`
|
|
60
|
+
).forEach(log);
|
|
60
61
|
}
|
|
61
62
|
const existingAlias = transformExistingAlias(config.resolve?.alias);
|
|
62
63
|
return {
|
|
@@ -76,7 +77,7 @@ const buildConfig = ({
|
|
|
76
77
|
externalPackages
|
|
77
78
|
}) => {
|
|
78
79
|
if (!externalPackages) {
|
|
79
|
-
log("
|
|
80
|
+
log("Externalized all packages.");
|
|
80
81
|
}
|
|
81
82
|
return {
|
|
82
83
|
name: "vite-plugin-lib:build",
|
|
@@ -116,7 +117,7 @@ function formatToFileName(entry, format) {
|
|
|
116
117
|
}
|
|
117
118
|
function library(options) {
|
|
118
119
|
return [
|
|
119
|
-
tsconfigPaths(
|
|
120
|
+
tsconfigPaths(),
|
|
120
121
|
buildConfig(options),
|
|
121
122
|
dts({
|
|
122
123
|
cleanVueFileName: true,
|
|
@@ -142,6 +143,9 @@ async function readConfig(configPath) {
|
|
|
142
143
|
try {
|
|
143
144
|
const configFileText = await promises.readFile(configPath, { encoding: "utf-8" });
|
|
144
145
|
const { config } = typescript.parseConfigFileTextToJson(configPath, configFileText);
|
|
146
|
+
if (!("baseUrl" in config?.compilerOptions)) {
|
|
147
|
+
throw new Error("No baseUrl provided in tsconfig.json.");
|
|
148
|
+
}
|
|
145
149
|
const { options } = typescript.parseJsonConfigFileContent(
|
|
146
150
|
config,
|
|
147
151
|
typescript.sys,
|
|
@@ -150,8 +154,8 @@ async function readConfig(configPath) {
|
|
|
150
154
|
return options;
|
|
151
155
|
} catch (error) {
|
|
152
156
|
const message = "message" in error ? error.message : error;
|
|
153
|
-
logError(`Could not read tsconfig.json: ${message}
|
|
154
|
-
|
|
157
|
+
logError(`Could not read tsconfig.json: ${message}`);
|
|
158
|
+
throw error;
|
|
155
159
|
}
|
|
156
160
|
}
|
|
157
161
|
|
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: (
|
|
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
|
@@ -13,7 +13,7 @@ function log(text) {
|
|
|
13
13
|
function logError(text) {
|
|
14
14
|
console.error(`${c.red("[vite:lib]")} ${text}`);
|
|
15
15
|
}
|
|
16
|
-
const tsconfigPaths = (
|
|
16
|
+
const tsconfigPaths = () => {
|
|
17
17
|
return {
|
|
18
18
|
name: "vite-plugin-lib:alias",
|
|
19
19
|
enforce: "pre",
|
|
@@ -24,26 +24,27 @@ const tsconfigPaths = ({ verbose } = {}) => {
|
|
|
24
24
|
return config;
|
|
25
25
|
}
|
|
26
26
|
const aliasOptions = Object.entries(paths).map(
|
|
27
|
-
([alias,
|
|
28
|
-
find
|
|
29
|
-
replacement
|
|
27
|
+
([alias, replacements]) => {
|
|
28
|
+
const find = alias.replace("/*", "");
|
|
29
|
+
const replacement = path.resolve(
|
|
30
30
|
tsconfigPath,
|
|
31
31
|
baseUrl,
|
|
32
|
-
|
|
33
|
-
)
|
|
34
|
-
|
|
32
|
+
replacements[0]?.replace("/*", "") ?? find
|
|
33
|
+
);
|
|
34
|
+
return {
|
|
35
|
+
find,
|
|
36
|
+
replacement
|
|
37
|
+
};
|
|
38
|
+
}
|
|
35
39
|
);
|
|
36
40
|
if (aliasOptions.length > 0) {
|
|
37
41
|
log(`Injected ${c.green(aliasOptions.length)} aliases.`);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
)} configured`
|
|
45
|
-
)
|
|
46
|
-
);
|
|
42
|
+
const base = `${path.resolve(config.root ?? ".")}/`;
|
|
43
|
+
aliasOptions.map(
|
|
44
|
+
({ find, replacement }) => `${c.gray(">")} ${c.green(find.toString())} ${c.gray(
|
|
45
|
+
c.bold("->")
|
|
46
|
+
)} ${c.green(replacement.replace(base, ""))}`
|
|
47
|
+
).forEach(log);
|
|
47
48
|
}
|
|
48
49
|
const existingAlias = transformExistingAlias(config.resolve?.alias);
|
|
49
50
|
return {
|
|
@@ -63,7 +64,7 @@ const buildConfig = ({
|
|
|
63
64
|
externalPackages
|
|
64
65
|
}) => {
|
|
65
66
|
if (!externalPackages) {
|
|
66
|
-
log("
|
|
67
|
+
log("Externalized all packages.");
|
|
67
68
|
}
|
|
68
69
|
return {
|
|
69
70
|
name: "vite-plugin-lib:build",
|
|
@@ -103,7 +104,7 @@ function formatToFileName(entry, format) {
|
|
|
103
104
|
}
|
|
104
105
|
function library(options) {
|
|
105
106
|
return [
|
|
106
|
-
tsconfigPaths(
|
|
107
|
+
tsconfigPaths(),
|
|
107
108
|
buildConfig(options),
|
|
108
109
|
dts__default({
|
|
109
110
|
cleanVueFileName: true,
|
|
@@ -129,6 +130,9 @@ async function readConfig(configPath) {
|
|
|
129
130
|
try {
|
|
130
131
|
const configFileText = await readFile(configPath, { encoding: "utf-8" });
|
|
131
132
|
const { config } = parseConfigFileTextToJson(configPath, configFileText);
|
|
133
|
+
if (!("baseUrl" in config?.compilerOptions)) {
|
|
134
|
+
throw new Error("No baseUrl provided in tsconfig.json.");
|
|
135
|
+
}
|
|
132
136
|
const { options } = parseJsonConfigFileContent(
|
|
133
137
|
config,
|
|
134
138
|
sys,
|
|
@@ -137,8 +141,8 @@ async function readConfig(configPath) {
|
|
|
137
141
|
return options;
|
|
138
142
|
} catch (error) {
|
|
139
143
|
const message = "message" in error ? error.message : error;
|
|
140
|
-
logError(`Could not read tsconfig.json: ${message}
|
|
141
|
-
|
|
144
|
+
logError(`Could not read tsconfig.json: ${message}`);
|
|
145
|
+
throw error;
|
|
142
146
|
}
|
|
143
147
|
}
|
|
144
148
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-lib",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
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,11 +40,11 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "18.11.13",
|
|
43
|
-
"@vitest/ui": "0.26.
|
|
43
|
+
"@vitest/ui": "0.26.3",
|
|
44
44
|
"typescript": "4.9.4",
|
|
45
45
|
"unbuild": "1.0.2",
|
|
46
46
|
"vite": "4.0.0",
|
|
47
|
-
"@yeger/tsconfig": "1.1.
|
|
47
|
+
"@yeger/tsconfig": "1.1.1"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|