Skip to content

Commit 00c23e3

Browse files
committed
fix(desk): moment types in editor
1 parent dead9f2 commit 00c23e3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/core/use-cases/execute-script/execute-script.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type ExecuteScriptDTO from './execute-script.dto'
44
import type AppConfig from '../../config/app'
55

66
import moment from 'moment'
7+
78
import EvaluationFacade from '../../facades/script'
89
export default class ExecuteScript {
910
constructor(private readonly app: AppConfig) {}
@@ -13,6 +14,10 @@ export default class ExecuteScript {
1314

1415
const drive = this.app.facades.drive.fromWorkspace(workspace)
1516

17+
const createRepository = (name: string) => {
18+
return this.app.facades.item.createRepositoryFromWorkspace(workspace, name)
19+
}
20+
1621
const sandbox: any = {
1722
...scope,
1823
scope,
@@ -21,6 +26,7 @@ export default class ExecuteScript {
2126
Facades: this.app.facades,
2227
Entry: DirectoryEntry,
2328
Moment: moment,
29+
createRepository,
2430
}
2531

2632
const evaluation = new EvaluationFacade(drive, this.app.services.evaluation, sandbox)

packages/desktop/modules/monaco/libs/script.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import { lib as core } from './core'
22

3+
import momentTypes from 'moment/moment.d.ts?raw'
4+
35
export function mount() {
46
const uri = 'ts:runtime/script.d.ts'
57

68
const libs = core.mount()
79

10+
libs.push({
11+
uri: 'ts:moment.d.ts',
12+
source: `
13+
declare module 'moment' { ${momentTypes} }
14+
`,
15+
})
16+
817
const source = `
918
declare const Workspace: import("core/entities/workspace").default
1019
@@ -18,7 +27,7 @@ export function mount() {
1827
1928
declare const scope: Record<string, any>
2029
21-
declare const Moment: any
30+
declare const Moment: typeof import("moment")
2231
2332
declare function setResult(data: any): void
2433
`

0 commit comments

Comments
 (0)