@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.
Files changed (215) hide show
  1. package/LICENSE +201 -0
  2. package/index.d.ts +22 -0
  3. package/lib/AssetGraph.js +518 -0
  4. package/lib/Atlaspack.js +587 -0
  5. package/lib/AtlaspackConfig.js +298 -0
  6. package/lib/AtlaspackConfig.schema.js +125 -0
  7. package/lib/BundleGraph.js +1445 -0
  8. package/lib/CommittedAsset.js +133 -0
  9. package/lib/Dependency.js +88 -0
  10. package/lib/Environment.js +128 -0
  11. package/lib/InternalConfig.js +48 -0
  12. package/lib/PackagerRunner.js +519 -0
  13. package/lib/ReporterRunner.js +151 -0
  14. package/lib/RequestTracker.js +1089 -0
  15. package/lib/SymbolPropagation.js +625 -0
  16. package/lib/TargetDescriptor.schema.js +115 -0
  17. package/lib/Transformation.js +536 -0
  18. package/lib/UncommittedAsset.js +342 -0
  19. package/lib/Validation.js +215 -0
  20. package/lib/applyRuntimes.js +279 -0
  21. package/lib/assetUtils.js +189 -0
  22. package/lib/atlaspack-v3/AtlaspackV3.js +74 -0
  23. package/lib/atlaspack-v3/fs.js +30 -0
  24. package/lib/atlaspack-v3/index.js +19 -0
  25. package/lib/atlaspack-v3/jsCallable.js +15 -0
  26. package/lib/atlaspack-v3/plugins/Resolver.js +12 -0
  27. package/lib/atlaspack-v3/plugins/index.js +16 -0
  28. package/lib/atlaspack-v3/worker/index.js +3 -0
  29. package/lib/atlaspack-v3/worker/worker.js +30 -0
  30. package/lib/buildCache.js +18 -0
  31. package/lib/constants.js +21 -0
  32. package/lib/dumpGraphToGraphViz.js +206 -0
  33. package/lib/index.js +106 -0
  34. package/lib/loadAtlaspackPlugin.js +148 -0
  35. package/lib/loadDotEnv.js +54 -0
  36. package/lib/projectPath.js +86 -0
  37. package/lib/public/Asset.js +259 -0
  38. package/lib/public/Bundle.js +231 -0
  39. package/lib/public/BundleGraph.js +193 -0
  40. package/lib/public/BundleGroup.js +44 -0
  41. package/lib/public/Config.js +202 -0
  42. package/lib/public/Dependency.js +131 -0
  43. package/lib/public/Environment.js +244 -0
  44. package/lib/public/MutableBundleGraph.js +184 -0
  45. package/lib/public/PluginOptions.js +71 -0
  46. package/lib/public/Symbols.js +247 -0
  47. package/lib/public/Target.js +64 -0
  48. package/lib/registerCoreWithSerializer.js +45 -0
  49. package/lib/requests/AssetGraphRequest.js +427 -0
  50. package/lib/requests/AssetGraphRequestRust.js +187 -0
  51. package/lib/requests/AssetRequest.js +137 -0
  52. package/lib/requests/AtlaspackBuildRequest.js +78 -0
  53. package/lib/requests/AtlaspackConfigRequest.js +473 -0
  54. package/lib/requests/BundleGraphRequest.js +419 -0
  55. package/lib/requests/ConfigRequest.js +198 -0
  56. package/lib/requests/DevDepRequest.js +166 -0
  57. package/lib/requests/EntryRequest.js +295 -0
  58. package/lib/requests/PackageRequest.js +88 -0
  59. package/lib/requests/PathRequest.js +349 -0
  60. package/lib/requests/TargetRequest.js +1177 -0
  61. package/lib/requests/ValidationRequest.js +66 -0
  62. package/lib/requests/WriteBundleRequest.js +252 -0
  63. package/lib/requests/WriteBundlesRequest.js +153 -0
  64. package/lib/resolveOptions.js +234 -0
  65. package/lib/serializer.js +216 -0
  66. package/lib/serializerCore.browser.js +29 -0
  67. package/lib/serializerCore.js +16 -0
  68. package/lib/summarizeRequest.js +55 -0
  69. package/lib/types.js +35 -0
  70. package/lib/utils.js +160 -0
  71. package/lib/worker.js +170 -0
  72. package/package.json +59 -0
  73. package/src/AssetGraph.js +646 -0
  74. package/src/Atlaspack.js +632 -0
  75. package/src/AtlaspackConfig.js +490 -0
  76. package/src/AtlaspackConfig.schema.js +141 -0
  77. package/src/BundleGraph.js +2193 -0
  78. package/src/CommittedAsset.js +143 -0
  79. package/src/Dependency.js +142 -0
  80. package/src/Environment.js +151 -0
  81. package/src/InternalConfig.js +72 -0
  82. package/src/PackagerRunner.js +790 -0
  83. package/src/ReporterRunner.js +158 -0
  84. package/src/RequestTracker.js +1697 -0
  85. package/src/SymbolPropagation.js +794 -0
  86. package/src/TargetDescriptor.schema.js +136 -0
  87. package/src/Transformation.js +752 -0
  88. package/src/UncommittedAsset.js +426 -0
  89. package/src/Validation.js +223 -0
  90. package/src/applyRuntimes.js +341 -0
  91. package/src/assetUtils.js +254 -0
  92. package/src/atlaspack-v3/AtlaspackV3.js +73 -0
  93. package/src/atlaspack-v3/fs.js +36 -0
  94. package/src/atlaspack-v3/index.js +5 -0
  95. package/src/atlaspack-v3/jsCallable.js +13 -0
  96. package/src/atlaspack-v3/plugins/Resolver.js +9 -0
  97. package/src/atlaspack-v3/plugins/index.js +3 -0
  98. package/src/atlaspack-v3/worker/index.js +8 -0
  99. package/src/atlaspack-v3/worker/worker.js +14 -0
  100. package/src/buildCache.js +15 -0
  101. package/src/constants.js +22 -0
  102. package/src/dumpGraphToGraphViz.js +244 -0
  103. package/src/index.js +22 -0
  104. package/src/loadAtlaspackPlugin.js +239 -0
  105. package/src/loadDotEnv.js +56 -0
  106. package/src/projectPath.js +87 -0
  107. package/src/public/Asset.js +359 -0
  108. package/src/public/Bundle.js +337 -0
  109. package/src/public/BundleGraph.js +335 -0
  110. package/src/public/BundleGroup.js +55 -0
  111. package/src/public/Config.js +261 -0
  112. package/src/public/Dependency.js +176 -0
  113. package/src/public/Environment.js +316 -0
  114. package/src/public/MutableBundleGraph.js +320 -0
  115. package/src/public/PluginOptions.js +99 -0
  116. package/src/public/Symbols.js +315 -0
  117. package/src/public/Target.js +71 -0
  118. package/src/registerCoreWithSerializer.js +34 -0
  119. package/src/requests/AssetGraphRequest.js +577 -0
  120. package/src/requests/AssetGraphRequestRust.js +222 -0
  121. package/src/requests/AssetRequest.js +179 -0
  122. package/src/requests/AtlaspackBuildRequest.js +109 -0
  123. package/src/requests/AtlaspackConfigRequest.js +709 -0
  124. package/src/requests/BundleGraphRequest.js +547 -0
  125. package/src/requests/ConfigRequest.js +287 -0
  126. package/src/requests/DevDepRequest.js +246 -0
  127. package/src/requests/EntryRequest.js +385 -0
  128. package/src/requests/PackageRequest.js +105 -0
  129. package/src/requests/PathRequest.js +454 -0
  130. package/src/requests/TargetRequest.js +1632 -0
  131. package/src/requests/ValidationRequest.js +79 -0
  132. package/src/requests/WriteBundleRequest.js +362 -0
  133. package/src/requests/WriteBundlesRequest.js +209 -0
  134. package/src/resolveOptions.js +278 -0
  135. package/src/serializer.js +255 -0
  136. package/src/serializerCore.browser.js +8 -0
  137. package/src/serializerCore.js +5 -0
  138. package/src/summarizeRequest.js +47 -0
  139. package/src/types.js +581 -0
  140. package/src/utils.js +211 -0
  141. package/src/worker.js +189 -0
  142. package/test/AssetGraph.test.js +679 -0
  143. package/test/Atlaspack.test.js +142 -0
  144. package/test/AtlaspackConfig.test.js +405 -0
  145. package/test/AtlaspackConfigRequest.test.js +993 -0
  146. package/test/BundleGraph.test.js +121 -0
  147. package/test/EntryRequest.test.js +215 -0
  148. package/test/Environment.test.js +99 -0
  149. package/test/InternalAsset.test.js +76 -0
  150. package/test/PackagerRunner.test.js +27 -0
  151. package/test/PublicAsset.test.js +40 -0
  152. package/test/PublicBundle.test.js +68 -0
  153. package/test/PublicDependency.test.js +22 -0
  154. package/test/PublicEnvironment.test.js +27 -0
  155. package/test/PublicMutableBundleGraph.test.js +192 -0
  156. package/test/RequestTracker.test.js +448 -0
  157. package/test/SymbolPropagation.test.js +716 -0
  158. package/test/TargetRequest.test.js +1715 -0
  159. package/test/fixtures/application-targets/package.json +3 -0
  160. package/test/fixtures/atlaspack/index.js +1 -0
  161. package/test/fixtures/atlaspack/other.js +3 -0
  162. package/test/fixtures/atlaspack/package.json +1 -0
  163. package/test/fixtures/atlaspack/yarn.lock +0 -0
  164. package/test/fixtures/bundle.js +10 -0
  165. package/test/fixtures/common-targets/package.json +24 -0
  166. package/test/fixtures/common-targets-ignore/package.json +13 -0
  167. package/test/fixtures/config/.atlaspackrc +6 -0
  168. package/test/fixtures/config/subfolder/.atlaspackrc +6 -0
  169. package/test/fixtures/config-extends-not-found/.atlaspackrc +3 -0
  170. package/test/fixtures/config-extends-not-found/.atlaspackrc-json5 +3 -0
  171. package/test/fixtures/config-extends-not-found/.atlaspackrc-multiple +3 -0
  172. package/test/fixtures/config-extends-not-found/.atlaspackrc-node-modules +3 -0
  173. package/test/fixtures/config-malformed/.atlaspackrc +3 -0
  174. package/test/fixtures/config-node-pipeline/.atlaspackrc +6 -0
  175. package/test/fixtures/config-plugin-not-found/.atlaspackrc +6 -0
  176. package/test/fixtures/context/package.json +8 -0
  177. package/test/fixtures/custom-format-infer-ext/package.json +6 -0
  178. package/test/fixtures/custom-format-infer-type/package.json +7 -0
  179. package/test/fixtures/custom-format-mismatch/package.json +8 -0
  180. package/test/fixtures/custom-targets/package.json +20 -0
  181. package/test/fixtures/custom-targets-distdir/package.json +11 -0
  182. package/test/fixtures/duplicate-targets/package.json +4 -0
  183. package/test/fixtures/glob-like/[entry].js +0 -0
  184. package/test/fixtures/invalid-distpath/package.json +11 -0
  185. package/test/fixtures/invalid-engines/package.json +12 -0
  186. package/test/fixtures/invalid-source-missing/package.json +5 -0
  187. package/test/fixtures/invalid-source-not-file/package.json +5 -0
  188. package/test/fixtures/invalid-source-not-file/src/index.js +1 -0
  189. package/test/fixtures/invalid-target-source-missing/package.json +9 -0
  190. package/test/fixtures/invalid-target-source-not-file/package.json +9 -0
  191. package/test/fixtures/invalid-target-source-not-file/src/index.js +1 -0
  192. package/test/fixtures/invalid-targets/package.json +19 -0
  193. package/test/fixtures/library-custom-scopehoist/package.json +9 -0
  194. package/test/fixtures/library-scopehoist/package.json +8 -0
  195. package/test/fixtures/local-plugin-config-pkg/.atlaspackrc +3 -0
  196. package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/index.json +8 -0
  197. package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/local-plugin.js +7 -0
  198. package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/package.json +7 -0
  199. package/test/fixtures/main-format-mismatch/package.json +8 -0
  200. package/test/fixtures/main-global/package.json +8 -0
  201. package/test/fixtures/main-mjs/package.json +8 -0
  202. package/test/fixtures/module-a.js +1 -0
  203. package/test/fixtures/module-b.js +1 -0
  204. package/test/fixtures/plugins/local-plugin.js +7 -0
  205. package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/index.js +7 -0
  206. package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/package.json +7 -0
  207. package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/index.js +7 -0
  208. package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/package.json +4 -0
  209. package/test/fixtures/targets-default-distdir-none/package.json +5 -0
  210. package/test/fixtures/targets-default-distdir-one/package.json +8 -0
  211. package/test/fixtures/targets-default-distdir-two/package.json +18 -0
  212. package/test/requests/ConfigRequest.test.js +254 -0
  213. package/test/serializer.test.js +302 -0
  214. package/test/test-utils.js +80 -0
  215. package/test/utils.test.js +43 -0
@@ -0,0 +1,87 @@
1
+ // @flow strict-local
2
+ import type {FilePath} from '@atlaspack/types';
3
+ import path from 'path';
4
+ import {relativePath, normalizeSeparators} from '@atlaspack/utils';
5
+
6
+ /**
7
+ * A path that's relative to the project root.
8
+ */
9
+ export opaque type ProjectPath = string;
10
+
11
+ function toProjectPath_(projectRoot: FilePath, p: FilePath): ProjectPath {
12
+ if (p == null) {
13
+ return p;
14
+ }
15
+
16
+ // If the file is outside the project root, store an absolute path rather
17
+ // than a relative one. This way if the project root is moved, the file
18
+ // references still work. Accessing files outside the project root is not
19
+ // portable anyway.
20
+ let relative = relativePath(projectRoot, p, false);
21
+ if (relative.startsWith('..')) {
22
+ return process.platform === 'win32' ? normalizeSeparators(p) : p;
23
+ }
24
+
25
+ return relative;
26
+ }
27
+
28
+ export const toProjectPath: ((
29
+ projectRoot: FilePath,
30
+ p: FilePath,
31
+ ) => ProjectPath) &
32
+ ((projectRoot: FilePath, p: FilePath | void) => ProjectPath | void) &
33
+ // $FlowFixMe Not sure how to type properly
34
+ ((projectRoot: FilePath, p: ?FilePath) => ?ProjectPath) = toProjectPath_;
35
+
36
+ function fromProjectPath_(projectRoot: FilePath, p: ?ProjectPath): ?FilePath {
37
+ if (p == null) {
38
+ return null;
39
+ }
40
+
41
+ // Project paths use normalized unix separators, so we only need to
42
+ // convert them on Windows.
43
+ let projectPath = process.platform === 'win32' ? path.normalize(p) : p;
44
+
45
+ // If the path is absolute (e.g. outside the project root), just return it.
46
+ if (path.isAbsolute(projectPath)) {
47
+ return projectPath;
48
+ }
49
+
50
+ // Add separator if needed. Doing this manunally is much faster than path.join.
51
+ if (projectRoot[projectRoot.length - 1] !== path.sep) {
52
+ return projectRoot + path.sep + projectPath;
53
+ }
54
+
55
+ return projectRoot + projectPath;
56
+ }
57
+
58
+ export const fromProjectPath: ((
59
+ projectRoot: FilePath,
60
+ p: ProjectPath,
61
+ ) => FilePath) &
62
+ // $FlowFixMe Not sure how to type properly
63
+ ((projectRoot: FilePath, p: ?ProjectPath) => ?FilePath) = fromProjectPath_;
64
+
65
+ /**
66
+ * Returns a path relative to the project root. This should be used when computing cache keys
67
+ */
68
+ export function fromProjectPathRelative(p: ProjectPath): FilePath {
69
+ return p;
70
+ }
71
+
72
+ /**
73
+ * This function should be avoided, it doesn't change the actual value.
74
+ */
75
+ export function toProjectPathUnsafe(p: FilePath): ProjectPath {
76
+ return p;
77
+ }
78
+
79
+ /**
80
+ * Joins a project root with relative paths (similar to `path.join`)
81
+ */
82
+ export function joinProjectPath(
83
+ a: ProjectPath,
84
+ ...b: Array<FilePath>
85
+ ): ProjectPath {
86
+ return path.posix.join(a, ...b);
87
+ }
@@ -0,0 +1,359 @@
1
+ // @flow strict-local
2
+
3
+ import type SourceMap from '@parcel/source-map';
4
+ import type {Readable} from 'stream';
5
+ import type {FileSystem} from '@atlaspack/fs';
6
+
7
+ import type {
8
+ Asset as IAsset,
9
+ AST,
10
+ ASTGenerator,
11
+ Dependency as IDependency,
12
+ DependencyOptions,
13
+ Environment as IEnvironment,
14
+ EnvironmentOptions,
15
+ FileCreateInvalidation,
16
+ FilePath,
17
+ Meta,
18
+ MutableAsset as IMutableAsset,
19
+ Stats,
20
+ MutableAssetSymbols as IMutableAssetSymbols,
21
+ AssetSymbols as IAssetSymbols,
22
+ BundleBehavior,
23
+ } from '@atlaspack/types';
24
+ import type {Asset as AssetValue, AtlaspackOptions} from '../types';
25
+
26
+ import nullthrows from 'nullthrows';
27
+ import Environment from './Environment';
28
+ import {getPublicDependency} from './Dependency';
29
+ import {AssetSymbols, MutableAssetSymbols} from './Symbols';
30
+ import UncommittedAsset from '../UncommittedAsset';
31
+ import CommittedAsset from '../CommittedAsset';
32
+ import {createEnvironment} from '../Environment';
33
+ import {fromProjectPath, toProjectPath} from '../projectPath';
34
+ import {
35
+ BundleBehavior as BundleBehaviorMap,
36
+ BundleBehaviorNames,
37
+ } from '../types';
38
+ import {toInternalSourceLocation} from '../utils';
39
+
40
+ const inspect = Symbol.for('nodejs.util.inspect.custom');
41
+
42
+ const uncommittedAssetValueToAsset: WeakMap<AssetValue, Asset> = new WeakMap();
43
+ const committedAssetValueToAsset: WeakMap<AssetValue, Asset> = new WeakMap();
44
+ const assetValueToMutableAsset: WeakMap<AssetValue, MutableAsset> =
45
+ new WeakMap();
46
+
47
+ const _assetToAssetValue: WeakMap<
48
+ IAsset | IMutableAsset | BaseAsset,
49
+ AssetValue,
50
+ > = new WeakMap();
51
+
52
+ const _mutableAssetToUncommittedAsset: WeakMap<
53
+ IMutableAsset,
54
+ UncommittedAsset,
55
+ > = new WeakMap();
56
+
57
+ export function assetToAssetValue(asset: IAsset | IMutableAsset): AssetValue {
58
+ return nullthrows(_assetToAssetValue.get(asset));
59
+ }
60
+
61
+ export function mutableAssetToUncommittedAsset(
62
+ mutableAsset: IMutableAsset,
63
+ ): UncommittedAsset {
64
+ return nullthrows(_mutableAssetToUncommittedAsset.get(mutableAsset));
65
+ }
66
+
67
+ export function assetFromValue(
68
+ value: AssetValue,
69
+ options: AtlaspackOptions,
70
+ ): Asset {
71
+ return new Asset(
72
+ value.committed
73
+ ? new CommittedAsset(value, options)
74
+ : new UncommittedAsset({
75
+ value,
76
+ options,
77
+ }),
78
+ );
79
+ }
80
+
81
+ class BaseAsset {
82
+ #asset: CommittedAsset | UncommittedAsset;
83
+ #query /*: ?URLSearchParams */;
84
+
85
+ constructor(asset: CommittedAsset | UncommittedAsset) {
86
+ this.#asset = asset;
87
+ _assetToAssetValue.set(this, asset.value);
88
+ }
89
+
90
+ // $FlowFixMe[unsupported-syntax]
91
+ [inspect](): string {
92
+ return `Asset(${this.filePath})`;
93
+ }
94
+
95
+ get id(): string {
96
+ return this.#asset.value.id;
97
+ }
98
+
99
+ get type(): string {
100
+ return this.#asset.value.type;
101
+ }
102
+
103
+ get env(): IEnvironment {
104
+ return new Environment(this.#asset.value.env, this.#asset.options);
105
+ }
106
+
107
+ get fs(): FileSystem {
108
+ return this.#asset.options.inputFS;
109
+ }
110
+
111
+ get filePath(): FilePath {
112
+ return fromProjectPath(
113
+ this.#asset.options.projectRoot,
114
+ this.#asset.value.filePath,
115
+ );
116
+ }
117
+
118
+ get query(): URLSearchParams {
119
+ if (!this.#query) {
120
+ this.#query = new URLSearchParams(this.#asset.value.query ?? '');
121
+ }
122
+ return this.#query;
123
+ }
124
+
125
+ get meta(): Meta {
126
+ return this.#asset.value.meta;
127
+ }
128
+
129
+ get bundleBehavior(): ?BundleBehavior {
130
+ let bundleBehavior = this.#asset.value.bundleBehavior;
131
+ return bundleBehavior == null ? null : BundleBehaviorNames[bundleBehavior];
132
+ }
133
+
134
+ get isBundleSplittable(): boolean {
135
+ return this.#asset.value.isBundleSplittable;
136
+ }
137
+
138
+ get isSource(): boolean {
139
+ return this.#asset.value.isSource;
140
+ }
141
+
142
+ get sideEffects(): boolean {
143
+ return this.#asset.value.sideEffects;
144
+ }
145
+
146
+ get symbols(): IAssetSymbols {
147
+ return new AssetSymbols(this.#asset.options, this.#asset.value);
148
+ }
149
+
150
+ get uniqueKey(): ?string {
151
+ return this.#asset.value.uniqueKey;
152
+ }
153
+
154
+ get astGenerator(): ?ASTGenerator {
155
+ return this.#asset.value.astGenerator;
156
+ }
157
+
158
+ get pipeline(): ?string {
159
+ return this.#asset.value.pipeline;
160
+ }
161
+
162
+ getDependencies(): $ReadOnlyArray<IDependency> {
163
+ return this.#asset
164
+ .getDependencies()
165
+ .map(dep => getPublicDependency(dep, this.#asset.options));
166
+ }
167
+
168
+ getCode(): Promise<string> {
169
+ return this.#asset.getCode();
170
+ }
171
+
172
+ getBuffer(): Promise<Buffer> {
173
+ return this.#asset.getBuffer();
174
+ }
175
+
176
+ getStream(): Readable {
177
+ return this.#asset.getStream();
178
+ }
179
+
180
+ getMap(): Promise<?SourceMap> {
181
+ return this.#asset.getMap();
182
+ }
183
+
184
+ getAST(): Promise<?AST> {
185
+ return this.#asset.getAST();
186
+ }
187
+
188
+ getMapBuffer(): Promise<?Buffer> {
189
+ return this.#asset.getMapBuffer();
190
+ }
191
+ }
192
+
193
+ export class Asset extends BaseAsset implements IAsset {
194
+ #asset /*: CommittedAsset | UncommittedAsset */;
195
+ #env /*: ?Environment */;
196
+
197
+ constructor(asset: CommittedAsset | UncommittedAsset): Asset {
198
+ let assetValueToAsset = asset.value.committed
199
+ ? committedAssetValueToAsset
200
+ : uncommittedAssetValueToAsset;
201
+ let existing = assetValueToAsset.get(asset.value);
202
+ if (existing != null) {
203
+ return existing;
204
+ }
205
+
206
+ super(asset);
207
+ this.#asset = asset;
208
+ assetValueToAsset.set(asset.value, this);
209
+ return this;
210
+ }
211
+
212
+ get env(): IEnvironment {
213
+ this.#env ??= new Environment(this.#asset.value.env, this.#asset.options);
214
+ return this.#env;
215
+ }
216
+
217
+ get stats(): Stats {
218
+ return this.#asset.value.stats;
219
+ }
220
+ }
221
+
222
+ export class MutableAsset extends BaseAsset implements IMutableAsset {
223
+ #asset /*: UncommittedAsset */;
224
+
225
+ constructor(asset: UncommittedAsset): MutableAsset {
226
+ let existing = assetValueToMutableAsset.get(asset.value);
227
+ if (existing != null) {
228
+ return existing;
229
+ }
230
+
231
+ super(asset);
232
+ this.#asset = asset;
233
+ assetValueToMutableAsset.set(asset.value, this);
234
+ _mutableAssetToUncommittedAsset.set(this, asset);
235
+ return this;
236
+ }
237
+
238
+ setMap(map: ?SourceMap): void {
239
+ this.#asset.setMap(map);
240
+ }
241
+
242
+ get type(): string {
243
+ return this.#asset.value.type;
244
+ }
245
+
246
+ set type(type: string): void {
247
+ if (type !== this.#asset.value.type) {
248
+ this.#asset.value.type = type;
249
+ this.#asset.updateId();
250
+ }
251
+ }
252
+
253
+ get bundleBehavior(): ?BundleBehavior {
254
+ let bundleBehavior = this.#asset.value.bundleBehavior;
255
+ return bundleBehavior == null ? null : BundleBehaviorNames[bundleBehavior];
256
+ }
257
+
258
+ set bundleBehavior(bundleBehavior: ?BundleBehavior): void {
259
+ this.#asset.value.bundleBehavior = bundleBehavior
260
+ ? BundleBehaviorMap[bundleBehavior]
261
+ : null;
262
+ }
263
+
264
+ get isBundleSplittable(): boolean {
265
+ return this.#asset.value.isBundleSplittable;
266
+ }
267
+
268
+ set isBundleSplittable(isBundleSplittable: boolean): void {
269
+ this.#asset.value.isBundleSplittable = isBundleSplittable;
270
+ }
271
+
272
+ get sideEffects(): boolean {
273
+ return this.#asset.value.sideEffects;
274
+ }
275
+
276
+ set sideEffects(sideEffects: boolean): void {
277
+ this.#asset.value.sideEffects = sideEffects;
278
+ }
279
+
280
+ get uniqueKey(): ?string {
281
+ return this.#asset.value.uniqueKey;
282
+ }
283
+
284
+ set uniqueKey(uniqueKey: ?string): void {
285
+ if (this.#asset.value.uniqueKey != null) {
286
+ throw new Error(
287
+ "Cannot change an asset's uniqueKey after it has been set.",
288
+ );
289
+ }
290
+ this.#asset.value.uniqueKey = uniqueKey;
291
+ }
292
+
293
+ get symbols(): IMutableAssetSymbols {
294
+ return new MutableAssetSymbols(this.#asset.options, this.#asset.value);
295
+ }
296
+
297
+ addDependency(dep: DependencyOptions): string {
298
+ return this.#asset.addDependency(dep);
299
+ }
300
+
301
+ invalidateOnFileChange(filePath: FilePath): void {
302
+ this.#asset.invalidateOnFileChange(
303
+ toProjectPath(this.#asset.options.projectRoot, filePath),
304
+ );
305
+ }
306
+
307
+ invalidateOnFileCreate(invalidation: FileCreateInvalidation): void {
308
+ this.#asset.invalidateOnFileCreate(invalidation);
309
+ }
310
+
311
+ invalidateOnEnvChange(env: string): void {
312
+ this.#asset.invalidateOnEnvChange(env);
313
+ }
314
+
315
+ invalidateOnStartup(): void {
316
+ this.#asset.invalidateOnStartup();
317
+ }
318
+
319
+ invalidateOnBuild(): void {
320
+ this.#asset.invalidateOnBuild();
321
+ }
322
+
323
+ isASTDirty(): boolean {
324
+ return this.#asset.isASTDirty;
325
+ }
326
+
327
+ setBuffer(buffer: Buffer): void {
328
+ this.#asset.setBuffer(buffer);
329
+ }
330
+
331
+ setCode(code: string): void {
332
+ this.#asset.setCode(code);
333
+ }
334
+
335
+ setStream(stream: Readable): void {
336
+ this.#asset.setStream(stream);
337
+ }
338
+
339
+ setAST(ast: AST): void {
340
+ return this.#asset.setAST(ast);
341
+ }
342
+
343
+ addURLDependency(url: string, opts: $Shape<DependencyOptions>): string {
344
+ return this.addDependency({
345
+ specifier: url,
346
+ specifierType: 'url',
347
+ priority: 'lazy',
348
+ ...opts,
349
+ });
350
+ }
351
+
352
+ setEnvironment(env: EnvironmentOptions): void {
353
+ this.#asset.value.env = createEnvironment({
354
+ ...env,
355
+ loc: toInternalSourceLocation(this.#asset.options.projectRoot, env.loc),
356
+ });
357
+ this.#asset.updateId();
358
+ }
359
+ }