weboptimizer 4.0.36 → 4.0.38

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.
@@ -4,5 +4,5 @@
4
4
  * @returns A promise holding a boolean which indicates directory existence.
5
5
  */
6
6
  export declare const isFile: (filePath: string) => Promise<boolean>;
7
- export declare const config: import("eslint/config").Config[];
7
+ export declare const config: import("eslint/config").ConfigObject[];
8
8
  export default config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weboptimizer",
3
- "version": "4.0.36",
3
+ "version": "4.0.38",
4
4
  "description": "A generic web optimizer, (module) bundler and development environment.",
5
5
  "keywords": [
6
6
  "webpack",
@@ -94,7 +94,7 @@
94
94
  "babel-loader": "^10.1.1",
95
95
  "babel-plugin-polyfill-corejs3": "^1.0.0",
96
96
  "babel-plugin-transform-rewrite-imports": "^1.5.4",
97
- "clientnode": "4.0.1467",
97
+ "clientnode": "4.0.1472",
98
98
  "core-js": "^3.49.0",
99
99
  "ejs": "^6.0.1",
100
100
  "exports-loader": "^5.0.0",
@@ -102,7 +102,7 @@
102
102
  "glob-all": "^3.3.1",
103
103
  "html-loader": "^5.1.0",
104
104
  "html-minifier": "^4.0.0",
105
- "html-webpack-plugin": "^5.6.7",
105
+ "html-webpack-plugin": "^5.6.8",
106
106
  "imports-loader": "^5.0.0",
107
107
  "jest-environment-jsdom": "^30.4.1",
108
108
  "rimraf": "^6.1.3",
@@ -130,7 +130,7 @@
130
130
  "@typescript-eslint/parser": "^8.65.0",
131
131
  "css-loader": "^7.1.4",
132
132
  "cssnano": "^8.0.2",
133
- "eslint": "^10.7.0",
133
+ "eslint": "^10.8.0",
134
134
  "eslint-config-google": "^0.14.0",
135
135
  "eslint-plugin-jsdoc": "^63.2.2",
136
136
  "favicons": "^7.3.1",
@@ -142,7 +142,7 @@
142
142
  "mini-css-extract-plugin": "^2.10.2",
143
143
  "mkdirp": "^3.0.1",
144
144
  "node-fetch": "^3.3.2",
145
- "postcss": "^8.5.22",
145
+ "postcss": "^8.5.23",
146
146
  "postcss-fontpath": "^1.0.0",
147
147
  "postcss-import": "^16.1.1",
148
148
  "postcss-loader": "^8.2.1",
package/type.d.ts CHANGED
@@ -403,7 +403,8 @@ export interface WebpackConfiguration extends BaseWebpackConfiguration {
403
403
  devServer: Mapping<unknown>;
404
404
  replaceWebOptimizer: WebpackConfiguration;
405
405
  }
406
- export type RuleSet = Array<WebpackRuleSetUseItem>;
406
+ export type RuleSetItem = WebpackRuleSetUseItem;
407
+ export type RuleSet = Array<RuleSetItem>;
407
408
  export type RuleSetRule = WebpackRuleSetRule & {
408
409
  use: RuleSet;
409
410
  };
@@ -82,12 +82,19 @@ const {
82
82
  // region initialization
83
83
  /// region determine library name
84
84
  const exportFormatsNeedingAValidVariableName = ['assign', 'global', 'this', 'var', 'window'];
85
+ const exportFormatsNeedingUnsetLibraryName = ['modern-module'];
85
86
  let libraryName;
86
- if (configuration.libraryName) libraryName = configuration.libraryName;else if (Object.keys(configuration.injection.entry.normalized).length > 1) libraryName = '[name]';else {
87
- libraryName = configuration.name;
88
- if (exportFormatsNeedingAValidVariableName.includes(configuration.exportFormat.self)) libraryName = convertToValidVariableName(libraryName);
87
+ if (!exportFormatsNeedingUnsetLibraryName.includes(configuration.exportFormat.self)) {
88
+ if (configuration.libraryName) libraryName = configuration.libraryName;else if (Object.keys(configuration.injection.entry.normalized).length > 1) libraryName = '[name]';else {
89
+ libraryName = configuration.name;
90
+ if (exportFormatsNeedingAValidVariableName.includes(configuration.exportFormat.self)) libraryName = convertToValidVariableName(libraryName);
91
+ }
92
+ if (libraryName === '*') libraryName = exportFormatsNeedingAValidVariableName.includes(configuration.exportFormat.self) ? Object.keys(configuration.injection.entry.normalized).map(name => convertToValidVariableName(name)) : undefined;
89
93
  }
90
- if (libraryName === '*') libraryName = exportFormatsNeedingAValidVariableName.includes(configuration.exportFormat.self) ? Object.keys(configuration.injection.entry.normalized).map(name => convertToValidVariableName(name)) : undefined;
94
+ console.log();
95
+ console.log('TODO', libraryName, configuration.exportFormat.self);
96
+ console.log();
97
+
91
98
  /// endregion
92
99
  /// region plugins
93
100
  const pluginInstances = [];
@@ -364,7 +371,7 @@ const scope = {
364
371
  isFilePathInDependencies,
365
372
  loader
366
373
  };
367
- const evaluateAndThrow = (object, givenOptions = {}) => {
374
+ const evaluateOrThrowOnError = (object, givenOptions = {}) => {
368
375
  const options = {
369
376
  filePath: configuration.path.context,
370
377
  ...givenOptions
@@ -380,23 +387,23 @@ const evaluateAndThrow = (object, givenOptions = {}) => {
380
387
  }
381
388
  return object;
382
389
  };
383
- const createEvaluateMapper = type => value => evaluateAndThrow(value, {
390
+ const createEvaluateMapper = type => value => evaluateOrThrowOnError(value, {
384
391
  type
385
392
  });
386
393
  const evaluateAdditionalLoaderConfiguration = loaderConfiguration => ({
387
- exclude: filePath => evaluateAndThrow(loaderConfiguration.exclude, {
394
+ exclude: filePath => evaluateOrThrowOnError(loaderConfiguration.exclude, {
388
395
  filePath
389
396
  }),
390
- include: loaderConfiguration.include && evaluateAndThrow(loaderConfiguration.include) || configuration.path.source.base,
391
- test: new RegExp(evaluateAndThrow(loaderConfiguration.test)),
392
- use: evaluateAndThrow(loaderConfiguration.use)
397
+ include: loaderConfiguration.include && evaluateOrThrowOnError(loaderConfiguration.include) || configuration.path.source.base,
398
+ test: new RegExp(evaluateOrThrowOnError(loaderConfiguration.test)),
399
+ use: evaluateOrThrowOnError(loaderConfiguration.use)
393
400
  });
394
401
  const getIncludingPaths = path => normalizePaths([path].concat(module.locations.directoryPaths));
395
402
  const postCSSResolver = (name, _context) => {
396
403
  for (const [source, target] of Object.entries(configuration.module.aliases)) if (source.startsWith(name)) return target;
397
404
  return name;
398
405
  };
399
- const cssUse = module.preprocessor.cascadingStyleSheet.additional.pre.map(createEvaluateMapper('css')).concat({
406
+ const cssUse = (await Promise.all(module.preprocessor.cascadingStyleSheet.additional.pre.map(createEvaluateMapper('css')))).concat({
400
407
  loader: module.style.loader,
401
408
  options: module.style.options || {}
402
409
  }, {
@@ -414,7 +421,7 @@ const cssUse = module.preprocessor.cascadingStyleSheet.additional.pre.map(create
414
421
  plugins: [].concat(postcssImport ? postcssImport({
415
422
  root: configuration.path.context,
416
423
  resolve: postCSSResolver
417
- }) : [], module.preprocessor.cascadingStyleSheet.additional.plugins.pre.map(createEvaluateMapper('css.postcss')),
424
+ }) : [], await Promise.all(module.preprocessor.cascadingStyleSheet.additional.plugins.pre.map(createEvaluateMapper('css.postcss'))),
418
425
  /*
419
426
  NOTE: Checking path doesn't work if fonts
420
427
  are referenced in libraries provided in
@@ -454,37 +461,37 @@ const cssUse = module.preprocessor.cascadingStyleSheet.additional.pre.map(create
454
461
  stylesheetPath: configuration.path.source.asset.cascadingStyleSheet,
455
462
  spritePath: configuration.path.source.asset.image,
456
463
  ...configuration.imageSprite
457
- }) : [], module.preprocessor.cascadingStyleSheet.additional.plugins.post.map(createEvaluateMapper('css.postcss')), module.optimizer.cssnano && postcssCSSnano ? postcssCSSnano(module.optimizer.cssnano) : [])
464
+ }) : [], await Promise.all(module.preprocessor.cascadingStyleSheet.additional.plugins.post.map(createEvaluateMapper('css.postcss'))), module.optimizer.cssnano && postcssCSSnano ? postcssCSSnano(module.optimizer.cssnano) : [])
458
465
  }
459
466
  } : {}, module.preprocessor.cascadingStyleSheet.options || {})
460
- } : [], module.preprocessor.cascadingStyleSheet.additional.post.map(createEvaluateMapper('css')));
467
+ } : [], await Promise.all(module.preprocessor.cascadingStyleSheet.additional.post.map(createEvaluateMapper('css'))));
461
468
  const genericLoader = {
462
469
  // Convert to compatible native web types.
463
470
  // region generic template
464
471
  ejs: {
465
- exclude: filePath => normalizePaths(configuration.files.html.concat(configuration.files.defaultHTML).map(htmlConfiguration => htmlConfiguration.template.filePath)).includes(filePath) || module.preprocessor.ejs.exclude === null ? false : evaluateAndThrow(module.preprocessor.ejs.exclude, {
472
+ exclude: filePath => normalizePaths(configuration.files.html.concat(configuration.files.defaultHTML).map(htmlConfiguration => htmlConfiguration.template.filePath)).includes(filePath) || module.preprocessor.ejs.exclude === null ? false : evaluateOrThrowOnError(module.preprocessor.ejs.exclude, {
466
473
  filePath
467
474
  }),
468
475
  include: getIncludingPaths(configuration.path.source.asset.template),
469
476
  test: /^(?!.+\.html\.ejs$).+\.ejs$/i,
470
- use: module.preprocessor.ejs.additional.pre.map(createEvaluateMapper('ejs')).concat({
477
+ use: (await Promise.all(module.preprocessor.ejs.additional.pre.map(createEvaluateMapper('ejs')))).concat({
471
478
  loader: module.preprocessor.ejs.loader,
472
479
  options: extend(true, module.preprocessor.ejs.options || {}, {
473
480
  compress: {
474
481
  html: false
475
482
  }
476
483
  })
477
- }, module.preprocessor.ejs.additional.post.map(createEvaluateMapper('ejs')))
484
+ }, await Promise.all(module.preprocessor.ejs.additional.post.map(createEvaluateMapper('ejs'))))
478
485
  },
479
486
  // endregion
480
487
  // region script
481
488
  script: {
482
- exclude: filePath => evaluateAndThrow(module.preprocessor.javaScript.exclude, {
489
+ exclude: filePath => evaluateOrThrowOnError(module.preprocessor.javaScript.exclude, {
483
490
  filePath,
484
491
  type: 'script'
485
492
  }),
486
493
  include: filePath => {
487
- const result = evaluateAndThrow(module.preprocessor.javaScript.include, {
494
+ const result = evaluateOrThrowOnError(module.preprocessor.javaScript.include, {
488
495
  filePath,
489
496
  type: 'script'
490
497
  });
@@ -495,10 +502,10 @@ const genericLoader = {
495
502
  return Boolean(result);
496
503
  },
497
504
  test: new RegExp(module.preprocessor.javaScript.regularExpression, 'i'),
498
- use: module.preprocessor.javaScript.additional.pre.map(createEvaluateMapper('script')).concat({
505
+ use: (await Promise.all(module.preprocessor.javaScript.additional.pre.map(createEvaluateMapper('script')))).concat({
499
506
  loader: module.preprocessor.javaScript.loader,
500
507
  options: module.preprocessor.javaScript.options || {}
501
- }, module.preprocessor.javaScript.additional.post.map(createEvaluateMapper('script')))
508
+ }, await Promise.all(module.preprocessor.javaScript.additional.post.map(createEvaluateMapper('script'))))
502
509
  },
503
510
  // endregion
504
511
  // region HTML template
@@ -509,16 +516,16 @@ const genericLoader = {
509
516
  use: configuration.files.defaultHTML.template.use
510
517
  },
511
518
  ejs: {
512
- exclude: filePath => normalizePaths(configuration.files.html.concat(configuration.files.defaultHTML).map(htmlConfiguration => htmlConfiguration.template.filePath)).includes(filePath) || (module.preprocessor.html.exclude === null ? false : evaluateAndThrow(module.preprocessor.html.exclude, {
519
+ exclude: filePath => normalizePaths(configuration.files.html.concat(configuration.files.defaultHTML).map(htmlConfiguration => htmlConfiguration.template.filePath)).includes(filePath) || (module.preprocessor.html.exclude === null ? false : evaluateOrThrowOnError(module.preprocessor.html.exclude, {
513
520
  filePath,
514
521
  type: 'html.ejs'
515
522
  })),
516
523
  include: configuration.path.source.asset.template,
517
524
  test: /\.html\.ejs(?:\?.*)?$/i,
518
- use: module.preprocessor.html.additional.pre.map(createEvaluateMapper('html.ejs')).concat(
525
+ use: (await Promise.all(module.preprocessor.html.additional.pre.map(createEvaluateMapper('html.ejs')))).concat(
519
526
  /*
520
527
  We might need to evaluate ejs before we are able to
521
- parse html beforhand. If not we parse it as html
528
+ parse html beforehand. If not we parse it as html
522
529
  directly.
523
530
  */
524
531
 
@@ -532,35 +539,35 @@ const genericLoader = {
532
539
  }], {
533
540
  loader: module.preprocessor.html.loader,
534
541
  options: module.preprocessor.html.options || {}
535
- }, module.preprocessor.html.additional.post.map(createEvaluateMapper('html.ejs')))
542
+ }, await Promise.all(module.preprocessor.html.additional.post.map(createEvaluateMapper('html.ejs'))))
536
543
  },
537
544
  html: {
538
- exclude: filePath => normalizePaths(configuration.files.html.concat(configuration.files.defaultHTML).map(htmlConfiguration => htmlConfiguration.template.filePath)).includes(filePath) || (module.html.exclude === null ? true : evaluateAndThrow(module.html.exclude, {
545
+ exclude: filePath => normalizePaths(configuration.files.html.concat(configuration.files.defaultHTML).map(htmlConfiguration => htmlConfiguration.template.filePath)).includes(filePath) || (module.html.exclude === null ? true : evaluateOrThrowOnError(module.html.exclude, {
539
546
  filePath,
540
547
  type: 'html'
541
548
  })),
542
549
  include: configuration.path.source.asset.template,
543
550
  test: /\.html(?:\?.*)?$/i,
544
- use: module.html.additional.pre.map(createEvaluateMapper('html')).concat({
551
+ use: (await Promise.all(module.html.additional.pre.map(createEvaluateMapper('html')))).concat({
545
552
  loader: 'file?name=' + join(relative(configuration.path.target.base, configuration.path.target.asset.template), `[name][ext]?${configuration.hashAlgorithm}=` + '[contenthash]')
546
553
  }, {
547
554
  loader: 'extract'
548
555
  }, {
549
556
  loader: module.html.loader,
550
557
  options: module.html.options || {}
551
- }, module.html.additional.post.map(createEvaluateMapper('html')))
558
+ }, await Promise.all(module.html.additional.post.map(createEvaluateMapper('html'))))
552
559
  }
553
560
  },
554
561
  // endregion
555
562
  // Load dependencies.
556
563
  // region style
557
564
  style: {
558
- exclude: filePath => module.cascadingStyleSheet.exclude === null ? isFilePathInDependencies(filePath) : evaluateAndThrow(module.cascadingStyleSheet.exclude, {
565
+ exclude: filePath => module.cascadingStyleSheet.exclude === null ? isFilePathInDependencies(filePath) : evaluateOrThrowOnError(module.cascadingStyleSheet.exclude, {
559
566
  filePath,
560
567
  type: 'style'
561
568
  }),
562
569
  include: filePath => {
563
- const result = evaluateAndThrow(module.cascadingStyleSheet.include, {
570
+ const result = evaluateOrThrowOnError(module.cascadingStyleSheet.include, {
564
571
  filePath,
565
572
  type: 'style'
566
573
  });
@@ -578,7 +585,7 @@ const genericLoader = {
578
585
  // region font
579
586
  font: {
580
587
  eot: {
581
- exclude: filePath => module.optimizer.font.eot.exclude === null ? false : evaluateAndThrow(module.optimizer.font.eot.exclude, {
588
+ exclude: filePath => module.optimizer.font.eot.exclude === null ? false : evaluateOrThrowOnError(module.optimizer.font.eot.exclude, {
582
589
  filePath,
583
590
  type: 'font.eot'
584
591
  }),
@@ -592,10 +599,10 @@ const genericLoader = {
592
599
  maxSize: configuration.inPlace.otherMaximumFileSizeLimitInByte
593
600
  }
594
601
  },
595
- use: module.optimizer.font.eot.loader.map(createEvaluateMapper('font.eot'))
602
+ use: await Promise.all(module.optimizer.font.eot.loader.map(createEvaluateMapper('font.eot')))
596
603
  },
597
604
  svg: {
598
- exclude: filePath => module.optimizer.font.svg.exclude === null ? false : evaluateAndThrow(module.optimizer.font.svg.exclude, {
605
+ exclude: filePath => module.optimizer.font.svg.exclude === null ? false : evaluateOrThrowOnError(module.optimizer.font.svg.exclude, {
599
606
  filePath,
600
607
  type: 'svg'
601
608
  }),
@@ -611,10 +618,10 @@ const genericLoader = {
611
618
  },
612
619
  test: /\.svg(?: \?.*)?$/i,
613
620
  type: 'asset/resource',
614
- use: module.optimizer.font.svg.loader.map(createEvaluateMapper('font.svg'))
621
+ use: await Promise.all(module.optimizer.font.svg.loader.map(createEvaluateMapper('font.svg')))
615
622
  },
616
623
  ttf: {
617
- exclude: filePath => module.optimizer.font.ttf.exclude === null ? false : evaluateAndThrow(module.optimizer.font.ttf.exclude, {
624
+ exclude: filePath => module.optimizer.font.ttf.exclude === null ? false : evaluateOrThrowOnError(module.optimizer.font.ttf.exclude, {
618
625
  filePath,
619
626
  type: 'ttf'
620
627
  }),
@@ -629,10 +636,10 @@ const genericLoader = {
629
636
  maxSize: configuration.inPlace.otherMaximumFileSizeLimitInByte
630
637
  }
631
638
  },
632
- use: module.optimizer.font.ttf.loader.map(createEvaluateMapper('font.ttf'))
639
+ use: await Promise.all(module.optimizer.font.ttf.loader.map(createEvaluateMapper('font.ttf')))
633
640
  },
634
641
  woff: {
635
- exclude: filePath => module.optimizer.font.woff.exclude === null ? false : evaluateAndThrow(module.optimizer.font.woff.exclude, {
642
+ exclude: filePath => module.optimizer.font.woff.exclude === null ? false : evaluateOrThrowOnError(module.optimizer.font.woff.exclude, {
636
643
  filePath,
637
644
  type: 'woff'
638
645
  }),
@@ -646,13 +653,13 @@ const genericLoader = {
646
653
  maxSize: configuration.inPlace.otherMaximumFileSizeLimitInByte
647
654
  }
648
655
  },
649
- use: module.optimizer.font.woff.loader.map(createEvaluateMapper('font.woff'))
656
+ use: await Promise.all(module.optimizer.font.woff.loader.map(createEvaluateMapper('font.woff')))
650
657
  }
651
658
  },
652
659
  // endregion
653
660
  // region image
654
661
  image: {
655
- exclude: filePath => module.optimizer.image.exclude === null ? isFilePathInDependencies(filePath) : evaluateAndThrow(module.optimizer.image.exclude, {
662
+ exclude: filePath => module.optimizer.image.exclude === null ? isFilePathInDependencies(filePath) : evaluateOrThrowOnError(module.optimizer.image.exclude, {
656
663
  filePath,
657
664
  type: 'image'
658
665
  }),
@@ -667,14 +674,14 @@ const genericLoader = {
667
674
  maxSize: configuration.inPlace.otherMaximumFileSizeLimitInByte
668
675
  }
669
676
  },
670
- use: module.optimizer.image.loader.map(createEvaluateMapper('image'))
677
+ use: await Promise.all(module.optimizer.image.loader.map(createEvaluateMapper('image')))
671
678
  },
672
679
  // endregion
673
680
  // region data
674
681
  data: {
675
682
  exclude: filePath => {
676
683
  if (typeof filePath !== 'string') return false;
677
- return configuration.extensions.file.internal.includes(extname(stripLoader(filePath))) || (module.optimizer.data.exclude === null ? isFilePathInDependencies(filePath) : evaluateAndThrow(module.optimizer.data.exclude, {
684
+ return configuration.extensions.file.internal.includes(extname(stripLoader(filePath))) || (module.optimizer.data.exclude === null ? isFilePathInDependencies(filePath) : evaluateOrThrowOnError(module.optimizer.data.exclude, {
678
685
  filePath,
679
686
  type: 'data'
680
687
  }));
@@ -689,7 +696,7 @@ const genericLoader = {
689
696
  maxSize: configuration.inPlace.otherMaximumFileSizeLimitInByte
690
697
  }
691
698
  },
692
- use: module.optimizer.data.loader.map(createEvaluateMapper('data'))
699
+ use: await Promise.all(module.optimizer.data.loader.map(createEvaluateMapper('data')))
693
700
  }
694
701
  // endregion
695
702
  };