Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] TS Declarations #668

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@
"./validation/ValidationError": "./lib/validation/ValidationError.js",
"./graph/ProjectGraph": "./lib/graph/ProjectGraph.js",
"./graph/projectGraphBuilder": "./lib/graph/projectGraphBuilder.js",
"./graph": "./lib/graph/graph.js",
"./package.json": "./package.json"
"./graph": {
"default": "./lib/graph/graph.js",
"types": "./types/index.d.ts"
},
"./package.json": "./package.json",
"./build/helpers/*": {
"types": "./types/*.d.ts"
}
},
"engines": {
"node": "^16.18.0 || >=18.12.0",
Expand Down
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "esnext",
"noEmit": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
},
}
41 changes: 41 additions & 0 deletions types/TaskUtil.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This one should be (eventually) provided globally or as a part of @ui5/project/Specification
declare type availableSpecVersions = "2.0" | "2.2" | "3.0" | "3.2";

// Mock some of the types, so it would be easier to follow
declare type ui5_fs_resourceFactory = object
declare type ui5_fs_Resource = object
declare type ProjectInterface = object

declare type StandardBuildTags = {
OmitFromBuildResult: string
IsBundle: string
IsDebugVariant: string
HasDebugVariant: string
}

declare class TaskUtil_v2_2 {
STANDARD_TAGS: StandardBuildTags
resourceFactory: ui5_fs_resourceFactory
getDependencies(projectName?: string): string[]
getProject(projectNameOrResource?: ProjectInterface | undefined)
isRootProject(): boolean
registerCleanupTask(callback: CallableFunction): never
}

declare class TaskUtil_v3_0 extends TaskUtil_v2_2 {
clearTag(resource: ui5_fs_Resource, tag: string): never
getTag(resource: ui5_fs_Resource, tag: string): string | boolean | number | undefined
setTag(resource: ui5_fs_Resource, tag: string, value: string | boolean | number): never
}

declare class TaskUtil_v3_2 extends TaskUtil_v3_0 {
someFutureMethod();
}

export declare type TaskUtil<specVersion extends availableSpecVersions> = specVersion extends "2.2"
? TaskUtil_v2_2
: specVersion extends "3.0"
? TaskUtil_v3_0
: specVersion extends "3.2"
? TaskUtil_v3_2
: never;
3 changes: 3 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare interface ProjectGraph { }

export declare function graphFromPackageDependencies(settings: Record<string, string | number | boolean>): ProjectGraph;
Loading