@powerlines/plugin-vite 0.14.61 → 0.14.63

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.
Files changed (46) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.mjs +1 -1
  3. package/dist/powerlines/src/api.cjs +3 -3
  4. package/dist/powerlines/src/api.mjs +1 -1
  5. package/dist/powerlines/src/internal/helpers/environment.cjs +1 -1
  6. package/dist/powerlines/src/internal/helpers/environment.mjs +1 -1
  7. package/dist/powerlines/src/internal/helpers/hooks.d.cts +48 -0
  8. package/dist/powerlines/src/internal/helpers/hooks.d.mts +50 -0
  9. package/dist/powerlines/src/internal/helpers/install.cjs +1 -1
  10. package/dist/powerlines/src/internal/helpers/install.mjs +1 -1
  11. package/dist/powerlines/src/internal/helpers/resolve-tsconfig.cjs +1 -1
  12. package/dist/powerlines/src/internal/helpers/resolve-tsconfig.mjs +1 -1
  13. package/dist/powerlines/src/internal/helpers/resolver.cjs +1 -1
  14. package/dist/powerlines/src/internal/helpers/resolver.mjs +1 -1
  15. package/dist/powerlines/src/lib/build/esbuild.cjs +2 -2
  16. package/dist/powerlines/src/lib/build/esbuild.mjs +2 -2
  17. package/dist/powerlines/src/lib/build/vite.cjs +1 -1
  18. package/dist/powerlines/src/lib/build/vite.mjs +1 -1
  19. package/dist/powerlines/src/lib/config-file.cjs +1 -1
  20. package/dist/powerlines/src/lib/config-file.mjs +1 -1
  21. package/dist/powerlines/src/lib/contexts/api-context.cjs +1 -1
  22. package/dist/powerlines/src/lib/contexts/api-context.mjs +1 -1
  23. package/dist/powerlines/src/lib/typescript/tsconfig.cjs +1 -1
  24. package/dist/powerlines/src/lib/typescript/tsconfig.mjs +1 -1
  25. package/dist/powerlines/src/types/api.d.cts +104 -0
  26. package/dist/powerlines/src/types/api.d.mts +104 -0
  27. package/dist/powerlines/src/types/build.d.cts +13 -2
  28. package/dist/powerlines/src/types/build.d.mts +13 -2
  29. package/dist/powerlines/src/types/config.d.cts +59 -1
  30. package/dist/powerlines/src/types/config.d.mts +60 -2
  31. package/dist/powerlines/src/types/context.d.cts +112 -1
  32. package/dist/powerlines/src/types/context.d.mts +112 -3
  33. package/dist/powerlines/src/types/hooks.d.cts +30 -0
  34. package/dist/powerlines/src/types/hooks.d.mts +30 -2
  35. package/dist/powerlines/src/types/internal.d.cts +58 -0
  36. package/dist/powerlines/src/types/internal.d.mts +58 -0
  37. package/dist/powerlines/src/types/plugin.d.cts +4 -1
  38. package/dist/powerlines/src/types/plugin.d.mts +4 -1
  39. package/dist/powerlines/src/types/resolved.d.mts +1 -0
  40. package/dist/types/internal.cjs +0 -0
  41. package/dist/types/internal.d.cts +14 -0
  42. package/dist/types/internal.d.mts +14 -0
  43. package/dist/types/internal.mjs +1 -0
  44. package/dist/types/plugin.d.cts +1 -8
  45. package/dist/types/plugin.d.mts +1 -8
  46. package/package.json +8 -13
@@ -0,0 +1,104 @@
1
+ import { ResolvedConfig } from "./resolved.mjs";
2
+ import { BuildInlineConfig, CleanInlineConfig, DeployInlineConfig, DocsInlineConfig, LintInlineConfig, NewInlineConfig, PrepareInlineConfig } from "./config.mjs";
3
+ import { HookKeys, InferHookParameters, InferHookReturnType } from "./hooks.mjs";
4
+ import { APIContext, EnvironmentContext, PluginContext } from "./context.mjs";
5
+ import { CallHookOptions } from "../internal/helpers/hooks.mjs";
6
+
7
+ //#region ../powerlines/src/types/api.d.ts
8
+
9
+ /**
10
+ * Powerlines API Interface
11
+ */
12
+ interface API<TResolvedConfig extends ResolvedConfig = ResolvedConfig> {
13
+ /**
14
+ * The Powerlines shared API context
15
+ */
16
+ context: APIContext<TResolvedConfig>;
17
+ /**
18
+ * Prepare the Powerlines API
19
+ *
20
+ * @remarks
21
+ * This method will prepare the Powerlines API for use, initializing any necessary resources.
22
+ *
23
+ * @param inlineConfig - The inline configuration for the prepare command
24
+ */
25
+ prepare: (inlineConfig: PrepareInlineConfig | NewInlineConfig | CleanInlineConfig | BuildInlineConfig | LintInlineConfig | DocsInlineConfig | DeployInlineConfig) => Promise<void>;
26
+ /**
27
+ * Create a new Powerlines project
28
+ *
29
+ * @remarks
30
+ * This method will create a new Powerlines project in the current directory.
31
+ *
32
+ * @param inlineConfig - The inline configuration for the new command
33
+ * @returns A promise that resolves when the project has been created
34
+ */
35
+ new: (inlineConfig: NewInlineConfig) => Promise<void>;
36
+ /**
37
+ * Clean any previously prepared artifacts
38
+ *
39
+ * @remarks
40
+ * This method will remove the previous Powerlines artifacts from the project.
41
+ *
42
+ * @param inlineConfig - The inline configuration for the clean command
43
+ * @returns A promise that resolves when the clean command has completed
44
+ */
45
+ clean: (inlineConfig: CleanInlineConfig | PrepareInlineConfig) => Promise<void>;
46
+ /**
47
+ * Lint the project source code
48
+ *
49
+ * @param inlineConfig - The inline configuration for the lint command
50
+ * @returns A promise that resolves when the lint command has completed
51
+ */
52
+ lint: (inlineConfig: LintInlineConfig) => Promise<void>;
53
+ /**
54
+ * Build the project
55
+ *
56
+ * @remarks
57
+ * This method will build the Powerlines project, generating the necessary artifacts.
58
+ *
59
+ * @param inlineConfig - The inline configuration for the build command
60
+ * @returns A promise that resolves when the build command has completed
61
+ */
62
+ build: (inlineConfig: BuildInlineConfig) => Promise<void>;
63
+ /**
64
+ * Prepare the documentation for the project
65
+ *
66
+ * @param inlineConfig - The inline configuration for the docs command
67
+ * @returns A promise that resolves when the documentation generation has completed
68
+ */
69
+ docs: (inlineConfig: DocsInlineConfig) => Promise<void>;
70
+ /**
71
+ * Deploy the project source code
72
+ *
73
+ * @remarks
74
+ * This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.
75
+ *
76
+ * @param inlineConfig - The inline configuration for the deploy command
77
+ */
78
+ deploy: (inlineConfig: DeployInlineConfig) => Promise<void>;
79
+ /**
80
+ * Finalization process
81
+ *
82
+ * @remarks
83
+ * This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
84
+ *
85
+ * @returns A promise that resolves when the finalization process has completed
86
+ */
87
+ finalize: () => Promise<void>;
88
+ /**
89
+ * Invokes the configured plugin hooks
90
+ *
91
+ * @remarks
92
+ * By default, it will call the `"pre"`, `"normal"`, and `"post"` ordered hooks in sequence
93
+ *
94
+ * @param hook - The hook to call
95
+ * @param options - The options to provide to the hook
96
+ * @param args - The arguments to pass to the hook
97
+ * @returns The result of the hook call
98
+ */
99
+ callHook: <TKey extends HookKeys<PluginContext<TResolvedConfig>>>(hook: TKey, options: CallHookOptions & {
100
+ environment?: string | EnvironmentContext<TResolvedConfig>;
101
+ }, ...args: InferHookParameters<PluginContext<TResolvedConfig>, TKey>) => Promise<InferHookReturnType<PluginContext<TResolvedConfig>, TKey> | undefined>;
102
+ }
103
+ //#endregion
104
+ export { API };
@@ -1,4 +1,4 @@
1
- import { UserConfig } from "vite";
1
+ import { DepOptimizationOptions, UserConfig } from "vite";
2
2
 
3
3
  //#region ../powerlines/src/types/build.d.ts
4
4
 
@@ -128,6 +128,12 @@ interface BuildConfig {
128
128
  * Should the Powerlines CLI processes skip bundling the `node_modules` directory?
129
129
  */
130
130
  skipNodeModulesBundle?: boolean;
131
+ /**
132
+ * If true, `process.env` referenced in code will be preserved as-is and evaluated in runtime. Otherwise, it is statically replaced as an empty object.
133
+ *
134
+ * @defaultValue false
135
+ */
136
+ keepProcessEnv?: boolean;
131
137
  /**
132
138
  * An optional set of override options to apply to the selected build variant.
133
139
  *
@@ -137,7 +143,12 @@ interface BuildConfig {
137
143
  override?: Record<string, any>;
138
144
  }
139
145
  type BuildResolvedConfig = Omit<BuildConfig, "override">;
140
- type ViteBuildConfig = Omit<UserConfig, "entry" | "entryPoints" | "tsconfig" | "tsconfigRaw" | "environments" | "output"> & BuildConfig;
146
+ type ViteBuildConfig = Omit<UserConfig, "entry" | "entryPoints" | "tsconfig" | "tsconfigRaw" | "environments" | "output"> & BuildConfig & {
147
+ /**
148
+ * Optimize deps config
149
+ */
150
+ optimizeDeps?: Omit<DepOptimizationOptions, "extensions">;
151
+ };
141
152
  type ViteResolvedBuildConfig = UserConfig & BuildResolvedConfig;
142
153
  //#endregion
143
154
  export { BuildConfig, BuildResolvedConfig, UnpluginBuildVariant, ViteBuildConfig, ViteResolvedBuildConfig };
@@ -1,4 +1,4 @@
1
- import { UserConfig } from "vite";
1
+ import { DepOptimizationOptions, UserConfig } from "vite";
2
2
 
3
3
  //#region ../powerlines/src/types/build.d.ts
4
4
 
@@ -128,6 +128,12 @@ interface BuildConfig {
128
128
  * Should the Powerlines CLI processes skip bundling the `node_modules` directory?
129
129
  */
130
130
  skipNodeModulesBundle?: boolean;
131
+ /**
132
+ * If true, `process.env` referenced in code will be preserved as-is and evaluated in runtime. Otherwise, it is statically replaced as an empty object.
133
+ *
134
+ * @defaultValue false
135
+ */
136
+ keepProcessEnv?: boolean;
131
137
  /**
132
138
  * An optional set of override options to apply to the selected build variant.
133
139
  *
@@ -137,7 +143,12 @@ interface BuildConfig {
137
143
  override?: Record<string, any>;
138
144
  }
139
145
  type BuildResolvedConfig = Omit<BuildConfig, "override">;
140
- type ViteBuildConfig = Omit<UserConfig, "entry" | "entryPoints" | "tsconfig" | "tsconfigRaw" | "environments" | "output"> & BuildConfig;
146
+ type ViteBuildConfig = Omit<UserConfig, "entry" | "entryPoints" | "tsconfig" | "tsconfigRaw" | "environments" | "output"> & BuildConfig & {
147
+ /**
148
+ * Optimize deps config
149
+ */
150
+ optimizeDeps?: Omit<DepOptimizationOptions, "extensions">;
151
+ };
141
152
  type ViteResolvedBuildConfig = UserConfig & BuildResolvedConfig;
142
153
  //#endregion
143
154
  export { BuildConfig, BuildResolvedConfig, UnpluginBuildVariant, ViteBuildConfig, ViteResolvedBuildConfig };
@@ -300,6 +300,18 @@ interface CommonUserConfig extends BaseConfig {
300
300
  * Environment-specific configurations
301
301
  */
302
302
  environments?: Record<string, EnvironmentConfig>;
303
+ /**
304
+ * Should a single `build` process be ran for each environment?
305
+ *
306
+ * @remarks
307
+ * This option determines how environments are managed during the `build` process. The available options are:
308
+ *
309
+ * - `false`: A separate build is ran for each environment.
310
+ * - `true`: A single build is ran for all environments.
311
+ *
312
+ * @defaultValue false
313
+ */
314
+ singleBuild?: boolean;
303
315
  /**
304
316
  * A string identifier that allows a child framework or tool to identify itself when using Powerlines.
305
317
  *
@@ -342,5 +354,51 @@ type InlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = Partial<TUs
342
354
  */
343
355
  command: PowerlinesCommand;
344
356
  };
357
+ type NewInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & Required<Pick<InlineConfig<TUserConfig>, "root">> & {
358
+ /**
359
+ * A string identifier for the Powerlines command being executed
360
+ */
361
+ command: "new";
362
+ /**
363
+ * The package name (from the \`package.json\`) for the project that will be used in the \`new\` command to create a new project based on this configuration
364
+ */
365
+ packageName?: string;
366
+ };
367
+ type CleanInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
368
+ /**
369
+ * A string identifier for the Powerlines command being executed
370
+ */
371
+ command: "clean";
372
+ };
373
+ type PrepareInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
374
+ /**
375
+ * A string identifier for the Powerlines command being executed
376
+ */
377
+ command: "prepare";
378
+ };
379
+ type BuildInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
380
+ /**
381
+ * A string identifier for the Powerlines command being executed
382
+ */
383
+ command: "build";
384
+ };
385
+ type LintInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
386
+ /**
387
+ * A string identifier for the Powerlines command being executed
388
+ */
389
+ command: "lint";
390
+ };
391
+ type DocsInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
392
+ /**
393
+ * A string identifier for the Powerlines command being executed
394
+ */
395
+ command: "docs";
396
+ };
397
+ type DeployInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
398
+ /**
399
+ * A string identifier for the Powerlines command being executed
400
+ */
401
+ command: "deploy";
402
+ };
345
403
  //#endregion
346
- export { EnvironmentConfig, InlineConfig, LogFn, OutputConfig, PluginConfig, UserConfig$1 as UserConfig, ViteUserConfig, WorkspaceConfig };
404
+ export { BuildInlineConfig, CleanInlineConfig, DeployInlineConfig, DocsInlineConfig, EnvironmentConfig, InlineConfig, LintInlineConfig, LogFn, NewInlineConfig, OutputConfig, PluginConfig, PrepareInlineConfig, UserConfig$1 as UserConfig, ViteUserConfig, WorkspaceConfig };
@@ -5,9 +5,9 @@ import { Plugin } from "./plugin.mjs";
5
5
  import { TSConfig } from "./tsconfig.mjs";
6
6
  import { PluginContext } from "./context.mjs";
7
7
  import { LogLevelLabel } from "@storm-software/config-tools/types";
8
+ import { PreviewOptions } from "vite";
8
9
  import { transformAsync } from "@babel/core";
9
10
  import "c12";
10
- import { PreviewOptions } from "vite";
11
11
  import { MaybePromise } from "@stryke/types/base";
12
12
  import { Format } from "@storm-software/build-tools/types";
13
13
  import { StormWorkspaceConfig } from "@storm-software/config/types";
@@ -302,6 +302,18 @@ interface CommonUserConfig extends BaseConfig {
302
302
  * Environment-specific configurations
303
303
  */
304
304
  environments?: Record<string, EnvironmentConfig>;
305
+ /**
306
+ * Should a single `build` process be ran for each environment?
307
+ *
308
+ * @remarks
309
+ * This option determines how environments are managed during the `build` process. The available options are:
310
+ *
311
+ * - `false`: A separate build is ran for each environment.
312
+ * - `true`: A single build is ran for all environments.
313
+ *
314
+ * @defaultValue false
315
+ */
316
+ singleBuild?: boolean;
305
317
  /**
306
318
  * A string identifier that allows a child framework or tool to identify itself when using Powerlines.
307
319
  *
@@ -344,5 +356,51 @@ type InlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = Partial<TUs
344
356
  */
345
357
  command: PowerlinesCommand;
346
358
  };
359
+ type NewInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & Required<Pick<InlineConfig<TUserConfig>, "root">> & {
360
+ /**
361
+ * A string identifier for the Powerlines command being executed
362
+ */
363
+ command: "new";
364
+ /**
365
+ * The package name (from the \`package.json\`) for the project that will be used in the \`new\` command to create a new project based on this configuration
366
+ */
367
+ packageName?: string;
368
+ };
369
+ type CleanInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
370
+ /**
371
+ * A string identifier for the Powerlines command being executed
372
+ */
373
+ command: "clean";
374
+ };
375
+ type PrepareInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
376
+ /**
377
+ * A string identifier for the Powerlines command being executed
378
+ */
379
+ command: "prepare";
380
+ };
381
+ type BuildInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
382
+ /**
383
+ * A string identifier for the Powerlines command being executed
384
+ */
385
+ command: "build";
386
+ };
387
+ type LintInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
388
+ /**
389
+ * A string identifier for the Powerlines command being executed
390
+ */
391
+ command: "lint";
392
+ };
393
+ type DocsInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
394
+ /**
395
+ * A string identifier for the Powerlines command being executed
396
+ */
397
+ command: "docs";
398
+ };
399
+ type DeployInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
400
+ /**
401
+ * A string identifier for the Powerlines command being executed
402
+ */
403
+ command: "deploy";
404
+ };
347
405
  //#endregion
348
- export { EnvironmentConfig, InlineConfig, LogFn, OutputConfig, PluginConfig, UserConfig$1 as UserConfig, ViteUserConfig, WorkspaceConfig };
406
+ export { BuildInlineConfig, CleanInlineConfig, DeployInlineConfig, DocsInlineConfig, EnvironmentConfig, InlineConfig, LintInlineConfig, LogFn, NewInlineConfig, OutputConfig, PluginConfig, PrepareInlineConfig, UserConfig$1 as UserConfig, ViteUserConfig, WorkspaceConfig };
@@ -1,7 +1,9 @@
1
1
  import { ResolveOptions, VirtualFile, VirtualFileSystemInterface } from "./fs.cjs";
2
2
  import { EnvironmentResolvedConfig, ResolvedConfig, ResolvedEntryTypeDefinition } from "./resolved.cjs";
3
+ import { Plugin } from "./plugin.cjs";
3
4
  import { ParsedTypeScriptConfig } from "./tsconfig.cjs";
4
5
  import { InlineConfig, LogFn, UserConfig, WorkspaceConfig } from "./config.cjs";
6
+ import { HookKeys, Hooks, HooksList } from "./hooks.cjs";
5
7
  import { EnvPaths } from "@stryke/env/get-env-paths";
6
8
  import { FetchRequestOptions } from "@stryke/http/fetch";
7
9
  import { NonUndefined } from "@stryke/types/base";
@@ -49,6 +51,9 @@ interface TransformResult$1 {
49
51
  code: string;
50
52
  map: SourceMap | null;
51
53
  }
54
+ interface SelectHooksOptions {
55
+ order?: "pre" | "post" | "normal";
56
+ }
52
57
  interface InitContextOptions {
53
58
  /**
54
59
  * If false, the plugin will be loaded after all other plugins.
@@ -329,6 +334,112 @@ type Context<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = Omit<Unr
329
334
  */
330
335
  config: TResolvedConfig;
331
336
  };
337
+ interface APIContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
338
+ /**
339
+ * The expected plugins options for the Powerlines project.
340
+ *
341
+ * @remarks
342
+ * This is a record of plugin identifiers to their respective options. This field is populated by the Powerlines engine during both plugin initialization and the `init` command.
343
+ */
344
+ plugins: Plugin<PluginContext<TResolvedConfig>>[];
345
+ /**
346
+ * A function to add a plugin to the context and update the configuration options
347
+ */
348
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
349
+ /**
350
+ * A table for storing the current context for each configured environment
351
+ */
352
+ environments: Record<string, EnvironmentContext<TResolvedConfig>>;
353
+ /**
354
+ * Retrieves the context for a specific environment by name
355
+ *
356
+ * @throws Will throw an error if the environment does not exist
357
+ *
358
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
359
+ * @returns A promise that resolves to the environment context.
360
+ *
361
+ * @example
362
+ * ```ts
363
+ * const devEnv = await apiContext.getEnvironment("development");
364
+ * const defaultEnv = await apiContext.getEnvironment();
365
+ * ```
366
+ */
367
+ getEnvironment: (name?: string) => Promise<EnvironmentContext<TResolvedConfig>>;
368
+ /**
369
+ * Safely retrieves the context for a specific environment by name
370
+ *
371
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
372
+ * @returns A promise that resolves to the environment context, or undefined if the environment does not exist.
373
+ *
374
+ * @example
375
+ * ```ts
376
+ * const devEnv = await apiContext.getEnvironmentSafe("development");
377
+ * const defaultEnv = await apiContext.getEnvironmentSafe();
378
+ * ```
379
+ *
380
+ * @remarks
381
+ * This method is similar to `getEnvironment`, but it returns `undefined` instead of throwing an error if the specified environment does not exist.
382
+ * This can be useful in scenarios where the existence of an environment is optional or uncertain.
383
+ *
384
+ * ```ts
385
+ * const testEnv = await apiContext.getEnvironmentSafe("test");
386
+ * if (testEnv) {
387
+ * // Environment exists, safe to use it
388
+ * } else {
389
+ * // Environment does not exist, handle accordingly
390
+ * }
391
+ * ```
392
+ *
393
+ * Using this method helps avoid unhandled exceptions in cases where an environment might not be defined.
394
+ */
395
+ getEnvironmentSafe: (name?: string) => Promise<EnvironmentContext<TResolvedConfig> | undefined>;
396
+ /**
397
+ * A function to copy the context and update the fields for a specific environment
398
+ *
399
+ * @param environment - The environment configuration to use.
400
+ * @returns A new context instance with the updated environment.
401
+ */
402
+ in: (environment: EnvironmentResolvedConfig) => Promise<EnvironmentContext<TResolvedConfig>>;
403
+ /**
404
+ * A function to merge all configured environments into a single context
405
+ *
406
+ * @returns A promise that resolves to the merged environment context.
407
+ */
408
+ toEnvironment: () => Promise<EnvironmentContext<TResolvedConfig>>;
409
+ }
410
+ interface EnvironmentContextPlugin<TResolvedConfig extends ResolvedConfig = ResolvedConfig> {
411
+ plugin: Plugin<PluginContext<TResolvedConfig>>;
412
+ context: PluginContext<TResolvedConfig>;
413
+ }
414
+ interface SelectHooksResult<TResolvedConfig extends ResolvedConfig, TKey extends HookKeys<PluginContext<TResolvedConfig>>> {
415
+ handle: Hooks[TKey];
416
+ context: PluginContext<TResolvedConfig>;
417
+ }
418
+ interface EnvironmentContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
419
+ /**
420
+ * The expected plugins options for the Powerlines project.
421
+ *
422
+ * @remarks
423
+ * This is a record of plugin identifiers to their respective options. This field is populated by the Powerlines engine during both plugin initialization and the `init` command.
424
+ */
425
+ plugins: EnvironmentContextPlugin<TResolvedConfig>[];
426
+ /**
427
+ * A function to add a plugin to the context and update the configuration options
428
+ */
429
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
430
+ /**
431
+ * The environment specific resolved configuration
432
+ */
433
+ environment: EnvironmentResolvedConfig;
434
+ /**
435
+ * A table holding references to hook functions registered by plugins
436
+ */
437
+ hooks: HooksList<PluginContext<TResolvedConfig>>;
438
+ /**
439
+ * Retrieves the hook handlers for a specific hook name
440
+ */
441
+ selectHooks: <TKey extends HookKeys<PluginContext<TResolvedConfig>>>(hook: TKey, options?: SelectHooksOptions) => SelectHooksResult<TResolvedConfig, TKey>[];
442
+ }
332
443
  interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig>, UnpluginContext {
333
444
  /**
334
445
  * The environment specific resolved configuration
@@ -344,4 +455,4 @@ interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedCon
344
455
  }
345
456
  type BuildPluginContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = UnpluginBuildContext & PluginContext<TResolvedConfig>;
346
457
  //#endregion
347
- export { BuildPluginContext, PluginContext, UnresolvedContext };
458
+ export { APIContext, BuildPluginContext, EnvironmentContext, PluginContext, SelectHooksOptions, UnresolvedContext };
@@ -1,9 +1,9 @@
1
1
  import { ResolveOptions, VirtualFile, VirtualFileSystemInterface } from "./fs.mjs";
2
2
  import { EnvironmentResolvedConfig, ResolvedConfig, ResolvedEntryTypeDefinition } from "./resolved.mjs";
3
- import "./plugin.mjs";
3
+ import { Plugin } from "./plugin.mjs";
4
4
  import { ParsedTypeScriptConfig } from "./tsconfig.mjs";
5
5
  import { InlineConfig, LogFn, UserConfig, WorkspaceConfig } from "./config.mjs";
6
- import "./hooks.mjs";
6
+ import { HookKeys, Hooks, HooksList } from "./hooks.mjs";
7
7
  import { ExternalIdResult, UnpluginBuildContext, UnpluginContext, UnpluginMessage } from "unplugin";
8
8
  import { Project } from "ts-morph";
9
9
  import { EnvPaths } from "@stryke/env/get-env-paths";
@@ -51,6 +51,9 @@ interface TransformResult$1 {
51
51
  code: string;
52
52
  map: SourceMap | null;
53
53
  }
54
+ interface SelectHooksOptions {
55
+ order?: "pre" | "post" | "normal";
56
+ }
54
57
  interface InitContextOptions {
55
58
  /**
56
59
  * If false, the plugin will be loaded after all other plugins.
@@ -331,6 +334,112 @@ type Context<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = Omit<Unr
331
334
  */
332
335
  config: TResolvedConfig;
333
336
  };
337
+ interface APIContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
338
+ /**
339
+ * The expected plugins options for the Powerlines project.
340
+ *
341
+ * @remarks
342
+ * This is a record of plugin identifiers to their respective options. This field is populated by the Powerlines engine during both plugin initialization and the `init` command.
343
+ */
344
+ plugins: Plugin<PluginContext<TResolvedConfig>>[];
345
+ /**
346
+ * A function to add a plugin to the context and update the configuration options
347
+ */
348
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
349
+ /**
350
+ * A table for storing the current context for each configured environment
351
+ */
352
+ environments: Record<string, EnvironmentContext<TResolvedConfig>>;
353
+ /**
354
+ * Retrieves the context for a specific environment by name
355
+ *
356
+ * @throws Will throw an error if the environment does not exist
357
+ *
358
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
359
+ * @returns A promise that resolves to the environment context.
360
+ *
361
+ * @example
362
+ * ```ts
363
+ * const devEnv = await apiContext.getEnvironment("development");
364
+ * const defaultEnv = await apiContext.getEnvironment();
365
+ * ```
366
+ */
367
+ getEnvironment: (name?: string) => Promise<EnvironmentContext<TResolvedConfig>>;
368
+ /**
369
+ * Safely retrieves the context for a specific environment by name
370
+ *
371
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
372
+ * @returns A promise that resolves to the environment context, or undefined if the environment does not exist.
373
+ *
374
+ * @example
375
+ * ```ts
376
+ * const devEnv = await apiContext.getEnvironmentSafe("development");
377
+ * const defaultEnv = await apiContext.getEnvironmentSafe();
378
+ * ```
379
+ *
380
+ * @remarks
381
+ * This method is similar to `getEnvironment`, but it returns `undefined` instead of throwing an error if the specified environment does not exist.
382
+ * This can be useful in scenarios where the existence of an environment is optional or uncertain.
383
+ *
384
+ * ```ts
385
+ * const testEnv = await apiContext.getEnvironmentSafe("test");
386
+ * if (testEnv) {
387
+ * // Environment exists, safe to use it
388
+ * } else {
389
+ * // Environment does not exist, handle accordingly
390
+ * }
391
+ * ```
392
+ *
393
+ * Using this method helps avoid unhandled exceptions in cases where an environment might not be defined.
394
+ */
395
+ getEnvironmentSafe: (name?: string) => Promise<EnvironmentContext<TResolvedConfig> | undefined>;
396
+ /**
397
+ * A function to copy the context and update the fields for a specific environment
398
+ *
399
+ * @param environment - The environment configuration to use.
400
+ * @returns A new context instance with the updated environment.
401
+ */
402
+ in: (environment: EnvironmentResolvedConfig) => Promise<EnvironmentContext<TResolvedConfig>>;
403
+ /**
404
+ * A function to merge all configured environments into a single context
405
+ *
406
+ * @returns A promise that resolves to the merged environment context.
407
+ */
408
+ toEnvironment: () => Promise<EnvironmentContext<TResolvedConfig>>;
409
+ }
410
+ interface EnvironmentContextPlugin<TResolvedConfig extends ResolvedConfig = ResolvedConfig> {
411
+ plugin: Plugin<PluginContext<TResolvedConfig>>;
412
+ context: PluginContext<TResolvedConfig>;
413
+ }
414
+ interface SelectHooksResult<TResolvedConfig extends ResolvedConfig, TKey extends HookKeys<PluginContext<TResolvedConfig>>> {
415
+ handle: Hooks[TKey];
416
+ context: PluginContext<TResolvedConfig>;
417
+ }
418
+ interface EnvironmentContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
419
+ /**
420
+ * The expected plugins options for the Powerlines project.
421
+ *
422
+ * @remarks
423
+ * This is a record of plugin identifiers to their respective options. This field is populated by the Powerlines engine during both plugin initialization and the `init` command.
424
+ */
425
+ plugins: EnvironmentContextPlugin<TResolvedConfig>[];
426
+ /**
427
+ * A function to add a plugin to the context and update the configuration options
428
+ */
429
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
430
+ /**
431
+ * The environment specific resolved configuration
432
+ */
433
+ environment: EnvironmentResolvedConfig;
434
+ /**
435
+ * A table holding references to hook functions registered by plugins
436
+ */
437
+ hooks: HooksList<PluginContext<TResolvedConfig>>;
438
+ /**
439
+ * Retrieves the hook handlers for a specific hook name
440
+ */
441
+ selectHooks: <TKey extends HookKeys<PluginContext<TResolvedConfig>>>(hook: TKey, options?: SelectHooksOptions) => SelectHooksResult<TResolvedConfig, TKey>[];
442
+ }
334
443
  interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig>, UnpluginContext {
335
444
  /**
336
445
  * The environment specific resolved configuration
@@ -346,4 +455,4 @@ interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedCon
346
455
  }
347
456
  type BuildPluginContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = UnpluginBuildContext & PluginContext<TResolvedConfig>;
348
457
  //#endregion
349
- export { BuildPluginContext, PluginContext, UnresolvedContext };
458
+ export { APIContext, BuildPluginContext, EnvironmentContext, PluginContext, SelectHooksOptions, UnresolvedContext };
@@ -0,0 +1,30 @@
1
+ import { BasePluginHookFunctions, ExternalPluginHookFunctions, Plugin, PluginHookFunctions, PluginHookObject } from "./plugin.cjs";
2
+ import { PluginContext } from "./context.cjs";
3
+
4
+ //#region ../powerlines/src/types/hooks.d.ts
5
+ type BaseHooks<TContext extends PluginContext = PluginContext> = BasePluginHookFunctions<TContext>;
6
+ type BaseHookKeys<TContext extends PluginContext = PluginContext> = keyof BaseHooks<TContext>;
7
+ type ExternalHooks<TContext extends PluginContext = PluginContext> = ExternalPluginHookFunctions<TContext>;
8
+ type ExternalHookKeys<TContext extends PluginContext = PluginContext> = keyof ExternalHooks<TContext>;
9
+ type Hooks<TContext extends PluginContext = PluginContext> = PluginHookFunctions<TContext>;
10
+ type HookKeys<TContext extends PluginContext = PluginContext> = keyof Hooks<TContext>;
11
+ interface BaseHooksListItem<TContext extends PluginContext = PluginContext, TKey$1 extends BaseHookKeys<TContext> = BaseHookKeys<TContext>> extends PluginHookObject<BaseHooks<TContext>[TKey$1]> {
12
+ plugin: Plugin<TContext>;
13
+ }
14
+ interface BaseHooksList<TContext extends PluginContext = PluginContext, TKey$1 extends BaseHookKeys<TContext> = BaseHookKeys<TContext>> {
15
+ preOrdered?: BaseHooksListItem<TContext, TKey$1>[];
16
+ preEnforced?: BaseHooksListItem<TContext, TKey$1>[];
17
+ normal?: BaseHooksListItem<TContext, TKey$1>[];
18
+ postEnforced?: BaseHooksListItem<TContext, TKey$1>[];
19
+ postOrdered?: BaseHooksListItem<TContext, TKey$1>[];
20
+ }
21
+ interface ExternalHooksListItem<TContext extends PluginContext = PluginContext, TKey$1 extends ExternalHookKeys<TContext> = ExternalHookKeys<TContext>> {
22
+ plugin: Plugin<TContext>;
23
+ handler: ExternalHooks<TContext>[TKey$1];
24
+ }
25
+ type HooksList<TContext extends PluginContext = PluginContext> = { [TKey in BaseHookKeys<TContext>]?: BaseHooksList<TContext, TKey> } & { [TKey in ExternalHookKeys<TContext>]?: ExternalHooksListItem<TContext, TKey>[] };
26
+ type InferHookHandler<TContext extends PluginContext, TKey$1 extends HookKeys<TContext>> = Hooks<TContext>[TKey$1];
27
+ type InferHookReturnType<TContext extends PluginContext, TKey$1 extends HookKeys<TContext>> = ReturnType<InferHookHandler<TContext, TKey$1>> extends Promise<infer U> ? U extends Promise<infer V> ? V : U : ReturnType<InferHookHandler<TContext, TKey$1>>;
28
+ type InferHookParameters<TContext extends PluginContext, TKey$1 extends HookKeys<TContext>> = Parameters<InferHookHandler<TContext, TKey$1>>;
29
+ //#endregion
30
+ export { HookKeys, Hooks, HooksList, InferHookParameters, InferHookReturnType };
@@ -1,2 +1,30 @@
1
- import "./plugin.mjs";
2
- import "./context.mjs";
1
+ import { BasePluginHookFunctions, ExternalPluginHookFunctions, Plugin, PluginHookFunctions, PluginHookObject } from "./plugin.mjs";
2
+ import { PluginContext } from "./context.mjs";
3
+
4
+ //#region ../powerlines/src/types/hooks.d.ts
5
+ type BaseHooks<TContext extends PluginContext = PluginContext> = BasePluginHookFunctions<TContext>;
6
+ type BaseHookKeys<TContext extends PluginContext = PluginContext> = keyof BaseHooks<TContext>;
7
+ type ExternalHooks<TContext extends PluginContext = PluginContext> = ExternalPluginHookFunctions<TContext>;
8
+ type ExternalHookKeys<TContext extends PluginContext = PluginContext> = keyof ExternalHooks<TContext>;
9
+ type Hooks<TContext extends PluginContext = PluginContext> = PluginHookFunctions<TContext>;
10
+ type HookKeys<TContext extends PluginContext = PluginContext> = keyof Hooks<TContext>;
11
+ interface BaseHooksListItem<TContext extends PluginContext = PluginContext, TKey$1 extends BaseHookKeys<TContext> = BaseHookKeys<TContext>> extends PluginHookObject<BaseHooks<TContext>[TKey$1]> {
12
+ plugin: Plugin<TContext>;
13
+ }
14
+ interface BaseHooksList<TContext extends PluginContext = PluginContext, TKey$1 extends BaseHookKeys<TContext> = BaseHookKeys<TContext>> {
15
+ preOrdered?: BaseHooksListItem<TContext, TKey$1>[];
16
+ preEnforced?: BaseHooksListItem<TContext, TKey$1>[];
17
+ normal?: BaseHooksListItem<TContext, TKey$1>[];
18
+ postEnforced?: BaseHooksListItem<TContext, TKey$1>[];
19
+ postOrdered?: BaseHooksListItem<TContext, TKey$1>[];
20
+ }
21
+ interface ExternalHooksListItem<TContext extends PluginContext = PluginContext, TKey$1 extends ExternalHookKeys<TContext> = ExternalHookKeys<TContext>> {
22
+ plugin: Plugin<TContext>;
23
+ handler: ExternalHooks<TContext>[TKey$1];
24
+ }
25
+ type HooksList<TContext extends PluginContext = PluginContext> = { [TKey in BaseHookKeys<TContext>]?: BaseHooksList<TContext, TKey> } & { [TKey in ExternalHookKeys<TContext>]?: ExternalHooksListItem<TContext, TKey>[] };
26
+ type InferHookHandler<TContext extends PluginContext, TKey$1 extends HookKeys<TContext>> = Hooks<TContext>[TKey$1];
27
+ type InferHookReturnType<TContext extends PluginContext, TKey$1 extends HookKeys<TContext>> = ReturnType<InferHookHandler<TContext, TKey$1>> extends Promise<infer U> ? U extends Promise<infer V> ? V : U : ReturnType<InferHookHandler<TContext, TKey$1>>;
28
+ type InferHookParameters<TContext extends PluginContext, TKey$1 extends HookKeys<TContext>> = Parameters<InferHookHandler<TContext, TKey$1>>;
29
+ //#endregion
30
+ export { HookKeys, Hooks, HooksList, InferHookParameters, InferHookReturnType };