@atlaspack/core 2.32.1 → 2.33.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/dist/atlaspack-v3/AtlaspackV3.js +3 -0
- package/dist/atlaspack-v3/worker/worker.js +1 -0
- package/dist/requests/AtlaspackBuildRequest.js +12 -5
- package/dist/requests/BundleGraphRequest.js +15 -78
- package/dist/requests/BundleGraphRequestRust.js +320 -0
- package/dist/requests/BundleGraphRequestUtils.js +131 -0
- package/lib/atlaspack-v3/AtlaspackV3.js +3 -0
- package/lib/atlaspack-v3/worker/worker.js +2 -1
- package/lib/requests/AtlaspackBuildRequest.js +6 -1
- package/lib/requests/BundleGraphRequest.js +15 -87
- package/lib/requests/BundleGraphRequestRust.js +378 -0
- package/lib/requests/BundleGraphRequestUtils.js +151 -0
- package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +1 -0
- package/lib/types/atlaspack-v3/worker/worker.d.ts +1 -0
- package/lib/types/requests/BundleGraphRequestRust.d.ts +34 -0
- package/lib/types/requests/BundleGraphRequestUtils.d.ts +31 -0
- package/package.json +15 -15
- package/src/atlaspack-v3/AtlaspackV3.ts +5 -0
- package/src/atlaspack-v3/worker/worker.ts +1 -0
- package/src/requests/AtlaspackBuildRequest.ts +13 -5
- package/src/requests/BundleGraphRequest.ts +25 -100
- package/src/requests/BundleGraphRequestRust.ts +464 -0
- package/src/requests/BundleGraphRequestUtils.ts +167 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for BundleGraphRequest and BundleGraphRequestRust.
|
|
3
|
+
*
|
|
4
|
+
* This module contains common functionality used by both the JS and native
|
|
5
|
+
* bundling paths, such as bundle validation, naming, and configuration loading.
|
|
6
|
+
*/
|
|
7
|
+
import type {Async, Bundle as IBundle, Namer} from '@atlaspack/types';
|
|
8
|
+
import type {SharedReference} from '@atlaspack/workers';
|
|
9
|
+
import type {AtlaspackConfig, LoadedPlugin} from '../AtlaspackConfig';
|
|
10
|
+
import type {RunAPI} from '../RequestTracker';
|
|
11
|
+
import type {
|
|
12
|
+
Bundle as InternalBundle,
|
|
13
|
+
Config,
|
|
14
|
+
DevDepRequest,
|
|
15
|
+
AtlaspackOptions,
|
|
16
|
+
DevDepRequestRef,
|
|
17
|
+
} from '../types';
|
|
18
|
+
|
|
19
|
+
import assert from 'assert';
|
|
20
|
+
import nullthrows from 'nullthrows';
|
|
21
|
+
import {PluginLogger} from '@atlaspack/logger';
|
|
22
|
+
import ThrowableDiagnostic, {errorToDiagnostic} from '@atlaspack/diagnostic';
|
|
23
|
+
import {unique, setSymmetricDifference} from '@atlaspack/utils';
|
|
24
|
+
import InternalBundleGraph from '../BundleGraph';
|
|
25
|
+
import BundleGraph from '../public/BundleGraph';
|
|
26
|
+
import {Bundle, NamedBundle} from '../public/Bundle';
|
|
27
|
+
import PluginOptions from '../public/PluginOptions';
|
|
28
|
+
import {createConfig} from '../InternalConfig';
|
|
29
|
+
import {
|
|
30
|
+
createDevDependency,
|
|
31
|
+
runDevDepRequest as runDevDepRequestInternal,
|
|
32
|
+
} from './DevDepRequest';
|
|
33
|
+
import {
|
|
34
|
+
loadPluginConfig,
|
|
35
|
+
runConfigRequest,
|
|
36
|
+
PluginWithLoadConfig,
|
|
37
|
+
} from './ConfigRequest';
|
|
38
|
+
import {
|
|
39
|
+
joinProjectPath,
|
|
40
|
+
fromProjectPathRelative,
|
|
41
|
+
toProjectPathUnsafe,
|
|
42
|
+
} from '../projectPath';
|
|
43
|
+
import {tracer, PluginTracer} from '@atlaspack/profiler';
|
|
44
|
+
import type {BundleGraphResult} from './BundleGraphRequest';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Validates that all bundles have unique names.
|
|
48
|
+
* Throws an assertion error if duplicate bundle names are found.
|
|
49
|
+
*/
|
|
50
|
+
export function validateBundles(bundleGraph: InternalBundleGraph): void {
|
|
51
|
+
const bundles = bundleGraph.getBundles();
|
|
52
|
+
|
|
53
|
+
const bundleNames = bundles.map((b) =>
|
|
54
|
+
joinProjectPath(b.target.distDir, nullthrows(b.name)),
|
|
55
|
+
);
|
|
56
|
+
assert.deepEqual(
|
|
57
|
+
bundleNames,
|
|
58
|
+
unique(bundleNames),
|
|
59
|
+
'Bundles must have unique name. Conflicting names: ' +
|
|
60
|
+
[
|
|
61
|
+
...setSymmetricDifference(
|
|
62
|
+
new Set(bundleNames),
|
|
63
|
+
new Set(unique(bundleNames)),
|
|
64
|
+
),
|
|
65
|
+
].join(),
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Names a bundle by running through the configured namers until one returns a name.
|
|
71
|
+
*/
|
|
72
|
+
export async function nameBundle(
|
|
73
|
+
namers: Array<LoadedPlugin<Namer<unknown>>>,
|
|
74
|
+
internalBundle: InternalBundle,
|
|
75
|
+
internalBundleGraph: InternalBundleGraph,
|
|
76
|
+
options: AtlaspackOptions,
|
|
77
|
+
pluginOptions: PluginOptions,
|
|
78
|
+
configs: Map<string, Config>,
|
|
79
|
+
): Promise<void> {
|
|
80
|
+
const bundle = Bundle.get(internalBundle, internalBundleGraph, options);
|
|
81
|
+
const bundleGraph = new BundleGraph<IBundle>(
|
|
82
|
+
internalBundleGraph,
|
|
83
|
+
NamedBundle.get.bind(NamedBundle),
|
|
84
|
+
options,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
for (const namer of namers) {
|
|
88
|
+
let measurement;
|
|
89
|
+
try {
|
|
90
|
+
measurement = tracer.createMeasurement(namer.name, 'namer', bundle.id);
|
|
91
|
+
const name = await namer.plugin.name({
|
|
92
|
+
bundle,
|
|
93
|
+
bundleGraph,
|
|
94
|
+
config: configs.get(namer.name)?.result,
|
|
95
|
+
options: pluginOptions,
|
|
96
|
+
logger: new PluginLogger({origin: namer.name}),
|
|
97
|
+
tracer: new PluginTracer({origin: namer.name, category: 'namer'}),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (name != null) {
|
|
101
|
+
internalBundle.name = name;
|
|
102
|
+
const {hashReference} = internalBundle;
|
|
103
|
+
internalBundle.displayName = name.includes(hashReference)
|
|
104
|
+
? name.replace(hashReference, '[hash]')
|
|
105
|
+
: name;
|
|
106
|
+
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
} catch (e: any) {
|
|
110
|
+
throw new ThrowableDiagnostic({
|
|
111
|
+
diagnostic: errorToDiagnostic(e, {
|
|
112
|
+
origin: namer.name,
|
|
113
|
+
}),
|
|
114
|
+
});
|
|
115
|
+
} finally {
|
|
116
|
+
measurement && measurement.end();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
throw new Error('Unable to name bundle');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Loads configuration for a plugin and tracks its dev dependencies.
|
|
125
|
+
*/
|
|
126
|
+
export async function loadPluginConfigWithDevDeps<
|
|
127
|
+
T extends PluginWithLoadConfig,
|
|
128
|
+
>(
|
|
129
|
+
plugin: LoadedPlugin<T>,
|
|
130
|
+
options: AtlaspackOptions,
|
|
131
|
+
api: RunAPI<BundleGraphResult>,
|
|
132
|
+
previousDevDeps: Map<string, string>,
|
|
133
|
+
devDepRequests: Map<string, DevDepRequest | DevDepRequestRef>,
|
|
134
|
+
configs: Map<string, Config>,
|
|
135
|
+
): Promise<void> {
|
|
136
|
+
const config = createConfig({
|
|
137
|
+
plugin: plugin.name,
|
|
138
|
+
searchPath: toProjectPathUnsafe('index'),
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
await loadPluginConfig(plugin, config, options);
|
|
142
|
+
await runConfigRequest(api, config);
|
|
143
|
+
for (const devDep of config.devDeps) {
|
|
144
|
+
const devDepRequest = await createDevDependency(
|
|
145
|
+
devDep,
|
|
146
|
+
previousDevDeps,
|
|
147
|
+
options,
|
|
148
|
+
);
|
|
149
|
+
await runDevDepRequest(api, devDepRequest, devDepRequests);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
configs.set(plugin.name, config);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Runs a dev dependency request and tracks it in the devDepRequests map.
|
|
157
|
+
*/
|
|
158
|
+
export async function runDevDepRequest(
|
|
159
|
+
api: RunAPI<BundleGraphResult>,
|
|
160
|
+
devDepRequest: DevDepRequest | DevDepRequestRef,
|
|
161
|
+
devDepRequests: Map<string, DevDepRequest | DevDepRequestRef>,
|
|
162
|
+
): Promise<void> {
|
|
163
|
+
const {specifier, resolveFrom} = devDepRequest;
|
|
164
|
+
const key = `${specifier}:${fromProjectPathRelative(resolveFrom)}`;
|
|
165
|
+
devDepRequests.set(key, devDepRequest);
|
|
166
|
+
await runDevDepRequestInternal(api, devDepRequest);
|
|
167
|
+
}
|