astro-purgecss 4.5.0 → 4.6.0
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/README.md +2 -2
- package/dist/index.cjs +3 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -143,8 +143,8 @@ We have also setup an example repository available here: [example-purgecss](../.
|
|
|
143
143
|
export default defineConfig({
|
|
144
144
|
integrations: [
|
|
145
145
|
purgecss({
|
|
146
|
-
+ keyframes: false
|
|
147
|
-
+
|
|
146
|
+
+ keyframes: false,
|
|
147
|
+
+ safelist: {
|
|
148
148
|
+ greedy: [/*astro*/]
|
|
149
149
|
+ }
|
|
150
150
|
}),
|
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var url = require('url');
|
|
4
3
|
var purgecss = require('purgecss');
|
|
5
4
|
var crypto = require('crypto');
|
|
6
5
|
var promises = require('fs/promises');
|
|
7
|
-
var
|
|
6
|
+
var url = require('url');
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
var l,f,w,h,b=!0;typeof process<"u"&&({FORCE_COLOR:l,NODE_DISABLE_COLORS:f,NO_COLOR:w,TERM:h}=process.env||{},b=process.stdout&&process.stdout.isTTY);var P={enabled:!f&&w==null&&h!=="dumb"&&(l!=null&&l!=="0"||b)};function e(n,t){let s=new RegExp(`\\x1b\\[${t}m`,"g"),r=`\x1B[${n}m`,i=`\x1B[${t}m`;return function(c){return !P.enabled||c==null?c:r+(~(""+c).indexOf(i)?c.replace(s,i+r):c)+i}}var u=e(2,22),y=e(32,39),O=e(34,39);async function R(n,t,s){try{let r=await promises.readFile(n,"utf8");if(r.includes(t)){let i=r.replace(new RegExp(t,"g"),s);await promises.writeFile(n,i,"utf8");}}catch(r){console.error(`Error processing file ${n}: ${r}`);}}function d(n){let t=url.fileURLToPath(n);return t=t.replace(/\/+$/,""),process.platform!=="win32"?t:t.replace(/^\/+/,"")}async function $({css:n,file:t}){if(!t.includes("_astro/"))return await promises.writeFile(t,n),[t,t];let s=crypto.createHash("sha256").update(n).digest("hex").substring(0,8),r=`${t.slice(0,-13)}.${s}.css`;return await promises.writeFile(r,n),await promises.unlink(t),[t,r]}var C=new Intl.DateTimeFormat("en-us",{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1});function x(n){let t=C.format(new Date);console.log(u(t),y("\u25B6"),n);}function m(n){let t=C.format(new Date);console.log(u(t),O("[purgecss]"),n);}function U(n={}){return {name:"astro-purgecss",hooks:{"astro:build:done":async({dir:t,routes:s})=>{m("Generating purged css files...");let r=d(t),i=await new purgecss.PurgeCSS().purge({css:[`${r}/**/*.css`],defaultExtractor:o=>o.match(/[\w-/:]+(?<!:)/g)||[],...n,content:[`${r}/**/*.html`,`${r}/**/*.js`,...n.content||[]]}),c=await Promise.all(i.filter(({file:o})=>o?.endsWith(".css")).map(async({css:o,file:p})=>{let a=await $({css:o,file:p});return x(a[1].replace(r,"")),a}));m("Generating purged html pages...");let L=s.filter(o=>!(o.pathname===void 0||o.distURL===void 0||o.type!=="page")).map(o=>d(o.distURL));await Promise.all(L.map(async o=>{await Promise.all(c.map(async([p,a])=>{p!==a&&await R(o,p.replace(r,""),a.replace(r,""));})),x(o.replace(r,""));}));}}}}var le=U;
|
|
10
9
|
|
|
11
|
-
module.exports =
|
|
10
|
+
module.exports = le;
|
|
12
11
|
//# sourceMappingURL=index.cjs.map
|
|
13
12
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts","../src/index.ts"],"names":["replaceStringInFile","filePath","searchValue","replaceValue","fileContent","readFile","re","newContent","writeFile","err","replaceStringInDirectory","directory","files","readdir","file","fullPath","join","resolveOutputPath","outputPath","writeCssFile","css","outDir","hash","createHash","newFile","unl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,CAAA,CACP,GAAGR,CAAM,CAAA,UAAA,CAAA,CACT,CAAGA,EAAAA,CAAM,WACT,GAAIQ,CAAAA,CAAQ,SAAW,EACzB,CACF,CAAC,CAAA,CACD,MAAM,OAAA,CAAQ,IACZG,CACG,CAAA,MAAA,CAAO,CAAC,CAAE,KAAAlB,CAAK,CAAA,GAAMA,CAAM,EAAA,QAAA,CAAS,MAAM,CAAC,CAAA,CAC3C,IACC,MAAO,CAAE,IAAAM,CAAK,CAAA,IAAA,CAAAN,CAAK,CAAA,GAAM,MAAMK,CAAa,CAAA,CAAE,IAAAC,CAAK,CAAA,IAAA,CAAAN,EAAM,MAAAO,CAAAA,CAAO,CAAC,CACnE,CACJ,EACF,CACF,CACF,CACF,KAEOc,CAAQP,CAAAA","file":"index.cjs","sourcesContent":["import { createHash } from 'node:crypto';\nimport { readdir, readFile, unlink, writeFile } from 'node:fs/promises';\nimport { basename, dirname, join } from 'node:path';\n\nasync function replaceStringInFile(\n filePath: string,\n searchValue: string,\n replaceValue: string\n) {\n try {\n const fileContent = await readFile(filePath, 'utf8');\n if (fileContent.includes(searchValue)) {\n const re = new RegExp(searchValue, 'g');\n const newContent = fileContent.replace(re, replaceValue);\n await writeFile(filePath, newContent, 'utf8');\n }\n } catch (err) {\n console.error(`Error processing file ${filePath}: ${err}`);\n }\n}\n\nasync function replaceStringInDirectory(\n directory: string,\n searchValue: string,\n replaceValue: string\n) {\n try {\n const files = await readdir(directory, { withFileTypes: true });\n for (const file of files) {\n const fullPath = join(directory, file.name);\n if (file.isDirectory()) {\n await replaceStringInDirectory(fullPath, searchValue, replaceValue);\n } else if (file.isFile()) {\n await replaceStringInFile(fullPath, searchValue, replaceValue);\n }\n }\n } catch (err) {\n console.error(`Error processing directory ${directory}: ${err}`);\n }\n}\n\nexport function resolveOutputPath(outputPath: string): string {\n if (process.platform !== 'win32') return outputPath;\n\n // Remove trailing backslash if present\n outputPath = outputPath.replace(/\\\\+$/, '');\n\n // Replace all backslashes with forward slashes\n return outputPath.replace(/\\\\/g, '/');\n}\n\nexport async function writeCssFile({\n css,\n file,\n outDir\n}: {\n css: string;\n file?: string;\n outDir: string;\n}) {\n if (!file) return;\n\n // Get content hash before writing to file\n const hash = createHash('sha256').update(css).digest('hex').substring(0, 8);\n\n // Generate new file name with hash\n // Astro orignal hash is 8 characters long\n const newFile = `${file.slice(0, -13)}.${hash}.css`;\n\n // Write purged CSS to new file\n await writeFile(newFile, css);\n\n // Remove old file\n await unlink(file);\n\n // Replace old name references with new file name\n await replaceStringInDirectory(\n dirname(outDir), // Search from parent directory\n basename(file),\n basename(newFile)\n );\n\n return newFile;\n}\n","import type { AstroIntegration } from 'astro';\nimport { fileURLToPath } from 'node:url';\nimport { PurgeCSS, type UserDefinedOptions } from 'purgecss';\n\nimport { resolveOutputPath, writeCssFile } from './utils';\n\nexport interface PurgeCSSOptions extends Partial<UserDefinedOptions> {}\n\nfunction Plugin(options: PurgeCSSOptions = {}): AstroIntegration {\n return {\n name: 'astro-purgecss',\n hooks: {\n 'astro:build:done': async ({ dir }) => {\n const outDir = resolveOutputPath(fileURLToPath(dir));\n const purged = await new PurgeCSS().purge({\n css: [`${outDir}/**/*.css`],\n defaultExtractor: (content) => content.match(/[\\w-/:]+(?<!:)/g) || [],\n ...options,\n content: [\n `${outDir}/**/*.html`,\n `${outDir}/**/*.js`,\n ...(options.content || [])\n ]\n });\n await Promise.all(\n purged\n .filter(({ file }) => file?.endsWith('.css'))\n .map(\n async ({ css, file }) => await writeCssFile({ css, file, outDir })\n )\n );\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","reset","dim","italic","green","blue","replaceValueInFile","filePath","searchValue","replaceValue","content","readFile","newContent","writeFile","err","cleanPath","file","path","fileURLToPath","writeCssFile","css","hash","createHash","newFile","unlink","dt","success","message","date","headline","Plugin","options","dir","routes","outDir","purged","PurgeCSS","processed","pages","route","page","oldFile","src_default"],"mappings":";;;;;;;AAAA,IAAIA,CAAAA,CAAaC,EAAqBC,CAAUC,CAAAA,CAAAA,CAAMC,CAAM,CAAA,CAAA,CAAA,CACxD,OAAO,OAAY,CAAA,GAAA,GACrB,CAAE,WAAA,CAAAJ,EAAa,mBAAAC,CAAAA,CAAAA,CAAqB,QAAAC,CAAAA,CAAAA,CAAU,KAAAC,CAAK,CAAA,CAAI,OAAQ,CAAA,GAAA,EAAO,EACvEC,CAAAA,CAAAA,CAAQ,OAAQ,CAAA,MAAA,EAAU,QAAQ,MAAO,CAAA,KAAA,CAAA,CAGnC,IAAMC,CAAAA,CAAI,CAChB,OAAS,CAAA,CAACJ,CAAuBC,EAAAA,CAAAA,EAAY,MAAQC,CAAS,GAAA,MAAA,GAC7DH,CAAe,EAAA,IAAA,EAAQA,IAAgB,GAAOI,EAAAA,CAAAA,CAEhD,CAEA,CAAA,SAASE,EAAKC,CAAGC,CAAAA,CAAAA,CAAG,CACnB,IAAIC,EAAM,IAAI,MAAA,CAAO,CAAWD,QAAAA,EAAAA,CAAC,IAAK,GAAG,CAAA,CACrCE,CAAO,CAAA,CAAA,KAAA,EAAQH,CAAC,CAAKI,CAAAA,CAAAA,CAAAA,CAAAA,CAAQ,CAAQH,KAAAA,EAAAA,CAAC,IAE1C,OAAO,SAAUI,EAAK,CACrB,OAAI,CAACP,CAAE,CAAA,OAAA,EAAWO,CAAO,EAAA,IAAA,CAAaA,EAC/BF,CAAU,EAAA,CAAA,CAAE,EAAGE,CAAAA,CAAAA,EAAK,QAAQD,CAAK,CAAA,CAAIC,CAAI,CAAA,OAAA,CAAQH,EAAKE,CAAQD,CAAAA,CAAI,CAAIE,CAAAA,CAAAA,CAAAA,CAAOD,CACrF,CACD,CAGaE,IAEAC,CAAAA,CAAMR,EAAK,CAAG,CAAA,EA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lB,GAAAA,CAAAA,EACd,MAAMjB,CACJkC,CAAAA,CAAAA,CACAC,CAAQ,CAAA,OAAA,CAAQP,EAAQ,EAAE,CAAA,CAC1BX,CAAQ,CAAA,OAAA,CAAQW,EAAQ,EAAE,CAC5B,EAEJ,CAAC,CACH,CACAR,CAAAA,CAAAA,CAAQc,CAAK,CAAA,OAAA,CAAQN,EAAQ,EAAE,CAAC,EAClC,CAAC,CACH,EACF,CACF,CACF,CACF,KAEOQ,EAAQZ,CAAAA","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 { blue, dim, green } from 'kleur/colors';\nimport { createHash } from 'node:crypto';\nimport { readFile, unlink, writeFile } from 'node:fs/promises';\nimport { fileURLToPath } from 'node:url';\n\nexport async function replaceValueInFile(\n filePath: string,\n searchValue: string,\n replaceValue: string\n) {\n try {\n const content = await readFile(filePath, 'utf8');\n if (content.includes(searchValue)) {\n const newContent = content.replace(\n new RegExp(searchValue, 'g'),\n replaceValue\n );\n await writeFile(filePath, newContent, 'utf8');\n }\n } catch (err) {\n console.error(`Error processing file ${filePath}: ${err}`);\n }\n}\n\n// Clean from extra slash on windows and trailing forward slash on non-windows\nexport function cleanPath(file: URL): string {\n let path = fileURLToPath(file);\n\n // Remove trailing forward slash if present\n path = path.replace(/\\/+$/, '');\n\n if (process.platform !== 'win32') return path;\n\n // Remove leading forward slash if present\n return path.replace(/^\\/+/, '');\n}\n\nexport async function writeCssFile({\n css,\n file\n}: {\n css: string;\n file: string;\n}) {\n // Skip re-hashing a file if it's not generated by Astro ex: assets/styles/light.css\n if (!file.includes('_astro/')) {\n await writeFile(file, css);\n return [file, file];\n }\n\n // Get content hash before writing to file\n const hash = createHash('sha256').update(css).digest('hex').substring(0, 8);\n\n // Generate new file name with hash\n // Astro orignal hash is 8 characters long\n const newFile = `${file.slice(0, -13)}.${hash}.css`;\n\n // Write purged CSS to new file\n await writeFile(newFile, css);\n\n // Remove old file\n await unlink(file);\n\n return [file, newFile];\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 headline(message: string) {\n const date = dt.format(new Date());\n console.log(dim(date), blue('[purgecss]'), message);\n}\n","import type { AstroIntegration } from 'astro';\nimport { PurgeCSS, type UserDefinedOptions } from 'purgecss';\n\nimport {\n cleanPath,\n headline,\n replaceValueInFile,\n success,\n writeCssFile\n} from './utils';\n\nexport interface PurgeCSSOptions extends Partial<UserDefinedOptions> {}\n\nfunction Plugin(options: PurgeCSSOptions = {}): AstroIntegration {\n return {\n name: 'astro-purgecss',\n hooks: {\n 'astro:build:done': async ({ dir, routes }) => {\n headline('Generating purged css files...');\n\n const outDir = cleanPath(dir);\n const purged = await new PurgeCSS().purge({\n css: [`${outDir}/**/*.css`],\n defaultExtractor: (content) => content.match(/[\\w-/:]+(?<!:)/g) || [],\n ...options,\n content: [\n `${outDir}/**/*.html`,\n `${outDir}/**/*.js`,\n ...(options.content || [])\n ]\n });\n\n const processed = await Promise.all(\n purged\n .filter(({ file }) => file?.endsWith('.css'))\n .map(async ({ css, file }) => {\n const processed = await writeCssFile({ css, file } as {\n css: string;\n file: string;\n });\n success(processed[1].replace(outDir, ''));\n\n return processed;\n })\n );\n\n headline('Generating purged html pages...');\n const pages = routes\n .filter((route) => {\n if (\n route.pathname === undefined ||\n route.distURL === undefined ||\n route.type !== 'page'\n ) {\n return false;\n }\n\n return true;\n })\n .map((route) => cleanPath(route.distURL as URL));\n\n await Promise.all(\n pages.map(async (page) => {\n await Promise.all(\n processed.map(async ([oldFile, newFile]) => {\n // Replace only if name of the old file\n // is different from name of the new file (hash changes)\n if (oldFile !== newFile) {\n await replaceValueInFile(\n page,\n oldFile.replace(outDir, ''),\n newFile.replace(outDir, '')\n );\n }\n })\n );\n success(page.replace(outDir, ''));\n })\n );\n }\n }\n };\n}\n\nexport default Plugin;\n"]}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { fileURLToPath } from 'node:url';
|
|
2
1
|
import { PurgeCSS } from 'purgecss';
|
|
3
2
|
import { createHash } from 'node:crypto';
|
|
4
|
-
import { writeFile, unlink
|
|
5
|
-
import {
|
|
3
|
+
import { readFile, writeFile, unlink } from 'node:fs/promises';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
var l,f,w,h,b=!0;typeof process<"u"&&({FORCE_COLOR:l,NODE_DISABLE_COLORS:f,NO_COLOR:w,TERM:h}=process.env||{},b=process.stdout&&process.stdout.isTTY);var P={enabled:!f&&w==null&&h!=="dumb"&&(l!=null&&l!=="0"||b)};function e(n,t){let s=new RegExp(`\\x1b\\[${t}m`,"g"),r=`\x1B[${n}m`,i=`\x1B[${t}m`;return function(c){return !P.enabled||c==null?c:r+(~(""+c).indexOf(i)?c.replace(s,i+r):c)+i}}var u=e(2,22),y=e(32,39),O=e(34,39);async function R(n,t,s){try{let r=await readFile(n,"utf8");if(r.includes(t)){let i=r.replace(new RegExp(t,"g"),s);await writeFile(n,i,"utf8");}}catch(r){console.error(`Error processing file ${n}: ${r}`);}}function d(n){let t=fileURLToPath(n);return t=t.replace(/\/+$/,""),process.platform!=="win32"?t:t.replace(/^\/+/,"")}async function $({css:n,file:t}){if(!t.includes("_astro/"))return await writeFile(t,n),[t,t];let s=createHash("sha256").update(n).digest("hex").substring(0,8),r=`${t.slice(0,-13)}.${s}.css`;return await writeFile(r,n),await unlink(t),[t,r]}var C=new Intl.DateTimeFormat("en-us",{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1});function x(n){let t=C.format(new Date);console.log(u(t),y("\u25B6"),n);}function m(n){let t=C.format(new Date);console.log(u(t),O("[purgecss]"),n);}function U(n={}){return {name:"astro-purgecss",hooks:{"astro:build:done":async({dir:t,routes:s})=>{m("Generating purged css files...");let r=d(t),i=await new PurgeCSS().purge({css:[`${r}/**/*.css`],defaultExtractor:o=>o.match(/[\w-/:]+(?<!:)/g)||[],...n,content:[`${r}/**/*.html`,`${r}/**/*.js`,...n.content||[]]}),c=await Promise.all(i.filter(({file:o})=>o?.endsWith(".css")).map(async({css:o,file:p})=>{let a=await $({css:o,file:p});return x(a[1].replace(r,"")),a}));m("Generating purged html pages...");let L=s.filter(o=>!(o.pathname===void 0||o.distURL===void 0||o.type!=="page")).map(o=>d(o.distURL));await Promise.all(L.map(async o=>{await Promise.all(c.map(async([p,a])=>{p!==a&&await R(o,p.replace(r,""),a.replace(r,""));})),x(o.replace(r,""));}));}}}}var le=U;
|
|
8
7
|
|
|
9
|
-
export {
|
|
8
|
+
export { le as default };
|
|
10
9
|
//# sourceMappingURL=index.js.map
|
|
11
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts","../src/index.ts"],"names":["replaceStringInFile","filePath","searchValue","replaceValue","fileContent","readFile","re","newContent","writeFile","err","replaceStringInDirectory","directory","files","readdir","file","fullPath","join","resolveOutputPath","outputPath","writeCssFile","css","outDir","hash","createHash","newFile","unlink","dirname","basename","Plugin","options","dir","fileURLToPath","purged","PurgeCSS","content","src_default"],"mappings":";;;;;;AAIA,eAAeA,CAAAA,CACbC,EACAC,CACAC,CAAAA,CAAAA,CACA,CACA,GAAI,CACF,IAAMC,CAAc,CAAA,MAAMC,QAASJ,CAAAA,CAAAA,CAAU,MAAM,CACnD,CAAA,GAAIG,CAAY,CAAA,QAAA,CAASF,CAAW,CAAG,CAAA,CACrC,IAAMI,CAAAA,CAAK,IAAI,MAAOJ,CAAAA,CAAAA,CAAa,GAAG,CAChCK,CAAAA,CAAAA,CAAaH,EAAY,OAAQE,CAAAA,CAAAA,CAAIH,CAAY,CAAA,CACvD,MAAMK,SAAUP,CAAAA,CAAAA,CAAUM,CAAY,CAAA,MAAM,EAC9C,CACF,CAAA,MAASE,CAAK,CAAA,CACZ,QAAQ,KAAM,CAAA,CAAA,sBAAA,EAAyBR,CAAQ,CAAKQ,EAAAA,EAAAA,CAAG,EAAE,EAC3D,CACF,CAEA,eAAeC,EACbC,CACAT,CAAAA,CAAAA,CACAC,CACA,CAAA,CACA,GAAI,CACF,IAAMS,CAAQ,C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L,CAAM,CAAA,CACdM,QAASb,CAAAA,CAAI,EACba,QAASH,CAAAA,CAAO,CAClB,CAEOA,CAAAA,CACT,CC3EA,SAASI,CAAAA,CAAOC,CAA2B,CAAA,GAAsB,CAC/D,OAAO,CACL,IAAA,CAAM,iBACN,KAAO,CAAA,CACL,kBAAoB,CAAA,MAAO,CAAE,GAAAC,CAAAA,CAAI,IAAM,CACrC,IAAMT,EAASJ,CAAkBc,CAAAA,aAAAA,CAAcD,CAAG,CAAC,EAC7CE,CAAS,CAAA,MAAM,IAAIC,QAAAA,GAAW,KAAM,CAAA,CACxC,GAAK,CAAA,CAAC,GAAGZ,CAAM,CAAA,SAAA,CAAW,EAC1B,gBAAmBa,CAAAA,CAAAA,EAAYA,EAAQ,KAAM,CAAA,iBAAiB,CAAK,EAAA,GACnE,GAAGL,CAAAA,CACH,OAAS,CAAA,CACP,GAAGR,CAAM,CAAA,UAAA,CAAA,CACT,CAAGA,EAAAA,CAAM,WACT,GAAIQ,CAAAA,CAAQ,SAAW,EACzB,CACF,CAAC,CAAA,CACD,MAAM,OAAA,CAAQ,IACZG,CACG,CAAA,MAAA,CAAO,CAAC,CAAE,KAAAlB,CAAK,CAAA,GAAMA,CAAM,EAAA,QAAA,CAAS,MAAM,CAAC,CAAA,CAC3C,IACC,MAAO,CAAE,IAAAM,CAAK,CAAA,IAAA,CAAAN,CAAK,CAAA,GAAM,MAAMK,CAAa,CAAA,CAAE,IAAAC,CAAK,CAAA,IAAA,CAAAN,EAAM,MAAAO,CAAAA,CAAO,CAAC,CACnE,CACJ,EACF,CACF,CACF,CACF,KAEOc,CAAQP,CAAAA","file":"index.js","sourcesContent":["import { createHash } from 'node:crypto';\nimport { readdir, readFile, unlink, writeFile } from 'node:fs/promises';\nimport { basename, dirname, join } from 'node:path';\n\nasync function replaceStringInFile(\n filePath: string,\n searchValue: string,\n replaceValue: string\n) {\n try {\n const fileContent = await readFile(filePath, 'utf8');\n if (fileContent.includes(searchValue)) {\n const re = new RegExp(searchValue, 'g');\n const newContent = fileContent.replace(re, replaceValue);\n await writeFile(filePath, newContent, 'utf8');\n }\n } catch (err) {\n console.error(`Error processing file ${filePath}: ${err}`);\n }\n}\n\nasync function replaceStringInDirectory(\n directory: string,\n searchValue: string,\n replaceValue: string\n) {\n try {\n const files = await readdir(directory, { withFileTypes: true });\n for (const file of files) {\n const fullPath = join(directory, file.name);\n if (file.isDirectory()) {\n await replaceStringInDirectory(fullPath, searchValue, replaceValue);\n } else if (file.isFile()) {\n await replaceStringInFile(fullPath, searchValue, replaceValue);\n }\n }\n } catch (err) {\n console.error(`Error processing directory ${directory}: ${err}`);\n }\n}\n\nexport function resolveOutputPath(outputPath: string): string {\n if (process.platform !== 'win32') return outputPath;\n\n // Remove trailing backslash if present\n outputPath = outputPath.replace(/\\\\+$/, '');\n\n // Replace all backslashes with forward slashes\n return outputPath.replace(/\\\\/g, '/');\n}\n\nexport async function writeCssFile({\n css,\n file,\n outDir\n}: {\n css: string;\n file?: string;\n outDir: string;\n}) {\n if (!file) return;\n\n // Get content hash before writing to file\n const hash = createHash('sha256').update(css).digest('hex').substring(0, 8);\n\n // Generate new file name with hash\n // Astro orignal hash is 8 characters long\n const newFile = `${file.slice(0, -13)}.${hash}.css`;\n\n // Write purged CSS to new file\n await writeFile(newFile, css);\n\n // Remove old file\n await unlink(file);\n\n // Replace old name references with new file name\n await replaceStringInDirectory(\n dirname(outDir), // Search from parent directory\n basename(file),\n basename(newFile)\n );\n\n return newFile;\n}\n","import type { AstroIntegration } from 'astro';\nimport { fileURLToPath } from 'node:url';\nimport { PurgeCSS, type UserDefinedOptions } from 'purgecss';\n\nimport { resolveOutputPath, writeCssFile } from './utils';\n\nexport interface PurgeCSSOptions extends Partial<UserDefinedOptions> {}\n\nfunction Plugin(options: PurgeCSSOptions = {}): AstroIntegration {\n return {\n name: 'astro-purgecss',\n hooks: {\n 'astro:build:done': async ({ dir }) => {\n const outDir = resolveOutputPath(fileURLToPath(dir));\n const purged = await new PurgeCSS().purge({\n css: [`${outDir}/**/*.css`],\n defaultExtractor: (content) => content.match(/[\\w-/:]+(?<!:)/g) || [],\n ...options,\n content: [\n `${outDir}/**/*.html`,\n `${outDir}/**/*.js`,\n ...(options.content || [])\n ]\n });\n await Promise.all(\n purged\n .filter(({ file }) => file?.endsWith('.css'))\n .map(\n async ({ css, file }) => await writeCssFile({ css, file, outDir })\n )\n );\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","reset","dim","italic","green","blue","replaceValueInFile","filePath","searchValue","replaceValue","content","readFile","newContent","writeFile","err","cleanPath","file","path","fileURLToPath","writeCssFile","css","hash","createHash","newFile","unlink","dt","success","message","date","headline","Plugin","options","dir","routes","outDir","purged","PurgeCSS","processed","pages","route","page","oldFile","src_default"],"mappings":";;;;;AAAA,IAAIA,CAAAA,CAAaC,EAAqBC,CAAUC,CAAAA,CAAAA,CAAMC,CAAM,CAAA,CAAA,CAAA,CACxD,OAAO,OAAY,CAAA,GAAA,GACrB,CAAE,WAAA,CAAAJ,EAAa,mBAAAC,CAAAA,CAAAA,CAAqB,QAAAC,CAAAA,CAAAA,CAAU,KAAAC,CAAK,CAAA,CAAI,OAAQ,CAAA,GAAA,EAAO,EACvEC,CAAAA,CAAAA,CAAQ,OAAQ,CAAA,MAAA,EAAU,QAAQ,MAAO,CAAA,KAAA,CAAA,CAGnC,IAAMC,CAAAA,CAAI,CAChB,OAAS,CAAA,CAACJ,CAAuBC,EAAAA,CAAAA,EAAY,MAAQC,CAAS,GAAA,MAAA,GAC7DH,CAAe,EAAA,IAAA,EAAQA,IAAgB,GAAOI,EAAAA,CAAAA,CAEhD,CAEA,CAAA,SAASE,EAAKC,CAAGC,CAAAA,CAAAA,CAAG,CACnB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jCG,CACT,CAAC,CACL,CAEAR,CAAAA,CAAAA,CAAS,iCAAiC,CAC1C,CAAA,IAAMS,CAAQL,CAAAA,CAAAA,CACX,OAAQM,CAEL,EAAA,EAAAA,CAAM,CAAA,QAAA,GAAa,QACnBA,CAAM,CAAA,OAAA,GAAY,KAClBA,CAAAA,EAAAA,CAAAA,CAAM,OAAS,MAMlB,CAAA,CAAA,CACA,GAAKA,CAAAA,CAAAA,EAAUxB,EAAUwB,CAAM,CAAA,OAAc,CAAC,CAAA,CAEjD,MAAM,OAAQ,CAAA,GAAA,CACZD,CAAM,CAAA,GAAA,CAAI,MAAOE,CAAS,EAAA,CACxB,MAAM,OAAQ,CAAA,GAAA,CACZH,EAAU,GAAI,CAAA,MAAO,CAACI,CAAAA,CAASlB,CAAO,CAAM,GAAA,CAGtCkB,CAAYlB,GAAAA,CAAAA,EACd,MAAMjB,CACJkC,CAAAA,CAAAA,CACAC,CAAQ,CAAA,OAAA,CAAQP,EAAQ,EAAE,CAAA,CAC1BX,CAAQ,CAAA,OAAA,CAAQW,EAAQ,EAAE,CAC5B,EAEJ,CAAC,CACH,CACAR,CAAAA,CAAAA,CAAQc,CAAK,CAAA,OAAA,CAAQN,EAAQ,EAAE,CAAC,EAClC,CAAC,CACH,EACF,CACF,CACF,CACF,KAEOQ,EAAQZ,CAAAA","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 { blue, dim, green } from 'kleur/colors';\nimport { createHash } from 'node:crypto';\nimport { readFile, unlink, writeFile } from 'node:fs/promises';\nimport { fileURLToPath } from 'node:url';\n\nexport async function replaceValueInFile(\n filePath: string,\n searchValue: string,\n replaceValue: string\n) {\n try {\n const content = await readFile(filePath, 'utf8');\n if (content.includes(searchValue)) {\n const newContent = content.replace(\n new RegExp(searchValue, 'g'),\n replaceValue\n );\n await writeFile(filePath, newContent, 'utf8');\n }\n } catch (err) {\n console.error(`Error processing file ${filePath}: ${err}`);\n }\n}\n\n// Clean from extra slash on windows and trailing forward slash on non-windows\nexport function cleanPath(file: URL): string {\n let path = fileURLToPath(file);\n\n // Remove trailing forward slash if present\n path = path.replace(/\\/+$/, '');\n\n if (process.platform !== 'win32') return path;\n\n // Remove leading forward slash if present\n return path.replace(/^\\/+/, '');\n}\n\nexport async function writeCssFile({\n css,\n file\n}: {\n css: string;\n file: string;\n}) {\n // Skip re-hashing a file if it's not generated by Astro ex: assets/styles/light.css\n if (!file.includes('_astro/')) {\n await writeFile(file, css);\n return [file, file];\n }\n\n // Get content hash before writing to file\n const hash = createHash('sha256').update(css).digest('hex').substring(0, 8);\n\n // Generate new file name with hash\n // Astro orignal hash is 8 characters long\n const newFile = `${file.slice(0, -13)}.${hash}.css`;\n\n // Write purged CSS to new file\n await writeFile(newFile, css);\n\n // Remove old file\n await unlink(file);\n\n return [file, newFile];\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 headline(message: string) {\n const date = dt.format(new Date());\n console.log(dim(date), blue('[purgecss]'), message);\n}\n","import type { AstroIntegration } from 'astro';\nimport { PurgeCSS, type UserDefinedOptions } from 'purgecss';\n\nimport {\n cleanPath,\n headline,\n replaceValueInFile,\n success,\n writeCssFile\n} from './utils';\n\nexport interface PurgeCSSOptions extends Partial<UserDefinedOptions> {}\n\nfunction Plugin(options: PurgeCSSOptions = {}): AstroIntegration {\n return {\n name: 'astro-purgecss',\n hooks: {\n 'astro:build:done': async ({ dir, routes }) => {\n headline('Generating purged css files...');\n\n const outDir = cleanPath(dir);\n const purged = await new PurgeCSS().purge({\n css: [`${outDir}/**/*.css`],\n defaultExtractor: (content) => content.match(/[\\w-/:]+(?<!:)/g) || [],\n ...options,\n content: [\n `${outDir}/**/*.html`,\n `${outDir}/**/*.js`,\n ...(options.content || [])\n ]\n });\n\n const processed = await Promise.all(\n purged\n .filter(({ file }) => file?.endsWith('.css'))\n .map(async ({ css, file }) => {\n const processed = await writeCssFile({ css, file } as {\n css: string;\n file: string;\n });\n success(processed[1].replace(outDir, ''));\n\n return processed;\n })\n );\n\n headline('Generating purged html pages...');\n const pages = routes\n .filter((route) => {\n if (\n route.pathname === undefined ||\n route.distURL === undefined ||\n route.type !== 'page'\n ) {\n return false;\n }\n\n return true;\n })\n .map((route) => cleanPath(route.distURL as URL));\n\n await Promise.all(\n pages.map(async (page) => {\n await Promise.all(\n processed.map(async ([oldFile, newFile]) => {\n // Replace only if name of the old file\n // is different from name of the new file (hash changes)\n if (oldFile !== newFile) {\n await replaceValueInFile(\n page,\n oldFile.replace(outDir, ''),\n newFile.replace(outDir, '')\n );\n }\n })\n );\n success(page.replace(outDir, ''));\n })\n );\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.
|
|
4
|
+
"version": "4.6.0",
|
|
5
5
|
"homepage": "https://github.com/codiume/orbit",
|
|
6
6
|
"bugs": "https://github.com/codiume/orbit/issues",
|
|
7
7
|
"author": "codiume",
|