Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: unjs/mlly
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.5.2
Choose a base ref
...
head repository: unjs/mlly
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.5.3
Choose a head ref
  • 5 commits
  • 9 files changed
  • 4 contributors

Commits on Jun 16, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    af777cb View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    37d5bcc View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7c1bda4 View commit details
  4. chore: add renovate.json

    pi0 committed Jun 16, 2022
    Copy the full SHA
    2333eb1 View commit details
  5. chore(release): 0.5.3

    pi0 committed Jun 16, 2022
    Copy the full SHA
    2417c40 View commit details
Showing with 35 additions and 9 deletions.
  1. +13 −0 CHANGELOG.md
  2. +1 −1 package.json
  3. +5 −0 renovate.json
  4. +1 −1 src/analyze.ts
  5. +2 −2 src/resolve.ts
  6. +2 −1 test/exports.test.ts
  7. +3 −1 test/fixture/eval-err.mjs
  8. +3 −3 test/fixture/resolve.mjs
  9. +5 −0 tsconfig.json
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,19 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.5.3](https://github.com/unjs/mlly/compare/v0.5.2...v0.5.3) (2022-06-16)


### Features

* support named star export ([#45](https://github.com/unjs/mlly/issues/45)) ([af777cb](https://github.com/unjs/mlly/commit/af777cbe3ce09d23c6a994334e658f1b21e71ea6))


### Bug Fixes

* don't throw if module subpath not found ([#46](https://github.com/unjs/mlly/issues/46)) ([37d5bcc](https://github.com/unjs/mlly/commit/37d5bcc221e83be4298a4e52b351900a962823e3))
* make `url` optional in resolver created with `createResolve` ([#44](https://github.com/unjs/mlly/issues/44)) ([7c1bda4](https://github.com/unjs/mlly/commit/7c1bda4221b8a162e39610ebf9f50f957a32d7f9))

### [0.5.2](https://github.com/unjs/mlly/compare/v0.5.1...v0.5.2) (2022-04-13)


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mlly",
"version": "0.5.2",
"version": "0.5.3",
"description": "Missing ECMAScript module utils for Node.js",
"repository": "unjs/mlly",
"license": "MIT",
5 changes: 5 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"@nuxtjs"
]
}
2 changes: 1 addition & 1 deletion src/analyze.ts
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ export const DYNAMIC_IMPORT_RE = /import\s*\((?<expression>(?:[^)(]+|\((?:[^)(]+

export const EXPORT_DECAL_RE = /\bexport\s+(?<declaration>(async function|function|let|const|var|class))\s+(?<name>[\w$_]+)/g
const EXPORT_NAMED_RE = /\bexport\s+{(?<exports>[^}]+)}(\s*from\s*["']\s*(?<specifier>(?<="\s*)[^"]*[^"\s](?=\s*")|(?<='\s*)[^']*[^'\s](?=\s*'))\s*["'][^\n]*)?/g
const EXPORT_STAR_RE = /\bexport\s*(\*)\s*(\s*from\s*["']\s*(?<specifier>(?<="\s*)[^"]*[^"\s](?=\s*")|(?<='\s*)[^']*[^'\s](?=\s*'))\s*["'][^\n]*)?/g
const EXPORT_STAR_RE = /\bexport\s*(\*)(\s*as\s+(?<name>[\w$_]+)\s+)?\s*(\s*from\s*["']\s*(?<specifier>(?<="\s*)[^"]*[^"\s](?=\s*")|(?<='\s*)[^']*[^'\s](?=\s*'))\s*["'][^\n]*)?/g
const EXPORT_DEFAULT_RE = /\bexport\s+default\s+/g

export function findStaticImports (code: string): StaticImport[] {
4 changes: 2 additions & 2 deletions src/resolve.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import { pcall, BUILTIN_MODULES } from './_utils'
const DEFAULT_CONDITIONS_SET = new Set(['node', 'import'])
const DEFAULT_URL = pathToFileURL(process.cwd())
const DEFAULT_EXTENSIONS = ['.mjs', '.cjs', '.js', '.json']
const NOT_FOUND_ERRORS = new Set(['ERR_MODULE_NOT_FOUND', 'ERR_UNSUPPORTED_DIR_IMPORT', 'MODULE_NOT_FOUND'])
const NOT_FOUND_ERRORS = new Set(['ERR_MODULE_NOT_FOUND', 'ERR_UNSUPPORTED_DIR_IMPORT', 'MODULE_NOT_FOUND', 'ERR_PACKAGE_PATH_NOT_EXPORTED'])

export interface ResolveOptions {
url?: string | URL | (string | URL)[]
@@ -118,7 +118,7 @@ export function resolvePath (id: string, opts?: ResolveOptions) {
}

export function createResolve (defaults?: ResolveOptions) {
return (id, url) => {
return (id: string, url?: ResolveOptions['url']) => {
return resolve(id, { url, ...defaults })
}
}
3 changes: 2 additions & 1 deletion test/exports.test.ts
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@ describe('findExports', () => {
'export async function foo ()': { type: 'declaration', names: ['foo'] },
'export const $foo = () => {}': { type: 'declaration', names: ['$foo'] },
'export { foo as default }': { type: 'default', name: 'default', names: ['default'] },
'export * from "./other"': { type: 'star', specifier: './other' }
'export * from "./other"': { type: 'star', specifier: './other' },
'export * as foo from "./other"': { type: 'star', specifier: './other', name: 'foo' }
}

describe('findExports', () => {
4 changes: 3 additions & 1 deletion test/fixture/eval-err.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
async function test() {
// @ts-nocheck
// eslint-disable-next-line require-await
async function test () {
throw new Error('Something went wrong in eval-err module!')
}

6 changes: 3 additions & 3 deletions test/fixture/resolve.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { resolvePath, createResolve, resolveImports } from 'mlly'

import.meta.resolve = createResolve({ url: import.meta.url })
console.log(await import.meta.resolve('./cjs.mjs'))
const resolve = createResolve({ url: import.meta.url })
console.log(await resolve('./cjs.mjs'))

console.log(await resolvePath('./cjs.mjs', { url: import.meta.url }))
console.log(await resolvePath('./foo', { url: import.meta.url }))

console.log(await resolveImports(`import foo from './eval.mjs'`, { url: import.meta.url }))
console.log(await resolveImports('import foo from \'./eval.mjs\'', { url: import.meta.url }))
5 changes: 5 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -3,7 +3,12 @@
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"esModuleInterop": true,
"checkJs": true,
"paths": {
"mlly": ["./"]
},
"types": [
"node"
]