chore: update frontend build for v1.1.82 [skip ci]

This commit is contained in:
github-actions[bot]
2025-08-06 02:27:53 +00:00
parent 2fd90c5620
commit f3787d775e
19300 changed files with 2 additions and 2351566 deletions

View File

@@ -1,21 +0,0 @@
MIT License
Copyright (c) Pooya Parsa <pooya@pi0.io>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,561 +0,0 @@
# mlly
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Codecov][codecov-src]][codecov-href]
> Missing [ECMAScript module](https://nodejs.org/api/esm.html) utils for Node.js
While ESM Modules are evolving in Node.js ecosystem, there are still
many required features that are still experimental or missing or needed to support ESM. This package tries to fill in the gap.
## Usage
Install npm package:
```sh
# using yarn
yarn add mlly
# using npm
npm install mlly
```
**Note:** Node.js 14+ is recommended.
Import utils:
```js
// ESM
import {} from "mlly";
// CommonJS
const {} = require("mlly");
```
## Resolving ESM modules
Several utilities to make ESM resolution easier:
- Respecting [ECMAScript Resolver algorithm](https://nodejs.org/dist/latest-v14.x/docs/api/esm.html#esm_resolver_algorithm)
- Exposed from Node.js implementation
- Windows paths normalized
- Supporting custom `extensions` and `/index` resolution
- Supporting custom `conditions`
- Support resolving from multiple paths or urls
### `resolve` / `resolveSync`
Resolve a module by respecting [ECMAScript Resolver algorithm](https://nodejs.org/dist/latest-v14.x/docs/api/esm.html#esm_resolver_algorithm)
(using [wooorm/import-meta-resolve](https://github.com/wooorm/import-meta-resolve)).
Additionally supports resolving without extension and `/index` similar to CommonJS.
```js
import { resolve, resolveSync } from "mlly";
// file:///home/user/project/module.mjs
console.log(await resolve("./module.mjs", { url: import.meta.url }));
```
**Resolve options:**
- `url`: URL or string to resolve from (default is `pwd()`)
- `conditions`: Array of conditions used for resolution algorithm (default is `['node', 'import']`)
- `extensions`: Array of additional extensions to check if import failed (default is `['.mjs', '.cjs', '.js', '.json']`)
### `resolvePath` / `resolvePathSync`
Similar to `resolve` but returns a path instead of URL using `fileURLToPath`.
```js
import { resolvePath, resolveSync } from "mlly";
// /home/user/project/module.mjs
console.log(await resolvePath("./module.mjs", { url: import.meta.url }));
```
### `createResolve`
Create a `resolve` function with defaults.
```js
import { createResolve } from "mlly";
const _resolve = createResolve({ url: import.meta.url });
// file:///home/user/project/module.mjs
console.log(await _resolve("./module.mjs"));
```
**Example:** Ponyfill [import.meta.resolve](https://nodejs.org/api/esm.html#esm_import_meta_resolve_specifier_parent):
```js
import { createResolve } from "mlly";
import.meta.resolve = createResolve({ url: import.meta.url });
```
### `resolveImports`
Resolve all static and dynamic imports with relative paths to full resolved path.
```js
import { resolveImports } from "mlly";
// import foo from 'file:///home/user/project/bar.mjs'
console.log(
await resolveImports(`import foo from './bar.mjs'`, { url: import.meta.url }),
);
```
## Syntax Analyzes
### `isValidNodeImport`
Using various syntax detection and heuristics, this method can determine if import is a valid import or not to be imported using dynamic `import()` before hitting an error!
When result is `false`, we usually need a to create a CommonJS require context or add specific rules to the bundler to transform dependency.
```js
import { isValidNodeImport } from "mlly";
// If returns true, we are safe to use `import('some-lib')`
await isValidNodeImport("some-lib", {});
```
**Algorithm:**
- Check import protocol - If is `data:` return `true` (✅ valid) - If is not `node:`, `file:` or `data:`, return `false` (
❌ invalid)
- Resolve full path of import using Node.js [Resolution algorithm](https://nodejs.org/api/esm.html#resolution-algorithm)
- Check full path extension
- If is `.mjs`, `.cjs`, `.node` or `.wasm`, return `true` (✅ valid)
- If is not `.js`, return `false` (❌ invalid)
- If is matching known mixed syntax (`.esm.js`, `.es.js`, etc) return `false` (
❌ invalid)
- Read closest `package.json` file to resolve path
- If `type: 'module'` field is set, return `true` (✅ valid)
- Read source code of resolved path
- Try to detect CommonJS syntax usage
- If yes, return `true` (✅ valid)
- Try to detect ESM syntax usage
- if yes, return `false` (
❌ invalid)
**Notes:**
- There might be still edge cases algorithm cannot cover. It is designed with best-efforts.
- This method also allows using dynamic import of CommonJS libraries considering
Node.js has [Interoperability with CommonJS](https://nodejs.org/api/esm.html#interoperability-with-commonjs).
### `hasESMSyntax`
Detect if code, has usage of ESM syntax (Static `import`, ESM `export` and `import.meta` usage)
```js
import { hasESMSyntax } from "mlly";
hasESMSyntax("export default foo = 123"); // true
```
### `hasCJSSyntax`
Detect if code, has usage of CommonJS syntax (`exports`, `module.exports`, `require` and `global` usage)
```js
import { hasCJSSyntax } from "mlly";
hasCJSSyntax("export default foo = 123"); // false
```
### `detectSyntax`
Tests code against both CJS and ESM.
`isMixed` indicates if both are detected! This is a common case with legacy packages exporting semi-compatible ESM syntax meant to be used by bundlers.
```js
import { detectSyntax } from "mlly";
// { hasESM: true, hasCJS: true, isMixed: true }
detectSyntax('export default require("lodash")');
```
## CommonJS Context
### `createCommonJS`
This utility creates a compatible CommonJS context that is missing in ECMAScript modules.
```js
import { createCommonJS } from "mlly";
const { __dirname, __filename, require } = createCommonJS(import.meta.url);
```
Note: `require` and `require.resolve` implementation are lazy functions. [`createRequire`](https://nodejs.org/api/module.html#module_module_createrequire_filename) will be called on first usage.
## Import/Export Analyzes
Tools to quickly analyze ESM syntax and extract static `import`/`export`
- Super fast Regex based implementation
- Handle most edge cases
- Find all static ESM imports
- Find all dynamic ESM imports
- Parse static import statement
- Find all named, declared and default exports
### `findStaticImports`
Find all static ESM imports.
Example:
```js
import { findStaticImports } from "mlly";
console.log(
findStaticImports(`
// Empty line
import foo, { bar /* foo */ } from 'baz'
`),
);
```
Outputs:
```js
[
{
type: "static",
imports: "foo, { bar /* foo */ } ",
specifier: "baz",
code: "import foo, { bar /* foo */ } from 'baz'",
start: 15,
end: 55,
},
];
```
### `parseStaticImport`
Parse a dynamic ESM import statement previously matched by `findStaticImports`.
Example:
```js
import { findStaticImports, parseStaticImport } from "mlly";
const [match0] = findStaticImports(`import baz, { x, y as z } from 'baz'`);
console.log(parseStaticImport(match0));
```
Outputs:
```js
{
type: 'static',
imports: 'baz, { x, y as z } ',
specifier: 'baz',
code: "import baz, { x, y as z } from 'baz'",
start: 0,
end: 36,
defaultImport: 'baz',
namespacedImport: undefined,
namedImports: { x: 'x', y: 'z' }
}
```
### `findDynamicImports`
Find all dynamic ESM imports.
Example:
```js
import { findDynamicImports } from "mlly";
console.log(
findDynamicImports(`
const foo = await import('bar')
`),
);
```
### `findExports`
```js
import { findExports } from "mlly";
console.log(
findExports(`
export const foo = 'bar'
export { bar, baz }
export default something
`),
);
```
Outputs:
```js
[
{
type: "declaration",
declaration: "const",
name: "foo",
code: "export const foo",
start: 1,
end: 17,
},
{
type: "named",
exports: " bar, baz ",
code: "export { bar, baz }",
start: 26,
end: 45,
names: ["bar", "baz"],
},
{ type: "default", code: "export default ", start: 46, end: 61 },
];
```
### `findExportNames`
Same as `findExports` but returns array of export names.
```js
import { findExportNames } from "mlly";
// [ "foo", "bar", "baz", "default" ]
console.log(
findExportNames(`
export const foo = 'bar'
export { bar, baz }
export default something
`),
);
```
## `resolveModuleExportNames`
Resolves module and reads its contents to extract possible export names using static analyzes.
```js
import { resolveModuleExportNames } from "mlly";
// ["basename", "dirname", ... ]
console.log(await resolveModuleExportNames("mlly"));
```
## Evaluating Modules
Set of utilities to evaluate ESM modules using `data:` imports
- Automatic import rewrite to resolved path using static analyzes
- Allow bypass ESM Cache
- Stack-trace support
- `.json` loader
### `evalModule`
Transform and evaluates module code using dynamic imports.
```js
import { evalModule } from "mlly";
await evalModule(`console.log("Hello World!")`);
await evalModule(
`
import { reverse } from './utils.mjs'
console.log(reverse('!emosewa si sj'))
`,
{ url: import.meta.url },
);
```
**Options:**
- all `resolve` options
- `url`: File URL
### `loadModule`
Dynamically loads a module by evaluating source code.
```js
import { loadModule } from "mlly";
await loadModule("./hello.mjs", { url: import.meta.url });
```
Options are same as `evalModule`.
### `transformModule`
- Resolves all relative imports will be resolved
- All usages of `import.meta.url` will be replaced with `url` or `from` option
```js
import { transformModule } from "mlly";
console.log(transformModule(`console.log(import.meta.url)`), {
url: "test.mjs",
});
```
Options are same as `evalModule`.
## Other Utils
### `fileURLToPath`
Similar to [url.fileURLToPath](https://nodejs.org/api/url.html#url_url_fileurltopath_url) but also converts windows backslash `\` to unix slash `/` and handles if input is already a path.
```js
import { fileURLToPath } from "mlly";
// /foo/bar.js
console.log(fileURLToPath("file:///foo/bar.js"));
// C:/path
console.log(fileURLToPath("file:///C:/path/"));
```
### `pathToFileURL`
Similar to [url.pathToFileURL](https://nodejs.org/api/url.html#urlpathtofileurlpath) but also handles `URL` input and returns a **string** with `file://` protocol.
```js
import { pathToFileURL } from "mlly";
// /foo/bar.js
console.log(pathToFileURL("foo/bar.js"));
// C:/path
console.log(pathToFileURL("C:\\path"));
```
### `normalizeid`
Ensures id has either of `node:`, `data:`, `http:`, `https:` or `file:` protocols.
```js
import { ensureProtocol } from "mlly";
// file:///foo/bar.js
console.log(normalizeid("/foo/bar.js"));
```
### `loadURL`
Read source contents of a URL. (currently only file protocol supported)
```js
import { resolve, loadURL } from "mlly";
const url = await resolve("./index.mjs", { url: import.meta.url });
console.log(await loadURL(url));
```
### `toDataURL`
Convert code to [`data:`](https://nodejs.org/api/esm.html#esm_data_imports) URL using base64 encoding.
```js
import { toDataURL } from "mlly";
console.log(
toDataURL(`
// This is an example
console.log('Hello world')
`),
);
```
### `interopDefault`
Return the default export of a module at the top-level, alongside any other named exports.
```js
// Assuming the shape { default: { foo: 'bar' }, baz: 'qux' }
import myModule from "my-module";
// Returns { foo: 'bar', baz: 'qux' }
console.log(interopDefault(myModule));
```
**Options:**
- `preferNamespace`: In case that `default` value exists but is not extendable (when is string for example), return input as-is (default is `false`, meaning `default`'s value is prefered even if cannot be extended)
### `sanitizeURIComponent`
Replace reserved characters from a segment of URI to make it compatible with [rfc2396](https://datatracker.ietf.org/doc/html/rfc2396).
```js
import { sanitizeURIComponent } from "mlly";
// foo_bar
console.log(sanitizeURIComponent(`foo:bar`));
```
### `sanitizeFilePath`
Sanitize each path of a file name or path with `sanitizeURIComponent` for URI compatibility.
```js
import { sanitizeFilePath } from "mlly";
// C:/te_st/_...slug_.jsx'
console.log(sanitizeFilePath("C:\\te#st\\[...slug].jsx"));
```
### `parseNodeModulePath`
Parses an absolute file path in `node_modules` to three segments:
- `dir`: Path to main directory of package
- `name`: Package name
- `subpath`: The optional package subpath
It returns an empty object (with partial keys) if parsing fails.
```js
import { parseNodeModulePath } from "mlly";
// dir: "/src/a/node_modules/"
// name: "lib"
// subpath: "./dist/index.mjs"
const { dir, name, subpath } = parseNodeModulePath(
"/src/a/node_modules/lib/dist/index.mjs",
);
```
### `lookupNodeModuleSubpath`
Parses an absolute file path in `node_modules` and tries to reverse lookup (or guess) the original package exports subpath for it.
```js
import { lookupNodeModuleSubpath } from "mlly";
// subpath: "./utils"
const subpath = lookupNodeModuleSubpath(
"/src/a/node_modules/lib/dist/utils.mjs",
);
```
## License
[MIT](./LICENSE) - Made with 💛
<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/mlly?style=flat&colorA=18181B&colorB=F0DB4F
[npm-version-href]: https://npmjs.com/package/mlly
[npm-downloads-src]: https://img.shields.io/npm/dm/mlly?style=flat&colorA=18181B&colorB=F0DB4F
[npm-downloads-href]: https://npmjs.com/package/mlly
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/mlly/main?style=flat&colorA=18181B&colorB=F0DB4F
[codecov-href]: https://codecov.io/gh/unjs/mlly

File diff suppressed because it is too large Load Diff

View File

@@ -1,563 +0,0 @@
interface ResolveOptions {
/**
* A URL, path or array of URLs/paths to resolve against.
*/
url?: string | URL | (string | URL)[];
/**
* File extensions to consider when resolving modules.
*/
extensions?: string[];
/**
* Conditions to consider when resolving package exports.
*/
conditions?: string[];
}
/**
* Synchronously resolves a module path based on the options provided.
*
* @param {string} id - The identifier or path of the module to resolve.
* @param {ResolveOptions} [options] - Options to resolve the module. See {@link ResolveOptions}.
* @returns {string} The resolved URL as a string.
*/
declare function resolveSync(id: string, options?: ResolveOptions): string;
/**
* Asynchronously resolves a module path based on the given options.
*
* @param {string} id - The identifier or path of the module to resolve.
* @param {ResolveOptions} [options] - Options for resolving the module. See {@link ResolveOptions}.
* @returns {Promise<string>} A promise to resolve the URL as a string.
*/
declare function resolve(id: string, options?: ResolveOptions): Promise<string>;
/**
* Synchronously resolves a module path to a local file path based on the given options.
*
* @param {string} id - The identifier or path of the module to resolve.
* @param {ResolveOptions} [options] - Options to resolve the module. See {@link ResolveOptions}.
* @returns {string} The resolved file path.
*/
declare function resolvePathSync(id: string, options?: ResolveOptions): string;
/**
* Asynchronously resolves a module path to a local file path based on the options provided.
*
* @param {string} id - The identifier or path of the module to resolve.
* @param {ResolveOptions} [options] - Options for resolving the module. See {@link ResolveOptions}.
* @returns {Promise<string>} A promise to resolve to the file path.
*/
declare function resolvePath(id: string, options?: ResolveOptions): Promise<string>;
/**
* Creates a resolver function with default options that can be used to resolve module identifiers.
*
* @param {ResolveOptions} [defaults] - Default options to use for all resolutions. See {@link ResolveOptions}.
* @returns {Function} A resolver function that takes an identifier and an optional URL, and resolves the identifier using the default options and the given URL.
*/
declare function createResolve(defaults?: ResolveOptions): (id: string, url?: ResolveOptions["url"]) => Promise<string>;
/**
* Parses a node module path to extract the directory, name, and subpath.
*
* @param {string} path - The path to parse.
* @returns {Object} An object containing the directory, module name, and subpath of the node module.
*/
declare function parseNodeModulePath(path: string): {
dir?: undefined;
name?: undefined;
subpath?: undefined;
} | {
dir: string;
name: string;
subpath: string | undefined;
};
/**
* Attempts to reverse engineer a subpath export within a node module.
*
* @param {string} path - The path within the node module.
* @returns {Promise<string | undefined>} A promise that resolves to the detected subpath or undefined if not found.
*/
declare function lookupNodeModuleSubpath(path: string): Promise<string | undefined>;
/**
* Represents a general structure for ECMAScript module imports.
*/
interface ESMImport {
/**
* Specifies the type of import: "static" for static imports and "dynamic" for dynamic imports.
*/
type: "static" | "dynamic";
/**
* The full import declaration code snippet as a string.
*/
code: string;
/**
* The starting position (index) of the import declaration in the source code.
*/
start: number;
/**
* The end position (index) of the import declaration in the source code.
*/
end: number;
}
/**
* Represents a static import declaration in an ECMAScript module.
* Extends {@link ESMImport}.
*/
interface StaticImport extends ESMImport {
/**
* Indicates the type of import, specifically a static import.
*/
type: "static";
/**
* Contains the entire import statement as a string, excluding the module specifier.
*/
imports: string;
/**
* The module specifier from which imports are being brought in.
*/
specifier: string;
}
/**
* Represents a parsed static import declaration with detailed components of the import.
* Extends {@link StaticImport}.
*/
interface ParsedStaticImport extends StaticImport {
/**
* The default import name, if any.
* @optional
*/
defaultImport?: string;
/**
* The namespace import name, if any, using the `* as` syntax.
* @optional
*/
namespacedImport?: string;
/**
* An object representing named imports, with their local aliases if specified.
* Each property key is the original name and its value is the alias.
* @optional
*/
namedImports?: {
[name: string]: string;
};
}
/**
* Represents a dynamic import declaration that is loaded at runtime.
* Extends {@link ESMImport}.
*/
interface DynamicImport extends ESMImport {
/**
* Indicates that this is a dynamic import.
*/
type: "dynamic";
/**
* The expression or path to be dynamically imported, typically a module path or URL.
*/
expression: string;
}
/**
* Represents a type-specific import, primarily used for importing types in TypeScript.
* Extends {@link ESMImport} but omits the 'type' to redefine it specifically for type imports.
*/
interface TypeImport extends Omit<ESMImport, "type"> {
/**
* Specifies that this is a type import.
*/
type: "type";
/**
* Contains the entire type import statement as a string, excluding the module specifier.
*/
imports: string;
/**
* The module specifier from which to import types.
*/
specifier: string;
}
/**
* Represents a general structure for ECMAScript module exports.
*/
interface ESMExport {
/**
* Optional explicit type for complex scenarios, often used internally.
* @optional
*/
_type?: "declaration" | "named" | "default" | "star";
/**
* The type of export (declaration, named, default or star).
*/
type: "declaration" | "named" | "default" | "star";
/**
* The specific type of declaration being exported, if applicable.
* @optional
*/
declarationType?: "let" | "var" | "const" | "enum" | "const enum" | "class" | "function" | "async function";
/**
* The full code snippet of the export statement.
*/
code: string;
/**
* The starting position (index) of the export declaration in the source code.
*/
start: number;
/**
* The end position (index) of the export declaration in the source code.
*/
end: number;
/**
* The name of the variable, function or class being exported, if given explicitly.
* @optional
*/
name?: string;
/**
* The name used for default exports when a specific identifier isn't given.
* @optional
*/
defaultName?: string;
/**
* An array of names to export, applicable to named and destructured exports.
*/
names: string[];
/**
* The module specifier, if any, from which exports are being re-exported.
* @optional
*/
specifier?: string;
}
/**
* Represents a declaration export within an ECMAScript module.
* Extends {@link ESMExport}.
*/
interface DeclarationExport extends ESMExport {
/**
* Indicates that this export is a declaration export.
*/
type: "declaration";
/**
* The declaration string, such as 'let', 'const', 'class', etc., describing what is being exported.
*/
declaration: string;
/**
* The name of the declaration to be exported.
*/
name: string;
}
/**
* Represents a named export within an ECMAScript module.
* Extends {@link ESMExport}.
*/
interface NamedExport extends ESMExport {
/**
* Specifies that this export is a named export.
*/
type: "named";
/**
* The export string, containing all exported identifiers.
*/
exports: string;
/**
* An array of names to export.
*/
names: string[];
/**
* The module specifier, if any, from which exports are being re-exported.
* @optional
*/
specifier?: string;
}
/**
* Represents a standard export within an ECMAScript module.
* Extends {@link ESMExport}.
*/
interface DefaultExport extends ESMExport {
/**
* Specifies that this export is a standard export.
*/
type: "default";
}
/**
* Regular expression to match static import statements in JavaScript/TypeScript code.
* @example `import { foo, bar as baz } from 'module'`
*/
declare const ESM_STATIC_IMPORT_RE: RegExp;
/**
* Regular expression to match dynamic import statements in JavaScript/TypeScript code.
* @example `import('module')`
*/
declare const DYNAMIC_IMPORT_RE: RegExp;
/**
* Regular expression to match various types of export declarations including variables, functions, and classes.
* @example `export const num = 1, str = 'hello'; export class Example {}`
*/
declare const EXPORT_DECAL_RE: RegExp;
/**
* Regular expression to match export declarations specifically for types, interfaces, and type aliases in TypeScript.
* @example `export type Result = { success: boolean; }; export interface User { name: string; age: number; };`
*/
declare const EXPORT_DECAL_TYPE_RE: RegExp;
/**
* Finds all static import statements within the given code string.
* @param {string} code - The source code to search for static imports.
* @returns {StaticImport[]} An array of {@link StaticImport} objects representing each static import found.
*/
declare function findStaticImports(code: string): StaticImport[];
/**
* Searches for dynamic import statements in the given source code.
* @param {string} code - The source to search for dynamic imports in.
* @returns {DynamicImport[]} An array of {@link DynamicImport} objects representing each dynamic import found.
*/
declare function findDynamicImports(code: string): DynamicImport[];
/**
* Identifies and returns all type import statements in the given source code.
* This function is specifically targeted at type imports used in TypeScript.
* @param {string} code - The source code to search for type imports.
* @returns {TypeImport[]} An array of {@link TypeImport} objects representing each type import found.
*/
declare function findTypeImports(code: string): TypeImport[];
/**
* Parses a static import or type import to extract detailed import elements such as default, namespace and named imports.
* @param {StaticImport | TypeImport} matched - The matched import statement to parse. See {@link StaticImport} and {@link TypeImport}.
* @returns {ParsedStaticImport} A structured object representing the parsed static import. See {@link ParsedStaticImport}.
*/
declare function parseStaticImport(matched: StaticImport | TypeImport): ParsedStaticImport;
/**
* Parses a static import or type import to extract detailed import elements such as default, namespace and named imports.
* @param {StaticImport | TypeImport} matched - The matched import statement to parse. See {@link StaticImport} and {@link TypeImport}.
* @returns {ParsedStaticImport} A structured object representing the parsed static import. See {@link ParsedStaticImport}.
*/
declare function parseTypeImport(matched: TypeImport | StaticImport): ParsedStaticImport;
/**
* Identifies all export statements in the supplied source code and categorises them into different types such as declarations, named, default and star exports.
* This function processes the code to capture different forms of export statements and normalise their representation for further processing.
*
* @param {string} code - The source code containing the export statements to be analysed.
* @returns {ESMExport[]} An array of {@link ESMExport} objects representing each export found, properly categorised and structured.
*/
declare function findExports(code: string): ESMExport[];
/**
* Searches specifically for type-related exports in TypeScript code, such as exported interfaces, types, and declarations prefixed with 'declare'.
* This function uses specialised regular expressions to identify type exports and normalises them for consistency.
*
* @param {string} code - The TypeScript source code to search for type exports.
* @returns {ESMExport[]} An array of {@link ESMExport} objects representing each type export found.
*/
declare function findTypeExports(code: string): ESMExport[];
/**
* Extracts and returns a list of all export names from the given source.
* This function uses {@link findExports} to retrieve all types of exports and consolidates their names into a single array.
*
* @param {string} code - The source code to search for export names.
* @returns {string[]} An array containing the names of all exports found in the code.
*/
declare function findExportNames(code: string): string[];
/**
* Asynchronously resolves and returns all export names from a module specified by its module identifier.
* This function recursively resolves all explicitly named and asterisked (* as) exports to fully enumerate the exported identifiers.
*
* @param {string} id - The module identifier to resolve.
* @param {ResolveOptions} [options] - Optional settings for resolving the module path, such as the base URL.
* @returns {Promise<string[]>} A promise that resolves to an array of export names from the module.
*/
declare function resolveModuleExportNames(id: string, options?: ResolveOptions): Promise<string[]>;
/**
* Represents the context of a CommonJS environment, providing node-like module resolution capabilities within a module.
*/
interface CommonjsContext {
/**
* The absolute path to the current module file.
*/
__filename: string;
/**
* The directory name of the current module.
*/
__dirname: string;
/**
* A function to require modules as in CommonJS.
*/
require: NodeRequire;
}
/**
* Creates a CommonJS context for a given module URL, enabling `require`, `__filename` and `__dirname` support similar to Node.js.
* This function dynamically generates a `require` function that is context-aware and bound to the location of the given module URL.
*
* @param {string} url - The URL of the module file to create a context for.
* @returns {CommonjsContext} A context object containing `__filename`, `__dirname` and a custom `require` function. See {@link CommonjsContext}.
*/
declare function createCommonJS(url: string): CommonjsContext;
declare function interopDefault(sourceModule: any, opts?: {
preferNamespace?: boolean;
}): any;
/**
* Options for evaluating or transforming modules, extending resolution options with optional URL specifications.
*/
interface EvaluateOptions extends ResolveOptions {
/**
* The URL of the module, which can be specified to override the URL resolved from the module identifier.
* @optional
*/
url?: string;
}
/**
* Loads a module by resolving its identifier to a URL, fetching the module's code and evaluating it.
*
* @param {string} id - The identifier of the module to load.
* @param {EvaluateOptions} options - Optional parameters to resolve and load the module. See {@link EvaluateOptions}.
* @returns {Promise<any>} A promise to resolve to the evaluated module.
* });
*/
declare function loadModule(id: string, options?: EvaluateOptions): Promise<any>;
/**
* Evaluates JavaScript code as a module using a dynamic import from a data URL.
*
* @param {string} code - The code of the module to evaluate.
* @param {EvaluateOptions} options - Includes the original URL of the module for better error mapping. See {@link EvaluateOptions}.
* @returns {Promise<any>} A promise that resolves to the evaluated module or throws an error if the evaluation fails.
*/
declare function evalModule(code: string, options?: EvaluateOptions): Promise<any>;
/**
* Transform module code to handle specific scenarios, such as converting JSON to a module or rewriting import.meta.url.
*
* @param {string} code - The code of the module to transform.
* @param {EvaluateOptions} options - Options to control how the code is transformed. See {@link EvaluateOptions}.
* @returns {Promise<string>} A promise that resolves to the transformed code.
*/
declare function transformModule(code: string, options?: EvaluateOptions): Promise<string>;
/**
* Resolves all import URLs found within the provided code to their absolute URLs, based on the given options.
*
* @param {string} code - The code containing the import directives to resolve.
* @param {EvaluateOptions} [options] - Options to use for resolving imports. See {@link EvaluateOptions}.
* @returns {Promise<string>} A promise that resolves to the code, replacing import URLs with resolved URLs.
*/
declare function resolveImports(code: string, options?: EvaluateOptions): Promise<string>;
/**
* Options for detecting syntax within a code string.
*/
type DetectSyntaxOptions = {
/**
* Indicates whether comments should be stripped from the code before syntax checking.
* @default false
*/
stripComments?: boolean;
};
/**
* Determines if a given code string contains ECMAScript module syntax.
*
* @param {string} code - The source code to analyse.
* @param {DetectSyntaxOptions} opts - See {@link DetectSyntaxOptions}.
* @returns {boolean} `true` if the code contains ESM syntax, otherwise `false`.
*/
declare function hasESMSyntax(code: string, opts?: DetectSyntaxOptions): boolean;
/**
* Determines if a given string of code contains CommonJS syntax.
*
* @param {string} code - The source code to analyse.
* @param {DetectSyntaxOptions} opts - See {@link DetectSyntaxOptions}.
* @returns {boolean} `true` if the code contains CommonJS syntax, `false` otherwise.
*/
declare function hasCJSSyntax(code: string, opts?: DetectSyntaxOptions): boolean;
/**
* Analyses the supplied code to determine if it contains ECMAScript module syntax, CommonJS syntax, or both.
*
* @param {string} code - The source code to analyse.
* @param {DetectSyntaxOptions} opts - See {@link DetectSyntaxOptions}.
* @returns {object} An object indicating the presence of ESM syntax (`hasESM`), CJS syntax (`hasCJS`) and whether both syntaxes are present (`isMixed`).
*/
declare function detectSyntax(code: string, opts?: DetectSyntaxOptions): {
hasESM: boolean;
hasCJS: boolean;
isMixed: boolean;
};
interface ValidNodeImportOptions extends ResolveOptions {
/**
* The contents of the import, which may be analyzed to see if it contains
* CJS or ESM syntax as a last step in checking whether it is a valid import.
*/
code?: string;
/**
* Protocols that are allowed as valid node imports.
*
* @default ['node', 'file', 'data']
*
*/
allowedProtocols?: Array<string>;
/**
* Whether to strip comments from the code before checking for ESM syntax.
*
* @default false
*/
stripComments?: boolean;
}
/**
* Validates whether a given identifier represents a valid node import, based on its protocol, file extension, and optionally its contents.
*
* @param {string} id - The identifier or URL of the import to validate.
* @param {ValidNodeImportOptions} _options - Options for resolving and validating the import. See {@link ValidNodeImportOptions}.
* @returns {Promise<boolean>} A promise that resolves to `true` if the import is valid, otherwise `false`.
*/
declare function isValidNodeImport(id: string, _options?: ValidNodeImportOptions): Promise<boolean>;
/**
* Converts a file URL to a local file system path with normalized slashes.
*
* @param {string | URL} id - The file URL or local path to convert.
* @returns {string} A normalized file system path.
*/
declare function fileURLToPath(id: string | URL): string;
/**
* Converts a local file system path to a file URL.
*
* @param {string | URL} id - The file system path to convert.
* @returns {string} The resulting file URL as a string.
*/
declare function pathToFileURL(id: string | URL): string;
/**
* Sanitises a component of a URI by replacing invalid characters.
*
* @param {string} name - The URI component to sanitise.
* @param {string} [replacement="_"] - The string to replace invalid characters with.
* @returns {string} The sanitised URI component.
*/
declare function sanitizeURIComponent(name?: string, replacement?: string): string;
/**
* Cleans a file path string by sanitising each component of the path.
*
* @param {string} filePath - The file path to sanitise.
* @returns {string} The sanitised file path.
*/
declare function sanitizeFilePath(filePath?: string): string;
/**
* Normalises a module identifier to ensure it has a protocol if missing, handling built-in modules and file paths.
*
* @param {string} id - The identifier to normalise.
* @returns {string} The normalised identifier with the appropriate protocol.
*/
declare function normalizeid(id: string): string;
/**
* Loads the contents of a file from a URL into a string.
*
* @param {string} url - The URL of the file to load.
* @returns {Promise<string>} A promise that resolves to the content of the file.
*/
declare function loadURL(url: string): Promise<string>;
/**
* Converts a string of code into a data URL that can be used for dynamic imports.
*
* @param {string} code - The string of code to convert.
* @returns {string} The data URL containing the encoded code.
*/
declare function toDataURL(code: string): string;
/**
* Checks if a module identifier matches a Node.js built-in module.
*
* @param {string} id - The identifier to check.
* @returns {boolean} `true` if the identifier is a built-in module, otherwise `false`.
*/
declare function isNodeBuiltin(id?: string): boolean;
/**
* Extracts the protocol portion of a given identifier string.
*
* @param {string} id - The identifier from which to extract the log.
* @returns {string | undefined} The protocol part of the identifier, or undefined if no protocol is present.
*/
declare function getProtocol(id: string): string | undefined;
export { type CommonjsContext, DYNAMIC_IMPORT_RE, type DeclarationExport, type DefaultExport, type DetectSyntaxOptions, type DynamicImport, type ESMExport, type ESMImport, ESM_STATIC_IMPORT_RE, EXPORT_DECAL_RE, EXPORT_DECAL_TYPE_RE, type EvaluateOptions, type NamedExport, type ParsedStaticImport, type ResolveOptions, type StaticImport, type TypeImport, type ValidNodeImportOptions, createCommonJS, createResolve, detectSyntax, evalModule, fileURLToPath, findDynamicImports, findExportNames, findExports, findStaticImports, findTypeExports, findTypeImports, getProtocol, hasCJSSyntax, hasESMSyntax, interopDefault, isNodeBuiltin, isValidNodeImport, loadModule, loadURL, lookupNodeModuleSubpath, normalizeid, parseNodeModulePath, parseStaticImport, parseTypeImport, pathToFileURL, resolve, resolveImports, resolveModuleExportNames, resolvePath, resolvePathSync, resolveSync, sanitizeFilePath, sanitizeURIComponent, toDataURL, transformModule };

View File

@@ -1,563 +0,0 @@
interface ResolveOptions {
/**
* A URL, path or array of URLs/paths to resolve against.
*/
url?: string | URL | (string | URL)[];
/**
* File extensions to consider when resolving modules.
*/
extensions?: string[];
/**
* Conditions to consider when resolving package exports.
*/
conditions?: string[];
}
/**
* Synchronously resolves a module path based on the options provided.
*
* @param {string} id - The identifier or path of the module to resolve.
* @param {ResolveOptions} [options] - Options to resolve the module. See {@link ResolveOptions}.
* @returns {string} The resolved URL as a string.
*/
declare function resolveSync(id: string, options?: ResolveOptions): string;
/**
* Asynchronously resolves a module path based on the given options.
*
* @param {string} id - The identifier or path of the module to resolve.
* @param {ResolveOptions} [options] - Options for resolving the module. See {@link ResolveOptions}.
* @returns {Promise<string>} A promise to resolve the URL as a string.
*/
declare function resolve(id: string, options?: ResolveOptions): Promise<string>;
/**
* Synchronously resolves a module path to a local file path based on the given options.
*
* @param {string} id - The identifier or path of the module to resolve.
* @param {ResolveOptions} [options] - Options to resolve the module. See {@link ResolveOptions}.
* @returns {string} The resolved file path.
*/
declare function resolvePathSync(id: string, options?: ResolveOptions): string;
/**
* Asynchronously resolves a module path to a local file path based on the options provided.
*
* @param {string} id - The identifier or path of the module to resolve.
* @param {ResolveOptions} [options] - Options for resolving the module. See {@link ResolveOptions}.
* @returns {Promise<string>} A promise to resolve to the file path.
*/
declare function resolvePath(id: string, options?: ResolveOptions): Promise<string>;
/**
* Creates a resolver function with default options that can be used to resolve module identifiers.
*
* @param {ResolveOptions} [defaults] - Default options to use for all resolutions. See {@link ResolveOptions}.
* @returns {Function} A resolver function that takes an identifier and an optional URL, and resolves the identifier using the default options and the given URL.
*/
declare function createResolve(defaults?: ResolveOptions): (id: string, url?: ResolveOptions["url"]) => Promise<string>;
/**
* Parses a node module path to extract the directory, name, and subpath.
*
* @param {string} path - The path to parse.
* @returns {Object} An object containing the directory, module name, and subpath of the node module.
*/
declare function parseNodeModulePath(path: string): {
dir?: undefined;
name?: undefined;
subpath?: undefined;
} | {
dir: string;
name: string;
subpath: string | undefined;
};
/**
* Attempts to reverse engineer a subpath export within a node module.
*
* @param {string} path - The path within the node module.
* @returns {Promise<string | undefined>} A promise that resolves to the detected subpath or undefined if not found.
*/
declare function lookupNodeModuleSubpath(path: string): Promise<string | undefined>;
/**
* Represents a general structure for ECMAScript module imports.
*/
interface ESMImport {
/**
* Specifies the type of import: "static" for static imports and "dynamic" for dynamic imports.
*/
type: "static" | "dynamic";
/**
* The full import declaration code snippet as a string.
*/
code: string;
/**
* The starting position (index) of the import declaration in the source code.
*/
start: number;
/**
* The end position (index) of the import declaration in the source code.
*/
end: number;
}
/**
* Represents a static import declaration in an ECMAScript module.
* Extends {@link ESMImport}.
*/
interface StaticImport extends ESMImport {
/**
* Indicates the type of import, specifically a static import.
*/
type: "static";
/**
* Contains the entire import statement as a string, excluding the module specifier.
*/
imports: string;
/**
* The module specifier from which imports are being brought in.
*/
specifier: string;
}
/**
* Represents a parsed static import declaration with detailed components of the import.
* Extends {@link StaticImport}.
*/
interface ParsedStaticImport extends StaticImport {
/**
* The default import name, if any.
* @optional
*/
defaultImport?: string;
/**
* The namespace import name, if any, using the `* as` syntax.
* @optional
*/
namespacedImport?: string;
/**
* An object representing named imports, with their local aliases if specified.
* Each property key is the original name and its value is the alias.
* @optional
*/
namedImports?: {
[name: string]: string;
};
}
/**
* Represents a dynamic import declaration that is loaded at runtime.
* Extends {@link ESMImport}.
*/
interface DynamicImport extends ESMImport {
/**
* Indicates that this is a dynamic import.
*/
type: "dynamic";
/**
* The expression or path to be dynamically imported, typically a module path or URL.
*/
expression: string;
}
/**
* Represents a type-specific import, primarily used for importing types in TypeScript.
* Extends {@link ESMImport} but omits the 'type' to redefine it specifically for type imports.
*/
interface TypeImport extends Omit<ESMImport, "type"> {
/**
* Specifies that this is a type import.
*/
type: "type";
/**
* Contains the entire type import statement as a string, excluding the module specifier.
*/
imports: string;
/**
* The module specifier from which to import types.
*/
specifier: string;
}
/**
* Represents a general structure for ECMAScript module exports.
*/
interface ESMExport {
/**
* Optional explicit type for complex scenarios, often used internally.
* @optional
*/
_type?: "declaration" | "named" | "default" | "star";
/**
* The type of export (declaration, named, default or star).
*/
type: "declaration" | "named" | "default" | "star";
/**
* The specific type of declaration being exported, if applicable.
* @optional
*/
declarationType?: "let" | "var" | "const" | "enum" | "const enum" | "class" | "function" | "async function";
/**
* The full code snippet of the export statement.
*/
code: string;
/**
* The starting position (index) of the export declaration in the source code.
*/
start: number;
/**
* The end position (index) of the export declaration in the source code.
*/
end: number;
/**
* The name of the variable, function or class being exported, if given explicitly.
* @optional
*/
name?: string;
/**
* The name used for default exports when a specific identifier isn't given.
* @optional
*/
defaultName?: string;
/**
* An array of names to export, applicable to named and destructured exports.
*/
names: string[];
/**
* The module specifier, if any, from which exports are being re-exported.
* @optional
*/
specifier?: string;
}
/**
* Represents a declaration export within an ECMAScript module.
* Extends {@link ESMExport}.
*/
interface DeclarationExport extends ESMExport {
/**
* Indicates that this export is a declaration export.
*/
type: "declaration";
/**
* The declaration string, such as 'let', 'const', 'class', etc., describing what is being exported.
*/
declaration: string;
/**
* The name of the declaration to be exported.
*/
name: string;
}
/**
* Represents a named export within an ECMAScript module.
* Extends {@link ESMExport}.
*/
interface NamedExport extends ESMExport {
/**
* Specifies that this export is a named export.
*/
type: "named";
/**
* The export string, containing all exported identifiers.
*/
exports: string;
/**
* An array of names to export.
*/
names: string[];
/**
* The module specifier, if any, from which exports are being re-exported.
* @optional
*/
specifier?: string;
}
/**
* Represents a standard export within an ECMAScript module.
* Extends {@link ESMExport}.
*/
interface DefaultExport extends ESMExport {
/**
* Specifies that this export is a standard export.
*/
type: "default";
}
/**
* Regular expression to match static import statements in JavaScript/TypeScript code.
* @example `import { foo, bar as baz } from 'module'`
*/
declare const ESM_STATIC_IMPORT_RE: RegExp;
/**
* Regular expression to match dynamic import statements in JavaScript/TypeScript code.
* @example `import('module')`
*/
declare const DYNAMIC_IMPORT_RE: RegExp;
/**
* Regular expression to match various types of export declarations including variables, functions, and classes.
* @example `export const num = 1, str = 'hello'; export class Example {}`
*/
declare const EXPORT_DECAL_RE: RegExp;
/**
* Regular expression to match export declarations specifically for types, interfaces, and type aliases in TypeScript.
* @example `export type Result = { success: boolean; }; export interface User { name: string; age: number; };`
*/
declare const EXPORT_DECAL_TYPE_RE: RegExp;
/**
* Finds all static import statements within the given code string.
* @param {string} code - The source code to search for static imports.
* @returns {StaticImport[]} An array of {@link StaticImport} objects representing each static import found.
*/
declare function findStaticImports(code: string): StaticImport[];
/**
* Searches for dynamic import statements in the given source code.
* @param {string} code - The source to search for dynamic imports in.
* @returns {DynamicImport[]} An array of {@link DynamicImport} objects representing each dynamic import found.
*/
declare function findDynamicImports(code: string): DynamicImport[];
/**
* Identifies and returns all type import statements in the given source code.
* This function is specifically targeted at type imports used in TypeScript.
* @param {string} code - The source code to search for type imports.
* @returns {TypeImport[]} An array of {@link TypeImport} objects representing each type import found.
*/
declare function findTypeImports(code: string): TypeImport[];
/**
* Parses a static import or type import to extract detailed import elements such as default, namespace and named imports.
* @param {StaticImport | TypeImport} matched - The matched import statement to parse. See {@link StaticImport} and {@link TypeImport}.
* @returns {ParsedStaticImport} A structured object representing the parsed static import. See {@link ParsedStaticImport}.
*/
declare function parseStaticImport(matched: StaticImport | TypeImport): ParsedStaticImport;
/**
* Parses a static import or type import to extract detailed import elements such as default, namespace and named imports.
* @param {StaticImport | TypeImport} matched - The matched import statement to parse. See {@link StaticImport} and {@link TypeImport}.
* @returns {ParsedStaticImport} A structured object representing the parsed static import. See {@link ParsedStaticImport}.
*/
declare function parseTypeImport(matched: TypeImport | StaticImport): ParsedStaticImport;
/**
* Identifies all export statements in the supplied source code and categorises them into different types such as declarations, named, default and star exports.
* This function processes the code to capture different forms of export statements and normalise their representation for further processing.
*
* @param {string} code - The source code containing the export statements to be analysed.
* @returns {ESMExport[]} An array of {@link ESMExport} objects representing each export found, properly categorised and structured.
*/
declare function findExports(code: string): ESMExport[];
/**
* Searches specifically for type-related exports in TypeScript code, such as exported interfaces, types, and declarations prefixed with 'declare'.
* This function uses specialised regular expressions to identify type exports and normalises them for consistency.
*
* @param {string} code - The TypeScript source code to search for type exports.
* @returns {ESMExport[]} An array of {@link ESMExport} objects representing each type export found.
*/
declare function findTypeExports(code: string): ESMExport[];
/**
* Extracts and returns a list of all export names from the given source.
* This function uses {@link findExports} to retrieve all types of exports and consolidates their names into a single array.
*
* @param {string} code - The source code to search for export names.
* @returns {string[]} An array containing the names of all exports found in the code.
*/
declare function findExportNames(code: string): string[];
/**
* Asynchronously resolves and returns all export names from a module specified by its module identifier.
* This function recursively resolves all explicitly named and asterisked (* as) exports to fully enumerate the exported identifiers.
*
* @param {string} id - The module identifier to resolve.
* @param {ResolveOptions} [options] - Optional settings for resolving the module path, such as the base URL.
* @returns {Promise<string[]>} A promise that resolves to an array of export names from the module.
*/
declare function resolveModuleExportNames(id: string, options?: ResolveOptions): Promise<string[]>;
/**
* Represents the context of a CommonJS environment, providing node-like module resolution capabilities within a module.
*/
interface CommonjsContext {
/**
* The absolute path to the current module file.
*/
__filename: string;
/**
* The directory name of the current module.
*/
__dirname: string;
/**
* A function to require modules as in CommonJS.
*/
require: NodeRequire;
}
/**
* Creates a CommonJS context for a given module URL, enabling `require`, `__filename` and `__dirname` support similar to Node.js.
* This function dynamically generates a `require` function that is context-aware and bound to the location of the given module URL.
*
* @param {string} url - The URL of the module file to create a context for.
* @returns {CommonjsContext} A context object containing `__filename`, `__dirname` and a custom `require` function. See {@link CommonjsContext}.
*/
declare function createCommonJS(url: string): CommonjsContext;
declare function interopDefault(sourceModule: any, opts?: {
preferNamespace?: boolean;
}): any;
/**
* Options for evaluating or transforming modules, extending resolution options with optional URL specifications.
*/
interface EvaluateOptions extends ResolveOptions {
/**
* The URL of the module, which can be specified to override the URL resolved from the module identifier.
* @optional
*/
url?: string;
}
/**
* Loads a module by resolving its identifier to a URL, fetching the module's code and evaluating it.
*
* @param {string} id - The identifier of the module to load.
* @param {EvaluateOptions} options - Optional parameters to resolve and load the module. See {@link EvaluateOptions}.
* @returns {Promise<any>} A promise to resolve to the evaluated module.
* });
*/
declare function loadModule(id: string, options?: EvaluateOptions): Promise<any>;
/**
* Evaluates JavaScript code as a module using a dynamic import from a data URL.
*
* @param {string} code - The code of the module to evaluate.
* @param {EvaluateOptions} options - Includes the original URL of the module for better error mapping. See {@link EvaluateOptions}.
* @returns {Promise<any>} A promise that resolves to the evaluated module or throws an error if the evaluation fails.
*/
declare function evalModule(code: string, options?: EvaluateOptions): Promise<any>;
/**
* Transform module code to handle specific scenarios, such as converting JSON to a module or rewriting import.meta.url.
*
* @param {string} code - The code of the module to transform.
* @param {EvaluateOptions} options - Options to control how the code is transformed. See {@link EvaluateOptions}.
* @returns {Promise<string>} A promise that resolves to the transformed code.
*/
declare function transformModule(code: string, options?: EvaluateOptions): Promise<string>;
/**
* Resolves all import URLs found within the provided code to their absolute URLs, based on the given options.
*
* @param {string} code - The code containing the import directives to resolve.
* @param {EvaluateOptions} [options] - Options to use for resolving imports. See {@link EvaluateOptions}.
* @returns {Promise<string>} A promise that resolves to the code, replacing import URLs with resolved URLs.
*/
declare function resolveImports(code: string, options?: EvaluateOptions): Promise<string>;
/**
* Options for detecting syntax within a code string.
*/
type DetectSyntaxOptions = {
/**
* Indicates whether comments should be stripped from the code before syntax checking.
* @default false
*/
stripComments?: boolean;
};
/**
* Determines if a given code string contains ECMAScript module syntax.
*
* @param {string} code - The source code to analyse.
* @param {DetectSyntaxOptions} opts - See {@link DetectSyntaxOptions}.
* @returns {boolean} `true` if the code contains ESM syntax, otherwise `false`.
*/
declare function hasESMSyntax(code: string, opts?: DetectSyntaxOptions): boolean;
/**
* Determines if a given string of code contains CommonJS syntax.
*
* @param {string} code - The source code to analyse.
* @param {DetectSyntaxOptions} opts - See {@link DetectSyntaxOptions}.
* @returns {boolean} `true` if the code contains CommonJS syntax, `false` otherwise.
*/
declare function hasCJSSyntax(code: string, opts?: DetectSyntaxOptions): boolean;
/**
* Analyses the supplied code to determine if it contains ECMAScript module syntax, CommonJS syntax, or both.
*
* @param {string} code - The source code to analyse.
* @param {DetectSyntaxOptions} opts - See {@link DetectSyntaxOptions}.
* @returns {object} An object indicating the presence of ESM syntax (`hasESM`), CJS syntax (`hasCJS`) and whether both syntaxes are present (`isMixed`).
*/
declare function detectSyntax(code: string, opts?: DetectSyntaxOptions): {
hasESM: boolean;
hasCJS: boolean;
isMixed: boolean;
};
interface ValidNodeImportOptions extends ResolveOptions {
/**
* The contents of the import, which may be analyzed to see if it contains
* CJS or ESM syntax as a last step in checking whether it is a valid import.
*/
code?: string;
/**
* Protocols that are allowed as valid node imports.
*
* @default ['node', 'file', 'data']
*
*/
allowedProtocols?: Array<string>;
/**
* Whether to strip comments from the code before checking for ESM syntax.
*
* @default false
*/
stripComments?: boolean;
}
/**
* Validates whether a given identifier represents a valid node import, based on its protocol, file extension, and optionally its contents.
*
* @param {string} id - The identifier or URL of the import to validate.
* @param {ValidNodeImportOptions} _options - Options for resolving and validating the import. See {@link ValidNodeImportOptions}.
* @returns {Promise<boolean>} A promise that resolves to `true` if the import is valid, otherwise `false`.
*/
declare function isValidNodeImport(id: string, _options?: ValidNodeImportOptions): Promise<boolean>;
/**
* Converts a file URL to a local file system path with normalized slashes.
*
* @param {string | URL} id - The file URL or local path to convert.
* @returns {string} A normalized file system path.
*/
declare function fileURLToPath(id: string | URL): string;
/**
* Converts a local file system path to a file URL.
*
* @param {string | URL} id - The file system path to convert.
* @returns {string} The resulting file URL as a string.
*/
declare function pathToFileURL(id: string | URL): string;
/**
* Sanitises a component of a URI by replacing invalid characters.
*
* @param {string} name - The URI component to sanitise.
* @param {string} [replacement="_"] - The string to replace invalid characters with.
* @returns {string} The sanitised URI component.
*/
declare function sanitizeURIComponent(name?: string, replacement?: string): string;
/**
* Cleans a file path string by sanitising each component of the path.
*
* @param {string} filePath - The file path to sanitise.
* @returns {string} The sanitised file path.
*/
declare function sanitizeFilePath(filePath?: string): string;
/**
* Normalises a module identifier to ensure it has a protocol if missing, handling built-in modules and file paths.
*
* @param {string} id - The identifier to normalise.
* @returns {string} The normalised identifier with the appropriate protocol.
*/
declare function normalizeid(id: string): string;
/**
* Loads the contents of a file from a URL into a string.
*
* @param {string} url - The URL of the file to load.
* @returns {Promise<string>} A promise that resolves to the content of the file.
*/
declare function loadURL(url: string): Promise<string>;
/**
* Converts a string of code into a data URL that can be used for dynamic imports.
*
* @param {string} code - The string of code to convert.
* @returns {string} The data URL containing the encoded code.
*/
declare function toDataURL(code: string): string;
/**
* Checks if a module identifier matches a Node.js built-in module.
*
* @param {string} id - The identifier to check.
* @returns {boolean} `true` if the identifier is a built-in module, otherwise `false`.
*/
declare function isNodeBuiltin(id?: string): boolean;
/**
* Extracts the protocol portion of a given identifier string.
*
* @param {string} id - The identifier from which to extract the log.
* @returns {string | undefined} The protocol part of the identifier, or undefined if no protocol is present.
*/
declare function getProtocol(id: string): string | undefined;
export { type CommonjsContext, DYNAMIC_IMPORT_RE, type DeclarationExport, type DefaultExport, type DetectSyntaxOptions, type DynamicImport, type ESMExport, type ESMImport, ESM_STATIC_IMPORT_RE, EXPORT_DECAL_RE, EXPORT_DECAL_TYPE_RE, type EvaluateOptions, type NamedExport, type ParsedStaticImport, type ResolveOptions, type StaticImport, type TypeImport, type ValidNodeImportOptions, createCommonJS, createResolve, detectSyntax, evalModule, fileURLToPath, findDynamicImports, findExportNames, findExports, findStaticImports, findTypeExports, findTypeImports, getProtocol, hasCJSSyntax, hasESMSyntax, interopDefault, isNodeBuiltin, isValidNodeImport, loadModule, loadURL, lookupNodeModuleSubpath, normalizeid, parseNodeModulePath, parseStaticImport, parseTypeImport, pathToFileURL, resolve, resolveImports, resolveModuleExportNames, resolvePath, resolvePathSync, resolveSync, sanitizeFilePath, sanitizeURIComponent, toDataURL, transformModule };

View File

@@ -1,563 +0,0 @@
interface ResolveOptions {
/**
* A URL, path or array of URLs/paths to resolve against.
*/
url?: string | URL | (string | URL)[];
/**
* File extensions to consider when resolving modules.
*/
extensions?: string[];
/**
* Conditions to consider when resolving package exports.
*/
conditions?: string[];
}
/**
* Synchronously resolves a module path based on the options provided.
*
* @param {string} id - The identifier or path of the module to resolve.
* @param {ResolveOptions} [options] - Options to resolve the module. See {@link ResolveOptions}.
* @returns {string} The resolved URL as a string.
*/
declare function resolveSync(id: string, options?: ResolveOptions): string;
/**
* Asynchronously resolves a module path based on the given options.
*
* @param {string} id - The identifier or path of the module to resolve.
* @param {ResolveOptions} [options] - Options for resolving the module. See {@link ResolveOptions}.
* @returns {Promise<string>} A promise to resolve the URL as a string.
*/
declare function resolve(id: string, options?: ResolveOptions): Promise<string>;
/**
* Synchronously resolves a module path to a local file path based on the given options.
*
* @param {string} id - The identifier or path of the module to resolve.
* @param {ResolveOptions} [options] - Options to resolve the module. See {@link ResolveOptions}.
* @returns {string} The resolved file path.
*/
declare function resolvePathSync(id: string, options?: ResolveOptions): string;
/**
* Asynchronously resolves a module path to a local file path based on the options provided.
*
* @param {string} id - The identifier or path of the module to resolve.
* @param {ResolveOptions} [options] - Options for resolving the module. See {@link ResolveOptions}.
* @returns {Promise<string>} A promise to resolve to the file path.
*/
declare function resolvePath(id: string, options?: ResolveOptions): Promise<string>;
/**
* Creates a resolver function with default options that can be used to resolve module identifiers.
*
* @param {ResolveOptions} [defaults] - Default options to use for all resolutions. See {@link ResolveOptions}.
* @returns {Function} A resolver function that takes an identifier and an optional URL, and resolves the identifier using the default options and the given URL.
*/
declare function createResolve(defaults?: ResolveOptions): (id: string, url?: ResolveOptions["url"]) => Promise<string>;
/**
* Parses a node module path to extract the directory, name, and subpath.
*
* @param {string} path - The path to parse.
* @returns {Object} An object containing the directory, module name, and subpath of the node module.
*/
declare function parseNodeModulePath(path: string): {
dir?: undefined;
name?: undefined;
subpath?: undefined;
} | {
dir: string;
name: string;
subpath: string | undefined;
};
/**
* Attempts to reverse engineer a subpath export within a node module.
*
* @param {string} path - The path within the node module.
* @returns {Promise<string | undefined>} A promise that resolves to the detected subpath or undefined if not found.
*/
declare function lookupNodeModuleSubpath(path: string): Promise<string | undefined>;
/**
* Represents a general structure for ECMAScript module imports.
*/
interface ESMImport {
/**
* Specifies the type of import: "static" for static imports and "dynamic" for dynamic imports.
*/
type: "static" | "dynamic";
/**
* The full import declaration code snippet as a string.
*/
code: string;
/**
* The starting position (index) of the import declaration in the source code.
*/
start: number;
/**
* The end position (index) of the import declaration in the source code.
*/
end: number;
}
/**
* Represents a static import declaration in an ECMAScript module.
* Extends {@link ESMImport}.
*/
interface StaticImport extends ESMImport {
/**
* Indicates the type of import, specifically a static import.
*/
type: "static";
/**
* Contains the entire import statement as a string, excluding the module specifier.
*/
imports: string;
/**
* The module specifier from which imports are being brought in.
*/
specifier: string;
}
/**
* Represents a parsed static import declaration with detailed components of the import.
* Extends {@link StaticImport}.
*/
interface ParsedStaticImport extends StaticImport {
/**
* The default import name, if any.
* @optional
*/
defaultImport?: string;
/**
* The namespace import name, if any, using the `* as` syntax.
* @optional
*/
namespacedImport?: string;
/**
* An object representing named imports, with their local aliases if specified.
* Each property key is the original name and its value is the alias.
* @optional
*/
namedImports?: {
[name: string]: string;
};
}
/**
* Represents a dynamic import declaration that is loaded at runtime.
* Extends {@link ESMImport}.
*/
interface DynamicImport extends ESMImport {
/**
* Indicates that this is a dynamic import.
*/
type: "dynamic";
/**
* The expression or path to be dynamically imported, typically a module path or URL.
*/
expression: string;
}
/**
* Represents a type-specific import, primarily used for importing types in TypeScript.
* Extends {@link ESMImport} but omits the 'type' to redefine it specifically for type imports.
*/
interface TypeImport extends Omit<ESMImport, "type"> {
/**
* Specifies that this is a type import.
*/
type: "type";
/**
* Contains the entire type import statement as a string, excluding the module specifier.
*/
imports: string;
/**
* The module specifier from which to import types.
*/
specifier: string;
}
/**
* Represents a general structure for ECMAScript module exports.
*/
interface ESMExport {
/**
* Optional explicit type for complex scenarios, often used internally.
* @optional
*/
_type?: "declaration" | "named" | "default" | "star";
/**
* The type of export (declaration, named, default or star).
*/
type: "declaration" | "named" | "default" | "star";
/**
* The specific type of declaration being exported, if applicable.
* @optional
*/
declarationType?: "let" | "var" | "const" | "enum" | "const enum" | "class" | "function" | "async function";
/**
* The full code snippet of the export statement.
*/
code: string;
/**
* The starting position (index) of the export declaration in the source code.
*/
start: number;
/**
* The end position (index) of the export declaration in the source code.
*/
end: number;
/**
* The name of the variable, function or class being exported, if given explicitly.
* @optional
*/
name?: string;
/**
* The name used for default exports when a specific identifier isn't given.
* @optional
*/
defaultName?: string;
/**
* An array of names to export, applicable to named and destructured exports.
*/
names: string[];
/**
* The module specifier, if any, from which exports are being re-exported.
* @optional
*/
specifier?: string;
}
/**
* Represents a declaration export within an ECMAScript module.
* Extends {@link ESMExport}.
*/
interface DeclarationExport extends ESMExport {
/**
* Indicates that this export is a declaration export.
*/
type: "declaration";
/**
* The declaration string, such as 'let', 'const', 'class', etc., describing what is being exported.
*/
declaration: string;
/**
* The name of the declaration to be exported.
*/
name: string;
}
/**
* Represents a named export within an ECMAScript module.
* Extends {@link ESMExport}.
*/
interface NamedExport extends ESMExport {
/**
* Specifies that this export is a named export.
*/
type: "named";
/**
* The export string, containing all exported identifiers.
*/
exports: string;
/**
* An array of names to export.
*/
names: string[];
/**
* The module specifier, if any, from which exports are being re-exported.
* @optional
*/
specifier?: string;
}
/**
* Represents a standard export within an ECMAScript module.
* Extends {@link ESMExport}.
*/
interface DefaultExport extends ESMExport {
/**
* Specifies that this export is a standard export.
*/
type: "default";
}
/**
* Regular expression to match static import statements in JavaScript/TypeScript code.
* @example `import { foo, bar as baz } from 'module'`
*/
declare const ESM_STATIC_IMPORT_RE: RegExp;
/**
* Regular expression to match dynamic import statements in JavaScript/TypeScript code.
* @example `import('module')`
*/
declare const DYNAMIC_IMPORT_RE: RegExp;
/**
* Regular expression to match various types of export declarations including variables, functions, and classes.
* @example `export const num = 1, str = 'hello'; export class Example {}`
*/
declare const EXPORT_DECAL_RE: RegExp;
/**
* Regular expression to match export declarations specifically for types, interfaces, and type aliases in TypeScript.
* @example `export type Result = { success: boolean; }; export interface User { name: string; age: number; };`
*/
declare const EXPORT_DECAL_TYPE_RE: RegExp;
/**
* Finds all static import statements within the given code string.
* @param {string} code - The source code to search for static imports.
* @returns {StaticImport[]} An array of {@link StaticImport} objects representing each static import found.
*/
declare function findStaticImports(code: string): StaticImport[];
/**
* Searches for dynamic import statements in the given source code.
* @param {string} code - The source to search for dynamic imports in.
* @returns {DynamicImport[]} An array of {@link DynamicImport} objects representing each dynamic import found.
*/
declare function findDynamicImports(code: string): DynamicImport[];
/**
* Identifies and returns all type import statements in the given source code.
* This function is specifically targeted at type imports used in TypeScript.
* @param {string} code - The source code to search for type imports.
* @returns {TypeImport[]} An array of {@link TypeImport} objects representing each type import found.
*/
declare function findTypeImports(code: string): TypeImport[];
/**
* Parses a static import or type import to extract detailed import elements such as default, namespace and named imports.
* @param {StaticImport | TypeImport} matched - The matched import statement to parse. See {@link StaticImport} and {@link TypeImport}.
* @returns {ParsedStaticImport} A structured object representing the parsed static import. See {@link ParsedStaticImport}.
*/
declare function parseStaticImport(matched: StaticImport | TypeImport): ParsedStaticImport;
/**
* Parses a static import or type import to extract detailed import elements such as default, namespace and named imports.
* @param {StaticImport | TypeImport} matched - The matched import statement to parse. See {@link StaticImport} and {@link TypeImport}.
* @returns {ParsedStaticImport} A structured object representing the parsed static import. See {@link ParsedStaticImport}.
*/
declare function parseTypeImport(matched: TypeImport | StaticImport): ParsedStaticImport;
/**
* Identifies all export statements in the supplied source code and categorises them into different types such as declarations, named, default and star exports.
* This function processes the code to capture different forms of export statements and normalise their representation for further processing.
*
* @param {string} code - The source code containing the export statements to be analysed.
* @returns {ESMExport[]} An array of {@link ESMExport} objects representing each export found, properly categorised and structured.
*/
declare function findExports(code: string): ESMExport[];
/**
* Searches specifically for type-related exports in TypeScript code, such as exported interfaces, types, and declarations prefixed with 'declare'.
* This function uses specialised regular expressions to identify type exports and normalises them for consistency.
*
* @param {string} code - The TypeScript source code to search for type exports.
* @returns {ESMExport[]} An array of {@link ESMExport} objects representing each type export found.
*/
declare function findTypeExports(code: string): ESMExport[];
/**
* Extracts and returns a list of all export names from the given source.
* This function uses {@link findExports} to retrieve all types of exports and consolidates their names into a single array.
*
* @param {string} code - The source code to search for export names.
* @returns {string[]} An array containing the names of all exports found in the code.
*/
declare function findExportNames(code: string): string[];
/**
* Asynchronously resolves and returns all export names from a module specified by its module identifier.
* This function recursively resolves all explicitly named and asterisked (* as) exports to fully enumerate the exported identifiers.
*
* @param {string} id - The module identifier to resolve.
* @param {ResolveOptions} [options] - Optional settings for resolving the module path, such as the base URL.
* @returns {Promise<string[]>} A promise that resolves to an array of export names from the module.
*/
declare function resolveModuleExportNames(id: string, options?: ResolveOptions): Promise<string[]>;
/**
* Represents the context of a CommonJS environment, providing node-like module resolution capabilities within a module.
*/
interface CommonjsContext {
/**
* The absolute path to the current module file.
*/
__filename: string;
/**
* The directory name of the current module.
*/
__dirname: string;
/**
* A function to require modules as in CommonJS.
*/
require: NodeRequire;
}
/**
* Creates a CommonJS context for a given module URL, enabling `require`, `__filename` and `__dirname` support similar to Node.js.
* This function dynamically generates a `require` function that is context-aware and bound to the location of the given module URL.
*
* @param {string} url - The URL of the module file to create a context for.
* @returns {CommonjsContext} A context object containing `__filename`, `__dirname` and a custom `require` function. See {@link CommonjsContext}.
*/
declare function createCommonJS(url: string): CommonjsContext;
declare function interopDefault(sourceModule: any, opts?: {
preferNamespace?: boolean;
}): any;
/**
* Options for evaluating or transforming modules, extending resolution options with optional URL specifications.
*/
interface EvaluateOptions extends ResolveOptions {
/**
* The URL of the module, which can be specified to override the URL resolved from the module identifier.
* @optional
*/
url?: string;
}
/**
* Loads a module by resolving its identifier to a URL, fetching the module's code and evaluating it.
*
* @param {string} id - The identifier of the module to load.
* @param {EvaluateOptions} options - Optional parameters to resolve and load the module. See {@link EvaluateOptions}.
* @returns {Promise<any>} A promise to resolve to the evaluated module.
* });
*/
declare function loadModule(id: string, options?: EvaluateOptions): Promise<any>;
/**
* Evaluates JavaScript code as a module using a dynamic import from a data URL.
*
* @param {string} code - The code of the module to evaluate.
* @param {EvaluateOptions} options - Includes the original URL of the module for better error mapping. See {@link EvaluateOptions}.
* @returns {Promise<any>} A promise that resolves to the evaluated module or throws an error if the evaluation fails.
*/
declare function evalModule(code: string, options?: EvaluateOptions): Promise<any>;
/**
* Transform module code to handle specific scenarios, such as converting JSON to a module or rewriting import.meta.url.
*
* @param {string} code - The code of the module to transform.
* @param {EvaluateOptions} options - Options to control how the code is transformed. See {@link EvaluateOptions}.
* @returns {Promise<string>} A promise that resolves to the transformed code.
*/
declare function transformModule(code: string, options?: EvaluateOptions): Promise<string>;
/**
* Resolves all import URLs found within the provided code to their absolute URLs, based on the given options.
*
* @param {string} code - The code containing the import directives to resolve.
* @param {EvaluateOptions} [options] - Options to use for resolving imports. See {@link EvaluateOptions}.
* @returns {Promise<string>} A promise that resolves to the code, replacing import URLs with resolved URLs.
*/
declare function resolveImports(code: string, options?: EvaluateOptions): Promise<string>;
/**
* Options for detecting syntax within a code string.
*/
type DetectSyntaxOptions = {
/**
* Indicates whether comments should be stripped from the code before syntax checking.
* @default false
*/
stripComments?: boolean;
};
/**
* Determines if a given code string contains ECMAScript module syntax.
*
* @param {string} code - The source code to analyse.
* @param {DetectSyntaxOptions} opts - See {@link DetectSyntaxOptions}.
* @returns {boolean} `true` if the code contains ESM syntax, otherwise `false`.
*/
declare function hasESMSyntax(code: string, opts?: DetectSyntaxOptions): boolean;
/**
* Determines if a given string of code contains CommonJS syntax.
*
* @param {string} code - The source code to analyse.
* @param {DetectSyntaxOptions} opts - See {@link DetectSyntaxOptions}.
* @returns {boolean} `true` if the code contains CommonJS syntax, `false` otherwise.
*/
declare function hasCJSSyntax(code: string, opts?: DetectSyntaxOptions): boolean;
/**
* Analyses the supplied code to determine if it contains ECMAScript module syntax, CommonJS syntax, or both.
*
* @param {string} code - The source code to analyse.
* @param {DetectSyntaxOptions} opts - See {@link DetectSyntaxOptions}.
* @returns {object} An object indicating the presence of ESM syntax (`hasESM`), CJS syntax (`hasCJS`) and whether both syntaxes are present (`isMixed`).
*/
declare function detectSyntax(code: string, opts?: DetectSyntaxOptions): {
hasESM: boolean;
hasCJS: boolean;
isMixed: boolean;
};
interface ValidNodeImportOptions extends ResolveOptions {
/**
* The contents of the import, which may be analyzed to see if it contains
* CJS or ESM syntax as a last step in checking whether it is a valid import.
*/
code?: string;
/**
* Protocols that are allowed as valid node imports.
*
* @default ['node', 'file', 'data']
*
*/
allowedProtocols?: Array<string>;
/**
* Whether to strip comments from the code before checking for ESM syntax.
*
* @default false
*/
stripComments?: boolean;
}
/**
* Validates whether a given identifier represents a valid node import, based on its protocol, file extension, and optionally its contents.
*
* @param {string} id - The identifier or URL of the import to validate.
* @param {ValidNodeImportOptions} _options - Options for resolving and validating the import. See {@link ValidNodeImportOptions}.
* @returns {Promise<boolean>} A promise that resolves to `true` if the import is valid, otherwise `false`.
*/
declare function isValidNodeImport(id: string, _options?: ValidNodeImportOptions): Promise<boolean>;
/**
* Converts a file URL to a local file system path with normalized slashes.
*
* @param {string | URL} id - The file URL or local path to convert.
* @returns {string} A normalized file system path.
*/
declare function fileURLToPath(id: string | URL): string;
/**
* Converts a local file system path to a file URL.
*
* @param {string | URL} id - The file system path to convert.
* @returns {string} The resulting file URL as a string.
*/
declare function pathToFileURL(id: string | URL): string;
/**
* Sanitises a component of a URI by replacing invalid characters.
*
* @param {string} name - The URI component to sanitise.
* @param {string} [replacement="_"] - The string to replace invalid characters with.
* @returns {string} The sanitised URI component.
*/
declare function sanitizeURIComponent(name?: string, replacement?: string): string;
/**
* Cleans a file path string by sanitising each component of the path.
*
* @param {string} filePath - The file path to sanitise.
* @returns {string} The sanitised file path.
*/
declare function sanitizeFilePath(filePath?: string): string;
/**
* Normalises a module identifier to ensure it has a protocol if missing, handling built-in modules and file paths.
*
* @param {string} id - The identifier to normalise.
* @returns {string} The normalised identifier with the appropriate protocol.
*/
declare function normalizeid(id: string): string;
/**
* Loads the contents of a file from a URL into a string.
*
* @param {string} url - The URL of the file to load.
* @returns {Promise<string>} A promise that resolves to the content of the file.
*/
declare function loadURL(url: string): Promise<string>;
/**
* Converts a string of code into a data URL that can be used for dynamic imports.
*
* @param {string} code - The string of code to convert.
* @returns {string} The data URL containing the encoded code.
*/
declare function toDataURL(code: string): string;
/**
* Checks if a module identifier matches a Node.js built-in module.
*
* @param {string} id - The identifier to check.
* @returns {boolean} `true` if the identifier is a built-in module, otherwise `false`.
*/
declare function isNodeBuiltin(id?: string): boolean;
/**
* Extracts the protocol portion of a given identifier string.
*
* @param {string} id - The identifier from which to extract the log.
* @returns {string | undefined} The protocol part of the identifier, or undefined if no protocol is present.
*/
declare function getProtocol(id: string): string | undefined;
export { type CommonjsContext, DYNAMIC_IMPORT_RE, type DeclarationExport, type DefaultExport, type DetectSyntaxOptions, type DynamicImport, type ESMExport, type ESMImport, ESM_STATIC_IMPORT_RE, EXPORT_DECAL_RE, EXPORT_DECAL_TYPE_RE, type EvaluateOptions, type NamedExport, type ParsedStaticImport, type ResolveOptions, type StaticImport, type TypeImport, type ValidNodeImportOptions, createCommonJS, createResolve, detectSyntax, evalModule, fileURLToPath, findDynamicImports, findExportNames, findExports, findStaticImports, findTypeExports, findTypeImports, getProtocol, hasCJSSyntax, hasESMSyntax, interopDefault, isNodeBuiltin, isValidNodeImport, loadModule, loadURL, lookupNodeModuleSubpath, normalizeid, parseNodeModulePath, parseStaticImport, parseTypeImport, pathToFileURL, resolve, resolveImports, resolveModuleExportNames, resolvePath, resolvePathSync, resolveSync, sanitizeFilePath, sanitizeURIComponent, toDataURL, transformModule };

File diff suppressed because it is too large Load Diff

View File

@@ -1,50 +0,0 @@
{
"name": "mlly",
"version": "1.7.4",
"description": "Missing ECMAScript module utils for Node.js",
"repository": "unjs/mlly",
"license": "MIT",
"sideEffects": false,
"type": "module",
"exports": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "unbuild",
"dev": "vitest",
"lint": "eslint src test && prettier -c src test",
"lint:fix": "eslint src test --fix && prettier -w src test",
"release": "pnpm test && pnpm build && changelogen --release && npm publish && git push --follow-tags",
"test": "pnpm lint && pnpm test:types && vitest run",
"test:types": "tsc --noEmit"
},
"dependencies": {
"acorn": "^8.14.0",
"pathe": "^2.0.1",
"pkg-types": "^1.3.0",
"ufo": "^1.5.4"
},
"devDependencies": {
"@types/node": "^22.10.5",
"@vitest/coverage-v8": "^2.1.8",
"changelogen": "^0.5.7",
"eslint": "^9.17.0",
"eslint-config-unjs": "^0.4.2",
"import-meta-resolve": "^4.1.0",
"jiti": "^2.4.2",
"prettier": "^3.4.2",
"std-env": "^3.8.0",
"typescript": "^5.7.2",
"unbuild": "^3.2.0",
"vitest": "^2.1.8"
},
"packageManager": "pnpm@9.15.3"
}