|
1 | 1 | import {Uri} from "vscode"; |
2 | 2 | import {BundleFileSet, BundleWatcher} from ".."; |
3 | | -import {BundleTarget} from "../types"; |
| 3 | +import {BundleSchema, BundleTarget} from "../types"; |
4 | 4 | import {BaseModelWithStateCache} from "../../configuration/models/BaseModelWithStateCache"; |
5 | 5 | import {UrlUtils} from "../../utils"; |
6 | 6 | import {Mutex} from "../../locking"; |
| 7 | +import * as lodash from "lodash"; |
7 | 8 |
|
8 | 9 | export type BundlePreValidateState = { |
9 | 10 | host?: URL; |
@@ -32,9 +33,16 @@ export class BundlePreValidateModel extends BaseModelWithStateCache<BundlePreVal |
32 | 33 | } |
33 | 34 |
|
34 | 35 | get targets() { |
35 | | - return this.bundleFileSet.bundleDataCache.value.then( |
36 | | - (data) => data?.targets |
37 | | - ); |
| 36 | + return (async () => { |
| 37 | + const bundle = await this.bundleFileSet.bundleDataCache.value; |
| 38 | + const targets = Object.assign({}, bundle.targets ?? {}); |
| 39 | + |
| 40 | + Object.keys(targets ?? {}).map((key) => { |
| 41 | + targets[key] = this.getRawTargetData(bundle, key); |
| 42 | + }); |
| 43 | + |
| 44 | + return targets; |
| 45 | + })(); |
38 | 46 | } |
39 | 47 |
|
40 | 48 | get defaultTarget() { |
@@ -67,16 +75,30 @@ export class BundlePreValidateModel extends BaseModelWithStateCache<BundlePreVal |
67 | 75 | : undefined; |
68 | 76 | } |
69 | 77 |
|
| 78 | + private getRawTargetData(bundle: BundleSchema, target: string) { |
| 79 | + const targetObject = Object.assign({}, bundle?.targets?.[target]); |
| 80 | + const globalWorkspace = Object.assign({}, bundle?.workspace); |
| 81 | + if (targetObject !== undefined) { |
| 82 | + targetObject.workspace = lodash.merge( |
| 83 | + globalWorkspace ?? {}, |
| 84 | + targetObject.workspace |
| 85 | + ); |
| 86 | + } |
| 87 | + return targetObject; |
| 88 | + } |
| 89 | + |
70 | 90 | @Mutex.synchronise("mutex") |
71 | 91 | protected async readState() { |
72 | 92 | if (this.target === undefined) { |
73 | 93 | return {}; |
74 | 94 | } |
75 | 95 |
|
76 | | - const targetObject = (await this.bundleFileSet.bundleDataCache.value) |
77 | | - .targets?.[this.target]; |
78 | | - |
79 | | - return this.readStateFromTarget(targetObject) ?? {}; |
| 96 | + const bundle = await this.bundleFileSet.bundleDataCache.value; |
| 97 | + return ( |
| 98 | + this.readStateFromTarget( |
| 99 | + this.getRawTargetData(bundle, this.target) |
| 100 | + ) ?? {} |
| 101 | + ); |
80 | 102 | } |
81 | 103 |
|
82 | 104 | public async getFileToWrite(key: string) { |
|
0 commit comments