weboptimizer 4.0.31 → 4.0.33

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/browser.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Browser, InitializedBrowser } from './type';
2
+ import { Logger } from 'clientnode';
2
3
  export declare const browser: Browser;
3
- export declare const log: any;
4
+ export declare const log: Logger;
4
5
  /**
5
6
  * Provides a generic browser api in node or web contexts.
6
7
  * @param replaceWindow - Indicates whether a potential existing window object
package/configurator.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { ResolvedConfiguration } from './type';
2
+ import { Logger } from 'clientnode';
2
3
  export declare let loadedConfiguration: null | ResolvedConfiguration;
3
- export declare const log: any;
4
+ export declare const log: Logger;
4
5
  /**
5
6
  * Main entry point to determine current configuration.
6
7
  * @param context - Location from where to build current application.
package/ejsLoader.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { Encoding, Mapping } from 'clientnode';
2
2
  import type { Options, AsyncTemplateFunction as EJSAsyncTemplateFunction } from 'ejs';
3
3
  import type { LoaderContext } from 'webpack';
4
4
  import type { Extensions, Replacements } from './type';
5
+ import { Logger } from 'clientnode';
5
6
  export type TemplateFunction = EJSAsyncTemplateFunction;
6
7
  export type CompilerOptions = Options & {
7
8
  encoding: Encoding;
@@ -23,8 +24,9 @@ export type LoaderConfiguration = Mapping<unknown> & {
23
24
  aliases: Mapping;
24
25
  replacements: Replacements;
25
26
  };
27
+ pathsToIgnore: Array<string>;
26
28
  };
27
- export declare const log: any;
29
+ export declare const log: Logger;
28
30
  /**
29
31
  * Main transformation function.
30
32
  * @param source - Input string to transform.
package/ejsLoader.js CHANGED
@@ -63,7 +63,8 @@ export const loader = async function (source) {
63
63
  module: {
64
64
  aliases: {},
65
65
  replacements: {}
66
- }
66
+ },
67
+ pathsToIgnore: []
67
68
  }, this.getOptions ? this.getOptions() : this.query ?? {}), /#%%%#/g, '!');
68
69
  const compile = (template, nestedGivenOptions = givenOptions.compiler, compileSteps = 2) => async (locals = {}) => {
69
70
  const options = {
@@ -92,7 +93,7 @@ export const loader = async function (source) {
92
93
  if (nestedOptions.isString) return await compile(template, nestedOptions)(nestedLocals);
93
94
  const templateFilePath = determineModuleFilePath(template, givenOptions.module?.aliases, givenOptions.module?.replacements, {
94
95
  file: givenOptions.extensions?.file.internal || []
95
- }, givenOptions.context, configuration.path.source.asset.base, configuration.path.ignore, configuration.module.directoryNames, configuration.package.main.fileNames, configuration.package.main.propertyNames, configuration.package.aliasPropertyNames, configuration.encoding);
96
+ }, givenOptions.context, configuration.path.source.asset.base, configuration.path.ignore.concat(givenOptions.pathsToIgnore ?? []), configuration.module.directoryNames, configuration.package.main.fileNames, configuration.package.main.propertyNames, configuration.package.aliasPropertyNames, configuration.encoding);
96
97
  if (templateFilePath) {
97
98
  if (this.addDependency) this.addDependency(templateFilePath);
98
99
  /*
@@ -133,7 +134,7 @@ export const loader = async function (source) {
133
134
  const isString = Boolean(options.isString);
134
135
  delete options.isString;
135
136
 
136
- // NOTE: Needed to have standalone useable js code afterwards.
137
+ // NOTE: Needed to have standalone usable code afterward.
137
138
  if (compileSteps % 2) options.client = true;
138
139
  let stepLocals;
139
140
  let scope = {};
package/helper.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import type { Encoding, Mapping } from 'clientnode';
2
2
  import type { BuildConfiguration, Extensions, GivenInjection, GivenInjectionConfiguration, NormalizedGivenInjection, PathConfiguration, PackageDescriptor, Replacements, ResolvedBuildConfiguration, SpecificExtensions } from './type';
3
+ import { Logger } from 'clientnode';
3
4
  export declare const KNOWN_FILE_EXTENSIONS: Array<string>;
4
- export declare const log: any;
5
+ export declare const KNOWN_PATHS_TO_IGNORE: Array<string>;
6
+ export declare const log: Logger;
5
7
  /**
6
8
  * Determines whether given file path is within given list of file locations.
7
9
  * @param filePath - Path to file to check.
@@ -11,7 +13,7 @@ export declare const log: any;
11
13
  */
12
14
  export declare const isFilePathInLocation: (filePath: string, locationsToCheck: Array<string>) => boolean;
13
15
  /**
14
- * Strips loader informations form given module request including loader prefix
16
+ * Strips loader information form given module request including loader prefix
15
17
  * and query parameter.
16
18
  * @param moduleID - Module request to strip.
17
19
  * @returns Given module id stripped.
@@ -25,7 +27,7 @@ export declare const stripLoader: (moduleID: string) => string;
25
27
  export declare const normalizePaths: (paths: Array<string>) => Array<string>;
26
28
  /**
27
29
  * Applies file path/name placeholder replacements with given bundle associated
28
- * informations.
30
+ * information.
29
31
  * @param template - File path to process placeholder in.
30
32
  * @param scope - Scope to use for processing.
31
33
  * @returns Processed file path.
@@ -82,8 +84,8 @@ export declare const applyContext: (request: string, context?: string, reference
82
84
  export declare const determineExternalRequest: (request: string, context?: string, requestContext?: string, normalizedGivenInjection?: NormalizedGivenInjection, relativeExternalModuleLocations?: Array<string>, aliases?: Mapping, moduleReplacements?: Replacements, extensions?: Extensions, referencePath?: string, pathsToIgnore?: Array<string>, relativeModuleLocations?: Array<string>, packageEntryFileNames?: Array<string>, packageMainPropertyNames?: Array<string>, packageAliasPropertyNames?: Array<string>, includePattern?: Array<string | RegExp>, excludePattern?: Array<string | RegExp>, inPlaceNormalLibrary?: boolean, inPlaceDynamicLibrary?: boolean, encoding?: Encoding) => null | string;
83
85
  /**
84
86
  * Determines asset type of given file.
85
- * @param filePath - Path to file to analyse.
86
- * @param buildConfiguration - Meta informations for available asset types.
87
+ * @param filePath - Path to file to analyze.
88
+ * @param buildConfiguration - Meta information for available asset types.
87
89
  * @param paths - List of paths to search if given path doesn't reference a
88
90
  * file directly.
89
91
  * @returns Determined file type or "null" of given file couldn't be
@@ -93,10 +95,10 @@ export declare const determineAssetType: (filePath: string, buildConfiguration:
93
95
  /**
94
96
  * Adds a property with a stored array of all matching file paths, which
95
97
  * matches each build configuration in given entry path and converts given
96
- * build configuration into a sorted array were javaScript files takes
98
+ * build configuration into a sorted array were JavaScript files takes
97
99
  * precedence.
98
100
  * @param configuration - Given build configurations.
99
- * @param entryPath - Path to analyse nested structure.
101
+ * @param entryPath - Path to analyze nested structure.
100
102
  * @param pathsToIgnore - Paths which marks location to ignore.
101
103
  * @param mainFileBasenames - File basenames to sort into the front.
102
104
  * @returns Converted build configuration.
@@ -242,7 +244,7 @@ export declare const findPackageDescriptorFilePath: (start: Array<string> | stri
242
244
  * @param modulePath - Module path to take as reference location (leaf in
243
245
  * tree).
244
246
  * @param fileName - Package configuration file name.
245
- * @returns A object containing found parsed configuration an their
247
+ * @returns A object containing found parsed configuration and their
246
248
  * corresponding file path.
247
249
  */
248
250
  export declare const getClosestPackageDescriptor: (modulePath: string, fileName?: string) => Promise<null | PackageDescriptor>;
package/helper.js CHANGED
@@ -16,12 +16,14 @@
16
16
  endregion
17
17
  */
18
18
  // region imports
19
- import { copy, escapeRegularExpressions, extend, isAnyMatching, isDirectorySync, isFileSync, isPlainObject, Logger, represent, walkDirectoryRecursivelySync } from 'clientnode';
19
+ import { copy, escapeRegularExpressions, extend, importFilesystemAPI, isAnyMatching, isDirectorySync, isFileSync, isPlainObject, Logger, represent, walkDirectoryRecursivelySync } from 'clientnode';
20
20
  import { existsSync, readFileSync } from 'fs';
21
21
  import { basename, dirname, extname, join, normalize, resolve, sep, relative } from 'path';
22
22
  // endregion
23
+ await importFilesystemAPI();
23
24
  // region constants
24
25
  export const KNOWN_FILE_EXTENSIONS = ['js', 'ts', 'json', 'css', 'eot', 'gif', 'html', 'ico', 'jpg', 'png', 'ejs', 'svg', 'ttf', 'woff', '.woff2'];
26
+ export const KNOWN_PATHS_TO_IGNORE = ['.cache', '.claude', '.git', '.github', '.idea', '.yarn'];
25
27
  export const log = new Logger({
26
28
  name: 'weboptimizer.helper'
27
29
  });
@@ -42,7 +44,7 @@ export const isFilePathInLocation = (filePath, locationsToCheck) => {
42
44
  // endregion
43
45
  // region string
44
46
  /**
45
- * Strips loader informations form given module request including loader prefix
47
+ * Strips loader information form given module request including loader prefix
46
48
  * and query parameter.
47
49
  * @param moduleID - Module request to strip.
48
50
  * @returns Given module id stripped.
@@ -67,7 +69,7 @@ export const normalizePaths = paths => Array.from(new Set(paths.map(givenPath =>
67
69
  // region file handler
68
70
  /**
69
71
  * Applies file path/name placeholder replacements with given bundle associated
70
- * informations.
72
+ * information.
71
73
  * @param template - File path to process placeholder in.
72
74
  * @param scope - Scope to use for processing.
73
75
  * @returns Processed file path.
@@ -160,7 +162,7 @@ export const determineExternalRequest = (request, context = './', requestContext
160
162
  external: ['.compiled.js', '.js', '.json'],
161
163
  internal: KNOWN_FILE_EXTENSIONS.map(suffix => `.${suffix}`)
162
164
  }
163
- }, referencePath = './', pathsToIgnore = ['.git'], relativeModuleLocations = ['node_modules'], packageEntryFileNames = ['index', 'main'], packageMainPropertyNames = ['main', 'module'], packageAliasPropertyNames = [], includePattern = [], excludePattern = [], inPlaceNormalLibrary = false, inPlaceDynamicLibrary = true, encoding = 'utf-8') => {
165
+ }, referencePath = './', pathsToIgnore = KNOWN_PATHS_TO_IGNORE, relativeModuleLocations = ['node_modules'], packageEntryFileNames = ['index', 'main'], packageMainPropertyNames = ['main', 'module'], packageAliasPropertyNames = [], includePattern = [], excludePattern = [], inPlaceNormalLibrary = false, inPlaceDynamicLibrary = true, encoding = 'utf-8') => {
164
166
  context = resolve(context);
165
167
  requestContext = resolve(requestContext);
166
168
  referencePath = resolve(referencePath);
@@ -191,15 +193,15 @@ export const determineExternalRequest = (request, context = './', requestContext
191
193
  /*
192
194
  NOTE: We mark dependencies as external if they do not contain a loader
193
195
  in their request and aren't part of the current main package or have a
194
- file extension other than javaScript aware.
196
+ file extension other than JavaScript aware.
195
197
  */
196
198
  if (!inPlaceNormalLibrary && (extensions.file.external.length === 0 || filePath && extensions.file.external.includes(extname(filePath)) || !filePath && extensions.file.external.includes('')) && !(inPlaceDynamicLibrary && request.includes('!')) && (!filePath && inPlaceDynamicLibrary || filePath && (!filePath.startsWith(context) || isFilePathInLocation(filePath, externalModuleLocations)))) return applyContext(resolvedRequest, requestContext, referencePath, aliases, moduleReplacements, relativeModuleLocations) || null;
197
199
  return null;
198
200
  };
199
201
  /**
200
202
  * Determines asset type of given file.
201
- * @param filePath - Path to file to analyse.
202
- * @param buildConfiguration - Meta informations for available asset types.
203
+ * @param filePath - Path to file to analyze.
204
+ * @param buildConfiguration - Meta information for available asset types.
203
205
  * @param paths - List of paths to search if given path doesn't reference a
204
206
  * file directly.
205
207
  * @returns Determined file type or "null" of given file couldn't be
@@ -217,15 +219,15 @@ export const determineAssetType = (filePath, buildConfiguration, paths) => {
217
219
  /**
218
220
  * Adds a property with a stored array of all matching file paths, which
219
221
  * matches each build configuration in given entry path and converts given
220
- * build configuration into a sorted array were javaScript files takes
222
+ * build configuration into a sorted array were JavaScript files takes
221
223
  * precedence.
222
224
  * @param configuration - Given build configurations.
223
- * @param entryPath - Path to analyse nested structure.
225
+ * @param entryPath - Path to analyze nested structure.
224
226
  * @param pathsToIgnore - Paths which marks location to ignore.
225
227
  * @param mainFileBasenames - File basenames to sort into the front.
226
228
  * @returns Converted build configuration.
227
229
  */
228
- export const resolveBuildConfigurationFilePaths = (configuration, entryPath = './', pathsToIgnore = ['.git'], mainFileBasenames = ['index', 'main']) => {
230
+ export const resolveBuildConfigurationFilePaths = (configuration, entryPath = './', pathsToIgnore = KNOWN_PATHS_TO_IGNORE, mainFileBasenames = ['index', 'main']) => {
229
231
  const buildConfiguration = [];
230
232
  for (const value of Object.values(configuration)) {
231
233
  const newItem = extend(true, {
@@ -277,7 +279,7 @@ export const resolveBuildConfigurationFilePaths = (configuration, entryPath = '.
277
279
  */
278
280
  export const determineModuleLocations = (givenInjection, aliases = {}, moduleReplacements = {}, extensions = {
279
281
  file: KNOWN_FILE_EXTENSIONS.map(suffix => `.${suffix}`)
280
- }, context = './', referencePath = '', pathsToIgnore = ['.git'], relativeModuleLocations = ['node_modules'], packageEntryFileNames = ['__package__', '', 'index', 'main'], packageMainPropertyNames = ['main', 'module'], packageAliasPropertyNames = [], encoding = 'utf-8') => {
282
+ }, context = './', referencePath = '', pathsToIgnore = KNOWN_PATHS_TO_IGNORE, relativeModuleLocations = ['node_modules'], packageEntryFileNames = ['__package__', '', 'index', 'main'], packageMainPropertyNames = ['main', 'module'], packageAliasPropertyNames = [], encoding = 'utf-8') => {
281
283
  const filePaths = [];
282
284
  const directoryPaths = [];
283
285
  const normalizedGivenInjection = resolveModulesInFolders(normalizeGivenInjection(givenInjection), aliases, moduleReplacements, context, referencePath, pathsToIgnore);
@@ -306,7 +308,7 @@ export const determineModuleLocations = (givenInjection, aliases = {}, moduleRep
306
308
  * @param pathsToIgnore - Paths which marks location to ignore.
307
309
  * @returns Given injections with resolved folder pointing modules.
308
310
  */
309
- export const resolveModulesInFolders = (normalizedGivenInjection, aliases = {}, moduleReplacements = {}, context = './', referencePath = '', pathsToIgnore = ['.git']) => {
311
+ export const resolveModulesInFolders = (normalizedGivenInjection, aliases = {}, moduleReplacements = {}, context = './', referencePath = '', pathsToIgnore = KNOWN_PATHS_TO_IGNORE) => {
310
312
  if (referencePath.startsWith('/')) referencePath = relative(context, referencePath);
311
313
  const result = copy(normalizedGivenInjection);
312
314
  for (const chunk of Object.values(result)) {
@@ -383,7 +385,7 @@ export const resolveAutoInjection = (givenInjection, buildConfigurations, aliase
383
385
  external: ['compiled.js', '.js', '.json'],
384
386
  internal: KNOWN_FILE_EXTENSIONS.map(suffix => `.${suffix}`)
385
387
  }
386
- }, context = './', referencePath = '', pathsToIgnore = ['.git']) => {
388
+ }, context = './', referencePath = '', pathsToIgnore = KNOWN_PATHS_TO_IGNORE) => {
387
389
  const injection = copy(givenInjection);
388
390
  const moduleFilePathsToExclude = determineModuleLocations(givenInjection.autoExclude.paths, aliases, moduleReplacements, {
389
391
  file: extensions.file.internal
@@ -396,8 +398,8 @@ export const resolveAutoInjection = (givenInjection, buildConfigurations, aliase
396
398
  const modules = getAutoInjection(buildConfigurations, moduleFilePathsToExclude, givenInjection.autoExclude.pattern, referencePath);
397
399
  for (const subChunk of Object.values(modules)) chunk.push(subChunk);
398
400
  /*
399
- Reverse array to let javaScript and main files be
400
- the last ones to export them rather.
401
+ Reverse array to let JavaScript and main files be the
402
+ last ones to export them rather.
401
403
  */
402
404
  chunk.reverse();
403
405
  }
@@ -509,7 +511,7 @@ export const determineModuleFilePathInPackage = (packagePath, packageMainPropert
509
511
  */
510
512
  export const determineModuleFilePath = (moduleID, aliases = {}, moduleReplacements = {}, extensions = {
511
513
  file: KNOWN_FILE_EXTENSIONS.map(suffix => `.${suffix}`)
512
- }, context = './', referencePath = '', pathsToIgnore = ['.git'], relativeModuleLocations = ['node_modules'], packageEntryFileNames = ['index'], packageMainPropertyNames = ['main'], packageAliasPropertyNames = [], encoding = 'utf-8') => {
514
+ }, context = './', referencePath = '', pathsToIgnore = KNOWN_PATHS_TO_IGNORE, relativeModuleLocations = ['node_modules'], packageEntryFileNames = ['index'], packageMainPropertyNames = ['main'], packageAliasPropertyNames = [], encoding = 'utf-8') => {
513
515
  if (!moduleID) return null;
514
516
  moduleID = applyModuleReplacements(applyAliases(stripLoader(moduleID), aliases), moduleReplacements);
515
517
  if (!moduleID) return null;
@@ -591,7 +593,7 @@ export const findPackageDescriptorFilePath = (start, fileName = 'package.json')
591
593
  * @param modulePath - Module path to take as reference location (leaf in
592
594
  * tree).
593
595
  * @param fileName - Package configuration file name.
594
- * @returns A object containing found parsed configuration an their
596
+ * @returns A object containing found parsed configuration and their
595
597
  * corresponding file path.
596
598
  */
597
599
  export const getClosestPackageDescriptor = async (modulePath, fileName = 'package.json') => {
@@ -599,7 +601,7 @@ export const getClosestPackageDescriptor = async (modulePath, fileName = 'packag
599
601
  if (!filePath) return null;
600
602
 
601
603
  /*
602
- NOTE: In native ecmascript module contexts json imports are wrapped
604
+ NOTE: In native ecma script module contexts JSON imports are wrapped
603
605
  into a module namespace object providing its content as "default"
604
606
  export whereas commonjs interoperability provides it directly.
605
607
  */
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env babel-node
2
- export declare const log: any;
2
+ import { Logger } from 'clientnode';
3
+ export declare const log: Logger;
3
4
  /**
4
5
  * Main entry point.
5
6
  * @param context - Location from where to build current application.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weboptimizer",
3
- "version": "4.0.31",
3
+ "version": "4.0.33",
4
4
  "description": "A generic web optimizer, (module) bundler and development environment.",
5
5
  "keywords": [
6
6
  "webpack",
@@ -77,7 +77,7 @@
77
77
  "lint:base": "eslint --no-warn-ignored *.ts */*.ts test/*/*.ts",
78
78
  "prepare": "yarn build",
79
79
  "prettify": "yarn lint:base --fix || true",
80
- "test": "yarn build:test && node --experimental-vm-modules node_modules/.bin/jest --config ./weboptimizerJest.json --noStackTrace --root-dir './' --test-regex '/test/.+\\\\.js$' test/browser.js test/configurator.js test/helper.js test/ejsLoader.js test/stylelintConfigurator.js test/index.js test/webpackConfigurator.js",
80
+ "test": "yarn build:test && node --experimental-vm-modules node_modules/.bin/jest --config ./weboptimizerJest.json --root-dir './' --test-regex '/test/.+\\\\.js$' test/browser.js test/configurator.js test/ejsLoader.js test/helper.js test/stylelintConfigurator.js test/index.js test/webpackConfigurator.js",
81
81
  "test:coverage": "yarn test --ci --coverage --coverageReporters=text --coverageReporters=text-summary --silent --testLocationInResults",
82
82
  "test:coverage:report": "yarn test:coverage --coverageDirectory=.coverage --coverageReporters=lcov --outputFile=lcov.info",
83
83
  "test:watch": "yarn test --watch",
@@ -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.1460",
97
+ "clientnode": "4.0.1464",
98
98
  "core-js": "^3.49.0",
99
99
  "ejs": "^6.0.1",
100
100
  "exports-loader": "^5.0.0",
@@ -1,2 +1,2 @@
1
- declare const _default: PlainObject;
1
+ declare const _default: import("clientnode").PlainObject;
2
2
  export default _default;
@@ -1,4 +1,5 @@
1
1
  import type { WebpackConfiguration } from './type';
2
- export declare const log: any;
2
+ import { Logger } from 'clientnode';
3
+ export declare const log: Logger;
3
4
  export declare let webpackConfiguration: WebpackConfiguration;
4
5
  export default webpackConfiguration;