@atlaspack/core 2.24.1 → 2.24.2-dev-ts-project-refs-d30e9754f.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 (86) hide show
  1. package/LICENSE +201 -0
  2. package/dist/AssetGraph.js +591 -0
  3. package/dist/Atlaspack.js +656 -0
  4. package/dist/AtlaspackConfig.js +324 -0
  5. package/dist/AtlaspackConfig.schema.js +108 -0
  6. package/dist/BundleGraph.js +1628 -0
  7. package/dist/CommittedAsset.js +142 -0
  8. package/dist/Dependency.js +125 -0
  9. package/dist/Environment.js +132 -0
  10. package/dist/EnvironmentManager.js +108 -0
  11. package/dist/IdentifierRegistry.js +38 -0
  12. package/dist/InternalConfig.js +37 -0
  13. package/dist/PackagerRunner.js +531 -0
  14. package/dist/ReporterRunner.js +151 -0
  15. package/dist/RequestTracker.js +1368 -0
  16. package/dist/SymbolPropagation.js +620 -0
  17. package/dist/TargetDescriptor.schema.js +143 -0
  18. package/dist/Transformation.js +487 -0
  19. package/dist/UncommittedAsset.js +315 -0
  20. package/dist/Validation.js +196 -0
  21. package/dist/applyRuntimes.js +305 -0
  22. package/dist/assetUtils.js +168 -0
  23. package/dist/atlaspack-v3/AtlaspackV3.js +70 -0
  24. package/dist/atlaspack-v3/NapiWorkerPool.js +57 -0
  25. package/dist/atlaspack-v3/fs.js +52 -0
  26. package/dist/atlaspack-v3/index.js +25 -0
  27. package/dist/atlaspack-v3/jsCallable.js +16 -0
  28. package/dist/atlaspack-v3/worker/compat/asset-symbols.js +190 -0
  29. package/dist/atlaspack-v3/worker/compat/bitflags.js +94 -0
  30. package/dist/atlaspack-v3/worker/compat/dependency.js +43 -0
  31. package/dist/atlaspack-v3/worker/compat/environment.js +57 -0
  32. package/dist/atlaspack-v3/worker/compat/index.js +25 -0
  33. package/dist/atlaspack-v3/worker/compat/mutable-asset.js +152 -0
  34. package/dist/atlaspack-v3/worker/compat/plugin-config.js +76 -0
  35. package/dist/atlaspack-v3/worker/compat/plugin-logger.js +26 -0
  36. package/dist/atlaspack-v3/worker/compat/plugin-options.js +122 -0
  37. package/dist/atlaspack-v3/worker/compat/plugin-tracer.js +10 -0
  38. package/dist/atlaspack-v3/worker/compat/target.js +14 -0
  39. package/dist/atlaspack-v3/worker/worker.js +292 -0
  40. package/dist/constants.js +17 -0
  41. package/dist/dumpGraphToGraphViz.js +281 -0
  42. package/dist/index.js +62 -0
  43. package/dist/loadAtlaspackPlugin.js +128 -0
  44. package/dist/loadDotEnv.js +41 -0
  45. package/dist/projectPath.js +83 -0
  46. package/dist/public/Asset.js +279 -0
  47. package/dist/public/Bundle.js +224 -0
  48. package/dist/public/BundleGraph.js +359 -0
  49. package/dist/public/BundleGroup.js +53 -0
  50. package/dist/public/Config.js +286 -0
  51. package/dist/public/Dependency.js +138 -0
  52. package/dist/public/Environment.js +278 -0
  53. package/dist/public/MutableBundleGraph.js +277 -0
  54. package/dist/public/PluginOptions.js +80 -0
  55. package/dist/public/Symbols.js +248 -0
  56. package/dist/public/Target.js +69 -0
  57. package/dist/registerCoreWithSerializer.js +38 -0
  58. package/dist/requests/AssetGraphRequest.js +429 -0
  59. package/dist/requests/AssetGraphRequestRust.js +246 -0
  60. package/dist/requests/AssetRequest.js +130 -0
  61. package/dist/requests/AtlaspackBuildRequest.js +60 -0
  62. package/dist/requests/AtlaspackConfigRequest.js +490 -0
  63. package/dist/requests/BundleGraphRequest.js +441 -0
  64. package/dist/requests/ConfigRequest.js +222 -0
  65. package/dist/requests/DevDepRequest.js +204 -0
  66. package/dist/requests/EntryRequest.js +314 -0
  67. package/dist/requests/PackageRequest.js +65 -0
  68. package/dist/requests/PathRequest.js +349 -0
  69. package/dist/requests/TargetRequest.js +1310 -0
  70. package/dist/requests/ValidationRequest.js +49 -0
  71. package/dist/requests/WriteBundleRequest.js +254 -0
  72. package/dist/requests/WriteBundlesRequest.js +165 -0
  73. package/dist/requests/asset-graph-diff.js +126 -0
  74. package/dist/requests/asset-graph-dot.js +131 -0
  75. package/dist/resolveOptions.js +268 -0
  76. package/dist/rustWorkerThreadDylibHack.js +19 -0
  77. package/dist/serializerCore.browser.js +43 -0
  78. package/dist/summarizeRequest.js +39 -0
  79. package/dist/types.js +31 -0
  80. package/dist/utils.js +172 -0
  81. package/dist/worker.js +130 -0
  82. package/lib/AssetGraph.js +1 -0
  83. package/package.json +22 -22
  84. package/src/AssetGraph.ts +1 -0
  85. package/tsconfig.json +55 -2
  86. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createDevDependency = createDevDependency;
7
+ exports.getDevDepRequests = getDevDepRequests;
8
+ exports.invalidateDevDeps = invalidateDevDeps;
9
+ exports.resolveDevDepRequestRef = resolveDevDepRequestRef;
10
+ exports.runDevDepRequest = runDevDepRequest;
11
+ exports.getWorkerDevDepRequests = getWorkerDevDepRequests;
12
+ const build_cache_1 = require("@atlaspack/build-cache");
13
+ const nullthrows_1 = __importDefault(require("nullthrows"));
14
+ const assetUtils_1 = require("../assetUtils");
15
+ const utils_1 = require("../utils");
16
+ const projectPath_1 = require("../projectPath");
17
+ const RequestTracker_1 = require("../RequestTracker");
18
+ // A cache of dev dep requests keyed by invalidations.
19
+ // If the package manager returns the same invalidation object, then
20
+ // we can reuse the dev dep request rather than recomputing the project
21
+ // paths and hashes.
22
+ const devDepRequestCache = new WeakMap();
23
+ async function createDevDependency(opts, requestDevDeps, options) {
24
+ let { specifier, resolveFrom, additionalInvalidations } = opts;
25
+ let key = `${specifier}:${(0, projectPath_1.fromProjectPathRelative)(resolveFrom)}`;
26
+ // If the request sent us a hash, we know the dev dep and all of its dependencies didn't change.
27
+ // Reuse the same hash in the response. No need to send back invalidations as the request won't
28
+ // be re-run anyway.
29
+ let hash = requestDevDeps.get(key);
30
+ if (hash != null) {
31
+ return {
32
+ type: 'ref',
33
+ specifier,
34
+ resolveFrom,
35
+ hash,
36
+ };
37
+ }
38
+ let resolveFromAbsolute = (0, projectPath_1.fromProjectPath)(options.projectRoot, resolveFrom);
39
+ // Ensure that the package manager has an entry for this resolution.
40
+ try {
41
+ await options.packageManager.resolve(specifier, resolveFromAbsolute);
42
+ }
43
+ catch (err) {
44
+ // ignore
45
+ }
46
+ let invalidations = options.packageManager.getInvalidations(specifier, resolveFromAbsolute);
47
+ let cached = devDepRequestCache.get(invalidations);
48
+ if (cached != null) {
49
+ return cached;
50
+ }
51
+ let invalidateOnFileChangeProject = [
52
+ ...invalidations.invalidateOnFileChange,
53
+ ].map((f) => (0, projectPath_1.toProjectPath)(options.projectRoot, f));
54
+ // It is possible for a transformer to have multiple different hashes due to
55
+ // different dependencies (e.g. conditional requires) so we must always
56
+ // recompute the hash and compare rather than only sending a transformer
57
+ // dev dependency once.
58
+ hash = await (0, assetUtils_1.getInvalidationHash)(invalidateOnFileChangeProject.map((f) => ({
59
+ type: 'file',
60
+ filePath: f,
61
+ })), options);
62
+ let devDepRequest = {
63
+ specifier,
64
+ resolveFrom,
65
+ hash,
66
+ invalidateOnFileCreate: invalidations.invalidateOnFileCreate.map((i) => (0, utils_1.invalidateOnFileCreateToInternal)(options.projectRoot, i)),
67
+ invalidateOnFileChange: new Set(invalidateOnFileChangeProject),
68
+ invalidateOnStartup: invalidations.invalidateOnStartup,
69
+ additionalInvalidations,
70
+ };
71
+ devDepRequestCache.set(invalidations, devDepRequest);
72
+ return devDepRequest;
73
+ }
74
+ async function getDevDepRequests(api) {
75
+ async function getPreviousDevDepRequests() {
76
+ const allDevDepRequests = await Promise.all(api
77
+ .getSubRequests()
78
+ .filter((req) => req.requestType === RequestTracker_1.requestTypes.dev_dep_request)
79
+ .map(async (req) => [
80
+ req.id,
81
+ await api.getRequestResult(req.id),
82
+ ]));
83
+ const nonNullDevDepRequests = [];
84
+ for (const [id, result] of allDevDepRequests) {
85
+ if (result != null) {
86
+ nonNullDevDepRequests.push([id, result]);
87
+ }
88
+ }
89
+ // @ts-expect-error TS2769
90
+ return new Map(nonNullDevDepRequests);
91
+ }
92
+ const previousDevDepRequests = await getPreviousDevDepRequests();
93
+ return {
94
+ devDeps: new Map([...previousDevDepRequests.entries()]
95
+ // @ts-expect-error TS2769
96
+ .filter(([id]) => api.canSkipSubrequest(id))
97
+ .map(([, req]) => [
98
+ `${req.specifier}:${(0, projectPath_1.fromProjectPathRelative)(req.resolveFrom)}`,
99
+ req.hash,
100
+ ])),
101
+ invalidDevDeps: await Promise.all([...previousDevDepRequests.entries()]
102
+ // @ts-expect-error TS2769
103
+ .filter(([id]) => !api.canSkipSubrequest(id))
104
+ .flatMap(([, req]) => {
105
+ return [
106
+ {
107
+ specifier: req.specifier,
108
+ resolveFrom: req.resolveFrom,
109
+ },
110
+ // @ts-expect-error TS7006
111
+ ...(req.additionalInvalidations ?? []).map((i) => ({
112
+ specifier: i.specifier,
113
+ resolveFrom: i.resolveFrom,
114
+ })),
115
+ ];
116
+ })),
117
+ };
118
+ }
119
+ // Tracks dev deps that have been invalidated during this build
120
+ // so we don't invalidate the require cache more than once.
121
+ const invalidatedDevDeps = (0, build_cache_1.createBuildCache)();
122
+ function invalidateDevDeps(invalidDevDeps, options, config) {
123
+ for (let { specifier, resolveFrom } of invalidDevDeps) {
124
+ let key = `${specifier}:${(0, projectPath_1.fromProjectPathRelative)(resolveFrom)}`;
125
+ if (!invalidatedDevDeps.has(key)) {
126
+ config.invalidatePlugin(specifier);
127
+ options.packageManager.invalidate(specifier, (0, projectPath_1.fromProjectPath)(options.projectRoot, resolveFrom));
128
+ invalidatedDevDeps.set(key, true);
129
+ }
130
+ }
131
+ }
132
+ const devDepRequests = (0, build_cache_1.createBuildCache)();
133
+ function resolveDevDepRequestRef(devDepRequestRef) {
134
+ const devDepRequest =
135
+ // @ts-expect-error TS2339
136
+ devDepRequestRef.type === 'ref'
137
+ ? devDepRequests.get(devDepRequestRef.hash)
138
+ : devDepRequestRef;
139
+ if (devDepRequest == null) {
140
+ throw new Error(`Worker send back a reference to a missing dev dep request.
141
+
142
+ This might happen due to internal in-memory build caches not being cleared
143
+ between builds or due a race condition.
144
+ ${process.env.NODE_ENV === 'test'
145
+ ? `If this is a unit test, call atlaspack.clearBuildCaches() between tests`
146
+ : ''}
147
+
148
+ This is a bug in Atlaspack.`);
149
+ }
150
+ // @ts-expect-error TS2339
151
+ if (devDepRequestRef.type !== 'ref') {
152
+ // @ts-expect-error TS2345
153
+ devDepRequests.set(devDepRequest.hash, devDepRequest);
154
+ }
155
+ // @ts-expect-error TS2322
156
+ return devDepRequest;
157
+ }
158
+ async function runDevDepRequest(api, devDepRequestRef) {
159
+ await api.runRequest({
160
+ id: 'dev_dep_request:' +
161
+ devDepRequestRef.specifier +
162
+ ':' +
163
+ devDepRequestRef.hash,
164
+ type: RequestTracker_1.requestTypes.dev_dep_request,
165
+ // @ts-expect-error TS2322
166
+ run: ({ api }) => {
167
+ const devDepRequest = resolveDevDepRequestRef(devDepRequestRef);
168
+ for (let filePath of (0, nullthrows_1.default)(devDepRequest.invalidateOnFileChange, 'DevDepRequest missing invalidateOnFileChange')) {
169
+ api.invalidateOnFileUpdate(filePath);
170
+ api.invalidateOnFileDelete(filePath);
171
+ }
172
+ for (let invalidation of (0, nullthrows_1.default)(devDepRequest.invalidateOnFileCreate, 'DevDepRequest missing invalidateOnFileCreate')) {
173
+ api.invalidateOnFileCreate(invalidation);
174
+ }
175
+ if (devDepRequest.invalidateOnStartup) {
176
+ api.invalidateOnStartup();
177
+ }
178
+ api.storeResult({
179
+ specifier: devDepRequest.specifier,
180
+ resolveFrom: devDepRequest.resolveFrom,
181
+ hash: devDepRequest.hash,
182
+ additionalInvalidations: devDepRequest.additionalInvalidations,
183
+ });
184
+ },
185
+ input: null,
186
+ });
187
+ }
188
+ // A cache of plugin dependency hashes that we've already sent to the main thread.
189
+ // Automatically cleared before each build.
190
+ const pluginCache = (0, build_cache_1.createBuildCache)();
191
+ function getWorkerDevDepRequests(devDepRequests) {
192
+ return devDepRequests.map((devDepRequest) => {
193
+ // If we've already sent a matching transformer + hash to the main thread during this build,
194
+ // there's no need to repeat ourselves.
195
+ let { specifier, resolveFrom, hash } = devDepRequest;
196
+ if (hash === pluginCache.get(specifier)) {
197
+ return { type: 'ref', specifier, resolveFrom, hash };
198
+ }
199
+ else {
200
+ pluginCache.set(specifier, hash);
201
+ return devDepRequest;
202
+ }
203
+ });
204
+ }
@@ -0,0 +1,314 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.EntryResolver = void 0;
40
+ exports.default = createEntryRequest;
41
+ const utils_1 = require("@atlaspack/utils");
42
+ const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
43
+ const path_1 = __importDefault(require("path"));
44
+ const json_sourcemap_1 = require("@mischnic/json-sourcemap");
45
+ const RequestTracker_1 = require("../RequestTracker");
46
+ const projectPath_1 = require("../projectPath");
47
+ const type = 'entry_request';
48
+ function createEntryRequest(input) {
49
+ return {
50
+ id: `${type}:${(0, projectPath_1.fromProjectPathRelative)(input)}`,
51
+ type: RequestTracker_1.requestTypes.entry_request,
52
+ run,
53
+ input,
54
+ };
55
+ }
56
+ // @ts-expect-error TS7031
57
+ async function run({ input, api, options }) {
58
+ let entryResolver = new EntryResolver(options);
59
+ let filePath = (0, projectPath_1.fromProjectPath)(options.projectRoot, input);
60
+ let result = await entryResolver.resolveEntry(filePath);
61
+ // Connect files like package.json that affect the entry
62
+ // resolution so we invalidate when they change.
63
+ for (let file of result.files) {
64
+ api.invalidateOnFileUpdate(file.filePath);
65
+ api.invalidateOnFileDelete(file.filePath);
66
+ }
67
+ // If the entry specifier is a glob, add a glob node so
68
+ // we invalidate when a new file matches.
69
+ for (let glob of result.globs) {
70
+ api.invalidateOnFileCreate({
71
+ glob: (0, projectPath_1.toProjectPath)(options.projectRoot, glob),
72
+ });
73
+ }
74
+ // Invalidate whenever an entry is deleted.
75
+ // If the entry was a glob, we'll re-evaluate it, and otherwise
76
+ // a proper entry error will be thrown.
77
+ for (let entry of result.entries) {
78
+ api.invalidateOnFileDelete(entry.filePath);
79
+ }
80
+ return result;
81
+ }
82
+ async function assertFile(fs, entry, relativeSource, pkgFilePath, keyPath, options) {
83
+ let source = path_1.default.join(entry, relativeSource);
84
+ let stat;
85
+ try {
86
+ stat = await fs.stat(source);
87
+ }
88
+ catch (err) {
89
+ let contents = await fs.readFile(pkgFilePath, 'utf8');
90
+ let alternatives = await (0, utils_1.findAlternativeFiles)(fs, relativeSource, entry, options.projectRoot, false);
91
+ throw new diagnostic_1.default({
92
+ diagnostic: {
93
+ origin: '@atlaspack/core',
94
+ message: (0, diagnostic_1.md) `${path_1.default.relative(process.cwd(), source)} does not exist.`,
95
+ codeFrames: [
96
+ {
97
+ filePath: pkgFilePath,
98
+ codeHighlights: (0, diagnostic_1.generateJSONCodeHighlights)(contents, [
99
+ {
100
+ key: keyPath,
101
+ type: 'value',
102
+ },
103
+ ]),
104
+ },
105
+ ],
106
+ hints: alternatives.map((r) => {
107
+ return (0, diagnostic_1.md) `Did you mean '__${r}__'?`;
108
+ }),
109
+ },
110
+ });
111
+ }
112
+ if (!stat.isFile()) {
113
+ let contents = await fs.readFile(pkgFilePath, 'utf8');
114
+ throw new diagnostic_1.default({
115
+ diagnostic: {
116
+ origin: '@atlaspack/core',
117
+ message: (0, diagnostic_1.md) `${path_1.default.relative(process.cwd(), source)} is not a file.`,
118
+ codeFrames: [
119
+ {
120
+ filePath: pkgFilePath,
121
+ codeHighlights: (0, diagnostic_1.generateJSONCodeHighlights)(contents, [
122
+ {
123
+ key: keyPath,
124
+ type: 'value',
125
+ },
126
+ ]),
127
+ },
128
+ ],
129
+ },
130
+ });
131
+ }
132
+ }
133
+ class EntryResolver {
134
+ constructor(options) {
135
+ this.options = options;
136
+ }
137
+ async resolveEntry(entry) {
138
+ let stat;
139
+ try {
140
+ stat = await this.options.inputFS.stat(entry);
141
+ }
142
+ catch (err) {
143
+ if (!(0, utils_1.isGlob)(entry)) {
144
+ throw new diagnostic_1.default({
145
+ diagnostic: {
146
+ message: (0, diagnostic_1.md) `Entry ${entry} does not exist`,
147
+ },
148
+ });
149
+ }
150
+ let files = await (0, utils_1.glob)(entry, this.options.inputFS, {
151
+ absolute: true,
152
+ onlyFiles: false,
153
+ });
154
+ let results = await Promise.all(files.map((f) => this.resolveEntry(path_1.default.normalize(f))));
155
+ return results.reduce((p, res) => ({
156
+ entries: p.entries.concat(res.entries),
157
+ files: p.files.concat(res.files),
158
+ globs: p.globs.concat(res.globs),
159
+ }), { entries: [], files: [], globs: [entry] });
160
+ }
161
+ if (stat.isDirectory()) {
162
+ let pkg = await this.readPackage(entry);
163
+ if (pkg) {
164
+ let { filePath } = pkg;
165
+ let entries = [];
166
+ let files = [
167
+ {
168
+ filePath: (0, projectPath_1.toProjectPath)(this.options.projectRoot, filePath),
169
+ },
170
+ ];
171
+ let globs = [];
172
+ let targetsWithSources = 0;
173
+ if (pkg.targets) {
174
+ for (let targetName in pkg.targets) {
175
+ let target = pkg.targets[targetName];
176
+ if (target.source != null) {
177
+ targetsWithSources++;
178
+ let targetSources = Array.isArray(target.source)
179
+ ? target.source
180
+ : [target.source];
181
+ let i = 0;
182
+ for (let source of targetSources) {
183
+ let sources;
184
+ if ((0, utils_1.isGlob)(source)) {
185
+ globs.push(source);
186
+ sources = await (0, utils_1.glob)(source, this.options.inputFS, {
187
+ onlyFiles: true,
188
+ cwd: entry,
189
+ });
190
+ }
191
+ else {
192
+ sources = [source];
193
+ }
194
+ let keyPath = `/targets/${targetName}/source${Array.isArray(target.source) ? `/${i}` : ''}`;
195
+ for (let relativeSource of sources) {
196
+ let source = path_1.default.join(entry, relativeSource);
197
+ await assertFile(this.options.inputFS, entry, relativeSource, filePath, keyPath, this.options);
198
+ entries.push({
199
+ filePath: (0, projectPath_1.toProjectPath)(this.options.projectRoot, source),
200
+ packagePath: (0, projectPath_1.toProjectPath)(this.options.projectRoot, entry),
201
+ target: targetName,
202
+ loc: {
203
+ filePath: (0, projectPath_1.toProjectPath)(this.options.projectRoot, pkg.filePath),
204
+ ...(0, diagnostic_1.getJSONSourceLocation)(pkg.map.pointers[keyPath], 'value'),
205
+ },
206
+ });
207
+ i++;
208
+ }
209
+ }
210
+ }
211
+ }
212
+ }
213
+ let allTargetsHaveSource = targetsWithSources > 0 &&
214
+ pkg != null &&
215
+ pkg.targets != null &&
216
+ Object.keys(pkg.targets).length === targetsWithSources;
217
+ if (!allTargetsHaveSource && pkg.source != null) {
218
+ let pkgSources = Array.isArray(pkg.source)
219
+ ? pkg.source
220
+ : [pkg.source];
221
+ let i = 0;
222
+ for (let pkgSource of pkgSources) {
223
+ let sources;
224
+ if ((0, utils_1.isGlob)(pkgSource)) {
225
+ globs.push(pkgSource);
226
+ sources = await (0, utils_1.glob)(pkgSource, this.options.inputFS, {
227
+ onlyFiles: true,
228
+ cwd: path_1.default.dirname(filePath),
229
+ });
230
+ }
231
+ else {
232
+ sources = [pkgSource];
233
+ }
234
+ let keyPath = `/source${Array.isArray(pkg.source) ? `/${i}` : ''}`;
235
+ for (let relativeSource of sources) {
236
+ let source = path_1.default.join(path_1.default.dirname(filePath), relativeSource);
237
+ await assertFile(this.options.inputFS, entry, relativeSource, filePath, keyPath, this.options);
238
+ entries.push({
239
+ filePath: (0, projectPath_1.toProjectPath)(this.options.projectRoot, source),
240
+ packagePath: (0, projectPath_1.toProjectPath)(this.options.projectRoot, entry),
241
+ loc: {
242
+ filePath: (0, projectPath_1.toProjectPath)(this.options.projectRoot, pkg.filePath),
243
+ ...(0, diagnostic_1.getJSONSourceLocation)(pkg.map.pointers[keyPath], 'value'),
244
+ },
245
+ });
246
+ i++;
247
+ }
248
+ }
249
+ }
250
+ // Only return if we found any valid entries
251
+ if (entries.length && files.length) {
252
+ return {
253
+ entries,
254
+ files,
255
+ globs,
256
+ };
257
+ }
258
+ }
259
+ throw new diagnostic_1.default({
260
+ diagnostic: {
261
+ message: (0, diagnostic_1.md) `Could not find entry: ${entry}`,
262
+ },
263
+ });
264
+ }
265
+ else if (stat.isFile()) {
266
+ let projectRoot = this.options.projectRoot;
267
+ let packagePath = (0, utils_1.isDirectoryInside)(this.options.inputFS.cwd(), projectRoot)
268
+ ? this.options.inputFS.cwd()
269
+ : projectRoot;
270
+ return {
271
+ entries: [
272
+ {
273
+ filePath: (0, projectPath_1.toProjectPath)(this.options.projectRoot, entry),
274
+ packagePath: (0, projectPath_1.toProjectPath)(this.options.projectRoot, packagePath),
275
+ },
276
+ ],
277
+ files: [],
278
+ globs: [],
279
+ };
280
+ }
281
+ throw new diagnostic_1.default({
282
+ diagnostic: {
283
+ message: (0, diagnostic_1.md) `Unknown entry: ${entry}`,
284
+ },
285
+ });
286
+ }
287
+ async readPackage(entry) {
288
+ let content, pkg;
289
+ let pkgFile = path_1.default.join(entry, 'package.json');
290
+ try {
291
+ content = await this.options.inputFS.readFile(pkgFile, 'utf8');
292
+ }
293
+ catch (err) {
294
+ return null;
295
+ }
296
+ try {
297
+ pkg = JSON.parse(content);
298
+ }
299
+ catch (err) {
300
+ // TODO: code frame?
301
+ throw new diagnostic_1.default({
302
+ diagnostic: {
303
+ message: (0, diagnostic_1.md) `Error parsing ${path_1.default.relative(this.options.inputFS.cwd(), pkgFile)}: ${err.message}`,
304
+ },
305
+ });
306
+ }
307
+ return {
308
+ ...pkg,
309
+ filePath: pkgFile,
310
+ map: (0, json_sourcemap_1.parse)(content, undefined, { tabWidth: 1 }),
311
+ };
312
+ }
313
+ }
314
+ exports.EntryResolver = EntryResolver;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createPackageRequest = createPackageRequest;
7
+ const RequestTracker_1 = require("../RequestTracker");
8
+ const nullthrows_1 = __importDefault(require("nullthrows"));
9
+ const ConfigRequest_1 = require("./ConfigRequest");
10
+ const DevDepRequest_1 = require("./DevDepRequest");
11
+ const AtlaspackConfigRequest_1 = __importDefault(require("./AtlaspackConfigRequest"));
12
+ function createPackageRequest(input) {
13
+ return {
14
+ type: RequestTracker_1.requestTypes.package_request,
15
+ id: input.bundleGraph.getHash(input.bundle),
16
+ run,
17
+ input,
18
+ };
19
+ }
20
+ // @ts-expect-error TS7031
21
+ async function run({ input, api, farm }) {
22
+ let { bundleGraphReference, optionsRef, bundle, useMainThread } = input;
23
+ let runPackage = farm.createHandle('runPackage', useMainThread);
24
+ let start = Date.now();
25
+ let { devDeps, invalidDevDeps } = await (0, DevDepRequest_1.getDevDepRequests)(api);
26
+ let { cachePath } = (0, nullthrows_1.default)(
27
+ // @ts-expect-error TS2347
28
+ await api.runRequest((0, AtlaspackConfigRequest_1.default)()));
29
+ let { devDepRequests, configRequests, bundleInfo, invalidations } = (await runPackage({
30
+ bundle,
31
+ bundleGraphReference,
32
+ optionsRef,
33
+ configCachePath: cachePath,
34
+ previousDevDeps: devDeps,
35
+ invalidDevDeps,
36
+ previousInvalidations: api.getInvalidations(),
37
+ }));
38
+ for (let devDepRequest of devDepRequests) {
39
+ await (0, DevDepRequest_1.runDevDepRequest)(api, devDepRequest);
40
+ }
41
+ for (let configRequest of configRequests) {
42
+ await (0, ConfigRequest_1.runConfigRequest)(api, configRequest);
43
+ }
44
+ for (let invalidation of invalidations) {
45
+ switch (invalidation.type) {
46
+ case 'file':
47
+ api.invalidateOnFileUpdate(invalidation.filePath);
48
+ api.invalidateOnFileDelete(invalidation.filePath);
49
+ break;
50
+ case 'env':
51
+ api.invalidateOnEnvChange(invalidation.key);
52
+ break;
53
+ case 'option':
54
+ api.invalidateOnOptionChange(invalidation.key);
55
+ break;
56
+ default:
57
+ // @ts-expect-error TS2339
58
+ throw new Error(`Unknown invalidation type: ${invalidation.type}`);
59
+ }
60
+ }
61
+ // @ts-expect-error TS2540
62
+ bundleInfo.time = Date.now() - start;
63
+ api.storeResult(bundleInfo);
64
+ return bundleInfo;
65
+ }