Skip to content

Commit 2414b55

Browse files
authored
fix broken ref docs urls (#343)
* fix broken ref docs urls * update the separate-snippets script to replace ref docs urls
1 parent 1852962 commit 2414b55

File tree

6 files changed

+34
-7
lines changed

6 files changed

+34
-7
lines changed

auth-next/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function authStateListener() {
5252
onAuthStateChanged(auth, (user) => {
5353
if (user) {
5454
// User is signed in, see docs for a list of available properties
55-
// https://firebase.google.com/docs/reference/js/firebase.User
55+
// https://firebase.google.com/docs/reference/js/v8/firebase.User
5656
const uid = user.uid;
5757
// ...
5858
} else {
@@ -72,7 +72,7 @@ function currentUser() {
7272

7373
if (user) {
7474
// User is signed in, see docs for a list of available properties
75-
// https://firebase.google.com/docs/reference/js/firebase.User
75+
// https://firebase.google.com/docs/reference/js/v8/firebase.User
7676
// ...
7777
} else {
7878
// No user is signed in.

auth/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function authStateListener() {
4343
firebase.auth().onAuthStateChanged((user) => {
4444
if (user) {
4545
// User is signed in, see docs for a list of available properties
46-
// https://firebase.google.com/docs/reference/js/firebase.User
46+
// https://firebase.google.com/docs/reference/js/v8/firebase.User
4747
var uid = user.uid;
4848
// ...
4949
} else {
@@ -60,7 +60,7 @@ function currentUser() {
6060

6161
if (user) {
6262
// User is signed in, see docs for a list of available properties
63-
// https://firebase.google.com/docs/reference/js/firebase.User
63+
// https://firebase.google.com/docs/reference/js/v8/firebase.User
6464
// ...
6565
} else {
6666
// No user is signed in.

firestore/test.firestore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ describe("firestore", () => {
600600
var docRef = db.collection("cities").doc("SF");
601601

602602
// Valid options for source are 'server', 'cache', or
603-
// 'default'. See https://firebase.google.com/docs/reference/js/firebase.firestore.GetOptions
603+
// 'default'. See https://firebase.google.com/docs/reference/js/v8/firebase.firestore.GetOptions
604604
// for more information.
605605
var getOptions = {
606606
source: 'cache'

scripts/separate-snippets.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ const RE_END_SNIPPET = /\[END\s+([A-Za-z_]+)\s*\]/;
1818
// TODO: Handle multiline imports?
1919
const RE_REQUIRE = /const {(.+?)} = require\((.+?)\)/;
2020

21+
// Regex for ref docs URLs
22+
// eg. "https://firebase.google.com/docs/reference/js/v8/firebase.User"
23+
const RE_REF_DOCS = /https:\/\/firebase\.google\.com\/docs\/reference\/js\/(.*)/;
24+
25+
// Maps v8 ref docs URLs to their v9 counterpart
26+
const REF_DOCS_MAPPINGS: { [key: string]: string } = {
27+
"v8/firebase.User" : "auth.user"
28+
};
29+
2130
type SnippetsConfig = {
2231
enabled: boolean;
2332
suffix: string;
@@ -30,6 +39,23 @@ function isBlank(line: string) {
3039
return line.trim().length === 0;
3140
}
3241

42+
/**
43+
* Replace all v8 ref doc urls with their v9 counterpart.
44+
*/
45+
function replaceRefDocsUrls(lines: string[]) {
46+
const outputLines = [];
47+
for (const line of lines) {
48+
if (line.match(RE_REF_DOCS)) {
49+
outputLines.push(line.replace(RE_REF_DOCS, (match: string, p1?: string) => {
50+
return p1 ? `https://firebase.google.com/docs/reference/js/${REF_DOCS_MAPPINGS[p1]}` : match;
51+
}));
52+
} else {
53+
outputLines.push(line);
54+
}
55+
}
56+
return outputLines;
57+
}
58+
3359
/**
3460
* Replace all const { foo } = require('bar') with import { foo } from 'bar';
3561
*/
@@ -119,6 +145,7 @@ function processSnippet(
119145
outputLines = addSuffixToSnippetNames(outputLines, snippetSuffix);
120146
outputLines = adjustIndentation(outputLines);
121147
outputLines = removeFirstLineAfterComments(outputLines);
148+
outputLines = replaceRefDocsUrls(outputLines);
122149

123150
// Add a preamble to every snippet
124151
const preambleLines = [

snippets/auth-next/index/auth_current_user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const user = auth.currentUser;
1212

1313
if (user) {
1414
// User is signed in, see docs for a list of available properties
15-
// https://firebase.google.com/docs/reference/js/firebase.User
15+
// https://firebase.google.com/docs/reference/js/auth.user
1616
// ...
1717
} else {
1818
// No user is signed in.

snippets/auth-next/index/auth_state_listener.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const auth = getAuth();
1111
onAuthStateChanged(auth, (user) => {
1212
if (user) {
1313
// User is signed in, see docs for a list of available properties
14-
// https://firebase.google.com/docs/reference/js/firebase.User
14+
// https://firebase.google.com/docs/reference/js/auth.user
1515
const uid = user.uid;
1616
// ...
1717
} else {

0 commit comments

Comments
 (0)