@moneko/core 3.55.5 → 3.55.6

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.
@@ -6,6 +6,7 @@ export interface CompressionPluginOptions {
6
6
  }
7
7
  export declare class CompressionPlugin {
8
8
  private name;
9
+ private worker;
9
10
  private options;
10
11
  constructor(options: CompressionPluginOptions);
11
12
  private runCompressionAlgorithm;
@@ -1 +1 @@
1
- import{compression as e}from"@moneko/utils";export class CompressionPlugin{constructor(e){this.name="CompressionPlugin";let{test:s,algorithm:t="brotli"}=e||{};this.options={test:s,algorithm:t,filename:`[path][base].${"brotli"===t?"br":"gz"}`}}runCompressionAlgorithm(s){return Buffer.from(e(Buffer.isBuffer(s)?Array.from(s):s,this.options.algorithm))}async compress(e,s,t){let o=s.getCache(this.name),{RawSource:i}=e.webpack.sources;await Promise.allSettled(Object.keys(t).map(async t=>{let r,a="gzip"===this.options.algorithm?"gzipped":`${this.options.algorithm}ed`,{info:m,source:n}=s.getAsset(t);if(m.compressed||!e.webpack.ModuleFilenameHelpers.matchObject.bind(void 0,this.options)(t)||m.related&&m.related[a])return!1;let p=o.getItemCache(JSON.stringify(`${t}${this.options.algorithm}`),o.getLazyHashedEtag(n)),l=await p.getPromise()||{};if(!l.source){if("function"==typeof n.buffer)r=n.buffer();else{let e=n.source();r=Buffer.isBuffer(e)?e:Buffer.from(e)}if(!l.compressed&&r)try{l.compressed=this.runCompressionAlgorithm(r)}catch(e){s.errors.push(e);return}l.compressed&&(l.source=new i(l.compressed)),await p.storePromise(l)}let f=s.getPath(this.options.filename,{filename:t}),c={compressed:!0};m.immutable&&/(\[name]|\[base]|\[file])/.test(this.options.filename)&&(c.immutable=!0),s.updateAsset(t,n,{related:{[a]:f}}),s.emitAsset(f,l.source,c)}))}apply(e){let s=this.name;e.hooks.thisCompilation.tap(s,t=>{t.hooks.processAssets.tapPromise({name:s,stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER,additionalAssets:!0},s=>this.compress(e,t,s))})}}
1
+ import{fileURLToPath as e}from"node:url";import{Worker as s}from"node:worker_threads";export class CompressionPlugin{constructor(t){this.name="CompressionPlugin";let{test:o,algorithm:r="brotli"}=t||{};this.options={test:o,algorithm:r,filename:`[path][base].${"brotli"===r?"br":"gz"}`},this.worker=new s(e(new URL("../worker/compression.mjs",import.meta.url))),this.worker.setMaxListeners(0)}async runCompressionAlgorithm(e,s){return new Promise(t=>{this.worker.postMessage({input:e,filename:s,algorithm:this.options.algorithm}),this.worker.addListener("message",e=>{e[0]===s&&t(Buffer.from(e[1]))})})}async compress(e,s,t){this.worker.removeAllListeners("message");let o=s.getCache(this.name),{RawSource:r}=e.webpack.sources;await Promise.allSettled(Object.keys(t).map(async t=>{let i,a="gzip"===this.options.algorithm?"gzipped":`${this.options.algorithm}ed`,{info:m,source:n}=s.getAsset(t);if(m.compressed||!e.webpack.ModuleFilenameHelpers.matchObject.bind(void 0,this.options)(t)||m.related&&m.related[a])return!1;let p=o.getItemCache(JSON.stringify(`${t}${this.options.algorithm}`),o.getLazyHashedEtag(n)),l=await p.getPromise()||{};if(!l.source){if("function"==typeof n.buffer)i=n.buffer();else{let e=n.source();i=Buffer.isBuffer(e)?e:Buffer.from(e)}if(!l.compressed&&i)try{l.compressed=await this.runCompressionAlgorithm(i,t)}catch(e){s.errors.push(e);return}l.compressed&&(l.source=new r(l.compressed)),await p.storePromise(l)}let h=s.getPath(this.options.filename,{filename:t}),c={compressed:!0};m.immutable&&/(\[name]|\[base]|\[file])/.test(this.options.filename)&&(c.immutable=!0),s.updateAsset(t,n,{related:{[a]:h}}),s.emitAsset(h,l.source,c)}))}apply(e){let s=this.name;e.hooks.thisCompilation.tap(s,t=>{t.hooks.processAssets.tapPromise({name:s,stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER,additionalAssets:!0},s=>this.compress(e,t,s))}),"development"!==e.options.mode&&e.hooks.done.tap(this.name,()=>{this.worker.terminate()})}}
@@ -1 +1 @@
1
- import{fileURLToPath as t}from"node:url";import{Worker as e}from"node:worker_threads";import s from"webpack";class o extends s.WebpackError{constructor(t){super(`[ESLint] ${t}`),this.name="ESLintError",this.stack=""}}export class ESLintPlugin{constructor(s={files:[]}){this.name="ESLintPlugin",this.options=s,this.worker=new e(t(new URL("../worker/eslint.mjs",import.meta.url))),this.worker.setMaxListeners(0)}apply(t){t.hooks.thisCompilation.tap(this.name,e=>{let s=t.modifiedFiles||new Set;e.hooks.finishModules.tap(this.name,t=>{let o=this.options;if(this.options?.lintDirtyModulesOnly){let e=[];for(let o of t){let t=o.resource;s.has(t)&&e.push(t)}o.files=e}this.worker.postMessage({options:o}),this.worker.once("message",t=>{this.report(e,t)})})}),t.hooks.shutdown.tap(this.name,()=>{this.worker.terminate()})}report(t,e){e?.length&&t&&(e[0]?.length&&t.warnings.push(new o(e[0])),e[1]?.length&&t.errors.push(new o(e[1])))}}
1
+ import{fileURLToPath as e}from"node:url";import{Worker as t}from"node:worker_threads";import s from"webpack";class o extends s.WebpackError{constructor(e){super(`[ESLint] ${e}`),this.name="ESLintError",this.stack=""}}export class ESLintPlugin{constructor(s={files:[]}){this.name="ESLintPlugin",this.options=s,this.worker=new t(e(new URL("../worker/eslint.mjs",import.meta.url))),this.worker.setMaxListeners(0)}apply(e){e.hooks.thisCompilation.tap(this.name,t=>{let s=e.modifiedFiles||new Set;t.hooks.finishModules.tap(this.name,e=>{let o=this.options;if(this.options?.lintDirtyModulesOnly){let t=[];for(let o of e){let e=o.resource;s.has(e)&&t.push(e)}o.files=t}let r=e=>{this.report(t,e)};this.worker.off("message",r),this.worker.postMessage({options:o}),this.worker.on("message",r)})}),"development"!==e.options.mode&&e.hooks.done.tap(this.name,()=>{this.worker.terminate()})}report(e,t){t?.length&&e&&(t[0]?.length&&e.warnings.push(new o(t[0])),t[1]?.length&&e.errors.push(new o(t[1])))}}
@@ -1 +1 @@
1
- import{fileURLToPath as t}from"node:url";import{Worker as e}from"node:worker_threads";import r from"webpack";class s extends r.WebpackError{constructor(t){super(`[Stylelint] ${t}`),this.name="StylelintError",this.stack=""}}export class StylelintPlugin{constructor(r={files:[]}){this.name="StylelintPlugin",this.options=r,this.worker=new e(t(new URL("../worker/stylelint.mjs",import.meta.url))),this.worker.setMaxListeners(0)}apply(t){t.hooks.thisCompilation.tap(this.name,t=>{this.worker.postMessage({options:this.options}),this.worker.once("message",e=>{this.report(e,t)})}),t.hooks.shutdown.tap(this.name,()=>{this.worker.terminate()})}report(t,e){t?.length&&e&&(t[0]?.length&&e.warnings.push(new s(t[0])),t[1]?.length&&e.errors.push(new s(t[1])))}}
1
+ import{fileURLToPath as t}from"node:url";import{Worker as e}from"node:worker_threads";import r from"webpack";class s extends r.WebpackError{constructor(t){super(`[Stylelint] ${t}`),this.name="StylelintError",this.stack=""}}export class StylelintPlugin{constructor(r={files:[]}){this.name="StylelintPlugin",this.options=r,this.worker=new e(t(new URL("../worker/stylelint.mjs",import.meta.url))),this.worker.setMaxListeners(0)}apply(t){t.hooks.thisCompilation.tap(this.name,t=>{let e=e=>{this.report(e,t)};this.worker.off("message",e),this.worker.postMessage({options:this.options}),this.worker.on("message",e)}),"development"!==t.options.mode&&t.hooks.done.tap(this.name,()=>{this.worker.terminate()})}report(t,e){t?.length&&e&&(t[0]?.length&&e.warnings.push(new s(t[0])),t[1]?.length&&e.errors.push(new s(t[1])))}}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ import{isUint8Array as e}from"node:util/types";import{parentPort as r}from"node:worker_threads";import{compression as o}from"@moneko/utils";r?.setMaxListeners(0),r?.on("message",async({input:s,filename:t,algorithm:m})=>{let f=o(Buffer.isBuffer(s)||e(s)?Array.from(s):s,m);r?.postMessage([t,f])});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.55.5",
3
+ "version": "3.55.6",
4
4
  "description": "core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",