screw-up 1.26.0 → 1.28.0
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/index.cjs +3014 -1096
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +770 -1113
- package/dist/index.mjs.map +1 -1
- package/dist/main.cjs +3802 -1565
- package/dist/main.cjs.map +1 -1
- package/dist/main.mjs +1259 -1508
- package/dist/main.mjs.map +1 -1
- package/dist/metadata-file-DtvzENuT.js +2514 -0
- package/dist/metadata-file-DtvzENuT.js.map +1 -0
- package/dist/packageMetadata-11MbeI_K.js +29 -0
- package/dist/packageMetadata-11MbeI_K.js.map +1 -0
- package/dist/packageMetadata-CCdz0AMJ.cjs +15 -0
- package/dist/packageMetadata-D1X6rTp_.cjs +55 -0
- package/dist/packageMetadata-D1X6rTp_.cjs.map +1 -0
- package/dist/src/analyzer.d.ts +38 -0
- package/dist/src/analyzer.d.ts.map +1 -0
- package/dist/src/cli-internal.d.ts +62 -0
- package/dist/src/cli-internal.d.ts.map +1 -0
- package/dist/src/cli.d.ts +13 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/default-import-fix.d.ts +22 -0
- package/dist/src/default-import-fix.d.ts.map +1 -0
- package/dist/src/fast-tags.d.ts +42 -0
- package/dist/src/fast-tags.d.ts.map +1 -0
- package/dist/src/generated/packageMetadata.d.ts +18 -0
- package/dist/src/generated/packageMetadata.d.ts.map +1 -0
- package/dist/src/git-operations.d.ts +69 -0
- package/dist/src/git-operations.d.ts.map +1 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/internal.d.ts +115 -0
- package/dist/src/internal.d.ts.map +1 -0
- package/dist/{main.d.ts → src/main.d.ts} +5 -3
- package/dist/src/main.d.ts.map +1 -0
- package/dist/src/metadata-file.d.ts +22 -0
- package/dist/src/metadata-file.d.ts.map +1 -0
- package/dist/{index.d.ts → src/types.d.ts} +72 -85
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/vite-plugin.d.ts +26 -0
- package/dist/src/vite-plugin.d.ts.map +1 -0
- package/package.json +19 -19
- package/dist/metadata-file-6Y1AngPB.cjs +0 -2358
- package/dist/metadata-file-6Y1AngPB.cjs.map +0 -1
- package/dist/metadata-file-B4RbKbol.js +0 -2343
- package/dist/metadata-file-B4RbKbol.js.map +0 -1
package/dist/main.mjs
CHANGED
|
@@ -1,1090 +1,989 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/*!
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
3
|
+
* name: screw-up
|
|
4
|
+
* version: 1.28.0
|
|
5
|
+
* description: Simply package metadata inserter on Vite plugin
|
|
6
|
+
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
7
|
+
* license: MIT
|
|
8
|
+
* repository.url: https://github.com/kekyo/screw-up.git
|
|
9
|
+
* git.commit.hash: 4bc8c338f32ab8ed9bbf0b9ad0ba4166d584be65
|
|
10
|
+
*/
|
|
11
|
+
import { a as collectWorkspaceSiblings, c as replacePeerDependenciesWildcards, d as require_dist, i as getFetchGitMetadata, l as resolvePackageMetadata, n as generateMetadataFileContent, o as createConsoleLogger, p as __toESM, r as writeFileIfChanged, s as findWorkspaceRoot, t as ensureMetadataGitignore, u as resolveRawPackageJsonObject } from "./metadata-file-DtvzENuT.js";
|
|
12
|
+
import { n as name } from "./packageMetadata-11MbeI_K.js";
|
|
13
|
+
import { copyFile, mkdir, mkdtemp, readFile, readdir, rm, stat, writeFile } from "fs/promises";
|
|
14
|
+
import { createReadStream, createWriteStream, existsSync, statSync } from "fs";
|
|
15
|
+
import { dirname, isAbsolute, join, resolve } from "path";
|
|
16
|
+
import { glob } from "glob";
|
|
15
17
|
import { spawn } from "child_process";
|
|
16
18
|
import { tmpdir } from "os";
|
|
17
19
|
import { Readable } from "stream";
|
|
18
20
|
import { createGunzip, createGzip } from "zlib";
|
|
19
21
|
import { pipeline } from "stream/promises";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
//#region node_modules/tar-vern/dist/index.js
|
|
23
|
+
/*!
|
|
24
|
+
* name: tar-vern
|
|
25
|
+
* version: 1.3.0
|
|
26
|
+
* description: Tape archiver library for Typescript
|
|
27
|
+
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
28
|
+
* license: MIT
|
|
29
|
+
* repository.url: https://github.com/kekyo/tar-vern.git
|
|
30
|
+
* git.commit.hash: 7ac8b1f258e17c93767650ef047a2db9f0ffd417
|
|
31
|
+
*/
|
|
32
|
+
var MAX_NAME = 100;
|
|
33
|
+
var MAX_PREFIX = 155;
|
|
34
|
+
var getUName = (candidateName, candidateId, reflectStat) => {
|
|
35
|
+
return candidateName !== null && candidateName !== void 0 ? candidateName : reflectStat === "all" ? candidateId.toString() : "root";
|
|
26
36
|
};
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
var getBuffer = (data) => {
|
|
38
|
+
return Buffer.isBuffer(data) ? data : Buffer.from(data, "utf8");
|
|
29
39
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
};
|
|
68
|
-
}
|
|
40
|
+
var createDirectoryItem = async (path, reflectStat, options, signal) => {
|
|
41
|
+
const rs = reflectStat !== null && reflectStat !== void 0 ? reflectStat : "none";
|
|
42
|
+
if (rs !== "none" && (options === null || options === void 0 ? void 0 : options.directoryPath)) {
|
|
43
|
+
var _options$mode, _options$uid, _options$gid, _options$date;
|
|
44
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
45
|
+
const stats = await stat(options.directoryPath);
|
|
46
|
+
const mode = (_options$mode = options === null || options === void 0 ? void 0 : options.mode) !== null && _options$mode !== void 0 ? _options$mode : stats.mode;
|
|
47
|
+
const uid = (_options$uid = options === null || options === void 0 ? void 0 : options.uid) !== null && _options$uid !== void 0 ? _options$uid : stats.uid;
|
|
48
|
+
const gid = (_options$gid = options === null || options === void 0 ? void 0 : options.gid) !== null && _options$gid !== void 0 ? _options$gid : stats.gid;
|
|
49
|
+
const date = (_options$date = options === null || options === void 0 ? void 0 : options.date) !== null && _options$date !== void 0 ? _options$date : stats.mtime;
|
|
50
|
+
return {
|
|
51
|
+
kind: "directory",
|
|
52
|
+
path,
|
|
53
|
+
mode,
|
|
54
|
+
uname: getUName(options === null || options === void 0 ? void 0 : options.uname, stats.uid, rs),
|
|
55
|
+
gname: getUName(options === null || options === void 0 ? void 0 : options.gname, stats.gid, rs),
|
|
56
|
+
uid,
|
|
57
|
+
gid,
|
|
58
|
+
date
|
|
59
|
+
};
|
|
60
|
+
} else {
|
|
61
|
+
var _options$mode2, _options$uid2, _options$gid2, _options$date2;
|
|
62
|
+
const mode = (_options$mode2 = options === null || options === void 0 ? void 0 : options.mode) !== null && _options$mode2 !== void 0 ? _options$mode2 : 493;
|
|
63
|
+
const uid = (_options$uid2 = options === null || options === void 0 ? void 0 : options.uid) !== null && _options$uid2 !== void 0 ? _options$uid2 : 0;
|
|
64
|
+
const gid = (_options$gid2 = options === null || options === void 0 ? void 0 : options.gid) !== null && _options$gid2 !== void 0 ? _options$gid2 : 0;
|
|
65
|
+
const date = (_options$date2 = options === null || options === void 0 ? void 0 : options.date) !== null && _options$date2 !== void 0 ? _options$date2 : /* @__PURE__ */ new Date();
|
|
66
|
+
return {
|
|
67
|
+
kind: "directory",
|
|
68
|
+
path,
|
|
69
|
+
mode,
|
|
70
|
+
uname: getUName(options === null || options === void 0 ? void 0 : options.uname, void 0, rs),
|
|
71
|
+
gname: getUName(options === null || options === void 0 ? void 0 : options.gname, void 0, rs),
|
|
72
|
+
uid,
|
|
73
|
+
gid,
|
|
74
|
+
date
|
|
75
|
+
};
|
|
76
|
+
}
|
|
69
77
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
78
|
+
var createReadableFileItem = async (path, readable, options, signal) => {
|
|
79
|
+
var _options$mode4, _options$uid4, _options$gid4, _options$date4, _options$uname2, _options$gname2;
|
|
80
|
+
const mode = (_options$mode4 = options === null || options === void 0 ? void 0 : options.mode) !== null && _options$mode4 !== void 0 ? _options$mode4 : 420;
|
|
81
|
+
const uid = (_options$uid4 = options === null || options === void 0 ? void 0 : options.uid) !== null && _options$uid4 !== void 0 ? _options$uid4 : 0;
|
|
82
|
+
const gid = (_options$gid4 = options === null || options === void 0 ? void 0 : options.gid) !== null && _options$gid4 !== void 0 ? _options$gid4 : 0;
|
|
83
|
+
const date = (_options$date4 = options === null || options === void 0 ? void 0 : options.date) !== null && _options$date4 !== void 0 ? _options$date4 : /* @__PURE__ */ new Date();
|
|
84
|
+
const uname = (_options$uname2 = options === null || options === void 0 ? void 0 : options.uname) !== null && _options$uname2 !== void 0 ? _options$uname2 : "root";
|
|
85
|
+
const gname = (_options$gname2 = options === null || options === void 0 ? void 0 : options.gname) !== null && _options$gname2 !== void 0 ? _options$gname2 : "root";
|
|
86
|
+
let length = options === null || options === void 0 ? void 0 : options.length;
|
|
87
|
+
if (!length) {
|
|
88
|
+
const chunks = [];
|
|
89
|
+
length = 0;
|
|
90
|
+
for await (const chunk of readable) {
|
|
91
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
92
|
+
const buffer = getBuffer(chunk);
|
|
93
|
+
chunks.push(buffer);
|
|
94
|
+
length += buffer.length;
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
kind: "file",
|
|
98
|
+
path,
|
|
99
|
+
mode,
|
|
100
|
+
uname,
|
|
101
|
+
gname,
|
|
102
|
+
uid,
|
|
103
|
+
gid,
|
|
104
|
+
date,
|
|
105
|
+
content: {
|
|
106
|
+
kind: "readable",
|
|
107
|
+
length,
|
|
108
|
+
readable: Readable.from(chunks, { signal })
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
} else return {
|
|
112
|
+
kind: "file",
|
|
113
|
+
path,
|
|
114
|
+
mode,
|
|
115
|
+
uname,
|
|
116
|
+
gname,
|
|
117
|
+
uid,
|
|
118
|
+
gid,
|
|
119
|
+
date,
|
|
120
|
+
content: {
|
|
121
|
+
kind: "readable",
|
|
122
|
+
length,
|
|
123
|
+
readable
|
|
124
|
+
}
|
|
125
|
+
};
|
|
119
126
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
127
|
+
var createReadFileItem = async (path, filePath, reflectStat, options, signal) => {
|
|
128
|
+
var _options$mode6, _options$uid6, _options$gid6, _options$date6;
|
|
129
|
+
const rs = reflectStat !== null && reflectStat !== void 0 ? reflectStat : "exceptName";
|
|
130
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
131
|
+
const stats = await stat(filePath);
|
|
132
|
+
const reader = createReadStream(filePath, { signal });
|
|
133
|
+
const mode = (_options$mode6 = options === null || options === void 0 ? void 0 : options.mode) !== null && _options$mode6 !== void 0 ? _options$mode6 : rs !== "none" ? stats.mode : void 0;
|
|
134
|
+
const uid = (_options$uid6 = options === null || options === void 0 ? void 0 : options.uid) !== null && _options$uid6 !== void 0 ? _options$uid6 : rs !== "none" ? stats.uid : void 0;
|
|
135
|
+
const gid = (_options$gid6 = options === null || options === void 0 ? void 0 : options.gid) !== null && _options$gid6 !== void 0 ? _options$gid6 : rs !== "none" ? stats.gid : void 0;
|
|
136
|
+
const date = (_options$date6 = options === null || options === void 0 ? void 0 : options.date) !== null && _options$date6 !== void 0 ? _options$date6 : rs !== "none" ? stats.mtime : void 0;
|
|
137
|
+
const uname = getUName(options === null || options === void 0 ? void 0 : options.uname, stats.uid, rs);
|
|
138
|
+
const gname = getUName(options === null || options === void 0 ? void 0 : options.gname, stats.gid, rs);
|
|
139
|
+
return await createReadableFileItem(path, reader, {
|
|
140
|
+
length: stats.size,
|
|
141
|
+
mode,
|
|
142
|
+
uname,
|
|
143
|
+
gname,
|
|
144
|
+
uid,
|
|
145
|
+
gid,
|
|
146
|
+
date
|
|
147
|
+
}, signal);
|
|
139
148
|
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
await pipeline(reader, writer, { signal });
|
|
149
|
+
var storeReaderToFile = async (reader, path, signal) => {
|
|
150
|
+
await pipeline(reader, createWriteStream(path, { signal }), { signal });
|
|
143
151
|
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
} catch (error) {
|
|
166
|
-
console.warn(`Warning: Could not read directory ${currentDir}:`, error);
|
|
167
|
-
return [];
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
return await collectFiles(baseDir, "");
|
|
152
|
+
var getAllFilesInDirectory = async (baseDir, signal) => {
|
|
153
|
+
const collectFiles = async (currentDir, relativePath) => {
|
|
154
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
155
|
+
try {
|
|
156
|
+
const entries = await readdir(currentDir, { withFileTypes: true });
|
|
157
|
+
const result = [];
|
|
158
|
+
const tasks = entries.map(async (entry) => {
|
|
159
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
160
|
+
const entryRelativePath = join(relativePath, entry.name);
|
|
161
|
+
if (entry.isDirectory()) return [entryRelativePath, ...await collectFiles(join(currentDir, entry.name), entryRelativePath)];
|
|
162
|
+
else return [entryRelativePath];
|
|
163
|
+
});
|
|
164
|
+
const allResults = await Promise.all(tasks);
|
|
165
|
+
for (const entryResults of allResults) result.push(...entryResults);
|
|
166
|
+
return result;
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.warn(`Warning: Could not read directory ${currentDir}:`, error);
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
return await collectFiles(baseDir, "");
|
|
171
173
|
};
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
console.warn(`Warning: Could not access ${fsPath}:`, error);
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
174
|
+
var createEntryItemGenerator = async function* (baseDir, relativePaths, includeDirectory, reflectStat, signal) {
|
|
175
|
+
const rs = reflectStat !== null && reflectStat !== void 0 ? reflectStat : "exceptName";
|
|
176
|
+
const includeDir = includeDirectory !== null && includeDirectory !== void 0 ? includeDirectory : true;
|
|
177
|
+
const pathsToProcess = relativePaths !== null && relativePaths !== void 0 ? relativePaths : await getAllFilesInDirectory(baseDir, signal);
|
|
178
|
+
for (const relativePath of pathsToProcess) {
|
|
179
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
180
|
+
const fsPath = join(baseDir, relativePath);
|
|
181
|
+
try {
|
|
182
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
183
|
+
const stats = await stat(fsPath);
|
|
184
|
+
if (includeDir && stats.isDirectory()) yield await createDirectoryItem(relativePath, rs, { directoryPath: fsPath }, signal);
|
|
185
|
+
else if (stats.isFile()) yield await createReadFileItem(relativePath, fsPath, rs, void 0, signal);
|
|
186
|
+
} catch (error) {
|
|
187
|
+
console.warn(`Warning: Could not access ${fsPath}:`, error);
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
193
191
|
};
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
192
|
+
var extractTo = async (iterator, basePath, signal) => {
|
|
193
|
+
for await (const entry of iterator) {
|
|
194
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
195
|
+
const targetPath = join(basePath, entry.path);
|
|
196
|
+
if (entry.kind === "directory") try {
|
|
197
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
198
|
+
await mkdir(targetPath, {
|
|
199
|
+
recursive: true,
|
|
200
|
+
mode: entry.mode
|
|
201
|
+
});
|
|
202
|
+
} catch (error) {
|
|
203
|
+
if (error.code !== "EEXIST") throw error;
|
|
204
|
+
}
|
|
205
|
+
else if (entry.kind === "file") {
|
|
206
|
+
const parentDir = dirname(targetPath);
|
|
207
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
208
|
+
await mkdir(parentDir, { recursive: true });
|
|
209
|
+
await writeFile(targetPath, await entry.getContent("buffer"), {
|
|
210
|
+
mode: entry.mode,
|
|
211
|
+
signal
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
214
215
|
};
|
|
215
|
-
|
|
216
|
-
|
|
216
|
+
var utf8ByteLength = (str) => {
|
|
217
|
+
return Buffer.byteLength(str, "utf8");
|
|
217
218
|
};
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
219
|
+
var truncateUtf8Safe = (str, maxBytes) => {
|
|
220
|
+
let total = 0;
|
|
221
|
+
let i = 0;
|
|
222
|
+
while (i < str.length) {
|
|
223
|
+
const codePoint = str.codePointAt(i);
|
|
224
|
+
const char = String.fromCodePoint(codePoint);
|
|
225
|
+
const charBytes = Buffer.byteLength(char, "utf8");
|
|
226
|
+
if (total + charBytes > maxBytes) break;
|
|
227
|
+
total += charBytes;
|
|
228
|
+
i += char.length;
|
|
229
|
+
}
|
|
230
|
+
return str.slice(0, i);
|
|
230
231
|
};
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
232
|
+
var splitPath = (path) => {
|
|
233
|
+
var _parts$pop;
|
|
234
|
+
if (utf8ByteLength(path) <= MAX_NAME) return {
|
|
235
|
+
prefix: "",
|
|
236
|
+
name: path
|
|
237
|
+
};
|
|
238
|
+
const parts = path.split("/");
|
|
239
|
+
let name = (_parts$pop = parts.pop()) !== null && _parts$pop !== void 0 ? _parts$pop : "";
|
|
240
|
+
let prefix = parts.join("/");
|
|
241
|
+
if (utf8ByteLength(name) > MAX_NAME) name = truncateUtf8Safe(name, MAX_NAME);
|
|
242
|
+
while (utf8ByteLength(prefix) > MAX_PREFIX) prefix = truncateUtf8Safe(prefix, MAX_PREFIX);
|
|
243
|
+
return {
|
|
244
|
+
prefix,
|
|
245
|
+
name
|
|
246
|
+
};
|
|
246
247
|
};
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
248
|
+
var getOctalBytes = (value, length) => {
|
|
249
|
+
const str = value.toString(8).padStart(length - 1, "0") + "\0";
|
|
250
|
+
return Buffer.from(str, "ascii");
|
|
250
251
|
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
} else {
|
|
256
|
-
return Buffer.concat([buffer, Buffer.alloc(512 - extra, 0)]);
|
|
257
|
-
}
|
|
252
|
+
var getPaddedBytes = (buffer) => {
|
|
253
|
+
const extra = buffer.length % 512;
|
|
254
|
+
if (extra === 0) return buffer;
|
|
255
|
+
else return Buffer.concat([buffer, Buffer.alloc(512 - extra, 0)]);
|
|
258
256
|
};
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
for (let i = 0; i < 512; i++) {
|
|
282
|
-
sum += buffer[i];
|
|
283
|
-
}
|
|
284
|
-
getOctalBytes(sum, 8).copy(buffer, 148);
|
|
285
|
-
return buffer;
|
|
257
|
+
var terminatorBytes = Buffer.alloc(1024, 0);
|
|
258
|
+
var createTarHeader = (type, path, size, mode, uname, gname, uid, gid, date) => {
|
|
259
|
+
const buffer = Buffer.alloc(512, 0);
|
|
260
|
+
const { name, prefix } = splitPath(path);
|
|
261
|
+
buffer.write(name, 0, 100, "utf8");
|
|
262
|
+
getOctalBytes(mode & 4095, 8).copy(buffer, 100);
|
|
263
|
+
getOctalBytes(uid, 8).copy(buffer, 108);
|
|
264
|
+
getOctalBytes(gid, 8).copy(buffer, 116);
|
|
265
|
+
getOctalBytes(size, 12).copy(buffer, 124);
|
|
266
|
+
getOctalBytes(Math.floor(date.getTime() / 1e3), 12).copy(buffer, 136);
|
|
267
|
+
Buffer.from(" ", "ascii").copy(buffer, 148);
|
|
268
|
+
if (type === "file") buffer.write("0", 156, 1, "ascii");
|
|
269
|
+
else buffer.write("5", 156, 1, "ascii");
|
|
270
|
+
buffer.write("ustar\0", 257, 6, "ascii");
|
|
271
|
+
buffer.write("00", 263, 2, "ascii");
|
|
272
|
+
buffer.write(uname, 265, 32, "utf8");
|
|
273
|
+
buffer.write(gname, 297, 32, "utf8");
|
|
274
|
+
buffer.write(prefix, 345, 155, "utf8");
|
|
275
|
+
let sum = 0;
|
|
276
|
+
for (let i = 0; i < 512; i++) sum += buffer[i];
|
|
277
|
+
getOctalBytes(sum, 8).copy(buffer, 148);
|
|
278
|
+
return buffer;
|
|
286
279
|
};
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
break;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
if (position % 512 !== 0) {
|
|
345
|
-
yield Buffer.alloc(512 - position % 512, 0);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
break;
|
|
349
|
-
}
|
|
350
|
-
// Entry is a directory
|
|
351
|
-
case "directory": {
|
|
352
|
-
const tarHeaderBytes = createTarHeader(
|
|
353
|
-
"directory",
|
|
354
|
-
entryItem.path,
|
|
355
|
-
0,
|
|
356
|
-
entryItem.mode,
|
|
357
|
-
entryItem.uname,
|
|
358
|
-
entryItem.gname,
|
|
359
|
-
entryItem.uid,
|
|
360
|
-
entryItem.gid,
|
|
361
|
-
entryItem.date
|
|
362
|
-
);
|
|
363
|
-
yield tarHeaderBytes;
|
|
364
|
-
break;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
yield terminatorBytes;
|
|
369
|
-
};
|
|
370
|
-
const ct = compressionType;
|
|
371
|
-
switch (ct) {
|
|
372
|
-
// No compression
|
|
373
|
-
case "none": {
|
|
374
|
-
return Readable.from(entryItemIterator(), { signal });
|
|
375
|
-
}
|
|
376
|
-
// Gzip compression
|
|
377
|
-
case "gzip": {
|
|
378
|
-
const gzipStream = createGzip({ level: 9 });
|
|
379
|
-
const entryItemStream = Readable.from(entryItemIterator(), { signal });
|
|
380
|
-
entryItemStream.pipe(gzipStream);
|
|
381
|
-
return gzipStream;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
280
|
+
var createTarPacker = (entryItemGenerator, compressionType, signal) => {
|
|
281
|
+
const entryItemIterator = async function* () {
|
|
282
|
+
for await (const entryItem of entryItemGenerator) {
|
|
283
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
284
|
+
switch (entryItem.kind) {
|
|
285
|
+
case "file": {
|
|
286
|
+
const entryItemContent = entryItem.content;
|
|
287
|
+
if (typeof entryItemContent === "string" || Buffer.isBuffer(entryItemContent)) {
|
|
288
|
+
const contentBytes = getBuffer(entryItemContent);
|
|
289
|
+
yield createTarHeader("file", entryItem.path, contentBytes.length, entryItem.mode, entryItem.uname, entryItem.gname, entryItem.uid, entryItem.gid, entryItem.date);
|
|
290
|
+
yield getPaddedBytes(contentBytes);
|
|
291
|
+
} else {
|
|
292
|
+
const content = entryItemContent;
|
|
293
|
+
yield createTarHeader("file", entryItem.path, content.length, entryItem.mode, entryItem.uname, entryItem.gname, entryItem.uid, entryItem.gid, entryItem.date);
|
|
294
|
+
let position = 0;
|
|
295
|
+
switch (content.kind) {
|
|
296
|
+
case "generator":
|
|
297
|
+
for await (const contentBytes of content.generator) {
|
|
298
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
299
|
+
yield contentBytes;
|
|
300
|
+
position += contentBytes.length;
|
|
301
|
+
}
|
|
302
|
+
break;
|
|
303
|
+
case "readable":
|
|
304
|
+
for await (const chunk of content.readable) {
|
|
305
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
306
|
+
const contentBytes = getBuffer(chunk);
|
|
307
|
+
yield contentBytes;
|
|
308
|
+
position += contentBytes.length;
|
|
309
|
+
}
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
if (position % 512 !== 0) {
|
|
313
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
314
|
+
yield Buffer.alloc(512 - position % 512, 0);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
case "directory":
|
|
320
|
+
yield createTarHeader("directory", entryItem.path, 0, entryItem.mode, entryItem.uname, entryItem.gname, entryItem.uid, entryItem.gid, entryItem.date);
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
yield terminatorBytes;
|
|
325
|
+
};
|
|
326
|
+
switch (compressionType !== null && compressionType !== void 0 ? compressionType : "none") {
|
|
327
|
+
case "none": return Readable.from(entryItemIterator(), { signal });
|
|
328
|
+
case "gzip": {
|
|
329
|
+
const gzipStream = createGzip({ level: 9 });
|
|
330
|
+
Readable.from(entryItemIterator(), { signal }).pipe(gzipStream);
|
|
331
|
+
return gzipStream;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
384
334
|
};
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
335
|
+
var parseOctalBytes = (buffer, offset, length) => {
|
|
336
|
+
const str = buffer.subarray(offset, offset + length).toString("ascii").replace(/\0/g, "").trim();
|
|
337
|
+
return str ? parseInt(str, 8) : 0;
|
|
388
338
|
};
|
|
389
|
-
|
|
390
|
-
|
|
339
|
+
var parseString = (buffer, offset, length) => {
|
|
340
|
+
return buffer.subarray(offset, offset + length).toString("utf8").replace(/\0/g, "").trim();
|
|
391
341
|
};
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
totalRead = size;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
return Buffer.concat(chunks, size);
|
|
342
|
+
var readExactBytes = async (iterator, size, signal) => {
|
|
343
|
+
const chunks = [];
|
|
344
|
+
let totalRead = 0;
|
|
345
|
+
while (totalRead < size) {
|
|
346
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
347
|
+
const { value, done } = await iterator.next();
|
|
348
|
+
if (done) if (totalRead === 0) return;
|
|
349
|
+
else throw new Error(`Unexpected end of stream: expected ${size} bytes, got ${totalRead} bytes`);
|
|
350
|
+
const chunk = getBuffer(value);
|
|
351
|
+
const needed = size - totalRead;
|
|
352
|
+
if (chunk.length <= needed) {
|
|
353
|
+
chunks.push(chunk);
|
|
354
|
+
totalRead += chunk.length;
|
|
355
|
+
} else {
|
|
356
|
+
var _iterator$return;
|
|
357
|
+
chunks.push(chunk.subarray(0, needed));
|
|
358
|
+
await ((_iterator$return = iterator.return) === null || _iterator$return === void 0 ? void 0 : _iterator$return.call(iterator, chunk.subarray(needed)));
|
|
359
|
+
totalRead = size;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return Buffer.concat(chunks, size);
|
|
417
363
|
};
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
}
|
|
364
|
+
var skipExactBytes = async (iterator, size, signal) => {
|
|
365
|
+
let totalSkipped = 0;
|
|
366
|
+
while (totalSkipped < size) {
|
|
367
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
368
|
+
const { value, done } = await iterator.next();
|
|
369
|
+
if (done) throw new Error(`Unexpected end of stream: expected to skip ${size} bytes, skipped ${totalSkipped} bytes`);
|
|
370
|
+
const chunk = getBuffer(value);
|
|
371
|
+
const needed = size - totalSkipped;
|
|
372
|
+
if (chunk.length <= needed) totalSkipped += chunk.length;
|
|
373
|
+
else {
|
|
374
|
+
var _iterator$return2;
|
|
375
|
+
await ((_iterator$return2 = iterator.return) === null || _iterator$return2 === void 0 ? void 0 : _iterator$return2.call(iterator, chunk.subarray(needed)));
|
|
376
|
+
totalSkipped = size;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
435
379
|
};
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
await skipExactBytes(iterator, padding);
|
|
440
|
-
}
|
|
380
|
+
var skipPaddingBytesTo512Boundary = async (iterator, contentSize, signal) => {
|
|
381
|
+
const padding = (512 - contentSize % 512) % 512;
|
|
382
|
+
if (padding > 0) await skipExactBytes(iterator, padding, signal);
|
|
441
383
|
};
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
const kind = typeflag === "5" ? "directory" : "file";
|
|
477
|
-
return {
|
|
478
|
-
kind,
|
|
479
|
-
path,
|
|
480
|
-
size,
|
|
481
|
-
mode,
|
|
482
|
-
uid,
|
|
483
|
-
gid,
|
|
484
|
-
mtime,
|
|
485
|
-
uname: uname || uid.toString(),
|
|
486
|
-
gname: gname || gid.toString(),
|
|
487
|
-
checksum,
|
|
488
|
-
consumed: false
|
|
489
|
-
};
|
|
384
|
+
var parseTarHeader = (buffer) => {
|
|
385
|
+
if (buffer.every((b) => b === 0)) return;
|
|
386
|
+
const name = parseString(buffer, 0, 100);
|
|
387
|
+
const mode = parseOctalBytes(buffer, 100, 8);
|
|
388
|
+
const uid = parseOctalBytes(buffer, 108, 8);
|
|
389
|
+
const gid = parseOctalBytes(buffer, 116, 8);
|
|
390
|
+
const size = parseOctalBytes(buffer, 124, 12);
|
|
391
|
+
const mtime = /* @__PURE__ */ new Date(parseOctalBytes(buffer, 136, 12) * 1e3);
|
|
392
|
+
const checksum = parseOctalBytes(buffer, 148, 8);
|
|
393
|
+
const typeflag = parseString(buffer, 156, 1);
|
|
394
|
+
const magic = parseString(buffer, 257, 6);
|
|
395
|
+
const uname = parseString(buffer, 265, 32);
|
|
396
|
+
const gname = parseString(buffer, 297, 32);
|
|
397
|
+
const prefix = parseString(buffer, 345, 155);
|
|
398
|
+
if (magic !== "ustar") throw new Error(`Invalid tar format: magic="${magic}"`);
|
|
399
|
+
let calculatedSum = 0;
|
|
400
|
+
for (let i = 0; i < 512; i++) if (i >= 148 && i < 156) calculatedSum += 32;
|
|
401
|
+
else calculatedSum += buffer[i];
|
|
402
|
+
if (calculatedSum !== checksum) throw new Error(`Invalid checksum: expected ${checksum}, got ${calculatedSum}`);
|
|
403
|
+
let path = prefix ? `${prefix}/${name}` : name;
|
|
404
|
+
if (path.endsWith("/")) path = path.slice(0, -1);
|
|
405
|
+
return {
|
|
406
|
+
kind: typeflag === "5" ? "directory" : "file",
|
|
407
|
+
path,
|
|
408
|
+
size,
|
|
409
|
+
mode,
|
|
410
|
+
uid,
|
|
411
|
+
gid,
|
|
412
|
+
mtime,
|
|
413
|
+
uname: uname || uid.toString(),
|
|
414
|
+
gname: gname || gid.toString(),
|
|
415
|
+
checksum,
|
|
416
|
+
consumed: false
|
|
417
|
+
};
|
|
490
418
|
};
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
419
|
+
var createBufferedAsyncIterator = (iterable, signal) => {
|
|
420
|
+
const buffer = [];
|
|
421
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
422
|
+
return {
|
|
423
|
+
next: async () => {
|
|
424
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
425
|
+
if (buffer.length > 0) return {
|
|
426
|
+
value: buffer.shift(),
|
|
427
|
+
done: false
|
|
428
|
+
};
|
|
429
|
+
return iterator.next();
|
|
430
|
+
},
|
|
431
|
+
return: async (value) => {
|
|
432
|
+
if (value !== void 0) buffer.unshift(value);
|
|
433
|
+
return {
|
|
434
|
+
value: void 0,
|
|
435
|
+
done: false
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
};
|
|
508
439
|
};
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
return Readable.from(generator(), { signal });
|
|
440
|
+
var createReadableFromIterator = (iterator, size, signal, consumedRef) => {
|
|
441
|
+
const generator = async function* () {
|
|
442
|
+
let remainingBytes = size;
|
|
443
|
+
while (remainingBytes > 0) {
|
|
444
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
445
|
+
const { value, done } = await iterator.next();
|
|
446
|
+
if (done) throw new Error(`Unexpected end of stream: expected ${size} bytes, remaining ${remainingBytes} bytes`);
|
|
447
|
+
const chunk = getBuffer(value);
|
|
448
|
+
if (chunk.length <= remainingBytes) {
|
|
449
|
+
remainingBytes -= chunk.length;
|
|
450
|
+
yield chunk;
|
|
451
|
+
} else {
|
|
452
|
+
var _iterator$return3;
|
|
453
|
+
const needed = chunk.subarray(0, remainingBytes);
|
|
454
|
+
const excess = chunk.subarray(remainingBytes);
|
|
455
|
+
remainingBytes = 0;
|
|
456
|
+
await ((_iterator$return3 = iterator.return) === null || _iterator$return3 === void 0 ? void 0 : _iterator$return3.call(iterator, excess));
|
|
457
|
+
yield needed;
|
|
458
|
+
break;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
await skipPaddingBytesTo512Boundary(iterator, size, signal);
|
|
462
|
+
consumedRef.consumed = true;
|
|
463
|
+
};
|
|
464
|
+
return Readable.from(generator(), { signal });
|
|
535
465
|
};
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
const dataBuffer = await readExactBytes(iterator, currentHeader.size);
|
|
618
|
-
if (dataBuffer === void 0) {
|
|
619
|
-
throw new Error(`Unexpected end of stream while reading file data for ${currentHeader.path}`);
|
|
620
|
-
}
|
|
621
|
-
await skipPaddingBytesTo512Boundary(iterator, currentHeader.size);
|
|
622
|
-
currentHeader.consumed = true;
|
|
623
|
-
return dataBuffer;
|
|
624
|
-
}
|
|
625
|
-
// For Readble stream
|
|
626
|
-
case "readable": {
|
|
627
|
-
const readable2 = createReadableFromIterator(iterator, currentHeader.size, signal, currentHeader);
|
|
628
|
-
return readable2;
|
|
629
|
-
}
|
|
630
|
-
default:
|
|
631
|
-
throw new Error(`Unsupported content type: ${type}`);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
}
|
|
466
|
+
var createTarExtractor = async function* (readable, compressionType, signal) {
|
|
467
|
+
const ct = compressionType !== null && compressionType !== void 0 ? compressionType : "none";
|
|
468
|
+
let inputStream;
|
|
469
|
+
switch (ct) {
|
|
470
|
+
case "gzip":
|
|
471
|
+
const gunzip = createGunzip();
|
|
472
|
+
readable.pipe(gunzip);
|
|
473
|
+
inputStream = gunzip;
|
|
474
|
+
break;
|
|
475
|
+
default:
|
|
476
|
+
inputStream = readable;
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
const iterator = createBufferedAsyncIterator(inputStream, signal);
|
|
480
|
+
let header;
|
|
481
|
+
while (true) {
|
|
482
|
+
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
483
|
+
if ((header === null || header === void 0 ? void 0 : header.kind) === "file" && !header.consumed) {
|
|
484
|
+
await skipExactBytes(iterator, header.size, signal);
|
|
485
|
+
await skipPaddingBytesTo512Boundary(iterator, header.size, signal);
|
|
486
|
+
header.consumed = true;
|
|
487
|
+
}
|
|
488
|
+
let headerBuffer;
|
|
489
|
+
try {
|
|
490
|
+
headerBuffer = await readExactBytes(iterator, 512, signal);
|
|
491
|
+
} catch (error) {
|
|
492
|
+
if (error instanceof Error && error.message.includes("Unexpected end of stream")) throw new Error("Invalid tar format: incomplete header");
|
|
493
|
+
throw error;
|
|
494
|
+
}
|
|
495
|
+
if (headerBuffer === void 0) break;
|
|
496
|
+
header = parseTarHeader(headerBuffer);
|
|
497
|
+
if (!header) {
|
|
498
|
+
const secondBlock = await readExactBytes(iterator, 512, signal);
|
|
499
|
+
if (secondBlock === void 0 || secondBlock.every((b) => b === 0)) break;
|
|
500
|
+
throw new Error("Invalid tar format: expected terminator block");
|
|
501
|
+
}
|
|
502
|
+
if (header.kind === "directory") yield {
|
|
503
|
+
kind: "directory",
|
|
504
|
+
path: header.path,
|
|
505
|
+
mode: header.mode,
|
|
506
|
+
uid: header.uid,
|
|
507
|
+
gid: header.gid,
|
|
508
|
+
uname: header.uname,
|
|
509
|
+
gname: header.gname,
|
|
510
|
+
date: header.mtime
|
|
511
|
+
};
|
|
512
|
+
else {
|
|
513
|
+
const currentHeader = header;
|
|
514
|
+
yield {
|
|
515
|
+
kind: "file",
|
|
516
|
+
path: currentHeader.path,
|
|
517
|
+
mode: currentHeader.mode,
|
|
518
|
+
uid: currentHeader.uid,
|
|
519
|
+
gid: currentHeader.gid,
|
|
520
|
+
uname: currentHeader.uname,
|
|
521
|
+
gname: currentHeader.gname,
|
|
522
|
+
date: currentHeader.mtime,
|
|
523
|
+
getContent: async (type) => {
|
|
524
|
+
if (currentHeader.consumed) throw new Error("Content has already been consumed. Multiple calls to getContent are not supported.");
|
|
525
|
+
switch (type) {
|
|
526
|
+
case "string": {
|
|
527
|
+
const dataBuffer = await readExactBytes(iterator, currentHeader.size, signal);
|
|
528
|
+
if (dataBuffer === void 0) throw new Error(`Unexpected end of stream while reading file data for ${currentHeader.path}`);
|
|
529
|
+
await skipPaddingBytesTo512Boundary(iterator, currentHeader.size, signal);
|
|
530
|
+
currentHeader.consumed = true;
|
|
531
|
+
return dataBuffer.toString("utf8");
|
|
532
|
+
}
|
|
533
|
+
case "buffer": {
|
|
534
|
+
const dataBuffer = await readExactBytes(iterator, currentHeader.size, signal);
|
|
535
|
+
if (dataBuffer === void 0) throw new Error(`Unexpected end of stream while reading file data for ${currentHeader.path}`);
|
|
536
|
+
await skipPaddingBytesTo512Boundary(iterator, currentHeader.size, signal);
|
|
537
|
+
currentHeader.consumed = true;
|
|
538
|
+
return dataBuffer;
|
|
539
|
+
}
|
|
540
|
+
case "readable": return createReadableFromIterator(iterator, currentHeader.size, signal, currentHeader);
|
|
541
|
+
default: throw new Error(`Unsupported content type: ${type}`);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
}
|
|
637
547
|
};
|
|
638
|
-
|
|
548
|
+
var JSON5 = __resolveDefaultExport((/* @__PURE__ */ __toESM(require_dist(), 1)).default, false);
|
|
639
549
|
globalThis.__screwUpIsInCJS_8e26734beef0 = false;
|
|
640
550
|
function __resolveDefaultExport(module, isESM) {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
return hasDefault ? resolvedDefault != null ? resolvedDefault : module : module;
|
|
658
|
-
}
|
|
659
|
-
return hasDefault ? resolvedDefault != null ? resolvedDefault : module : module;
|
|
551
|
+
const __isInCJS = typeof globalThis !== "undefined" && globalThis.__screwUpIsInCJS_8e26734beef0 === true;
|
|
552
|
+
const maybe = module;
|
|
553
|
+
const hasDefault = !!(maybe && typeof maybe === "object" && "default" in maybe);
|
|
554
|
+
const unwrapNamespaceDefault = (value) => {
|
|
555
|
+
if (!value || typeof value !== "object") return value;
|
|
556
|
+
const inner = value;
|
|
557
|
+
if ((inner.__esModule === true || typeof Symbol !== "undefined" && inner[Symbol.toStringTag] === "Module") && "default" in inner) return inner.default;
|
|
558
|
+
return value;
|
|
559
|
+
};
|
|
560
|
+
const resolvedDefault = hasDefault ? unwrapNamespaceDefault(maybe.default) : void 0;
|
|
561
|
+
if (__isInCJS) return hasDefault ? resolvedDefault !== null && resolvedDefault !== void 0 ? resolvedDefault : module : module;
|
|
562
|
+
if (isESM) {
|
|
563
|
+
if (hasDefault) return resolvedDefault;
|
|
564
|
+
throw new Error("Default export not found.");
|
|
565
|
+
}
|
|
566
|
+
return hasDefault ? resolvedDefault !== null && resolvedDefault !== void 0 ? resolvedDefault : module : module;
|
|
660
567
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
568
|
+
var readPackageJsonFile = async (packageJsonPath) => {
|
|
569
|
+
const content = await readFile(packageJsonPath, "utf-8");
|
|
570
|
+
return JSON5.parse(content);
|
|
571
|
+
};
|
|
572
|
+
var dependencySectionKeys = new Set([
|
|
573
|
+
"dependencies",
|
|
574
|
+
"devDependencies",
|
|
575
|
+
"peerDependencies",
|
|
576
|
+
"optionalDependencies"
|
|
577
|
+
]);
|
|
578
|
+
var clonePackageJson = (packageJson) => JSON5.parse(JSON.stringify(packageJson));
|
|
579
|
+
var mergeResolvedPackageJson = (packedPackageJson, resolvedPackageJson) => {
|
|
580
|
+
const mergedPackageJson = clonePackageJson(packedPackageJson);
|
|
581
|
+
for (const [key, value] of Object.entries(resolvedPackageJson !== null && resolvedPackageJson !== void 0 ? resolvedPackageJson : {})) {
|
|
582
|
+
if (dependencySectionKeys.has(key)) continue;
|
|
583
|
+
mergedPackageJson[key] = value;
|
|
584
|
+
}
|
|
585
|
+
return mergedPackageJson;
|
|
586
|
+
};
|
|
587
|
+
var workspaceProtocolPrefix = "workspace:";
|
|
588
|
+
var inferVersionPrefix = (dependencySpec) => {
|
|
589
|
+
if (dependencySpec.startsWith("^")) return "^";
|
|
590
|
+
if (dependencySpec.startsWith("~")) return "~";
|
|
591
|
+
return "";
|
|
664
592
|
};
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
const entries = packageJson.files.filter(
|
|
670
|
-
(entry) => typeof entry === "string"
|
|
671
|
-
);
|
|
672
|
-
return entries.length > 0 ? entries : void 0;
|
|
593
|
+
var looksLikeWorkspaceProtocolAlias = (rawSpecifier) => {
|
|
594
|
+
if (!rawSpecifier) return false;
|
|
595
|
+
if (rawSpecifier === "*" || rawSpecifier === "^" || rawSpecifier === "~" || rawSpecifier.startsWith("^") || rawSpecifier.startsWith("~") || /^[0-9]/.test(rawSpecifier)) return false;
|
|
596
|
+
return true;
|
|
673
597
|
};
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
598
|
+
var parseWorkspaceProtocolDependencyReference = (dependencyName, workspaceProtocolSpecifier) => {
|
|
599
|
+
if (!workspaceProtocolSpecifier.startsWith(workspaceProtocolPrefix)) return;
|
|
600
|
+
const rawSpecifier = workspaceProtocolSpecifier.slice(10).trim();
|
|
601
|
+
if (!looksLikeWorkspaceProtocolAlias(rawSpecifier)) return {
|
|
602
|
+
targetPackageName: dependencyName,
|
|
603
|
+
alias: false
|
|
604
|
+
};
|
|
605
|
+
if (rawSpecifier.startsWith("@")) {
|
|
606
|
+
const secondAt = rawSpecifier.indexOf("@", 1);
|
|
607
|
+
const targetPackageName = secondAt >= 0 ? rawSpecifier.slice(0, secondAt) : rawSpecifier;
|
|
608
|
+
return {
|
|
609
|
+
targetPackageName,
|
|
610
|
+
alias: targetPackageName !== dependencyName
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
const atIndex = rawSpecifier.indexOf("@");
|
|
614
|
+
const targetPackageName = atIndex >= 0 ? rawSpecifier.slice(0, atIndex) : rawSpecifier;
|
|
615
|
+
return {
|
|
616
|
+
targetPackageName,
|
|
617
|
+
alias: targetPackageName !== dependencyName
|
|
618
|
+
};
|
|
694
619
|
};
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
const segments = value.split(/[\\/]+/);
|
|
700
|
-
if (segments.some((segment) => segment === "..")) {
|
|
701
|
-
return false;
|
|
702
|
-
}
|
|
703
|
-
return true;
|
|
620
|
+
var formatResolvedWorkspaceDependency = (packedDependencySpecifier, reference, sibling) => {
|
|
621
|
+
const aliasPrefix = `npm:${reference.targetPackageName}@`;
|
|
622
|
+
if (packedDependencySpecifier.startsWith(aliasPrefix)) return `${aliasPrefix}${inferVersionPrefix(packedDependencySpecifier.slice(aliasPrefix.length))}${sibling.version}`;
|
|
623
|
+
return `${inferVersionPrefix(packedDependencySpecifier)}${sibling.version}`;
|
|
704
624
|
};
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
for (const match of matches) {
|
|
723
|
-
if (isSafeRelativePath(match)) {
|
|
724
|
-
result.add(match);
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
for (const pattern of excludePatterns) {
|
|
729
|
-
const matches = await glob(pattern, { cwd, nodir: true });
|
|
730
|
-
for (const match of matches) {
|
|
731
|
-
result.delete(match);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
return result;
|
|
625
|
+
var replaceWorkspaceProtocolDependencies = (packageJson, resolvedPackageJson, siblings) => {
|
|
626
|
+
const modifiedPackageJson = clonePackageJson(packageJson);
|
|
627
|
+
for (const sectionKey of dependencySectionKeys) {
|
|
628
|
+
const modifiedSection = modifiedPackageJson[sectionKey];
|
|
629
|
+
const resolvedSection = resolvedPackageJson === null || resolvedPackageJson === void 0 ? void 0 : resolvedPackageJson[sectionKey];
|
|
630
|
+
if (!modifiedSection || typeof modifiedSection !== "object" || !resolvedSection || typeof resolvedSection !== "object") continue;
|
|
631
|
+
for (const [dependencyName, dependencySpecifier] of Object.entries(resolvedSection)) {
|
|
632
|
+
if (typeof dependencySpecifier !== "string") continue;
|
|
633
|
+
const reference = parseWorkspaceProtocolDependencyReference(dependencyName, dependencySpecifier);
|
|
634
|
+
if (!reference) continue;
|
|
635
|
+
const sibling = siblings.get(reference.targetPackageName);
|
|
636
|
+
const packedDependencySpecifier = modifiedSection[dependencyName];
|
|
637
|
+
if (!sibling || typeof packedDependencySpecifier !== "string") continue;
|
|
638
|
+
modifiedSection[dependencyName] = formatResolvedWorkspaceDependency(packedDependencySpecifier, reference, sibling);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return modifiedPackageJson;
|
|
735
642
|
};
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
}
|
|
741
|
-
if (childFiles == null ? void 0 : childFiles.length) {
|
|
742
|
-
merged.push(...childFiles);
|
|
743
|
-
}
|
|
744
|
-
return merged.length > 0 ? merged : void 0;
|
|
643
|
+
var getFilesArray = (packageJson) => {
|
|
644
|
+
if (!packageJson || !Array.isArray(packageJson.files)) return;
|
|
645
|
+
const entries = packageJson.files.filter((entry) => typeof entry === "string");
|
|
646
|
+
return entries.length > 0 ? entries : void 0;
|
|
745
647
|
};
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
const parentFiles = getFilesArray(rootPackageJson);
|
|
761
|
-
const childFiles = getFilesArray(childPackageJson);
|
|
762
|
-
const mergedFiles = mergeFilesPatterns(parentFiles, childFiles);
|
|
763
|
-
if (!parentFiles && !childFiles) {
|
|
764
|
-
return void 0;
|
|
765
|
-
}
|
|
766
|
-
return {
|
|
767
|
-
workspaceRoot,
|
|
768
|
-
parentFiles,
|
|
769
|
-
childFiles,
|
|
770
|
-
mergedFiles
|
|
771
|
-
};
|
|
648
|
+
var isGlobPattern = (pattern) => /[*?[\]{}()]/.test(pattern);
|
|
649
|
+
var normalizeFilesPattern = (pattern, cwd) => {
|
|
650
|
+
const trimmed = pattern.trim();
|
|
651
|
+
if (!trimmed) return;
|
|
652
|
+
const isNegated = trimmed.startsWith("!");
|
|
653
|
+
const raw = isNegated ? trimmed.slice(1) : trimmed;
|
|
654
|
+
if (!raw) return;
|
|
655
|
+
if (isGlobPattern(raw)) return trimmed;
|
|
656
|
+
const fullPath = join(cwd, raw);
|
|
657
|
+
if (existsSync(fullPath) && statSync(fullPath).isDirectory()) {
|
|
658
|
+
const dirPattern = `${raw.replace(/\/+$/, "")}/**`;
|
|
659
|
+
return isNegated ? `!${dirPattern}` : dirPattern;
|
|
660
|
+
}
|
|
661
|
+
return trimmed;
|
|
772
662
|
};
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
["pack", "--pack-destination", packDestDir],
|
|
778
|
-
{
|
|
779
|
-
cwd: targetDir,
|
|
780
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
781
|
-
}
|
|
782
|
-
);
|
|
783
|
-
let stdout = "";
|
|
784
|
-
let stderr = "";
|
|
785
|
-
npmProcess.stdout.on("data", (data) => {
|
|
786
|
-
stdout += data.toString();
|
|
787
|
-
});
|
|
788
|
-
npmProcess.stderr.on("data", (data) => {
|
|
789
|
-
stderr += data.toString();
|
|
790
|
-
});
|
|
791
|
-
npmProcess.on("close", (code) => {
|
|
792
|
-
if (code === 0) {
|
|
793
|
-
const lines = stdout.trim().split("\n");
|
|
794
|
-
const filename = lines.find((line) => line.trim().endsWith(".tgz")) || lines[lines.length - 1];
|
|
795
|
-
if (filename && filename.trim().endsWith(".tgz")) {
|
|
796
|
-
const fullPath = join(packDestDir, filename.trim());
|
|
797
|
-
res(fullPath);
|
|
798
|
-
} else {
|
|
799
|
-
rej(new Error("npm pack did not output a valid .tgz filename"));
|
|
800
|
-
}
|
|
801
|
-
} else {
|
|
802
|
-
const errorMessage = `npm pack failed with exit code ${code}`;
|
|
803
|
-
const fullError = stderr ? `${errorMessage}
|
|
804
|
-
stderr: ${stderr}` : errorMessage;
|
|
805
|
-
if (stdout) {
|
|
806
|
-
rej(new Error(`${fullError}
|
|
807
|
-
stdout: ${stdout}`));
|
|
808
|
-
} else {
|
|
809
|
-
rej(new Error(fullError));
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
});
|
|
813
|
-
npmProcess.on("error", (error) => {
|
|
814
|
-
rej(new Error(`Failed to spawn npm pack: ${error.message}`));
|
|
815
|
-
});
|
|
816
|
-
});
|
|
663
|
+
var isSafeRelativePath = (value) => {
|
|
664
|
+
if (isAbsolute(value)) return false;
|
|
665
|
+
if (value.split(/[\\/]+/).some((segment) => segment === "..")) return false;
|
|
666
|
+
return true;
|
|
817
667
|
};
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
return void 0;
|
|
844
|
-
}
|
|
845
|
-
const packageJsonReadme = resolvedPackageJson.readme;
|
|
846
|
-
if (packageJsonReadme) {
|
|
847
|
-
if (!readmeReplacementCandidatePath) {
|
|
848
|
-
const packageJsonReadmeDir = result.sourceMap.get("readme");
|
|
849
|
-
const packageJsonReadmePath = join(
|
|
850
|
-
packageJsonReadmeDir,
|
|
851
|
-
packageJsonReadme
|
|
852
|
-
);
|
|
853
|
-
if (!existsSync(packageJsonReadmePath)) {
|
|
854
|
-
throw new Error(
|
|
855
|
-
`README replacement file is not found: ${packageJsonReadmePath}`
|
|
856
|
-
);
|
|
857
|
-
}
|
|
858
|
-
readmeReplacementCandidatePath = packageJsonReadmePath;
|
|
859
|
-
}
|
|
860
|
-
delete resolvedPackageJson.readme;
|
|
861
|
-
}
|
|
862
|
-
if (replacePeerDepsWildcards) {
|
|
863
|
-
const workspaceRoot = await findWorkspaceRoot(targetDir, logger2);
|
|
864
|
-
if (workspaceRoot) {
|
|
865
|
-
const siblings = await collectWorkspaceSiblings(
|
|
866
|
-
workspaceRoot,
|
|
867
|
-
fetchGitMetadata,
|
|
868
|
-
alwaysOverrideVersionFromGit,
|
|
869
|
-
inheritableFields,
|
|
870
|
-
logger2
|
|
871
|
-
);
|
|
872
|
-
if (siblings.size > 0) {
|
|
873
|
-
resolvedPackageJson = replacePeerDependenciesWildcards(
|
|
874
|
-
resolvedPackageJson,
|
|
875
|
-
siblings,
|
|
876
|
-
peerDepsVersionPrefix
|
|
877
|
-
);
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
const filesMergeEnabled = mergeFiles && inheritableFields.has("files");
|
|
882
|
-
const workspaceFilesMerge = filesMergeEnabled ? await resolveWorkspaceFilesMerge(targetDir, logger2) : void 0;
|
|
883
|
-
if (filesMergeEnabled && (workspaceFilesMerge == null ? void 0 : workspaceFilesMerge.mergedFiles)) {
|
|
884
|
-
resolvedPackageJson.files = workspaceFilesMerge.mergedFiles;
|
|
885
|
-
}
|
|
886
|
-
const baseTempDir = await mkdtemp(join(tmpdir(), "screw-up-npm-pack-"));
|
|
887
|
-
await mkdir(baseTempDir, { recursive: true });
|
|
888
|
-
try {
|
|
889
|
-
const npmTarballPath = await runNpmPack(targetDir, baseTempDir);
|
|
890
|
-
const stagingDir = join(baseTempDir, "staging");
|
|
891
|
-
await mkdir(stagingDir, { recursive: true });
|
|
892
|
-
const stream = createReadStream(npmTarballPath);
|
|
893
|
-
await extractTo(createTarExtractor(stream, "gzip"), stagingDir);
|
|
894
|
-
const packageRoot = join(stagingDir, "package");
|
|
895
|
-
if (filesMergeEnabled && ((_a = workspaceFilesMerge == null ? void 0 : workspaceFilesMerge.parentFiles) == null ? void 0 : _a.length)) {
|
|
896
|
-
const parentFiles = await expandFilesPatterns(
|
|
897
|
-
workspaceFilesMerge.parentFiles,
|
|
898
|
-
workspaceFilesMerge.workspaceRoot
|
|
899
|
-
);
|
|
900
|
-
for (const parentFile of parentFiles) {
|
|
901
|
-
const destPath = join(packageRoot, parentFile);
|
|
902
|
-
if (existsSync(destPath)) {
|
|
903
|
-
continue;
|
|
904
|
-
}
|
|
905
|
-
await mkdir(dirname(destPath), { recursive: true });
|
|
906
|
-
await copyFile(
|
|
907
|
-
join(workspaceFilesMerge.workspaceRoot, parentFile),
|
|
908
|
-
destPath
|
|
909
|
-
);
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
const packageJsonPath = join(packageRoot, "package.json");
|
|
913
|
-
if (existsSync(packageJsonPath)) {
|
|
914
|
-
await writeFile(
|
|
915
|
-
packageJsonPath,
|
|
916
|
-
JSON.stringify(resolvedPackageJson, null, 2)
|
|
917
|
-
);
|
|
918
|
-
}
|
|
919
|
-
if (readmeReplacementCandidatePath) {
|
|
920
|
-
const readmeDestPath = join(packageRoot, "README.md");
|
|
921
|
-
await copyFile(readmeReplacementCandidatePath, readmeDestPath);
|
|
922
|
-
}
|
|
923
|
-
const outputFileName = `${(_c = (_b = resolvedPackageJson == null ? void 0 : resolvedPackageJson.name) == null ? void 0 : _b.replace("/", "-")) != null ? _c : "package"}-${(_d = resolvedPackageJson == null ? void 0 : resolvedPackageJson.version) != null ? _d : "0.0.0"}.tgz`;
|
|
924
|
-
await mkdir(outputDir, { recursive: true });
|
|
925
|
-
const outputFile = join(outputDir, outputFileName);
|
|
926
|
-
const itemGenerator = createEntryItemGenerator(stagingDir);
|
|
927
|
-
const packer = createTarPacker(itemGenerator, "gzip");
|
|
928
|
-
await storeReaderToFile(packer, outputFile);
|
|
929
|
-
return {
|
|
930
|
-
packageFileName: outputFileName,
|
|
931
|
-
metadata: resolvedPackageJson
|
|
932
|
-
};
|
|
933
|
-
} finally {
|
|
934
|
-
await rm(baseTempDir, { recursive: true, force: true });
|
|
935
|
-
}
|
|
668
|
+
var expandFilesPatterns = async (patterns, cwd) => {
|
|
669
|
+
const includePatterns = [];
|
|
670
|
+
const excludePatterns = [];
|
|
671
|
+
for (const pattern of patterns) {
|
|
672
|
+
const normalized = normalizeFilesPattern(pattern, cwd);
|
|
673
|
+
if (!normalized) continue;
|
|
674
|
+
if (normalized.startsWith("!")) excludePatterns.push(normalized.slice(1));
|
|
675
|
+
else includePatterns.push(normalized);
|
|
676
|
+
}
|
|
677
|
+
const result = /* @__PURE__ */ new Set();
|
|
678
|
+
for (const pattern of includePatterns) {
|
|
679
|
+
const matches = await glob(pattern, {
|
|
680
|
+
cwd,
|
|
681
|
+
nodir: true
|
|
682
|
+
});
|
|
683
|
+
for (const match of matches) if (isSafeRelativePath(match)) result.add(match);
|
|
684
|
+
}
|
|
685
|
+
for (const pattern of excludePatterns) {
|
|
686
|
+
const matches = await glob(pattern, {
|
|
687
|
+
cwd,
|
|
688
|
+
nodir: true
|
|
689
|
+
});
|
|
690
|
+
for (const match of matches) result.delete(match);
|
|
691
|
+
}
|
|
692
|
+
return result;
|
|
936
693
|
};
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
targetDir,
|
|
943
|
-
fetchGitMetadata,
|
|
944
|
-
alwaysOverrideVersionFromGit,
|
|
945
|
-
inheritableFields,
|
|
946
|
-
logger2,
|
|
947
|
-
ignoreNotExist
|
|
948
|
-
);
|
|
949
|
-
return result.metadata;
|
|
694
|
+
var mergeFilesPatterns = (parentFiles, childFiles) => {
|
|
695
|
+
const merged = [];
|
|
696
|
+
if (parentFiles === null || parentFiles === void 0 ? void 0 : parentFiles.length) merged.push(...parentFiles);
|
|
697
|
+
if (childFiles === null || childFiles === void 0 ? void 0 : childFiles.length) merged.push(...childFiles);
|
|
698
|
+
return merged.length > 0 ? merged : void 0;
|
|
950
699
|
};
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
} else {
|
|
969
|
-
result.options[optionName] = true;
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
} else if (arg.startsWith("-")) {
|
|
973
|
-
const optionName = arg.slice(1);
|
|
974
|
-
if (optionName.length == 1) {
|
|
975
|
-
const argOptions = result.command ? argOptionMap2.get(result.command) : void 0;
|
|
976
|
-
if (argOptions == null ? void 0 : argOptions.has(optionName)) {
|
|
977
|
-
i++;
|
|
978
|
-
result.options[optionName] = args[i];
|
|
979
|
-
} else {
|
|
980
|
-
result.options[optionName] = true;
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
} else if (!result.command) {
|
|
984
|
-
result.command = arg;
|
|
985
|
-
} else {
|
|
986
|
-
result.positional.push(arg);
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
return result;
|
|
700
|
+
var resolveWorkspaceFilesMerge = async (targetDir, logger) => {
|
|
701
|
+
const workspaceRoot = await findWorkspaceRoot(targetDir, logger);
|
|
702
|
+
if (!workspaceRoot) return;
|
|
703
|
+
const rootPackagePath = join(workspaceRoot, "package.json");
|
|
704
|
+
const targetPackagePath = join(targetDir, "package.json");
|
|
705
|
+
if (resolve(rootPackagePath) === resolve(targetPackagePath)) return;
|
|
706
|
+
const [rootPackageJson, childPackageJson] = await Promise.all([readPackageJsonFile(rootPackagePath), readPackageJsonFile(targetPackagePath)]);
|
|
707
|
+
const parentFiles = getFilesArray(rootPackageJson);
|
|
708
|
+
const childFiles = getFilesArray(childPackageJson);
|
|
709
|
+
const mergedFiles = mergeFilesPatterns(parentFiles, childFiles);
|
|
710
|
+
if (!parentFiles && !childFiles) return;
|
|
711
|
+
return {
|
|
712
|
+
workspaceRoot,
|
|
713
|
+
parentFiles,
|
|
714
|
+
childFiles,
|
|
715
|
+
mergedFiles
|
|
716
|
+
};
|
|
990
717
|
};
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
718
|
+
var readPackResultPath = (packageManager, packDestDir, stdout) => {
|
|
719
|
+
if (packageManager === "pnpm") {
|
|
720
|
+
const parsed = JSON5.parse(stdout);
|
|
721
|
+
const packResult = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
722
|
+
if (!(packResult === null || packResult === void 0 ? void 0 : packResult.filename) || typeof packResult.filename !== "string") throw new Error("pnpm pack did not output a valid filename");
|
|
723
|
+
return isAbsolute(packResult.filename) ? packResult.filename : join(packDestDir, packResult.filename);
|
|
724
|
+
}
|
|
725
|
+
const lines = stdout.trim().split("\n");
|
|
726
|
+
const filename = lines.find((line) => line.trim().endsWith(".tgz")) || lines[lines.length - 1];
|
|
727
|
+
if (!filename || !filename.trim().endsWith(".tgz")) throw new Error("npm pack did not output a valid .tgz filename");
|
|
728
|
+
return join(packDestDir, filename.trim());
|
|
729
|
+
};
|
|
730
|
+
/**
|
|
731
|
+
* Execute package manager pack and return the generated tarball path
|
|
732
|
+
* @param packageManager - Package manager to use
|
|
733
|
+
* @param targetDir - Target directory to pack
|
|
734
|
+
* @param packDestDir - Directory to store the generated tarball (must exist)
|
|
735
|
+
* @returns Path to generated tarball
|
|
736
|
+
*/
|
|
737
|
+
var runPack = async (packageManager, targetDir, packDestDir) => {
|
|
738
|
+
const packArgs = packageManager === "pnpm" ? [
|
|
739
|
+
"pack",
|
|
740
|
+
"--json",
|
|
741
|
+
"--pack-destination",
|
|
742
|
+
packDestDir
|
|
743
|
+
] : [
|
|
744
|
+
"pack",
|
|
745
|
+
"--pack-destination",
|
|
746
|
+
packDestDir
|
|
747
|
+
];
|
|
748
|
+
return new Promise((res, rej) => {
|
|
749
|
+
const packProcess = spawn(packageManager, packArgs, {
|
|
750
|
+
cwd: targetDir,
|
|
751
|
+
stdio: [
|
|
752
|
+
"ignore",
|
|
753
|
+
"pipe",
|
|
754
|
+
"pipe"
|
|
755
|
+
]
|
|
756
|
+
});
|
|
757
|
+
let stdout = "";
|
|
758
|
+
let stderr = "";
|
|
759
|
+
packProcess.stdout.on("data", (data) => {
|
|
760
|
+
stdout += data.toString();
|
|
761
|
+
});
|
|
762
|
+
packProcess.stderr.on("data", (data) => {
|
|
763
|
+
stderr += data.toString();
|
|
764
|
+
});
|
|
765
|
+
packProcess.on("close", (code) => {
|
|
766
|
+
if (code === 0) try {
|
|
767
|
+
res(readPackResultPath(packageManager, packDestDir, stdout.trim()));
|
|
768
|
+
} catch (error) {
|
|
769
|
+
rej(error);
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
const errorMessage = `${packageManager} pack failed with exit code ${code}`;
|
|
773
|
+
const fullError = stderr ? `${errorMessage}\nstderr: ${stderr}` : errorMessage;
|
|
774
|
+
if (stdout) rej(/* @__PURE__ */ new Error(`${fullError}\nstdout: ${stdout}`));
|
|
775
|
+
else rej(new Error(fullError));
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
packProcess.on("error", (error) => {
|
|
779
|
+
rej(/* @__PURE__ */ new Error(`Failed to spawn ${packageManager} pack: ${error.message}`));
|
|
780
|
+
});
|
|
781
|
+
});
|
|
782
|
+
};
|
|
783
|
+
/**
|
|
784
|
+
* Pack assets using npm pack delegation method
|
|
785
|
+
* @param targetDir - Target directory to pack
|
|
786
|
+
* @param outputDir - Output directory to write the tarball
|
|
787
|
+
* @param checkWorkingDirectoryStatus - Check working directory status
|
|
788
|
+
* @param inheritableFields - Package metadata fields that should be inherited from parent
|
|
789
|
+
* @param readmeReplacementPath - Optional path to replacement README file
|
|
790
|
+
* @param replacePeerDepsWildcards - Replace "*" in peerDependencies with actual versions
|
|
791
|
+
* @param peerDepsVersionPrefix - Version prefix for replaced peerDependencies
|
|
792
|
+
* @param alwaysOverrideVersionFromGit - Always override version from Git (default: true)
|
|
793
|
+
* @param packageManager - Package manager backend used for the initial pack
|
|
794
|
+
* @returns Package metadata (package.json) or undefined if failed
|
|
795
|
+
*/
|
|
796
|
+
var packAssets = async (targetDir, outputDir, checkWorkingDirectoryStatus, alwaysOverrideVersionFromGit, inheritableFields, readmeReplacementPath, replacePeerDepsWildcards, peerDepsVersionPrefix, logger, mergeFiles = true, packageManager = "npm") => {
|
|
797
|
+
if (!existsSync(targetDir)) throw new Error(`Target directory is not found: ${targetDir}`);
|
|
798
|
+
let readmeReplacementCandidatePath = readmeReplacementPath;
|
|
799
|
+
if (readmeReplacementCandidatePath && !existsSync(readmeReplacementCandidatePath)) throw new Error(`README replacement file is not found: ${readmeReplacementCandidatePath}`);
|
|
800
|
+
const fetchGitMetadata = getFetchGitMetadata(targetDir, checkWorkingDirectoryStatus, logger);
|
|
801
|
+
const result = await resolveRawPackageJsonObject(targetDir, fetchGitMetadata, alwaysOverrideVersionFromGit, inheritableFields, logger);
|
|
802
|
+
let resolvedPackageJson = result.metadata;
|
|
803
|
+
if (resolvedPackageJson === null || resolvedPackageJson === void 0 ? void 0 : resolvedPackageJson.private) return;
|
|
804
|
+
const packageJsonReadme = resolvedPackageJson.readme;
|
|
805
|
+
if (packageJsonReadme) {
|
|
806
|
+
if (!readmeReplacementCandidatePath) {
|
|
807
|
+
const packageJsonReadmeDir = result.sourceMap.get("readme");
|
|
808
|
+
if (!packageJsonReadmeDir) throw new Error(`README replacement source directory is unknown: ${packageJsonReadme}`);
|
|
809
|
+
const packageJsonReadmePath = join(packageJsonReadmeDir, packageJsonReadme);
|
|
810
|
+
if (!existsSync(packageJsonReadmePath)) throw new Error(`README replacement file is not found: ${packageJsonReadmePath}`);
|
|
811
|
+
readmeReplacementCandidatePath = packageJsonReadmePath;
|
|
812
|
+
}
|
|
813
|
+
delete resolvedPackageJson.readme;
|
|
814
|
+
}
|
|
815
|
+
const workspaceRoot = replacePeerDepsWildcards || packageManager === "pnpm" ? await findWorkspaceRoot(targetDir, logger) : void 0;
|
|
816
|
+
const workspaceSiblings = workspaceRoot ? await collectWorkspaceSiblings(workspaceRoot, fetchGitMetadata, alwaysOverrideVersionFromGit, inheritableFields, logger) : void 0;
|
|
817
|
+
const filesMergeEnabled = mergeFiles && inheritableFields.has("files");
|
|
818
|
+
const workspaceFilesMerge = filesMergeEnabled ? await resolveWorkspaceFilesMerge(targetDir, logger) : void 0;
|
|
819
|
+
if (filesMergeEnabled && (workspaceFilesMerge === null || workspaceFilesMerge === void 0 ? void 0 : workspaceFilesMerge.mergedFiles)) resolvedPackageJson.files = workspaceFilesMerge.mergedFiles;
|
|
820
|
+
const baseTempDir = await mkdtemp(join(tmpdir(), "screw-up-npm-pack-"));
|
|
821
|
+
await mkdir(baseTempDir, { recursive: true });
|
|
822
|
+
try {
|
|
823
|
+
var _workspaceFilesMerge$, _finalPackageJson$nam, _finalPackageJson$nam2, _finalPackageJson$ver;
|
|
824
|
+
const packedTarballPath = await runPack(packageManager, targetDir, baseTempDir);
|
|
825
|
+
const stagingDir = join(baseTempDir, "staging");
|
|
826
|
+
await mkdir(stagingDir, { recursive: true });
|
|
827
|
+
await extractTo(createTarExtractor(createReadStream(packedTarballPath), "gzip"), stagingDir);
|
|
828
|
+
const packageRoot = join(stagingDir, "package");
|
|
829
|
+
if (filesMergeEnabled && (workspaceFilesMerge === null || workspaceFilesMerge === void 0 || (_workspaceFilesMerge$ = workspaceFilesMerge.parentFiles) === null || _workspaceFilesMerge$ === void 0 ? void 0 : _workspaceFilesMerge$.length)) {
|
|
830
|
+
const parentFiles = await expandFilesPatterns(workspaceFilesMerge.parentFiles, workspaceFilesMerge.workspaceRoot);
|
|
831
|
+
for (const parentFile of parentFiles) {
|
|
832
|
+
const destPath = join(packageRoot, parentFile);
|
|
833
|
+
if (existsSync(destPath)) continue;
|
|
834
|
+
await mkdir(dirname(destPath), { recursive: true });
|
|
835
|
+
await copyFile(join(workspaceFilesMerge.workspaceRoot, parentFile), destPath);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
const packageJsonPath = join(packageRoot, "package.json");
|
|
839
|
+
let finalPackageJson = resolvedPackageJson;
|
|
840
|
+
if (existsSync(packageJsonPath)) {
|
|
841
|
+
finalPackageJson = mergeResolvedPackageJson(await readPackageJsonFile(packageJsonPath), resolvedPackageJson);
|
|
842
|
+
if (packageManager === "pnpm" && (workspaceSiblings === null || workspaceSiblings === void 0 ? void 0 : workspaceSiblings.size)) finalPackageJson = replaceWorkspaceProtocolDependencies(finalPackageJson, resolvedPackageJson, workspaceSiblings);
|
|
843
|
+
if (workspaceSiblings && workspaceSiblings.size > 0) finalPackageJson = replacePeerDependenciesWildcards(finalPackageJson, workspaceSiblings, peerDepsVersionPrefix);
|
|
844
|
+
if (packageJsonReadme) delete finalPackageJson.readme;
|
|
845
|
+
await writeFile(packageJsonPath, JSON.stringify(finalPackageJson, null, 2));
|
|
846
|
+
}
|
|
847
|
+
if (readmeReplacementCandidatePath) {
|
|
848
|
+
const readmeDestPath = join(packageRoot, "README.md");
|
|
849
|
+
await copyFile(readmeReplacementCandidatePath, readmeDestPath);
|
|
850
|
+
}
|
|
851
|
+
const outputFileName = `${(_finalPackageJson$nam = finalPackageJson === null || finalPackageJson === void 0 || (_finalPackageJson$nam2 = finalPackageJson.name) === null || _finalPackageJson$nam2 === void 0 ? void 0 : _finalPackageJson$nam2.replace("/", "-")) !== null && _finalPackageJson$nam !== void 0 ? _finalPackageJson$nam : "package"}-${(_finalPackageJson$ver = finalPackageJson === null || finalPackageJson === void 0 ? void 0 : finalPackageJson.version) !== null && _finalPackageJson$ver !== void 0 ? _finalPackageJson$ver : "0.0.0"}.tgz`;
|
|
852
|
+
await mkdir(outputDir, { recursive: true });
|
|
853
|
+
const outputFile = join(outputDir, outputFileName);
|
|
854
|
+
await storeReaderToFile(createTarPacker(createEntryItemGenerator(stagingDir), "gzip"), outputFile);
|
|
855
|
+
return {
|
|
856
|
+
packageFileName: outputFileName,
|
|
857
|
+
metadata: finalPackageJson
|
|
858
|
+
};
|
|
859
|
+
} finally {
|
|
860
|
+
await rm(baseTempDir, {
|
|
861
|
+
recursive: true,
|
|
862
|
+
force: true
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
/**
|
|
867
|
+
* Get computed package.json object
|
|
868
|
+
* @param targetDir - Target directory to resolve package metadata
|
|
869
|
+
* @param fetchGitMetadata - Git metadata fetcher
|
|
870
|
+
* @param inheritableFields - Package metadata fields that should be inherited from parent
|
|
871
|
+
* @returns Computed package.json object or undefined if failed
|
|
872
|
+
*/
|
|
873
|
+
var getComputedPackageJsonObject = async (targetDir, fetchGitMetadata, alwaysOverrideVersionFromGit, inheritableFields, logger, ignoreNotExist = false) => {
|
|
874
|
+
if (!existsSync(targetDir)) return;
|
|
875
|
+
return (await resolveRawPackageJsonObject(targetDir, fetchGitMetadata, alwaysOverrideVersionFromGit, inheritableFields, logger, ignoreNotExist)).metadata;
|
|
876
|
+
};
|
|
877
|
+
/**
|
|
878
|
+
* Parse command line arguments
|
|
879
|
+
* @param args - Command line arguments
|
|
880
|
+
* @param argOptionMap - Map of command options to their argument options
|
|
881
|
+
* @returns Parsed arguments
|
|
882
|
+
*/
|
|
883
|
+
var parseArgs = (args, argOptionMap) => {
|
|
884
|
+
const result = {
|
|
885
|
+
argv: args,
|
|
886
|
+
positional: [],
|
|
887
|
+
options: {}
|
|
888
|
+
};
|
|
889
|
+
for (let i = 0; i < args.length; i++) {
|
|
890
|
+
const arg = args[i];
|
|
891
|
+
if (arg.startsWith("--")) {
|
|
892
|
+
const optionName = arg.slice(2);
|
|
893
|
+
if (!result.command) result.options[optionName] = true;
|
|
894
|
+
else {
|
|
895
|
+
const argOptions = argOptionMap.get(result.command);
|
|
896
|
+
if (argOptions === null || argOptions === void 0 ? void 0 : argOptions.has(optionName)) {
|
|
897
|
+
i++;
|
|
898
|
+
result.options[optionName] = args[i];
|
|
899
|
+
} else result.options[optionName] = true;
|
|
900
|
+
}
|
|
901
|
+
} else if (arg.startsWith("-")) {
|
|
902
|
+
const optionName = arg.slice(1);
|
|
903
|
+
if (optionName.length == 1) {
|
|
904
|
+
const argOptions = result.command ? argOptionMap.get(result.command) : void 0;
|
|
905
|
+
if (argOptions === null || argOptions === void 0 ? void 0 : argOptions.has(optionName)) {
|
|
906
|
+
i++;
|
|
907
|
+
result.options[optionName] = args[i];
|
|
908
|
+
} else result.options[optionName] = true;
|
|
909
|
+
}
|
|
910
|
+
} else if (!result.command) result.command = arg;
|
|
911
|
+
else result.positional.push(arg);
|
|
912
|
+
}
|
|
913
|
+
return result;
|
|
914
|
+
};
|
|
915
|
+
//#endregion
|
|
916
|
+
//#region src/cli.ts
|
|
917
|
+
var defaultInheritableFields = new Set([
|
|
918
|
+
"version",
|
|
919
|
+
"description",
|
|
920
|
+
"author",
|
|
921
|
+
"license",
|
|
922
|
+
"repository",
|
|
923
|
+
"keywords",
|
|
924
|
+
"homepage",
|
|
925
|
+
"bugs",
|
|
926
|
+
"readme",
|
|
927
|
+
"files"
|
|
1002
928
|
]);
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
929
|
+
var defaultOutputMetadataKeys = [
|
|
930
|
+
"name",
|
|
931
|
+
"version",
|
|
932
|
+
"description",
|
|
933
|
+
"author",
|
|
934
|
+
"license",
|
|
935
|
+
"repository.url",
|
|
936
|
+
"git.commit.hash"
|
|
1011
937
|
];
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
if (!inheritableFieldsOption.trim()) {
|
|
1017
|
-
return /* @__PURE__ */ new Set();
|
|
1018
|
-
}
|
|
1019
|
-
return new Set(
|
|
1020
|
-
inheritableFieldsOption.split(",").map((field) => field.trim()).filter((field) => field.length > 0)
|
|
1021
|
-
);
|
|
938
|
+
var parseInheritableFields = (inheritableFieldsOption) => {
|
|
939
|
+
if (typeof inheritableFieldsOption !== "string") return defaultInheritableFields;
|
|
940
|
+
if (!inheritableFieldsOption.trim()) return /* @__PURE__ */ new Set();
|
|
941
|
+
return new Set(inheritableFieldsOption.split(",").map((field) => field.trim()).filter((field) => field.length > 0));
|
|
1022
942
|
};
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
if (!outputMetadataKeysOption.trim()) {
|
|
1028
|
-
return [];
|
|
1029
|
-
}
|
|
1030
|
-
return outputMetadataKeysOption.split(",").map((key) => key.trim()).filter((key) => key.length > 0);
|
|
943
|
+
var parseOutputMetadataKeys = (outputMetadataKeysOption) => {
|
|
944
|
+
if (typeof outputMetadataKeysOption !== "string") return defaultOutputMetadataKeys;
|
|
945
|
+
if (!outputMetadataKeysOption.trim()) return [];
|
|
946
|
+
return outputMetadataKeysOption.split(",").map((key) => key.trim()).filter((key) => key.length > 0);
|
|
1031
947
|
};
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
process.stdin.on("end", () => resolvePromise(data));
|
|
1044
|
-
process.stdin.on("error", (err) => rejectPromise(err));
|
|
1045
|
-
});
|
|
948
|
+
var readInputText = async (inputPath) => {
|
|
949
|
+
if (inputPath) return await readFile(resolve(inputPath), "utf-8");
|
|
950
|
+
return await new Promise((resolvePromise, rejectPromise) => {
|
|
951
|
+
let data = "";
|
|
952
|
+
process.stdin.setEncoding("utf-8");
|
|
953
|
+
process.stdin.on("data", (chunk) => {
|
|
954
|
+
data += chunk;
|
|
955
|
+
});
|
|
956
|
+
process.stdin.on("end", () => resolvePromise(data));
|
|
957
|
+
process.stdin.on("error", (err) => rejectPromise(err));
|
|
958
|
+
});
|
|
1046
959
|
};
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
return void 0;
|
|
1055
|
-
}
|
|
1056
|
-
return current[key];
|
|
1057
|
-
}, source);
|
|
960
|
+
var escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
961
|
+
var getValueByPath = (source, path) => {
|
|
962
|
+
return path.split(".").reduce((current, key) => {
|
|
963
|
+
if (current === void 0 || current === null) return;
|
|
964
|
+
if (typeof current !== "object" && !Array.isArray(current)) return;
|
|
965
|
+
return current[key];
|
|
966
|
+
}, source);
|
|
1058
967
|
};
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
return JSON.stringify(value);
|
|
1069
|
-
} catch (e) {
|
|
1070
|
-
return String(value);
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
return String(value);
|
|
968
|
+
var stringifyValue = (value) => {
|
|
969
|
+
if (value === void 0) return;
|
|
970
|
+
if (value === null) return "null";
|
|
971
|
+
if (typeof value === "object") try {
|
|
972
|
+
return JSON.stringify(value);
|
|
973
|
+
} catch (_unused) {
|
|
974
|
+
return String(value);
|
|
975
|
+
}
|
|
976
|
+
return String(value);
|
|
1074
977
|
};
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
const trimmedKey = String(key).trim();
|
|
1082
|
-
const resolvedValue = stringifyValue(getValueByPath(values, trimmedKey));
|
|
1083
|
-
return resolvedValue !== void 0 ? resolvedValue : match;
|
|
1084
|
-
});
|
|
978
|
+
var replacePlaceholders = (text, values, openBracket, closeBracket) => {
|
|
979
|
+
const pattern = new RegExp(`${escapeRegExp(openBracket)}(.*?)${escapeRegExp(closeBracket)}`, "g");
|
|
980
|
+
return text.replace(pattern, (match, key) => {
|
|
981
|
+
const resolvedValue = stringifyValue(getValueByPath(values, String(key).trim()));
|
|
982
|
+
return resolvedValue !== void 0 ? resolvedValue : match;
|
|
983
|
+
});
|
|
1085
984
|
};
|
|
1086
|
-
|
|
1087
|
-
|
|
985
|
+
var showFormatHelp = () => {
|
|
986
|
+
console.info(`Usage: screw-up format [options] [output]
|
|
1088
987
|
|
|
1089
988
|
Format input text by replacing placeholders with package metadata
|
|
1090
989
|
|
|
@@ -1101,95 +1000,65 @@ Options:
|
|
|
1101
1000
|
-h, --help Show help for format command
|
|
1102
1001
|
`);
|
|
1103
1002
|
};
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1003
|
+
var parseBracketOption = (bracketOption) => {
|
|
1004
|
+
if (!bracketOption) return {
|
|
1005
|
+
openBracket: "{",
|
|
1006
|
+
closeBracket: "}"
|
|
1007
|
+
};
|
|
1008
|
+
const delimiterIndex = bracketOption.indexOf(",");
|
|
1009
|
+
if (delimiterIndex === -1) return;
|
|
1010
|
+
const openBracket = bracketOption.slice(0, delimiterIndex);
|
|
1011
|
+
const closeBracket = bracketOption.slice(delimiterIndex + 1);
|
|
1012
|
+
if (!openBracket || !closeBracket) return;
|
|
1013
|
+
return {
|
|
1014
|
+
openBracket,
|
|
1015
|
+
closeBracket
|
|
1016
|
+
};
|
|
1118
1017
|
};
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
targetDir,
|
|
1161
|
-
fetchGitMetadata,
|
|
1162
|
-
alwaysOverrideVersionFromGit,
|
|
1163
|
-
inheritableFields,
|
|
1164
|
-
_logger,
|
|
1165
|
-
ignorePackageJsonNotExist
|
|
1166
|
-
);
|
|
1167
|
-
if (!computedPackageJson) {
|
|
1168
|
-
_logger.error(`format: Unable to read package.json from: ${targetDir}`);
|
|
1169
|
-
return 1;
|
|
1170
|
-
}
|
|
1171
|
-
const inputText = await readInputText(
|
|
1172
|
-
typeof inputPathOption === "string" ? inputPathOption : void 0
|
|
1173
|
-
);
|
|
1174
|
-
const formattedText = replacePlaceholders(
|
|
1175
|
-
inputText,
|
|
1176
|
-
computedPackageJson,
|
|
1177
|
-
openBracket,
|
|
1178
|
-
closeBracket
|
|
1179
|
-
);
|
|
1180
|
-
if (outputPath) {
|
|
1181
|
-
const resolvedOutputPath = resolve(outputPath);
|
|
1182
|
-
await writeFile(resolvedOutputPath, formattedText);
|
|
1183
|
-
}
|
|
1184
|
-
process.stdout.write(formattedText);
|
|
1185
|
-
} catch (error) {
|
|
1186
|
-
_logger.error(`format: Failed to format text: ${error}`);
|
|
1187
|
-
return 1;
|
|
1188
|
-
}
|
|
1189
|
-
return 0;
|
|
1018
|
+
var formatCommand = async (args, logger) => {
|
|
1019
|
+
var _args$options$input, _args$options$bracket;
|
|
1020
|
+
if (args.options.help || args.options.h) {
|
|
1021
|
+
showFormatHelp();
|
|
1022
|
+
return 1;
|
|
1023
|
+
}
|
|
1024
|
+
const outputPath = args.positional[0];
|
|
1025
|
+
const inputPathOption = (_args$options$input = args.options["input"]) !== null && _args$options$input !== void 0 ? _args$options$input : args.options["i"];
|
|
1026
|
+
const bracketOption = (_args$options$bracket = args.options["bracket"]) !== null && _args$options$bracket !== void 0 ? _args$options$bracket : args.options["b"];
|
|
1027
|
+
const inheritableFieldsOption = args.options["inheritable-fields"];
|
|
1028
|
+
const alwaysOverrideVersionFromGit = !args.options["no-git-version-override"];
|
|
1029
|
+
const checkWorkingDirectoryStatus = args.options["no-wds"] ? false : true;
|
|
1030
|
+
const ignorePackageJsonNotExist = args.options["force"] || args.options["f"] ? true : false;
|
|
1031
|
+
const bracket = parseBracketOption(typeof bracketOption === "string" ? bracketOption : void 0);
|
|
1032
|
+
if (!bracket) {
|
|
1033
|
+
logger.error("format: Invalid bracket option, expected \"open,close\" pattern.");
|
|
1034
|
+
return 1;
|
|
1035
|
+
}
|
|
1036
|
+
const { openBracket, closeBracket } = bracket;
|
|
1037
|
+
const targetDir = resolve(process.cwd());
|
|
1038
|
+
const inheritableFields = parseInheritableFields(inheritableFieldsOption);
|
|
1039
|
+
const _logger = {
|
|
1040
|
+
debug: (msg) => {},
|
|
1041
|
+
info: (msg) => {},
|
|
1042
|
+
warn: (msg) => {},
|
|
1043
|
+
error: logger.error
|
|
1044
|
+
};
|
|
1045
|
+
try {
|
|
1046
|
+
const computedPackageJson = await getComputedPackageJsonObject(targetDir, getFetchGitMetadata(targetDir, checkWorkingDirectoryStatus, _logger), alwaysOverrideVersionFromGit, inheritableFields, _logger, ignorePackageJsonNotExist);
|
|
1047
|
+
if (!computedPackageJson) {
|
|
1048
|
+
_logger.error(`format: Unable to read package.json from: ${targetDir}`);
|
|
1049
|
+
return 1;
|
|
1050
|
+
}
|
|
1051
|
+
const formattedText = replacePlaceholders(await readInputText(typeof inputPathOption === "string" ? inputPathOption : void 0), computedPackageJson, openBracket, closeBracket);
|
|
1052
|
+
if (outputPath) await writeFile(resolve(outputPath), formattedText);
|
|
1053
|
+
process.stdout.write(formattedText);
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
_logger.error(`format: Failed to format text: ${error}`);
|
|
1056
|
+
return 1;
|
|
1057
|
+
}
|
|
1058
|
+
return 0;
|
|
1190
1059
|
};
|
|
1191
|
-
|
|
1192
|
-
|
|
1060
|
+
var showDumpHelp = () => {
|
|
1061
|
+
console.info(`Usage: screw-up dump [options] [directory]
|
|
1193
1062
|
|
|
1194
1063
|
Dump computed package.json as JSON
|
|
1195
1064
|
|
|
@@ -1205,65 +1074,45 @@ Options:
|
|
|
1205
1074
|
-h, --help Show help for dump command
|
|
1206
1075
|
`);
|
|
1207
1076
|
};
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
if (computedPackageJson) {
|
|
1245
|
-
if (mergeFiles && inheritableFields.has("files") && existsSync(join(targetDir, "package.json"))) {
|
|
1246
|
-
const workspaceFilesMerge = await resolveWorkspaceFilesMerge(
|
|
1247
|
-
targetDir,
|
|
1248
|
-
_logger
|
|
1249
|
-
);
|
|
1250
|
-
if (workspaceFilesMerge == null ? void 0 : workspaceFilesMerge.mergedFiles) {
|
|
1251
|
-
computedPackageJson.files = workspaceFilesMerge.mergedFiles;
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
console.info(JSON.stringify(computedPackageJson, null, 2));
|
|
1255
|
-
} else {
|
|
1256
|
-
_logger.error(`dump: Unable to read package.json from: ${targetDir}`);
|
|
1257
|
-
return 1;
|
|
1258
|
-
}
|
|
1259
|
-
} catch (error) {
|
|
1260
|
-
_logger.error(`dump: Failed to dump package.json: ${error}`);
|
|
1261
|
-
return 1;
|
|
1262
|
-
}
|
|
1263
|
-
return 0;
|
|
1077
|
+
var dumpCommand = async (args, logger) => {
|
|
1078
|
+
if (args.options.help || args.options.h) {
|
|
1079
|
+
showDumpHelp();
|
|
1080
|
+
return 1;
|
|
1081
|
+
}
|
|
1082
|
+
const directory = args.positional[0];
|
|
1083
|
+
const inheritableFieldsOption = args.options["inheritable-fields"];
|
|
1084
|
+
const alwaysOverrideVersionFromGit = !args.options["no-git-version-override"];
|
|
1085
|
+
const checkWorkingDirectoryStatus = args.options["no-wds"] ? false : true;
|
|
1086
|
+
const mergeFiles = !args.options["no-merge-files"];
|
|
1087
|
+
const ignorePackageJsonNotExist = args.options["force"] || args.options["f"] ? true : false;
|
|
1088
|
+
const inheritableFields = parseInheritableFields(inheritableFieldsOption);
|
|
1089
|
+
const targetDir = resolve(directory !== null && directory !== void 0 ? directory : process.cwd());
|
|
1090
|
+
const _logger = {
|
|
1091
|
+
debug: (msg) => {},
|
|
1092
|
+
info: (msg) => {},
|
|
1093
|
+
warn: (msg) => {},
|
|
1094
|
+
error: logger.error
|
|
1095
|
+
};
|
|
1096
|
+
try {
|
|
1097
|
+
const computedPackageJson = await getComputedPackageJsonObject(targetDir, getFetchGitMetadata(targetDir, checkWorkingDirectoryStatus, _logger), alwaysOverrideVersionFromGit, inheritableFields, _logger, ignorePackageJsonNotExist);
|
|
1098
|
+
if (computedPackageJson) {
|
|
1099
|
+
if (mergeFiles && inheritableFields.has("files") && existsSync(join(targetDir, "package.json"))) {
|
|
1100
|
+
const workspaceFilesMerge = await resolveWorkspaceFilesMerge(targetDir, _logger);
|
|
1101
|
+
if (workspaceFilesMerge === null || workspaceFilesMerge === void 0 ? void 0 : workspaceFilesMerge.mergedFiles) computedPackageJson.files = workspaceFilesMerge.mergedFiles;
|
|
1102
|
+
}
|
|
1103
|
+
console.info(JSON.stringify(computedPackageJson, null, 2));
|
|
1104
|
+
} else {
|
|
1105
|
+
_logger.error(`dump: Unable to read package.json from: ${targetDir}`);
|
|
1106
|
+
return 1;
|
|
1107
|
+
}
|
|
1108
|
+
} catch (error) {
|
|
1109
|
+
_logger.error(`dump: Failed to dump package.json: ${error}`);
|
|
1110
|
+
return 1;
|
|
1111
|
+
}
|
|
1112
|
+
return 0;
|
|
1264
1113
|
};
|
|
1265
|
-
|
|
1266
|
-
|
|
1114
|
+
var showMetadataHelp = () => {
|
|
1115
|
+
console.info(`Usage: screw-up metadata [options] [directory]
|
|
1267
1116
|
|
|
1268
1117
|
Generate TypeScript metadata file from package metadata
|
|
1269
1118
|
|
|
@@ -1278,78 +1127,40 @@ Options:
|
|
|
1278
1127
|
-h, --help Show help for metadata command
|
|
1279
1128
|
`);
|
|
1280
1129
|
};
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
metadataSourcePath,
|
|
1313
|
-
metadataSourceContent,
|
|
1314
|
-
"metadata source file",
|
|
1315
|
-
logger2
|
|
1316
|
-
);
|
|
1317
|
-
if (existsSync(metadataSourcePath)) {
|
|
1318
|
-
const gitignoreWritten = await ensureMetadataGitignore(
|
|
1319
|
-
metadataSourcePath,
|
|
1320
|
-
logger2
|
|
1321
|
-
);
|
|
1322
|
-
if (gitignoreWritten) {
|
|
1323
|
-
logger2.info(
|
|
1324
|
-
`metadata: .gitignore is generated: ${join(
|
|
1325
|
-
dirname(outputMetadataFilePath),
|
|
1326
|
-
".gitignore"
|
|
1327
|
-
)}`
|
|
1328
|
-
);
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
if (metadataWritten) {
|
|
1332
|
-
logger2.info(
|
|
1333
|
-
`metadata: Metadata source file is generated: ${outputMetadataFilePath}`
|
|
1334
|
-
);
|
|
1335
|
-
} else if (existsSync(metadataSourcePath)) {
|
|
1336
|
-
logger2.info(
|
|
1337
|
-
`metadata: Metadata source file is unchanged: ${outputMetadataFilePath}`
|
|
1338
|
-
);
|
|
1339
|
-
} else {
|
|
1340
|
-
logger2.error(
|
|
1341
|
-
`metadata: Failed to write metadata file: ${outputMetadataFilePath}`
|
|
1342
|
-
);
|
|
1343
|
-
return 1;
|
|
1344
|
-
}
|
|
1345
|
-
} catch (error) {
|
|
1346
|
-
logger2.error(`metadata: Failed to generate metadata file: ${error}`);
|
|
1347
|
-
return 1;
|
|
1348
|
-
}
|
|
1349
|
-
return 0;
|
|
1130
|
+
var metadataCommand = async (args, logger) => {
|
|
1131
|
+
if (args.options.help || args.options.h) {
|
|
1132
|
+
showMetadataHelp();
|
|
1133
|
+
return 1;
|
|
1134
|
+
}
|
|
1135
|
+
const directory = args.positional[0];
|
|
1136
|
+
const outputMetadataFilePathOption = args.options["output-metadata-file-path"];
|
|
1137
|
+
const outputMetadataKeysOption = args.options["output-metadata-keys"];
|
|
1138
|
+
const alwaysOverrideVersionFromGit = !args.options["no-git-version-override"];
|
|
1139
|
+
const checkWorkingDirectoryStatus = args.options["no-wds"] ? false : true;
|
|
1140
|
+
const outputMetadataFilePath = typeof outputMetadataFilePathOption === "string" && outputMetadataFilePathOption.trim() ? outputMetadataFilePathOption : "src/generated/packageMetadata.ts";
|
|
1141
|
+
const outputMetadataKeys = parseOutputMetadataKeys(outputMetadataKeysOption);
|
|
1142
|
+
const targetDir = resolve(directory !== null && directory !== void 0 ? directory : process.cwd());
|
|
1143
|
+
try {
|
|
1144
|
+
const metadataSourceContent = generateMetadataFileContent((await resolvePackageMetadata(targetDir, getFetchGitMetadata(targetDir, checkWorkingDirectoryStatus, logger), alwaysOverrideVersionFromGit, logger)).metadata, outputMetadataKeys);
|
|
1145
|
+
const metadataSourcePath = join(targetDir, outputMetadataFilePath);
|
|
1146
|
+
const metadataWritten = await writeFileIfChanged(metadataSourcePath, metadataSourceContent, "metadata source file", logger);
|
|
1147
|
+
if (existsSync(metadataSourcePath)) {
|
|
1148
|
+
if (await ensureMetadataGitignore(metadataSourcePath, logger)) logger.info(`metadata: .gitignore is generated: ${join(dirname(outputMetadataFilePath), ".gitignore")}`);
|
|
1149
|
+
}
|
|
1150
|
+
if (metadataWritten) logger.info(`metadata: Metadata source file is generated: ${outputMetadataFilePath}`);
|
|
1151
|
+
else if (existsSync(metadataSourcePath)) logger.info(`metadata: Metadata source file is unchanged: ${outputMetadataFilePath}`);
|
|
1152
|
+
else {
|
|
1153
|
+
logger.error(`metadata: Failed to write metadata file: ${outputMetadataFilePath}`);
|
|
1154
|
+
return 1;
|
|
1155
|
+
}
|
|
1156
|
+
} catch (error) {
|
|
1157
|
+
logger.error(`metadata: Failed to generate metadata file: ${error}`);
|
|
1158
|
+
return 1;
|
|
1159
|
+
}
|
|
1160
|
+
return 0;
|
|
1350
1161
|
};
|
|
1351
|
-
|
|
1352
|
-
|
|
1162
|
+
var showPackHelp = () => {
|
|
1163
|
+
console.info(`Usage: screw-up pack [options] [directory]
|
|
1353
1164
|
|
|
1354
1165
|
Pack the project into a tar archive
|
|
1355
1166
|
|
|
@@ -1359,6 +1170,7 @@ Arguments:
|
|
|
1359
1170
|
Options:
|
|
1360
1171
|
--pack-destination <path> Directory to write the tarball
|
|
1361
1172
|
--readme <path> Replace README.md with specified file
|
|
1173
|
+
--use-pnpm Use pnpm pack and preserve workspace protocol resolution
|
|
1362
1174
|
--inheritable-fields <list> Comma-separated list of fields to inherit from parent
|
|
1363
1175
|
--no-wds Do not check working directory status to increase version
|
|
1364
1176
|
--no-git-version-override Do not override version from Git (use package.json version)
|
|
@@ -1369,62 +1181,44 @@ Options:
|
|
|
1369
1181
|
-h, --help Show help for pack command
|
|
1370
1182
|
`);
|
|
1371
1183
|
};
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
);
|
|
1408
|
-
if (result) {
|
|
1409
|
-
if (verbose) {
|
|
1410
|
-
logger2.info(
|
|
1411
|
-
`pack: Archive created successfully: ${result.packageFileName}`
|
|
1412
|
-
);
|
|
1413
|
-
} else {
|
|
1414
|
-
logger2.info(result.packageFileName);
|
|
1415
|
-
}
|
|
1416
|
-
} else {
|
|
1417
|
-
logger2.error(`pack: Unable to find any files to pack: ${targetDir}`);
|
|
1418
|
-
return 1;
|
|
1419
|
-
}
|
|
1420
|
-
} catch (error) {
|
|
1421
|
-
logger2.error(`pack: Failed to create archive: ${error}`);
|
|
1422
|
-
return 1;
|
|
1423
|
-
}
|
|
1424
|
-
return 0;
|
|
1184
|
+
var packCommand = async (args, logger) => {
|
|
1185
|
+
var _args$options$peerDe;
|
|
1186
|
+
if (args.options.help || args.options.h) {
|
|
1187
|
+
showPackHelp();
|
|
1188
|
+
return 1;
|
|
1189
|
+
}
|
|
1190
|
+
const directory = args.positional[0];
|
|
1191
|
+
const packDestination = args.options["pack-destination"];
|
|
1192
|
+
const readmeOption = args.options["readme"];
|
|
1193
|
+
const inheritableFieldsOption = args.options["inheritable-fields"];
|
|
1194
|
+
const checkWorkingDirectoryStatus = args.options["no-wds"] ? false : true;
|
|
1195
|
+
const alwaysOverrideVersionFromGit = !args.options["no-git-version-override"];
|
|
1196
|
+
const mergeFiles = !args.options["no-merge-files"];
|
|
1197
|
+
const replacePeerDepsWildcards = !args.options["no-replace-peer-deps"];
|
|
1198
|
+
const peerDepsVersionPrefix = (_args$options$peerDe = args.options["peer-deps-prefix"]) !== null && _args$options$peerDe !== void 0 ? _args$options$peerDe : "^";
|
|
1199
|
+
const packageManager = args.options["use-pnpm"] ? "pnpm" : "npm";
|
|
1200
|
+
const verbose = args.options["verbose"] ? true : false;
|
|
1201
|
+
const targetDir = resolve(directory !== null && directory !== void 0 ? directory : process.cwd());
|
|
1202
|
+
const outputDir = packDestination ? resolve(packDestination) : process.cwd();
|
|
1203
|
+
const readmeReplacementPath = readmeOption ? resolve(readmeOption) : void 0;
|
|
1204
|
+
const inheritableFields = parseInheritableFields(inheritableFieldsOption);
|
|
1205
|
+
if (verbose) logger.info(`pack: Creating archive of ${targetDir}...`);
|
|
1206
|
+
try {
|
|
1207
|
+
const result = await packAssets(targetDir, outputDir, checkWorkingDirectoryStatus, alwaysOverrideVersionFromGit, inheritableFields, readmeReplacementPath, replacePeerDepsWildcards, peerDepsVersionPrefix, logger, mergeFiles, packageManager);
|
|
1208
|
+
if (result) if (verbose) logger.info(`pack: Archive created successfully: ${result.packageFileName}`);
|
|
1209
|
+
else logger.info(result.packageFileName);
|
|
1210
|
+
else {
|
|
1211
|
+
logger.error(`pack: Unable to find any files to pack: ${targetDir}`);
|
|
1212
|
+
return 1;
|
|
1213
|
+
}
|
|
1214
|
+
} catch (error) {
|
|
1215
|
+
logger.error(`pack: Failed to create archive: ${error}`);
|
|
1216
|
+
return 1;
|
|
1217
|
+
}
|
|
1218
|
+
return 0;
|
|
1425
1219
|
};
|
|
1426
|
-
|
|
1427
|
-
|
|
1220
|
+
var showPublishHelp = () => {
|
|
1221
|
+
console.info(`Usage: screw-up publish [options] [directory|package.tgz]
|
|
1428
1222
|
|
|
1429
1223
|
Publish the project
|
|
1430
1224
|
|
|
@@ -1432,6 +1226,7 @@ Arguments:
|
|
|
1432
1226
|
directory|package.tgz Directory to pack and publish, or existing tarball to publish
|
|
1433
1227
|
|
|
1434
1228
|
Options:
|
|
1229
|
+
--use-pnpm Use pnpm pack before publish; final publish still targets npm-compatible registries
|
|
1435
1230
|
All npm publish options are supported, including:
|
|
1436
1231
|
--dry-run Perform a dry run
|
|
1437
1232
|
--tag <tag> Tag for the published version
|
|
@@ -1446,162 +1241,124 @@ Examples:
|
|
|
1446
1241
|
screw-up publish --dry-run --tag beta # Publish with options
|
|
1447
1242
|
`);
|
|
1448
1243
|
};
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1244
|
+
var runNpmPublish = async (tarballPath, npmOptions, verbose, logger) => {
|
|
1245
|
+
if (verbose) logger.info(`publish: Publishing ${tarballPath} to npm...`);
|
|
1246
|
+
const publishArgs = [
|
|
1247
|
+
"publish",
|
|
1248
|
+
tarballPath,
|
|
1249
|
+
...npmOptions
|
|
1250
|
+
];
|
|
1251
|
+
if (process.env.SCREW_UP_TEST_MODE === "true") {
|
|
1252
|
+
logger.info(`TEST_MODE: Would execute: npm ${publishArgs.join(" ")}`);
|
|
1253
|
+
logger.info(`TEST_MODE: Tarball path: ${tarballPath}`);
|
|
1254
|
+
logger.info(`TEST_MODE: Options: ${npmOptions.join(" ")}`);
|
|
1255
|
+
logger.info(`publish: Successfully published ${tarballPath}`);
|
|
1256
|
+
return 0;
|
|
1257
|
+
}
|
|
1258
|
+
const npmProcess = spawn("npm", publishArgs, { stdio: "inherit" });
|
|
1259
|
+
return new Promise((resolve, reject) => {
|
|
1260
|
+
npmProcess.on("close", (code, signal) => {
|
|
1261
|
+
if (code === 0) {
|
|
1262
|
+
if (verbose) logger.info(`publish: Successfully published ${tarballPath}`);
|
|
1263
|
+
resolve(0);
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1266
|
+
if (signal) {
|
|
1267
|
+
logger.error(`publish: npm publish terminated by signal ${signal}: ${tarballPath}`);
|
|
1268
|
+
resolve(1);
|
|
1269
|
+
return;
|
|
1270
|
+
}
|
|
1271
|
+
const exitCode = code !== null && code !== void 0 ? code : 1;
|
|
1272
|
+
logger.error(`publish: npm publish failed with exit code ${exitCode}: ${tarballPath}`);
|
|
1273
|
+
resolve(exitCode);
|
|
1274
|
+
});
|
|
1275
|
+
npmProcess.on("error", reject);
|
|
1276
|
+
});
|
|
1476
1277
|
};
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
alwaysOverrideVersionFromGit,
|
|
1558
|
-
inheritableFields,
|
|
1559
|
-
readmeReplacementPath,
|
|
1560
|
-
replacePeerDepsWildcards,
|
|
1561
|
-
peerDepsVersionPrefix,
|
|
1562
|
-
logger2,
|
|
1563
|
-
mergeFiles
|
|
1564
|
-
);
|
|
1565
|
-
if (result == null ? void 0 : result.metadata) {
|
|
1566
|
-
if (verbose) {
|
|
1567
|
-
logger2.info(
|
|
1568
|
-
`publish: Archive created successfully: ${result.packageFileName}`
|
|
1569
|
-
);
|
|
1570
|
-
}
|
|
1571
|
-
const archivePath = join(outputDir, result.packageFileName);
|
|
1572
|
-
return await runNpmPublish(
|
|
1573
|
-
archivePath,
|
|
1574
|
-
npmOptions,
|
|
1575
|
-
verbose,
|
|
1576
|
-
logger2
|
|
1577
|
-
);
|
|
1578
|
-
} else {
|
|
1579
|
-
logger2.error(
|
|
1580
|
-
`publish: Unable to find any files to pack: ${targetDir}`
|
|
1581
|
-
);
|
|
1582
|
-
return 1;
|
|
1583
|
-
}
|
|
1584
|
-
} finally {
|
|
1585
|
-
await rm(outputDir, { recursive: true, force: true });
|
|
1586
|
-
}
|
|
1587
|
-
} else {
|
|
1588
|
-
logger2.error(
|
|
1589
|
-
`publish: Invalid path - must be a directory or .tgz/.tar.gz file: ${path}`
|
|
1590
|
-
);
|
|
1591
|
-
return 1;
|
|
1592
|
-
}
|
|
1593
|
-
} else {
|
|
1594
|
-
logger2.error(`publish: Path does not exist: ${path}`);
|
|
1595
|
-
return 1;
|
|
1596
|
-
}
|
|
1597
|
-
} catch (error) {
|
|
1598
|
-
logger2.error(`publish: Failed to publish: ${error}`);
|
|
1599
|
-
return 1;
|
|
1600
|
-
}
|
|
1278
|
+
var publishCommand = async (args, logger) => {
|
|
1279
|
+
var _args$options$peerDe2;
|
|
1280
|
+
if (args.options.help || args.options.h) {
|
|
1281
|
+
showPublishHelp();
|
|
1282
|
+
return 1;
|
|
1283
|
+
}
|
|
1284
|
+
const path = args.positional[0];
|
|
1285
|
+
const readmeOption = args.options["readme"];
|
|
1286
|
+
const inheritableFieldsOption = args.options["inheritable-fields"];
|
|
1287
|
+
const checkWorkingDirectoryStatus = args.options["no-wds"] ? false : true;
|
|
1288
|
+
const alwaysOverrideVersionFromGit = !args.options["no-git-version-override"];
|
|
1289
|
+
const mergeFiles = !args.options["no-merge-files"];
|
|
1290
|
+
const replacePeerDepsWildcards = !args.options["no-replace-peer-deps"];
|
|
1291
|
+
const peerDepsVersionPrefix = (_args$options$peerDe2 = args.options["peer-deps-prefix"]) !== null && _args$options$peerDe2 !== void 0 ? _args$options$peerDe2 : "^";
|
|
1292
|
+
const packageManager = args.options["use-pnpm"] ? "pnpm" : "npm";
|
|
1293
|
+
const verbose = args.options["verbose"] ? true : false;
|
|
1294
|
+
const inheritableFields = parseInheritableFields(inheritableFieldsOption);
|
|
1295
|
+
const readmeReplacementPath = readmeOption ? resolve(readmeOption) : void 0;
|
|
1296
|
+
const npmOptions = [];
|
|
1297
|
+
let pathSkipped = false;
|
|
1298
|
+
for (let i = 0; i < args.argv.length; i++) {
|
|
1299
|
+
const arg = args.argv[i];
|
|
1300
|
+
if (arg === "publish") {} else if (arg === "--help" || arg === "--verbose" || arg === "--use-pnpm" || arg === "-h" || arg === "--no-wds" || arg === "--no-git-version-override" || arg === "--no-merge-files" || arg === "--no-replace-peer-deps") {} else if (arg === "--readme" || arg === "--inheritable-fields" || arg === "--peer-deps-prefix") i++;
|
|
1301
|
+
else if (!pathSkipped && path && arg === path) pathSkipped = true;
|
|
1302
|
+
else npmOptions.push(arg);
|
|
1303
|
+
}
|
|
1304
|
+
try {
|
|
1305
|
+
if (!path) {
|
|
1306
|
+
const targetDir = process.cwd();
|
|
1307
|
+
const outputDir = await mkdtemp(join(tmpdir(), "screw-up-publish-"));
|
|
1308
|
+
if (verbose) logger.info(`publish: Creating archive of ${targetDir}...`);
|
|
1309
|
+
try {
|
|
1310
|
+
const result = await packAssets(targetDir, outputDir, checkWorkingDirectoryStatus, alwaysOverrideVersionFromGit, inheritableFields, readmeReplacementPath, replacePeerDepsWildcards, peerDepsVersionPrefix, logger, mergeFiles, packageManager);
|
|
1311
|
+
if (result === null || result === void 0 ? void 0 : result.metadata) {
|
|
1312
|
+
if (verbose) logger.info(`publish: Archive created successfully: ${result.packageFileName}`);
|
|
1313
|
+
return await runNpmPublish(join(outputDir, result.packageFileName), npmOptions, verbose, logger);
|
|
1314
|
+
} else {
|
|
1315
|
+
logger.error(`publish: Unable to find any files to pack: ${targetDir}`);
|
|
1316
|
+
return 1;
|
|
1317
|
+
}
|
|
1318
|
+
} finally {
|
|
1319
|
+
await rm(outputDir, {
|
|
1320
|
+
recursive: true,
|
|
1321
|
+
force: true
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
} else if (existsSync(path)) {
|
|
1325
|
+
const pathStat = await stat(path);
|
|
1326
|
+
if (pathStat.isFile() && (path.endsWith(".tgz") || path.endsWith(".tar.gz"))) return await runNpmPublish(resolve(path), npmOptions, verbose, logger);
|
|
1327
|
+
else if (pathStat.isDirectory()) {
|
|
1328
|
+
const targetDir = resolve(path);
|
|
1329
|
+
const outputDir = await mkdtemp(join(tmpdir(), "screw-up-publish-"));
|
|
1330
|
+
if (verbose) logger.info(`publish: Creating archive of ${targetDir}...`);
|
|
1331
|
+
try {
|
|
1332
|
+
const result = await packAssets(targetDir, outputDir, checkWorkingDirectoryStatus, alwaysOverrideVersionFromGit, inheritableFields, readmeReplacementPath, replacePeerDepsWildcards, peerDepsVersionPrefix, logger, mergeFiles, packageManager);
|
|
1333
|
+
if (result === null || result === void 0 ? void 0 : result.metadata) {
|
|
1334
|
+
if (verbose) logger.info(`publish: Archive created successfully: ${result.packageFileName}`);
|
|
1335
|
+
return await runNpmPublish(join(outputDir, result.packageFileName), npmOptions, verbose, logger);
|
|
1336
|
+
} else {
|
|
1337
|
+
logger.error(`publish: Unable to find any files to pack: ${targetDir}`);
|
|
1338
|
+
return 1;
|
|
1339
|
+
}
|
|
1340
|
+
} finally {
|
|
1341
|
+
await rm(outputDir, {
|
|
1342
|
+
recursive: true,
|
|
1343
|
+
force: true
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
} else {
|
|
1347
|
+
logger.error(`publish: Invalid path - must be a directory or .tgz/.tar.gz file: ${path}`);
|
|
1348
|
+
return 1;
|
|
1349
|
+
}
|
|
1350
|
+
} else {
|
|
1351
|
+
logger.error(`publish: Path does not exist: ${path}`);
|
|
1352
|
+
return 1;
|
|
1353
|
+
}
|
|
1354
|
+
} catch (error) {
|
|
1355
|
+
logger.error(`publish: Failed to publish: ${error}`);
|
|
1356
|
+
return 1;
|
|
1357
|
+
}
|
|
1601
1358
|
};
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1359
|
+
var showHelp = async () => {
|
|
1360
|
+
const { author, license, repository_url, version, git_commit_hash } = await import("./packageMetadata-11MbeI_K.js").then((n) => n.r);
|
|
1361
|
+
console.info(`screw-up [${version}-${git_commit_hash}]
|
|
1605
1362
|
Easy package metadata inserter CLI
|
|
1606
1363
|
Copyright (c) ${author}
|
|
1607
1364
|
Repository: ${repository_url}
|
|
@@ -1629,56 +1386,50 @@ Examples:
|
|
|
1629
1386
|
screw-up publish package.tgz # Publish existing tarball
|
|
1630
1387
|
`);
|
|
1631
1388
|
};
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1389
|
+
var argOptionMap = new Map([
|
|
1390
|
+
["dump", new Set(["inheritable-fields"])],
|
|
1391
|
+
["metadata", new Set(["output-metadata-file-path", "output-metadata-keys"])],
|
|
1392
|
+
["pack", new Set([
|
|
1393
|
+
"pack-destination",
|
|
1394
|
+
"readme",
|
|
1395
|
+
"inheritable-fields",
|
|
1396
|
+
"peer-deps-prefix"
|
|
1397
|
+
])],
|
|
1398
|
+
["format", new Set([
|
|
1399
|
+
"input",
|
|
1400
|
+
"i",
|
|
1401
|
+
"bracket",
|
|
1402
|
+
"b",
|
|
1403
|
+
"inheritable-fields"
|
|
1404
|
+
])],
|
|
1405
|
+
["publish", new Set(["inheritable-fields", "peer-deps-prefix"])]
|
|
1646
1406
|
]);
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
if (parsedArgs.command) {
|
|
1666
|
-
logger2.error(`Unknown command: ${parsedArgs.command}`);
|
|
1667
|
-
} else {
|
|
1668
|
-
logger2.error(`Unknown command`);
|
|
1669
|
-
}
|
|
1670
|
-
logger2.error('Run "screw-up --help" for usage information.');
|
|
1671
|
-
return 1;
|
|
1672
|
-
}
|
|
1407
|
+
var cliMain = async (args, logger) => {
|
|
1408
|
+
const parsedArgs = parseArgs(args, argOptionMap);
|
|
1409
|
+
if (!parsedArgs.command && (parsedArgs.options.help || parsedArgs.options.h)) {
|
|
1410
|
+
await showHelp();
|
|
1411
|
+
return 1;
|
|
1412
|
+
}
|
|
1413
|
+
switch (parsedArgs.command) {
|
|
1414
|
+
case "format": return await formatCommand(parsedArgs, logger);
|
|
1415
|
+
case "dump": return await dumpCommand(parsedArgs, logger);
|
|
1416
|
+
case "metadata": return await metadataCommand(parsedArgs, logger);
|
|
1417
|
+
case "pack": return await packCommand(parsedArgs, logger);
|
|
1418
|
+
case "publish": return await publishCommand(parsedArgs, logger);
|
|
1419
|
+
default:
|
|
1420
|
+
if (parsedArgs.command) logger.error(`Unknown command: ${parsedArgs.command}`);
|
|
1421
|
+
else logger.error(`Unknown command`);
|
|
1422
|
+
logger.error("Run \"screw-up --help\" for usage information.");
|
|
1423
|
+
return 1;
|
|
1424
|
+
}
|
|
1673
1425
|
};
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
).then((code) => process.exit(code)).catch((error) => {
|
|
1681
|
-
logger.error(`CLI error: ${error}`);
|
|
1682
|
-
process.exit(1);
|
|
1426
|
+
//#endregion
|
|
1427
|
+
//#region src/main.ts
|
|
1428
|
+
var logger = createConsoleLogger(`${name}-cli`);
|
|
1429
|
+
cliMain(process.argv.slice(2), logger).then((code) => process.exit(code)).catch((error) => {
|
|
1430
|
+
logger.error(`CLI error: ${error}`);
|
|
1431
|
+
process.exit(1);
|
|
1683
1432
|
});
|
|
1684
|
-
//#
|
|
1433
|
+
//#endregion
|
|
1434
|
+
|
|
1435
|
+
//# sourceMappingURL=main.mjs.map
|