Skip to content

Commit

Permalink
fix(deps): parse pre-relelease versions
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Aug 17, 2023
1 parent 7a592aa commit 8d86755
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ const importRe = [
/\brequire\(['"](?<path>[^'"]+)['"]\)/,
/\bfrom\s+['"](?<path>[^'"]+)['"]/,
]
// Adapted from https://github.com/dword-design/package-name-regex/blob/5d8bfe9b6e140e3e114833e68dc1fbf500991f2c/src/index.js#L1C22-L1C22
const nameRe =
/^(?<name>(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*)\/?.*$/i
const versionRe = /(\/\/|\/\*)\s*@(?<version>[~^]?([\dvx*]+([-.][\dx*]+)*))/i
const versionRe = /(\/\/|\/\*)\s*@(?<version>[~^]?(v?[\dx*]+([-.][\d*a-z-]+)*))/i

export function parseDeps(content: Buffer): Record<string, string> {
const deps: Record<string, string> = {}
Expand Down
2 changes: 2 additions & 0 deletions test/deps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ test('parseDeps(): multiline', () => {
import bar from "bar" /* @1.0.0 */
import baz from "baz" // @^2.0
import qux from "@qux/pkg/entry" // @^3.0
import {api as alias} from "qux/entry/index.js" // @^4.0.0-beta.0
const cpy = await import('cpy')
const { pick } = require("lodash") // @4.17.15
Expand All @@ -119,6 +120,7 @@ test('parseDeps(): multiline', () => {
bar: '1.0.0',
baz: '^2.0',
'@qux/pkg': '^3.0',
qux: '^4.0.0-beta.0',
cpy: 'latest',
lodash: '4.17.15',
})
Expand Down

0 comments on commit 8d86755

Please sign in to comment.