@vltpkg/cli-sdk 0.0.0-9 → 1.0.0-rc.2
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/dist/esm/commands/build.d.ts +25 -0
- package/dist/esm/commands/build.d.ts.map +1 -0
- package/dist/esm/commands/build.js +102 -0
- package/dist/esm/commands/build.js.map +1 -0
- package/dist/esm/commands/cache.d.ts +18 -0
- package/dist/esm/commands/cache.d.ts.map +1 -1
- package/dist/esm/commands/cache.js +48 -2
- package/dist/esm/commands/cache.js.map +1 -1
- package/dist/esm/commands/ci.d.ts +11 -0
- package/dist/esm/commands/ci.d.ts.map +1 -0
- package/dist/esm/commands/ci.js +32 -0
- package/dist/esm/commands/ci.js.map +1 -0
- package/dist/esm/commands/config.d.ts +3 -2
- package/dist/esm/commands/config.d.ts.map +1 -1
- package/dist/esm/commands/config.js +372 -101
- package/dist/esm/commands/config.js.map +1 -1
- package/dist/esm/commands/docs.d.ts +18 -0
- package/dist/esm/commands/docs.d.ts.map +1 -0
- package/dist/esm/commands/docs.js +154 -0
- package/dist/esm/commands/docs.js.map +1 -0
- package/dist/esm/commands/exec-cache.d.ts +49 -0
- package/dist/esm/commands/exec-cache.d.ts.map +1 -0
- package/dist/esm/commands/exec-cache.js +146 -0
- package/dist/esm/commands/exec-cache.js.map +1 -0
- package/dist/esm/commands/exec-local.d.ts +1 -0
- package/dist/esm/commands/exec-local.d.ts.map +1 -1
- package/dist/esm/commands/exec-local.js +2 -0
- package/dist/esm/commands/exec-local.js.map +1 -1
- package/dist/esm/commands/exec.d.ts +6 -1
- package/dist/esm/commands/exec.d.ts.map +1 -1
- package/dist/esm/commands/exec.js +79 -5
- package/dist/esm/commands/exec.js.map +1 -1
- package/dist/esm/commands/help.d.ts +1 -1
- package/dist/esm/commands/help.d.ts.map +1 -1
- package/dist/esm/commands/help.js +32 -3
- package/dist/esm/commands/help.js.map +1 -1
- package/dist/esm/commands/init.d.ts +3 -3
- package/dist/esm/commands/init.d.ts.map +1 -1
- package/dist/esm/commands/init.js +95 -9
- package/dist/esm/commands/init.js.map +1 -1
- package/dist/esm/commands/install/reporter.d.ts +3 -2
- package/dist/esm/commands/install/reporter.d.ts.map +1 -1
- package/dist/esm/commands/install/reporter.js +42 -15
- package/dist/esm/commands/install/reporter.js.map +1 -1
- package/dist/esm/commands/install.d.ts +21 -3
- package/dist/esm/commands/install.d.ts.map +1 -1
- package/dist/esm/commands/install.js +27 -3
- package/dist/esm/commands/install.js.map +1 -1
- package/dist/esm/commands/list.d.ts +2 -2
- package/dist/esm/commands/list.d.ts.map +1 -1
- package/dist/esm/commands/list.js +149 -49
- package/dist/esm/commands/list.js.map +1 -1
- package/dist/esm/commands/pack.d.ts +32 -0
- package/dist/esm/commands/pack.d.ts.map +1 -0
- package/dist/esm/commands/pack.js +147 -0
- package/dist/esm/commands/pack.js.map +1 -0
- package/dist/esm/commands/pkg.d.ts +1 -2
- package/dist/esm/commands/pkg.d.ts.map +1 -1
- package/dist/esm/commands/pkg.js +123 -38
- package/dist/esm/commands/pkg.js.map +1 -1
- package/dist/esm/commands/publish.d.ts +22 -0
- package/dist/esm/commands/publish.d.ts.map +1 -0
- package/dist/esm/commands/publish.js +245 -0
- package/dist/esm/commands/publish.js.map +1 -0
- package/dist/esm/commands/query.d.ts +2 -3
- package/dist/esm/commands/query.d.ts.map +1 -1
- package/dist/esm/commands/query.js +132 -38
- package/dist/esm/commands/query.js.map +1 -1
- package/dist/esm/commands/run-exec.d.ts +1 -0
- package/dist/esm/commands/run-exec.d.ts.map +1 -1
- package/dist/esm/commands/run-exec.js +1 -0
- package/dist/esm/commands/run-exec.js.map +1 -1
- package/dist/esm/commands/run.d.ts +1 -0
- package/dist/esm/commands/run.d.ts.map +1 -1
- package/dist/esm/commands/run.js +13 -16
- package/dist/esm/commands/run.js.map +1 -1
- package/dist/esm/commands/serve.d.ts +14 -0
- package/dist/esm/commands/serve.d.ts.map +1 -0
- package/dist/esm/commands/serve.js +103 -0
- package/dist/esm/commands/serve.js.map +1 -0
- package/dist/esm/commands/uninstall.d.ts +8 -2
- package/dist/esm/commands/uninstall.d.ts.map +1 -1
- package/dist/esm/commands/uninstall.js +8 -3
- package/dist/esm/commands/uninstall.js.map +1 -1
- package/dist/esm/commands/update.d.ts +14 -0
- package/dist/esm/commands/update.d.ts.map +1 -0
- package/dist/esm/commands/update.js +41 -0
- package/dist/esm/commands/update.js.map +1 -0
- package/dist/esm/commands/version.d.ts +26 -0
- package/dist/esm/commands/version.d.ts.map +1 -0
- package/dist/esm/commands/version.js +226 -0
- package/dist/esm/commands/version.js.map +1 -0
- package/dist/esm/config/definition.d.ts +118 -15
- package/dist/esm/config/definition.d.ts.map +1 -1
- package/dist/esm/config/definition.js +185 -37
- package/dist/esm/config/definition.js.map +1 -1
- package/dist/esm/config/index.d.ts +41 -37
- package/dist/esm/config/index.d.ts.map +1 -1
- package/dist/esm/config/index.js +109 -172
- package/dist/esm/config/index.js.map +1 -1
- package/dist/esm/config/merge.d.ts +3 -1
- package/dist/esm/config/merge.d.ts.map +1 -1
- package/dist/esm/config/merge.js +11 -6
- package/dist/esm/config/merge.js.map +1 -1
- package/dist/esm/custom-help.d.ts +9 -0
- package/dist/esm/custom-help.d.ts.map +1 -0
- package/dist/esm/custom-help.js +400 -0
- package/dist/esm/custom-help.js.map +1 -0
- package/dist/esm/exec-command.d.ts +33 -14
- package/dist/esm/exec-command.d.ts.map +1 -1
- package/dist/esm/exec-command.js +213 -64
- package/dist/esm/exec-command.js.map +1 -1
- package/dist/esm/index.d.ts +1 -14
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +45 -19
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/load-command.d.ts +16 -0
- package/dist/esm/load-command.d.ts.map +1 -0
- package/dist/esm/load-command.js +21 -0
- package/dist/esm/load-command.js.map +1 -0
- package/dist/esm/output.d.ts +6 -11
- package/dist/esm/output.d.ts.map +1 -1
- package/dist/esm/output.js +64 -27
- package/dist/esm/output.js.map +1 -1
- package/dist/esm/pack-tarball.d.ts +22 -0
- package/dist/esm/pack-tarball.d.ts.map +1 -0
- package/dist/esm/pack-tarball.js +249 -0
- package/dist/esm/pack-tarball.js.map +1 -0
- package/dist/esm/print-err.d.ts +9 -2
- package/dist/esm/print-err.d.ts.map +1 -1
- package/dist/esm/print-err.js +130 -46
- package/dist/esm/print-err.js.map +1 -1
- package/dist/esm/query-host-contexts.d.ts +16 -0
- package/dist/esm/query-host-contexts.d.ts.map +1 -0
- package/dist/esm/query-host-contexts.js +135 -0
- package/dist/esm/query-host-contexts.js.map +1 -0
- package/dist/esm/start-gui.d.ts +1 -0
- package/dist/esm/start-gui.d.ts.map +1 -1
- package/dist/esm/start-gui.js +28 -8
- package/dist/esm/start-gui.js.map +1 -1
- package/dist/esm/view.d.ts +2 -3
- package/dist/esm/view.d.ts.map +1 -1
- package/dist/esm/view.js +1 -1
- package/dist/esm/view.js.map +1 -1
- package/package.json +51 -37
- package/dist/esm/commands/gui.d.ts +0 -6
- package/dist/esm/commands/gui.d.ts.map +0 -1
- package/dist/esm/commands/gui.js +0 -13
- package/dist/esm/commands/gui.js.map +0 -1
package/dist/esm/output.d.ts
CHANGED
|
@@ -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> = (
|
|
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
|
package/dist/esm/output.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/output.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/output.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,SAAS,IAAI,aAAa,EAC3B,MAAM,WAAW,CAAA;AAGlB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,OAAO,KAAK,EAAE,IAAI,EAAe,KAAK,EAAE,MAAM,WAAW,CAAA;AAezD,eAAO,MAAM,MAAM,YAAa,OAAO,EAAE,SAAyB,CAAA;AAElE,eAAO,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"}
|
package/dist/esm/output.js
CHANGED
|
@@ -1,24 +1,45 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
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
|
-
|
|
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
|
-
:
|
|
16
|
-
:
|
|
17
|
-
:
|
|
18
|
-
|
|
19
|
-
// then set it back to the
|
|
20
|
-
// This will fall back to identity if it's also
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const { onDone, onError } = startView(conf,
|
|
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(
|
|
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,
|
|
119
|
+
printErr(err, usage, stderr, {
|
|
120
|
+
...formatOptions,
|
|
121
|
+
colors: stderrColor,
|
|
122
|
+
});
|
|
86
123
|
process.exit(process.exitCode);
|
|
87
124
|
}
|
|
88
125
|
};
|
package/dist/esm/output.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/output.ts"],"names":[],"mappings":"
|
|
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,OA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EpB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CACnC,IAAI;IACJ,4EAA4E;IAC5E,EAAE,MAAM,EAAE,WAAW,EAAE,EACvB,KAAK,EACL,EAAE,KAAK,EAAE,CACV,CAAA;IAED,IAAI,CAAC;QACH,MAAM,MAAM,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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,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;wBACpD,IAAI,SAAS,EAAE,CAAC;4BACd,mBAAmB;4BACnB,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;wBACvB,CAAC;oBACH,CAAC;gBACH,CAAC;aACF,CAAC,CAAA;YACF,MAAM;iBACH,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;iBAC1B,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC;iBACnB,KAAK,CAAC,WAAW,CAAC,CAAA;YACrB,MAAM,CAAC,GAAG,EAAE,CAAA;QACd,CAAC,CAAC,CAAA;QAEF,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE;YAC9C,UAAU,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;SAC7C,CAAC,CAAA;QAEF,gEAAgE;QAChE,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAA;QACtD,0DAA0D;QAC1D,6DAA6D;QAC7D,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAEnC,CAAA;QAEb,OAAO;YACL,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,OAAO,EAAE,QAAQ,CAAC,OAAO;YACzB,QAAQ;YACR,WAAW;YACX,WAAW;YACX,YAAY;YACZ,KAAK;YACL,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"]}
|
package/dist/esm/print-err.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import type { CommandUsage } from './index.ts';
|
|
2
1
|
import type { InspectOptions } from 'node:util';
|
|
2
|
+
import type { CommandUsage } from './index.ts';
|
|
3
|
+
export declare const formatOptions: {
|
|
4
|
+
readonly depth: number;
|
|
5
|
+
readonly maxArrayLength: number;
|
|
6
|
+
readonly maxStringLength: number;
|
|
7
|
+
};
|
|
3
8
|
export type ErrorFormatOptions = InspectOptions & {
|
|
4
9
|
maxLines?: number;
|
|
5
10
|
};
|
|
6
|
-
export
|
|
11
|
+
export type Formatter = (arg: unknown, options?: ErrorFormatOptions) => string;
|
|
12
|
+
export declare const indent: (lines: string, num?: number) => string;
|
|
13
|
+
export declare const printErr: (e: unknown, usage: CommandUsage, stderr: (...a: string[]) => void, baseOpts?: ErrorFormatOptions) => void;
|
|
7
14
|
//# sourceMappingURL=print-err.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"print-err.d.ts","sourceRoot":"","sources":["../../src/print-err.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"print-err.d.ts","sourceRoot":"","sources":["../../src/print-err.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,eAAO,MAAM,aAAa;;;;CAIS,CAAA;AAEnC,MAAM,MAAM,kBAAkB,GAAG,cAAc,GAAG;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,CACtB,GAAG,EAAE,OAAO,EACZ,OAAO,CAAC,EAAE,kBAAkB,KACzB,MAAM,CAAA;AAWX,eAAO,MAAM,MAAM,UAAW,MAAM,yBAIrB,CAAA;AAoBf,eAAO,MAAM,QAAQ,MAChB,OAAO,SACH,YAAY,UACX,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,KAAK,IAAI,aACrB,kBAAkB,SAwC9B,CAAA"}
|