@repometry/lockparse 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repometry/lockparse",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "description": "Read dependency graphs from lockfiles",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,7 +1,7 @@
1
1
  import { literalGemGroups } from './bundler-gemfile.js';
2
2
  import { gemKey, readBundlerLock } from './bundler-lock.js';
3
3
  export const bundler = { id: 'bundler', ecosystem: 'rubygems', files: ['Gemfile.lock'],
4
- edges: true, direct: true, licenses: false };
4
+ edges: true, direct: true, licenses: false, integrity: true };
5
5
  function packageUrl({ name, version, platform }) {
6
6
  const base = 'pkg:gem/' + encodeURIComponent(name) + '@' + encodeURIComponent(version);
7
7
  return platform === undefined || platform === 'ruby' ? base : base + '?platform=' + encodeURIComponent(platform);
@@ -1,7 +1,7 @@
1
1
  import { readCargoLock } from './cargo-lock.js';
2
2
  import { cargoEvidence } from './cargo-roots.js';
3
3
  export const cargo = { id: 'cargo', ecosystem: 'cargo', files: ['Cargo.lock'],
4
- edges: true, direct: true, licenses: false };
4
+ edges: true, direct: true, licenses: false, integrity: true };
5
5
  const cratesIo = new Set(['registry+https://github.com/rust-lang/crates.io-index', 'sparse+https://index.crates.io/']);
6
6
  const namePattern = /^[\p{L}\p{N}_-]+$/u;
7
7
  const versionPattern = /^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/;
@@ -1,3 +1,5 @@
1
- import type { LockFormat, LockGraph, LockInput } from '../model.js';
1
+ import type { LockFormat, LockGraph, LockInput, LockPackage } from '../model.js';
2
2
  export declare const composer: LockFormat;
3
+ /** Composer evidence shared with the legacy reader for noncanonical package coordinates. */
4
+ export declare function composerEvidence(entry: Record<string, unknown>): Pick<LockPackage, 'license' | 'source' | 'integrity'>;
3
5
  export declare function readComposer(input: LockInput): LockGraph;
@@ -1,7 +1,7 @@
1
1
  import { locateJsonSpans, pointer } from '../json-spans.js';
2
2
  import { isRecord, readJson } from '../json.js';
3
3
  export const composer = { id: 'composer', ecosystem: 'composer', files: ['composer.lock'],
4
- edges: true, direct: true, licenses: true };
4
+ edges: true, direct: true, licenses: true, integrity: true };
5
5
  const packageName = /^[a-z0-9][a-z0-9_.-]*\/[a-z0-9][a-z0-9_.-]*$/i;
6
6
  function packageUrl(name, version) {
7
7
  return 'pkg:composer/' + name.toLowerCase() + (version === undefined ? '' : '@' + encodeURIComponent(version));
@@ -12,23 +12,41 @@ function requirements(value) {
12
12
  function sourceOf(entry) {
13
13
  const source = entry.source;
14
14
  const dist = entry.dist;
15
- if (isRecord(dist) && dist.type === 'path')
16
- return 'path';
15
+ if (isRecord(dist)) {
16
+ if (dist.type === 'path')
17
+ return 'path';
18
+ if (typeof dist.url === 'string' && dist.url.trim()) {
19
+ if (/^file:/i.test(dist.url))
20
+ return 'path';
21
+ // The notification URL is attached by Composer repositories, including Packagist.
22
+ const notify = entry['notification-url'];
23
+ const repository = typeof notify === 'string' && /^https?:\/\//i.test(notify)
24
+ || /^https?:\/\/(?:[^/?#:]+\.)?packagist\.org(?=[:/?#]|$)/i.test(dist.url);
25
+ return repository && /^https?:\/\//i.test(dist.url) ? 'registry' : 'url';
26
+ }
27
+ }
17
28
  if (isRecord(source) && source.type === 'git')
18
29
  return 'git';
19
- if (isRecord(dist) && typeof dist.url === 'string')
20
- return 'url';
21
30
  return 'unknown';
22
31
  }
23
32
  function licenseOf(value) {
24
- if (typeof value === 'string')
25
- return value.trim() || undefined;
33
+ if (typeof value === 'string') {
34
+ const text = value.trim();
35
+ return /^\(([A-Za-z0-9.+-]+)\)$/.exec(text)?.[1] ?? (text || undefined);
36
+ }
26
37
  if (isRecord(value) && typeof value.type === 'string')
27
38
  return licenseOf(value.type);
28
39
  if (!Array.isArray(value) || value.length === 0)
29
40
  return undefined;
30
41
  const choices = value.map(item => typeof item === 'string' || isRecord(item) ? licenseOf(item) : undefined);
31
- return choices.every(choice => choice !== undefined) ? choices.map(choice => '(' + choice + ')').join(' OR ') : undefined;
42
+ return choices.every(choice => choice !== undefined) ? choices.join(' OR ') : undefined;
43
+ }
44
+ /** Composer evidence shared with the legacy reader for noncanonical package coordinates. */
45
+ export function composerEvidence(entry) {
46
+ const license = licenseOf(entry.license);
47
+ const integrity = isRecord(entry.dist) && typeof entry.dist.shasum === 'string' && /^[a-f0-9]{40}$/i.test(entry.dist.shasum)
48
+ ? 'sha1:' + entry.dist.shasum : undefined;
49
+ return { source: sourceOf(entry), ...(license === undefined ? {} : { license }), ...(integrity === undefined ? {} : { integrity }) };
32
50
  }
33
51
  function manifestFor({ path, manifests }) {
34
52
  const name = path.slice(0, path.lastIndexOf('/') + 1) + 'composer.json';
@@ -48,12 +66,8 @@ function entries(section, value) {
48
66
  throw new Error(`Invalid Composer package at ${section}[${index}]`);
49
67
  }
50
68
  const { name, version } = entry;
51
- const license = licenseOf(entry.license);
52
- const integrity = isRecord(entry.dist) && typeof entry.dist.shasum === 'string' && /^[a-f0-9]{40}$/i.test(entry.dist.shasum)
53
- ? 'sha1:' + entry.dist.shasum : undefined;
54
69
  return { path: pointer([section, index]), requires: requirements(entry.require), locked: {
55
- id: packageUrl(name, version), name, version, source: sourceOf(entry), groups: [section],
56
- ...(license === undefined ? {} : { license }), ...(integrity === undefined ? {} : { integrity }),
70
+ id: packageUrl(name, version), name, version, groups: [section], ...composerEvidence(entry),
57
71
  } };
58
72
  });
59
73
  }
@@ -1,6 +1,6 @@
1
1
  import { readLines } from './lines.js';
2
2
  export const dart = { id: 'dart', ecosystem: 'pub', files: ['pubspec.lock'],
3
- edges: false, direct: true, licenses: false };
3
+ edges: false, direct: true, licenses: false, integrity: true };
4
4
  const kinds = new Map([['hosted', 'registry'], ['git', 'git'], ['path', 'path'], ['sdk', 'unknown']]);
5
5
  const sourceName = /^[A-Za-z_][A-Za-z0-9_]*$/;
6
6
  const packageVersion = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
@@ -1,7 +1,7 @@
1
1
  import { readGoMod } from './go-mod.js';
2
2
  import { readLines } from './lines.js';
3
3
  export const go = { id: 'go', ecosystem: 'go', files: ['go.mod'],
4
- edges: true, direct: true, licenses: false };
4
+ edges: true, direct: true, licenses: false, integrity: true };
5
5
  const canonical = /^v\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+incompatible)?$/;
6
6
  function packageUrl(name, version) {
7
7
  return 'pkg:golang/' + name.split('/').map(encodeURIComponent).join('/')
@@ -1,6 +1,6 @@
1
1
  import { readMixLiterals } from './mix-literals.js';
2
2
  export const mix = { id: 'mix', ecosystem: 'hex', files: ['mix.lock'],
3
- edges: true, direct: false, licenses: false };
3
+ edges: true, direct: false, licenses: false, integrity: true };
4
4
  function text(value, type) {
5
5
  return value?.type === type ? value.value : undefined;
6
6
  }
@@ -1,7 +1,7 @@
1
1
  import { isRecord, readJson } from '../json.js';
2
2
  import { locateJsonSpans, pointer } from '../json-spans.js';
3
3
  export const nuget = { id: 'nuget', ecosystem: 'nuget', files: ['packages.lock.json'],
4
- edges: true, direct: true, licenses: false };
4
+ edges: true, direct: true, licenses: false, integrity: true };
5
5
  function packageId(name, version) {
6
6
  const base = 'pkg:nuget/' + encodeURIComponent(name);
7
7
  return version === undefined ? base : base + '@' + encodeURIComponent(version);
@@ -4,7 +4,7 @@ import { projectFor } from './python-project.js';
4
4
  import { readTomlDocument } from './toml-document.js';
5
5
  import { textField } from './toml-values.js';
6
6
  export const pdm = { id: 'pdm', ecosystem: 'pypi', files: ['pdm.lock'],
7
- edges: true, direct: true, licenses: false };
7
+ edges: true, direct: true, licenses: false, integrity: true };
8
8
  function texts(values) {
9
9
  if (values === undefined)
10
10
  return undefined;
@@ -4,7 +4,7 @@ import { exactPythonVersion, pypi, pypiIds, pythonName, tableField } from './pyt
4
4
  import { readTomlDocument } from './toml-document.js';
5
5
  import { textField } from './toml-values.js';
6
6
  export const pipenv = { id: 'pipenv', ecosystem: 'pypi', files: ['Pipfile.lock'],
7
- edges: false, direct: true, licenses: false };
7
+ edges: false, direct: true, licenses: false, integrity: true };
8
8
  const nativeSections = new Map([['default', 'packages'], ['develop', 'dev-packages']]);
9
9
  const locatorKinds = new Map([
10
10
  ['git', 'git'], ['hg', 'unknown'], ['svn', 'unknown'], ['bzr', 'unknown'], ['path', 'path'], ['file', 'url'],
@@ -2,7 +2,7 @@ import { readPoetryLock } from './poetry-lock.js';
2
2
  import { pythonGraph } from './python-graph.js';
3
3
  import { projectFor } from './python-project.js';
4
4
  export const poetry = { id: 'poetry', ecosystem: 'pypi', files: ['poetry.lock'],
5
- edges: true, direct: true, licenses: false };
5
+ edges: true, direct: true, licenses: false, integrity: true };
6
6
  export function readPoetry(input) {
7
7
  return pythonGraph('poetry', readPoetryLock(input.text), projectFor(input));
8
8
  }
@@ -1,6 +1,6 @@
1
1
  import { isSymbol, tomlRecords } from './toml-statements.js';
2
2
  export const terraform = { id: 'terraform', ecosystem: 'terraform', files: ['.terraform.lock.hcl'],
3
- edges: false, direct: false, licenses: false };
3
+ edges: false, direct: false, licenses: false, integrity: true };
4
4
  const providerAddress = /^(?:[A-Za-z0-9.-]+(?::\d+)?\/)?[A-Za-z0-9_-]+\/[A-Za-z0-9_-]+$/;
5
5
  function stringList(tokens, position) {
6
6
  const values = [];
@@ -2,7 +2,7 @@ import { pypi, pythonName } from './python-package.js';
2
2
  import { projectFor } from './python-project.js';
3
3
  import { readUvLock } from './uv-lock.js';
4
4
  export const uv = { id: 'uv', ecosystem: 'pypi', files: ['uv.lock'],
5
- edges: true, direct: true, licenses: false };
5
+ edges: true, direct: true, licenses: false, integrity: true };
6
6
  function key(name, version, sourceKey) {
7
7
  return JSON.stringify([name, version, sourceKey]);
8
8
  }
@@ -1,4 +1,5 @@
1
1
  import type { FormatId, LockError, LockGraph, LockInput } from './model.js';
2
+ export { composerEvidence } from './formats/composer.js';
2
3
  export type { FormatId, LockError, LockFormat, LockGraph, LockInput, LockPackage, LockEdge } from './model.js';
3
4
  export declare const formats: readonly Readonly<{
4
5
  id: FormatId;
@@ -6,6 +7,7 @@ export declare const formats: readonly Readonly<{
6
7
  edges: boolean;
7
8
  direct: boolean;
8
9
  licenses: boolean;
10
+ integrity?: true;
9
11
  files: readonly string[];
10
12
  }>[];
11
13
  export declare function detect(path: string, _text: string): FormatId | undefined;
@@ -15,6 +15,7 @@ import { pdm, readPdm } from './formats/pdm.js';
15
15
  import { pipenv, readPipenv } from './formats/pipenv.js';
16
16
  import { poetry, readPoetry } from './formats/poetry.js';
17
17
  import { uv, readUv } from './formats/uv.js';
18
+ export { composerEvidence } from './formats/composer.js';
18
19
  const registry = [
19
20
  [composer, readComposer],
20
21
  [cargo, readCargo],
@@ -44,4 +44,5 @@ export interface LockFormat {
44
44
  readonly edges: boolean;
45
45
  readonly direct: boolean;
46
46
  readonly licenses: boolean;
47
+ readonly integrity?: true;
47
48
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Idleware
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/README.md DELETED
@@ -1,51 +0,0 @@
1
- # Lockparse
2
-
3
- Read dependency graphs from lockfiles. Pass the file contents and any companion manifests. Each graph includes package identities, recorded dependency edges, native groups, and source line ranges. The graph lists which information the input could not establish.
4
-
5
- ```js
6
- import { detect, formats, parse } from '@repometry/lockparse'
7
-
8
- // Discover supported filenames and capabilities.
9
- console.log(formats)
10
-
11
- // Detect a lockfile from its repository-relative path.
12
- const format = detect('apps/shop/composer.lock', lockfileText)
13
-
14
- // Decode supplied text and optionally its adjacent manifest.
15
- const result = parse({
16
- path: 'apps/shop/composer.lock',
17
- text: lockfileText,
18
- manifests: { 'apps/shop/composer.json': manifestText },
19
- })
20
- if ('error' in result) throw new Error(result.error.message)
21
- console.log(result.packages, result.edges, result.losses)
22
- ```
23
-
24
- ## Requirements
25
-
26
- Node.js 24 or newer. Parsing uses the supplied text and accepts up to 64 MiB per input file.
27
-
28
- ## Supported lockfiles
29
-
30
- | Ecosystem | Files |
31
- | --- | --- |
32
- | PHP | `composer.lock` |
33
- | Rust | `Cargo.lock` |
34
- | Go | `go.mod` with companion `go.sum` |
35
- | Ruby | `Gemfile.lock` |
36
- | Python | `poetry.lock`, `uv.lock`, `Pipfile.lock`, `pdm.lock` |
37
- | JVM | `gradle.lockfile`, `buildscript-gradle.lockfile` |
38
- | .NET | `packages.lock.json` |
39
- | Swift | `Package.resolved` |
40
- | Dart | `pubspec.lock` |
41
- | Elixir | `mix.lock` |
42
- | Terraform | `.terraform.lock.hcl` |
43
- | R | `renv.lock` |
44
- | Perl | `cpanfile.snapshot` |
45
- | C and C++ | `conan.lock` |
46
-
47
- A capability in `formats` means that a reader can report it when the source format records it. A specific file can leave that capability unavailable. The `losses` field makes these gaps explicit.
48
-
49
- ## License
50
-
51
- [MIT](./LICENSE)