diff --git a/packages/pages/src/bin/spawn.ts b/packages/pages/src/bin/spawn.ts index 1a588b6c1..8f83d0dda 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.win32.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" }) diff --git a/packages/pages/src/common/src/function/internal/functionMetadataParser.ts b/packages/pages/src/common/src/function/internal/functionMetadataParser.ts index 1414c5540..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"]; @@ -42,10 +43,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 +67,7 @@ export class FunctionMetadataParser { if ( functionType === "onUrlChange" && - relativePath.split("/").length > 2 && + relativePath.split(path.sep).length > 2 && functionsRoot !== distPath ) { throw new Error( @@ -76,7 +79,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("."); @@ -111,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/getFunctionFilepaths.test.ts b/packages/pages/src/common/src/function/internal/getFunctionFilepaths.test.ts index 8fb401787..cc10df552 100644 --- a/packages/pages/src/common/src/function/internal/getFunctionFilepaths.test.ts +++ b/packages/pages/src/common/src/function/internal/getFunctionFilepaths.test.ts @@ -2,41 +2,41 @@ import path from "path"; import { getFunctionFilepaths } from "./getFunctionFilepaths.js"; import { minimatch } from "minimatch"; -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 = [ - `${multiLevelPath}/test1.ts`, - `${multiLevelPath}/test2.js`, - `${rootPath}/test3.js`, - `${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: "/", - dir: process.cwd() + "/src/functions/http/api/fetch", + root: path.resolve("/"), + dir: path.join(process.cwd(), multiLevelPath), base: "test1.ts", ext: ".ts", name: "test1", }, { - root: "/", - dir: process.cwd() + "/src/functions/http/api/fetch", + root: path.resolve("/"), + dir: path.join(process.cwd(), multiLevelPath), base: "test2.js", ext: ".js", name: "test2", }, { - root: "/", - dir: process.cwd() + "/src/functions", + root: path.resolve("/"), + dir: path.join(process.cwd(), rootPath), base: "test3.js", ext: ".js", name: "test3", }, { - root: "/", - dir: process.cwd() + "/src/functions", + root: path.resolve("/"), + dir: path.join(process.cwd(), rootPath), base: "test4.ts", ext: ".ts", name: "test4", @@ -53,7 +53,7 @@ jest.mock("glob", () => { describe("getFunctionFilepaths", () => { it("collects all function files under the src/functions path", () => { - const templatesFilepath = getFunctionFilepaths("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/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..694058a70 100644 --- a/packages/pages/src/common/src/function/internal/loader.test.ts +++ b/packages/pages/src/common/src/function/internal/loader.test.ts @@ -26,7 +26,7 @@ describe("loadTemplateModules", () => { it("loads and transpiles raw templates", async () => { const functionFile: path.ParsedPath[] = [ - path.parse("tests/fixtures/src/functions/http/[param].ts"), + path.parse(path.resolve("tests/fixtures/src/functions/http/[param].ts")), ]; const functionModules = await loadFunctionModules( 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..bdf309761 100644 --- a/packages/pages/src/common/src/function/internal/types.test.ts +++ b/packages/pages/src/common/src/function/internal/types.test.ts @@ -51,7 +51,7 @@ const exampleOnUrlChangeArgument: SitesOnUrlChangeRequest = { }; const createMockFilePath = (filepath: string): path.ParsedPath => { - return path.parse(path.resolve(path.join("src/functions/", filepath))); + return path.parse(path.resolve(path.join("src", "functions", filepath))); }; describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => { @@ -63,7 +63,7 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => }; const functionModuleInternal = convertFunctionModuleToFunctionModuleInternal( - createMockFilePath("http/api/example.ts"), + createMockFilePath(path.join("http", "api", "example.ts")), functionModule, projectStructure ); @@ -74,16 +74,16 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => event: "API", }, filePath: { - root: "/", - dir: process.cwd() + "/src/functions/http/api", + root: path.resolve("/"), + dir: path.join(process.cwd(), "src", "functions", "http", "api"), base: "example.ts", ext: ".ts", name: "example", }, slug: { - original: "api/example", - dev: "api/example", - production: "api/example", + original: path.join("api", "example"), + dev: path.join("api", "example"), + production: path.join("api", "example"), }, }; expect(JSON.stringify(functionModuleInternal)).toEqual( @@ -107,7 +107,7 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => }; const functionModuleInternal = convertFunctionModuleToFunctionModuleInternal( - createMockFilePath("onUrlChange/example.ts"), + createMockFilePath(path.join("onUrlChange", "example.ts")), functionModule, projectStructure ); @@ -118,8 +118,8 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => event: "ON_URL_CHANGE", }, filePath: { - root: "/", - dir: process.cwd() + "/src/functions/onUrlChange", + root: path.resolve("/"), + dir: path.join(process.cwd(), "src", "functions", "onUrlChange"), base: "example.ts", ext: ".ts", name: "example", @@ -149,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 ); @@ -160,16 +162,23 @@ describe("internal/types - convertFunctionModuleToFunctionModuleInternal", () => event: "API", }, filePath: { - root: "/", - dir: process.cwd() + "/src/functions/http/api/example", + root: path.resolve("/"), + dir: path.join( + 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: 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 61e56276d..582aa2485 100644 --- a/packages/pages/src/common/src/template/internal/getTemplateFilepaths.test.ts +++ b/packages/pages/src/common/src/template/internal/getTemplateFilepaths.test.ts @@ -3,19 +3,19 @@ import { getTemplateFilepaths } from "./getTemplateFilepaths.js"; import { minimatch } from "minimatch"; import { Path } from "../../project/path.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 = [ - `${domain1Path}/brand1.tsx`, - `${domain1Path}/test.tsx`, - `${domain2Path}/brand2.tsx`, - `${domain2Path}/test.tsx`, - `${rootPath}/share.tsx`, - `${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)); }, @@ -28,7 +28,7 @@ describe("getTemplateFilepaths", () => { new Path(path.join(process.cwd(), rootPath)), ]); expect(templatesFilepath.sort()).toEqual( - [`${rootPath}/share.tsx`, `${rootPath}/test.tsx`].sort() + [path.join(rootPath, "share.tsx"), path.join(rootPath, "test.tsx")].sort() ); }); @@ -39,9 +39,9 @@ describe("getTemplateFilepaths", () => { ]); expect(templatesFilepath.sort()).toEqual( [ - `${rootPath}/share.tsx`, - `${domain1Path}/test.tsx`, - `${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/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..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,6 +3,9 @@ import { TemplateModuleInternal, } from "./types.js"; import { Template, TemplateModule } from "../types.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 () => { @@ -22,7 +25,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - "src/templates/myTemplateName.tsx", + myTemplateNamePath, templateModule, false ); @@ -40,7 +43,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: "src/templates/myTemplateName.tsx", + path: myTemplateNamePath, filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -63,7 +66,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - "src/templates/myTemplateName.tsx", + myTemplateNamePath, templateModule, false ); @@ -76,7 +79,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: "src/templates/myTemplateName.tsx", + path: myTemplateNamePath, filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -98,7 +101,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - "src/templates/myTemplateName.0ab33d.tsx", + path.join("src", "templates", "myTemplateName.0ab33d.tsx"), templateModule, true ); @@ -111,7 +114,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: "src/templates/myTemplateName.0ab33d.tsx", + path: path.join("src", "templates", "myTemplateName.0ab33d.tsx"), filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -137,7 +140,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - "src/templates/myTemplateName.tsx", + myTemplateNamePath, templateModule, false ); @@ -155,7 +158,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: true, streamId: "$id", }, - path: "src/templates/myTemplateName.tsx", + path: myTemplateNamePath, filename: "myTemplateName.tsx", templateName: "myTemplateName", }; @@ -182,7 +185,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => const templateConfigInternal = convertTemplateModuleToTemplateModuleInternal( - "src/templates/myTemplateName.tsx", + myTemplateNamePath, templateModule, false ); @@ -200,7 +203,7 @@ describe("internal/types - convertTemplateModuleToTemplateModuleInternal", () => hydrate: false, streamId: "$id", }, - path: "src/templates/myTemplateName.tsx", + path: myTemplateNamePath, 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 fc7b78e99..ca8586208 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..c2ce4a5ac 100644 --- a/packages/pages/src/common/src/template/paths.test.ts +++ b/packages/pages/src/common/src/template/paths.test.ts @@ -1,6 +1,15 @@ -import { getRelativePrefixToRootFromPath } from "../../src/template/paths.js"; +import { + convertToPosixPath, + getRelativePrefixToRootFromPath, +} from "../../src/template/paths.js"; +import path from "node:path"; describe("getRelativePrefixToRootFromPath", () => { + 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"; @@ -12,12 +21,19 @@ 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 posix path", async () => { + 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/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..ba019cea2 100644 --- a/packages/pages/src/util/runSubprocess.test.ts +++ b/packages/pages/src/util/runSubprocess.test.ts @@ -7,7 +7,12 @@ describe("runSubprocess", () => { }); it("returns non-zero when subprocess fails", async () => { - const exitCode = await runSubprocess("echo", ["$((0/0))"]); - expect(exitCode).not.toEqual(0); + 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); + } }); }); 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 } ) 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