Skip to content

Commit 925ced3

Browse files
committed
lint
1 parent 73447d9 commit 925ced3

File tree

2 files changed

+52
-33
lines changed

2 files changed

+52
-33
lines changed

src/commands/crashlytics-sourcemap-upload.spec.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ describe("crashlytics:sourcemap:upload", () => {
4242
});
4343

4444
it("should throw an error if no app ID is provided", async () => {
45-
await expect(command.runner()('filename', {})).to.be.rejectedWith(
45+
await expect(command.runner()("filename", {})).to.be.rejectedWith(
4646
FirebaseError,
47-
"set --app <appId> to a valid Firebase application id"
47+
"set --app <appId> to a valid Firebase application id",
4848
);
4949
});
5050

@@ -64,31 +64,33 @@ describe("crashlytics:sourcemap:upload", () => {
6464
await command.runner()(FILE_PATH, options);
6565
expect(gcsMock.upsertBucket).to.be.calledOnce;
6666
const args = gcsMock.upsertBucket.firstCall.args;
67-
expect(args[0].req.baseName).to.equal("firebasecrashlytics-sourcemaps-12345-a-different-location");
67+
expect(args[0].req.baseName).to.equal(
68+
"firebasecrashlytics-sourcemaps-12345-a-different-location",
69+
);
6870
expect(args[0].req.location).to.equal("A-DIFFERENT-LOCATION");
6971
});
7072

7173
it("should throw an error if the mapping file path is invalid", async () => {
72-
expect(
73-
command.runner()("invalid/path", { app: "test-app" })
74-
).to.be.rejectedWith(FirebaseError, "provide a valid file path or directory");
74+
expect(command.runner()("invalid/path", { app: "test-app" })).to.be.rejectedWith(
75+
FirebaseError,
76+
"provide a valid file path or directory",
77+
);
7578
});
7679

7780
it("should upload a single mapping file", async () => {
7881
await command.runner()(FILE_PATH, { app: "test-app" });
7982
expect(gcsMock.uploadObject).to.be.calledOnce;
80-
expect(gcsMock.uploadObject).to.be.calledWith(
81-
sinon.match.any,
82-
BUCKET_NAME,
83+
expect(gcsMock.uploadObject).to.be.calledWith(sinon.match.any, BUCKET_NAME);
84+
expect(gcsMock.uploadObject.firstCall.args[0].file).to.match(
85+
/test-app-default-mockdata-mock_mapping\.js\.map\.zip/,
8386
);
84-
expect(gcsMock.uploadObject.firstCall.args[0].file)
85-
.to.match(/test-app-default-mockdata-mock_mapping\.js\.map\.zip/);
8687
});
8788

8889
it("should find and upload mapping files in a directory", async () => {
8990
await command.runner()(DIR_PATH, { app: "test-app" });
9091
expect(gcsMock.uploadObject).to.be.calledOnce;
91-
expect(gcsMock.uploadObject.firstCall.args[0].file)
92-
.to.match(/test-app-default-mockdata-mock_mapping\.js\.map\.zip/);
92+
expect(gcsMock.uploadObject.firstCall.args[0].file).to.match(
93+
/test-app-default-mockdata-mock_mapping\.js\.map\.zip/,
94+
);
9395
});
9496
});

src/commands/crashlytics-sourcemap-upload.ts

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ interface CommandOptions extends Options {
2121
export const command = new Command("crashlytics:sourcemap:upload <mappingFiles>")
2222
.description("upload javascript source maps to de-minify stack traces")
2323
.option("--app <appID>", "the app id of your Firebase app")
24-
.option("--bucket-location <bucketLocation>", "the location of the Google Cloud Storage bucket (default: \"US-CENTRAL1\"")
25-
.option("--app-version <appVersion>", "the version of your Firebase app (defaults to Git commit hash, if available)")
24+
.option(
25+
"--bucket-location <bucketLocation>",
26+
'the location of the Google Cloud Storage bucket (default: "US-CENTRAL1"',
27+
)
28+
.option(
29+
"--app-version <appVersion>",
30+
"the version of your Firebase app (defaults to Git commit hash, if available)",
31+
)
2632
.action(async (mappingFiles: string, options: CommandOptions) => {
27-
const app = getGoogleAppID(options);
28-
const debug = !!options.debug;
33+
checkGoogleAppID(options);
2934

3035
// App version
31-
const appVersion = getAppVersion(options);
36+
const appVersion = getAppVersion();
3237

3338
// Get project identifiers
3439
const projectId = needProjectId(options);
@@ -42,7 +47,7 @@ export const command = new Command("crashlytics:sourcemap:upload <mappingFiles>"
4247
const filePath = path.relative(rootDir, mappingFiles);
4348
let fstat: fs.Stats;
4449
try {
45-
fstat = statSync(filePath)
50+
fstat = statSync(filePath);
4651
} catch (e) {
4752
throw new FirebaseError(
4853
"provide a valid file path or directory to mapping file(s), e.g. app/build/outputs/app.js.map or app/build/outputs",
@@ -52,10 +57,11 @@ export const command = new Command("crashlytics:sourcemap:upload <mappingFiles>"
5257
await uploadMap(mappingFiles, bucketName, appVersion, options);
5358
} else if (fstat.isDirectory()) {
5459
logLabeledBullet("crashlytics", "Looking for mapping files in your directory...");
55-
const files = (await readdirRecursive({ path: filePath, ignore: ["node_modules", ".git"] }))
56-
.filter(f => f.name.endsWith('.js.map'));
60+
const files = (
61+
await readdirRecursive({ path: filePath, ignore: ["node_modules", ".git"] })
62+
).filter((f) => f.name.endsWith(".js.map"));
5763
for (const file of files) {
58-
await uploadMap(file.name, bucketName, appVersion, options);
64+
await uploadMap(file.name, bucketName, appVersion, options);
5965
}
6066
} else {
6167
throw new FirebaseError(
@@ -66,26 +72,32 @@ export const command = new Command("crashlytics:sourcemap:upload <mappingFiles>"
6672
// TODO: notify Firebase Telemetry service of the new mapping file
6773
});
6874

69-
function getGoogleAppID(options: CommandOptions): string {
75+
function checkGoogleAppID(options: CommandOptions): void {
7076
if (!options.app) {
7177
throw new FirebaseError(
7278
"set --app <appId> to a valid Firebase application id, e.g. 1:00000000:android:0000000",
7379
);
7480
}
75-
return options.app;
7681
}
7782

78-
function getAppVersion(options: CommandOptions): string {
83+
function getAppVersion(): string {
7984
// TODO: implement app version lookup
8085
return "default";
8186
}
8287

83-
async function upsertBucket(projectId: string, projectNumber: string, options: CommandOptions): Promise<string> {
84-
let loc: string = 'US-CENTRAL1';
88+
async function upsertBucket(
89+
projectId: string,
90+
projectNumber: string,
91+
options: CommandOptions,
92+
): Promise<string> {
93+
let loc: string = "US-CENTRAL1";
8594
if (options.bucketLocation) {
8695
loc = (options.bucketLocation as string).toUpperCase();
8796
} else {
88-
logLabeledBullet("crashlytics", "No Google Cloud Storage bucket location specified. Defaulting to US-CENTRAL1.");
97+
logLabeledBullet(
98+
"crashlytics",
99+
"No Google Cloud Storage bucket location specified. Defaulting to US-CENTRAL1.",
100+
);
89101
}
90102

91103
const baseName = `firebasecrashlytics-sourcemaps-${projectNumber}-${loc.toLowerCase()}`;
@@ -113,11 +125,16 @@ async function upsertBucket(projectId: string, projectNumber: string, options: C
113125
});
114126
}
115127

116-
async function uploadMap(mappingFile: string, bucketName: string, appVersion: string, options: CommandOptions) {
128+
async function uploadMap(
129+
mappingFile: string,
130+
bucketName: string,
131+
appVersion: string,
132+
options: CommandOptions,
133+
) {
117134
logLabeledBullet("crashlytics", `Found mapping file ${mappingFile}...`);
118135
try {
119136
const tmpArchive = await createArchive(mappingFile, options);
120-
const gcsFile = `${options.app}-${appVersion}-${normalizeFileName(mappingFile)}.zip`
137+
const gcsFile = `${options.app}-${appVersion}-${normalizeFileName(mappingFile)}.zip`;
121138

122139
const { bucket, object } = await gcs.uploadObject(
123140
{
@@ -142,7 +159,7 @@ async function createArchive(mappingFile: string, options: CommandOptions): Prom
142159
const archive = archiver("zip");
143160
const rootDir = options.projectRoot ?? process.cwd();
144161
const name = path.relative(rootDir, mappingFile);
145-
archive.file(name, {name: 'mapping.js.map'});
162+
archive.file(name, { name: "mapping.js.map" });
146163
await pipeAsync(archive, fileStream);
147164
return tmpFile;
148165
}
@@ -157,5 +174,5 @@ async function pipeAsync(from: archiver.Archiver, to: fs.WriteStream): Promise<v
157174
}
158175

159176
function normalizeFileName(fileName: string): string {
160-
return fileName.replaceAll(/\//g, '-');
161-
}
177+
return fileName.replaceAll(/\//g, "-");
178+
}

0 commit comments

Comments
 (0)