Skip to content

Commit 66a4c69

Browse files
Merge branch 'master' into clean-some-ts-ignore
2 parents 04ffeb4 + 499dd97 commit 66a4c69

File tree

11 files changed

+46
-40
lines changed

11 files changed

+46
-40
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"simple-git": "2.46.0",
8484
"sinon": "11.1.2",
8585
"ts-node": "10.3.0",
86+
"type-fest": "^2.5.0",
8687
"typescript": "4.4.3"
8788
},
8889
"dependencies": {

src/cli/domain/get-components-by-dir.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import fs from 'fs-extra';
22
import path from 'path';
3+
import { Component } from '../../types';
34

45
export default function getComponentsByDir() {
56
return (componentsDir: string, callback: Callback<string[]>): void => {
67
const isOcComponent = function (file: string) {
78
const filePath = path.resolve(componentsDir, file),
89
packagePath = path.join(filePath, 'package.json');
9-
let content;
10+
let content: Component;
1011

1112
try {
1213
content = fs.readJsonSync(packagePath);

src/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import strings from '../../../resources';
2+
import { Component } from '../../../types';
23

34
export default function ensureCompilerIsDeclaredAsDevDependency(
45
options: {
56
componentPath: string;
6-
pkg: { devDependencies: Dictionary<string> };
7+
pkg: Component;
78
template: string;
89
},
910
cb: Callback<string, string>
1011
): void {
1112
const { componentPath, pkg, template } = options;
1213
const compilerDep = `${template}-compiler`;
13-
const isOk = pkg.devDependencies[compilerDep];
14+
const isOk = pkg.devDependencies?.[compilerDep];
1415

1516
const err = isOk
1617
? null

src/cli/domain/handle-dependencies/get-compiler.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function getCompiler(
99
compilerDep: string;
1010
componentPath: string;
1111
logger: Logger;
12-
pkg: { name: string; devDependencies: Dictionary<string> };
12+
pkg: { devDependencies: Dictionary<string> };
1313
},
1414
cb: Callback<string, string | number>
1515
): void {
@@ -28,7 +28,6 @@ export default function getCompiler(
2828

2929
const installOptions = {
3030
compilerPath,
31-
componentName: pkg.name,
3231
componentPath,
3332
dependency,
3433
logger

src/cli/domain/handle-dependencies/index.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import async from 'async';
22
import coreModules from 'builtin-modules';
33
import fs from 'fs-extra';
44
import path from 'path';
5-
import _ from 'lodash';
65

76
import ensureCompilerIsDeclaredAsDevDependency from './ensure-compiler-is-declared-as-devDependency';
87
import getCompiler from './get-compiler';
@@ -13,8 +12,14 @@ import strings from '../../../resources';
1312
import { Logger } from '../../logger';
1413
import { Component } from '../../../types';
1514

16-
const getComponentPackageJson = (componentPath: string, cb: Callback<any>) =>
17-
fs.readJson(path.join(componentPath, 'package.json'), cb);
15+
const getComponentPackageJson = (
16+
componentPath: string,
17+
cb: Callback<Component>
18+
) => fs.readJson(path.join(componentPath, 'package.json'), cb);
19+
20+
const union = (a: ReadonlyArray<string>, b: ReadonlyArray<string>) => [
21+
...new Set([...a, ...b])
22+
];
1823

1924
export default function handleDependencies(
2025
options: {
@@ -33,10 +38,12 @@ export default function handleDependencies(
3338
const { components, logger, useComponentDependencies } = options;
3439

3540
const dependencies: Dictionary<string> = {};
36-
const addDependencies = (componentDependencies: Dictionary<string>) =>
37-
_.each(componentDependencies || {}, (version, dependency) => {
38-
dependencies[dependency] = version;
39-
});
41+
const addDependencies = (componentDependencies?: Dictionary<string>) =>
42+
Object.entries(componentDependencies || {}).forEach(
43+
([dependency, version]) => {
44+
dependencies[dependency] = version;
45+
}
46+
);
4047

4148
const templates: Dictionary<(...args: unknown[]) => unknown> = {};
4249
const addTemplate = (
@@ -82,21 +89,21 @@ export default function handleDependencies(
8289
cb: any
8390
) =>
8491
ensureCompilerIsDeclaredAsDevDependency(options, (err, compilerDep) =>
85-
cb(err, _.extend(options, { compilerDep }))
92+
cb(err, Object.assign(options, { compilerDep }))
8693
),
8794

8895
(
8996
options: {
9097
componentPath: string;
9198
logger: Logger;
92-
pkg: Component;
99+
pkg: Component & { devDependencies: Dictionary<string> };
93100
template: string;
94101
compilerDep: string;
95102
},
96103
cb: any
97104
) =>
98105
getCompiler(options, (err, compiler) =>
99-
cb(err, _.extend(options, { compiler }))
106+
cb(err, Object.assign(options, { compiler }))
100107
),
101108

102109
(
@@ -121,7 +128,7 @@ export default function handleDependencies(
121128
}
122129

123130
const result = {
124-
modules: _.union(coreModules, Object.keys(dependencies)).sort(),
131+
modules: union(coreModules, Object.keys(dependencies)).sort(),
125132
templates: Object.values(templates)
126133
};
127134
const options = { dependencies, logger };

src/cli/domain/package-components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const packageComponents =
3737

3838
fs.emptyDirSync(publishPath);
3939

40-
const componentPackage = fs.readJsonSync(componentPackagePath);
40+
const componentPackage: Component = fs.readJsonSync(componentPackagePath);
4141
const ocPackage = fs.readJsonSync(ocPackagePath);
4242

4343
if (!validator.validateComponentName(componentPackage.name)) {

src/registry/domain/extract-package.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'path';
22
import targz from 'targz';
3+
import { PackageJson } from 'type-fest';
34

45
import getPackageJsonFromTempDir from './get-package-json-from-temp-dir';
56

@@ -11,7 +12,7 @@ export default function extractPackage(
1112
},
1213
callback: Callback<{
1314
outputFolder: string;
14-
packageJson: any;
15+
packageJson: PackageJson;
1516
}>
1617
): void {
1718
const packageFile: Express.Multer.File = (files as any)[0];
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import fs from 'fs-extra';
22
import path from 'path';
3+
import { PackageJson } from 'type-fest';
34

45
export default function getPackageJsonFromTempDir(
56
tempDirPath: string,
6-
callback: Callback<any>
7+
callback: Callback<PackageJson>
78
): void {
89
return fs.readJson(path.join(tempDirPath, 'package.json'), callback);
910
}

src/registry/routes/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@ import getComponentsHistory from './helpers/get-components-history';
99
import getAvailableDependencies from './helpers/get-available-dependencies';
1010
import indexView from '../views';
1111
import urlBuilder = require('../domain/url-builder');
12-
import { Author, Component, Repository } from '../../types';
12+
import { Author, Component, ParsedComponent, Repository } from '../../types';
1313
import { NextFunction, Request, Response } from 'express';
1414
import { IncomingHttpHeaders } from 'http';
15+
import { PackageJson } from 'type-fest';
1516

16-
const packageInfo = fs.readJsonSync(
17+
const packageInfo: PackageJson = fs.readJsonSync(
1718
path.join(__dirname, '..', '..', '..', 'package.json')
1819
);
1920

20-
const getParsedAuthor = (author: Author | string): Author => {
21+
const getParsedAuthor = (author?: Author | string): Author => {
2122
author = author || {};
2223
return typeof author === 'string' ? parseAuthor(author) : author;
2324
};
2425

25-
const mapComponentDetails = (component: Component): Component =>
26+
const mapComponentDetails = (component: Component): ParsedComponent =>
2627
_.extend(component, { author: getParsedAuthor(component.author) });
2728

2829
const isHtmlRequest = (headers: IncomingHttpHeaders) =>
@@ -43,7 +44,7 @@ export default function (repository: Repository) {
4344
};
4445

4546
if (isHtmlRequest(req.headers) && !!res.conf.discovery) {
46-
let componentsInfo: Component[] = [];
47+
let componentsInfo: ParsedComponent[] = [];
4748
let componentsReleases = 0;
4849
const stateCounts: { deprecated?: number; experimental?: number } = {};
4950

src/registry/views/partials/components-list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, VM } from '../../../types';
1+
import { ParsedComponent, VM } from '../../../types';
22
import getSelectedCheckbox from './selected-checkbox';
33

44
export default function componentsList(vm: VM): string {
@@ -9,7 +9,7 @@ export default function componentsList(vm: VM): string {
99
? '<div class="date">Updated</div><div class="activity">Activity</div>'
1010
: '';
1111

12-
const componentRow = (component: Component) => {
12+
const componentRow = (component: ParsedComponent) => {
1313
const componentState = component.oc.state
1414
? `<div class="state component-state-${component.oc.state.toLowerCase()}">${
1515
component.oc.state

0 commit comments

Comments
 (0)