@powerlines/plugin-image-compression 0.2.66 → 0.2.68

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.
@@ -1 +1,29 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));exports.__toESM=s;
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
package/dist/index.cjs CHANGED
@@ -1 +1,121 @@
1
- Object.defineProperty(exports,`__esModule`,{value:!0});const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./powerlines/src/plugin-utils/paths.cjs`);let n=require(`@stryke/convert/to-array`),r=require(`@stryke/fs/list-files`),i=require(`@stryke/fs/read-file`),a=require(`@stryke/fs/write-file`),o=require(`@stryke/path/find`),s=require(`@stryke/string-format/pretty-bytes`),c=require(`chalk`);c=e.__toESM(c);let l=require(`node:buffer`),u=require(`node:fs/promises`),d=require(`svgo`);const f=(e={})=>({name:`image-compression`,config(){return{imageCompression:{filter:`{projectRoot}/**/*.{svg,jpg,jpeg,png,webp,avif,heif,gif,tiff,jp2,jxl}`,svg:{},jpeg:{},png:{},webp:{},avif:{},heif:{},tiff:{},jp2:{},jxl:{},...e}}},async configResolved(){if(!this.config.imageCompression.filter)throw Error(`ImageCompression plugin requires a filter or glob pattern to be specified in the configuration.`);this.config.imageCompression.filter=(0,n.toArray)(this.config.imageCompression.filter).map(e=>t.replacePathTokens(this,e)).filter(Boolean)},async prepare(){await Promise.all((0,n.toArray)(this.config.imageCompression.filter).map(async e=>{await Promise.all((await(0,r.listFiles)(e)).map(async e=>{let n=this.config.imageCompression.outputPath?t.replacePathTokens(this,this.config.imageCompression.outputPath).replace(/\{fileName\}/g,e.split(`/`).pop()||`output`):e,r=performance.now(),f=(await(0,u.stat)(e)).size,p=0,m=(0,o.findFileExtensionSafe)(e).toLowerCase();if(!m){this.error(` Failed to optimize ${e} - Unable to determine file extension`);return}if(m===`svg`){let t=(0,d.optimize)(await(0,i.readFile)(e),{multipass:!0,path:e,...this.config.imageCompression.svg});t.data&&(p=l.Buffer.byteLength(t.data,`utf8`),await(0,a.writeFile)(n,t.data))}else{let t=await import(`sharp`).then(t=>t.default(e,{animated:m===`gif`}));switch(m){case`jpeg`:case`jpg`:t=t.jpeg(this.config.imageCompression.jpeg);break;case`png`:t=t.png(this.config.imageCompression.png);break;case`webp`:t=t.webp(this.config.imageCompression.webp);break;case`avif`:t=t.avif(this.config.imageCompression.avif);break;case`gif`:t=t.gif(this.config.imageCompression.gif);break;case`heif`:t=t.heif(this.config.imageCompression.heif);break;case`tiff`:t=t.tiff(this.config.imageCompression.tiff);break;case`jp2`:t=t.jp2(this.config.imageCompression.jp2);break;case`jxl`:t=t.jxl(this.config.imageCompression.jxl);break}p=(await t.toFile(n)).size}if(!p){this.error(` ✘ Failed to optimize ${e} - No data returned`);return}if(p>=f){this.error(` ✘ Failed to optimize ${e} - Compression output was not smaller than the original`);return}this.info(` ✔ Successfully optimized ${e}: ${c.default.redBright((0,s.prettyBytes)(f))} -> ${c.default.greenBright((0,s.prettyBytes)(p))} (${c.default.green((100-p/f*100).toFixed(2))}%) in ${(performance.now()-r).toFixed(2)} ms`)}))}))}});var p=f;exports.default=p,exports.plugin=f;
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
3
+ const require_paths = require('./powerlines/src/plugin-utils/paths.cjs');
4
+ let __stryke_convert_to_array = require("@stryke/convert/to-array");
5
+ let __stryke_fs_list_files = require("@stryke/fs/list-files");
6
+ let __stryke_fs_read_file = require("@stryke/fs/read-file");
7
+ let __stryke_fs_write_file = require("@stryke/fs/write-file");
8
+ let __stryke_path_find = require("@stryke/path/find");
9
+ let __stryke_string_format_pretty_bytes = require("@stryke/string-format/pretty-bytes");
10
+ let chalk = require("chalk");
11
+ chalk = require_rolldown_runtime.__toESM(chalk);
12
+ let node_buffer = require("node:buffer");
13
+ let node_fs_promises = require("node:fs/promises");
14
+ let svgo = require("svgo");
15
+
16
+ //#region src/index.ts
17
+ /**
18
+ * A Powerlines plugin to optimize image assets used by the project.
19
+ *
20
+ * @see https://sharp.pixelplumbing.com
21
+ *
22
+ * @param options - The plugin options.
23
+ * @returns A Powerlines plugin instance.
24
+ */
25
+ const plugin = (options = {}) => {
26
+ return {
27
+ name: "image-compression",
28
+ config() {
29
+ return { imageCompression: {
30
+ filter: "{projectRoot}/**/*.{svg,jpg,jpeg,png,webp,avif,heif,gif,tiff,jp2,jxl}",
31
+ svg: {},
32
+ jpeg: {},
33
+ png: {},
34
+ webp: {},
35
+ avif: {},
36
+ heif: {},
37
+ tiff: {},
38
+ jp2: {},
39
+ jxl: {},
40
+ ...options
41
+ } };
42
+ },
43
+ async configResolved() {
44
+ if (!this.config.imageCompression.filter) throw new Error("ImageCompression plugin requires a filter or glob pattern to be specified in the configuration.");
45
+ this.config.imageCompression.filter = (0, __stryke_convert_to_array.toArray)(this.config.imageCompression.filter).map((path) => require_paths.replacePathTokens(this, path)).filter(Boolean);
46
+ },
47
+ async prepare() {
48
+ await Promise.all((0, __stryke_convert_to_array.toArray)(this.config.imageCompression.filter).map(async (path) => {
49
+ await Promise.all((await (0, __stryke_fs_list_files.listFiles)(path)).map(async (file) => {
50
+ const outputPath = this.config.imageCompression.outputPath ? require_paths.replacePathTokens(this, this.config.imageCompression.outputPath).replace(/\{fileName\}/g, file.split("/").pop() || "output") : file;
51
+ const start = performance.now();
52
+ const originalSize = (await (0, node_fs_promises.stat)(file)).size;
53
+ let compressedSize = 0;
54
+ const extension = (0, __stryke_path_find.findFileExtensionSafe)(file).toLowerCase();
55
+ if (!extension) {
56
+ this.error(` ✘ Failed to optimize ${file} - Unable to determine file extension`);
57
+ return;
58
+ }
59
+ if (extension === "svg") {
60
+ const result = (0, svgo.optimize)(await (0, __stryke_fs_read_file.readFile)(file), {
61
+ multipass: true,
62
+ path: file,
63
+ ...this.config.imageCompression.svg
64
+ });
65
+ if (result.data) {
66
+ compressedSize = node_buffer.Buffer.byteLength(result.data, "utf8");
67
+ await (0, __stryke_fs_write_file.writeFile)(outputPath, result.data);
68
+ }
69
+ } else {
70
+ let image = await import("sharp").then((sharpModule) => sharpModule.default(file, { animated: extension === "gif" }));
71
+ switch (extension) {
72
+ case "jpeg":
73
+ case "jpg":
74
+ image = image.jpeg(this.config.imageCompression.jpeg);
75
+ break;
76
+ case "png":
77
+ image = image.png(this.config.imageCompression.png);
78
+ break;
79
+ case "webp":
80
+ image = image.webp(this.config.imageCompression.webp);
81
+ break;
82
+ case "avif":
83
+ image = image.avif(this.config.imageCompression.avif);
84
+ break;
85
+ case "gif":
86
+ image = image.gif(this.config.imageCompression.gif);
87
+ break;
88
+ case "heif":
89
+ image = image.heif(this.config.imageCompression.heif);
90
+ break;
91
+ case "tiff":
92
+ image = image.tiff(this.config.imageCompression.tiff);
93
+ break;
94
+ case "jp2":
95
+ image = image.jp2(this.config.imageCompression.jp2);
96
+ break;
97
+ case "jxl":
98
+ image = image.jxl(this.config.imageCompression.jxl);
99
+ break;
100
+ }
101
+ compressedSize = (await image.toFile(outputPath)).size;
102
+ }
103
+ if (!compressedSize) {
104
+ this.error(` ✘ Failed to optimize ${file} - No data returned`);
105
+ return;
106
+ }
107
+ if (compressedSize >= originalSize) {
108
+ this.error(` ✘ Failed to optimize ${file} - Compression output was not smaller than the original`);
109
+ return;
110
+ }
111
+ this.info(` ✔ Successfully optimized ${file}: ${chalk.default.redBright((0, __stryke_string_format_pretty_bytes.prettyBytes)(originalSize))} -> ${chalk.default.greenBright((0, __stryke_string_format_pretty_bytes.prettyBytes)(compressedSize))} (${chalk.default.green((100 - compressedSize / originalSize * 100).toFixed(2))}%) in ${(performance.now() - start).toFixed(2)} ms`);
112
+ }));
113
+ }));
114
+ }
115
+ };
116
+ };
117
+ var src_default = plugin;
118
+
119
+ //#endregion
120
+ exports.default = src_default;
121
+ exports.plugin = plugin;
package/dist/index.mjs CHANGED
@@ -1 +1,117 @@
1
- import{replacePathTokens as e}from"./powerlines/src/plugin-utils/paths.mjs";import{toArray as t}from"@stryke/convert/to-array";import{listFiles as n}from"@stryke/fs/list-files";import{readFile as r}from"@stryke/fs/read-file";import{writeFile as i}from"@stryke/fs/write-file";import{findFileExtensionSafe as a}from"@stryke/path/find";import{prettyBytes as o}from"@stryke/string-format/pretty-bytes";import s from"chalk";import{Buffer as c}from"node:buffer";import{stat as l}from"node:fs/promises";import{optimize as u}from"svgo";const d=(d={})=>({name:`image-compression`,config(){return{imageCompression:{filter:`{projectRoot}/**/*.{svg,jpg,jpeg,png,webp,avif,heif,gif,tiff,jp2,jxl}`,svg:{},jpeg:{},png:{},webp:{},avif:{},heif:{},tiff:{},jp2:{},jxl:{},...d}}},async configResolved(){if(!this.config.imageCompression.filter)throw Error(`ImageCompression plugin requires a filter or glob pattern to be specified in the configuration.`);this.config.imageCompression.filter=t(this.config.imageCompression.filter).map(t=>e(this,t)).filter(Boolean)},async prepare(){await Promise.all(t(this.config.imageCompression.filter).map(async t=>{await Promise.all((await n(t)).map(async t=>{let n=this.config.imageCompression.outputPath?e(this,this.config.imageCompression.outputPath).replace(/\{fileName\}/g,t.split(`/`).pop()||`output`):t,d=performance.now(),f=(await l(t)).size,p=0,m=a(t).toLowerCase();if(!m){this.error(` ✘ Failed to optimize ${t} - Unable to determine file extension`);return}if(m===`svg`){let e=u(await r(t),{multipass:!0,path:t,...this.config.imageCompression.svg});e.data&&(p=c.byteLength(e.data,`utf8`),await i(n,e.data))}else{let e=await import(`sharp`).then(e=>e.default(t,{animated:m===`gif`}));switch(m){case`jpeg`:case`jpg`:e=e.jpeg(this.config.imageCompression.jpeg);break;case`png`:e=e.png(this.config.imageCompression.png);break;case`webp`:e=e.webp(this.config.imageCompression.webp);break;case`avif`:e=e.avif(this.config.imageCompression.avif);break;case`gif`:e=e.gif(this.config.imageCompression.gif);break;case`heif`:e=e.heif(this.config.imageCompression.heif);break;case`tiff`:e=e.tiff(this.config.imageCompression.tiff);break;case`jp2`:e=e.jp2(this.config.imageCompression.jp2);break;case`jxl`:e=e.jxl(this.config.imageCompression.jxl);break}p=(await e.toFile(n)).size}if(!p){this.error(` ✘ Failed to optimize ${t} - No data returned`);return}if(p>=f){this.error(` ✘ Failed to optimize ${t} - Compression output was not smaller than the original`);return}this.info(` ✔ Successfully optimized ${t}: ${s.redBright(o(f))} -> ${s.greenBright(o(p))} (${s.green((100-p/f*100).toFixed(2))}%) in ${(performance.now()-d).toFixed(2)} ms`)}))}))}});var f=d;export{f as default,d as plugin};
1
+ import { replacePathTokens } from "./powerlines/src/plugin-utils/paths.mjs";
2
+ import { toArray } from "@stryke/convert/to-array";
3
+ import { listFiles } from "@stryke/fs/list-files";
4
+ import { readFile } from "@stryke/fs/read-file";
5
+ import { writeFile } from "@stryke/fs/write-file";
6
+ import { findFileExtensionSafe } from "@stryke/path/find";
7
+ import { prettyBytes } from "@stryke/string-format/pretty-bytes";
8
+ import chalk from "chalk";
9
+ import { Buffer } from "node:buffer";
10
+ import { stat } from "node:fs/promises";
11
+ import { optimize } from "svgo";
12
+
13
+ //#region src/index.ts
14
+ /**
15
+ * A Powerlines plugin to optimize image assets used by the project.
16
+ *
17
+ * @see https://sharp.pixelplumbing.com
18
+ *
19
+ * @param options - The plugin options.
20
+ * @returns A Powerlines plugin instance.
21
+ */
22
+ const plugin = (options = {}) => {
23
+ return {
24
+ name: "image-compression",
25
+ config() {
26
+ return { imageCompression: {
27
+ filter: "{projectRoot}/**/*.{svg,jpg,jpeg,png,webp,avif,heif,gif,tiff,jp2,jxl}",
28
+ svg: {},
29
+ jpeg: {},
30
+ png: {},
31
+ webp: {},
32
+ avif: {},
33
+ heif: {},
34
+ tiff: {},
35
+ jp2: {},
36
+ jxl: {},
37
+ ...options
38
+ } };
39
+ },
40
+ async configResolved() {
41
+ if (!this.config.imageCompression.filter) throw new Error("ImageCompression plugin requires a filter or glob pattern to be specified in the configuration.");
42
+ this.config.imageCompression.filter = toArray(this.config.imageCompression.filter).map((path) => replacePathTokens(this, path)).filter(Boolean);
43
+ },
44
+ async prepare() {
45
+ await Promise.all(toArray(this.config.imageCompression.filter).map(async (path) => {
46
+ await Promise.all((await listFiles(path)).map(async (file) => {
47
+ const outputPath = this.config.imageCompression.outputPath ? replacePathTokens(this, this.config.imageCompression.outputPath).replace(/\{fileName\}/g, file.split("/").pop() || "output") : file;
48
+ const start = performance.now();
49
+ const originalSize = (await stat(file)).size;
50
+ let compressedSize = 0;
51
+ const extension = findFileExtensionSafe(file).toLowerCase();
52
+ if (!extension) {
53
+ this.error(` ✘ Failed to optimize ${file} - Unable to determine file extension`);
54
+ return;
55
+ }
56
+ if (extension === "svg") {
57
+ const result = optimize(await readFile(file), {
58
+ multipass: true,
59
+ path: file,
60
+ ...this.config.imageCompression.svg
61
+ });
62
+ if (result.data) {
63
+ compressedSize = Buffer.byteLength(result.data, "utf8");
64
+ await writeFile(outputPath, result.data);
65
+ }
66
+ } else {
67
+ let image = await import("sharp").then((sharpModule) => sharpModule.default(file, { animated: extension === "gif" }));
68
+ switch (extension) {
69
+ case "jpeg":
70
+ case "jpg":
71
+ image = image.jpeg(this.config.imageCompression.jpeg);
72
+ break;
73
+ case "png":
74
+ image = image.png(this.config.imageCompression.png);
75
+ break;
76
+ case "webp":
77
+ image = image.webp(this.config.imageCompression.webp);
78
+ break;
79
+ case "avif":
80
+ image = image.avif(this.config.imageCompression.avif);
81
+ break;
82
+ case "gif":
83
+ image = image.gif(this.config.imageCompression.gif);
84
+ break;
85
+ case "heif":
86
+ image = image.heif(this.config.imageCompression.heif);
87
+ break;
88
+ case "tiff":
89
+ image = image.tiff(this.config.imageCompression.tiff);
90
+ break;
91
+ case "jp2":
92
+ image = image.jp2(this.config.imageCompression.jp2);
93
+ break;
94
+ case "jxl":
95
+ image = image.jxl(this.config.imageCompression.jxl);
96
+ break;
97
+ }
98
+ compressedSize = (await image.toFile(outputPath)).size;
99
+ }
100
+ if (!compressedSize) {
101
+ this.error(` ✘ Failed to optimize ${file} - No data returned`);
102
+ return;
103
+ }
104
+ if (compressedSize >= originalSize) {
105
+ this.error(` ✘ Failed to optimize ${file} - Compression output was not smaller than the original`);
106
+ return;
107
+ }
108
+ this.info(` ✔ Successfully optimized ${file}: ${chalk.redBright(prettyBytes(originalSize))} -> ${chalk.greenBright(prettyBytes(compressedSize))} (${chalk.green((100 - compressedSize / originalSize * 100).toFixed(2))}%) in ${(performance.now() - start).toFixed(2)} ms`);
109
+ }));
110
+ }));
111
+ }
112
+ };
113
+ };
114
+ var src_default = plugin;
115
+
116
+ //#endregion
117
+ export { src_default as default, plugin };
@@ -1 +1,36 @@
1
- const e=require(`../../../_virtual/rolldown_runtime.cjs`);let t=require(`@stryke/path/replace`);function n(e,n){return n&&n.replaceAll(`{workspaceRoot}`,e.workspaceConfig.workspaceRoot).replaceAll(`{root}`,e.config.projectRoot).replaceAll(`{projectRoot}`,e.config.projectRoot).replaceAll(`{sourceRoot}`,e.config.sourceRoot).replaceAll(`{powerlinesPath}`,e.powerlinesPath).replaceAll(`{cachePath}`,e.cachePath).replaceAll(`{dataPath}`,e.dataPath).replaceAll(`{logPath}`,e.envPaths.log).replaceAll(`{tempPath}`,e.envPaths.temp).replaceAll(`{configPath}`,e.envPaths.config).replaceAll(`{outputPath}`,e.config.output.outputPath).replaceAll(`{buildPath}`,e.config.output.buildPath).replaceAll(`{artifactsPath}`,(0,t.replacePath)(e.artifactsPath,e.workspaceConfig.workspaceRoot)).replaceAll(`{builtinPath}`,(0,t.replacePath)(e.builtinsPath,e.workspaceConfig.workspaceRoot)).replaceAll(`{entryPath}`,(0,t.replacePath)(e.entryPath,e.workspaceConfig.workspaceRoot))}exports.replacePathTokens=n;
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ let __stryke_path_replace = require("@stryke/path/replace");
3
+
4
+ //#region ../powerlines/src/plugin-utils/paths.ts
5
+ /**
6
+ * Replaces tokens in the given path string with their corresponding values from the context.
7
+ *
8
+ * @remarks
9
+ * The following tokens are supported:
10
+ * - `{workspaceRoot}` - The root directory of the workspace.
11
+ * - `{root}` - The root directory of the project (same as `{projectRoot}`).
12
+ * - `{projectRoot}` - The root directory of the project (same as `{root}`).
13
+ * - `{sourceRoot}` - The source root directory of the project (usually `./src`).
14
+ * - `{powerlinesPath}` - The directory where Powerlines is installed.
15
+ * - `{cachePath}` - The environment's directory for cached files.
16
+ * - `{dataPath}` - The environment's directory for data files.
17
+ * - `{logPath}` - The environment's directory for log files.
18
+ * - `{tempPath}` - The environment's directory for temporary files.
19
+ * - `{configPath}` - The environment's directory for configuration files.
20
+ * - `{outputPath}` - The configured output directory for the project.
21
+ * - `{buildPath}` - The configured distribution directory for the project.
22
+ * - `{artifactsPath}` - The configured directory for build artifacts.
23
+ * - `{builtinPath}` - The configured directory for generated built-in plugins.
24
+ * - `{entryPath}` - The configured directory for generated entry files.
25
+ *
26
+ * @param context - The context containing the values for the path tokens.
27
+ * @param path - The path string with tokens to replace.
28
+ * @returns The path string with tokens replaced by their corresponding values from the context.
29
+ */
30
+ function replacePathTokens(context, path) {
31
+ if (!path) return path;
32
+ return path.replaceAll("{workspaceRoot}", context.workspaceConfig.workspaceRoot).replaceAll("{root}", context.config.projectRoot).replaceAll("{projectRoot}", context.config.projectRoot).replaceAll("{sourceRoot}", context.config.sourceRoot).replaceAll("{powerlinesPath}", context.powerlinesPath).replaceAll("{cachePath}", context.cachePath).replaceAll("{dataPath}", context.dataPath).replaceAll("{logPath}", context.envPaths.log).replaceAll("{tempPath}", context.envPaths.temp).replaceAll("{configPath}", context.envPaths.config).replaceAll("{outputPath}", context.config.output.outputPath).replaceAll("{buildPath}", context.config.output.buildPath).replaceAll("{artifactsPath}", (0, __stryke_path_replace.replacePath)(context.artifactsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{builtinPath}", (0, __stryke_path_replace.replacePath)(context.builtinsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{entryPath}", (0, __stryke_path_replace.replacePath)(context.entryPath, context.workspaceConfig.workspaceRoot));
33
+ }
34
+
35
+ //#endregion
36
+ exports.replacePathTokens = replacePathTokens;
@@ -1 +1,35 @@
1
- import{replacePath as e}from"@stryke/path/replace";function t(t,n){return n&&n.replaceAll(`{workspaceRoot}`,t.workspaceConfig.workspaceRoot).replaceAll(`{root}`,t.config.projectRoot).replaceAll(`{projectRoot}`,t.config.projectRoot).replaceAll(`{sourceRoot}`,t.config.sourceRoot).replaceAll(`{powerlinesPath}`,t.powerlinesPath).replaceAll(`{cachePath}`,t.cachePath).replaceAll(`{dataPath}`,t.dataPath).replaceAll(`{logPath}`,t.envPaths.log).replaceAll(`{tempPath}`,t.envPaths.temp).replaceAll(`{configPath}`,t.envPaths.config).replaceAll(`{outputPath}`,t.config.output.outputPath).replaceAll(`{buildPath}`,t.config.output.buildPath).replaceAll(`{artifactsPath}`,e(t.artifactsPath,t.workspaceConfig.workspaceRoot)).replaceAll(`{builtinPath}`,e(t.builtinsPath,t.workspaceConfig.workspaceRoot)).replaceAll(`{entryPath}`,e(t.entryPath,t.workspaceConfig.workspaceRoot))}export{t as replacePathTokens};
1
+ import { replacePath } from "@stryke/path/replace";
2
+
3
+ //#region ../powerlines/src/plugin-utils/paths.ts
4
+ /**
5
+ * Replaces tokens in the given path string with their corresponding values from the context.
6
+ *
7
+ * @remarks
8
+ * The following tokens are supported:
9
+ * - `{workspaceRoot}` - The root directory of the workspace.
10
+ * - `{root}` - The root directory of the project (same as `{projectRoot}`).
11
+ * - `{projectRoot}` - The root directory of the project (same as `{root}`).
12
+ * - `{sourceRoot}` - The source root directory of the project (usually `./src`).
13
+ * - `{powerlinesPath}` - The directory where Powerlines is installed.
14
+ * - `{cachePath}` - The environment's directory for cached files.
15
+ * - `{dataPath}` - The environment's directory for data files.
16
+ * - `{logPath}` - The environment's directory for log files.
17
+ * - `{tempPath}` - The environment's directory for temporary files.
18
+ * - `{configPath}` - The environment's directory for configuration files.
19
+ * - `{outputPath}` - The configured output directory for the project.
20
+ * - `{buildPath}` - The configured distribution directory for the project.
21
+ * - `{artifactsPath}` - The configured directory for build artifacts.
22
+ * - `{builtinPath}` - The configured directory for generated built-in plugins.
23
+ * - `{entryPath}` - The configured directory for generated entry files.
24
+ *
25
+ * @param context - The context containing the values for the path tokens.
26
+ * @param path - The path string with tokens to replace.
27
+ * @returns The path string with tokens replaced by their corresponding values from the context.
28
+ */
29
+ function replacePathTokens(context, path) {
30
+ if (!path) return path;
31
+ return path.replaceAll("{workspaceRoot}", context.workspaceConfig.workspaceRoot).replaceAll("{root}", context.config.projectRoot).replaceAll("{projectRoot}", context.config.projectRoot).replaceAll("{sourceRoot}", context.config.sourceRoot).replaceAll("{powerlinesPath}", context.powerlinesPath).replaceAll("{cachePath}", context.cachePath).replaceAll("{dataPath}", context.dataPath).replaceAll("{logPath}", context.envPaths.log).replaceAll("{tempPath}", context.envPaths.temp).replaceAll("{configPath}", context.envPaths.config).replaceAll("{outputPath}", context.config.output.outputPath).replaceAll("{buildPath}", context.config.output.buildPath).replaceAll("{artifactsPath}", replacePath(context.artifactsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{builtinPath}", replacePath(context.builtinsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{entryPath}", replacePath(context.entryPath, context.workspaceConfig.workspaceRoot));
32
+ }
33
+
34
+ //#endregion
35
+ export { replacePathTokens };
@@ -78,10 +78,18 @@ interface ParseOptions extends ParserOptions {
78
78
  */
79
79
  allowReturnOutsideFunction?: boolean;
80
80
  }
81
+ interface EmitOptions extends WriteOptions {
82
+ /**
83
+ * If true, will emit the file using {@link UnpluginBuildContext.emitFile | the bundler's emit function}.
84
+ */
85
+ emitWithBundler?: boolean;
86
+ needsCodeReference?: Parameters<UnpluginBuildContext["emitFile"]>[0]["needsCodeReference"];
87
+ originalFileName?: Parameters<UnpluginBuildContext["emitFile"]>[0]["originalFileName"];
88
+ }
81
89
  /**
82
90
  * Options for emitting entry virtual files
83
91
  */
84
- type EmitEntryOptions = WriteOptions & Omit<ResolvedEntryTypeDefinition, "file">;
92
+ type EmitEntryOptions = EmitOptions & Omit<ResolvedEntryTypeDefinition, "file">;
85
93
  /**
86
94
  * The unresolved Powerlines context.
87
95
  *
@@ -292,6 +300,22 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
292
300
  * The Powerlines builtin virtual files
293
301
  */
294
302
  getBuiltins: () => Promise<VirtualFile[]>;
303
+ /**
304
+ * Resolves a file and writes it to the VFS if it does not already exist
305
+ *
306
+ * @param code - The source code of the file
307
+ * @param path - The path to write the file to
308
+ * @param options - Additional options for writing the file
309
+ */
310
+ emit: (code: string, path: string, options?: EmitOptions) => Promise<void>;
311
+ /**
312
+ * Synchronously resolves a file and writes it to the VFS if it does not already exist
313
+ *
314
+ * @param code - The source code of the file
315
+ * @param path - The path to write the file to
316
+ * @param options - Additional options for writing the file
317
+ */
318
+ emitSync: (code: string, path: string, options?: EmitOptions) => void;
295
319
  /**
296
320
  * Resolves a builtin virtual file and writes it to the VFS if it does not already exist
297
321
  *
@@ -300,7 +324,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
300
324
  * @param path - An optional path to write the builtin file to
301
325
  * @param options - Additional options for writing the builtin file
302
326
  */
303
- emitBuiltin: (code: string, id: string, path?: string, options?: WriteOptions) => Promise<void>;
327
+ emitBuiltin: (code: string, id: string, path?: string, options?: EmitOptions) => Promise<void>;
304
328
  /**
305
329
  * Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
306
330
  *
@@ -309,7 +333,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
309
333
  * @param path - An optional path to write the builtin file to
310
334
  * @param options - Additional options for writing the builtin file
311
335
  */
312
- emitBuiltinSync: (code: string, id: string, path?: string, options?: WriteOptions) => void;
336
+ emitBuiltinSync: (code: string, id: string, path?: string, options?: EmitOptions) => void;
313
337
  /**
314
338
  * Resolves a entry virtual file and writes it to the VFS if it does not already exist
315
339
  *
@@ -78,10 +78,18 @@ interface ParseOptions extends ParserOptions {
78
78
  */
79
79
  allowReturnOutsideFunction?: boolean;
80
80
  }
81
+ interface EmitOptions extends WriteOptions {
82
+ /**
83
+ * If true, will emit the file using {@link UnpluginBuildContext.emitFile | the bundler's emit function}.
84
+ */
85
+ emitWithBundler?: boolean;
86
+ needsCodeReference?: Parameters<UnpluginBuildContext["emitFile"]>[0]["needsCodeReference"];
87
+ originalFileName?: Parameters<UnpluginBuildContext["emitFile"]>[0]["originalFileName"];
88
+ }
81
89
  /**
82
90
  * Options for emitting entry virtual files
83
91
  */
84
- type EmitEntryOptions = WriteOptions & Omit<ResolvedEntryTypeDefinition, "file">;
92
+ type EmitEntryOptions = EmitOptions & Omit<ResolvedEntryTypeDefinition, "file">;
85
93
  /**
86
94
  * The unresolved Powerlines context.
87
95
  *
@@ -292,6 +300,22 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
292
300
  * The Powerlines builtin virtual files
293
301
  */
294
302
  getBuiltins: () => Promise<VirtualFile[]>;
303
+ /**
304
+ * Resolves a file and writes it to the VFS if it does not already exist
305
+ *
306
+ * @param code - The source code of the file
307
+ * @param path - The path to write the file to
308
+ * @param options - Additional options for writing the file
309
+ */
310
+ emit: (code: string, path: string, options?: EmitOptions) => Promise<void>;
311
+ /**
312
+ * Synchronously resolves a file and writes it to the VFS if it does not already exist
313
+ *
314
+ * @param code - The source code of the file
315
+ * @param path - The path to write the file to
316
+ * @param options - Additional options for writing the file
317
+ */
318
+ emitSync: (code: string, path: string, options?: EmitOptions) => void;
295
319
  /**
296
320
  * Resolves a builtin virtual file and writes it to the VFS if it does not already exist
297
321
  *
@@ -300,7 +324,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
300
324
  * @param path - An optional path to write the builtin file to
301
325
  * @param options - Additional options for writing the builtin file
302
326
  */
303
- emitBuiltin: (code: string, id: string, path?: string, options?: WriteOptions) => Promise<void>;
327
+ emitBuiltin: (code: string, id: string, path?: string, options?: EmitOptions) => Promise<void>;
304
328
  /**
305
329
  * Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
306
330
  *
@@ -309,7 +333,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
309
333
  * @param path - An optional path to write the builtin file to
310
334
  * @param options - Additional options for writing the builtin file
311
335
  */
312
- emitBuiltinSync: (code: string, id: string, path?: string, options?: WriteOptions) => void;
336
+ emitBuiltinSync: (code: string, id: string, path?: string, options?: EmitOptions) => void;
313
337
  /**
314
338
  * Resolves a entry virtual file and writes it to the VFS if it does not already exist
315
339
  *
@@ -1 +1 @@
1
- export{};
1
+ export { };
@@ -1 +1 @@
1
- export{};
1
+ export { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-image-compression",
3
- "version": "0.2.66",
3
+ "version": "0.2.68",
4
4
  "type": "module",
5
5
  "description": "A Powerlines plugin to optimize images used by the project.",
6
6
  "repository": {
@@ -123,22 +123,22 @@
123
123
  "powerlines-plugin"
124
124
  ],
125
125
  "dependencies": {
126
- "@stryke/path": "^0.24.0",
127
- "@stryke/fs": "^0.33.26",
128
- "@stryke/convert": "^0.6.29",
126
+ "@stryke/path": "^0.24.1",
127
+ "@stryke/fs": "^0.33.27",
128
+ "@stryke/convert": "^0.6.30",
129
129
  "chalk": "5.6.2",
130
130
  "defu": "^6.1.4",
131
131
  "jiti": "^2.6.1",
132
132
  "sharp": "^0.34.5",
133
133
  "svgo": "^4.0.0",
134
- "powerlines": "^0.36.22"
134
+ "powerlines": "^0.36.24"
135
135
  },
136
136
  "devDependencies": {
137
- "@storm-software/config": "^1.134.74",
138
- "@powerlines/nx": "^0.11.48",
139
- "@powerlines/plugin-plugin": "^0.12.69",
137
+ "@storm-software/config": "^1.134.75",
138
+ "@powerlines/nx": "^0.11.50",
139
+ "@powerlines/plugin-plugin": "^0.12.71",
140
140
  "@types/node": "^24.10.4"
141
141
  },
142
142
  "publishConfig": { "access": "public" },
143
- "gitHead": "f88fe8eb30f96536b83fc9af884972d48e31e63a"
143
+ "gitHead": "4b695d4b3476fd9dd79521f92258d52dab2b8d72"
144
144
  }