Skip to content

Commit

Permalink
AstroCompress/v2.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Oct 24, 2024
2 parents 655840d + 043ced6 commit 378d888
Show file tree
Hide file tree
Showing 24 changed files with 178 additions and 50 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ CODE_OF_CONDUCT.md
CONTRIBUTING.md
docs/
Source/
Configuration/
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
## 2.3.5

### Added

- New Configuration folder with ESBuild.js and ESBuild.ts files
- Added browserslist as a development dependency

### Changed

- Updated .npmignore to exclude the Configuration/ directory
- Modified package.json scripts to use the new ESBuild configuration
- Updated version to 0.1.6
- Enhanced error handling in CSS compression in Source/Function/Integration.ts
- Updated Source/Interface/CSS/lightningcss.ts to set default value for
unusedSymbols
- Added targets to Source/Variable/CSS/lightningcss.ts

## 2.3.4

### Changed
Expand Down
41 changes: 41 additions & 0 deletions Configuration/ESBuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @module ESBuild
*
*/
export default {
color: true,
format: "esm",
logLevel: "debug",
metafile: true,
minify: true,
outdir: "Target",
platform: "node",
target: "esnext",
tsconfig: "tsconfig.json",
write: true,
plugins: [
{
name: "Target",
setup({ onStart, initialOptions: { outdir } }) {
onStart(async () => {
try {
outdir
? await (await import("fs/promises")).rm(outdir, {
recursive: true,
})
: {};
}
catch (_Error) {
console.log(_Error);
}
});
},
},
],
define: {
"process.env.VERSION_PACKAGE": `'${(await (await import("@playform/build/Target/Function/JSON.js")).default("package.json"))?.version}'`,
"process.env.TARGETS": JSON.stringify((await import("lightningcss")).browserslistToTargets(
// @ts-expect-error
(await import("browserslist")).default("defaults"))),
},
};
53 changes: 53 additions & 0 deletions Configuration/ESBuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { BuildOptions } from "esbuild";

/**
* @module ESBuild
*
*/
export default {
color: true,
format: "esm",
logLevel: "debug",
metafile: true,
minify: true,
outdir: "Target",
platform: "node",
target: "esnext",
tsconfig: "tsconfig.json",
write: true,
plugins: [
{
name: "Target",
setup({ onStart, initialOptions: { outdir } }) {
onStart(async () => {
try {
outdir
? await (
await import("fs/promises")
).rm(outdir, {
recursive: true,
})
: {};
} catch (_Error) {
console.log(_Error);
}
});
},
},
],
define: {
"process.env.VERSION_PACKAGE": `'${
(
await (
await import("@playform/build/Target/Function/JSON.js")
).default("package.json")
)?.version
}'`,
"process.env.TARGETS": JSON.stringify(
(await import("lightningcss")).browserslistToTargets(
// @ts-expect-error
(await import("browserslist")).default("defaults"),
),
),
},
} satisfies BuildOptions as BuildOptions;
66 changes: 39 additions & 27 deletions Source/Function/Integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,33 +107,45 @@ export default ((...[_Option = {}]) => {
case "CSS": {
let CSS = Buffer.toString();

// @ts-expect-error
if (Setting["lightningcss"]) {
CSS = (await import("lightningcss"))
.transform(
Merge(
{
code: (
await import(
"buffer"
)
).Buffer.from(CSS),
filename: Input,
},
// @ts-expect-error
Setting["lightningcss"],
),
try {
// @ts-expect-error
if (Setting["lightningcss"]) {
CSS = (
await import("lightningcss")
)
.code.toString();
}
.transform(
Merge(
{
code: (
await import(
"buffer"
)
).Buffer.from(
CSS,
),
filename: Input,
},
// @ts-expect-error
Setting[
"lightningcss"
],
),
)
.code.toString();
}

// @ts-expect-error
if (Setting["csso"]) {
CSS = (await import("csso")).minify(
CSS,
// @ts-expect-error
Setting["csso"],
).css;
// @ts-expect-error
if (Setting["csso"]) {
CSS = (
await import("csso")
).minify(
CSS,
// @ts-expect-error
Setting["csso"],
).css;
}
} catch (_Error) {
console.log(_Error);
}

return CSS;
Expand Down Expand Up @@ -207,8 +219,8 @@ export default ((...[_Option = {}]) => {
Fulfilled: async ({ File, Info: { Total } }) =>
File > 0
? `${(await import("kleur/colors")).green(
`✓ Successfully compressed a total of ${File} ${Type} ${
File === 1 ? "file" : "files"
`✓ Successfully compressed a total of ${File} ${Type} file${
File !== 1 ? "s" : ""
} for ${(
await import(
"@playform/pipe/Target/Function/Bytes.js"
Expand Down
4 changes: 2 additions & 2 deletions Source/Interface/CSS/lightningcss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default interface Interface
/**
* Whether to remove unused selectors or keywords.
*
* @default Compress false
* @default Compress []
* @default lightningcss undefined
*/
unusedSymbols?: string[] | boolean;
unusedSymbols?: string[];
}
3 changes: 3 additions & 0 deletions Source/Variable/CSS/lightningcss.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Targets } from "lightningcss";

import type Interface from "../../Interface/CSS/lightningcss.js";

/**
Expand All @@ -8,4 +10,5 @@ export default {
minify: true,
sourceMap: false,
unusedSymbols: [],
targets: process.env["TARGETS"] as Targets,
} satisfies Interface as Interface;
2 changes: 1 addition & 1 deletion Target/Function/Directory.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Target/Function/Image/Writesharp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Target/Function/Integration.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Target/Function/Merge.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var e=(await import("deepmerge-ts")).deepmergeCustom({mergeArrays:!1});export{e as default};
var r=(await import("deepmerge-ts")).deepmergeCustom({mergeArrays:!1});export{r as default};
4 changes: 2 additions & 2 deletions Target/Interface/CSS/lightningcss.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default interface Interface extends Omit<TransformOptions<CustomAtRules>,
/**
* Whether to remove unused selectors or keywords.
*
* @default Compress false
* @default Compress []
* @default lightningcss undefined
*/
unusedSymbols?: string[] | boolean;
unusedSymbols?: string[];
}
2 changes: 1 addition & 1 deletion Target/Type/Image/Filesharp.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const{default:e}=await import("../../Variable/Image/Mapsharp.js");export{e as _Map};
const{default:p}=await import("../../Variable/Image/Mapsharp.js");export{p as _Map};
2 changes: 1 addition & 1 deletion Target/Variable/CSS/csso.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var e={comments:!1,forceMediaMerge:!0,restructure:!1};export{e as default};
var r={comments:!1,forceMediaMerge:!0,restructure:!1};export{r as default};
2 changes: 1 addition & 1 deletion Target/Variable/CSS/lightningcss.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Target/Variable/HTML/html-minifier-terser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Target/Variable/Image/Mapsharp.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var e={avci:"avif",avcs:"avif",avifs:"avif",heic:"heif",heics:"heif",heifs:"heif",jfif:"jpeg",jif:"jpeg",jpe:"jpeg",apng:"png",jpg:"jpeg"};export{e as default};
var f={avci:"avif",avcs:"avif",avifs:"avif",heic:"heif",heics:"heif",heifs:"heif",jfif:"jpeg",jif:"jpeg",jpe:"jpeg",apng:"png",jpg:"jpeg"};export{f as default};
2 changes: 1 addition & 1 deletion Target/Variable/Image/sharp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Target/Variable/JavaScript/terser.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var e={ecma:5,enclose:!1,keep_classnames:!1,keep_fnames:!1,ie8:!1,module:!1,safari10:!1,toplevel:!1,format:{comments:!1}};export{e as default};
var s={ecma:5,enclose:!1,keep_classnames:!1,keep_fnames:!1,ie8:!1,module:!1,safari10:!1,toplevel:!1,format:{comments:!1}};export{s as default};
2 changes: 1 addition & 1 deletion Target/Variable/Map.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 378d888

Please sign in to comment.