dotcom-tool-kit 4.9.0 → 4.10.1

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/bin/run CHANGED
@@ -30,7 +30,7 @@ async function main() {
30
30
  const showHelp = require('../lib/help').default
31
31
  await showHelp(rootLogger, argv._)
32
32
  } else {
33
- const { runTasks } = require('../lib')
33
+ const { runCommands } = require('../lib')
34
34
  if (argv['--'].length > 0) {
35
35
  // The `--` in a command such as `dotcom-tool-kit test:staged --`
36
36
  // delineates between hooks and file patterns. For example, when the
@@ -39,9 +39,9 @@ async function main() {
39
39
  // the command becomes something like `dotcom-tool-kit test:staged --
40
40
  // index.js`. When this command is executed it runs the configured task
41
41
  // where the file path arguments would then be extracted.
42
- await runTasks(rootLogger, argv._, argv['--'])
42
+ await runCommands(rootLogger, argv._, argv['--'])
43
43
  } else {
44
- await runTasks(rootLogger, argv._)
44
+ await runCommands(rootLogger, argv._)
45
45
  }
46
46
  }
47
47
  } catch (error) {
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Logger } from 'winston';
2
- export { runTasks } from './tasks';
2
+ export { runCommands } from './tasks';
3
3
  export { shouldDisableNativeFetch } from './fetch';
4
4
  export declare function listPlugins(logger: Logger): Promise<void>;
5
5
  export declare function printConfig(logger: Logger): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAKrC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAElD,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAO/D;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAI/D;AAED,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBtE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAKrC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAElD,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAO/D;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAI/D;AAED,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBtE"}
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shouldDisableNativeFetch = exports.runTasks = void 0;
3
+ exports.shouldDisableNativeFetch = exports.runCommands = void 0;
4
4
  exports.listPlugins = listPlugins;
5
5
  exports.printConfig = printConfig;
6
6
  exports.printMergedOptions = printMergedOptions;
@@ -10,7 +10,7 @@ const util_1 = tslib_1.__importDefault(require("util"));
10
10
  const messages_1 = require("./messages");
11
11
  const install_1 = require("./install");
12
12
  var tasks_1 = require("./tasks");
13
- Object.defineProperty(exports, "runTasks", { enumerable: true, get: function () { return tasks_1.runTasks; } });
13
+ Object.defineProperty(exports, "runCommands", { enumerable: true, get: function () { return tasks_1.runCommands; } });
14
14
  var fetch_1 = require("./fetch");
15
15
  Object.defineProperty(exports, "shouldDisableNativeFetch", { enumerable: true, get: function () { return fetch_1.shouldDisableNativeFetch; } });
16
16
  async function listPlugins(logger) {
@@ -2,10 +2,11 @@ import type { Base } from '@dotcom-tool-kit/base';
2
2
  import type { EntryPoint } from '@dotcom-tool-kit/plugin';
3
3
  import { Validated } from '@dotcom-tool-kit/validated';
4
4
  import type * as z from 'zod';
5
+ import type { ReadonlyDeep } from 'type-fest';
5
6
  export declare function importSchemaEntryPoint(entryPoint: EntryPoint, exportName?: string): Promise<Validated<z.ZodSchema>>;
6
7
  export declare function importEntryPoint<T extends {
7
8
  name: string;
8
- } & Omit<typeof Base, 'new'>>(type: T, entryPoint: EntryPoint): Promise<Validated<{
9
+ } & Omit<typeof Base, 'new'>>(type: T, entryPoint: ReadonlyDeep<EntryPoint>): Promise<Validated<{
9
10
  baseClass: T;
10
11
  schema?: z.ZodSchema;
11
12
  }>>;
@@ -1 +1 @@
1
- {"version":3,"file":"entry-point.d.ts","sourceRoot":"","sources":["../../src/plugin/entry-point.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,SAAS,EAAkB,MAAM,4BAA4B,CAAA;AAEtE,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAA;AAsC7B,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,UAAU,EACtB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAYjC;AAID,wBAAsB,gBAAgB,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,KAAK,CAAC,EAC1F,IAAI,EAAE,CAAC,EACP,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,SAAS,CAAC;IAAE,SAAS,EAAE,CAAC,CAAC;IAAC,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS,CAAA;CAAE,CAAC,CAAC,CAiC5D"}
1
+ {"version":3,"file":"entry-point.d.ts","sourceRoot":"","sources":["../../src/plugin/entry-point.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,SAAS,EAAkB,MAAM,4BAA4B,CAAA;AAEtE,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAA;AAE7B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAqC7C,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,UAAU,EACtB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAYjC;AAID,wBAAsB,gBAAgB,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,KAAK,CAAC,EAC1F,IAAI,EAAE,CAAC,EACP,UAAU,EAAE,YAAY,CAAC,UAAU,CAAC,GACnC,OAAO,CAAC,SAAS,CAAC;IAAE,SAAS,EAAE,CAAC,CAAC;IAAC,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS,CAAA;CAAE,CAAC,CAAC,CAiC5D"}
package/lib/tasks.d.ts CHANGED
@@ -1,5 +1,16 @@
1
1
  import type { ValidConfig } from '@dotcom-tool-kit/config';
2
+ import { Task } from '@dotcom-tool-kit/base';
3
+ import { Validated } from '@dotcom-tool-kit/validated';
2
4
  import type { Logger } from 'winston';
3
- export declare function runTasksFromConfig(logger: Logger, config: ValidConfig, commands: string[], files?: string[]): Promise<void>;
4
- export declare function runTasks(logger: Logger, commands: string[], files?: string[]): Promise<void>;
5
+ import { OptionsForTask } from '@dotcom-tool-kit/plugin';
6
+ import type { ReadonlyDeep } from 'type-fest';
7
+ export type ErrorSummary = {
8
+ task: string;
9
+ error: Error;
10
+ };
11
+ export declare function loadTasks(logger: Logger, tasks: OptionsForTask[], config: ReadonlyDeep<ValidConfig>): Promise<Validated<Task[]>>;
12
+ export declare function handleTaskErrors(errors: ErrorSummary[], command: string): void;
13
+ export declare function runTasks(logger: Logger, config: ValidConfig, tasks: Task[], command: string, files?: string[]): Promise<void>;
14
+ export declare function runCommandsFromConfig(logger: Logger, config: ValidConfig, commands: string[], files?: string[]): Promise<void>;
15
+ export declare function runCommands(logger: Logger, commands: string[], files?: string[]): Promise<void>;
5
16
  //# sourceMappingURL=tasks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../src/tasks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAG1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAyDrC,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,MAAM,EAAE,EAClB,KAAK,CAAC,EAAE,MAAM,EAAE,GACf,OAAO,CAAC,IAAI,CAAC,CA8Df;AAED,wBAAsB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAIlG"}
1
+ {"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../src/tasks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,IAAI,EAAmB,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAmC,MAAM,4BAA4B,CAAA;AACvF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAUrC,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAGxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAE7C,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,wBAAsB,SAAS,CAC7B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,cAAc,EAAE,EACvB,MAAM,EAAE,YAAY,CAAC,WAAW,CAAC,GAChC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAiC5B;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,EAAE,EAAE,OAAO,EAAE,MAAM,QAQvE;AAED,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,IAAI,EAAE,EACb,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,EAAE,iBA8BjB;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,MAAM,EAAE,EAClB,KAAK,CAAC,EAAE,MAAM,EAAE,GACf,OAAO,CAAC,IAAI,CAAC,CA6Bf;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAIrG"}
package/lib/tasks.js CHANGED
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runTasksFromConfig = runTasksFromConfig;
3
+ exports.loadTasks = loadTasks;
4
+ exports.handleTaskErrors = handleTaskErrors;
4
5
  exports.runTasks = runTasks;
6
+ exports.runCommandsFromConfig = runCommandsFromConfig;
7
+ exports.runCommands = runCommands;
5
8
  const tslib_1 = require("tslib");
6
9
  const base_1 = require("@dotcom-tool-kit/base");
7
10
  const validated_1 = require("@dotcom-tool-kit/validated");
@@ -15,8 +18,8 @@ const init_1 = require("./init");
15
18
  const messages_1 = require("./messages");
16
19
  const schemas_1 = require("@dotcom-tool-kit/schemas");
17
20
  const pluralize_1 = tslib_1.__importDefault(require("pluralize"));
18
- const loadTasks = async (logger, tasks, config) => {
19
- const taskResults = await Promise.all(tasks.map(async ({ task: taskId, options }) => {
21
+ async function loadTasks(logger, tasks, config) {
22
+ const taskResults = await Promise.all(tasks.map(async ({ task: taskId, options, plugin }) => {
20
23
  const entryPoint = config.tasks[taskId];
21
24
  const taskResult = await (0, entry_point_1.importEntryPoint)(base_1.Task, entryPoint);
22
25
  return taskResult.flatMap((taskModule) => {
@@ -27,7 +30,7 @@ const loadTasks = async (logger, tasks, config) => {
27
30
  data: mergedOptions
28
31
  };
29
32
  if (parsedOptions.success) {
30
- const task = new taskModule.baseClass(logger, taskId, config.pluginOptions[entryPoint.plugin.id]?.options ?? {}, parsedOptions.data);
33
+ const task = new taskModule.baseClass(logger, taskId, config.pluginOptions[entryPoint.plugin.id]?.options ?? {}, parsedOptions.data, plugin);
31
34
  return (0, validated_1.valid)(task);
32
35
  }
33
36
  else {
@@ -36,8 +39,41 @@ const loadTasks = async (logger, tasks, config) => {
36
39
  });
37
40
  }));
38
41
  return (0, validated_1.reduceValidated)(taskResults);
39
- };
40
- async function runTasksFromConfig(logger, config, commands, files) {
42
+ }
43
+ function handleTaskErrors(errors, command) {
44
+ throw new AggregateError(errors.map(({ task, error }) => {
45
+ error.name = `${logger_1.styles.task(task)} → ${error.name}`;
46
+ return error;
47
+ }), `${(0, pluralize_1.default)('error', errors.length, true)} running tasks for ${logger_1.styles.command(command)}`);
48
+ }
49
+ async function runTasks(logger, config, tasks, command, files) {
50
+ const errors = [];
51
+ if (tasks.length === 0) {
52
+ logger.warn(`no task configured for ${command}: skipping assignment...`);
53
+ }
54
+ for (const task of tasks) {
55
+ try {
56
+ logger.info(logger_1.styles.taskHeader(`running ${logger_1.styles.task(task.id)} task`));
57
+ await task.run({ files, command, cwd: config.root, config });
58
+ }
59
+ catch (error) {
60
+ // if there's an exit code, that's a request from the task to exit early
61
+ if (error instanceof error_1.ToolKitError && error.exitCode) {
62
+ throw error;
63
+ }
64
+ // if not, we allow subsequent hook tasks to run on error
65
+ // TODO use validated for this
66
+ errors.push({
67
+ task: task.id,
68
+ error: error
69
+ });
70
+ }
71
+ }
72
+ if (errors.length > 0) {
73
+ handleTaskErrors(errors, command);
74
+ }
75
+ }
76
+ async function runCommandsFromConfig(logger, config, commands, files) {
41
77
  await (0, init_1.runInit)(logger, config);
42
78
  await (0, install_1.checkInstall)(logger, config);
43
79
  if ((0, fetch_1.shouldDisableNativeFetch)(config.pluginOptions['app root'].options) &&
@@ -53,37 +89,10 @@ async function runTasksFromConfig(logger, config, commands, files) {
53
89
  // passing it into task run contexts so that plugins can't do crimes
54
90
  Object.freeze(config);
55
91
  for (const { command, tasks } of commandTasks) {
56
- const errors = [];
57
- if (tasks.length === 0) {
58
- logger.warn(`no task configured for ${command}: skipping assignment...`);
59
- }
60
- for (const task of tasks) {
61
- try {
62
- logger.info(logger_1.styles.taskHeader(`running ${logger_1.styles.task(task.id)} task`));
63
- await task.run({ files, command, cwd: config.root, config });
64
- }
65
- catch (error) {
66
- // if there's an exit code, that's a request from the task to exit early
67
- if (error instanceof error_1.ToolKitError && error.exitCode) {
68
- throw error;
69
- }
70
- // if not, we allow subsequent hook tasks to run on error
71
- // TODO use validated for this
72
- errors.push({
73
- task: task.id,
74
- error: error
75
- });
76
- }
77
- }
78
- if (errors.length > 0) {
79
- throw new AggregateError(errors.map(({ task, error }) => {
80
- error.name = `${logger_1.styles.task(task)} → ${error.name}`;
81
- return error;
82
- }), `${(0, pluralize_1.default)('error', errors.length, true)} running tasks for ${logger_1.styles.command(command)}`);
83
- }
92
+ await runTasks(logger, config, tasks, command, files);
84
93
  }
85
94
  }
86
- async function runTasks(logger, commands, files) {
95
+ async function runCommands(logger, commands, files) {
87
96
  const config = await (0, config_1.loadConfig)(logger, { root: process.cwd() });
88
- return runTasksFromConfig(logger, config, commands, files);
97
+ return runCommandsFromConfig(logger, config, commands, files);
89
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dotcom-tool-kit",
3
- "version": "4.9.0",
3
+ "version": "4.10.1",
4
4
  "description": "modern, maintainable, modular developer tooling for FT.com projects",
5
5
  "author": "FT.com Platforms Team <platforms-team.customer-products@ft.com>",
6
6
  "license": "MIT",
@@ -25,11 +25,12 @@
25
25
  "@types/lodash": "^4.17.20",
26
26
  "@types/pluralize": "^0.0.33",
27
27
  "globby": "^10.0.2",
28
+ "type-fest": "^4.41.0",
28
29
  "winston": "^3.17.0",
29
30
  "zod": "^3.24.4"
30
31
  },
31
32
  "dependencies": {
32
- "@dotcom-tool-kit/base": "^1.2.3",
33
+ "@dotcom-tool-kit/base": "^1.3.1",
33
34
  "@dotcom-tool-kit/config": "^1.1.1",
34
35
  "@dotcom-tool-kit/conflict": "^1.0.1",
35
36
  "@dotcom-tool-kit/error": "^4.1.1",