1 | /**
|
2 | * Helper routines for use with the jsii compiler
|
3 | *
|
4 | * These are mostly used for testing, but all projects that need to exercise
|
5 | * the JSII compiler to test something need to share this code, so might as
|
6 | * well put it in one reusable place.
|
7 | */
|
8 | import { PackageJson } from '@jsii/spec';
|
9 | import * as spec from '@jsii/spec';
|
10 | import { CompilerOptions } from './compiler';
|
11 | /**
|
12 | * A set of source files for `sourceToAssemblyHelper`, at least containing 'index.ts'
|
13 | */
|
14 | export type MultipleSourceFiles = {
|
15 | 'index.ts': string;
|
16 | [name: string]: string;
|
17 | };
|
18 | /**
|
19 | * Compile a piece of source and return the JSII assembly for it
|
20 | *
|
21 | * Only usable for trivial cases and tests.
|
22 | *
|
23 | * @param source can either be a single `string` (the content of `index.ts`), or
|
24 | * a map of fileName to content, which *must* include `index.ts`.
|
25 | * @param options accepts a callback for historical reasons but really expects to
|
26 | * take an options object.
|
27 | */
|
28 | export declare function sourceToAssemblyHelper(source: string | MultipleSourceFiles, options?: TestCompilationOptions | ((obj: PackageJson) => void)): spec.Assembly;
|
29 | export interface HelperCompilationResult {
|
30 | /**
|
31 | * The generated assembly
|
32 | */
|
33 | readonly assembly: spec.Assembly;
|
34 | /**
|
35 | * Generated .js/.d.ts file(s)
|
36 | */
|
37 | readonly files: Record<string, string>;
|
38 | /**
|
39 | * The packageInfo used
|
40 | */
|
41 | readonly packageJson: PackageJson;
|
42 | /**
|
43 | * Whether to compress the assembly file
|
44 | */
|
45 | readonly compressAssembly: boolean;
|
46 | }
|
47 | /**
|
48 | * Compile a piece of source and return the assembly and compiled sources for it
|
49 | *
|
50 | * Only usable for trivial cases and tests.
|
51 | *
|
52 | * @param source can either be a single `string` (the content of `index.ts`), or
|
53 | * a map of fileName to content, which *must* include `index.ts`.
|
54 | * @param options accepts a callback for historical reasons but really expects to
|
55 | * take an options object.
|
56 | */
|
57 | export declare function compileJsiiForTest(source: string | {
|
58 | 'index.ts': string;
|
59 | [name: string]: string;
|
60 | }, options?: TestCompilationOptions | ((obj: PackageJson) => void), compilerOptions?: Omit<CompilerOptions, 'projectInfo' | 'watch'>): HelperCompilationResult;
|
61 | export interface TestCompilationOptions {
|
62 | /**
|
63 | * The directory in which we write and compile the files
|
64 | */
|
65 | readonly compilationDirectory?: string;
|
66 | /**
|
67 | * Parts of projectInfo to override (package name etc)
|
68 | *
|
69 | * @deprecated Prefer using `packageJson` instead.
|
70 | */
|
71 | readonly projectInfo?: Partial<PackageJson>;
|
72 | /**
|
73 | * Parts of projectInfo to override (package name etc)
|
74 | *
|
75 | * @default - Use some default values
|
76 | */
|
77 | readonly packageJson?: Partial<PackageJson>;
|
78 | /**
|
79 | * Whether to compress the assembly file.
|
80 | *
|
81 | * @default false
|
82 | */
|
83 | readonly compressAssembly?: boolean;
|
84 | }
|
85 | /**
|
86 | * An NPM-ready workspace where we can install test-compile dependencies and compile new assemblies
|
87 | */
|
88 | export declare class TestWorkspace {
|
89 | readonly rootDirectory: string;
|
90 | /**
|
91 | * Create a new workspace.
|
92 | *
|
93 | * Creates a temporary directory, don't forget to call cleanUp
|
94 | */
|
95 | static create(): TestWorkspace;
|
96 | /**
|
97 | * Execute a block with a temporary workspace
|
98 | */
|
99 | static withWorkspace<A>(block: (ws: TestWorkspace) => A): A;
|
100 | private readonly installed;
|
101 | private constructor();
|
102 | /**
|
103 | * Add a test-compiled jsii assembly as a dependency
|
104 | */
|
105 | addDependency(dependencyAssembly: HelperCompilationResult): void;
|
106 | dependencyDir(name: string): string;
|
107 | cleanup(): void;
|
108 | }
|
109 | export type PackageInfo = PackageJson;
|
110 | //# sourceMappingURL=helpers.d.ts.map |
\ | No newline at end of file |