From ead9b8c6f6488876eb8a9d6b7f26c924814795a5 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Fri, 14 Oct 2022 16:40:19 +0530 Subject: [PATCH] Revert "fix(build): better align server and client side filename sanitization" (#1484) * Revert "fix(build): remove leading underscore from chunks" This reverts commit 41a519cc775551387093e1e18323b72bd1efe9ad. * Revert "fix(build): better align server and client side filename sanitization" This reverts commit 3fd20fedb81c88c188cff22b4c03ccc2ad416d2c. --- src/client/app/utils.ts | 10 +++------- src/node/build/bundle.ts | 2 -- src/node/build/render.ts | 5 ++--- src/shared/shared.ts | 18 ------------------ 4 files changed, 5 insertions(+), 30 deletions(-) diff --git a/src/client/app/utils.ts b/src/client/app/utils.ts index 4e9687db..2bc3f28b 100644 --- a/src/client/app/utils.ts +++ b/src/client/app/utils.ts @@ -1,5 +1,5 @@ import { siteDataRef } from './data.js' -import { inBrowser, EXTERNAL_URL_RE, sanitizeFileName } from '../shared.js' +import { inBrowser, EXTERNAL_URL_RE } from '../shared.js' export { inBrowser } @@ -36,18 +36,14 @@ export function pathToFile(path: string): string { if (inBrowser) { const base = import.meta.env.BASE_URL pagePath = - sanitizeFileName( - pagePath.slice(base.length).replace(/\//g, '_') || 'index' - ) + '.md' + (pagePath.slice(base.length).replace(/\//g, '_') || 'index') + '.md' // client production build needs to account for page hash, which is // injected directly in the page's html const pageHash = __VP_HASH_MAP__[pagePath.toLowerCase()] pagePath = `${base}assets/${pagePath}.${pageHash}.js` } else { // ssr build uses much simpler name mapping - pagePath = `./${sanitizeFileName( - pagePath.slice(1).replace(/\//g, '_') - )}.md.js` + pagePath = `./${pagePath.slice(1).replace(/\//g, '_')}.md.js` } } diff --git a/src/node/build/bundle.ts b/src/node/build/bundle.ts index 8bab50bd..1ec51b37 100644 --- a/src/node/build/bundle.ts +++ b/src/node/build/bundle.ts @@ -7,7 +7,6 @@ import { slash } from '../utils/slash' import { SiteConfig } from '../config' import { APP_PATH } from '../alias' import { createVitePressPlugin } from '../plugin' -import { sanitizeFileName } from '../shared' import { buildMPAClient } from './buildMPAClient' export const okMark = '\x1b[32m✓\x1b[0m' @@ -69,7 +68,6 @@ export async function bundle( // other preserveEntrySignatures: 'allow-extension', output: { - sanitizeFileName, ...rollupOptions?.output, ...(ssr ? { diff --git a/src/node/build/render.ts b/src/node/build/render.ts index 89d94167..238bb0ff 100644 --- a/src/node/build/render.ts +++ b/src/node/build/render.ts @@ -10,8 +10,7 @@ import { createTitle, notFoundPageData, mergeHead, - EXTERNAL_URL_RE, - sanitizeFileName + EXTERNAL_URL_RE } from '../shared' import { slash } from '../utils/slash' import { SiteConfig, resolveSiteDataByRoute } from '../config' @@ -32,7 +31,7 @@ export async function renderPage( // render page const content = await render(routePath) - const pageName = sanitizeFileName(page.replace(/\//g, '_')) + const pageName = page.replace(/\//g, '_') // server build doesn't need hash const pageServerJsFileName = pageName + '.js' // for any initial page load, we only need the lean version of the page js diff --git a/src/shared/shared.ts b/src/shared/shared.ts index 29d1e424..2459bafe 100644 --- a/src/shared/shared.ts +++ b/src/shared/shared.ts @@ -161,21 +161,3 @@ function hasTag(head: HeadConfig[], tag: HeadConfig) { export function mergeHead(prev: HeadConfig[], curr: HeadConfig[]) { return [...prev.filter((tagAttrs) => !hasTag(curr, tagAttrs)), ...curr] } - -// https://github.com/rollup/rollup/blob/fec513270c6ac350072425cc045db367656c623b/src/utils/sanitizeFileName.ts - -const INVALID_CHAR_REGEX = /[\u0000-\u001F"#$&*+,:;<=>?[\]^`{|}\u007F]/g -const DRIVE_LETTER_REGEX = /^[a-z]:/i - -export function sanitizeFileName(name: string): string { - const match = DRIVE_LETTER_REGEX.exec(name) - const driveLetter = match ? match[0] : '' - - return ( - driveLetter + - name - .slice(driveLetter.length) - .replace(INVALID_CHAR_REGEX, '_') - .replace(/(?<=^|\/)_+(?=[^/]*$)/, '') - ) -}