Skip to content

Commit 7a7111b

Browse files
authored
Merge pull request #873 from acacode/fix-build-warnings
Fix build warnings
2 parents 5c010c7 + b99cd5b commit 7a7111b

35 files changed

+428
-369
lines changed

cli/execute.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import didYouMean from "didyoumean";
2-
import _ from "lodash";
2+
import * as lodash from "lodash";
33
import { root_command, skip_command } from "./constants.js";
44
import { parseArgs } from "./parse-args.js";
55

@@ -98,14 +98,14 @@ const processArgs = (commands, args) => {
9898

9999
let allFlagKeys = [];
100100

101-
_.forEach(args, (arg, i) => {
101+
lodash.forEach(args, (arg, i) => {
102102
if (error) return;
103103

104104
if (i === 0) {
105105
command = commands[arg];
106106

107107
if (!command && !arg.startsWith("-")) {
108-
const tip = didYouMean(arg, _.keys(commands));
108+
const tip = didYouMean(arg, lodash.keys(commands));
109109
error = `unknown command ${arg}${
110110
tip ? `\n(Did you mean ${tip} ?)` : ""
111111
}`;

cli/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _ from "lodash";
1+
import * as lodash from "lodash";
22
import { reservedOptions, root_command } from "./constants.js";
33
import { execute } from "./execute.js";
44
import { displayHelp } from "./operations/display-help.js";
@@ -12,7 +12,7 @@ const cli = (input) => {
1212
commands[command.name] = {
1313
name: command.name,
1414
description: `${command.description || ""}`,
15-
options: _.compact(_.map(command.options, processOption)),
15+
options: lodash.compact(lodash.map(command.options, processOption)),
1616
};
1717

1818
if (addVersion) {
@@ -57,7 +57,7 @@ const cli = (input) => {
5757
},
5858
);
5959

60-
_.forEach(input.options, (option) => {
60+
lodash.forEach(input.options, (option) => {
6161
const processed = processOption(option);
6262

6363
if (!processed) return;
@@ -86,7 +86,7 @@ const cli = (input) => {
8686
}),
8787
);
8888

89-
_.forEach(input.commands, addCommand);
89+
lodash.forEach(input.commands, addCommand);
9090

9191
return instance;
9292
};

cli/operations/display-help.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _ from "lodash";
1+
import * as lodash from "lodash";
22
import { root_command } from "../constants.js";
33

44
const generateOptionsOutput = (options) =>
@@ -62,32 +62,31 @@ const displayAllHelp = (commands, instance) => {
6262
commands[root_command].options,
6363
);
6464

65-
const { commands: commandLabels, maxLength: maxCommandLength } = _.filter(
66-
commands,
67-
(command) => command.name !== root_command,
68-
).reduce(
69-
(acc, command) => {
70-
const options = generateOptionsOutput(command.options);
71-
const name = `${command.name}${options.length ? " [options]" : ""}`;
72-
const description = command.description;
73-
74-
const maxLength = Math.max(name.length, options.maxLength);
75-
if (maxLength > acc.maxLength) {
76-
acc.maxLength = maxLength;
77-
}
78-
79-
acc.commands.push({
80-
description,
81-
name,
82-
options,
83-
});
84-
return acc;
85-
},
86-
{
87-
commands: [],
88-
maxLength: maxOptionLength,
89-
},
90-
);
65+
const { commands: commandLabels, maxLength: maxCommandLength } = lodash
66+
.filter(commands, (command) => command.name !== root_command)
67+
.reduce(
68+
(acc, command) => {
69+
const options = generateOptionsOutput(command.options);
70+
const name = `${command.name}${options.length ? " [options]" : ""}`;
71+
const description = command.description;
72+
73+
const maxLength = Math.max(name.length, options.maxLength);
74+
if (maxLength > acc.maxLength) {
75+
acc.maxLength = maxLength;
76+
}
77+
78+
acc.commands.push({
79+
description,
80+
name,
81+
options,
82+
});
83+
return acc;
84+
},
85+
{
86+
commands: [],
87+
maxLength: maxOptionLength,
88+
},
89+
);
9190

9291
const optionsOutput = generateOptionsTextOutput(options, maxOptionLength, 2);
9392

cli/process-option.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _ from "lodash";
1+
import * as lodash from "lodash";
22

33
const optionFormatters = {
44
number: (str) => +str,
@@ -15,8 +15,9 @@ const processFlags = (flags) => {
1515
let value = null;
1616
const isNoFlag = flags.includes("--no-");
1717

18-
_.compact(_.split(flags, " ").map((str) => str.replace(/,/g, ""))).forEach(
19-
(str) => {
18+
lodash
19+
.compact(lodash.split(flags, " ").map((str) => str.replace(/,/g, "")))
20+
.forEach((str) => {
2021
if (str.startsWith("-")) {
2122
keys.push(str);
2223
} else if (value === null) {
@@ -31,13 +32,12 @@ const processFlags = (flags) => {
3132
};
3233
}
3334
}
34-
},
35-
);
35+
});
3636

3737
const longestKey = keys.slice().sort((a, b) => b.length - a.length)[0];
3838

39-
if (!_.isEmpty(longestKey)) {
40-
name = _.camelCase(
39+
if (!lodash.isEmpty(longestKey)) {
40+
name = lodash.camelCase(
4141
(isNoFlag ? longestKey.replace("--no-", "") : longestKey).replace(
4242
/(--?)/,
4343
"",

src/code-formatter.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import _ from "lodash";
2-
import prettier from "prettier";
3-
import ts from "typescript";
1+
import * as lodash from "lodash";
2+
import * as prettier from "prettier";
3+
import * as typescript from "typescript";
44

55
class CodeFormatter {
66
/**
@@ -16,15 +16,15 @@ class CodeFormatter {
1616
const tempFileName = "file.ts";
1717

1818
const host = new TsLanguageServiceHost(tempFileName, content);
19-
const languageService = ts.createLanguageService(host);
19+
const languageService = typescript.createLanguageService(host);
2020

2121
const fileTextChanges = languageService.organizeImports(
2222
{ type: "file", fileName: tempFileName },
23-
{ newLineCharacter: ts.sys.newLine },
23+
{ newLineCharacter: typescript.sys.newLine },
2424
)[0];
2525

2626
if (fileTextChanges?.textChanges.length) {
27-
return _.reduceRight(
27+
return lodash.reduceRight(
2828
fileTextChanges.textChanges,
2929
(content, { span, newText }) =>
3030
`${content.slice(0, span.start)}${newText}${content.slice(
@@ -65,21 +65,25 @@ class CodeFormatter {
6565

6666
class TsLanguageServiceHost {
6767
constructor(fileName, content) {
68-
const tsconfig = ts.findConfigFile(fileName, ts.sys.fileExists);
68+
const tsconfig = typescript.findConfigFile(
69+
fileName,
70+
typescript.sys.fileExists,
71+
);
6972

7073
Object.assign(this, {
7174
fileName,
7275
content,
7376
compilerOptions: tsconfig
74-
? ts.convertCompilerOptionsFromJson(
75-
ts.readConfigFile(tsconfig, ts.sys.readFile).config.compilerOptions,
77+
? typescript.convertCompilerOptionsFromJson(
78+
typescript.readConfigFile(tsconfig, typescript.sys.readFile).config
79+
.compilerOptions,
7680
).options
77-
: ts.getDefaultCompilerOptions(),
81+
: typescript.getDefaultCompilerOptions(),
7882
});
7983
}
8084

8185
getNewLine() {
82-
return "newLine" in ts.sys ? ts.sys.newLine : "\n";
86+
return "newLine" in typescript.sys ? typescript.sys.newLine : "\n";
8387
}
8488
getScriptFileNames() {
8589
return [this.fileName];
@@ -88,26 +92,26 @@ class TsLanguageServiceHost {
8892
return this.compilerOptions;
8993
}
9094
getDefaultLibFileName() {
91-
return ts.getDefaultLibFileName(this.getCompilationSettings());
95+
return typescript.getDefaultLibFileName(this.getCompilationSettings());
9296
}
9397
getCurrentDirectory() {
9498
return process.cwd();
9599
}
96100
getScriptVersion() {
97-
return ts.version;
101+
return typescript.version;
98102
}
99103
getScriptSnapshot() {
100-
return ts.ScriptSnapshot.fromString(this.content);
104+
return typescript.ScriptSnapshot.fromString(this.content);
101105
}
102106
readFile(fileName, encoding) {
103107
if (fileName === this.fileName) {
104108
return this.content;
105109
}
106110

107-
return ts.sys.readFile(fileName, encoding);
111+
return typescript.sys.readFile(fileName, encoding);
108112
}
109113
fileExists(path) {
110-
return ts.sys.fileExists(path);
114+
return typescript.sys.fileExists(path);
111115
}
112116
}
113117

src/code-gen-process.js

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import _ from "lodash";
2-
import ts from "typescript";
1+
import * as lodash from "lodash";
2+
import * as typescript from "typescript";
33
import { CodeFormatter } from "./code-formatter.js";
44
import { CodeGenConfig } from "./configuration.js";
55
import { SchemaComponentsMap } from "./schema-components-map.js";
@@ -103,8 +103,8 @@ class CodeGenProcess {
103103

104104
this.schemaComponentsMap.clear();
105105

106-
_.each(swagger.usageSchema.components, (component, componentName) =>
107-
_.each(component, (rawTypeData, typeName) => {
106+
lodash.each(swagger.usageSchema.components, (component, componentName) =>
107+
lodash.each(component, (rawTypeData, typeName) => {
108108
this.schemaComponentsMap.createComponent(
109109
this.schemaComponentsMap.createRef([
110110
"components",
@@ -120,7 +120,7 @@ class CodeGenProcess {
120120
* @type {SchemaComponent[]}
121121
*/
122122
const componentsToParse = this.schemaComponentsMap.filter(
123-
_.compact(["schemas", this.config.extractResponses && "responses"]),
123+
lodash.compact(["schemas", this.config.extractResponses && "responses"]),
124124
);
125125

126126
const parsedSchemas = componentsToParse.map((schemaComponent) => {
@@ -228,7 +228,7 @@ class CodeGenProcess {
228228
return ` * ${line}${eol ? "\n" : ""}`;
229229
},
230230
NameResolver: NameResolver,
231-
_,
231+
_: lodash,
232232
require: this.templatesWorker.requireFnFromTemplate,
233233
},
234234
config: this.config,
@@ -239,7 +239,7 @@ class CodeGenProcess {
239239
const components = this.schemaComponentsMap.getComponents();
240240
let modelTypes = [];
241241

242-
const modelTypeComponents = _.compact([
242+
const modelTypeComponents = lodash.compact([
243243
"schemas",
244244
this.config.extractResponses && "responses",
245245
]);
@@ -322,7 +322,7 @@ class CodeGenProcess {
322322
? await this.createMultipleFileInfos(templatesToRender, configuration)
323323
: await this.createSingleFileInfo(templatesToRender, configuration);
324324

325-
if (!_.isEmpty(configuration.extraTemplates)) {
325+
if (!lodash.isEmpty(configuration.extraTemplates)) {
326326
for (const extraTemplate of configuration.extraTemplates) {
327327
const content = this.templatesWorker.renderTemplate(
328328
this.fileSystem.getFileContent(extraTemplate.path),
@@ -467,27 +467,29 @@ class CodeGenProcess {
467467
return await this.createOutputFileInfo(
468468
configuration,
469469
configuration.fileName,
470-
_.compact([
471-
this.templatesWorker.renderTemplate(
472-
templatesToRender.dataContracts,
473-
configuration,
474-
),
475-
generateRouteTypes &&
476-
this.templatesWorker.renderTemplate(
477-
templatesToRender.routeTypes,
478-
configuration,
479-
),
480-
generateClient &&
481-
this.templatesWorker.renderTemplate(
482-
templatesToRender.httpClient,
483-
configuration,
484-
),
485-
generateClient &&
470+
lodash
471+
.compact([
486472
this.templatesWorker.renderTemplate(
487-
templatesToRender.api,
473+
templatesToRender.dataContracts,
488474
configuration,
489475
),
490-
]).join("\n"),
476+
generateRouteTypes &&
477+
this.templatesWorker.renderTemplate(
478+
templatesToRender.routeTypes,
479+
configuration,
480+
),
481+
generateClient &&
482+
this.templatesWorker.renderTemplate(
483+
templatesToRender.httpClient,
484+
configuration,
485+
),
486+
generateClient &&
487+
this.templatesWorker.renderTemplate(
488+
templatesToRender.api,
489+
configuration,
490+
),
491+
])
492+
.join("\n"),
491493
);
492494
};
493495

@@ -500,7 +502,7 @@ class CodeGenProcess {
500502
*/
501503
createOutputFileInfo = async (configuration, fileNameFull, content) => {
502504
const fileName = this.fileSystem.cropExtension(fileNameFull);
503-
const fileExtension = ts.Extension.Ts;
505+
const fileExtension = typescript.Extension.Ts;
504506

505507
if (configuration.translateToJavaScript) {
506508
this.logger.debug("using js translator for", fileName);
@@ -542,14 +544,14 @@ class CodeGenProcess {
542544
servers: servers || [],
543545
basePath,
544546
host,
545-
externalDocs: _.merge(
547+
externalDocs: lodash.merge(
546548
{
547549
url: "",
548550
description: "",
549551
},
550552
externalDocs,
551553
),
552-
tags: _.compact(tags),
554+
tags: lodash.compact(tags),
553555
baseUrl: serverUrl,
554556
title,
555557
version,

0 commit comments

Comments
 (0)