uniky 1.0.16 → 1.0.18
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/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// 该插件用于作为 vite.config.ts 中 作为插件;
|
|
2
|
-
// 该插件用于收集 src/
|
|
2
|
+
// 该插件用于收集 src/_unikey/global文件夹下的ts文件 所有export 导出的内容, 并将其合并为一个全局定义文件 src/_unikey/global.d.ts 文件 同时,生成一个 /src/_unikey/global.install.ts 文件.
|
|
3
3
|
// 以便在项目中全局使用这些类型定义,避免了手动维护全局类型定义文件的麻烦。
|
|
4
4
|
|
|
5
5
|
import type { Plugin } from 'vite';
|
|
@@ -14,9 +14,9 @@ interface ExportInfo {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export default function globalDefinedPlugin(): Plugin {
|
|
17
|
-
const globalDir = 'src/
|
|
18
|
-
const globalDtsPath = 'src/
|
|
19
|
-
const installTsPath = 'src/
|
|
17
|
+
const globalDir = 'src/_unikey/global';
|
|
18
|
+
const globalDtsPath = 'src/_unikey/global.d.ts';
|
|
19
|
+
const installTsPath = 'src/_unikey/global.install.ts';
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* 递归获取目录下所有 .ts 文件(排除 .d.ts 和 install.ts)
|
|
@@ -158,7 +158,7 @@ export default function globalDefinedPlugin(): Plugin {
|
|
|
158
158
|
|
|
159
159
|
// 按文件分组导出
|
|
160
160
|
for (const exp of allExports) {
|
|
161
|
-
const relativePath = path.relative('src/
|
|
161
|
+
const relativePath = path.relative('src/_unikey', exp.filePath).replace(/\\/g, '/').replace(/\.ts$/, '');
|
|
162
162
|
if (!imports.has(relativePath)) {
|
|
163
163
|
imports.set(relativePath, new Set());
|
|
164
164
|
}
|
|
@@ -187,11 +187,11 @@ export default function globalDefinedPlugin(): Plugin {
|
|
|
187
187
|
if (globalItems.length > 0) {
|
|
188
188
|
for (const exp of globalItems) {
|
|
189
189
|
if (exp.type === 'function') {
|
|
190
|
-
content += ` const ${exp.name}: typeof import('./${path.relative('src/
|
|
190
|
+
content += ` const ${exp.name}: typeof import('./${path.relative('src/_unikey', exp.filePath).replace(/\\/g, '/').replace(/\.ts$/, '')}').${exp.name};\n`;
|
|
191
191
|
} else if (exp.type === 'const') {
|
|
192
|
-
content += ` const ${exp.name}: typeof import('./${path.relative('src/
|
|
192
|
+
content += ` const ${exp.name}: typeof import('./${path.relative('src/_unikey', exp.filePath).replace(/\\/g, '/').replace(/\.ts$/, '')}').${exp.name};\n`;
|
|
193
193
|
} else if (exp.type === 'class') {
|
|
194
|
-
content += ` const ${exp.name}: typeof import('./${path.relative('src/
|
|
194
|
+
content += ` const ${exp.name}: typeof import('./${path.relative('src/_unikey', exp.filePath).replace(/\\/g, '/').replace(/\.ts$/, '')}').${exp.name};\n`;
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
}
|
|
@@ -210,7 +210,7 @@ export default function globalDefinedPlugin(): Plugin {
|
|
|
210
210
|
|
|
211
211
|
// 按文件分组导出
|
|
212
212
|
for (const exp of allExports) {
|
|
213
|
-
const relativePath = './global/' + path.relative(path.join('src', '
|
|
213
|
+
const relativePath = './global/' + path.relative(path.join('src', '_unikey', 'global'), exp.filePath).replace(/\\/g, '/').replace(/\.ts$/, '');
|
|
214
214
|
if (!imports.has(relativePath)) {
|
|
215
215
|
imports.set(relativePath, { names: new Set(), hasDefault: false });
|
|
216
216
|
}
|
|
@@ -247,7 +247,7 @@ export default function globalDefinedPlugin(): Plugin {
|
|
|
247
247
|
// 将导出的内容挂载到 globalThis
|
|
248
248
|
const globalItems = allExports.filter(exp => exp.type !== 'interface' && exp.type !== 'type');
|
|
249
249
|
for (const exp of globalItems) {
|
|
250
|
-
const name = exp.isDefault ? (imports.get('./global/' + path.relative(path.join('src', '
|
|
250
|
+
const name = exp.isDefault ? (imports.get('./global/' + path.relative(path.join('src', '_unikey', 'global'), exp.filePath).replace(/\\/g, '/').replace(/\.ts$/, ''))?.defaultName || exp.name) : exp.name;
|
|
251
251
|
content += ` (globalThis as any).${exp.name} = ${name};\n`;
|
|
252
252
|
}
|
|
253
253
|
|
|
@@ -305,25 +305,25 @@ export default function globalDefinedPlugin(): Plugin {
|
|
|
305
305
|
},
|
|
306
306
|
|
|
307
307
|
configureServer(server) {
|
|
308
|
-
// 监听 src/
|
|
308
|
+
// 监听 src/_unikey/global 目录下的文件变化
|
|
309
309
|
server.watcher.add(globalDir);
|
|
310
310
|
|
|
311
311
|
server.watcher.on('change', (file) => {
|
|
312
|
-
if (file.includes('src/
|
|
312
|
+
if (file.includes('src/_unikey/global') && file.endsWith('.ts') && !file.endsWith('.d.ts') && !file.includes('global.install.ts')) {
|
|
313
313
|
console.log(`[globalDefined] 检测到文件变化: ${file}`);
|
|
314
314
|
generate();
|
|
315
315
|
}
|
|
316
316
|
});
|
|
317
317
|
|
|
318
318
|
server.watcher.on('add', (file) => {
|
|
319
|
-
if (file.includes('src/
|
|
319
|
+
if (file.includes('src/_unikey/global') && file.endsWith('.ts') && !file.endsWith('.d.ts') && !file.includes('global.install.ts')) {
|
|
320
320
|
console.log(`[globalDefined] 检测到新文件: ${file}`);
|
|
321
321
|
generate();
|
|
322
322
|
}
|
|
323
323
|
});
|
|
324
324
|
|
|
325
325
|
server.watcher.on('unlink', (file) => {
|
|
326
|
-
if (file.includes('src/
|
|
326
|
+
if (file.includes('src/_unikey/global') && file.endsWith('.ts') && !file.endsWith('.d.ts') && !file.includes('global.install.ts')) {
|
|
327
327
|
console.log(`[globalDefined] 检测到文件删除: ${file}`);
|
|
328
328
|
generate();
|
|
329
329
|
}
|
|
@@ -248,7 +248,7 @@ export default function pagesDefinedPlugin(): Plugin {
|
|
|
248
248
|
configResolved(config) {
|
|
249
249
|
// 确定 src 目录和输出路径
|
|
250
250
|
srcDir = path.resolve(config.root, 'src');
|
|
251
|
-
outputPath = path.resolve(srcDir, '
|
|
251
|
+
outputPath = path.resolve(srcDir, '_unikey/global/pages.ts');
|
|
252
252
|
},
|
|
253
253
|
|
|
254
254
|
buildStart() {
|