From 925fb8400d733e453b7cd74a8e44dbe456077d8c Mon Sep 17 00:00:00 2001 From: Giorgio Boa <35845425+gioboa@users.noreply.github.com> Date: Tue, 25 Jun 2024 20:27:34 +0000 Subject: [PATCH] 35aba35 feat: manage assetsDir (#6588) https://github.com/QwikDev/qwik/commit/798db2c8c04919364068197c3d9d5765de1105ee --- adapters/cloudflare-pages/vite/index.cjs | 7 ++++--- adapters/cloudflare-pages/vite/index.mjs | 7 ++++--- adapters/shared/vite/index.cjs | 17 +++++++++++------ adapters/shared/vite/index.d.ts | 1 + adapters/shared/vite/index.mjs | 17 +++++++++++------ adapters/static/vite/index.cjs | 17 +++++++++++------ adapters/static/vite/index.mjs | 17 +++++++++++------ package.json | 2 +- vite/index.cjs | 16 ++++++++++------ vite/index.mjs | 16 ++++++++++------ 10 files changed, 74 insertions(+), 43 deletions(-) diff --git a/adapters/cloudflare-pages/vite/index.cjs b/adapters/cloudflare-pages/vite/index.cjs index d25c242..e2b944d 100644 --- a/adapters/cloudflare-pages/vite/index.cjs +++ b/adapters/cloudflare-pages/vite/index.cjs @@ -82,14 +82,15 @@ function cloudflarePagesAdapter(opts = {}) { publicDir: false }; }, - async generate({ clientOutDir, serverOutDir, basePathname }) { + async generate({ clientOutDir, serverOutDir, basePathname, assetsDir }) { const routesJsonPath = (0, import_node_path.join)(clientOutDir, "_routes.json"); const hasRoutesJson = import_node_fs.default.existsSync(routesJsonPath); if (!hasRoutesJson && opts.functionRoutes !== false) { + const pathName = assetsDir ? (0, import_node_path.join)(basePathname, assetsDir) : basePathname; const routesJson = { version: 1, - include: [basePathname + "*"], - exclude: [basePathname + "build/*", basePathname + "assets/*"] + include: [pathName + "*"], + exclude: [pathName + "build/*", pathName + "assets/*"] }; await import_node_fs.default.promises.writeFile(routesJsonPath, JSON.stringify(routesJson, void 0, 2)); } diff --git a/adapters/cloudflare-pages/vite/index.mjs b/adapters/cloudflare-pages/vite/index.mjs index e34241b..d0210d7 100644 --- a/adapters/cloudflare-pages/vite/index.mjs +++ b/adapters/cloudflare-pages/vite/index.mjs @@ -48,14 +48,15 @@ function cloudflarePagesAdapter(opts = {}) { publicDir: false }; }, - async generate({ clientOutDir, serverOutDir, basePathname }) { + async generate({ clientOutDir, serverOutDir, basePathname, assetsDir }) { const routesJsonPath = join(clientOutDir, "_routes.json"); const hasRoutesJson = fs.existsSync(routesJsonPath); if (!hasRoutesJson && opts.functionRoutes !== false) { + const pathName = assetsDir ? join(basePathname, assetsDir) : basePathname; const routesJson = { version: 1, - include: [basePathname + "*"], - exclude: [basePathname + "build/*", basePathname + "assets/*"] + include: [pathName + "*"], + exclude: [pathName + "build/*", pathName + "assets/*"] }; await fs.promises.writeFile(routesJsonPath, JSON.stringify(routesJson, void 0, 2)); } diff --git a/adapters/shared/vite/index.cjs b/adapters/shared/vite/index.cjs index 1d12ace..dc8726b 100644 --- a/adapters/shared/vite/index.cjs +++ b/adapters/shared/vite/index.cjs @@ -45,8 +45,11 @@ var import_node_path2 = require("node:path"); var import_node_fs = __toESM(require("node:fs"), 1); var import_node_path = require("node:path"); var import_request_handler = require("../../../middleware/request-handler/index.cjs"); -async function postBuild(clientOutDir, basePathname, userStaticPaths, format, cleanStatic) { - const ignorePathnames = /* @__PURE__ */ new Set([basePathname + "build/", basePathname + "assets/"]); +async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanStatic) { + if (pathName && !pathName.endsWith("/")) { + pathName += "/"; + } + const ignorePathnames = /* @__PURE__ */ new Set([pathName + "build/", pathName + "assets/"]); const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash)); const notFounds = []; const loadItem = async (fsDir, fsName, pathname) => { @@ -78,10 +81,10 @@ async function postBuild(clientOutDir, basePathname, userStaticPaths, format, cl await Promise.all(itemNames.map((i) => loadItem(fsDir, i, pathname))); }; if (import_node_fs.default.existsSync(clientOutDir)) { - await loadDir(clientOutDir, basePathname); + await loadDir(clientOutDir, pathName); } - const notFoundPathsCode = createNotFoundPathsModule(basePathname, notFounds, format); - const staticPathsCode = createStaticPathsModule(basePathname, staticPaths, format); + const notFoundPathsCode = createNotFoundPathsModule(pathName, notFounds, format); + const staticPathsCode = createStaticPathsModule(pathName, staticPaths, format); return { notFoundPathsCode, staticPathsCode @@ -264,6 +267,7 @@ function viteAdapter(opts) { const basePathname = qwikCityPlugin.api.getBasePathname(); const clientOutDir = qwikVitePlugin.api.getClientOutDir(); const clientPublicOutDir = qwikVitePlugin.api.getClientPublicOutDir(); + const assetsDir = qwikVitePlugin.api.getAssetsDir(); const rootDir = qwikVitePlugin.api.getRootDir() ?? void 0; if (renderModulePath && qwikCityPlanModulePath && clientOutDir && clientPublicOutDir) { let ssgOrigin = ((_a = opts.ssg) == null ? void 0 : _a.origin) ?? opts.origin; @@ -306,7 +310,7 @@ function viteAdapter(opts) { staticPaths.push(...staticGenerateResult.staticPaths); const { staticPathsCode, notFoundPathsCode } = await postBuild( clientPublicOutDir, - basePathname, + assetsDir ? (0, import_node_path2.join)(basePathname, assetsDir) : basePathname, staticPaths, format, !!opts.cleanStaticGenerated @@ -326,6 +330,7 @@ function viteAdapter(opts) { clientPublicOutDir, basePathname, routes, + assetsDir, warn: (message) => this.warn(message), error: (message) => this.error(message) }); diff --git a/adapters/shared/vite/index.d.ts b/adapters/shared/vite/index.d.ts index a799007..c5db173 100644 --- a/adapters/shared/vite/index.d.ts +++ b/adapters/shared/vite/index.d.ts @@ -105,6 +105,7 @@ declare interface ViteAdapterPluginOptions { serverOutDir: string; basePathname: string; routes: BuildRoute[]; + assetsDir?: string; warn: (message: string) => void; error: (message: string) => void; }) => Promise; diff --git a/adapters/shared/vite/index.mjs b/adapters/shared/vite/index.mjs index b3b3440..b590804 100644 --- a/adapters/shared/vite/index.mjs +++ b/adapters/shared/vite/index.mjs @@ -6,8 +6,11 @@ import { basename, dirname, join as join2, resolve } from "node:path"; import fs from "node:fs"; import { join } from "node:path"; import { getErrorHtml } from "../../../middleware/request-handler/index.mjs"; -async function postBuild(clientOutDir, basePathname, userStaticPaths, format, cleanStatic) { - const ignorePathnames = /* @__PURE__ */ new Set([basePathname + "build/", basePathname + "assets/"]); +async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanStatic) { + if (pathName && !pathName.endsWith("/")) { + pathName += "/"; + } + const ignorePathnames = /* @__PURE__ */ new Set([pathName + "build/", pathName + "assets/"]); const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash)); const notFounds = []; const loadItem = async (fsDir, fsName, pathname) => { @@ -39,10 +42,10 @@ async function postBuild(clientOutDir, basePathname, userStaticPaths, format, cl await Promise.all(itemNames.map((i) => loadItem(fsDir, i, pathname))); }; if (fs.existsSync(clientOutDir)) { - await loadDir(clientOutDir, basePathname); + await loadDir(clientOutDir, pathName); } - const notFoundPathsCode = createNotFoundPathsModule(basePathname, notFounds, format); - const staticPathsCode = createStaticPathsModule(basePathname, staticPaths, format); + const notFoundPathsCode = createNotFoundPathsModule(pathName, notFounds, format); + const staticPathsCode = createStaticPathsModule(pathName, staticPaths, format); return { notFoundPathsCode, staticPathsCode @@ -225,6 +228,7 @@ function viteAdapter(opts) { const basePathname = qwikCityPlugin.api.getBasePathname(); const clientOutDir = qwikVitePlugin.api.getClientOutDir(); const clientPublicOutDir = qwikVitePlugin.api.getClientPublicOutDir(); + const assetsDir = qwikVitePlugin.api.getAssetsDir(); const rootDir = qwikVitePlugin.api.getRootDir() ?? void 0; if (renderModulePath && qwikCityPlanModulePath && clientOutDir && clientPublicOutDir) { let ssgOrigin = ((_a = opts.ssg) == null ? void 0 : _a.origin) ?? opts.origin; @@ -267,7 +271,7 @@ function viteAdapter(opts) { staticPaths.push(...staticGenerateResult.staticPaths); const { staticPathsCode, notFoundPathsCode } = await postBuild( clientPublicOutDir, - basePathname, + assetsDir ? join2(basePathname, assetsDir) : basePathname, staticPaths, format, !!opts.cleanStaticGenerated @@ -287,6 +291,7 @@ function viteAdapter(opts) { clientPublicOutDir, basePathname, routes, + assetsDir, warn: (message) => this.warn(message), error: (message) => this.error(message) }); diff --git a/adapters/static/vite/index.cjs b/adapters/static/vite/index.cjs index d72fa9b..9f39529 100644 --- a/adapters/static/vite/index.cjs +++ b/adapters/static/vite/index.cjs @@ -42,8 +42,11 @@ var import_node_path2 = require("node:path"); var import_node_fs = __toESM(require("node:fs"), 1); var import_node_path = require("node:path"); var import_request_handler = require("@builder.io/qwik-city/middleware/request-handler"); -async function postBuild(clientOutDir, basePathname, userStaticPaths, format, cleanStatic) { - const ignorePathnames = /* @__PURE__ */ new Set([basePathname + "build/", basePathname + "assets/"]); +async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanStatic) { + if (pathName && !pathName.endsWith("/")) { + pathName += "/"; + } + const ignorePathnames = /* @__PURE__ */ new Set([pathName + "build/", pathName + "assets/"]); const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash)); const notFounds = []; const loadItem = async (fsDir, fsName, pathname) => { @@ -75,10 +78,10 @@ async function postBuild(clientOutDir, basePathname, userStaticPaths, format, cl await Promise.all(itemNames.map((i) => loadItem(fsDir, i, pathname))); }; if (import_node_fs.default.existsSync(clientOutDir)) { - await loadDir(clientOutDir, basePathname); + await loadDir(clientOutDir, pathName); } - const notFoundPathsCode = createNotFoundPathsModule(basePathname, notFounds, format); - const staticPathsCode = createStaticPathsModule(basePathname, staticPaths, format); + const notFoundPathsCode = createNotFoundPathsModule(pathName, notFounds, format); + const staticPathsCode = createStaticPathsModule(pathName, staticPaths, format); return { notFoundPathsCode, staticPathsCode @@ -261,6 +264,7 @@ function viteAdapter(opts) { const basePathname = qwikCityPlugin.api.getBasePathname(); const clientOutDir = qwikVitePlugin.api.getClientOutDir(); const clientPublicOutDir = qwikVitePlugin.api.getClientPublicOutDir(); + const assetsDir = qwikVitePlugin.api.getAssetsDir(); const rootDir = qwikVitePlugin.api.getRootDir() ?? void 0; if (renderModulePath && qwikCityPlanModulePath && clientOutDir && clientPublicOutDir) { let ssgOrigin = ((_a = opts.ssg) == null ? void 0 : _a.origin) ?? opts.origin; @@ -303,7 +307,7 @@ function viteAdapter(opts) { staticPaths.push(...staticGenerateResult.staticPaths); const { staticPathsCode, notFoundPathsCode } = await postBuild( clientPublicOutDir, - basePathname, + assetsDir ? (0, import_node_path2.join)(basePathname, assetsDir) : basePathname, staticPaths, format, !!opts.cleanStaticGenerated @@ -323,6 +327,7 @@ function viteAdapter(opts) { clientPublicOutDir, basePathname, routes, + assetsDir, warn: (message) => this.warn(message), error: (message) => this.error(message) }); diff --git a/adapters/static/vite/index.mjs b/adapters/static/vite/index.mjs index 59e1af3..652217c 100644 --- a/adapters/static/vite/index.mjs +++ b/adapters/static/vite/index.mjs @@ -6,8 +6,11 @@ import { basename, dirname, join as join2, resolve } from "node:path"; import fs from "node:fs"; import { join } from "node:path"; import { getErrorHtml } from "@builder.io/qwik-city/middleware/request-handler"; -async function postBuild(clientOutDir, basePathname, userStaticPaths, format, cleanStatic) { - const ignorePathnames = /* @__PURE__ */ new Set([basePathname + "build/", basePathname + "assets/"]); +async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanStatic) { + if (pathName && !pathName.endsWith("/")) { + pathName += "/"; + } + const ignorePathnames = /* @__PURE__ */ new Set([pathName + "build/", pathName + "assets/"]); const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash)); const notFounds = []; const loadItem = async (fsDir, fsName, pathname) => { @@ -39,10 +42,10 @@ async function postBuild(clientOutDir, basePathname, userStaticPaths, format, cl await Promise.all(itemNames.map((i) => loadItem(fsDir, i, pathname))); }; if (fs.existsSync(clientOutDir)) { - await loadDir(clientOutDir, basePathname); + await loadDir(clientOutDir, pathName); } - const notFoundPathsCode = createNotFoundPathsModule(basePathname, notFounds, format); - const staticPathsCode = createStaticPathsModule(basePathname, staticPaths, format); + const notFoundPathsCode = createNotFoundPathsModule(pathName, notFounds, format); + const staticPathsCode = createStaticPathsModule(pathName, staticPaths, format); return { notFoundPathsCode, staticPathsCode @@ -225,6 +228,7 @@ function viteAdapter(opts) { const basePathname = qwikCityPlugin.api.getBasePathname(); const clientOutDir = qwikVitePlugin.api.getClientOutDir(); const clientPublicOutDir = qwikVitePlugin.api.getClientPublicOutDir(); + const assetsDir = qwikVitePlugin.api.getAssetsDir(); const rootDir = qwikVitePlugin.api.getRootDir() ?? void 0; if (renderModulePath && qwikCityPlanModulePath && clientOutDir && clientPublicOutDir) { let ssgOrigin = ((_a = opts.ssg) == null ? void 0 : _a.origin) ?? opts.origin; @@ -267,7 +271,7 @@ function viteAdapter(opts) { staticPaths.push(...staticGenerateResult.staticPaths); const { staticPathsCode, notFoundPathsCode } = await postBuild( clientPublicOutDir, - basePathname, + assetsDir ? join2(basePathname, assetsDir) : basePathname, staticPaths, format, !!opts.cleanStaticGenerated @@ -287,6 +291,7 @@ function viteAdapter(opts) { clientPublicOutDir, basePathname, routes, + assetsDir, warn: (message) => this.warn(message), error: (message) => this.error(message) }); diff --git a/package.json b/package.json index 2099d5d..7651317 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@builder.io/qwik-city", "description": "The meta-framework for Qwik.", - "version": "1.5.7-dev20240622232712", + "version": "1.5.7-dev20240625202021", "bugs": "https://github.com/QwikDev/qwik/issues", "dependencies": { "@mdx-js/mdx": "^3.0.1", diff --git a/vite/index.cjs b/vite/index.cjs index 7ef3915..b843b58 100644 --- a/vite/index.cjs +++ b/vite/index.cjs @@ -26578,8 +26578,11 @@ navigator.serviceWorker?.getRegistrations().then((regs) => { // packages/qwik-city/adapters/shared/vite/post-build.ts var import_node_fs7 = __toESM(require("node:fs"), 1); var import_node_path9 = require("node:path"); -async function postBuild(clientOutDir, basePathname, userStaticPaths, format, cleanStatic) { - const ignorePathnames = /* @__PURE__ */ new Set([basePathname + "build/", basePathname + "assets/"]); +async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanStatic) { + if (pathName && !pathName.endsWith("/")) { + pathName += "/"; + } + const ignorePathnames = /* @__PURE__ */ new Set([pathName + "build/", pathName + "assets/"]); const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash)); const notFounds = []; const loadItem = async (fsDir, fsName, pathname) => { @@ -26611,10 +26614,10 @@ async function postBuild(clientOutDir, basePathname, userStaticPaths, format, cl await Promise.all(itemNames.map((i) => loadItem(fsDir, i, pathname))); }; if (import_node_fs7.default.existsSync(clientOutDir)) { - await loadDir(clientOutDir, basePathname); + await loadDir(clientOutDir, pathName); } - const notFoundPathsCode = createNotFoundPathsModule(basePathname, notFounds, format); - const staticPathsCode = createStaticPathsModule(basePathname, staticPaths, format); + const notFoundPathsCode = createNotFoundPathsModule(pathName, notFounds, format); + const staticPathsCode = createStaticPathsModule(pathName, staticPaths, format); return { notFoundPathsCode, staticPathsCode @@ -27111,9 +27114,10 @@ function qwikCityPlugin(userOpts) { } } if (outDir && clientOutDir) { + const assetsDir = qwikPlugin.api.getAssetsDir(); const { staticPathsCode, notFoundPathsCode } = await postBuild( clientOutDir, - api.getBasePathname(), + assetsDir ? (0, import_node_path11.join)(api.getBasePathname(), assetsDir) : api.getBasePathname(), [], ssrFormat, false diff --git a/vite/index.mjs b/vite/index.mjs index d514021..065c6e5 100644 --- a/vite/index.mjs +++ b/vite/index.mjs @@ -26573,8 +26573,11 @@ navigator.serviceWorker?.getRegistrations().then((regs) => { // packages/qwik-city/adapters/shared/vite/post-build.ts import fs6 from "node:fs"; import { join as join5 } from "node:path"; -async function postBuild(clientOutDir, basePathname, userStaticPaths, format, cleanStatic) { - const ignorePathnames = /* @__PURE__ */ new Set([basePathname + "build/", basePathname + "assets/"]); +async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanStatic) { + if (pathName && !pathName.endsWith("/")) { + pathName += "/"; + } + const ignorePathnames = /* @__PURE__ */ new Set([pathName + "build/", pathName + "assets/"]); const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash)); const notFounds = []; const loadItem = async (fsDir, fsName, pathname) => { @@ -26606,10 +26609,10 @@ async function postBuild(clientOutDir, basePathname, userStaticPaths, format, cl await Promise.all(itemNames.map((i) => loadItem(fsDir, i, pathname))); }; if (fs6.existsSync(clientOutDir)) { - await loadDir(clientOutDir, basePathname); + await loadDir(clientOutDir, pathName); } - const notFoundPathsCode = createNotFoundPathsModule(basePathname, notFounds, format); - const staticPathsCode = createStaticPathsModule(basePathname, staticPaths, format); + const notFoundPathsCode = createNotFoundPathsModule(pathName, notFounds, format); + const staticPathsCode = createStaticPathsModule(pathName, staticPaths, format); return { notFoundPathsCode, staticPathsCode @@ -27106,9 +27109,10 @@ function qwikCityPlugin(userOpts) { } } if (outDir && clientOutDir) { + const assetsDir = qwikPlugin.api.getAssetsDir(); const { staticPathsCode, notFoundPathsCode } = await postBuild( clientOutDir, - api.getBasePathname(), + assetsDir ? join6(api.getBasePathname(), assetsDir) : api.getBasePathname(), [], ssrFormat, false