jsii 5.9.6-dev.0 → 5.9.6

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/lib/helpers.d.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import { PackageJson } from '@jsii/spec';
9
9
  import * as spec from '@jsii/spec';
10
+ import { Diagnostic } from 'typescript';
10
11
  import { CompilerOptions } from './compiler';
11
12
  /**
12
13
  * A set of source files for `sourceToAssemblyHelper`, at least containing 'index.ts'
@@ -15,6 +16,10 @@ export type MultipleSourceFiles = {
15
16
  'index.ts': string;
16
17
  [name: string]: string;
17
18
  };
19
+ /**
20
+ * Assembly features supported by this compiler
21
+ */
22
+ export declare const ASSEMBLY_FEATURES_SUPPORTED: spec.JsiiFeature[];
18
23
  /**
19
24
  * Compile a piece of source and return the JSII assembly for it
20
25
  *
@@ -26,7 +31,15 @@ export type MultipleSourceFiles = {
26
31
  * take an options object.
27
32
  */
28
33
  export declare function sourceToAssemblyHelper(source: string | MultipleSourceFiles, options?: TestCompilationOptions | ((obj: PackageJson) => void)): spec.Assembly;
34
+ export type HelperCompilationOut = HelperCompilationResult | HelperCompilationFailure;
35
+ /**
36
+ * Successful output of a compilation command (for testing)
37
+ *
38
+ * A better name would have been `HelperCompilationSuccess`, but the name is part of
39
+ * the public API surface, so we keep it like this.
40
+ */
29
41
  export interface HelperCompilationResult {
42
+ readonly type: 'success';
30
43
  /**
31
44
  * The generated assembly
32
45
  */
@@ -43,6 +56,19 @@ export interface HelperCompilationResult {
43
56
  * Whether to compress the assembly file
44
57
  */
45
58
  readonly compressAssembly: boolean;
59
+ /**
60
+ * Diagnostics that occurred during compilation
61
+ */
62
+ readonly diagnostics: readonly Diagnostic[];
63
+ }
64
+ export interface HelperCompilationFailure {
65
+ readonly type: 'failure';
66
+ /**
67
+ * Diagnostics that occurred during compilation
68
+ *
69
+ * Contains at least one error.
70
+ */
71
+ readonly diagnostics: readonly Diagnostic[];
46
72
  }
47
73
  /**
48
74
  * Compile a piece of source and return the assembly and compiled sources for it
@@ -54,10 +80,11 @@ export interface HelperCompilationResult {
54
80
  * @param options accepts a callback for historical reasons but really expects to
55
81
  * take an options object.
56
82
  */
57
- export declare function compileJsiiForTest(source: string | {
83
+ export declare function compileJsiiForTest<O extends TestCompilationOptions>(source: string | {
58
84
  'index.ts': string;
59
85
  [name: string]: string;
60
- }, options?: TestCompilationOptions | ((obj: PackageJson) => void), compilerOptions?: Omit<CompilerOptions, 'projectInfo' | 'watch'>): HelperCompilationResult;
86
+ }, options?: O | ((obj: PackageJson) => void), compilerOptions?: Omit<CompilerOptions, 'projectInfo' | 'watch'>): ResultOrSuccess<O>;
87
+ type ResultOrSuccess<O extends TestCompilationOptions> = O['captureDiagnostics'] extends true ? HelperCompilationOut : HelperCompilationResult;
61
88
  export interface TestCompilationOptions {
62
89
  /**
63
90
  * The directory in which we write and compile the files
@@ -81,6 +108,12 @@ export interface TestCompilationOptions {
81
108
  * @default false
82
109
  */
83
110
  readonly compressAssembly?: boolean;
111
+ /**
112
+ * Whether or not to print the diagnostics
113
+ *
114
+ * @default false
115
+ */
116
+ readonly captureDiagnostics?: boolean;
84
117
  }
85
118
  /**
86
119
  * An NPM-ready workspace where we can install test-compile dependencies and compile new assemblies
@@ -102,7 +135,7 @@ export declare class TestWorkspace {
102
135
  /**
103
136
  * Add a test-compiled jsii assembly as a dependency
104
137
  */
105
- addDependency(dependencyAssembly: HelperCompilationResult): void;
138
+ addDependency(dependencyAssembly: HelperCompilationOut): void;
106
139
  dependencyDir(name: string): string;
107
140
  cleanup(): void;
108
141
  }
@@ -116,4 +149,5 @@ export type PackageInfo = PackageJson;
116
149
  * @param pathToNormalize the path to normalize, might be empty
117
150
  */
118
151
  export declare function normalizeConfigPath(root: string, pathToNormalize?: string): string | undefined;
152
+ export {};
119
153
  //# sourceMappingURL=helpers.d.ts.map
package/lib/helpers.js CHANGED
@@ -7,7 +7,7 @@
7
7
  * well put it in one reusable place.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.TestWorkspace = void 0;
10
+ exports.TestWorkspace = exports.ASSEMBLY_FEATURES_SUPPORTED = void 0;
11
11
  exports.sourceToAssemblyHelper = sourceToAssemblyHelper;
12
12
  exports.compileJsiiForTest = compileJsiiForTest;
13
13
  exports.normalizeConfigPath = normalizeConfigPath;
@@ -19,6 +19,10 @@ const typescript_1 = require("typescript");
19
19
  const compiler_1 = require("./compiler");
20
20
  const project_info_1 = require("./project-info");
21
21
  const utils_1 = require("./utils");
22
+ /**
23
+ * Assembly features supported by this compiler
24
+ */
25
+ exports.ASSEMBLY_FEATURES_SUPPORTED = ['intersection-types'];
22
26
  /**
23
27
  * Compile a piece of source and return the JSII assembly for it
24
28
  *
@@ -30,7 +34,11 @@ const utils_1 = require("./utils");
30
34
  * take an options object.
31
35
  */
32
36
  function sourceToAssemblyHelper(source, options) {
33
- return compileJsiiForTest(source, options).assembly;
37
+ const result = compileJsiiForTest(source, options);
38
+ if (result.type !== 'success') {
39
+ throw new Error('Compilation failed');
40
+ }
41
+ return result.assembly;
34
42
  }
35
43
  /**
36
44
  * Compile a piece of source and return the assembly and compiled sources for it
@@ -65,14 +73,22 @@ function compileJsiiForTest(source, options, compilerOptions) {
65
73
  });
66
74
  const emitResult = compiler.emit();
67
75
  const errors = emitResult.diagnostics.filter((d) => d.category === typescript_1.DiagnosticCategory.Error);
68
- for (const error of errors) {
69
- console.error((0, utils_1.formatDiagnostic)(error, projectInfo.projectRoot));
70
- // logDiagnostic() doesn't work out of the box, so console.error() it is.
76
+ if (typeof options !== 'object' || !options?.captureDiagnostics) {
77
+ for (const error of errors) {
78
+ console.error((0, utils_1.formatDiagnostic)(error, projectInfo.projectRoot));
79
+ // logDiagnostic() doesn't work out of the box, so console.error() it is.
80
+ }
71
81
  }
72
82
  if (errors.length > 0 || emitResult.emitSkipped) {
83
+ if (typeof options === 'object' && options?.captureDiagnostics) {
84
+ return {
85
+ type: 'failure',
86
+ diagnostics: emitResult.diagnostics,
87
+ };
88
+ }
73
89
  throw new utils_1.JsiiError('There were compiler errors');
74
90
  }
75
- const assembly = (0, spec_1.loadAssemblyFromPath)(process.cwd(), false);
91
+ const assembly = (0, spec_1.loadAssemblyFromPath)(process.cwd(), false, exports.ASSEMBLY_FEATURES_SUPPORTED);
76
92
  const files = {};
77
93
  for (const filename of Object.keys(source)) {
78
94
  let jsFile = filename.replace(/\.ts$/, '.js');
@@ -94,10 +110,12 @@ function compileJsiiForTest(source, options, compilerOptions) {
94
110
  }
95
111
  }
96
112
  return {
113
+ type: 'success',
97
114
  assembly,
98
115
  files,
99
116
  packageJson,
100
117
  compressAssembly: isOptionsObject(options) && options.compressAssembly ? true : false,
118
+ diagnostics: emitResult.diagnostics,
101
119
  };
102
120
  });
103
121
  }
@@ -187,6 +205,9 @@ class TestWorkspace {
187
205
  * Add a test-compiled jsii assembly as a dependency
188
206
  */
189
207
  addDependency(dependencyAssembly) {
208
+ if (dependencyAssembly.type !== 'success') {
209
+ throw new utils_1.JsiiError('Cannot add dependency: assembly compilation failed');
210
+ }
190
211
  if (this.installed.has(dependencyAssembly.assembly.name)) {
191
212
  throw new utils_1.JsiiError(`A dependency with name '${dependencyAssembly.assembly.name}' was already installed. Give one a different name.`);
192
213
  }
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AA+BH,wDAKC;AAkCD,gDAyEC;AA4LD,kDAKC;AA9UD,8BAA8B;AAC9B,8BAA8B;AAC9B,kCAAkC;AAClC,qCAA8E;AAE9E,2CAAgD;AAEhD,yCAAuD;AACvD,iDAA8D;AAC9D,mCAAsD;AAUtD;;;;;;;;;GASG;AACH,SAAgB,sBAAsB,CACpC,MAAoC,EACpC,OAA+D;IAE/D,OAAO,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC;AACtD,CAAC;AAwBD;;;;;;;;;GAS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AAgB,mBAAmB,CAAC,IAAY,EAAE,eAAwB;IACxE,IAAI,eAAe,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACjE,OAAO,eAAe,CAAC;IACzB,CAAC;IACD,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * Helper routines for use with the jsii compiler\n *\n * These are mostly used for testing, but all projects that need to exercise\n * the JSII compiler to test something need to share this code, so might as\n * well put it in one reusable place.\n */\n\nimport * as fs from 'node:fs';\nimport * as os from 'node:os';\nimport * as path from 'node:path';\nimport { PackageJson, loadAssemblyFromPath, writeAssembly } from '@jsii/spec';\nimport * as spec from '@jsii/spec';\nimport { DiagnosticCategory } from 'typescript';\n\nimport { Compiler, CompilerOptions } from './compiler';\nimport { loadProjectInfo, ProjectInfo } from './project-info';\nimport { formatDiagnostic, JsiiError } from './utils';\n\n/**\n * A set of source files for `sourceToAssemblyHelper`, at least containing 'index.ts'\n */\nexport type MultipleSourceFiles = {\n 'index.ts': string;\n [name: string]: string;\n};\n\n/**\n * Compile a piece of source and return the JSII assembly for it\n *\n * Only usable for trivial cases and tests.\n *\n * @param source can either be a single `string` (the content of `index.ts`), or\n * a map of fileName to content, which *must* include `index.ts`.\n * @param options accepts a callback for historical reasons but really expects to\n * take an options object.\n */\nexport function sourceToAssemblyHelper(\n source: string | MultipleSourceFiles,\n options?: TestCompilationOptions | ((obj: PackageJson) => void),\n): spec.Assembly {\n return compileJsiiForTest(source, options).assembly;\n}\n\nexport interface HelperCompilationResult {\n /**\n * The generated assembly\n */\n readonly assembly: spec.Assembly;\n\n /**\n * Generated .js/.d.ts file(s)\n */\n readonly files: Record<string, string>;\n\n /**\n * The packageInfo used\n */\n readonly packageJson: PackageJson;\n\n /**\n * Whether to compress the assembly file\n */\n readonly compressAssembly: boolean;\n}\n\n/**\n * Compile a piece of source and return the assembly and compiled sources for it\n *\n * Only usable for trivial cases and tests.\n *\n * @param source can either be a single `string` (the content of `index.ts`), or\n * a map of fileName to content, which *must* include `index.ts`.\n * @param options accepts a callback for historical reasons but really expects to\n * take an options object.\n */\nexport function compileJsiiForTest(\n source: string | { 'index.ts': string; [name: string]: string },\n options?: TestCompilationOptions | ((obj: PackageJson) => void),\n compilerOptions?: Omit<CompilerOptions, 'projectInfo' | 'watch'>,\n): HelperCompilationResult {\n if (typeof source === 'string') {\n source = { 'index.ts': source };\n }\n\n const inSomeLocation =\n isOptionsObject(options) && options.compilationDirectory ? inOtherDir(options.compilationDirectory) : inTempDir;\n\n // Easiest way to get the source into the compiler is to write it to disk somewhere.\n // I guess we could make an in-memory compiler host but that seems like work...\n return inSomeLocation(() => {\n for (const [fileName, content] of Object.entries(source)) {\n fs.mkdirSync(path.dirname(fileName), { recursive: true });\n fs.writeFileSync(fileName, content, { encoding: 'utf-8' });\n }\n const { projectInfo, packageJson } = makeProjectInfo(\n 'index.ts',\n typeof options === 'function'\n ? options\n : (pi) => {\n Object.assign(pi, options?.packageJson ?? options?.projectInfo ?? {});\n },\n );\n const compiler = new Compiler({\n projectInfo,\n ...compilerOptions,\n });\n const emitResult = compiler.emit();\n\n const errors = emitResult.diagnostics.filter((d) => d.category === DiagnosticCategory.Error);\n for (const error of errors) {\n console.error(formatDiagnostic(error, projectInfo.projectRoot));\n // logDiagnostic() doesn't work out of the box, so console.error() it is.\n }\n if (errors.length > 0 || emitResult.emitSkipped) {\n throw new JsiiError('There were compiler errors');\n }\n const assembly = loadAssemblyFromPath(process.cwd(), false);\n const files: Record<string, string> = {};\n\n for (const filename of Object.keys(source)) {\n let jsFile = filename.replace(/\\.ts$/, '.js');\n let dtsFile = filename.replace(/\\.ts$/, '.d.ts');\n if (projectInfo.tsc?.outDir && filename !== 'README.md') {\n jsFile = path.join(projectInfo.tsc.outDir, jsFile);\n dtsFile = path.join(projectInfo.tsc.outDir, dtsFile);\n }\n\n // eslint-disable-next-line no-await-in-loop\n files[jsFile] = fs.readFileSync(jsFile, { encoding: 'utf-8' });\n // eslint-disable-next-line no-await-in-loop\n files[dtsFile] = fs.readFileSync(dtsFile, { encoding: 'utf-8' });\n\n const warningsFileName = '.warnings.jsii.js';\n if (fs.existsSync(warningsFileName)) {\n // eslint-disable-next-line no-await-in-loop\n files[warningsFileName] = fs.readFileSync(warningsFileName, {\n encoding: 'utf-8',\n });\n }\n }\n\n return {\n assembly,\n files,\n packageJson,\n compressAssembly: isOptionsObject(options) && options.compressAssembly ? true : false,\n } as HelperCompilationResult;\n });\n}\n\nfunction inTempDir<T>(block: () => T): T {\n const origDir = process.cwd();\n const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsii'));\n process.chdir(tmpDir);\n const ret = block();\n process.chdir(origDir);\n fs.rmSync(tmpDir, { force: true, recursive: true });\n return ret;\n}\n\nfunction inOtherDir(dir: string) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint\n return <T extends unknown>(block: () => T): T => {\n const origDir = process.cwd();\n process.chdir(dir);\n try {\n return block();\n } finally {\n process.chdir(origDir);\n }\n };\n}\n\n/**\n * Obtain project info so we can call the compiler\n *\n * Creating this directly in-memory leads to slightly different behavior from calling\n * jsii from the command-line, and I don't want to figure out right now.\n *\n * Most consistent behavior seems to be to write a package.json to disk and\n * then calling the same functions as the CLI would.\n */\nfunction makeProjectInfo(\n types: string,\n cb?: (obj: PackageJson) => void,\n): { projectInfo: ProjectInfo; packageJson: PackageJson } {\n const packageJson: PackageJson = {\n types,\n main: types.replace(/(?:\\.d)?\\.ts(x?)/, '.js$1'),\n name: 'testpkg', // That's what package.json would tell if we look up...\n version: '0.0.1',\n license: 'Apache-2.0',\n author: { name: 'John Doe' },\n repository: { type: 'git', url: 'https://github.com/aws/jsii.git' },\n jsii: {},\n };\n\n if (cb) {\n cb(packageJson);\n }\n\n fs.writeFileSync(\n 'package.json',\n JSON.stringify(packageJson, (_: string, v: any) => v, 2),\n 'utf-8',\n );\n\n const { projectInfo } = loadProjectInfo(path.resolve(process.cwd(), '.'));\n return { projectInfo, packageJson };\n}\n\nexport interface TestCompilationOptions {\n /**\n * The directory in which we write and compile the files\n */\n readonly compilationDirectory?: string;\n\n /**\n * Parts of projectInfo to override (package name etc)\n *\n * @deprecated Prefer using `packageJson` instead.\n */\n readonly projectInfo?: Partial<PackageJson>;\n\n /**\n * Parts of projectInfo to override (package name etc)\n *\n * @default - Use some default values\n */\n readonly packageJson?: Partial<PackageJson>;\n\n /**\n * Whether to compress the assembly file.\n *\n * @default false\n */\n readonly compressAssembly?: boolean;\n}\n\nfunction isOptionsObject(\n x: TestCompilationOptions | ((obj: PackageJson) => void) | undefined,\n): x is TestCompilationOptions {\n return x ? typeof x === 'object' : false;\n}\n\n/**\n * An NPM-ready workspace where we can install test-compile dependencies and compile new assemblies\n */\nexport class TestWorkspace {\n /**\n * Create a new workspace.\n *\n * Creates a temporary directory, don't forget to call cleanUp\n */\n public static create(): TestWorkspace {\n const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsii-testworkspace'));\n fs.mkdirSync(tmpDir, { recursive: true });\n return new TestWorkspace(tmpDir);\n }\n\n /**\n * Execute a block with a temporary workspace\n */\n public static withWorkspace<A>(block: (ws: TestWorkspace) => A): A {\n const ws = TestWorkspace.create();\n try {\n return block(ws);\n } finally {\n ws.cleanup();\n }\n }\n\n private readonly installed = new Set<string>();\n\n private constructor(public readonly rootDirectory: string) {}\n\n /**\n * Add a test-compiled jsii assembly as a dependency\n */\n public addDependency(dependencyAssembly: HelperCompilationResult) {\n if (this.installed.has(dependencyAssembly.assembly.name)) {\n throw new JsiiError(\n `A dependency with name '${dependencyAssembly.assembly.name}' was already installed. Give one a different name.`,\n );\n }\n this.installed.add(dependencyAssembly.assembly.name);\n\n // The following is silly, however: the helper has compiled the given source to\n // an assembly, and output files, and then removed their traces from disk.\n // We need those files back on disk, so write them back out again.\n //\n // We will drop them in 'node_modules/<name>' so they can be imported\n // as if they were installed.\n const modDir = path.join(this.rootDirectory, 'node_modules', dependencyAssembly.assembly.name);\n fs.mkdirSync(modDir, { recursive: true });\n\n writeAssembly(modDir, dependencyAssembly.assembly, {\n compress: dependencyAssembly.compressAssembly,\n });\n fs.writeFileSync(\n path.join(modDir, 'package.json'),\n JSON.stringify(dependencyAssembly.packageJson, null, 2),\n 'utf-8',\n );\n\n for (const [fileName, fileContents] of Object.entries(dependencyAssembly.files)) {\n fs.mkdirSync(path.dirname(path.join(modDir, fileName)), {\n recursive: true,\n });\n fs.writeFileSync(path.join(modDir, fileName), fileContents);\n }\n }\n\n public dependencyDir(name: string) {\n if (!this.installed.has(name)) {\n throw new JsiiError(`No dependency with name '${name}' has been installed`);\n }\n return path.join(this.rootDirectory, 'node_modules', name);\n }\n\n public cleanup() {\n fs.rmSync(this.rootDirectory, { force: true, recursive: true });\n }\n}\n\n// Alias for backwards compatibility\nexport type PackageInfo = PackageJson;\n\n/**\n * TSConfig paths can either be relative to the project or absolute.\n * This function normalizes paths to be relative to the provided root.\n * After normalization, code using these paths can be much simpler.\n *\n * @param root the project root\n * @param pathToNormalize the path to normalize, might be empty\n */\nexport function normalizeConfigPath(root: string, pathToNormalize?: string): string | undefined {\n if (pathToNormalize == null || !path.isAbsolute(pathToNormalize)) {\n return pathToNormalize;\n }\n return path.relative(root, pathToNormalize);\n}\n"]}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAoCH,wDASC;AA4DD,gDAsFC;AA2MD,kDAKC;AA7YD,8BAA8B;AAC9B,8BAA8B;AAC9B,kCAAkC;AAClC,qCAA8E;AAE9E,2CAA4D;AAE5D,yCAAuD;AACvD,iDAA8D;AAC9D,mCAAsD;AAUtD;;GAEG;AACU,QAAA,2BAA2B,GAAuB,CAAC,oBAAoB,CAAC,CAAC;AAEtF;;;;;;;;;GASG;AACH,SAAgB,sBAAsB,CACpC,MAAoC,EACpC,OAA+D;IAE/D,MAAM,MAA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CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,EAAE;gBACtD,SAAS,EAAE,IAAI;aAChB,CAAC,CAAC;YACH,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAEM,aAAa,CAAC,IAAY;QAC/B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,iBAAS,CAAC,4BAA4B,IAAI,sBAAsB,CAAC,CAAC;QAC9E,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC;IAC7D,CAAC;IAEM,OAAO;QACZ,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAClE,CAAC;CACF;AA/ED,sCA+EC;AAKD;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CAAC,IAAY,EAAE,eAAwB;IACxE,IAAI,eAAe,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACjE,OAAO,eAAe,CAAC;IACzB,CAAC;IACD,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * Helper routines for use with the jsii compiler\n *\n * These are mostly used for testing, but all projects that need to exercise\n * the JSII compiler to test something need to share this code, so might as\n * well put it in one reusable place.\n */\n\nimport * as fs from 'node:fs';\nimport * as os from 'node:os';\nimport * as path from 'node:path';\nimport { PackageJson, loadAssemblyFromPath, writeAssembly } from '@jsii/spec';\nimport * as spec from '@jsii/spec';\nimport { Diagnostic, DiagnosticCategory } from 'typescript';\n\nimport { Compiler, CompilerOptions } from './compiler';\nimport { loadProjectInfo, ProjectInfo } from './project-info';\nimport { formatDiagnostic, JsiiError } from './utils';\n\n/**\n * A set of source files for `sourceToAssemblyHelper`, at least containing 'index.ts'\n */\nexport type MultipleSourceFiles = {\n 'index.ts': string;\n [name: string]: string;\n};\n\n/**\n * Assembly features supported by this compiler\n */\nexport const ASSEMBLY_FEATURES_SUPPORTED: spec.JsiiFeature[] = ['intersection-types'];\n\n/**\n * Compile a piece of source and return the JSII assembly for it\n *\n * Only usable for trivial cases and tests.\n *\n * @param source can either be a single `string` (the content of `index.ts`), or\n * a map of fileName to content, which *must* include `index.ts`.\n * @param options accepts a callback for historical reasons but really expects to\n * take an options object.\n */\nexport function sourceToAssemblyHelper(\n source: string | MultipleSourceFiles,\n options?: TestCompilationOptions | ((obj: PackageJson) => void),\n): spec.Assembly {\n const result = compileJsiiForTest(source, options);\n if (result.type !== 'success') {\n throw new Error('Compilation failed');\n }\n return result.assembly;\n}\n\nexport type HelperCompilationOut = HelperCompilationResult | HelperCompilationFailure;\n\n/**\n * Successful output of a compilation command (for testing)\n *\n * A better name would have been `HelperCompilationSuccess`, but the name is part of\n * the public API surface, so we keep it like this.\n */\nexport interface HelperCompilationResult {\n readonly type: 'success';\n\n /**\n * The generated assembly\n */\n readonly assembly: spec.Assembly;\n\n /**\n * Generated .js/.d.ts file(s)\n */\n readonly files: Record<string, string>;\n\n /**\n * The packageInfo used\n */\n readonly packageJson: PackageJson;\n\n /**\n * Whether to compress the assembly file\n */\n readonly compressAssembly: boolean;\n\n /**\n * Diagnostics that occurred during compilation\n */\n readonly diagnostics: readonly Diagnostic[];\n}\n\nexport interface HelperCompilationFailure {\n readonly type: 'failure';\n\n /**\n * Diagnostics that occurred during compilation\n *\n * Contains at least one error.\n */\n readonly diagnostics: readonly Diagnostic[];\n}\n\n/**\n * Compile a piece of source and return the assembly and compiled sources for it\n *\n * Only usable for trivial cases and tests.\n *\n * @param source can either be a single `string` (the content of `index.ts`), or\n * a map of fileName to content, which *must* include `index.ts`.\n * @param options accepts a callback for historical reasons but really expects to\n * take an options object.\n */\nexport function compileJsiiForTest<O extends TestCompilationOptions>(\n source: string | { 'index.ts': string; [name: string]: string },\n options?: O | ((obj: PackageJson) => void),\n compilerOptions?: Omit<CompilerOptions, 'projectInfo' | 'watch'>,\n): ResultOrSuccess<O> {\n if (typeof source === 'string') {\n source = { 'index.ts': source };\n }\n\n const inSomeLocation =\n isOptionsObject(options) && options.compilationDirectory ? inOtherDir(options.compilationDirectory) : inTempDir;\n\n // Easiest way to get the source into the compiler is to write it to disk somewhere.\n // I guess we could make an in-memory compiler host but that seems like work...\n return inSomeLocation(() => {\n for (const [fileName, content] of Object.entries(source)) {\n fs.mkdirSync(path.dirname(fileName), { recursive: true });\n fs.writeFileSync(fileName, content, { encoding: 'utf-8' });\n }\n const { projectInfo, packageJson } = makeProjectInfo(\n 'index.ts',\n typeof options === 'function'\n ? options\n : (pi) => {\n Object.assign(pi, options?.packageJson ?? options?.projectInfo ?? {});\n },\n );\n const compiler = new Compiler({\n projectInfo,\n ...compilerOptions,\n });\n const emitResult = compiler.emit();\n\n const errors = emitResult.diagnostics.filter((d) => d.category === DiagnosticCategory.Error);\n\n if (typeof options !== 'object' || !options?.captureDiagnostics) {\n for (const error of errors) {\n console.error(formatDiagnostic(error, projectInfo.projectRoot));\n // logDiagnostic() doesn't work out of the box, so console.error() it is.\n }\n }\n\n if (errors.length > 0 || emitResult.emitSkipped) {\n if (typeof options === 'object' && options?.captureDiagnostics) {\n return {\n type: 'failure',\n diagnostics: emitResult.diagnostics,\n } satisfies HelperCompilationFailure;\n }\n throw new JsiiError('There were compiler errors');\n }\n\n const assembly = loadAssemblyFromPath(process.cwd(), false, ASSEMBLY_FEATURES_SUPPORTED);\n const files: Record<string, string> = {};\n\n for (const filename of Object.keys(source)) {\n let jsFile = filename.replace(/\\.ts$/, '.js');\n let dtsFile = filename.replace(/\\.ts$/, '.d.ts');\n if (projectInfo.tsc?.outDir && filename !== 'README.md') {\n jsFile = path.join(projectInfo.tsc.outDir, jsFile);\n dtsFile = path.join(projectInfo.tsc.outDir, dtsFile);\n }\n\n // eslint-disable-next-line no-await-in-loop\n files[jsFile] = fs.readFileSync(jsFile, { encoding: 'utf-8' });\n // eslint-disable-next-line no-await-in-loop\n files[dtsFile] = fs.readFileSync(dtsFile, { encoding: 'utf-8' });\n\n const warningsFileName = '.warnings.jsii.js';\n if (fs.existsSync(warningsFileName)) {\n // eslint-disable-next-line no-await-in-loop\n files[warningsFileName] = fs.readFileSync(warningsFileName, {\n encoding: 'utf-8',\n });\n }\n }\n\n return {\n type: 'success',\n assembly,\n files,\n packageJson,\n compressAssembly: isOptionsObject(options) && options.compressAssembly ? true : false,\n diagnostics: emitResult.diagnostics,\n } satisfies HelperCompilationResult;\n }) as ResultOrSuccess<O>;\n}\n\ntype ResultOrSuccess<O extends TestCompilationOptions> = O['captureDiagnostics'] extends true\n ? HelperCompilationOut\n : HelperCompilationResult;\n\nfunction inTempDir<T>(block: () => T): T {\n const origDir = process.cwd();\n const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsii'));\n process.chdir(tmpDir);\n const ret = block();\n process.chdir(origDir);\n fs.rmSync(tmpDir, { force: true, recursive: true });\n return ret;\n}\n\nfunction inOtherDir(dir: string) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint\n return <T extends unknown>(block: () => T): T => {\n const origDir = process.cwd();\n process.chdir(dir);\n try {\n return block();\n } finally {\n process.chdir(origDir);\n }\n };\n}\n\n/**\n * Obtain project info so we can call the compiler\n *\n * Creating this directly in-memory leads to slightly different behavior from calling\n * jsii from the command-line, and I don't want to figure out right now.\n *\n * Most consistent behavior seems to be to write a package.json to disk and\n * then calling the same functions as the CLI would.\n */\nfunction makeProjectInfo(\n types: string,\n cb?: (obj: PackageJson) => void,\n): { projectInfo: ProjectInfo; packageJson: PackageJson } {\n const packageJson: PackageJson = {\n types,\n main: types.replace(/(?:\\.d)?\\.ts(x?)/, '.js$1'),\n name: 'testpkg', // That's what package.json would tell if we look up...\n version: '0.0.1',\n license: 'Apache-2.0',\n author: { name: 'John Doe' },\n repository: { type: 'git', url: 'https://github.com/aws/jsii.git' },\n jsii: {},\n };\n\n if (cb) {\n cb(packageJson);\n }\n\n fs.writeFileSync(\n 'package.json',\n JSON.stringify(packageJson, (_: string, v: any) => v, 2),\n 'utf-8',\n );\n\n const { projectInfo } = loadProjectInfo(path.resolve(process.cwd(), '.'));\n return { projectInfo, packageJson };\n}\n\nexport interface TestCompilationOptions {\n /**\n * The directory in which we write and compile the files\n */\n readonly compilationDirectory?: string;\n\n /**\n * Parts of projectInfo to override (package name etc)\n *\n * @deprecated Prefer using `packageJson` instead.\n */\n readonly projectInfo?: Partial<PackageJson>;\n\n /**\n * Parts of projectInfo to override (package name etc)\n *\n * @default - Use some default values\n */\n readonly packageJson?: Partial<PackageJson>;\n\n /**\n * Whether to compress the assembly file.\n *\n * @default false\n */\n readonly compressAssembly?: boolean;\n\n /**\n * Whether or not to print the diagnostics\n *\n * @default false\n */\n readonly captureDiagnostics?: boolean;\n}\n\nfunction isOptionsObject(\n x: TestCompilationOptions | ((obj: PackageJson) => void) | undefined,\n): x is TestCompilationOptions {\n return x ? typeof x === 'object' : false;\n}\n\n/**\n * An NPM-ready workspace where we can install test-compile dependencies and compile new assemblies\n */\nexport class TestWorkspace {\n /**\n * Create a new workspace.\n *\n * Creates a temporary directory, don't forget to call cleanUp\n */\n public static create(): TestWorkspace {\n const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsii-testworkspace'));\n fs.mkdirSync(tmpDir, { recursive: true });\n return new TestWorkspace(tmpDir);\n }\n\n /**\n * Execute a block with a temporary workspace\n */\n public static withWorkspace<A>(block: (ws: TestWorkspace) => A): A {\n const ws = TestWorkspace.create();\n try {\n return block(ws);\n } finally {\n ws.cleanup();\n }\n }\n\n private readonly installed = new Set<string>();\n\n private constructor(public readonly rootDirectory: string) {}\n\n /**\n * Add a test-compiled jsii assembly as a dependency\n */\n public addDependency(dependencyAssembly: HelperCompilationOut) {\n if (dependencyAssembly.type !== 'success') {\n throw new JsiiError('Cannot add dependency: assembly compilation failed');\n }\n\n if (this.installed.has(dependencyAssembly.assembly.name)) {\n throw new JsiiError(\n `A dependency with name '${dependencyAssembly.assembly.name}' was already installed. Give one a different name.`,\n );\n }\n this.installed.add(dependencyAssembly.assembly.name);\n\n // The following is silly, however: the helper has compiled the given source to\n // an assembly, and output files, and then removed their traces from disk.\n // We need those files back on disk, so write them back out again.\n //\n // We will drop them in 'node_modules/<name>' so they can be imported\n // as if they were installed.\n const modDir = path.join(this.rootDirectory, 'node_modules', dependencyAssembly.assembly.name);\n fs.mkdirSync(modDir, { recursive: true });\n\n writeAssembly(modDir, dependencyAssembly.assembly, {\n compress: dependencyAssembly.compressAssembly,\n });\n fs.writeFileSync(\n path.join(modDir, 'package.json'),\n JSON.stringify(dependencyAssembly.packageJson, null, 2),\n 'utf-8',\n );\n\n for (const [fileName, fileContents] of Object.entries(dependencyAssembly.files)) {\n fs.mkdirSync(path.dirname(path.join(modDir, fileName)), {\n recursive: true,\n });\n fs.writeFileSync(path.join(modDir, fileName), fileContents);\n }\n }\n\n public dependencyDir(name: string) {\n if (!this.installed.has(name)) {\n throw new JsiiError(`No dependency with name '${name}' has been installed`);\n }\n return path.join(this.rootDirectory, 'node_modules', name);\n }\n\n public cleanup() {\n fs.rmSync(this.rootDirectory, { force: true, recursive: true });\n }\n}\n\n// Alias for backwards compatibility\nexport type PackageInfo = PackageJson;\n\n/**\n * TSConfig paths can either be relative to the project or absolute.\n * This function normalizes paths to be relative to the provided root.\n * After normalization, code using these paths can be much simpler.\n *\n * @param root the project root\n * @param pathToNormalize the path to normalize, might be empty\n */\nexport function normalizeConfigPath(root: string, pathToNormalize?: string): string | undefined {\n if (pathToNormalize == null || !path.isAbsolute(pathToNormalize)) {\n return pathToNormalize;\n }\n return path.relative(root, pathToNormalize);\n}\n"]}
@@ -91,6 +91,11 @@ export declare class JsiiDiagnostic implements ts.Diagnostic {
91
91
  static readonly JSII_1004_DUPLICATE_ENUM_VALUE: Code<(enumValue: string, enumMemberNames: string[]) => string>;
92
92
  static readonly JSII_1005_SEPARATE_WRITE_TYPE: Code<() => string>;
93
93
  static readonly JSII_1006_GENERIC_TYPE: Code<() => string>;
94
+ static readonly JSII_1007_NEVER_TYPE: Code<() => string>;
95
+ static readonly JSII_1008_ONLY_INTERFACE_INTERSECTION: Code<(type: string) => string>;
96
+ static readonly JSII_1009_INTERSECTION_ONLY_INPUT: Code<(location: string) => string>;
97
+ static readonly JSII_1010_INTERSECTION_NOT_IN_CTOR: Code<() => string>;
98
+ static readonly JSII_1011_INTERSECTION_MEMBER_DIFFERENT: Code<(member: string, type1: string, reason1: string, type2: string, reason2: string) => string>;
94
99
  static readonly JSII_1999_UNSUPPORTED: Code<({ what, alternative, suggestInternal, }: {
95
100
  what: string;
96
101
  alternative?: string;
@@ -323,6 +323,31 @@ JsiiDiagnostic.JSII_1006_GENERIC_TYPE = Code.error({
323
323
  formatter: () => 'Generic types are not supported because semantics are not uniform in target languages.',
324
324
  name: 'typescript-restriction/generic-type',
325
325
  });
326
+ JsiiDiagnostic.JSII_1007_NEVER_TYPE = Code.error({
327
+ code: 1007,
328
+ formatter: () => 'The "never" type is not allowed because it cannot be represented in target languages.',
329
+ name: 'typescript-restriction/no-never-type',
330
+ });
331
+ JsiiDiagnostic.JSII_1008_ONLY_INTERFACE_INTERSECTION = Code.error({
332
+ code: 1008,
333
+ formatter: (type) => `Found non-interface type in type intersection: ${type}`,
334
+ name: 'typescript-restriction/only-interface-intersection',
335
+ });
336
+ JsiiDiagnostic.JSII_1009_INTERSECTION_ONLY_INPUT = Code.error({
337
+ code: 1009,
338
+ formatter: (location) => `Intersection types may only be used as inputs, but ${location} is used as output`,
339
+ name: 'typescript-restriction/intersection-only-input',
340
+ });
341
+ JsiiDiagnostic.JSII_1010_INTERSECTION_NOT_IN_CTOR = Code.error({
342
+ code: 1010,
343
+ formatter: () => `Intersection types cannot be used as constructor arguments`,
344
+ name: 'typescript-restriction/intersection-no-ctor',
345
+ });
346
+ JsiiDiagnostic.JSII_1011_INTERSECTION_MEMBER_DIFFERENT = Code.error({
347
+ code: 1011,
348
+ formatter: (member, type1, reason1, type2, reason2) => `Member ${member} is different between types in a type intersection: ${type1} (${reason1}) and ${type2} (${reason2})`,
349
+ name: 'typescript-restriction/intersection-member-different',
350
+ });
326
351
  JsiiDiagnostic.JSII_1999_UNSUPPORTED = Code.error({
327
352
  code: 1999,
328
353
  formatter: ({ what, alternative, suggestInternal, }) => `${what} are not supported in jsii APIs.${alternative ? ` Consider using ${alternative} instead.` : ''}${suggestInternal