dotcom-tool-kit 4.4.2 → 4.5.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.
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAUrC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAgBpF,eAAO,MAAM,YAAY,SAAU,MAAM,KAAG,SAgB1C,CAAA;AAEF,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,GAAG,WAAW,CA6FtE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE;IAAE,QAAQ,CAAC,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;AAC5G,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAUrC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAgBpF,eAAO,MAAM,YAAY,SAAU,MAAM,KAAG,SAgB1C,CAAA;AAEF,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,GAAG,WAAW,CA4FtE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE;IAAE,QAAQ,CAAC,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;AAC5G,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA"}
package/lib/config.js CHANGED
@@ -103,7 +103,7 @@ async function loadConfig(logger, { validate = true, root }) {
103
103
  // start with options so we can substitute resolved values into other parts
104
104
  // of the config
105
105
  (0, plugin_1.resolvePluginOptions)(validRootPlugin, validPluginConfig);
106
- const invalidOptions = (0, options_1.validatePluginOptions)(logger, validPluginConfig);
106
+ const invalidOptions = await (0, options_1.validatePluginOptions)(logger, validPluginConfig);
107
107
  if (invalidOptions.length > 0 && validate) {
108
108
  const error = new error_1.ToolKitError(`There are options in your ${logger_1.styles.filepath('.toolkitrc.yml')} that aren't what Tool Kit expected.`);
109
109
  error.details = (0, messages_1.formatInvalidPluginOptions)(invalidOptions);
package/lib/fetch.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { RootOptions } from '@dotcom-tool-kit/schemas/src/plugins/dotcom-tool-kit';
1
+ import type { RootOptions } from '@dotcom-tool-kit/plugin/src/root-schema';
2
2
  export declare const shouldDisableNativeFetch: (options: RootOptions) => boolean;
3
3
  //# sourceMappingURL=fetch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sDAAsD,CAAA;AAIlF,eAAO,MAAM,wBAAwB,YAAa,WAAW,KAAG,OAK/D,CAAA"}
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAA;AAI1E,eAAO,MAAM,wBAAwB,YAAa,WAAW,KAAG,OAK/D,CAAA"}
package/lib/init.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAG1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAWrC,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAKhF"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAG1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAarC,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAKhF"}
package/lib/init.js CHANGED
@@ -5,8 +5,8 @@ const base_1 = require("@dotcom-tool-kit/base");
5
5
  const validated_1 = require("@dotcom-tool-kit/validated");
6
6
  const entry_point_1 = require("./plugin/entry-point");
7
7
  const loadInitEntrypoints = async (logger, config) => {
8
- const initClassResults = (0, validated_1.reduceValidated)(await Promise.all(config.inits.map((entryPoint) => (0, entry_point_1.importEntryPoint)(base_1.Init, entryPoint))));
9
- return initClassResults.map((initClasses) => initClasses.map((initClass) => new initClass(logger)));
8
+ const initModuleResults = (0, validated_1.reduceValidated)(await Promise.all(config.inits.map((entryPoint) => (0, entry_point_1.importEntryPoint)(base_1.Init, entryPoint))));
9
+ return initModuleResults.map((initModules) => initModules.map((initModule) => new initModule.baseClass(logger)));
10
10
  };
11
11
  async function runInit(logger, config) {
12
12
  const initResults = await loadInitEntrypoints(logger, config);
@@ -1 +1 @@
1
- {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAGrC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,IAAI,EAAa,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,SAAS,EAAmC,MAAM,4BAA4B,CAAA;AAyCvF,eAAO,MAAM,qBAAqB,WACxB,MAAM,UACN,WAAW,KAClB,QAAQ,UAAU,IAAI,EAAE,CAAC,CA2C3B,CAAA;AAED,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBrF;AAED,wBAA8B,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAiD/E"}
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAGrC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,IAAI,EAAa,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,SAAS,EAAmC,MAAM,4BAA4B,CAAA;AA0CvF,eAAO,MAAM,qBAAqB,WACxB,MAAM,UACN,WAAW,KAClB,QAAQ,UAAU,IAAI,EAAE,CAAC,CAsC3B,CAAA;AAED,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBrF;AAED,wBAA8B,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAiD/E"}
package/lib/install.js CHANGED
@@ -31,8 +31,8 @@ async function asyncFilter(items, predicate) {
31
31
  }
32
32
  const loadHookEntrypoints = async (logger, config) => {
33
33
  const hookResultEntries = (0, validated_1.reduceValidated)(await Promise.all(Object.entries(config.hooks).map(async ([hookName, entryPoint]) => {
34
- const hookResult = await (0, entry_point_1.importEntryPoint)(base_1.Hook, entryPoint);
35
- return hookResult.map((hookClass) => [hookName, hookClass]);
34
+ const hookModule = await (0, entry_point_1.importEntryPoint)(base_1.Hook, entryPoint);
35
+ return hookModule.map(({ baseClass, schema }) => [hookName, { hookClass: baseClass, schema }]);
36
36
  })));
37
37
  return hookResultEntries.map((hookEntries) => Object.fromEntries(hookEntries));
38
38
  };
@@ -1,7 +1,12 @@
1
1
  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
+ import type * as z from 'zod';
5
+ export declare function importSchemaEntryPoint(entryPoint: EntryPoint, exportName?: string): Promise<Validated<z.ZodSchema>>;
4
6
  export declare function importEntryPoint<T extends {
5
7
  name: string;
6
- } & Omit<typeof Base, 'new'>>(type: T, entryPoint: EntryPoint): Promise<Validated<T>>;
8
+ } & Omit<typeof Base, 'new'>>(type: T, entryPoint: EntryPoint): Promise<Validated<{
9
+ baseClass: T;
10
+ schema?: z.ZodSchema;
11
+ }>>;
7
12
  //# sourceMappingURL=entry-point.d.ts.map
@@ -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,EAAW,MAAM,4BAA4B,CAAA;AAS/D,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,CAAC,CAAC,CAAC,CAwCvB"}
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,24 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.importEntryPoint = void 0;
3
+ exports.importEntryPoint = exports.importSchemaEntryPoint = void 0;
4
4
  const logger_1 = require("@dotcom-tool-kit/logger");
5
5
  const validated_1 = require("@dotcom-tool-kit/validated");
6
- const lodash_1 = require("lodash");
7
6
  const tslib_1 = require("tslib");
8
7
  const messages_1 = require("../messages");
9
- const isPlainObjectGuard = (value) => (0, lodash_1.isPlainObject)(value);
10
- // the subclasses of Base have different constructor signatures so we need to omit
11
- // the constructor from the type bound here so you can actually pass in a subclass
12
- async function importEntryPoint(type, entryPoint) {
8
+ function guessIsZodSchema(schema) {
9
+ return typeof schema === 'object' && schema !== null && '_def' in schema;
10
+ }
11
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any --
12
+ * We aren't confident on the most reliable way to ensure the returned modules
13
+ * are the correct shape right now so let's leave this as any and hope for the
14
+ * best.
15
+ **/
16
+ async function requireEntrypoint(entryPoint) {
13
17
  const resolvedPath = require.resolve(entryPoint.modulePath, { paths: [entryPoint.plugin.root] });
14
18
  if (!resolvedPath) {
15
19
  return (0, validated_1.invalid)([
16
20
  `could not find entrypoint ${logger_1.styles.filepath(entryPoint.modulePath)} in plugin ${logger_1.styles.plugin(entryPoint.plugin.id)}`
17
21
  ]);
18
22
  }
19
- let pluginModule;
23
+ let requiredModule;
20
24
  try {
21
- pluginModule = require(resolvedPath);
25
+ requiredModule = require(resolvedPath);
22
26
  }
23
27
  catch (e) {
24
28
  const err = e;
@@ -26,16 +30,47 @@ async function importEntryPoint(type, entryPoint) {
26
30
  `an error was thrown when loading entrypoint ${logger_1.styles.filepath(entryPoint.modulePath)} in plugin ${logger_1.styles.plugin(entryPoint.plugin.id)}:\n ${logger_1.styles.code((0, messages_1.indentReasons)(err.toString()))}`
27
31
  ]);
28
32
  }
29
- const defaultExport = (0, tslib_1.__importDefault)(pluginModule).default;
30
- if (typeof defaultExport === 'function') {
31
- return type
32
- .isCompatible(defaultExport)
33
- .mapError((reasons) => [
34
- `the ${type.name.toLowerCase()} ${logger_1.styles.hook(defaultExport.name)} is not a compatible instance of ${logger_1.styles.code(type.name)}:\n - ${reasons.join('\n - ')}`
33
+ return (0, validated_1.valid)(requiredModule);
34
+ }
35
+ async function importSchemaEntryPoint(entryPoint, exportName) {
36
+ const schemaResult = await requireEntrypoint(entryPoint);
37
+ return schemaResult.flatMap((schemaModule) => {
38
+ const schema = exportName ? schemaModule[exportName] : (0, tslib_1.__importDefault)(schemaModule).default;
39
+ return guessIsZodSchema(schema)
40
+ ? (0, validated_1.valid)(schema)
41
+ : (0, validated_1.invalid)([
42
+ `found an invalid Zod schema when loading entrypoint ${logger_1.styles.filepath(entryPoint.modulePath)} in plugin ${logger_1.styles.plugin(entryPoint.plugin.id)}`
43
+ ]);
44
+ });
45
+ }
46
+ exports.importSchemaEntryPoint = importSchemaEntryPoint;
47
+ // the subclasses of Base have different constructor signatures so we need to omit
48
+ // the constructor from the type bound here so you can actually pass in a subclass
49
+ async function importEntryPoint(type, entryPoint) {
50
+ const pluginModuleResult = await requireEntrypoint(entryPoint);
51
+ return pluginModuleResult.flatMap((pluginModule) => {
52
+ const defaultExport = (0, tslib_1.__importDefault)(pluginModule).default;
53
+ const schemaExport = pluginModule.schema;
54
+ if (typeof defaultExport === 'function') {
55
+ return type
56
+ .isCompatible(defaultExport)
57
+ .flatMap((baseClass) => {
58
+ if (schemaExport === undefined || guessIsZodSchema(schemaExport)) {
59
+ return (0, validated_1.valid)({ baseClass, schema: schemaExport });
60
+ }
61
+ else {
62
+ return (0, validated_1.invalid)([
63
+ `found an invalid Zod schema exported as ${logger_1.styles.code('schema')} at the entrypoint ${logger_1.styles.filepath(pluginModule.modulePath)} in plugin ${logger_1.styles.plugin(pluginModule.plugin.id)}`
64
+ ]);
65
+ }
66
+ })
67
+ .mapError((reasons) => [
68
+ `the ${type.name.toLowerCase()} ${logger_1.styles.hook(defaultExport.name)} is not a compatible instance of ${logger_1.styles.code(type.name)}:\n - ${reasons.join('\n - ')}`
69
+ ]);
70
+ }
71
+ return (0, validated_1.invalid)([
72
+ `entrypoint ${logger_1.styles.filepath(entryPoint.modulePath)} in plugin ${logger_1.styles.plugin(entryPoint.plugin.id)} does not export a class as its ${logger_1.styles.code('default')} export or ${logger_1.styles.code('module.exports')}`
35
73
  ]);
36
- }
37
- return (0, validated_1.invalid)([
38
- `entrypoint ${logger_1.styles.filepath(entryPoint.modulePath)} in plugin ${logger_1.styles.plugin(entryPoint.plugin.id)} does not export a class as its ${logger_1.styles.code('default')} export or ${logger_1.styles.code('module.exports')}`
39
- ]);
74
+ });
40
75
  }
41
76
  exports.importEntryPoint = importEntryPoint;
@@ -2,6 +2,6 @@ import { ValidPluginsConfig } from '@dotcom-tool-kit/config';
2
2
  import { type Plugin } from '@dotcom-tool-kit/plugin';
3
3
  import type { Logger } from 'winston';
4
4
  import { InvalidOption } from '../messages';
5
- export declare const validatePluginOptions: (logger: Logger, config: ValidPluginsConfig) => InvalidOption[];
5
+ export declare const validatePluginOptions: (logger: Logger, config: ValidPluginsConfig) => Promise<InvalidOption[]>;
6
6
  export declare const substituteOptionTags: (plugin: Plugin, config: ValidPluginsConfig) => void;
7
7
  //# sourceMappingURL=options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/plugin/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D,OAAO,EAA4B,KAAK,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAI/E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAKrC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C,eAAO,MAAM,qBAAqB,WAAY,MAAM,UAAU,kBAAkB,KAAG,aAAa,EAwD/F,CAAA;AAED,eAAO,MAAM,oBAAoB,WAAY,MAAM,UAAU,kBAAkB,KAAG,IAgHjF,CAAA"}
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/plugin/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D,OAAO,EAA4B,KAAK,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAQ/E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAKrC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAG3C,eAAO,MAAM,qBAAqB,WACxB,MAAM,UACN,kBAAkB,KACzB,QAAQ,aAAa,EAAE,CAkEzB,CAAA;AAED,eAAO,MAAM,oBAAoB,WAAY,MAAM,UAAU,kBAAkB,KAAG,IAgHjF,CAAA"}
@@ -1,32 +1,52 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.substituteOptionTags = exports.validatePluginOptions = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const conflict_1 = require("@dotcom-tool-kit/conflict");
6
+ const root_schema_1 = require("@dotcom-tool-kit/plugin/lib/root-schema");
7
+ // HACK:IM:20250217 preserve backwards compatibility with older plugins without
8
+ // a colocated schema by falling back to the now-deleted schemas library if no
9
+ // schema found
5
10
  const schemas_1 = require("@dotcom-tool-kit/schemas");
6
11
  const validated_1 = require("@dotcom-tool-kit/validated");
7
- const zod_1 = require("zod");
12
+ const z = tslib_1.__importStar(require("zod"));
8
13
  const logger_1 = require("@dotcom-tool-kit/logger");
9
14
  const rc_file_1 = require("../rc-file");
10
- const validatePluginOptions = (logger, config) => {
15
+ const entry_point_1 = require("./entry-point");
16
+ const validatePluginOptions = async (logger, config) => {
11
17
  const invalidOptions = [];
12
18
  for (const [id, plugin] of Object.entries(config.plugins)) {
13
- const pluginId = id;
14
- const pluginOptions = config.pluginOptions[pluginId];
19
+ const pluginOptions = config.pluginOptions[id];
15
20
  if (pluginOptions && (0, conflict_1.isConflict)(pluginOptions)) {
16
21
  continue;
17
22
  }
18
- const pluginSchema = schemas_1.PluginSchemas[pluginId];
23
+ let pluginSchema;
24
+ const schemaEntrypoint = plugin.rcFile?.optionsSchema;
25
+ if (schemaEntrypoint) {
26
+ const schema = await (0, entry_point_1.importSchemaEntryPoint)({ plugin, modulePath: schemaEntrypoint });
27
+ if (!schema.valid) {
28
+ invalidOptions.push([id, new z.ZodError([])]);
29
+ continue;
30
+ }
31
+ pluginSchema = schema.value;
32
+ }
33
+ else if (id === 'app root') {
34
+ pluginSchema = root_schema_1.RootSchema;
35
+ }
36
+ else {
37
+ pluginSchema = schemas_1.PluginSchemas[id];
38
+ }
19
39
  if (!pluginSchema) {
20
- logger.silly(`skipping validation of ${pluginId} plugin as no schema can be found`);
40
+ logger.silly(`skipping validation of ${id} plugin as no schema can be found`);
21
41
  // TODO:KB:20240412 remove legacyPluginOptions in a future major version
22
- if (pluginOptions && pluginId in schemas_1.legacyPluginOptions) {
23
- const movedToTask = schemas_1.legacyPluginOptions[pluginId];
42
+ if (pluginOptions && id in schemas_1.legacyPluginOptions) {
43
+ const movedToTask = schemas_1.legacyPluginOptions[id];
24
44
  invalidOptions.push([
25
45
  id,
26
- new zod_1.ZodError([
46
+ new z.ZodError([
27
47
  {
28
48
  message: `options for the ${logger_1.styles.plugin(id)} plugin have moved to ${logger_1.styles.code(`options.tasks.${logger_1.styles.task(movedToTask)}`)}`,
29
- code: zod_1.ZodIssueCode.custom,
49
+ code: z.ZodIssueCode.custom,
30
50
  path: []
31
51
  }
32
52
  ])
@@ -39,7 +59,7 @@ const validatePluginOptions = (logger, config) => {
39
59
  // Set up options entry for plugins that don't have options specified
40
60
  // explicitly. They could still have default options that are set by zod.
41
61
  if (!pluginOptions) {
42
- config.pluginOptions[pluginId] = {
62
+ config.pluginOptions[id] = {
43
63
  options: result.data,
44
64
  plugin: config.plugins['app root'],
45
65
  forPlugin: plugin
@@ -1,8 +1,13 @@
1
1
  import type { Logger } from 'winston';
2
+ import * as z from 'zod';
2
3
  import type { HookClass, HookInstallation } from '@dotcom-tool-kit/base';
3
4
  import type { ValidConfig } from '@dotcom-tool-kit/config';
4
5
  import { Conflict } from '@dotcom-tool-kit/conflict';
5
6
  import type { Plugin } from '@dotcom-tool-kit/plugin';
6
7
  import { Validated } from '@dotcom-tool-kit/validated';
7
- export declare function reducePluginHookInstallations(logger: Logger, config: ValidConfig, hookClasses: Record<string, HookClass>, plugin: Plugin): Promise<Validated<(HookInstallation | Conflict<HookInstallation>)[]>>;
8
+ export interface HookModule {
9
+ hookClass: HookClass;
10
+ schema?: z.ZodTypeAny;
11
+ }
12
+ export declare function reducePluginHookInstallations(logger: Logger, config: ValidConfig, hookModules: Record<string, HookModule>, plugin: Plugin): Promise<Validated<(HookInstallation | Conflict<HookInstallation>)[]>>;
8
13
  //# sourceMappingURL=reduce-installations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reduce-installations.d.ts","sourceRoot":"","sources":["../../src/plugin/reduce-installations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAGrC,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAc,MAAM,2BAA2B,CAAA;AAEhE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAErD,OAAO,EAAE,SAAS,EAAmC,MAAM,4BAA4B,CAAA;AAiCvF,wBAAsB,6BAA6B,CACjD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,WAAW,EACnB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EACtC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,SAAS,CAAC,CAAC,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAgEvE"}
1
+ {"version":3,"file":"reduce-installations.d.ts","sourceRoot":"","sources":["../../src/plugin/reduce-installations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAc,MAAM,2BAA2B,CAAA;AAEhE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAErD,OAAO,EAAE,SAAS,EAAmC,MAAM,4BAA4B,CAAA;AAIvF,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,CAAC,EAAE,CAAC,CAAC,UAAU,CAAA;CACtB;AA+BD,wBAAsB,6BAA6B,CACjD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,WAAW,EACnB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,EACvC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,SAAS,CAAC,CAAC,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAkEvE"}
@@ -33,17 +33,17 @@ const extractForHook = (installation) => (0, conflict_1.isConflict)(installation
33
33
  // the resulting installations and/or conflicts from `a`, `b`, and `c`
34
34
  // - call `Hook.overrideChildInstallations` with the appropriate concrete Hook class, and
35
35
  // the resulting installations and/or conflicts from `Hook.mergeChildInstallations` and `p`
36
- async function reducePluginHookInstallations(logger, config, hookClasses, plugin) {
36
+ async function reducePluginHookInstallations(logger, config, hookModules, plugin) {
37
37
  if (!plugin.rcFile || config.resolutionTrackers.reducedInstallationPlugins.has(plugin.id)) {
38
38
  return (0, validated_1.valid)([]);
39
39
  }
40
40
  config.resolutionTrackers.reducedInstallationPlugins.add(plugin.id);
41
- const rawChildInstallations = (0, validated_1.reduceValidated)(await Promise.all((plugin.children ?? []).map((child) => reducePluginHookInstallations(logger, config, hookClasses, child)))).map((installations) => installations.flat());
41
+ const rawChildInstallations = (0, validated_1.reduceValidated)(await Promise.all((plugin.children ?? []).map((child) => reducePluginHookInstallations(logger, config, hookModules, child)))).map((installations) => installations.flat());
42
42
  if (!rawChildInstallations.valid) {
43
43
  return rawChildInstallations;
44
44
  }
45
45
  const childInstallations = Object.entries((0, lodash_1.groupBy)(rawChildInstallations.value, extractForHook)).flatMap(([forHook, installations]) => {
46
- const hookClass = hookClasses[forHook];
46
+ const { hookClass } = hookModules[forHook];
47
47
  return hookClass.mergeChildInstallations(plugin, installations);
48
48
  });
49
49
  if (plugin.rcFile.options.hooks.length === 0) {
@@ -51,14 +51,14 @@ async function reducePluginHookInstallations(logger, config, hookClasses, plugin
51
51
  }
52
52
  const unusedHookOptions = plugin.rcFile.options.hooks
53
53
  .flatMap(Object.keys)
54
- .filter((hookId) => !(hookId in hookClasses))
54
+ .filter((hookId) => !(hookId in hookModules))
55
55
  .map((hookId) => logger_1.styles.hook(hookId));
56
56
  if (unusedHookOptions.length > 0) {
57
- return (0, validated_1.invalid)([(0, messages_1.formatUnusedHookOptions)(unusedHookOptions, Object.keys(hookClasses))]);
57
+ return (0, validated_1.invalid)([(0, messages_1.formatUnusedHookOptions)(unusedHookOptions, Object.keys(hookModules))]);
58
58
  }
59
59
  const validatedInstallations = plugin.rcFile.options.hooks.flatMap((hookEntry) => Object.entries(hookEntry).map(([id, configHookOptions]) => {
60
- const hookClass = hookClasses[id];
61
- const parsedOptions = schemas_1.HookSchemas[id]?.safeParse(configHookOptions);
60
+ const hookModule = hookModules[id];
61
+ const parsedOptions = (hookModule.schema ?? schemas_1.HookSchemas[id])?.safeParse(configHookOptions);
62
62
  if (parsedOptions && !parsedOptions.success) {
63
63
  return (0, validated_1.invalid)([(0, messages_1.formatInvalidOption)([logger_1.styles.hook(id), parsedOptions.error])]);
64
64
  }
@@ -66,10 +66,10 @@ async function reducePluginHookInstallations(logger, config, hookClasses, plugin
66
66
  options: parsedOptions?.data ?? configHookOptions,
67
67
  plugin,
68
68
  forHook: id,
69
- hookConstructor: hookClass
69
+ hookConstructor: hookModule.hookClass
70
70
  };
71
71
  const childInstallationsForHook = childInstallations.filter((childInstallation) => id === extractForHook(childInstallation));
72
- return (0, validated_1.valid)(hookClass.overrideChildInstallations(plugin, installation, childInstallationsForHook));
72
+ return (0, validated_1.valid)(hookModule.hookClass.overrideChildInstallations(plugin, installation, childInstallationsForHook));
73
73
  }));
74
74
  return (0, validated_1.reduceValidated)(validatedInstallations).map((installations) => installations.flat());
75
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rc-file.d.ts","sourceRoot":"","sources":["../src/rc-file.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAErD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AA0BrC,eAAO,MAAM,kBAAkB,uBAAuB,CAAA;AACtD,eAAO,MAAM,qBAAqB,2BAA2B,CAAA;AAoB7D,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAqEjF"}
1
+ {"version":3,"file":"rc-file.d.ts","sourceRoot":"","sources":["../src/rc-file.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAErD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AA0BrC,eAAO,MAAM,kBAAkB,uBAAuB,CAAA;AACtD,eAAO,MAAM,qBAAqB,2BAA2B,CAAA;AAoB7D,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAsEjF"}
package/lib/rc-file.js CHANGED
@@ -87,6 +87,7 @@ async function loadToolKitRC(logger, root) {
87
87
  hooks: config.options.hooks ?? []
88
88
  }
89
89
  : { plugins: {}, tasks: {}, hooks: [] },
90
+ optionsSchema: config.optionsSchema ?? undefined,
90
91
  hooks: config.hooks ?? undefined,
91
92
  init: config.init ?? []
92
93
  };
@@ -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;AAuDrC,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;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"}
package/lib/tasks.js CHANGED
@@ -18,16 +18,15 @@ const loadTasks = async (logger, tasks, config) => {
18
18
  const taskResults = await Promise.all(tasks.map(async ({ task: taskId, options }) => {
19
19
  const entryPoint = config.tasks[taskId];
20
20
  const taskResult = await (0, entry_point_1.importEntryPoint)(base_1.Task, entryPoint);
21
- return taskResult.flatMap((Task) => {
22
- const taskSchema = schemas_1.TaskSchemas[taskId];
21
+ return taskResult.flatMap((taskModule) => {
23
22
  const configOptions = config.taskOptions[taskId]?.options ?? {};
24
23
  const mergedOptions = { ...configOptions, ...options };
25
- const parsedOptions = taskSchema?.safeParse(mergedOptions) ?? {
24
+ const parsedOptions = (taskModule.schema ?? schemas_1.TaskSchemas[taskId])?.safeParse(mergedOptions) ?? {
26
25
  success: true,
27
26
  data: mergedOptions
28
27
  };
29
28
  if (parsedOptions.success) {
30
- const task = new Task(logger, taskId, config.pluginOptions[entryPoint.plugin.id]?.options ?? {}, parsedOptions.data);
29
+ const task = new taskModule.baseClass(logger, taskId, config.pluginOptions[entryPoint.plugin.id]?.options ?? {}, parsedOptions.data);
31
30
  return (0, validated_1.valid)(task);
32
31
  }
33
32
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dotcom-tool-kit",
3
- "version": "4.4.2",
3
+ "version": "4.5.0",
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",
@@ -30,19 +30,21 @@
30
30
  "zod": "^3.22.4"
31
31
  },
32
32
  "dependencies": {
33
- "@dotcom-tool-kit/base": "^1.1.9",
34
- "@dotcom-tool-kit/config": "^1.0.12",
35
- "@dotcom-tool-kit/conflict": "^1.0.0",
33
+ "@dotcom-tool-kit/base": "^1.1.10",
34
+ "@dotcom-tool-kit/config": "^1.1.0",
35
+ "@dotcom-tool-kit/conflict": "^1.0.1",
36
36
  "@dotcom-tool-kit/error": "^4.1.0",
37
37
  "@dotcom-tool-kit/logger": "^4.1.1",
38
- "@dotcom-tool-kit/plugin": "^1.0.0",
39
- "@dotcom-tool-kit/state": "^4.3.0",
38
+ "@dotcom-tool-kit/plugin": "^1.1.0",
39
+ "@dotcom-tool-kit/schemas": "^1.9.0",
40
+ "@dotcom-tool-kit/state": "^4.3.1",
40
41
  "@dotcom-tool-kit/validated": "^1.0.2",
41
42
  "@dotcom-tool-kit/wait-for-ok": "^4.1.0",
42
43
  "endent": "^2.1.0",
43
44
  "lodash": "^4.17.21",
44
45
  "minimist": "^1.2.5",
45
46
  "pluralize": "^8.0.0",
47
+ "pretty-format": "^29.7.0",
46
48
  "tslib": "^2.3.1",
47
49
  "yaml": "^2.4.1",
48
50
  "zod-validation-error": "^2.1.0"