Skip to content

fix broken ref docs urls #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions auth-next/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function authStateListener() {
onAuthStateChanged(auth, (user) => {
if (user) {
// User is signed in, see docs for a list of available properties
// https://firebase.google.com/docs/reference/js/firebase.User
// https://firebase.google.com/docs/reference/js/v8/firebase.User
const uid = user.uid;
// ...
} else {
Expand All @@ -72,7 +72,7 @@ function currentUser() {

if (user) {
// User is signed in, see docs for a list of available properties
// https://firebase.google.com/docs/reference/js/firebase.User
// https://firebase.google.com/docs/reference/js/v8/firebase.User
// ...
} else {
// No user is signed in.
Expand Down
4 changes: 2 additions & 2 deletions auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function authStateListener() {
firebase.auth().onAuthStateChanged((user) => {
if (user) {
// User is signed in, see docs for a list of available properties
// https://firebase.google.com/docs/reference/js/firebase.User
// https://firebase.google.com/docs/reference/js/v8/firebase.User
var uid = user.uid;
// ...
} else {
Expand All @@ -60,7 +60,7 @@ function currentUser() {

if (user) {
// User is signed in, see docs for a list of available properties
// https://firebase.google.com/docs/reference/js/firebase.User
// https://firebase.google.com/docs/reference/js/v8/firebase.User
// ...
} else {
// No user is signed in.
Expand Down
2 changes: 1 addition & 1 deletion firestore/test.firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ describe("firestore", () => {
var docRef = db.collection("cities").doc("SF");

// Valid options for source are 'server', 'cache', or
// 'default'. See https://firebase.google.com/docs/reference/js/firebase.firestore.GetOptions
// 'default'. See https://firebase.google.com/docs/reference/js/v8/firebase.firestore.GetOptions
// for more information.
var getOptions = {
source: 'cache'
Expand Down
27 changes: 27 additions & 0 deletions scripts/separate-snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ const RE_END_SNIPPET = /\[END\s+([A-Za-z_]+)\s*\]/;
// TODO: Handle multiline imports?
const RE_REQUIRE = /const {(.+?)} = require\((.+?)\)/;

// Regex for ref docs URLs
// eg. "https://firebase.google.com/docs/reference/js/v8/firebase.User"
const RE_REF_DOCS = /https:\/\/firebase\.google\.com\/docs\/reference\/js\/(.*)/;

// Maps v8 ref docs URLs to their v9 counterpart
const REF_DOCS_MAPPINGS: { [key: string]: string } = {
"v8/firebase.User" : "auth.user"
};

type SnippetsConfig = {
enabled: boolean;
suffix: string;
Expand All @@ -30,6 +39,23 @@ function isBlank(line: string) {
return line.trim().length === 0;
}

/**
* Replace all v8 ref doc urls with their v9 counterpart.
*/
function replaceRefDocsUrls(lines: string[]) {
const outputLines = [];
for (const line of lines) {
if (line.match(RE_REF_DOCS)) {
outputLines.push(line.replace(RE_REF_DOCS, (match: string, p1?: string) => {
return p1 ? `https://firebase.google.com/docs/reference/js/${REF_DOCS_MAPPINGS[p1]}` : match;
}));
} else {
outputLines.push(line);
}
}
return outputLines;
}

/**
* Replace all const { foo } = require('bar') with import { foo } from 'bar';
*/
Expand Down Expand Up @@ -119,6 +145,7 @@ function processSnippet(
outputLines = addSuffixToSnippetNames(outputLines, snippetSuffix);
outputLines = adjustIndentation(outputLines);
outputLines = removeFirstLineAfterComments(outputLines);
outputLines = replaceRefDocsUrls(outputLines);

// Add a preamble to every snippet
const preambleLines = [
Expand Down
2 changes: 1 addition & 1 deletion snippets/auth-next/index/auth_current_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const user = auth.currentUser;

if (user) {
// User is signed in, see docs for a list of available properties
// https://firebase.google.com/docs/reference/js/firebase.User
// https://firebase.google.com/docs/reference/js/auth.user
// ...
} else {
// No user is signed in.
Expand Down
2 changes: 1 addition & 1 deletion snippets/auth-next/index/auth_state_listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const auth = getAuth();
onAuthStateChanged(auth, (user) => {
if (user) {
// User is signed in, see docs for a list of available properties
// https://firebase.google.com/docs/reference/js/firebase.User
// https://firebase.google.com/docs/reference/js/auth.user
const uid = user.uid;
// ...
} else {
Expand Down