1 |
|
2 | import invariant from 'assert';
|
3 | import type {Bundle, ParcelOptions} from './types';
|
4 | import BundleGraph from './BundleGraph';
|
5 | import type {WorkerApi} from '@parcel/workers';
|
6 |
|
7 | import Transformation, {type TransformationOpts} from './Transformation';
|
8 | import {reportWorker} from './ReporterRunner';
|
9 | import PackagerRunner from './PackagerRunner';
|
10 | import Validation, {type ValidationOpts} from './Validation';
|
11 | import ParcelConfig from './ParcelConfig';
|
12 | import {registerCoreWithSerializer} from './utils';
|
13 |
|
14 | import '@parcel/cache';
|
15 | import '@parcel/package-manager';
|
16 | import '@parcel/fs';
|
17 |
|
18 | registerCoreWithSerializer();
|
19 |
|
20 |
|
21 |
|
22 | type TransformationOptsWithoutWorkerApi = $Diff<
|
23 | TransformationOpts,
|
24 | {|workerApi: mixed|},
|
25 | >;
|
26 | type ValidationOptsWithoutWorkerApi = $Diff<
|
27 | ValidationOpts,
|
28 | {|workerApi: mixed|},
|
29 | >;
|
30 |
|
31 | export function runTransform(
|
32 | workerApi: WorkerApi,
|
33 | opts: TransformationOptsWithoutWorkerApi,
|
34 | ) {
|
35 | return new Transformation({
|
36 | workerApi,
|
37 | report: reportWorker.bind(null, workerApi),
|
38 | ...opts,
|
39 | }).run();
|
40 | }
|
41 |
|
42 | export function runValidate(
|
43 | workerApi: WorkerApi,
|
44 | opts: ValidationOptsWithoutWorkerApi,
|
45 | ) {
|
46 | return new Validation({
|
47 | workerApi,
|
48 | report: reportWorker.bind(null, workerApi),
|
49 | ...opts,
|
50 | }).run();
|
51 | }
|
52 |
|
53 | export function runPackage(
|
54 | workerApi: WorkerApi,
|
55 | {
|
56 | bundle,
|
57 | bundleGraphReference,
|
58 | config,
|
59 | cacheKey,
|
60 | options,
|
61 | }: {|
|
62 | bundle: Bundle,
|
63 | bundleGraphReference: number,
|
64 | config: ParcelConfig,
|
65 | cacheKey: string,
|
66 | options: ParcelOptions,
|
67 | |},
|
68 | ) {
|
69 | let bundleGraph = workerApi.getSharedReference(bundleGraphReference);
|
70 | invariant(bundleGraph instanceof BundleGraph);
|
71 | return new PackagerRunner({
|
72 | config,
|
73 | options,
|
74 | report: reportWorker.bind(null, workerApi),
|
75 | }).packageAndWriteBundle(bundle, bundleGraph, cacheKey);
|
76 | }
|