@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,143 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import type {AST, Blob} from '@atlaspack/types';
|
|
4
|
+
import type {Asset, Dependency, AtlaspackOptions} from './types';
|
|
5
|
+
|
|
6
|
+
import {Readable} from 'stream';
|
|
7
|
+
import SourceMap from '@parcel/source-map';
|
|
8
|
+
import {bufferStream, blobToStream, streamFromPromise} from '@atlaspack/utils';
|
|
9
|
+
import {generateFromAST} from './assetUtils';
|
|
10
|
+
import {deserializeRaw} from './serializer';
|
|
11
|
+
|
|
12
|
+
export default class CommittedAsset {
|
|
13
|
+
key: ?string;
|
|
14
|
+
value: Asset;
|
|
15
|
+
options: AtlaspackOptions;
|
|
16
|
+
content: ?Promise<Buffer | string>;
|
|
17
|
+
mapBuffer: ?Promise<?Buffer>;
|
|
18
|
+
map: ?Promise<?SourceMap>;
|
|
19
|
+
ast: ?Promise<AST>;
|
|
20
|
+
idBase: ?string;
|
|
21
|
+
generatingPromise: ?Promise<void>;
|
|
22
|
+
|
|
23
|
+
constructor(value: Asset, options: AtlaspackOptions) {
|
|
24
|
+
this.value = value;
|
|
25
|
+
this.key = this.value.contentKey;
|
|
26
|
+
this.options = options;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
getContent(): Blob | Promise<Buffer | string> {
|
|
30
|
+
if (this.content == null) {
|
|
31
|
+
if (this.key != null) {
|
|
32
|
+
if (this.value.isLargeBlob) {
|
|
33
|
+
return this.options.cache.getStream(this.key);
|
|
34
|
+
} else {
|
|
35
|
+
return this.options.cache.getBlob(this.key);
|
|
36
|
+
}
|
|
37
|
+
} else if (this.value.astKey != null) {
|
|
38
|
+
return streamFromPromise(
|
|
39
|
+
generateFromAST(this).then(({content}) => {
|
|
40
|
+
if (!(content instanceof Readable)) {
|
|
41
|
+
this.content = Promise.resolve(content);
|
|
42
|
+
}
|
|
43
|
+
return content;
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
} else {
|
|
47
|
+
throw new Error('Asset has no content');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return this.content;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async getCode(): Promise<string> {
|
|
55
|
+
let content;
|
|
56
|
+
if (this.content == null && this.key != null) {
|
|
57
|
+
this.content = this.options.cache.getBlob(this.key);
|
|
58
|
+
content = await this.content;
|
|
59
|
+
} else {
|
|
60
|
+
content = await this.getContent();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (typeof content === 'string' || content instanceof Buffer) {
|
|
64
|
+
return content.toString();
|
|
65
|
+
} else if (content != null) {
|
|
66
|
+
this.content = bufferStream(content);
|
|
67
|
+
return (await this.content).toString();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return '';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async getBuffer(): Promise<Buffer> {
|
|
74
|
+
let content = await this.getContent();
|
|
75
|
+
|
|
76
|
+
if (content == null) {
|
|
77
|
+
return Buffer.alloc(0);
|
|
78
|
+
} else if (typeof content === 'string' || content instanceof Buffer) {
|
|
79
|
+
return Buffer.from(content);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.content = bufferStream(content);
|
|
83
|
+
return this.content;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
getStream(): Readable {
|
|
87
|
+
let content = this.getContent();
|
|
88
|
+
return content instanceof Promise
|
|
89
|
+
? streamFromPromise(content)
|
|
90
|
+
: blobToStream(content);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getMapBuffer(): Promise<?Buffer> {
|
|
94
|
+
let mapKey = this.value.mapKey;
|
|
95
|
+
if (mapKey != null && this.mapBuffer == null) {
|
|
96
|
+
this.mapBuffer = (async () => {
|
|
97
|
+
try {
|
|
98
|
+
return await this.options.cache.getBlob(mapKey);
|
|
99
|
+
} catch (err) {
|
|
100
|
+
if (err.code === 'ENOENT' && this.value.astKey != null) {
|
|
101
|
+
return (await generateFromAST(this)).map?.toBuffer();
|
|
102
|
+
} else {
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
})();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return this.mapBuffer ?? Promise.resolve();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
getMap(): Promise<?SourceMap> {
|
|
113
|
+
if (this.map == null) {
|
|
114
|
+
this.map = (async () => {
|
|
115
|
+
let mapBuffer = await this.getMapBuffer();
|
|
116
|
+
if (mapBuffer) {
|
|
117
|
+
// Get sourcemap from flatbuffer
|
|
118
|
+
return new SourceMap(this.options.projectRoot, mapBuffer);
|
|
119
|
+
}
|
|
120
|
+
})();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return this.map;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
getAST(): Promise<?AST> {
|
|
127
|
+
if (this.value.astKey == null) {
|
|
128
|
+
return Promise.resolve(null);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (this.ast == null) {
|
|
132
|
+
this.ast = this.options.cache
|
|
133
|
+
.getBlob(this.value.astKey)
|
|
134
|
+
.then(serializedAst => deserializeRaw(serializedAst));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return this.ast;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
getDependencies(): Array<Dependency> {
|
|
141
|
+
return Array.from(this.value.dependencies.values());
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import type {
|
|
3
|
+
FilePath,
|
|
4
|
+
Meta,
|
|
5
|
+
DependencySpecifier,
|
|
6
|
+
SourceLocation,
|
|
7
|
+
Symbol,
|
|
8
|
+
BundleBehavior as IBundleBehavior,
|
|
9
|
+
SemverRange,
|
|
10
|
+
} from '@atlaspack/types';
|
|
11
|
+
import type {Dependency, Environment, Target} from './types';
|
|
12
|
+
import {hashString} from '@atlaspack/rust';
|
|
13
|
+
import {
|
|
14
|
+
SpecifierType,
|
|
15
|
+
Priority,
|
|
16
|
+
BundleBehavior,
|
|
17
|
+
ExportsCondition,
|
|
18
|
+
} from './types';
|
|
19
|
+
|
|
20
|
+
import {toInternalSourceLocation} from './utils';
|
|
21
|
+
import {toProjectPath} from './projectPath';
|
|
22
|
+
|
|
23
|
+
type DependencyOpts = {|
|
|
24
|
+
id?: string,
|
|
25
|
+
sourcePath?: FilePath,
|
|
26
|
+
sourceAssetId?: string,
|
|
27
|
+
specifier: DependencySpecifier,
|
|
28
|
+
specifierType: $Keys<typeof SpecifierType>,
|
|
29
|
+
priority?: $Keys<typeof Priority>,
|
|
30
|
+
needsStableName?: boolean,
|
|
31
|
+
bundleBehavior?: ?IBundleBehavior,
|
|
32
|
+
isEntry?: boolean,
|
|
33
|
+
isOptional?: boolean,
|
|
34
|
+
loc?: SourceLocation,
|
|
35
|
+
env: Environment,
|
|
36
|
+
packageConditions?: Array<string>,
|
|
37
|
+
meta?: Meta,
|
|
38
|
+
resolveFrom?: FilePath,
|
|
39
|
+
range?: SemverRange,
|
|
40
|
+
target?: Target,
|
|
41
|
+
symbols?: ?Map<
|
|
42
|
+
Symbol,
|
|
43
|
+
{|local: Symbol, loc: ?SourceLocation, isWeak: boolean, meta?: ?Meta|},
|
|
44
|
+
>,
|
|
45
|
+
pipeline?: ?string,
|
|
46
|
+
|};
|
|
47
|
+
|
|
48
|
+
export function createDependency(
|
|
49
|
+
projectRoot: FilePath,
|
|
50
|
+
opts: DependencyOpts,
|
|
51
|
+
): Dependency {
|
|
52
|
+
let id =
|
|
53
|
+
opts.id ||
|
|
54
|
+
hashString(
|
|
55
|
+
(opts.sourceAssetId ?? '') +
|
|
56
|
+
opts.specifier +
|
|
57
|
+
opts.env.id +
|
|
58
|
+
(opts.target ? JSON.stringify(opts.target) : '') +
|
|
59
|
+
(opts.pipeline ?? '') +
|
|
60
|
+
opts.specifierType +
|
|
61
|
+
(opts.bundleBehavior ?? '') +
|
|
62
|
+
(opts.priority ?? 'sync') +
|
|
63
|
+
(opts.packageConditions ? JSON.stringify(opts.packageConditions) : ''),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
let dep: Dependency = {
|
|
67
|
+
id,
|
|
68
|
+
specifier: opts.specifier,
|
|
69
|
+
specifierType: SpecifierType[opts.specifierType],
|
|
70
|
+
priority: Priority[opts.priority ?? 'sync'],
|
|
71
|
+
needsStableName: opts.needsStableName ?? false,
|
|
72
|
+
bundleBehavior: opts.bundleBehavior
|
|
73
|
+
? BundleBehavior[opts.bundleBehavior]
|
|
74
|
+
: null,
|
|
75
|
+
isEntry: opts.isEntry ?? false,
|
|
76
|
+
isOptional: opts.isOptional ?? false,
|
|
77
|
+
loc: toInternalSourceLocation(projectRoot, opts.loc),
|
|
78
|
+
env: opts.env,
|
|
79
|
+
meta: opts.meta || {},
|
|
80
|
+
target: opts.target,
|
|
81
|
+
sourceAssetId: opts.sourceAssetId,
|
|
82
|
+
sourcePath: toProjectPath(projectRoot, opts.sourcePath),
|
|
83
|
+
resolveFrom: toProjectPath(projectRoot, opts.resolveFrom),
|
|
84
|
+
range: opts.range,
|
|
85
|
+
symbols:
|
|
86
|
+
opts.symbols &&
|
|
87
|
+
new Map(
|
|
88
|
+
[...opts.symbols].map(([k, v]) => [
|
|
89
|
+
k,
|
|
90
|
+
{
|
|
91
|
+
local: v.local,
|
|
92
|
+
meta: v.meta,
|
|
93
|
+
isWeak: v.isWeak,
|
|
94
|
+
loc: toInternalSourceLocation(projectRoot, v.loc),
|
|
95
|
+
},
|
|
96
|
+
]),
|
|
97
|
+
),
|
|
98
|
+
pipeline: opts.pipeline,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
if (opts.packageConditions) {
|
|
102
|
+
convertConditions(opts.packageConditions, dep);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return dep;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function mergeDependencies(a: Dependency, b: Dependency): void {
|
|
109
|
+
let {meta, symbols, needsStableName, isEntry, isOptional, ...other} = b;
|
|
110
|
+
Object.assign(a, other);
|
|
111
|
+
Object.assign(a.meta, meta);
|
|
112
|
+
if (a.symbols && symbols) {
|
|
113
|
+
for (let [k, v] of symbols) {
|
|
114
|
+
a.symbols.set(k, v);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (needsStableName) a.needsStableName = true;
|
|
118
|
+
if (isEntry) a.isEntry = true;
|
|
119
|
+
if (!isOptional) a.isOptional = false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function convertConditions(conditions: Array<string>, dep: Dependency) {
|
|
123
|
+
// Store common package conditions as bit flags to reduce size.
|
|
124
|
+
// Custom conditions are stored as strings.
|
|
125
|
+
let packageConditions = 0;
|
|
126
|
+
let customConditions = [];
|
|
127
|
+
for (let condition of conditions) {
|
|
128
|
+
if (ExportsCondition[condition]) {
|
|
129
|
+
packageConditions |= ExportsCondition[condition];
|
|
130
|
+
} else {
|
|
131
|
+
customConditions.push(condition);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (packageConditions) {
|
|
136
|
+
dep.packageConditions = packageConditions;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (customConditions.length) {
|
|
140
|
+
dep.customPackageConditions = customConditions;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import type {
|
|
3
|
+
EnvironmentOptions,
|
|
4
|
+
Environment as IEnvironment,
|
|
5
|
+
FilePath,
|
|
6
|
+
} from '@atlaspack/types';
|
|
7
|
+
import type {Environment, InternalSourceLocation} from './types';
|
|
8
|
+
import {hashString} from '@atlaspack/rust';
|
|
9
|
+
import {toInternalSourceLocation} from './utils';
|
|
10
|
+
import PublicEnvironment from './public/Environment';
|
|
11
|
+
import {environmentToInternalEnvironment} from './public/Environment';
|
|
12
|
+
|
|
13
|
+
const DEFAULT_ENGINES = {
|
|
14
|
+
browsers: ['> 0.25%'],
|
|
15
|
+
node: '>= 8.0.0',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type EnvironmentOpts = {|
|
|
19
|
+
...EnvironmentOptions,
|
|
20
|
+
loc?: ?InternalSourceLocation,
|
|
21
|
+
|};
|
|
22
|
+
|
|
23
|
+
export function createEnvironment({
|
|
24
|
+
context,
|
|
25
|
+
engines,
|
|
26
|
+
includeNodeModules,
|
|
27
|
+
outputFormat,
|
|
28
|
+
sourceType = 'module',
|
|
29
|
+
shouldOptimize = false,
|
|
30
|
+
isLibrary = false,
|
|
31
|
+
shouldScopeHoist = false,
|
|
32
|
+
sourceMap,
|
|
33
|
+
loc,
|
|
34
|
+
}: EnvironmentOpts = {
|
|
35
|
+
/*::...null*/
|
|
36
|
+
}): Environment {
|
|
37
|
+
if (context == null) {
|
|
38
|
+
if (engines?.node) {
|
|
39
|
+
context = 'node';
|
|
40
|
+
} else if (engines?.browsers) {
|
|
41
|
+
context = 'browser';
|
|
42
|
+
} else {
|
|
43
|
+
context = 'browser';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (engines == null) {
|
|
48
|
+
switch (context) {
|
|
49
|
+
case 'node':
|
|
50
|
+
case 'electron-main':
|
|
51
|
+
engines = {
|
|
52
|
+
node: DEFAULT_ENGINES.node,
|
|
53
|
+
};
|
|
54
|
+
break;
|
|
55
|
+
case 'browser':
|
|
56
|
+
case 'web-worker':
|
|
57
|
+
case 'service-worker':
|
|
58
|
+
case 'electron-renderer':
|
|
59
|
+
engines = {
|
|
60
|
+
browsers: DEFAULT_ENGINES.browsers,
|
|
61
|
+
};
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
engines = {};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (includeNodeModules == null) {
|
|
69
|
+
switch (context) {
|
|
70
|
+
case 'node':
|
|
71
|
+
case 'electron-main':
|
|
72
|
+
case 'electron-renderer':
|
|
73
|
+
includeNodeModules = false;
|
|
74
|
+
break;
|
|
75
|
+
case 'browser':
|
|
76
|
+
case 'web-worker':
|
|
77
|
+
case 'service-worker':
|
|
78
|
+
default:
|
|
79
|
+
includeNodeModules = true;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (outputFormat == null) {
|
|
85
|
+
switch (context) {
|
|
86
|
+
case 'node':
|
|
87
|
+
case 'electron-main':
|
|
88
|
+
case 'electron-renderer':
|
|
89
|
+
outputFormat = 'commonjs';
|
|
90
|
+
break;
|
|
91
|
+
default:
|
|
92
|
+
outputFormat = 'global';
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let res: Environment = {
|
|
98
|
+
id: '',
|
|
99
|
+
context,
|
|
100
|
+
engines,
|
|
101
|
+
includeNodeModules,
|
|
102
|
+
outputFormat,
|
|
103
|
+
sourceType,
|
|
104
|
+
isLibrary,
|
|
105
|
+
shouldOptimize,
|
|
106
|
+
shouldScopeHoist,
|
|
107
|
+
sourceMap,
|
|
108
|
+
loc,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
res.id = getEnvironmentHash(res);
|
|
112
|
+
return res;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function mergeEnvironments(
|
|
116
|
+
projectRoot: FilePath,
|
|
117
|
+
a: Environment,
|
|
118
|
+
b: ?(EnvironmentOptions | IEnvironment),
|
|
119
|
+
): Environment {
|
|
120
|
+
// If merging the same object, avoid copying.
|
|
121
|
+
if (a === b || !b) {
|
|
122
|
+
return a;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (b instanceof PublicEnvironment) {
|
|
126
|
+
return environmentToInternalEnvironment(b);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// $FlowFixMe - ignore the `id` that is already on a
|
|
130
|
+
return createEnvironment({
|
|
131
|
+
...a,
|
|
132
|
+
...b,
|
|
133
|
+
loc: b.loc ? toInternalSourceLocation(projectRoot, b.loc) : a.loc,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function getEnvironmentHash(env: Environment): string {
|
|
138
|
+
return hashString(
|
|
139
|
+
JSON.stringify([
|
|
140
|
+
env.context,
|
|
141
|
+
env.engines,
|
|
142
|
+
env.includeNodeModules,
|
|
143
|
+
env.outputFormat,
|
|
144
|
+
env.sourceType,
|
|
145
|
+
env.isLibrary,
|
|
146
|
+
env.shouldOptimize,
|
|
147
|
+
env.shouldScopeHoist,
|
|
148
|
+
env.sourceMap,
|
|
149
|
+
]),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import type {PackageName, ConfigResult} from '@atlaspack/types';
|
|
4
|
+
import type {
|
|
5
|
+
Config,
|
|
6
|
+
Environment,
|
|
7
|
+
InternalFileCreateInvalidation,
|
|
8
|
+
InternalDevDepOptions,
|
|
9
|
+
} from './types';
|
|
10
|
+
import type {ProjectPath} from './projectPath';
|
|
11
|
+
|
|
12
|
+
import {fromProjectPathRelative} from './projectPath';
|
|
13
|
+
import {createEnvironment} from './Environment';
|
|
14
|
+
import {hashString} from '@atlaspack/rust';
|
|
15
|
+
|
|
16
|
+
type ConfigOpts = {|
|
|
17
|
+
plugin: PackageName,
|
|
18
|
+
searchPath: ProjectPath,
|
|
19
|
+
isSource?: boolean,
|
|
20
|
+
env?: Environment,
|
|
21
|
+
result?: ConfigResult,
|
|
22
|
+
invalidateOnFileChange?: Set<ProjectPath>,
|
|
23
|
+
invalidateOnConfigKeyChange?: Array<{|
|
|
24
|
+
filePath: ProjectPath,
|
|
25
|
+
configKey: string,
|
|
26
|
+
|}>,
|
|
27
|
+
invalidateOnFileCreate?: Array<InternalFileCreateInvalidation>,
|
|
28
|
+
invalidateOnEnvChange?: Set<string>,
|
|
29
|
+
invalidateOnOptionChange?: Set<string>,
|
|
30
|
+
devDeps?: Array<InternalDevDepOptions>,
|
|
31
|
+
invalidateOnStartup?: boolean,
|
|
32
|
+
invalidateOnBuild?: boolean,
|
|
33
|
+
|};
|
|
34
|
+
|
|
35
|
+
export function createConfig({
|
|
36
|
+
plugin,
|
|
37
|
+
isSource,
|
|
38
|
+
searchPath,
|
|
39
|
+
env,
|
|
40
|
+
result,
|
|
41
|
+
invalidateOnFileChange,
|
|
42
|
+
invalidateOnConfigKeyChange,
|
|
43
|
+
invalidateOnFileCreate,
|
|
44
|
+
invalidateOnEnvChange,
|
|
45
|
+
invalidateOnOptionChange,
|
|
46
|
+
devDeps,
|
|
47
|
+
invalidateOnStartup,
|
|
48
|
+
invalidateOnBuild,
|
|
49
|
+
}: ConfigOpts): Config {
|
|
50
|
+
let environment = env ?? createEnvironment();
|
|
51
|
+
return {
|
|
52
|
+
id: hashString(
|
|
53
|
+
plugin +
|
|
54
|
+
fromProjectPathRelative(searchPath) +
|
|
55
|
+
environment.id +
|
|
56
|
+
String(isSource),
|
|
57
|
+
),
|
|
58
|
+
isSource: isSource ?? false,
|
|
59
|
+
searchPath,
|
|
60
|
+
env: environment,
|
|
61
|
+
result: result ?? null,
|
|
62
|
+
cacheKey: null,
|
|
63
|
+
invalidateOnFileChange: invalidateOnFileChange ?? new Set(),
|
|
64
|
+
invalidateOnConfigKeyChange: invalidateOnConfigKeyChange ?? [],
|
|
65
|
+
invalidateOnFileCreate: invalidateOnFileCreate ?? [],
|
|
66
|
+
invalidateOnEnvChange: invalidateOnEnvChange ?? new Set(),
|
|
67
|
+
invalidateOnOptionChange: invalidateOnOptionChange ?? new Set(),
|
|
68
|
+
devDeps: devDeps ?? [],
|
|
69
|
+
invalidateOnStartup: invalidateOnStartup ?? false,
|
|
70
|
+
invalidateOnBuild: invalidateOnBuild ?? false,
|
|
71
|
+
};
|
|
72
|
+
}
|