@atlaspack/core 2.14.0 → 2.14.1-canary.6

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 (81) hide show
  1. package/LICENSE +201 -0
  2. package/lib/AssetGraph.js +521 -0
  3. package/lib/Atlaspack.js +677 -0
  4. package/lib/AtlaspackConfig.js +298 -0
  5. package/lib/AtlaspackConfig.schema.js +103 -0
  6. package/lib/BundleGraph.js +1527 -0
  7. package/lib/CommittedAsset.js +155 -0
  8. package/lib/Dependency.js +136 -0
  9. package/lib/Environment.js +144 -0
  10. package/lib/IdentifierRegistry.js +36 -0
  11. package/lib/InternalConfig.js +56 -0
  12. package/lib/PackagerRunner.js +525 -0
  13. package/lib/ReporterRunner.js +151 -0
  14. package/lib/RequestTracker.js +1178 -0
  15. package/lib/SymbolPropagation.js +618 -0
  16. package/lib/TargetDescriptor.schema.js +118 -0
  17. package/lib/Transformation.js +522 -0
  18. package/lib/UncommittedAsset.js +348 -0
  19. package/lib/Validation.js +203 -0
  20. package/lib/applyRuntimes.js +355 -0
  21. package/lib/assetUtils.js +205 -0
  22. package/lib/atlaspack-v3/AtlaspackV3.js +66 -0
  23. package/lib/atlaspack-v3/NapiWorkerPool.js +71 -0
  24. package/lib/atlaspack-v3/fs.js +39 -0
  25. package/lib/atlaspack-v3/index.js +26 -0
  26. package/lib/atlaspack-v3/jsCallable.js +20 -0
  27. package/lib/atlaspack-v3/worker/compat/asset-symbols.js +197 -0
  28. package/lib/atlaspack-v3/worker/compat/bitflags.js +84 -0
  29. package/lib/atlaspack-v3/worker/compat/dependency.js +44 -0
  30. package/lib/atlaspack-v3/worker/compat/environment.js +57 -0
  31. package/lib/atlaspack-v3/worker/compat/index.js +104 -0
  32. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +164 -0
  33. package/lib/atlaspack-v3/worker/compat/plugin-config.js +78 -0
  34. package/lib/atlaspack-v3/worker/compat/plugin-logger.js +29 -0
  35. package/lib/atlaspack-v3/worker/compat/plugin-options.js +113 -0
  36. package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +12 -0
  37. package/lib/atlaspack-v3/worker/compat/target.js +17 -0
  38. package/lib/atlaspack-v3/worker/index.js +3 -0
  39. package/lib/atlaspack-v3/worker/worker.js +280 -0
  40. package/lib/constants.js +21 -0
  41. package/lib/dumpGraphToGraphViz.js +206 -0
  42. package/lib/index.js +70 -0
  43. package/lib/loadAtlaspackPlugin.js +115 -0
  44. package/lib/loadDotEnv.js +54 -0
  45. package/lib/projectPath.js +112 -0
  46. package/lib/public/Asset.js +259 -0
  47. package/lib/public/Bundle.js +236 -0
  48. package/lib/public/BundleGraph.js +279 -0
  49. package/lib/public/BundleGroup.js +50 -0
  50. package/lib/public/Config.js +202 -0
  51. package/lib/public/Dependency.js +131 -0
  52. package/lib/public/Environment.js +247 -0
  53. package/lib/public/MutableBundleGraph.js +204 -0
  54. package/lib/public/PluginOptions.js +71 -0
  55. package/lib/public/Symbols.js +247 -0
  56. package/lib/public/Target.js +64 -0
  57. package/lib/registerCoreWithSerializer.js +51 -0
  58. package/lib/requests/AssetGraphRequest.js +432 -0
  59. package/lib/requests/AssetGraphRequestRust.js +220 -0
  60. package/lib/requests/AssetRequest.js +132 -0
  61. package/lib/requests/AtlaspackBuildRequest.js +79 -0
  62. package/lib/requests/AtlaspackConfigRequest.js +479 -0
  63. package/lib/requests/BundleGraphRequest.js +485 -0
  64. package/lib/requests/ConfigRequest.js +203 -0
  65. package/lib/requests/DevDepRequest.js +193 -0
  66. package/lib/requests/EntryRequest.js +295 -0
  67. package/lib/requests/PackageRequest.js +88 -0
  68. package/lib/requests/PathRequest.js +357 -0
  69. package/lib/requests/TargetRequest.js +1179 -0
  70. package/lib/requests/ValidationRequest.js +66 -0
  71. package/lib/requests/WriteBundleRequest.js +252 -0
  72. package/lib/requests/WriteBundlesRequest.js +167 -0
  73. package/lib/requests/asset-graph-diff.js +128 -0
  74. package/lib/requests/asset-graph-dot.js +131 -0
  75. package/lib/resolveOptions.js +265 -0
  76. package/lib/serializerCore.browser.js +29 -0
  77. package/lib/summarizeRequest.js +55 -0
  78. package/lib/types.js +35 -0
  79. package/lib/utils.js +160 -0
  80. package/lib/worker.js +184 -0
  81. package/package.json +20 -19
@@ -0,0 +1,298 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AtlaspackConfig = void 0;
7
+ function _diagnostic() {
8
+ const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
9
+ _diagnostic = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _json() {
15
+ const data = _interopRequireDefault(require("json5"));
16
+ _json = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _utils() {
22
+ const data = require("@atlaspack/utils");
23
+ _utils = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _path() {
29
+ const data = require("path");
30
+ _path = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ var _loadAtlaspackPlugin = _interopRequireDefault(require("./loadAtlaspackPlugin"));
36
+ var _projectPath = require("./projectPath");
37
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
+ 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); }
39
+ 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; }
40
+ class AtlaspackConfig {
41
+ constructor(config, options) {
42
+ this.options = options;
43
+ this.filePath = config.filePath;
44
+ this.resolvers = config.resolvers || [];
45
+ this.transformers = config.transformers || {};
46
+ this.runtimes = config.runtimes || [];
47
+ this.bundler = config.bundler;
48
+ this.namers = config.namers || [];
49
+ this.packagers = config.packagers || {};
50
+ this.optimizers = config.optimizers || {};
51
+ this.compressors = config.compressors || {};
52
+ this.reporters = config.reporters || [];
53
+ this.validators = config.validators || {};
54
+ this.pluginCache = new Map();
55
+ this.regexCache = new Map();
56
+ }
57
+ static deserialize(serialized) {
58
+ return new AtlaspackConfig(serialized.config, serialized.options);
59
+ }
60
+ getConfig() {
61
+ return {
62
+ filePath: this.filePath,
63
+ resolvers: this.resolvers,
64
+ transformers: this.transformers,
65
+ validators: this.validators,
66
+ runtimes: this.runtimes,
67
+ bundler: this.bundler,
68
+ namers: this.namers,
69
+ packagers: this.packagers,
70
+ optimizers: this.optimizers,
71
+ compressors: this.compressors,
72
+ reporters: this.reporters
73
+ };
74
+ }
75
+ serialize() {
76
+ return {
77
+ $$raw: false,
78
+ config: this.getConfig(),
79
+ options: this.options
80
+ };
81
+ }
82
+ _loadPlugin(node) {
83
+ let plugin = this.pluginCache.get(node.packageName);
84
+ if (plugin) {
85
+ return plugin;
86
+ }
87
+ plugin = (0, _loadAtlaspackPlugin.default)(node.packageName, (0, _projectPath.fromProjectPath)(this.options.projectRoot, node.resolveFrom), node.keyPath, this.options);
88
+ this.pluginCache.set(node.packageName, plugin);
89
+ return plugin;
90
+ }
91
+ async loadPlugin(node) {
92
+ let plugin = await this._loadPlugin(node);
93
+ return {
94
+ ...plugin,
95
+ name: node.packageName,
96
+ keyPath: node.keyPath
97
+ };
98
+ }
99
+ invalidatePlugin(packageName) {
100
+ this.pluginCache.delete(packageName);
101
+ }
102
+ loadPlugins(plugins) {
103
+ return Promise.all(plugins.map(p => this.loadPlugin(p)));
104
+ }
105
+ async getResolvers() {
106
+ if (this.resolvers.length === 0) {
107
+ throw await this.missingPluginError(this.resolvers, 'No resolver plugins specified in .parcelrc config', '/resolvers');
108
+ }
109
+ return this.loadPlugins(this.resolvers);
110
+ }
111
+ _getValidatorNodes(filePath) {
112
+ let validators = this.matchGlobMapPipelines(filePath, this.validators) || [];
113
+ return validators;
114
+ }
115
+ getValidatorNames(filePath) {
116
+ let validators = this._getValidatorNodes(filePath);
117
+ return validators.map(v => v.packageName);
118
+ }
119
+ getValidators(filePath) {
120
+ let validators = this._getValidatorNodes(filePath);
121
+ return this.loadPlugins(validators);
122
+ }
123
+ getNamedPipelines() {
124
+ return Object.keys(this.transformers).filter(glob => glob.includes(':')).map(glob => glob.split(':')[0]);
125
+ }
126
+ async getTransformers(filePath, pipeline, allowEmpty) {
127
+ let transformers = this.matchGlobMapPipelines(filePath, this.transformers, pipeline);
128
+ if (!transformers || transformers.length === 0) {
129
+ if (allowEmpty) {
130
+ return [];
131
+ }
132
+ throw await this.missingPluginError(this.transformers, (0, _diagnostic().md)`No transformers found for __${(0, _projectPath.fromProjectPathRelative)(filePath)}__` + (pipeline != null ? ` with pipeline: '${pipeline}'` : '') + '.', '/transformers');
133
+ }
134
+ return this.loadPlugins(transformers);
135
+ }
136
+ async getBundler() {
137
+ if (!this.bundler) {
138
+ throw await this.missingPluginError([], 'No bundler specified in .parcelrc config', '/bundler');
139
+ }
140
+ return this.loadPlugin(this.bundler);
141
+ }
142
+ async getNamers() {
143
+ if (this.namers.length === 0) {
144
+ throw await this.missingPluginError(this.namers, 'No namer plugins specified in .parcelrc config', '/namers');
145
+ }
146
+ return this.loadPlugins(this.namers);
147
+ }
148
+ getRuntimes() {
149
+ if (!this.runtimes) {
150
+ return Promise.resolve([]);
151
+ }
152
+ return this.loadPlugins(this.runtimes);
153
+ }
154
+ async getPackager(filePath) {
155
+ let packager = this.matchGlobMap((0, _projectPath.toProjectPathUnsafe)(filePath), this.packagers);
156
+ if (!packager) {
157
+ throw await this.missingPluginError(this.packagers, (0, _diagnostic().md)`No packager found for __${filePath}__.`, '/packagers');
158
+ }
159
+ return this.loadPlugin(packager);
160
+ }
161
+ _getOptimizerNodes(filePath, pipeline) {
162
+ // If a pipeline is specified, but it doesn't exist in the optimizers config, ignore it.
163
+ // Pipelines for bundles come from their entry assets, so the pipeline likely exists in transformers.
164
+ if (pipeline) {
165
+ let prefix = pipeline + ':';
166
+ if (!Object.keys(this.optimizers).some(glob => glob.startsWith(prefix))) {
167
+ pipeline = null;
168
+ }
169
+ }
170
+ return this.matchGlobMapPipelines((0, _projectPath.toProjectPathUnsafe)(filePath), this.optimizers, pipeline) ?? [];
171
+ }
172
+ getOptimizerNames(filePath, pipeline) {
173
+ let optimizers = this._getOptimizerNodes(filePath, pipeline);
174
+ return optimizers.map(o => o.packageName);
175
+ }
176
+ getOptimizers(filePath, pipeline) {
177
+ let optimizers = this._getOptimizerNodes(filePath, pipeline);
178
+ if (optimizers.length === 0) {
179
+ return Promise.resolve([]);
180
+ }
181
+ return this.loadPlugins(optimizers);
182
+ }
183
+ async getCompressors(filePath) {
184
+ let compressors = this.matchGlobMapPipelines((0, _projectPath.toProjectPathUnsafe)(filePath), this.compressors) ?? [];
185
+ if (compressors.length === 0) {
186
+ throw await this.missingPluginError(this.compressors, (0, _diagnostic().md)`No compressors found for __${filePath}__.`, '/compressors');
187
+ }
188
+ return this.loadPlugins(compressors);
189
+ }
190
+ getReporters() {
191
+ return this.loadPlugins(this.reporters);
192
+ }
193
+ isGlobMatch(projectPath, pattern, pipeline) {
194
+ // glob's shouldn't be dependant on absolute paths anyway
195
+ let filePath = (0, _projectPath.fromProjectPathRelative)(projectPath);
196
+ let [patternPipeline, patternGlob] = pattern.split(':');
197
+ if (!patternGlob) {
198
+ patternGlob = patternPipeline;
199
+ patternPipeline = null;
200
+ }
201
+ let re = this.regexCache.get(patternGlob);
202
+ if (!re) {
203
+ re = (0, _utils().globToRegex)(patternGlob, {
204
+ dot: true,
205
+ nocase: true
206
+ });
207
+ this.regexCache.set(patternGlob, re);
208
+ }
209
+ return (pipeline === patternPipeline || !pipeline && !patternPipeline) && (re.test(filePath) || re.test((0, _path().basename)(filePath)));
210
+ }
211
+ matchGlobMap(filePath, globMap) {
212
+ for (let pattern in globMap) {
213
+ if (this.isGlobMatch(filePath, pattern)) {
214
+ return globMap[pattern];
215
+ }
216
+ }
217
+ return null;
218
+ }
219
+ matchGlobMapPipelines(filePath, globMap, pipeline) {
220
+ let matches = [];
221
+ if (pipeline) {
222
+ // If a pipeline is requested, a the glob needs to match exactly
223
+ let exactMatch;
224
+ for (let pattern in globMap) {
225
+ if (this.isGlobMatch(filePath, pattern, pipeline)) {
226
+ exactMatch = globMap[pattern];
227
+ break;
228
+ }
229
+ }
230
+ if (!exactMatch) {
231
+ return [];
232
+ } else {
233
+ matches.push(exactMatch);
234
+ }
235
+ }
236
+ for (let pattern in globMap) {
237
+ if (this.isGlobMatch(filePath, pattern)) {
238
+ matches.push(globMap[pattern]);
239
+ }
240
+ }
241
+ let flatten = () => {
242
+ let pipeline = matches.shift() || [];
243
+ let spreadIndex = pipeline.indexOf('...');
244
+ if (spreadIndex >= 0) {
245
+ pipeline = [...pipeline.slice(0, spreadIndex), ...flatten(), ...pipeline.slice(spreadIndex + 1)];
246
+ }
247
+ if (pipeline.includes('...')) {
248
+ throw new Error('Only one spread parameter can be included in a config pipeline');
249
+ }
250
+ return pipeline;
251
+ };
252
+ let res = flatten();
253
+ // $FlowFixMe afaik this should work
254
+ return res;
255
+ }
256
+ async missingPluginError(plugins, message, key) {
257
+ let configsWithPlugin;
258
+ if (Array.isArray(plugins)) {
259
+ configsWithPlugin = new Set(getConfigPaths(this.options, plugins));
260
+ } else {
261
+ configsWithPlugin = new Set(Object.keys(plugins).flatMap(k => Array.isArray(plugins[k]) ? getConfigPaths(this.options, plugins[k]) : [getConfigPath(this.options, plugins[k])]));
262
+ }
263
+ if (configsWithPlugin.size === 0) {
264
+ configsWithPlugin.add((0, _projectPath.fromProjectPath)(this.options.projectRoot, this.filePath));
265
+ }
266
+ let seenKey = false;
267
+ let codeFrames = await Promise.all([...configsWithPlugin].map(async filePath => {
268
+ let configContents = await this.options.inputFS.readFile(filePath, 'utf8');
269
+ if (!_json().default.parse(configContents)[key.slice(1)]) {
270
+ key = '';
271
+ } else {
272
+ seenKey = true;
273
+ }
274
+ return {
275
+ filePath,
276
+ code: configContents,
277
+ codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(configContents, [{
278
+ key
279
+ }])
280
+ };
281
+ }));
282
+ return new (_diagnostic().default)({
283
+ diagnostic: {
284
+ message,
285
+ origin: '@atlaspack/core',
286
+ codeFrames,
287
+ hints: !seenKey ? ['Try extending __@atlaspack/config-default__'] : []
288
+ }
289
+ });
290
+ }
291
+ }
292
+ exports.AtlaspackConfig = AtlaspackConfig;
293
+ function getConfigPaths(options, nodes) {
294
+ return nodes.map(node => node !== '...' ? getConfigPath(options, node) : null).filter(Boolean);
295
+ }
296
+ function getConfigPath(options, node) {
297
+ return (0, _projectPath.fromProjectPath)(options.projectRoot, node.resolveFrom);
298
+ }
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ exports.validatePackageName = validatePackageName;
8
+ // Parcel validates plugin package names due to:
9
+ //
10
+ // * https://github.com/parcel-bundler/parcel/issues/3397#issuecomment-521353931
11
+ //
12
+ // Ultimately:
13
+ //
14
+ // * We do not care about package names
15
+ // * Validation makes interop between parcel/atlaspack confusing.
16
+ //
17
+ function validatePackageName() {}
18
+ const validatePluginName = (pluginType, key) => {
19
+ return val => {
20
+ // allow plugin spread...
21
+ if (val === '...') return;
22
+ try {
23
+ validatePackageName(val, pluginType, key);
24
+ } catch (e) {
25
+ return e.message;
26
+ }
27
+ };
28
+ };
29
+ const validateExtends = val => {
30
+ // allow relative paths...
31
+ if (val.startsWith('.')) return;
32
+ try {
33
+ validatePackageName(val, 'config', 'extends');
34
+ } catch (e) {
35
+ return e.message;
36
+ }
37
+ };
38
+ const pipelineSchema = (pluginType, key) => {
39
+ return {
40
+ type: 'array',
41
+ items: {
42
+ type: 'string',
43
+ __validate: validatePluginName(pluginType, key)
44
+ }
45
+ };
46
+ };
47
+ const mapPipelineSchema = (pluginType, key) => {
48
+ return {
49
+ type: 'object',
50
+ properties: {},
51
+ additionalProperties: pipelineSchema(pluginType, key)
52
+ };
53
+ };
54
+ const mapStringSchema = (pluginType, key) => {
55
+ return {
56
+ type: 'object',
57
+ properties: {},
58
+ additionalProperties: {
59
+ type: 'string',
60
+ __validate: validatePluginName(pluginType, key)
61
+ }
62
+ };
63
+ };
64
+ var _default = exports.default = {
65
+ type: 'object',
66
+ properties: {
67
+ $schema: {
68
+ type: 'string'
69
+ },
70
+ extends: {
71
+ oneOf: [{
72
+ type: 'string',
73
+ __validate: validateExtends
74
+ }, {
75
+ type: 'array',
76
+ items: {
77
+ type: 'string',
78
+ __validate: validateExtends
79
+ }
80
+ }]
81
+ },
82
+ bundler: {
83
+ type: 'string',
84
+ __validate: validatePluginName('bundler', 'bundler')
85
+ },
86
+ resolvers: pipelineSchema('resolver', 'resolvers'),
87
+ transformers: mapPipelineSchema('transformer', 'transformers'),
88
+ validators: mapPipelineSchema('validator', 'validators'),
89
+ namers: pipelineSchema('namer', 'namers'),
90
+ packagers: mapStringSchema('packager', 'packagers'),
91
+ optimizers: mapPipelineSchema('optimizer', 'optimizers'),
92
+ compressors: mapPipelineSchema('compressor', 'compressors'),
93
+ reporters: pipelineSchema('reporter', 'reporters'),
94
+ runtimes: pipelineSchema('runtime', 'runtimes'),
95
+ filePath: {
96
+ type: 'string'
97
+ },
98
+ resolveFrom: {
99
+ type: 'string'
100
+ }
101
+ },
102
+ additionalProperties: false
103
+ };