Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
globals: {
__PATH_PREFIX__: true,
browser: true,
Expand Down
4 changes: 2 additions & 2 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { CLIEngine } = require('eslint');
import CLIEngine from 'eslint';

// lint-staged seems to disregard eslint ignore rules if we have the eslint
// "--max-warnings 0" option set. This will potentially break our linting process
Expand All @@ -7,7 +7,7 @@ const { CLIEngine } = require('eslint');
// This was the recommended fix according to lint-staged's README:
// https://github.com/okonet/lint-staged/blob/fa15d686deb90b7ffddfbcf644d56ed05fcd8a38/README.md#how-can-i-ignore-files-from-eslintignore

module.exports = {
export default {
'*.js': (files) => {
const cli = new CLIEngine({});
const filesToLint = files.filter((file) => !cli.isPathIgnored(file)).join(' ');
Expand Down
4 changes: 2 additions & 2 deletions __mocks__/gatsby.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const React = require('react');
import React from 'react';

const gatsby = jest.requireActual('gatsby');

module.exports = {
export default {
...gatsby,
graphql: jest.fn(),
navigate: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion __mocks__/redoc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Mock redoc library by default to avoid nested import error in RedocStandalone component
// import * as YAML from './dist/index.js'
module.exports = {
export default {
RedocStandalone: jest.fn(),
};
18 changes: 10 additions & 8 deletions gatsby-config.js → gatsby-config.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
const { generatePathPrefix } = require('./src/utils/generate-path-prefix');
const { siteMetadata } = require('./src/utils/site-metadata');
const { isGatsbyPreview } = require('./src/utils/is-gatsby-preview');
import { createRequire } from 'module';
import generatePathPrefix from './src/utils/generate-path-prefix.js';
import { siteMetadata } from './src/utils/site-metadata.mjs';
import isGatsbyPreview from './src/utils/is-gatsby-preview.js';
// const { generatePathPrefix } = require('./src/utils/generate-path-prefix');
// const { siteMetadata } = require('./src/utils/site-metadata');
// const { isGatsbyPreview } = require('./src/utils/is-gatsby-preview');

const isPreview = isGatsbyPreview();
const pathPrefix = !isPreview ? generatePathPrefix(siteMetadata) : undefined;

const require = createRequire(import.meta.url);

console.log('PATH PREFIX', pathPrefix);

// Specifies which plugins to use depending on build environment
Expand Down Expand Up @@ -32,8 +38,4 @@ if (!isPreview) {
});
}

module.exports = {
plugins,
pathPrefix,
siteMetadata,
};
export { plugins, pathPrefix, siteMetadata };
4 changes: 3 additions & 1 deletion jest-preprocess.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createTransformer } from 'babel-jest';

const babelOptions = {
presets: ['babel-preset-gatsby', '@emotion/babel-preset-css-prop'],
plugins: ['@emotion'],
};

module.exports = require('babel-jest').createTransformer(babelOptions);
export default createTransformer(babelOptions);
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
globals: {
__PATH_PREFIX__: ``,
},
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "snooty",
"type": "module",
"version": "0.15.1",
"repository": "github:mongodb/snooty",
"engines": {
Expand Down Expand Up @@ -102,7 +103,7 @@
"clipboard": "^2.0.8",
"dotenv": "^8.2.0",
"eventsource": "^2.0.2",
"gatsby": "^5.0.0",
"gatsby": "^5.3.0",
"gatsby-plugin-emotion": "^8.0.0",
"gatsby-plugin-google-tagmanager": "^5.0.0",
"gatsby-plugin-layout": "^4.7.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
const { getDataStore } = require('gatsby/dist/datastore');
const path = require('path');
const stream = require('stream');
const { promisify } = require('util');
import getDataStore from 'gatsby/dist/datastore';
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
import { createRequire } from "module"
import stream from 'stream';
import promisify from 'util';
import got from `got`;
import parser from `stream-json/jsonl/Parser`;
import { sourceNodes } from `./other-things-to-source.mjs`;
import fetchClientAccessToken from './utils/kanopy-auth.mjs';
import callPostBuildWebhook from './utils/post-build.mjs';
import { consumeData, createSnootyMetadataId, KEY_LAST_FETCHED, KEY_LAST_CLIENT_ACCESS_TOKEN, } from './utils/data-consumer.mjs';

const pipeline = promisify(stream.pipeline);
const got = require(`got`);
const { parser } = require(`stream-json/jsonl/Parser`);
const { sourceNodes } = require(`./other-things-to-source`);
const { fetchClientAccessToken } = require('./utils/kanopy-auth.js');
const { callPostBuildWebhook } = require('./utils/post-build.js');
const {
consumeData,
createSnootyMetadataId,
KEY_LAST_FETCHED,
KEY_LAST_CLIENT_ACCESS_TOKEN,
} = require('./utils/data-consumer.js');

// Global variable to allow webhookBody from sourceNodes step to be passed down
// to other Gatsby build steps that might not pass webhookBody natively.
let currentWebhookBody = {};

exports.createSchemaCustomization = async ({ actions }) => {
export const createSchemaCustomization = async ({ actions }) => {
const { createTypes } = actions;
const typeDefs = `
type Page implements Node @dontInfer {
Expand Down Expand Up @@ -58,7 +56,7 @@ const APIBase = process.env.API_BASE || `https://snooty-data-api.mongodb.com`;
const GATSBY_CLOUD_SITE_USER = process.env.GATSBY_CLOUD_SITE_USER;

let isFirstRun = true;
exports.sourceNodes = async ({
export const sourceNodes = async ({
actions,
createNodeId,
getNode,
Expand Down Expand Up @@ -166,15 +164,19 @@ exports.sourceNodes = async ({
isFirstRun = false;
};



// Prevent errors when running gatsby build caused by browser packages run in a node environment.
exports.onCreateWebpackConfig = ({ plugins, actions }) => {
export const onCreateWebpackConfig = ({ plugins, actions }) => {
const require = createRequire(import.meta.url);
const base = import.meta.url;
const providePlugins = {
Buffer: ['buffer', 'Buffer'],
process: require.resolve('../../stubs/process.js'),
};

const fallbacks = { stream: require.resolve('stream-browserify'), buffer: require.resolve('buffer/') };

const fallbacks = { stream: require.resolve('stream-browserify'), buffer: require.resolve('buffer/')};
console.log("FALLBACKS", fallbacks)
actions.setWebpackConfig({
plugins: [plugins.provide(providePlugins)],
resolve: {
Expand All @@ -186,8 +188,9 @@ exports.onCreateWebpackConfig = ({ plugins, actions }) => {
});
};

exports.createPages = async ({ actions, createNodeId, getNode, graphql, reporter }) => {
export const createPages = async ({ actions, createNodeId, getNode, graphql, reporter }) => {
const { createPage } = actions;
const __dirname = dirname(fileURLToPath(import.meta.url));
const templatePath = path.join(__dirname, `../../src/components/DocumentBodyPreview.js`);
const result = await graphql(`
query {
Expand Down Expand Up @@ -252,6 +255,6 @@ exports.createPages = async ({ actions, createNodeId, getNode, graphql, reporter
// Ideally, we would use Gatsby Cloud's Outgoing Notifications feature once it can
// support passing through custom data from the preview webhook's body (to include the
// Autobuilder job ID associated with the GC build).
exports.onPostBuild = async () => {
export const onPostBuild = async () => {
await callPostBuildWebhook(currentWebhookBody, 'completed');
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { siteMetadata } = require('../../src/utils/site-metadata');
const { realmDocumentDatabase } = require('../../src/init/DocumentDatabase.js');
const { createOpenAPIChangelogNode } = require('../utils/openapi');
const { createProductNodes } = require('../utils/products');
import { siteMetadata } from '../../src/utils/site-metadata.mjs';
import { realmDocumentDatabase } from '../../src/init/DocumentDatabase.mjs';
import createOpenAPIChangelogNode from '../utils/openapi.mjs';
import createProductNodes from '../utils/products.mjs';

// Sources nodes for the preview plugin that are not directly related to data
// from the Snooty Data API
exports.sourceNodes = async ({ hasOpenAPIChangelog, createNode, createContentDigest, createNodeId }) => {
export const sourceNodes = async ({ hasOpenAPIChangelog, createNode, createContentDigest, createNodeId }) => {
let db = realmDocumentDatabase;
await db.connect();
await createProductNodes({ db, createNode, createNodeId, createContentDigest });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { transformBreadcrumbs } = require('../../../src/utils/setup/transform-breadcrumbs.js');
const { saveStaticFiles, saveFile } = require('../../../src/utils/setup/save-asset-files');
const { getNestedValue } = require('../../../src/utils/get-nested-value');
import transformBreadcrumbs from '../../../src/utils/setup/transform-breadcrumbs.mjs';
import { saveStaticFiles, saveFile } from '../../../src/utils/setup/save-asset-files.mjs';
import getNestedValue from '../../../src/utils/get-nested-value.mjs';

const KEY_LAST_FETCHED = 'lastFetched';
const KEY_LAST_CLIENT_ACCESS_TOKEN = 'lastClientAccessToken';
Expand Down Expand Up @@ -177,4 +177,4 @@ const consumeData = async (
}
};

module.exports = { consumeData, createSnootyMetadataId, KEY_LAST_FETCHED, KEY_LAST_CLIENT_ACCESS_TOKEN };
export { consumeData, createSnootyMetadataId, KEY_LAST_FETCHED, KEY_LAST_CLIENT_ACCESS_TOKEN };
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ const fetchClientAccessToken = async (prevToken) => {
return prevToken;
};

module.exports = { fetchClientAccessToken };
export default fetchClientAccessToken;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const crypto = require('crypto');
import crypto from 'crypto';

/**
* Constructs a signature using the payload and Snooty's secret. The signature
Expand Down Expand Up @@ -52,4 +52,4 @@ const callPostBuildWebhook = async (webhookBody, status) => {
console.log('Post-build webhook was successfully called!');
};

module.exports = { callPostBuildWebhook };
export default callPostBuildWebhook;
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const path = require('path');
const { transformBreadcrumbs } = require('../../src/utils/setup/transform-breadcrumbs.js');
const { saveAssetFiles, saveStaticFiles } = require('../../src/utils/setup/save-asset-files');
const { validateEnvVariables } = require('../../src/utils/setup/validate-env-variables');
const { getNestedValue } = require('../../src/utils/get-nested-value');
const { removeNestedValue } = require('../../src/utils/remove-nested-value.js');
const { getPageSlug } = require('../../src/utils/get-page-slug');
const { manifestMetadata, siteMetadata } = require('../../src/utils/site-metadata');
const { assertTrailingSlash } = require('../../src/utils/assert-trailing-slash');
const { constructPageIdPrefix } = require('../../src/utils/setup/construct-page-id-prefix');
const { manifestDocumentDatabase, realmDocumentDatabase } = require('../../src/init/DocumentDatabase.js');
const { createOpenAPIChangelogNode } = require('../utils/openapi.js');
const { createProductNodes } = require('../utils/products.js');
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
import { createRequire } from 'module';
import transformBreadcrumbs from '../../src/utils/setup/transform-breadcrumbs.mjs';
import { saveAssetFiles, saveStaticFiles } from '../../src/utils/setup/save-asset-files.mjs';
import validateEnvVariables from '../../src/utils/setup/validate-env-variables.mjs';
import getNestedValue from '../../src/utils/get-nested-value.mjs';
import removeNestedValue from '../../src/utils/remove-nested-value.mjs';
import getPageSlug from '../../src/utils/get-page-slug.mjs';
import { manifestMetadata, siteMetadata } from '../../src/utils/site-metadata.mjs';
import assertTrailingSlash from '../../src/utils/assert-trailing-slash.mjs';
import constructPageIdPrefix from '../../src/utils/setup/construct-page-id-prefix.mjs';
import { manifestDocumentDatabase, realmDocumentDatabase } from '../../src/init/DocumentDatabase.mjs';
import createOpenAPIChangelogNode from '../utils/openapi.mjs';
import createProductNodes from '../utils/products.mjs';

// different types of references
const PAGES = [];
Expand Down Expand Up @@ -76,7 +78,7 @@ const createRemoteMetadataNode = async ({ createNode, createNodeId, createConten
}
};

exports.sourceNodes = async ({ actions, createContentDigest, createNodeId }) => {
export const sourceNodes = async ({ actions, createContentDigest, createNodeId }) => {
let hasOpenAPIChangelog = false;
const { createNode } = actions;

Expand Down Expand Up @@ -174,7 +176,7 @@ exports.sourceNodes = async ({ actions, createContentDigest, createNodeId }) =>
});
};

exports.createPages = async ({ actions }) => {
export const createPages = async ({ actions }) => {
const { createPage } = actions;

let repoBranches = null;
Expand Down Expand Up @@ -228,6 +230,8 @@ exports.createPages = async ({ actions }) => {
// TODO: Gatsby v4 will enable code splitting automatically. Delete duplicate component, add conditional for consistent-nav UnifiedFooter
const mainComponentRelativePath = `../../src/components/DocumentBody.js`;

const __dirname = dirname(fileURLToPath(import.meta.url));

if (RESOLVED_REF_DOC_MAPPING[page] && Object.keys(RESOLVED_REF_DOC_MAPPING[page]).length > 0) {
createPage({
path: assertTrailingSlash(slug),
Expand All @@ -249,7 +253,8 @@ exports.createPages = async ({ actions }) => {
};

// Prevent errors when running gatsby build caused by browser packages run in a node environment.
exports.onCreateWebpackConfig = ({ plugins, actions }) => {
export const onCreateWebpackConfig = ({ plugins, actions }) => {
const require = createRequire(import.meta.url);
const providePlugins = {
Buffer: ['buffer', 'Buffer'],
process: require.resolve('../../stubs/process.js'),
Expand All @@ -270,7 +275,7 @@ exports.onCreateWebpackConfig = ({ plugins, actions }) => {

// Remove type inference, as our schema is too ambiguous for this to be useful.
// https://www.gatsbyjs.com/docs/scaling-issues/#switch-off-type-inference-for-sitepagecontext
exports.createSchemaCustomization = ({ actions }) => {
export const createSchemaCustomization = ({ actions }) => {
actions.createTypes(`
type Page implements Node @dontInfer {
page_id: String
Expand Down
6 changes: 2 additions & 4 deletions plugins/utils/openapi.js → plugins/utils/openapi.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { hideChanges, hideDiffChanges } = require('../../src/components/OpenAPIChangelog/utils/filterHiddenChanges');
import { hideChanges, hideDiffChanges } from '../../src/components/OpenAPIChangelog/utils/filterHiddenChanges.js';

const atlasAdminProdChangelogS3Prefix = 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/changelog';
const atlasAdminDevChangelogS3Prefix = 'https://mongodb-mms-build-server.s3.amazonaws.com/openapi/changelog';
Expand Down Expand Up @@ -112,6 +112,4 @@ const createOpenAPIChangelogNode = async ({ createNode, createNodeId, createCont
}
};

module.exports = {
createOpenAPIChangelogNode,
};
export default createOpenAPIChangelogNode;
6 changes: 2 additions & 4 deletions plugins/utils/products.js → plugins/utils/products.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { baseUrl } = require('../../src/utils/base-url');
import { baseUrl } from '../../src/utils/base-url.js';

const createProductNodes = async ({ db, createNode, createNodeId, createContentDigest }) => {
// Get all MongoDB products for the sidenav
Expand All @@ -20,6 +20,4 @@ const createProductNodes = async ({ db, createNode, createNodeId, createContentD
});
};

module.exports = {
createProductNodes,
};
export default createProductNodes;
2 changes: 1 addition & 1 deletion scripts/ensure-master.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { execSync } = require('child_process');
import { execSync } from 'child_process';

const getGitBranch = () => {
return execSync('git rev-parse --abbrev-ref HEAD')
Expand Down
12 changes: 6 additions & 6 deletions src/build-constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
DOCUMENTS_COLLECTION: 'documents',
ASSETS_COLLECTION: 'assets',
METADATA_COLLECTION: 'metadata',
SNOOTY_REALM_APP_ID: 'snooty-koueq',
};
const DOCUMENTS_COLLECTION = 'documents';
const ASSETS_COLLECTION = 'assets';
const METADATA_COLLECTION = 'metadata';
const SNOOTY_REALM_APP_ID = 'snooty-koueq';

export { DOCUMENTS_COLLECTION, ASSETS_COLLECTION, METADATA_COLLECTION, SNOOTY_REALM_APP_ID };
2 changes: 1 addition & 1 deletion src/components/Admonition.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import Callout, { Variant } from '@leafygreen-ui/callout';
import { cx, css } from '@leafygreen-ui/emotion';
import { getPlaintext } from '../utils/get-plaintext';
import getPlaintext from '../utils/get-plaintext';
import { theme } from '../theme/docsTheme';
import ComponentFactory from './ComponentFactory';

Expand Down
2 changes: 1 addition & 1 deletion src/components/Banner/SiteBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { SNOOTY_REALM_APP_ID } from '../../build-constants';
import { useSiteMetadata } from '../../hooks/use-site-metadata';
import { theme } from '../../theme/docsTheme';
import { isBrowser } from '../../utils/is-browser';
import { normalizePath } from '../../utils/normalize-path';
import normalizePath from '../../utils/normalize-path';
import { fetchBanner } from '../../utils/realm';

const getBannerSource = (src) => {
Expand Down
Loading