@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,55 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import type {
|
|
3
|
+
BundleGroup as IBundleGroup,
|
|
4
|
+
Target as ITarget,
|
|
5
|
+
} from '@atlaspack/types';
|
|
6
|
+
import type {
|
|
7
|
+
BundleGroup as InternalBundleGroup,
|
|
8
|
+
AtlaspackOptions,
|
|
9
|
+
} from '../types';
|
|
10
|
+
|
|
11
|
+
import nullthrows from 'nullthrows';
|
|
12
|
+
import Target from './Target';
|
|
13
|
+
|
|
14
|
+
const internalBundleGroupToBundleGroup: WeakMap<
|
|
15
|
+
InternalBundleGroup,
|
|
16
|
+
BundleGroup,
|
|
17
|
+
> = new WeakMap();
|
|
18
|
+
const _bundleGroupToInternalBundleGroup: WeakMap<
|
|
19
|
+
IBundleGroup,
|
|
20
|
+
InternalBundleGroup,
|
|
21
|
+
> = new WeakMap();
|
|
22
|
+
export function bundleGroupToInternalBundleGroup(
|
|
23
|
+
target: IBundleGroup,
|
|
24
|
+
): InternalBundleGroup {
|
|
25
|
+
return nullthrows(_bundleGroupToInternalBundleGroup.get(target));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default class BundleGroup implements IBundleGroup {
|
|
29
|
+
#bundleGroup /*: InternalBundleGroup */;
|
|
30
|
+
#options /*: AtlaspackOptions */;
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
bundleGroup: InternalBundleGroup,
|
|
34
|
+
options: AtlaspackOptions,
|
|
35
|
+
): BundleGroup {
|
|
36
|
+
let existing = internalBundleGroupToBundleGroup.get(bundleGroup);
|
|
37
|
+
if (existing != null) {
|
|
38
|
+
return existing;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.#bundleGroup = bundleGroup;
|
|
42
|
+
this.#options = options;
|
|
43
|
+
_bundleGroupToInternalBundleGroup.set(this, bundleGroup);
|
|
44
|
+
internalBundleGroupToBundleGroup.set(bundleGroup, this);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get target(): ITarget {
|
|
49
|
+
return new Target(this.#bundleGroup.target, this.#options);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get entryAssetId(): string {
|
|
53
|
+
return this.#bundleGroup.entryAssetId;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
import type {
|
|
3
|
+
Config as IConfig,
|
|
4
|
+
ConfigResult,
|
|
5
|
+
FileCreateInvalidation,
|
|
6
|
+
FilePath,
|
|
7
|
+
PackageJSON,
|
|
8
|
+
ConfigResultWithFilePath,
|
|
9
|
+
DevDepOptions,
|
|
10
|
+
} from '@atlaspack/types';
|
|
11
|
+
import type {Config, AtlaspackOptions} from '../types';
|
|
12
|
+
|
|
13
|
+
import invariant from 'assert';
|
|
14
|
+
import path from 'path';
|
|
15
|
+
import {
|
|
16
|
+
DefaultWeakMap,
|
|
17
|
+
resolveConfig,
|
|
18
|
+
readConfig,
|
|
19
|
+
relativePath,
|
|
20
|
+
} from '@atlaspack/utils';
|
|
21
|
+
import Environment from './Environment';
|
|
22
|
+
import {fromProjectPath, toProjectPath} from '../projectPath';
|
|
23
|
+
|
|
24
|
+
const internalConfigToConfig: DefaultWeakMap<
|
|
25
|
+
AtlaspackOptions,
|
|
26
|
+
WeakMap<Config, PublicConfig>,
|
|
27
|
+
> = new DefaultWeakMap(() => new WeakMap());
|
|
28
|
+
|
|
29
|
+
export default class PublicConfig implements IConfig {
|
|
30
|
+
#config /*: Config */;
|
|
31
|
+
#pkg /*: ?PackageJSON */;
|
|
32
|
+
#pkgFilePath /*: ?FilePath */;
|
|
33
|
+
#options /*: AtlaspackOptions */;
|
|
34
|
+
|
|
35
|
+
constructor(config: Config, options: AtlaspackOptions): PublicConfig {
|
|
36
|
+
let existing = internalConfigToConfig.get(options).get(config);
|
|
37
|
+
if (existing != null) {
|
|
38
|
+
return existing;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.#config = config;
|
|
42
|
+
this.#options = options;
|
|
43
|
+
internalConfigToConfig.get(options).set(config, this);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get env(): Environment {
|
|
48
|
+
return new Environment(this.#config.env, this.#options);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get searchPath(): FilePath {
|
|
52
|
+
return fromProjectPath(this.#options.projectRoot, this.#config.searchPath);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get result(): ConfigResult {
|
|
56
|
+
return this.#config.result;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get isSource(): boolean {
|
|
60
|
+
return this.#config.isSource;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// $FlowFixMe
|
|
64
|
+
setResult(result: any): void {
|
|
65
|
+
this.#config.result = result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
setCacheKey(cacheKey: string) {
|
|
69
|
+
this.#config.cacheKey = cacheKey;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
invalidateOnFileChange(filePath: FilePath) {
|
|
73
|
+
this.#config.invalidateOnFileChange.add(
|
|
74
|
+
toProjectPath(this.#options.projectRoot, filePath),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
invalidateOnConfigKeyChange(filePath: FilePath, configKey: string) {
|
|
79
|
+
this.#config.invalidateOnConfigKeyChange.push({
|
|
80
|
+
filePath: toProjectPath(this.#options.projectRoot, filePath),
|
|
81
|
+
configKey,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
addDevDependency(devDep: DevDepOptions) {
|
|
86
|
+
this.#config.devDeps.push({
|
|
87
|
+
...devDep,
|
|
88
|
+
resolveFrom: toProjectPath(this.#options.projectRoot, devDep.resolveFrom),
|
|
89
|
+
additionalInvalidations: devDep.additionalInvalidations?.map(i => ({
|
|
90
|
+
...i,
|
|
91
|
+
resolveFrom: toProjectPath(this.#options.projectRoot, i.resolveFrom),
|
|
92
|
+
})),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
invalidateOnFileCreate(invalidation: FileCreateInvalidation) {
|
|
97
|
+
if (invalidation.glob != null) {
|
|
98
|
+
// $FlowFixMe
|
|
99
|
+
this.#config.invalidateOnFileCreate.push(invalidation);
|
|
100
|
+
} else if (invalidation.filePath != null) {
|
|
101
|
+
this.#config.invalidateOnFileCreate.push({
|
|
102
|
+
filePath: toProjectPath(
|
|
103
|
+
this.#options.projectRoot,
|
|
104
|
+
invalidation.filePath,
|
|
105
|
+
),
|
|
106
|
+
});
|
|
107
|
+
} else {
|
|
108
|
+
invariant(invalidation.aboveFilePath != null);
|
|
109
|
+
this.#config.invalidateOnFileCreate.push({
|
|
110
|
+
// $FlowFixMe
|
|
111
|
+
fileName: invalidation.fileName,
|
|
112
|
+
aboveFilePath: toProjectPath(
|
|
113
|
+
this.#options.projectRoot,
|
|
114
|
+
invalidation.aboveFilePath,
|
|
115
|
+
),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
invalidateOnEnvChange(env: string) {
|
|
121
|
+
this.#config.invalidateOnEnvChange.add(env);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
invalidateOnStartup() {
|
|
125
|
+
this.#config.invalidateOnStartup = true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
invalidateOnBuild() {
|
|
129
|
+
this.#config.invalidateOnBuild = true;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async getConfigFrom<T>(
|
|
133
|
+
searchPath: FilePath,
|
|
134
|
+
fileNames: Array<string>,
|
|
135
|
+
options: ?{|
|
|
136
|
+
packageKey?: string,
|
|
137
|
+
parse?: boolean,
|
|
138
|
+
exclude?: boolean,
|
|
139
|
+
|},
|
|
140
|
+
): Promise<?ConfigResultWithFilePath<T>> {
|
|
141
|
+
let packageKey = options?.packageKey;
|
|
142
|
+
if (packageKey != null) {
|
|
143
|
+
let pkg = await this.getConfigFrom(searchPath, ['package.json'], {
|
|
144
|
+
exclude: true,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
if (pkg && pkg.contents[packageKey]) {
|
|
148
|
+
// Invalidate only when the package key changes
|
|
149
|
+
this.invalidateOnConfigKeyChange(pkg.filePath, packageKey);
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
contents: pkg.contents[packageKey],
|
|
153
|
+
filePath: pkg.filePath,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (fileNames.length === 0) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Invalidate when any of the file names are created above the search path.
|
|
163
|
+
for (let fileName of fileNames) {
|
|
164
|
+
this.invalidateOnFileCreate({
|
|
165
|
+
fileName,
|
|
166
|
+
aboveFilePath: searchPath,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
let parse = options && options.parse;
|
|
171
|
+
let configFilePath = await resolveConfig(
|
|
172
|
+
this.#options.inputFS,
|
|
173
|
+
searchPath,
|
|
174
|
+
fileNames,
|
|
175
|
+
this.#options.projectRoot,
|
|
176
|
+
);
|
|
177
|
+
if (configFilePath == null) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (!options || !options.exclude) {
|
|
182
|
+
this.invalidateOnFileChange(configFilePath);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// If this is a JavaScript file, load it with the package manager.
|
|
186
|
+
let extname = path.extname(configFilePath);
|
|
187
|
+
if (extname === '.js' || extname === '.cjs' || extname === '.mjs') {
|
|
188
|
+
let specifier = relativePath(path.dirname(searchPath), configFilePath);
|
|
189
|
+
|
|
190
|
+
// Add dev dependency so we reload the config and any dependencies in watch mode.
|
|
191
|
+
this.addDevDependency({
|
|
192
|
+
specifier,
|
|
193
|
+
resolveFrom: searchPath,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Invalidate on startup in case the config is non-deterministic,
|
|
197
|
+
// e.g. uses unknown environment variables, reads from the filesystem, etc.
|
|
198
|
+
this.invalidateOnStartup();
|
|
199
|
+
|
|
200
|
+
let config = await this.#options.packageManager.require(
|
|
201
|
+
specifier,
|
|
202
|
+
searchPath,
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
if (
|
|
206
|
+
// $FlowFixMe
|
|
207
|
+
Object.prototype.toString.call(config) === '[object Module]' &&
|
|
208
|
+
config.default != null
|
|
209
|
+
) {
|
|
210
|
+
// Native ESM config. Try to use a default export, otherwise fall back to the whole namespace.
|
|
211
|
+
config = config.default;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return {
|
|
215
|
+
contents: config,
|
|
216
|
+
filePath: configFilePath,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
let conf = await readConfig(
|
|
221
|
+
this.#options.inputFS,
|
|
222
|
+
configFilePath,
|
|
223
|
+
parse == null ? null : {parse},
|
|
224
|
+
);
|
|
225
|
+
if (conf == null) {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
contents: conf.config,
|
|
231
|
+
filePath: configFilePath,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
getConfig<T>(
|
|
236
|
+
filePaths: Array<FilePath>,
|
|
237
|
+
options: ?{|
|
|
238
|
+
packageKey?: string,
|
|
239
|
+
parse?: boolean,
|
|
240
|
+
exclude?: boolean,
|
|
241
|
+
|},
|
|
242
|
+
): Promise<?ConfigResultWithFilePath<T>> {
|
|
243
|
+
return this.getConfigFrom(this.searchPath, filePaths, options);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async getPackage(): Promise<?PackageJSON> {
|
|
247
|
+
if (this.#pkg) {
|
|
248
|
+
return this.#pkg;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
let pkgConfig = await this.getConfig<PackageJSON>(['package.json']);
|
|
252
|
+
if (!pkgConfig) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
this.#pkg = pkgConfig.contents;
|
|
257
|
+
this.#pkgFilePath = pkgConfig.filePath;
|
|
258
|
+
|
|
259
|
+
return this.#pkg;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import type {
|
|
3
|
+
Dependency as IDependency,
|
|
4
|
+
Environment as IEnvironment,
|
|
5
|
+
FilePath,
|
|
6
|
+
Meta,
|
|
7
|
+
MutableDependencySymbols as IMutableDependencySymbols,
|
|
8
|
+
SourceLocation,
|
|
9
|
+
SpecifierType,
|
|
10
|
+
DependencyPriority,
|
|
11
|
+
BundleBehavior,
|
|
12
|
+
} from '@atlaspack/types';
|
|
13
|
+
import type {
|
|
14
|
+
Dependency as InternalDependency,
|
|
15
|
+
AtlaspackOptions,
|
|
16
|
+
} from '../types';
|
|
17
|
+
import {BundleBehaviorNames} from '../types';
|
|
18
|
+
|
|
19
|
+
import nullthrows from 'nullthrows';
|
|
20
|
+
import Environment from './Environment';
|
|
21
|
+
import Target from './Target';
|
|
22
|
+
import {MutableDependencySymbols} from './Symbols';
|
|
23
|
+
import {
|
|
24
|
+
SpecifierType as SpecifierTypeMap,
|
|
25
|
+
Priority,
|
|
26
|
+
ExportsCondition,
|
|
27
|
+
} from '../types';
|
|
28
|
+
import {fromProjectPath} from '../projectPath';
|
|
29
|
+
import {fromInternalSourceLocation} from '../utils';
|
|
30
|
+
|
|
31
|
+
const SpecifierTypeNames = Object.keys(SpecifierTypeMap);
|
|
32
|
+
const PriorityNames = Object.keys(Priority);
|
|
33
|
+
|
|
34
|
+
const inspect = Symbol.for('nodejs.util.inspect.custom');
|
|
35
|
+
|
|
36
|
+
const internalDependencyToDependency: WeakMap<InternalDependency, Dependency> =
|
|
37
|
+
new WeakMap();
|
|
38
|
+
const _dependencyToInternalDependency: WeakMap<
|
|
39
|
+
IDependency,
|
|
40
|
+
InternalDependency,
|
|
41
|
+
> = new WeakMap();
|
|
42
|
+
export function dependencyToInternalDependency(
|
|
43
|
+
dependency: IDependency,
|
|
44
|
+
): InternalDependency {
|
|
45
|
+
return nullthrows(_dependencyToInternalDependency.get(dependency));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getPublicDependency(
|
|
49
|
+
dep: InternalDependency,
|
|
50
|
+
options: AtlaspackOptions,
|
|
51
|
+
): Dependency {
|
|
52
|
+
let existing = internalDependencyToDependency.get(dep);
|
|
53
|
+
if (existing != null) {
|
|
54
|
+
return existing;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return new Dependency(dep, options);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default class Dependency implements IDependency {
|
|
61
|
+
#dep /*: InternalDependency */;
|
|
62
|
+
#options /*: AtlaspackOptions */;
|
|
63
|
+
|
|
64
|
+
constructor(dep: InternalDependency, options: AtlaspackOptions): Dependency {
|
|
65
|
+
this.#dep = dep;
|
|
66
|
+
this.#options = options;
|
|
67
|
+
_dependencyToInternalDependency.set(this, dep);
|
|
68
|
+
internalDependencyToDependency.set(dep, this);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// $FlowFixMe
|
|
73
|
+
[inspect](): string {
|
|
74
|
+
return `Dependency(${String(this.sourcePath)} -> ${this.specifier})`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get id(): string {
|
|
78
|
+
return this.#dep.id;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get specifier(): string {
|
|
82
|
+
return this.#dep.specifier;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get specifierType(): SpecifierType {
|
|
86
|
+
return SpecifierTypeNames[this.#dep.specifierType];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get priority(): DependencyPriority {
|
|
90
|
+
return PriorityNames[this.#dep.priority];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get needsStableName(): boolean {
|
|
94
|
+
return this.#dep.needsStableName;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get bundleBehavior(): ?BundleBehavior {
|
|
98
|
+
let bundleBehavior = this.#dep.bundleBehavior;
|
|
99
|
+
return bundleBehavior == null ? null : BundleBehaviorNames[bundleBehavior];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get isEntry(): boolean {
|
|
103
|
+
return this.#dep.isEntry;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get isOptional(): boolean {
|
|
107
|
+
return this.#dep.isOptional;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
get loc(): ?SourceLocation {
|
|
111
|
+
return fromInternalSourceLocation(this.#options.projectRoot, this.#dep.loc);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
get env(): IEnvironment {
|
|
115
|
+
return new Environment(this.#dep.env, this.#options);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
get packageConditions(): ?Array<string> {
|
|
119
|
+
// Merge custom conditions with conditions stored as bitflags.
|
|
120
|
+
// Order is not important because exports conditions are resolved
|
|
121
|
+
// in the order they are declared in the package.json.
|
|
122
|
+
let conditions = this.#dep.customPackageConditions;
|
|
123
|
+
if (this.#dep.packageConditions) {
|
|
124
|
+
conditions = conditions ? [...conditions] : [];
|
|
125
|
+
for (let key in ExportsCondition) {
|
|
126
|
+
if (this.#dep.packageConditions & ExportsCondition[key]) {
|
|
127
|
+
conditions.push(key);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return conditions;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
get meta(): Meta {
|
|
136
|
+
return this.#dep.meta;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
get symbols(): IMutableDependencySymbols {
|
|
140
|
+
return new MutableDependencySymbols(this.#options, this.#dep);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
get target(): ?Target {
|
|
144
|
+
let target = this.#dep.target;
|
|
145
|
+
return target ? new Target(target, this.#options) : null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
get sourceAssetId(): ?string {
|
|
149
|
+
// TODO: does this need to be public?
|
|
150
|
+
return this.#dep.sourceAssetId;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
get sourcePath(): ?FilePath {
|
|
154
|
+
// TODO: does this need to be public?
|
|
155
|
+
return fromProjectPath(this.#options.projectRoot, this.#dep.sourcePath);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
get sourceAssetType(): ?string {
|
|
159
|
+
return this.#dep.sourceAssetType;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
get resolveFrom(): ?string {
|
|
163
|
+
return fromProjectPath(
|
|
164
|
+
this.#options.projectRoot,
|
|
165
|
+
this.#dep.resolveFrom ?? this.#dep.sourcePath,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
get range(): ?string {
|
|
170
|
+
return this.#dep.range;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
get pipeline(): ?string {
|
|
174
|
+
return this.#dep.pipeline;
|
|
175
|
+
}
|
|
176
|
+
}
|