jsii 5.9.62 → 5.9.63-dev.1
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/assembler.d.ts +14 -0
- package/lib/assembler.js +66 -6
- package/lib/assembler.js.map +1 -1
- package/lib/jsii-diagnostic.d.ts +2 -0
- package/lib/jsii-diagnostic.js +16 -0
- package/lib/jsii-diagnostic.js.map +1 -1
- package/lib/version.d.ts +2 -2
- package/lib/version.js +2 -2
- package/lib/version.js.map +1 -1
- package/package.json +4 -3
package/lib/assembler.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export declare class Assembler implements Emitter {
|
|
|
15
15
|
private readonly mainFile;
|
|
16
16
|
private readonly tscRootDir?;
|
|
17
17
|
private readonly tscOutDir?;
|
|
18
|
+
/** Set when package.json's `types` is outside of tsc's outDir, to explain a missing `mainFile`. */
|
|
19
|
+
private readonly typesOutsideOutDir?;
|
|
18
20
|
private readonly compressAssembly?;
|
|
19
21
|
private readonly usedFeatures;
|
|
20
22
|
private readonly _typeChecker;
|
|
@@ -24,6 +26,8 @@ export declare class Assembler implements Emitter {
|
|
|
24
26
|
private readonly _packageInfoCache;
|
|
25
27
|
/** Map of Symbol to namespace export Symbol */
|
|
26
28
|
private readonly _submoduleMap;
|
|
29
|
+
/** Symbols reachable from the entry point's exports, including those of submodules and namespaces. */
|
|
30
|
+
private _entryPointExports?;
|
|
27
31
|
/**
|
|
28
32
|
* Submodule information
|
|
29
33
|
*
|
|
@@ -153,6 +157,16 @@ export declare class Assembler implements Emitter {
|
|
|
153
157
|
* partially-ignored merged declaration stays a visible part of the public API.
|
|
154
158
|
*/
|
|
155
159
|
private _isIgnored;
|
|
160
|
+
/**
|
|
161
|
+
* Collects the symbols exported from the entry point, following re-exports into submodules and namespaces.
|
|
162
|
+
*/
|
|
163
|
+
private _collectEntryPointExports;
|
|
164
|
+
/**
|
|
165
|
+
* Whether a type is declared in this package's sources but is not reachable from the entry point. Such a type is
|
|
166
|
+
* hidden from jsii consumers just like a type declared without `export`, which it must have to be imported from
|
|
167
|
+
* another file.
|
|
168
|
+
*/
|
|
169
|
+
private _isUnexportedLocalType;
|
|
156
170
|
/**
|
|
157
171
|
* @returns true if this member is internal and should be omitted from the type manifest
|
|
158
172
|
*/
|
package/lib/assembler.js
CHANGED
|
@@ -88,6 +88,7 @@ class Assembler {
|
|
|
88
88
|
this.tscOutDir = (0, helpers_1.normalizeConfigPath)(projectInfo.projectRoot, program.getCompilerOptions().outDir);
|
|
89
89
|
if (this.tscOutDir != null) {
|
|
90
90
|
mainFile = path.relative(this.tscOutDir, mainFile);
|
|
91
|
+
const typesOutsideOutDir = isOutsideOfDirectory(mainFile);
|
|
91
92
|
// rootDir may be set explicitly or not. If not, inferRootDir replicates
|
|
92
93
|
// tsc's behavior of using the longest prefix of all built source files.
|
|
93
94
|
// rootDir might also be absolute (just like outDir), so we normalize it
|
|
@@ -98,6 +99,15 @@ class Assembler {
|
|
|
98
99
|
if (this.tscRootDir != null) {
|
|
99
100
|
mainFile = path.join(this.tscRootDir, mainFile);
|
|
100
101
|
}
|
|
102
|
+
if (typesOutsideOutDir) {
|
|
103
|
+
// tsc writes declarations into outDir, so `types` can't be re-rooted from it, and the entry point is usually
|
|
104
|
+
// looked up in the wrong place. Remember where tsc puts the declarations, to report that if it is not found.
|
|
105
|
+
const fromRootDir = path.relative(this.tscRootDir ?? '.', dts);
|
|
106
|
+
this.typesOutsideOutDir = {
|
|
107
|
+
types: dts,
|
|
108
|
+
suggestion: isOutsideOfDirectory(fromRootDir) ? undefined : path.join(this.tscOutDir, fromRootDir),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
101
111
|
}
|
|
102
112
|
this.mainFile = path.resolve(projectInfo.projectRoot, mainFile);
|
|
103
113
|
this.runtimeTypeInfoInjector = new runtime_info_1.RuntimeTypeInfoInjector(projectInfo.version);
|
|
@@ -111,6 +121,9 @@ class Assembler {
|
|
|
111
121
|
* @return the result of the assembly emission.
|
|
112
122
|
*/
|
|
113
123
|
emit() {
|
|
124
|
+
if (this.projectInfo.name.includes('.')) {
|
|
125
|
+
this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_0009_PACKAGE_NAME_CONTAINS_DOT.createDetached(this.projectInfo.name));
|
|
126
|
+
}
|
|
114
127
|
if (!this.projectInfo.description) {
|
|
115
128
|
this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_0001_PKG_MISSING_DESCRIPTION.createDetached());
|
|
116
129
|
}
|
|
@@ -123,7 +136,10 @@ class Assembler {
|
|
|
123
136
|
}
|
|
124
137
|
const docs = _loadDocs.call(this);
|
|
125
138
|
const sourceFile = this.program.getSourceFile(this.mainFile);
|
|
126
|
-
if (sourceFile == null) {
|
|
139
|
+
if (sourceFile == null && this.typesOutsideOutDir != null) {
|
|
140
|
+
this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_0008_TYPES_OUTSIDE_OUT_DIR.createDetached(this.typesOutsideOutDir.types, this.tscOutDir, this.typesOutsideOutDir.suggestion));
|
|
141
|
+
}
|
|
142
|
+
else if (sourceFile == null) {
|
|
127
143
|
this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_0004_COULD_NOT_FIND_ENTRYPOINT.createDetached(this.mainFile));
|
|
128
144
|
}
|
|
129
145
|
else {
|
|
@@ -133,6 +149,7 @@ class Assembler {
|
|
|
133
149
|
}
|
|
134
150
|
const symbol = this._typeChecker.getSymbolAtLocation(sourceFile);
|
|
135
151
|
if (symbol) {
|
|
152
|
+
this._entryPointExports = this._collectEntryPointExports(symbol);
|
|
136
153
|
const moduleExports = this._typeChecker.getExportsOfModule(symbol);
|
|
137
154
|
moduleExports.map((item) => this._registerNamespaces(item, this.projectInfo.projectRoot));
|
|
138
155
|
for (const node of moduleExports) {
|
|
@@ -332,12 +349,12 @@ class Assembler {
|
|
|
332
349
|
if (typeof ref !== 'string') {
|
|
333
350
|
ref = ref.fqn;
|
|
334
351
|
}
|
|
335
|
-
const [assm] = ref.split('.');
|
|
336
352
|
let type;
|
|
337
|
-
if (
|
|
353
|
+
if (ref.startsWith(`${this.projectInfo.name}.`)) {
|
|
338
354
|
type = this._types.get(ref);
|
|
339
355
|
}
|
|
340
356
|
else {
|
|
357
|
+
const [assm] = ref.split('.');
|
|
341
358
|
const assembly = this.projectInfo.dependencyClosure.find((dep) => dep.name === assm);
|
|
342
359
|
type = assembly?.types?.[ref];
|
|
343
360
|
// since we are exposing a type of this assembly in this module's public API,
|
|
@@ -859,7 +876,9 @@ class Assembler {
|
|
|
859
876
|
const processBaseTypes = (types) => {
|
|
860
877
|
for (const iface of types) {
|
|
861
878
|
// base is private/internal, so we continue recursively with it's own bases
|
|
862
|
-
if (this._isPrivateOrInternal(iface.symbol) ||
|
|
879
|
+
if (this._isPrivateOrInternal(iface.symbol) ||
|
|
880
|
+
isInternalSymbol(iface.symbol) ||
|
|
881
|
+
this._isUnexportedLocalType(iface.symbol)) {
|
|
863
882
|
erasedBases.push(iface);
|
|
864
883
|
if (!isInternalSymbol(iface.symbol)) {
|
|
865
884
|
const bases = iface.getBaseTypes();
|
|
@@ -935,7 +954,7 @@ class Assembler {
|
|
|
935
954
|
// base classes ("extends foo")
|
|
936
955
|
// Crawl up the inheritance tree if the current base type is not exported, so we identify the type(s) to be
|
|
937
956
|
// erased, and identify the closest exported base class, should there be one.
|
|
938
|
-
while (base?.symbol && this._isPrivateOrInternal(base.symbol)) {
|
|
957
|
+
while (base?.symbol && (this._isPrivateOrInternal(base.symbol) || this._isUnexportedLocalType(base.symbol))) {
|
|
939
958
|
LOG.debug(`Base class of ${chalk.green(jsiiType.fqn)} named ${chalk.green(base.symbol.name)} is not exported, erasing it...`);
|
|
940
959
|
erasedBases.push(base);
|
|
941
960
|
base = (base.getBaseTypes() ?? [])[0];
|
|
@@ -1191,6 +1210,42 @@ class Assembler {
|
|
|
1191
1210
|
return ((symbol.declarations?.length ?? 0) > 0 &&
|
|
1192
1211
|
symbol.declarations.every((decl) => directives_1.Directives.of(decl, (diag) => this._diagnostics.push(diag)).ignore != null));
|
|
1193
1212
|
}
|
|
1213
|
+
/**
|
|
1214
|
+
* Collects the symbols exported from the entry point, following re-exports into submodules and namespaces.
|
|
1215
|
+
*/
|
|
1216
|
+
_collectEntryPointExports(entryPoint) {
|
|
1217
|
+
const result = new Set();
|
|
1218
|
+
const visit = (moduleSymbol) => {
|
|
1219
|
+
for (const exported of this._typeChecker.getExportsOfModule(moduleSymbol)) {
|
|
1220
|
+
const target = (exported.flags & ts.SymbolFlags.Alias) !== 0 ? this._typeChecker.getAliasedSymbol(exported) : exported;
|
|
1221
|
+
if (result.has(target)) {
|
|
1222
|
+
continue;
|
|
1223
|
+
}
|
|
1224
|
+
result.add(target);
|
|
1225
|
+
if ((target.flags & ts.SymbolFlags.Module) !== 0) {
|
|
1226
|
+
visit(target);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
visit(entryPoint);
|
|
1231
|
+
return result;
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Whether a type is declared in this package's sources but is not reachable from the entry point. Such a type is
|
|
1235
|
+
* hidden from jsii consumers just like a type declared without `export`, which it must have to be imported from
|
|
1236
|
+
* another file.
|
|
1237
|
+
*/
|
|
1238
|
+
_isUnexportedLocalType(symbol) {
|
|
1239
|
+
if (this._entryPointExports == null || this._entryPointExports.has(symbol)) {
|
|
1240
|
+
return false;
|
|
1241
|
+
}
|
|
1242
|
+
const declarations = symbol.declarations ?? [];
|
|
1243
|
+
return (declarations.length > 0 &&
|
|
1244
|
+
declarations.every((decl) => {
|
|
1245
|
+
const sourceFile = decl.getSourceFile();
|
|
1246
|
+
return !sourceFile.isDeclarationFile && !this.program.isSourceFileFromExternalLibrary(sourceFile);
|
|
1247
|
+
}));
|
|
1248
|
+
}
|
|
1194
1249
|
/**
|
|
1195
1250
|
* @returns true if this member is internal and should be omitted from the type manifest
|
|
1196
1251
|
*/
|
|
@@ -1685,7 +1740,8 @@ class Assembler {
|
|
|
1685
1740
|
this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_1001_TYPE_HAS_NO_SYMBOL.create(declaration));
|
|
1686
1741
|
return { type: spec.CANONICAL_ANY };
|
|
1687
1742
|
}
|
|
1688
|
-
|
|
1743
|
+
// Built-in Array/ReadonlyArray (including `readonly T[]`), by type identity.
|
|
1744
|
+
if (type.symbol.name === 'Array' || this._typeChecker.isArrayType(type)) {
|
|
1689
1745
|
return { type: _arrayType.call(this) };
|
|
1690
1746
|
}
|
|
1691
1747
|
if (type.symbol.name === '__type' && type.symbol.members) {
|
|
@@ -2432,6 +2488,10 @@ class EmitContext {
|
|
|
2432
2488
|
return new EmitContext(this.namespace, undefined);
|
|
2433
2489
|
}
|
|
2434
2490
|
}
|
|
2491
|
+
/** Whether a path that is relative to some directory points outside of that directory. */
|
|
2492
|
+
function isOutsideOfDirectory(relativePath) {
|
|
2493
|
+
return relativePath === '..' || relativePath.startsWith(`..${path.sep}`) || path.isAbsolute(relativePath);
|
|
2494
|
+
}
|
|
2435
2495
|
function inferRootDir(program) {
|
|
2436
2496
|
const directories = program
|
|
2437
2497
|
.getRootFileNames()
|