knip 6.25.0 → 6.26.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/ConfigurationChief.d.ts +102 -0
- package/dist/compilers/index.d.ts +170 -0
- package/dist/constants.js +13 -0
- package/dist/graph/build.js +8 -3
- package/dist/plugins/_vue/auto-import.d.ts +12 -0
- package/dist/plugins/_vue/auto-import.js +272 -0
- package/dist/plugins/_vue/types.d.ts +38 -0
- package/dist/plugins/_vue/types.js +1 -0
- package/dist/plugins/astro/index.js +2 -37
- package/dist/plugins/astro/resolveFromAST.d.ts +4 -4
- package/dist/plugins/astro/resolveFromAST.js +34 -7
- package/dist/plugins/electron-vite/index.d.ts +3 -0
- package/dist/plugins/electron-vite/index.js +51 -0
- package/dist/plugins/electron-vite/types.d.ts +23 -0
- package/dist/plugins/electron-vite/types.js +1 -0
- package/dist/plugins/esbuild/index.d.ts +3 -0
- package/dist/plugins/esbuild/index.js +17 -0
- package/dist/plugins/eslint/resolveFromAST.js +18 -21
- package/dist/plugins/index.d.ts +17 -0
- package/dist/plugins/index.js +34 -0
- package/dist/plugins/laravel-vite-plugin/index.d.ts +3 -0
- package/dist/plugins/laravel-vite-plugin/index.js +14 -0
- package/dist/plugins/laravel-vite-plugin/resolveFromAST.d.ts +2 -0
- package/dist/plugins/laravel-vite-plugin/resolveFromAST.js +27 -0
- package/dist/plugins/next/index.js +2 -2
- package/dist/plugins/next-mdx/index.js +2 -8
- package/dist/plugins/next-mdx/resolveFromAST.d.ts +3 -2
- package/dist/plugins/next-mdx/resolveFromAST.js +17 -21
- package/dist/plugins/nuxt/index.js +5 -68
- package/dist/plugins/nuxt/types.d.ts +0 -34
- package/dist/plugins/nuxtjs-i18n/index.d.ts +3 -0
- package/dist/plugins/nuxtjs-i18n/index.js +12 -0
- package/dist/plugins/oclif/index.js +10 -5
- package/dist/plugins/orval/index.js +1 -3
- package/dist/plugins/orval/resolveFromAST.d.ts +2 -2
- package/dist/plugins/orval/resolveFromAST.js +4 -7
- package/dist/plugins/oxlint/index.js +23 -2
- package/dist/plugins/pnpm/index.js +2 -1
- package/dist/plugins/pnpm/types.d.ts +2 -4
- package/dist/plugins/quasar/index.d.ts +3 -0
- package/dist/plugins/quasar/index.js +15 -0
- package/dist/plugins/quasar/resolveFromAST.d.ts +3 -0
- package/dist/plugins/quasar/resolveFromAST.js +63 -0
- package/dist/plugins/qwik/index.js +1 -25
- package/dist/plugins/qwik/resolveFromAST.d.ts +5 -3
- package/dist/plugins/qwik/resolveFromAST.js +28 -9
- package/dist/plugins/rolldown/index.js +2 -5
- package/dist/plugins/rollup/index.js +2 -5
- package/dist/plugins/rslib/index.js +2 -5
- package/dist/plugins/sst/index.js +1 -5
- package/dist/plugins/sst/resolveFromAST.d.ts +1 -1
- package/dist/plugins/sst/resolveFromAST.js +1 -1
- package/dist/plugins/starlight/index.js +1 -19
- package/dist/plugins/starlight/resolveFromAST.d.ts +2 -2
- package/dist/plugins/starlight/resolveFromAST.js +12 -8
- package/dist/plugins/stencil/index.js +2 -37
- package/dist/plugins/stencil/resolveFromAST.d.ts +3 -0
- package/dist/plugins/stencil/resolveFromAST.js +36 -0
- package/dist/plugins/storybook/index.js +3 -0
- package/dist/plugins/sveltekit/index.js +1 -48
- package/dist/plugins/sveltekit/resolveFromAST.d.ts +2 -0
- package/dist/plugins/sveltekit/resolveFromAST.js +45 -0
- package/dist/plugins/tauri/index.d.ts +3 -0
- package/dist/plugins/tauri/index.js +42 -0
- package/dist/plugins/tauri/types.d.ts +16 -0
- package/dist/plugins/tauri/types.js +1 -0
- package/dist/plugins/tsdown/index.js +2 -5
- package/dist/plugins/tsup/index.js +2 -5
- package/dist/plugins/unplugin-auto-import/index.d.ts +3 -0
- package/dist/plugins/unplugin-auto-import/index.js +18 -0
- package/dist/plugins/unplugin-icons/index.d.ts +3 -0
- package/dist/plugins/unplugin-icons/index.js +17 -0
- package/dist/plugins/unplugin-vue-components/index.d.ts +3 -0
- package/dist/plugins/unplugin-vue-components/index.js +16 -0
- package/dist/plugins/unplugin-vue-i18n/index.d.ts +3 -0
- package/dist/plugins/unplugin-vue-i18n/index.js +10 -0
- package/dist/plugins/unplugin-vue-markdown/index.d.ts +3 -0
- package/dist/plugins/unplugin-vue-markdown/index.js +16 -0
- package/dist/plugins/unplugin-vue-router/index.d.ts +3 -0
- package/dist/plugins/unplugin-vue-router/index.js +14 -0
- package/dist/plugins/vite/helpers.d.ts +2 -0
- package/dist/plugins/vite/helpers.js +46 -31
- package/dist/plugins/vite/index.js +1 -1
- package/dist/plugins/vite-plugin-pages/index.d.ts +3 -0
- package/dist/plugins/vite-plugin-pages/index.js +26 -0
- package/dist/plugins/vite-plugin-pwa/index.d.ts +3 -0
- package/dist/plugins/vite-plugin-pwa/index.js +17 -0
- package/dist/plugins/vite-plugin-pwa/resolveFromAST.d.ts +4 -0
- package/dist/plugins/vite-plugin-pwa/resolveFromAST.js +37 -0
- package/dist/plugins/vite-plugin-vue-layouts-next/index.d.ts +3 -0
- package/dist/plugins/vite-plugin-vue-layouts-next/index.js +23 -0
- package/dist/plugins/vite-plus/index.d.ts +3 -0
- package/dist/plugins/vite-plus/index.js +14 -0
- package/dist/plugins/vite-plus/resolveFromAST.d.ts +2 -0
- package/dist/plugins/vite-plus/resolveFromAST.js +37 -0
- package/dist/plugins/vite-pwa-assets-generator/index.d.ts +3 -0
- package/dist/plugins/vite-pwa-assets-generator/index.js +12 -0
- package/dist/plugins/vitepress/index.js +5 -1
- package/dist/plugins/vitest/index.js +4 -0
- package/dist/plugins/vitest/types.d.ts +3 -0
- package/dist/plugins/vue/index.js +5 -3
- package/dist/plugins/yarn/index.js +2 -1
- package/dist/plugins/yarn/types.d.ts +2 -4
- package/dist/schema/configuration.d.ts +255 -0
- package/dist/schema/plugins.d.ts +85 -0
- package/dist/schema/plugins.js +17 -0
- package/dist/types/PluginNames.d.ts +2 -2
- package/dist/types/PluginNames.js +17 -0
- package/dist/types/package-json.d.ts +8 -4
- package/dist/typescript/ast-helpers.d.ts +7 -2
- package/dist/typescript/ast-helpers.js +36 -8
- package/dist/typescript/ast-nodes.d.ts +1 -0
- package/dist/typescript/ast-nodes.js +8 -0
- package/dist/util/cli-arguments.d.ts +1 -1
- package/dist/util/cli-arguments.js +1 -1
- package/dist/util/create-options.d.ts +170 -0
- package/dist/util/resolve.js +4 -1
- package/dist/util/to-source-path.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/schema.json +68 -0
- package/dist/plugins/next/resolveFromAST.d.ts +0 -2
- package/dist/plugins/next/resolveFromAST.js +0 -2
- package/dist/plugins/nuxt/helpers.d.ts +0 -15
- package/dist/plugins/nuxt/helpers.js +0 -133
- package/dist/plugins/rolldown/resolveFromAST.d.ts +0 -2
- package/dist/plugins/rolldown/resolveFromAST.js +0 -4
- package/dist/plugins/rollup/resolveFromAST.d.ts +0 -2
- package/dist/plugins/rollup/resolveFromAST.js +0 -4
- package/dist/plugins/rslib/resolveFromAST.d.ts +0 -2
- package/dist/plugins/rslib/resolveFromAST.js +0 -4
- package/dist/plugins/tsdown/resolveFromAST.d.ts +0 -2
- package/dist/plugins/tsdown/resolveFromAST.js +0 -4
- package/dist/plugins/tsup/resolveFromAST.d.ts +0 -2
- package/dist/plugins/tsup/resolveFromAST.js +0 -4
- package/dist/plugins/vue/compiler.d.ts +0 -3
- package/dist/plugins/vue/compiler.js +0 -10
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { Visitor } from 'oxc-parser';
|
|
4
|
+
import { scriptBodies } from '../../compilers/compilers.js';
|
|
5
|
+
import { stylePreprocessorImports } from '../../compilers/style-preprocessors.js';
|
|
6
|
+
import { _parseFile } from '../../typescript/ast-nodes.js';
|
|
7
|
+
import { isFile } from '../../util/fs.js';
|
|
8
|
+
import { _syncGlob } from '../../util/glob.js';
|
|
9
|
+
import { dirname, isInNodeModules, join } from '../../util/path.js';
|
|
10
|
+
const getVueSfc = (cwd) => {
|
|
11
|
+
try {
|
|
12
|
+
return createRequire(join(cwd, 'package.json'))('vue/compiler-sfc');
|
|
13
|
+
}
|
|
14
|
+
catch { }
|
|
15
|
+
return {
|
|
16
|
+
parse: (source, path) => ({
|
|
17
|
+
descriptor: { script: { content: scriptBodies(source, path) }, scriptSetup: null, template: { content: '' } },
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
const readFile = (filePath) => {
|
|
22
|
+
try {
|
|
23
|
+
return readFileSync(filePath, 'utf8');
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export const readAndParseFile = (filePath) => _parseFile(filePath, readFile(filePath));
|
|
30
|
+
const collectIdentifiers = (source, fileName) => {
|
|
31
|
+
const identifiers = new Set();
|
|
32
|
+
const visitor = new Visitor({
|
|
33
|
+
Identifier(node) {
|
|
34
|
+
identifiers.add(node.name);
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
visitor.visit(_parseFile(fileName, source).program);
|
|
38
|
+
return identifiers;
|
|
39
|
+
};
|
|
40
|
+
const collectTemplateInfo = (tree) => {
|
|
41
|
+
const tags = new Set();
|
|
42
|
+
const identifiers = new Set();
|
|
43
|
+
const addExprIdentifiers = (expr) => {
|
|
44
|
+
for (const id of collectIdentifiers(expr, 'expr.ts'))
|
|
45
|
+
identifiers.add(id);
|
|
46
|
+
};
|
|
47
|
+
const visit = (node) => {
|
|
48
|
+
if (node.tag)
|
|
49
|
+
tags.add(node.tag);
|
|
50
|
+
if (node.type === 5 && node.content && !node.content.isStatic)
|
|
51
|
+
addExprIdentifiers(node.content.content);
|
|
52
|
+
if (node.props) {
|
|
53
|
+
for (const prop of node.props) {
|
|
54
|
+
if (prop.type === 7) {
|
|
55
|
+
if (prop.exp && !prop.exp.isStatic)
|
|
56
|
+
addExprIdentifiers(prop.exp.content);
|
|
57
|
+
if (prop.arg && !prop.arg.isStatic)
|
|
58
|
+
addExprIdentifiers(prop.arg.content);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (node.children)
|
|
63
|
+
for (const child of node.children)
|
|
64
|
+
visit(child);
|
|
65
|
+
};
|
|
66
|
+
visit(tree);
|
|
67
|
+
return { tags, identifiers };
|
|
68
|
+
};
|
|
69
|
+
const toKebabCase = (s) => s.replace(/[A-Z]/g, (m, i) => (i ? '-' : '') + m.toLowerCase());
|
|
70
|
+
const isLocalSpecifier = (specifier) => specifier.startsWith('.') && !isInNodeModules(specifier);
|
|
71
|
+
export const collectLocalImportPaths = (filePath, result) => {
|
|
72
|
+
const dir = dirname(filePath);
|
|
73
|
+
const paths = new Set();
|
|
74
|
+
const visitor = new Visitor({
|
|
75
|
+
TSImportType(node) {
|
|
76
|
+
const specifier = node.source.value;
|
|
77
|
+
if (isLocalSpecifier(specifier))
|
|
78
|
+
paths.add(join(dir, specifier));
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
visitor.visit(result.program);
|
|
82
|
+
return paths;
|
|
83
|
+
};
|
|
84
|
+
export function buildAutoImportMap(filePath, result, maps, isComponents) {
|
|
85
|
+
const dir = dirname(filePath);
|
|
86
|
+
const importTypes = [];
|
|
87
|
+
const collectVisitor = new Visitor({
|
|
88
|
+
TSImportType(node) {
|
|
89
|
+
importTypes.push({ start: node.start, end: node.end, specifier: node.source.value });
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
collectVisitor.visit(result.program);
|
|
93
|
+
const addEntry = (name, start, end) => {
|
|
94
|
+
const importType = importTypes.find(it => it.start >= start && it.end <= end);
|
|
95
|
+
if (!importType || !isLocalSpecifier(importType.specifier))
|
|
96
|
+
return;
|
|
97
|
+
const absSpecifier = join(dir, importType.specifier);
|
|
98
|
+
if (isComponents) {
|
|
99
|
+
const components = maps.componentMap.get(name);
|
|
100
|
+
if (components) {
|
|
101
|
+
if (!components.includes(absSpecifier))
|
|
102
|
+
components.push(absSpecifier);
|
|
103
|
+
}
|
|
104
|
+
else
|
|
105
|
+
maps.componentMap.set(name, [absSpecifier]);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
maps.importMap.set(name, absSpecifier);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const matchVisitor = new Visitor({
|
|
112
|
+
VariableDeclarator(node) {
|
|
113
|
+
if (node.id?.type !== 'Identifier' || node.id.name.startsWith('Lazy'))
|
|
114
|
+
return;
|
|
115
|
+
addEntry(node.id.name, node.start, node.end);
|
|
116
|
+
},
|
|
117
|
+
TSPropertySignature(node) {
|
|
118
|
+
if (!isComponents)
|
|
119
|
+
return;
|
|
120
|
+
const key = node.key;
|
|
121
|
+
const name = key?.type === 'Identifier' ? key.name : key?.type === 'Literal' ? String(key.value) : undefined;
|
|
122
|
+
if (name)
|
|
123
|
+
addEntry(name, node.start, node.end);
|
|
124
|
+
},
|
|
125
|
+
ExportNamedDeclaration(node) {
|
|
126
|
+
if (!node.source)
|
|
127
|
+
return;
|
|
128
|
+
const specifier = node.source.value;
|
|
129
|
+
if (!isLocalSpecifier(specifier))
|
|
130
|
+
return;
|
|
131
|
+
const absSpecifier = join(dir, specifier);
|
|
132
|
+
for (const s of node.specifiers) {
|
|
133
|
+
const name = s.exported.type === 'Identifier' ? s.exported.name : s.exported.value;
|
|
134
|
+
if (name)
|
|
135
|
+
maps.importMap.set(name, absSpecifier);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
matchVisitor.visit(result.program);
|
|
140
|
+
}
|
|
141
|
+
export const createAutoImportMaps = () => ({ importMap: new Map(), componentMap: new Map() });
|
|
142
|
+
export const findGeneratedDts = (cwd, signature) => _syncGlob({ cwd, patterns: ['*.d.ts', 'src/**/*.d.ts'] }).filter(filePath => readFile(filePath).slice(0, 300).includes(signature));
|
|
143
|
+
const generators = [
|
|
144
|
+
{ signature: 'Generated by unplugin-vue-components', isComponents: true },
|
|
145
|
+
{ signature: 'Generated by unplugin-auto-import', isComponents: false },
|
|
146
|
+
];
|
|
147
|
+
const getVueAutoImportMaps = (cwd) => {
|
|
148
|
+
const maps = createAutoImportMaps();
|
|
149
|
+
for (const filePath of _syncGlob({ cwd, patterns: ['*.d.ts', 'src/**/*.d.ts'] })) {
|
|
150
|
+
const source = readFile(filePath);
|
|
151
|
+
const generator = generators.find(({ signature }) => source.slice(0, 300).includes(signature));
|
|
152
|
+
if (generator)
|
|
153
|
+
buildAutoImportMap(filePath, _parseFile(filePath, source), maps, generator.isComponents);
|
|
154
|
+
}
|
|
155
|
+
return maps;
|
|
156
|
+
};
|
|
157
|
+
const getSyntheticImports = (maps, identifiers, templateTags) => {
|
|
158
|
+
const { importMap, componentMap } = maps;
|
|
159
|
+
if (importMap.size === 0 && (!templateTags || componentMap.size === 0))
|
|
160
|
+
return [];
|
|
161
|
+
const syntheticImports = [];
|
|
162
|
+
for (const [name, specifier] of importMap) {
|
|
163
|
+
if (identifiers.has(name))
|
|
164
|
+
syntheticImports.push(`import { ${name} } from '${specifier}';`);
|
|
165
|
+
}
|
|
166
|
+
if (templateTags) {
|
|
167
|
+
for (const [name, specifiers] of componentMap) {
|
|
168
|
+
const kebab = toKebabCase(name);
|
|
169
|
+
if (templateTags.has(name) ||
|
|
170
|
+
templateTags.has(kebab) ||
|
|
171
|
+
templateTags.has(`Lazy${name}`) ||
|
|
172
|
+
templateTags.has(`lazy-${kebab}`)) {
|
|
173
|
+
syntheticImports.push(`import { default as ${name} } from '${specifiers[0]}';`);
|
|
174
|
+
for (let i = 1; i < specifiers.length; i++)
|
|
175
|
+
syntheticImports.push(`import '${specifiers[i]}';`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return syntheticImports;
|
|
180
|
+
};
|
|
181
|
+
const compileVueSfc = (source, path, maps, root) => {
|
|
182
|
+
if (maps.importMap.size === 0 && maps.componentMap.size === 0) {
|
|
183
|
+
return [scriptBodies(source, path), stylePreprocessorImports(source, path)].filter(Boolean).join(';\n');
|
|
184
|
+
}
|
|
185
|
+
const { descriptor } = sfcForRoot(root).parse(source, path);
|
|
186
|
+
const scripts = [];
|
|
187
|
+
if (descriptor.script?.content)
|
|
188
|
+
scripts.push(descriptor.script.content);
|
|
189
|
+
if (descriptor.scriptSetup?.content)
|
|
190
|
+
scripts.push(descriptor.scriptSetup.content);
|
|
191
|
+
const identifiers = scripts.length === 0 ? new Set() : collectIdentifiers(scripts.join('\n'), path);
|
|
192
|
+
let templateTags;
|
|
193
|
+
if (descriptor.template?.ast) {
|
|
194
|
+
const info = collectTemplateInfo(descriptor.template.ast);
|
|
195
|
+
templateTags = info.tags;
|
|
196
|
+
for (const id of info.identifiers)
|
|
197
|
+
identifiers.add(id);
|
|
198
|
+
}
|
|
199
|
+
scripts.push(...getSyntheticImports(maps, identifiers, templateTags));
|
|
200
|
+
const styles = stylePreprocessorImports(source, path);
|
|
201
|
+
if (styles)
|
|
202
|
+
scripts.push(styles);
|
|
203
|
+
return scripts.join(';\n');
|
|
204
|
+
};
|
|
205
|
+
const compileTs = (source, path, maps) => {
|
|
206
|
+
if (maps.importMap.size === 0 || path.endsWith('.d.ts') || path.endsWith('.config.ts'))
|
|
207
|
+
return source;
|
|
208
|
+
const syntheticImports = getSyntheticImports(maps, collectIdentifiers(source, path));
|
|
209
|
+
return syntheticImports.length === 0 ? source : `${source}\n${syntheticImports.join('\n')}`;
|
|
210
|
+
};
|
|
211
|
+
const tagMatcher = /<([a-zA-Z][\w.-]*)/g;
|
|
212
|
+
const fencedCodeMatcher = /(`{3,}|~{3,})[\s\S]*?^[ \t]*\1/gm;
|
|
213
|
+
const inlineCodeMatcher = /`[^`\n]*`/g;
|
|
214
|
+
const stripCode = (md) => md.replace(fencedCodeMatcher, '').replace(inlineCodeMatcher, '');
|
|
215
|
+
const compileMarkdown = (source, path, maps) => {
|
|
216
|
+
const code = stripCode(source);
|
|
217
|
+
const scripts = scriptBodies(code, path);
|
|
218
|
+
if (maps.importMap.size === 0 && maps.componentMap.size === 0)
|
|
219
|
+
return scripts;
|
|
220
|
+
const tags = new Set();
|
|
221
|
+
for (const [, tag] of code.matchAll(tagMatcher))
|
|
222
|
+
tags.add(tag);
|
|
223
|
+
const identifiers = scripts ? collectIdentifiers(scripts, path) : new Set();
|
|
224
|
+
return [scripts, ...getSyntheticImports(maps, identifiers, tags)].filter(Boolean).join(';\n');
|
|
225
|
+
};
|
|
226
|
+
export const createVueCompiler = (maps, cwd) => (source, path) => compileVueSfc(source, path, maps, cwd);
|
|
227
|
+
export const createTsCompiler = (maps) => (source, path) => compileTs(source, path, maps);
|
|
228
|
+
const EMPTY_MAPS = createAutoImportMaps();
|
|
229
|
+
const rootByDir = new Map();
|
|
230
|
+
const mapsByRoot = new Map();
|
|
231
|
+
const sfcByRoot = new Map();
|
|
232
|
+
const findRoot = (fromDir) => {
|
|
233
|
+
const cached = rootByDir.get(fromDir);
|
|
234
|
+
if (cached !== undefined)
|
|
235
|
+
return cached;
|
|
236
|
+
let dir = fromDir;
|
|
237
|
+
let root = '';
|
|
238
|
+
for (;;) {
|
|
239
|
+
if (isFile(join(dir, 'package.json'))) {
|
|
240
|
+
root = dir;
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
const parent = dirname(dir);
|
|
244
|
+
if (parent === dir)
|
|
245
|
+
break;
|
|
246
|
+
dir = parent;
|
|
247
|
+
}
|
|
248
|
+
rootByDir.set(fromDir, root);
|
|
249
|
+
return root;
|
|
250
|
+
};
|
|
251
|
+
const mapsForFile = (path) => {
|
|
252
|
+
const root = findRoot(dirname(path));
|
|
253
|
+
if (!root)
|
|
254
|
+
return EMPTY_MAPS;
|
|
255
|
+
let maps = mapsByRoot.get(root);
|
|
256
|
+
if (!maps) {
|
|
257
|
+
maps = getVueAutoImportMaps(root);
|
|
258
|
+
mapsByRoot.set(root, maps);
|
|
259
|
+
}
|
|
260
|
+
return maps;
|
|
261
|
+
};
|
|
262
|
+
function sfcForRoot(root) {
|
|
263
|
+
let sfc = sfcByRoot.get(root);
|
|
264
|
+
if (!sfc) {
|
|
265
|
+
sfc = getVueSfc(root);
|
|
266
|
+
sfcByRoot.set(root, sfc);
|
|
267
|
+
}
|
|
268
|
+
return sfc;
|
|
269
|
+
}
|
|
270
|
+
export const vueAutoImportCompiler = (source, path) => compileVueSfc(source, path, mapsForFile(path), findRoot(dirname(path)));
|
|
271
|
+
export const tsAutoImportCompiler = (source, path) => compileTs(source, path, mapsForFile(path));
|
|
272
|
+
export const markdownAutoImportCompiler = (source, path) => compileMarkdown(source, path, mapsForFile(path));
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
interface TemplateExpressionNode {
|
|
2
|
+
content: string;
|
|
3
|
+
isStatic: boolean;
|
|
4
|
+
}
|
|
5
|
+
interface TemplateAstProp {
|
|
6
|
+
type: number;
|
|
7
|
+
exp?: TemplateExpressionNode;
|
|
8
|
+
arg?: TemplateExpressionNode;
|
|
9
|
+
}
|
|
10
|
+
export interface TemplateAstNode {
|
|
11
|
+
type?: number;
|
|
12
|
+
tag?: string;
|
|
13
|
+
props?: TemplateAstProp[];
|
|
14
|
+
content?: TemplateExpressionNode;
|
|
15
|
+
children?: TemplateAstNode[];
|
|
16
|
+
}
|
|
17
|
+
interface Descriptor {
|
|
18
|
+
script: {
|
|
19
|
+
content: string;
|
|
20
|
+
} | null;
|
|
21
|
+
scriptSetup: {
|
|
22
|
+
content: string;
|
|
23
|
+
} | null;
|
|
24
|
+
template: {
|
|
25
|
+
content: string;
|
|
26
|
+
ast?: TemplateAstNode;
|
|
27
|
+
} | null;
|
|
28
|
+
}
|
|
29
|
+
export type VueSfc = {
|
|
30
|
+
parse: (source: string, path: string) => {
|
|
31
|
+
descriptor: Descriptor;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export interface AutoImportMaps {
|
|
35
|
+
importMap: Map<string, string>;
|
|
36
|
+
componentMap: Map<string, string[]>;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,47 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { toConfig, toDependency, toEntry, toProductionEntry } from '../../util/input.js';
|
|
1
|
+
import { toDependency } from '../../util/input.js';
|
|
3
2
|
import { hasDependency } from '../../util/plugin.js';
|
|
4
|
-
import { getAliasInputs } from '../vitest/helpers.js';
|
|
5
3
|
import compiler from './compiler.js';
|
|
6
4
|
import mdxCompiler from './compiler-mdx.js';
|
|
7
|
-
import {
|
|
5
|
+
import { entry, production, resolveFromAST } from './resolveFromAST.js';
|
|
8
6
|
const title = 'Astro';
|
|
9
7
|
const enablers = ['astro'];
|
|
10
8
|
const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
|
|
11
9
|
export const config = ['astro.config.{js,cjs,mjs,ts,mts}'];
|
|
12
|
-
const entry = ['src/content/config.ts', 'src/content.config.ts'];
|
|
13
|
-
const production = [
|
|
14
|
-
'src/pages/**/*.{astro,mdx,js,ts}',
|
|
15
|
-
'!src/pages/**/_*',
|
|
16
|
-
'!src/pages/**/_*/**',
|
|
17
|
-
'src/content/**/*.mdx',
|
|
18
|
-
'src/middleware.{js,ts}',
|
|
19
|
-
'src/middleware/index.{js,ts}',
|
|
20
|
-
'src/actions/index.{js,ts}',
|
|
21
|
-
];
|
|
22
|
-
const resolveFromAST = (program, options) => {
|
|
23
|
-
const srcDir = getSrcDir(program);
|
|
24
|
-
const setSrcDir = (entry) => entry.replace(/^src\//, `${srcDir}/`);
|
|
25
|
-
const inputs = [
|
|
26
|
-
...entry.map(setSrcDir).map(path => toEntry(path)),
|
|
27
|
-
...production.map(setSrcDir).map(path => toProductionEntry(path)),
|
|
28
|
-
...getAliasInputs(getViteAliases(program), options.cwd),
|
|
29
|
-
];
|
|
30
|
-
if (!usesPassthroughImageService(program))
|
|
31
|
-
inputs.push(toDependency('sharp', { optional: true }));
|
|
32
|
-
const importMap = getImportMap(program);
|
|
33
|
-
const lunariaImportName = getDefaultImportName(importMap, '@lunariajs/starlight');
|
|
34
|
-
if (lunariaImportName) {
|
|
35
|
-
const lunariaConfig = findCallArg(program, lunariaImportName);
|
|
36
|
-
if (lunariaConfig) {
|
|
37
|
-
const configPaths = getPropertyValues(lunariaConfig, 'configPath');
|
|
38
|
-
for (const id of configPaths) {
|
|
39
|
-
inputs.push(toConfig('lunaria', id));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return inputs;
|
|
44
|
-
};
|
|
45
10
|
const registerCompilers = ({ registerCompiler, hasDependency }) => {
|
|
46
11
|
if (hasDependency('astro'))
|
|
47
12
|
registerCompiler({ extension: '.astro', compiler });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
1
|
+
import type { ResolveFromAST } from '../../types/config.ts';
|
|
2
|
+
export declare const entry: string[];
|
|
3
|
+
export declare const production: string[];
|
|
4
|
+
export declare const resolveFromAST: ResolveFromAST;
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
+
import { collectFirstPropertyValue, findImportedCallArg, findProperty, getPropertyKey, getPropertyValues, hasImportSpecifier, resolveObjectArg, } from '../../typescript/ast-helpers.js';
|
|
1
2
|
import { getStringValue } from '../../typescript/ast-nodes.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
3
|
+
import { toConfig, toDependency, toEntry, toProductionEntry } from '../../util/input.js';
|
|
4
|
+
import { getAliasInputs } from '../vitest/helpers.js';
|
|
5
|
+
export const entry = ['src/content/config.ts', 'src/content.config.ts'];
|
|
6
|
+
export const production = [
|
|
7
|
+
'src/pages/**/*.{astro,mdx,js,ts}',
|
|
8
|
+
'!src/pages/**/_*',
|
|
9
|
+
'!src/pages/**/_*/**',
|
|
10
|
+
'src/content/**/*.mdx',
|
|
11
|
+
'src/middleware.{js,ts}',
|
|
12
|
+
'src/middleware/index.{js,ts}',
|
|
13
|
+
'src/actions/index.{js,ts}',
|
|
14
|
+
];
|
|
15
|
+
const getSrcDir = (program) => collectFirstPropertyValue(program, 'srcDir') ?? 'src';
|
|
16
|
+
const usesPassthroughImageService = (program) => hasImportSpecifier(program, 'astro/config', 'passthroughImageService');
|
|
8
17
|
const findFirstStringArg = (node) => {
|
|
9
18
|
const literal = getStringValue(node);
|
|
10
19
|
if (literal)
|
|
@@ -17,7 +26,7 @@ const findFirstStringArg = (node) => {
|
|
|
17
26
|
}
|
|
18
27
|
}
|
|
19
28
|
};
|
|
20
|
-
|
|
29
|
+
const getViteAliases = (program) => {
|
|
21
30
|
const aliases = {};
|
|
22
31
|
for (const node of program.body ?? []) {
|
|
23
32
|
if (node.type !== 'ExportDefaultDeclaration')
|
|
@@ -40,3 +49,21 @@ export const getViteAliases = (program) => {
|
|
|
40
49
|
}
|
|
41
50
|
return aliases;
|
|
42
51
|
};
|
|
52
|
+
export const resolveFromAST = (program, options) => {
|
|
53
|
+
const srcDir = getSrcDir(program);
|
|
54
|
+
const setSrcDir = (entry) => entry.replace(/^src\//, `${srcDir}/`);
|
|
55
|
+
const inputs = [
|
|
56
|
+
...entry.map(setSrcDir).map(path => toEntry(path)),
|
|
57
|
+
...production.map(setSrcDir).map(path => toProductionEntry(path)),
|
|
58
|
+
...getAliasInputs(getViteAliases(program), options.cwd),
|
|
59
|
+
];
|
|
60
|
+
if (!usesPassthroughImageService(program))
|
|
61
|
+
inputs.push(toDependency('sharp', { optional: true }));
|
|
62
|
+
const lunariaConfig = findImportedCallArg(program, '@lunariajs/starlight');
|
|
63
|
+
if (lunariaConfig) {
|
|
64
|
+
for (const id of getPropertyValues(lunariaConfig, 'configPath')) {
|
|
65
|
+
inputs.push(toConfig('lunaria', id));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return inputs;
|
|
69
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { toProductionEntry } from '../../util/input.js';
|
|
2
|
+
import { isAbsolute, join } from '../../util/path.js';
|
|
3
|
+
import { hasDependency } from '../../util/plugin.js';
|
|
4
|
+
import { getHtmlScriptEntries } from '../vite/helpers.js';
|
|
5
|
+
const title = 'electron-vite';
|
|
6
|
+
const enablers = ['electron-vite'];
|
|
7
|
+
const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
|
|
8
|
+
const config = ['electron.vite.config.{js,mjs,cjs,ts,mts,cts}'];
|
|
9
|
+
const defaultEntry = {
|
|
10
|
+
main: 'src/main/index.{js,mjs,cjs,ts,mts,cts}',
|
|
11
|
+
preload: 'src/preload/index.{js,mjs,cjs,ts,mts,cts}',
|
|
12
|
+
renderer: 'src/renderer/index.html',
|
|
13
|
+
};
|
|
14
|
+
const production = Object.values(defaultEntry);
|
|
15
|
+
const buildEnv = { command: 'build', mode: 'production' };
|
|
16
|
+
const resolveConfig = async (localConfig, options) => {
|
|
17
|
+
const { configFileDir } = options;
|
|
18
|
+
const config = typeof localConfig === 'function' ? await localConfig(buildEnv) : localConfig;
|
|
19
|
+
const inputs = [];
|
|
20
|
+
for (const name of ['main', 'preload', 'renderer']) {
|
|
21
|
+
let section = config?.[name];
|
|
22
|
+
if (typeof section === 'function')
|
|
23
|
+
section = await section(buildEnv);
|
|
24
|
+
const ids = [];
|
|
25
|
+
for (const input of [section?.build?.rollupOptions?.input, section?.build?.lib?.entry]) {
|
|
26
|
+
if (typeof input === 'string')
|
|
27
|
+
ids.push(input);
|
|
28
|
+
else if (input)
|
|
29
|
+
ids.push(...Object.values(input));
|
|
30
|
+
}
|
|
31
|
+
const patterns = ids.length > 0 ? ids : [defaultEntry[name]];
|
|
32
|
+
for (const id of patterns) {
|
|
33
|
+
const resolved = isAbsolute(id) ? id : join(configFileDir, id);
|
|
34
|
+
inputs.push(toProductionEntry(resolved));
|
|
35
|
+
if (name === 'renderer' && resolved.endsWith('.html')) {
|
|
36
|
+
for (const input of await getHtmlScriptEntries(resolved))
|
|
37
|
+
inputs.push(input);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return inputs;
|
|
42
|
+
};
|
|
43
|
+
const plugin = {
|
|
44
|
+
title,
|
|
45
|
+
enablers,
|
|
46
|
+
isEnabled,
|
|
47
|
+
config,
|
|
48
|
+
production,
|
|
49
|
+
resolveConfig,
|
|
50
|
+
};
|
|
51
|
+
export default plugin;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type EntryInput = string | string[] | Record<string, string>;
|
|
2
|
+
interface ViteBuildConfig {
|
|
3
|
+
build?: {
|
|
4
|
+
rollupOptions?: {
|
|
5
|
+
input?: EntryInput;
|
|
6
|
+
};
|
|
7
|
+
lib?: {
|
|
8
|
+
entry?: EntryInput;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
type ConfigEnv = {
|
|
13
|
+
command: string;
|
|
14
|
+
mode: string;
|
|
15
|
+
};
|
|
16
|
+
type Section = ViteBuildConfig | ((env: ConfigEnv) => ViteBuildConfig | Promise<ViteBuildConfig>);
|
|
17
|
+
type ElectronViteConfigObject = {
|
|
18
|
+
main?: Section;
|
|
19
|
+
preload?: Section;
|
|
20
|
+
renderer?: Section;
|
|
21
|
+
};
|
|
22
|
+
export type ElectronViteConfig = ElectronViteConfigObject | ((env: ConfigEnv) => ElectronViteConfigObject | Promise<ElectronViteConfigObject>);
|
|
23
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { collectPropertyValues } from '../../typescript/ast-helpers.js';
|
|
2
|
+
import { toProductionEntry } from '../../util/input.js';
|
|
3
|
+
import { join } from '../../util/path.js';
|
|
4
|
+
import { hasDependency } from '../../util/plugin.js';
|
|
5
|
+
const title = 'esbuild';
|
|
6
|
+
const enablers = ['esbuild'];
|
|
7
|
+
const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
|
|
8
|
+
const config = ['esbuild.config.{js,mjs,cjs,ts,mts,cts}', 'esbuild.{js,mjs,cjs,ts,mts,cts}'];
|
|
9
|
+
const resolveFromAST = (program, { configFileDir }) => [...collectPropertyValues(program, 'entryPoints')].map(id => toProductionEntry(join(configFileDir, id)));
|
|
10
|
+
const plugin = {
|
|
11
|
+
title,
|
|
12
|
+
enablers,
|
|
13
|
+
isEnabled,
|
|
14
|
+
config,
|
|
15
|
+
resolveFromAST,
|
|
16
|
+
};
|
|
17
|
+
export default plugin;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { Visitor } from 'oxc-parser';
|
|
2
2
|
import { toDeferResolve } from '../../util/input.js';
|
|
3
|
-
import { findProperty } from '../../typescript/ast-helpers.js';
|
|
3
|
+
import { findProperty, getPropertyKey } from '../../typescript/ast-helpers.js';
|
|
4
|
+
import { getStringValue } from '../../typescript/ast-nodes.js';
|
|
4
5
|
import { isInternal } from '../../util/path.js';
|
|
5
6
|
export const getInputsFromFlatConfigAST = (program) => {
|
|
6
7
|
const inputs = [];
|
|
8
|
+
const addResolver = (key, resolver) => {
|
|
9
|
+
if (!resolver || resolver === 'node' || isInternal(resolver))
|
|
10
|
+
return;
|
|
11
|
+
const dep = key === 'import/resolver' ? `eslint-import-resolver-${resolver}` : resolver;
|
|
12
|
+
inputs.push(toDeferResolve(dep, { optional: true }));
|
|
13
|
+
};
|
|
7
14
|
const visitor = new Visitor({
|
|
8
15
|
ObjectExpression(node) {
|
|
9
16
|
const settingsNode = findProperty(node, 'settings');
|
|
@@ -12,28 +19,18 @@ export const getInputsFromFlatConfigAST = (program) => {
|
|
|
12
19
|
for (const prop of settingsNode.properties ?? []) {
|
|
13
20
|
if (prop.type !== 'Property')
|
|
14
21
|
continue;
|
|
15
|
-
const key = prop
|
|
16
|
-
if (key
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (resolver && resolver !== 'node' && !isInternal(resolver)) {
|
|
23
|
-
const dep = key === 'import/resolver' ? `eslint-import-resolver-${resolver}` : resolver;
|
|
24
|
-
inputs.push(toDeferResolve(dep, { optional: true }));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
else if (prop.value?.type === 'StringLiteral' ||
|
|
29
|
-
(prop.value?.type === 'Literal' && typeof prop.value.value === 'string')) {
|
|
30
|
-
const resolver = prop.value.value;
|
|
31
|
-
if (resolver && resolver !== 'node' && !isInternal(resolver)) {
|
|
32
|
-
const dep = key === 'import/resolver' ? `eslint-import-resolver-${resolver}` : resolver;
|
|
33
|
-
inputs.push(toDeferResolve(dep, { optional: true }));
|
|
34
|
-
}
|
|
22
|
+
const key = getPropertyKey(prop);
|
|
23
|
+
if (key !== 'import/resolver' && key !== 'import/parsers')
|
|
24
|
+
continue;
|
|
25
|
+
if (prop.value?.type === 'ObjectExpression') {
|
|
26
|
+
for (const p of prop.value.properties ?? []) {
|
|
27
|
+
if (p.type === 'Property')
|
|
28
|
+
addResolver(key, getPropertyKey(p));
|
|
35
29
|
}
|
|
36
30
|
}
|
|
31
|
+
else {
|
|
32
|
+
addResolver(key, getStringValue(prop.value));
|
|
33
|
+
}
|
|
37
34
|
}
|
|
38
35
|
},
|
|
39
36
|
});
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -27,7 +27,9 @@ export declare const Plugins: {
|
|
|
27
27
|
docusaurus: import("../types/config.ts").Plugin;
|
|
28
28
|
dotenv: import("../types/config.ts").Plugin;
|
|
29
29
|
drizzle: import("../types/config.ts").Plugin;
|
|
30
|
+
'electron-vite': import("../types/config.ts").Plugin;
|
|
30
31
|
eleventy: import("../types/config.ts").Plugin;
|
|
32
|
+
esbuild: import("../types/config.ts").Plugin;
|
|
31
33
|
eslint: import("../types/config.ts").Plugin;
|
|
32
34
|
eve: import("../types/config.ts").Plugin;
|
|
33
35
|
execa: import("../types/config.ts").Plugin;
|
|
@@ -52,6 +54,7 @@ export declare const Plugins: {
|
|
|
52
54
|
karma: import("../types/config.ts").Plugin;
|
|
53
55
|
knex: import("../types/config.ts").Plugin;
|
|
54
56
|
ladle: import("../types/config.ts").Plugin;
|
|
57
|
+
'laravel-vite-plugin': import("../types/config.ts").Plugin;
|
|
55
58
|
lefthook: import("../types/config.ts").Plugin;
|
|
56
59
|
'lint-staged': import("../types/config.ts").Plugin;
|
|
57
60
|
linthtml: import("../types/config.ts").Plugin;
|
|
@@ -79,6 +82,7 @@ export declare const Plugins: {
|
|
|
79
82
|
nodemon: import("../types/config.ts").Plugin;
|
|
80
83
|
'npm-package-json-lint': import("../types/config.ts").Plugin;
|
|
81
84
|
nuxt: import("../types/config.ts").Plugin;
|
|
85
|
+
'nuxtjs-i18n': import("../types/config.ts").Plugin;
|
|
82
86
|
nx: import("../types/config.ts").Plugin;
|
|
83
87
|
nyc: import("../types/config.ts").Plugin;
|
|
84
88
|
oclif: import("../types/config.ts").Plugin;
|
|
@@ -100,6 +104,7 @@ export declare const Plugins: {
|
|
|
100
104
|
preconstruct: import("../types/config.ts").Plugin;
|
|
101
105
|
prettier: import("../types/config.ts").Plugin;
|
|
102
106
|
prisma: import("../types/config.ts").Plugin;
|
|
107
|
+
quasar: import("../types/config.ts").Plugin;
|
|
103
108
|
qwik: import("../types/config.ts").Plugin;
|
|
104
109
|
raycast: import("../types/config.ts").Plugin;
|
|
105
110
|
'react-cosmos': import("../types/config.ts").Plugin;
|
|
@@ -138,6 +143,7 @@ export declare const Plugins: {
|
|
|
138
143
|
tailwind: import("../types/config.ts").Plugin;
|
|
139
144
|
'tanstack-router': import("../types/config.ts").Plugin;
|
|
140
145
|
taskfile: import("../types/config.ts").Plugin;
|
|
146
|
+
tauri: import("../types/config.ts").Plugin;
|
|
141
147
|
travis: import("../types/config.ts").Plugin;
|
|
142
148
|
'ts-node': import("../types/config.ts").Plugin;
|
|
143
149
|
tsdown: import("../types/config.ts").Plugin;
|
|
@@ -147,10 +153,21 @@ export declare const Plugins: {
|
|
|
147
153
|
typescript: import("../types/config.ts").Plugin;
|
|
148
154
|
unbuild: import("../types/config.ts").Plugin;
|
|
149
155
|
unocss: import("../types/config.ts").Plugin;
|
|
156
|
+
'unplugin-auto-import': import("../types/config.ts").Plugin;
|
|
157
|
+
'unplugin-icons': import("../types/config.ts").Plugin;
|
|
158
|
+
'unplugin-vue-components': import("../types/config.ts").Plugin;
|
|
159
|
+
'unplugin-vue-i18n': import("../types/config.ts").Plugin;
|
|
160
|
+
'unplugin-vue-markdown': import("../types/config.ts").Plugin;
|
|
161
|
+
'unplugin-vue-router': import("../types/config.ts").Plugin;
|
|
150
162
|
vercel: import("../types/config.ts").Plugin;
|
|
151
163
|
'vercel-og': import("../types/config.ts").Plugin;
|
|
152
164
|
vike: import("../types/config.ts").Plugin;
|
|
153
165
|
vite: import("../types/config.ts").Plugin;
|
|
166
|
+
'vite-plugin-pages': import("../types/config.ts").Plugin;
|
|
167
|
+
'vite-plugin-pwa': import("../types/config.ts").Plugin;
|
|
168
|
+
'vite-plugin-vue-layouts-next': import("../types/config.ts").Plugin;
|
|
169
|
+
'vite-plus': import("../types/config.ts").Plugin;
|
|
170
|
+
'vite-pwa-assets-generator': import("../types/config.ts").Plugin;
|
|
154
171
|
vitepress: import("../types/config.ts").Plugin;
|
|
155
172
|
vitest: import("../types/config.ts").Plugin;
|
|
156
173
|
vue: import("../types/config.ts").Plugin;
|