vite-plugin-lib 1.2.1 → 1.2.3
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 +44 -36
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +16 -15
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const promises = require('fs/promises');
|
|
5
|
-
const
|
|
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
|
|
8
|
+
const ts = require('typescript');
|
|
9
9
|
const dts = require('vite-plugin-dts');
|
|
10
10
|
|
|
11
|
-
function
|
|
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
|
|
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(`${
|
|
32
|
+
console.log(`${c__default.cyan("[vite:lib]")} ${text}`);
|
|
26
33
|
}
|
|
27
34
|
function logWarn(text) {
|
|
28
|
-
console.warn(`${
|
|
35
|
+
console.warn(`${c__default.yellow("[vite:lib]")} ${text}`);
|
|
29
36
|
}
|
|
30
37
|
function logError(text) {
|
|
31
|
-
console.error(`${
|
|
38
|
+
console.error(`${c__default.red("[vite:lib]")} ${text}`);
|
|
32
39
|
}
|
|
33
|
-
|
|
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 =
|
|
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
|
-
|
|
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:
|
|
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/, ...
|
|
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 ${
|
|
100
|
+
log(`Injected ${c__default.green(aliasOptions.length)} aliases.`);
|
|
94
101
|
if (!verbose) {
|
|
95
102
|
return;
|
|
96
103
|
}
|
|
97
|
-
const base = `${
|
|
104
|
+
const base = `${path__default.resolve(config.root ?? ".")}/`;
|
|
98
105
|
aliasOptions.map(
|
|
99
|
-
({ find, replacement }) => `${
|
|
100
|
-
|
|
101
|
-
)} ${
|
|
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 ${
|
|
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 ${
|
|
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 ${
|
|
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 =
|
|
144
|
+
const resolvedReplacement = path__default.resolve(
|
|
138
145
|
tsconfigPath,
|
|
139
146
|
baseUrl,
|
|
140
147
|
replacement.replace("/*", "") ?? find
|
|
141
148
|
);
|
|
142
|
-
if (
|
|
149
|
+
if (node_fs.existsSync(resolvedReplacement)) {
|
|
143
150
|
return resolvedReplacement;
|
|
144
151
|
} else if (verbose) {
|
|
145
|
-
logWarn(`Path ${
|
|
152
|
+
logWarn(`Path ${c__default.green(replacement)} does not exist.`);
|
|
146
153
|
}
|
|
147
154
|
}
|
|
148
155
|
return void 0;
|
|
@@ -164,11 +171,11 @@ function library(options) {
|
|
|
164
171
|
return [
|
|
165
172
|
tsconfigPaths(),
|
|
166
173
|
buildConfig(options),
|
|
167
|
-
|
|
174
|
+
dts__default({
|
|
168
175
|
cleanVueFileName: true,
|
|
169
176
|
copyDtsFiles: true,
|
|
170
|
-
include: `${
|
|
171
|
-
|
|
177
|
+
include: `${path__default.resolve(options.entry, "..")}/**`,
|
|
178
|
+
outDir: "dist/types",
|
|
172
179
|
staticImport: true
|
|
173
180
|
})
|
|
174
181
|
];
|
|
@@ -188,14 +195,15 @@ function transformExistingAlias(alias) {
|
|
|
188
195
|
async function readConfig(configPath) {
|
|
189
196
|
try {
|
|
190
197
|
const configFileText = await promises.readFile(configPath, { encoding: "utf-8" });
|
|
191
|
-
const { config } =
|
|
198
|
+
const { config } = ts__default.parseConfigFileTextToJson(configPath, configFileText);
|
|
192
199
|
if (!("baseUrl" in config?.compilerOptions)) {
|
|
193
200
|
throw new Error("No baseUrl provided in tsconfig.json.");
|
|
194
201
|
}
|
|
195
|
-
const { options } =
|
|
202
|
+
const { options } = ts__default.parseJsonConfigFileContent(
|
|
196
203
|
config,
|
|
197
|
-
|
|
198
|
-
|
|
204
|
+
// eslint-disable-next-line import/no-named-as-default-member
|
|
205
|
+
ts__default.sys,
|
|
206
|
+
path__default.dirname(configPath)
|
|
199
207
|
);
|
|
200
208
|
return options;
|
|
201
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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) {
|
|
@@ -154,8 +154,8 @@ function library(options) {
|
|
|
154
154
|
dts__default({
|
|
155
155
|
cleanVueFileName: true,
|
|
156
156
|
copyDtsFiles: true,
|
|
157
|
-
include: `${path.resolve(options.entry, "..")}
|
|
158
|
-
|
|
157
|
+
include: `${path.resolve(options.entry, "..")}/**`,
|
|
158
|
+
outDir: "dist/types",
|
|
159
159
|
staticImport: true
|
|
160
160
|
})
|
|
161
161
|
];
|
|
@@ -175,13 +175,14 @@ function transformExistingAlias(alias) {
|
|
|
175
175
|
async function readConfig(configPath) {
|
|
176
176
|
try {
|
|
177
177
|
const configFileText = await readFile(configPath, { encoding: "utf-8" });
|
|
178
|
-
const { config } = parseConfigFileTextToJson(configPath, configFileText);
|
|
178
|
+
const { config } = ts.parseConfigFileTextToJson(configPath, configFileText);
|
|
179
179
|
if (!("baseUrl" in config?.compilerOptions)) {
|
|
180
180
|
throw new Error("No baseUrl provided in tsconfig.json.");
|
|
181
181
|
}
|
|
182
|
-
const { options } = parseJsonConfigFileContent(
|
|
182
|
+
const { options } = ts.parseJsonConfigFileContent(
|
|
183
183
|
config,
|
|
184
|
-
|
|
184
|
+
// eslint-disable-next-line import/no-named-as-default-member
|
|
185
|
+
ts.sys,
|
|
185
186
|
path.dirname(configPath)
|
|
186
187
|
);
|
|
187
188
|
return options;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-lib",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
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,14 +36,13 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"picocolors": "1.0.0",
|
|
39
|
-
"vite-plugin-dts": "
|
|
39
|
+
"vite-plugin-dts": "3.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/node": "18.
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"vite": "4.1.4",
|
|
42
|
+
"@types/node": "18.16.18",
|
|
43
|
+
"typescript": "5.1.3",
|
|
44
|
+
"unbuild": "1.2.1",
|
|
45
|
+
"vite": "4.3.9",
|
|
47
46
|
"@yeger/tsconfig": "1.1.2"
|
|
48
47
|
},
|
|
49
48
|
"publishConfig": {
|
|
@@ -51,7 +50,8 @@
|
|
|
51
50
|
},
|
|
52
51
|
"scripts": {
|
|
53
52
|
"build": "unbuild",
|
|
54
|
-
"
|
|
55
|
-
"check:tsc": "tsc --noEmit"
|
|
53
|
+
"check:publish": "publint run --strict",
|
|
54
|
+
"check:tsc": "tsc --noEmit",
|
|
55
|
+
"lint": "yeger-lint"
|
|
56
56
|
}
|
|
57
57
|
}
|