jsii 5.9.62 → 5.9.63-dev.0
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 +61 -4
- package/lib/assembler.js.map +1 -1
- package/lib/jsii-diagnostic.d.ts +1 -0
- package/lib/jsii-diagnostic.js +9 -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);
|
|
@@ -123,7 +133,10 @@ class Assembler {
|
|
|
123
133
|
}
|
|
124
134
|
const docs = _loadDocs.call(this);
|
|
125
135
|
const sourceFile = this.program.getSourceFile(this.mainFile);
|
|
126
|
-
if (sourceFile == null) {
|
|
136
|
+
if (sourceFile == null && this.typesOutsideOutDir != null) {
|
|
137
|
+
this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_0008_TYPES_OUTSIDE_OUT_DIR.createDetached(this.typesOutsideOutDir.types, this.tscOutDir, this.typesOutsideOutDir.suggestion));
|
|
138
|
+
}
|
|
139
|
+
else if (sourceFile == null) {
|
|
127
140
|
this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_0004_COULD_NOT_FIND_ENTRYPOINT.createDetached(this.mainFile));
|
|
128
141
|
}
|
|
129
142
|
else {
|
|
@@ -133,6 +146,7 @@ class Assembler {
|
|
|
133
146
|
}
|
|
134
147
|
const symbol = this._typeChecker.getSymbolAtLocation(sourceFile);
|
|
135
148
|
if (symbol) {
|
|
149
|
+
this._entryPointExports = this._collectEntryPointExports(symbol);
|
|
136
150
|
const moduleExports = this._typeChecker.getExportsOfModule(symbol);
|
|
137
151
|
moduleExports.map((item) => this._registerNamespaces(item, this.projectInfo.projectRoot));
|
|
138
152
|
for (const node of moduleExports) {
|
|
@@ -859,7 +873,9 @@ class Assembler {
|
|
|
859
873
|
const processBaseTypes = (types) => {
|
|
860
874
|
for (const iface of types) {
|
|
861
875
|
// base is private/internal, so we continue recursively with it's own bases
|
|
862
|
-
if (this._isPrivateOrInternal(iface.symbol) ||
|
|
876
|
+
if (this._isPrivateOrInternal(iface.symbol) ||
|
|
877
|
+
isInternalSymbol(iface.symbol) ||
|
|
878
|
+
this._isUnexportedLocalType(iface.symbol)) {
|
|
863
879
|
erasedBases.push(iface);
|
|
864
880
|
if (!isInternalSymbol(iface.symbol)) {
|
|
865
881
|
const bases = iface.getBaseTypes();
|
|
@@ -935,7 +951,7 @@ class Assembler {
|
|
|
935
951
|
// base classes ("extends foo")
|
|
936
952
|
// Crawl up the inheritance tree if the current base type is not exported, so we identify the type(s) to be
|
|
937
953
|
// erased, and identify the closest exported base class, should there be one.
|
|
938
|
-
while (base?.symbol && this._isPrivateOrInternal(base.symbol)) {
|
|
954
|
+
while (base?.symbol && (this._isPrivateOrInternal(base.symbol) || this._isUnexportedLocalType(base.symbol))) {
|
|
939
955
|
LOG.debug(`Base class of ${chalk.green(jsiiType.fqn)} named ${chalk.green(base.symbol.name)} is not exported, erasing it...`);
|
|
940
956
|
erasedBases.push(base);
|
|
941
957
|
base = (base.getBaseTypes() ?? [])[0];
|
|
@@ -1191,6 +1207,42 @@ class Assembler {
|
|
|
1191
1207
|
return ((symbol.declarations?.length ?? 0) > 0 &&
|
|
1192
1208
|
symbol.declarations.every((decl) => directives_1.Directives.of(decl, (diag) => this._diagnostics.push(diag)).ignore != null));
|
|
1193
1209
|
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Collects the symbols exported from the entry point, following re-exports into submodules and namespaces.
|
|
1212
|
+
*/
|
|
1213
|
+
_collectEntryPointExports(entryPoint) {
|
|
1214
|
+
const result = new Set();
|
|
1215
|
+
const visit = (moduleSymbol) => {
|
|
1216
|
+
for (const exported of this._typeChecker.getExportsOfModule(moduleSymbol)) {
|
|
1217
|
+
const target = (exported.flags & ts.SymbolFlags.Alias) !== 0 ? this._typeChecker.getAliasedSymbol(exported) : exported;
|
|
1218
|
+
if (result.has(target)) {
|
|
1219
|
+
continue;
|
|
1220
|
+
}
|
|
1221
|
+
result.add(target);
|
|
1222
|
+
if ((target.flags & ts.SymbolFlags.Module) !== 0) {
|
|
1223
|
+
visit(target);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
};
|
|
1227
|
+
visit(entryPoint);
|
|
1228
|
+
return result;
|
|
1229
|
+
}
|
|
1230
|
+
/**
|
|
1231
|
+
* Whether a type is declared in this package's sources but is not reachable from the entry point. Such a type is
|
|
1232
|
+
* hidden from jsii consumers just like a type declared without `export`, which it must have to be imported from
|
|
1233
|
+
* another file.
|
|
1234
|
+
*/
|
|
1235
|
+
_isUnexportedLocalType(symbol) {
|
|
1236
|
+
if (this._entryPointExports == null || this._entryPointExports.has(symbol)) {
|
|
1237
|
+
return false;
|
|
1238
|
+
}
|
|
1239
|
+
const declarations = symbol.declarations ?? [];
|
|
1240
|
+
return (declarations.length > 0 &&
|
|
1241
|
+
declarations.every((decl) => {
|
|
1242
|
+
const sourceFile = decl.getSourceFile();
|
|
1243
|
+
return !sourceFile.isDeclarationFile && !this.program.isSourceFileFromExternalLibrary(sourceFile);
|
|
1244
|
+
}));
|
|
1245
|
+
}
|
|
1194
1246
|
/**
|
|
1195
1247
|
* @returns true if this member is internal and should be omitted from the type manifest
|
|
1196
1248
|
*/
|
|
@@ -1685,7 +1737,8 @@ class Assembler {
|
|
|
1685
1737
|
this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_1001_TYPE_HAS_NO_SYMBOL.create(declaration));
|
|
1686
1738
|
return { type: spec.CANONICAL_ANY };
|
|
1687
1739
|
}
|
|
1688
|
-
|
|
1740
|
+
// Built-in Array/ReadonlyArray (including `readonly T[]`), by type identity.
|
|
1741
|
+
if (type.symbol.name === 'Array' || this._typeChecker.isArrayType(type)) {
|
|
1689
1742
|
return { type: _arrayType.call(this) };
|
|
1690
1743
|
}
|
|
1691
1744
|
if (type.symbol.name === '__type' && type.symbol.members) {
|
|
@@ -2432,6 +2485,10 @@ class EmitContext {
|
|
|
2432
2485
|
return new EmitContext(this.namespace, undefined);
|
|
2433
2486
|
}
|
|
2434
2487
|
}
|
|
2488
|
+
/** Whether a path that is relative to some directory points outside of that directory. */
|
|
2489
|
+
function isOutsideOfDirectory(relativePath) {
|
|
2490
|
+
return relativePath === '..' || relativePath.startsWith(`..${path.sep}`) || path.isAbsolute(relativePath);
|
|
2491
|
+
}
|
|
2435
2492
|
function inferRootDir(program) {
|
|
2436
2493
|
const directories = program
|
|
2437
2494
|
.getRootFileNames()
|