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