mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 08:33:11 +00:00
fix: build
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {first, last, tail, filter} from 'lodash';
|
||||
import {
|
||||
ArrayTypeNode,
|
||||
ClassDeclaration,
|
||||
@@ -44,22 +43,22 @@ import {LightweightComment} from './types/lightweight-comment';
|
||||
|
||||
/** @internal */
|
||||
export function extractComment(node: ts.Node): LightweightComment | undefined {
|
||||
const jsDocument = last(
|
||||
const jsDocuments =
|
||||
// @ts-expect-error jsDoc exists in reality
|
||||
node.jsDoc as
|
||||
| Array<{
|
||||
comment?: string;
|
||||
tags?: Array<{comment?: string; tagName?: {escapedText?: string}}>;
|
||||
}>
|
||||
| undefined,
|
||||
);
|
||||
| undefined;
|
||||
const jsDocument = jsDocuments?.[jsDocuments.length - 1]
|
||||
const comment = jsDocument?.comment?.split('\n\n');
|
||||
|
||||
return jsDocument === undefined
|
||||
? undefined
|
||||
: cleanupEmpty({
|
||||
shortSummary: first(comment),
|
||||
description: tail(comment)?.join('\n\n'),
|
||||
shortSummary: comment?.[0],
|
||||
description: comment?.[comment.length - 1],
|
||||
tags: jsDocument?.tags?.map(tag =>
|
||||
cleanupEmpty({
|
||||
name: tag.tagName?.escapedText ?? 'UNRESOLVED_NAME',
|
||||
@@ -81,7 +80,7 @@ export function filterNodeTo<T extends ts.Node, S extends T>(
|
||||
node: NodeArray<T>,
|
||||
check: (node: T) => node is S,
|
||||
): S[] {
|
||||
return filter(node, check);
|
||||
return node.filter(check);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {flatMap, keyBy, isEmpty} from 'lodash';
|
||||
import {TypeFlags} from 'typescript';
|
||||
import {LightweightAliasDefinition} from './types/lightweight-alias-definition';
|
||||
import {LightweightClassDefinition} from './types/lightweight-class-definition';
|
||||
@@ -21,6 +20,7 @@ import {LightweightDefinition} from './types/lightweight-definition';
|
||||
import {LightweightDefinitionKind} from './types/lightweight-definition-kind';
|
||||
import {LightweightProject} from './types/lightweight-project';
|
||||
import {LightweightType} from './types/lightweight-type';
|
||||
import {keyBy} from "@openstapps/collection-utils/lib/key-by";
|
||||
|
||||
/**
|
||||
* Creates a printable name of a type
|
||||
@@ -35,7 +35,7 @@ export function expandTypeValue(type: LightweightType): string | undefined {
|
||||
if (isUnionOrIntersectionType(type)) {
|
||||
return type.specificationTypes?.map(expandTypeValue).join(isUnionType(type) ? ' | ' : ' & ');
|
||||
}
|
||||
if (isEmpty(type.genericsTypes)) {
|
||||
if (type.genericsTypes?.length === 0) {
|
||||
return `${type.value}<${type.genericsTypes?.map(expandTypeValue).join(', ')}>`;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ export function expandTypeValue(type: LightweightType): string | undefined {
|
||||
}
|
||||
|
||||
export function definitionsOf(project: LightweightProject): Record<string, LightweightDefinition> {
|
||||
return keyBy(flatMap(project, Object.values), 'name');
|
||||
return keyBy(Object.values(project).flatMap(Object.values), it => it.name);
|
||||
}
|
||||
|
||||
export function isPrimitiveType(type: {flags: TypeFlags}): boolean {
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {flatMap, groupBy, keyBy, mapValues} from 'lodash';
|
||||
import * as ts from 'typescript';
|
||||
import {
|
||||
ClassDeclaration,
|
||||
@@ -62,6 +61,9 @@ import {LightweightProject} from './types/lightweight-project';
|
||||
import {LightweightType} from './types/lightweight-type';
|
||||
import path from 'path';
|
||||
import {LightweightProperty} from './types/lightweight-property';
|
||||
import {mapValues} from "@openstapps/collection-utils/lib/map-values";
|
||||
import {groupBy} from "@openstapps/collection-utils/lib/group-by";
|
||||
import {keyBy} from "@openstapps/collection-utils/lib/key-by";
|
||||
|
||||
/**
|
||||
* Convert a TypeScript project to a lightweight Type-AST representation of the project
|
||||
@@ -142,8 +144,8 @@ class LightweightDefinitionBuilder {
|
||||
|
||||
private convertClassLike(classLike: ClassDeclaration | InterfaceDeclaration): LightweightClassDefinition {
|
||||
const heritages = mapValues(
|
||||
groupBy(classLike.heritageClauses, it => it.token),
|
||||
heritages => flatMap(heritages, it => it.types),
|
||||
groupBy([...(classLike.heritageClauses!)], it => it.token.toString()),
|
||||
heritages => heritages.flatMap(it => it.types),
|
||||
);
|
||||
|
||||
return cleanupEmpty({
|
||||
@@ -252,7 +254,7 @@ class LightweightDefinitionBuilder {
|
||||
*/
|
||||
convert(): LightweightProject {
|
||||
return mapValues(
|
||||
keyBy(this.sourceFiles, it => it.fileName),
|
||||
keyBy([...this.sourceFiles], it => it.fileName),
|
||||
file =>
|
||||
keyBy(
|
||||
[
|
||||
@@ -268,6 +270,6 @@ class LightweightDefinitionBuilder {
|
||||
* Same as conversion, but generates a simple list of all definitions.
|
||||
*/
|
||||
convertToList(): LightweightDefinition[] {
|
||||
return flatMap(this.convert(), it => it.values);
|
||||
return Object.values(this.convert()).flatMap(it => it.values);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {assign, cloneDeep, flatMap, fromPairs, trimEnd} from 'lodash';
|
||||
import {mapNotNil} from '../../util/collections';
|
||||
import {definitionsOf, isLightweightClass} from '../ast-util';
|
||||
import {lightweightProjectFromPath} from '../easy-ast';
|
||||
@@ -23,8 +22,8 @@ import {LightweightDefinition} from './lightweight-definition';
|
||||
* Build an index for a lightweight project
|
||||
*/
|
||||
function buildIndex(project: LightweightProject): Record<string, string> {
|
||||
return fromPairs(
|
||||
flatMap(project, (definitions, file) => Object.keys(definitions).map(definition => [definition, file])),
|
||||
return Object.fromEntries(
|
||||
Object.values(project).flatMap((definitions, file) => Object.keys(definitions).map(definition => [definition, file.toString()]))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -59,7 +58,7 @@ export class LightweightProjectWithIndex {
|
||||
* Apply inherited classes; default deeply
|
||||
*/
|
||||
applyInheritance(classLike: LightweightClassDefinition, deep?: boolean): LightweightDefinition {
|
||||
return assign(
|
||||
return Object.assign(
|
||||
mapNotNil(
|
||||
[...(classLike.implementedDefinitions ?? []), ...(classLike.extendedDefinitions ?? [])],
|
||||
extension => {
|
||||
@@ -67,10 +66,10 @@ export class LightweightProjectWithIndex {
|
||||
|
||||
return (deep ?? true) && isLightweightClass(object)
|
||||
? this.applyInheritance(object)
|
||||
: cloneDeep(object);
|
||||
: JSON.parse(JSON.stringify(object));
|
||||
},
|
||||
),
|
||||
cloneDeep(classLike),
|
||||
JSON.parse(JSON.stringify(classLike)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -85,7 +84,7 @@ export class LightweightProjectWithIndex {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const module = await import(findCompiledModule ? `${trimEnd(fsPath, 'd.ts')}.js` : fsPath);
|
||||
const module = await import(findCompiledModule ? `${fsPath.replace(/\.d\.ts$/, '')}.js` : fsPath);
|
||||
|
||||
return new module[name]() as T;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import {JavaScriptModule} from './types/pack';
|
||||
import path from 'path';
|
||||
|
||||
const PACK_IDENTIFIER = '/* PACKED BY @openstapps/pack */';
|
||||
const posixCwd = cwd().replaceAll(path.win32.sep, path.posix.sep)
|
||||
|
||||
/**
|
||||
* Pack cli.js
|
||||
@@ -93,11 +94,11 @@ async function packCliJs(): Promise<void> {
|
||||
* Get a list containing the contents of all type definition files
|
||||
*/
|
||||
async function getAllTypeDefinitions(): Promise<string[]> {
|
||||
const fileNames = await globPromisified(path.join(cwd(), '*(lib|src)', '**', '*.d.ts'), {
|
||||
const fileNames = await globPromisified(path.posix.join(posixCwd, '*(lib|src)', '**', '*.d.ts'), {
|
||||
ignore: [
|
||||
path.join(cwd(), 'lib', 'doc', '**', '*.d.ts'),
|
||||
path.join(cwd(), 'lib', 'test', '**', '*.d.ts'),
|
||||
path.join(cwd(), 'lib', 'cli.d.ts'),
|
||||
path.posix.join(posixCwd, 'lib', 'doc', '**', '*.d.ts'),
|
||||
path.posix.join(posixCwd, 'lib', 'test', '**', '*.d.ts'),
|
||||
path.posix.join(posixCwd, 'lib', 'cli.d.ts'),
|
||||
],
|
||||
});
|
||||
|
||||
@@ -142,7 +143,7 @@ async function packTypeDefinitions(): Promise<void> {
|
||||
}
|
||||
|
||||
// match import lines
|
||||
const match = line.match(/^import {([^}].*)} from '([^'].*)';$/);
|
||||
const match = line.match(/^import\s+{\s*([^}].*)\s*}\s+from\s+['"]([^'"].*)['"];$/);
|
||||
|
||||
if (match !== null) {
|
||||
const module = match[2];
|
||||
@@ -204,11 +205,11 @@ ${allDefinitions}`,
|
||||
* Get all JavaScript modules
|
||||
*/
|
||||
async function getAllJavaScriptModules(): Promise<JavaScriptModule[]> {
|
||||
const fileNames = await globPromisified(path.join(cwd(), 'lib', '**', '*.js'), {
|
||||
const fileNames = await globPromisified(path.posix.join(posixCwd, 'lib', '**', '*.js'), {
|
||||
ignore: [
|
||||
path.join(cwd(), 'lib', 'doc', '**', '*.js'),
|
||||
path.join(cwd(), 'lib', 'test', '*.js'),
|
||||
path.join(cwd(), 'lib', 'cli.js'),
|
||||
path.posix.join(posixCwd, 'lib', 'doc', '**', '*.js'),
|
||||
path.posix.join(posixCwd, 'lib', 'test', '*.js'),
|
||||
path.posix.join(posixCwd, 'lib', 'cli.js'),
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
@@ -12,13 +12,12 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {omitBy, isNil, reject, isEmpty, isArray, isObject} from 'lodash';
|
||||
|
||||
/**
|
||||
* Filters only defined elements
|
||||
*/
|
||||
export function rejectNil<T>(array: Array<T | undefined | null>): T[] {
|
||||
return reject(array, isNil) as T[];
|
||||
// eslint-disable-next-line unicorn/no-null
|
||||
return array.filter(it => it == null) as T[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,5 +32,13 @@ export function mapNotNil<T, S>(array: readonly T[], transform: (element: T) =>
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
export function cleanupEmpty<T extends object>(object: T): T {
|
||||
return omitBy(object, it => isNil(it) || ((isObject(it) || isArray(it)) && isEmpty(it))) as T;
|
||||
const out = {} as T;
|
||||
for (const key in object) {
|
||||
const value = object[key]
|
||||
// eslint-disable-next-line unicorn/no-null
|
||||
if (value != null && (typeof value !== 'object' || Object.values(value).length > 0)) {
|
||||
out[key] = value
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {readdirSync, statSync} from 'fs';
|
||||
import {flatMap} from 'lodash';
|
||||
import path from 'path';
|
||||
|
||||
/**
|
||||
@@ -24,9 +23,9 @@ export function expandPathToFilesSync(sourcePath: string, accept: (fileName: str
|
||||
const directory = statSync(fullPath);
|
||||
|
||||
return directory.isDirectory()
|
||||
? flatMap(readdirSync(fullPath), fragment =>
|
||||
? readdirSync(fullPath).flatMap(fragment =>
|
||||
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
|
||||
)
|
||||
)
|
||||
: [fullPath].filter(accept);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user