feature: vor und nachteile

This commit is contained in:
Hikyu
2026-05-31 13:54:31 +02:00
parent 552a947a1c
commit e3dad17446
23270 changed files with 3024794 additions and 200 deletions
+224
View File
@@ -0,0 +1,224 @@
'use strict';
const fs = require('node:fs');
const node_path = require('node:path');
const process = require('node:process');
const utils = require('@antfu/utils');
const defu = require('defu');
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
const process__default = /*#__PURE__*/_interopDefaultCompat(process);
const defu__default = /*#__PURE__*/_interopDefaultCompat(defu);
function existsSync(fp) {
try {
fs__default.accessSync(fp, fs.constants.R_OK);
return true;
} catch {
return false;
}
}
async function findUp(paths, options = {}) {
const {
cwd = process__default.cwd(),
stopAt = node_path.parse(cwd).root,
multiple = false,
allowSymlinks = true
} = options;
let current = cwd;
const files = [];
const stat = allowSymlinks ? fs.promises.stat : fs.promises.lstat;
while (current && current !== stopAt) {
for (const path of paths) {
const filepath = node_path.resolve(current, path);
if (existsSync(filepath) && (await stat(filepath)).isFile()) {
files.push(filepath);
if (!multiple)
return files;
}
}
const parent = node_path.dirname(current);
if (parent === current)
break;
current = parent;
}
return files;
}
function interopDefault(mod) {
if (mod == null || typeof mod !== "object" || !("default" in mod) || mod.default == null)
return mod;
const defaultValue = mod.default;
if (typeof defaultValue !== "object")
return defaultValue;
for (const key in mod) {
try {
if (!(key in defaultValue)) {
Object.defineProperty(defaultValue, key, {
enumerable: key !== "default",
configurable: key !== "default",
get() {
return mod[key];
}
});
}
} catch {
}
}
return defaultValue;
}
const defaultExtensions = ["mts", "cts", "ts", "mjs", "cjs", "js", "json", ""];
function createConfigLoader(options) {
const sources = utils.toArray(options.sources || []);
const {
cwd = process__default.cwd(),
merge,
defaults
} = options;
const results = [];
let matchedFiles;
async function findConfigs() {
if (matchedFiles == null)
matchedFiles = [];
matchedFiles.length = 0;
for (const source of sources) {
const { extensions = defaultExtensions } = source;
const flatTargets = utils.toArray(source?.files || []).flatMap(
(file) => !extensions.length ? [file] : extensions.map((i) => i ? `${file}.${i}` : file)
);
const files = await findUp(flatTargets, { cwd, stopAt: options.stopAt, multiple: merge });
matchedFiles.push([source, files]);
}
return matchedFiles.flatMap((i) => i[1]);
}
async function load(force = false) {
if (matchedFiles == null || force)
await findConfigs();
for (const [source, files] of matchedFiles) {
if (!files.length)
continue;
if (!merge) {
const result = await loadConfigFile(files[0], source, options);
if (result) {
return {
config: applyDefaults(result.config, defaults),
sources: result.sources,
dependencies: result.dependencies
};
}
} else {
results.push(
...(await Promise.all(
files.map((file) => loadConfigFile(file, source, options))
)).filter(utils.notNullish)
);
}
}
if (!results.length) {
return {
config: defaults,
sources: []
};
}
return {
config: applyDefaults(...results.map((i) => i.config), defaults),
sources: results.map((i) => i.sources).flat(),
dependencies: results.flatMap((i) => i.dependencies || [])
};
}
return {
load,
findConfigs
};
}
function applyDefaults(...args) {
return defu__default(...args.map((i) => ({ config: i }))).config;
}
async function loadConfig(options) {
return createConfigLoader(options).load();
}
async function loadConfigFile(filepath, source, options) {
let config;
let parser = source.parser || "auto";
let bundleFilepath = filepath;
let code;
async function read() {
if (code == null)
code = await fs.promises.readFile(filepath, "utf-8");
return code;
}
if (source.transform) {
const transformed = await source.transform(await read(), filepath);
if (transformed) {
bundleFilepath = node_path.join(node_path.dirname(filepath), `__unconfig_${node_path.basename(filepath)}`);
await fs.promises.writeFile(bundleFilepath, transformed, "utf-8");
code = transformed;
}
}
if (parser === "auto") {
try {
config = JSON.parse(await read());
parser = "json";
} catch {
parser = "import";
}
}
let dependencies;
try {
if (!config) {
if (typeof parser === "function") {
config = await parser(filepath);
} else if (parser === "require" || parser === "import") {
config = await import('importx').then(async (r) => {
let mod = await r.import(bundleFilepath, {
parentURL: filepath,
cache: false,
loader: source.loader,
fallbackLoaders: source.fallbackLoaders,
loaderOptions: {
...options.importx?.loaderOptions,
...source.importx?.loaderOptions,
jiti: {
interopDefault: true,
...options.importx?.loaderOptions?.jiti,
...source.importx?.loaderOptions?.jiti
}
},
...options.importx,
...source.importx
});
dependencies = r.getModuleInfo(mod)?.dependencies;
mod = interopDefault(mod);
return interopDefault(mod);
});
} else if (parser === "json") {
config = JSON.parse(await read());
}
}
if (!config)
return;
const rewritten = source.rewrite ? await source.rewrite(config, filepath) : config;
if (!rewritten)
return void 0;
return {
config: rewritten,
sources: [filepath],
dependencies
};
} catch (e) {
if (source.skipOnError)
return;
throw e;
} finally {
if (bundleFilepath !== filepath)
await fs.promises.unlink(bundleFilepath).catch();
}
}
exports.createConfigLoader = createConfigLoader;
exports.defaultExtensions = defaultExtensions;
exports.loadConfig = loadConfig;
+12
View File
@@ -0,0 +1,12 @@
import { L as LoadConfigOptions, a as LoadConfigResult } from './shared/unconfig.13feb805.cjs';
export { B as BuiltinParsers, C as CustomParser, I as ImportxOptions, b as LoadConfigSource, S as SearchOptions, d as defaultExtensions } from './shared/unconfig.13feb805.cjs';
import '@antfu/utils';
import 'importx';
declare function createConfigLoader<T>(options: LoadConfigOptions): {
load: (force?: boolean) => Promise<LoadConfigResult<T>>;
findConfigs: () => Promise<string[]>;
};
declare function loadConfig<T>(options: LoadConfigOptions<T>): Promise<LoadConfigResult<T>>;
export { LoadConfigOptions, LoadConfigResult, createConfigLoader, loadConfig };
+12
View File
@@ -0,0 +1,12 @@
import { L as LoadConfigOptions, a as LoadConfigResult } from './shared/unconfig.13feb805.mjs';
export { B as BuiltinParsers, C as CustomParser, I as ImportxOptions, b as LoadConfigSource, S as SearchOptions, d as defaultExtensions } from './shared/unconfig.13feb805.mjs';
import '@antfu/utils';
import 'importx';
declare function createConfigLoader<T>(options: LoadConfigOptions): {
load: (force?: boolean) => Promise<LoadConfigResult<T>>;
findConfigs: () => Promise<string[]>;
};
declare function loadConfig<T>(options: LoadConfigOptions<T>): Promise<LoadConfigResult<T>>;
export { LoadConfigOptions, LoadConfigResult, createConfigLoader, loadConfig };
+12
View File
@@ -0,0 +1,12 @@
import { L as LoadConfigOptions, a as LoadConfigResult } from './shared/unconfig.13feb805.js';
export { B as BuiltinParsers, C as CustomParser, I as ImportxOptions, b as LoadConfigSource, S as SearchOptions, d as defaultExtensions } from './shared/unconfig.13feb805.js';
import '@antfu/utils';
import 'importx';
declare function createConfigLoader<T>(options: LoadConfigOptions): {
load: (force?: boolean) => Promise<LoadConfigResult<T>>;
findConfigs: () => Promise<string[]>;
};
declare function loadConfig<T>(options: LoadConfigOptions<T>): Promise<LoadConfigResult<T>>;
export { LoadConfigOptions, LoadConfigResult, createConfigLoader, loadConfig };
+214
View File
@@ -0,0 +1,214 @@
import fs, { promises, constants } from 'node:fs';
import { parse, resolve, dirname, join, basename } from 'node:path';
import process from 'node:process';
import { toArray, notNullish } from '@antfu/utils';
import defu from 'defu';
function existsSync(fp) {
try {
fs.accessSync(fp, constants.R_OK);
return true;
} catch {
return false;
}
}
async function findUp(paths, options = {}) {
const {
cwd = process.cwd(),
stopAt = parse(cwd).root,
multiple = false,
allowSymlinks = true
} = options;
let current = cwd;
const files = [];
const stat = allowSymlinks ? promises.stat : promises.lstat;
while (current && current !== stopAt) {
for (const path of paths) {
const filepath = resolve(current, path);
if (existsSync(filepath) && (await stat(filepath)).isFile()) {
files.push(filepath);
if (!multiple)
return files;
}
}
const parent = dirname(current);
if (parent === current)
break;
current = parent;
}
return files;
}
function interopDefault(mod) {
if (mod == null || typeof mod !== "object" || !("default" in mod) || mod.default == null)
return mod;
const defaultValue = mod.default;
if (typeof defaultValue !== "object")
return defaultValue;
for (const key in mod) {
try {
if (!(key in defaultValue)) {
Object.defineProperty(defaultValue, key, {
enumerable: key !== "default",
configurable: key !== "default",
get() {
return mod[key];
}
});
}
} catch {
}
}
return defaultValue;
}
const defaultExtensions = ["mts", "cts", "ts", "mjs", "cjs", "js", "json", ""];
function createConfigLoader(options) {
const sources = toArray(options.sources || []);
const {
cwd = process.cwd(),
merge,
defaults
} = options;
const results = [];
let matchedFiles;
async function findConfigs() {
if (matchedFiles == null)
matchedFiles = [];
matchedFiles.length = 0;
for (const source of sources) {
const { extensions = defaultExtensions } = source;
const flatTargets = toArray(source?.files || []).flatMap(
(file) => !extensions.length ? [file] : extensions.map((i) => i ? `${file}.${i}` : file)
);
const files = await findUp(flatTargets, { cwd, stopAt: options.stopAt, multiple: merge });
matchedFiles.push([source, files]);
}
return matchedFiles.flatMap((i) => i[1]);
}
async function load(force = false) {
if (matchedFiles == null || force)
await findConfigs();
for (const [source, files] of matchedFiles) {
if (!files.length)
continue;
if (!merge) {
const result = await loadConfigFile(files[0], source, options);
if (result) {
return {
config: applyDefaults(result.config, defaults),
sources: result.sources,
dependencies: result.dependencies
};
}
} else {
results.push(
...(await Promise.all(
files.map((file) => loadConfigFile(file, source, options))
)).filter(notNullish)
);
}
}
if (!results.length) {
return {
config: defaults,
sources: []
};
}
return {
config: applyDefaults(...results.map((i) => i.config), defaults),
sources: results.map((i) => i.sources).flat(),
dependencies: results.flatMap((i) => i.dependencies || [])
};
}
return {
load,
findConfigs
};
}
function applyDefaults(...args) {
return defu(...args.map((i) => ({ config: i }))).config;
}
async function loadConfig(options) {
return createConfigLoader(options).load();
}
async function loadConfigFile(filepath, source, options) {
let config;
let parser = source.parser || "auto";
let bundleFilepath = filepath;
let code;
async function read() {
if (code == null)
code = await promises.readFile(filepath, "utf-8");
return code;
}
if (source.transform) {
const transformed = await source.transform(await read(), filepath);
if (transformed) {
bundleFilepath = join(dirname(filepath), `__unconfig_${basename(filepath)}`);
await promises.writeFile(bundleFilepath, transformed, "utf-8");
code = transformed;
}
}
if (parser === "auto") {
try {
config = JSON.parse(await read());
parser = "json";
} catch {
parser = "import";
}
}
let dependencies;
try {
if (!config) {
if (typeof parser === "function") {
config = await parser(filepath);
} else if (parser === "require" || parser === "import") {
config = await import('importx').then(async (r) => {
let mod = await r.import(bundleFilepath, {
parentURL: filepath,
cache: false,
loader: source.loader,
fallbackLoaders: source.fallbackLoaders,
loaderOptions: {
...options.importx?.loaderOptions,
...source.importx?.loaderOptions,
jiti: {
interopDefault: true,
...options.importx?.loaderOptions?.jiti,
...source.importx?.loaderOptions?.jiti
}
},
...options.importx,
...source.importx
});
dependencies = r.getModuleInfo(mod)?.dependencies;
mod = interopDefault(mod);
return interopDefault(mod);
});
} else if (parser === "json") {
config = JSON.parse(await read());
}
}
if (!config)
return;
const rewritten = source.rewrite ? await source.rewrite(config, filepath) : config;
if (!rewritten)
return void 0;
return {
config: rewritten,
sources: [filepath],
dependencies
};
} catch (e) {
if (source.skipOnError)
return;
throw e;
} finally {
if (bundleFilepath !== filepath)
await promises.unlink(bundleFilepath).catch();
}
}
export { createConfigLoader, defaultExtensions, loadConfig };
+62
View File
@@ -0,0 +1,62 @@
'use strict';
const utils = require('@antfu/utils');
function sourcePluginFactory(options) {
return {
...options,
transform: (source) => {
const prefix = `
let __unconfig_data;
let __unconfig_stub = function (data = {}) { __unconfig_data = data };
__unconfig_stub.default = (data = {}) => { __unconfig_data = data };
`;
const suffix = "export default __unconfig_data;";
let code = source.replace(new RegExp(`import (.+?) from (['"])${options.targetModule}\\2`), "const $1 = __unconfig_stub;").replace("export default", "const __unconfig_default = ");
if (code.includes("__unconfig_default"))
code += `
if (typeof __unconfig_default === "function") __unconfig_default(...${JSON.stringify(options.parameters || [])});`;
return `${prefix}${code}${suffix}`;
}
};
}
function sourceVitePluginConfig(options) {
const plugins = utils.toArray(options.plugins);
return {
files: ["vite.config"],
async rewrite(obj) {
const config = await (typeof obj === "function" ? obj(...options.parameters || [{ env: {} }, {}]) : obj);
if (!config)
return config;
return config.plugins.find((i) => plugins.includes(i.name) && i?.api?.config)?.api?.config;
}
};
}
function sourceObjectFields(options) {
const fields = utils.toArray(options.fields);
return {
...options,
async rewrite(obj) {
const config = await (typeof obj === "function" ? obj(...options.parameters || []) : obj);
if (!config)
return config;
for (const field of fields) {
if (field in config)
return config[field];
}
}
};
}
function sourcePackageJsonFields(options) {
return sourceObjectFields({
files: ["package.json"],
extensions: [],
parser: "json",
fields: options.fields
});
}
exports.sourceObjectFields = sourceObjectFields;
exports.sourcePackageJsonFields = sourcePackageJsonFields;
exports.sourcePluginFactory = sourcePluginFactory;
exports.sourceVitePluginConfig = sourceVitePluginConfig;
+57
View File
@@ -0,0 +1,57 @@
import * as importx_index from 'importx/index';
import { b as LoadConfigSource, B as BuiltinParsers, C as CustomParser, I as ImportxOptions } from './shared/unconfig.13feb805.cjs';
import { Arrayable } from '@antfu/utils';
import 'importx';
interface SourceVitePluginConfigOptions {
plugins: Arrayable<string>;
/**
* Parameters that passed to when the default export is a function
*/
parameters?: any[];
}
interface SourceObjectFieldOptions extends Omit<LoadConfigSource, 'rewrite'> {
fields: Arrayable<string>;
/**
* Parameters that passed to when the default export is a function
*/
parameters?: any[];
}
interface SourcePluginFactoryOptions extends Omit<LoadConfigSource, 'transform'> {
targetModule: string;
/**
* Parameters that passed to when the default export is a function
*/
parameters?: any[];
}
/**
* Rewrite the config file and extract the options passed to plugin factory
* (e.g. Vite and Rollup plugins)
*/
declare function sourcePluginFactory(options: SourcePluginFactoryOptions): {
transform: (source: string) => string;
targetModule: string;
/**
* Parameters that passed to when the default export is a function
*/
parameters?: any[];
rewrite?: (<F = any>(obj: F, filepath: string) => any) | undefined;
files: Arrayable<string>;
extensions?: string[] | undefined;
parser?: BuiltinParsers | "auto" | CustomParser<any> | undefined;
importx?: ImportxOptions | undefined;
loader?: (importx_index.SupportedLoader | "auto") | undefined;
fallbackLoaders?: (importx_index.SupportedLoader[] | false) | undefined;
skipOnError?: boolean | undefined;
};
declare function sourceVitePluginConfig(options: SourceVitePluginConfigOptions): LoadConfigSource;
/**
* Get one field of the config object
*/
declare function sourceObjectFields(options: SourceObjectFieldOptions): LoadConfigSource;
/**
* Get one field of `package.json`
*/
declare function sourcePackageJsonFields(options: Pick<SourceObjectFieldOptions, 'fields'>): LoadConfigSource;
export { type SourceObjectFieldOptions, type SourcePluginFactoryOptions, type SourceVitePluginConfigOptions, sourceObjectFields, sourcePackageJsonFields, sourcePluginFactory, sourceVitePluginConfig };
+57
View File
@@ -0,0 +1,57 @@
import * as importx_index from 'importx/index';
import { b as LoadConfigSource, B as BuiltinParsers, C as CustomParser, I as ImportxOptions } from './shared/unconfig.13feb805.mjs';
import { Arrayable } from '@antfu/utils';
import 'importx';
interface SourceVitePluginConfigOptions {
plugins: Arrayable<string>;
/**
* Parameters that passed to when the default export is a function
*/
parameters?: any[];
}
interface SourceObjectFieldOptions extends Omit<LoadConfigSource, 'rewrite'> {
fields: Arrayable<string>;
/**
* Parameters that passed to when the default export is a function
*/
parameters?: any[];
}
interface SourcePluginFactoryOptions extends Omit<LoadConfigSource, 'transform'> {
targetModule: string;
/**
* Parameters that passed to when the default export is a function
*/
parameters?: any[];
}
/**
* Rewrite the config file and extract the options passed to plugin factory
* (e.g. Vite and Rollup plugins)
*/
declare function sourcePluginFactory(options: SourcePluginFactoryOptions): {
transform: (source: string) => string;
targetModule: string;
/**
* Parameters that passed to when the default export is a function
*/
parameters?: any[];
rewrite?: (<F = any>(obj: F, filepath: string) => any) | undefined;
files: Arrayable<string>;
extensions?: string[] | undefined;
parser?: BuiltinParsers | "auto" | CustomParser<any> | undefined;
importx?: ImportxOptions | undefined;
loader?: (importx_index.SupportedLoader | "auto") | undefined;
fallbackLoaders?: (importx_index.SupportedLoader[] | false) | undefined;
skipOnError?: boolean | undefined;
};
declare function sourceVitePluginConfig(options: SourceVitePluginConfigOptions): LoadConfigSource;
/**
* Get one field of the config object
*/
declare function sourceObjectFields(options: SourceObjectFieldOptions): LoadConfigSource;
/**
* Get one field of `package.json`
*/
declare function sourcePackageJsonFields(options: Pick<SourceObjectFieldOptions, 'fields'>): LoadConfigSource;
export { type SourceObjectFieldOptions, type SourcePluginFactoryOptions, type SourceVitePluginConfigOptions, sourceObjectFields, sourcePackageJsonFields, sourcePluginFactory, sourceVitePluginConfig };
+57
View File
@@ -0,0 +1,57 @@
import * as importx_index from 'importx/index';
import { b as LoadConfigSource, B as BuiltinParsers, C as CustomParser, I as ImportxOptions } from './shared/unconfig.13feb805.js';
import { Arrayable } from '@antfu/utils';
import 'importx';
interface SourceVitePluginConfigOptions {
plugins: Arrayable<string>;
/**
* Parameters that passed to when the default export is a function
*/
parameters?: any[];
}
interface SourceObjectFieldOptions extends Omit<LoadConfigSource, 'rewrite'> {
fields: Arrayable<string>;
/**
* Parameters that passed to when the default export is a function
*/
parameters?: any[];
}
interface SourcePluginFactoryOptions extends Omit<LoadConfigSource, 'transform'> {
targetModule: string;
/**
* Parameters that passed to when the default export is a function
*/
parameters?: any[];
}
/**
* Rewrite the config file and extract the options passed to plugin factory
* (e.g. Vite and Rollup plugins)
*/
declare function sourcePluginFactory(options: SourcePluginFactoryOptions): {
transform: (source: string) => string;
targetModule: string;
/**
* Parameters that passed to when the default export is a function
*/
parameters?: any[];
rewrite?: (<F = any>(obj: F, filepath: string) => any) | undefined;
files: Arrayable<string>;
extensions?: string[] | undefined;
parser?: BuiltinParsers | "auto" | CustomParser<any> | undefined;
importx?: ImportxOptions | undefined;
loader?: (importx_index.SupportedLoader | "auto") | undefined;
fallbackLoaders?: (importx_index.SupportedLoader[] | false) | undefined;
skipOnError?: boolean | undefined;
};
declare function sourceVitePluginConfig(options: SourceVitePluginConfigOptions): LoadConfigSource;
/**
* Get one field of the config object
*/
declare function sourceObjectFields(options: SourceObjectFieldOptions): LoadConfigSource;
/**
* Get one field of `package.json`
*/
declare function sourcePackageJsonFields(options: Pick<SourceObjectFieldOptions, 'fields'>): LoadConfigSource;
export { type SourceObjectFieldOptions, type SourcePluginFactoryOptions, type SourceVitePluginConfigOptions, sourceObjectFields, sourcePackageJsonFields, sourcePluginFactory, sourceVitePluginConfig };
+57
View File
@@ -0,0 +1,57 @@
import { toArray } from '@antfu/utils';
function sourcePluginFactory(options) {
return {
...options,
transform: (source) => {
const prefix = `
let __unconfig_data;
let __unconfig_stub = function (data = {}) { __unconfig_data = data };
__unconfig_stub.default = (data = {}) => { __unconfig_data = data };
`;
const suffix = "export default __unconfig_data;";
let code = source.replace(new RegExp(`import (.+?) from (['"])${options.targetModule}\\2`), "const $1 = __unconfig_stub;").replace("export default", "const __unconfig_default = ");
if (code.includes("__unconfig_default"))
code += `
if (typeof __unconfig_default === "function") __unconfig_default(...${JSON.stringify(options.parameters || [])});`;
return `${prefix}${code}${suffix}`;
}
};
}
function sourceVitePluginConfig(options) {
const plugins = toArray(options.plugins);
return {
files: ["vite.config"],
async rewrite(obj) {
const config = await (typeof obj === "function" ? obj(...options.parameters || [{ env: {} }, {}]) : obj);
if (!config)
return config;
return config.plugins.find((i) => plugins.includes(i.name) && i?.api?.config)?.api?.config;
}
};
}
function sourceObjectFields(options) {
const fields = toArray(options.fields);
return {
...options,
async rewrite(obj) {
const config = await (typeof obj === "function" ? obj(...options.parameters || []) : obj);
if (!config)
return config;
for (const field of fields) {
if (field in config)
return config[field];
}
}
};
}
function sourcePackageJsonFields(options) {
return sourceObjectFields({
files: ["package.json"],
extensions: [],
parser: "json",
fields: options.fields
});
}
export { sourceObjectFields, sourcePackageJsonFields, sourcePluginFactory, sourceVitePluginConfig };
@@ -0,0 +1,89 @@
import { Awaitable, Arrayable } from '@antfu/utils';
import { ImportxOptions as ImportxOptions$1, SupportedLoader } from 'importx';
declare const defaultExtensions: string[];
type BuiltinParsers = 'require' | 'json' | 'import';
type CustomParser<T> = (filepath: string) => Awaitable<T | undefined>;
type ImportxOptions = Partial<Omit<ImportxOptions$1, 'parentURL'>>;
interface LoadConfigSource<T = any> {
files: Arrayable<string>;
/**
* @default ['mts', 'cts', 'ts', 'mjs', 'cjs', 'js', 'json', '']
*/
extensions?: string[];
/**
* Parser for loading config,
*
* @default 'auto'
*/
parser?: BuiltinParsers | CustomParser<T> | 'auto';
/**
* Importx options for loading TS files.
*/
importx?: ImportxOptions;
/**
* Loader for importing JS and TS files.
*
* @default 'auto'
* @deprecated use `importx.loader` instead
*/
loader?: SupportedLoader | 'auto';
/**
* Fallback loaders when the previous loader failed.
*
* Set to `false` to disable fallback.
*
* Default to importx's default.
* @deprecated use `importx.fallbackLoaders` instead
*/
fallbackLoaders?: SupportedLoader[] | false;
/**
* Rewrite the config object,
* return nullish value to bypassing loading the file
*/
rewrite?: <F = any>(obj: F, filepath: string) => Promise<T | undefined> | T | undefined;
/**
* Transform the source code before loading,
* return nullish value to skip transformation
*/
transform?: (code: string, filepath: string) => Promise<string | undefined> | string | undefined;
/**
* Skip this source if error occurred on loading
*
* @default false
*/
skipOnError?: boolean;
}
interface SearchOptions {
/**
* Root directory
*
* @default process.cwd()
*/
cwd?: string;
/**
* @default path.parse(cwd).root
*/
stopAt?: string;
/**
* Load from multiple sources and merge them
*
* @default false
*/
merge?: boolean;
}
interface LoadConfigOptions<T = any> extends SearchOptions {
sources: Arrayable<LoadConfigSource<T>>;
defaults?: T;
/**
* Importx options for loading TS files.
*/
importx?: ImportxOptions;
}
interface LoadConfigResult<T> {
config: T;
sources: string[];
dependencies?: string[];
}
export { type BuiltinParsers as B, type CustomParser as C, type ImportxOptions as I, type LoadConfigOptions as L, type SearchOptions as S, type LoadConfigResult as a, type LoadConfigSource as b, defaultExtensions as d };
@@ -0,0 +1,89 @@
import { Awaitable, Arrayable } from '@antfu/utils';
import { ImportxOptions as ImportxOptions$1, SupportedLoader } from 'importx';
declare const defaultExtensions: string[];
type BuiltinParsers = 'require' | 'json' | 'import';
type CustomParser<T> = (filepath: string) => Awaitable<T | undefined>;
type ImportxOptions = Partial<Omit<ImportxOptions$1, 'parentURL'>>;
interface LoadConfigSource<T = any> {
files: Arrayable<string>;
/**
* @default ['mts', 'cts', 'ts', 'mjs', 'cjs', 'js', 'json', '']
*/
extensions?: string[];
/**
* Parser for loading config,
*
* @default 'auto'
*/
parser?: BuiltinParsers | CustomParser<T> | 'auto';
/**
* Importx options for loading TS files.
*/
importx?: ImportxOptions;
/**
* Loader for importing JS and TS files.
*
* @default 'auto'
* @deprecated use `importx.loader` instead
*/
loader?: SupportedLoader | 'auto';
/**
* Fallback loaders when the previous loader failed.
*
* Set to `false` to disable fallback.
*
* Default to importx's default.
* @deprecated use `importx.fallbackLoaders` instead
*/
fallbackLoaders?: SupportedLoader[] | false;
/**
* Rewrite the config object,
* return nullish value to bypassing loading the file
*/
rewrite?: <F = any>(obj: F, filepath: string) => Promise<T | undefined> | T | undefined;
/**
* Transform the source code before loading,
* return nullish value to skip transformation
*/
transform?: (code: string, filepath: string) => Promise<string | undefined> | string | undefined;
/**
* Skip this source if error occurred on loading
*
* @default false
*/
skipOnError?: boolean;
}
interface SearchOptions {
/**
* Root directory
*
* @default process.cwd()
*/
cwd?: string;
/**
* @default path.parse(cwd).root
*/
stopAt?: string;
/**
* Load from multiple sources and merge them
*
* @default false
*/
merge?: boolean;
}
interface LoadConfigOptions<T = any> extends SearchOptions {
sources: Arrayable<LoadConfigSource<T>>;
defaults?: T;
/**
* Importx options for loading TS files.
*/
importx?: ImportxOptions;
}
interface LoadConfigResult<T> {
config: T;
sources: string[];
dependencies?: string[];
}
export { type BuiltinParsers as B, type CustomParser as C, type ImportxOptions as I, type LoadConfigOptions as L, type SearchOptions as S, type LoadConfigResult as a, type LoadConfigSource as b, defaultExtensions as d };
+89
View File
@@ -0,0 +1,89 @@
import { Awaitable, Arrayable } from '@antfu/utils';
import { ImportxOptions as ImportxOptions$1, SupportedLoader } from 'importx';
declare const defaultExtensions: string[];
type BuiltinParsers = 'require' | 'json' | 'import';
type CustomParser<T> = (filepath: string) => Awaitable<T | undefined>;
type ImportxOptions = Partial<Omit<ImportxOptions$1, 'parentURL'>>;
interface LoadConfigSource<T = any> {
files: Arrayable<string>;
/**
* @default ['mts', 'cts', 'ts', 'mjs', 'cjs', 'js', 'json', '']
*/
extensions?: string[];
/**
* Parser for loading config,
*
* @default 'auto'
*/
parser?: BuiltinParsers | CustomParser<T> | 'auto';
/**
* Importx options for loading TS files.
*/
importx?: ImportxOptions;
/**
* Loader for importing JS and TS files.
*
* @default 'auto'
* @deprecated use `importx.loader` instead
*/
loader?: SupportedLoader | 'auto';
/**
* Fallback loaders when the previous loader failed.
*
* Set to `false` to disable fallback.
*
* Default to importx's default.
* @deprecated use `importx.fallbackLoaders` instead
*/
fallbackLoaders?: SupportedLoader[] | false;
/**
* Rewrite the config object,
* return nullish value to bypassing loading the file
*/
rewrite?: <F = any>(obj: F, filepath: string) => Promise<T | undefined> | T | undefined;
/**
* Transform the source code before loading,
* return nullish value to skip transformation
*/
transform?: (code: string, filepath: string) => Promise<string | undefined> | string | undefined;
/**
* Skip this source if error occurred on loading
*
* @default false
*/
skipOnError?: boolean;
}
interface SearchOptions {
/**
* Root directory
*
* @default process.cwd()
*/
cwd?: string;
/**
* @default path.parse(cwd).root
*/
stopAt?: string;
/**
* Load from multiple sources and merge them
*
* @default false
*/
merge?: boolean;
}
interface LoadConfigOptions<T = any> extends SearchOptions {
sources: Arrayable<LoadConfigSource<T>>;
defaults?: T;
/**
* Importx options for loading TS files.
*/
importx?: ImportxOptions;
}
interface LoadConfigResult<T> {
config: T;
sources: string[];
dependencies?: string[];
}
export { type BuiltinParsers as B, type CustomParser as C, type ImportxOptions as I, type LoadConfigOptions as L, type SearchOptions as S, type LoadConfigResult as a, type LoadConfigSource as b, defaultExtensions as d };