From 8f2cb6420b706ed7c125d223d06806118eb905d0 Mon Sep 17 00:00:00 2001 From: Abhi Aiyer Date: Fri, 20 Aug 2021 07:25:59 -0700 Subject: [PATCH 01/16] Move some utils to core-utils --- .../src/__tests__/page-html.ts | 13 ++++++++++++ packages/gatsby-core-utils/src/page-html.ts | 20 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 packages/gatsby-core-utils/src/__tests__/page-html.ts create mode 100644 packages/gatsby-core-utils/src/page-html.ts diff --git a/packages/gatsby-core-utils/src/__tests__/page-html.ts b/packages/gatsby-core-utils/src/__tests__/page-html.ts new file mode 100644 index 0000000000000..90d637abee1e9 --- /dev/null +++ b/packages/gatsby-core-utils/src/__tests__/page-html.ts @@ -0,0 +1,13 @@ +import { getPageHtmlFilePath } from "../page-html" + +describe("page-html", () => { + it("returns correct html path", () => { + expect(getPageHtmlFilePath("public", "/path/1")).toBe( + "public/path/1/index.html" + ) + + expect(getPageHtmlFilePath("public", "/path/1/index.html")).toBe( + "public/path/1/index.html" + ) + }) +}) diff --git a/packages/gatsby-core-utils/src/page-html.ts b/packages/gatsby-core-utils/src/page-html.ts new file mode 100644 index 0000000000000..fe734e04ab1c4 --- /dev/null +++ b/packages/gatsby-core-utils/src/page-html.ts @@ -0,0 +1,20 @@ +import fs from "fs-extra" +import path from "path" + +const checkForHtmlSuffix = pagePath => !/\.(html?)$/i.test(pagePath) + +export async function remove({ publicDir }, pagePath) { + const filePath = getPageHtmlFilePath(publicDir, pagePath) + + return fs.remove(filePath) +} + +export function getPageHtmlFilePath(dir, outputPath) { + let outputFileName = outputPath.replace(/^(\/|\\)/, ``) // Remove leading slashes for webpack-dev-server + + if (checkForHtmlSuffix(outputPath)) { + outputFileName = path.join(outputFileName, `index.html`) + } + + return path.join(dir, outputFileName) +} From 768a53bd8db75df00cddfcc522b40046abfd7fea Mon Sep 17 00:00:00 2001 From: Abhi Aiyer Date: Fri, 20 Aug 2021 07:26:30 -0700 Subject: [PATCH 02/16] Move some utils to core-utils --- packages/gatsby-core-utils/src/page-html.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-core-utils/src/page-html.ts b/packages/gatsby-core-utils/src/page-html.ts index fe734e04ab1c4..8d2f4f27eb282 100644 --- a/packages/gatsby-core-utils/src/page-html.ts +++ b/packages/gatsby-core-utils/src/page-html.ts @@ -9,7 +9,7 @@ export async function remove({ publicDir }, pagePath) { return fs.remove(filePath) } -export function getPageHtmlFilePath(dir, outputPath) { +export function getPageHtmlFilePath(dir: string, outputPath: string): string { let outputFileName = outputPath.replace(/^(\/|\\)/, ``) // Remove leading slashes for webpack-dev-server if (checkForHtmlSuffix(outputPath)) { From 51c06dce3ad71397bc936a2eaa614cacbff8744c Mon Sep 17 00:00:00 2001 From: Abhi Aiyer Date: Fri, 20 Aug 2021 07:26:52 -0700 Subject: [PATCH 03/16] Move some utils to core-utils --- packages/gatsby-core-utils/src/page-html.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-core-utils/src/page-html.ts b/packages/gatsby-core-utils/src/page-html.ts index 8d2f4f27eb282..63c477a944f10 100644 --- a/packages/gatsby-core-utils/src/page-html.ts +++ b/packages/gatsby-core-utils/src/page-html.ts @@ -1,7 +1,8 @@ import fs from "fs-extra" import path from "path" -const checkForHtmlSuffix = pagePath => !/\.(html?)$/i.test(pagePath) +const checkForHtmlSuffix = (pagePath: string): boolean => + !/\.(html?)$/i.test(pagePath) export async function remove({ publicDir }, pagePath) { const filePath = getPageHtmlFilePath(publicDir, pagePath) From 9f83b1cf2203ae1500810b2c6b8ca1a4b919d3d4 Mon Sep 17 00:00:00 2001 From: Abhi Aiyer Date: Fri, 20 Aug 2021 07:27:09 -0700 Subject: [PATCH 04/16] Move some utils to core-utils --- packages/gatsby-core-utils/src/page-html.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-core-utils/src/page-html.ts b/packages/gatsby-core-utils/src/page-html.ts index 63c477a944f10..547c9a45a2c21 100644 --- a/packages/gatsby-core-utils/src/page-html.ts +++ b/packages/gatsby-core-utils/src/page-html.ts @@ -4,7 +4,7 @@ import path from "path" const checkForHtmlSuffix = (pagePath: string): boolean => !/\.(html?)$/i.test(pagePath) -export async function remove({ publicDir }, pagePath) { +export async function remove({ publicDir }, pagePath): Promise { const filePath = getPageHtmlFilePath(publicDir, pagePath) return fs.remove(filePath) From 625303241be59650ae10f22129688b19ab73ad75 Mon Sep 17 00:00:00 2001 From: Abhi Aiyer Date: Fri, 20 Aug 2021 08:04:05 -0700 Subject: [PATCH 05/16] moreUtils --- .../gatsby-core-utils/src/__tests__/page-data.ts | 13 +++++++++++++ packages/gatsby-core-utils/src/page-data.ts | 14 ++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 packages/gatsby-core-utils/src/__tests__/page-data.ts create mode 100644 packages/gatsby-core-utils/src/page-data.ts diff --git a/packages/gatsby-core-utils/src/__tests__/page-data.ts b/packages/gatsby-core-utils/src/__tests__/page-data.ts new file mode 100644 index 0000000000000..21d465e5a6ce4 --- /dev/null +++ b/packages/gatsby-core-utils/src/__tests__/page-data.ts @@ -0,0 +1,13 @@ +import { pageDataFilePath } from "../page-data" + +describe(`page-data`, () => { + it(`returns correct page data path`, () => { + expect(pageDataFilePath(`public`, `/path/1`)).toBe( + `public/page-data/path/1/page-data.json` + ) + + expect(pageDataFilePath(`public`, `/`)).toBe( + `public/page-data/index/page-data.json` + ) + }) +}) diff --git a/packages/gatsby-core-utils/src/page-data.ts b/packages/gatsby-core-utils/src/page-data.ts new file mode 100644 index 0000000000000..cc8fb39be39b2 --- /dev/null +++ b/packages/gatsby-core-utils/src/page-data.ts @@ -0,0 +1,14 @@ +import path from "path" + +export function fixedPagePath(pagePath: string): string { + return pagePath === `/` ? `index` : pagePath +} + +export function pageDataFilePath(publicDir: string, pagePath: string): string { + return path.join( + publicDir, + `page-data`, + fixedPagePath(pagePath), + `page-data.json` + ) +} From 4f142e05756c4d8486f31d196d59768ba9ce837c Mon Sep 17 00:00:00 2001 From: Abhi Aiyer Date: Fri, 20 Aug 2021 08:48:09 -0700 Subject: [PATCH 06/16] Replace getPageHtmlFilePath in app --- integration-tests/ssr/test-output.js | 2 +- packages/gatsby-core-utils/src/index.ts | 2 ++ packages/gatsby/src/commands/build-utils.ts | 3 +- packages/gatsby/src/utils/page-html.ts | 30 ------------------- .../src/utils/worker/child/render-html.ts | 2 +- 5 files changed, 5 insertions(+), 34 deletions(-) delete mode 100644 packages/gatsby/src/utils/page-html.ts diff --git a/integration-tests/ssr/test-output.js b/integration-tests/ssr/test-output.js index a9cdb5f95f020..77dcde8ddce9b 100644 --- a/integration-tests/ssr/test-output.js +++ b/integration-tests/ssr/test-output.js @@ -3,7 +3,7 @@ // - start the develop server // - run this script async function run() { - const { getPageHtmlFilePath } = require(`gatsby/dist/utils/page-html`) + const { getPageHtmlFilePath } = require(`gatsby-core-utils/dist/page-html`) const { join } = require(`path`) const fs = require(`fs-extra`) const fetch = require(`node-fetch`) diff --git a/packages/gatsby-core-utils/src/index.ts b/packages/gatsby-core-utils/src/index.ts index a4cb4c4cb375f..85d2ec3f79a48 100644 --- a/packages/gatsby-core-utils/src/index.ts +++ b/packages/gatsby-core-utils/src/index.ts @@ -12,3 +12,5 @@ export { isTruthy } from "./is-truthy" export { getMatchPath } from "./match-path" export * from "./service-lock" export * from "./site-metadata" +export * from "./page-data" +export * from "./page-html" diff --git a/packages/gatsby/src/commands/build-utils.ts b/packages/gatsby/src/commands/build-utils.ts index a8d954ea027b5..80f3dd7cbdeba 100644 --- a/packages/gatsby/src/commands/build-utils.ts +++ b/packages/gatsby/src/commands/build-utils.ts @@ -2,11 +2,10 @@ import fs from "fs-extra" import path from "path" import { platform } from "os" import reporter from "gatsby-cli/lib/reporter" - import { remove as removePageHtmlFile, getPageHtmlFilePath, -} from "../utils/page-html" +} from "gatsby-core-utils" import { removePageData, fixedPagePath } from "../utils/page-data" import { store } from "../redux" import { IGatsbyState } from "../redux/types" diff --git a/packages/gatsby/src/utils/page-html.ts b/packages/gatsby/src/utils/page-html.ts deleted file mode 100644 index 505a8471caf8b..0000000000000 --- a/packages/gatsby/src/utils/page-html.ts +++ /dev/null @@ -1,30 +0,0 @@ -import fs from "fs-extra" -import path from "path" - -const checkForHtmlSuffix = (pagePath: string): boolean => - !/\.(html?)$/i.test(pagePath) - -// copied from https://github.com/markdalgleish/static-site-generator-webpack-plugin/blob/master/index.js#L161 -export const getPageHtmlFilePath = ( - dir: string, - outputPath: string -): string => { - let outputFileName = outputPath.replace(/^(\/|\\)/, ``) // Remove leading slashes for webpack-dev-server - - if (checkForHtmlSuffix(outputPath)) { - outputFileName = path.join(outputFileName, `index.html`) - } - - return path.join(dir, outputFileName) -} - -export const remove = async ( - { publicDir }: { publicDir: string }, - pagePath: string -): Promise => { - const filePath = getPageHtmlFilePath(publicDir, pagePath) - if (fs.existsSync(filePath)) { - return await fs.remove(filePath) - } - return Promise.resolve() -} diff --git a/packages/gatsby/src/utils/worker/child/render-html.ts b/packages/gatsby/src/utils/worker/child/render-html.ts index a971336cb7994..20331390f3d91 100644 --- a/packages/gatsby/src/utils/worker/child/render-html.ts +++ b/packages/gatsby/src/utils/worker/child/render-html.ts @@ -3,8 +3,8 @@ import fs from "fs-extra" import Bluebird from "bluebird" import * as path from "path" +import { getPageHtmlFilePath } from "gatsby-core-utils" -import { getPageHtmlFilePath } from "../../page-html" import { IPageDataWithQueryResult } from "../../page-data" import { IRenderHtmlResult } from "../../../commands/build-html" // we want to force posix-style joins, so Windows doesn't produce backslashes for urls From a4ffaeb4aadf29c47012a42107fa930b292f840c Mon Sep 17 00:00:00 2001 From: Abhi Aiyer Date: Fri, 20 Aug 2021 08:53:51 -0700 Subject: [PATCH 07/16] Backticks --- .../gatsby-core-utils/src/__tests__/page-html.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/gatsby-core-utils/src/__tests__/page-html.ts b/packages/gatsby-core-utils/src/__tests__/page-html.ts index 90d637abee1e9..d19ea46ab57f9 100644 --- a/packages/gatsby-core-utils/src/__tests__/page-html.ts +++ b/packages/gatsby-core-utils/src/__tests__/page-html.ts @@ -1,13 +1,13 @@ import { getPageHtmlFilePath } from "../page-html" -describe("page-html", () => { - it("returns correct html path", () => { - expect(getPageHtmlFilePath("public", "/path/1")).toBe( - "public/path/1/index.html" +describe(`page-html`, () => { + it(`returns correct html path`, () => { + expect(getPageHtmlFilePath(`public`, `/path/1`)).toBe( + `public/path/1/index.html` ) - expect(getPageHtmlFilePath("public", "/path/1/index.html")).toBe( - "public/path/1/index.html" + expect(getPageHtmlFilePath(`public`, `/path/1/index.html`)).toBe( + `public/path/1/index.html` ) }) }) From dfe42b7da1626c0654118f822be7a5ef9f95e438 Mon Sep 17 00:00:00 2001 From: Abhi Aiyer Date: Fri, 20 Aug 2021 09:00:45 -0700 Subject: [PATCH 08/16] replace fixedPagePath --- .../src/build-headers-program.js | 4 +-- .../src/build-headers-program.js | 4 +-- packages/gatsby/src/commands/build-utils.ts | 3 ++- .../src/utils/__tests__/get-page-data.ts | 7 ++---- .../src/utils/develop-preload-headers.ts | 4 +-- packages/gatsby/src/utils/page-data.ts | 25 +++++-------------- .../src/utils/worker/child/render-html.ts | 10 +++++--- 7 files changed, 23 insertions(+), 34 deletions(-) diff --git a/packages/gatsby-plugin-gatsby-cloud/src/build-headers-program.js b/packages/gatsby-plugin-gatsby-cloud/src/build-headers-program.js index 1c802a4f226ff..f51646f986255 100644 --- a/packages/gatsby-plugin-gatsby-cloud/src/build-headers-program.js +++ b/packages/gatsby-plugin-gatsby-cloud/src/build-headers-program.js @@ -2,6 +2,7 @@ import _ from "lodash" import { createWriteStream, existsSync } from "fs-extra" import { parse, posix } from "path" import kebabHash from "kebab-hash" +import { fixedPagePath } from "gatsby-core-utils" import { IMMUTABLE_CACHING_HEADER } from "./constants" import { @@ -56,8 +57,7 @@ function pathChunkName(path) { } function getPageDataPath(path) { - const fixedPagePath = path === `/` ? `index` : path - return posix.join(`page-data`, fixedPagePath, `page-data.json`) + return posix.join(`page-data`, fixedPagePath(path), `page-data.json`) } function getScriptPath(file, manifest) { diff --git a/packages/gatsby-plugin-netlify/src/build-headers-program.js b/packages/gatsby-plugin-netlify/src/build-headers-program.js index 1e58d7fb09682..2a6685a670e4b 100644 --- a/packages/gatsby-plugin-netlify/src/build-headers-program.js +++ b/packages/gatsby-plugin-netlify/src/build-headers-program.js @@ -2,6 +2,7 @@ import _ from "lodash" import { writeFile, existsSync } from "fs-extra" import { parse, posix } from "path" import kebabHash from "kebab-hash" +import { fixedPagePath } from "gatsby-core-utils" import { HEADER_COMMENT, IMMUTABLE_CACHING_HEADER } from "./constants" import { @@ -55,8 +56,7 @@ function pathChunkName(path) { } function getPageDataPath(path) { - const fixedPagePath = path === `/` ? `index` : path - return posix.join(`page-data`, fixedPagePath, `page-data.json`) + return posix.join(`page-data`, fixedPagePath(path), `page-data.json`) } function getScriptPath(file, manifest) { diff --git a/packages/gatsby/src/commands/build-utils.ts b/packages/gatsby/src/commands/build-utils.ts index 80f3dd7cbdeba..51df2b6229ac3 100644 --- a/packages/gatsby/src/commands/build-utils.ts +++ b/packages/gatsby/src/commands/build-utils.ts @@ -5,8 +5,9 @@ import reporter from "gatsby-cli/lib/reporter" import { remove as removePageHtmlFile, getPageHtmlFilePath, + fixedPagePath, } from "gatsby-core-utils" -import { removePageData, fixedPagePath } from "../utils/page-data" +import { removePageData } from "../utils/page-data" import { store } from "../redux" import { IGatsbyState } from "../redux/types" diff --git a/packages/gatsby/src/utils/__tests__/get-page-data.ts b/packages/gatsby/src/utils/__tests__/get-page-data.ts index 5921f45a03fc2..796a037e54963 100644 --- a/packages/gatsby/src/utils/__tests__/get-page-data.ts +++ b/packages/gatsby/src/utils/__tests__/get-page-data.ts @@ -1,10 +1,7 @@ +import { fixedPagePath } from "gatsby-core-utils" import { store } from "../../redux" import { getPageData, RETRY_INTERVAL } from "../get-page-data" -import { - fixedPagePath, - flush as flushPageData, - savePageQueryResult, -} from "../page-data" +import { flush as flushPageData, savePageQueryResult } from "../page-data" import { IGatsbyPage, IGatsbyPlugin, diff --git a/packages/gatsby/src/utils/develop-preload-headers.ts b/packages/gatsby/src/utils/develop-preload-headers.ts index 24682100a78bb..80d251d9e582c 100644 --- a/packages/gatsby/src/utils/develop-preload-headers.ts +++ b/packages/gatsby/src/utils/develop-preload-headers.ts @@ -1,8 +1,8 @@ import { Response } from "express" import * as path from "path" - +import { fixedPagePath } from "gatsby-core-utils" import { findPageByPath } from "./find-page-by-path" -import { fixedPagePath, readPageData } from "./page-data" +import { readPageData } from "./page-data" import { store } from "../redux" /** diff --git a/packages/gatsby/src/utils/page-data.ts b/packages/gatsby/src/utils/page-data.ts index bea68bf54c51a..6bad4fd647e31 100644 --- a/packages/gatsby/src/utils/page-data.ts +++ b/packages/gatsby/src/utils/page-data.ts @@ -3,7 +3,7 @@ import fs from "fs-extra" import reporter from "gatsby-cli/lib/reporter" import fastq from "fastq" import path from "path" -import { createContentDigest } from "gatsby-core-utils" +import { createContentDigest, pageDataFilePath } from "gatsby-core-utils" import { IGatsbyPage } from "../redux/types" import { websocketManager } from "./websocket-manager" import { isWebpackStatusPending } from "./webpack-status" @@ -25,28 +25,15 @@ export interface IPageDataWithQueryResult extends IPageData { result: IExecutionResult } -export function fixedPagePath(pagePath: string): string { - return pagePath === `/` ? `index` : pagePath -} - export function reverseFixedPagePath(pageDataRequestPath: string): string { return pageDataRequestPath === `index` ? `/` : pageDataRequestPath } -function getFilePath(publicDir: string, pagePath: string): string { - return path.join( - publicDir, - `page-data`, - fixedPagePath(pagePath), - `page-data.json` - ) -} - export async function readPageData( publicDir: string, pagePath: string ): Promise { - const filePath = getFilePath(publicDir, pagePath) + const filePath = pageDataFilePath(publicDir, pagePath) const rawPageData = await fs.readFile(filePath, `utf-8`) return JSON.parse(rawPageData) @@ -56,7 +43,7 @@ export async function removePageData( publicDir: string, pagePath: string ): Promise { - const filePath = getFilePath(publicDir, pagePath) + const filePath = pageDataFilePath(publicDir, pagePath) if (fs.existsSync(filePath)) { return await fs.remove(filePath) @@ -66,7 +53,7 @@ export async function removePageData( } export function pageDataExists(publicDir: string, pagePath: string): boolean { - return fs.existsSync(getFilePath(publicDir, pagePath)) + return fs.existsSync(pageDataFilePath(publicDir, pagePath)) } let lmdbPageQueryResultsCache: GatsbyCacheLmdb @@ -141,7 +128,7 @@ export async function writePageData( ): Promise { const result = await readPageQueryResult(publicDir, pagePath) - const outputFilePath = getFilePath(publicDir, pagePath) + const outputFilePath = pageDataFilePath(publicDir, pagePath) let body = `{ "componentChunkName": "${componentChunkName}", "path": "${pagePath}", @@ -327,7 +314,7 @@ export async function handleStalePageData(): Promise { const expectedPageDataFiles = new Set() store.getState().pages.forEach(page => { - expectedPageDataFiles.add(getFilePath(`public`, page.path)) + expectedPageDataFiles.add(pageDataFilePath(`public`, page.path)) }) const deletionPromises: Array> = [] diff --git a/packages/gatsby/src/utils/worker/child/render-html.ts b/packages/gatsby/src/utils/worker/child/render-html.ts index 20331390f3d91..e28f44e09d9f1 100644 --- a/packages/gatsby/src/utils/worker/child/render-html.ts +++ b/packages/gatsby/src/utils/worker/child/render-html.ts @@ -3,7 +3,7 @@ import fs from "fs-extra" import Bluebird from "bluebird" import * as path from "path" -import { getPageHtmlFilePath } from "gatsby-core-utils" +import { getPageHtmlFilePath, fixedPagePath } from "gatsby-core-utils" import { IPageDataWithQueryResult } from "../../page-data" import { IRenderHtmlResult } from "../../../commands/build-html" @@ -64,8 +64,12 @@ async function readPageData( publicDir: string, pagePath: string ): Promise { - const fixedPagePath = pagePath === `/` ? `index` : pagePath - const filePath = join(publicDir, `page-data`, fixedPagePath, `page-data.json`) + const filePath = join( + publicDir, + `page-data`, + fixedPagePath(pagePath), + `page-data.json` + ) const rawPageData = await fs.readFile(filePath, `utf-8`) return JSON.parse(rawPageData) From 95c4fd7c6f87f503a710328b3d637dd062f9673c Mon Sep 17 00:00:00 2001 From: Abhi Aiyer Date: Fri, 20 Aug 2021 09:09:52 -0700 Subject: [PATCH 09/16] Add more imports of fixedPagePath --- .../cypress/plugins/block-resources.js | 17 +++++++++++++---- .../cypress/plugins/block-resources.js | 5 ++--- .../cache-dir/ssr-develop-static-entry.js | 9 ++++----- packages/gatsby/cache-dir/static-entry.js | 7 +++---- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/e2e-tests/development-runtime/cypress/plugins/block-resources.js b/e2e-tests/development-runtime/cypress/plugins/block-resources.js index cf9d8dd5633b8..537e01d439256 100644 --- a/e2e-tests/development-runtime/cypress/plugins/block-resources.js +++ b/e2e-tests/development-runtime/cypress/plugins/block-resources.js @@ -4,6 +4,7 @@ const fs = require(`fs-extra`) const path = require(`path`) const glob = require(`glob`) +const { fixedPagePath } = require(`gatsby-core-utils/dist/page-data`) const siteDir = path.join(__dirname, `..`, `..`) const srcDir = path.join(siteDir, `src`) @@ -32,13 +33,21 @@ const restoreAsset = hiddenPath => { } const getPageDataPath = pagePath => { - const fixedPagePath = pagePath === `/` ? `index` : pagePath - return path.join(publicDir, `page-data`, fixedPagePath, `page-data.json`) + return path.join( + publicDir, + `page-data`, + fixedPagePath(pagePath), + `page-data.json` + ) } const getHiddenPageDataPath = pagePath => { - const fixedPagePath = pagePath === `/` ? `index` : pagePath - return path.join(publicDir, `page-data`, fixedPagePath, `_page-data.json`) + return path.join( + publicDir, + `page-data`, + fixedPagePath(pagePath), + `_page-data.json` + ) } const blockPageData = pagePath => diff --git a/e2e-tests/production-runtime/cypress/plugins/block-resources.js b/e2e-tests/production-runtime/cypress/plugins/block-resources.js index 2fa9c6f780d1b..07aa14c68ab0b 100644 --- a/e2e-tests/production-runtime/cypress/plugins/block-resources.js +++ b/e2e-tests/production-runtime/cypress/plugins/block-resources.js @@ -1,6 +1,6 @@ const fs = require(`fs-extra`) const path = require(`path`) - +const { fixedPagePath } = require(`gatsby-core-utils/dist/page-data`) const publicDir = path.join(__dirname, `..`, `..`, `public`) function getAssetManifest() { @@ -9,8 +9,7 @@ function getAssetManifest() { } function getPageDataPath(pagePath) { - const fixedPagePath = pagePath === `/` ? `index` : pagePath - return path.posix.join(`page-data`, fixedPagePath, `page-data.json`) + return path.posix.join(`page-data`, fixedPagePath(pagePath), `page-data.json`) } const filterAssets = (assetsForPath, filter) => { diff --git a/packages/gatsby/cache-dir/ssr-develop-static-entry.js b/packages/gatsby/cache-dir/ssr-develop-static-entry.js index e67a275dc05d0..7cb499c7200f7 100644 --- a/packages/gatsby/cache-dir/ssr-develop-static-entry.js +++ b/packages/gatsby/cache-dir/ssr-develop-static-entry.js @@ -4,12 +4,13 @@ import fs from "fs" import { renderToString, renderToStaticMarkup } from "react-dom/server" import { get, merge, isObject, flatten, uniqBy, concat } from "lodash" import nodePath from "path" +import { ServerLocation, Router, isRedirect } from "@reach/router" +import { fixedPagePath } from "gatsby-core-utils" import { apiRunner, apiRunnerAsync } from "./api-runner-ssr" import { grabMatchParams } from "./find-path" import syncRequires from "$virtual/ssr-sync-requires" import { RouteAnnouncerProps } from "./route-announcer-props" -import { ServerLocation, Router, isRedirect } from "@reach/router" // import testRequireError from "./test-require-error" // For some extremely mysterious reason, webpack adds the above module *after* @@ -138,10 +139,8 @@ export default async function staticPage( postBodyComponents = components } - const getPageDataPath = path => { - const fixedPagePath = path === `/` ? `index` : path - return nodePath.join(`page-data`, fixedPagePath, `page-data.json`) - } + const getPageDataPath = path => + nodePath.join(`page-data`, fixedPagePath(path), `page-data.json`) const getPageData = pagePath => { const pageDataPath = getPageDataPath(pagePath) diff --git a/packages/gatsby/cache-dir/static-entry.js b/packages/gatsby/cache-dir/static-entry.js index af702b2884f71..4299ea0711df2 100644 --- a/packages/gatsby/cache-dir/static-entry.js +++ b/packages/gatsby/cache-dir/static-entry.js @@ -8,6 +8,7 @@ const { const { ServerLocation, Router, isRedirect } = require(`@gatsbyjs/reach-router`) const { merge, flattenDeep, replace } = require(`lodash`) const { StaticQueryContext } = require(`gatsby`) +const { fixedPagePath } = require(`gatsby-core-utils/dist/page-data`) const fs = require(`fs`) const { RouteAnnouncerProps } = require(`./route-announcer-props`) @@ -44,10 +45,8 @@ try { Html = Html && Html.__esModule ? Html.default : Html -const getPageDataPath = path => { - const fixedPagePath = path === `/` ? `index` : path - return join(`page-data`, fixedPagePath, `page-data.json`) -} +const getPageDataPath = path => + join(`page-data`, fixedPagePath(path), `page-data.json`) const getPageDataUrl = pagePath => { const pageDataPath = getPageDataPath(pagePath) From 9a1b0fe38911157107ca95fc6264fc5a432f968d Mon Sep 17 00:00:00 2001 From: Abhi Aiyer Date: Fri, 20 Aug 2021 09:26:18 -0700 Subject: [PATCH 10/16] change name of getPageHtmlFilePath --- integration-tests/ssr/test-output.js | 4 ++-- .../gatsby-core-utils/src/__tests__/page-html.ts | 6 +++--- packages/gatsby-core-utils/src/page-html.ts | 14 +++++++------- packages/gatsby/src/commands/build-utils.ts | 6 ++---- .../gatsby/src/utils/worker/child/render-html.ts | 9 +++------ 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/integration-tests/ssr/test-output.js b/integration-tests/ssr/test-output.js index 77dcde8ddce9b..8c54e60fed848 100644 --- a/integration-tests/ssr/test-output.js +++ b/integration-tests/ssr/test-output.js @@ -3,7 +3,7 @@ // - start the develop server // - run this script async function run() { - const { getPageHtmlFilePath } = require(`gatsby-core-utils/dist/page-html`) + const { generateHtmlPath } = require(`gatsby-core-utils`) const { join } = require(`path`) const fs = require(`fs-extra`) const fetch = require(`node-fetch`) @@ -38,7 +38,7 @@ async function run() { const builtHtml = format( filterHtml( fs.readFileSync( - getPageHtmlFilePath(join(process.cwd(), `public`), path), + generateHtmlPath(join(process.cwd(), `public`), path), `utf-8` ) ) diff --git a/packages/gatsby-core-utils/src/__tests__/page-html.ts b/packages/gatsby-core-utils/src/__tests__/page-html.ts index d19ea46ab57f9..8374c34fa3091 100644 --- a/packages/gatsby-core-utils/src/__tests__/page-html.ts +++ b/packages/gatsby-core-utils/src/__tests__/page-html.ts @@ -1,12 +1,12 @@ -import { getPageHtmlFilePath } from "../page-html" +import { generateHtmlPath } from "../page-html" describe(`page-html`, () => { it(`returns correct html path`, () => { - expect(getPageHtmlFilePath(`public`, `/path/1`)).toBe( + expect(generateHtmlPath(`public`, `/path/1`)).toBe( `public/path/1/index.html` ) - expect(getPageHtmlFilePath(`public`, `/path/1/index.html`)).toBe( + expect(generateHtmlPath(`public`, `/path/1/index.html`)).toBe( `public/path/1/index.html` ) }) diff --git a/packages/gatsby-core-utils/src/page-html.ts b/packages/gatsby-core-utils/src/page-html.ts index 547c9a45a2c21..718d6d2bdc741 100644 --- a/packages/gatsby-core-utils/src/page-html.ts +++ b/packages/gatsby-core-utils/src/page-html.ts @@ -4,13 +4,7 @@ import path from "path" const checkForHtmlSuffix = (pagePath: string): boolean => !/\.(html?)$/i.test(pagePath) -export async function remove({ publicDir }, pagePath): Promise { - const filePath = getPageHtmlFilePath(publicDir, pagePath) - - return fs.remove(filePath) -} - -export function getPageHtmlFilePath(dir: string, outputPath: string): string { +export function generateHtmlPath(dir: string, outputPath: string): string { let outputFileName = outputPath.replace(/^(\/|\\)/, ``) // Remove leading slashes for webpack-dev-server if (checkForHtmlSuffix(outputPath)) { @@ -19,3 +13,9 @@ export function getPageHtmlFilePath(dir: string, outputPath: string): string { return path.join(dir, outputFileName) } + +export async function remove({ publicDir }, pagePath): Promise { + const filePath = generateHtmlPath(publicDir, pagePath) + + return fs.remove(filePath) +} diff --git a/packages/gatsby/src/commands/build-utils.ts b/packages/gatsby/src/commands/build-utils.ts index 51df2b6229ac3..72b3b087ad76d 100644 --- a/packages/gatsby/src/commands/build-utils.ts +++ b/packages/gatsby/src/commands/build-utils.ts @@ -4,7 +4,7 @@ import { platform } from "os" import reporter from "gatsby-cli/lib/reporter" import { remove as removePageHtmlFile, - getPageHtmlFilePath, + generateHtmlPath, fixedPagePath, } from "gatsby-core-utils" import { removePageData } from "../utils/page-data" @@ -15,9 +15,7 @@ const checkFolderIsEmpty = (path: string): boolean => fs.existsSync(path) && !fs.readdirSync(path).length const checkAndRemoveEmptyDir = (publicDir: string, pagePath: string): void => { - const pageHtmlDirectory = path.dirname( - getPageHtmlFilePath(publicDir, pagePath) - ) + const pageHtmlDirectory = path.dirname(generateHtmlPath(publicDir, pagePath)) const pageDataDirectory = path.join( publicDir, `page-data`, diff --git a/packages/gatsby/src/utils/worker/child/render-html.ts b/packages/gatsby/src/utils/worker/child/render-html.ts index e28f44e09d9f1..f466d5b32a7df 100644 --- a/packages/gatsby/src/utils/worker/child/render-html.ts +++ b/packages/gatsby/src/utils/worker/child/render-html.ts @@ -3,7 +3,7 @@ import fs from "fs-extra" import Bluebird from "bluebird" import * as path from "path" -import { getPageHtmlFilePath, fixedPagePath } from "gatsby-core-utils" +import { generateHtmlPath, fixedPagePath } from "gatsby-core-utils" import { IPageDataWithQueryResult } from "../../page-data" import { IRenderHtmlResult } from "../../../commands/build-html" @@ -340,7 +340,7 @@ export const renderHTMLProd = async ({ unsafeBuiltinsUsageByPagePath[pagePath] = unsafeBuiltinsUsage } - return fs.outputFile(getPageHtmlFilePath(publicDir, pagePath), html) + return fs.outputFile(generateHtmlPath(publicDir, pagePath), html) } catch (e) { if (e.unsafeBuiltinsUsage && e.unsafeBuiltinsUsage.length > 0) { unsafeBuiltinsUsageByPagePath[pagePath] = e.unsafeBuiltinsUsage @@ -394,10 +394,7 @@ export const renderHTMLDev = async ({ const htmlString = await htmlComponentRenderer.default({ pagePath, }) - return fs.outputFile( - getPageHtmlFilePath(outputDir, pagePath), - htmlString - ) + return fs.outputFile(generateHtmlPath(outputDir, pagePath), htmlString) } catch (e) { // add some context to error so we can display more helpful message e.context = { From a301372590ba991be9c0b0526c85731d651920e6 Mon Sep 17 00:00:00 2001 From: Abhi Aiyer Date: Fri, 20 Aug 2021 09:30:23 -0700 Subject: [PATCH 11/16] change name of getPageDataPath --- .../gatsby-core-utils/src/__tests__/page-data.ts | 6 +++--- packages/gatsby-core-utils/src/page-data.ts | 5 ++++- packages/gatsby/src/utils/page-data.ts | 12 ++++++------ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/gatsby-core-utils/src/__tests__/page-data.ts b/packages/gatsby-core-utils/src/__tests__/page-data.ts index 21d465e5a6ce4..4c7ea7ae2a4f4 100644 --- a/packages/gatsby-core-utils/src/__tests__/page-data.ts +++ b/packages/gatsby-core-utils/src/__tests__/page-data.ts @@ -1,12 +1,12 @@ -import { pageDataFilePath } from "../page-data" +import { generatePageDataPath } from "../page-data" describe(`page-data`, () => { it(`returns correct page data path`, () => { - expect(pageDataFilePath(`public`, `/path/1`)).toBe( + expect(generatePageDataPath(`public`, `/path/1`)).toBe( `public/page-data/path/1/page-data.json` ) - expect(pageDataFilePath(`public`, `/`)).toBe( + expect(generatePageDataPath(`public`, `/`)).toBe( `public/page-data/index/page-data.json` ) }) diff --git a/packages/gatsby-core-utils/src/page-data.ts b/packages/gatsby-core-utils/src/page-data.ts index cc8fb39be39b2..5be08dbc7af7a 100644 --- a/packages/gatsby-core-utils/src/page-data.ts +++ b/packages/gatsby-core-utils/src/page-data.ts @@ -4,7 +4,10 @@ export function fixedPagePath(pagePath: string): string { return pagePath === `/` ? `index` : pagePath } -export function pageDataFilePath(publicDir: string, pagePath: string): string { +export function generatePageDataPath( + publicDir: string, + pagePath: string +): string { return path.join( publicDir, `page-data`, diff --git a/packages/gatsby/src/utils/page-data.ts b/packages/gatsby/src/utils/page-data.ts index 6bad4fd647e31..74ad13775e08b 100644 --- a/packages/gatsby/src/utils/page-data.ts +++ b/packages/gatsby/src/utils/page-data.ts @@ -3,7 +3,7 @@ import fs from "fs-extra" import reporter from "gatsby-cli/lib/reporter" import fastq from "fastq" import path from "path" -import { createContentDigest, pageDataFilePath } from "gatsby-core-utils" +import { createContentDigest, generatePageDataPath } from "gatsby-core-utils" import { IGatsbyPage } from "../redux/types" import { websocketManager } from "./websocket-manager" import { isWebpackStatusPending } from "./webpack-status" @@ -33,7 +33,7 @@ export async function readPageData( publicDir: string, pagePath: string ): Promise { - const filePath = pageDataFilePath(publicDir, pagePath) + const filePath = generatePageDataPath(publicDir, pagePath) const rawPageData = await fs.readFile(filePath, `utf-8`) return JSON.parse(rawPageData) @@ -43,7 +43,7 @@ export async function removePageData( publicDir: string, pagePath: string ): Promise { - const filePath = pageDataFilePath(publicDir, pagePath) + const filePath = generatePageDataPath(publicDir, pagePath) if (fs.existsSync(filePath)) { return await fs.remove(filePath) @@ -53,7 +53,7 @@ export async function removePageData( } export function pageDataExists(publicDir: string, pagePath: string): boolean { - return fs.existsSync(pageDataFilePath(publicDir, pagePath)) + return fs.existsSync(generatePageDataPath(publicDir, pagePath)) } let lmdbPageQueryResultsCache: GatsbyCacheLmdb @@ -128,7 +128,7 @@ export async function writePageData( ): Promise { const result = await readPageQueryResult(publicDir, pagePath) - const outputFilePath = pageDataFilePath(publicDir, pagePath) + const outputFilePath = generatePageDataPath(publicDir, pagePath) let body = `{ "componentChunkName": "${componentChunkName}", "path": "${pagePath}", @@ -314,7 +314,7 @@ export async function handleStalePageData(): Promise { const expectedPageDataFiles = new Set() store.getState().pages.forEach(page => { - expectedPageDataFiles.add(pageDataFilePath(`public`, page.path)) + expectedPageDataFiles.add(generatePageDataPath(`public`, page.path)) }) const deletionPromises: Array> = [] From 7b179569bd18d87105fd15a5db24cf9c612f0c98 Mon Sep 17 00:00:00 2001 From: Abhi Aiyer Date: Fri, 20 Aug 2021 09:32:51 -0700 Subject: [PATCH 12/16] change require --- .../development-runtime/cypress/plugins/block-resources.js | 2 +- e2e-tests/production-runtime/cypress/plugins/block-resources.js | 2 +- packages/gatsby/cache-dir/static-entry.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e-tests/development-runtime/cypress/plugins/block-resources.js b/e2e-tests/development-runtime/cypress/plugins/block-resources.js index 537e01d439256..ec6a084102b7f 100644 --- a/e2e-tests/development-runtime/cypress/plugins/block-resources.js +++ b/e2e-tests/development-runtime/cypress/plugins/block-resources.js @@ -4,7 +4,7 @@ const fs = require(`fs-extra`) const path = require(`path`) const glob = require(`glob`) -const { fixedPagePath } = require(`gatsby-core-utils/dist/page-data`) +const { fixedPagePath } = require(`gatsby-core-utils`) const siteDir = path.join(__dirname, `..`, `..`) const srcDir = path.join(siteDir, `src`) diff --git a/e2e-tests/production-runtime/cypress/plugins/block-resources.js b/e2e-tests/production-runtime/cypress/plugins/block-resources.js index 07aa14c68ab0b..3c0a9eb9c034f 100644 --- a/e2e-tests/production-runtime/cypress/plugins/block-resources.js +++ b/e2e-tests/production-runtime/cypress/plugins/block-resources.js @@ -1,6 +1,6 @@ const fs = require(`fs-extra`) const path = require(`path`) -const { fixedPagePath } = require(`gatsby-core-utils/dist/page-data`) +const { fixedPagePath } = require(`gatsby-core-utils`) const publicDir = path.join(__dirname, `..`, `..`, `public`) function getAssetManifest() { diff --git a/packages/gatsby/cache-dir/static-entry.js b/packages/gatsby/cache-dir/static-entry.js index 4299ea0711df2..9667dee7f230a 100644 --- a/packages/gatsby/cache-dir/static-entry.js +++ b/packages/gatsby/cache-dir/static-entry.js @@ -8,7 +8,7 @@ const { const { ServerLocation, Router, isRedirect } = require(`@gatsbyjs/reach-router`) const { merge, flattenDeep, replace } = require(`lodash`) const { StaticQueryContext } = require(`gatsby`) -const { fixedPagePath } = require(`gatsby-core-utils/dist/page-data`) +const { fixedPagePath } = require(`gatsby-core-utils`) const fs = require(`fs`) const { RouteAnnouncerProps } = require(`./route-announcer-props`) From 4a16f67e086f8b7838f3aaa42f57aeeafe900394 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Mon, 23 Aug 2021 13:18:01 +0200 Subject: [PATCH 13/16] add deps, add windows test utils, delete unused remove function --- e2e-tests/development-runtime/package.json | 1 + e2e-tests/production-runtime/package.json | 3 ++- integration-tests/ssr/package.json | 7 +++--- .../src/__tests__/page-data.ts | 25 ++++++++++++++----- .../src/__tests__/page-html.ts | 25 ++++++++++++++----- packages/gatsby-core-utils/src/page-html.ts | 7 ------ 6 files changed, 45 insertions(+), 23 deletions(-) diff --git a/e2e-tests/development-runtime/package.json b/e2e-tests/development-runtime/package.json index 57b832c82ec2a..06b94586ca88c 100644 --- a/e2e-tests/development-runtime/package.json +++ b/e2e-tests/development-runtime/package.json @@ -57,6 +57,7 @@ "cross-env": "^5.2.0", "cypress": "6.1.0", "fs-extra": "^7.0.1", + "gatsby-core-utils": "^2.12.0", "gatsby-cypress": "^0.1.7", "is-ci": "^2.0.0", "prettier": "2.0.4", diff --git a/e2e-tests/production-runtime/package.json b/e2e-tests/production-runtime/package.json index 546fb23aca7d2..0f24c4e07d504 100644 --- a/e2e-tests/production-runtime/package.json +++ b/e2e-tests/production-runtime/package.json @@ -16,8 +16,8 @@ "gatsby-plugin-sass": "^4.1.0-next.2", "gatsby-plugin-sharp": "^3.0.0-next.5", "gatsby-plugin-stylus": "^3.1.0-next.2", - "gatsby-source-filesystem": "^3.3.0", "gatsby-seo": "^0.1.0", + "gatsby-source-filesystem": "^3.3.0", "glob": "^7.1.3", "react": "^16.9.0", "react-dom": "^16.9.0", @@ -51,6 +51,7 @@ "devDependencies": { "cross-env": "^5.2.0", "fs-extra": "^7.0.1", + "gatsby-core-utils": "^2.12.0", "is-ci": "^2.0.0", "prettier": "2.0.4", "start-server-and-test": "^1.7.1" diff --git a/integration-tests/ssr/package.json b/integration-tests/ssr/package.json index 453202cc614e1..8b74e6f0fa9c2 100644 --- a/integration-tests/ssr/package.json +++ b/integration-tests/ssr/package.json @@ -14,16 +14,17 @@ "tailwindcss": "1" }, "devDependencies": { + "cheerio": "^1.0.0-rc.9", "cross-env": "^5.0.2", "fs-extra": "^9.0.0", + "gatsby-core-utils": "^2.12.0", "jest": "^24.0.0", "jest-diff": "^24.0.0", "jest-serializer-path": "^0.1.15", - "npm-run-all": "4.1.5", - "start-server-and-test": "^1.11.3", "node-fetch": "^2.6.1", + "npm-run-all": "4.1.5", "prettier": "^2.3.1", - "cheerio": "^1.0.0-rc.9", + "start-server-and-test": "^1.11.3", "strip-ansi": "^6.0.0" }, "license": "MIT", diff --git a/packages/gatsby-core-utils/src/__tests__/page-data.ts b/packages/gatsby-core-utils/src/__tests__/page-data.ts index 4c7ea7ae2a4f4..e9a22076b2a09 100644 --- a/packages/gatsby-core-utils/src/__tests__/page-data.ts +++ b/packages/gatsby-core-utils/src/__tests__/page-data.ts @@ -1,13 +1,26 @@ +import os from "os" import { generatePageDataPath } from "../page-data" describe(`page-data`, () => { it(`returns correct page data path`, () => { - expect(generatePageDataPath(`public`, `/path/1`)).toBe( - `public/page-data/path/1/page-data.json` - ) + if (os.platform() !== `win32`) { + expect(generatePageDataPath(`public`, `/path/1`)).toBe( + `public/page-data/path/1/page-data.json` + ) - expect(generatePageDataPath(`public`, `/`)).toBe( - `public/page-data/index/page-data.json` - ) + expect(generatePageDataPath(`public`, `/`)).toBe( + `public/page-data/index/page-data.json` + ) + } + + if (os.platform() === `win32`) { + expect(generatePageDataPath(`public`, `/path/1`)).toBe( + `public\\page-data\\path\\1\\page-data.json` + ) + + expect(generatePageDataPath(`public`, `/`)).toBe( + `public\\page-data\\index\\page-data.json` + ) + } }) }) diff --git a/packages/gatsby-core-utils/src/__tests__/page-html.ts b/packages/gatsby-core-utils/src/__tests__/page-html.ts index 8374c34fa3091..191e855f386ae 100644 --- a/packages/gatsby-core-utils/src/__tests__/page-html.ts +++ b/packages/gatsby-core-utils/src/__tests__/page-html.ts @@ -1,13 +1,26 @@ +import os from "os" import { generateHtmlPath } from "../page-html" describe(`page-html`, () => { it(`returns correct html path`, () => { - expect(generateHtmlPath(`public`, `/path/1`)).toBe( - `public/path/1/index.html` - ) + if (os.platform() !== `win32`) { + expect(generateHtmlPath(`public`, `/path/1`)).toBe( + `public/path/1/index.html` + ) - expect(generateHtmlPath(`public`, `/path/1/index.html`)).toBe( - `public/path/1/index.html` - ) + expect(generateHtmlPath(`public`, `/path/1/index.html`)).toBe( + `public/path/1/index.html` + ) + } + + if (os.platform() === `win32`) { + expect(generateHtmlPath(`public`, `/path/1`)).toBe( + `public\\path\\1\\index.html` + ) + + expect(generateHtmlPath(`public`, `/path/1/index.html`)).toBe( + `public\\path\\1\\index.html` + ) + } }) }) diff --git a/packages/gatsby-core-utils/src/page-html.ts b/packages/gatsby-core-utils/src/page-html.ts index 718d6d2bdc741..c8850c3c66441 100644 --- a/packages/gatsby-core-utils/src/page-html.ts +++ b/packages/gatsby-core-utils/src/page-html.ts @@ -1,4 +1,3 @@ -import fs from "fs-extra" import path from "path" const checkForHtmlSuffix = (pagePath: string): boolean => @@ -13,9 +12,3 @@ export function generateHtmlPath(dir: string, outputPath: string): string { return path.join(dir, outputFileName) } - -export async function remove({ publicDir }, pagePath): Promise { - const filePath = generateHtmlPath(publicDir, pagePath) - - return fs.remove(filePath) -} From 642883d2e6ae626f1d95cf98241e11b639e47e6d Mon Sep 17 00:00:00 2001 From: LekoArts Date: Mon, 23 Aug 2021 13:21:53 +0200 Subject: [PATCH 14/16] revert cache-dir changes --- packages/gatsby/cache-dir/ssr-develop-static-entry.js | 7 ++++--- packages/gatsby/cache-dir/static-entry.js | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/gatsby/cache-dir/ssr-develop-static-entry.js b/packages/gatsby/cache-dir/ssr-develop-static-entry.js index 7cb499c7200f7..5ae855a2548f2 100644 --- a/packages/gatsby/cache-dir/ssr-develop-static-entry.js +++ b/packages/gatsby/cache-dir/ssr-develop-static-entry.js @@ -5,7 +5,6 @@ import { renderToString, renderToStaticMarkup } from "react-dom/server" import { get, merge, isObject, flatten, uniqBy, concat } from "lodash" import nodePath from "path" import { ServerLocation, Router, isRedirect } from "@reach/router" -import { fixedPagePath } from "gatsby-core-utils" import { apiRunner, apiRunnerAsync } from "./api-runner-ssr" import { grabMatchParams } from "./find-path" import syncRequires from "$virtual/ssr-sync-requires" @@ -139,8 +138,10 @@ export default async function staticPage( postBodyComponents = components } - const getPageDataPath = path => - nodePath.join(`page-data`, fixedPagePath(path), `page-data.json`) + const getPageDataPath = path => { + const fixedPagePath = path === `/` ? `index` : path + return nodePath.join(`page-data`, fixedPagePath(path), `page-data.json`) + } const getPageData = pagePath => { const pageDataPath = getPageDataPath(pagePath) diff --git a/packages/gatsby/cache-dir/static-entry.js b/packages/gatsby/cache-dir/static-entry.js index 9667dee7f230a..4fd280bc0ae52 100644 --- a/packages/gatsby/cache-dir/static-entry.js +++ b/packages/gatsby/cache-dir/static-entry.js @@ -8,7 +8,6 @@ const { const { ServerLocation, Router, isRedirect } = require(`@gatsbyjs/reach-router`) const { merge, flattenDeep, replace } = require(`lodash`) const { StaticQueryContext } = require(`gatsby`) -const { fixedPagePath } = require(`gatsby-core-utils`) const fs = require(`fs`) const { RouteAnnouncerProps } = require(`./route-announcer-props`) @@ -45,8 +44,10 @@ try { Html = Html && Html.__esModule ? Html.default : Html -const getPageDataPath = path => - join(`page-data`, fixedPagePath(path), `page-data.json`) +const getPageDataPath = path => { + const fixedPagePath = path === `/` ? `index` : path + return join(`page-data`, fixedPagePath(path), `page-data.json`) +} const getPageDataUrl = pagePath => { const pageDataPath = getPageDataPath(pagePath) From aea35cf623840aeac6d0fc2a50261824caf75023 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Mon, 23 Aug 2021 13:26:11 +0200 Subject: [PATCH 15/16] add deps --- packages/gatsby-plugin-gatsby-cloud/package.json | 1 + packages/gatsby-plugin-netlify/package.json | 1 + packages/gatsby/cache-dir/ssr-develop-static-entry.js | 4 ++-- packages/gatsby/cache-dir/static-entry.js | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-plugin-gatsby-cloud/package.json b/packages/gatsby-plugin-gatsby-cloud/package.json index 4c60d3b69c35a..3fb53dd9652c3 100644 --- a/packages/gatsby-plugin-gatsby-cloud/package.json +++ b/packages/gatsby-plugin-gatsby-cloud/package.json @@ -10,6 +10,7 @@ "@babel/runtime": "^7.14.8", "date-fns": "^2.22.1", "fs-extra": "^8.1.0", + "gatsby-core-utils": "^2.13.0-next.0", "gatsby-telemetry": "^2.13.0-next.0", "kebab-hash": "^0.1.2", "lodash": "^4.17.21", diff --git a/packages/gatsby-plugin-netlify/package.json b/packages/gatsby-plugin-netlify/package.json index 3ab47441711e4..afdcf80ac9183 100644 --- a/packages/gatsby-plugin-netlify/package.json +++ b/packages/gatsby-plugin-netlify/package.json @@ -15,6 +15,7 @@ "dependencies": { "@babel/runtime": "^7.14.8", "fs-extra": "^8.1.0", + "gatsby-core-utils": "^2.13.0-next.0", "kebab-hash": "^0.1.2", "lodash": "^4.17.21", "webpack-assets-manifest": "^5.0.6" diff --git a/packages/gatsby/cache-dir/ssr-develop-static-entry.js b/packages/gatsby/cache-dir/ssr-develop-static-entry.js index 5ae855a2548f2..e67a275dc05d0 100644 --- a/packages/gatsby/cache-dir/ssr-develop-static-entry.js +++ b/packages/gatsby/cache-dir/ssr-develop-static-entry.js @@ -4,12 +4,12 @@ import fs from "fs" import { renderToString, renderToStaticMarkup } from "react-dom/server" import { get, merge, isObject, flatten, uniqBy, concat } from "lodash" import nodePath from "path" -import { ServerLocation, Router, isRedirect } from "@reach/router" import { apiRunner, apiRunnerAsync } from "./api-runner-ssr" import { grabMatchParams } from "./find-path" import syncRequires from "$virtual/ssr-sync-requires" import { RouteAnnouncerProps } from "./route-announcer-props" +import { ServerLocation, Router, isRedirect } from "@reach/router" // import testRequireError from "./test-require-error" // For some extremely mysterious reason, webpack adds the above module *after* @@ -140,7 +140,7 @@ export default async function staticPage( const getPageDataPath = path => { const fixedPagePath = path === `/` ? `index` : path - return nodePath.join(`page-data`, fixedPagePath(path), `page-data.json`) + return nodePath.join(`page-data`, fixedPagePath, `page-data.json`) } const getPageData = pagePath => { diff --git a/packages/gatsby/cache-dir/static-entry.js b/packages/gatsby/cache-dir/static-entry.js index 4fd280bc0ae52..af702b2884f71 100644 --- a/packages/gatsby/cache-dir/static-entry.js +++ b/packages/gatsby/cache-dir/static-entry.js @@ -46,7 +46,7 @@ Html = Html && Html.__esModule ? Html.default : Html const getPageDataPath = path => { const fixedPagePath = path === `/` ? `index` : path - return join(`page-data`, fixedPagePath(path), `page-data.json`) + return join(`page-data`, fixedPagePath, `page-data.json`) } const getPageDataUrl = pagePath => { From 4f12b2bb8461f2b27ed772b1434e0fe7feaaad0c Mon Sep 17 00:00:00 2001 From: LekoArts Date: Mon, 23 Aug 2021 13:48:01 +0200 Subject: [PATCH 16/16] fix remove function --- packages/gatsby-core-utils/src/page-html.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/gatsby-core-utils/src/page-html.ts b/packages/gatsby-core-utils/src/page-html.ts index c8850c3c66441..39b6d043f8a3c 100644 --- a/packages/gatsby-core-utils/src/page-html.ts +++ b/packages/gatsby-core-utils/src/page-html.ts @@ -1,3 +1,4 @@ +import fs from "fs-extra" import path from "path" const checkForHtmlSuffix = (pagePath: string): boolean => @@ -12,3 +13,14 @@ export function generateHtmlPath(dir: string, outputPath: string): string { return path.join(dir, outputFileName) } + +export async function remove( + { publicDir }: { publicDir: string }, + pagePath: string +): Promise { + const filePath = generateHtmlPath(publicDir, pagePath) + if (fs.existsSync(filePath)) { + return await fs.remove(filePath) + } + return Promise.resolve() +}