@atlaspack/core 2.12.1-canary.3354
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/LICENSE +201 -0
- package/index.d.ts +22 -0
- package/lib/AssetGraph.js +518 -0
- package/lib/Atlaspack.js +587 -0
- package/lib/AtlaspackConfig.js +298 -0
- package/lib/AtlaspackConfig.schema.js +125 -0
- package/lib/BundleGraph.js +1445 -0
- package/lib/CommittedAsset.js +133 -0
- package/lib/Dependency.js +88 -0
- package/lib/Environment.js +128 -0
- package/lib/InternalConfig.js +48 -0
- package/lib/PackagerRunner.js +519 -0
- package/lib/ReporterRunner.js +151 -0
- package/lib/RequestTracker.js +1089 -0
- package/lib/SymbolPropagation.js +625 -0
- package/lib/TargetDescriptor.schema.js +115 -0
- package/lib/Transformation.js +536 -0
- package/lib/UncommittedAsset.js +342 -0
- package/lib/Validation.js +215 -0
- package/lib/applyRuntimes.js +279 -0
- package/lib/assetUtils.js +189 -0
- package/lib/atlaspack-v3/AtlaspackV3.js +74 -0
- package/lib/atlaspack-v3/fs.js +30 -0
- package/lib/atlaspack-v3/index.js +19 -0
- package/lib/atlaspack-v3/jsCallable.js +15 -0
- package/lib/atlaspack-v3/plugins/Resolver.js +12 -0
- package/lib/atlaspack-v3/plugins/index.js +16 -0
- package/lib/atlaspack-v3/worker/index.js +3 -0
- package/lib/atlaspack-v3/worker/worker.js +30 -0
- package/lib/buildCache.js +18 -0
- package/lib/constants.js +21 -0
- package/lib/dumpGraphToGraphViz.js +206 -0
- package/lib/index.js +106 -0
- package/lib/loadAtlaspackPlugin.js +148 -0
- package/lib/loadDotEnv.js +54 -0
- package/lib/projectPath.js +86 -0
- package/lib/public/Asset.js +259 -0
- package/lib/public/Bundle.js +231 -0
- package/lib/public/BundleGraph.js +193 -0
- package/lib/public/BundleGroup.js +44 -0
- package/lib/public/Config.js +202 -0
- package/lib/public/Dependency.js +131 -0
- package/lib/public/Environment.js +244 -0
- package/lib/public/MutableBundleGraph.js +184 -0
- package/lib/public/PluginOptions.js +71 -0
- package/lib/public/Symbols.js +247 -0
- package/lib/public/Target.js +64 -0
- package/lib/registerCoreWithSerializer.js +45 -0
- package/lib/requests/AssetGraphRequest.js +427 -0
- package/lib/requests/AssetGraphRequestRust.js +187 -0
- package/lib/requests/AssetRequest.js +137 -0
- package/lib/requests/AtlaspackBuildRequest.js +78 -0
- package/lib/requests/AtlaspackConfigRequest.js +473 -0
- package/lib/requests/BundleGraphRequest.js +419 -0
- package/lib/requests/ConfigRequest.js +198 -0
- package/lib/requests/DevDepRequest.js +166 -0
- package/lib/requests/EntryRequest.js +295 -0
- package/lib/requests/PackageRequest.js +88 -0
- package/lib/requests/PathRequest.js +349 -0
- package/lib/requests/TargetRequest.js +1177 -0
- package/lib/requests/ValidationRequest.js +66 -0
- package/lib/requests/WriteBundleRequest.js +252 -0
- package/lib/requests/WriteBundlesRequest.js +153 -0
- package/lib/resolveOptions.js +234 -0
- package/lib/serializer.js +216 -0
- package/lib/serializerCore.browser.js +29 -0
- package/lib/serializerCore.js +16 -0
- package/lib/summarizeRequest.js +55 -0
- package/lib/types.js +35 -0
- package/lib/utils.js +160 -0
- package/lib/worker.js +170 -0
- package/package.json +59 -0
- package/src/AssetGraph.js +646 -0
- package/src/Atlaspack.js +632 -0
- package/src/AtlaspackConfig.js +490 -0
- package/src/AtlaspackConfig.schema.js +141 -0
- package/src/BundleGraph.js +2193 -0
- package/src/CommittedAsset.js +143 -0
- package/src/Dependency.js +142 -0
- package/src/Environment.js +151 -0
- package/src/InternalConfig.js +72 -0
- package/src/PackagerRunner.js +790 -0
- package/src/ReporterRunner.js +158 -0
- package/src/RequestTracker.js +1697 -0
- package/src/SymbolPropagation.js +794 -0
- package/src/TargetDescriptor.schema.js +136 -0
- package/src/Transformation.js +752 -0
- package/src/UncommittedAsset.js +426 -0
- package/src/Validation.js +223 -0
- package/src/applyRuntimes.js +341 -0
- package/src/assetUtils.js +254 -0
- package/src/atlaspack-v3/AtlaspackV3.js +73 -0
- package/src/atlaspack-v3/fs.js +36 -0
- package/src/atlaspack-v3/index.js +5 -0
- package/src/atlaspack-v3/jsCallable.js +13 -0
- package/src/atlaspack-v3/plugins/Resolver.js +9 -0
- package/src/atlaspack-v3/plugins/index.js +3 -0
- package/src/atlaspack-v3/worker/index.js +8 -0
- package/src/atlaspack-v3/worker/worker.js +14 -0
- package/src/buildCache.js +15 -0
- package/src/constants.js +22 -0
- package/src/dumpGraphToGraphViz.js +244 -0
- package/src/index.js +22 -0
- package/src/loadAtlaspackPlugin.js +239 -0
- package/src/loadDotEnv.js +56 -0
- package/src/projectPath.js +87 -0
- package/src/public/Asset.js +359 -0
- package/src/public/Bundle.js +337 -0
- package/src/public/BundleGraph.js +335 -0
- package/src/public/BundleGroup.js +55 -0
- package/src/public/Config.js +261 -0
- package/src/public/Dependency.js +176 -0
- package/src/public/Environment.js +316 -0
- package/src/public/MutableBundleGraph.js +320 -0
- package/src/public/PluginOptions.js +99 -0
- package/src/public/Symbols.js +315 -0
- package/src/public/Target.js +71 -0
- package/src/registerCoreWithSerializer.js +34 -0
- package/src/requests/AssetGraphRequest.js +577 -0
- package/src/requests/AssetGraphRequestRust.js +222 -0
- package/src/requests/AssetRequest.js +179 -0
- package/src/requests/AtlaspackBuildRequest.js +109 -0
- package/src/requests/AtlaspackConfigRequest.js +709 -0
- package/src/requests/BundleGraphRequest.js +547 -0
- package/src/requests/ConfigRequest.js +287 -0
- package/src/requests/DevDepRequest.js +246 -0
- package/src/requests/EntryRequest.js +385 -0
- package/src/requests/PackageRequest.js +105 -0
- package/src/requests/PathRequest.js +454 -0
- package/src/requests/TargetRequest.js +1632 -0
- package/src/requests/ValidationRequest.js +79 -0
- package/src/requests/WriteBundleRequest.js +362 -0
- package/src/requests/WriteBundlesRequest.js +209 -0
- package/src/resolveOptions.js +278 -0
- package/src/serializer.js +255 -0
- package/src/serializerCore.browser.js +8 -0
- package/src/serializerCore.js +5 -0
- package/src/summarizeRequest.js +47 -0
- package/src/types.js +581 -0
- package/src/utils.js +211 -0
- package/src/worker.js +189 -0
- package/test/AssetGraph.test.js +679 -0
- package/test/Atlaspack.test.js +142 -0
- package/test/AtlaspackConfig.test.js +405 -0
- package/test/AtlaspackConfigRequest.test.js +993 -0
- package/test/BundleGraph.test.js +121 -0
- package/test/EntryRequest.test.js +215 -0
- package/test/Environment.test.js +99 -0
- package/test/InternalAsset.test.js +76 -0
- package/test/PackagerRunner.test.js +27 -0
- package/test/PublicAsset.test.js +40 -0
- package/test/PublicBundle.test.js +68 -0
- package/test/PublicDependency.test.js +22 -0
- package/test/PublicEnvironment.test.js +27 -0
- package/test/PublicMutableBundleGraph.test.js +192 -0
- package/test/RequestTracker.test.js +448 -0
- package/test/SymbolPropagation.test.js +716 -0
- package/test/TargetRequest.test.js +1715 -0
- package/test/fixtures/application-targets/package.json +3 -0
- package/test/fixtures/atlaspack/index.js +1 -0
- package/test/fixtures/atlaspack/other.js +3 -0
- package/test/fixtures/atlaspack/package.json +1 -0
- package/test/fixtures/atlaspack/yarn.lock +0 -0
- package/test/fixtures/bundle.js +10 -0
- package/test/fixtures/common-targets/package.json +24 -0
- package/test/fixtures/common-targets-ignore/package.json +13 -0
- package/test/fixtures/config/.atlaspackrc +6 -0
- package/test/fixtures/config/subfolder/.atlaspackrc +6 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc +3 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc-json5 +3 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc-multiple +3 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc-node-modules +3 -0
- package/test/fixtures/config-malformed/.atlaspackrc +3 -0
- package/test/fixtures/config-node-pipeline/.atlaspackrc +6 -0
- package/test/fixtures/config-plugin-not-found/.atlaspackrc +6 -0
- package/test/fixtures/context/package.json +8 -0
- package/test/fixtures/custom-format-infer-ext/package.json +6 -0
- package/test/fixtures/custom-format-infer-type/package.json +7 -0
- package/test/fixtures/custom-format-mismatch/package.json +8 -0
- package/test/fixtures/custom-targets/package.json +20 -0
- package/test/fixtures/custom-targets-distdir/package.json +11 -0
- package/test/fixtures/duplicate-targets/package.json +4 -0
- package/test/fixtures/glob-like/[entry].js +0 -0
- package/test/fixtures/invalid-distpath/package.json +11 -0
- package/test/fixtures/invalid-engines/package.json +12 -0
- package/test/fixtures/invalid-source-missing/package.json +5 -0
- package/test/fixtures/invalid-source-not-file/package.json +5 -0
- package/test/fixtures/invalid-source-not-file/src/index.js +1 -0
- package/test/fixtures/invalid-target-source-missing/package.json +9 -0
- package/test/fixtures/invalid-target-source-not-file/package.json +9 -0
- package/test/fixtures/invalid-target-source-not-file/src/index.js +1 -0
- package/test/fixtures/invalid-targets/package.json +19 -0
- package/test/fixtures/library-custom-scopehoist/package.json +9 -0
- package/test/fixtures/library-scopehoist/package.json +8 -0
- package/test/fixtures/local-plugin-config-pkg/.atlaspackrc +3 -0
- package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/index.json +8 -0
- package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/local-plugin.js +7 -0
- package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/package.json +7 -0
- package/test/fixtures/main-format-mismatch/package.json +8 -0
- package/test/fixtures/main-global/package.json +8 -0
- package/test/fixtures/main-mjs/package.json +8 -0
- package/test/fixtures/module-a.js +1 -0
- package/test/fixtures/module-b.js +1 -0
- package/test/fixtures/plugins/local-plugin.js +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/index.js +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/package.json +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/index.js +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/package.json +4 -0
- package/test/fixtures/targets-default-distdir-none/package.json +5 -0
- package/test/fixtures/targets-default-distdir-one/package.json +8 -0
- package/test/fixtures/targets-default-distdir-two/package.json +18 -0
- package/test/requests/ConfigRequest.test.js +254 -0
- package/test/serializer.test.js +302 -0
- package/test/test-utils.js +80 -0
- package/test/utils.test.js +43 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import type {
|
|
3
|
+
Async,
|
|
4
|
+
Config as IConfig,
|
|
5
|
+
PluginOptions as IPluginOptions,
|
|
6
|
+
PluginLogger as IPluginLogger,
|
|
7
|
+
PluginTracer as IPluginTracer,
|
|
8
|
+
NamedBundle as INamedBundle,
|
|
9
|
+
BundleGraph as IBundleGraph,
|
|
10
|
+
} from '@atlaspack/types';
|
|
11
|
+
import {readConfig, hashObject} from '@atlaspack/utils';
|
|
12
|
+
import type {
|
|
13
|
+
Config,
|
|
14
|
+
AtlaspackOptions,
|
|
15
|
+
InternalFileCreateInvalidation,
|
|
16
|
+
} from '../types';
|
|
17
|
+
import type {LoadedPlugin} from '../AtlaspackConfig';
|
|
18
|
+
import type {RequestResult, RunAPI} from '../RequestTracker';
|
|
19
|
+
import type {ProjectPath} from '../projectPath';
|
|
20
|
+
|
|
21
|
+
import {serializeRaw} from '../serializer.js';
|
|
22
|
+
import {PluginLogger} from '@atlaspack/logger';
|
|
23
|
+
import PluginOptions from '../public/PluginOptions';
|
|
24
|
+
import ThrowableDiagnostic, {errorToDiagnostic} from '@atlaspack/diagnostic';
|
|
25
|
+
import PublicConfig from '../public/Config';
|
|
26
|
+
import {optionsProxy} from '../utils';
|
|
27
|
+
import {getInvalidationHash} from '../assetUtils';
|
|
28
|
+
import {hashString, Hash} from '@atlaspack/rust';
|
|
29
|
+
import {PluginTracer} from '@atlaspack/profiler';
|
|
30
|
+
import {requestTypes} from '../RequestTracker';
|
|
31
|
+
import {fromProjectPath, fromProjectPathRelative} from '../projectPath';
|
|
32
|
+
import {createBuildCache} from '../buildCache';
|
|
33
|
+
|
|
34
|
+
export type PluginWithLoadConfig = {
|
|
35
|
+
loadConfig?: ({|
|
|
36
|
+
config: IConfig,
|
|
37
|
+
options: IPluginOptions,
|
|
38
|
+
logger: IPluginLogger,
|
|
39
|
+
tracer: IPluginTracer,
|
|
40
|
+
|}) => Async<mixed>,
|
|
41
|
+
...
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type PluginWithBundleConfig = {
|
|
45
|
+
loadConfig?: ({|
|
|
46
|
+
config: IConfig,
|
|
47
|
+
options: IPluginOptions,
|
|
48
|
+
logger: IPluginLogger,
|
|
49
|
+
tracer: IPluginTracer,
|
|
50
|
+
|}) => Async<mixed>,
|
|
51
|
+
loadBundleConfig?: ({|
|
|
52
|
+
bundle: INamedBundle,
|
|
53
|
+
bundleGraph: IBundleGraph<INamedBundle>,
|
|
54
|
+
config: IConfig,
|
|
55
|
+
options: IPluginOptions,
|
|
56
|
+
logger: IPluginLogger,
|
|
57
|
+
tracer: IPluginTracer,
|
|
58
|
+
|}) => Async<mixed>,
|
|
59
|
+
...
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type ConfigRequest = {
|
|
63
|
+
id: string,
|
|
64
|
+
invalidateOnFileChange: Set<ProjectPath>,
|
|
65
|
+
invalidateOnConfigKeyChange: Array<{|
|
|
66
|
+
filePath: ProjectPath,
|
|
67
|
+
configKey: string,
|
|
68
|
+
|}>,
|
|
69
|
+
invalidateOnFileCreate: Array<InternalFileCreateInvalidation>,
|
|
70
|
+
invalidateOnEnvChange: Set<string>,
|
|
71
|
+
invalidateOnOptionChange: Set<string>,
|
|
72
|
+
invalidateOnStartup: boolean,
|
|
73
|
+
invalidateOnBuild: boolean,
|
|
74
|
+
...
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type ConfigRequestResult = void;
|
|
78
|
+
|
|
79
|
+
export async function loadPluginConfig<T: PluginWithLoadConfig>(
|
|
80
|
+
loadedPlugin: LoadedPlugin<T>,
|
|
81
|
+
config: Config,
|
|
82
|
+
options: AtlaspackOptions,
|
|
83
|
+
): Promise<void> {
|
|
84
|
+
let loadConfig = loadedPlugin.plugin.loadConfig;
|
|
85
|
+
if (!loadConfig) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
config.result = await loadConfig({
|
|
91
|
+
config: new PublicConfig(config, options),
|
|
92
|
+
options: new PluginOptions(
|
|
93
|
+
optionsProxy(options, option => {
|
|
94
|
+
config.invalidateOnOptionChange.add(option);
|
|
95
|
+
}),
|
|
96
|
+
),
|
|
97
|
+
logger: new PluginLogger({origin: loadedPlugin.name}),
|
|
98
|
+
tracer: new PluginTracer({
|
|
99
|
+
origin: loadedPlugin.name,
|
|
100
|
+
category: 'loadConfig',
|
|
101
|
+
}),
|
|
102
|
+
});
|
|
103
|
+
} catch (e) {
|
|
104
|
+
throw new ThrowableDiagnostic({
|
|
105
|
+
diagnostic: errorToDiagnostic(e, {
|
|
106
|
+
origin: loadedPlugin.name,
|
|
107
|
+
}),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const configKeyCache = createBuildCache();
|
|
113
|
+
|
|
114
|
+
export async function getConfigKeyContentHash(
|
|
115
|
+
filePath: ProjectPath,
|
|
116
|
+
configKey: string,
|
|
117
|
+
options: AtlaspackOptions,
|
|
118
|
+
): Async<string> {
|
|
119
|
+
let cacheKey = `${fromProjectPathRelative(filePath)}:${configKey}`;
|
|
120
|
+
let cachedValue = configKeyCache.get(cacheKey);
|
|
121
|
+
|
|
122
|
+
if (cachedValue) {
|
|
123
|
+
return cachedValue;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let conf = await readConfig(
|
|
127
|
+
options.inputFS,
|
|
128
|
+
fromProjectPath(options.projectRoot, filePath),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
if (conf == null || conf.config[configKey] == null) {
|
|
132
|
+
// This can occur when a config key has been removed entirely during `respondToFSEvents`
|
|
133
|
+
return '';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let contentHash =
|
|
137
|
+
typeof conf.config[configKey] === 'object'
|
|
138
|
+
? hashObject(conf.config[configKey])
|
|
139
|
+
: hashString(JSON.stringify(conf.config[configKey]));
|
|
140
|
+
|
|
141
|
+
configKeyCache.set(cacheKey, contentHash);
|
|
142
|
+
|
|
143
|
+
return contentHash;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export async function runConfigRequest<TResult: RequestResult>(
|
|
147
|
+
api: RunAPI<TResult>,
|
|
148
|
+
configRequest: ConfigRequest,
|
|
149
|
+
) {
|
|
150
|
+
let {
|
|
151
|
+
invalidateOnFileChange,
|
|
152
|
+
invalidateOnConfigKeyChange,
|
|
153
|
+
invalidateOnFileCreate,
|
|
154
|
+
invalidateOnEnvChange,
|
|
155
|
+
invalidateOnOptionChange,
|
|
156
|
+
invalidateOnStartup,
|
|
157
|
+
invalidateOnBuild,
|
|
158
|
+
} = configRequest;
|
|
159
|
+
|
|
160
|
+
// If there are no invalidations, then no need to create a node.
|
|
161
|
+
if (
|
|
162
|
+
invalidateOnFileChange.size === 0 &&
|
|
163
|
+
invalidateOnConfigKeyChange.length === 0 &&
|
|
164
|
+
invalidateOnFileCreate.length === 0 &&
|
|
165
|
+
invalidateOnOptionChange.size === 0 &&
|
|
166
|
+
invalidateOnEnvChange.size === 0 &&
|
|
167
|
+
!invalidateOnStartup &&
|
|
168
|
+
!invalidateOnBuild
|
|
169
|
+
) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
await api.runRequest<null, void>({
|
|
174
|
+
id: 'config_request:' + configRequest.id,
|
|
175
|
+
type: requestTypes.config_request,
|
|
176
|
+
run: async ({api, options}) => {
|
|
177
|
+
for (let filePath of invalidateOnFileChange) {
|
|
178
|
+
api.invalidateOnFileUpdate(filePath);
|
|
179
|
+
api.invalidateOnFileDelete(filePath);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
for (let {filePath, configKey} of invalidateOnConfigKeyChange) {
|
|
183
|
+
let contentHash = await getConfigKeyContentHash(
|
|
184
|
+
filePath,
|
|
185
|
+
configKey,
|
|
186
|
+
options,
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
api.invalidateOnConfigKeyChange(filePath, configKey, contentHash);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
for (let invalidation of invalidateOnFileCreate) {
|
|
193
|
+
api.invalidateOnFileCreate(invalidation);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
for (let env of invalidateOnEnvChange) {
|
|
197
|
+
api.invalidateOnEnvChange(env);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
for (let option of invalidateOnOptionChange) {
|
|
201
|
+
api.invalidateOnOptionChange(option);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (invalidateOnStartup) {
|
|
205
|
+
api.invalidateOnStartup();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (invalidateOnBuild) {
|
|
209
|
+
api.invalidateOnBuild();
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
input: null,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export async function getConfigHash(
|
|
217
|
+
config: Config,
|
|
218
|
+
pluginName: string,
|
|
219
|
+
options: AtlaspackOptions,
|
|
220
|
+
): Promise<string> {
|
|
221
|
+
if (config.result == null) {
|
|
222
|
+
return '';
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
let hash = new Hash();
|
|
226
|
+
hash.writeString(config.id);
|
|
227
|
+
|
|
228
|
+
// If there is no result hash set by the transformer, default to hashing the included
|
|
229
|
+
// files if any, otherwise try to hash the config result itself.
|
|
230
|
+
if (config.cacheKey == null) {
|
|
231
|
+
if (config.invalidateOnFileChange.size > 0) {
|
|
232
|
+
hash.writeString(
|
|
233
|
+
await getInvalidationHash(
|
|
234
|
+
[...config.invalidateOnFileChange].map(filePath => ({
|
|
235
|
+
type: 'file',
|
|
236
|
+
filePath,
|
|
237
|
+
})),
|
|
238
|
+
options,
|
|
239
|
+
),
|
|
240
|
+
);
|
|
241
|
+
} else if (config.result != null) {
|
|
242
|
+
try {
|
|
243
|
+
hash.writeBuffer(serializeRaw(config.result));
|
|
244
|
+
} catch (err) {
|
|
245
|
+
throw new ThrowableDiagnostic({
|
|
246
|
+
diagnostic: {
|
|
247
|
+
message:
|
|
248
|
+
'Config result is not hashable because it contains non-serializable objects. Please use config.setCacheKey to set the hash manually.',
|
|
249
|
+
origin: pluginName,
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
} else {
|
|
255
|
+
hash.writeString(config.cacheKey ?? '');
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return hash.finish();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export function getConfigRequests(
|
|
262
|
+
configs: Array<Config>,
|
|
263
|
+
): Array<ConfigRequest> {
|
|
264
|
+
return configs
|
|
265
|
+
.filter(config => {
|
|
266
|
+
// No need to send to the graph if there are no invalidations.
|
|
267
|
+
return (
|
|
268
|
+
config.invalidateOnFileChange.size > 0 ||
|
|
269
|
+
config.invalidateOnConfigKeyChange.length > 0 ||
|
|
270
|
+
config.invalidateOnFileCreate.length > 0 ||
|
|
271
|
+
config.invalidateOnEnvChange.size > 0 ||
|
|
272
|
+
config.invalidateOnOptionChange.size > 0 ||
|
|
273
|
+
config.invalidateOnStartup ||
|
|
274
|
+
config.invalidateOnBuild
|
|
275
|
+
);
|
|
276
|
+
})
|
|
277
|
+
.map(config => ({
|
|
278
|
+
id: config.id,
|
|
279
|
+
invalidateOnFileChange: config.invalidateOnFileChange,
|
|
280
|
+
invalidateOnConfigKeyChange: config.invalidateOnConfigKeyChange,
|
|
281
|
+
invalidateOnFileCreate: config.invalidateOnFileCreate,
|
|
282
|
+
invalidateOnEnvChange: config.invalidateOnEnvChange,
|
|
283
|
+
invalidateOnOptionChange: config.invalidateOnOptionChange,
|
|
284
|
+
invalidateOnStartup: config.invalidateOnStartup,
|
|
285
|
+
invalidateOnBuild: config.invalidateOnBuild,
|
|
286
|
+
}));
|
|
287
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import type {
|
|
3
|
+
DependencySpecifier,
|
|
4
|
+
SemverRange,
|
|
5
|
+
Invalidations,
|
|
6
|
+
} from '@atlaspack/types';
|
|
7
|
+
import type AtlaspackConfig from '../AtlaspackConfig';
|
|
8
|
+
import type {
|
|
9
|
+
DevDepRequest,
|
|
10
|
+
AtlaspackOptions,
|
|
11
|
+
InternalDevDepOptions,
|
|
12
|
+
} from '../types';
|
|
13
|
+
import type {RequestResult, RunAPI} from '../RequestTracker';
|
|
14
|
+
import type {ProjectPath} from '../projectPath';
|
|
15
|
+
|
|
16
|
+
import nullthrows from 'nullthrows';
|
|
17
|
+
import {getInvalidationHash} from '../assetUtils';
|
|
18
|
+
import {createBuildCache} from '../buildCache';
|
|
19
|
+
import {invalidateOnFileCreateToInternal} from '../utils';
|
|
20
|
+
import {
|
|
21
|
+
fromProjectPath,
|
|
22
|
+
fromProjectPathRelative,
|
|
23
|
+
toProjectPath,
|
|
24
|
+
} from '../projectPath';
|
|
25
|
+
import {requestTypes} from '../RequestTracker';
|
|
26
|
+
|
|
27
|
+
// A cache of dev dep requests keyed by invalidations.
|
|
28
|
+
// If the package manager returns the same invalidation object, then
|
|
29
|
+
// we can reuse the dev dep request rather than recomputing the project
|
|
30
|
+
// paths and hashes.
|
|
31
|
+
const devDepRequestCache: WeakMap<Invalidations, DevDepRequest> = new WeakMap();
|
|
32
|
+
|
|
33
|
+
export async function createDevDependency(
|
|
34
|
+
opts: InternalDevDepOptions,
|
|
35
|
+
requestDevDeps: Map<string, string>,
|
|
36
|
+
options: AtlaspackOptions,
|
|
37
|
+
): Promise<DevDepRequest> {
|
|
38
|
+
let {specifier, resolveFrom, additionalInvalidations} = opts;
|
|
39
|
+
let key = `${specifier}:${fromProjectPathRelative(resolveFrom)}`;
|
|
40
|
+
|
|
41
|
+
// If the request sent us a hash, we know the dev dep and all of its dependencies didn't change.
|
|
42
|
+
// Reuse the same hash in the response. No need to send back invalidations as the request won't
|
|
43
|
+
// be re-run anyway.
|
|
44
|
+
let hash = requestDevDeps.get(key);
|
|
45
|
+
if (hash != null) {
|
|
46
|
+
return {
|
|
47
|
+
specifier,
|
|
48
|
+
resolveFrom,
|
|
49
|
+
hash,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let resolveFromAbsolute = fromProjectPath(options.projectRoot, resolveFrom);
|
|
54
|
+
|
|
55
|
+
// Ensure that the package manager has an entry for this resolution.
|
|
56
|
+
try {
|
|
57
|
+
await options.packageManager.resolve(specifier, resolveFromAbsolute);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
// ignore
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let invalidations = options.packageManager.getInvalidations(
|
|
63
|
+
specifier,
|
|
64
|
+
resolveFromAbsolute,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
let cached = devDepRequestCache.get(invalidations);
|
|
68
|
+
if (cached != null) {
|
|
69
|
+
return cached;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let invalidateOnFileChangeProject = [
|
|
73
|
+
...invalidations.invalidateOnFileChange,
|
|
74
|
+
].map(f => toProjectPath(options.projectRoot, f));
|
|
75
|
+
|
|
76
|
+
// It is possible for a transformer to have multiple different hashes due to
|
|
77
|
+
// different dependencies (e.g. conditional requires) so we must always
|
|
78
|
+
// recompute the hash and compare rather than only sending a transformer
|
|
79
|
+
// dev dependency once.
|
|
80
|
+
hash = await getInvalidationHash(
|
|
81
|
+
invalidateOnFileChangeProject.map(f => ({
|
|
82
|
+
type: 'file',
|
|
83
|
+
filePath: f,
|
|
84
|
+
})),
|
|
85
|
+
options,
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
let devDepRequest: DevDepRequest = {
|
|
89
|
+
specifier,
|
|
90
|
+
resolveFrom,
|
|
91
|
+
hash,
|
|
92
|
+
invalidateOnFileCreate: invalidations.invalidateOnFileCreate.map(i =>
|
|
93
|
+
invalidateOnFileCreateToInternal(options.projectRoot, i),
|
|
94
|
+
),
|
|
95
|
+
invalidateOnFileChange: new Set(invalidateOnFileChangeProject),
|
|
96
|
+
invalidateOnStartup: invalidations.invalidateOnStartup,
|
|
97
|
+
additionalInvalidations,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
devDepRequestCache.set(invalidations, devDepRequest);
|
|
101
|
+
return devDepRequest;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export type DevDepSpecifier = {|
|
|
105
|
+
specifier: DependencySpecifier,
|
|
106
|
+
resolveFrom: ProjectPath,
|
|
107
|
+
|};
|
|
108
|
+
|
|
109
|
+
type DevDepRequests = {|
|
|
110
|
+
devDeps: Map<string, string>,
|
|
111
|
+
invalidDevDeps: Array<DevDepSpecifier>,
|
|
112
|
+
|};
|
|
113
|
+
|
|
114
|
+
export async function getDevDepRequests<TResult: RequestResult>(
|
|
115
|
+
api: RunAPI<TResult>,
|
|
116
|
+
): Promise<DevDepRequests> {
|
|
117
|
+
let previousDevDepRequests: Map<string, DevDepRequestResult> = new Map(
|
|
118
|
+
await Promise.all(
|
|
119
|
+
api
|
|
120
|
+
.getSubRequests()
|
|
121
|
+
.filter(req => req.requestType === requestTypes.dev_dep_request)
|
|
122
|
+
.map(async req => [
|
|
123
|
+
req.id,
|
|
124
|
+
nullthrows(await api.getRequestResult<DevDepRequestResult>(req.id)),
|
|
125
|
+
]),
|
|
126
|
+
),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
devDeps: new Map(
|
|
131
|
+
[...previousDevDepRequests.entries()]
|
|
132
|
+
.filter(([id]) => api.canSkipSubrequest(id))
|
|
133
|
+
.map(([, req]: [string, DevDepRequestResult]) => [
|
|
134
|
+
`${req.specifier}:${fromProjectPathRelative(req.resolveFrom)}`,
|
|
135
|
+
req.hash,
|
|
136
|
+
]),
|
|
137
|
+
),
|
|
138
|
+
invalidDevDeps: await Promise.all(
|
|
139
|
+
[...previousDevDepRequests.entries()]
|
|
140
|
+
.filter(([id]) => !api.canSkipSubrequest(id))
|
|
141
|
+
.flatMap(([, req]: [string, DevDepRequestResult]) => {
|
|
142
|
+
return [
|
|
143
|
+
{
|
|
144
|
+
specifier: req.specifier,
|
|
145
|
+
resolveFrom: req.resolveFrom,
|
|
146
|
+
},
|
|
147
|
+
...(req.additionalInvalidations ?? []).map(i => ({
|
|
148
|
+
specifier: i.specifier,
|
|
149
|
+
resolveFrom: i.resolveFrom,
|
|
150
|
+
})),
|
|
151
|
+
];
|
|
152
|
+
}),
|
|
153
|
+
),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Tracks dev deps that have been invalidated during this build
|
|
158
|
+
// so we don't invalidate the require cache more than once.
|
|
159
|
+
const invalidatedDevDeps = createBuildCache();
|
|
160
|
+
|
|
161
|
+
export function invalidateDevDeps(
|
|
162
|
+
invalidDevDeps: Array<DevDepSpecifier>,
|
|
163
|
+
options: AtlaspackOptions,
|
|
164
|
+
config: AtlaspackConfig,
|
|
165
|
+
) {
|
|
166
|
+
for (let {specifier, resolveFrom} of invalidDevDeps) {
|
|
167
|
+
let key = `${specifier}:${fromProjectPathRelative(resolveFrom)}`;
|
|
168
|
+
if (!invalidatedDevDeps.has(key)) {
|
|
169
|
+
config.invalidatePlugin(specifier);
|
|
170
|
+
options.packageManager.invalidate(
|
|
171
|
+
specifier,
|
|
172
|
+
fromProjectPath(options.projectRoot, resolveFrom),
|
|
173
|
+
);
|
|
174
|
+
invalidatedDevDeps.set(key, true);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export type DevDepRequestResult = {|
|
|
180
|
+
specifier: DependencySpecifier,
|
|
181
|
+
resolveFrom: ProjectPath,
|
|
182
|
+
hash: string,
|
|
183
|
+
additionalInvalidations: void | Array<{|
|
|
184
|
+
range?: ?SemverRange,
|
|
185
|
+
resolveFrom: ProjectPath,
|
|
186
|
+
specifier: DependencySpecifier,
|
|
187
|
+
|}>,
|
|
188
|
+
|};
|
|
189
|
+
|
|
190
|
+
export async function runDevDepRequest<TResult: RequestResult>(
|
|
191
|
+
api: RunAPI<TResult>,
|
|
192
|
+
devDepRequest: DevDepRequest,
|
|
193
|
+
) {
|
|
194
|
+
await api.runRequest<null, DevDepRequestResult | void>({
|
|
195
|
+
id: 'dev_dep_request:' + devDepRequest.specifier + ':' + devDepRequest.hash,
|
|
196
|
+
type: requestTypes.dev_dep_request,
|
|
197
|
+
run: ({api}) => {
|
|
198
|
+
for (let filePath of nullthrows(
|
|
199
|
+
devDepRequest.invalidateOnFileChange,
|
|
200
|
+
'DevDepRequest missing invalidateOnFileChange',
|
|
201
|
+
)) {
|
|
202
|
+
api.invalidateOnFileUpdate(filePath);
|
|
203
|
+
api.invalidateOnFileDelete(filePath);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
for (let invalidation of nullthrows(
|
|
207
|
+
devDepRequest.invalidateOnFileCreate,
|
|
208
|
+
'DevDepRequest missing invalidateOnFileCreate',
|
|
209
|
+
)) {
|
|
210
|
+
api.invalidateOnFileCreate(invalidation);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (devDepRequest.invalidateOnStartup) {
|
|
214
|
+
api.invalidateOnStartup();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
api.storeResult({
|
|
218
|
+
specifier: devDepRequest.specifier,
|
|
219
|
+
resolveFrom: devDepRequest.resolveFrom,
|
|
220
|
+
hash: devDepRequest.hash,
|
|
221
|
+
additionalInvalidations: devDepRequest.additionalInvalidations,
|
|
222
|
+
});
|
|
223
|
+
},
|
|
224
|
+
input: null,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// A cache of plugin dependency hashes that we've already sent to the main thread.
|
|
229
|
+
// Automatically cleared before each build.
|
|
230
|
+
const pluginCache = createBuildCache();
|
|
231
|
+
|
|
232
|
+
export function getWorkerDevDepRequests(
|
|
233
|
+
devDepRequests: Array<DevDepRequest>,
|
|
234
|
+
): Array<DevDepRequest> {
|
|
235
|
+
return devDepRequests.map(devDepRequest => {
|
|
236
|
+
// If we've already sent a matching transformer + hash to the main thread during this build,
|
|
237
|
+
// there's no need to repeat ourselves.
|
|
238
|
+
let {specifier, resolveFrom, hash} = devDepRequest;
|
|
239
|
+
if (hash === pluginCache.get(specifier)) {
|
|
240
|
+
return {specifier, resolveFrom, hash};
|
|
241
|
+
} else {
|
|
242
|
+
pluginCache.set(specifier, hash);
|
|
243
|
+
return devDepRequest;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|