Skip to content

Commit

Permalink
Fix #10555 Define and reuse definitions both as global and export
Browse files Browse the repository at this point in the history
  • Loading branch information
ComLock committed Aug 16, 2024
1 parent 6fbd3f0 commit ee1d3b8
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 310 deletions.
10 changes: 9 additions & 1 deletion modules/lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ check.dependsOn lint

/* Configure & Build */

task typescript( type: NpmTask, dependsOn: npmInstall ) {
task typescript( type: NpmTask ) {
dependsOn 'npmInstall', 'prepareToPublish'

description = 'Create JS and DTS files from TS'
args = ['run', 'build']

Expand Down Expand Up @@ -102,6 +104,11 @@ task prepareCoreToPublish( type: Copy ) {
from "$coreDir/README.md"
from "$coreDir/index.d.ts"

def dependencyLines = [
' "dependencies": {',
' "@enonic-types/global": "' + version + '"',
' }'
]
from( 'package.template.json' ) {
filter { line ->
line
Expand All @@ -110,6 +117,7 @@ task prepareCoreToPublish( type: Copy ) {
.replaceAll( '%FULL_NAME%', 'core' )
.replaceAll( '%FILE_NAME%', 'index' )
.replaceAll( '%DESCRIPTION%', 'Shared type definition for core libraries.' )
.replaceAll( / "dependencies": \{\}/, dependencyLines.join( '\n' ) )
}
rename '.+', 'package.json'
}
Expand Down
24 changes: 0 additions & 24 deletions modules/lib/core/globalModifying.d.ts

This file was deleted.

122 changes: 0 additions & 122 deletions modules/lib/core/globals.d.ts

This file was deleted.

72 changes: 46 additions & 26 deletions modules/lib/core/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// This also makes sure XpLayoutMap, etc are available.
import type {
ComponentDescriptor,
NestedRecord,
} from './globalModifying';

export type {
ComponentDescriptor,
NestedRecord,
} from './globalModifying';
export type {
App,
DoubleUnderscore,
Log,
NewBean,
Resolve,
ScriptValue,
XpRequire,
} from './globals';
export type {
ByteSource,
Resource,
ResourceKey,
} from './resource';
export type { ResourceKey } from '@enonic-types/global';

export type ComponentDescriptor = `${string}:${string}`;

export interface NestedRecord {
[name: PropertyKey]: NestedRecord | unknown
}

declare global {
interface XpBeans {}
interface XpLayoutMap {
[layoutDescriptor: ComponentDescriptor]: NestedRecord;
}
interface XpLibraries {}
interface XpPageMap {
[pageDescriptor: ComponentDescriptor]: NestedRecord;
}
interface XpPartMap {
[partDescriptor: ComponentDescriptor]: NestedRecord;
}
interface XpXData {
[key: string]: Record<string, Record<string, unknown>>;
}
}

export type UserKey = `user:${string}:${string}`;
export type GroupKey = `group:${string}:${string}`;
Expand Down Expand Up @@ -220,6 +220,26 @@ export interface Content<
fragment?: Type extends 'portal:fragment' ? _Component : never;
}

// Compliant with npm module ts-brand
type Brand<
Base,
Branding
> = Base & {
'__type__': Branding
};

export type ByteSource = Brand<object, 'ByteSource'>;

export interface Resource {
getSize(): number;

getTimestamp(): number;

getStream(): ByteSource;

exists(): boolean;
}

//
// DSL QUERIES
//
Expand Down Expand Up @@ -328,9 +348,9 @@ export type QueryDsl = {
exists: ExistsDslExpression;
};

type SortDirection = 'ASC' | 'DESC';
export type SortDirection = 'ASC' | 'DESC';

type DistanceUnit =
export type DistanceUnit =
| 'm'
| 'meters'
| 'in'
Expand Down
28 changes: 0 additions & 28 deletions modules/lib/core/resource.d.ts

This file was deleted.

Loading

0 comments on commit ee1d3b8

Please sign in to comment.