Comparing version 1.3.0 to 1.4.0
@@ -9,4 +9,15 @@ interface ResolveOptions { | ||
declare function resolvePathSync(id: string, options?: ResolveOptions): string; | ||
declare function resolvePath(id: string, options?: ResolveOptions): Promise<any>; | ||
declare function resolvePath(id: string, options?: ResolveOptions): Promise<string>; | ||
declare function createResolve(defaults?: ResolveOptions): (id: string, url?: ResolveOptions["url"]) => Promise<string>; | ||
declare function parseNodeModulePath(path: string): { | ||
dir?: undefined; | ||
name?: undefined; | ||
subpath?: undefined; | ||
} | { | ||
dir: string; | ||
name: string; | ||
subpath: string; | ||
}; | ||
/** Reverse engineer a subpath export if possible */ | ||
declare function lookupNodeModuleSubpath(path: string): Promise<string | undefined>; | ||
@@ -35,2 +46,7 @@ interface ESMImport { | ||
} | ||
interface TypeImport extends Omit<ESMImport, "type"> { | ||
type: "type"; | ||
imports: string; | ||
specifier: string; | ||
} | ||
interface ESMExport { | ||
@@ -66,3 +82,5 @@ _type?: "declaration" | "named" | "default" | "star"; | ||
declare function findDynamicImports(code: string): DynamicImport[]; | ||
declare function parseStaticImport(matched: StaticImport): ParsedStaticImport; | ||
declare function findTypeImports(code: string): TypeImport[]; | ||
declare function parseStaticImport(matched: StaticImport | TypeImport): ParsedStaticImport; | ||
declare function parseTypeImport(matched: TypeImport | StaticImport): ParsedStaticImport; | ||
declare function findExports(code: string): ESMExport[]; | ||
@@ -120,2 +138,2 @@ declare function findTypeExports(code: string): ESMExport[]; | ||
export { CommonjsContext, DYNAMIC_IMPORT_RE, DeclarationExport, DefaultExport, DynamicImport, ESMExport, ESMImport, ESM_STATIC_IMPORT_RE, EXPORT_DECAL_RE, EXPORT_DECAL_TYPE_RE, EvaluateOptions, NamedExport, ParsedStaticImport, ResolveOptions, StaticImport, ValidNodeImportOptions, createCommonJS, createResolve, detectSyntax, evalModule, fileURLToPath, findDynamicImports, findExportNames, findExports, findStaticImports, findTypeExports, getProtocol, hasCJSSyntax, hasESMSyntax, interopDefault, isNodeBuiltin, isValidNodeImport, loadModule, loadURL, normalizeid, parseStaticImport, resolve, resolveImports, resolveModuleExportNames, resolvePath, resolvePathSync, resolveSync, sanitizeFilePath, sanitizeURIComponent, toDataURL, transformModule }; | ||
export { CommonjsContext, DYNAMIC_IMPORT_RE, DeclarationExport, DefaultExport, DynamicImport, ESMExport, ESMImport, ESM_STATIC_IMPORT_RE, EXPORT_DECAL_RE, EXPORT_DECAL_TYPE_RE, EvaluateOptions, NamedExport, ParsedStaticImport, ResolveOptions, StaticImport, TypeImport, 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, resolve, resolveImports, resolveModuleExportNames, resolvePath, resolvePathSync, resolveSync, sanitizeFilePath, sanitizeURIComponent, toDataURL, transformModule }; |
{ | ||
"name": "mlly", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Missing ECMAScript module utils for Node.js", | ||
@@ -24,2 +24,3 @@ "repository": "unjs/mlly", | ||
"lint": "eslint --ext .ts,.js src test && prettier -c src test", | ||
"lint:fix": "eslint --ext .ts,.js src test --fix && prettier -w src test", | ||
"release": "pnpm test && pnpm build && changelogen --release && npm publish && git push --follow-tags", | ||
@@ -29,4 +30,4 @@ "test": "pnpm lint && vitest run" | ||
"dependencies": { | ||
"acorn": "^8.8.2", | ||
"pathe": "^1.1.0", | ||
"acorn": "^8.9.0", | ||
"pathe": "^1.1.1", | ||
"pkg-types": "^1.0.3", | ||
@@ -36,16 +37,15 @@ "ufo": "^1.1.2" | ||
"devDependencies": { | ||
"@types/node": "^20.2.3", | ||
"@vitest/coverage-c8": "^0.31.1", | ||
"c8": "^7.13.0", | ||
"@types/node": "^20.3.1", | ||
"@vitest/coverage-v8": "^0.32.2", | ||
"changelogen": "^0.5.3", | ||
"eslint": "^8.41.0", | ||
"eslint-config-unjs": "^0.2.0", | ||
"eslint": "^8.43.0", | ||
"eslint-config-unjs": "^0.2.1", | ||
"import-meta-resolve": "^3.0.0", | ||
"jiti": "^1.18.2", | ||
"prettier": "^2.8.8", | ||
"typescript": "^5.0.4", | ||
"typescript": "^5.1.3", | ||
"unbuild": "^1.2.1", | ||
"vitest": "^0.31.1" | ||
"vitest": "^0.32.2" | ||
}, | ||
"packageManager": "pnpm@8.5.1" | ||
} |
@@ -494,4 +494,38 @@ # mlly | ||
### `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 ❤️ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
161217
11
4738
531
Updatedacorn@^8.9.0
Updatedpathe@^1.1.1