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.
@@ -0,0 +1,199 @@
1
+ import { Arrayable, Awaitable } from "@antfu/utils";
2
+ import { Import, InlinePreset, PackagePreset, ScanDirExportsOptions, UnimportOptions } from "unimport";
3
+ import { NextConfig } from "next";
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.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","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,WAAA;AAKpB,UDoEL,QAAA,CCpEK;EAAkB;;;;;;;;;;;;;qBDkFnB;;UAGJ,WAAA;;;;;;;;;;;;UAaA,OAAA;;;;;;YAML,UAAU,aAAa,aAAa;;;;;;;;;oBAU5B;;;;qBAKC;;;;wBAKG;;;;;;;;;;oBAYJ,KAAK;;;;mBAKN;;;;;;cAOL,UAAU,UAAU;;;;;;;WAQvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAoCC;;;;;;YAOA;;;;aAKC;;;;gBAKG;;;;;;;;;;;;;;;;;;;;;;iBCtNA,gBAAA,WAA0B,wBAKpB,eAAkB"}
package/dist/index.mjs ADDED
@@ -0,0 +1,324 @@
1
+ import { existsSync, promises } from "node:fs";
2
+ import { dirname, isAbsolute, relative, resolve } from "node:path";
3
+ import process from "node:process";
4
+ import { slash, toArray } from "@antfu/utils";
5
+ import { isPackageExists } from "local-pkg";
6
+ import { createUnimport, resolvePreset } from "unimport";
7
+
8
+ //#region src/presets/react.ts
9
+ const CommonReactAPI = [
10
+ "useState",
11
+ "useCallback",
12
+ "useMemo",
13
+ "useEffect",
14
+ "useRef",
15
+ "useContext",
16
+ "useReducer",
17
+ "useImperativeHandle",
18
+ "useDebugValue",
19
+ "useDeferredValue",
20
+ "useLayoutEffect",
21
+ "useTransition",
22
+ "startTransition",
23
+ "useSyncExternalStore",
24
+ "useInsertionEffect",
25
+ "useId",
26
+ "lazy",
27
+ "memo",
28
+ "createRef",
29
+ "forwardRef"
30
+ ];
31
+ var react_default = { react: [
32
+ ...CommonReactAPI,
33
+ "cache",
34
+ "cacheSignal",
35
+ "createContext",
36
+ "use",
37
+ "useOptimistic",
38
+ "useEffectEvent",
39
+ "useActionState",
40
+ "Fragment",
41
+ "Suspense",
42
+ "Activity"
43
+ ] };
44
+
45
+ //#endregion
46
+ //#region src/presets/react-dom.ts
47
+ var react_dom_default = { "react-dom": [
48
+ "useFormStatus",
49
+ "createPortal",
50
+ "flushSync",
51
+ "preconnect",
52
+ "prefetchDNS",
53
+ "preinit",
54
+ "preinitModule",
55
+ "preload",
56
+ "preloadModule"
57
+ ] };
58
+
59
+ //#endregion
60
+ //#region src/presets/index.ts
61
+ const presets = {
62
+ "react": react_default,
63
+ "react-dom": react_dom_default
64
+ };
65
+
66
+ //#endregion
67
+ //#region src/core/biomelintrc.ts
68
+ function generateBiomeLintConfigs(imports) {
69
+ const config = { javascript: { globals: imports.map((i) => i.as ?? i.name).filter(Boolean).sort() } };
70
+ return JSON.stringify(config, null, 2);
71
+ }
72
+
73
+ //#endregion
74
+ //#region src/core/eslintrc.ts
75
+ function generateESLintConfigs(imports, eslintrc) {
76
+ const eslintConfigs = { globals: {} };
77
+ imports.map((i) => i.as ?? i.name).filter(Boolean).sort().forEach((name) => {
78
+ eslintConfigs.globals[name] = eslintrc.globalsPropValue;
79
+ });
80
+ return JSON.stringify(eslintConfigs, null, 2);
81
+ }
82
+
83
+ //#endregion
84
+ //#region src/core/resolvers.ts
85
+ function normalizeImport(info, name) {
86
+ if (typeof info === "string") return {
87
+ name: "default",
88
+ as: name,
89
+ from: info
90
+ };
91
+ if ("path" in info) return {
92
+ from: info.path,
93
+ as: info.name,
94
+ name: info.importName,
95
+ sideEffects: info.sideEffects
96
+ };
97
+ return {
98
+ name,
99
+ as: name,
100
+ ...info
101
+ };
102
+ }
103
+ async function firstMatchedResolver(resolvers, fullname) {
104
+ let name = fullname;
105
+ for (const resolver of resolvers) {
106
+ if (typeof resolver === "object" && resolver.type === "directive") if (name.startsWith("v")) name = name.slice(1);
107
+ else continue;
108
+ const resolved = await (typeof resolver === "function" ? resolver(name) : resolver.resolve(name));
109
+ if (resolved) return normalizeImport(resolved, fullname);
110
+ }
111
+ }
112
+ function resolversAddon(resolvers) {
113
+ return {
114
+ name: "unplugin-auto-import:resolvers",
115
+ async matchImports(names, matched) {
116
+ if (!resolvers.length) return;
117
+ const dynamic = [];
118
+ const sideEffects = [];
119
+ await Promise.all([...names].map(async (name) => {
120
+ const matchedImport = matched.find((i) => i.as === name);
121
+ if (matchedImport) {
122
+ if ("sideEffects" in matchedImport) sideEffects.push(...toArray(matchedImport.sideEffects).map((i) => normalizeImport(i, "")));
123
+ return;
124
+ }
125
+ const resolved = await firstMatchedResolver(resolvers, name);
126
+ if (resolved) dynamic.push(resolved);
127
+ if (resolved?.sideEffects) sideEffects.push(...toArray(resolved?.sideEffects).map((i) => normalizeImport(i, "")));
128
+ }));
129
+ if (dynamic.length) {
130
+ this.dynamicImports.push(...dynamic);
131
+ this.invalidate();
132
+ }
133
+ if (dynamic.length || sideEffects.length) return [
134
+ ...matched,
135
+ ...dynamic,
136
+ ...sideEffects
137
+ ];
138
+ }
139
+ };
140
+ }
141
+
142
+ //#endregion
143
+ //#region src/core/ctx.ts
144
+ function createContext(options = {}, root = process.cwd()) {
145
+ root = slash(root);
146
+ const { dts: preferDTS = isPackageExists("typescript"), dtsMode = "append", dtsPreserveExts = false, dirsScanOptions, dirs } = options;
147
+ const eslintrc = options.eslintrc || {};
148
+ eslintrc.enabled = eslintrc.enabled === void 0 ? false : eslintrc.enabled;
149
+ eslintrc.filepath = eslintrc.filepath || "./.eslintrc-auto-import.json";
150
+ eslintrc.globalsPropValue = eslintrc.globalsPropValue === void 0 ? true : eslintrc.globalsPropValue;
151
+ const biomelintrc = options.biomelintrc || {};
152
+ biomelintrc.enabled = biomelintrc.enabled !== void 0;
153
+ biomelintrc.filepath = biomelintrc.filepath || "./.biomelintrc-auto-import.json";
154
+ const dumpUnimportItems = options.dumpUnimportItems === true ? "./.unimport-items.json" : options.dumpUnimportItems ?? false;
155
+ const resolvers = options.resolvers ? [options.resolvers].flat(2) : [];
156
+ const injectAtEnd = options.injectAtEnd !== false;
157
+ const unimport = createUnimport({
158
+ imports: [],
159
+ presets: options.packagePresets?.map((p) => typeof p === "string" ? { package: p } : p) ?? [],
160
+ dirsScanOptions: {
161
+ ...dirsScanOptions,
162
+ cwd: root
163
+ },
164
+ dirs,
165
+ injectAtEnd,
166
+ parser: options.parser,
167
+ addons: { addons: [resolversAddon(resolvers), {
168
+ name: "unplugin-auto-import:dts",
169
+ declaration(dts$1) {
170
+ return `${`
171
+ /* eslint-disable */
172
+ /* prettier-ignore */
173
+ // @ts-nocheck
174
+ // noinspection JSUnusedGlobalSymbols
175
+ // Generated by unplugin-auto-import
176
+ // biome-ignore lint: disable
177
+ ${dts$1}`.trim()}\n`;
178
+ }
179
+ }] }
180
+ });
181
+ const importsPromise = flattenImports(options.imports).then((imports) => {
182
+ 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");
183
+ const compare = (left, right) => {
184
+ return right instanceof RegExp ? right.test(left) : right === left;
185
+ };
186
+ options.ignore?.forEach((name) => {
187
+ const i = imports.find((i$1) => compare(i$1.as, name));
188
+ if (i) i.disabled = true;
189
+ });
190
+ options.ignoreDts?.forEach((name) => {
191
+ const i = imports.find((i$1) => compare(i$1.as, name));
192
+ if (i) i.dtsDisabled = true;
193
+ });
194
+ return unimport.getInternalContext().replaceImports(imports);
195
+ });
196
+ const dts = preferDTS === false ? false : preferDTS === true ? resolve(root, "auto-imports.d.ts") : resolve(root, preferDTS);
197
+ const multilineCommentsRE = /\/\*.*?\*\//gs;
198
+ const singlelineCommentsRE = /\/\/.*$/gm;
199
+ const dtsReg = /declare\s+global\s*\{(.*?)[\n\r]\}/s;
200
+ function parseDTS(dts$1) {
201
+ dts$1 = dts$1.replace(multilineCommentsRE, "").replace(singlelineCommentsRE, "");
202
+ const code = dts$1.match(dtsReg)?.[0];
203
+ if (!code) return;
204
+ return Object.fromEntries(Array.from(code.matchAll(/['"]?(const\s*[^\s'"]+)['"]?\s*:\s*(.+?)[,;\r\n]/g)).map((i) => [i[1], i[2]]));
205
+ }
206
+ async function generateDTS(file) {
207
+ await importsPromise;
208
+ const dir = dirname(file);
209
+ const originalDTS = parseDTS(existsSync(file) ? await promises.readFile(file, "utf-8") : "");
210
+ const currentContent = await unimport.generateTypeDeclarations({ resolvePath: (i) => {
211
+ if (i.from.startsWith(".") || isAbsolute(i.from)) {
212
+ const related = slash(dtsPreserveExts ? relative(dir, i.from) : relative(dir, i.from).replace(/\.ts(x)?$/, ""));
213
+ return !related.startsWith(".") ? `./${related}` : related;
214
+ }
215
+ return i.from;
216
+ } });
217
+ if (dtsMode === "append") {
218
+ const currentDTS = parseDTS(currentContent);
219
+ if (originalDTS) {
220
+ Object.assign(originalDTS, currentDTS);
221
+ const dtsList = Object.keys(originalDTS).sort().map((k) => ` ${k}: ${originalDTS[k]}`);
222
+ return currentContent.replace(dtsReg, () => `declare global {\n${dtsList.join("\n")}\n}`);
223
+ }
224
+ }
225
+ return currentContent;
226
+ }
227
+ async function generateESLint() {
228
+ return generateESLintConfigs(await unimport.getImports(), eslintrc);
229
+ }
230
+ async function generateBiomeLint() {
231
+ return generateBiomeLintConfigs(await unimport.getImports());
232
+ }
233
+ async function writeFile(filePath, content = "") {
234
+ await promises.mkdir(dirname(filePath), { recursive: true });
235
+ return await promises.writeFile(filePath, content, "utf-8");
236
+ }
237
+ let lastDTS;
238
+ let lastESLint;
239
+ let lastBiomeLint;
240
+ let lastUnimportItems;
241
+ async function writeConfigFiles() {
242
+ const promises$1 = [];
243
+ if (dts) promises$1.push(generateDTS(dts).then((content) => {
244
+ if (content !== lastDTS) {
245
+ lastDTS = content;
246
+ return writeFile(dts, content);
247
+ }
248
+ }));
249
+ if (eslintrc.enabled && eslintrc.filepath) {
250
+ const filepath = eslintrc.filepath;
251
+ promises$1.push(generateESLint().then(async (content) => {
252
+ if (filepath.endsWith(".cjs")) content = `module.exports = ${content}`;
253
+ else if (filepath.endsWith(".mjs") || filepath.endsWith(".js")) content = `export default ${content}`;
254
+ content = `${content}\n`;
255
+ if (content.trim() !== lastESLint?.trim()) {
256
+ lastESLint = content;
257
+ return writeFile(eslintrc.filepath, content);
258
+ }
259
+ }));
260
+ }
261
+ if (biomelintrc.enabled) promises$1.push(generateBiomeLint().then((content) => {
262
+ if (content !== lastBiomeLint) {
263
+ lastBiomeLint = content;
264
+ return writeFile(biomelintrc.filepath, content);
265
+ }
266
+ }));
267
+ if (dumpUnimportItems) promises$1.push(unimport.getImports().then((items) => {
268
+ if (!dumpUnimportItems) return;
269
+ const content = JSON.stringify(items, null, 2);
270
+ if (content !== lastUnimportItems) {
271
+ lastUnimportItems = content;
272
+ return writeFile(dumpUnimportItems, content);
273
+ }
274
+ }));
275
+ return Promise.all(promises$1);
276
+ }
277
+ return { writeConfigFiles };
278
+ }
279
+ async function flattenImports(map) {
280
+ return (await Promise.all(toArray(map).map(async (definition) => {
281
+ if (typeof definition === "string") {
282
+ if (!presets[definition]) throw new Error(`[auto-import] preset ${definition} not found`);
283
+ definition = presets[definition];
284
+ }
285
+ if ("from" in definition && "imports" in definition) return await resolvePreset(definition);
286
+ else {
287
+ const resolved = [];
288
+ for (const mod of Object.keys(definition)) for (const id of definition[mod]) {
289
+ const meta = { from: mod };
290
+ if (Array.isArray(id)) {
291
+ meta.name = id[0];
292
+ meta.as = id[1];
293
+ } else {
294
+ meta.name = id;
295
+ meta.as = id;
296
+ }
297
+ resolved.push(meta);
298
+ }
299
+ return resolved;
300
+ }
301
+ }))).flat();
302
+ }
303
+
304
+ //#endregion
305
+ //#region src/index.ts
306
+ /**
307
+ * Creates a Next.js auto-import context
308
+ */
309
+ function createAutoImport(options = {}) {
310
+ createContext(options).writeConfigFiles();
311
+ return (nextConfig = {}) => {
312
+ return {
313
+ ...nextConfig,
314
+ experimental: {
315
+ ...nextConfig.experimental,
316
+ swcPlugins: [["swc-plugin-auto-import", { presets: ["react"] }], ...nextConfig.experimental?.swcPlugins ?? []]
317
+ }
318
+ };
319
+ };
320
+ }
321
+
322
+ //#endregion
323
+ export { createAutoImport };
324
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["react","reactDom","eslintConfigs: any","dynamic: ImportExtended[]","sideEffects: ImportExtended[]","eslintrc: ESLintrc","biomelintrc: BiomeLintrc","dts","i","fs","lastDTS: string | undefined","lastESLint: string | undefined","lastBiomeLint: string | undefined","lastUnimportItems: string | undefined","promises: any[]","promises","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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AAmB;AACjC,wBAAoB;AACpB,WAAO,UAAU,mBAAmB,QAAQ;;IAE9C,CACH;AAGH,SAAO,QAAQ,IAAIC,WAAS;;AAG9B,QAAO,EACL,kBACD;;AAGH,eAAsB,eACpB,KACmB;AAkCnB,SAjCiB,MAAM,QAAQ,IAC7B,QAAQ,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,MAAM,cAAc,WAA2B;OACjD;GACL,MAAMC,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/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "next-auto-import",
3
+ "type": "module",
4
+ "version": "0.0.0",
5
+ "description": "Auto-import generator for Next.js projects",
6
+ "author": "Brendan Dash <me@aiwan.run> (https://aiwan.run)",
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/Debbl/next-auto-import#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/Debbl/next-auto-import.git"
12
+ },
13
+ "bugs": "https://github.com/Debbl/next-auto-import/issues",
14
+ "keywords": [
15
+ "next",
16
+ "nextjs",
17
+ "auto-import",
18
+ "typescript",
19
+ "dts"
20
+ ],
21
+ "exports": {
22
+ ".": {
23
+ "import": "./dist/index.mjs",
24
+ "require": "./dist/index.cjs"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "main": "./dist/index.cjs",
29
+ "module": "./dist/index.mjs",
30
+ "types": "./dist/index.d.cts",
31
+ "files": [
32
+ "dist",
33
+ "src"
34
+ ],
35
+ "peerDependencies": {
36
+ "next": "^16.1.1"
37
+ },
38
+ "dependencies": {
39
+ "@antfu/utils": "^9.3.0",
40
+ "local-pkg": "^1.1.2",
41
+ "magic-string": "^0.30.21",
42
+ "swc-plugin-auto-import": "^0.0.1",
43
+ "unimport": "^5.6.0",
44
+ "unplugin-utils": "^0.3.1"
45
+ },
46
+ "devDependencies": {
47
+ "@debbl/eslint-config": "^3.14.3",
48
+ "@types/node": "^24.10.1",
49
+ "bumpp": "^10.3.1",
50
+ "eslint": "^9.39.1",
51
+ "lint-staged": "^16.2.7",
52
+ "simple-git-hooks": "^2.13.1",
53
+ "tsdown": "^0.16.6",
54
+ "typescript": "^5.9.3",
55
+ "vitest": "^4.0.11"
56
+ },
57
+ "simple-git-hooks": {
58
+ "pre-commit": "pnpm lint-staged"
59
+ },
60
+ "lint-staged": {
61
+ "*": "eslint --fix"
62
+ },
63
+ "scripts": {
64
+ "dev": "node ./src/index.ts",
65
+ "build": "tsdown",
66
+ "test": "vitest",
67
+ "release": "pnpm build && bumpp && pnpm publish",
68
+ "typecheck": "tsc --noEmit",
69
+ "lint": "eslint .",
70
+ "lint:fix": "eslint . --fix"
71
+ }
72
+ }
@@ -0,0 +1,13 @@
1
+ import type { Import } from 'unimport'
2
+
3
+ export function generateBiomeLintConfigs(imports: Import[]) {
4
+ const names = imports
5
+ .map((i) => i.as ?? i.name)
6
+ .filter(Boolean)
7
+ .sort()
8
+
9
+ const config = { javascript: { globals: names } }
10
+ const jsonBody = JSON.stringify(config, null, 2)
11
+
12
+ return jsonBody
13
+ }