jsii 6.0.25-dev.2 → 6.0.26-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 +65 -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 +2 -2
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
|
@@ -84,6 +84,8 @@ class Assembler {
|
|
|
84
84
|
mainFile;
|
|
85
85
|
tscRootDir;
|
|
86
86
|
tscOutDir;
|
|
87
|
+
/** Set when package.json's `types` is outside of tsc's outDir, to explain a missing `mainFile`. */
|
|
88
|
+
typesOutsideOutDir;
|
|
87
89
|
compressAssembly;
|
|
88
90
|
usedFeatures = new Set();
|
|
89
91
|
_typeChecker;
|
|
@@ -93,6 +95,8 @@ class Assembler {
|
|
|
93
95
|
_packageInfoCache = new Map();
|
|
94
96
|
/** Map of Symbol to namespace export Symbol */
|
|
95
97
|
_submoduleMap = new Map();
|
|
98
|
+
/** Symbols reachable from the entry point's exports, including those of submodules and namespaces. */
|
|
99
|
+
_entryPointExports;
|
|
96
100
|
/**
|
|
97
101
|
* Submodule information
|
|
98
102
|
*
|
|
@@ -136,6 +140,7 @@ class Assembler {
|
|
|
136
140
|
this.tscOutDir = (0, helpers_1.normalizeConfigPath)(projectInfo.projectRoot, program.getCompilerOptions().outDir);
|
|
137
141
|
if (this.tscOutDir != null) {
|
|
138
142
|
mainFile = path.relative(this.tscOutDir, mainFile);
|
|
143
|
+
const typesOutsideOutDir = isOutsideOfDirectory(mainFile);
|
|
139
144
|
// rootDir may be set explicitly or not. If not, inferRootDir replicates
|
|
140
145
|
// tsc's behavior of using the longest prefix of all built source files.
|
|
141
146
|
// rootDir might also be absolute (just like outDir), so we normalize it
|
|
@@ -146,6 +151,15 @@ class Assembler {
|
|
|
146
151
|
if (this.tscRootDir != null) {
|
|
147
152
|
mainFile = path.join(this.tscRootDir, mainFile);
|
|
148
153
|
}
|
|
154
|
+
if (typesOutsideOutDir) {
|
|
155
|
+
// tsc writes declarations into outDir, so `types` can't be re-rooted from it, and the entry point is usually
|
|
156
|
+
// looked up in the wrong place. Remember where tsc puts the declarations, to report that if it is not found.
|
|
157
|
+
const fromRootDir = path.relative(this.tscRootDir ?? '.', dts);
|
|
158
|
+
this.typesOutsideOutDir = {
|
|
159
|
+
types: dts,
|
|
160
|
+
suggestion: isOutsideOfDirectory(fromRootDir) ? undefined : path.join(this.tscOutDir, fromRootDir),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
149
163
|
}
|
|
150
164
|
this.mainFile = path.resolve(projectInfo.projectRoot, mainFile);
|
|
151
165
|
this.runtimeTypeInfoInjector = new runtime_info_1.RuntimeTypeInfoInjector(projectInfo.version);
|
|
@@ -171,7 +185,10 @@ class Assembler {
|
|
|
171
185
|
}
|
|
172
186
|
const docs = _loadDocs.call(this);
|
|
173
187
|
const sourceFile = this.program.getSourceFile(this.mainFile);
|
|
174
|
-
if (sourceFile == null) {
|
|
188
|
+
if (sourceFile == null && this.typesOutsideOutDir != null) {
|
|
189
|
+
this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_0008_TYPES_OUTSIDE_OUT_DIR.createDetached(this.typesOutsideOutDir.types, this.tscOutDir, this.typesOutsideOutDir.suggestion));
|
|
190
|
+
}
|
|
191
|
+
else if (sourceFile == null) {
|
|
175
192
|
this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_0004_COULD_NOT_FIND_ENTRYPOINT.createDetached(this.mainFile));
|
|
176
193
|
}
|
|
177
194
|
else {
|
|
@@ -181,6 +198,7 @@ class Assembler {
|
|
|
181
198
|
}
|
|
182
199
|
const symbol = this._typeChecker.getSymbolAtLocation(sourceFile);
|
|
183
200
|
if (symbol) {
|
|
201
|
+
this._entryPointExports = this._collectEntryPointExports(symbol);
|
|
184
202
|
const moduleExports = this._typeChecker.getExportsOfModule(symbol);
|
|
185
203
|
moduleExports.map((item) => this._registerNamespaces(item, this.projectInfo.projectRoot));
|
|
186
204
|
for (const node of moduleExports) {
|
|
@@ -907,7 +925,9 @@ class Assembler {
|
|
|
907
925
|
const processBaseTypes = (types) => {
|
|
908
926
|
for (const iface of types) {
|
|
909
927
|
// base is private/internal, so we continue recursively with it's own bases
|
|
910
|
-
if (this._isPrivateOrInternal(iface.symbol) ||
|
|
928
|
+
if (this._isPrivateOrInternal(iface.symbol) ||
|
|
929
|
+
isInternalSymbol(iface.symbol) ||
|
|
930
|
+
this._isUnexportedLocalType(iface.symbol)) {
|
|
911
931
|
erasedBases.push(iface);
|
|
912
932
|
if (!isInternalSymbol(iface.symbol)) {
|
|
913
933
|
const bases = iface.getBaseTypes();
|
|
@@ -983,7 +1003,7 @@ class Assembler {
|
|
|
983
1003
|
// base classes ("extends foo")
|
|
984
1004
|
// Crawl up the inheritance tree if the current base type is not exported, so we identify the type(s) to be
|
|
985
1005
|
// erased, and identify the closest exported base class, should there be one.
|
|
986
|
-
while (base?.symbol && this._isPrivateOrInternal(base.symbol)) {
|
|
1006
|
+
while (base?.symbol && (this._isPrivateOrInternal(base.symbol) || this._isUnexportedLocalType(base.symbol))) {
|
|
987
1007
|
LOG.debug(`Base class of ${chalk_1.default.green(jsiiType.fqn)} named ${chalk_1.default.green(base.symbol.name)} is not exported, erasing it...`);
|
|
988
1008
|
erasedBases.push(base);
|
|
989
1009
|
base = (base.getBaseTypes() ?? [])[0];
|
|
@@ -1239,6 +1259,42 @@ class Assembler {
|
|
|
1239
1259
|
return ((symbol.declarations?.length ?? 0) > 0 &&
|
|
1240
1260
|
symbol.declarations.every((decl) => directives_1.Directives.of(decl, (diag) => this._diagnostics.push(diag)).ignore != null));
|
|
1241
1261
|
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Collects the symbols exported from the entry point, following re-exports into submodules and namespaces.
|
|
1264
|
+
*/
|
|
1265
|
+
_collectEntryPointExports(entryPoint) {
|
|
1266
|
+
const result = new Set();
|
|
1267
|
+
const visit = (moduleSymbol) => {
|
|
1268
|
+
for (const exported of this._typeChecker.getExportsOfModule(moduleSymbol)) {
|
|
1269
|
+
const target = (exported.flags & ts.SymbolFlags.Alias) !== 0 ? this._typeChecker.getAliasedSymbol(exported) : exported;
|
|
1270
|
+
if (result.has(target)) {
|
|
1271
|
+
continue;
|
|
1272
|
+
}
|
|
1273
|
+
result.add(target);
|
|
1274
|
+
if ((target.flags & ts.SymbolFlags.Module) !== 0) {
|
|
1275
|
+
visit(target);
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
};
|
|
1279
|
+
visit(entryPoint);
|
|
1280
|
+
return result;
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Whether a type is declared in this package's sources but is not reachable from the entry point. Such a type is
|
|
1284
|
+
* hidden from jsii consumers just like a type declared without `export`, which it must have to be imported from
|
|
1285
|
+
* another file.
|
|
1286
|
+
*/
|
|
1287
|
+
_isUnexportedLocalType(symbol) {
|
|
1288
|
+
if (this._entryPointExports == null || this._entryPointExports.has(symbol)) {
|
|
1289
|
+
return false;
|
|
1290
|
+
}
|
|
1291
|
+
const declarations = symbol.declarations ?? [];
|
|
1292
|
+
return (declarations.length > 0 &&
|
|
1293
|
+
declarations.every((decl) => {
|
|
1294
|
+
const sourceFile = decl.getSourceFile();
|
|
1295
|
+
return !sourceFile.isDeclarationFile && !this.program.isSourceFileFromExternalLibrary(sourceFile);
|
|
1296
|
+
}));
|
|
1297
|
+
}
|
|
1242
1298
|
/**
|
|
1243
1299
|
* @returns true if this member is internal and should be omitted from the type manifest
|
|
1244
1300
|
*/
|
|
@@ -1733,7 +1789,8 @@ class Assembler {
|
|
|
1733
1789
|
this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_1001_TYPE_HAS_NO_SYMBOL.create(declaration));
|
|
1734
1790
|
return { type: spec.CANONICAL_ANY };
|
|
1735
1791
|
}
|
|
1736
|
-
|
|
1792
|
+
// Built-in Array/ReadonlyArray (including `readonly T[]`), by type identity.
|
|
1793
|
+
if (type.symbol.name === 'Array' || this._typeChecker.isArrayType(type)) {
|
|
1737
1794
|
return { type: _arrayType.call(this) };
|
|
1738
1795
|
}
|
|
1739
1796
|
if (type.symbol.name === '__type' && type.symbol.members) {
|
|
@@ -2482,6 +2539,10 @@ class EmitContext {
|
|
|
2482
2539
|
return new EmitContext(this.namespace, undefined);
|
|
2483
2540
|
}
|
|
2484
2541
|
}
|
|
2542
|
+
/** Whether a path that is relative to some directory points outside of that directory. */
|
|
2543
|
+
function isOutsideOfDirectory(relativePath) {
|
|
2544
|
+
return relativePath === '..' || relativePath.startsWith(`..${path.sep}`) || path.isAbsolute(relativePath);
|
|
2545
|
+
}
|
|
2485
2546
|
function inferRootDir(program) {
|
|
2486
2547
|
const directories = program
|
|
2487
2548
|
.getRootFileNames()
|