Comparing version 0.2.2 to 0.2.3
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.2.3](https://github.com/unjs/mlly/compare/v0.2.2...v0.2.3) (2021-10-01) | ||
### Features | ||
* static import analyzes tools ([#3](https://github.com/unjs/mlly/issues/3)) ([8193226](https://github.com/unjs/mlly/commit/8193226dc48f83a3dbf957db1d6c56d1684273e2)) | ||
### [0.2.2](https://github.com/unjs/mlly/compare/v0.2.1...v0.2.2) (2021-09-20) | ||
@@ -7,0 +14,0 @@ |
{ | ||
"name": "mlly", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Missing ECMAScript module utils for Node.js", | ||
@@ -18,3 +18,3 @@ "repository": "unjs/mlly", | ||
"release": "yarn test && standard-version && npm publish && git push --follow-tags", | ||
"test": "yarn lint" | ||
"test": "mocha ./test/**/*.test.mjs" | ||
}, | ||
@@ -27,5 +27,8 @@ "dependencies": { | ||
"@types/node": "latest", | ||
"chai": "^4.3.4", | ||
"eslint": "latest", | ||
"jiti": "^1.12.5", | ||
"mocha": "^9.1.2", | ||
"standard-version": "latest" | ||
} | ||
} |
@@ -43,3 +43,10 @@ # 🤝 mlly | ||
- Multiple composable module utils exposed | ||
- Static import analyzes | ||
- Super fast Regex based implementation | ||
- Handle most of edge cases | ||
- Find all static ESM imports | ||
- Find all dynamic ESM imports | ||
- Parse static import statement | ||
## CommonJS Context | ||
@@ -170,3 +177,94 @@ | ||
## Import analyzes | ||
### `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 previusly 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') | ||
`)) | ||
``` | ||
Outputs: | ||
```js | ||
[ | ||
{ | ||
type: 'dynamic', | ||
expression: "'bar'", | ||
code: "import('bar')", | ||
start: 19, | ||
end: 32 | ||
} | ||
] | ||
``` | ||
## Other Utils | ||
@@ -173,0 +271,0 @@ |
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
20482
251
322
7