@atlaspack/core 2.13.2-dev.3689 → 2.14.0

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 (85) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/package.json +20 -20
  3. package/src/Atlaspack.js +3 -2
  4. package/src/atlaspack-v3/AtlaspackV3.js +25 -9
  5. package/src/requests/WriteBundlesRequest.js +31 -22
  6. package/LICENSE +0 -201
  7. package/lib/AssetGraph.js +0 -521
  8. package/lib/Atlaspack.js +0 -676
  9. package/lib/AtlaspackConfig.js +0 -298
  10. package/lib/AtlaspackConfig.schema.js +0 -103
  11. package/lib/BundleGraph.js +0 -1527
  12. package/lib/CommittedAsset.js +0 -155
  13. package/lib/Dependency.js +0 -136
  14. package/lib/Environment.js +0 -144
  15. package/lib/IdentifierRegistry.js +0 -36
  16. package/lib/InternalConfig.js +0 -56
  17. package/lib/PackagerRunner.js +0 -525
  18. package/lib/ReporterRunner.js +0 -151
  19. package/lib/RequestTracker.js +0 -1178
  20. package/lib/SymbolPropagation.js +0 -618
  21. package/lib/TargetDescriptor.schema.js +0 -118
  22. package/lib/Transformation.js +0 -522
  23. package/lib/UncommittedAsset.js +0 -348
  24. package/lib/Validation.js +0 -203
  25. package/lib/applyRuntimes.js +0 -355
  26. package/lib/assetUtils.js +0 -205
  27. package/lib/atlaspack-v3/AtlaspackV3.js +0 -57
  28. package/lib/atlaspack-v3/NapiWorkerPool.js +0 -71
  29. package/lib/atlaspack-v3/fs.js +0 -39
  30. package/lib/atlaspack-v3/index.js +0 -26
  31. package/lib/atlaspack-v3/jsCallable.js +0 -20
  32. package/lib/atlaspack-v3/worker/compat/asset-symbols.js +0 -197
  33. package/lib/atlaspack-v3/worker/compat/bitflags.js +0 -84
  34. package/lib/atlaspack-v3/worker/compat/dependency.js +0 -44
  35. package/lib/atlaspack-v3/worker/compat/environment.js +0 -57
  36. package/lib/atlaspack-v3/worker/compat/index.js +0 -104
  37. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +0 -164
  38. package/lib/atlaspack-v3/worker/compat/plugin-config.js +0 -78
  39. package/lib/atlaspack-v3/worker/compat/plugin-logger.js +0 -29
  40. package/lib/atlaspack-v3/worker/compat/plugin-options.js +0 -113
  41. package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +0 -12
  42. package/lib/atlaspack-v3/worker/compat/target.js +0 -17
  43. package/lib/atlaspack-v3/worker/index.js +0 -3
  44. package/lib/atlaspack-v3/worker/worker.js +0 -280
  45. package/lib/constants.js +0 -21
  46. package/lib/dumpGraphToGraphViz.js +0 -206
  47. package/lib/index.js +0 -70
  48. package/lib/loadAtlaspackPlugin.js +0 -115
  49. package/lib/loadDotEnv.js +0 -54
  50. package/lib/projectPath.js +0 -112
  51. package/lib/public/Asset.js +0 -259
  52. package/lib/public/Bundle.js +0 -236
  53. package/lib/public/BundleGraph.js +0 -279
  54. package/lib/public/BundleGroup.js +0 -50
  55. package/lib/public/Config.js +0 -202
  56. package/lib/public/Dependency.js +0 -131
  57. package/lib/public/Environment.js +0 -247
  58. package/lib/public/MutableBundleGraph.js +0 -204
  59. package/lib/public/PluginOptions.js +0 -71
  60. package/lib/public/Symbols.js +0 -247
  61. package/lib/public/Target.js +0 -64
  62. package/lib/registerCoreWithSerializer.js +0 -51
  63. package/lib/requests/AssetGraphRequest.js +0 -432
  64. package/lib/requests/AssetGraphRequestRust.js +0 -220
  65. package/lib/requests/AssetRequest.js +0 -132
  66. package/lib/requests/AtlaspackBuildRequest.js +0 -79
  67. package/lib/requests/AtlaspackConfigRequest.js +0 -479
  68. package/lib/requests/BundleGraphRequest.js +0 -485
  69. package/lib/requests/ConfigRequest.js +0 -203
  70. package/lib/requests/DevDepRequest.js +0 -193
  71. package/lib/requests/EntryRequest.js +0 -295
  72. package/lib/requests/PackageRequest.js +0 -88
  73. package/lib/requests/PathRequest.js +0 -357
  74. package/lib/requests/TargetRequest.js +0 -1179
  75. package/lib/requests/ValidationRequest.js +0 -66
  76. package/lib/requests/WriteBundleRequest.js +0 -252
  77. package/lib/requests/WriteBundlesRequest.js +0 -153
  78. package/lib/requests/asset-graph-diff.js +0 -128
  79. package/lib/requests/asset-graph-dot.js +0 -131
  80. package/lib/resolveOptions.js +0 -265
  81. package/lib/serializerCore.browser.js +0 -29
  82. package/lib/summarizeRequest.js +0 -55
  83. package/lib/types.js +0 -35
  84. package/lib/utils.js +0 -160
  85. package/lib/worker.js +0 -184
@@ -1,118 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.PACKAGE_DESCRIPTOR_SCHEMA = exports.ENGINES_SCHEMA = exports.DESCRIPTOR_SCHEMA = exports.COMMON_TARGET_DESCRIPTOR_SCHEMA = void 0;
7
- const ENGINES_SCHEMA = exports.ENGINES_SCHEMA = {
8
- type: 'object',
9
- properties: {
10
- browsers: {
11
- oneOf: [{
12
- type: 'array',
13
- items: {
14
- type: 'string'
15
- }
16
- }, {
17
- type: 'string'
18
- }]
19
- }
20
- },
21
- __forbiddenProperties: ['browser'],
22
- additionalProperties: {
23
- type: 'string'
24
- }
25
- };
26
- const PACKAGE_DESCRIPTOR_SCHEMA = exports.PACKAGE_DESCRIPTOR_SCHEMA = {
27
- type: 'object',
28
- properties: {
29
- context: {
30
- type: 'string',
31
- enum: ['node', 'browser', 'web-worker', 'electron-main', 'electron-renderer', 'service-worker']
32
- },
33
- includeNodeModules: {
34
- oneOf: [{
35
- type: 'boolean'
36
- }, {
37
- type: 'array',
38
- items: {
39
- type: 'string',
40
- __type: 'a wildcard or filepath'
41
- }
42
- }, {
43
- type: 'object',
44
- properties: {},
45
- additionalProperties: {
46
- type: 'boolean'
47
- }
48
- }]
49
- },
50
- outputFormat: {
51
- type: 'string',
52
- enum: ['global', 'esmodule', 'commonjs']
53
- },
54
- distDir: {
55
- type: 'string'
56
- },
57
- publicUrl: {
58
- type: 'string'
59
- },
60
- isLibrary: {
61
- type: 'boolean'
62
- },
63
- source: {
64
- oneOf: [{
65
- type: 'string'
66
- }, {
67
- type: 'array',
68
- items: {
69
- type: 'string'
70
- }
71
- }]
72
- },
73
- sourceMap: {
74
- oneOf: [{
75
- type: 'boolean'
76
- }, {
77
- type: 'object',
78
- properties: {
79
- inlineSources: {
80
- type: 'boolean'
81
- },
82
- sourceRoot: {
83
- type: 'string'
84
- },
85
- inline: {
86
- type: 'boolean'
87
- }
88
- },
89
- additionalProperties: false
90
- }]
91
- },
92
- engines: ENGINES_SCHEMA,
93
- optimize: {
94
- type: 'boolean'
95
- },
96
- scopeHoist: {
97
- type: 'boolean'
98
- },
99
- __unstable_singleFileOutput: {
100
- type: 'boolean'
101
- }
102
- },
103
- additionalProperties: false
104
- };
105
- const DESCRIPTOR_SCHEMA = exports.DESCRIPTOR_SCHEMA = {
106
- ...PACKAGE_DESCRIPTOR_SCHEMA,
107
- properties: {
108
- ...PACKAGE_DESCRIPTOR_SCHEMA.properties,
109
- distEntry: {
110
- type: 'string'
111
- }
112
- }
113
- };
114
- const COMMON_TARGET_DESCRIPTOR_SCHEMA = exports.COMMON_TARGET_DESCRIPTOR_SCHEMA = {
115
- oneOf: [PACKAGE_DESCRIPTOR_SCHEMA, {
116
- enum: [false]
117
- }]
118
- };
@@ -1,522 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- function _path() {
8
- const data = _interopRequireDefault(require("path"));
9
- _path = function () {
10
- return data;
11
- };
12
- return data;
13
- }
14
- function _stream() {
15
- const data = require("stream");
16
- _stream = function () {
17
- return data;
18
- };
19
- return data;
20
- }
21
- function _nullthrows() {
22
- const data = _interopRequireDefault(require("nullthrows"));
23
- _nullthrows = function () {
24
- return data;
25
- };
26
- return data;
27
- }
28
- function _logger() {
29
- const data = _interopRequireWildcard(require("@atlaspack/logger"));
30
- _logger = function () {
31
- return data;
32
- };
33
- return data;
34
- }
35
- function _diagnostic() {
36
- const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
37
- _diagnostic = function () {
38
- return data;
39
- };
40
- return data;
41
- }
42
- function _utils() {
43
- const data = require("@atlaspack/utils");
44
- _utils = function () {
45
- return data;
46
- };
47
- return data;
48
- }
49
- var _Dependency = require("./Dependency");
50
- var _AtlaspackConfig = require("./AtlaspackConfig");
51
- var _PathRequest = require("./requests/PathRequest");
52
- var _Asset = require("./public/Asset");
53
- var _UncommittedAsset = _interopRequireDefault(require("./UncommittedAsset"));
54
- var _assetUtils = require("./assetUtils");
55
- var _summarizeRequest = _interopRequireDefault(require("./summarizeRequest"));
56
- var _PluginOptions = _interopRequireDefault(require("./public/PluginOptions"));
57
- var _utils2 = require("./utils");
58
- var _InternalConfig = require("./InternalConfig");
59
- var _ConfigRequest = require("./requests/ConfigRequest");
60
- var _DevDepRequest = require("./requests/DevDepRequest");
61
- var _projectPath = require("./projectPath");
62
- function _assert() {
63
- const data = _interopRequireDefault(require("assert"));
64
- _assert = function () {
65
- return data;
66
- };
67
- return data;
68
- }
69
- function _profiler() {
70
- const data = require("@atlaspack/profiler");
71
- _profiler = function () {
72
- return data;
73
- };
74
- return data;
75
- }
76
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
77
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
78
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
79
- // TODO: eventually call path request as sub requests
80
- class Transformation {
81
- constructor({
82
- request,
83
- options,
84
- config,
85
- workerApi
86
- }) {
87
- this.configs = new Map();
88
- this.atlaspackConfig = config;
89
- this.options = options;
90
- this.request = request;
91
- this.workerApi = workerApi;
92
- this.invalidations = (0, _utils2.createInvalidations)();
93
- this.devDepRequests = new Map();
94
- this.pluginDevDeps = [];
95
- this.resolverRunner = new _PathRequest.ResolverRunner({
96
- config,
97
- options,
98
- previousDevDeps: request.devDeps
99
- });
100
- this.pluginOptions = new _PluginOptions.default((0, _utils2.optionsProxy)(this.options, option => {
101
- this.invalidations.invalidateOnOptionChange.add(option);
102
- }, devDep => {
103
- this.pluginDevDeps.push(devDep);
104
- }));
105
- }
106
- async run() {
107
- let asset = await this.loadAsset();
108
- let existing;
109
- if (!asset.mapBuffer && _utils().SOURCEMAP_EXTENSIONS.has(asset.value.type)) {
110
- // Load existing sourcemaps, this automatically runs the source contents extraction
111
- try {
112
- existing = await asset.loadExistingSourcemap();
113
- } catch (err) {
114
- _logger().default.verbose([{
115
- origin: '@atlaspack/core',
116
- message: (0, _diagnostic().md)`Could not load existing source map for ${(0, _projectPath.fromProjectPathRelative)(asset.value.filePath)}`
117
- }, {
118
- origin: '@atlaspack/core',
119
- message: (0, _diagnostic().escapeMarkdown)(err.message)
120
- }]);
121
- }
122
- }
123
- if (existing == null &&
124
- // Don't buffer an entire stream into memory since it may not need sourceContent,
125
- // e.g. large binary files
126
- !(asset.content instanceof _stream().Readable)) {
127
- // If no existing sourcemap was found, initialize asset.sourceContent
128
- // with the original contents. This will be used when the transformer
129
- // calls setMap to ensure the source content is in the sourcemap.
130
- asset.sourceContent = await asset.getCode();
131
- }
132
- (0, _DevDepRequest.invalidateDevDeps)(this.request.invalidDevDeps, this.options, this.atlaspackConfig);
133
- let pipeline = await this.loadPipeline(this.request.filePath, asset.value.isSource, asset.value.pipeline);
134
- let assets, error;
135
- try {
136
- let results = await this.runPipelines(pipeline, asset);
137
- await Promise.all(results.map(asset => asset.commit()));
138
- assets = results.map(a => a.value);
139
- } catch (e) {
140
- error = e;
141
- }
142
- let configRequests = (0, _ConfigRequest.getConfigRequests)([...this.configs.values(), ...this.resolverRunner.configs.values()]);
143
- let devDepRequests = (0, _DevDepRequest.getWorkerDevDepRequests)([...this.devDepRequests.values(), ...this.resolverRunner.devDepRequests.values()]);
144
-
145
- // $FlowFixMe because of $$raw
146
- return {
147
- $$raw: true,
148
- assets,
149
- configRequests,
150
- // When throwing an error, this (de)serialization is done automatically by the WorkerFarm
151
- error: error ? (0, _diagnostic().anyToDiagnostic)(error) : undefined,
152
- invalidations: this.invalidations,
153
- devDepRequests
154
- };
155
- }
156
- async loadAsset() {
157
- let {
158
- filePath,
159
- env,
160
- code,
161
- pipeline,
162
- isSource: isSourceOverride,
163
- sideEffects,
164
- query
165
- } = this.request;
166
- let {
167
- content,
168
- size,
169
- isSource: summarizedIsSource
170
- } = await (0, _summarizeRequest.default)(this.options.inputFS, {
171
- filePath: (0, _projectPath.fromProjectPath)(this.options.projectRoot, filePath),
172
- code
173
- });
174
-
175
- // Prefer `isSource` originating from the AssetRequest.
176
-
177
- return new _UncommittedAsset.default({
178
- value: (0, _assetUtils.createAsset)(this.options.projectRoot, {
179
- code,
180
- filePath,
181
- isSource: isSourceOverride ?? summarizedIsSource,
182
- type: _path().default.extname((0, _projectPath.fromProjectPathRelative)(filePath)).slice(1),
183
- pipeline,
184
- env,
185
- query,
186
- stats: {
187
- time: 0,
188
- size
189
- },
190
- sideEffects
191
- }),
192
- options: this.options,
193
- content,
194
- invalidations: this.invalidations
195
- });
196
- }
197
- async runPipelines(pipeline, initialAsset) {
198
- let initialType = initialAsset.value.type;
199
- let assets;
200
- try {
201
- assets = await this.runPipeline(pipeline, initialAsset);
202
- } finally {
203
- // Add dev dep requests for each transformer
204
- for (let transformer of pipeline.transformers) {
205
- await this.addDevDependency({
206
- specifier: transformer.name,
207
- resolveFrom: transformer.resolveFrom,
208
- range: transformer.range
209
- });
210
- }
211
-
212
- // Add dev dep requests for dependencies of transformer plugins
213
- // (via proxied packageManager.require calls).
214
- for (let devDep of this.pluginDevDeps) {
215
- await this.addDevDependency(devDep);
216
- }
217
- }
218
- let finalAssets = [];
219
- for (let asset of assets) {
220
- let nextPipeline;
221
- if (asset.value.type !== initialType) {
222
- nextPipeline = await this.loadNextPipeline({
223
- filePath: initialAsset.value.filePath,
224
- isSource: asset.value.isSource,
225
- newType: asset.value.type,
226
- newPipeline: asset.value.pipeline,
227
- currentPipeline: pipeline
228
- });
229
- }
230
- if (nextPipeline) {
231
- let nextPipelineAssets = await this.runPipelines(nextPipeline, asset);
232
- finalAssets = finalAssets.concat(nextPipelineAssets);
233
- } else {
234
- finalAssets.push(asset);
235
- }
236
- }
237
- if (!pipeline.postProcess) {
238
- return finalAssets;
239
- }
240
- (0, _assert().default)(pipeline.postProcess != null);
241
- let processedFinalAssets = (await pipeline.postProcess(finalAssets)) ?? [];
242
- return processedFinalAssets;
243
- }
244
- async addDevDependency(opts) {
245
- let {
246
- specifier,
247
- resolveFrom,
248
- range
249
- } = opts;
250
- let key = `${specifier}:${(0, _projectPath.fromProjectPathRelative)(resolveFrom)}`;
251
- if (this.devDepRequests.has(key)) {
252
- return;
253
- }
254
-
255
- // Ensure that the package manager has an entry for this resolution.
256
- try {
257
- await this.options.packageManager.resolve(specifier, (0, _projectPath.fromProjectPath)(this.options.projectRoot, opts.resolveFrom), {
258
- range
259
- });
260
- } catch (err) {
261
- // ignore
262
- }
263
- let devDepRequest = await (0, _DevDepRequest.createDevDependency)(opts, this.request.devDeps, this.options);
264
- this.devDepRequests.set(key, devDepRequest);
265
- }
266
- async runPipeline(pipeline, initialAsset) {
267
- if (pipeline.transformers.length === 0) {
268
- return [initialAsset];
269
- }
270
- let initialType = initialAsset.value.type;
271
- let inputAssets = [initialAsset];
272
- let resultingAssets = [];
273
- let finalAssets = [];
274
- for (let transformer of pipeline.transformers) {
275
- resultingAssets = [];
276
- for (let asset of inputAssets) {
277
- if (asset.value.type !== initialType && (await this.loadNextPipeline({
278
- filePath: initialAsset.value.filePath,
279
- isSource: asset.value.isSource,
280
- newType: asset.value.type,
281
- newPipeline: asset.value.pipeline,
282
- currentPipeline: pipeline
283
- }))) {
284
- finalAssets.push(asset);
285
- continue;
286
- }
287
- try {
288
- const measurement = _profiler().tracer.createMeasurement(transformer.name, 'transform', (0, _projectPath.fromProjectPathRelative)(initialAsset.value.filePath));
289
- let transformerResults = await this.runTransformer(pipeline, asset, transformer.plugin, transformer.name, transformer.config, transformer.configKeyPath, this.atlaspackConfig);
290
- measurement && measurement.end();
291
- for (let result of transformerResults) {
292
- if (result instanceof _UncommittedAsset.default) {
293
- resultingAssets.push(result);
294
- continue;
295
- }
296
- resultingAssets.push(asset.createChildAsset(result, transformer.name, this.atlaspackConfig.filePath, transformer.configKeyPath));
297
- }
298
- } catch (e) {
299
- let diagnostic = (0, _diagnostic().errorToDiagnostic)(e, {
300
- origin: transformer.name,
301
- filePath: (0, _projectPath.fromProjectPath)(this.options.projectRoot, asset.value.filePath)
302
- });
303
-
304
- // If this request is a virtual asset that might not exist on the filesystem,
305
- // add the `code` property to each code frame in the diagnostics that match the
306
- // request's filepath. This can't be done by the transformer because it might not
307
- // have access to the original code (e.g. an inline script tag in HTML).
308
- if (this.request.code != null) {
309
- for (let d of diagnostic) {
310
- if (d.codeFrames) {
311
- for (let codeFrame of d.codeFrames) {
312
- if (codeFrame.code == null && codeFrame.filePath === this.request.filePath) {
313
- codeFrame.code = this.request.code;
314
- }
315
- }
316
- }
317
- }
318
- }
319
- throw new (_diagnostic().default)({
320
- diagnostic
321
- });
322
- }
323
- }
324
- inputAssets = resultingAssets;
325
- }
326
-
327
- // Make assets with ASTs generate unless they are CSS modules. This parallelizes generation
328
- // and distributes work more evenly across workers than if one worker needed to
329
- // generate all assets in a large bundle during packaging.
330
- await Promise.all(resultingAssets.filter(asset => asset.ast != null && !(this.options.mode === 'production' && asset.value.type === 'css' && asset.value.symbols)).map(async asset => {
331
- if (asset.isASTDirty && asset.generate) {
332
- var _output$map;
333
- let output = await asset.generate();
334
- asset.content = output.content;
335
- asset.mapBuffer = (_output$map = output.map) === null || _output$map === void 0 ? void 0 : _output$map.toBuffer();
336
- }
337
- asset.clearAST();
338
- }));
339
- return finalAssets.concat(resultingAssets);
340
- }
341
- async loadPipeline(filePath, isSource, pipeline) {
342
- let transformers = await this.atlaspackConfig.getTransformers(filePath, pipeline, this.request.isURL);
343
- for (let transformer of transformers) {
344
- let config = await this.loadTransformerConfig(transformer, isSource);
345
- if (config) {
346
- this.configs.set(transformer.name, config);
347
- }
348
- }
349
- return {
350
- id: transformers.map(t => t.name).join(':'),
351
- transformers: transformers.map(transformer => {
352
- var _this$configs$get;
353
- return {
354
- name: transformer.name,
355
- resolveFrom: transformer.resolveFrom,
356
- config: (_this$configs$get = this.configs.get(transformer.name)) === null || _this$configs$get === void 0 ? void 0 : _this$configs$get.result,
357
- configKeyPath: transformer.keyPath,
358
- plugin: transformer.plugin
359
- };
360
- }),
361
- options: this.options,
362
- pluginOptions: this.pluginOptions,
363
- workerApi: this.workerApi
364
- };
365
- }
366
- async loadNextPipeline({
367
- filePath,
368
- isSource,
369
- newType,
370
- newPipeline,
371
- currentPipeline
372
- }) {
373
- let filePathRelative = (0, _projectPath.fromProjectPathRelative)(filePath);
374
- let nextFilePath = (0, _projectPath.toProjectPathUnsafe)(filePathRelative.slice(0, -_path().default.extname(filePathRelative).length) + '.' + newType);
375
- let nextPipeline = await this.loadPipeline(nextFilePath, isSource, newPipeline);
376
- if (nextPipeline.id === currentPipeline.id) {
377
- return null;
378
- }
379
- return nextPipeline;
380
- }
381
- async loadTransformerConfig(transformer, isSource) {
382
- let loadConfig = transformer.plugin.loadConfig;
383
- if (!loadConfig) {
384
- return;
385
- }
386
- let config = (0, _InternalConfig.createConfig)({
387
- plugin: transformer.name,
388
- isSource,
389
- searchPath: this.request.filePath,
390
- env: this.request.env
391
- });
392
- await (0, _ConfigRequest.loadPluginConfig)(transformer, config, this.options);
393
- for (let devDep of config.devDeps) {
394
- await this.addDevDependency(devDep);
395
- }
396
- return config;
397
- }
398
- async runTransformer(pipeline, asset, transformer, transformerName, preloadedConfig, configKeyPath, atlaspackConfig) {
399
- var _transformer$parse;
400
- const logger = new (_logger().PluginLogger)({
401
- origin: transformerName
402
- });
403
- const tracer = new (_profiler().PluginTracer)({
404
- origin: transformerName,
405
- category: 'transform'
406
- });
407
- const resolve = async (from, to, options) => {
408
- let result = await this.resolverRunner.resolve((0, _Dependency.createDependency)(this.options.projectRoot, {
409
- env: asset.value.env,
410
- specifier: to,
411
- specifierType: (options === null || options === void 0 ? void 0 : options.specifierType) || 'esm',
412
- packageConditions: options === null || options === void 0 ? void 0 : options.packageConditions,
413
- sourcePath: from
414
- }));
415
- if (result.invalidateOnFileCreate) {
416
- this.invalidations.invalidateOnFileCreate.push(...result.invalidateOnFileCreate.map(i => (0, _utils2.invalidateOnFileCreateToInternal)(this.options.projectRoot, i)));
417
- }
418
- if (result.invalidateOnFileChange) {
419
- for (let filePath of result.invalidateOnFileChange) {
420
- this.invalidations.invalidateOnFileChange.add((0, _projectPath.toProjectPath)(this.options.projectRoot, filePath));
421
- }
422
- }
423
- if (result.diagnostics && result.diagnostics.length > 0) {
424
- throw new (_diagnostic().default)({
425
- diagnostic: result.diagnostics
426
- });
427
- }
428
- return (0, _projectPath.fromProjectPath)(this.options.projectRoot, (0, _nullthrows().default)(result.assetGroup).filePath);
429
- };
430
-
431
- // If an ast exists on the asset, but we cannot reuse it,
432
- // use the previous transform to generate code that we can re-parse.
433
- if (asset.ast && asset.isASTDirty && (!transformer.canReuseAST || !transformer.canReuseAST({
434
- ast: asset.ast,
435
- options: pipeline.pluginOptions,
436
- logger,
437
- tracer
438
- })) && asset.generate) {
439
- var _output$map2;
440
- let output = await asset.generate();
441
- asset.content = output.content;
442
- asset.mapBuffer = (_output$map2 = output.map) === null || _output$map2 === void 0 ? void 0 : _output$map2.toBuffer();
443
- }
444
-
445
- // Load config for the transformer.
446
- let config = preloadedConfig;
447
-
448
- // Parse if there is no AST available from a previous transform.
449
- let parse = (_transformer$parse = transformer.parse) === null || _transformer$parse === void 0 ? void 0 : _transformer$parse.bind(transformer);
450
- if (!asset.ast && parse) {
451
- let ast = await parse({
452
- asset: new _Asset.Asset(asset),
453
- config,
454
- options: pipeline.pluginOptions,
455
- resolve,
456
- logger,
457
- tracer
458
- });
459
- if (ast) {
460
- asset.setAST(ast);
461
- asset.isASTDirty = false;
462
- }
463
- }
464
-
465
- // Transform.
466
- let transfomerResult =
467
- // $FlowFixMe the returned IMutableAsset really is a MutableAsset
468
- await transformer.transform({
469
- asset: new _Asset.MutableAsset(asset),
470
- config,
471
- options: pipeline.pluginOptions,
472
- resolve,
473
- logger,
474
- tracer
475
- });
476
- let results = await normalizeAssets(this.options, transfomerResult);
477
-
478
- // Create generate and postProcess function that can be called later
479
- asset.generate = () => {
480
- let publicAsset = new _Asset.Asset(asset);
481
- if (transformer.generate && asset.ast) {
482
- let generated = transformer.generate({
483
- asset: publicAsset,
484
- ast: asset.ast,
485
- options: pipeline.pluginOptions,
486
- logger,
487
- tracer
488
- });
489
- asset.clearAST();
490
- return Promise.resolve(generated);
491
- }
492
- throw new Error('Asset has an AST but no generate method is available on the transform');
493
- };
494
- let postProcess = transformer.postProcess;
495
- if (postProcess) {
496
- pipeline.postProcess = async assets => {
497
- let results = await postProcess.call(transformer, {
498
- assets: assets.map(asset => new _Asset.MutableAsset(asset)),
499
- config,
500
- options: pipeline.pluginOptions,
501
- resolve,
502
- logger,
503
- tracer
504
- });
505
- return Promise.all(results.map(result => asset.createChildAsset(result, transformerName, atlaspackConfig.filePath
506
- // configKeyPath,
507
- )));
508
- };
509
- }
510
-
511
- return results;
512
- }
513
- }
514
- exports.default = Transformation;
515
- function normalizeAssets(options, results) {
516
- return results.map(result => {
517
- if (result instanceof _Asset.MutableAsset) {
518
- return (0, _Asset.mutableAssetToUncommittedAsset)(result);
519
- }
520
- return result;
521
- });
522
- }