astro-purgecss 5.5.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var fs=require('fs'),path=require('path'),crypto=require('crypto'),purgecss=require('purgecss'),promises=require('fs/promises'),url=require('url');var
|
|
2
|
-
`+l,map:null}):null}});}},"astro:build:done":async({dir:i,pages
|
|
1
|
+
'use strict';var fs=require('fs'),path=require('path'),crypto=require('crypto'),purgecss=require('purgecss'),promises=require('fs/promises'),url=require('url');var S,P,E,A,T=true;typeof process<"u"&&({FORCE_COLOR:S,NODE_DISABLE_COLORS:P,NO_COLOR:E,TERM:A}=process.env||{},T=process.stdout&&process.stdout.isTTY);var M={enabled:!P&&E==null&&A!=="dumb"&&(S!=null&&S!=="0"||T)};function e(n,t){let a=new RegExp(`\\x1b\\[${t}m`,"g"),w=`\x1B[${n}m`,g=`\x1B[${t}m`;return function(i){return !M.enabled||i==null?i:w+(~(""+i).indexOf(g)?i.replace(a,g+w):i)+g}}var R=e(2,22),D=e(31,39),L=e(32,39);async function U(n){try{return await promises.readFile(n,"utf8")}catch(t){return k(`Error reading file ${n}: ${t}`),""}}async function O(n,t){try{await promises.writeFile(n,t,"utf8");}catch(a){k(`Error writing file ${n}: ${a}`);}}async function C(n,t,a){await O(n,t),a!==n&&fs.existsSync(a)&&await promises.unlink(a);}function _(n,t){let a=crypto.createHash("sha256").update(t).digest("hex").slice(0,8);return `${n.slice(0,-13)}.${a}.css`}function I(n){if(!(n instanceof URL))throw new TypeError("Expected a URL object");let t=url.fileURLToPath(n).replace(/(?:\/+|\\+)$/,"");return process.platform==="win32"?t.replace(/^\/+/,""):t}var N=new Intl.DateTimeFormat("en-us",{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:false});function h(n){let t=N.format(new Date);console.log(R(t),L("\u25B6"),n);}function k(n){let t=N.format(new Date);console.error(R(t),D("\u25A0"),n);}var j="astro-purgecss",Q=n=>n.match(/[\w-/:\.#\(\),';%]+(?<!:)/g)||[];function V(n={}){let t,{strategy:a="default",__unsafeContent:w,...g}=n;return {name:j,hooks:{"astro:config:done":({config:i})=>{t=i;},...a==="cache-buster"&&{"astro:build:setup":({vite:i,logger:$})=>{i.plugins||(i.plugins=[]),i.plugins.push({name:"inject-css-cache-buster",apply:"build",enforce:"pre",transform(l,f){return /\.(css|scss|sass|less|styl)(\?|$)/.test(f)?($.info(`Injecting cache-buster CSS into: ${f}`),{code:`/*! Build: ${crypto.randomUUID().slice(0,8)} */
|
|
2
|
+
`+l,map:null}):null}});}},"astro:build:done":async({dir:i,pages:$,logger:l})=>{let f=t.output;l.info(`\u{1F4E6} Running in '${f}' mode`);let s=I(i),v=f!=="static"||a==="cache-buster";if(!s||!t.build.format||!t.build.assets){l.warn(`${j} requires the following astro.config options: 'outDir', 'build.format', 'build.assets'`);return}let d=(await new purgecss.PurgeCSS().purge({css:[`${s}/**/*.css`.replace(/\\/g,"/")],defaultExtractor:Q,...g,content:w??[`${s}/**/*.html`.replace(/\\/g,"/"),`${s}/**/*.js`.replace(/\\/g,"/"),...g.content||[]]})).filter(({file:c})=>c?.endsWith(".css"));if(d.length===0){l.info("\u2139\uFE0F No CSS files found to process");return}if(l.info(`Found ${d.length} CSS ${d.length===1?"file":"files"} to process`),v){await Promise.all(d.map(async({css:c,file:r})=>{await C(r,c,r),h(path.relative(s,r));})),l.info("\u{1F389} Purging completed successfully!");return}let b=(await Promise.all(d.map(async({css:c,file:r})=>{if(!r.includes(t.build.assets)){await C(r,c,r);let m=path.relative(s,r);return h(m),{oldFilename:m,newFilename:m}}let p=_(r,c);await C(p,c,r);let F=path.relative(s,r),y=path.relative(s,p);return h(y),{oldFilename:F,newFilename:y}}))).filter(({oldFilename:c,newFilename:r})=>c!==r);if(b.length>0){l.info(`Updating ${b.length} CSS ${b.length===1?"reference":"references"} in HTML files...`);let c=$.filter(r=>typeof r.pathname=="string").map(r=>{let o=r.pathname;if(o==="")return path.join(s,"index.html");if(o==="404/"||o==="404")return path.join(s,"404.html");if(o==="500/"||o==="500")return path.join(s,"500.html");switch(t.build.format){case "file":return path.join(s,`${o}.html`);case "directory":return path.join(s,o,"index.html");case "preserve":let p=path.join(s,`${o}.html`);return fs.existsSync(p)?p:path.join(s,o,"index.html")}});await Promise.all(c.map(async r=>{let o=await U(r);for(let{oldFilename:p,newFilename:F}of b){let y=p.replace(/\\/g,"/"),m=F.replace(/\\/g,"/");o=o.replace(new RegExp(y,"g"),m);}await O(r,o),h(path.relative(s,r));}));}l.info("\u{1F389} Purging completed successfully!");}}}}var Ie=V;module.exports=Ie;//# sourceMappingURL=index.cjs.map
|
|
3
3
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/colors.mjs","../src/utils.ts","../src/index.ts"],"names":["FORCE_COLOR","NODE_DISABLE_COLORS","NO_COLOR","TERM","isTTY","$","init","x","y","rgx","open","close","txt","dim","red","green","readFileContent","filePath","readFile","err","error","writeFileContent","content","writeFile","writeCssFile","newFilePath","css","oldFilePath","existsSync","unlink","generateFileHash","hash","createHash","cleanPath","file","path","fileURLToPath","dt","success","message","date","INTEGRATION_NAME","defaultExtractor","Plugin","options","config","strategy","__unsafeContent","purgecssOptions","cfg","vite","logger","code","id","randomUUID","dir","pages","buildMode","outDir","skipRehash","purgedCssFiles","PurgeCSS","changedFiles","relativePath","hashedFilename","relativeOldPath","relativeNewPath","oldFilename","newFilename","htmlFiles","page","pathname","join","directFile","htmlFile","normalizedOldPath","normalizedNewPath","index_default"],"mappings":"gKAAA,IAAIA,CAAAA,CAAaC,CAAAA,CAAqBC,CAAAA,CAAU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,EAAoBR,CAAAA,CAAY,OAAA,CAAQ,KAAA,CAAO,GAAG,CAAA,CAExD9C,CAAAA,CAAUA,CAAAA,CAAQ,OAAA,CAChB,IAAI,MAAA,CAAOqD,CAAAA,CAAmB,GAAG,CAAA,CACjCC,CACF,EACF,CAEA,MAAMvD,CAAAA,CAAiBqD,CAAAA,CAAUpD,CAAO,CAAA,CACxCgB,EAAQoC,CAAAA,CAAS,OAAA,CAAQhB,CAAAA,CAAQ,EAAE,CAAC,EACtC,CAAC,CACH,EACF,CAEAP,CAAAA,CAAO,IAAA,CAAK,2CAAoC,EAClD,CACF,CACF,CACF,CAEA,IAAO0B,EAAAA,CAAQlC","file":"index.cjs","sourcesContent":["let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY=true;\nif (typeof process !== 'undefined') {\n\t({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});\n\tisTTY = process.stdout && process.stdout.isTTY;\n}\n\nexport const $ = {\n\tenabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && (\n\t\tFORCE_COLOR != null && FORCE_COLOR !== '0' || isTTY\n\t)\n}\n\nfunction init(x, y) {\n\tlet rgx = new RegExp(`\\\\x1b\\\\[${y}m`, 'g');\n\tlet open = `\\x1b[${x}m`, close = `\\x1b[${y}m`;\n\n\treturn function (txt) {\n\t\tif (!$.enabled || txt == null) return txt;\n\t\treturn open + (!!~(''+txt).indexOf(close) ? txt.replace(rgx, close + open) : txt) + close;\n\t};\n}\n\n// modifiers\nexport const reset = init(0, 0);\nexport const bold = init(1, 22);\nexport const dim = init(2, 22);\nexport const italic = init(3, 23);\nexport const underline = init(4, 24);\nexport const inverse = init(7, 27);\nexport const hidden = init(8, 28);\nexport const strikethrough = init(9, 29);\n\n// colors\nexport const black = init(30, 39);\nexport const red = init(31, 39);\nexport const green = init(32, 39);\nexport const yellow = init(33, 39);\nexport const blue = init(34, 39);\nexport const magenta = init(35, 39);\nexport const cyan = init(36, 39);\nexport const white = init(37, 39);\nexport const gray = init(90, 39);\nexport const grey = init(90, 39);\n\n// background colors\nexport const bgBlack = init(40, 49);\nexport const bgRed = init(41, 49);\nexport const bgGreen = init(42, 49);\nexport const bgYellow = init(43, 49);\nexport const bgBlue = init(44, 49);\nexport const bgMagenta = init(45, 49);\nexport const bgCyan = init(46, 49);\nexport const bgWhite = init(47, 49);\n","import { dim, green, red } from 'kleur/colors';\nimport { createHash } from 'node:crypto';\nimport { existsSync } from 'node:fs';\nimport { readFile, unlink, writeFile } from 'node:fs/promises';\nimport { fileURLToPath } from 'node:url';\n\nexport async function readFileContent(filePath: string): Promise<string> {\n try {\n const content = await readFile(filePath, 'utf8');\n return content;\n } catch (err) {\n error(`Error reading file ${filePath}: ${err}`);\n return '';\n }\n}\n\nexport async function writeFileContent(filePath: string, content: string) {\n try {\n await writeFile(filePath, content, 'utf8');\n } catch (err) {\n error(`Error writing file ${filePath}: ${err}`);\n }\n}\n\nexport async function writeCssFile(\n newFilePath: string,\n css: string,\n oldFilePath: string\n) {\n await writeFileContent(newFilePath, css);\n\n // Remove old file if it exists and is different from new file\n if (oldFilePath !== newFilePath && existsSync(oldFilePath)) {\n await unlink(oldFilePath);\n }\n}\n\nexport function generateFileHash(filePath: string, content: string) {\n // Get content hash before writing to file\n const hash = createHash('sha256').update(content).digest('hex').slice(0, 8);\n\n // Generate new file name with hash\n // Astro original hash is 8 characters long\n return `${filePath.slice(0, -13)}.${hash}.css`;\n}\n\n// Clean from extra slash on windows and trailing forward slash on non-windows\nexport function cleanPath(file: URL): string {\n if (!(file instanceof URL)) {\n throw new TypeError('Expected a URL object');\n }\n\n // Remove trailing forward slash if present\n let path = fileURLToPath(file).replace(/\\/+$/, '');\n\n // Remove leading forward slash on windows if present\n return process.platform === 'win32' ? path.replace(/^\\/+/, '') : path;\n}\n\nexport const dt = new Intl.DateTimeFormat('en-us', {\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hour12: false\n});\n\nexport function success(message: string) {\n const date = dt.format(new Date());\n console.log(dim(date), green('▶'), message);\n}\n\nexport function error(message: string) {\n const date = dt.format(new Date());\n console.error(dim(date), red('■'), message);\n}\n","import type { AstroConfig, AstroIntegration } from 'astro';\nimport { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { randomUUID } from 'node:crypto';\nimport { PurgeCSS, type UserDefinedOptions, type RawContent } from 'purgecss';\n\nimport {\n cleanPath,\n generateFileHash,\n readFileContent,\n success,\n writeCssFile,\n writeFileContent\n} from './utils';\n\ntype PurgeStrategy = 'default' | 'cache-buster';\n\n/**\n * Extended PurgeCSS options interface that allows partial configuration\n * of the standard PurgeCSS options\n */\nexport interface PurgeCSSOptions extends Partial<UserDefinedOptions> {\n strategy?: PurgeStrategy;\n /**\n * ⚠️ UNSAFE: Completely overrides the default content globs.\n * When provided, only these content sources will be scanned by PurgeCSS.\n * The default globs (outDir/**\\/*.html and outDir/**\\/*.js) will be ignored.\n *\n * Use this ONLY if the default globs cause performance issues on very large sites.\n * The double underscore prefix indicates this is an advanced option that should\n * be used with extreme caution.\n *\n * @example\n * ```ts\n * {\n * __unsafeContent: [\n * './dist/**\\/*.js',\n * './src/**\\/*.{astro,vue,jsx,tsx}'\n * ]\n * }\n * ```\n */\n __unsafeContent?: Array<string | RawContent>;\n}\n\nconst INTEGRATION_NAME = 'astro-purgecss' as const;\n\n/**\n * default extractor to handle various CSS selector patterns\n * @param content string\n */\nconst defaultExtractor = (content: string) =>\n content.match(/[\\w-/:\\.#\\(\\),';%]+(?<!:)/g) || [];\n\n/**\n * Astro integration for PurgeCSS that removes unused CSS from the final build\n * @param options - PurgeCSS configuration options\n * @returns AstroIntegration - The configured Astro integration\n */\nfunction Plugin(options: PurgeCSSOptions = {}): AstroIntegration {\n let config: AstroConfig;\n const { strategy = 'default', __unsafeContent, ...purgecssOptions } = options;\n\n return {\n name: INTEGRATION_NAME,\n hooks: {\n 'astro:config:done': ({ config: cfg }) => {\n config = cfg;\n },\n ...(strategy === 'cache-buster' && {\n 'astro:build:setup': ({ vite, logger }) => {\n if (!vite.plugins) vite.plugins = [];\n vite.plugins.push({\n name: 'inject-css-cache-buster',\n apply: 'build',\n enforce: 'pre',\n transform(code, id) {\n if (!/\\.(css|scss|sass|less|styl)(\\?|$)/.test(id)) {\n return null;\n }\n logger.info(`Injecting cache-buster CSS into: ${id}`);\n return {\n code: `/*! Build: ${randomUUID().slice(0, 8)} */\\n` + code,\n map: null\n };\n }\n });\n }\n }),\n 'astro:build:done': async ({ dir, pages, logger }) => {\n const buildMode = config.output;\n logger.info(`📦 Running in '${buildMode}' mode`);\n\n // Convert the URL to a filesystem path\n const outDir = cleanPath(dir);\n\n // skip file rehashing for SSR/Server mode or cache-buster strategy\n const skipRehash =\n buildMode !== 'static' || strategy === 'cache-buster';\n\n // Validate required Astro configuration\n if (!outDir || !config.build.format || !config.build.assets) {\n logger.warn(\n `${INTEGRATION_NAME} requires the following astro.config options: 'outDir', 'build.format', 'build.assets'`\n );\n return;\n }\n\n // Run PurgeCSS on all CSS files\n const purgeResults = await new PurgeCSS().purge({\n css: [`${outDir}/**/*.css`.replace(/\\\\/g, '/')],\n defaultExtractor,\n ...purgecssOptions,\n content: __unsafeContent ?? [\n `${outDir}/**/*.html`.replace(/\\\\/g, '/'),\n `${outDir}/**/*.js`.replace(/\\\\/g, '/'),\n ...(purgecssOptions.content || [])\n ]\n });\n\n // Filter out non-CSS files from purge results\n const purgedCssFiles = purgeResults.filter(({ file }) =>\n file?.endsWith('.css')\n ) as Array<{\n css: string;\n file: string;\n }>;\n\n if (purgedCssFiles.length === 0) {\n logger.info('ℹ️ No CSS files found to process');\n return;\n }\n\n logger.info(\n `Found ${purgedCssFiles.length} CSS ${purgedCssFiles.length === 1 ? 'file' : 'files'} to process`\n );\n\n // If SSR/Server mode or cache-buster strategy skip file rehash\n if (skipRehash) {\n await Promise.all(\n purgedCssFiles.map(async ({ css, file }) => {\n await writeCssFile(file, css, file);\n success(file.replace(outDir, ''));\n })\n );\n logger.info('🎉 Purging completed successfully!');\n return;\n }\n\n // Process files for static mode with content hashing\n let processedFiles = await Promise.all(\n purgedCssFiles.map(async ({ css, file }) => {\n const isAssetFile = file.includes(config.build.assets);\n\n // Skip rehashing for non-asset files (not generated by astro)\n // ex: assets/styles/light.css\n if (!isAssetFile) {\n await writeCssFile(file, css, file);\n const relativePath = file.replace(outDir, '');\n success(relativePath);\n return {\n oldFilename: relativePath,\n newFilename: relativePath\n };\n }\n\n // Generate new filename with content hash\n const hashedFilename = generateFileHash(file, css);\n await writeCssFile(hashedFilename, css, file);\n\n const relativeOldPath = file.replace(outDir, '');\n const relativeNewPath = hashedFilename.replace(outDir, '');\n success(relativeNewPath);\n\n return {\n oldFilename: relativeOldPath,\n newFilename: relativeNewPath\n };\n })\n );\n\n // Filter to only get files that actually changed\n const changedFiles = processedFiles.filter(\n ({ oldFilename, newFilename }) => oldFilename !== newFilename\n );\n\n if (changedFiles.length > 0) {\n logger.info(\n `Updating ${changedFiles.length} CSS ${changedFiles.length === 1 ? 'reference' : 'references'} in HTML files...`\n );\n // Get all HTML pages based on build format\n const htmlFiles = pages\n .filter((page) => typeof page.pathname === 'string')\n .map((page) => {\n const pathname = page.pathname as string;\n\n // Handle root/index page\n if (pathname === '') {\n return join(outDir, 'index.html');\n }\n\n /**\n * Custom 404 Error Page\n *\n * @see https://docs.astro.build/en/basics/astro-pages/#custom-404-error-page\n */\n if (pathname === '404/' || pathname === '404') {\n return join(outDir, '404.html');\n }\n\n /**\n * Custom 500 Error Page\n *\n * @see https://docs.astro.build/en/basics/astro-pages/#custom-500-error-page\n */\n if (pathname === '500/' || pathname === '500') {\n return join(outDir, '500.html');\n }\n\n switch (config.build.format) {\n case 'file':\n // Format: /blog -> /blog.html\n return join(outDir, `${pathname}.html`);\n\n case 'directory':\n // Format: /blog -> /blog/index.html\n return join(outDir, pathname, 'index.html');\n\n case 'preserve':\n // Check if direct HTML file exists, otherwise use directory format\n const directFile = join(outDir, `${pathname}.html`);\n return existsSync(directFile)\n ? directFile\n : join(outDir, pathname, 'index.html');\n }\n });\n\n // Update CSS references in HTML files\n await Promise.all(\n htmlFiles.map(async (htmlFile) => {\n let content = await readFileContent(htmlFile);\n\n for (const { oldFilename, newFilename } of changedFiles) {\n const normalizedOldPath = oldFilename.replace(/\\\\/g, '/');\n const normalizedNewPath = newFilename.replace(/\\\\/g, '/');\n\n content = content.replace(\n new RegExp(normalizedOldPath, 'g'),\n normalizedNewPath\n );\n }\n\n await writeFileContent(htmlFile, content);\n success(htmlFile.replace(outDir, ''));\n })\n );\n }\n\n logger.info('🎉 Purging completed successfully!');\n }\n }\n };\n}\n\nexport default Plugin;\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/colors.mjs","../src/utils.ts","../src/index.ts"],"names":["FORCE_COLOR","NODE_DISABLE_COLORS","NO_COLOR","TERM","isTTY","$","init","x","y","rgx","open","close","txt","dim","red","green","readFileContent","filePath","readFile","err","error","writeFileContent","content","writeFile","writeCssFile","newFilePath","css","oldFilePath","existsSync","unlink","generateFileHash","hash","createHash","cleanPath","file","path","fileURLToPath","dt","success","message","date","INTEGRATION_NAME","defaultExtractor","Plugin","options","config","strategy","__unsafeContent","purgecssOptions","cfg","vite","logger","code","id","randomUUID","dir","pages","buildMode","outDir","skipRehash","purgedCssFiles","PurgeCSS","relative","changedFiles","relativePath","hashedFilename","relativeOldPath","relativeNewPath","oldFilename","newFilename","htmlFiles","page","pathname","join","directFile","htmlFile","normalizedOldPath","normalizedNewPath","index_default"],"mappings":"gKAAA,IAAIA,CAAAA,CAAaC,CAAAA,CAAqBC,CAAAA,CAAUC,EAAMC,CAAAA,CAAM,IAAA,CACxD,OAAO,OAAA,CAAY,GAAA,GACrB,CAAE,WAAA,CAAAJ,CAAAA,CAAa,oBAAAC,CAAAA,CAAqB,QAAA,CAAAC,CAAAA,CAAU,IAAA,CAAAC,CAAK,CAAA,CAAI,OAAA,CAAQ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AAAA,CAASJ,CAAAA,CAAQiB,CAAQ,CAAC,EACpC,CAAC,CACH,EACF,CAEAxB,CAAAA,CAAO,IAAA,CAAK,2CAAoC,EAClD,CACF,CACF,CACF,CAEA,IAAO2B,EAAAA,CAAQnC","file":"index.cjs","sourcesContent":["let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY=true;\nif (typeof process !== 'undefined') {\n\t({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});\n\tisTTY = process.stdout && process.stdout.isTTY;\n}\n\nexport const $ = {\n\tenabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && (\n\t\tFORCE_COLOR != null && FORCE_COLOR !== '0' || isTTY\n\t)\n}\n\nfunction init(x, y) {\n\tlet rgx = new RegExp(`\\\\x1b\\\\[${y}m`, 'g');\n\tlet open = `\\x1b[${x}m`, close = `\\x1b[${y}m`;\n\n\treturn function (txt) {\n\t\tif (!$.enabled || txt == null) return txt;\n\t\treturn open + (!!~(''+txt).indexOf(close) ? txt.replace(rgx, close + open) : txt) + close;\n\t};\n}\n\n// modifiers\nexport const reset = init(0, 0);\nexport const bold = init(1, 22);\nexport const dim = init(2, 22);\nexport const italic = init(3, 23);\nexport const underline = init(4, 24);\nexport const inverse = init(7, 27);\nexport const hidden = init(8, 28);\nexport const strikethrough = init(9, 29);\n\n// colors\nexport const black = init(30, 39);\nexport const red = init(31, 39);\nexport const green = init(32, 39);\nexport const yellow = init(33, 39);\nexport const blue = init(34, 39);\nexport const magenta = init(35, 39);\nexport const cyan = init(36, 39);\nexport const white = init(37, 39);\nexport const gray = init(90, 39);\nexport const grey = init(90, 39);\n\n// background colors\nexport const bgBlack = init(40, 49);\nexport const bgRed = init(41, 49);\nexport const bgGreen = init(42, 49);\nexport const bgYellow = init(43, 49);\nexport const bgBlue = init(44, 49);\nexport const bgMagenta = init(45, 49);\nexport const bgCyan = init(46, 49);\nexport const bgWhite = init(47, 49);\n","import { dim, green, red } from 'kleur/colors';\nimport { createHash } from 'node:crypto';\nimport { existsSync } from 'node:fs';\nimport { readFile, unlink, writeFile } from 'node:fs/promises';\nimport { fileURLToPath } from 'node:url';\n\nexport async function readFileContent(filePath: string): Promise<string> {\n try {\n const content = await readFile(filePath, 'utf8');\n return content;\n } catch (err) {\n error(`Error reading file ${filePath}: ${err}`);\n return '';\n }\n}\n\nexport async function writeFileContent(filePath: string, content: string) {\n try {\n await writeFile(filePath, content, 'utf8');\n } catch (err) {\n error(`Error writing file ${filePath}: ${err}`);\n }\n}\n\nexport async function writeCssFile(\n newFilePath: string,\n css: string,\n oldFilePath: string\n) {\n await writeFileContent(newFilePath, css);\n\n // Remove old file if it exists and is different from new file\n if (oldFilePath !== newFilePath && existsSync(oldFilePath)) {\n await unlink(oldFilePath);\n }\n}\n\nexport function generateFileHash(filePath: string, content: string) {\n // Get content hash before writing to file\n const hash = createHash('sha256').update(content).digest('hex').slice(0, 8);\n\n // Generate new file name with hash\n // Astro original hash is 8 characters long\n return `${filePath.slice(0, -13)}.${hash}.css`;\n}\n\n// Clean from trailing slash and extra leading slash on windows\nexport function cleanPath(file: URL): string {\n if (!(file instanceof URL)) {\n throw new TypeError('Expected a URL object');\n }\n\n // Remove trailing slash if present\n let path = fileURLToPath(file).replace(/(?:\\/+|\\\\+)$/, '');\n\n // Remove leading forward slash on windows if present\n return process.platform === 'win32' ? path.replace(/^\\/+/, '') : path;\n}\n\nexport const dt = new Intl.DateTimeFormat('en-us', {\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hour12: false\n});\n\nexport function success(message: string) {\n const date = dt.format(new Date());\n console.log(dim(date), green('▶'), message);\n}\n\nexport function error(message: string) {\n const date = dt.format(new Date());\n console.error(dim(date), red('■'), message);\n}\n","import type { AstroConfig, AstroIntegration } from 'astro';\nimport { existsSync } from 'node:fs';\nimport { join, relative } from 'node:path';\nimport { randomUUID } from 'node:crypto';\nimport { PurgeCSS, type UserDefinedOptions, type RawContent } from 'purgecss';\n\nimport {\n cleanPath,\n generateFileHash,\n readFileContent,\n success,\n writeCssFile,\n writeFileContent\n} from './utils';\n\ntype PurgeStrategy = 'default' | 'cache-buster';\n\n/**\n * Extended PurgeCSS options interface that allows partial configuration\n * of the standard PurgeCSS options\n */\nexport interface PurgeCSSOptions extends Partial<UserDefinedOptions> {\n strategy?: PurgeStrategy;\n /**\n * ⚠️ UNSAFE: Completely overrides the default content globs.\n * When provided, only these content sources will be scanned by PurgeCSS.\n * The default globs (outDir/**\\/*.html and outDir/**\\/*.js) will be ignored.\n *\n * Use this ONLY if the default globs cause performance issues on very large sites.\n * The double underscore prefix indicates this is an advanced option that should\n * be used with extreme caution.\n *\n * @example\n * ```ts\n * {\n * __unsafeContent: [\n * './dist/**\\/*.js',\n * './src/**\\/*.{astro,vue,jsx,tsx}'\n * ]\n * }\n * ```\n */\n __unsafeContent?: Array<string | RawContent>;\n}\n\nconst INTEGRATION_NAME = 'astro-purgecss' as const;\n\n/**\n * default extractor to handle various CSS selector patterns\n * @param content string\n */\nconst defaultExtractor = (content: string) =>\n content.match(/[\\w-/:\\.#\\(\\),';%]+(?<!:)/g) || [];\n\n/**\n * Astro integration for PurgeCSS that removes unused CSS from the final build\n * @param options - PurgeCSS configuration options\n * @returns AstroIntegration - The configured Astro integration\n */\nfunction Plugin(options: PurgeCSSOptions = {}): AstroIntegration {\n let config: AstroConfig;\n const { strategy = 'default', __unsafeContent, ...purgecssOptions } = options;\n\n return {\n name: INTEGRATION_NAME,\n hooks: {\n 'astro:config:done': ({ config: cfg }) => {\n config = cfg;\n },\n ...(strategy === 'cache-buster' && {\n 'astro:build:setup': ({ vite, logger }) => {\n if (!vite.plugins) vite.plugins = [];\n vite.plugins.push({\n name: 'inject-css-cache-buster',\n apply: 'build',\n enforce: 'pre',\n transform(code, id) {\n if (!/\\.(css|scss|sass|less|styl)(\\?|$)/.test(id)) {\n return null;\n }\n logger.info(`Injecting cache-buster CSS into: ${id}`);\n return {\n code: `/*! Build: ${randomUUID().slice(0, 8)} */\\n` + code,\n map: null\n };\n }\n });\n }\n }),\n 'astro:build:done': async ({ dir, pages, logger }) => {\n const buildMode = config.output;\n logger.info(`📦 Running in '${buildMode}' mode`);\n\n // Convert the URL to a filesystem path\n const outDir = cleanPath(dir);\n\n // skip file rehashing for SSR/Server mode or cache-buster strategy\n const skipRehash =\n buildMode !== 'static' || strategy === 'cache-buster';\n\n // Validate required Astro configuration\n if (!outDir || !config.build.format || !config.build.assets) {\n logger.warn(\n `${INTEGRATION_NAME} requires the following astro.config options: 'outDir', 'build.format', 'build.assets'`\n );\n return;\n }\n\n // Run PurgeCSS on all CSS files\n const purgeResults = await new PurgeCSS().purge({\n css: [`${outDir}/**/*.css`.replace(/\\\\/g, '/')],\n defaultExtractor,\n ...purgecssOptions,\n content: __unsafeContent ?? [\n `${outDir}/**/*.html`.replace(/\\\\/g, '/'),\n `${outDir}/**/*.js`.replace(/\\\\/g, '/'),\n ...(purgecssOptions.content || [])\n ]\n });\n\n // Filter out non-CSS files from purge results\n const purgedCssFiles = purgeResults.filter(({ file }) =>\n file?.endsWith('.css')\n ) as Array<{\n css: string;\n file: string;\n }>;\n\n if (purgedCssFiles.length === 0) {\n logger.info('ℹ️ No CSS files found to process');\n return;\n }\n\n logger.info(\n `Found ${purgedCssFiles.length} CSS ${purgedCssFiles.length === 1 ? 'file' : 'files'} to process`\n );\n\n // If SSR/Server mode or cache-buster strategy skip file rehash\n if (skipRehash) {\n await Promise.all(\n purgedCssFiles.map(async ({ css, file }) => {\n await writeCssFile(file, css, file);\n success(relative(outDir, file));\n })\n );\n logger.info('🎉 Purging completed successfully!');\n return;\n }\n\n // Process files for static mode with content hashing\n let processedFiles = await Promise.all(\n purgedCssFiles.map(async ({ css, file }) => {\n const isAssetFile = file.includes(config.build.assets);\n\n // Skip rehashing for non-asset files (not generated by astro)\n // ex: assets/styles/light.css\n if (!isAssetFile) {\n await writeCssFile(file, css, file);\n const relativePath = relative(outDir, file);\n success(relativePath);\n return {\n oldFilename: relativePath,\n newFilename: relativePath\n };\n }\n\n // Generate new filename with content hash\n const hashedFilename = generateFileHash(file, css);\n await writeCssFile(hashedFilename, css, file);\n\n const relativeOldPath = relative(outDir, file);\n const relativeNewPath = relative(outDir, hashedFilename);\n success(relativeNewPath);\n\n return {\n oldFilename: relativeOldPath,\n newFilename: relativeNewPath\n };\n })\n );\n\n // Filter to only get files that actually changed\n const changedFiles = processedFiles.filter(\n ({ oldFilename, newFilename }) => oldFilename !== newFilename\n );\n\n if (changedFiles.length > 0) {\n logger.info(\n `Updating ${changedFiles.length} CSS ${changedFiles.length === 1 ? 'reference' : 'references'} in HTML files...`\n );\n // Get all HTML pages based on build format\n const htmlFiles = pages\n .filter((page) => typeof page.pathname === 'string')\n .map((page) => {\n const pathname = page.pathname as string;\n\n // Handle root/index page\n if (pathname === '') {\n return join(outDir, 'index.html');\n }\n\n /**\n * Custom 404 Error Page\n *\n * @see https://docs.astro.build/en/basics/astro-pages/#custom-404-error-page\n */\n if (pathname === '404/' || pathname === '404') {\n return join(outDir, '404.html');\n }\n\n /**\n * Custom 500 Error Page\n *\n * @see https://docs.astro.build/en/basics/astro-pages/#custom-500-error-page\n */\n if (pathname === '500/' || pathname === '500') {\n return join(outDir, '500.html');\n }\n\n switch (config.build.format) {\n case 'file':\n // Format: /blog -> /blog.html\n return join(outDir, `${pathname}.html`);\n\n case 'directory':\n // Format: /blog -> /blog/index.html\n return join(outDir, pathname, 'index.html');\n\n case 'preserve':\n // Check if direct HTML file exists, otherwise use directory format\n const directFile = join(outDir, `${pathname}.html`);\n return existsSync(directFile)\n ? directFile\n : join(outDir, pathname, 'index.html');\n }\n });\n\n // Update CSS references in HTML files\n await Promise.all(\n htmlFiles.map(async (htmlFile) => {\n let content = await readFileContent(htmlFile);\n\n for (const { oldFilename, newFilename } of changedFiles) {\n const normalizedOldPath = oldFilename.replace(/\\\\/g, '/');\n const normalizedNewPath = newFilename.replace(/\\\\/g, '/');\n\n content = content.replace(\n new RegExp(normalizedOldPath, 'g'),\n normalizedNewPath\n );\n }\n\n await writeFileContent(htmlFile, content);\n success(relative(outDir, htmlFile));\n })\n );\n }\n\n logger.info('🎉 Purging completed successfully!');\n }\n }\n };\n}\n\nexport default Plugin;\n"]}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {existsSync}from'fs';import {join}from'path';import {randomUUID,createHash}from'crypto';import {PurgeCSS}from'purgecss';import {unlink,readFile,writeFile}from'fs/promises';import {fileURLToPath}from'url';var
|
|
2
|
-
`+l,map:null}):null}});}},"astro:build:done":async({dir:i,pages
|
|
1
|
+
import {existsSync}from'fs';import {relative,join}from'path';import {randomUUID,createHash}from'crypto';import {PurgeCSS}from'purgecss';import {unlink,readFile,writeFile}from'fs/promises';import {fileURLToPath}from'url';var S,P,E,A,T=true;typeof process<"u"&&({FORCE_COLOR:S,NODE_DISABLE_COLORS:P,NO_COLOR:E,TERM:A}=process.env||{},T=process.stdout&&process.stdout.isTTY);var M={enabled:!P&&E==null&&A!=="dumb"&&(S!=null&&S!=="0"||T)};function e(n,t){let a=new RegExp(`\\x1b\\[${t}m`,"g"),w=`\x1B[${n}m`,g=`\x1B[${t}m`;return function(i){return !M.enabled||i==null?i:w+(~(""+i).indexOf(g)?i.replace(a,g+w):i)+g}}var R=e(2,22),D=e(31,39),L=e(32,39);async function U(n){try{return await readFile(n,"utf8")}catch(t){return k(`Error reading file ${n}: ${t}`),""}}async function O(n,t){try{await writeFile(n,t,"utf8");}catch(a){k(`Error writing file ${n}: ${a}`);}}async function C(n,t,a){await O(n,t),a!==n&&existsSync(a)&&await unlink(a);}function _(n,t){let a=createHash("sha256").update(t).digest("hex").slice(0,8);return `${n.slice(0,-13)}.${a}.css`}function I(n){if(!(n instanceof URL))throw new TypeError("Expected a URL object");let t=fileURLToPath(n).replace(/(?:\/+|\\+)$/,"");return process.platform==="win32"?t.replace(/^\/+/,""):t}var N=new Intl.DateTimeFormat("en-us",{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:false});function h(n){let t=N.format(new Date);console.log(R(t),L("\u25B6"),n);}function k(n){let t=N.format(new Date);console.error(R(t),D("\u25A0"),n);}var j="astro-purgecss",Q=n=>n.match(/[\w-/:\.#\(\),';%]+(?<!:)/g)||[];function V(n={}){let t,{strategy:a="default",__unsafeContent:w,...g}=n;return {name:j,hooks:{"astro:config:done":({config:i})=>{t=i;},...a==="cache-buster"&&{"astro:build:setup":({vite:i,logger:$})=>{i.plugins||(i.plugins=[]),i.plugins.push({name:"inject-css-cache-buster",apply:"build",enforce:"pre",transform(l,f){return /\.(css|scss|sass|less|styl)(\?|$)/.test(f)?($.info(`Injecting cache-buster CSS into: ${f}`),{code:`/*! Build: ${randomUUID().slice(0,8)} */
|
|
2
|
+
`+l,map:null}):null}});}},"astro:build:done":async({dir:i,pages:$,logger:l})=>{let f=t.output;l.info(`\u{1F4E6} Running in '${f}' mode`);let s=I(i),v=f!=="static"||a==="cache-buster";if(!s||!t.build.format||!t.build.assets){l.warn(`${j} requires the following astro.config options: 'outDir', 'build.format', 'build.assets'`);return}let d=(await new PurgeCSS().purge({css:[`${s}/**/*.css`.replace(/\\/g,"/")],defaultExtractor:Q,...g,content:w??[`${s}/**/*.html`.replace(/\\/g,"/"),`${s}/**/*.js`.replace(/\\/g,"/"),...g.content||[]]})).filter(({file:c})=>c?.endsWith(".css"));if(d.length===0){l.info("\u2139\uFE0F No CSS files found to process");return}if(l.info(`Found ${d.length} CSS ${d.length===1?"file":"files"} to process`),v){await Promise.all(d.map(async({css:c,file:r})=>{await C(r,c,r),h(relative(s,r));})),l.info("\u{1F389} Purging completed successfully!");return}let b=(await Promise.all(d.map(async({css:c,file:r})=>{if(!r.includes(t.build.assets)){await C(r,c,r);let m=relative(s,r);return h(m),{oldFilename:m,newFilename:m}}let p=_(r,c);await C(p,c,r);let F=relative(s,r),y=relative(s,p);return h(y),{oldFilename:F,newFilename:y}}))).filter(({oldFilename:c,newFilename:r})=>c!==r);if(b.length>0){l.info(`Updating ${b.length} CSS ${b.length===1?"reference":"references"} in HTML files...`);let c=$.filter(r=>typeof r.pathname=="string").map(r=>{let o=r.pathname;if(o==="")return join(s,"index.html");if(o==="404/"||o==="404")return join(s,"404.html");if(o==="500/"||o==="500")return join(s,"500.html");switch(t.build.format){case "file":return join(s,`${o}.html`);case "directory":return join(s,o,"index.html");case "preserve":let p=join(s,`${o}.html`);return existsSync(p)?p:join(s,o,"index.html")}});await Promise.all(c.map(async r=>{let o=await U(r);for(let{oldFilename:p,newFilename:F}of b){let y=p.replace(/\\/g,"/"),m=F.replace(/\\/g,"/");o=o.replace(new RegExp(y,"g"),m);}await O(r,o),h(relative(s,r));}));}l.info("\u{1F389} Purging completed successfully!");}}}}var Ie=V;export{Ie as default};//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/colors.mjs","../src/utils.ts","../src/index.ts"],"names":["FORCE_COLOR","NODE_DISABLE_COLORS","NO_COLOR","TERM","isTTY","$","init","x","y","rgx","open","close","txt","dim","red","green","readFileContent","filePath","readFile","err","error","writeFileContent","content","writeFile","writeCssFile","newFilePath","css","oldFilePath","existsSync","unlink","generateFileHash","hash","createHash","cleanPath","file","path","fileURLToPath","dt","success","message","date","INTEGRATION_NAME","defaultExtractor","Plugin","options","config","strategy","__unsafeContent","purgecssOptions","cfg","vite","logger","code","id","randomUUID","dir","pages","buildMode","outDir","skipRehash","purgedCssFiles","PurgeCSS","changedFiles","relativePath","hashedFilename","relativeOldPath","relativeNewPath","oldFilename","newFilename","htmlFiles","page","pathname","join","directFile","htmlFile","normalizedOldPath","normalizedNewPath","index_default"],"mappings":"mNAAA,IAAIA,CAAAA,CAAaC,CAAAA,CAAqBC,CAAAA,CAAUC,CAAAA,CAAMC,CAAAA,CAAM,KACxD,OAAO,OAAA,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AAA,CAExD9C,CAAAA,CAAUA,CAAAA,CAAQ,OAAA,CAChB,IAAI,MAAA,CAAOqD,CAAAA,CAAmB,GAAG,CAAA,CACjCC,CACF,EACF,CAEA,MAAMvD,CAAAA,CAAiBqD,CAAAA,CAAUpD,CAAO,CAAA,CACxCgB,EAAQoC,CAAAA,CAAS,OAAA,CAAQhB,CAAAA,CAAQ,EAAE,CAAC,EACtC,CAAC,CACH,EACF,CAEAP,CAAAA,CAAO,IAAA,CAAK,2CAAoC,EAClD,CACF,CACF,CACF,CAEA,IAAO0B,EAAAA,CAAQlC","file":"index.js","sourcesContent":["let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY=true;\nif (typeof process !== 'undefined') {\n\t({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});\n\tisTTY = process.stdout && process.stdout.isTTY;\n}\n\nexport const $ = {\n\tenabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && (\n\t\tFORCE_COLOR != null && FORCE_COLOR !== '0' || isTTY\n\t)\n}\n\nfunction init(x, y) {\n\tlet rgx = new RegExp(`\\\\x1b\\\\[${y}m`, 'g');\n\tlet open = `\\x1b[${x}m`, close = `\\x1b[${y}m`;\n\n\treturn function (txt) {\n\t\tif (!$.enabled || txt == null) return txt;\n\t\treturn open + (!!~(''+txt).indexOf(close) ? txt.replace(rgx, close + open) : txt) + close;\n\t};\n}\n\n// modifiers\nexport const reset = init(0, 0);\nexport const bold = init(1, 22);\nexport const dim = init(2, 22);\nexport const italic = init(3, 23);\nexport const underline = init(4, 24);\nexport const inverse = init(7, 27);\nexport const hidden = init(8, 28);\nexport const strikethrough = init(9, 29);\n\n// colors\nexport const black = init(30, 39);\nexport const red = init(31, 39);\nexport const green = init(32, 39);\nexport const yellow = init(33, 39);\nexport const blue = init(34, 39);\nexport const magenta = init(35, 39);\nexport const cyan = init(36, 39);\nexport const white = init(37, 39);\nexport const gray = init(90, 39);\nexport const grey = init(90, 39);\n\n// background colors\nexport const bgBlack = init(40, 49);\nexport const bgRed = init(41, 49);\nexport const bgGreen = init(42, 49);\nexport const bgYellow = init(43, 49);\nexport const bgBlue = init(44, 49);\nexport const bgMagenta = init(45, 49);\nexport const bgCyan = init(46, 49);\nexport const bgWhite = init(47, 49);\n","import { dim, green, red } from 'kleur/colors';\nimport { createHash } from 'node:crypto';\nimport { existsSync } from 'node:fs';\nimport { readFile, unlink, writeFile } from 'node:fs/promises';\nimport { fileURLToPath } from 'node:url';\n\nexport async function readFileContent(filePath: string): Promise<string> {\n try {\n const content = await readFile(filePath, 'utf8');\n return content;\n } catch (err) {\n error(`Error reading file ${filePath}: ${err}`);\n return '';\n }\n}\n\nexport async function writeFileContent(filePath: string, content: string) {\n try {\n await writeFile(filePath, content, 'utf8');\n } catch (err) {\n error(`Error writing file ${filePath}: ${err}`);\n }\n}\n\nexport async function writeCssFile(\n newFilePath: string,\n css: string,\n oldFilePath: string\n) {\n await writeFileContent(newFilePath, css);\n\n // Remove old file if it exists and is different from new file\n if (oldFilePath !== newFilePath && existsSync(oldFilePath)) {\n await unlink(oldFilePath);\n }\n}\n\nexport function generateFileHash(filePath: string, content: string) {\n // Get content hash before writing to file\n const hash = createHash('sha256').update(content).digest('hex').slice(0, 8);\n\n // Generate new file name with hash\n // Astro original hash is 8 characters long\n return `${filePath.slice(0, -13)}.${hash}.css`;\n}\n\n// Clean from extra slash on windows and trailing forward slash on non-windows\nexport function cleanPath(file: URL): string {\n if (!(file instanceof URL)) {\n throw new TypeError('Expected a URL object');\n }\n\n // Remove trailing forward slash if present\n let path = fileURLToPath(file).replace(/\\/+$/, '');\n\n // Remove leading forward slash on windows if present\n return process.platform === 'win32' ? path.replace(/^\\/+/, '') : path;\n}\n\nexport const dt = new Intl.DateTimeFormat('en-us', {\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hour12: false\n});\n\nexport function success(message: string) {\n const date = dt.format(new Date());\n console.log(dim(date), green('▶'), message);\n}\n\nexport function error(message: string) {\n const date = dt.format(new Date());\n console.error(dim(date), red('■'), message);\n}\n","import type { AstroConfig, AstroIntegration } from 'astro';\nimport { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { randomUUID } from 'node:crypto';\nimport { PurgeCSS, type UserDefinedOptions, type RawContent } from 'purgecss';\n\nimport {\n cleanPath,\n generateFileHash,\n readFileContent,\n success,\n writeCssFile,\n writeFileContent\n} from './utils';\n\ntype PurgeStrategy = 'default' | 'cache-buster';\n\n/**\n * Extended PurgeCSS options interface that allows partial configuration\n * of the standard PurgeCSS options\n */\nexport interface PurgeCSSOptions extends Partial<UserDefinedOptions> {\n strategy?: PurgeStrategy;\n /**\n * ⚠️ UNSAFE: Completely overrides the default content globs.\n * When provided, only these content sources will be scanned by PurgeCSS.\n * The default globs (outDir/**\\/*.html and outDir/**\\/*.js) will be ignored.\n *\n * Use this ONLY if the default globs cause performance issues on very large sites.\n * The double underscore prefix indicates this is an advanced option that should\n * be used with extreme caution.\n *\n * @example\n * ```ts\n * {\n * __unsafeContent: [\n * './dist/**\\/*.js',\n * './src/**\\/*.{astro,vue,jsx,tsx}'\n * ]\n * }\n * ```\n */\n __unsafeContent?: Array<string | RawContent>;\n}\n\nconst INTEGRATION_NAME = 'astro-purgecss' as const;\n\n/**\n * default extractor to handle various CSS selector patterns\n * @param content string\n */\nconst defaultExtractor = (content: string) =>\n content.match(/[\\w-/:\\.#\\(\\),';%]+(?<!:)/g) || [];\n\n/**\n * Astro integration for PurgeCSS that removes unused CSS from the final build\n * @param options - PurgeCSS configuration options\n * @returns AstroIntegration - The configured Astro integration\n */\nfunction Plugin(options: PurgeCSSOptions = {}): AstroIntegration {\n let config: AstroConfig;\n const { strategy = 'default', __unsafeContent, ...purgecssOptions } = options;\n\n return {\n name: INTEGRATION_NAME,\n hooks: {\n 'astro:config:done': ({ config: cfg }) => {\n config = cfg;\n },\n ...(strategy === 'cache-buster' && {\n 'astro:build:setup': ({ vite, logger }) => {\n if (!vite.plugins) vite.plugins = [];\n vite.plugins.push({\n name: 'inject-css-cache-buster',\n apply: 'build',\n enforce: 'pre',\n transform(code, id) {\n if (!/\\.(css|scss|sass|less|styl)(\\?|$)/.test(id)) {\n return null;\n }\n logger.info(`Injecting cache-buster CSS into: ${id}`);\n return {\n code: `/*! Build: ${randomUUID().slice(0, 8)} */\\n` + code,\n map: null\n };\n }\n });\n }\n }),\n 'astro:build:done': async ({ dir, pages, logger }) => {\n const buildMode = config.output;\n logger.info(`📦 Running in '${buildMode}' mode`);\n\n // Convert the URL to a filesystem path\n const outDir = cleanPath(dir);\n\n // skip file rehashing for SSR/Server mode or cache-buster strategy\n const skipRehash =\n buildMode !== 'static' || strategy === 'cache-buster';\n\n // Validate required Astro configuration\n if (!outDir || !config.build.format || !config.build.assets) {\n logger.warn(\n `${INTEGRATION_NAME} requires the following astro.config options: 'outDir', 'build.format', 'build.assets'`\n );\n return;\n }\n\n // Run PurgeCSS on all CSS files\n const purgeResults = await new PurgeCSS().purge({\n css: [`${outDir}/**/*.css`.replace(/\\\\/g, '/')],\n defaultExtractor,\n ...purgecssOptions,\n content: __unsafeContent ?? [\n `${outDir}/**/*.html`.replace(/\\\\/g, '/'),\n `${outDir}/**/*.js`.replace(/\\\\/g, '/'),\n ...(purgecssOptions.content || [])\n ]\n });\n\n // Filter out non-CSS files from purge results\n const purgedCssFiles = purgeResults.filter(({ file }) =>\n file?.endsWith('.css')\n ) as Array<{\n css: string;\n file: string;\n }>;\n\n if (purgedCssFiles.length === 0) {\n logger.info('ℹ️ No CSS files found to process');\n return;\n }\n\n logger.info(\n `Found ${purgedCssFiles.length} CSS ${purgedCssFiles.length === 1 ? 'file' : 'files'} to process`\n );\n\n // If SSR/Server mode or cache-buster strategy skip file rehash\n if (skipRehash) {\n await Promise.all(\n purgedCssFiles.map(async ({ css, file }) => {\n await writeCssFile(file, css, file);\n success(file.replace(outDir, ''));\n })\n );\n logger.info('🎉 Purging completed successfully!');\n return;\n }\n\n // Process files for static mode with content hashing\n let processedFiles = await Promise.all(\n purgedCssFiles.map(async ({ css, file }) => {\n const isAssetFile = file.includes(config.build.assets);\n\n // Skip rehashing for non-asset files (not generated by astro)\n // ex: assets/styles/light.css\n if (!isAssetFile) {\n await writeCssFile(file, css, file);\n const relativePath = file.replace(outDir, '');\n success(relativePath);\n return {\n oldFilename: relativePath,\n newFilename: relativePath\n };\n }\n\n // Generate new filename with content hash\n const hashedFilename = generateFileHash(file, css);\n await writeCssFile(hashedFilename, css, file);\n\n const relativeOldPath = file.replace(outDir, '');\n const relativeNewPath = hashedFilename.replace(outDir, '');\n success(relativeNewPath);\n\n return {\n oldFilename: relativeOldPath,\n newFilename: relativeNewPath\n };\n })\n );\n\n // Filter to only get files that actually changed\n const changedFiles = processedFiles.filter(\n ({ oldFilename, newFilename }) => oldFilename !== newFilename\n );\n\n if (changedFiles.length > 0) {\n logger.info(\n `Updating ${changedFiles.length} CSS ${changedFiles.length === 1 ? 'reference' : 'references'} in HTML files...`\n );\n // Get all HTML pages based on build format\n const htmlFiles = pages\n .filter((page) => typeof page.pathname === 'string')\n .map((page) => {\n const pathname = page.pathname as string;\n\n // Handle root/index page\n if (pathname === '') {\n return join(outDir, 'index.html');\n }\n\n /**\n * Custom 404 Error Page\n *\n * @see https://docs.astro.build/en/basics/astro-pages/#custom-404-error-page\n */\n if (pathname === '404/' || pathname === '404') {\n return join(outDir, '404.html');\n }\n\n /**\n * Custom 500 Error Page\n *\n * @see https://docs.astro.build/en/basics/astro-pages/#custom-500-error-page\n */\n if (pathname === '500/' || pathname === '500') {\n return join(outDir, '500.html');\n }\n\n switch (config.build.format) {\n case 'file':\n // Format: /blog -> /blog.html\n return join(outDir, `${pathname}.html`);\n\n case 'directory':\n // Format: /blog -> /blog/index.html\n return join(outDir, pathname, 'index.html');\n\n case 'preserve':\n // Check if direct HTML file exists, otherwise use directory format\n const directFile = join(outDir, `${pathname}.html`);\n return existsSync(directFile)\n ? directFile\n : join(outDir, pathname, 'index.html');\n }\n });\n\n // Update CSS references in HTML files\n await Promise.all(\n htmlFiles.map(async (htmlFile) => {\n let content = await readFileContent(htmlFile);\n\n for (const { oldFilename, newFilename } of changedFiles) {\n const normalizedOldPath = oldFilename.replace(/\\\\/g, '/');\n const normalizedNewPath = newFilename.replace(/\\\\/g, '/');\n\n content = content.replace(\n new RegExp(normalizedOldPath, 'g'),\n normalizedNewPath\n );\n }\n\n await writeFileContent(htmlFile, content);\n success(htmlFile.replace(outDir, ''));\n })\n );\n }\n\n logger.info('🎉 Purging completed successfully!');\n }\n }\n };\n}\n\nexport default Plugin;\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/colors.mjs","../src/utils.ts","../src/index.ts"],"names":["FORCE_COLOR","NODE_DISABLE_COLORS","NO_COLOR","TERM","isTTY","$","init","x","y","rgx","open","close","txt","dim","red","green","readFileContent","filePath","readFile","err","error","writeFileContent","content","writeFile","writeCssFile","newFilePath","css","oldFilePath","existsSync","unlink","generateFileHash","hash","createHash","cleanPath","file","path","fileURLToPath","dt","success","message","date","INTEGRATION_NAME","defaultExtractor","Plugin","options","config","strategy","__unsafeContent","purgecssOptions","cfg","vite","logger","code","id","randomUUID","dir","pages","buildMode","outDir","skipRehash","purgedCssFiles","PurgeCSS","relative","changedFiles","relativePath","hashedFilename","relativeOldPath","relativeNewPath","oldFilename","newFilename","htmlFiles","page","pathname","join","directFile","htmlFile","normalizedOldPath","normalizedNewPath","index_default"],"mappings":"4NAAA,IAAIA,CAAAA,CAAaC,CAAAA,CAAqBC,CAAAA,CAAUC,EAAMC,CAAAA,CAAM,IAAA,CACxD,OAAO,OAAA,CAAY,GAAA,GACrB,CAAE,WAAA,CAAAJ,CAAAA,CAAa,oBAAAC,CAAAA,CAAqB,QAAA,CAAAC,CAAAA,CAAU,IAAA,CAAAC,CAAK,CAAA,CAAI,OAAA,CAAQ,GAAA,EAAO,EAAC,CACxEC,CAAAA,CAAQ,OAAA,CAAQ,MA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AEAxB,CAAAA,CAAO,IAAA,CAAK,2CAAoC,EAClD,CACF,CACF,CACF,CAEA,IAAO2B,EAAAA,CAAQnC","file":"index.js","sourcesContent":["let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY=true;\nif (typeof process !== 'undefined') {\n\t({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});\n\tisTTY = process.stdout && process.stdout.isTTY;\n}\n\nexport const $ = {\n\tenabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && (\n\t\tFORCE_COLOR != null && FORCE_COLOR !== '0' || isTTY\n\t)\n}\n\nfunction init(x, y) {\n\tlet rgx = new RegExp(`\\\\x1b\\\\[${y}m`, 'g');\n\tlet open = `\\x1b[${x}m`, close = `\\x1b[${y}m`;\n\n\treturn function (txt) {\n\t\tif (!$.enabled || txt == null) return txt;\n\t\treturn open + (!!~(''+txt).indexOf(close) ? txt.replace(rgx, close + open) : txt) + close;\n\t};\n}\n\n// modifiers\nexport const reset = init(0, 0);\nexport const bold = init(1, 22);\nexport const dim = init(2, 22);\nexport const italic = init(3, 23);\nexport const underline = init(4, 24);\nexport const inverse = init(7, 27);\nexport const hidden = init(8, 28);\nexport const strikethrough = init(9, 29);\n\n// colors\nexport const black = init(30, 39);\nexport const red = init(31, 39);\nexport const green = init(32, 39);\nexport const yellow = init(33, 39);\nexport const blue = init(34, 39);\nexport const magenta = init(35, 39);\nexport const cyan = init(36, 39);\nexport const white = init(37, 39);\nexport const gray = init(90, 39);\nexport const grey = init(90, 39);\n\n// background colors\nexport const bgBlack = init(40, 49);\nexport const bgRed = init(41, 49);\nexport const bgGreen = init(42, 49);\nexport const bgYellow = init(43, 49);\nexport const bgBlue = init(44, 49);\nexport const bgMagenta = init(45, 49);\nexport const bgCyan = init(46, 49);\nexport const bgWhite = init(47, 49);\n","import { dim, green, red } from 'kleur/colors';\nimport { createHash } from 'node:crypto';\nimport { existsSync } from 'node:fs';\nimport { readFile, unlink, writeFile } from 'node:fs/promises';\nimport { fileURLToPath } from 'node:url';\n\nexport async function readFileContent(filePath: string): Promise<string> {\n try {\n const content = await readFile(filePath, 'utf8');\n return content;\n } catch (err) {\n error(`Error reading file ${filePath}: ${err}`);\n return '';\n }\n}\n\nexport async function writeFileContent(filePath: string, content: string) {\n try {\n await writeFile(filePath, content, 'utf8');\n } catch (err) {\n error(`Error writing file ${filePath}: ${err}`);\n }\n}\n\nexport async function writeCssFile(\n newFilePath: string,\n css: string,\n oldFilePath: string\n) {\n await writeFileContent(newFilePath, css);\n\n // Remove old file if it exists and is different from new file\n if (oldFilePath !== newFilePath && existsSync(oldFilePath)) {\n await unlink(oldFilePath);\n }\n}\n\nexport function generateFileHash(filePath: string, content: string) {\n // Get content hash before writing to file\n const hash = createHash('sha256').update(content).digest('hex').slice(0, 8);\n\n // Generate new file name with hash\n // Astro original hash is 8 characters long\n return `${filePath.slice(0, -13)}.${hash}.css`;\n}\n\n// Clean from trailing slash and extra leading slash on windows\nexport function cleanPath(file: URL): string {\n if (!(file instanceof URL)) {\n throw new TypeError('Expected a URL object');\n }\n\n // Remove trailing slash if present\n let path = fileURLToPath(file).replace(/(?:\\/+|\\\\+)$/, '');\n\n // Remove leading forward slash on windows if present\n return process.platform === 'win32' ? path.replace(/^\\/+/, '') : path;\n}\n\nexport const dt = new Intl.DateTimeFormat('en-us', {\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hour12: false\n});\n\nexport function success(message: string) {\n const date = dt.format(new Date());\n console.log(dim(date), green('▶'), message);\n}\n\nexport function error(message: string) {\n const date = dt.format(new Date());\n console.error(dim(date), red('■'), message);\n}\n","import type { AstroConfig, AstroIntegration } from 'astro';\nimport { existsSync } from 'node:fs';\nimport { join, relative } from 'node:path';\nimport { randomUUID } from 'node:crypto';\nimport { PurgeCSS, type UserDefinedOptions, type RawContent } from 'purgecss';\n\nimport {\n cleanPath,\n generateFileHash,\n readFileContent,\n success,\n writeCssFile,\n writeFileContent\n} from './utils';\n\ntype PurgeStrategy = 'default' | 'cache-buster';\n\n/**\n * Extended PurgeCSS options interface that allows partial configuration\n * of the standard PurgeCSS options\n */\nexport interface PurgeCSSOptions extends Partial<UserDefinedOptions> {\n strategy?: PurgeStrategy;\n /**\n * ⚠️ UNSAFE: Completely overrides the default content globs.\n * When provided, only these content sources will be scanned by PurgeCSS.\n * The default globs (outDir/**\\/*.html and outDir/**\\/*.js) will be ignored.\n *\n * Use this ONLY if the default globs cause performance issues on very large sites.\n * The double underscore prefix indicates this is an advanced option that should\n * be used with extreme caution.\n *\n * @example\n * ```ts\n * {\n * __unsafeContent: [\n * './dist/**\\/*.js',\n * './src/**\\/*.{astro,vue,jsx,tsx}'\n * ]\n * }\n * ```\n */\n __unsafeContent?: Array<string | RawContent>;\n}\n\nconst INTEGRATION_NAME = 'astro-purgecss' as const;\n\n/**\n * default extractor to handle various CSS selector patterns\n * @param content string\n */\nconst defaultExtractor = (content: string) =>\n content.match(/[\\w-/:\\.#\\(\\),';%]+(?<!:)/g) || [];\n\n/**\n * Astro integration for PurgeCSS that removes unused CSS from the final build\n * @param options - PurgeCSS configuration options\n * @returns AstroIntegration - The configured Astro integration\n */\nfunction Plugin(options: PurgeCSSOptions = {}): AstroIntegration {\n let config: AstroConfig;\n const { strategy = 'default', __unsafeContent, ...purgecssOptions } = options;\n\n return {\n name: INTEGRATION_NAME,\n hooks: {\n 'astro:config:done': ({ config: cfg }) => {\n config = cfg;\n },\n ...(strategy === 'cache-buster' && {\n 'astro:build:setup': ({ vite, logger }) => {\n if (!vite.plugins) vite.plugins = [];\n vite.plugins.push({\n name: 'inject-css-cache-buster',\n apply: 'build',\n enforce: 'pre',\n transform(code, id) {\n if (!/\\.(css|scss|sass|less|styl)(\\?|$)/.test(id)) {\n return null;\n }\n logger.info(`Injecting cache-buster CSS into: ${id}`);\n return {\n code: `/*! Build: ${randomUUID().slice(0, 8)} */\\n` + code,\n map: null\n };\n }\n });\n }\n }),\n 'astro:build:done': async ({ dir, pages, logger }) => {\n const buildMode = config.output;\n logger.info(`📦 Running in '${buildMode}' mode`);\n\n // Convert the URL to a filesystem path\n const outDir = cleanPath(dir);\n\n // skip file rehashing for SSR/Server mode or cache-buster strategy\n const skipRehash =\n buildMode !== 'static' || strategy === 'cache-buster';\n\n // Validate required Astro configuration\n if (!outDir || !config.build.format || !config.build.assets) {\n logger.warn(\n `${INTEGRATION_NAME} requires the following astro.config options: 'outDir', 'build.format', 'build.assets'`\n );\n return;\n }\n\n // Run PurgeCSS on all CSS files\n const purgeResults = await new PurgeCSS().purge({\n css: [`${outDir}/**/*.css`.replace(/\\\\/g, '/')],\n defaultExtractor,\n ...purgecssOptions,\n content: __unsafeContent ?? [\n `${outDir}/**/*.html`.replace(/\\\\/g, '/'),\n `${outDir}/**/*.js`.replace(/\\\\/g, '/'),\n ...(purgecssOptions.content || [])\n ]\n });\n\n // Filter out non-CSS files from purge results\n const purgedCssFiles = purgeResults.filter(({ file }) =>\n file?.endsWith('.css')\n ) as Array<{\n css: string;\n file: string;\n }>;\n\n if (purgedCssFiles.length === 0) {\n logger.info('ℹ️ No CSS files found to process');\n return;\n }\n\n logger.info(\n `Found ${purgedCssFiles.length} CSS ${purgedCssFiles.length === 1 ? 'file' : 'files'} to process`\n );\n\n // If SSR/Server mode or cache-buster strategy skip file rehash\n if (skipRehash) {\n await Promise.all(\n purgedCssFiles.map(async ({ css, file }) => {\n await writeCssFile(file, css, file);\n success(relative(outDir, file));\n })\n );\n logger.info('🎉 Purging completed successfully!');\n return;\n }\n\n // Process files for static mode with content hashing\n let processedFiles = await Promise.all(\n purgedCssFiles.map(async ({ css, file }) => {\n const isAssetFile = file.includes(config.build.assets);\n\n // Skip rehashing for non-asset files (not generated by astro)\n // ex: assets/styles/light.css\n if (!isAssetFile) {\n await writeCssFile(file, css, file);\n const relativePath = relative(outDir, file);\n success(relativePath);\n return {\n oldFilename: relativePath,\n newFilename: relativePath\n };\n }\n\n // Generate new filename with content hash\n const hashedFilename = generateFileHash(file, css);\n await writeCssFile(hashedFilename, css, file);\n\n const relativeOldPath = relative(outDir, file);\n const relativeNewPath = relative(outDir, hashedFilename);\n success(relativeNewPath);\n\n return {\n oldFilename: relativeOldPath,\n newFilename: relativeNewPath\n };\n })\n );\n\n // Filter to only get files that actually changed\n const changedFiles = processedFiles.filter(\n ({ oldFilename, newFilename }) => oldFilename !== newFilename\n );\n\n if (changedFiles.length > 0) {\n logger.info(\n `Updating ${changedFiles.length} CSS ${changedFiles.length === 1 ? 'reference' : 'references'} in HTML files...`\n );\n // Get all HTML pages based on build format\n const htmlFiles = pages\n .filter((page) => typeof page.pathname === 'string')\n .map((page) => {\n const pathname = page.pathname as string;\n\n // Handle root/index page\n if (pathname === '') {\n return join(outDir, 'index.html');\n }\n\n /**\n * Custom 404 Error Page\n *\n * @see https://docs.astro.build/en/basics/astro-pages/#custom-404-error-page\n */\n if (pathname === '404/' || pathname === '404') {\n return join(outDir, '404.html');\n }\n\n /**\n * Custom 500 Error Page\n *\n * @see https://docs.astro.build/en/basics/astro-pages/#custom-500-error-page\n */\n if (pathname === '500/' || pathname === '500') {\n return join(outDir, '500.html');\n }\n\n switch (config.build.format) {\n case 'file':\n // Format: /blog -> /blog.html\n return join(outDir, `${pathname}.html`);\n\n case 'directory':\n // Format: /blog -> /blog/index.html\n return join(outDir, pathname, 'index.html');\n\n case 'preserve':\n // Check if direct HTML file exists, otherwise use directory format\n const directFile = join(outDir, `${pathname}.html`);\n return existsSync(directFile)\n ? directFile\n : join(outDir, pathname, 'index.html');\n }\n });\n\n // Update CSS references in HTML files\n await Promise.all(\n htmlFiles.map(async (htmlFile) => {\n let content = await readFileContent(htmlFile);\n\n for (const { oldFilename, newFilename } of changedFiles) {\n const normalizedOldPath = oldFilename.replace(/\\\\/g, '/');\n const normalizedNewPath = newFilename.replace(/\\\\/g, '/');\n\n content = content.replace(\n new RegExp(normalizedOldPath, 'g'),\n normalizedNewPath\n );\n }\n\n await writeFileContent(htmlFile, content);\n success(relative(outDir, htmlFile));\n })\n );\n }\n\n logger.info('🎉 Purging completed successfully!');\n }\n }\n };\n}\n\nexport default Plugin;\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-purgecss",
|
|
3
3
|
"description": "Remove unused CSS rules from your final Astro bundle",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "6.0.1",
|
|
5
5
|
"homepage": "https://github.com/codiume/orbit",
|
|
6
6
|
"bugs": "https://github.com/codiume/orbit/issues",
|
|
7
7
|
"author": "codiume",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"astro": "^
|
|
42
|
-
"purgecss": "^
|
|
41
|
+
"astro": "^6.0.0",
|
|
42
|
+
"purgecss": "^8.0.0"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsup",
|