next-auto-import 0.0.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/README.md +62 -0
- package/dist/index.cjs +352 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +199 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +199 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +324 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +72 -0
- package/src/core/biomelintrc.ts +13 -0
- package/src/core/ctx.ts +287 -0
- package/src/core/eslintrc.ts +16 -0
- package/src/core/resolvers.ts +94 -0
- package/src/core/unplugin.ts +80 -0
- package/src/index.ts +30 -0
- package/src/presets/index.ts +9 -0
- package/src/presets/react-dom.ts +15 -0
- package/src/presets/react.ts +40 -0
- package/src/types.ts +242 -0
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# next-auto-import
|
|
2
|
+
|
|
3
|
+
Auto-import generator for Next.js projects. Automatically scans your directories and generates TypeScript declarations for global auto-imports, inspired by [unplugin-auto-import](https://github.com/unplugin/unplugin-auto-import).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🚀 Automatically scan directories for exports
|
|
8
|
+
- 📝 Generate TypeScript declaration files
|
|
9
|
+
- 🔄 Watch mode in development
|
|
10
|
+
- ⚡ Zero runtime overhead
|
|
11
|
+
- 🎯 Full TypeScript support
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add next-auto-import
|
|
17
|
+
# or
|
|
18
|
+
npm install next-auto-import
|
|
19
|
+
# or
|
|
20
|
+
yarn add next-auto-import
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Basic Setup
|
|
26
|
+
|
|
27
|
+
In your `next.config.js` or `next.config.mjs`:
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import { withAutoImport } from 'next-auto-import'
|
|
31
|
+
|
|
32
|
+
const nextConfig = {
|
|
33
|
+
// your next config
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const withAutoImport = createAutoImport({
|
|
37
|
+
imports: ['react'],
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
export default withAutoImport(nextConfig)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### TypeScript Configuration
|
|
44
|
+
|
|
45
|
+
Make sure to include the generated `.d.ts` file in your `tsconfig.json`:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"compilerOptions": {
|
|
50
|
+
// ... other options
|
|
51
|
+
},
|
|
52
|
+
"include": ["auto-imports.d.ts", "**/*.ts", "**/*.tsx"]
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Related
|
|
57
|
+
|
|
58
|
+
- [unplugin-auto-import](https://github.com/unplugin/unplugin-auto-import) - The original auto-import plugin for Vite, Webpack, Rollup, and more
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
let node_fs = require("node:fs");
|
|
29
|
+
let node_path = require("node:path");
|
|
30
|
+
let node_process = require("node:process");
|
|
31
|
+
node_process = __toESM(node_process);
|
|
32
|
+
let __antfu_utils = require("@antfu/utils");
|
|
33
|
+
let local_pkg = require("local-pkg");
|
|
34
|
+
let unimport = require("unimport");
|
|
35
|
+
|
|
36
|
+
//#region src/presets/react.ts
|
|
37
|
+
const CommonReactAPI = [
|
|
38
|
+
"useState",
|
|
39
|
+
"useCallback",
|
|
40
|
+
"useMemo",
|
|
41
|
+
"useEffect",
|
|
42
|
+
"useRef",
|
|
43
|
+
"useContext",
|
|
44
|
+
"useReducer",
|
|
45
|
+
"useImperativeHandle",
|
|
46
|
+
"useDebugValue",
|
|
47
|
+
"useDeferredValue",
|
|
48
|
+
"useLayoutEffect",
|
|
49
|
+
"useTransition",
|
|
50
|
+
"startTransition",
|
|
51
|
+
"useSyncExternalStore",
|
|
52
|
+
"useInsertionEffect",
|
|
53
|
+
"useId",
|
|
54
|
+
"lazy",
|
|
55
|
+
"memo",
|
|
56
|
+
"createRef",
|
|
57
|
+
"forwardRef"
|
|
58
|
+
];
|
|
59
|
+
var react_default = { react: [
|
|
60
|
+
...CommonReactAPI,
|
|
61
|
+
"cache",
|
|
62
|
+
"cacheSignal",
|
|
63
|
+
"createContext",
|
|
64
|
+
"use",
|
|
65
|
+
"useOptimistic",
|
|
66
|
+
"useEffectEvent",
|
|
67
|
+
"useActionState",
|
|
68
|
+
"Fragment",
|
|
69
|
+
"Suspense",
|
|
70
|
+
"Activity"
|
|
71
|
+
] };
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/presets/react-dom.ts
|
|
75
|
+
var react_dom_default = { "react-dom": [
|
|
76
|
+
"useFormStatus",
|
|
77
|
+
"createPortal",
|
|
78
|
+
"flushSync",
|
|
79
|
+
"preconnect",
|
|
80
|
+
"prefetchDNS",
|
|
81
|
+
"preinit",
|
|
82
|
+
"preinitModule",
|
|
83
|
+
"preload",
|
|
84
|
+
"preloadModule"
|
|
85
|
+
] };
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/presets/index.ts
|
|
89
|
+
const presets = {
|
|
90
|
+
"react": react_default,
|
|
91
|
+
"react-dom": react_dom_default
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/core/biomelintrc.ts
|
|
96
|
+
function generateBiomeLintConfigs(imports) {
|
|
97
|
+
const config = { javascript: { globals: imports.map((i) => i.as ?? i.name).filter(Boolean).sort() } };
|
|
98
|
+
return JSON.stringify(config, null, 2);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/core/eslintrc.ts
|
|
103
|
+
function generateESLintConfigs(imports, eslintrc) {
|
|
104
|
+
const eslintConfigs = { globals: {} };
|
|
105
|
+
imports.map((i) => i.as ?? i.name).filter(Boolean).sort().forEach((name) => {
|
|
106
|
+
eslintConfigs.globals[name] = eslintrc.globalsPropValue;
|
|
107
|
+
});
|
|
108
|
+
return JSON.stringify(eslintConfigs, null, 2);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/core/resolvers.ts
|
|
113
|
+
function normalizeImport(info, name) {
|
|
114
|
+
if (typeof info === "string") return {
|
|
115
|
+
name: "default",
|
|
116
|
+
as: name,
|
|
117
|
+
from: info
|
|
118
|
+
};
|
|
119
|
+
if ("path" in info) return {
|
|
120
|
+
from: info.path,
|
|
121
|
+
as: info.name,
|
|
122
|
+
name: info.importName,
|
|
123
|
+
sideEffects: info.sideEffects
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
name,
|
|
127
|
+
as: name,
|
|
128
|
+
...info
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
async function firstMatchedResolver(resolvers, fullname) {
|
|
132
|
+
let name = fullname;
|
|
133
|
+
for (const resolver of resolvers) {
|
|
134
|
+
if (typeof resolver === "object" && resolver.type === "directive") if (name.startsWith("v")) name = name.slice(1);
|
|
135
|
+
else continue;
|
|
136
|
+
const resolved = await (typeof resolver === "function" ? resolver(name) : resolver.resolve(name));
|
|
137
|
+
if (resolved) return normalizeImport(resolved, fullname);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function resolversAddon(resolvers) {
|
|
141
|
+
return {
|
|
142
|
+
name: "unplugin-auto-import:resolvers",
|
|
143
|
+
async matchImports(names, matched) {
|
|
144
|
+
if (!resolvers.length) return;
|
|
145
|
+
const dynamic = [];
|
|
146
|
+
const sideEffects = [];
|
|
147
|
+
await Promise.all([...names].map(async (name) => {
|
|
148
|
+
const matchedImport = matched.find((i) => i.as === name);
|
|
149
|
+
if (matchedImport) {
|
|
150
|
+
if ("sideEffects" in matchedImport) sideEffects.push(...(0, __antfu_utils.toArray)(matchedImport.sideEffects).map((i) => normalizeImport(i, "")));
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const resolved = await firstMatchedResolver(resolvers, name);
|
|
154
|
+
if (resolved) dynamic.push(resolved);
|
|
155
|
+
if (resolved?.sideEffects) sideEffects.push(...(0, __antfu_utils.toArray)(resolved?.sideEffects).map((i) => normalizeImport(i, "")));
|
|
156
|
+
}));
|
|
157
|
+
if (dynamic.length) {
|
|
158
|
+
this.dynamicImports.push(...dynamic);
|
|
159
|
+
this.invalidate();
|
|
160
|
+
}
|
|
161
|
+
if (dynamic.length || sideEffects.length) return [
|
|
162
|
+
...matched,
|
|
163
|
+
...dynamic,
|
|
164
|
+
...sideEffects
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/core/ctx.ts
|
|
172
|
+
function createContext(options = {}, root = node_process.default.cwd()) {
|
|
173
|
+
root = (0, __antfu_utils.slash)(root);
|
|
174
|
+
const { dts: preferDTS = (0, local_pkg.isPackageExists)("typescript"), dtsMode = "append", dtsPreserveExts = false, dirsScanOptions, dirs } = options;
|
|
175
|
+
const eslintrc = options.eslintrc || {};
|
|
176
|
+
eslintrc.enabled = eslintrc.enabled === void 0 ? false : eslintrc.enabled;
|
|
177
|
+
eslintrc.filepath = eslintrc.filepath || "./.eslintrc-auto-import.json";
|
|
178
|
+
eslintrc.globalsPropValue = eslintrc.globalsPropValue === void 0 ? true : eslintrc.globalsPropValue;
|
|
179
|
+
const biomelintrc = options.biomelintrc || {};
|
|
180
|
+
biomelintrc.enabled = biomelintrc.enabled !== void 0;
|
|
181
|
+
biomelintrc.filepath = biomelintrc.filepath || "./.biomelintrc-auto-import.json";
|
|
182
|
+
const dumpUnimportItems = options.dumpUnimportItems === true ? "./.unimport-items.json" : options.dumpUnimportItems ?? false;
|
|
183
|
+
const resolvers = options.resolvers ? [options.resolvers].flat(2) : [];
|
|
184
|
+
const injectAtEnd = options.injectAtEnd !== false;
|
|
185
|
+
const unimport$1 = (0, unimport.createUnimport)({
|
|
186
|
+
imports: [],
|
|
187
|
+
presets: options.packagePresets?.map((p) => typeof p === "string" ? { package: p } : p) ?? [],
|
|
188
|
+
dirsScanOptions: {
|
|
189
|
+
...dirsScanOptions,
|
|
190
|
+
cwd: root
|
|
191
|
+
},
|
|
192
|
+
dirs,
|
|
193
|
+
injectAtEnd,
|
|
194
|
+
parser: options.parser,
|
|
195
|
+
addons: { addons: [resolversAddon(resolvers), {
|
|
196
|
+
name: "unplugin-auto-import:dts",
|
|
197
|
+
declaration(dts$1) {
|
|
198
|
+
return `${`
|
|
199
|
+
/* eslint-disable */
|
|
200
|
+
/* prettier-ignore */
|
|
201
|
+
// @ts-nocheck
|
|
202
|
+
// noinspection JSUnusedGlobalSymbols
|
|
203
|
+
// Generated by unplugin-auto-import
|
|
204
|
+
// biome-ignore lint: disable
|
|
205
|
+
${dts$1}`.trim()}\n`;
|
|
206
|
+
}
|
|
207
|
+
}] }
|
|
208
|
+
});
|
|
209
|
+
const importsPromise = flattenImports(options.imports).then((imports) => {
|
|
210
|
+
if (!imports.length && !resolvers.length && !dirs?.length) console.warn("[auto-import] plugin installed but no imports has defined, see https://github.com/antfu/unplugin-auto-import#configurations for configurations");
|
|
211
|
+
const compare = (left, right) => {
|
|
212
|
+
return right instanceof RegExp ? right.test(left) : right === left;
|
|
213
|
+
};
|
|
214
|
+
options.ignore?.forEach((name) => {
|
|
215
|
+
const i = imports.find((i$1) => compare(i$1.as, name));
|
|
216
|
+
if (i) i.disabled = true;
|
|
217
|
+
});
|
|
218
|
+
options.ignoreDts?.forEach((name) => {
|
|
219
|
+
const i = imports.find((i$1) => compare(i$1.as, name));
|
|
220
|
+
if (i) i.dtsDisabled = true;
|
|
221
|
+
});
|
|
222
|
+
return unimport$1.getInternalContext().replaceImports(imports);
|
|
223
|
+
});
|
|
224
|
+
const dts = preferDTS === false ? false : preferDTS === true ? (0, node_path.resolve)(root, "auto-imports.d.ts") : (0, node_path.resolve)(root, preferDTS);
|
|
225
|
+
const multilineCommentsRE = /\/\*.*?\*\//gs;
|
|
226
|
+
const singlelineCommentsRE = /\/\/.*$/gm;
|
|
227
|
+
const dtsReg = /declare\s+global\s*\{(.*?)[\n\r]\}/s;
|
|
228
|
+
function parseDTS(dts$1) {
|
|
229
|
+
dts$1 = dts$1.replace(multilineCommentsRE, "").replace(singlelineCommentsRE, "");
|
|
230
|
+
const code = dts$1.match(dtsReg)?.[0];
|
|
231
|
+
if (!code) return;
|
|
232
|
+
return Object.fromEntries(Array.from(code.matchAll(/['"]?(const\s*[^\s'"]+)['"]?\s*:\s*(.+?)[,;\r\n]/g)).map((i) => [i[1], i[2]]));
|
|
233
|
+
}
|
|
234
|
+
async function generateDTS(file) {
|
|
235
|
+
await importsPromise;
|
|
236
|
+
const dir = (0, node_path.dirname)(file);
|
|
237
|
+
const originalDTS = parseDTS((0, node_fs.existsSync)(file) ? await node_fs.promises.readFile(file, "utf-8") : "");
|
|
238
|
+
const currentContent = await unimport$1.generateTypeDeclarations({ resolvePath: (i) => {
|
|
239
|
+
if (i.from.startsWith(".") || (0, node_path.isAbsolute)(i.from)) {
|
|
240
|
+
const related = (0, __antfu_utils.slash)(dtsPreserveExts ? (0, node_path.relative)(dir, i.from) : (0, node_path.relative)(dir, i.from).replace(/\.ts(x)?$/, ""));
|
|
241
|
+
return !related.startsWith(".") ? `./${related}` : related;
|
|
242
|
+
}
|
|
243
|
+
return i.from;
|
|
244
|
+
} });
|
|
245
|
+
if (dtsMode === "append") {
|
|
246
|
+
const currentDTS = parseDTS(currentContent);
|
|
247
|
+
if (originalDTS) {
|
|
248
|
+
Object.assign(originalDTS, currentDTS);
|
|
249
|
+
const dtsList = Object.keys(originalDTS).sort().map((k) => ` ${k}: ${originalDTS[k]}`);
|
|
250
|
+
return currentContent.replace(dtsReg, () => `declare global {\n${dtsList.join("\n")}\n}`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return currentContent;
|
|
254
|
+
}
|
|
255
|
+
async function generateESLint() {
|
|
256
|
+
return generateESLintConfigs(await unimport$1.getImports(), eslintrc);
|
|
257
|
+
}
|
|
258
|
+
async function generateBiomeLint() {
|
|
259
|
+
return generateBiomeLintConfigs(await unimport$1.getImports());
|
|
260
|
+
}
|
|
261
|
+
async function writeFile(filePath, content = "") {
|
|
262
|
+
await node_fs.promises.mkdir((0, node_path.dirname)(filePath), { recursive: true });
|
|
263
|
+
return await node_fs.promises.writeFile(filePath, content, "utf-8");
|
|
264
|
+
}
|
|
265
|
+
let lastDTS;
|
|
266
|
+
let lastESLint;
|
|
267
|
+
let lastBiomeLint;
|
|
268
|
+
let lastUnimportItems;
|
|
269
|
+
async function writeConfigFiles() {
|
|
270
|
+
const promises = [];
|
|
271
|
+
if (dts) promises.push(generateDTS(dts).then((content) => {
|
|
272
|
+
if (content !== lastDTS) {
|
|
273
|
+
lastDTS = content;
|
|
274
|
+
return writeFile(dts, content);
|
|
275
|
+
}
|
|
276
|
+
}));
|
|
277
|
+
if (eslintrc.enabled && eslintrc.filepath) {
|
|
278
|
+
const filepath = eslintrc.filepath;
|
|
279
|
+
promises.push(generateESLint().then(async (content) => {
|
|
280
|
+
if (filepath.endsWith(".cjs")) content = `module.exports = ${content}`;
|
|
281
|
+
else if (filepath.endsWith(".mjs") || filepath.endsWith(".js")) content = `export default ${content}`;
|
|
282
|
+
content = `${content}\n`;
|
|
283
|
+
if (content.trim() !== lastESLint?.trim()) {
|
|
284
|
+
lastESLint = content;
|
|
285
|
+
return writeFile(eslintrc.filepath, content);
|
|
286
|
+
}
|
|
287
|
+
}));
|
|
288
|
+
}
|
|
289
|
+
if (biomelintrc.enabled) promises.push(generateBiomeLint().then((content) => {
|
|
290
|
+
if (content !== lastBiomeLint) {
|
|
291
|
+
lastBiomeLint = content;
|
|
292
|
+
return writeFile(biomelintrc.filepath, content);
|
|
293
|
+
}
|
|
294
|
+
}));
|
|
295
|
+
if (dumpUnimportItems) promises.push(unimport$1.getImports().then((items) => {
|
|
296
|
+
if (!dumpUnimportItems) return;
|
|
297
|
+
const content = JSON.stringify(items, null, 2);
|
|
298
|
+
if (content !== lastUnimportItems) {
|
|
299
|
+
lastUnimportItems = content;
|
|
300
|
+
return writeFile(dumpUnimportItems, content);
|
|
301
|
+
}
|
|
302
|
+
}));
|
|
303
|
+
return Promise.all(promises);
|
|
304
|
+
}
|
|
305
|
+
return { writeConfigFiles };
|
|
306
|
+
}
|
|
307
|
+
async function flattenImports(map) {
|
|
308
|
+
return (await Promise.all((0, __antfu_utils.toArray)(map).map(async (definition) => {
|
|
309
|
+
if (typeof definition === "string") {
|
|
310
|
+
if (!presets[definition]) throw new Error(`[auto-import] preset ${definition} not found`);
|
|
311
|
+
definition = presets[definition];
|
|
312
|
+
}
|
|
313
|
+
if ("from" in definition && "imports" in definition) return await (0, unimport.resolvePreset)(definition);
|
|
314
|
+
else {
|
|
315
|
+
const resolved = [];
|
|
316
|
+
for (const mod of Object.keys(definition)) for (const id of definition[mod]) {
|
|
317
|
+
const meta = { from: mod };
|
|
318
|
+
if (Array.isArray(id)) {
|
|
319
|
+
meta.name = id[0];
|
|
320
|
+
meta.as = id[1];
|
|
321
|
+
} else {
|
|
322
|
+
meta.name = id;
|
|
323
|
+
meta.as = id;
|
|
324
|
+
}
|
|
325
|
+
resolved.push(meta);
|
|
326
|
+
}
|
|
327
|
+
return resolved;
|
|
328
|
+
}
|
|
329
|
+
}))).flat();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region src/index.ts
|
|
334
|
+
/**
|
|
335
|
+
* Creates a Next.js auto-import context
|
|
336
|
+
*/
|
|
337
|
+
function createAutoImport(options = {}) {
|
|
338
|
+
createContext(options).writeConfigFiles();
|
|
339
|
+
return (nextConfig = {}) => {
|
|
340
|
+
return {
|
|
341
|
+
...nextConfig,
|
|
342
|
+
experimental: {
|
|
343
|
+
...nextConfig.experimental,
|
|
344
|
+
swcPlugins: [["swc-plugin-auto-import", { presets: ["react"] }], ...nextConfig.experimental?.swcPlugins ?? []]
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
//#endregion
|
|
351
|
+
exports.createAutoImport = createAutoImport;
|
|
352
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["react","reactDom","eslintConfigs: any","dynamic: ImportExtended[]","sideEffects: ImportExtended[]","process","eslintrc: ESLintrc","biomelintrc: BiomeLintrc","unimport","dts","i","fs","lastDTS: string | undefined","lastESLint: string | undefined","lastBiomeLint: string | undefined","lastUnimportItems: string | undefined","promises: any[]","resolved: Import[]"],"sources":["../src/presets/react.ts","../src/presets/react-dom.ts","../src/presets/index.ts","../src/core/biomelintrc.ts","../src/core/eslintrc.ts","../src/core/resolvers.ts","../src/core/ctx.ts","../src/index.ts"],"sourcesContent":["import type { ImportsMap } from '../types'\n\nexport const CommonReactAPI = [\n 'useState',\n 'useCallback',\n 'useMemo',\n 'useEffect',\n 'useRef',\n 'useContext',\n 'useReducer',\n 'useImperativeHandle',\n 'useDebugValue',\n 'useDeferredValue',\n 'useLayoutEffect',\n 'useTransition',\n 'startTransition',\n 'useSyncExternalStore',\n 'useInsertionEffect',\n 'useId',\n 'lazy',\n 'memo',\n 'createRef',\n 'forwardRef',\n] as const\n\nexport default {\n react: [\n ...CommonReactAPI,\n 'cache',\n 'cacheSignal',\n 'createContext',\n 'use',\n 'useOptimistic',\n 'useEffectEvent',\n 'useActionState',\n 'Fragment',\n 'Suspense',\n 'Activity',\n ],\n} as const satisfies ImportsMap\n","import type { ImportsMap } from '../types'\n\nexport default {\n 'react-dom': [\n 'useFormStatus',\n 'createPortal',\n 'flushSync',\n 'preconnect',\n 'prefetchDNS',\n 'preinit',\n 'preinitModule',\n 'preload',\n 'preloadModule',\n ],\n} as const satisfies ImportsMap\n","import react from './react'\nimport reactDom from './react-dom'\n\nexport const presets = {\n 'react': react,\n 'react-dom': reactDom,\n}\n\nexport type PresetName = keyof typeof presets\n","import type { Import } from 'unimport'\n\nexport function generateBiomeLintConfigs(imports: Import[]) {\n const names = imports\n .map((i) => i.as ?? i.name)\n .filter(Boolean)\n .sort()\n\n const config = { javascript: { globals: names } }\n const jsonBody = JSON.stringify(config, null, 2)\n\n return jsonBody\n}\n","import type { Import } from 'unimport'\nimport type { ESLintrc } from '../types'\n\nexport function generateESLintConfigs(imports: Import[], eslintrc: ESLintrc) {\n const eslintConfigs: any = { globals: {} }\n\n imports\n .map((i) => i.as ?? i.name)\n .filter(Boolean)\n .sort()\n .forEach((name) => {\n eslintConfigs.globals[name] = eslintrc.globalsPropValue\n })\n const jsonBody = JSON.stringify(eslintConfigs, null, 2)\n return jsonBody\n}\n","import { toArray } from '@antfu/utils'\nimport type { Addon, Import } from 'unimport'\nimport type {\n ImportExtended,\n ImportLegacy,\n Resolver,\n ResolverResult,\n} from '../types'\n\nexport function normalizeImport(\n info: Import | ResolverResult | ImportExtended | ImportLegacy | string,\n name: string,\n): ImportExtended {\n if (typeof info === 'string') {\n return {\n name: 'default',\n as: name,\n from: info,\n }\n }\n if ('path' in info) {\n return {\n from: info.path,\n as: info.name,\n name: info.importName!,\n sideEffects: info.sideEffects,\n }\n }\n return {\n name,\n as: name,\n ...info,\n }\n}\n\nexport async function firstMatchedResolver(\n resolvers: Resolver[],\n fullname: string,\n) {\n let name = fullname\n for (const resolver of resolvers) {\n if (typeof resolver === 'object' && resolver.type === 'directive') {\n if (name.startsWith('v')) name = name.slice(1)\n else continue\n }\n const resolved = await (typeof resolver === 'function'\n ? resolver(name)\n : resolver.resolve(name))\n if (resolved) return normalizeImport(resolved, fullname)\n }\n}\n\nexport function resolversAddon(resolvers: Resolver[]): Addon {\n return {\n name: 'unplugin-auto-import:resolvers',\n async matchImports(names, matched) {\n if (!resolvers.length) return\n const dynamic: ImportExtended[] = []\n const sideEffects: ImportExtended[] = []\n await Promise.all(\n [...names].map(async (name) => {\n const matchedImport = matched.find((i) => i.as === name)\n if (matchedImport) {\n if ('sideEffects' in matchedImport)\n sideEffects.push(\n ...toArray((matchedImport as ImportExtended).sideEffects).map(\n (i) => normalizeImport(i, ''),\n ),\n )\n\n return\n }\n const resolved = await firstMatchedResolver(resolvers, name)\n if (resolved) dynamic.push(resolved)\n\n if (resolved?.sideEffects)\n sideEffects.push(\n ...toArray(resolved?.sideEffects).map((i) =>\n normalizeImport(i, ''),\n ),\n )\n }),\n )\n\n if (dynamic.length) {\n this.dynamicImports.push(...dynamic)\n this.invalidate()\n }\n\n if (dynamic.length || sideEffects.length)\n return [...matched, ...dynamic, ...sideEffects]\n },\n }\n}\n","import { existsSync, promises as fs } from 'node:fs'\nimport { dirname, isAbsolute, relative, resolve } from 'node:path'\nimport process from 'node:process'\nimport { slash, toArray } from '@antfu/utils'\nimport { isPackageExists } from 'local-pkg'\nimport { createUnimport, resolvePreset } from 'unimport'\nimport { presets } from '../presets'\nimport { generateBiomeLintConfigs } from './biomelintrc'\nimport { generateESLintConfigs } from './eslintrc'\nimport { resolversAddon } from './resolvers'\nimport type { Import, InlinePreset } from 'unimport'\nimport type { BiomeLintrc, ESLintrc, Options } from '../types'\n\nexport const INCLUDE_RE_LIST = [/\\.[jt]sx?$/]\nexport const EXCLUDE_RE_LIST = [/[\\\\/]node_modules[\\\\/]/, /[\\\\/]\\.git[\\\\/]/]\n\nexport function createContext(options: Options = {}, root = process.cwd()) {\n root = slash(root)\n\n const {\n dts: preferDTS = isPackageExists('typescript'),\n dtsMode = 'append',\n dtsPreserveExts = false,\n dirsScanOptions,\n dirs,\n } = options\n\n const eslintrc: ESLintrc = options.eslintrc || {}\n eslintrc.enabled = eslintrc.enabled === undefined ? false : eslintrc.enabled\n eslintrc.filepath = eslintrc.filepath || './.eslintrc-auto-import.json'\n eslintrc.globalsPropValue =\n eslintrc.globalsPropValue === undefined ? true : eslintrc.globalsPropValue\n\n const biomelintrc: BiomeLintrc = options.biomelintrc || {}\n biomelintrc.enabled = biomelintrc.enabled !== undefined\n biomelintrc.filepath =\n biomelintrc.filepath || './.biomelintrc-auto-import.json'\n\n const dumpUnimportItems =\n options.dumpUnimportItems === true\n ? './.unimport-items.json'\n : (options.dumpUnimportItems ?? false)\n\n const resolvers = options.resolvers ? [options.resolvers].flat(2) : []\n\n // When \"options.injectAtEnd\" is undefined or true, it's true.\n const injectAtEnd = options.injectAtEnd !== false\n\n const unimport = createUnimport({\n imports: [],\n presets:\n options.packagePresets?.map((p) =>\n typeof p === 'string' ? { package: p } : p,\n ) ?? [],\n dirsScanOptions: {\n ...dirsScanOptions,\n cwd: root,\n },\n dirs,\n injectAtEnd,\n parser: options.parser,\n addons: {\n addons: [\n resolversAddon(resolvers),\n {\n name: 'unplugin-auto-import:dts',\n declaration(dts) {\n return `${`\n/* eslint-disable */\n/* prettier-ignore */\n// @ts-nocheck\n// noinspection JSUnusedGlobalSymbols\n// Generated by unplugin-auto-import\n// biome-ignore lint: disable\n${dts}`.trim()}\\n`\n },\n },\n ],\n },\n })\n\n const importsPromise = flattenImports(options.imports).then((imports) => {\n if (!imports.length && !resolvers.length && !dirs?.length)\n console.warn(\n '[auto-import] plugin installed but no imports has defined, see https://github.com/antfu/unplugin-auto-import#configurations for configurations',\n )\n\n const compare = (\n left: string | undefined,\n right: NonNullable<Options['ignore'] | Options['ignoreDts']>[number],\n ) => {\n return right instanceof RegExp ? right.test(left!) : right === left\n }\n\n options.ignore?.forEach((name) => {\n const i = imports.find((i) => compare(i.as, name))\n if (i) i.disabled = true\n })\n\n options.ignoreDts?.forEach((name) => {\n const i = imports.find((i) => compare(i.as, name))\n if (i) i.dtsDisabled = true\n })\n\n return unimport.getInternalContext().replaceImports(imports)\n })\n\n const dts =\n preferDTS === false\n ? false\n : preferDTS === true\n ? resolve(root, 'auto-imports.d.ts')\n : resolve(root, preferDTS)\n\n const multilineCommentsRE = /\\/\\*.*?\\*\\//gs\n const singlelineCommentsRE = /\\/\\/.*$/gm\n const dtsReg = /declare\\s+global\\s*\\{(.*?)[\\n\\r]\\}/s\n function parseDTS(dts: string) {\n dts = dts.replace(multilineCommentsRE, '').replace(singlelineCommentsRE, '')\n\n const code = dts.match(dtsReg)?.[0]\n if (!code) return\n\n return Object.fromEntries(\n Array.from(\n code.matchAll(/['\"]?(const\\s*[^\\s'\"]+)['\"]?\\s*:\\s*(.+?)[,;\\r\\n]/g),\n ).map((i) => [i[1], i[2]]),\n )\n }\n\n async function generateDTS(file: string) {\n await importsPromise\n const dir = dirname(file)\n const originalContent = existsSync(file)\n ? await fs.readFile(file, 'utf-8')\n : ''\n const originalDTS = parseDTS(originalContent)\n const currentContent = await unimport.generateTypeDeclarations({\n resolvePath: (i) => {\n if (i.from.startsWith('.') || isAbsolute(i.from)) {\n const related = slash(\n dtsPreserveExts\n ? relative(dir, i.from)\n : relative(dir, i.from).replace(/\\.ts(x)?$/, ''),\n )\n return !related.startsWith('.') ? `./${related}` : related\n }\n return i.from\n },\n })\n\n if (dtsMode === 'append') {\n const currentDTS = parseDTS(currentContent)!\n if (originalDTS) {\n Object.assign(originalDTS, currentDTS)\n\n const dtsList = Object.keys(originalDTS)\n .sort()\n .map((k) => ` ${k}: ${originalDTS[k]}`)\n return currentContent.replace(\n dtsReg,\n () => `declare global {\\n${dtsList.join('\\n')}\\n}`,\n )\n }\n }\n\n return currentContent\n }\n\n async function generateESLint() {\n return generateESLintConfigs(await unimport.getImports(), eslintrc)\n }\n\n async function generateBiomeLint() {\n return generateBiomeLintConfigs(await unimport.getImports())\n }\n\n // eslint-disable-next-line unicorn/consistent-function-scoping\n async function writeFile(filePath: string, content = '') {\n await fs.mkdir(dirname(filePath), { recursive: true })\n return await fs.writeFile(filePath, content, 'utf-8')\n }\n\n let lastDTS: string | undefined\n let lastESLint: string | undefined\n let lastBiomeLint: string | undefined\n let lastUnimportItems: string | undefined\n\n async function writeConfigFiles() {\n const promises: any[] = []\n if (dts) {\n promises.push(\n generateDTS(dts).then((content) => {\n if (content !== lastDTS) {\n lastDTS = content\n return writeFile(dts, content)\n }\n }),\n )\n }\n if (eslintrc.enabled && eslintrc.filepath) {\n const filepath = eslintrc.filepath\n promises.push(\n generateESLint().then(async (content) => {\n if (filepath.endsWith('.cjs')) content = `module.exports = ${content}`\n else if (filepath.endsWith('.mjs') || filepath.endsWith('.js'))\n content = `export default ${content}`\n\n content = `${content}\\n`\n if (content.trim() !== lastESLint?.trim()) {\n lastESLint = content\n return writeFile(eslintrc.filepath!, content)\n }\n }),\n )\n }\n\n if (biomelintrc.enabled) {\n promises.push(\n generateBiomeLint().then((content) => {\n if (content !== lastBiomeLint) {\n lastBiomeLint = content\n return writeFile(biomelintrc.filepath!, content)\n }\n }),\n )\n }\n\n if (dumpUnimportItems) {\n promises.push(\n unimport.getImports().then((items) => {\n if (!dumpUnimportItems) return\n const content = JSON.stringify(items, null, 2)\n if (content !== lastUnimportItems) {\n lastUnimportItems = content\n return writeFile(dumpUnimportItems, content)\n }\n }),\n )\n }\n\n return Promise.all(promises)\n }\n\n return {\n writeConfigFiles,\n }\n}\n\nexport async function flattenImports(\n map: Options['imports'],\n): Promise<Import[]> {\n const promises = await Promise.all(\n toArray(map).map(async (definition) => {\n if (typeof definition === 'string') {\n if (!presets[definition])\n throw new Error(`[auto-import] preset ${definition} not found`)\n const preset = presets[definition]\n definition = preset\n }\n\n if ('from' in definition && 'imports' in definition) {\n return await resolvePreset(definition as InlinePreset)\n } else {\n const resolved: Import[] = []\n for (const mod of Object.keys(definition)) {\n for (const id of definition[mod]) {\n const meta = {\n from: mod,\n } as Import\n if (Array.isArray(id)) {\n meta.name = id[0]\n meta.as = id[1]\n } else {\n meta.name = id\n meta.as = id\n }\n resolved.push(meta)\n }\n }\n return resolved\n }\n }),\n )\n\n return promises.flat()\n}\n","import { createContext } from './core/ctx'\nimport type { NextConfig } from 'next'\nimport type { Options } from './types'\n\n/**\n * Creates a Next.js auto-import context\n */\nexport function createAutoImport(options: Options = {}) {\n const ctx = createContext(options)\n\n ctx.writeConfigFiles()\n\n return (nextConfig: NextConfig = {}): NextConfig => {\n return {\n ...nextConfig,\n experimental: {\n ...nextConfig.experimental,\n swcPlugins: [\n [\n 'swc-plugin-auto-import',\n {\n presets: ['react'],\n },\n ],\n ...(nextConfig.experimental?.swcPlugins ?? []),\n ],\n },\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAa,iBAAiB;CAC5B;C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,CACH;AAGH,SAAO,QAAQ,IAAI,SAAS;;AAG9B,QAAO,EACL,kBACD;;AAGH,eAAsB,eACpB,KACmB;AAkCnB,SAjCiB,MAAM,QAAQ,+BACrB,IAAI,CAAC,IAAI,OAAO,eAAe;AACrC,MAAI,OAAO,eAAe,UAAU;AAClC,OAAI,CAAC,QAAQ,YACX,OAAM,IAAI,MAAM,wBAAwB,WAAW,YAAY;AAEjE,gBADe,QAAQ;;AAIzB,MAAI,UAAU,cAAc,aAAa,WACvC,QAAO,kCAAoB,WAA2B;OACjD;GACL,MAAMS,WAAqB,EAAE;AAC7B,QAAK,MAAM,OAAO,OAAO,KAAK,WAAW,CACvC,MAAK,MAAM,MAAM,WAAW,MAAM;IAChC,MAAM,OAAO,EACX,MAAM,KACP;AACD,QAAI,MAAM,QAAQ,GAAG,EAAE;AACrB,UAAK,OAAO,GAAG;AACf,UAAK,KAAK,GAAG;WACR;AACL,UAAK,OAAO;AACZ,UAAK,KAAK;;AAEZ,aAAS,KAAK,KAAK;;AAGvB,UAAO;;GAET,CACH,EAEe,MAAM;;;;;;;;ACtRxB,SAAgB,iBAAiB,UAAmB,EAAE,EAAE;AAGtD,CAFY,cAAc,QAAQ,CAE9B,kBAAkB;AAEtB,SAAQ,aAAyB,EAAE,KAAiB;AAClD,SAAO;GACL,GAAG;GACH,cAAc;IACZ,GAAG,WAAW;IACd,YAAY,CACV,CACE,0BACA,EACE,SAAS,CAAC,QAAQ,EACnB,CACF,EACD,GAAI,WAAW,cAAc,cAAc,EAAE,CAC9C;IACF;GACF"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { NextConfig } from "next";
|
|
2
|
+
import { Arrayable, Awaitable } from "@antfu/utils";
|
|
3
|
+
import { Import, InlinePreset, PackagePreset, ScanDirExportsOptions, UnimportOptions } from "unimport";
|
|
4
|
+
import { FilterPattern } from "unplugin-utils";
|
|
5
|
+
|
|
6
|
+
//#region src/presets/index.d.ts
|
|
7
|
+
declare const presets: {
|
|
8
|
+
react: {
|
|
9
|
+
readonly react: ["useState", "useCallback", "useMemo", "useEffect", "useRef", "useContext", "useReducer", "useImperativeHandle", "useDebugValue", "useDeferredValue", "useLayoutEffect", "useTransition", "startTransition", "useSyncExternalStore", "useInsertionEffect", "useId", "lazy", "memo", "createRef", "forwardRef", "cache", "cacheSignal", "createContext", "use", "useOptimistic", "useEffectEvent", "useActionState", "Fragment", "Suspense", "Activity"];
|
|
10
|
+
};
|
|
11
|
+
'react-dom': {
|
|
12
|
+
readonly 'react-dom': ["useFormStatus", "createPortal", "flushSync", "preconnect", "prefetchDNS", "preinit", "preinitModule", "preload", "preloadModule"];
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
type PresetName = keyof typeof presets;
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/types.d.ts
|
|
18
|
+
|
|
19
|
+
interface ImportExtended extends Import {
|
|
20
|
+
sideEffects?: SideEffectsInfo;
|
|
21
|
+
__source?: 'dir' | 'resolver';
|
|
22
|
+
}
|
|
23
|
+
type ImportNameAlias = [string, string];
|
|
24
|
+
type SideEffectsInfo = Arrayable<ResolverResult | string> | undefined;
|
|
25
|
+
interface ResolverResult {
|
|
26
|
+
as?: string;
|
|
27
|
+
name?: string;
|
|
28
|
+
from: string;
|
|
29
|
+
}
|
|
30
|
+
type ResolverFunction = (name: string) => Awaitable<string | ResolverResult | ImportExtended | null | undefined | void>;
|
|
31
|
+
interface ResolverResultObject {
|
|
32
|
+
type: 'component' | 'directive';
|
|
33
|
+
resolve: ResolverFunction;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Given a identifier name, returns the import path or an import object
|
|
37
|
+
*/
|
|
38
|
+
type Resolver = ResolverFunction | ResolverResultObject;
|
|
39
|
+
/**
|
|
40
|
+
* module, name, alias
|
|
41
|
+
*/
|
|
42
|
+
type ImportsMap = Record<string, (string | ImportNameAlias)[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Directory to search for import
|
|
45
|
+
*/
|
|
46
|
+
interface ScanDir {
|
|
47
|
+
glob: string;
|
|
48
|
+
types?: boolean;
|
|
49
|
+
}
|
|
50
|
+
type ESLintGlobalsPropValue = boolean | 'readonly' | 'readable' | 'writable' | 'writeable';
|
|
51
|
+
interface ESLintrc {
|
|
52
|
+
/**
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
enabled?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Filepath to save the generated eslint config
|
|
58
|
+
*
|
|
59
|
+
* @default './.eslintrc-auto-import.json'
|
|
60
|
+
*/
|
|
61
|
+
filepath?: string;
|
|
62
|
+
/**
|
|
63
|
+
* @default true
|
|
64
|
+
*/
|
|
65
|
+
globalsPropValue?: ESLintGlobalsPropValue;
|
|
66
|
+
}
|
|
67
|
+
interface BiomeLintrc {
|
|
68
|
+
/**
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
71
|
+
enabled?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Filepath to save the generated eslint config
|
|
74
|
+
*
|
|
75
|
+
* @default './.eslintrc-auto-import.json'
|
|
76
|
+
*/
|
|
77
|
+
filepath?: string;
|
|
78
|
+
}
|
|
79
|
+
interface Options {
|
|
80
|
+
/**
|
|
81
|
+
* Preset names or custom imports map
|
|
82
|
+
*
|
|
83
|
+
* @default []
|
|
84
|
+
*/
|
|
85
|
+
imports?: Arrayable<ImportsMap | PresetName | InlinePreset>;
|
|
86
|
+
/**
|
|
87
|
+
* Local package presets.
|
|
88
|
+
*
|
|
89
|
+
* Register local installed packages as a preset.
|
|
90
|
+
*
|
|
91
|
+
* @default []
|
|
92
|
+
* @see https://github.com/unplugin/unplugin-auto-import#package-presets
|
|
93
|
+
*/
|
|
94
|
+
packagePresets?: (PackagePreset | string)[];
|
|
95
|
+
/**
|
|
96
|
+
* Identifiers to be ignored
|
|
97
|
+
*/
|
|
98
|
+
ignore?: (string | RegExp)[];
|
|
99
|
+
/**
|
|
100
|
+
* These identifiers won't be put on the DTS file
|
|
101
|
+
*/
|
|
102
|
+
ignoreDts?: (string | RegExp)[];
|
|
103
|
+
/**
|
|
104
|
+
* Inject the imports at the end of other imports
|
|
105
|
+
*
|
|
106
|
+
* @default true
|
|
107
|
+
*/
|
|
108
|
+
injectAtEnd?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Options for scanning directories for auto import
|
|
111
|
+
*/
|
|
112
|
+
dirsScanOptions?: Omit<ScanDirExportsOptions, 'cwd'>;
|
|
113
|
+
/**
|
|
114
|
+
* Path for directories to be auto imported
|
|
115
|
+
*/
|
|
116
|
+
dirs?: (string | ScanDir)[];
|
|
117
|
+
/**
|
|
118
|
+
* Pass a custom function to resolve the component importing path from the component name.
|
|
119
|
+
*
|
|
120
|
+
* The component names are always in PascalCase
|
|
121
|
+
*/
|
|
122
|
+
resolvers?: Arrayable<Arrayable<Resolver>>;
|
|
123
|
+
/**
|
|
124
|
+
* Parser to be used for parsing the source code.
|
|
125
|
+
*
|
|
126
|
+
* @see https://github.com/unjs/unimport#acorn-parser
|
|
127
|
+
* @default 'regex'
|
|
128
|
+
*/
|
|
129
|
+
parser?: UnimportOptions['parser'];
|
|
130
|
+
/**
|
|
131
|
+
* Specifies the file path for generating the corresponding .d.ts file.
|
|
132
|
+
* This option is enabled by default when `typescript` is installed locally.
|
|
133
|
+
* Set to `false` to disable this feature.
|
|
134
|
+
*/
|
|
135
|
+
dts?: string | boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Mode for generating the .d.ts file.
|
|
138
|
+
* - `overwrite`: overwrite the whole existing .d.ts file with the new type definitions.
|
|
139
|
+
* - `append`: only append the new type definitions to the existing .d.ts file, means the existing type definitions will be kept.
|
|
140
|
+
* @default 'append'
|
|
141
|
+
*/
|
|
142
|
+
dtsMode?: 'overwrite' | 'append';
|
|
143
|
+
/**
|
|
144
|
+
* Preserve the original file extensions in the generated .d.ts file.
|
|
145
|
+
* Set to `true` to keep the extensions for .ts and .tsx files.
|
|
146
|
+
* @default false
|
|
147
|
+
*/
|
|
148
|
+
dtsPreserveExts?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Set default export alias by file name
|
|
151
|
+
*
|
|
152
|
+
* @default false
|
|
153
|
+
*/
|
|
154
|
+
defaultExportByFilename?: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Rules to include transforming target.
|
|
157
|
+
*
|
|
158
|
+
* @default [/\.[jt]sx?$/, /\.astro$/, /\.vue$/, /\.vue\?vue/, /\.vue\.[tj]sx?\?vue/, /\.svelte$/]
|
|
159
|
+
*/
|
|
160
|
+
include?: FilterPattern;
|
|
161
|
+
/**
|
|
162
|
+
* Rules to exclude transforming target.
|
|
163
|
+
*
|
|
164
|
+
* @default [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/]
|
|
165
|
+
*/
|
|
166
|
+
exclude?: FilterPattern;
|
|
167
|
+
/**
|
|
168
|
+
* Generate corresponding .eslintrc-auto-import.json file.
|
|
169
|
+
*/
|
|
170
|
+
eslintrc?: ESLintrc;
|
|
171
|
+
/**
|
|
172
|
+
* Generate corresponding .biomelintrc.json file.
|
|
173
|
+
*/
|
|
174
|
+
biomelintrc?: BiomeLintrc;
|
|
175
|
+
/**
|
|
176
|
+
* Save unimport items into a JSON file for other tools to consume.
|
|
177
|
+
* Provide a filepath to save the JSON file.
|
|
178
|
+
*
|
|
179
|
+
* When set to `true`, it will save to `./.unimport-items.json`
|
|
180
|
+
*
|
|
181
|
+
* @default false
|
|
182
|
+
*/
|
|
183
|
+
dumpUnimportItems?: boolean | string;
|
|
184
|
+
/**
|
|
185
|
+
* Include auto-imported packages in Vite's `optimizeDeps` option
|
|
186
|
+
*
|
|
187
|
+
* @default true
|
|
188
|
+
*/
|
|
189
|
+
viteOptimizeDeps?: boolean;
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/index.d.ts
|
|
193
|
+
/**
|
|
194
|
+
* Creates a Next.js auto-import context
|
|
195
|
+
*/
|
|
196
|
+
declare function createAutoImport(options?: Options): (nextConfig?: NextConfig) => NextConfig;
|
|
197
|
+
//#endregion
|
|
198
|
+
export { createAutoImport };
|
|
199
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/presets/index.ts","../src/types.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;cAGa;;;;;;EAAA,CAAA;AAKb,CAAA;KAAY,UAAA,gBAA0B;;;;ACoCxB,UAhBG,cAAA,SAAuB,MAgB1B,CAAA;EAIG,WAAA,CAAA,EAnBD,eAmBqB;EAQzB,QAAA,CAAA,EAAQ,KAAA,GAAA,UAAG;AAKvB;AAKiB,KAjCL,eAAA,GAiCY,CAAA,MAAA,EAAA,MAAA,CAAA;AAOZ,KAvCA,eAAA,GAAkB,SAuCI,CAvCM,cAuCN,GAAA,MAAA,CAAA,GAAA,SAAA;AAOjB,UA5CA,cAAA,CA0DI;EAGJ,EAAA,CAAA,EAAA,MAAA;EAaA,IAAA,CAAA,EAAA,MAAO;EAMF,IAAA,EAAA,MAAA;;AAA0B,KA1EpC,gBAAA,GA0EoC,CAAA,IAAA,EAAA,MAAA,EAAA,GAxE3C,SAwE2C,CAAA,MAAA,GAvErC,cAuEqC,GAvEpB,cAuEoB,GAAA,IAAA,GAAA,SAAA,GAAA,IAAA,CAAA;AAApC,UApEK,oBAAA,CAoEL;EAUQ,IAAA,EAAA,WAAA,GAAA,WAAA;EAKC,OAAA,EAjFV,gBAiFU;;;;;AA6Ba,KAxGtB,QAAA,GAAW,gBAwGW,GAxGQ,oBAwGR;;;;AA4CtB,KA/IA,UAAA,GAAa,MA+Ib,CAAA,MAAA,EAAA,CAAA,MAAA,GA/IsC,eA+ItC,CAAA,EAAA,CAAA;;;;AAiBe,UA3JV,OAAA,CA2JU;;;;ACtNe,KDkE9B,sBAAA,GClE8B,OAAA,GAAA,UAAA,GAAA,UAAA,GAAA,UAAA,GAAA,WAA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