@vltpkg/cli-sdk 0.0.0-9 → 1.0.0-rc.10

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.
Files changed (157) hide show
  1. package/dist/esm/commands/bugs.d.ts +18 -0
  2. package/dist/esm/commands/bugs.d.ts.map +1 -0
  3. package/dist/esm/commands/bugs.js +164 -0
  4. package/dist/esm/commands/bugs.js.map +1 -0
  5. package/dist/esm/commands/build.d.ts +25 -0
  6. package/dist/esm/commands/build.d.ts.map +1 -0
  7. package/dist/esm/commands/build.js +102 -0
  8. package/dist/esm/commands/build.js.map +1 -0
  9. package/dist/esm/commands/cache.d.ts +18 -0
  10. package/dist/esm/commands/cache.d.ts.map +1 -1
  11. package/dist/esm/commands/cache.js +48 -2
  12. package/dist/esm/commands/cache.js.map +1 -1
  13. package/dist/esm/commands/ci.d.ts +11 -0
  14. package/dist/esm/commands/ci.d.ts.map +1 -0
  15. package/dist/esm/commands/ci.js +32 -0
  16. package/dist/esm/commands/ci.js.map +1 -0
  17. package/dist/esm/commands/config.d.ts +3 -2
  18. package/dist/esm/commands/config.d.ts.map +1 -1
  19. package/dist/esm/commands/config.js +372 -101
  20. package/dist/esm/commands/config.js.map +1 -1
  21. package/dist/esm/commands/docs.d.ts +18 -0
  22. package/dist/esm/commands/docs.d.ts.map +1 -0
  23. package/dist/esm/commands/docs.js +154 -0
  24. package/dist/esm/commands/docs.js.map +1 -0
  25. package/dist/esm/commands/exec-cache.d.ts +49 -0
  26. package/dist/esm/commands/exec-cache.d.ts.map +1 -0
  27. package/dist/esm/commands/exec-cache.js +146 -0
  28. package/dist/esm/commands/exec-cache.js.map +1 -0
  29. package/dist/esm/commands/exec-local.d.ts +1 -0
  30. package/dist/esm/commands/exec-local.d.ts.map +1 -1
  31. package/dist/esm/commands/exec-local.js +2 -0
  32. package/dist/esm/commands/exec-local.js.map +1 -1
  33. package/dist/esm/commands/exec.d.ts +6 -1
  34. package/dist/esm/commands/exec.d.ts.map +1 -1
  35. package/dist/esm/commands/exec.js +79 -5
  36. package/dist/esm/commands/exec.js.map +1 -1
  37. package/dist/esm/commands/help.d.ts +1 -1
  38. package/dist/esm/commands/help.d.ts.map +1 -1
  39. package/dist/esm/commands/help.js +32 -3
  40. package/dist/esm/commands/help.js.map +1 -1
  41. package/dist/esm/commands/init.d.ts +3 -3
  42. package/dist/esm/commands/init.d.ts.map +1 -1
  43. package/dist/esm/commands/init.js +95 -9
  44. package/dist/esm/commands/init.js.map +1 -1
  45. package/dist/esm/commands/install/reporter.d.ts +3 -2
  46. package/dist/esm/commands/install/reporter.d.ts.map +1 -1
  47. package/dist/esm/commands/install/reporter.js +42 -15
  48. package/dist/esm/commands/install/reporter.js.map +1 -1
  49. package/dist/esm/commands/install.d.ts +21 -3
  50. package/dist/esm/commands/install.d.ts.map +1 -1
  51. package/dist/esm/commands/install.js +29 -4
  52. package/dist/esm/commands/install.js.map +1 -1
  53. package/dist/esm/commands/list.d.ts +2 -2
  54. package/dist/esm/commands/list.d.ts.map +1 -1
  55. package/dist/esm/commands/list.js +149 -49
  56. package/dist/esm/commands/list.js.map +1 -1
  57. package/dist/esm/commands/pack.d.ts +32 -0
  58. package/dist/esm/commands/pack.d.ts.map +1 -0
  59. package/dist/esm/commands/pack.js +147 -0
  60. package/dist/esm/commands/pack.js.map +1 -0
  61. package/dist/esm/commands/pkg.d.ts +1 -2
  62. package/dist/esm/commands/pkg.d.ts.map +1 -1
  63. package/dist/esm/commands/pkg.js +123 -38
  64. package/dist/esm/commands/pkg.js.map +1 -1
  65. package/dist/esm/commands/publish.d.ts +22 -0
  66. package/dist/esm/commands/publish.d.ts.map +1 -0
  67. package/dist/esm/commands/publish.js +245 -0
  68. package/dist/esm/commands/publish.js.map +1 -0
  69. package/dist/esm/commands/query.d.ts +2 -3
  70. package/dist/esm/commands/query.d.ts.map +1 -1
  71. package/dist/esm/commands/query.js +132 -38
  72. package/dist/esm/commands/query.js.map +1 -1
  73. package/dist/esm/commands/run-exec.d.ts +1 -0
  74. package/dist/esm/commands/run-exec.d.ts.map +1 -1
  75. package/dist/esm/commands/run-exec.js +1 -0
  76. package/dist/esm/commands/run-exec.js.map +1 -1
  77. package/dist/esm/commands/run.d.ts +1 -0
  78. package/dist/esm/commands/run.d.ts.map +1 -1
  79. package/dist/esm/commands/run.js +13 -16
  80. package/dist/esm/commands/run.js.map +1 -1
  81. package/dist/esm/commands/serve.d.ts +14 -0
  82. package/dist/esm/commands/serve.d.ts.map +1 -0
  83. package/dist/esm/commands/serve.js +103 -0
  84. package/dist/esm/commands/serve.js.map +1 -0
  85. package/dist/esm/commands/uninstall.d.ts +8 -2
  86. package/dist/esm/commands/uninstall.d.ts.map +1 -1
  87. package/dist/esm/commands/uninstall.js +10 -5
  88. package/dist/esm/commands/uninstall.js.map +1 -1
  89. package/dist/esm/commands/update.d.ts +14 -0
  90. package/dist/esm/commands/update.d.ts.map +1 -0
  91. package/dist/esm/commands/update.js +41 -0
  92. package/dist/esm/commands/update.js.map +1 -0
  93. package/dist/esm/commands/version.d.ts +26 -0
  94. package/dist/esm/commands/version.d.ts.map +1 -0
  95. package/dist/esm/commands/version.js +226 -0
  96. package/dist/esm/commands/version.js.map +1 -0
  97. package/dist/esm/config/definition.d.ts +119 -15
  98. package/dist/esm/config/definition.d.ts.map +1 -1
  99. package/dist/esm/config/definition.js +186 -37
  100. package/dist/esm/config/definition.js.map +1 -1
  101. package/dist/esm/config/index.d.ts +41 -37
  102. package/dist/esm/config/index.d.ts.map +1 -1
  103. package/dist/esm/config/index.js +109 -172
  104. package/dist/esm/config/index.js.map +1 -1
  105. package/dist/esm/config/merge.d.ts +3 -1
  106. package/dist/esm/config/merge.d.ts.map +1 -1
  107. package/dist/esm/config/merge.js +11 -6
  108. package/dist/esm/config/merge.js.map +1 -1
  109. package/dist/esm/custom-help.d.ts +9 -0
  110. package/dist/esm/custom-help.d.ts.map +1 -0
  111. package/dist/esm/custom-help.js +400 -0
  112. package/dist/esm/custom-help.js.map +1 -0
  113. package/dist/esm/exec-command.d.ts +33 -14
  114. package/dist/esm/exec-command.d.ts.map +1 -1
  115. package/dist/esm/exec-command.js +213 -64
  116. package/dist/esm/exec-command.js.map +1 -1
  117. package/dist/esm/index.d.ts +1 -14
  118. package/dist/esm/index.d.ts.map +1 -1
  119. package/dist/esm/index.js +45 -19
  120. package/dist/esm/index.js.map +1 -1
  121. package/dist/esm/load-command.d.ts +16 -0
  122. package/dist/esm/load-command.d.ts.map +1 -0
  123. package/dist/esm/load-command.js +21 -0
  124. package/dist/esm/load-command.js.map +1 -0
  125. package/dist/esm/output.d.ts +6 -11
  126. package/dist/esm/output.d.ts.map +1 -1
  127. package/dist/esm/output.js +64 -27
  128. package/dist/esm/output.js.map +1 -1
  129. package/dist/esm/pack-tarball.d.ts +22 -0
  130. package/dist/esm/pack-tarball.d.ts.map +1 -0
  131. package/dist/esm/pack-tarball.js +249 -0
  132. package/dist/esm/pack-tarball.js.map +1 -0
  133. package/dist/esm/parse-add-remove-args.d.ts +9 -2
  134. package/dist/esm/parse-add-remove-args.d.ts.map +1 -1
  135. package/dist/esm/parse-add-remove-args.js +43 -10
  136. package/dist/esm/parse-add-remove-args.js.map +1 -1
  137. package/dist/esm/print-err.d.ts +9 -2
  138. package/dist/esm/print-err.d.ts.map +1 -1
  139. package/dist/esm/print-err.js +130 -46
  140. package/dist/esm/print-err.js.map +1 -1
  141. package/dist/esm/query-host-contexts.d.ts +16 -0
  142. package/dist/esm/query-host-contexts.d.ts.map +1 -0
  143. package/dist/esm/query-host-contexts.js +135 -0
  144. package/dist/esm/query-host-contexts.js.map +1 -0
  145. package/dist/esm/start-gui.d.ts +1 -0
  146. package/dist/esm/start-gui.d.ts.map +1 -1
  147. package/dist/esm/start-gui.js +28 -8
  148. package/dist/esm/start-gui.js.map +1 -1
  149. package/dist/esm/view.d.ts +2 -3
  150. package/dist/esm/view.d.ts.map +1 -1
  151. package/dist/esm/view.js +1 -1
  152. package/dist/esm/view.js.map +1 -1
  153. package/package.json +55 -41
  154. package/dist/esm/commands/gui.d.ts +0 -6
  155. package/dist/esm/commands/gui.d.ts.map +0 -1
  156. package/dist/esm/commands/gui.js +0 -13
  157. package/dist/esm/commands/gui.js.map +0 -1
@@ -1,20 +1,14 @@
1
+ import { styleText as utilStyleText } from 'node:util';
1
2
  import type { LoadedConfig } from './config/index.ts';
2
3
  import type { Command } from './index.ts';
3
4
  import type { View, Views } from './view.ts';
4
5
  export declare const stdout: (...args: unknown[]) => void;
5
6
  export declare const stderr: (...args: unknown[]) => void;
7
+ type StyleTextFn = (format: Parameters<typeof utilStyleText>[0], s: string) => string;
8
+ export declare let styleTextStdout: StyleTextFn;
9
+ export declare let styleTextStderr: StyleTextFn;
6
10
  export declare const getView: <T>(conf: LoadedConfig, views?: Views<T>) => View<T>;
7
- export type OnDone<T> = ((result: T) => Promise<unknown>) | ((result: T) => unknown);
8
- /**
9
- * If the view is a View class, then instantiate and start it.
10
- * If it's a view function, then just define the onDone method.
11
- */
12
- export declare const startView: <T>(conf: LoadedConfig, views?: Views<T>, { start }?: {
13
- start: number;
14
- }) => {
15
- onDone: OnDone<T>;
16
- onError?: (err: unknown) => void;
17
- };
11
+ export type OnDone<T> = (result: T) => Promise<unknown>;
18
12
  /**
19
13
  * Main export. Run the command appropriately, displaying output using
20
14
  * the user-requested view, or the default if the user requested a view
@@ -23,4 +17,5 @@ export declare const startView: <T>(conf: LoadedConfig, views?: Views<T>, { star
23
17
  export declare const outputCommand: <T>(cliCommand: Command<T>, conf: LoadedConfig, { start }?: {
24
18
  start: number;
25
19
  }) => Promise<void>;
20
+ export {};
26
21
  //# sourceMappingURL=output.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/output.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,OAAO,KAA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O,MAAM,MAAM,YAAa,OAAO,EAAE,SAA2B,CAAA;AAEpE,KAAK,WAAW,GAAG,CACjB,MAAM,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,EAC3C,CAAC,EAAE,MAAM,KACN,MAAM,CAAA;AASX,eAAO,IAAI,eAAe,EAAE,WAAyB,CAAA;AACrD,eAAO,IAAI,eAAe,EAAE,WAAyB,CAAA;AAKrD,eAAO,MAAM,OAAO,GAAI,CAAC,QACjB,YAAY,UACV,KAAK,CAAC,CAAC,CAAC,KACf,IAAI,CAAC,CAAC,CA2BR,CAAA;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAsCvD;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAU,CAAC,cACvB,OAAO,CAAC,CAAC,CAAC,QAChB,YAAY,cACP;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,kBA6D7B,CAAA"}
@@ -1,24 +1,45 @@
1
- import chalk from 'chalk';
2
- import { formatWithOptions } from 'node:util';
1
+ import { formatWithOptions, styleText as utilStyleText, } from 'node:util';
2
+ import { createSupportsColor } from 'supports-color';
3
3
  import { defaultView } from "./config/definition.js";
4
- import { printErr } from "./print-err.js";
4
+ import { printErr, formatOptions } from "./print-err.js";
5
5
  import { isViewClass } from "./view.js";
6
- // TODO: make these have log levels etc
6
+ import { generateDefaultHelp, generateFullHelp, } from "./custom-help.js";
7
+ const supportsColor = (stream) => {
8
+ const res = createSupportsColor(stream, { sniffFlags: false });
9
+ if (res === false)
10
+ return false;
11
+ /* c8 ignore next */
12
+ return res.level > 0;
13
+ };
7
14
  // eslint-disable-next-line no-console
8
15
  export const stdout = (...args) => console.log(...args);
9
16
  // eslint-disable-next-line no-console
10
17
  export const stderr = (...args) => console.error(...args);
18
+ /* c8 ignore start */
19
+ const styleText = (f, s) => utilStyleText(f, s, { validateStream: false });
20
+ /* c8 ignore stop */
21
+ // TODO: stop exporting mutable variables once exec output is refactored
22
+ /* c8 ignore start */
23
+ export let styleTextStdout = (_, s) => s;
24
+ export let styleTextStderr = (_, s) => s;
25
+ /* c8 ignore stop */
11
26
  const identity = (x) => x;
12
27
  export const getView = (conf, views) => {
13
28
  const viewName = conf.values.view;
14
29
  const viewFn = viewName === 'inspect' ? identity
15
- : typeof views === 'function' ? views
16
- : views && typeof views === 'object' ? views[viewName]
17
- : identity;
18
- // if the user specified a view that doesn't exist,
19
- // then set it back to the default, and try again.
20
- // This will fall back to identity if it's also missing.
21
- if (!viewFn && conf.values.view !== defaultView) {
30
+ : viewName === 'silent' ? () => undefined
31
+ : typeof views === 'function' ? views
32
+ : views && typeof views === 'object' ? views[viewName]
33
+ : identity;
34
+ // if the user specified a view that doesn't exist, then set it back to the
35
+ // default, and try again. This will fall back to identity if it's also
36
+ // missing. We also always treat 'json' as a valid view that falls back to
37
+ // identity. This allows the explicit use of `--view=json` to work even
38
+ // when the default view is `human`.
39
+ if (!viewFn &&
40
+ conf.values.view !== defaultView &&
41
+ conf.values.view !== 'json' &&
42
+ conf.values.view !== 'silent') {
22
43
  conf.values.view = defaultView;
23
44
  process.env.VLT_VIEW = defaultView;
24
45
  return getView(conf, views);
@@ -29,16 +50,13 @@ export const getView = (conf, views) => {
29
50
  * If the view is a View class, then instantiate and start it.
30
51
  * If it's a view function, then just define the onDone method.
31
52
  */
32
- export const startView = (conf, views, { start } = { start: Date.now() }) => {
53
+ const startView = (conf, opts, views, { start } = { start: Date.now() }) => {
33
54
  const View = getView(conf, views);
34
- const opts = {
35
- colors: conf.values.color ? chalk : undefined,
36
- };
37
55
  if (isViewClass(View)) {
38
56
  const view = new View(opts, conf);
39
57
  view.start();
40
58
  return {
41
- onDone(r) {
59
+ async onDone(r) {
42
60
  return view.done(r, { time: Date.now() - start });
43
61
  },
44
62
  onError(err) {
@@ -61,28 +79,47 @@ export const startView = (conf, views, { start } = { start: Date.now() }) => {
61
79
  */
62
80
  export const outputCommand = async (cliCommand, conf, { start } = { start: Date.now() }) => {
63
81
  const { usage, views, command } = cliCommand;
64
- if (conf.get('help')) {
82
+ const stdoutColor = conf.values.color ?? supportsColor(process.stdout);
83
+ const stderrColor = conf.values.color ?? supportsColor(process.stderr);
84
+ if (conf.values.help) {
85
+ // Show custom help for main vlt command
86
+ /* c8 ignore start */
87
+ if (conf.command === 'help' && conf.positionals.length === 0) {
88
+ if (conf.get('all')) {
89
+ return stdout(generateFullHelp(stdoutColor));
90
+ }
91
+ return stdout(generateDefaultHelp(stdoutColor));
92
+ }
93
+ /* c8 ignore stop */
65
94
  return stdout(usage().usage());
66
95
  }
67
- const formatOptions = {
68
- colors: conf.values.color,
69
- depth: Infinity,
70
- maxArrayLength: Infinity,
71
- maxStringLength: Infinity,
72
- };
73
- const { onDone, onError } = startView(conf, views, { start });
96
+ /* c8 ignore start */
97
+ if (stdoutColor)
98
+ styleTextStdout = styleText;
99
+ if (stderrColor)
100
+ styleTextStderr = styleText;
101
+ /* c8 ignore stop */
102
+ const { onDone, onError } = startView(conf,
103
+ // assume views will always output to stdout so use color support from there
104
+ { colors: stdoutColor }, views, { start });
74
105
  try {
75
106
  const output = await onDone(await command(conf));
76
- if (output !== undefined) {
107
+ if (output !== undefined && conf.values.view !== 'silent') {
77
108
  stdout(conf.values.view === 'json' ?
78
109
  JSON.stringify(output, null, 2)
79
- : formatWithOptions(formatOptions, output));
110
+ : formatWithOptions({
111
+ ...formatOptions,
112
+ colors: stdoutColor,
113
+ }, output));
80
114
  }
81
115
  }
82
116
  catch (err) {
83
117
  onError?.(err);
84
118
  process.exitCode ||= 1;
85
- printErr(err, usage, stderr, formatOptions);
119
+ printErr(err, usage, stderr, {
120
+ ...formatOptions,
121
+ colors: stderrColor,
122
+ });
86
123
  process.exit(process.exitCode);
87
124
  }
88
125
  };
@@ -1 +1 @@
1
- {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAA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from 'node:util'\nimport { defaultView } from './config/definition.ts'\nimport type { LoadedConfig } from './config/index.ts'\nimport type { Command } from './index.ts'\nimport { printErr } from './print-err.ts'\nimport type { View, Views } from './view.ts'\nimport { isViewClass } from './view.ts'\n\n// TODO: make these have log levels etc\n// eslint-disable-next-line no-console\nexport const stdout = (...args: unknown[]) => console.log(...args)\n// eslint-disable-next-line no-console\nexport const stderr = (...args: unknown[]) => console.error(...args)\n\nconst identity = <T>(x: T): T => x\n\nexport const getView = <T>(\n conf: LoadedConfig,\n views?: Views<T>,\n): View<T> => {\n const viewName = conf.values.view\n\n const viewFn =\n viewName === 'inspect' ? identity\n : typeof views === 'function' ? views\n : views && typeof views === 'object' ? views[viewName]\n : identity\n\n // if the user specified a view that doesn't exist,\n // then set it back to the default, and try again.\n // This will fall back to identity if it's also missing.\n if (!viewFn && conf.values.view !== defaultView) {\n conf.values.view = defaultView\n process.env.VLT_VIEW = defaultView\n return getView(conf, views)\n }\n\n return viewFn ?? identity\n}\n\nexport type OnDone<T> =\n | ((result: T) => Promise<unknown>)\n | ((result: T) => unknown)\n\n/**\n * If the view is a View class, then instantiate and start it.\n * If it's a view function, then just define the onDone method.\n */\nexport const startView = <T>(\n conf: LoadedConfig,\n views?: Views<T>,\n { start }: { start: number } = { start: Date.now() },\n): {\n onDone: OnDone<T>\n onError?: (err: unknown) => void\n} => {\n const View = getView<T>(conf, views)\n\n const opts = {\n colors: conf.values.color ? chalk : undefined,\n }\n\n if (isViewClass(View)) {\n const view = new View(opts, conf)\n view.start()\n return {\n onDone(r) {\n return view.done(r, { time: Date.now() - start })\n },\n onError(err) {\n view.error(err)\n },\n }\n }\n\n return {\n async onDone(r) {\n if (r === undefined) return\n return View(r, opts, conf)\n },\n }\n}\n\n/**\n * Main export. Run the command appropriately, displaying output using\n * the user-requested view, or the default if the user requested a view\n * that is not defined for this command.\n */\nexport const outputCommand = async <T>(\n cliCommand: Command<T>,\n conf: LoadedConfig,\n { start }: { start: number } = { start: Date.now() },\n) => {\n const { usage, views, command } = cliCommand\n if (conf.get('help')) {\n return stdout(usage().usage())\n }\n\n const formatOptions = {\n colors: conf.values.color,\n depth: Infinity,\n maxArrayLength: Infinity,\n maxStringLength: Infinity,\n } as const satisfies InspectOptions\n\n const { onDone, onError } = startView(conf, views, { start })\n\n try {\n const output = await onDone(await command(conf))\n if (output !== undefined) {\n stdout(\n conf.values.view === 'json' ?\n JSON.stringify(output, null, 2)\n : formatWithOptions(formatOptions, output),\n )\n }\n } catch (err) {\n onError?.(err)\n process.exitCode ||= 1\n\n printErr(err, usage, stderr, formatOptions)\n\n process.exit(process.exitCode)\n }\n}\n"]}
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/output.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,SAAS,IAAI,aAAa,GAC3B,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAGpD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EACL,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,kBAAkB,CAAA;AAEzB,MAAM,aAAa,GAAG,CAAC,MAAmB,EAAE,EAAE;IAC5C,MAAM,GAAG,GAAG,mBAAmB,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAA;IAC9D,IAAI,GAAG,KAAK,KAAK;QAAE,OAAO,KAAK,CAAA;IAC/B,oBAAoB;IACpB,OAAO,GAAG,CAAC,KAAK,GAAG,CAAC,CAAA;AACtB,CAAC,CAAA;AAED,sCAAsC;AACtC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;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AAM,GAAG,MAAM,MAAM,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;QAChD,IAAI,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC1D,MAAM,CACJ,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;gBAC3B,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;gBACjC,CAAC,CAAC,iBAAiB,CACf;oBACE,GAAG,aAAa;oBAChB,MAAM,EAAE,WAAW;iBACpB,EACD,MAAM,CACP,CACJ,CAAA;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,EAAE,CAAC,GAAG,CAAC,CAAA;QACd,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAA;QAEtB,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE;YAC3B,GAAG,aAAa;YAChB,MAAM,EAAE,WAAW;SACpB,CAAC,CAAA;QAEF,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAChC,CAAC;AACH,CAAC,CAAA","sourcesContent":["import type { WriteStream } from 'node:tty'\nimport {\n formatWithOptions,\n styleText as utilStyleText,\n} from 'node:util'\nimport { createSupportsColor } from 'supports-color'\nimport { defaultView } from './config/definition.ts'\nimport type { LoadedConfig } from './config/index.ts'\nimport type { Command } from './index.ts'\nimport { printErr, formatOptions } from './print-err.ts'\nimport type { View, ViewOptions, Views } from './view.ts'\nimport { isViewClass } from './view.ts'\nimport {\n generateDefaultHelp,\n generateFullHelp,\n} from './custom-help.ts'\n\nconst supportsColor = (stream: WriteStream) => {\n const res = createSupportsColor(stream, { sniffFlags: false })\n if (res === false) return false\n /* c8 ignore next */\n return res.level > 0\n}\n\n// eslint-disable-next-line no-console\nexport const stdout = (...args: unknown[]) => console.log(...args)\n// eslint-disable-next-line no-console\nexport const stderr = (...args: unknown[]) => console.error(...args)\n\ntype StyleTextFn = (\n format: Parameters<typeof utilStyleText>[0],\n s: string,\n) => string\n\n/* c8 ignore start */\nconst styleText: StyleTextFn = (f, s) =>\n utilStyleText(f, s, { validateStream: false })\n/* c8 ignore stop */\n\n// TODO: stop exporting mutable variables once exec output is refactored\n/* c8 ignore start */\nexport let styleTextStdout: StyleTextFn = (_, s) => s\nexport let styleTextStderr: StyleTextFn = (_, s) => s\n/* c8 ignore stop */\n\nconst identity = <T>(x: T): T => x\n\nexport const getView = <T>(\n conf: LoadedConfig,\n views?: Views<T>,\n): View<T> => {\n const viewName = conf.values.view\n\n const viewFn =\n viewName === 'inspect' ? identity\n : viewName === 'silent' ? () => undefined\n : typeof views === 'function' ? views\n : views && typeof views === 'object' ? views[viewName]\n : identity\n\n // if the user specified a view that doesn't exist, then set it back to the\n // default, and try again. This will fall back to identity if it's also\n // missing. We also always treat 'json' as a valid view that falls back to\n // identity. This allows the explicit use of `--view=json` to work even\n // when the default view is `human`.\n if (\n !viewFn &&\n conf.values.view !== defaultView &&\n conf.values.view !== 'json' &&\n conf.values.view !== 'silent'\n ) {\n conf.values.view = defaultView\n process.env.VLT_VIEW = defaultView\n return getView(conf, views)\n }\n\n return viewFn ?? identity\n}\n\nexport type OnDone<T> = (result: T) => Promise<unknown>\n\n/**\n * If the view is a View class, then instantiate and start it.\n * If it's a view function, then just define the onDone method.\n */\nconst startView = <T>(\n conf: LoadedConfig,\n opts: ViewOptions,\n views?: Views<T>,\n { start }: { start: number } = { start: Date.now() },\n): {\n onDone: OnDone<T>\n onError?: (err: unknown) => void\n} => {\n const View = getView<T>(conf, views)\n\n if (isViewClass(View)) {\n const view = new View(opts, conf)\n view.start()\n return {\n async onDone(r) {\n return view.done(r, { time: Date.now() - start })\n },\n onError(err) {\n view.error(err)\n },\n }\n }\n\n return {\n async onDone(r) {\n if (r === undefined) return\n return View(r, opts, conf)\n },\n }\n}\n\n/**\n * Main export. Run the command appropriately, displaying output using\n * the user-requested view, or the default if the user requested a view\n * that is not defined for this command.\n */\nexport const outputCommand = async <T>(\n cliCommand: Command<T>,\n conf: LoadedConfig,\n { start }: { start: number } = { start: Date.now() },\n) => {\n const { usage, views, command } = cliCommand\n\n const stdoutColor =\n conf.values.color ?? supportsColor(process.stdout)\n const stderrColor =\n conf.values.color ?? supportsColor(process.stderr)\n\n if (conf.values.help) {\n // Show custom help for main vlt command\n /* c8 ignore start */\n if (conf.command === 'help' && conf.positionals.length === 0) {\n if (conf.get('all')) {\n return stdout(generateFullHelp(stdoutColor))\n }\n return stdout(generateDefaultHelp(stdoutColor))\n }\n /* c8 ignore stop */\n return stdout(usage().usage())\n }\n\n /* c8 ignore start */\n if (stdoutColor) styleTextStdout = styleText\n if (stderrColor) styleTextStderr = styleText\n /* c8 ignore stop */\n\n const { onDone, onError } = startView(\n conf,\n // assume views will always output to stdout so use color support from there\n { colors: stdoutColor },\n views,\n { start },\n )\n\n try {\n const output = await onDone(await command(conf))\n if (output !== undefined && conf.values.view !== 'silent') {\n stdout(\n conf.values.view === 'json' ?\n JSON.stringify(output, null, 2)\n : formatWithOptions(\n {\n ...formatOptions,\n colors: stdoutColor,\n },\n output,\n ),\n )\n }\n } catch (err) {\n onError?.(err)\n process.exitCode ||= 1\n\n printErr(err, usage, stderr, {\n ...formatOptions,\n colors: stderrColor,\n })\n\n process.exit(process.exitCode)\n }\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import type { NormalizedManifest } from '@vltpkg/types';
2
+ import type { LoadedConfig } from './config/index.ts';
3
+ export type PackTarballResult = {
4
+ name: string;
5
+ version: string;
6
+ filename: string;
7
+ tarballName: string;
8
+ tarballData: Buffer;
9
+ unpackedSize: number;
10
+ files: string[];
11
+ integrity?: string;
12
+ shasum?: string;
13
+ };
14
+ /**
15
+ * Create a tarball from a package directory
16
+ * @param {NormalizedManifest} manifest - The manifest of the package to pack
17
+ * @param {string} dir - The directory containing the package to pack
18
+ * @param {LoadedConfig} [config] - The loaded configuration (for workspace/catalog resolution)
19
+ * @returns {Promise<PackTarballResult>} The manifest, filename, and tarball data (unless dry run)
20
+ */
21
+ export declare const packTarball: (manifest: NormalizedManifest, dir: string, config: LoadedConfig) => Promise<PackTarballResult>;
22
+ //# sourceMappingURL=pack-tarball.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack-tarball.d.ts","sourceRoot":"","sources":["../../src/pack-tarball.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAQvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAIrD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAwHD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,aACZ,kBAAkB,OACvB,MAAM,UACH,YAAY,KACnB,OAAO,CAAC,iBAAiB,CAsN3B,CAAA"}
@@ -0,0 +1,249 @@
1
+ import { create as tarCreate, list as tarList } from 'tar';
2
+ import { minimatch } from 'minimatch';
3
+ import { error } from '@vltpkg/error-cause';
4
+ import * as ssri from 'ssri';
5
+ import assert from 'node:assert';
6
+ import { existsSync, statSync } from 'node:fs';
7
+ import { Spec } from '@vltpkg/spec';
8
+ import { join } from 'node:path';
9
+ import { parse, stringify } from 'polite-json';
10
+ /**
11
+ * Replace workspace: and catalog: specs with actual versions
12
+ * @param {NormalizedManifest} manifest_ - The manifest to process
13
+ * @param {LoadedConfig} config - The loaded configuration containing project root, monorepo, and catalog data
14
+ * @returns {NormalizedManifest} The manifest with replaced specs
15
+ */
16
+ const replaceWorkspaceAndCatalogSpecs = (manifest_, config) => {
17
+ // Create a json copy of the manifest to avoid modifying the original
18
+ // preserves original formatting symbols from polite-json
19
+ const manifest = parse(stringify(manifest_));
20
+ // Get workspace and catalog configuration from config
21
+ const { monorepo, catalog = {}, catalogs = {} } = config.options;
22
+ // Process dependency types
23
+ const depTypes = [
24
+ 'dependencies',
25
+ 'devDependencies',
26
+ 'optionalDependencies',
27
+ 'peerDependencies',
28
+ ];
29
+ for (const depType of depTypes) {
30
+ const deps = manifest[depType];
31
+ /* c8 ignore next */
32
+ if (!deps || typeof deps !== 'object')
33
+ continue;
34
+ const depsObj = deps;
35
+ for (const [depName, depSpec] of Object.entries(depsObj)) {
36
+ /* c8 ignore next */
37
+ if (typeof depSpec !== 'string')
38
+ continue;
39
+ const spec = Spec.parse(`${depName}@${depSpec}`, {
40
+ catalog,
41
+ catalogs,
42
+ });
43
+ switch (spec.type) {
44
+ case 'workspace': {
45
+ assert(monorepo, error(`No workspace configuration found for ${depName}`, {
46
+ found: depName,
47
+ }));
48
+ const workspaceName = spec.workspace;
49
+ assert(workspaceName, error(`No workspace name found for ${depName}`, {
50
+ found: depName,
51
+ }));
52
+ const workspace = monorepo.get(workspaceName);
53
+ assert(workspace, error(`Workspace '${workspaceName}' not found`, {
54
+ found: workspaceName,
55
+ validOptions: Array.from(monorepo.keys()),
56
+ }));
57
+ const actualVersion = workspace.manifest.version;
58
+ assert(actualVersion, error(`No version found for workspace '${workspaceName}'`, {
59
+ found: workspaceName,
60
+ wanted: 'package version',
61
+ }));
62
+ depsObj[depName] = actualVersion;
63
+ break;
64
+ }
65
+ case 'catalog': {
66
+ const catalogName = spec.catalog || '';
67
+ const targetCatalog = catalogName ? catalogs[catalogName] : catalog;
68
+ assert(targetCatalog, error(`Catalog '${catalogName}' not found`, {
69
+ found: catalogName,
70
+ validOptions: Object.keys(catalogs),
71
+ }));
72
+ const actualVersion = targetCatalog[depName];
73
+ assert(actualVersion, error(`Package '${depName}' not found in catalog '${catalogName || 'default'}'`, {
74
+ found: depName,
75
+ validOptions: Object.keys(targetCatalog),
76
+ }));
77
+ depsObj[depName] = actualVersion;
78
+ break;
79
+ }
80
+ }
81
+ }
82
+ }
83
+ return manifest;
84
+ };
85
+ /**
86
+ * Create a tarball from a package directory
87
+ * @param {NormalizedManifest} manifest - The manifest of the package to pack
88
+ * @param {string} dir - The directory containing the package to pack
89
+ * @param {LoadedConfig} [config] - The loaded configuration (for workspace/catalog resolution)
90
+ * @returns {Promise<PackTarballResult>} The manifest, filename, and tarball data (unless dry run)
91
+ */
92
+ export const packTarball = async (manifest, dir, config) => {
93
+ let packDir = dir;
94
+ // Check if publishDirectory is configured
95
+ const publishDirectory = config.get('publish-directory');
96
+ if (publishDirectory) {
97
+ // Validate that the publish directory exists and is a directory
98
+ assert(existsSync(publishDirectory), error(`Publish directory does not exist: ${publishDirectory}`, {
99
+ found: publishDirectory,
100
+ }));
101
+ assert(statSync(publishDirectory).isDirectory(), error(`Publish directory is not a directory: ${publishDirectory}`, {
102
+ found: publishDirectory,
103
+ wanted: 'directory',
104
+ }));
105
+ if (existsSync(join(publishDirectory, 'package.json'))) {
106
+ manifest = config.options.packageJson.read(publishDirectory);
107
+ }
108
+ packDir = publishDirectory;
109
+ }
110
+ assert(manifest.name && manifest.version, error('Package must have a name and version'));
111
+ const processedManifest = replaceWorkspaceAndCatalogSpecs(manifest, config);
112
+ const filename = `${manifest.name.replace('@', '').replace('/', '-')}-${manifest.version}.tgz`;
113
+ const tarballName = `${manifest.name}-${manifest.version}.tgz`;
114
+ try {
115
+ config.options.packageJson.write(packDir, processedManifest);
116
+ const tarballData = await tarCreate({
117
+ cwd: packDir,
118
+ gzip: true,
119
+ portable: true,
120
+ prefix: 'package/',
121
+ filter: (path) => {
122
+ // Normalize path - remove leading './'
123
+ const normalizedPath = path.replace(/^\.\//, '');
124
+ // Always include root directory
125
+ if (path === '.' || normalizedPath === '') {
126
+ return true;
127
+ }
128
+ // Always exclude certain files/directories
129
+ const alwaysExcludePatterns = [
130
+ /^\.?\/?\.git(\/|$)/,
131
+ /^\.?\/?node_modules(\/|$)/,
132
+ /^\.?\/?\.nyc_output(\/|$)/,
133
+ /^\.?\/?coverage(\/|$)/,
134
+ /^\.?\/?\.DS_Store$/,
135
+ /^\.?\/?\.npmrc$/,
136
+ /^\.?\/?package-lock\.json$/,
137
+ /^\.?\/?yarn\.lock$/,
138
+ /^\.?\/?pnpm-lock\.yaml$/,
139
+ /^\.?\/?bun\.lockb$/,
140
+ /^\.?\/?bun\.lock$/,
141
+ /^\.?\/?vlt-lock\.json$/,
142
+ /~$/,
143
+ /\.swp$/,
144
+ ];
145
+ if (alwaysExcludePatterns.some(pattern => pattern.test(normalizedPath))) {
146
+ return false;
147
+ }
148
+ // Always include certain files
149
+ const alwaysIncludePatterns = [
150
+ /^README(\..*)?$/i,
151
+ /^CHANGELOG(\..*)?$/i,
152
+ /^HISTORY(\..*)?$/i,
153
+ /^LICENSE(\..*)?$/i,
154
+ /^LICENCE(\..*)?$/i,
155
+ ];
156
+ if (alwaysIncludePatterns.some(pattern => pattern.test(normalizedPath))) {
157
+ return true;
158
+ }
159
+ // Always include package.json
160
+ if (normalizedPath === 'package.json') {
161
+ return true;
162
+ }
163
+ // If files field is specified in package.json, use it for inclusion
164
+ const manifestWithFiles = manifest;
165
+ if (manifestWithFiles.files &&
166
+ Array.isArray(manifestWithFiles.files)) {
167
+ // Empty files array means exclude everything except always-included files
168
+ if (manifestWithFiles.files.length === 0) {
169
+ return false;
170
+ }
171
+ return manifestWithFiles.files.some((pattern) => {
172
+ if (pattern.endsWith('/')) {
173
+ const dirName = pattern.slice(0, -1);
174
+ const globPattern = pattern.replace(/\/$/, '/**');
175
+ const matchesDir = normalizedPath === dirName;
176
+ const matchesContents = minimatch(normalizedPath, globPattern, {
177
+ dot: true,
178
+ });
179
+ return matchesDir || matchesContents;
180
+ }
181
+ // File pattern: check direct match and if this path is a directory that could contain the pattern
182
+ const directMatch = minimatch(normalizedPath, pattern, {
183
+ dot: true,
184
+ });
185
+ // Check if this path is a directory that could contain the pattern
186
+ const isParentDir = pattern.includes('/') &&
187
+ pattern.startsWith(normalizedPath + '/');
188
+ return directMatch || isParentDir;
189
+ });
190
+ }
191
+ // Default behavior when no files field - exclude common development files
192
+ const defaultExcludePatterns = [
193
+ /^\.?\/?\.vscode(\/|$)/,
194
+ /^\.?\/?\.idea(\/|$)/,
195
+ /^\.?\/?\.gitignore$/,
196
+ /^\.?\/?\.npmignore$/,
197
+ /^\.?\/?\.editorconfig$/,
198
+ ];
199
+ return !defaultExcludePatterns.some(pattern => pattern.test(normalizedPath));
200
+ },
201
+ }, ['.']).concat();
202
+ let unpackedSize = 0;
203
+ const files = [];
204
+ await new Promise((resolve, reject) => {
205
+ const stream = tarList({
206
+ onentry: entry => {
207
+ if (entry.type === 'File') {
208
+ unpackedSize += entry.size;
209
+ // Remove the package/ prefix for cleaner file listing
210
+ const cleanPath = entry.path.replace(/^[^/]+\//, '');
211
+ if (cleanPath) {
212
+ // Skip empty paths
213
+ files.push(cleanPath);
214
+ }
215
+ }
216
+ },
217
+ });
218
+ stream
219
+ .on('end', () => resolve())
220
+ .on('error', reject)
221
+ .write(tarballData);
222
+ stream.end();
223
+ });
224
+ const integrityMap = ssri.fromData(tarballData, {
225
+ algorithms: [...new Set(['sha1', 'sha512'])],
226
+ });
227
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
228
+ const integrity = integrityMap.sha512?.[0]?.toString();
229
+ // @ts-expect-error -- types from DT are missing hexDigest
230
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
231
+ const shasum = integrityMap.sha1?.[0]?.hexDigest();
232
+ return {
233
+ name: manifest.name,
234
+ version: manifest.version,
235
+ filename,
236
+ tarballName,
237
+ tarballData,
238
+ unpackedSize,
239
+ files,
240
+ integrity,
241
+ shasum,
242
+ };
243
+ }
244
+ finally {
245
+ // Restore the original package.json to the pack directory
246
+ config.options.packageJson.write(packDir, manifest);
247
+ }
248
+ };
249
+ //# sourceMappingURL=pack-tarball.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack-tarball.js","sourceRoot":"","sources":["../../src/pack-tarball.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,KAAK,CAAA;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAc9C;;;;;GAKG;AACH,MAAM,+BAA+B,GAAG,CACtC,SAA6B,EAC7B,MAAoB,EACA,EAAE;IACtB,qEAAqE;IACrE,yDAAyD;IACzD,MAAM,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAuB,CAAA;IAElE,sDAAsD;IACtD,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC,OAAO,CAAA;IAEhE,2BAA2B;IAC3B,MAAM,QAAQ,GAAG;QACf,cAAc;QACd,iBAAiB;QACjB,sBAAsB;QACtB,kBAAkB;KACV,CAAA;IAEV,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;QAC9B,oBAAoB;QACpB,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KA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,SAAS;YACT,MAAM;SACP,CAAA;IACH,CAAC;YAAS,CAAC;QACT,0DAA0D;QAC1D,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IACrD,CAAC;AACH,CAAC,CAAA","sourcesContent":["import type { NormalizedManifest } from '@vltpkg/types'\nimport { create as tarCreate, list as tarList } from 'tar'\nimport { minimatch } from 'minimatch'\nimport { error } from '@vltpkg/error-cause'\nimport * as ssri from 'ssri'\nimport assert from 'node:assert'\nimport { existsSync, statSync } from 'node:fs'\nimport { Spec } from '@vltpkg/spec'\nimport type { LoadedConfig } from './config/index.ts'\nimport { join } from 'node:path'\nimport { parse, stringify } from 'polite-json'\n\nexport type PackTarballResult = {\n name: string\n version: string\n filename: string\n tarballName: string\n tarballData: Buffer\n unpackedSize: number\n files: string[]\n integrity?: string\n shasum?: string\n}\n\n/**\n * Replace workspace: and catalog: specs with actual versions\n * @param {NormalizedManifest} manifest_ - The manifest to process\n * @param {LoadedConfig} config - The loaded configuration containing project root, monorepo, and catalog data\n * @returns {NormalizedManifest} The manifest with replaced specs\n */\nconst replaceWorkspaceAndCatalogSpecs = (\n manifest_: NormalizedManifest,\n config: LoadedConfig,\n): NormalizedManifest => {\n // Create a json copy of the manifest to avoid modifying the original\n // preserves original formatting symbols from polite-json\n const manifest = parse(stringify(manifest_)) as NormalizedManifest\n\n // Get workspace and catalog configuration from config\n const { monorepo, catalog = {}, catalogs = {} } = config.options\n\n // Process dependency types\n const depTypes = [\n 'dependencies',\n 'devDependencies',\n 'optionalDependencies',\n 'peerDependencies',\n ] as const\n\n for (const depType of depTypes) {\n const deps = manifest[depType]\n /* c8 ignore next */\n if (!deps || typeof deps !== 'object') continue\n\n const depsObj = deps as Record<string, unknown>\n for (const [depName, depSpec] of Object.entries(depsObj)) {\n /* c8 ignore next */\n if (typeof depSpec !== 'string') continue\n\n const spec = Spec.parse(`${depName}@${depSpec}`, {\n catalog,\n catalogs,\n })\n\n switch (spec.type) {\n case 'workspace': {\n assert(\n monorepo,\n error(`No workspace configuration found for ${depName}`, {\n found: depName,\n }),\n )\n\n const workspaceName = spec.workspace\n assert(\n workspaceName,\n error(`No workspace name found for ${depName}`, {\n found: depName,\n }),\n )\n\n const workspace = monorepo.get(workspaceName)\n assert(\n workspace,\n error(`Workspace '${workspaceName}' not found`, {\n found: workspaceName,\n validOptions: Array.from(monorepo.keys()),\n }),\n )\n\n const actualVersion = workspace.manifest.version\n assert(\n actualVersion,\n error(\n `No version found for workspace '${workspaceName}'`,\n {\n found: workspaceName,\n wanted: 'package version',\n },\n ),\n )\n\n depsObj[depName] = actualVersion\n\n break\n }\n\n case 'catalog': {\n const catalogName = spec.catalog || ''\n const targetCatalog =\n catalogName ? catalogs[catalogName] : catalog\n assert(\n targetCatalog,\n error(`Catalog '${catalogName}' not found`, {\n found: catalogName,\n validOptions: Object.keys(catalogs),\n }),\n )\n\n const actualVersion = targetCatalog[depName]\n assert(\n actualVersion,\n error(\n `Package '${depName}' not found in catalog '${catalogName || 'default'}'`,\n {\n found: depName,\n validOptions: Object.keys(targetCatalog),\n },\n ),\n )\n\n depsObj[depName] = actualVersion\n\n break\n }\n }\n }\n }\n\n return manifest\n}\n\n/**\n * Create a tarball from a package directory\n * @param {NormalizedManifest} manifest - The manifest of the package to pack\n * @param {string} dir - The directory containing the package to pack\n * @param {LoadedConfig} [config] - The loaded configuration (for workspace/catalog resolution)\n * @returns {Promise<PackTarballResult>} The manifest, filename, and tarball data (unless dry run)\n */\nexport const packTarball = async (\n manifest: NormalizedManifest,\n dir: string,\n config: LoadedConfig,\n): Promise<PackTarballResult> => {\n let packDir = dir\n\n // Check if publishDirectory is configured\n const publishDirectory = config.get('publish-directory')\n if (publishDirectory) {\n // Validate that the publish directory exists and is a directory\n assert(\n existsSync(publishDirectory),\n error(`Publish directory does not exist: ${publishDirectory}`, {\n found: publishDirectory,\n }),\n )\n assert(\n statSync(publishDirectory).isDirectory(),\n error(\n `Publish directory is not a directory: ${publishDirectory}`,\n {\n found: publishDirectory,\n wanted: 'directory',\n },\n ),\n )\n if (existsSync(join(publishDirectory, 'package.json'))) {\n manifest = config.options.packageJson.read(publishDirectory)\n }\n packDir = publishDirectory\n }\n\n assert(\n manifest.name && manifest.version,\n error('Package must have a name and version'),\n )\n\n const processedManifest = replaceWorkspaceAndCatalogSpecs(\n manifest,\n config,\n )\n\n const filename = `${manifest.name.replace('@', '').replace('/', '-')}-${manifest.version}.tgz`\n const tarballName = `${manifest.name}-${manifest.version}.tgz`\n\n try {\n config.options.packageJson.write(packDir, processedManifest)\n\n const tarballData = await tarCreate(\n {\n cwd: packDir,\n gzip: true,\n portable: true,\n prefix: 'package/',\n filter: (path: string) => {\n // Normalize path - remove leading './'\n const normalizedPath = path.replace(/^\\.\\//, '')\n\n // Always include root directory\n if (path === '.' || normalizedPath === '') {\n return true\n }\n\n // Always exclude certain files/directories\n const alwaysExcludePatterns = [\n /^\\.?\\/?\\.git(\\/|$)/,\n /^\\.?\\/?node_modules(\\/|$)/,\n /^\\.?\\/?\\.nyc_output(\\/|$)/,\n /^\\.?\\/?coverage(\\/|$)/,\n /^\\.?\\/?\\.DS_Store$/,\n /^\\.?\\/?\\.npmrc$/,\n /^\\.?\\/?package-lock\\.json$/,\n /^\\.?\\/?yarn\\.lock$/,\n /^\\.?\\/?pnpm-lock\\.yaml$/,\n /^\\.?\\/?bun\\.lockb$/,\n /^\\.?\\/?bun\\.lock$/,\n /^\\.?\\/?vlt-lock\\.json$/,\n /~$/,\n /\\.swp$/,\n ]\n\n if (\n alwaysExcludePatterns.some(pattern =>\n pattern.test(normalizedPath),\n )\n ) {\n return false\n }\n\n // Always include certain files\n const alwaysIncludePatterns = [\n /^README(\\..*)?$/i,\n /^CHANGELOG(\\..*)?$/i,\n /^HISTORY(\\..*)?$/i,\n /^LICENSE(\\..*)?$/i,\n /^LICENCE(\\..*)?$/i,\n ]\n\n if (\n alwaysIncludePatterns.some(pattern =>\n pattern.test(normalizedPath),\n )\n ) {\n return true\n }\n\n // Always include package.json\n if (normalizedPath === 'package.json') {\n return true\n }\n\n // If files field is specified in package.json, use it for inclusion\n const manifestWithFiles = manifest as NormalizedManifest & {\n files?: string[]\n }\n if (\n manifestWithFiles.files &&\n Array.isArray(manifestWithFiles.files)\n ) {\n // Empty files array means exclude everything except always-included files\n if (manifestWithFiles.files.length === 0) {\n return false\n }\n return manifestWithFiles.files.some((pattern: string) => {\n if (pattern.endsWith('/')) {\n const dirName = pattern.slice(0, -1)\n const globPattern = pattern.replace(/\\/$/, '/**')\n const matchesDir = normalizedPath === dirName\n const matchesContents = minimatch(\n normalizedPath,\n globPattern,\n {\n dot: true,\n },\n )\n return matchesDir || matchesContents\n }\n\n // File pattern: check direct match and if this path is a directory that could contain the pattern\n const directMatch = minimatch(normalizedPath, pattern, {\n dot: true,\n })\n // Check if this path is a directory that could contain the pattern\n const isParentDir =\n pattern.includes('/') &&\n pattern.startsWith(normalizedPath + '/')\n return directMatch || isParentDir\n })\n }\n\n // Default behavior when no files field - exclude common development files\n const defaultExcludePatterns = [\n /^\\.?\\/?\\.vscode(\\/|$)/,\n /^\\.?\\/?\\.idea(\\/|$)/,\n /^\\.?\\/?\\.gitignore$/,\n /^\\.?\\/?\\.npmignore$/,\n /^\\.?\\/?\\.editorconfig$/,\n ]\n\n return !defaultExcludePatterns.some(pattern =>\n pattern.test(normalizedPath),\n )\n },\n },\n ['.'],\n ).concat()\n\n let unpackedSize = 0\n const files: string[] = []\n await new Promise<void>((resolve, reject) => {\n const stream = tarList({\n onentry: entry => {\n if (entry.type === 'File') {\n unpackedSize += entry.size\n // Remove the package/ prefix for cleaner file listing\n const cleanPath = entry.path.replace(/^[^/]+\\//, '')\n if (cleanPath) {\n // Skip empty paths\n files.push(cleanPath)\n }\n }\n },\n })\n stream\n .on('end', () => resolve())\n .on('error', reject)\n .write(tarballData)\n stream.end()\n })\n\n const integrityMap = ssri.fromData(tarballData, {\n algorithms: [...new Set(['sha1', 'sha512'])],\n })\n\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n const integrity = integrityMap.sha512?.[0]?.toString()\n // @ts-expect-error -- types from DT are missing hexDigest\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n const shasum = integrityMap.sha1?.[0]?.hexDigest() as\n | string\n | undefined\n\n return {\n name: manifest.name,\n version: manifest.version,\n filename,\n tarballName,\n tarballData,\n unpackedSize,\n files,\n integrity,\n shasum,\n }\n } finally {\n // Restore the original package.json to the pack directory\n config.options.packageJson.write(packDir, manifest)\n }\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import type { PathScurry } from 'path-scurry';
1
2
  import type { AddImportersDependenciesMap, RemoveImportersDependenciesMap } from '@vltpkg/graph';
2
3
  import type { Monorepo } from '@vltpkg/workspaces';
3
4
  import type { LoadedConfig } from './config/index.ts';
@@ -17,6 +18,12 @@ export type WorkspaceTypes = {
17
18
  workspace?: string[];
18
19
  'workspace-group'?: string[];
19
20
  };
20
- export declare const parseAddArgs: (config: LoadedConfig, monorepo?: Monorepo) => ParsedAddArgs;
21
- export declare const parseRemoveArgs: (config: LoadedConfig, monorepo?: Monorepo) => ParsedRemoveArgs;
21
+ /**
22
+ * Parses the positional arguments into {@link AddImportersDependenciesMap}.
23
+ */
24
+ export declare const parseAddArgs: (config: LoadedConfig, scurry: PathScurry, monorepo?: Monorepo) => ParsedAddArgs;
25
+ /**
26
+ * Parses the positional arguments into {@link RemoveImportersDependenciesMap}.
27
+ */
28
+ export declare const parseRemoveArgs: (config: LoadedConfig, scurry: PathScurry, monorepo?: Monorepo) => ParsedRemoveArgs;
22
29
  //# sourceMappingURL=parse-add-remove-args.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-add-remove-args.d.ts","sourceRoot":"","sources":["../../src/parse-add-remove-args.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,2BAA2B,EAE3B,8BAA8B,EAC/B,MAAM,eAAe,CAAA;AAKtB,OAAO,KAAK,EAAE,QAAQ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