@flatjs/evolve 2.1.0-next.10 → 2.1.0-next.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. package/dist/constants.js +36 -1
  2. package/dist/create-webpack/create-externals.js +6 -1
  3. package/dist/create-webpack/create-optimization.js +43 -1
  4. package/dist/create-webpack/create-output.js +35 -1
  5. package/dist/create-webpack/create-performance.js +7 -1
  6. package/dist/create-webpack/create-plugins.js +78 -1
  7. package/dist/create-webpack/create-resolve.js +37 -1
  8. package/dist/create-webpack/create-rule-sets.js +20 -1
  9. package/dist/create-webpack/load-webpack-config.js +57 -1
  10. package/dist/create-webpack/resolve-public-path.js +15 -1
  11. package/dist/create-webpack/rule-sets/constants.js +3 -1
  12. package/dist/create-webpack/rule-sets/rule-assets.js +52 -1
  13. package/dist/create-webpack/rule-sets/rule-css.js +111 -1
  14. package/dist/create-webpack/rule-sets/rule-less.js +44 -1
  15. package/dist/create-webpack/rule-sets/rule-scripts.js +34 -1
  16. package/dist/create-webpack/rule-sets/rule-svg-icon.js +25 -1
  17. package/dist/create-webpack/rule-sets/rule-utils.js +10 -1
  18. package/dist/create-webpack/types.js +1 -1
  19. package/dist/default-options.js +83 -1
  20. package/dist/define-config/define-config.js +4 -1
  21. package/dist/define-config/index.js +1 -1
  22. package/dist/dev-server/add-compiler-to-dev-server.js +58 -1
  23. package/dist/dev-server/create-app-page-route.js +13 -1
  24. package/dist/dev-server/create-dev-server-compiler-task.js +55 -1
  25. package/dist/dev-server/create-dev-server-entries.js +25 -1
  26. package/dist/dev-server/create-dev-server.js +24 -1
  27. package/dist/dev-server/index.js +6 -1
  28. package/dist/dev-server/middlewares/create-page-middleware.js +33 -1
  29. package/dist/dev-server/middlewares/create-public-assets-middleware.js +25 -1
  30. package/dist/dev-server/middlewares/get-all-sorted-modules.js +24 -1
  31. package/dist/dev-server/middlewares/get-bundle-asset.js +7 -1
  32. package/dist/dev-server/middlewares/get-dev-server-host-uri.js +5 -1
  33. package/dist/dev-server/middlewares/get-hmr-runtime-chunks.js +14 -1
  34. package/dist/dev-server/middlewares/get-normalized-entry-name.js +14 -1
  35. package/dist/dev-server/middlewares/get-page-main-html.js +49 -1
  36. package/dist/dev-server/middlewares/get-page-module-html.js +123 -1
  37. package/dist/dev-server/middlewares/get-project-virtual-path.js +3 -1
  38. package/dist/dev-server/middlewares/get-runtime-manifest.js +25 -1
  39. package/dist/dev-server/middlewares/index.js +2 -1
  40. package/dist/dev-server/middlewares/types.js +1 -1
  41. package/dist/errors/evolve-build-error.js +10 -1
  42. package/dist/helpers/allow-px2rem-for-module.js +6 -1
  43. package/dist/helpers/assert-group-entry-item.js +19 -1
  44. package/dist/helpers/assert-single-compiler.js +45 -1
  45. package/dist/helpers/chunk-entry-map.js +21 -1
  46. package/dist/helpers/delete-object-keys.js +20 -1
  47. package/dist/helpers/enable-bundle-hashname-for-module.js +6 -1
  48. package/dist/helpers/filter-actived-entries.js +42 -1
  49. package/dist/helpers/flat-entry-map.js +11 -1
  50. package/dist/helpers/get-bundle-file-name.js +23 -1
  51. package/dist/helpers/get-git-root.js +4 -1
  52. package/dist/helpers/get-html-plugin-config.js +47 -1
  53. package/dist/helpers/get-max-process-tasks.js +7 -1
  54. package/dist/helpers/get-pacakge-dir.js +13 -1
  55. package/dist/helpers/get-runtime-cdn-base.js +21 -1
  56. package/dist/helpers/index.js +27 -1
  57. package/dist/helpers/is-deep-equal.js +67 -1
  58. package/dist/helpers/json-serializer.js +52 -1
  59. package/dist/helpers/merge-babel-options.js +45 -1
  60. package/dist/helpers/normalize-check-entry-options.js +28 -1
  61. package/dist/helpers/normalize-entry-map.js +59 -1
  62. package/dist/helpers/normalize-group-name.js +16 -1
  63. package/dist/helpers/normalize-page-proxy.js +9 -1
  64. package/dist/helpers/normalize-resolve-alias.js +7 -1
  65. package/dist/helpers/normalize-template-inject-tokens.js +22 -1
  66. package/dist/helpers/open-page.js +15 -1
  67. package/dist/helpers/print-log.js +49 -1
  68. package/dist/helpers/refresh-evolve-mock-options.js +34 -1
  69. package/dist/helpers/resolve-entry-map-input-files.js +20 -1
  70. package/dist/helpers/script-injects.js +39 -1
  71. package/dist/helpers/should-enable-react-fast-refresh.js +14 -1
  72. package/dist/helpers/split-to-entry-group.d.ts +5 -5
  73. package/dist/helpers/split-to-entry-group.js +139 -1
  74. package/dist/helpers/verify-group-entry-options.js +21 -1
  75. package/dist/index.js +5 -1
  76. package/dist/load-config/index.js +1 -1
  77. package/dist/load-config/load-evolve-config.js +41 -1
  78. package/dist/load-config/types.js +1 -1
  79. package/dist/main/create-thread-worker.js +51 -1
  80. package/dist/main/env-verify.js +21 -1
  81. package/dist/main/get-worker-path.js +5 -1
  82. package/dist/main/index.js +4 -1
  83. package/dist/main/prepare-build.js +39 -1
  84. package/dist/main/prepare-serve.js +69 -1
  85. package/dist/main/prepare-static.js +30 -1
  86. package/dist/main/start-build-dynamic.js +171 -1
  87. package/dist/main/start-build-worker.js +44 -1
  88. package/dist/main/start-build.js +69 -1
  89. package/dist/main/start-group-entry-build.js +32 -1
  90. package/dist/main/start-serve.js +34 -1
  91. package/dist/main/start-static.js +19 -1
  92. package/dist/minimizer/create-minimizers.js +25 -1
  93. package/dist/minimizer/default-options.js +14 -1
  94. package/dist/minimizer/image-minimizer.js +65 -1
  95. package/dist/minimizer/index.js +1 -1
  96. package/dist/minimizer/terser-minimizer.js +15 -3
  97. package/dist/minimizer/types.js +1 -1
  98. package/dist/plugins/circular-dependency/circular-dependency-plugin.js +119 -1
  99. package/dist/plugins/circular-dependency/index.js +15 -1
  100. package/dist/plugins/clean-webpack/clean-webpack-plugin.js +173 -1
  101. package/dist/plugins/clean-webpack/index.js +22 -1
  102. package/dist/plugins/define-variable/define-variable-plugin.js +28 -1
  103. package/dist/plugins/define-variable/index.js +1 -1
  104. package/dist/plugins/html-inject-scripts/plugin-html-inject-script.js +27 -1
  105. package/dist/plugins/module-federation/external-template-remotes.js +92 -1
  106. package/dist/plugins/module-federation/index.js +1 -1
  107. package/dist/plugins/module-federation/module-federation.js +100 -1
  108. package/dist/plugins/multi-html/index.js +16 -1
  109. package/dist/plugins/multi-html/multi-html-cdn-plugin.js +83 -1
  110. package/dist/plugins/multi-html/multi-html-plugin.js +65 -1
  111. package/dist/plugins/ts-checker/index.js +1 -1
  112. package/dist/plugins/ts-checker/ts-checker-plugin.js +24 -1
  113. package/dist/types/index.js +8 -1
  114. package/dist/types/types-ci.js +1 -1
  115. package/dist/types/types-dev-server.js +1 -1
  116. package/dist/types/types-entry-map.js +1 -1
  117. package/dist/types/types-federation.js +1 -1
  118. package/dist/types/types-loader-options.d.ts +30 -3
  119. package/dist/types/types-loader-options.js +1 -1
  120. package/dist/types/types-modular-import.js +1 -1
  121. package/dist/types/types-multi-html.js +1 -1
  122. package/dist/types/types-options.js +1 -1
  123. package/dist/types/types-plugin-options.js +1 -1
  124. package/dist/types/types-threads-options.js +1 -1
  125. package/dist/types/types-webpack.js +1 -1
  126. package/package.json +2 -2
@@ -1 +1,34 @@
1
- import{logger,requireResolve}from"@flatjs/common";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareServe}from"./prepare-serve.js";export const startServe=async(e,r,o={},t)=>{const i={projectCwd:e,command:"serve",resolve:requireResolve},n=await loadEvolveConfig(i,e,o,t),l=filterActivedEntriesByModule(n.entryMap,r),s=Object.keys(l);if(!s.length)return logger.warn("No served entries providered!"),[];logger.info({servedEntries:s});const v=normalizeEvolveEntryMap(l,n.entryMap);return prepareServe(e,v,n)};
1
+ import { logger, requireResolve } from '@flatjs/common';
2
+ import { filterActivedEntriesByModule } from '../helpers/filter-actived-entries.js';
3
+ import { normalizeEvolveEntryMap } from '../helpers/normalize-entry-map.js';
4
+ import { loadEvolveConfig } from '../load-config/load-evolve-config.js';
5
+ import { prepareServe } from './prepare-serve.js';
6
+ /**
7
+ * The main entry to start evolve serve
8
+ * @param projectCwd The Root directory (workspace) of this project.
9
+ * @param serveModules The filter pattern to detect modules we want to serve.
10
+ * @param overrideEvolveOptions The overrided evolve options
11
+ * @param configLoaderOptions Evolve config loader options
12
+ */
13
+ export const startServe = async (projectCwd, serveModules, overrideEvolveOptions = {}, configLoaderOptions) => {
14
+ const command = {
15
+ projectCwd,
16
+ command: 'serve',
17
+ resolve: requireResolve,
18
+ };
19
+ // Try to load evolve configuration from `flatjs-evolve.config.ts`
20
+ const evolveOptions = await loadEvolveConfig(command, projectCwd, overrideEvolveOptions, configLoaderOptions);
21
+ const servedEntries = filterActivedEntriesByModule(evolveOptions.entryMap, serveModules);
22
+ const servedEntryKeys = Object.keys(servedEntries);
23
+ // Make sure that we have at least one serve entry module.
24
+ if (!servedEntryKeys.length) {
25
+ logger.warn(`No served entries providered!`);
26
+ return [];
27
+ }
28
+ logger.info({
29
+ servedEntries: servedEntryKeys,
30
+ });
31
+ // Normalized served entries to make sure we have latested entry options.
32
+ const normalizedServedEntries = normalizeEvolveEntryMap(servedEntries, evolveOptions.entryMap);
33
+ return prepareServe(projectCwd, normalizedServedEntries, evolveOptions);
34
+ };
@@ -1 +1,19 @@
1
- import{requireResolve}from"@flatjs/common";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareStatic}from"./prepare-static.js";export const startStatic=async(o,e={},r)=>{const t={projectCwd:o,command:"static",resolve:requireResolve},a=await loadEvolveConfig(t,o,e,r);return prepareStatic(o,a)};
1
+ import { requireResolve } from '@flatjs/common';
2
+ import { loadEvolveConfig } from '../load-config/load-evolve-config.js';
3
+ import { prepareStatic } from './prepare-static.js';
4
+ /**
5
+ * The main entry to start evolve static server to proxy all modules of `production` build
6
+ * @param projectCwd The Root directory (workspace) of this project.
7
+ * @param overrideEvolveOptions The overrided evolve options
8
+ * @param configLoaderOptions Evolve config loader options
9
+ */
10
+ export const startStatic = async (projectCwd, overrideEvolveOptions = {}, configLoaderOptions) => {
11
+ const command = {
12
+ projectCwd,
13
+ command: 'static',
14
+ resolve: requireResolve,
15
+ };
16
+ // Try to load evolve configuration from `flatjs-evolve.config.ts`
17
+ const evolveOptions = await loadEvolveConfig(command, projectCwd, overrideEvolveOptions, configLoaderOptions);
18
+ return prepareStatic(projectCwd, evolveOptions);
19
+ };
@@ -1 +1,25 @@
1
- import{logger}from"@flatjs/common";import{moduleName}from"../constants.js";import{printInfo}from"../helpers/print-log.js";import{imageMinimizer}from"./image-minimizer.js";import{terserMinimizer}from"./terser-minimizer.js";export const createMinimizers=(i,r)=>{const e=[];if(i)return logger.debug("Ignore minimizer plugin for `serve` mode",moduleName),e;if(!1===r?.minimizer)return printInfo("Note `minimizer` has been disabled for now"),e;if(r?.minimizer?.imageMin){const i=imageMinimizer();i&&e.push(i)}const m=terserMinimizer(r?.minimizer?.terserOptions||{});return e.push(m),e};
1
+ import { logger } from '@flatjs/common';
2
+ import { moduleName } from '../constants.js';
3
+ import { printInfo } from '../helpers/print-log.js';
4
+ import { imageMinimizer } from './image-minimizer.js';
5
+ import { terserMinimizer } from './terser-minimizer.js';
6
+ export const createMinimizers = (serveMode, webpackOptions) => {
7
+ const minimizers = [];
8
+ if (serveMode) {
9
+ logger.debug('Ignore minimizer plugin for `serve` mode', moduleName);
10
+ return minimizers;
11
+ }
12
+ if (webpackOptions?.minimizer === false) {
13
+ printInfo('Note `minimizer` has been disabled for now');
14
+ return minimizers;
15
+ }
16
+ if (webpackOptions?.minimizer?.imageMin) {
17
+ const imageMinPlugin = imageMinimizer();
18
+ if (imageMinPlugin) {
19
+ minimizers.push(imageMinPlugin);
20
+ }
21
+ }
22
+ const terserPlugin = terserMinimizer(webpackOptions?.minimizer?.terserOptions || {});
23
+ minimizers.push(terserPlugin);
24
+ return minimizers;
25
+ };
@@ -1 +1,14 @@
1
- export const defaultTerserOptions={ecma:void 0,parse:{},compress:{},mangle:!0,module:!1,output:void 0,toplevel:!1,ie8:!1,keep_classnames:void 0,keep_fnames:!1,safari10:!1};
1
+ export const defaultTerserOptions = {
2
+ ecma: undefined,
3
+ parse: {},
4
+ compress: {},
5
+ // Note `mangle.properties` is `false` by default.
6
+ mangle: true,
7
+ module: false,
8
+ output: undefined,
9
+ toplevel: false,
10
+ ie8: false,
11
+ keep_classnames: undefined,
12
+ keep_fnames: false,
13
+ safari10: false,
14
+ };
@@ -1 +1,65 @@
1
- import{projectHasYarn}from"@armit/package";import{chalk,logger,requireResolve}from"@flatjs/common";import ImageMinimizerPlugin from"image-minimizer-webpack-plugin";import{moduleName}from"../constants.js";const logs=new Map;export const imageMinimizer=()=>{const e=[],i=[["svgo",{}],["gifsicle",{}],["jpegtran",{}],["pngquant",{}]].map((i=>{const n=i[0];try{return requireResolve(import.meta.url,`imagemin-${n}`),i}catch(i){if(!logs.get(n)){logs.set(n,!0);const i=chalk(["magenta"])(`"${projectHasYarn()?"yarn add":"npm install"} imagemin-${n} -D"`);e.push(`Execute ${i} for assets optimization`)}return null}})).filter(Boolean);if(e.length)for(const i of e)logger.warn(i,moduleName);return i.length?new ImageMinimizerPlugin({minimizer:{implementation:ImageMinimizerPlugin.imageminMinify,options:{plugins:i}}}):null};
1
+ import { projectHasYarn } from '@armit/package';
2
+ import { chalk, logger, requireResolve } from '@flatjs/common';
3
+ import ImageMinimizerPlugin from 'image-minimizer-webpack-plugin';
4
+ import { moduleName } from '../constants.js';
5
+ const logs = new Map();
6
+ /**
7
+ * Install libpng library & gifsicle tool
8
+ * macos
9
+ * =====================
10
+ * brew install libpng
11
+ * brew install gifsicle
12
+ *
13
+ * centos
14
+ * =====================
15
+ * sudo yum install libpng
16
+ * sudo yum install epel-release
17
+ * sudo yum install gifsicle
18
+ * @returns
19
+ */
20
+ export const imageMinimizer = () => {
21
+ const suggestedPlugins = [
22
+ // Svgo configuration here https://github.com/svg/svgo#configuration
23
+ ['svgo', {}],
24
+ ['gifsicle', {}],
25
+ ['jpegtran', {}],
26
+ ['pngquant', {}],
27
+ ];
28
+ const logMessage = [];
29
+ const availabledPlugins = suggestedPlugins
30
+ .map((item) => {
31
+ const moduleId = item[0];
32
+ try {
33
+ requireResolve(import.meta.url, `imagemin-${moduleId}`);
34
+ return item;
35
+ }
36
+ catch (err) {
37
+ if (!logs.get(moduleId)) {
38
+ logs.set(moduleId, true);
39
+ const command = chalk(['magenta'])(`"${projectHasYarn() ? 'yarn add' : 'npm install'} imagemin-${moduleId} -D"`);
40
+ logMessage.push(`Execute ${command} for assets optimization`);
41
+ }
42
+ return null;
43
+ }
44
+ })
45
+ .filter(Boolean);
46
+ if (logMessage.length) {
47
+ for (const msg of logMessage) {
48
+ logger.warn(msg, moduleName);
49
+ }
50
+ }
51
+ if (availabledPlugins.length) {
52
+ return new ImageMinimizerPlugin({
53
+ minimizer: {
54
+ // Recommended squoosh options for lossless optimization
55
+ implementation: ImageMinimizerPlugin.imageminMinify,
56
+ options: {
57
+ // Lossless optimization with custom option
58
+ // Feel free to experiment with options for better result for you
59
+ plugins: availabledPlugins,
60
+ },
61
+ },
62
+ });
63
+ }
64
+ return null;
65
+ };
@@ -1 +1 @@
1
- export*from"./create-minimizers.js";
1
+ export * from './create-minimizers.js';
@@ -1,3 +1,15 @@
1
- import{mergeOptions}from"@flatjs/common";import TerserPlugin from"terser-webpack-plugin";import{defaultTerserOptions}from"./default-options.js";export const terserMinimizer=e=>new TerserPlugin({parallel:!0,
2
- // Disable Extract all or some (use /^\**!|@preserve|@license|@cc_on/i RegExp) comments.
3
- extractComments:!1,terserOptions:mergeOptions(defaultTerserOptions,e)});
1
+ import { mergeOptions } from '@flatjs/common';
2
+ import TerserPlugin from 'terser-webpack-plugin';
3
+ import { defaultTerserOptions } from './default-options.js';
4
+ /**
5
+ * https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
6
+ */
7
+ export const terserMinimizer = (terserOptions) => {
8
+ return new TerserPlugin({
9
+ parallel: true,
10
+ // Disable Extract all or some (use /^\**!|@preserve|@license|@cc_on/i RegExp) comments.
11
+ extractComments: false,
12
+ // Terser minify options.
13
+ terserOptions: mergeOptions(defaultTerserOptions, terserOptions),
14
+ });
15
+ };
@@ -1 +1 @@
1
- export{};
1
+ export {};
@@ -1 +1,119 @@
1
- import{relative}from"node:path";import{mergeOptions}from"@flatjs/common";import Graph from"tarjan-graph";import webpack from"webpack";const BASE_ERROR="Circular dependency detected:\r\n",PLUGIN_TITLE="CircularDependencyPlugin";export class CircularDependencyPlugin{constructor(o={}){this.options=mergeOptions({exclude:/node_modules/,include:/.*/,failOnError:!1,allowAsyncCycles:!1,projectCwd:process.cwd()},o)}apply(o){const e=this.options.projectCwd;o.hooks.compilation.tap(PLUGIN_TITLE,(o=>{o.hooks.optimizeModules.tap(PLUGIN_TITLE,(t=>{this.options.onStart&&this.options.onStart({compilation:o});const n=new(Graph.default||Graph);for(const e of t){const t=[];for(const n of e.dependencies){if(n.constructor&&"CommonJsSelfReferenceDependency"===n.constructor.name)continue;let r=null;r=o.moduleGraph?o.moduleGraph.getModule(n):n.module,r&&(r instanceof webpack.NormalModule&&r.resource&&(this.options.allowAsyncCycles&&n.weak||e!==r&&t.push(r.identifier())))}n.add(e.identifier(),t)}const r=n.getCycles();this.isCyclic(r,o,e),this.options.onEnd&&this.options.onEnd({compilation:o})}))}))}isCyclic(o,e,t){o.forEach((o=>{const n=o.slice().reverse().map((o=>{const t=e.findModule(o.name);return t instanceof webpack.NormalModule&&t.resource||null}));if(n.every((o=>!o||this.options.exclude.test(o)||!this.options.include.test(o))))return;const r=n.map((o=>relative(t,o)));if(this.options.onDetected){try{this.options.onDetected({paths:r.concat([r[0]]),compilation:e})}catch(o){e.errors.push(o)}return}const s=new Error(BASE_ERROR.concat(r.concat([r[0]]).join(" -> ")));this.options.failOnError?e.errors.push(s):e.warnings.push(s)}))}}
1
+ import { relative } from 'node:path';
2
+ import { mergeOptions } from '@flatjs/common';
3
+ import Graph from 'tarjan-graph';
4
+ import webpack from 'webpack';
5
+ const BASE_ERROR = 'Circular dependency detected:\r\n';
6
+ const PLUGIN_TITLE = `CircularDependencyPlugin`;
7
+ export class CircularDependencyPlugin {
8
+ constructor(options = {}) {
9
+ this.options = mergeOptions({
10
+ exclude: /node_modules/,
11
+ include: /.*/,
12
+ failOnError: false,
13
+ allowAsyncCycles: false,
14
+ projectCwd: process.cwd(),
15
+ }, options);
16
+ }
17
+ apply(compiler) {
18
+ const cwd = this.options.projectCwd;
19
+ // eslint-disable-next-line sonarjs/cognitive-complexity
20
+ compiler.hooks.compilation.tap(PLUGIN_TITLE, (compilation) => {
21
+ // eslint-disable-next-line sonarjs/cognitive-complexity
22
+ compilation.hooks.optimizeModules.tap(PLUGIN_TITLE, (modules) => {
23
+ if (this.options.onStart) {
24
+ this.options.onStart({ compilation });
25
+ }
26
+ const dependencyGraph = new (Graph.default || Graph)();
27
+ for (const module of modules) {
28
+ // Iterate over the current modules dependencies
29
+ const dependedModuleIds = [];
30
+ for (const dependency of module.dependencies) {
31
+ if (dependency.constructor &&
32
+ dependency.constructor.name === 'CommonJsSelfReferenceDependency') {
33
+ continue;
34
+ }
35
+ let depModule = null;
36
+ if (compilation.moduleGraph) {
37
+ // handle getting a module for webpack 5
38
+ depModule = compilation.moduleGraph.getModule(dependency);
39
+ }
40
+ else {
41
+ // handle getting a module for webpack 4
42
+ depModule = dependency.module;
43
+ }
44
+ if (!depModule) {
45
+ continue;
46
+ }
47
+ // ignore dependencies that don't have an associated resource
48
+ if (!(depModule instanceof webpack.NormalModule) ||
49
+ !depModule.resource) {
50
+ continue;
51
+ }
52
+ // optionally ignore dependencies that are resolved asynchronously
53
+ if (this.options.allowAsyncCycles && dependency.weak) {
54
+ continue;
55
+ }
56
+ // the dependency was resolved to the current module due to how webpack internals
57
+ // setup dependencies like CommonJsSelfReferenceDependency and ModuleDecoratorDependency
58
+ if (module === depModule) {
59
+ continue;
60
+ }
61
+ dependedModuleIds.push(depModule.identifier());
62
+ }
63
+ dependencyGraph.add(module.identifier(), dependedModuleIds);
64
+ }
65
+ const cycles = dependencyGraph.getCycles();
66
+ this.isCyclic(cycles, compilation, cwd);
67
+ if (this.options.onEnd) {
68
+ this.options.onEnd({ compilation });
69
+ }
70
+ });
71
+ });
72
+ }
73
+ isCyclic(cycles, compilation, cwd) {
74
+ cycles.forEach((vertices) => {
75
+ // Convert the array of vertices into an array of module paths
76
+ const cyclicAbsolutePaths = vertices
77
+ .slice()
78
+ .reverse()
79
+ .map((vertex) => {
80
+ const module = compilation.findModule(vertex.name);
81
+ if (!(module instanceof webpack.NormalModule)) {
82
+ return null;
83
+ }
84
+ return module.resource || null;
85
+ });
86
+ if (cyclicAbsolutePaths.every((resource) => !resource ||
87
+ this.options.exclude.test(resource) ||
88
+ !this.options.include.test(resource))) {
89
+ // If all modules in the cycle are excluded by the config, don't report an error
90
+ return;
91
+ }
92
+ const cyclicPaths = cyclicAbsolutePaths.map((resource) => relative(cwd, resource));
93
+ // allow consumers to override all behavior with onDetected
94
+ if (this.options.onDetected) {
95
+ try {
96
+ this.options.onDetected({
97
+ paths: cyclicPaths.concat([cyclicPaths[0]]),
98
+ compilation: compilation,
99
+ });
100
+ }
101
+ catch (err) {
102
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
103
+ compilation.errors.push(err);
104
+ }
105
+ return;
106
+ }
107
+ // mark warnings or errors on webpack compilation
108
+ const error = new Error(BASE_ERROR.concat(cyclicPaths.concat([cyclicPaths[0]]).join(' -> ')));
109
+ if (this.options.failOnError) {
110
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
+ compilation.errors.push(error);
112
+ }
113
+ else {
114
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
115
+ compilation.warnings.push(error);
116
+ }
117
+ });
118
+ }
119
+ }
@@ -1 +1,15 @@
1
- import{CircularDependencyPlugin}from"./circular-dependency-plugin.js";export const createCircularDependencyPlugin=(e,n)=>e?[new CircularDependencyPlugin({projectCwd:n.projectCwd})]:[];
1
+ import { CircularDependencyPlugin } from './circular-dependency-plugin.js';
2
+ /**
3
+ * Detect modules with circular dependencies when bundling with webpack for `development` mode.
4
+ * @returns
5
+ */
6
+ export const createCircularDependencyPlugin = (serveMode, evolveOptions) => {
7
+ if (!serveMode) {
8
+ return [];
9
+ }
10
+ return [
11
+ new CircularDependencyPlugin({
12
+ projectCwd: evolveOptions.projectCwd,
13
+ }),
14
+ ];
15
+ };
@@ -1 +1,173 @@
1
- import{rmSync}from"node:fs";import{relative}from"node:path";import{fileWalkSync}from"@armit/file-utility";import{logger}from"@flatjs/common";import{moduleName}from"../../constants.js";export class CleanWebpackPlugin{constructor(e={}){this.verbose=!0===e.verbose||!1,this.projectCwd=e.projectCwd||process.cwd(),this.cleanStaleWebpackAssets=!0!==e.cleanStaleWebpackAssets&&!1!==e.cleanStaleWebpackAssets||e.cleanStaleWebpackAssets,this.protectWebpackAssets=!0!==e.protectWebpackAssets&&!1!==e.protectWebpackAssets||e.protectWebpackAssets,this.cleanAfterEveryBuildPatterns=Array.isArray(e.cleanAfterEveryBuildPatterns)?e.cleanAfterEveryBuildPatterns:[],this.cleanOnceBeforeBuildPatterns=Array.isArray(e.cleanOnceBeforeBuildPatterns)?e.cleanOnceBeforeBuildPatterns:["**/*"],this.currentAssets=[],this.initialClean=!1,this.outputPath="",this.apply=this.apply.bind(this),this.handleInitial=this.handleInitial.bind(this),this.handleDone=this.handleDone.bind(this),this.removeFiles=this.removeFiles.bind(this)}apply(e){if(!e.options.output||!e.options.output.path)return void logger.warn("clean-webpack-plugin: options.output.path not defined. Plugin disabled...",moduleName);this.outputPath=e.options.output.path;const t=e.hooks;0!==this.cleanOnceBeforeBuildPatterns.length&&t.emit.tap("clean-webpack-plugin",(e=>{this.handleInitial(e)})),t.done.tap("clean-webpack-plugin",(e=>{this.handleDone(e)}))}handleInitial(e){if(this.initialClean)return;e.getStats().hasErrors()||(this.initialClean=!0,this.removeFiles(this.cleanOnceBeforeBuildPatterns))}handleDone(e){if(e.hasErrors())return void(this.verbose&&logger.warn("clean-webpack-plugin: pausing due to webpack errors",moduleName));const t=(e.toJson({assets:!0}).assets||[]).map((e=>e.name)),s=this.currentAssets.filter((e=>!1===t.includes(e)));this.currentAssets=t.sort();const i=[];!0===this.cleanStaleWebpackAssets&&0!==s.length&&i.push(...s),0!==this.cleanAfterEveryBuildPatterns.length&&i.push(...this.cleanAfterEveryBuildPatterns),0!==i.length&&this.removeFiles(i)}removeFiles(e){try{const t=fileWalkSync(e,{absolute:!0,unique:!0,cwd:this.outputPath,dot:!0,ignore:this.protectWebpackAssets?this.currentAssets:[]});for(const e of t)rmSync(e,{force:!0,recursive:!0});this.verbose&&t.forEach((e=>{const t=relative(this.projectCwd,e);logger.debug(`clean-webpack-plugin: removed ${t}`,moduleName)}))}catch(e){if(/Cannot delete files\/folders outside the current working directory\./.test(e.message)){throw new Error("clean-webpack-plugin: Cannot delete files/folders outside the current working directory. Can be overridden with the `dangerouslyAllowCleanPatternsOutsideProject` option.")}throw e}}}
1
+ import { rmSync } from 'node:fs';
2
+ import { relative } from 'node:path';
3
+ import { fileWalkSync } from '@armit/file-utility';
4
+ import { logger } from '@flatjs/common';
5
+ import { moduleName } from '../../constants.js';
6
+ export class CleanWebpackPlugin {
7
+ constructor(options = {}) {
8
+ this.verbose = options.verbose === true || false;
9
+ this.projectCwd = options.projectCwd || process.cwd();
10
+ this.cleanStaleWebpackAssets =
11
+ options.cleanStaleWebpackAssets === true ||
12
+ options.cleanStaleWebpackAssets === false
13
+ ? options.cleanStaleWebpackAssets
14
+ : true;
15
+ this.protectWebpackAssets =
16
+ options.protectWebpackAssets === true ||
17
+ options.protectWebpackAssets === false
18
+ ? options.protectWebpackAssets
19
+ : true;
20
+ this.cleanAfterEveryBuildPatterns = Array.isArray(options.cleanAfterEveryBuildPatterns)
21
+ ? options.cleanAfterEveryBuildPatterns
22
+ : [];
23
+ this.cleanOnceBeforeBuildPatterns = Array.isArray(options.cleanOnceBeforeBuildPatterns)
24
+ ? options.cleanOnceBeforeBuildPatterns
25
+ : ['**/*'];
26
+ /**
27
+ * Store webpack build assets
28
+ */
29
+ this.currentAssets = [];
30
+ /**
31
+ * Only used with cleanOnceBeforeBuildPatterns
32
+ */
33
+ this.initialClean = false;
34
+ this.outputPath = '';
35
+ this.apply = this.apply.bind(this);
36
+ this.handleInitial = this.handleInitial.bind(this);
37
+ this.handleDone = this.handleDone.bind(this);
38
+ this.removeFiles = this.removeFiles.bind(this);
39
+ }
40
+ apply(compiler) {
41
+ if (!compiler.options.output || !compiler.options.output.path) {
42
+ logger.warn('clean-webpack-plugin: options.output.path not defined. Plugin disabled...', moduleName);
43
+ return;
44
+ }
45
+ this.outputPath = compiler.options.output.path;
46
+ /**
47
+ * webpack 4+ comes with a new plugin system.
48
+ *
49
+ * Check for hooks in-order to support old plugin system
50
+ */
51
+ const hooks = compiler.hooks;
52
+ if (this.cleanOnceBeforeBuildPatterns.length !== 0) {
53
+ hooks.emit.tap('clean-webpack-plugin', (compilation) => {
54
+ this.handleInitial(compilation);
55
+ });
56
+ }
57
+ hooks.done.tap('clean-webpack-plugin', (stats) => {
58
+ this.handleDone(stats);
59
+ });
60
+ }
61
+ /**
62
+ * Initially remove files from output directory prior to build.
63
+ *
64
+ * Only happens once.
65
+ *
66
+ * Warning: It is recommended to initially clean your build directory outside of webpack to minimize unexpected behavior.
67
+ */
68
+ handleInitial(compilation) {
69
+ if (this.initialClean) {
70
+ return;
71
+ }
72
+ /**
73
+ * Do not remove files if there are compilation errors
74
+ *
75
+ * Handle logging inside this.handleDone
76
+ */
77
+ const stats = compilation.getStats();
78
+ if (stats.hasErrors()) {
79
+ return;
80
+ }
81
+ this.initialClean = true;
82
+ this.removeFiles(this.cleanOnceBeforeBuildPatterns);
83
+ }
84
+ handleDone(stats) {
85
+ /**
86
+ * Do nothing if there is a webpack error
87
+ */
88
+ if (stats.hasErrors()) {
89
+ if (this.verbose) {
90
+ logger.warn('clean-webpack-plugin: pausing due to webpack errors', moduleName);
91
+ }
92
+ return;
93
+ }
94
+ /**
95
+ * Fetch Webpack's output asset files
96
+ */
97
+ const assets = stats.toJson({
98
+ assets: true,
99
+ }).assets || [];
100
+ const assetList = assets.map((asset) => {
101
+ return asset.name;
102
+ });
103
+ /**
104
+ * Get all files that were in the previous build but not the current
105
+ *
106
+ * (relies on del's cwd: outputPath option)
107
+ */
108
+ const staleFiles = this.currentAssets.filter((previousAsset) => {
109
+ return assetList.includes(previousAsset) === false;
110
+ });
111
+ /**
112
+ * Save assets for next compilation
113
+ */
114
+ this.currentAssets = assetList.sort();
115
+ const removePatterns = [];
116
+ /**
117
+ * Remove unused webpack assets
118
+ */
119
+ if (this.cleanStaleWebpackAssets === true && staleFiles.length !== 0) {
120
+ removePatterns.push(...staleFiles);
121
+ }
122
+ /**
123
+ * Remove cleanAfterEveryBuildPatterns
124
+ */
125
+ if (this.cleanAfterEveryBuildPatterns.length !== 0) {
126
+ removePatterns.push(...this.cleanAfterEveryBuildPatterns);
127
+ }
128
+ if (removePatterns.length !== 0) {
129
+ this.removeFiles(removePatterns);
130
+ }
131
+ }
132
+ removeFiles(patterns) {
133
+ try {
134
+ const deleted = fileWalkSync(patterns, {
135
+ absolute: true,
136
+ unique: true,
137
+ // Change context to build directory
138
+ cwd: this.outputPath,
139
+ dot: true,
140
+ ignore: this.protectWebpackAssets ? this.currentAssets : [],
141
+ });
142
+ for (const filepath of deleted) {
143
+ rmSync(filepath, {
144
+ force: true,
145
+ recursive: true,
146
+ });
147
+ }
148
+ /**
149
+ * Log if verbose is enabled
150
+ */
151
+ if (this.verbose) {
152
+ deleted.forEach((file) => {
153
+ const filename = relative(this.projectCwd, file);
154
+ const message = 'removed';
155
+ /**
156
+ * Use console.warn over .log
157
+ * https://github.com/webpack/webpack/issues/1904
158
+ * https://github.com/johnagan/clean-webpack-plugin/issues/11
159
+ */
160
+ logger.debug(`clean-webpack-plugin: ${message} ${filename}`, moduleName);
161
+ });
162
+ }
163
+ }
164
+ catch (error) {
165
+ const needsForce = /Cannot delete files\/folders outside the current working directory\./.test(error.message);
166
+ if (needsForce) {
167
+ const message = 'clean-webpack-plugin: Cannot delete files/folders outside the current working directory. Can be overridden with the `dangerouslyAllowCleanPatternsOutsideProject` option.';
168
+ throw new Error(message);
169
+ }
170
+ throw error;
171
+ }
172
+ }
173
+ }
@@ -1 +1,22 @@
1
- import{join}from"node:path";import{ensureSlash}from"@flatjs/common";import{CleanWebpackPlugin}from"./clean-webpack-plugin.js";export const createCleanWebpackPlugin=(e,n,o)=>e?[]:[new CleanWebpackPlugin({verbose:!0,projectCwd:o.projectCwd,cleanOnceBeforeBuildPatterns:n.map((e=>`${join(ensureSlash(e[0],!0),"**/*")}`))})];
1
+ import { join } from 'node:path';
2
+ import { ensureSlash } from '@flatjs/common';
3
+ import { CleanWebpackPlugin } from './clean-webpack-plugin.js';
4
+ /**
5
+ * Cleaning up the /dist folder for `production` build
6
+ * @param singleEntryItem
7
+ * @returns
8
+ */
9
+ export const createCleanWebpackPlugin = (serveMode, entryMapItemList, evolveOptions) => {
10
+ if (serveMode) {
11
+ return [];
12
+ }
13
+ return [
14
+ new CleanWebpackPlugin({
15
+ verbose: true,
16
+ projectCwd: evolveOptions.projectCwd,
17
+ cleanOnceBeforeBuildPatterns: entryMapItemList.map((entryMapItem) => {
18
+ return `${join(ensureSlash(entryMapItem[0], true), '**/*')}`;
19
+ }),
20
+ }),
21
+ ];
22
+ };
@@ -1 +1,28 @@
1
- import{getLastCommitHash,gitBranchName}from"@armit/git";import webpack from"webpack";export const createBuiltinDefineVariables=async(e,i)=>{const t=await getLastCommitHash(),n=await gitBranchName();return[new webpack.DefinePlugin({__SENTRY_DEBUG__:e,"process.env.FLAT_BUILD_DATE":JSON.stringify((new Date).toISOString()),"process.env.FLAT_COMMIT_HASH":JSON.stringify(t),"process.env.FLAT_BRANCH_NAME":JSON.stringify(n),"process.env.FLAT_RELEASE_VERSION":JSON.stringify(i.ci?.releaseVersion||t),...i.pluginOptions.definePlugin})]};
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
+ import { getLastCommitHash, gitBranchName } from '@armit/git';
3
+ import webpack from 'webpack';
4
+ /**
5
+ * The DefinePlugin replaces variables in your code with other values or expressions at compile time.
6
+ * ```ts
7
+ * `__SENTRY_DEBUG__`
8
+ * `process.env.FLAT_BUILD_DATE`
9
+ * `process.env.FLAT_COMMIT_HASH`
10
+ * `process.env.FLAT_BRANCH_NAME`
11
+ * `process.env.FLAT_RELEASE_VERSION`
12
+ * ```
13
+ * @returns
14
+ */
15
+ export const createBuiltinDefineVariables = async (serveMode, evolveOptions) => {
16
+ const commitHash = await getLastCommitHash();
17
+ const branchName = await gitBranchName();
18
+ return [
19
+ new webpack.DefinePlugin({
20
+ __SENTRY_DEBUG__: serveMode,
21
+ 'process.env.FLAT_BUILD_DATE': JSON.stringify(new Date().toISOString()),
22
+ 'process.env.FLAT_COMMIT_HASH': JSON.stringify(commitHash),
23
+ 'process.env.FLAT_BRANCH_NAME': JSON.stringify(branchName),
24
+ 'process.env.FLAT_RELEASE_VERSION': JSON.stringify(evolveOptions.ci?.releaseVersion || commitHash),
25
+ ...evolveOptions.pluginOptions.definePlugin,
26
+ }),
27
+ ];
28
+ };
@@ -1 +1 @@
1
- export*from"./define-variable-plugin.js";
1
+ export * from './define-variable-plugin.js';
@@ -1 +1,27 @@
1
- import htmlWebpackPlugin from"html-webpack-plugin";const PLUGIN_PREFIX="HtmlInjectScriptPlugin";export class HtmlInjectScriptPlugin{constructor(t){this.scripts=t||[]}processScripts(){return this.scripts.filter(Boolean).map((t=>({tagName:"script",innerHTML:t,voidTag:!1,attributes:{},meta:{plugin:"html-inject-script-webpack-plugin"}})))}apply(t){t.hooks.compilation.tap(`${PLUGIN_PREFIX}_compilation`,(t=>{htmlWebpackPlugin.getHooks(t).alterAssetTags.tap(`${PLUGIN_PREFIX}_alterAssetTags`,(t=>(t.assetTags.scripts.unshift(...this.processScripts()),t)))}))}}
1
+ import htmlWebpackPlugin from 'html-webpack-plugin';
2
+ const PLUGIN_PREFIX = `HtmlInjectScriptPlugin`;
3
+ export class HtmlInjectScriptPlugin {
4
+ constructor(scripts) {
5
+ this.scripts = scripts || [];
6
+ }
7
+ processScripts() {
8
+ return this.scripts.filter(Boolean).map((asset) => {
9
+ return {
10
+ tagName: 'script',
11
+ innerHTML: asset,
12
+ voidTag: false,
13
+ attributes: {},
14
+ meta: { plugin: 'html-inject-script-webpack-plugin' },
15
+ };
16
+ });
17
+ }
18
+ apply(compiler) {
19
+ compiler.hooks.compilation.tap(`${PLUGIN_PREFIX}_compilation`, (compilation) => {
20
+ const hooks = htmlWebpackPlugin.getHooks(compilation);
21
+ hooks.alterAssetTags.tap(`${PLUGIN_PREFIX}_alterAssetTags`, (data) => {
22
+ data.assetTags.scripts.unshift(...this.processScripts());
23
+ return data;
24
+ });
25
+ });
26
+ }
27
+ }