screw-up 0.9.1 → 0.10.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/cli.cjs CHANGED
@@ -5,80 +5,374 @@ const fs = require("fs");
5
5
  const promises = require("fs/promises");
6
6
  const child_process = require("child_process");
7
7
  const glob = require("glob");
8
- const internal = require("./internal-BJ2gdqpB.cjs");
9
- const tar = require("tar-stream");
8
+ const stream = require("stream");
10
9
  const zlib = require("zlib");
11
- const addPackContentEntry = async (pack, name, content) => {
12
- pack.entry({
13
- name,
14
- type: "file",
15
- mode: 420,
16
- mtime: /* @__PURE__ */ new Date(),
17
- size: Buffer.byteLength(content, "utf8")
18
- }, content);
10
+ const internal = require("./internal-Dli6fSLz.cjs");
11
+ /*!
12
+ * name: tar-vern
13
+ * version: 0.3.0
14
+ * description: Tape archiver library for Typescript
15
+ * author: Kouji Matsui (@kekyo@mi.kekyo.net)
16
+ * license: MIT
17
+ * repository.url: https://github.com/kekyo/tar-vern.git
18
+ */
19
+ const getUName = (candidateName, candidateId, reflectStat) => {
20
+ return "root";
19
21
  };
20
- const addPackFileEntry = async (pack, baseDir, path$1, stat) => {
21
- const writer = pack.entry({
22
- name: path$1,
23
- mode: stat.mode,
24
- mtime: stat.mtime,
25
- size: stat.size
22
+ const getBuffer = (data) => {
23
+ return Buffer.isBuffer(data) ? data : Buffer.from(data, "utf8");
24
+ };
25
+ const createFileItem = async (path2, content, options) => {
26
+ var _a, _b, _c, _d, _e, _f;
27
+ const mode = (_a = options == null ? void 0 : options.mode) != null ? _a : 420;
28
+ const uid = (_b = options == null ? void 0 : options.uid) != null ? _b : 0;
29
+ const gid = (_c = options == null ? void 0 : options.gid) != null ? _c : 0;
30
+ const date = (_d = options == null ? void 0 : options.date) != null ? _d : /* @__PURE__ */ new Date();
31
+ const uname = (_e = options == null ? void 0 : options.uname) != null ? _e : "root";
32
+ const gname = (_f = options == null ? void 0 : options.gname) != null ? _f : "root";
33
+ return {
34
+ kind: "file",
35
+ path: path2,
36
+ mode,
37
+ uname,
38
+ gname,
39
+ uid,
40
+ gid,
41
+ date,
42
+ content
43
+ };
44
+ };
45
+ const createReadableFileItem = async (path2, readable, options) => {
46
+ var _a, _b, _c, _d, _e, _f;
47
+ const mode = (_a = options == null ? void 0 : options.mode) != null ? _a : 420;
48
+ const uid = (_b = options == null ? void 0 : options.uid) != null ? _b : 0;
49
+ const gid = (_c = options == null ? void 0 : options.gid) != null ? _c : 0;
50
+ const date = (_d = options == null ? void 0 : options.date) != null ? _d : /* @__PURE__ */ new Date();
51
+ const uname = (_e = options == null ? void 0 : options.uname) != null ? _e : "root";
52
+ const gname = (_f = options == null ? void 0 : options.gname) != null ? _f : "root";
53
+ let length = options == null ? void 0 : options.length;
54
+ if (!length) {
55
+ const chunks = [];
56
+ length = 0;
57
+ for await (const chunk of readable) {
58
+ const buffer = getBuffer(chunk);
59
+ chunks.push(buffer);
60
+ length += buffer.length;
61
+ }
62
+ return {
63
+ kind: "file",
64
+ path: path2,
65
+ mode,
66
+ uname,
67
+ gname,
68
+ uid,
69
+ gid,
70
+ date,
71
+ content: {
72
+ kind: "readable",
73
+ length,
74
+ readable: stream.Readable.from(chunks)
75
+ }
76
+ };
77
+ } else {
78
+ return {
79
+ kind: "file",
80
+ path: path2,
81
+ mode,
82
+ uname,
83
+ gname,
84
+ uid,
85
+ gid,
86
+ date,
87
+ content: {
88
+ kind: "readable",
89
+ length,
90
+ readable
91
+ }
92
+ };
93
+ }
94
+ };
95
+ const createReadFileItem = async (path2, filePath, reflectStat, options) => {
96
+ const stats = await promises.stat(filePath);
97
+ const reader = fs.createReadStream(filePath);
98
+ const mode = stats.mode;
99
+ const uid = stats.uid;
100
+ const gid = stats.gid;
101
+ const date = stats.mtime;
102
+ const uname = getUName(options == null ? void 0 : options.uname, stats.uid);
103
+ const gname = getUName(options == null ? void 0 : options.gname, stats.gid);
104
+ return await createReadableFileItem(path2, reader, {
105
+ length: stats.size,
106
+ mode,
107
+ uname,
108
+ gname,
109
+ uid,
110
+ gid,
111
+ date
26
112
  });
27
- const stream = fs.createReadStream(path.resolve(baseDir, path$1));
28
- stream.pipe(writer);
29
- return new Promise((resolve2, reject) => {
30
- stream.on("end", resolve2);
31
- stream.on("error", reject);
32
- writer.on("error", reject);
113
+ };
114
+ const storeReaderToFile = (reader, path2) => {
115
+ const writer = fs.createWriteStream(path2);
116
+ reader.pipe(writer);
117
+ return new Promise((res, rej) => {
118
+ writer.on("finish", res);
119
+ writer.on("error", rej);
120
+ reader.on("error", rej);
33
121
  });
34
122
  };
35
- const packAssets = async (targetDir, outputDir) => {
123
+ const utf8ByteLength = (str) => {
124
+ return Buffer.byteLength(str, "utf8");
125
+ };
126
+ const truncateUtf8Safe = (str, maxBytes) => {
127
+ let total = 0;
128
+ let i = 0;
129
+ while (i < str.length) {
130
+ const codePoint = str.codePointAt(i);
131
+ const char = String.fromCodePoint(codePoint);
132
+ const charBytes = Buffer.byteLength(char, "utf8");
133
+ if (total + charBytes > maxBytes) break;
134
+ total += charBytes;
135
+ i += char.length;
136
+ }
137
+ return str.slice(0, i);
138
+ };
139
+ const MAX_NAME = 100;
140
+ const MAX_PREFIX = 155;
141
+ const splitPath = (path2) => {
142
+ var _a;
143
+ if (utf8ByteLength(path2) <= MAX_NAME) {
144
+ return { prefix: "", name: path2 };
145
+ }
146
+ const parts = path2.split("/");
147
+ let name = (_a = parts.pop()) != null ? _a : "";
148
+ let prefix = parts.join("/");
149
+ if (utf8ByteLength(name) > MAX_NAME) {
150
+ name = truncateUtf8Safe(name, MAX_NAME);
151
+ }
152
+ while (utf8ByteLength(prefix) > MAX_PREFIX) {
153
+ prefix = truncateUtf8Safe(prefix, MAX_PREFIX);
154
+ }
155
+ return { prefix, name };
156
+ };
157
+ const getOctalBytes = (value, length) => {
158
+ const str = value.toString(8).padStart(length - 1, "0") + "\0";
159
+ return Buffer.from(str, "ascii");
160
+ };
161
+ const getPaddedBytes = (buffer) => {
162
+ const extra = buffer.length % 512;
163
+ if (extra === 0) {
164
+ return buffer;
165
+ } else {
166
+ return Buffer.concat([buffer, Buffer.alloc(512 - extra, 0)]);
167
+ }
168
+ };
169
+ const terminatorBytes = Buffer.alloc(1024, 0);
170
+ const createTarHeader = (type, path2, size, mode, uname, gname, uid, gid, date) => {
171
+ const buffer = Buffer.alloc(512, 0);
172
+ const { name, prefix } = splitPath(path2);
173
+ buffer.write(name, 0, 100, "utf8");
174
+ getOctalBytes(mode & 4095, 8).copy(buffer, 100);
175
+ getOctalBytes(uid, 8).copy(buffer, 108);
176
+ getOctalBytes(gid, 8).copy(buffer, 116);
177
+ getOctalBytes(size, 12).copy(buffer, 124);
178
+ getOctalBytes(Math.floor(date.getTime() / 1e3), 12).copy(buffer, 136);
179
+ Buffer.from(" ", "ascii").copy(buffer, 148);
180
+ if (type === "file") {
181
+ buffer.write("0", 156, 1, "ascii");
182
+ } else {
183
+ buffer.write("5", 156, 1, "ascii");
184
+ }
185
+ buffer.write("ustar\0", 257, 6, "ascii");
186
+ buffer.write("00", 263, 2, "ascii");
187
+ buffer.write(uname, 265, 32, "utf8");
188
+ buffer.write(gname, 297, 32, "utf8");
189
+ buffer.write(prefix, 345, 155, "utf8");
190
+ let sum = 0;
191
+ for (let i = 0; i < 512; i++) {
192
+ sum += buffer[i];
193
+ }
194
+ getOctalBytes(sum, 8).copy(buffer, 148);
195
+ return buffer;
196
+ };
197
+ const createTarPacker = (entryItemGenerator, compressionType, signal) => {
198
+ const entryItemIterator = async function* () {
199
+ for await (const entryItem of entryItemGenerator) {
200
+ switch (entryItem.kind) {
201
+ case "file": {
202
+ const entryItemContent = entryItem.content;
203
+ if (typeof entryItemContent === "string" || Buffer.isBuffer(entryItemContent)) {
204
+ const contentBytes = getBuffer(entryItemContent);
205
+ const tarHeaderBytes = createTarHeader(
206
+ "file",
207
+ entryItem.path,
208
+ contentBytes.length,
209
+ entryItem.mode,
210
+ entryItem.uname,
211
+ entryItem.gname,
212
+ entryItem.uid,
213
+ entryItem.gid,
214
+ entryItem.date
215
+ );
216
+ yield tarHeaderBytes;
217
+ const totalPaddedContentBytes = getPaddedBytes(contentBytes);
218
+ yield totalPaddedContentBytes;
219
+ } else {
220
+ const tarHeaderBytes = createTarHeader(
221
+ "file",
222
+ entryItem.path,
223
+ entryItemContent.length,
224
+ entryItem.mode,
225
+ entryItem.uname,
226
+ entryItem.gname,
227
+ entryItem.uid,
228
+ entryItem.gid,
229
+ entryItem.date
230
+ );
231
+ yield tarHeaderBytes;
232
+ let position = 0;
233
+ switch (entryItemContent.kind) {
234
+ case "generator": {
235
+ for await (const contentBytes of entryItemContent.generator) {
236
+ yield contentBytes;
237
+ position += contentBytes.length;
238
+ }
239
+ break;
240
+ }
241
+ case "readable": {
242
+ for await (const content of entryItemContent.readable) {
243
+ const contentBytes = getBuffer(content);
244
+ yield contentBytes;
245
+ position += contentBytes.length;
246
+ }
247
+ break;
248
+ }
249
+ }
250
+ if (position % 512 !== 0) {
251
+ yield Buffer.alloc(512 - position % 512, 0);
252
+ }
253
+ }
254
+ break;
255
+ }
256
+ case "directory": {
257
+ const tarHeaderBytes = createTarHeader(
258
+ "directory",
259
+ entryItem.path,
260
+ 0,
261
+ entryItem.mode,
262
+ entryItem.uname,
263
+ entryItem.gname,
264
+ entryItem.uid,
265
+ entryItem.gid,
266
+ entryItem.date
267
+ );
268
+ yield tarHeaderBytes;
269
+ break;
270
+ }
271
+ }
272
+ }
273
+ yield terminatorBytes;
274
+ };
275
+ const ct = compressionType;
276
+ switch (ct) {
277
+ case "none": {
278
+ return stream.Readable.from(entryItemIterator());
279
+ }
280
+ case "gzip": {
281
+ const gzipStream = zlib.createGzip({ level: 9 });
282
+ const entryItemStream = stream.Readable.from(entryItemIterator());
283
+ entryItemStream.pipe(gzipStream);
284
+ return gzipStream;
285
+ }
286
+ }
287
+ };
288
+ const createPackEntryGenerator = async function* (targetDir, resolvedPackageJson, readmeReplacementPath) {
289
+ var _a;
290
+ const packageJsonContent = JSON.stringify(resolvedPackageJson, null, 2);
291
+ yield await createFileItem("package/package.json", packageJsonContent);
292
+ const distributionFileGlobs = (_a = resolvedPackageJson == null ? void 0 : resolvedPackageJson.files) != null ? _a : ["**/*"];
293
+ const packingFilePaths = (await Promise.all(
294
+ distributionFileGlobs.map(async (pattern) => {
295
+ const fullPath = path.resolve(targetDir, pattern);
296
+ try {
297
+ if (fs.existsSync(fullPath) && (await promises.lstat(fullPath)).isDirectory()) {
298
+ return await glob.glob(`${pattern}/**/*`, { cwd: targetDir });
299
+ }
300
+ return await glob.glob(pattern, { cwd: targetDir });
301
+ } catch (error) {
302
+ return await glob.glob(pattern, { cwd: targetDir });
303
+ }
304
+ })
305
+ )).flat();
306
+ for (const packingFilePath of packingFilePaths) {
307
+ if (packingFilePath !== "package.json") {
308
+ const fullPath = path.resolve(targetDir, packingFilePath);
309
+ const stat = await promises.lstat(fullPath);
310
+ if (stat.isFile()) {
311
+ if (packingFilePath === "README.md" && readmeReplacementPath) {
312
+ yield await createReadFileItem("package/README.md", readmeReplacementPath);
313
+ } else {
314
+ yield await createReadFileItem(`package/${packingFilePath}`, fullPath);
315
+ }
316
+ }
317
+ }
318
+ }
319
+ if (readmeReplacementPath && !packingFilePaths.includes("README.md")) {
320
+ yield await createReadFileItem("package/README.md", readmeReplacementPath);
321
+ }
322
+ };
323
+ const packAssets = async (targetDir, outputDir, checkWorkingDirectoryStatus, inheritableFields, readmeReplacementPath) => {
36
324
  var _a, _b, _c, _d;
37
325
  if (!fs.existsSync(targetDir)) {
38
326
  return void 0;
39
327
  }
40
- let resolvedPackageJson;
328
+ let result;
41
329
  try {
42
- resolvedPackageJson = await internal.resolveRawPackageJson(targetDir);
330
+ result = await internal.resolveRawPackageJsonObject(
331
+ targetDir,
332
+ checkWorkingDirectoryStatus,
333
+ inheritableFields
334
+ );
43
335
  } catch (error) {
44
336
  return void 0;
45
337
  }
338
+ const { packageJson: resolvedPackageJson, sourceMap } = result;
46
339
  if (resolvedPackageJson == null ? void 0 : resolvedPackageJson.private) {
47
340
  return void 0;
48
341
  }
49
- const outputFileName = `${(_b = (_a = resolvedPackageJson == null ? void 0 : resolvedPackageJson.name) == null ? void 0 : _a.replace("/", "-")) != null ? _b : "package"}-${(_c = resolvedPackageJson == null ? void 0 : resolvedPackageJson.version) != null ? _c : "0.0.0"}.tgz`;
50
- const pack = tar.pack();
51
- try {
52
- const packageJsonContent = JSON.stringify(resolvedPackageJson, null, 2);
53
- await addPackContentEntry(pack, "package.json", packageJsonContent);
54
- const distributionFileGlobs = (_d = resolvedPackageJson == null ? void 0 : resolvedPackageJson.files) != null ? _d : ["**/*"];
55
- const packingFilePaths = distributionFileGlobs.map((fg) => glob.glob.sync(fg, { cwd: targetDir })).flat();
56
- for (const packingFilePath of packingFilePaths) {
57
- const fullPath = path.resolve(targetDir, packingFilePath);
58
- const stat = await promises.lstat(fullPath);
59
- if (stat.isFile() && packingFilePath !== "package.json") {
60
- await addPackFileEntry(pack, targetDir, packingFilePath, stat);
61
- }
62
- }
63
- pack.finalize();
64
- if (!fs.existsSync(outputDir)) {
65
- await promises.mkdir(outputDir, { recursive: true });
342
+ let finalReadmeReplacementPath = readmeReplacementPath;
343
+ if (!finalReadmeReplacementPath && (resolvedPackageJson == null ? void 0 : resolvedPackageJson.readme)) {
344
+ const readmeSourceDir = (_a = sourceMap.get("readme")) != null ? _a : targetDir;
345
+ const packageReadmePath = path.resolve(readmeSourceDir, resolvedPackageJson.readme);
346
+ if (fs.existsSync(packageReadmePath)) {
347
+ finalReadmeReplacementPath = packageReadmePath;
66
348
  }
67
- const outputFile = path.resolve(outputDir, outputFileName);
68
- const outputStream = fs.createWriteStream(outputFile);
69
- const gzip = zlib.createGzip();
70
- await new Promise((resolve2, reject) => {
71
- pack.pipe(gzip).pipe(outputStream);
72
- outputStream.on("finish", () => resolve2());
73
- outputStream.on("error", reject);
74
- pack.on("error", reject);
75
- gzip.on("error", reject);
76
- });
77
- } finally {
78
- pack.destroy();
79
349
  }
350
+ if (finalReadmeReplacementPath && !fs.existsSync(finalReadmeReplacementPath)) {
351
+ throw new Error(`README replacement file not found: ${finalReadmeReplacementPath}`);
352
+ }
353
+ 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`;
354
+ if (!fs.existsSync(outputDir)) {
355
+ await promises.mkdir(outputDir, { recursive: true });
356
+ }
357
+ const packer = createTarPacker(
358
+ createPackEntryGenerator(targetDir, resolvedPackageJson, finalReadmeReplacementPath),
359
+ "gzip"
360
+ );
361
+ const outputFile = path.resolve(outputDir, outputFileName);
362
+ await storeReaderToFile(packer, outputFile);
80
363
  return resolvedPackageJson;
81
364
  };
365
+ const getComputedPackageJsonObject = async (targetDir, checkWorkingDirectoryStatus, inheritableFields) => {
366
+ if (!fs.existsSync(targetDir)) {
367
+ return void 0;
368
+ }
369
+ const result = await internal.resolveRawPackageJsonObject(
370
+ targetDir,
371
+ checkWorkingDirectoryStatus,
372
+ inheritableFields
373
+ );
374
+ return result.packageJson;
375
+ };
82
376
  const parseArgs = (argv) => {
83
377
  const args = argv.slice(2);
84
378
  const result = {
@@ -95,7 +389,7 @@ const parseArgs = (argv) => {
95
389
  if (arg.startsWith("--")) {
96
390
  const optionName = arg.slice(2);
97
391
  const nextArg = args[i2 + 1];
98
- if (nextArg && !nextArg.startsWith("-")) {
392
+ if (nextArg !== void 0 && !nextArg.startsWith("-")) {
99
393
  result.options[optionName] = nextArg;
100
394
  i2 += 2;
101
395
  } else {
@@ -120,7 +414,7 @@ const parseArgs = (argv) => {
120
414
  if (arg.startsWith("--")) {
121
415
  const optionName = arg.slice(2);
122
416
  const nextArg = args[i + 1];
123
- if (nextArg && !nextArg.startsWith("-")) {
417
+ if (nextArg !== void 0 && !nextArg.startsWith("-")) {
124
418
  result.options[optionName] = nextArg;
125
419
  i += 2;
126
420
  } else {
@@ -138,8 +432,28 @@ const parseArgs = (argv) => {
138
432
  }
139
433
  return result;
140
434
  };
435
+ const defaultInheritableFields = /* @__PURE__ */ new Set([
436
+ "version",
437
+ "description",
438
+ "author",
439
+ "license",
440
+ "repository",
441
+ "keywords",
442
+ "homepage",
443
+ "bugs",
444
+ "readme"
445
+ ]);
446
+ const parseInheritableFields = (inheritableFieldsOption) => {
447
+ if (typeof inheritableFieldsOption !== "string") {
448
+ return defaultInheritableFields;
449
+ }
450
+ if (!inheritableFieldsOption.trim()) {
451
+ return /* @__PURE__ */ new Set();
452
+ }
453
+ return new Set(inheritableFieldsOption.split(",").map((field) => field.trim()).filter((field) => field.length > 0));
454
+ };
141
455
  const showHelp = () => {
142
- console.log(`screw-up - Easy package metadata inserter CLI [${"0.9.1"}]
456
+ console.log(`screw-up - Easy package metadata inserter CLI [${void 0}]
143
457
  Copyright (c) ${"Kouji Matsui (@kekyo@mi.kekyo.net)"}
144
458
  Repository: ${"https://github.com/kekyo/screw-up.git"}
145
459
  License: ${"MIT"}
@@ -149,24 +463,29 @@ Usage: screw-up <command> [options]
149
463
  Commands:
150
464
  pack [directory] Pack the project into a tar archive
151
465
  publish [directory|package.tgz] Publish the project
466
+ dump [directory] Dump computed package.json as JSON
152
467
 
153
468
  Options:
154
469
  -h, --help Show help
155
470
 
156
471
  Pack Options:
157
472
  --pack-destination <path> Directory to write the tarball
473
+ --readme <path> Replace README.md with specified file
474
+ --inheritable-fields <list> Comma-separated list of fields to inherit from parent (default: version,description,author,license,repository,keywords,homepage,bugs,readme)
475
+ --no-wds Do not check working directory status to increase version
158
476
 
159
477
  Publish Options:
160
478
  All npm publish options are supported (e.g., --dry-run, --tag, --access, --registry)
161
479
 
162
480
  Examples:
163
- screw-up pack # Pack current directory
164
- screw-up pack ./my-project # Pack specific directory
165
- screw-up pack --pack-destination ./dist # Pack to specific output directory
166
- screw-up publish # Publish current directory
167
- screw-up publish ./my-project # Publish specific directory
168
- screw-up publish package.tgz # Publish existing tarball
169
- screw-up publish --dry-run --tag beta # Publish with npm options
481
+ screw-up pack # Pack current directory
482
+ screw-up pack ./my-project # Pack specific directory
483
+ screw-up pack --pack-destination ./dist # Pack to specific output directory
484
+ screw-up pack --readme ./README_pack.md # Pack with custom README
485
+ screw-up publish # Publish current directory
486
+ screw-up publish ./my-project # Publish specific directory
487
+ screw-up publish package.tgz # Publish existing tarball
488
+ screw-up publish --dry-run --tag beta # Publish with npm options
170
489
  `);
171
490
  };
172
491
  const showPackHelp = () => {
@@ -179,6 +498,9 @@ Arguments:
179
498
 
180
499
  Options:
181
500
  --pack-destination <path> Directory to write the tarball
501
+ --readme <path> Replace README.md with specified file
502
+ --inheritable-fields <list> Comma-separated list of fields to inherit from parent
503
+ --no-wds Do not check working directory status to increase version
182
504
  -h, --help Show help for pack command
183
505
  `);
184
506
  };
@@ -212,11 +534,22 @@ const packCommand = async (args) => {
212
534
  }
213
535
  const directory = args.positional[0];
214
536
  const packDestination = args.options["pack-destination"];
537
+ const readmeOption = args.options["readme"];
538
+ const inheritableFieldsOption = args.options["inheritable-fields"];
539
+ const checkWorkingDirectoryStatus = args.options["no-wds"] ? false : true;
215
540
  const targetDir = path.resolve(directory != null ? directory : process.cwd());
216
541
  const outputDir = packDestination ? path.resolve(packDestination) : process.cwd();
542
+ const readmeReplacementPath = readmeOption ? path.resolve(readmeOption) : void 0;
543
+ const inheritableFields = parseInheritableFields(inheritableFieldsOption);
217
544
  console.log(`[screw-up/cli]: pack: Creating archive of ${targetDir}...`);
218
545
  try {
219
- const metadata = await packAssets(targetDir, outputDir);
546
+ const metadata = await packAssets(
547
+ targetDir,
548
+ outputDir,
549
+ checkWorkingDirectoryStatus,
550
+ inheritableFields,
551
+ readmeReplacementPath
552
+ );
220
553
  if (metadata) {
221
554
  console.log(`[screw-up/cli]: pack: Archive created successfully: ${outputDir}`);
222
555
  } else {
@@ -233,7 +566,7 @@ const publishCommand = async (args) => {
233
566
  showPublishHelp();
234
567
  return;
235
568
  }
236
- const runNpmPublish = async (tarballPath, npmOptions2 = []) => {
569
+ const runNpmPublish = async (tarballPath, npmOptions2) => {
237
570
  console.log(`[screw-up/cli]: publish: Publishing ${tarballPath} to npm...`);
238
571
  const publishArgs = ["publish", tarballPath, ...npmOptions2];
239
572
  if (process.env.SCREW_UP_TEST_MODE === "true") {
@@ -257,9 +590,12 @@ const publishCommand = async (args) => {
257
590
  });
258
591
  };
259
592
  const path$1 = args.positional[0];
593
+ const inheritableFieldsOption = args.options["inheritable-fields"];
594
+ const checkWorkingDirectoryStatus = args.options["no-wds"] ? false : true;
595
+ const inheritableFields = parseInheritableFields(inheritableFieldsOption);
260
596
  const npmOptions = [];
261
597
  Object.entries(args.options).forEach(([key, value]) => {
262
- if (key === "help" || key === "h") return;
598
+ if (key === "help" || key === "h" || key === "no-wds" || key === "inheritable-fields") return;
263
599
  if (value === true) {
264
600
  npmOptions.push(`--${key}`);
265
601
  } else {
@@ -272,7 +608,13 @@ const publishCommand = async (args) => {
272
608
  const outputDir = await promises.mkdtemp("screw-up-publish-");
273
609
  console.log(`[screw-up/cli]: publish: Creating archive of ${targetDir}...`);
274
610
  try {
275
- const metadata = await packAssets(targetDir, outputDir);
611
+ const metadata = await packAssets(
612
+ targetDir,
613
+ outputDir,
614
+ checkWorkingDirectoryStatus,
615
+ inheritableFields,
616
+ void 0
617
+ );
276
618
  if (metadata) {
277
619
  const archiveName = `${metadata.name}-${metadata.version}.tgz`;
278
620
  const archivePath = path.join(outputDir, archiveName);
@@ -293,7 +635,13 @@ const publishCommand = async (args) => {
293
635
  const outputDir = await promises.mkdtemp("screw-up-publish-");
294
636
  console.log(`[screw-up/cli]: publish: Creating archive of ${targetDir}...`);
295
637
  try {
296
- const metadata = await packAssets(targetDir, outputDir);
638
+ const metadata = await packAssets(
639
+ targetDir,
640
+ outputDir,
641
+ checkWorkingDirectoryStatus,
642
+ inheritableFields,
643
+ void 0
644
+ );
297
645
  if (metadata) {
298
646
  const archiveName = `${metadata.name}-${metadata.version}.tgz`;
299
647
  const archivePath = path.join(outputDir, archiveName);
@@ -318,6 +666,47 @@ const publishCommand = async (args) => {
318
666
  process.exit(1);
319
667
  }
320
668
  };
669
+ const showDumpHelp = () => {
670
+ console.log(`Usage: screw-up dump [options] [directory]
671
+
672
+ Dump computed package.json as JSON
673
+
674
+ Arguments:
675
+ directory Directory to dump package.json from (default: current directory)
676
+
677
+ Options:
678
+ --inheritable-fields <list> Comma-separated list of fields to inherit from parent
679
+ --no-wds Do not check working directory status to increase version
680
+ -h, --help Show help for dump command
681
+ `);
682
+ };
683
+ const dumpCommand = async (args) => {
684
+ if (args.options.help || args.options.h) {
685
+ showDumpHelp();
686
+ return;
687
+ }
688
+ const directory = args.positional[0];
689
+ const inheritableFieldsOption = args.options["inheritable-fields"];
690
+ const checkWorkingDirectoryStatus = args.options["no-wds"] ? false : true;
691
+ const inheritableFields = parseInheritableFields(inheritableFieldsOption);
692
+ const targetDir = path.resolve(directory != null ? directory : process.cwd());
693
+ try {
694
+ const computedPackageJson = await getComputedPackageJsonObject(
695
+ targetDir,
696
+ checkWorkingDirectoryStatus,
697
+ inheritableFields
698
+ );
699
+ if (computedPackageJson) {
700
+ console.log(JSON.stringify(computedPackageJson, null, 2));
701
+ } else {
702
+ console.error(`[screw-up/cli]: dump: Unable to read package.json from: ${targetDir}`);
703
+ process.exit(1);
704
+ }
705
+ } catch (error) {
706
+ console.error("[screw-up/cli]: dump: Failed to dump package.json:", error);
707
+ process.exit(1);
708
+ }
709
+ };
321
710
  const main = async () => {
322
711
  const args = parseArgs(process.argv);
323
712
  if (args.options.help || args.options.h || !args.command || args.command === "help" || args.command === "--help") {
@@ -331,6 +720,9 @@ const main = async () => {
331
720
  case "publish":
332
721
  await publishCommand(args);
333
722
  break;
723
+ case "dump":
724
+ await dumpCommand(args);
725
+ break;
334
726
  default:
335
727
  console.error(`Unknown command: ${args.command}`);
336
728
  console.error('Run "screw-up --help" for usage information.');
@@ -341,3 +733,4 @@ main().catch((error) => {
341
733
  console.error("CLI error:", error);
342
734
  process.exit(1);
343
735
  });
736
+ //# sourceMappingURL=cli.cjs.map