From eb06134889c148c93552d22b2ffbea96815c1e99 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Tue, 17 Oct 2023 15:41:47 +0300 Subject: [PATCH 1/4] TaskUtil ts declarations --- package.json | 3 ++- types/TaskUtil.d.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ types/index.d.ts | 4 ++++ types/ui5_project.d.ts | 5 +++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 types/TaskUtil.d.ts create mode 100644 types/index.d.ts create mode 100644 types/ui5_project.d.ts diff --git a/package.json b/package.json index bc959649e..1ef594727 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "./graph/ProjectGraph": "./lib/graph/ProjectGraph.js", "./graph/projectGraphBuilder": "./lib/graph/projectGraphBuilder.js", "./graph": "./lib/graph/graph.js", - "./package.json": "./package.json" + "./package.json": "./package.json", + "./types": "./types/index.d.ts" }, "engines": { "node": "^16.18.0 || >=18.12.0", diff --git a/types/TaskUtil.d.ts b/types/TaskUtil.d.ts new file mode 100644 index 000000000..754fef217 --- /dev/null +++ b/types/TaskUtil.d.ts @@ -0,0 +1,42 @@ +declare module "@ui5/project/build/helpers/TaskUtil" { + // This one should be (eventually) provided globally or as a part of @ui5/project/Specification + type availableSpecVersions = "2.0" | "2.2" | "3.0" | "3.2"; + + // Mock some of the types, so it would be easier to follow + type ui5_fs_resourceFactory = object + type ProjectInterface = object + + type StandardBuildTags = { + OmitFromBuildResult: string + IsBundle: string + IsDebugVariant: string + HasDebugVariant: string + } + + type TaskUtil = specVersion extends "2.2" + ? TaskUtil_v2_2 + : specVersion extends "3.0" + ? TaskUtil_v3_0 + : specVersion extends "3.2" + ? TaskUtil_v3_2 + : never; + + 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 + } + + 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 + } + + class TaskUtil_v3_2 extends TaskUtil_v3_0 { + someFutureMethod(); + } +} \ No newline at end of file diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 000000000..21766bcac --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,4 @@ +// Reference multiple definitions, so they could act like a bundle + +/// +/// \ No newline at end of file diff --git a/types/ui5_project.d.ts b/types/ui5_project.d.ts new file mode 100644 index 000000000..4ce219cc7 --- /dev/null +++ b/types/ui5_project.d.ts @@ -0,0 +1,5 @@ +declare module "@ui5/project/graph" { + interface ProjectGraph { } + + function graphFromPackageDependencies(settings: Record): ProjectGraph; +} From 3f9acb40600661cb6450b6c7d2244478262854e1 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Tue, 17 Oct 2023 15:50:46 +0300 Subject: [PATCH 2/4] Fix definitions --- types/TaskUtil.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/TaskUtil.d.ts b/types/TaskUtil.d.ts index 754fef217..abfbfa4d3 100644 --- a/types/TaskUtil.d.ts +++ b/types/TaskUtil.d.ts @@ -4,6 +4,7 @@ declare module "@ui5/project/build/helpers/TaskUtil" { // Mock some of the types, so it would be easier to follow type ui5_fs_resourceFactory = object + type ui5_fs_Resource = object type ProjectInterface = object type StandardBuildTags = { From a9d320f2a438f0ddabd1854ea1a85959676f2346 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Fri, 20 Oct 2023 15:16:20 +0300 Subject: [PATCH 3/4] Remove ambient modules and use package.json export's conditional syntax instead --- package.json | 9 ++++-- types/TaskUtil.d.ts | 72 ++++++++++++++++++++---------------------- types/index.d.ts | 5 ++- types/ui5_project.d.ts | 5 --- 4 files changed, 44 insertions(+), 47 deletions(-) delete mode 100644 types/ui5_project.d.ts diff --git a/package.json b/package.json index 1ef594727..e7c57558b 100644 --- a/package.json +++ b/package.json @@ -29,9 +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", + "./graph": { + "default": "./lib/graph/graph.js", + "types": "./types/index.d.ts" + }, "./package.json": "./package.json", - "./types": "./types/index.d.ts" + "./build/helpers/*": { + "types": "./types/*.d.ts" + } }, "engines": { "node": "^16.18.0 || >=18.12.0", diff --git a/types/TaskUtil.d.ts b/types/TaskUtil.d.ts index abfbfa4d3..3f7017bc5 100644 --- a/types/TaskUtil.d.ts +++ b/types/TaskUtil.d.ts @@ -1,43 +1,41 @@ -declare module "@ui5/project/build/helpers/TaskUtil" { - // This one should be (eventually) provided globally or as a part of @ui5/project/Specification - type availableSpecVersions = "2.0" | "2.2" | "3.0" | "3.2"; +// 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 - type ui5_fs_resourceFactory = object - type ui5_fs_Resource = object - type ProjectInterface = object +// 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 - type StandardBuildTags = { - OmitFromBuildResult: string - IsBundle: string - IsDebugVariant: string - HasDebugVariant: string - } +declare type StandardBuildTags = { + OmitFromBuildResult: string + IsBundle: string + IsDebugVariant: string + HasDebugVariant: string +} - type TaskUtil = specVersion extends "2.2" - ? TaskUtil_v2_2 - : specVersion extends "3.0" - ? TaskUtil_v3_0 - : specVersion extends "3.2" - ? TaskUtil_v3_2 - : never; +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 +} - 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 +} - 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(); +} - class TaskUtil_v3_2 extends TaskUtil_v3_0 { - someFutureMethod(); - } -} \ No newline at end of file +export declare type TaskUtil = specVersion extends "2.2" + ? TaskUtil_v2_2 + : specVersion extends "3.0" + ? TaskUtil_v3_0 + : specVersion extends "3.2" + ? TaskUtil_v3_2 + : never; \ No newline at end of file diff --git a/types/index.d.ts b/types/index.d.ts index 21766bcac..92160abac 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,4 +1,3 @@ -// Reference multiple definitions, so they could act like a bundle +export declare interface ProjectGraph { } -/// -/// \ No newline at end of file +export declare function graphFromPackageDependencies(settings: Record): ProjectGraph; diff --git a/types/ui5_project.d.ts b/types/ui5_project.d.ts deleted file mode 100644 index 4ce219cc7..000000000 --- a/types/ui5_project.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare module "@ui5/project/graph" { - interface ProjectGraph { } - - function graphFromPackageDependencies(settings: Record): ProjectGraph; -} From c72f27ab11be47a21f182d33aaff7d21cd8a1aac Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Fri, 20 Oct 2023 15:18:29 +0300 Subject: [PATCH 4/4] Add .tsconfig file --- tsconfig.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tsconfig.json diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..bfce1eb8a --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "esnext", + "noEmit": true, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "allowSyntheticDefaultImports": true, + "module": "NodeNext", + "moduleResolution": "NodeNext", + }, +}