@opencraw/cli 0.1.25 → 0.1.27

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/dist/index.esm.js CHANGED
@@ -245,7 +245,8 @@ function parseArguments(argv, env = {}) {
245
245
  if (rest.length > 1) throw new Error('studio takes at most one folder');
246
246
  return {
247
247
  name: 'studio',
248
- folder: rest[0]
248
+ folder: rest[0],
249
+ plugins: options.plugins
249
250
  };
250
251
  }
251
252
  default:
@@ -377,7 +378,7 @@ const PLUGIN_EXPORTS = ['hooks', 'accessPlugins', 'captchaSolvers'];
377
378
  * The module runs with the caller's privileges, like any code the caller
378
379
  * imports: point this only at a file you trust.
379
380
  *
380
- * @param path - A `.mjs` / `.js` / `.cjs` file.
381
+ * @param path - A `.mjs` / `.js` / `.cjs` file, or a `.ts` / `.mts` file on a Node that strips types (22.18+).
381
382
  * @param importModule - How to import it; `import()` unless a test says otherwise.
382
383
  * @returns The hooks and plugins.
383
384
  * @throws Error naming the file when it cannot be imported, provides nothing,
@@ -899,9 +900,11 @@ function loadErrorLines(error) {
899
900
  * @param folder - The recipe folder to open; `@opencraw/studio`'s own default (the current directory) when omitted.
900
901
  * @param terminal - Where output goes.
901
902
  * @param importStudio - How the module is loaded; the real dynamic `import()` by default, replaced in tests.
903
+ * @param pluginsFile - A hooks or plugins module (`--hooks`, issue #150), loaded here, on the command line's own authority, and handed to Studio: the server never loads code itself.
904
+ * @param load - How the module is read; `loadPlugins` unless a test says otherwise.
902
905
  * @returns The exit code: 0 once the server has stopped, 1 when `@opencraw/studio` is missing.
903
906
  */
904
- async function runStudio(folder, terminal, importStudio = () => import('@opencraw/studio')) {
907
+ async function runStudio(folder, terminal, importStudio = () => import('@opencraw/studio'), pluginsFile, load = loadPlugins) {
905
908
  let studio;
906
909
  try {
907
910
  studio = await importStudio();
@@ -910,7 +913,13 @@ async function runStudio(folder, terminal, importStudio = () => import('@opencra
910
913
  terminal.err('the studio is not installed: run `npm install @opencraw/studio`, then try again');
911
914
  return 1;
912
915
  }
913
- await studio.main(folder === undefined ? [] : [folder]);
916
+ const plugins = pluginsFile === undefined ? undefined : {
917
+ source: pluginsFile,
918
+ ...(await load(pluginsFile))
919
+ };
920
+ await studio.main(folder === undefined ? [] : [folder], {
921
+ plugins
922
+ });
914
923
  return 0;
915
924
  }
916
925
  function isModuleNotFound(error) {
@@ -1012,7 +1021,7 @@ async function main(argv, terminal) {
1012
1021
  }
1013
1022
  case 'studio':
1014
1023
  {
1015
- return runStudio(command.folder, terminal);
1024
+ return runStudio(command.folder, terminal, undefined, command.plugins);
1016
1025
  }
1017
1026
  }
1018
1027
  }
@@ -69,5 +69,7 @@ export type Command = {
69
69
  name: 'studio';
70
70
  /** The recipe folder to open; the current directory when not given. */
71
71
  folder?: string;
72
+ /** A hooks or plugins module to run recipes with (`--hooks`, `--plugins`, `OPENCRAW_HOOKS`, `OPENCRAW_PLUGINS`; issue #150). */
73
+ plugins?: string;
72
74
  };
73
75
  //# sourceMappingURL=command.contract.d.ts.map
@@ -26,7 +26,7 @@ export interface PluginModule {
26
26
  * The module runs with the caller's privileges, like any code the caller
27
27
  * imports: point this only at a file you trust.
28
28
  *
29
- * @param path - A `.mjs` / `.js` / `.cjs` file.
29
+ * @param path - A `.mjs` / `.js` / `.cjs` file, or a `.ts` / `.mts` file on a Node that strips types (22.18+).
30
30
  * @param importModule - How to import it; `import()` unless a test says otherwise.
31
31
  * @returns The hooks and plugins.
32
32
  * @throws Error naming the file when it cannot be imported, provides nothing,
@@ -1,7 +1,13 @@
1
+ import { loadPlugins } from '../hooks-module/index.js';
2
+ import type { PluginModule } from '../hooks-module/index.js';
1
3
  import type { Terminal } from '../terminal/index.js';
2
4
  /** The one export the cli needs from `@opencraw/studio`. */
3
5
  export interface StudioModule {
4
- main: (argv: readonly string[]) => Promise<void>;
6
+ main: (argv: readonly string[], options?: {
7
+ plugins?: PluginModule & {
8
+ source: string;
9
+ };
10
+ }) => Promise<void>;
5
11
  }
6
12
  /**
7
13
  * Runs `opencraw studio [folder]`: imports `@opencraw/studio` lazily and
@@ -16,7 +22,9 @@ export interface StudioModule {
16
22
  * @param folder - The recipe folder to open; `@opencraw/studio`'s own default (the current directory) when omitted.
17
23
  * @param terminal - Where output goes.
18
24
  * @param importStudio - How the module is loaded; the real dynamic `import()` by default, replaced in tests.
25
+ * @param pluginsFile - A hooks or plugins module (`--hooks`, issue #150), loaded here, on the command line's own authority, and handed to Studio: the server never loads code itself.
26
+ * @param load - How the module is read; `loadPlugins` unless a test says otherwise.
19
27
  * @returns The exit code: 0 once the server has stopped, 1 when `@opencraw/studio` is missing.
20
28
  */
21
- export declare function runStudio(folder: string | undefined, terminal: Terminal, importStudio?: () => Promise<StudioModule>): Promise<number>;
29
+ export declare function runStudio(folder: string | undefined, terminal: Terminal, importStudio?: () => Promise<StudioModule>, pluginsFile?: string, load?: typeof loadPlugins): Promise<number>;
22
30
  //# sourceMappingURL=run-studio.use-case.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencraw/cli",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
4
4
  "type": "module",
5
5
  "main": "./dist/index.esm.js",
6
6
  "module": "./dist/index.esm.js",
@@ -24,12 +24,12 @@
24
24
  "!**/*.js.map"
25
25
  ],
26
26
  "dependencies": {
27
- "@opencraw/core": "^0.1.25",
28
- "@opencraw/probe": "^0.0.8",
27
+ "@opencraw/core": "^0.1.27",
28
+ "@opencraw/probe": "^0.0.10",
29
29
  "playwright": "^1.63.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "@opencraw/studio": "^0.0.14"
32
+ "@opencraw/studio": "^0.0.16"
33
33
  },
34
34
  "peerDependenciesMeta": {
35
35
  "@opencraw/studio": {