@dotcom-tool-kit/webpack 3.2.0 → 4.0.0-beta.0

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/.toolkitrc.yml CHANGED
@@ -1,5 +1,10 @@
1
- hooks:
2
- 'build:local': WebpackDevelopment
3
- 'build:ci': WebpackProduction
4
- 'build:remote': WebpackProduction
5
- 'run:local': WebpackWatch
1
+ tasks:
2
+ Webpack: './lib/tasks/webpack'
3
+
4
+ commands:
5
+ 'build:local': Webpack
6
+ 'build:ci': Webpack
7
+ 'build:remote': Webpack
8
+ 'run:local': Webpack
9
+
10
+ version: 2
@@ -0,0 +1,8 @@
1
+ import { type WebpackSchema } from '@dotcom-tool-kit/schemas/lib/tasks/webpack';
2
+ import { Task } from '@dotcom-tool-kit/base';
3
+ export default class Webpack extends Task<{
4
+ task: typeof WebpackSchema;
5
+ }> {
6
+ run(): Promise<void>;
7
+ }
8
+ //# sourceMappingURL=webpack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.d.ts","sourceRoot":"","sources":["../../src/tasks/webpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,4CAA4C,CAAA;AAC/E,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAM5C,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,IAAI,CAAC;IAAE,IAAI,EAAE,OAAO,aAAa,CAAA;CAAE,CAAC;IACjE,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAuB3B"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const base_1 = require("@dotcom-tool-kit/base");
4
+ const logger_1 = require("@dotcom-tool-kit/logger");
5
+ const child_process_1 = require("child_process");
6
+ const webpackCLIPath = require.resolve('webpack-cli/bin/cli');
7
+ class Webpack extends base_1.Task {
8
+ async run() {
9
+ this.logger.info('starting Webpack...');
10
+ const args = ['build', '--color', `--mode=${this.options.envName}`];
11
+ if (this.options.configPath) {
12
+ args.push(`--config=${this.options.configPath}`);
13
+ }
14
+ if (this.options.watch) {
15
+ args.push('--watch');
16
+ }
17
+ let { execArgv } = process;
18
+ if (process.allowedNodeEnvironmentFlags.has('--openssl-legacy-provider')) {
19
+ // webpack 4 uses a legacy hashing function that is no longer provided by
20
+ // default in OpenSSL 3: https://github.com/webpack/webpack/issues/14532
21
+ execArgv = [...execArgv, '--openssl-legacy-provider'];
22
+ }
23
+ const child = (0, child_process_1.fork)(webpackCLIPath, args, { silent: true, execArgv });
24
+ (0, logger_1.hookFork)(this.logger, 'webpack', child);
25
+ return (0, logger_1.waitOnExit)('webpack', child);
26
+ }
27
+ }
28
+ exports.default = Webpack;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcom-tool-kit/webpack",
3
- "version": "3.2.0",
3
+ "version": "4.0.0-beta.0",
4
4
  "main": "lib",
5
5
  "description": "",
6
6
  "author": "FT.com Platforms Team <platforms-team.customer-products@ft.com>",
@@ -17,17 +17,18 @@
17
17
  "test": "cd ../../ ; npx jest --silent --projects plugins/webpack"
18
18
  },
19
19
  "dependencies": {
20
- "@dotcom-tool-kit/error": "^3.2.0",
21
- "@dotcom-tool-kit/logger": "^3.4.0",
22
- "@dotcom-tool-kit/types": "^3.6.0",
20
+ "@dotcom-tool-kit/base": "4.0.0-beta.0",
21
+ "@dotcom-tool-kit/error": "4.0.0-beta.0",
22
+ "@dotcom-tool-kit/logger": "4.0.0-beta.0",
23
23
  "webpack-cli": "^4.6.0",
24
24
  "tslib": "^2.3.1"
25
25
  },
26
26
  "peerDependencies": {
27
- "webpack": "4.x.x || 5.x.x",
28
- "dotcom-tool-kit": "3.x"
27
+ "dotcom-tool-kit": "4.0.0-beta.0",
28
+ "webpack": "4.x.x || 5.x.x"
29
29
  },
30
30
  "devDependencies": {
31
+ "@dotcom-tool-kit/schemas": "2.0.0-beta.0",
31
32
  "@jest/globals": "^27.4.6",
32
33
  "ts-node": "^10.0.0",
33
34
  "webpack": "^4.42.1",
@@ -41,7 +42,7 @@
41
42
  "extends": "../../package.json"
42
43
  },
43
44
  "engines": {
44
- "node": "16.x || 18.x || 20.x",
45
+ "node": "18.x || 20.x",
45
46
  "npm": "7.x || 8.x || 9.x || 10.x"
46
47
  }
47
48
  }
package/readme.md CHANGED
@@ -17,37 +17,40 @@ plugins:
17
17
  - '@dotcom-tool-kit/webpack'
18
18
  ```
19
19
 
20
- You will need plugins that provides hooks to run the `Webpack*` tasks.
21
-
22
20
  ### Building with Webpack locally
23
21
 
24
- For local development, by default the `WebpackDevelopment` task runs on the `build:local` hook, and `WebpackWatch` runs on `run:local`. One plugin that provides these hooks is [`npm`](../npm), allowing you to run Webpack with `npm run build` and `npm start`. `WebpackWatch` runs Webpack in the background, allowing it to run alongside your other tasks that run on `run:local`, which lets you run e.g. your app with the [`node`](../node) plugin in parallel with Webpack.
22
+ For local development, by default the `WebpackDevelopment` task runs on the `build:local` command, and `WebpackWatch` runs on `run:local`. One plugin that provides these commands is [`npm`](../npm), allowing you to run Webpack with `npm run build` and `npm start`. `WebpackWatch` runs Webpack in the background, allowing it to run alongside your other tasks that run on `run:local`, which lets you run e.g. your app with the [`node`](../node) plugin in parallel with Webpack.
25
23
 
26
24
  ### Building with Webpack on CI and remote apps
27
25
 
28
- The `WebpackProduction` task runs on the `build:ci` and `build:remote` hooks by default. `build:ci` is for compiling an app's source in CI jobs, and is provided by plugins like [`circleci`](../circleci/). `build:remote` compiles an app for running on a production or testing server, and can be provided by plugins like [`heroku`](../heroku/).
26
+ The `WebpackProduction` task runs on the `build:ci` and `build:remote` commands by default. `build:ci` is for compiling an app's source in CI jobs, and is provided by plugins like [`circleci`](../circleci/). `build:remote` compiles an app for running on a production or testing server, and can be provided by plugins like [`heroku`](../heroku/).
29
27
 
30
- ### Running on another hook
31
- You can also configure Webpack to run on any other hook; for example, if you want to run it with `npm run test` via the `npm` plugin, you can manually configure Webpack to run on `npm`'s `test:local` hook:
28
+ ### Running on another command
29
+ You can also configure Webpack to run on any other command; for example, if you want to run it with `npm run test` via the `npm` plugin, you can manually configure Webpack to run on `npm`'s `test:local` command:
32
30
 
33
31
  ```yml
34
32
  plugins:
35
33
  - '@dotcom-tool-kit/webpack'
36
34
  - '@dotcom-tool-kit/npm'
37
- hooks:
38
- 'test:local': WebpackDevelopment
35
+ command:
36
+ 'test:local':
37
+ Webpack:
38
+ mode: development
39
39
  ```
40
40
 
41
- ## Options
41
+ <!-- begin autogenerated docs -->
42
+ ## Tasks
43
+
44
+ ### `Webpack`
42
45
 
43
- | Key | Description | Default value |
44
- |-|-|-|
45
- | `configPath` | An optional path to your Webpack config file | none |
46
+ Bundle code with `webpack`.
47
+ #### Task options
46
48
 
47
- ## Tasks
49
+ | Property | Description | Type |
50
+ | :----------------- | :-------------------------------------------------------------------------- | :------------------------------ |
51
+ | `configPath` | path to a Webpack config file. Webpack will default to `webpack.config.js`. | `string` |
52
+ | **`envName`** (\*) | set Webpack's [mode](https://webpack.js.org/configuration/mode/). | `'production' \| 'development'` |
53
+ | `watch` | run Webpack in watch mode | `boolean` |
48
54
 
49
- | Task | Description | Default hooks |
50
- |-|-|-|
51
- | `WebpackDevelopment` | Run Webpack in development mode | `build:local` |
52
- | `WebpackProduction` | Run Webpack in production mode | `build:ci`, `build:remote` |
53
- | `WebpackWatch` | Run Webpack in watch mode in the background | `run:local` |
55
+ _(\*) Required._
56
+ <!-- end autogenerated docs -->
package/lib/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import WebpackDevelopment from './tasks/development';
2
- export declare const tasks: (typeof WebpackDevelopment)[];
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,qBAAqB,CAAA;AAIpD,eAAO,MAAM,KAAK,+BAAwD,CAAA"}
package/lib/index.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tasks = void 0;
4
- const tslib_1 = require("tslib");
5
- const development_1 = tslib_1.__importDefault(require("./tasks/development"));
6
- const production_1 = tslib_1.__importDefault(require("./tasks/production"));
7
- const watch_1 = tslib_1.__importDefault(require("./tasks/watch"));
8
- exports.tasks = [development_1.default, production_1.default, watch_1.default];
@@ -1,8 +0,0 @@
1
- import { Logger } from 'winston';
2
- import type { WebpackOptions } from '@dotcom-tool-kit/types/lib/schema/webpack';
3
- export interface RunWebpackOptions {
4
- mode: 'production' | 'development';
5
- watch?: boolean;
6
- }
7
- export default function runWebpack(logger: Logger, options: WebpackOptions & RunWebpackOptions): Promise<void>;
8
- //# sourceMappingURL=run-webpack.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"run-webpack.d.ts","sourceRoot":"","sources":["../src/run-webpack.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAA;AAK/E,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,YAAY,GAAG,aAAa,CAAA;IAClC,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,cAAc,GAAG,iBAAiB,GAC1C,OAAO,CAAC,IAAI,CAAC,CAsBf"}
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const child_process_1 = require("child_process");
4
- const logger_1 = require("@dotcom-tool-kit/logger");
5
- const webpackCLIPath = require.resolve('webpack-cli/bin/cli');
6
- function runWebpack(logger, options) {
7
- logger.info('starting Webpack...');
8
- const args = ['build', '--color', `--mode=${options.mode}`];
9
- if (options.configPath) {
10
- args.push(`--config=${options.configPath}`);
11
- }
12
- if (options.watch) {
13
- args.push('--watch');
14
- }
15
- let { execArgv } = process;
16
- if (process.allowedNodeEnvironmentFlags.has('--openssl-legacy-provider')) {
17
- // webpack 4 uses a legacy hashing function that is no longer provided by
18
- // default in OpenSSL 3: https://github.com/webpack/webpack/issues/14532
19
- execArgv = [...execArgv, '--openssl-legacy-provider'];
20
- }
21
- const child = (0, child_process_1.fork)(webpackCLIPath, args, { silent: true, execArgv });
22
- (0, logger_1.hookFork)(logger, 'webpack', child);
23
- return (0, logger_1.waitOnExit)('webpack', child);
24
- }
25
- exports.default = runWebpack;
@@ -1,7 +0,0 @@
1
- import { Task } from '@dotcom-tool-kit/types';
2
- import { WebpackSchema } from '@dotcom-tool-kit/types/lib/schema/webpack';
3
- export default class WebpackDevelopment extends Task<typeof WebpackSchema> {
4
- static description: string;
5
- run(): Promise<void>;
6
- }
7
- //# sourceMappingURL=development.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"development.d.ts","sourceRoot":"","sources":["../../src/tasks/development.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAA;AAGzE,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,IAAI,CAAC,OAAO,aAAa,CAAC;IACxE,MAAM,CAAC,WAAW,SAAoC;IAEhD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAM3B"}
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const types_1 = require("@dotcom-tool-kit/types");
5
- const run_webpack_1 = tslib_1.__importDefault(require("../run-webpack"));
6
- class WebpackDevelopment extends types_1.Task {
7
- async run() {
8
- await (0, run_webpack_1.default)(this.logger, {
9
- ...this.options,
10
- mode: 'development'
11
- });
12
- }
13
- }
14
- exports.default = WebpackDevelopment;
15
- WebpackDevelopment.description = 'Run Webpack in development mode';
@@ -1,7 +0,0 @@
1
- import { Task } from '@dotcom-tool-kit/types';
2
- import { WebpackSchema } from '@dotcom-tool-kit/types/lib/schema/webpack';
3
- export default class WebpackProduction extends Task<typeof WebpackSchema> {
4
- static description: string;
5
- run(): Promise<void>;
6
- }
7
- //# sourceMappingURL=production.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"production.d.ts","sourceRoot":"","sources":["../../src/tasks/production.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAA;AAGzE,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,IAAI,CAAC,OAAO,aAAa,CAAC;IACvE,MAAM,CAAC,WAAW,SAAmC;IAE/C,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAM3B"}
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const types_1 = require("@dotcom-tool-kit/types");
5
- const run_webpack_1 = tslib_1.__importDefault(require("../run-webpack"));
6
- class WebpackProduction extends types_1.Task {
7
- async run() {
8
- await (0, run_webpack_1.default)(this.logger, {
9
- ...this.options,
10
- mode: 'production'
11
- });
12
- }
13
- }
14
- exports.default = WebpackProduction;
15
- WebpackProduction.description = 'Run Webpack in production mode';
@@ -1,7 +0,0 @@
1
- import { Task } from '@dotcom-tool-kit/types';
2
- import { WebpackSchema } from '@dotcom-tool-kit/types/lib/schema/webpack';
3
- export default class WebpackWatch extends Task<typeof WebpackSchema> {
4
- static description: string;
5
- run(): Promise<void>;
6
- }
7
- //# sourceMappingURL=watch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/tasks/watch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAA;AAGzE,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,IAAI,CAAC,OAAO,aAAa,CAAC;IAClE,MAAM,CAAC,WAAW,SAAgD;IAE5D,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ3B"}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const types_1 = require("@dotcom-tool-kit/types");
5
- const run_webpack_1 = tslib_1.__importDefault(require("../run-webpack"));
6
- class WebpackWatch extends types_1.Task {
7
- async run() {
8
- // don't wait for Webpack to exit, to leave it running in the background
9
- (0, run_webpack_1.default)(this.logger, {
10
- ...this.options,
11
- mode: 'development',
12
- watch: true
13
- });
14
- }
15
- }
16
- exports.default = WebpackWatch;
17
- WebpackWatch.description = 'Run Webpack in watch mode in the background';