@zharp/cli 0.2.1 → 0.3.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.js +879 -124
- package/dist/cli.js.map +1 -1
- package/dist/index.d.mts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +191 -44
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +181 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const DEFAULT_URL = "https://api.zharp.io";
|
|
2
|
-
type ArtifactKind = 'sourcemap' | 'minified-source' | 'proguard' | 'dart-symbols' | 'dart-obfuscation-map' | 'dsym';
|
|
2
|
+
type ArtifactKind = 'sourcemap' | 'minified-source' | 'proguard' | 'dart-symbols' | 'dart-obfuscation-map' | 'dsym' | 'source-bundle' | 'symbol-names';
|
|
3
3
|
interface Connection {
|
|
4
4
|
/** The Zharp API's base URL, e.g. https://api.zharp.io. */
|
|
5
5
|
url: string;
|
|
@@ -132,12 +132,23 @@ interface MachOImage {
|
|
|
132
132
|
/** The images in a Mach-O file: one for a thin file, one per slice for a universal one. */
|
|
133
133
|
declare function readMachO(data: Uint8Array): MachOImage[];
|
|
134
134
|
|
|
135
|
+
/** Runs an Xcode tool with `input` on stdin; its stdout, or null when it isn't there or fails. */
|
|
136
|
+
type XcodeTool = (tool: string, args: string[], input?: string) => string | null;
|
|
137
|
+
|
|
135
138
|
interface NativeUploadOptions {
|
|
136
139
|
release?: string;
|
|
137
140
|
dryRun?: boolean;
|
|
138
141
|
logger?: Logger;
|
|
139
142
|
fetch?: typeof fetch;
|
|
140
143
|
retries?: number;
|
|
144
|
+
/**
|
|
145
|
+
* The app's source files go with the symbols, so errors show the code of the build (default:
|
|
146
|
+
* on). `false` leaves them out; a path is the project folder to read them from (default: found
|
|
147
|
+
* from the working directory — pubspec.yaml for Flutter, the .xcodeproj or $SRCROOT for iOS).
|
|
148
|
+
*/
|
|
149
|
+
sources?: string | false;
|
|
150
|
+
/** dsym upload: how Xcode's tools are run (tests); default xcrun on a Mac, none elsewhere. */
|
|
151
|
+
xcodeTool?: XcodeTool | null;
|
|
141
152
|
}
|
|
142
153
|
/** Upload an R8/ProGuard `mapping.txt` under the build's UUID (the one the Gradle plugin put in the app). */
|
|
143
154
|
declare function uploadProguard(mappingFile: string, uuid: string, connection: Connection | null, options?: NativeUploadOptions): Promise<Artifact[]>;
|
|
@@ -244,7 +255,7 @@ declare function deleteSourcemaps(files: SourceFile[], options?: {
|
|
|
244
255
|
stripSourceMappingUrl?: boolean;
|
|
245
256
|
}): string[];
|
|
246
257
|
|
|
247
|
-
declare const VERSION = "0.
|
|
258
|
+
declare const VERSION = "0.3.0";
|
|
248
259
|
|
|
249
260
|
interface ZharpPluginOptions {
|
|
250
261
|
/** The application's ID (the number in its dashboard URL). Default `ZHARP_APP`. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const DEFAULT_URL = "https://api.zharp.io";
|
|
2
|
-
type ArtifactKind = 'sourcemap' | 'minified-source' | 'proguard' | 'dart-symbols' | 'dart-obfuscation-map' | 'dsym';
|
|
2
|
+
type ArtifactKind = 'sourcemap' | 'minified-source' | 'proguard' | 'dart-symbols' | 'dart-obfuscation-map' | 'dsym' | 'source-bundle' | 'symbol-names';
|
|
3
3
|
interface Connection {
|
|
4
4
|
/** The Zharp API's base URL, e.g. https://api.zharp.io. */
|
|
5
5
|
url: string;
|
|
@@ -132,12 +132,23 @@ interface MachOImage {
|
|
|
132
132
|
/** The images in a Mach-O file: one for a thin file, one per slice for a universal one. */
|
|
133
133
|
declare function readMachO(data: Uint8Array): MachOImage[];
|
|
134
134
|
|
|
135
|
+
/** Runs an Xcode tool with `input` on stdin; its stdout, or null when it isn't there or fails. */
|
|
136
|
+
type XcodeTool = (tool: string, args: string[], input?: string) => string | null;
|
|
137
|
+
|
|
135
138
|
interface NativeUploadOptions {
|
|
136
139
|
release?: string;
|
|
137
140
|
dryRun?: boolean;
|
|
138
141
|
logger?: Logger;
|
|
139
142
|
fetch?: typeof fetch;
|
|
140
143
|
retries?: number;
|
|
144
|
+
/**
|
|
145
|
+
* The app's source files go with the symbols, so errors show the code of the build (default:
|
|
146
|
+
* on). `false` leaves them out; a path is the project folder to read them from (default: found
|
|
147
|
+
* from the working directory — pubspec.yaml for Flutter, the .xcodeproj or $SRCROOT for iOS).
|
|
148
|
+
*/
|
|
149
|
+
sources?: string | false;
|
|
150
|
+
/** dsym upload: how Xcode's tools are run (tests); default xcrun on a Mac, none elsewhere. */
|
|
151
|
+
xcodeTool?: XcodeTool | null;
|
|
141
152
|
}
|
|
142
153
|
/** Upload an R8/ProGuard `mapping.txt` under the build's UUID (the one the Gradle plugin put in the app). */
|
|
143
154
|
declare function uploadProguard(mappingFile: string, uuid: string, connection: Connection | null, options?: NativeUploadOptions): Promise<Artifact[]>;
|
|
@@ -244,7 +255,7 @@ declare function deleteSourcemaps(files: SourceFile[], options?: {
|
|
|
244
255
|
stripSourceMappingUrl?: boolean;
|
|
245
256
|
}): string[];
|
|
246
257
|
|
|
247
|
-
declare const VERSION = "0.
|
|
258
|
+
declare const VERSION = "0.3.0";
|
|
248
259
|
|
|
249
260
|
interface ZharpPluginOptions {
|
|
250
261
|
/** The application's ID (the number in its dashboard URL). Default `ZHARP_APP`. */
|
package/dist/index.js
CHANGED
|
@@ -81,7 +81,7 @@ function resolveConnection(options) {
|
|
|
81
81
|
function artifactsUrl(connection) {
|
|
82
82
|
return `${connection.url}/api/v1/applications/${encodeURIComponent(String(connection.app))}/artifacts`;
|
|
83
83
|
}
|
|
84
|
-
var sleep = (ms) => new Promise((
|
|
84
|
+
var sleep = (ms) => new Promise((resolve5) => setTimeout(resolve5, ms));
|
|
85
85
|
async function uploadArtifact(connection, artifact, options = {}) {
|
|
86
86
|
const doFetch = options.fetch ?? fetch;
|
|
87
87
|
const retries = options.retries ?? 3;
|
|
@@ -512,8 +512,143 @@ function formatUuid(bytes) {
|
|
|
512
512
|
}
|
|
513
513
|
|
|
514
514
|
// src/native.ts
|
|
515
|
+
var import_node_fs5 = require("fs");
|
|
516
|
+
var import_node_path4 = require("path");
|
|
517
|
+
|
|
518
|
+
// src/swift-names.ts
|
|
519
|
+
var import_node_child_process = require("child_process");
|
|
515
520
|
var import_node_fs3 = require("fs");
|
|
521
|
+
var xcrun = (tool, args, input) => {
|
|
522
|
+
const result = (0, import_node_child_process.spawnSync)("xcrun", [tool, ...args], { input, encoding: "utf8", maxBuffer: 512 * 1024 * 1024 });
|
|
523
|
+
return result.status === 0 && typeof result.stdout === "string" ? result.stdout : null;
|
|
524
|
+
};
|
|
525
|
+
var SWIFT = /\$s[0-9A-Za-z_$]{3,}/g;
|
|
526
|
+
var NOT_CODE = /^(type metadata(?! accessor)|full type metadata|(nominal type|protocol|protocol conformance|associated (type|conformance)|method|property|module|extension|anonymous|reflection metadata|opaque type) descriptor|reflection metadata|protocol (requirements base|witness table)(?! accessor)|value witness table|field offset|enum case for|lazy cache variable|demangling cache variable|flag for loading|metaclass for|class metadata base offset|objc metaclass|type metadata (pattern|completion|instantiation cache)|generic (type|protocol witness table) (instantiation cache|pattern))/;
|
|
527
|
+
function mangledNamesIn(data) {
|
|
528
|
+
return new Set(data.toString("latin1").match(SWIFT) ?? []);
|
|
529
|
+
}
|
|
530
|
+
function swiftNames(files, tool = process.platform === "darwin" ? xcrun : null, read = import_node_fs3.readFileSync) {
|
|
531
|
+
if (!tool) return null;
|
|
532
|
+
const symbols = /* @__PURE__ */ new Set();
|
|
533
|
+
for (const file of new Set(files)) {
|
|
534
|
+
for (const name of mangledNamesIn(read(file))) symbols.add(name);
|
|
535
|
+
}
|
|
536
|
+
if (!symbols.size) return {};
|
|
537
|
+
const mangled = [...symbols];
|
|
538
|
+
const decoded = tool("swift-demangle", ["--simplified", "--compact"], `${mangled.join("\n")}
|
|
539
|
+
`);
|
|
540
|
+
if (decoded === null) return null;
|
|
541
|
+
const lines = decoded.split("\n");
|
|
542
|
+
const out = {};
|
|
543
|
+
mangled.forEach((name, i) => {
|
|
544
|
+
const readable = lines[i]?.trim();
|
|
545
|
+
if (readable && readable !== name && !NOT_CODE.test(readable)) out[name] = readable;
|
|
546
|
+
});
|
|
547
|
+
return out;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// src/source-bundle.ts
|
|
551
|
+
var import_node_fs4 = require("fs");
|
|
516
552
|
var import_node_path3 = require("path");
|
|
553
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
554
|
+
"node_modules",
|
|
555
|
+
".git",
|
|
556
|
+
".svn",
|
|
557
|
+
".hg",
|
|
558
|
+
"build",
|
|
559
|
+
".build",
|
|
560
|
+
".dart_tool",
|
|
561
|
+
".pub-cache",
|
|
562
|
+
".gradle",
|
|
563
|
+
".idea",
|
|
564
|
+
".vscode",
|
|
565
|
+
"test",
|
|
566
|
+
"integration_test",
|
|
567
|
+
"Pods",
|
|
568
|
+
"Carthage",
|
|
569
|
+
"DerivedData",
|
|
570
|
+
"xcuserdata",
|
|
571
|
+
".swiftpm",
|
|
572
|
+
"SourcePackages",
|
|
573
|
+
"vendor",
|
|
574
|
+
".fvm",
|
|
575
|
+
".symlinks",
|
|
576
|
+
"ephemeral"
|
|
577
|
+
]);
|
|
578
|
+
var MAX_FILE_BYTES = 1024 * 1024;
|
|
579
|
+
var MAX_TOTAL_BYTES = 50 * 1024 * 1024;
|
|
580
|
+
var MAX_FILES = 2e4;
|
|
581
|
+
function collectSources(root, extensions, skipDirs = []) {
|
|
582
|
+
const skip = /* @__PURE__ */ new Set([...SKIP_DIRS, ...skipDirs]);
|
|
583
|
+
const wanted = new Set(extensions.map((e) => e.toLowerCase()));
|
|
584
|
+
const out = { root, files: {}, count: 0, bytes: 0, skipped: 0 };
|
|
585
|
+
const visit = (dir) => {
|
|
586
|
+
let entries;
|
|
587
|
+
try {
|
|
588
|
+
entries = (0, import_node_fs4.readdirSync)(dir, { withFileTypes: true });
|
|
589
|
+
} catch {
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
593
|
+
const full = (0, import_node_path3.join)(dir, entry.name);
|
|
594
|
+
if (entry.isDirectory()) {
|
|
595
|
+
if (!skip.has(entry.name) && !/\.(xcassets|dSYM)$|Tests$/.test(entry.name)) visit(full);
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
if (!entry.isFile()) continue;
|
|
599
|
+
const dot = entry.name.lastIndexOf(".");
|
|
600
|
+
if (dot < 0 || !wanted.has(entry.name.slice(dot).toLowerCase())) continue;
|
|
601
|
+
const size = (0, import_node_fs4.statSync)(full).size;
|
|
602
|
+
if (size > MAX_FILE_BYTES || out.bytes + size > MAX_TOTAL_BYTES || out.count >= MAX_FILES) {
|
|
603
|
+
out.skipped += 1;
|
|
604
|
+
continue;
|
|
605
|
+
}
|
|
606
|
+
out.files[relativePath(root, full)] = (0, import_node_fs4.readFileSync)(full, "utf8");
|
|
607
|
+
out.count += 1;
|
|
608
|
+
out.bytes += size;
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
visit(root);
|
|
612
|
+
return out;
|
|
613
|
+
}
|
|
614
|
+
function sourceBundleArtifacts(sources, buildIds, release) {
|
|
615
|
+
if (!sources.count) return [];
|
|
616
|
+
const data = Buffer.from(JSON.stringify({ files: sources.files }), "utf8");
|
|
617
|
+
return [...new Set(buildIds)].map((debugId) => ({ kind: "source-bundle", debugId, name: "sources.json", release, data, gzip: true }));
|
|
618
|
+
}
|
|
619
|
+
function projectRoot(from, marker) {
|
|
620
|
+
let dir = (0, import_node_path3.resolve)(from);
|
|
621
|
+
for (; ; ) {
|
|
622
|
+
if (marker(dir)) return dir;
|
|
623
|
+
const parent = (0, import_node_path3.dirname)(dir);
|
|
624
|
+
if (parent === dir) return null;
|
|
625
|
+
dir = parent;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
var FLUTTER_SOURCES = [".dart"];
|
|
629
|
+
var APPLE_SOURCES = [".swift", ".m", ".mm", ".h", ".c", ".cc", ".cpp", ".hpp"];
|
|
630
|
+
var isFlutterRoot = (dir) => (0, import_node_fs4.existsSync)((0, import_node_path3.join)(dir, "pubspec.yaml"));
|
|
631
|
+
var isAppleRoot = (dir) => {
|
|
632
|
+
try {
|
|
633
|
+
return (0, import_node_fs4.existsSync)((0, import_node_path3.join)(dir, "Package.swift")) || (0, import_node_fs4.readdirSync)(dir).some((name) => name.endsWith(".xcodeproj") || name.endsWith(".xcworkspace"));
|
|
634
|
+
} catch {
|
|
635
|
+
return false;
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
// src/native.ts
|
|
640
|
+
function withSources(kind, buildIds, options, logger) {
|
|
641
|
+
if (options.sources === false || !buildIds.length) return [];
|
|
642
|
+
const root = typeof options.sources === "string" ? (0, import_node_path4.resolve)(options.sources) : kind === "apple" && process.env.SRCROOT ? process.env.SRCROOT : projectRoot(process.cwd(), kind === "flutter" ? isFlutterRoot : isAppleRoot);
|
|
643
|
+
if (!root || !(0, import_node_fs5.existsSync)(root)) {
|
|
644
|
+
logger.info(`Sources: no ${kind === "flutter" ? "Flutter project (pubspec.yaml)" : "Xcode project"} found from ${process.cwd()} \u2014 pass --sources <project folder>, or --no-sources.`);
|
|
645
|
+
return [];
|
|
646
|
+
}
|
|
647
|
+
const sources = collectSources(root, kind === "flutter" ? FLUTTER_SOURCES : APPLE_SOURCES);
|
|
648
|
+
if (!sources.count) return [];
|
|
649
|
+
logger.info(`With the app's sources: ${sources.count} file(s), ${formatBytes(sources.bytes)} from ${root}${sources.skipped ? ` (${sources.skipped} over the size caps left out)` : ""} \u2014 errors show the code of this build. --no-sources to leave them out.`);
|
|
650
|
+
return sourceBundleArtifacts(sources, buildIds, options.release);
|
|
651
|
+
}
|
|
517
652
|
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
518
653
|
async function send(connection, artifacts, options) {
|
|
519
654
|
const logger = options.logger ?? consoleLogger();
|
|
@@ -531,46 +666,46 @@ async function send(connection, artifacts, options) {
|
|
|
531
666
|
}
|
|
532
667
|
async function uploadProguard(mappingFile, uuid, connection, options = {}) {
|
|
533
668
|
if (!UUID.test(uuid)) throw new Error(`--uuid must be a UUID, got "${uuid}".`);
|
|
534
|
-
const data = (0,
|
|
535
|
-
return send(connection, [{ kind: "proguard", debugId: uuid.toLowerCase(), name: (0,
|
|
669
|
+
const data = (0, import_node_fs5.readFileSync)(mappingFile);
|
|
670
|
+
return send(connection, [{ kind: "proguard", debugId: uuid.toLowerCase(), name: (0, import_node_path4.basename)(mappingFile), release: options.release, data, gzip: true }], options);
|
|
536
671
|
}
|
|
537
672
|
var DART_ARCH = { x86_64: "x64", x86: "ia32" };
|
|
538
673
|
function findDartSymbols(path, logger = consoleLogger()) {
|
|
539
|
-
const files = (0,
|
|
674
|
+
const files = (0, import_node_fs5.statSync)(path).isDirectory() ? walk((0, import_node_path4.resolve)(path)) : [(0, import_node_path4.resolve)(path)];
|
|
540
675
|
const out = [];
|
|
541
676
|
for (const file of files) {
|
|
542
677
|
const named = /\.symbols$/.test(file);
|
|
543
|
-
const data = (0,
|
|
678
|
+
const data = (0, import_node_fs5.readFileSync)(file);
|
|
544
679
|
if (!isElf(data)) {
|
|
545
|
-
if (named) logger.warn(`Skipped ${(0,
|
|
680
|
+
if (named) logger.warn(`Skipped ${(0, import_node_path4.basename)(file)}: not an ELF file.`);
|
|
546
681
|
continue;
|
|
547
682
|
}
|
|
548
683
|
const elf = readElf(data);
|
|
549
684
|
if (!elf.buildId) {
|
|
550
|
-
logger.warn(`Skipped ${(0,
|
|
685
|
+
logger.warn(`Skipped ${(0, import_node_path4.basename)(file)}: it has no GNU build ID.`);
|
|
551
686
|
continue;
|
|
552
687
|
}
|
|
553
|
-
const match = /\.([a-z]+)-([a-z0-9_]+)\.symbols$/.exec((0,
|
|
688
|
+
const match = /\.([a-z]+)-([a-z0-9_]+)\.symbols$/.exec((0, import_node_path4.basename)(file));
|
|
554
689
|
out.push({ path: file, buildId: elf.buildId, os: match?.[1], arch: match?.[2] ?? (elf.arch && (DART_ARCH[elf.arch] ?? elf.arch)) });
|
|
555
690
|
}
|
|
556
691
|
return out;
|
|
557
692
|
}
|
|
558
693
|
function findObfuscationMap(symbolsPath) {
|
|
559
|
-
const dir = (0,
|
|
560
|
-
for (const where of [dir, (0,
|
|
694
|
+
const dir = (0, import_node_fs5.statSync)(symbolsPath).isDirectory() ? (0, import_node_path4.resolve)(symbolsPath) : (0, import_node_path4.dirname)((0, import_node_path4.resolve)(symbolsPath));
|
|
695
|
+
for (const where of [dir, (0, import_node_path4.dirname)(dir)]) {
|
|
561
696
|
let names;
|
|
562
697
|
try {
|
|
563
|
-
names = (0,
|
|
698
|
+
names = (0, import_node_fs5.readdirSync)(where).sort();
|
|
564
699
|
} catch {
|
|
565
700
|
continue;
|
|
566
701
|
}
|
|
567
702
|
const found = names.find((n) => n === "obfuscation.json") ?? names.find((n) => n.endsWith(".obfuscation.json"));
|
|
568
|
-
if (found && (0,
|
|
703
|
+
if (found && (0, import_node_fs5.statSync)((0, import_node_path4.join)(where, found)).isFile()) return (0, import_node_path4.join)(where, found);
|
|
569
704
|
}
|
|
570
705
|
return void 0;
|
|
571
706
|
}
|
|
572
707
|
function readObfuscationMap(file) {
|
|
573
|
-
const data = (0,
|
|
708
|
+
const data = (0, import_node_fs5.readFileSync)(file);
|
|
574
709
|
let parsed;
|
|
575
710
|
try {
|
|
576
711
|
parsed = JSON.parse(data.toString("utf8"));
|
|
@@ -588,32 +723,33 @@ async function uploadDartSymbols(path, connection, options = {}) {
|
|
|
588
723
|
const artifacts = files.map((f) => ({
|
|
589
724
|
kind: "dart-symbols",
|
|
590
725
|
debugId: f.buildId,
|
|
591
|
-
name: (0,
|
|
726
|
+
name: (0, import_node_path4.basename)(f.path),
|
|
592
727
|
arch: f.arch,
|
|
593
728
|
release: options.release,
|
|
594
|
-
data: (0,
|
|
729
|
+
data: (0, import_node_fs5.readFileSync)(f.path),
|
|
595
730
|
gzip: true
|
|
596
731
|
}));
|
|
597
|
-
if (options.obfuscationMap && !(0,
|
|
732
|
+
if (options.obfuscationMap && !(0, import_node_fs5.existsSync)(options.obfuscationMap)) throw new Error(`${options.obfuscationMap} does not exist.`);
|
|
598
733
|
const mapFile = options.obfuscationMap ?? findObfuscationMap(path);
|
|
599
734
|
if (mapFile) {
|
|
600
735
|
const data = readObfuscationMap(mapFile);
|
|
601
736
|
const buildIds = [...new Set(files.map((f) => f.buildId))];
|
|
602
|
-
logger.info(`With obfuscation map ${(0,
|
|
737
|
+
logger.info(`With obfuscation map ${(0, import_node_path4.basename)(mapFile)} for ${buildIds.length} build ID(s)`);
|
|
603
738
|
for (const debugId of buildIds) {
|
|
604
|
-
artifacts.push({ kind: "dart-obfuscation-map", debugId, name: (0,
|
|
739
|
+
artifacts.push({ kind: "dart-obfuscation-map", debugId, name: (0, import_node_path4.basename)(mapFile), release: options.release, data, gzip: true });
|
|
605
740
|
}
|
|
606
741
|
} else {
|
|
607
742
|
logger.info("No obfuscation map found (build with --extra-gen-snapshot-options=--save-obfuscation-map=build/obfuscation.json, or pass --obfuscation-map): obfuscated names in error messages stay as they are.");
|
|
608
743
|
}
|
|
744
|
+
artifacts.push(...withSources("flutter", [...new Set(files.map((f) => f.buildId))], options, logger));
|
|
609
745
|
return send(connection, artifacts, options);
|
|
610
746
|
}
|
|
611
747
|
function findDsymImages(path) {
|
|
612
|
-
const root = (0,
|
|
613
|
-
const candidates = (0,
|
|
748
|
+
const root = (0, import_node_path4.resolve)(path);
|
|
749
|
+
const candidates = (0, import_node_fs5.statSync)(root).isDirectory() ? walk(root).filter((f) => /[\\/]Contents[\\/]Resources[\\/]DWARF[\\/][^\\/]+$/.test(f)) : [root];
|
|
614
750
|
const out = [];
|
|
615
751
|
for (const file of candidates) {
|
|
616
|
-
const data = (0,
|
|
752
|
+
const data = (0, import_node_fs5.readFileSync)(file);
|
|
617
753
|
if (!isMachO(data)) continue;
|
|
618
754
|
for (const image of readMachO(data)) out.push({ path: file, ...image });
|
|
619
755
|
}
|
|
@@ -627,11 +763,11 @@ async function uploadDsyms(path, connection, options = {}) {
|
|
|
627
763
|
const cache = /* @__PURE__ */ new Map();
|
|
628
764
|
const artifacts = images.map((image) => {
|
|
629
765
|
let data = cache.get(image.path);
|
|
630
|
-
if (!data) cache.set(image.path, data = (0,
|
|
766
|
+
if (!data) cache.set(image.path, data = (0, import_node_fs5.readFileSync)(image.path));
|
|
631
767
|
return {
|
|
632
768
|
kind: "dsym",
|
|
633
769
|
debugId: image.uuid,
|
|
634
|
-
name: (0,
|
|
770
|
+
name: (0, import_node_path4.basename)(image.path),
|
|
635
771
|
arch: image.arch,
|
|
636
772
|
release: options.release,
|
|
637
773
|
// One architecture's slice of a universal file is a complete Mach-O file on its own.
|
|
@@ -639,17 +775,28 @@ async function uploadDsyms(path, connection, options = {}) {
|
|
|
639
775
|
gzip: true
|
|
640
776
|
};
|
|
641
777
|
});
|
|
778
|
+
const names = swiftNames(images.map((image) => image.path), options.xcodeTool === void 0 ? void 0 : options.xcodeTool);
|
|
779
|
+
if (names && Object.keys(names).length) {
|
|
780
|
+
const data = Buffer.from(JSON.stringify({ names }), "utf8");
|
|
781
|
+
logger.info(`With readable names for ${Object.keys(names).length} Swift symbol(s)`);
|
|
782
|
+
for (const uuid of new Set(images.map((image) => image.uuid))) {
|
|
783
|
+
artifacts.push({ kind: "symbol-names", debugId: uuid, name: "swift-names.json", release: options.release, data, gzip: true });
|
|
784
|
+
}
|
|
785
|
+
} else if (names === null) {
|
|
786
|
+
logger.info("Swift names stay mangled: run the upload on a Mac with Xcode (xcrun swift-demangle) to send readable ones.");
|
|
787
|
+
}
|
|
788
|
+
artifacts.push(...withSources("apple", [...new Set(images.map((image) => image.uuid))], options, logger));
|
|
642
789
|
return send(connection, artifacts, options);
|
|
643
790
|
}
|
|
644
791
|
|
|
645
792
|
// src/sourcemaps.ts
|
|
646
|
-
var
|
|
647
|
-
var
|
|
793
|
+
var import_node_fs6 = require("fs");
|
|
794
|
+
var import_node_path5 = require("path");
|
|
648
795
|
var JS_FILE = /\.(?:js|mjs|cjs)$/;
|
|
649
796
|
function mapFor(file, code) {
|
|
650
797
|
const sibling = `${file}.map`;
|
|
651
|
-
if ((0,
|
|
652
|
-
const url = sourceMappingUrl(code ?? (0,
|
|
798
|
+
if ((0, import_node_fs6.existsSync)(sibling)) return sibling;
|
|
799
|
+
const url = sourceMappingUrl(code ?? (0, import_node_fs6.readFileSync)(file, "utf8"));
|
|
653
800
|
if (!url || /^[a-z][a-z0-9+.-]*:/i.test(url)) return void 0;
|
|
654
801
|
let path;
|
|
655
802
|
try {
|
|
@@ -657,16 +804,16 @@ function mapFor(file, code) {
|
|
|
657
804
|
} catch {
|
|
658
805
|
return void 0;
|
|
659
806
|
}
|
|
660
|
-
const full = (0,
|
|
661
|
-
return (0,
|
|
807
|
+
const full = (0, import_node_path5.isAbsolute)(path) ? path : (0, import_node_path5.resolve)((0, import_node_path5.dirname)(file), path);
|
|
808
|
+
return (0, import_node_fs6.existsSync)(full) ? full : void 0;
|
|
662
809
|
}
|
|
663
810
|
function findSourceFiles(dir, options = {}) {
|
|
664
|
-
const root = (0,
|
|
811
|
+
const root = (0, import_node_path5.resolve)(dir);
|
|
665
812
|
const keep = pathFilter(options.include, options.exclude);
|
|
666
|
-
const candidates = options.files ? options.files.map((f) => (0,
|
|
813
|
+
const candidates = options.files ? options.files.map((f) => (0, import_node_path5.resolve)(f)) : walk(root);
|
|
667
814
|
const out = [];
|
|
668
815
|
for (const file of candidates) {
|
|
669
|
-
if (!JS_FILE.test(file) || !(0,
|
|
816
|
+
if (!JS_FILE.test(file) || !(0, import_node_fs6.existsSync)(file)) continue;
|
|
670
817
|
const name = relativePath(root, file);
|
|
671
818
|
if (!keep(name)) continue;
|
|
672
819
|
const map = mapFor(file);
|
|
@@ -680,18 +827,18 @@ function injectDirectory(dir, options = {}) {
|
|
|
680
827
|
const out = [];
|
|
681
828
|
const noSourcesContent = [];
|
|
682
829
|
for (const source of files) {
|
|
683
|
-
const code = (0,
|
|
830
|
+
const code = (0, import_node_fs6.readFileSync)(source.file, "utf8");
|
|
684
831
|
const injected = injectCode(code, { stripSourceMappingUrl: options.stripSourceMappingUrl });
|
|
685
832
|
let map;
|
|
686
833
|
try {
|
|
687
|
-
map = injectMap((0,
|
|
834
|
+
map = injectMap((0, import_node_fs6.readFileSync)(source.map, "utf8"), injected.debugId, source.map);
|
|
688
835
|
} catch (error) {
|
|
689
836
|
logger.warn(`Skipped ${source.name}: ${source.mapName} is not a readable source map (${error.message}).`);
|
|
690
837
|
continue;
|
|
691
838
|
}
|
|
692
839
|
if (!options.dryRun) {
|
|
693
|
-
if (injected.changed) (0,
|
|
694
|
-
if (map.changed) (0,
|
|
840
|
+
if (injected.changed) (0, import_node_fs6.writeFileSync)(source.file, injected.code);
|
|
841
|
+
if (map.changed) (0, import_node_fs6.writeFileSync)(source.map, map.text);
|
|
695
842
|
}
|
|
696
843
|
if (!map.hasSourcesContent) noSourcesContent.push(source.mapName);
|
|
697
844
|
const changed = injected.changed || map.changed;
|
|
@@ -712,13 +859,13 @@ async function uploadSourcemaps(dir, connection, options = {}) {
|
|
|
712
859
|
const result = { files: 0, artifacts: 0, bytes: 0, deleted: [], skipped: [] };
|
|
713
860
|
const work = [];
|
|
714
861
|
for (const source of files) {
|
|
715
|
-
const code = (0,
|
|
862
|
+
const code = (0, import_node_fs6.readFileSync)(source.file);
|
|
716
863
|
const debugId = existingDebugId(code.toString("utf8"));
|
|
717
864
|
if (!debugId) {
|
|
718
865
|
result.skipped.push(source.name);
|
|
719
866
|
continue;
|
|
720
867
|
}
|
|
721
|
-
work.push({ source, debugId, code, map: (0,
|
|
868
|
+
work.push({ source, debugId, code, map: (0, import_node_fs6.readFileSync)(source.map) });
|
|
722
869
|
}
|
|
723
870
|
if (result.skipped.length) {
|
|
724
871
|
logger.warn(`${result.skipped.length} file(s) have a source map but no debug ID \u2014 run \`zharp sourcemaps inject\` first: ${result.skipped.slice(0, 3).join(", ")}${result.skipped.length > 3 ? ", \u2026" : ""}`);
|
|
@@ -755,13 +902,13 @@ async function uploadSourcemaps(dir, connection, options = {}) {
|
|
|
755
902
|
function deleteSourcemaps(files, options = {}) {
|
|
756
903
|
const deleted = [];
|
|
757
904
|
for (const source of files) {
|
|
758
|
-
if (options.stripSourceMappingUrl && (0,
|
|
759
|
-
const code = (0,
|
|
905
|
+
if (options.stripSourceMappingUrl && (0, import_node_fs6.existsSync)(source.file)) {
|
|
906
|
+
const code = (0, import_node_fs6.readFileSync)(source.file, "utf8");
|
|
760
907
|
const stripped = withoutSourceMappingUrl(code);
|
|
761
|
-
if (stripped !== code) (0,
|
|
908
|
+
if (stripped !== code) (0, import_node_fs6.writeFileSync)(source.file, stripped);
|
|
762
909
|
}
|
|
763
|
-
if ((0,
|
|
764
|
-
(0,
|
|
910
|
+
if ((0, import_node_fs6.existsSync)(source.map)) {
|
|
911
|
+
(0, import_node_fs6.unlinkSync)(source.map);
|
|
765
912
|
deleted.push(source.mapName);
|
|
766
913
|
}
|
|
767
914
|
}
|
|
@@ -769,7 +916,7 @@ function deleteSourcemaps(files, options = {}) {
|
|
|
769
916
|
}
|
|
770
917
|
|
|
771
918
|
// src/version.ts
|
|
772
|
-
var VERSION = "0.
|
|
919
|
+
var VERSION = "0.3.0";
|
|
773
920
|
|
|
774
921
|
// src/build.ts
|
|
775
922
|
function defaultRelease(options) {
|