Skip to content

Commit 9378880

Browse files
dependabot[bot]marikanercloud-sdk-js
authored
chore(deps): bump bignumber.js from 9.3.1 to 10.0.2 (#6359)
* chore(deps): bump bignumber.js from 9.3.1 to 10.0.2 Bumps [bignumber.js](https://github.com/MikeMcl/bignumber.js) from 9.3.1 to 10.0.2. - [Release notes](https://github.com/MikeMcl/bignumber.js/releases) - [Changelog](https://github.com/MikeMcl/bignumber.js/blob/main/CHANGELOG.md) - [Commits](MikeMcl/bignumber.js@v9.3.1...v10.0.2) --- updated-dependencies: - dependency-name: bignumber.js dependency-version: 10.0.2 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * Add default imports * fix some tests * Changes from lint:fix * regenerate * fix common generation * remove unnecessary dependency --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Marika Marszalkowski <[email protected]> Co-authored-by: cloud-sdk-js <[email protected]>
1 parent 01151c2 commit 9378880

33 files changed

Lines changed: 118 additions & 86 deletions

File tree

.github/actions/check-public-api/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/generator-common/src/file-writer/imports.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export interface Import {
77
* Names of the exports that are to be imported.
88
*/
99
names: string[];
10+
/**
11+
* The default export to import.
12+
*/
13+
defaultImport?: string | undefined;
1014
/**
1115
* The module to import from.
1216
*/
@@ -21,11 +25,13 @@ export interface Import {
2125
* @internal
2226
*/
2327
export function serializeImports(imports: Import[]): string {
24-
const relevantImports = imports.filter(({ names }) => names.length);
28+
const relevantImports = imports.filter(
29+
({ names, defaultImport }) => names.length || defaultImport
30+
);
2531
return relevantImports
2632
.map(
27-
({ names, moduleIdentifier, typeOnly }) =>
28-
codeBlock`import ${typeOnly ? 'type ' : ''}{ ${names.join(
33+
({ names, defaultImport, moduleIdentifier, typeOnly }) =>
34+
codeBlock`import ${typeOnly ? 'type ' : ''}${defaultImport ? `${defaultImport},` : ''}{ ${names.join(
2935
', '
3036
)} } from '${moduleIdentifier}';`
3137
)

packages/generator/src/generator-without-ts-morph/entity-api/imports.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,24 @@ function complexTypeImport(
5656
*/
5757
export function externalImports(properties: VdmMappedEdmType[]): Import[] {
5858
return potentialExternalImportDeclarations
59-
.map(([moduleIdentifier, ...names]) =>
60-
externalImport(properties, moduleIdentifier, names)
59+
.map(({ moduleSpecifier, namedImports = [], defaultImport }) =>
60+
externalImport(properties, moduleSpecifier, namedImports, defaultImport)
6161
)
6262
.filter(anImport => anImport.names && anImport.names.length);
6363
}
6464

6565
function externalImport(
6666
properties: VdmMappedEdmType[],
6767
moduleIdentifier: string,
68-
names: string[]
68+
names: string[] = [],
69+
defaultImport: string | undefined
6970
): Import {
7071
return {
7172
moduleIdentifier,
7273
names: names.filter(name =>
7374
properties.map(prop => prop.jsType).includes(name)
74-
)
75+
),
76+
defaultImport
7577
};
7678
}
7779

packages/generator/src/generator-without-ts-morph/imports.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,19 @@ export function externalImportDeclarations(
1111
properties: VdmMappedEdmType[]
1212
): Import[] {
1313
return potentialExternalImportDeclarations
14-
.map(([moduleIdentifier, ...names]) =>
15-
externalImportDeclaration(properties, moduleIdentifier, names)
14+
.map(({ moduleSpecifier, namedImports, defaultImport }) =>
15+
externalImportDeclaration(
16+
properties,
17+
moduleSpecifier,
18+
namedImports,
19+
defaultImport
20+
)
1621
)
17-
.filter(declaration => declaration.names && declaration.names.length);
22+
.filter(
23+
declaration =>
24+
(declaration.names && declaration.names.length) ||
25+
declaration.defaultImport
26+
);
1827
}
1928

2029
/**
@@ -23,13 +32,19 @@ export function externalImportDeclarations(
2332
export function externalImportDeclaration(
2433
properties: VdmMappedEdmType[],
2534
moduleIdentifier: string,
26-
names: string[]
35+
names: string[] = [],
36+
defaultImport: string | undefined
2737
): Import {
2838
return {
2939
moduleIdentifier,
3040
names: names.filter(namedImport =>
3141
properties.map(prop => prop.jsType).includes(namedImport)
32-
)
42+
),
43+
defaultImport: properties
44+
.map(prop => prop.jsType)
45+
.includes(defaultImport || '')
46+
? defaultImport
47+
: undefined
3348
};
3449
}
3550

packages/generator/src/generator-without-ts-morph/service/file.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export function imports(
6363
})),
6464
...operations,
6565
{
66-
names: ['BigNumber'],
66+
names: [],
67+
defaultImport: 'BigNumber',
6768
moduleIdentifier: 'bignumber.js'
6869
},
6970
{

packages/generator/src/imports.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ describe('imports', () => {
174174
namedImports: ['2']
175175
} as ImportDeclarationStructure;
176176

177-
it('merges named imports', () => {
177+
it('merges imports', () => {
178178
const merged = {
179179
kind: StructureKind.ImportDeclaration,
180180
moduleSpecifier: './module',
@@ -195,7 +195,7 @@ describe('imports', () => {
195195
).toEqual([merged, momentImport, bigNumberImport]);
196196
});
197197

198-
it('merges named imports including type imports', () => {
198+
it('merges imports including type imports', () => {
199199
const declarations = [
200200
{ ...declaration1FromModule, isTypeOnly: true },
201201
declaration2FromModule

packages/generator/src/imports.ts

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ import type { CreateFileOptions } from '@sap-cloud-sdk/generator-common/internal
1414
* @internal
1515
*/
1616
export const potentialExternalImportDeclarations = [
17-
['moment', 'Moment', 'Duration'],
18-
['bignumber.js', 'BigNumber']
17+
{
18+
moduleSpecifier: 'moment',
19+
namedImports: ['Moment', 'Duration']
20+
},
21+
{
22+
moduleSpecifier: 'bignumber.js',
23+
defaultImport: 'BigNumber'
24+
}
1925
];
2026

2127
/**
@@ -25,32 +31,35 @@ export function externalImportDeclarationsTsMorph(
2531
properties: VdmMappedEdmType[]
2632
): ImportDeclarationStructure[] {
2733
return potentialExternalImportDeclarations
28-
.map(([moduleSpecifier, ...namedImports]) =>
29-
externalImportDeclarationTsMorph(
30-
properties,
31-
moduleSpecifier,
32-
namedImports
33-
)
34+
.map(importDeclaration =>
35+
externalImportDeclarationTsMorph(properties, importDeclaration)
3436
)
3537
.filter(
36-
declaration => declaration.namedImports && declaration.namedImports.length
38+
declaration =>
39+
(declaration.namedImports && declaration.namedImports.length) ||
40+
declaration.defaultImport
3741
);
3842
}
3943

40-
/**
41-
* @internal
42-
*/
43-
export function externalImportDeclarationTsMorph(
44+
function externalImportDeclarationTsMorph(
4445
properties: VdmMappedEdmType[],
45-
moduleSpecifier: string,
46-
namedImports: string[]
46+
{
47+
moduleSpecifier,
48+
namedImports = [],
49+
defaultImport
50+
}: (typeof potentialExternalImportDeclarations)[number]
4751
): ImportDeclarationStructure {
4852
return {
4953
kind: StructureKind.ImportDeclaration,
5054
moduleSpecifier,
5155
namedImports: namedImports.filter(namedImport =>
5256
properties.map(prop => prop.jsType).includes(namedImport)
53-
)
57+
),
58+
defaultImport:
59+
defaultImport &&
60+
properties
61+
.map(prop => prop.jsType)
62+
.find(jsType => jsType === defaultImport)
5463
};
5564
}
5665

@@ -132,7 +141,7 @@ export function enumTypeImportDeclarations(
132141
);
133142
}
134143

135-
// Only supports named imports
144+
// Does not support writer functions or strings as named imports
136145
/**
137146
* @internal
138147
*/
@@ -142,47 +151,41 @@ export function mergeImportDeclarations(
142151
return importDeclarations
143152
.reduce(
144153
(mergedDeclarations: ImportDeclarationStructure[], importDeclaration) => {
145-
const sameModuleSpecifier = mergedDeclarations.find(
154+
const mergedDeclaration = mergedDeclarations.find(
146155
declaration =>
147156
declaration.moduleSpecifier === importDeclaration.moduleSpecifier &&
148157
declaration.isTypeOnly === importDeclaration.isTypeOnly
149158
);
150-
if (sameModuleSpecifier) {
151-
if (!sameModuleSpecifier.namedImports) {
152-
sameModuleSpecifier.namedImports = [
153-
...(importDeclaration.namedImports as string[])
154-
];
155-
} else if (sameModuleSpecifier.namedImports instanceof Array) {
156-
sameModuleSpecifier.namedImports = [
157-
...sameModuleSpecifier.namedImports,
158-
...(importDeclaration.namedImports as string[])
159-
];
160-
} else {
161-
sameModuleSpecifier.namedImports = [
162-
sameModuleSpecifier.namedImports,
163-
...(importDeclaration.namedImports as string[])
164-
];
159+
if (mergedDeclaration) {
160+
const mergedNamedImports = mergedDeclaration.namedImports || [];
161+
const newNamedImports = importDeclaration.namedImports || [];
162+
if (
163+
!Array.isArray(mergedNamedImports) ||
164+
!Array.isArray(newNamedImports)
165+
) {
166+
throw new Error(
167+
'mergeImportDeclarations only supports array or undefined named imports. This should never happen.'
168+
);
165169
}
170+
mergedDeclaration.namedImports = unique([
171+
...mergedNamedImports,
172+
...newNamedImports
173+
]);
174+
175+
mergedDeclaration.defaultImport =
176+
mergedDeclaration.defaultImport || importDeclaration.defaultImport;
166177
} else {
167178
mergedDeclarations.push(importDeclaration);
168179
}
169180
return mergedDeclarations;
170181
},
171182
[]
172183
)
173-
.map(importDeclaration => {
174-
if (!importDeclaration.namedImports) {
175-
importDeclaration.namedImports = undefined;
176-
} else if (importDeclaration.namedImports instanceof Array) {
177-
importDeclaration.namedImports = unique(importDeclaration.namedImports);
178-
} else {
179-
importDeclaration.namedImports = [importDeclaration.namedImports];
180-
}
181-
return importDeclaration;
182-
})
183184
.filter(
184185
importDeclaration =>
185-
importDeclaration.namedImports && importDeclaration.namedImports.length
186+
(importDeclaration.namedImports &&
187+
importDeclaration.namedImports.length) ||
188+
importDeclaration.defaultImport
186189
);
187190
}
188191

packages/generator/test/test-util/import-declaration-structures.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ export const momentImport = {
1010
export const bigNumberImport = {
1111
kind: StructureKind.ImportDeclaration,
1212
moduleSpecifier: 'bignumber.js',
13-
namedImports: ['BigNumber']
13+
defaultImport: 'BigNumber',
14+
namedImports: []
1415
} as ImportDeclarationStructure;

packages/odata-common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@sap-cloud-sdk/connectivity": "^4.5.1",
4444
"@sap-cloud-sdk/http-client": "^4.5.1",
4545
"@sap-cloud-sdk/util": "^4.5.1",
46-
"bignumber.js": "^9.3.1",
46+
"bignumber.js": "^10.0.2",
4747
"moment": "^2.30.1",
4848
"voca": "^1.4.1"
4949
},

packages/odata-v2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"@sap-cloud-sdk/http-client": "^4.5.1",
4545
"@sap-cloud-sdk/odata-common": "^4.5.1",
4646
"@sap-cloud-sdk/util": "^4.5.1",
47-
"bignumber.js": "^9.3.1",
47+
"bignumber.js": "^10.0.2",
4848
"moment": "^2.30.1"
4949
},
5050
"devDependencies": {

0 commit comments

Comments
 (0)