Skip to content

Commit

Permalink
fix(config): support inlinedLibraries is undefined, mark all as inline.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gggpound committed Dec 11, 2024
1 parent 61d4b5c commit a675bc9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/bundle-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export function generateDtsBundle(entries: readonly EntryPointConfig[], options:
const criteria: ModuleCriteria = {
allowedTypesLibraries: librariesOptions.allowedTypesLibraries,
importedLibraries: librariesOptions.importedLibraries,
inlinedLibraries: librariesOptions.inlinedLibraries || [],
inlinedLibraries: librariesOptions.inlinedLibraries,
typeRoots,
};

Expand Down Expand Up @@ -698,12 +698,14 @@ export function generateDtsBundle(entries: readonly EntryPointConfig[], options:

if (ts.isExportSpecifier(imp)) {
// export { El1, El2 as ExportedName } from 'module';
// @ts-expect-error wait
addNamedImport(importItem, imp.name, imp.propertyName || imp.name);
return;
}

if (ts.isNamespaceExport(imp)) {
// export * as name from 'module';
// @ts-expect-error wait
addNsImport(importItem, imp.name);
return;
}
Expand All @@ -716,6 +718,7 @@ export function generateDtsBundle(entries: readonly EntryPointConfig[], options:

if (ts.isImportSpecifier(imp)) {
// import { El1, El2 as ImportedName } from 'module';
// @ts-expect-error wait
addNamedImport(importItem, imp.name, imp.propertyName || imp.name);
return;
}
Expand Down Expand Up @@ -1102,6 +1105,7 @@ export function generateDtsBundle(entries: readonly EntryPointConfig[], options:

// if it is namespace export then it should be from a inlined module (e.g. `export * as NS from './local-module';`)
if (ts.isNamespaceExport(decl) && !isReferencedModuleImportable(decl.parent)) {
// @ts-expect-error wait
return decl.name;
}

Expand All @@ -1120,6 +1124,7 @@ export function generateDtsBundle(entries: readonly EntryPointConfig[], options:

// in case of a chain of imports/exports we need to keep searching recursively
if (getIdentifierOfNamespaceImportFromInlinedModule(getImportExportReferencedSymbol(decl, typeChecker))) {
// @ts-expect-error wait
return decl.name;
}
}
Expand All @@ -1141,6 +1146,7 @@ export function generateDtsBundle(entries: readonly EntryPointConfig[], options:
});

if (result) {
// @ts-expect-error wait
return decl.name;
}
}
Expand Down Expand Up @@ -1244,6 +1250,7 @@ export function generateDtsBundle(entries: readonly EntryPointConfig[], options:
// here we want to handle creation of artificial namespace for a inlined module
// so we don't care about other type of imports/exports - only these that create a "namespace"
if (ts.isNamespaceExport(imp) || ts.isNamespaceImport(imp)) {
// @ts-expect-error wait
namespaceIdentifier = imp.name;
}
});
Expand Down Expand Up @@ -1392,13 +1399,10 @@ export function generateDtsBundle(entries: readonly EntryPointConfig[], options:
warnLog(`The following type nodes were renamed because of the name collisions and will not be exported from the generated bundle:\n- ${
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
renamedAndNotExplicitlyExportedTypes.map(node => `${getNodeName(node)!.getText()} (from ${node.getSourceFile().fileName})`).join('\n- ')
}${
'\n'
}This might lead to unpredictable and unexpected output, and possible breaking changes to your API.${
'\n'
}${'\n'
}This might lead to unpredictable and unexpected output, and possible breaking changes to your API.${'\n'
}Consider either (re-)exporting them explicitly from the entry point, or disable --export-referenced-types option ('output.exportReferencedTypes' in the config).`);
}

return output;
});
}
4 changes: 2 additions & 2 deletions src/module-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface UsedForModulesModuleInfo extends UsedModuleInfoCommon {
export type ModuleInfo = InlinedModuleInfo | ImportedModuleInfo | ReferencedModuleInfo | UsedForModulesModuleInfo;

export interface ModuleCriteria {
inlinedLibraries: string[];
inlinedLibraries?: string[];
importedLibraries: string[] | undefined;
allowedTypesLibraries: string[] | undefined;
typeRoots?: string[];
Expand Down Expand Up @@ -120,7 +120,7 @@ function getModuleInfoImpl(currentFilePath: string, originalFileName: string, cr
return { type: ModuleType.ShouldBeUsedForModulesOnly, fileName: originalFileName, isExternal: true };
}

function shouldLibraryBeInlined(npmLibraryName: string, typesLibraryName: string | null, inlinedLibraries: string[]): boolean {
function shouldLibraryBeInlined(npmLibraryName: string, typesLibraryName: string | null, inlinedLibraries?: string[]): boolean {
return isLibraryAllowed(npmLibraryName, inlinedLibraries) || typesLibraryName !== null && isLibraryAllowed(typesLibraryName, inlinedLibraries);
}

Expand Down
7 changes: 6 additions & 1 deletion tests/e2e/test-cases/run-test-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ function getTestCaseConfig(testCaseDir: string): TestCase {

const outputFileName = path.resolve(testCaseDir, 'output.d.ts');
assert(fs.existsSync(outputFileName), `Output file doesn't exist for ${testCaseDir}`);

// eslint-disable-next-line @typescript-eslint/no-var-requires
const config = require(path.resolve(testCaseDir, 'config.ts')) as TestCaseConfig;
if (!config.libraries) {
config.libraries = {};
}
config.libraries.inlinedLibraries = config.libraries?.inlinedLibraries || [];
return {
inputFileName,
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down

0 comments on commit a675bc9

Please sign in to comment.