@vzn/vx-lockfile 0.0.524 → 0.0.525

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": "@vzn/vx-lockfile",
3
- "version": "0.0.524",
3
+ "version": "0.0.525",
4
4
  "license": "MIT",
5
5
  "description": "Lockfile plugins for vx — pnpm(), bun(), npm(), yarn(): each keys every task on its project's own resolved dependency closure from the package manager's lockfile, so a lockfile change re-keys only the projects it reaches; --affected follows the same answer; `vx prune` cuts the workspace and the lockfile to a Docker subset.",
6
6
  "keywords": [
@@ -37,7 +37,7 @@
37
37
  "access": "public"
38
38
  },
39
39
  "peerDependencies": {
40
- "@vzn/vx": "^0.0.524"
40
+ "@vzn/vx": "^0.0.525"
41
41
  },
42
42
  "repository": {
43
43
  "type": "git",
package/src/index.ts CHANGED
@@ -15,18 +15,31 @@
15
15
  // and the diff are core's.
16
16
  //
17
17
  // Imports core only through the public `@vzn/vx` specifier.
18
+ import { createRequire } from 'node:module'
18
19
  import {
19
20
  refuseUnknownOptions,
21
+ type PluginCommand,
20
22
  type PluginOptionKinds,
21
23
  definePlugin,
22
24
  lockfileClaim,
23
25
  type VxPlugin,
24
26
  } from '@vzn/vx'
25
- import * as pnpmLock from './pnpm.js'
26
- import * as bunLock from './bun.js'
27
- import * as npmLock from './npm.js'
28
- import * as yarnLock from './yarn.js'
29
- import { pruneCommand } from './prune.js'
27
+
28
+ // Each parser and `prune` load when first used: every run evaluates
29
+ // `vx.workspace.ts`, and the four parsers and the verb were ~2.5 ms of it
30
+ // for a workspace that declares one manager and runs no `prune`. The
31
+ // digest seam is synchronous, so a parser loads by `require`.
32
+ const load = createRequire(import.meta.url)
33
+ const pnpmLock = (): typeof import('./pnpm.js') => load('./pnpm.js')
34
+ const bunLock = (): typeof import('./bun.js') => load('./bun.js')
35
+ const npmLock = (): typeof import('./npm.js') => load('./npm.js')
36
+ const yarnLock = (): typeof import('./yarn.js') => load('./yarn.js')
37
+
38
+ /** One object for all four plugins, so a workspace declaring two still has one `prune`. */
39
+ const pruneCommand: PluginCommand = {
40
+ description: 'copy projects and their workspace deps, lockfile pruned, for a Docker build',
41
+ run: async (argv, ctx) => (await import('./prune.js')).prune(argv, ctx),
42
+ }
30
43
 
31
44
  export interface LockfileOptions {
32
45
  /**
@@ -53,23 +66,23 @@ const MANAGERS = {
53
66
  pnpm: {
54
67
  name: 'pnpm',
55
68
  file: 'pnpm-lock.yaml',
56
- digest: (t) => pnpmLock.importerDigests(pnpmLock.parseLockfile(t)),
69
+ digest: (t) => pnpmLock().importerDigests(pnpmLock().parseLockfile(t)),
57
70
  },
58
71
  bun: {
59
72
  name: 'bun',
60
73
  file: 'bun.lock',
61
- digest: (t, files) => bunLock.importerDigests(bunLock.parseLockfile(t), files),
62
- extraFiles: (t) => bunLock.patchFiles(t),
74
+ digest: (t, files) => bunLock().importerDigests(bunLock().parseLockfile(t), files),
75
+ extraFiles: (t) => bunLock().patchFiles(t),
63
76
  },
64
77
  npm: {
65
78
  name: 'npm',
66
79
  file: 'package-lock.json',
67
- digest: (t) => npmLock.importerDigests(npmLock.parseLockfile(t)),
80
+ digest: (t) => npmLock().importerDigests(npmLock().parseLockfile(t)),
68
81
  },
69
82
  yarn: {
70
83
  name: 'yarn',
71
84
  file: 'yarn.lock',
72
- digest: (t) => yarnLock.importerDigests(yarnLock.parseLockfile(t)),
85
+ digest: (t) => yarnLock().importerDigests(yarnLock().parseLockfile(t)),
73
86
  },
74
87
  } satisfies Record<string, Manager>
75
88
 
package/src/prune.ts CHANGED
@@ -22,7 +22,6 @@ import {
22
22
  loadWorkspace,
23
23
  UserError,
24
24
  type CommandContext,
25
- type PluginCommand,
26
25
  type ProjectMeta,
27
26
  } from '@vzn/vx'
28
27
  import * as bunLock from './bun.js'
@@ -66,12 +65,6 @@ const DEP_FIELDS = ['dependencies', 'devDependencies', 'optionalDependencies'] a
66
65
  /** `from '…'`, `import '…'`, `import('…')`: static specifiers only. */
67
66
  const SPECIFIER_RE = /(?:from|import)\s*\(?\s*['"]([^'"]+)['"]/g
68
67
 
69
- /** One object for all four plugins, so a workspace declaring two still has one `prune`. */
70
- export const pruneCommand: PluginCommand = {
71
- description: 'copy projects and their workspace deps, lockfile pruned, for a Docker build',
72
- run: (argv, ctx) => prune(argv, ctx),
73
- }
74
-
75
68
  interface Args {
76
69
  readonly projects: readonly string[]
77
70
  readonly outDir: string
@@ -110,7 +103,7 @@ const posix = (p: string): string => p.split(path.sep).join('/')
110
103
  /** `a` within `dir`, or `dir` itself. */
111
104
  const within = (a: string, dir: string): boolean => a === dir || a.startsWith(dir + path.sep)
112
105
 
113
- async function prune(argv: readonly string[], ctx: CommandContext): Promise<number> {
106
+ export async function prune(argv: readonly string[], ctx: CommandContext): Promise<number> {
114
107
  const args = parseArgs(argv)
115
108
  if (args === null) {
116
109
  process.stdout.write(`${USAGE}\n`)