dotcom-tool-kit 4.0.0-beta.4 → 4.0.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":"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;AAU/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,CA4CvB"}
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;AAQ/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,CA4CvB"}
@@ -1,17 +1,38 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.importEntryPoint = void 0;
4
- const tslib_1 = require("tslib");
5
27
  const logger_1 = require("@dotcom-tool-kit/logger");
6
28
  const validated_1 = require("@dotcom-tool-kit/validated");
7
- const resolve_from_1 = tslib_1.__importDefault(require("resolve-from"));
8
29
  const lodash_1 = require("lodash");
9
30
  const messages_1 = require("../messages");
10
31
  const isPlainObjectGuard = (value) => (0, lodash_1.isPlainObject)(value);
11
32
  // the subclasses of Base have different constructor signatures so we need to omit
12
33
  // the constructor from the type bound here so you can actually pass in a subclass
13
34
  async function importEntryPoint(type, entryPoint) {
14
- const resolvedPath = resolve_from_1.default.silent(entryPoint.plugin.root, entryPoint.modulePath);
35
+ const resolvedPath = require.resolve(entryPoint.modulePath, { paths: [entryPoint.plugin.root] });
15
36
  if (!resolvedPath) {
16
37
  return (0, validated_1.invalid)([
17
38
  `could not find entrypoint ${logger_1.styles.filepath(entryPoint.modulePath)} in plugin ${logger_1.styles.plugin(entryPoint.plugin.id)}`
@@ -19,7 +40,7 @@ async function importEntryPoint(type, entryPoint) {
19
40
  }
20
41
  let pluginModule;
21
42
  try {
22
- pluginModule = await Promise.resolve(`${resolvedPath}`).then(s => tslib_1.__importStar(require(s)));
43
+ pluginModule = await Promise.resolve(`${resolvedPath}`).then(s => __importStar(require(s)));
23
44
  }
24
45
  catch (e) {
25
46
  const err = e;
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,KAAK,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAmC,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAEvF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAUrC,wBAAsB,UAAU,CAC9B,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAmD5B;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,GAAG,IAAI,CAiBrF;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAqB9F"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,KAAK,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAmC,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAEvF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAoBrC,wBAAsB,UAAU,CAC9B,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAmD5B;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,GAAG,IAAI,CAiBrF;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAqB9F"}
package/lib/plugin.js CHANGED
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
5
5
  const logger_1 = require("@dotcom-tool-kit/logger");
6
6
  const plugin_1 = require("@dotcom-tool-kit/plugin");
7
7
  const validated_1 = require("@dotcom-tool-kit/validated");
8
- const resolve_pkg_1 = tslib_1.__importDefault(require("resolve-pkg"));
8
+ const path = tslib_1.__importStar(require("path"));
9
9
  const rc_file_1 = require("./rc-file");
10
10
  const messages_1 = require("./messages");
11
11
  const merge_tasks_1 = require("./plugin/merge-tasks");
@@ -14,6 +14,15 @@ const merge_commands_1 = require("./plugin/merge-commands");
14
14
  const merge_plugin_options_1 = require("./plugin/merge-plugin-options");
15
15
  const merge_inits_1 = require("./plugin/merge-inits");
16
16
  const merge_task_options_1 = require("./plugin/merge-task-options");
17
+ function resolveRoot(id, root) {
18
+ const isPath = id.startsWith('.') || id.startsWith('/');
19
+ // resolve the package.json of a plugin as many plugins don't have valid
20
+ // entrypoints now that we're intending their tasks/hooks to be loaded via
21
+ // entrypoints defined in config
22
+ const modulePath = isPath ? id : path.join(id, 'package.json');
23
+ const resolvedPath = require.resolve(modulePath, { paths: [root] });
24
+ return path.dirname(resolvedPath);
25
+ }
17
26
  async function loadPlugin(id, config, logger, parent) {
18
27
  // don't load duplicate plugins
19
28
  if (id in config.plugins) {
@@ -22,7 +31,7 @@ async function loadPlugin(id, config, logger, parent) {
22
31
  const isAppRoot = id === 'app root';
23
32
  // load plugin relative to the parent plugin
24
33
  const root = parent ? parent.root : process.cwd();
25
- const pluginRoot = isAppRoot ? root : (0, resolve_pkg_1.default)(id, { cwd: root });
34
+ const pluginRoot = isAppRoot ? root : resolveRoot(id, root);
26
35
  if (!pluginRoot) {
27
36
  return (0, validated_1.invalid)([`could not find path for name ${logger_1.styles.filepath(id)}`]);
28
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../src/tasks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAsDrC,wBAAsB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA+DlG"}
1
+ {"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../src/tasks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAuDrC,wBAAsB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA0ElG"}
package/lib/tasks.js CHANGED
@@ -20,20 +20,21 @@ const loadTasks = async (logger, tasks, config) => {
20
20
  return taskResult.flatMap((Task) => {
21
21
  const taskSchema = schemas_1.TaskSchemas[taskId];
22
22
  const configOptions = config.taskOptions[taskId]?.options ?? {};
23
- const parsedOptions = taskSchema?.safeParse({ ...configOptions, ...options }) ?? {
23
+ const mergedOptions = { ...configOptions, ...options };
24
+ const parsedOptions = taskSchema?.safeParse(mergedOptions) ?? {
24
25
  success: true,
25
- data: {}
26
+ data: mergedOptions
26
27
  };
27
28
  if (parsedOptions.success) {
28
29
  const task = new Task(logger, taskId, (0, options_1.getOptions)(entryPoint.plugin.id) ?? {}, parsedOptions.data);
29
- return (0, validated_1.valid)([taskId, task]);
30
+ return (0, validated_1.valid)(task);
30
31
  }
31
32
  else {
32
33
  return (0, validated_1.invalid)([(0, messages_1.formatInvalidOption)([logger_1.styles.task(taskId), parsedOptions.error])]);
33
34
  }
34
35
  });
35
36
  }));
36
- return (0, validated_1.reduceValidated)(taskResults).map(Object.fromEntries);
37
+ return (0, validated_1.reduceValidated)(taskResults);
37
38
  };
38
39
  async function runTasks(logger, commands, files) {
39
40
  const config = await (0, config_1.loadConfig)(logger);
@@ -47,24 +48,30 @@ async function runTasks(logger, commands, files) {
47
48
  if ((0, fetch_1.shouldDisableNativeFetch)()) {
48
49
  process.execArgv.push('--no-experimental-fetch');
49
50
  }
50
- const commandTasks = commands.flatMap((command) => config.commandTasks[command]?.tasks ?? []);
51
- const tasks = (await loadTasks(logger, commandTasks, config)).unwrap('tasks are invalid');
52
- for (const command of commands) {
51
+ const commandTasks = (0, validated_1.reduceValidated)(await Promise.all(commands.map(async (command) => {
52
+ const tasks = config.commandTasks[command]?.tasks ?? [];
53
+ const validatedTaskInstances = await loadTasks(logger, tasks, config);
54
+ return validatedTaskInstances.map((taskInstances) => ({ command, tasks: taskInstances }));
55
+ }))).unwrap('tasks are invalid!');
56
+ for (const { command, tasks } of commandTasks) {
53
57
  const errors = [];
54
- if (!config.commandTasks[command]) {
58
+ if (tasks.length === 0) {
55
59
  logger.warn(`no task configured for ${command}: skipping assignment...`);
56
- continue;
57
60
  }
58
- for (const { task: taskId } of config.commandTasks[command].tasks) {
61
+ for (const task of tasks) {
59
62
  try {
60
- logger.info(logger_1.styles.taskHeader(`running ${logger_1.styles.task(taskId)} task`));
61
- await tasks[taskId].run(files);
63
+ logger.info(logger_1.styles.taskHeader(`running ${logger_1.styles.task(task.id)} task`));
64
+ await task.run({ files });
62
65
  }
63
66
  catch (error) {
67
+ // if there's an exit code, that's a request from the task to exit early
68
+ if (error instanceof error_1.ToolKitError && error.exitCode) {
69
+ throw error;
70
+ }
71
+ // if not, we allow subsequent hook tasks to run on error
64
72
  // TODO use validated for this
65
- // allow subsequent command tasks to run on error
66
73
  errors.push({
67
- task: taskId,
74
+ task: task.id,
68
75
  error: error
69
76
  });
70
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dotcom-tool-kit",
3
- "version": "4.0.0-beta.4",
3
+ "version": "4.0.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,20 +30,18 @@
30
30
  "zod": "^3.22.4"
31
31
  },
32
32
  "dependencies": {
33
- "@dotcom-tool-kit/base": "4.0.0-beta.0",
34
- "@dotcom-tool-kit/config": "2.0.0-beta.0",
35
- "@dotcom-tool-kit/conflict": "2.0.0-beta.0",
36
- "@dotcom-tool-kit/error": "4.0.0-beta.0",
37
- "@dotcom-tool-kit/logger": "4.0.0-beta.0",
38
- "@dotcom-tool-kit/options": "4.0.0-beta.0",
39
- "@dotcom-tool-kit/plugin": "2.0.0-beta.0",
40
- "@dotcom-tool-kit/validated": "2.0.0-beta.0",
41
- "@dotcom-tool-kit/wait-for-ok": "4.0.0-beta.0",
33
+ "@dotcom-tool-kit/base": "^1.0.0",
34
+ "@dotcom-tool-kit/config": "^1.0.0",
35
+ "@dotcom-tool-kit/conflict": "^1.0.0",
36
+ "@dotcom-tool-kit/error": "^4.0.0",
37
+ "@dotcom-tool-kit/logger": "^4.0.0",
38
+ "@dotcom-tool-kit/options": "^4.0.0",
39
+ "@dotcom-tool-kit/plugin": "^1.0.0",
40
+ "@dotcom-tool-kit/validated": "^1.0.0",
41
+ "@dotcom-tool-kit/wait-for-ok": "^4.0.0",
42
42
  "endent": "^2.1.0",
43
43
  "lodash": "^4.17.21",
44
44
  "minimist": "^1.2.5",
45
- "resolve-from": "^5.0.0",
46
- "resolve-pkg": "^2.0.0",
47
45
  "tslib": "^2.3.1",
48
46
  "yaml": "^2.4.1",
49
47
  "zod-validation-error": "^2.1.0"