@relative-ci/webpack-plugin 5.0.0-alpha.2

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.
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ var webpack = require('webpack');
4
+ var _ = require('lodash');
5
+ var core = require('@relative-ci/core');
6
+ var ingest = require('@relative-ci/core/ingest');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var webpack__default = /*#__PURE__*/_interopDefault(webpack);
11
+ var ___default = /*#__PURE__*/_interopDefault(_);
12
+ var ingest__default = /*#__PURE__*/_interopDefault(ingest);
13
+
14
+ const PLUGIN_NAME = 'RelativeCiAgent';
15
+ const DEFAULT_OPTIONS = {
16
+ includeCommitMessage: true,
17
+ payloadFilepath: null,
18
+ stats: {
19
+ assets: true,
20
+ chunks: true,
21
+ modules: true,
22
+ },
23
+ };
24
+ const isWebpack5 = parseInt(webpack__default.default.version, 10) === 5;
25
+ async function sendStats(compilation, options) {
26
+ const { stats: statsOptions, failOnError, ...config } = options;
27
+ const data = compilation.getStats().toJson(statsOptions);
28
+ const logger = compilation.compiler?.getInfrastructureLogger
29
+ ? compilation.compiler.getInfrastructureLogger(PLUGIN_NAME)
30
+ : console;
31
+ try {
32
+ core.validateWebpackStats(data);
33
+ const params = core.normalizeParams({}, config);
34
+ const artifactsData = core.filterArtifacts([{ key: core.SOURCE_WEBPACK_STATS, data }]);
35
+ const response = await ingest__default.default(artifactsData, params, config, logger);
36
+ core.logResponse(response);
37
+ }
38
+ catch (error) {
39
+ if (failOnError) {
40
+ compilation.errors.push(error);
41
+ }
42
+ else {
43
+ logger.warn(error); // catch error to prevent failure on error
44
+ }
45
+ }
46
+ }
47
+ class RelativeCiAgentWebpackPlugin {
48
+ constructor(options) {
49
+ this.options = options;
50
+ }
51
+ apply(compiler) {
52
+ const { isCi } = core.getEnvVars();
53
+ const options = ___default.default.merge({}, DEFAULT_OPTIONS, {
54
+ enabled: isCi,
55
+ }, this.options);
56
+ core.debug(options);
57
+ // Skip if not enabled
58
+ if (!options.enabled) {
59
+ core.debug(`${PLUGIN_NAME} is disabled, skip sending data`);
60
+ return;
61
+ }
62
+ if (isWebpack5) {
63
+ compiler.hooks.make.tap(PLUGIN_NAME, (compilation) => {
64
+ compilation.hooks.processAssets.tap({ name: PLUGIN_NAME, stage: webpack__default.default.Compilation.PROCESS_ASSETS_STAGE_REPORT }, () => sendStats(compilation, options));
65
+ });
66
+ return;
67
+ }
68
+ compiler.hooks.emit.tapAsync(PLUGIN_NAME, async (compilation, callback) => {
69
+ await sendStats(compilation, options);
70
+ callback();
71
+ });
72
+ }
73
+ }
74
+
75
+ exports.RelativeCiAgentWebpackPlugin = RelativeCiAgentWebpackPlugin;
76
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/index.ts"],"sourcesContent":[null],"names":["webpack","validateWebpackStats","normalizeParams","filterArtifacts","SOURCE_WEBPACK_STATS","ingest","logResponse","getEnvVars","_","debug"],"mappings":";;;;;;;;;;;;;AA4CA,MAAM,WAAW,GAAG,iBAAiB;AAErC,MAAM,eAAe,GAAG;AACtB,IAAA,oBAAoB,EAAE,IAAI;AAC1B,IAAA,eAAe,EAAE,IAAI;AACrB,IAAA,KAAK,EAAE;AACL,QAAA,MAAM,EAAE,IAAI;AACZ,QAAA,MAAM,EAAE,IAAI;AACZ,QAAA,OAAO,EAAE,IAAI;AACd,KAAA;CACF;AAED,MAAM,UAAU,GAAG,QAAQ,CAACA,wBAAO,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC;AAEtD,eAAe,SAAS,CACtB,WAAwB,EACxB,OAA4C,EAAA;AAE5C,IAAA,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,EAAE,GAAG,OAAO;IAC/D,MAAM,IAAI,GAAG,WAAW,CAAC,QAAQ,EAAE,CAAC,MAAM,CAA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I,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,WAAW,KAAI;AACnD,gBAAA,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CACjC,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAET,wBAAO,CAAC,WAAW,CAAC,2BAA2B,EAAE,EAC7E,MAAM,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CACtC;AACH,aAAC,CAAC;YAEF;;AAGF,QAAA,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAC1B,WAAW,EACX,OAAO,WAAW,EAAE,QAAQ,KAAI;AAC9B,YAAA,MAAM,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC;AACrC,YAAA,QAAQ,EAAE;AACZ,SAAC,CACF;;AAEJ;;;;"}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,68 @@
1
+ import webpack from 'webpack';
2
+ import _ from 'lodash';
3
+ import { getEnvVars, debug, validateWebpackStats, normalizeParams, filterArtifacts, SOURCE_WEBPACK_STATS, logResponse } from '@relative-ci/core';
4
+ import ingest from '@relative-ci/core/ingest';
5
+
6
+ const PLUGIN_NAME = 'RelativeCiAgent';
7
+ const DEFAULT_OPTIONS = {
8
+ includeCommitMessage: true,
9
+ payloadFilepath: null,
10
+ stats: {
11
+ assets: true,
12
+ chunks: true,
13
+ modules: true,
14
+ },
15
+ };
16
+ const isWebpack5 = parseInt(webpack.version, 10) === 5;
17
+ async function sendStats(compilation, options) {
18
+ const { stats: statsOptions, failOnError, ...config } = options;
19
+ const data = compilation.getStats().toJson(statsOptions);
20
+ const logger = compilation.compiler?.getInfrastructureLogger
21
+ ? compilation.compiler.getInfrastructureLogger(PLUGIN_NAME)
22
+ : console;
23
+ try {
24
+ validateWebpackStats(data);
25
+ const params = normalizeParams({}, config);
26
+ const artifactsData = filterArtifacts([{ key: SOURCE_WEBPACK_STATS, data }]);
27
+ const response = await ingest(artifactsData, params, config, logger);
28
+ logResponse(response);
29
+ }
30
+ catch (error) {
31
+ if (failOnError) {
32
+ compilation.errors.push(error);
33
+ }
34
+ else {
35
+ logger.warn(error); // catch error to prevent failure on error
36
+ }
37
+ }
38
+ }
39
+ class RelativeCiAgentWebpackPlugin {
40
+ constructor(options) {
41
+ this.options = options;
42
+ }
43
+ apply(compiler) {
44
+ const { isCi } = getEnvVars();
45
+ const options = _.merge({}, DEFAULT_OPTIONS, {
46
+ enabled: isCi,
47
+ }, this.options);
48
+ debug(options);
49
+ // Skip if not enabled
50
+ if (!options.enabled) {
51
+ debug(`${PLUGIN_NAME} is disabled, skip sending data`);
52
+ return;
53
+ }
54
+ if (isWebpack5) {
55
+ compiler.hooks.make.tap(PLUGIN_NAME, (compilation) => {
56
+ compilation.hooks.processAssets.tap({ name: PLUGIN_NAME, stage: webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT }, () => sendStats(compilation, options));
57
+ });
58
+ return;
59
+ }
60
+ compiler.hooks.emit.tapAsync(PLUGIN_NAME, async (compilation, callback) => {
61
+ await sendStats(compilation, options);
62
+ callback();
63
+ });
64
+ }
65
+ }
66
+
67
+ export { RelativeCiAgentWebpackPlugin };
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AA4CA,MAAM,WAAW,GAAG,iBAAiB;AAErC,MAAM,eAAe,GAAG;AACtB,IAAA,oBAAoB,EAAE,IAAI;AAC1B,IAAA,eAAe,EAAE,IAAI;AACrB,IAAA,KAAK,EAAE;AACL,QAAA,MAAM,EAAE,IAAI;AACZ,QAAA,MAAM,EAAE,IAAI;AACZ,QAAA,OAAO,EAAE,IAAI;AACd,KAAA;CACF;AAED,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC;AAEtD,eAAe,SAAS,CACtB,WAAwB,EACxB,OAA4C,EAAA;AAE5C,IAAA,MAA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CAAC,CAAA,EAAG,WAAW,CAAA,+BAAA,CAAiC,CAAC;YACtD;;QAGF,IAAI,UAAU,EAAE;AACd,YAAA,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,WAAW,KAAI;AACnD,gBAAA,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CACjC,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,2BAA2B,EAAE,EAC7E,MAAM,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CACtC;AACH,aAAC,CAAC;YAEF;;AAGF,QAAA,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAC1B,WAAW,EACX,OAAO,WAAW,EAAE,QAAQ,KAAI;AAC9B,YAAA,MAAM,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC;AACrC,YAAA,QAAQ,EAAE;AACZ,SAAC,CACF;;AAEJ;;;;"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,34 @@
1
+ import { type Compiler, type Configuration } from 'webpack';
2
+ import { type PluginConfig } from '@relative-ci/core';
3
+ type RelativeCiAgentWebpackPluginOptions = {
4
+ /**
5
+ * Plugin is enabled - sends data to RelativeCI
6
+ * @default env-ci isCi value
7
+ */
8
+ enabled?: boolean;
9
+ /**
10
+ * Throw error when validation or ingestion fails
11
+ * @default {false}
12
+ */
13
+ failOnError?: boolean;
14
+ /**
15
+ * Read commit message from git
16
+ * @default true
17
+ */
18
+ includeCommitMessage?: PluginConfig['includeCommitMessage'];
19
+ /**
20
+ * Output payload on a local file for debugging
21
+ */
22
+ payloadFilepath?: PluginConfig['payloadFilepath'];
23
+ /**
24
+ * Webpack stats options
25
+ * @default assets, chunks, modules
26
+ */
27
+ stats?: Configuration['stats'];
28
+ };
29
+ export declare class RelativeCiAgentWebpackPlugin {
30
+ options: RelativeCiAgentWebpackPluginOptions;
31
+ constructor(options: RelativeCiAgentWebpackPluginOptions);
32
+ apply(compiler: Compiler): void;
33
+ }
34
+ export {};
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@relative-ci/webpack-plugin",
3
+ "version": "5.0.0-alpha.2",
4
+ "description": "Webpack plugin that sends bundle stats and CI build information to RelativeCI",
5
+ "keywords": [
6
+ "webpack",
7
+ "vitejs",
8
+ "rspack",
9
+ "rollup",
10
+ "bundle-size",
11
+ "bundle-analyzer",
12
+ "bundle-stats",
13
+ "stats",
14
+ "bundle",
15
+ "size",
16
+ "assets",
17
+ "chunks",
18
+ "modules"
19
+ ],
20
+ "repository": "https://github.com/relative-ci/agent",
21
+ "bugs": {
22
+ "url": "https://github.com/relative-ci/agent/issues"
23
+ },
24
+ "homepage": "https://relative-ci.com/documentation/setup",
25
+ "license": "MIT",
26
+ "author": {
27
+ "name": "Viorel Cojocaru",
28
+ "email": "vio@relative-ci.com",
29
+ "url": "https://relative-ci.com"
30
+ },
31
+ "engines": {
32
+ "node": ">= 18.0.0"
33
+ },
34
+ "main": "./lib/cjs/index.js",
35
+ "module": "./lib/esm/index.js",
36
+ "types": "./lib/types/index.d.ts",
37
+ "scripts": {
38
+ "build": "npm run clean && rollup -c && npm run build-type",
39
+ "build-type": "echo '{\"type\":\"commonjs\"}' > lib/cjs/package.json && echo '{\"type\":\"module\"}' > lib/esm/package.json",
40
+ "clean": "rimraf ./lib",
41
+ "clean-deps": "rimraf ./test/webpack/*/node_modules ./node_modules",
42
+ "lint": "eslint .",
43
+ "test": "vitest src --passWithNoTests --run"
44
+ },
45
+ "devDependencies": {
46
+ "@rollup/plugin-commonjs": "28.0.3",
47
+ "@rollup/plugin-node-resolve": "16.0.0",
48
+ "@rollup/plugin-replace": "6.0.2",
49
+ "@rollup/plugin-typescript": "12.1.2",
50
+ "@tsconfig/node18": "^18.2.4",
51
+ "@types/lodash": "4.17.16",
52
+ "memory-fs": "0.5.0",
53
+ "rimraf": "6.0.1",
54
+ "rollup": "4.35.0",
55
+ "rollup-plugin-node-externals": "8.0.0",
56
+ "typescript": "5.8.2",
57
+ "vitest": "3.0.8",
58
+ "webpack": "5.98.0"
59
+ },
60
+ "dependencies": {
61
+ "@relative-ci/core": "*",
62
+ "lodash": "4.17.21"
63
+ },
64
+ "peerDependencies": {
65
+ "webpack": "^4.0.0 || ^5.0.0-rc.1"
66
+ }
67
+ }