node-modules-architect-host.d.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.dev/license
  7. */
  8. import { json, workspaces } from '@angular-devkit/core';
  9. import { BuilderInfo } from '../src';
  10. import { Target } from '../src/input-schema';
  11. import { ArchitectHost, Builder } from '../src/internal';
  12. export type NodeModulesBuilderInfo = BuilderInfo & {
  13. import: string;
  14. };
  15. export interface WorkspaceHost {
  16. getBuilderName(project: string, target: string): Promise<string>;
  17. getMetadata(project: string): Promise<json.JsonObject>;
  18. getOptions(project: string, target: string, configuration?: string): Promise<json.JsonObject>;
  19. hasTarget(project: string, target: string): Promise<boolean>;
  20. getDefaultConfigurationName(project: string, target: string): Promise<string | undefined>;
  21. }
  22. export declare class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModulesBuilderInfo> {
  23. protected _root: string;
  24. private workspaceHost;
  25. constructor(workspaceHost: WorkspaceHost, _root: string);
  26. constructor(workspace: workspaces.WorkspaceDefinition, _root: string);
  27. getBuilderNameForTarget(target: Target): Promise<string>;
  28. /**
  29. * Resolve a builder. This needs to be a string which will be used in a dynamic `import()`
  30. * clause. This should throw if no builder can be found. The dynamic import will throw if
  31. * it is unsupported.
  32. * @param builderStr The name of the builder to be used.
  33. * @returns All the info needed for the builder itself.
  34. */
  35. resolveBuilder(builderStr: string, basePath?: string, seenBuilders?: Set<string>): Promise<NodeModulesBuilderInfo>;
  36. getCurrentDirectory(): Promise<string>;
  37. getWorkspaceRoot(): Promise<string>;
  38. getOptionsForTarget(target: Target): Promise<json.JsonObject | null>;
  39. getProjectMetadata(target: Target | string): Promise<json.JsonObject | null>;
  40. loadBuilder(info: NodeModulesBuilderInfo): Promise<Builder>;
  41. }
  42. /**
  43. * This uses a dynamic import to load a module which may be ESM.
  44. * CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
  45. * will currently, unconditionally downlevel dynamic import into a require call.
  46. * require calls cannot load ESM code and will result in a runtime error. To workaround
  47. * this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
  48. * Once TypeScript provides support for keeping the dynamic import this workaround can
  49. * be dropped.
  50. *
  51. * @param modulePath The path of the module to load.
  52. * @returns A Promise that resolves to the dynamically imported module.
  53. */
  54. export declare function loadEsmModule<T>(modulePath: string | URL): Promise<T>;