/
PackageRequest.js
97 lines (83 loc) 路 2.63 KB
/
PackageRequest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// @flow strict-local
import type {ContentKey} from '@parcel/graph';
import type {Async} from '@parcel/types';
import type {SharedReference} from '@parcel/workers';
import type {StaticRunOpts} from '../RequestTracker';
import type {Bundle} from '../types';
import type BundleGraph from '../BundleGraph';
import type {BundleInfo} from '../PackagerRunner';
import type {ConfigAndCachePath} from './ParcelConfigRequest';
import nullthrows from 'nullthrows';
import {runConfigRequest} from './ConfigRequest';
import {getDevDepRequests, runDevDepRequest} from './DevDepRequest';
import createParcelConfigRequest from './ParcelConfigRequest';
type PackageRequestInput = {|
bundleGraph: BundleGraph,
bundle: Bundle,
bundleGraphReference: SharedReference,
optionsRef: SharedReference,
|};
type RunInput = {|
input: PackageRequestInput,
...StaticRunOpts,
|};
export type PackageRequest = {|
id: ContentKey,
+type: 'package_request',
run: RunInput => Async<BundleInfo>,
input: PackageRequestInput,
|};
export function createPackageRequest(
input: PackageRequestInput,
): PackageRequest {
return {
type: 'package_request',
id: input.bundleGraph.getHash(input.bundle),
run,
input,
};
}
async function run({input, api, farm}: RunInput) {
let {bundleGraphReference, optionsRef, bundle} = input;
let runPackage = farm.createHandle('runPackage');
let start = Date.now();
let {devDeps, invalidDevDeps} = await getDevDepRequests(api);
let {cachePath} = nullthrows(
await api.runRequest<null, ConfigAndCachePath>(createParcelConfigRequest()),
);
let {devDepRequests, configRequests, bundleInfo, invalidations} =
await runPackage({
bundle,
bundleGraphReference,
optionsRef,
configCachePath: cachePath,
previousDevDeps: devDeps,
invalidDevDeps,
previousInvalidations: api.getInvalidations(),
});
for (let devDepRequest of devDepRequests) {
await runDevDepRequest(api, devDepRequest);
}
for (let configRequest of configRequests) {
await runConfigRequest(api, configRequest);
}
for (let invalidation of invalidations) {
switch (invalidation.type) {
case 'file':
api.invalidateOnFileUpdate(invalidation.filePath);
api.invalidateOnFileDelete(invalidation.filePath);
break;
case 'env':
api.invalidateOnEnvChange(invalidation.key);
break;
case 'option':
api.invalidateOnOptionChange(invalidation.key);
break;
default:
throw new Error(`Unknown invalidation type: ${invalidation.type}`);
}
}
bundleInfo.time = Date.now() - start;
api.storeResult(bundleInfo);
return bundleInfo;
}