From b01240d67000a0ffd3ca09f46c52a9466a5d56d3 Mon Sep 17 00:00:00 2001 From: jwartofsky Date: Wed, 6 Sep 2023 18:26:20 -0400 Subject: [PATCH 01/14] fix(dev): fix dev and tests on Windows Fixes issues with paths in various places. Convert to posix paths in globSync and Windows paths for filepaths when appropriate. Unit tests pass and npm run dev works as expected. Pages are fully functional and appear the same as on MacOS. --- .../internal/functionMetadataParser.ts | 10 +++-- .../internal/getFunctionFilepaths.test.ts | 29 ++++++++------- .../function/internal/getFunctionFilepaths.ts | 5 ++- .../src/function/internal/loader.test.ts | 9 +++-- .../src/function/internal/types.test.ts | 35 ++++++++++-------- .../internal/getTemplateFilepaths.test.ts | 26 +++++++------ .../template/internal/getTemplateFilepaths.ts | 5 ++- .../src/template/internal/loader.test.ts | 7 +++- .../src/template/internal/types.test.ts | 21 ++++++----- .../src/common/src/template/internal/types.ts | 3 +- .../src/common/src/template/paths.test.ts | 37 +++++++++++++++++-- .../pages/src/common/src/template/paths.ts | 11 +++++- .../dev/server/ssr/generateTestData.test.ts | 3 +- packages/pages/src/util/runSubprocess.test.ts | 7 +++- 14 files changed, 139 insertions(+), 69 deletions(-) diff --git a/packages/pages/src/common/src/function/internal/functionMetadataParser.ts b/packages/pages/src/common/src/function/internal/functionMetadataParser.ts index 1414c5540..09a705975 100644 --- a/packages/pages/src/common/src/function/internal/functionMetadataParser.ts +++ b/packages/pages/src/common/src/function/internal/functionMetadataParser.ts @@ -42,10 +42,12 @@ export class FunctionMetadataParser { const testsPath = path.join("tests", "fixtures", "src", "functions"); // The path after /src/functions - const relativePath = absolutePathToFunction.split(`/${sourcePath}/`)[1]; + const relativePath = absolutePathToFunction.split( + `${path.sep}${sourcePath}${path.sep}` + )[1]; // Should be onUrlChange or http - const functionType = relativePath.split("/")[0]; + const functionType = relativePath.split(path.sep)[0]; if (!validFunctionTypes.find((ft) => ft === functionType)) { throw new Error( `Cannot load ${absolutePathToFunction}.\n` + @@ -64,7 +66,7 @@ export class FunctionMetadataParser { if ( functionType === "onUrlChange" && - relativePath.split("/").length > 2 && + relativePath.split(path.sep).length > 2 && functionsRoot !== distPath ) { throw new Error( @@ -76,7 +78,7 @@ export class FunctionMetadataParser { // Slug is defined by the path and filename const defaultSlug = relativePath - .replace(`${functionType}/`, "") + .replace(`${functionType}${path.sep}`, "") .split(".") .slice(0, -1) .join("."); diff --git a/packages/pages/src/common/src/function/internal/getFunctionFilepaths.test.ts b/packages/pages/src/common/src/function/internal/getFunctionFilepaths.test.ts index 8fb401787..e8e8af5a7 100644 --- a/packages/pages/src/common/src/function/internal/getFunctionFilepaths.test.ts +++ b/packages/pages/src/common/src/function/internal/getFunctionFilepaths.test.ts @@ -1,42 +1,43 @@ import path from "path"; import { getFunctionFilepaths } from "./getFunctionFilepaths.js"; import { minimatch } from "minimatch"; +import { convertToOSPath } from "../../template/paths.js"; const rootPath = "src/functions"; const multiLevelPath = "src/functions/http/api/fetch"; const filepaths = [ - `${multiLevelPath}/test1.ts`, - `${multiLevelPath}/test2.js`, - `${rootPath}/test3.js`, - `${rootPath}/test4.ts`, + convertToOSPath(`${multiLevelPath}/test1.ts`), + convertToOSPath(`${multiLevelPath}/test2.js`), + convertToOSPath(`${rootPath}/test3.js`), + convertToOSPath(`${rootPath}/test4.ts`), ]; const expected = [ { - root: "/", - dir: process.cwd() + "/src/functions/http/api/fetch", + root: path.resolve("/"), + dir: convertToOSPath(process.cwd() + "/src/functions/http/api/fetch"), base: "test1.ts", ext: ".ts", name: "test1", }, { - root: "/", - dir: process.cwd() + "/src/functions/http/api/fetch", + root: path.resolve("/"), + dir: convertToOSPath(process.cwd() + "/src/functions/http/api/fetch"), base: "test2.js", ext: ".js", name: "test2", }, { - root: "/", - dir: process.cwd() + "/src/functions", + root: path.resolve("/"), + dir: convertToOSPath(process.cwd() + "/src/functions"), base: "test3.js", ext: ".js", name: "test3", }, { - root: "/", - dir: process.cwd() + "/src/functions", + root: path.resolve("/"), + dir: convertToOSPath(process.cwd() + "/src/functions"), base: "test4.ts", ext: ".ts", name: "test4", @@ -53,7 +54,9 @@ jest.mock("glob", () => { describe("getFunctionFilepaths", () => { it("collects all function files under the src/functions path", () => { - const templatesFilepath = getFunctionFilepaths("src/functions"); + const templatesFilepath = getFunctionFilepaths( + convertToOSPath("src/functions") + ); expect(JSON.stringify(templatesFilepath.sort())).toEqual( JSON.stringify(expected) ); diff --git a/packages/pages/src/common/src/function/internal/getFunctionFilepaths.ts b/packages/pages/src/common/src/function/internal/getFunctionFilepaths.ts index f2f4b5f8e..d33a2e3ac 100644 --- a/packages/pages/src/common/src/function/internal/getFunctionFilepaths.ts +++ b/packages/pages/src/common/src/function/internal/getFunctionFilepaths.ts @@ -1,6 +1,7 @@ import { globSync } from "glob"; import path from "path"; import { Path } from "../../project/path.js"; +import { convertToPosixPath } from "../../template/paths.js"; /** * Get all the functions files in a directory @@ -11,7 +12,9 @@ export const getFunctionFilepaths = (root: string): path.ParsedPath[] => { const functionsRoot = new Path(root); // resolve the functions root // Get all js/ts files in the directory or subdirectories const filepaths = globSync( - `${functionsRoot.getAbsolutePath()}/**/*.{tsx,jsx,js,ts}` + convertToPosixPath( + `${functionsRoot.getAbsolutePath()}/**/*.{tsx,jsx,js,ts}` + ) ); return filepaths.map((filepath) => { diff --git a/packages/pages/src/common/src/function/internal/loader.test.ts b/packages/pages/src/common/src/function/internal/loader.test.ts index aebd4660e..39b0dbe83 100644 --- a/packages/pages/src/common/src/function/internal/loader.test.ts +++ b/packages/pages/src/common/src/function/internal/loader.test.ts @@ -1,6 +1,7 @@ import path from "path"; import { loadFunctionModules, FunctionModuleCollection } from "./loader.js"; import { ProjectStructure } from "../../project/structure.js"; +import { convertToOSPath } from "../../template/paths.js"; // our jest configuration doesn't support file urls so update pathToFileURL to do nothing during // this test. @@ -26,7 +27,9 @@ describe("loadTemplateModules", () => { it("loads and transpiles raw templates", async () => { const functionFile: path.ParsedPath[] = [ - path.parse("tests/fixtures/src/functions/http/[param].ts"), + path.parse( + convertToOSPath("tests/fixtures/src/functions/http/[param].ts") + ), ]; const functionModules = await loadFunctionModules( @@ -34,7 +37,7 @@ describe("loadTemplateModules", () => { true, projectStructure ); - commonTests(functionModules, "param-47543"); + commonTests(functionModules, "param-19926"); }); it("loads transpiled templates", async () => { @@ -46,7 +49,7 @@ describe("loadTemplateModules", () => { false, projectStructure ); - commonTests(functionModules, "param-47853"); + commonTests(functionModules, "param-19616"); }); const commonTests = ( diff --git a/packages/pages/src/common/src/function/internal/types.test.ts b/packages/pages/src/common/src/function/internal/types.test.ts index 2d557ddd9..e29e9b280 100644 --- a/packages/pages/src/common/src/function/internal/types.test.ts +++ b/packages/pages/src/common/src/function/internal/types.test.ts @@ -10,6 +10,7 @@ import { } from "../types.js"; import { mockSiteInfo } from "../../../../dev/server/middleware/serveHttpFunction.js"; import { ProjectStructure } from "../../project/structure.js"; +import { convertToOSPath } from "../../template/paths.js"; const exampleReturnValue: SitesHttpResponse = { body: "Hello World", @@ -51,7 +52,9 @@ const exampleOnUrlChangeArgument: SitesOnUrlChangeRequest = { }; const createMockFilePath = (filepath: string): path.ParsedPath => { - return path.parse(path.resolve(path.join("src/functions/", filepath))); + return path.parse( + path.resolve(convertToOSPath(path.join("src/functions/", filepath))) + ); }; describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => { @@ -69,21 +72,21 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => ); const expected = { config: { - name: "example-01535", + name: "example-23673", functionName: "default", event: "API", }, filePath: { - root: "/", - dir: process.cwd() + "/src/functions/http/api", + root: path.resolve("/"), + dir: convertToOSPath(process.cwd() + "/src/functions/http/api"), base: "example.ts", ext: ".ts", name: "example", }, slug: { - original: "api/example", - dev: "api/example", - production: "api/example", + original: convertToOSPath("api/example"), + dev: convertToOSPath("api/example"), + production: convertToOSPath("api/example"), }, }; expect(JSON.stringify(functionModuleInternal)).toEqual( @@ -113,13 +116,13 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => ); const expected = { config: { - name: "example-55662", + name: "example-11807", functionName: "default", event: "ON_URL_CHANGE", }, filePath: { - root: "/", - dir: process.cwd() + "/src/functions/onUrlChange", + root: path.resolve("/"), + dir: convertToOSPath(process.cwd() + "/src/functions/onUrlChange"), base: "example.ts", ext: ".ts", name: "example", @@ -155,21 +158,21 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => ); const expected = { config: { - name: "testParam-00975", + name: "testParam-61704", functionName: "default", event: "API", }, filePath: { - root: "/", - dir: process.cwd() + "/src/functions/http/api/example", + root: path.resolve("/"), + dir: convertToOSPath(process.cwd() + "/src/functions/http/api/example"), base: "[testParam].ts", ext: ".ts", name: "[testParam]", }, slug: { - original: "api/example/[testParam]", - dev: "api/example/:testParam", - production: "api/example/{{testParam}}", + original: convertToOSPath("api/example/[testParam]"), + dev: convertToOSPath("api/example/:testParam"), + production: convertToOSPath("api/example/{{testParam}}"), }, }; expect(JSON.stringify(functionModuleInternal)).toEqual( diff --git a/packages/pages/src/common/src/template/internal/getTemplateFilepaths.test.ts b/packages/pages/src/common/src/template/internal/getTemplateFilepaths.test.ts index 61e56276d..4421e1d4d 100644 --- a/packages/pages/src/common/src/template/internal/getTemplateFilepaths.test.ts +++ b/packages/pages/src/common/src/template/internal/getTemplateFilepaths.test.ts @@ -2,6 +2,7 @@ import path from "path"; import { getTemplateFilepaths } from "./getTemplateFilepaths.js"; import { minimatch } from "minimatch"; import { Path } from "../../project/path.js"; +import { convertToOSPath } from "../paths.js"; const rootPath = "src/templates"; const domain1Path = "src/templates/some.domain1.com"; @@ -10,12 +11,12 @@ jest.mock("glob", () => { return { globSync: (glob: string) => { const filepaths = [ - `${domain1Path}/brand1.tsx`, - `${domain1Path}/test.tsx`, - `${domain2Path}/brand2.tsx`, - `${domain2Path}/test.tsx`, - `${rootPath}/share.tsx`, - `${rootPath}/test.tsx`, + convertToOSPath(`${domain1Path}/brand1.tsx`), + convertToOSPath(`${domain1Path}/test.tsx`), + convertToOSPath(`${domain2Path}/brand2.tsx`), + convertToOSPath(`${domain2Path}/test.tsx`), + convertToOSPath(`${rootPath}/share.tsx`), + convertToOSPath(`${rootPath}/test.tsx`), ]; return filepaths.filter((f) => minimatch(path.resolve(f), glob)); }, @@ -25,10 +26,13 @@ jest.mock("glob", () => { describe("getTemplateFilepaths", () => { it("collects all template files from root folder path", () => { const templatesFilepath = getTemplateFilepaths([ - new Path(path.join(process.cwd(), rootPath)), + new Path(convertToOSPath(path.join(process.cwd(), rootPath))), ]); expect(templatesFilepath.sort()).toEqual( - [`${rootPath}/share.tsx`, `${rootPath}/test.tsx`].sort() + [ + convertToOSPath(`${rootPath}/share.tsx`), + convertToOSPath(`${rootPath}/test.tsx`), + ].sort() ); }); @@ -39,9 +43,9 @@ describe("getTemplateFilepaths", () => { ]); expect(templatesFilepath.sort()).toEqual( [ - `${rootPath}/share.tsx`, - `${domain1Path}/test.tsx`, - `${domain1Path}/brand1.tsx`, + convertToOSPath(`${rootPath}/share.tsx`), + convertToOSPath(`${domain1Path}/test.tsx`), + convertToOSPath(`${domain1Path}/brand1.tsx`), ].sort() ); }); diff --git a/packages/pages/src/common/src/template/internal/getTemplateFilepaths.ts b/packages/pages/src/common/src/template/internal/getTemplateFilepaths.ts index ac084b52f..b333e1b1a 100644 --- a/packages/pages/src/common/src/template/internal/getTemplateFilepaths.ts +++ b/packages/pages/src/common/src/template/internal/getTemplateFilepaths.ts @@ -6,6 +6,7 @@ import { ProjectStructure } from "../../project/structure.js"; import { ClientServerRenderTemplates } from "../types.js"; import fs from "node:fs"; import { fileURLToPath } from "node:url"; +import { convertToPosixPath } from "../paths.js"; /** * Get all the template files in the provided template folder path(s). @@ -21,7 +22,9 @@ export const getTemplateFilepaths = (paths: Path[]): string[] => { const templateFilepaths: string[] = []; const addedFilenames: Set = new Set(); paths.forEach((p) => { - const filepaths = globSync(`${p.getAbsolutePath()}/*.{tsx,jsx,js,ts}`); + const filepaths = globSync( + convertToPosixPath(`${p.getAbsolutePath()}/*.{tsx,jsx,js,ts}`) + ); filepaths // Don't include the client/server rendering templates .filter( diff --git a/packages/pages/src/common/src/template/internal/loader.test.ts b/packages/pages/src/common/src/template/internal/loader.test.ts index d96c55de9..b883ac26d 100644 --- a/packages/pages/src/common/src/template/internal/loader.test.ts +++ b/packages/pages/src/common/src/template/internal/loader.test.ts @@ -1,6 +1,7 @@ import { glob } from "glob"; import path from "path"; import { loadTemplateModules } from "./loader.js"; +import { convertToPosixPath } from "../paths.js"; // our jest configuration doesn't support file urls so update pathToFileURL to do nothing during // this test. @@ -23,7 +24,9 @@ afterAll(() => jest.unmock("url")); describe("loadTemplateModules", () => { it("loads and transpiles raw templates", async () => { const templateFile = glob.sync( - path.join(process.cwd(), "tests/fixtures/template.tsx") + convertToPosixPath( + path.join(process.cwd(), "tests/fixtures/template.tsx") + ) ); const templateModules = await loadTemplateModules( templateFile, @@ -36,7 +39,7 @@ describe("loadTemplateModules", () => { it("loads transpiled templates", async () => { const templateFile = glob.sync( - path.join(process.cwd(), "tests/fixtures/template.js") + convertToPosixPath(path.join(process.cwd(), "tests/fixtures/template.js")) ); const templateModules = await loadTemplateModules( templateFile, diff --git a/packages/pages/src/common/src/template/internal/types.test.ts b/packages/pages/src/common/src/template/internal/types.test.ts index d01ec2cdb..b4c8db388 100644 --- a/packages/pages/src/common/src/template/internal/types.test.ts +++ b/packages/pages/src/common/src/template/internal/types.test.ts @@ -3,6 +3,7 @@ import { TemplateModuleInternal, } from "./types.js"; import { Template, TemplateModule } from "../types.js"; +import { convertToOSPath } from "../paths.js"; describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => { it("uses the filename as the config name when not set", async () => { @@ -22,7 +23,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - "src/templates/myTemplateName.tsx", + convertToOSPath("src/templates/myTemplateName.tsx"), templateModule, false ); @@ -40,7 +41,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: "src/templates/myTemplateName.tsx", + path: convertToOSPath("src/templates/myTemplateName.tsx"), filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -63,7 +64,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - "src/templates/myTemplateName.tsx", + convertToOSPath("src/templates/myTemplateName.tsx"), templateModule, false ); @@ -76,7 +77,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: "src/templates/myTemplateName.tsx", + path: convertToOSPath("src/templates/myTemplateName.tsx"), filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -98,7 +99,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - "src/templates/myTemplateName.0ab33d.tsx", + convertToOSPath("src/templates/myTemplateName.0ab33d.tsx"), templateModule, true ); @@ -111,7 +112,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: "src/templates/myTemplateName.0ab33d.tsx", + path: convertToOSPath("src/templates/myTemplateName.0ab33d.tsx"), filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -137,7 +138,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - "src/templates/myTemplateName.tsx", + convertToOSPath("src/templates/myTemplateName.tsx"), templateModule, false ); @@ -155,7 +156,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: true, streamId: "$id", }, - path: "src/templates/myTemplateName.tsx", + path: convertToOSPath("src/templates/myTemplateName.tsx"), filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -182,7 +183,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - "src/templates/myTemplateName.tsx", + convertToOSPath("src/templates/myTemplateName.tsx"), templateModule, false ); @@ -200,7 +201,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: "src/templates/myTemplateName.tsx", + path: convertToOSPath("src/templates/myTemplateName.tsx"), filename: "myTemplateName.tsx", templateName: "myTemplateName", }; diff --git a/packages/pages/src/common/src/template/internal/types.ts b/packages/pages/src/common/src/template/internal/types.ts index f69dc2af5..326f4919e 100644 --- a/packages/pages/src/common/src/template/internal/types.ts +++ b/packages/pages/src/common/src/template/internal/types.ts @@ -11,6 +11,7 @@ import { TemplateProps, TemplateRenderProps, } from "../types.js"; +import path from "node:path"; import { validateTemplateModuleInternal } from "./validateTemplateModuleInternal.js"; /** @@ -104,7 +105,7 @@ export const parse = ( filepath: string, adjustForFingerprintedAsset: boolean ) => { - let base = filepath.split("/")[filepath.split("/").length - 1]; + let base = filepath.split(path.sep)[filepath.split(path.sep).length - 1]; const extension = base.slice(base.lastIndexOf(".")); let name = base.slice(0, base.lastIndexOf(".")); diff --git a/packages/pages/src/common/src/template/paths.test.ts b/packages/pages/src/common/src/template/paths.test.ts index 0e04283f7..34f5d013d 100644 --- a/packages/pages/src/common/src/template/paths.test.ts +++ b/packages/pages/src/common/src/template/paths.test.ts @@ -1,6 +1,16 @@ -import { getRelativePrefixToRootFromPath } from "../../src/template/paths.js"; +import { + convertToOSPath, + convertToPosixPath, + getRelativePrefixToRootFromPath, +} from "../../src/template/paths.js"; +import path from "node:path"; describe("getRelativePrefixToRootFromPath", () => { + const relativePath = "spaghetti/meatballs"; + const relativeWinPath = "spaghetti\\meatballs"; + const absolutePath = "/enchilada/burrito/taco"; + const absoluteWinPath = "\\enchilada\\burrito\\taco"; + it("properly returns the empty string when on root level", async () => { const path = "foobar.txt"; @@ -12,12 +22,33 @@ describe("getRelativePrefixToRootFromPath", () => { }); it("properly returns the relative directory prefix when deeper than root level", async () => { - const path = "foo/bar/foo/foobar.txt"; + const p = "foo/bar/foo/foobar.txt"; const expectedRelativePathPrefix = "../../../"; - expect(getRelativePrefixToRootFromPath(path)).toEqual( + expect(getRelativePrefixToRootFromPath(p)).toEqual( expectedRelativePathPrefix ); }); + + it("convert to OS path", async () => { + if (path.sep === path.posix.sep) { + expect(convertToOSPath(relativePath)).toEqual(relativePath); + expect(convertToOSPath(relativeWinPath)).toEqual(relativePath); + expect(convertToOSPath(absolutePath)).toEqual(absolutePath); + expect(convertToOSPath(absoluteWinPath)).toEqual(absolutePath); + } else { + expect(convertToOSPath(relativePath)).toEqual("spaghetti\\meatballs"); + expect(convertToOSPath(relativeWinPath)).toEqual(relativeWinPath); + expect(convertToOSPath(absolutePath)).toEqual(absoluteWinPath); + expect(convertToOSPath(absoluteWinPath)).toEqual(absoluteWinPath); + } + }); + + it("convert to posix path", async () => { + expect(convertToPosixPath(relativePath)).toEqual(relativePath); + expect(convertToPosixPath(relativeWinPath)).toEqual(relativePath); + expect(convertToPosixPath(absolutePath)).toEqual(absolutePath); + expect(convertToPosixPath(absoluteWinPath)).toEqual(absolutePath); + }); }); diff --git a/packages/pages/src/common/src/template/paths.ts b/packages/pages/src/common/src/template/paths.ts index 1b0cf990e..2cbbc427a 100644 --- a/packages/pages/src/common/src/template/paths.ts +++ b/packages/pages/src/common/src/template/paths.ts @@ -1,5 +1,7 @@ import path from "node:path"; +const winSep = "\\"; + /** * Function that takes a path to a generated template and returns the * relative path to the root of the site. Will return the empty string @@ -21,5 +23,12 @@ export const getRelativePrefixToRootFromPath = (path: string): string => { * paths are supported with import. */ export const convertToPosixPath = (p: string) => { - return p.split(path.sep).join(path.posix.sep); + return p.split(winSep).join(path.posix.sep); +}; + +/** + * Convert any path to match the format of the OS. If it already matches no change occurs. + */ +export const convertToOSPath = (p: string) => { + return p.split(path.posix.sep).join(path.sep).split(winSep).join(path.sep); }; diff --git a/packages/pages/src/dev/server/ssr/generateTestData.test.ts b/packages/pages/src/dev/server/ssr/generateTestData.test.ts index 59fc7c2d3..24e55eecc 100644 --- a/packages/pages/src/dev/server/ssr/generateTestData.test.ts +++ b/packages/pages/src/dev/server/ssr/generateTestData.test.ts @@ -1,4 +1,3 @@ -import { WriteStream } from "tty"; import { generateTestDataForPage } from "./generateTestData.js"; import { EventEmitter } from "stream"; import { @@ -18,7 +17,7 @@ import { import { Socket } from "net"; import { ProjectStructure } from "../../../common/src/project/structure.js"; -const mockParentProcessStdout = jest.mocked(new WriteStream(0)); +const mockParentProcessStdout = jest.mocked(process.stdout); mockParentProcessStdout.write = jest.fn(); const mockChildProcessEventEmitter = new EventEmitter(); diff --git a/packages/pages/src/util/runSubprocess.test.ts b/packages/pages/src/util/runSubprocess.test.ts index c0f561348..f40e9f20f 100644 --- a/packages/pages/src/util/runSubprocess.test.ts +++ b/packages/pages/src/util/runSubprocess.test.ts @@ -1,4 +1,5 @@ import runSubprocess from "./runSubprocess.js"; +import path from "node:path"; describe("runSubprocess", () => { it("runs echo successfully", async () => { @@ -8,6 +9,10 @@ describe("runSubprocess", () => { it("returns non-zero when subprocess fails", async () => { const exitCode = await runSubprocess("echo", ["$((0/0))"]); - expect(exitCode).not.toEqual(0); + if (path.sep === path.posix.sep) { + expect(exitCode).not.toEqual(0); + } + // commands do not return exit codes on Windows, so we skip this test in that case + expect(true).toEqual(true); }); }); From 49b5784ef50fbed94817bfc704c6ad81d4bd560b Mon Sep 17 00:00:00 2001 From: jwartofsky Date: Wed, 6 Sep 2023 18:26:20 -0400 Subject: [PATCH 02/14] fix(dev): fix dev and tests on Windows Fixes issues with paths in various places. Convert to posix paths in globSync and Windows paths for filepaths when appropriate. Unit tests pass and npm run dev works as expected. Pages are fully functional and appear the same as on MacOS. --- .../internal/functionMetadataParser.ts | 10 +++-- .../internal/getFunctionFilepaths.test.ts | 29 ++++++++------- .../function/internal/getFunctionFilepaths.ts | 5 ++- .../src/function/internal/loader.test.ts | 9 +++-- .../src/function/internal/types.test.ts | 35 ++++++++++-------- .../internal/getTemplateFilepaths.test.ts | 26 +++++++------ .../template/internal/getTemplateFilepaths.ts | 5 ++- .../src/template/internal/loader.test.ts | 7 +++- .../src/template/internal/types.test.ts | 21 ++++++----- .../src/common/src/template/internal/types.ts | 3 +- .../src/common/src/template/paths.test.ts | 37 +++++++++++++++++-- .../pages/src/common/src/template/paths.ts | 11 +++++- .../dev/server/ssr/generateTestData.test.ts | 3 +- packages/pages/src/util/runSubprocess.test.ts | 7 +++- 14 files changed, 139 insertions(+), 69 deletions(-) diff --git a/packages/pages/src/common/src/function/internal/functionMetadataParser.ts b/packages/pages/src/common/src/function/internal/functionMetadataParser.ts index 1414c5540..09a705975 100644 --- a/packages/pages/src/common/src/function/internal/functionMetadataParser.ts +++ b/packages/pages/src/common/src/function/internal/functionMetadataParser.ts @@ -42,10 +42,12 @@ export class FunctionMetadataParser { const testsPath = path.join("tests", "fixtures", "src", "functions"); // The path after /src/functions - const relativePath = absolutePathToFunction.split(`/${sourcePath}/`)[1]; + const relativePath = absolutePathToFunction.split( + `${path.sep}${sourcePath}${path.sep}` + )[1]; // Should be onUrlChange or http - const functionType = relativePath.split("/")[0]; + const functionType = relativePath.split(path.sep)[0]; if (!validFunctionTypes.find((ft) => ft === functionType)) { throw new Error( `Cannot load ${absolutePathToFunction}.\n` + @@ -64,7 +66,7 @@ export class FunctionMetadataParser { if ( functionType === "onUrlChange" && - relativePath.split("/").length > 2 && + relativePath.split(path.sep).length > 2 && functionsRoot !== distPath ) { throw new Error( @@ -76,7 +78,7 @@ export class FunctionMetadataParser { // Slug is defined by the path and filename const defaultSlug = relativePath - .replace(`${functionType}/`, "") + .replace(`${functionType}${path.sep}`, "") .split(".") .slice(0, -1) .join("."); diff --git a/packages/pages/src/common/src/function/internal/getFunctionFilepaths.test.ts b/packages/pages/src/common/src/function/internal/getFunctionFilepaths.test.ts index 8fb401787..e8e8af5a7 100644 --- a/packages/pages/src/common/src/function/internal/getFunctionFilepaths.test.ts +++ b/packages/pages/src/common/src/function/internal/getFunctionFilepaths.test.ts @@ -1,42 +1,43 @@ import path from "path"; import { getFunctionFilepaths } from "./getFunctionFilepaths.js"; import { minimatch } from "minimatch"; +import { convertToOSPath } from "../../template/paths.js"; const rootPath = "src/functions"; const multiLevelPath = "src/functions/http/api/fetch"; const filepaths = [ - `${multiLevelPath}/test1.ts`, - `${multiLevelPath}/test2.js`, - `${rootPath}/test3.js`, - `${rootPath}/test4.ts`, + convertToOSPath(`${multiLevelPath}/test1.ts`), + convertToOSPath(`${multiLevelPath}/test2.js`), + convertToOSPath(`${rootPath}/test3.js`), + convertToOSPath(`${rootPath}/test4.ts`), ]; const expected = [ { - root: "/", - dir: process.cwd() + "/src/functions/http/api/fetch", + root: path.resolve("/"), + dir: convertToOSPath(process.cwd() + "/src/functions/http/api/fetch"), base: "test1.ts", ext: ".ts", name: "test1", }, { - root: "/", - dir: process.cwd() + "/src/functions/http/api/fetch", + root: path.resolve("/"), + dir: convertToOSPath(process.cwd() + "/src/functions/http/api/fetch"), base: "test2.js", ext: ".js", name: "test2", }, { - root: "/", - dir: process.cwd() + "/src/functions", + root: path.resolve("/"), + dir: convertToOSPath(process.cwd() + "/src/functions"), base: "test3.js", ext: ".js", name: "test3", }, { - root: "/", - dir: process.cwd() + "/src/functions", + root: path.resolve("/"), + dir: convertToOSPath(process.cwd() + "/src/functions"), base: "test4.ts", ext: ".ts", name: "test4", @@ -53,7 +54,9 @@ jest.mock("glob", () => { describe("getFunctionFilepaths", () => { it("collects all function files under the src/functions path", () => { - const templatesFilepath = getFunctionFilepaths("src/functions"); + const templatesFilepath = getFunctionFilepaths( + convertToOSPath("src/functions") + ); expect(JSON.stringify(templatesFilepath.sort())).toEqual( JSON.stringify(expected) ); diff --git a/packages/pages/src/common/src/function/internal/getFunctionFilepaths.ts b/packages/pages/src/common/src/function/internal/getFunctionFilepaths.ts index f2f4b5f8e..d33a2e3ac 100644 --- a/packages/pages/src/common/src/function/internal/getFunctionFilepaths.ts +++ b/packages/pages/src/common/src/function/internal/getFunctionFilepaths.ts @@ -1,6 +1,7 @@ import { globSync } from "glob"; import path from "path"; import { Path } from "../../project/path.js"; +import { convertToPosixPath } from "../../template/paths.js"; /** * Get all the functions files in a directory @@ -11,7 +12,9 @@ export const getFunctionFilepaths = (root: string): path.ParsedPath[] => { const functionsRoot = new Path(root); // resolve the functions root // Get all js/ts files in the directory or subdirectories const filepaths = globSync( - `${functionsRoot.getAbsolutePath()}/**/*.{tsx,jsx,js,ts}` + convertToPosixPath( + `${functionsRoot.getAbsolutePath()}/**/*.{tsx,jsx,js,ts}` + ) ); return filepaths.map((filepath) => { diff --git a/packages/pages/src/common/src/function/internal/loader.test.ts b/packages/pages/src/common/src/function/internal/loader.test.ts index aebd4660e..39b0dbe83 100644 --- a/packages/pages/src/common/src/function/internal/loader.test.ts +++ b/packages/pages/src/common/src/function/internal/loader.test.ts @@ -1,6 +1,7 @@ import path from "path"; import { loadFunctionModules, FunctionModuleCollection } from "./loader.js"; import { ProjectStructure } from "../../project/structure.js"; +import { convertToOSPath } from "../../template/paths.js"; // our jest configuration doesn't support file urls so update pathToFileURL to do nothing during // this test. @@ -26,7 +27,9 @@ describe("loadTemplateModules", () => { it("loads and transpiles raw templates", async () => { const functionFile: path.ParsedPath[] = [ - path.parse("tests/fixtures/src/functions/http/[param].ts"), + path.parse( + convertToOSPath("tests/fixtures/src/functions/http/[param].ts") + ), ]; const functionModules = await loadFunctionModules( @@ -34,7 +37,7 @@ describe("loadTemplateModules", () => { true, projectStructure ); - commonTests(functionModules, "param-47543"); + commonTests(functionModules, "param-19926"); }); it("loads transpiled templates", async () => { @@ -46,7 +49,7 @@ describe("loadTemplateModules", () => { false, projectStructure ); - commonTests(functionModules, "param-47853"); + commonTests(functionModules, "param-19616"); }); const commonTests = ( diff --git a/packages/pages/src/common/src/function/internal/types.test.ts b/packages/pages/src/common/src/function/internal/types.test.ts index 2d557ddd9..e29e9b280 100644 --- a/packages/pages/src/common/src/function/internal/types.test.ts +++ b/packages/pages/src/common/src/function/internal/types.test.ts @@ -10,6 +10,7 @@ import { } from "../types.js"; import { mockSiteInfo } from "../../../../dev/server/middleware/serveHttpFunction.js"; import { ProjectStructure } from "../../project/structure.js"; +import { convertToOSPath } from "../../template/paths.js"; const exampleReturnValue: SitesHttpResponse = { body: "Hello World", @@ -51,7 +52,9 @@ const exampleOnUrlChangeArgument: SitesOnUrlChangeRequest = { }; const createMockFilePath = (filepath: string): path.ParsedPath => { - return path.parse(path.resolve(path.join("src/functions/", filepath))); + return path.parse( + path.resolve(convertToOSPath(path.join("src/functions/", filepath))) + ); }; describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => { @@ -69,21 +72,21 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => ); const expected = { config: { - name: "example-01535", + name: "example-23673", functionName: "default", event: "API", }, filePath: { - root: "/", - dir: process.cwd() + "/src/functions/http/api", + root: path.resolve("/"), + dir: convertToOSPath(process.cwd() + "/src/functions/http/api"), base: "example.ts", ext: ".ts", name: "example", }, slug: { - original: "api/example", - dev: "api/example", - production: "api/example", + original: convertToOSPath("api/example"), + dev: convertToOSPath("api/example"), + production: convertToOSPath("api/example"), }, }; expect(JSON.stringify(functionModuleInternal)).toEqual( @@ -113,13 +116,13 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => ); const expected = { config: { - name: "example-55662", + name: "example-11807", functionName: "default", event: "ON_URL_CHANGE", }, filePath: { - root: "/", - dir: process.cwd() + "/src/functions/onUrlChange", + root: path.resolve("/"), + dir: convertToOSPath(process.cwd() + "/src/functions/onUrlChange"), base: "example.ts", ext: ".ts", name: "example", @@ -155,21 +158,21 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => ); const expected = { config: { - name: "testParam-00975", + name: "testParam-61704", functionName: "default", event: "API", }, filePath: { - root: "/", - dir: process.cwd() + "/src/functions/http/api/example", + root: path.resolve("/"), + dir: convertToOSPath(process.cwd() + "/src/functions/http/api/example"), base: "[testParam].ts", ext: ".ts", name: "[testParam]", }, slug: { - original: "api/example/[testParam]", - dev: "api/example/:testParam", - production: "api/example/{{testParam}}", + original: convertToOSPath("api/example/[testParam]"), + dev: convertToOSPath("api/example/:testParam"), + production: convertToOSPath("api/example/{{testParam}}"), }, }; expect(JSON.stringify(functionModuleInternal)).toEqual( diff --git a/packages/pages/src/common/src/template/internal/getTemplateFilepaths.test.ts b/packages/pages/src/common/src/template/internal/getTemplateFilepaths.test.ts index 61e56276d..4421e1d4d 100644 --- a/packages/pages/src/common/src/template/internal/getTemplateFilepaths.test.ts +++ b/packages/pages/src/common/src/template/internal/getTemplateFilepaths.test.ts @@ -2,6 +2,7 @@ import path from "path"; import { getTemplateFilepaths } from "./getTemplateFilepaths.js"; import { minimatch } from "minimatch"; import { Path } from "../../project/path.js"; +import { convertToOSPath } from "../paths.js"; const rootPath = "src/templates"; const domain1Path = "src/templates/some.domain1.com"; @@ -10,12 +11,12 @@ jest.mock("glob", () => { return { globSync: (glob: string) => { const filepaths = [ - `${domain1Path}/brand1.tsx`, - `${domain1Path}/test.tsx`, - `${domain2Path}/brand2.tsx`, - `${domain2Path}/test.tsx`, - `${rootPath}/share.tsx`, - `${rootPath}/test.tsx`, + convertToOSPath(`${domain1Path}/brand1.tsx`), + convertToOSPath(`${domain1Path}/test.tsx`), + convertToOSPath(`${domain2Path}/brand2.tsx`), + convertToOSPath(`${domain2Path}/test.tsx`), + convertToOSPath(`${rootPath}/share.tsx`), + convertToOSPath(`${rootPath}/test.tsx`), ]; return filepaths.filter((f) => minimatch(path.resolve(f), glob)); }, @@ -25,10 +26,13 @@ jest.mock("glob", () => { describe("getTemplateFilepaths", () => { it("collects all template files from root folder path", () => { const templatesFilepath = getTemplateFilepaths([ - new Path(path.join(process.cwd(), rootPath)), + new Path(convertToOSPath(path.join(process.cwd(), rootPath))), ]); expect(templatesFilepath.sort()).toEqual( - [`${rootPath}/share.tsx`, `${rootPath}/test.tsx`].sort() + [ + convertToOSPath(`${rootPath}/share.tsx`), + convertToOSPath(`${rootPath}/test.tsx`), + ].sort() ); }); @@ -39,9 +43,9 @@ describe("getTemplateFilepaths", () => { ]); expect(templatesFilepath.sort()).toEqual( [ - `${rootPath}/share.tsx`, - `${domain1Path}/test.tsx`, - `${domain1Path}/brand1.tsx`, + convertToOSPath(`${rootPath}/share.tsx`), + convertToOSPath(`${domain1Path}/test.tsx`), + convertToOSPath(`${domain1Path}/brand1.tsx`), ].sort() ); }); diff --git a/packages/pages/src/common/src/template/internal/getTemplateFilepaths.ts b/packages/pages/src/common/src/template/internal/getTemplateFilepaths.ts index ac084b52f..b333e1b1a 100644 --- a/packages/pages/src/common/src/template/internal/getTemplateFilepaths.ts +++ b/packages/pages/src/common/src/template/internal/getTemplateFilepaths.ts @@ -6,6 +6,7 @@ import { ProjectStructure } from "../../project/structure.js"; import { ClientServerRenderTemplates } from "../types.js"; import fs from "node:fs"; import { fileURLToPath } from "node:url"; +import { convertToPosixPath } from "../paths.js"; /** * Get all the template files in the provided template folder path(s). @@ -21,7 +22,9 @@ export const getTemplateFilepaths = (paths: Path[]): string[] => { const templateFilepaths: string[] = []; const addedFilenames: Set = new Set(); paths.forEach((p) => { - const filepaths = globSync(`${p.getAbsolutePath()}/*.{tsx,jsx,js,ts}`); + const filepaths = globSync( + convertToPosixPath(`${p.getAbsolutePath()}/*.{tsx,jsx,js,ts}`) + ); filepaths // Don't include the client/server rendering templates .filter( diff --git a/packages/pages/src/common/src/template/internal/loader.test.ts b/packages/pages/src/common/src/template/internal/loader.test.ts index d96c55de9..b883ac26d 100644 --- a/packages/pages/src/common/src/template/internal/loader.test.ts +++ b/packages/pages/src/common/src/template/internal/loader.test.ts @@ -1,6 +1,7 @@ import { glob } from "glob"; import path from "path"; import { loadTemplateModules } from "./loader.js"; +import { convertToPosixPath } from "../paths.js"; // our jest configuration doesn't support file urls so update pathToFileURL to do nothing during // this test. @@ -23,7 +24,9 @@ afterAll(() => jest.unmock("url")); describe("loadTemplateModules", () => { it("loads and transpiles raw templates", async () => { const templateFile = glob.sync( - path.join(process.cwd(), "tests/fixtures/template.tsx") + convertToPosixPath( + path.join(process.cwd(), "tests/fixtures/template.tsx") + ) ); const templateModules = await loadTemplateModules( templateFile, @@ -36,7 +39,7 @@ describe("loadTemplateModules", () => { it("loads transpiled templates", async () => { const templateFile = glob.sync( - path.join(process.cwd(), "tests/fixtures/template.js") + convertToPosixPath(path.join(process.cwd(), "tests/fixtures/template.js")) ); const templateModules = await loadTemplateModules( templateFile, diff --git a/packages/pages/src/common/src/template/internal/types.test.ts b/packages/pages/src/common/src/template/internal/types.test.ts index d01ec2cdb..b4c8db388 100644 --- a/packages/pages/src/common/src/template/internal/types.test.ts +++ b/packages/pages/src/common/src/template/internal/types.test.ts @@ -3,6 +3,7 @@ import { TemplateModuleInternal, } from "./types.js"; import { Template, TemplateModule } from "../types.js"; +import { convertToOSPath } from "../paths.js"; describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => { it("uses the filename as the config name when not set", async () => { @@ -22,7 +23,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - "src/templates/myTemplateName.tsx", + convertToOSPath("src/templates/myTemplateName.tsx"), templateModule, false ); @@ -40,7 +41,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: "src/templates/myTemplateName.tsx", + path: convertToOSPath("src/templates/myTemplateName.tsx"), filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -63,7 +64,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - "src/templates/myTemplateName.tsx", + convertToOSPath("src/templates/myTemplateName.tsx"), templateModule, false ); @@ -76,7 +77,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: "src/templates/myTemplateName.tsx", + path: convertToOSPath("src/templates/myTemplateName.tsx"), filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -98,7 +99,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - "src/templates/myTemplateName.0ab33d.tsx", + convertToOSPath("src/templates/myTemplateName.0ab33d.tsx"), templateModule, true ); @@ -111,7 +112,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: "src/templates/myTemplateName.0ab33d.tsx", + path: convertToOSPath("src/templates/myTemplateName.0ab33d.tsx"), filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -137,7 +138,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - "src/templates/myTemplateName.tsx", + convertToOSPath("src/templates/myTemplateName.tsx"), templateModule, false ); @@ -155,7 +156,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: true, streamId: "$id", }, - path: "src/templates/myTemplateName.tsx", + path: convertToOSPath("src/templates/myTemplateName.tsx"), filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -182,7 +183,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - "src/templates/myTemplateName.tsx", + convertToOSPath("src/templates/myTemplateName.tsx"), templateModule, false ); @@ -200,7 +201,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: "src/templates/myTemplateName.tsx", + path: convertToOSPath("src/templates/myTemplateName.tsx"), filename: "myTemplateName.tsx", templateName: "myTemplateName", }; diff --git a/packages/pages/src/common/src/template/internal/types.ts b/packages/pages/src/common/src/template/internal/types.ts index f69dc2af5..326f4919e 100644 --- a/packages/pages/src/common/src/template/internal/types.ts +++ b/packages/pages/src/common/src/template/internal/types.ts @@ -11,6 +11,7 @@ import { TemplateProps, TemplateRenderProps, } from "../types.js"; +import path from "node:path"; import { validateTemplateModuleInternal } from "./validateTemplateModuleInternal.js"; /** @@ -104,7 +105,7 @@ export const parse = ( filepath: string, adjustForFingerprintedAsset: boolean ) => { - let base = filepath.split("/")[filepath.split("/").length - 1]; + let base = filepath.split(path.sep)[filepath.split(path.sep).length - 1]; const extension = base.slice(base.lastIndexOf(".")); let name = base.slice(0, base.lastIndexOf(".")); diff --git a/packages/pages/src/common/src/template/paths.test.ts b/packages/pages/src/common/src/template/paths.test.ts index 0e04283f7..34f5d013d 100644 --- a/packages/pages/src/common/src/template/paths.test.ts +++ b/packages/pages/src/common/src/template/paths.test.ts @@ -1,6 +1,16 @@ -import { getRelativePrefixToRootFromPath } from "../../src/template/paths.js"; +import { + convertToOSPath, + convertToPosixPath, + getRelativePrefixToRootFromPath, +} from "../../src/template/paths.js"; +import path from "node:path"; describe("getRelativePrefixToRootFromPath", () => { + const relativePath = "spaghetti/meatballs"; + const relativeWinPath = "spaghetti\\meatballs"; + const absolutePath = "/enchilada/burrito/taco"; + const absoluteWinPath = "\\enchilada\\burrito\\taco"; + it("properly returns the empty string when on root level", async () => { const path = "foobar.txt"; @@ -12,12 +22,33 @@ describe("getRelativePrefixToRootFromPath", () => { }); it("properly returns the relative directory prefix when deeper than root level", async () => { - const path = "foo/bar/foo/foobar.txt"; + const p = "foo/bar/foo/foobar.txt"; const expectedRelativePathPrefix = "../../../"; - expect(getRelativePrefixToRootFromPath(path)).toEqual( + expect(getRelativePrefixToRootFromPath(p)).toEqual( expectedRelativePathPrefix ); }); + + it("convert to OS path", async () => { + if (path.sep === path.posix.sep) { + expect(convertToOSPath(relativePath)).toEqual(relativePath); + expect(convertToOSPath(relativeWinPath)).toEqual(relativePath); + expect(convertToOSPath(absolutePath)).toEqual(absolutePath); + expect(convertToOSPath(absoluteWinPath)).toEqual(absolutePath); + } else { + expect(convertToOSPath(relativePath)).toEqual("spaghetti\\meatballs"); + expect(convertToOSPath(relativeWinPath)).toEqual(relativeWinPath); + expect(convertToOSPath(absolutePath)).toEqual(absoluteWinPath); + expect(convertToOSPath(absoluteWinPath)).toEqual(absoluteWinPath); + } + }); + + it("convert to posix path", async () => { + expect(convertToPosixPath(relativePath)).toEqual(relativePath); + expect(convertToPosixPath(relativeWinPath)).toEqual(relativePath); + expect(convertToPosixPath(absolutePath)).toEqual(absolutePath); + expect(convertToPosixPath(absoluteWinPath)).toEqual(absolutePath); + }); }); diff --git a/packages/pages/src/common/src/template/paths.ts b/packages/pages/src/common/src/template/paths.ts index 1b0cf990e..2cbbc427a 100644 --- a/packages/pages/src/common/src/template/paths.ts +++ b/packages/pages/src/common/src/template/paths.ts @@ -1,5 +1,7 @@ import path from "node:path"; +const winSep = "\\"; + /** * Function that takes a path to a generated template and returns the * relative path to the root of the site. Will return the empty string @@ -21,5 +23,12 @@ export const getRelativePrefixToRootFromPath = (path: string): string => { * paths are supported with import. */ export const convertToPosixPath = (p: string) => { - return p.split(path.sep).join(path.posix.sep); + return p.split(winSep).join(path.posix.sep); +}; + +/** + * Convert any path to match the format of the OS. If it already matches no change occurs. + */ +export const convertToOSPath = (p: string) => { + return p.split(path.posix.sep).join(path.sep).split(winSep).join(path.sep); }; diff --git a/packages/pages/src/dev/server/ssr/generateTestData.test.ts b/packages/pages/src/dev/server/ssr/generateTestData.test.ts index 59fc7c2d3..24e55eecc 100644 --- a/packages/pages/src/dev/server/ssr/generateTestData.test.ts +++ b/packages/pages/src/dev/server/ssr/generateTestData.test.ts @@ -1,4 +1,3 @@ -import { WriteStream } from "tty"; import { generateTestDataForPage } from "./generateTestData.js"; import { EventEmitter } from "stream"; import { @@ -18,7 +17,7 @@ import { import { Socket } from "net"; import { ProjectStructure } from "../../../common/src/project/structure.js"; -const mockParentProcessStdout = jest.mocked(new WriteStream(0)); +const mockParentProcessStdout = jest.mocked(process.stdout); mockParentProcessStdout.write = jest.fn(); const mockChildProcessEventEmitter = new EventEmitter(); diff --git a/packages/pages/src/util/runSubprocess.test.ts b/packages/pages/src/util/runSubprocess.test.ts index c0f561348..f40e9f20f 100644 --- a/packages/pages/src/util/runSubprocess.test.ts +++ b/packages/pages/src/util/runSubprocess.test.ts @@ -1,4 +1,5 @@ import runSubprocess from "./runSubprocess.js"; +import path from "node:path"; describe("runSubprocess", () => { it("runs echo successfully", async () => { @@ -8,6 +9,10 @@ describe("runSubprocess", () => { it("returns non-zero when subprocess fails", async () => { const exitCode = await runSubprocess("echo", ["$((0/0))"]); - expect(exitCode).not.toEqual(0); + if (path.sep === path.posix.sep) { + expect(exitCode).not.toEqual(0); + } + // commands do not return exit codes on Windows, so we skip this test in that case + expect(true).toEqual(true); }); }); From 1b752f7bc67070cc52ec246a9ff830a1b8c210e5 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 6 Sep 2023 22:52:33 +0000 Subject: [PATCH 03/14] Commit new snapshots for macos-latest --- .../locations-site/sites-config/features.json | 43 ++++++++++++++++++- .../sunglasses.oakley.com/features.json | 41 +++++++++++++++++- 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/playground/locations-site/sites-config/features.json b/playground/locations-site/sites-config/features.json index 02c781471..f80e38ca0 100644 --- a/playground/locations-site/sites-config/features.json +++ b/playground/locations-site/sites-config/features.json @@ -1,4 +1,43 @@ { - "features": [], - "streams": [] + "features": [ + { + "name": "turtlehead-tacos", + "templateType": "JS", + "staticPage": {} + }, + { + "name": "robots", + "templateType": "JS", + "staticPage": {} + }, + { + "name": "location", + "streamId": "location-stream", + "templateType": "JS", + "entityPageSet": {} + } + ], + "streams": [ + { + "$id": "location-stream", + "filter": { + "entityTypes": [ + "location" + ] + }, + "fields": [ + "id", + "uid", + "meta", + "address", + "slug" + ], + "localization": { + "locales": [ + "en" + ], + "primary": false + } + } + ] } \ No newline at end of file diff --git a/playground/multibrand-site/sites-config/sunglasses.oakley.com/features.json b/playground/multibrand-site/sites-config/sunglasses.oakley.com/features.json index 02c781471..87177a020 100644 --- a/playground/multibrand-site/sites-config/sunglasses.oakley.com/features.json +++ b/playground/multibrand-site/sites-config/sunglasses.oakley.com/features.json @@ -1,4 +1,41 @@ { - "features": [], - "streams": [] + "features": [ + { + "name": "sunglasses", + "streamId": "oakley-stream", + "templateType": "JS", + "entityPageSet": {} + }, + { + "name": "turtlehead-tacos", + "templateType": "JS", + "staticPage": {} + }, + { + "name": "robots", + "templateType": "JS", + "staticPage": {} + } + ], + "streams": [ + { + "$id": "oakley-stream", + "fields": [ + "id", + "name", + "slug" + ], + "filter": { + "savedFilterIds": [ + "1241548641" + ] + }, + "localization": { + "locales": [ + "en" + ], + "primary": false + } + } + ] } \ No newline at end of file From b8e6f9da692f9f1a42bbc4f007f49782c71bd004 Mon Sep 17 00:00:00 2001 From: jwartofsky Date: Thu, 7 Sep 2023 10:01:16 -0400 Subject: [PATCH 04/14] Empty commit From b15abf80d8df402fab2f7678fd2217094ab6699f Mon Sep 17 00:00:00 2001 From: jwartofsky Date: Thu, 7 Sep 2023 13:20:04 -0400 Subject: [PATCH 05/14] Removed convertToOSPath Reran all tests --- .../internal/getFunctionFilepaths.test.ts | 25 ++++++------ .../src/function/internal/loader.test.ts | 9 ++--- .../src/function/internal/types.test.ts | 38 +++++++++++-------- .../internal/getTemplateFilepaths.test.ts | 32 +++++++--------- .../src/template/internal/types.test.ts | 24 ++++++------ .../src/common/src/template/paths.test.ts | 15 -------- 6 files changed, 64 insertions(+), 79 deletions(-) diff --git a/packages/pages/src/common/src/function/internal/getFunctionFilepaths.test.ts b/packages/pages/src/common/src/function/internal/getFunctionFilepaths.test.ts index e8e8af5a7..cc10df552 100644 --- a/packages/pages/src/common/src/function/internal/getFunctionFilepaths.test.ts +++ b/packages/pages/src/common/src/function/internal/getFunctionFilepaths.test.ts @@ -1,43 +1,42 @@ import path from "path"; import { getFunctionFilepaths } from "./getFunctionFilepaths.js"; import { minimatch } from "minimatch"; -import { convertToOSPath } from "../../template/paths.js"; -const rootPath = "src/functions"; -const multiLevelPath = "src/functions/http/api/fetch"; +const rootPath = path.join("src", "functions"); +const multiLevelPath = path.join("src", "functions", "http", "api", "fetch"); const filepaths = [ - convertToOSPath(`${multiLevelPath}/test1.ts`), - convertToOSPath(`${multiLevelPath}/test2.js`), - convertToOSPath(`${rootPath}/test3.js`), - convertToOSPath(`${rootPath}/test4.ts`), + path.join(multiLevelPath, "test1.ts"), + path.join(multiLevelPath, "test2.js"), + path.join(rootPath, "test3.js"), + path.join(rootPath, "test4.ts"), ]; const expected = [ { root: path.resolve("/"), - dir: convertToOSPath(process.cwd() + "/src/functions/http/api/fetch"), + dir: path.join(process.cwd(), multiLevelPath), base: "test1.ts", ext: ".ts", name: "test1", }, { root: path.resolve("/"), - dir: convertToOSPath(process.cwd() + "/src/functions/http/api/fetch"), + dir: path.join(process.cwd(), multiLevelPath), base: "test2.js", ext: ".js", name: "test2", }, { root: path.resolve("/"), - dir: convertToOSPath(process.cwd() + "/src/functions"), + dir: path.join(process.cwd(), rootPath), base: "test3.js", ext: ".js", name: "test3", }, { root: path.resolve("/"), - dir: convertToOSPath(process.cwd() + "/src/functions"), + dir: path.join(process.cwd(), rootPath), base: "test4.ts", ext: ".ts", name: "test4", @@ -54,9 +53,7 @@ jest.mock("glob", () => { describe("getFunctionFilepaths", () => { it("collects all function files under the src/functions path", () => { - const templatesFilepath = getFunctionFilepaths( - convertToOSPath("src/functions") - ); + const templatesFilepath = getFunctionFilepaths(rootPath); expect(JSON.stringify(templatesFilepath.sort())).toEqual( JSON.stringify(expected) ); diff --git a/packages/pages/src/common/src/function/internal/loader.test.ts b/packages/pages/src/common/src/function/internal/loader.test.ts index 39b0dbe83..8c70c5a93 100644 --- a/packages/pages/src/common/src/function/internal/loader.test.ts +++ b/packages/pages/src/common/src/function/internal/loader.test.ts @@ -1,7 +1,8 @@ import path from "path"; import { loadFunctionModules, FunctionModuleCollection } from "./loader.js"; import { ProjectStructure } from "../../project/structure.js"; -import { convertToOSPath } from "../../template/paths.js"; + +const httpPath = path.join("tests", "fixtures", "src", "functions", "http"); // our jest configuration doesn't support file urls so update pathToFileURL to do nothing during // this test. @@ -27,9 +28,7 @@ describe("loadTemplateModules", () => { it("loads and transpiles raw templates", async () => { const functionFile: path.ParsedPath[] = [ - path.parse( - convertToOSPath("tests/fixtures/src/functions/http/[param].ts") - ), + path.parse(path.join(httpPath, "[param].ts")), ]; const functionModules = await loadFunctionModules( @@ -42,7 +41,7 @@ describe("loadTemplateModules", () => { it("loads transpiled templates", async () => { const functionFile: path.ParsedPath[] = [ - path.parse(path.resolve("tests/fixtures/src/functions/http/[param].js")), + path.parse(path.resolve(path.join(httpPath, "[param].js"))), ]; const functionModules = await loadFunctionModules( functionFile, diff --git a/packages/pages/src/common/src/function/internal/types.test.ts b/packages/pages/src/common/src/function/internal/types.test.ts index e29e9b280..692c342ea 100644 --- a/packages/pages/src/common/src/function/internal/types.test.ts +++ b/packages/pages/src/common/src/function/internal/types.test.ts @@ -10,7 +10,6 @@ import { } from "../types.js"; import { mockSiteInfo } from "../../../../dev/server/middleware/serveHttpFunction.js"; import { ProjectStructure } from "../../project/structure.js"; -import { convertToOSPath } from "../../template/paths.js"; const exampleReturnValue: SitesHttpResponse = { body: "Hello World", @@ -52,9 +51,7 @@ const exampleOnUrlChangeArgument: SitesOnUrlChangeRequest = { }; const createMockFilePath = (filepath: string): path.ParsedPath => { - return path.parse( - path.resolve(convertToOSPath(path.join("src/functions/", filepath))) - ); + return path.parse(path.resolve(path.join("src", "functions", filepath))); }; describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => { @@ -66,7 +63,7 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => }; const functionModuleInternal = convertFunctionModuleToFunctionModuleInternal( - createMockFilePath("http/api/example.ts"), + createMockFilePath(path.join("http", "api", "example.ts")), functionModule, projectStructure ); @@ -78,15 +75,15 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => }, filePath: { root: path.resolve("/"), - dir: convertToOSPath(process.cwd() + "/src/functions/http/api"), + dir: path.join(process.cwd(), "src", "functions", "http", "api"), base: "example.ts", ext: ".ts", name: "example", }, slug: { - original: convertToOSPath("api/example"), - dev: convertToOSPath("api/example"), - production: convertToOSPath("api/example"), + original: path.join("api", "example"), + dev: path.join("api", "example"), + production: path.join("api", "example"), }, }; expect(JSON.stringify(functionModuleInternal)).toEqual( @@ -110,7 +107,7 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => }; const functionModuleInternal = convertFunctionModuleToFunctionModuleInternal( - createMockFilePath("onUrlChange/example.ts"), + createMockFilePath(path.join("onUrlChange", "example.ts")), functionModule, projectStructure ); @@ -122,7 +119,7 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => }, filePath: { root: path.resolve("/"), - dir: convertToOSPath(process.cwd() + "/src/functions/onUrlChange"), + dir: path.join(process.cwd(), "src", "functions", "onUrlChange"), base: "example.ts", ext: ".ts", name: "example", @@ -152,7 +149,9 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => }; const functionModuleInternal = convertFunctionModuleToFunctionModuleInternal( - createMockFilePath("http/api/example/[testParam].ts"), + createMockFilePath( + path.join("http", "api", "example", "[testParam].ts") + ), functionModule, projectStructure ); @@ -164,15 +163,22 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => }, filePath: { root: path.resolve("/"), - dir: convertToOSPath(process.cwd() + "/src/functions/http/api/example"), + dir: path.join( + process.cwd(), + "src", + "functions", + "http", + "api", + "example" + ), base: "[testParam].ts", ext: ".ts", name: "[testParam]", }, slug: { - original: convertToOSPath("api/example/[testParam]"), - dev: convertToOSPath("api/example/:testParam"), - production: convertToOSPath("api/example/{{testParam}}"), + original: path.join("api", "example", "[testParam]"), + dev: path.join("api", "example", ":testParam"), + production: path.join("api", "example", "{{testParam}}"), }, }; expect(JSON.stringify(functionModuleInternal)).toEqual( diff --git a/packages/pages/src/common/src/template/internal/getTemplateFilepaths.test.ts b/packages/pages/src/common/src/template/internal/getTemplateFilepaths.test.ts index 4421e1d4d..582aa2485 100644 --- a/packages/pages/src/common/src/template/internal/getTemplateFilepaths.test.ts +++ b/packages/pages/src/common/src/template/internal/getTemplateFilepaths.test.ts @@ -2,21 +2,20 @@ import path from "path"; import { getTemplateFilepaths } from "./getTemplateFilepaths.js"; import { minimatch } from "minimatch"; import { Path } from "../../project/path.js"; -import { convertToOSPath } from "../paths.js"; -const rootPath = "src/templates"; -const domain1Path = "src/templates/some.domain1.com"; -const domain2Path = "src/templates/some.domain2.com"; +const rootPath = path.join("src", "templates"); +const domain1Path = path.join("src", "templates", "some.domain1.com"); +const domain2Path = path.join("src", "templates", "some.domain2.com"); jest.mock("glob", () => { return { globSync: (glob: string) => { const filepaths = [ - convertToOSPath(`${domain1Path}/brand1.tsx`), - convertToOSPath(`${domain1Path}/test.tsx`), - convertToOSPath(`${domain2Path}/brand2.tsx`), - convertToOSPath(`${domain2Path}/test.tsx`), - convertToOSPath(`${rootPath}/share.tsx`), - convertToOSPath(`${rootPath}/test.tsx`), + path.join(domain1Path, "brand1.tsx"), + path.join(domain1Path, "test.tsx"), + path.join(domain2Path, "brand2.tsx"), + path.join(domain2Path, "test.tsx"), + path.join(rootPath, "share.tsx"), + path.join(rootPath, "test.tsx"), ]; return filepaths.filter((f) => minimatch(path.resolve(f), glob)); }, @@ -26,13 +25,10 @@ jest.mock("glob", () => { describe("getTemplateFilepaths", () => { it("collects all template files from root folder path", () => { const templatesFilepath = getTemplateFilepaths([ - new Path(convertToOSPath(path.join(process.cwd(), rootPath))), + new Path(path.join(process.cwd(), rootPath)), ]); expect(templatesFilepath.sort()).toEqual( - [ - convertToOSPath(`${rootPath}/share.tsx`), - convertToOSPath(`${rootPath}/test.tsx`), - ].sort() + [path.join(rootPath, "share.tsx"), path.join(rootPath, "test.tsx")].sort() ); }); @@ -43,9 +39,9 @@ describe("getTemplateFilepaths", () => { ]); expect(templatesFilepath.sort()).toEqual( [ - convertToOSPath(`${rootPath}/share.tsx`), - convertToOSPath(`${domain1Path}/test.tsx`), - convertToOSPath(`${domain1Path}/brand1.tsx`), + path.join(rootPath, "share.tsx"), + path.join(domain1Path, "test.tsx"), + path.join(domain1Path, "brand1.tsx"), ].sort() ); }); diff --git a/packages/pages/src/common/src/template/internal/types.test.ts b/packages/pages/src/common/src/template/internal/types.test.ts index b4c8db388..983c23501 100644 --- a/packages/pages/src/common/src/template/internal/types.test.ts +++ b/packages/pages/src/common/src/template/internal/types.test.ts @@ -3,7 +3,9 @@ import { TemplateModuleInternal, } from "./types.js"; import { Template, TemplateModule } from "../types.js"; -import { convertToOSPath } from "../paths.js"; +import path from "path"; + +const myTemplateNamePath = path.join("src", "templates", "myTemplateName.tsx"); describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => { it("uses the filename as the config name when not set", async () => { @@ -23,7 +25,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - convertToOSPath("src/templates/myTemplateName.tsx"), + myTemplateNamePath, templateModule, false ); @@ -41,7 +43,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: convertToOSPath("src/templates/myTemplateName.tsx"), + path: myTemplateNamePath, filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -64,7 +66,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - convertToOSPath("src/templates/myTemplateName.tsx"), + myTemplateNamePath, templateModule, false ); @@ -77,7 +79,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: convertToOSPath("src/templates/myTemplateName.tsx"), + path: myTemplateNamePath, filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -99,7 +101,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - convertToOSPath("src/templates/myTemplateName.0ab33d.tsx"), + path.join("src", "templates", "myTemplateName.0ab33d.tsx"), templateModule, true ); @@ -112,7 +114,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: convertToOSPath("src/templates/myTemplateName.0ab33d.tsx"), + path: path.join("src", "templates", "myTemplateName.0ab33d.tsx"), filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -138,7 +140,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - convertToOSPath("src/templates/myTemplateName.tsx"), + myTemplateNamePath, templateModule, false ); @@ -156,7 +158,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: true, streamId: "$id", }, - path: convertToOSPath("src/templates/myTemplateName.tsx"), + path: myTemplateNamePath, filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -183,7 +185,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - convertToOSPath("src/templates/myTemplateName.tsx"), + myTemplateNamePath, templateModule, false ); @@ -201,7 +203,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: convertToOSPath("src/templates/myTemplateName.tsx"), + path: myTemplateNamePath, filename: "myTemplateName.tsx", templateName: "myTemplateName", }; diff --git a/packages/pages/src/common/src/template/paths.test.ts b/packages/pages/src/common/src/template/paths.test.ts index 34f5d013d..51d90422a 100644 --- a/packages/pages/src/common/src/template/paths.test.ts +++ b/packages/pages/src/common/src/template/paths.test.ts @@ -1,5 +1,4 @@ import { - convertToOSPath, convertToPosixPath, getRelativePrefixToRootFromPath, } from "../../src/template/paths.js"; @@ -31,20 +30,6 @@ describe("getRelativePrefixToRootFromPath", () => { ); }); - it("convert to OS path", async () => { - if (path.sep === path.posix.sep) { - expect(convertToOSPath(relativePath)).toEqual(relativePath); - expect(convertToOSPath(relativeWinPath)).toEqual(relativePath); - expect(convertToOSPath(absolutePath)).toEqual(absolutePath); - expect(convertToOSPath(absoluteWinPath)).toEqual(absolutePath); - } else { - expect(convertToOSPath(relativePath)).toEqual("spaghetti\\meatballs"); - expect(convertToOSPath(relativeWinPath)).toEqual(relativeWinPath); - expect(convertToOSPath(absolutePath)).toEqual(absoluteWinPath); - expect(convertToOSPath(absoluteWinPath)).toEqual(absoluteWinPath); - } - }); - it("convert to posix path", async () => { expect(convertToPosixPath(relativePath)).toEqual(relativePath); expect(convertToPosixPath(relativeWinPath)).toEqual(relativePath); From 484387d5e0c90daf4e699e118b1f69fe67196093 Mon Sep 17 00:00:00 2001 From: jwartofsky Date: Thu, 7 Sep 2023 14:45:00 -0400 Subject: [PATCH 06/14] fix tests for Posix systems In several places we compare a hash of the URL, which is different depending on the system. --- .../common/src/function/internal/loader.test.ts | 12 ++++++++++-- .../common/src/function/internal/types.test.ts | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/pages/src/common/src/function/internal/loader.test.ts b/packages/pages/src/common/src/function/internal/loader.test.ts index 8c70c5a93..8c013f062 100644 --- a/packages/pages/src/common/src/function/internal/loader.test.ts +++ b/packages/pages/src/common/src/function/internal/loader.test.ts @@ -36,7 +36,11 @@ describe("loadTemplateModules", () => { true, projectStructure ); - commonTests(functionModules, "param-19926"); + if (path.sep === path.posix.sep) { + commonTests(functionModules, "param-47543"); + } else { + commonTests(functionModules, "param-19926"); + } }); it("loads transpiled templates", async () => { @@ -48,7 +52,11 @@ describe("loadTemplateModules", () => { false, projectStructure ); - commonTests(functionModules, "param-19616"); + if (path.sep === path.posix.sep) { + commonTests(functionModules, "param-47853"); + } else { + commonTests(functionModules, "param-19616"); + } }); const commonTests = ( diff --git a/packages/pages/src/common/src/function/internal/types.test.ts b/packages/pages/src/common/src/function/internal/types.test.ts index 692c342ea..9b9f28cd1 100644 --- a/packages/pages/src/common/src/function/internal/types.test.ts +++ b/packages/pages/src/common/src/function/internal/types.test.ts @@ -69,7 +69,7 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => ); const expected = { config: { - name: "example-23673", + name: "example-01535", functionName: "default", event: "API", }, @@ -86,6 +86,9 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => production: path.join("api", "example"), }, }; + if (path.sep !== path.posix.sep) { + expected.config.name = "example-23673"; + } expect(JSON.stringify(functionModuleInternal)).toEqual( JSON.stringify(expected) ); @@ -113,7 +116,7 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => ); const expected = { config: { - name: "example-11807", + name: "example-55662", functionName: "default", event: "ON_URL_CHANGE", }, @@ -130,6 +133,9 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => production: "example", }, }; + if (path.sep !== path.posix.sep) { + expected.config.name = "example-11807"; + } expect(JSON.stringify(functionModuleInternal)).toEqual( JSON.stringify(expected) ); @@ -157,7 +163,7 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => ); const expected = { config: { - name: "testParam-61704", + name: "testParam-00975", functionName: "default", event: "API", }, @@ -181,6 +187,9 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => production: path.join("api", "example", "{{testParam}}"), }, }; + if (path.sep !== path.posix.sep) { + expected.config.name = "testParam-61704"; + } expect(JSON.stringify(functionModuleInternal)).toEqual( JSON.stringify(expected) ); From 142aadda83101c873c1306edce95edc5ca3877d7 Mon Sep 17 00:00:00 2001 From: jwartofsky Date: Thu, 7 Sep 2023 17:36:09 -0400 Subject: [PATCH 07/14] cleanup paths helper --- packages/pages/src/common/src/template/paths.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/packages/pages/src/common/src/template/paths.ts b/packages/pages/src/common/src/template/paths.ts index 2cbbc427a..1b0cf990e 100644 --- a/packages/pages/src/common/src/template/paths.ts +++ b/packages/pages/src/common/src/template/paths.ts @@ -1,7 +1,5 @@ import path from "node:path"; -const winSep = "\\"; - /** * Function that takes a path to a generated template and returns the * relative path to the root of the site. Will return the empty string @@ -23,12 +21,5 @@ export const getRelativePrefixToRootFromPath = (path: string): string => { * paths are supported with import. */ export const convertToPosixPath = (p: string) => { - return p.split(winSep).join(path.posix.sep); -}; - -/** - * Convert any path to match the format of the OS. If it already matches no change occurs. - */ -export const convertToOSPath = (p: string) => { - return p.split(path.posix.sep).join(path.sep).split(winSep).join(path.sep); + return p.split(path.sep).join(path.posix.sep); }; From 2a07bb27726e15fee3a30c677e75f3a8a77aee32 Mon Sep 17 00:00:00 2001 From: jwartofsky Date: Thu, 7 Sep 2023 18:06:12 -0400 Subject: [PATCH 08/14] replcae path.sep with "\\" for convertToPosixPath Without this, the method will fail to convert a Windows URL to Posix on Mac. --- packages/pages/src/common/src/template/paths.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pages/src/common/src/template/paths.ts b/packages/pages/src/common/src/template/paths.ts index 1b0cf990e..e1c35b6f8 100644 --- a/packages/pages/src/common/src/template/paths.ts +++ b/packages/pages/src/common/src/template/paths.ts @@ -21,5 +21,5 @@ export const getRelativePrefixToRootFromPath = (path: string): string => { * paths are supported with import. */ export const convertToPosixPath = (p: string) => { - return p.split(path.sep).join(path.posix.sep); + return p.split("\\").join(path.posix.sep); }; From d72789ffa581991e583221337c94f64277f746dd Mon Sep 17 00:00:00 2001 From: Jacob Wartofsky Date: Fri, 8 Sep 2023 10:50:19 -0400 Subject: [PATCH 09/14] use path.sep instead of \ --- .../pages/src/common/src/template/paths.test.ts | 16 ++++++++-------- packages/pages/src/common/src/template/paths.ts | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/pages/src/common/src/template/paths.test.ts b/packages/pages/src/common/src/template/paths.test.ts index 51d90422a..c2ce4a5ac 100644 --- a/packages/pages/src/common/src/template/paths.test.ts +++ b/packages/pages/src/common/src/template/paths.test.ts @@ -5,10 +5,10 @@ import { import path from "node:path"; describe("getRelativePrefixToRootFromPath", () => { - const relativePath = "spaghetti/meatballs"; - const relativeWinPath = "spaghetti\\meatballs"; - const absolutePath = "/enchilada/burrito/taco"; - const absoluteWinPath = "\\enchilada\\burrito\\taco"; + const relativePosixPath = "spaghetti/meatballs"; + const relativeOSPath = `spaghetti${path.sep}meatballs`; + const absolutePosixPath = "/enchilada/burrito/taco"; + const absoluteOSPath = `${path.sep}enchilada${path.sep}burrito${path.sep}taco`; it("properly returns the empty string when on root level", async () => { const path = "foobar.txt"; @@ -31,9 +31,9 @@ describe("getRelativePrefixToRootFromPath", () => { }); it("convert to posix path", async () => { - expect(convertToPosixPath(relativePath)).toEqual(relativePath); - expect(convertToPosixPath(relativeWinPath)).toEqual(relativePath); - expect(convertToPosixPath(absolutePath)).toEqual(absolutePath); - expect(convertToPosixPath(absoluteWinPath)).toEqual(absolutePath); + expect(convertToPosixPath(relativePosixPath)).toEqual(relativePosixPath); + expect(convertToPosixPath(relativeOSPath)).toEqual(relativePosixPath); + expect(convertToPosixPath(absolutePosixPath)).toEqual(absolutePosixPath); + expect(convertToPosixPath(absoluteOSPath)).toEqual(absolutePosixPath); }); }); diff --git a/packages/pages/src/common/src/template/paths.ts b/packages/pages/src/common/src/template/paths.ts index e1c35b6f8..1b0cf990e 100644 --- a/packages/pages/src/common/src/template/paths.ts +++ b/packages/pages/src/common/src/template/paths.ts @@ -21,5 +21,5 @@ export const getRelativePrefixToRootFromPath = (path: string): string => { * paths are supported with import. */ export const convertToPosixPath = (p: string) => { - return p.split("\\").join(path.posix.sep); + return p.split(path.sep).join(path.posix.sep); }; From dc90f70567396e4b2551ec7f0d458b79c0684508 Mon Sep 17 00:00:00 2001 From: jwartofsky Date: Fri, 8 Sep 2023 13:13:40 -0400 Subject: [PATCH 10/14] fix loader path for Node19+ on Windows --- packages/pages/src/bin/spawn.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/pages/src/bin/spawn.ts b/packages/pages/src/bin/spawn.ts index 1a588b6c1..7ea3265e3 100644 --- a/packages/pages/src/bin/spawn.ts +++ b/packages/pages/src/bin/spawn.ts @@ -6,9 +6,9 @@ import path from "path"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); +const filePrefix = path.sep !== path.posix.sep ? "file:\\\\" : ""; const pathToPagesScript = path.resolve(__dirname, "./pages.js"); - -const pathToLoader = path.resolve(__dirname, "./loader.js"); +const pathToLoader = filePrefix + path.resolve(__dirname, "./loader.js"); const nodeVersion = Number( spawnSync("node", ["-v"], { encoding: "utf-8" }) From eeae30b7e838fd90c982c99c1dcc344f3d642ca7 Mon Sep 17 00:00:00 2001 From: jwartofsky Date: Fri, 8 Sep 2023 17:57:24 -0400 Subject: [PATCH 11/14] address comments --- packages/pages/src/bin/spawn.ts | 2 +- .../internal/functionMetadataParser.ts | 6 ++++-- .../src/function/internal/loader.test.ts | 18 ++++-------------- .../common/src/function/internal/types.test.ts | 9 --------- 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/packages/pages/src/bin/spawn.ts b/packages/pages/src/bin/spawn.ts index 7ea3265e3..8f83d0dda 100644 --- a/packages/pages/src/bin/spawn.ts +++ b/packages/pages/src/bin/spawn.ts @@ -6,7 +6,7 @@ import path from "path"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -const filePrefix = path.sep !== path.posix.sep ? "file:\\\\" : ""; +const filePrefix = path.sep === path.win32.sep ? "file:\\\\" : ""; const pathToPagesScript = path.resolve(__dirname, "./pages.js"); const pathToLoader = filePrefix + path.resolve(__dirname, "./loader.js"); diff --git a/packages/pages/src/common/src/function/internal/functionMetadataParser.ts b/packages/pages/src/common/src/function/internal/functionMetadataParser.ts index 09a705975..a2ef40540 100644 --- a/packages/pages/src/common/src/function/internal/functionMetadataParser.ts +++ b/packages/pages/src/common/src/function/internal/functionMetadataParser.ts @@ -1,5 +1,6 @@ import { ProjectStructure } from "../../project/structure.js"; import path from "node:path"; +import { convertToPosixPath } from "../../template/paths.js"; // type functionType = typeof validFunctionTypes[number]; const validFunctionTypes = ["onUrlChange", "http"]; @@ -113,9 +114,10 @@ export class FunctionMetadataParser { * @returns A five-character string of the hash. */ const unsecureHashPluginName = (input: string): string => { + const posixPath = convertToPosixPath(input); let hash = 0; - for (let i = 0; i < input.length; i++) { - const code = input.charCodeAt(i); + for (let i = 0; i < posixPath.length; i++) { + const code = posixPath.charCodeAt(i); hash = (hash << 5) - hash + code; hash = hash & hash; // Convert to 32bit integer } diff --git a/packages/pages/src/common/src/function/internal/loader.test.ts b/packages/pages/src/common/src/function/internal/loader.test.ts index 8c013f062..694058a70 100644 --- a/packages/pages/src/common/src/function/internal/loader.test.ts +++ b/packages/pages/src/common/src/function/internal/loader.test.ts @@ -2,8 +2,6 @@ import path from "path"; import { loadFunctionModules, FunctionModuleCollection } from "./loader.js"; import { ProjectStructure } from "../../project/structure.js"; -const httpPath = path.join("tests", "fixtures", "src", "functions", "http"); - // our jest configuration doesn't support file urls so update pathToFileURL to do nothing during // this test. jest.mock("url", () => { @@ -28,7 +26,7 @@ describe("loadTemplateModules", () => { it("loads and transpiles raw templates", async () => { const functionFile: path.ParsedPath[] = [ - path.parse(path.join(httpPath, "[param].ts")), + path.parse(path.resolve("tests/fixtures/src/functions/http/[param].ts")), ]; const functionModules = await loadFunctionModules( @@ -36,27 +34,19 @@ describe("loadTemplateModules", () => { true, projectStructure ); - if (path.sep === path.posix.sep) { - commonTests(functionModules, "param-47543"); - } else { - commonTests(functionModules, "param-19926"); - } + commonTests(functionModules, "param-47543"); }); it("loads transpiled templates", async () => { const functionFile: path.ParsedPath[] = [ - path.parse(path.resolve(path.join(httpPath, "[param].js"))), + path.parse(path.resolve("tests/fixtures/src/functions/http/[param].js")), ]; const functionModules = await loadFunctionModules( functionFile, false, projectStructure ); - if (path.sep === path.posix.sep) { - commonTests(functionModules, "param-47853"); - } else { - commonTests(functionModules, "param-19616"); - } + commonTests(functionModules, "param-47853"); }); const commonTests = ( diff --git a/packages/pages/src/common/src/function/internal/types.test.ts b/packages/pages/src/common/src/function/internal/types.test.ts index 9b9f28cd1..bdf309761 100644 --- a/packages/pages/src/common/src/function/internal/types.test.ts +++ b/packages/pages/src/common/src/function/internal/types.test.ts @@ -86,9 +86,6 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => production: path.join("api", "example"), }, }; - if (path.sep !== path.posix.sep) { - expected.config.name = "example-23673"; - } expect(JSON.stringify(functionModuleInternal)).toEqual( JSON.stringify(expected) ); @@ -133,9 +130,6 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => production: "example", }, }; - if (path.sep !== path.posix.sep) { - expected.config.name = "example-11807"; - } expect(JSON.stringify(functionModuleInternal)).toEqual( JSON.stringify(expected) ); @@ -187,9 +181,6 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => production: path.join("api", "example", "{{testParam}}"), }, }; - if (path.sep !== path.posix.sep) { - expected.config.name = "testParam-61704"; - } expect(JSON.stringify(functionModuleInternal)).toEqual( JSON.stringify(expected) ); From a156b0a5fb61215ac6825b2a74a7db27fbc5ea81 Mon Sep 17 00:00:00 2001 From: jwartofsky Date: Mon, 11 Sep 2023 12:45:51 -0400 Subject: [PATCH 12/14] fixed npm run prod. tested generate commands --- packages/pages/src/dev/server/server.ts | 2 +- .../build/buildStart/buildStart.ts | 5 +++-- .../build/buildStart/rendering/wrapper.ts | 7 ++++--- .../build/closeBundle/bundleValidator.ts | 13 +++++++----- .../build/closeBundle/closeBundle.ts | 21 ++++++++++++------- .../build/closeBundle/functionMetadata.ts | 5 ++++- .../vite-plugin/build/closeBundle/manifest.ts | 12 ++++++----- .../build/closeBundle/serverlessFunctions.ts | 11 ++++++---- 8 files changed, 47 insertions(+), 29 deletions(-) diff --git a/packages/pages/src/dev/server/server.ts b/packages/pages/src/dev/server/server.ts index c56847c8c..15fead4f1 100644 --- a/packages/pages/src/dev/server/server.ts +++ b/packages/pages/src/dev/server/server.ts @@ -51,7 +51,7 @@ export const createServer = async ( projectStructure.config.envVarConfig.envVarPrefix ), optimizeDeps: { - include: ["react-dom", "react-dom/client"], + include: ["react-dom"], }, }); diff --git a/packages/pages/src/vite-plugin/build/buildStart/buildStart.ts b/packages/pages/src/vite-plugin/build/buildStart/buildStart.ts index 4fb3da98a..88d7d19ab 100644 --- a/packages/pages/src/vite-plugin/build/buildStart/buildStart.ts +++ b/packages/pages/src/vite-plugin/build/buildStart/buildStart.ts @@ -6,6 +6,7 @@ import { fileURLToPath } from "url"; import { PluginContext, EmitFile } from "rollup"; import { ProjectStructure } from "../../../common/src/project/structure.js"; import { Path } from "../../../common/src/project/path.js"; +import { convertToPosixPath } from "../../../common/src/template/paths.js"; export default (projectStructure: ProjectStructure) => { return async function (this: PluginContext): Promise { @@ -43,7 +44,7 @@ const copyPluginFiles = (fileEmitter: EmitFile) => { // We must use path.resolve to reconcile filepaths on Windows as glob returns filepaths with forward slashes by default. const pluginFiles = glob - .sync(`${pathToPluginsDir}/*.ts`) + .sync(convertToPosixPath(`${pathToPluginsDir}/*.ts`)) .map((f) => path.resolve(f)); if (pluginFiles.length == 0) { @@ -52,7 +53,7 @@ const copyPluginFiles = (fileEmitter: EmitFile) => { } pluginFiles.forEach((filepath) => { - const filename = path.join("plugin", path.basename(filepath)); + const filename = path.posix.join("plugin", path.basename(filepath)); fileEmitter({ type: "asset", fileName: filename, diff --git a/packages/pages/src/vite-plugin/build/buildStart/rendering/wrapper.ts b/packages/pages/src/vite-plugin/build/buildStart/rendering/wrapper.ts index edf47d292..c3c661e22 100644 --- a/packages/pages/src/vite-plugin/build/buildStart/rendering/wrapper.ts +++ b/packages/pages/src/vite-plugin/build/buildStart/rendering/wrapper.ts @@ -27,9 +27,10 @@ export const reactWrapper = async ( ? templateModuleInternal.getHeadConfig(props) : undefined; - const templateFilepath = `${projectStructure.getTemplatePaths()[0].path}/${ - templateModuleInternal.templateName - }.tsx`; + const templateFilepath = path.join( + projectStructure.getTemplatePaths()[0].path, + `${templateModuleInternal.templateName}.tsx` + ); const serverHtml = await pluginRenderTemplates.server.render({ Page: templateModuleInternal.default!, diff --git a/packages/pages/src/vite-plugin/build/closeBundle/bundleValidator.ts b/packages/pages/src/vite-plugin/build/closeBundle/bundleValidator.ts index 7b3ac8ead..7cad7e82b 100644 --- a/packages/pages/src/vite-plugin/build/closeBundle/bundleValidator.ts +++ b/packages/pages/src/vite-plugin/build/closeBundle/bundleValidator.ts @@ -2,6 +2,7 @@ import { statSync } from "fs"; import { glob } from "glob"; import path from "path"; import { ProjectStructure } from "../../../common/src/project/structure.js"; +import { convertToPosixPath } from "../../../common/src/template/paths.js"; const PLUGIN_FILESIZE_LIMIT = 10; // MB const PLUGIN_TOTAL_FILESIZE_LIMIT = 10; // MB @@ -23,11 +24,13 @@ const getBundlePaths = (projectStructure: ProjectStructure): string[] => { const { rootFolders, subfolders } = projectStructure.config; return glob.sync( - `${path.resolve(rootFolders.dist, subfolders.assets)}/{${ - subfolders.renderBundle - },${subfolders.renderer},${subfolders.serverBundle},${ - subfolders.static - }}/**/*.*` + convertToPosixPath( + `${path.resolve(rootFolders.dist, subfolders.assets)}/{${ + subfolders.renderBundle + },${subfolders.renderer},${subfolders.serverBundle},${ + subfolders.static + }}/**/*.*` + ) ); }; diff --git a/packages/pages/src/vite-plugin/build/closeBundle/closeBundle.ts b/packages/pages/src/vite-plugin/build/closeBundle/closeBundle.ts index 19d186739..ac0a7704c 100644 --- a/packages/pages/src/vite-plugin/build/closeBundle/closeBundle.ts +++ b/packages/pages/src/vite-plugin/build/closeBundle/closeBundle.ts @@ -21,6 +21,7 @@ import { shouldBundleServerlessFunctions, } from "./serverlessFunctions.js"; import { createFeaturesJson } from "../../../generate/templates/createTemplatesJsonFromModule.js"; +import { convertToPosixPath } from "../../../common/src/template/paths.js"; export default (projectStructure: ProjectStructure) => { return async () => { @@ -31,13 +32,15 @@ export default (projectStructure: ProjectStructure) => { try { const serverBundles = glob.sync( - path.join( - path.resolve( - rootFolders.dist, - subfolders.assets, - subfolders.serverBundle - ), - "**/*.js" + convertToPosixPath( + path.join( + path.resolve( + rootFolders.dist, + subfolders.assets, + subfolders.serverBundle + ), + "**/*.js" + ) ), { ignore: path.join( @@ -68,7 +71,9 @@ export default (projectStructure: ProjectStructure) => { if (shouldGenerateFunctionMetadata(projectStructure)) { finisher = logger.timedLog({ startLog: "Validating functions" }); try { - const functionFilepaths = getFunctionFilepaths("dist/functions"); + const functionFilepaths = getFunctionFilepaths( + path.join("dist", "functions") + ); await Promise.all( functionFilepaths.map(async (filepath) => { const jsFilepath = path.format(filepath).replace(".ts", ".js"); diff --git a/packages/pages/src/vite-plugin/build/closeBundle/functionMetadata.ts b/packages/pages/src/vite-plugin/build/closeBundle/functionMetadata.ts index 55d1364bd..0cee49fb0 100644 --- a/packages/pages/src/vite-plugin/build/closeBundle/functionMetadata.ts +++ b/packages/pages/src/vite-plugin/build/closeBundle/functionMetadata.ts @@ -6,6 +6,7 @@ import { glob } from "glob"; import chalk from "chalk"; import os from "os"; import { ProjectStructure } from "../../../common/src/project/structure.js"; +import { convertToPosixPath } from "../../../common/src/template/paths.js"; const TEMP_DIR = os.tmpdir(); @@ -26,7 +27,9 @@ const getFunctionMetadataMap = async ( ): Promise> => { const filepaths = glob .sync( - path.join(projectStructure.config.rootFolders.functions, "**/*.{js,ts}"), + convertToPosixPath( + path.join(projectStructure.config.rootFolders.functions, "**/*.{js,ts}") + ), { nodir: true } ) .map((f) => path.resolve(f)); diff --git a/packages/pages/src/vite-plugin/build/closeBundle/manifest.ts b/packages/pages/src/vite-plugin/build/closeBundle/manifest.ts index a5d6781fe..ff3b278b0 100644 --- a/packages/pages/src/vite-plugin/build/closeBundle/manifest.ts +++ b/packages/pages/src/vite-plugin/build/closeBundle/manifest.ts @@ -29,11 +29,13 @@ export const generateManifestFile = ( // Add the renderPaths to the manifest. This defines the _client and _server entries. const renderPaths = glob.sync( - path.resolve( - projectStructure.config.rootFolders.dist, - projectStructure.config.subfolders.assets, - projectStructure.config.subfolders.renderBundle, - "**/*.js" + convertToPosixPath( + path.resolve( + projectStructure.config.rootFolders.dist, + projectStructure.config.subfolders.assets, + projectStructure.config.subfolders.renderBundle, + "**/*.js" + ) ) ); diff --git a/packages/pages/src/vite-plugin/build/closeBundle/serverlessFunctions.ts b/packages/pages/src/vite-plugin/build/closeBundle/serverlessFunctions.ts index 7e63866de..1730afe55 100644 --- a/packages/pages/src/vite-plugin/build/closeBundle/serverlessFunctions.ts +++ b/packages/pages/src/vite-plugin/build/closeBundle/serverlessFunctions.ts @@ -6,6 +6,7 @@ import { COMMON_ESBUILD_LOADERS } from "../../../common/src/loader/esbuild.js"; import { processEnvVariables } from "../../../util/processEnvVariables.js"; import { FunctionMetadataParser } from "../../../common/src/function/internal/functionMetadataParser.js"; import fs from "fs"; +import { convertToPosixPath } from "../../../common/src/template/paths.js"; /** * Returns a mapping of file path (relative to the repo root) to the metadata @@ -20,10 +21,12 @@ export const bundleServerlessFunctions = async ( const filepaths = glob .sync( - path.join( - rootFolders.source, - subfolders.serverlessFunctions, - "**/*.{js,ts}" + convertToPosixPath( + path.join( + rootFolders.source, + subfolders.serverlessFunctions, + "**/*.{js,ts}" + ) ), { nodir: true } ) From a765ea22016f6a4ed3ad86643fa48716ff7d08a7 Mon Sep 17 00:00:00 2001 From: jwartofsky Date: Mon, 11 Sep 2023 13:08:42 -0400 Subject: [PATCH 13/14] fix subprocess test --- packages/pages/src/util/runSubprocess.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/pages/src/util/runSubprocess.test.ts b/packages/pages/src/util/runSubprocess.test.ts index f40e9f20f..ba019cea2 100644 --- a/packages/pages/src/util/runSubprocess.test.ts +++ b/packages/pages/src/util/runSubprocess.test.ts @@ -1,5 +1,4 @@ import runSubprocess from "./runSubprocess.js"; -import path from "node:path"; describe("runSubprocess", () => { it("runs echo successfully", async () => { @@ -8,11 +7,12 @@ describe("runSubprocess", () => { }); it("returns non-zero when subprocess fails", async () => { - const exitCode = await runSubprocess("echo", ["$((0/0))"]); - if (path.sep === path.posix.sep) { + if (process.platform === "win32") { + const exitCode = await runSubprocess("powershell.exe", ["0/0"]); + expect(exitCode).not.toEqual(0); + } else { + const exitCode = await runSubprocess("echo", ["$((0/0))"]); expect(exitCode).not.toEqual(0); } - // commands do not return exit codes on Windows, so we skip this test in that case - expect(true).toEqual(true); }); }); From 58d9f20cd227a9c3e909c8e6d67eee0b028fe469 Mon Sep 17 00:00:00 2001 From: jwartofsky Date: Mon, 11 Sep 2023 13:28:53 -0400 Subject: [PATCH 14/14] restore react-dom/client --- packages/pages/src/dev/server/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pages/src/dev/server/server.ts b/packages/pages/src/dev/server/server.ts index 15fead4f1..c56847c8c 100644 --- a/packages/pages/src/dev/server/server.ts +++ b/packages/pages/src/dev/server/server.ts @@ -51,7 +51,7 @@ export const createServer = async ( projectStructure.config.envVarConfig.envVarPrefix ), optimizeDeps: { - include: ["react-dom"], + include: ["react-dom", "react-dom/client"], }, });