@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.
- package/LICENSE +201 -0
- package/index.d.ts +22 -0
- package/lib/AssetGraph.js +518 -0
- package/lib/Atlaspack.js +587 -0
- package/lib/AtlaspackConfig.js +298 -0
- package/lib/AtlaspackConfig.schema.js +125 -0
- package/lib/BundleGraph.js +1445 -0
- package/lib/CommittedAsset.js +133 -0
- package/lib/Dependency.js +88 -0
- package/lib/Environment.js +128 -0
- package/lib/InternalConfig.js +48 -0
- package/lib/PackagerRunner.js +519 -0
- package/lib/ReporterRunner.js +151 -0
- package/lib/RequestTracker.js +1089 -0
- package/lib/SymbolPropagation.js +625 -0
- package/lib/TargetDescriptor.schema.js +115 -0
- package/lib/Transformation.js +536 -0
- package/lib/UncommittedAsset.js +342 -0
- package/lib/Validation.js +215 -0
- package/lib/applyRuntimes.js +279 -0
- package/lib/assetUtils.js +189 -0
- package/lib/atlaspack-v3/AtlaspackV3.js +74 -0
- package/lib/atlaspack-v3/fs.js +30 -0
- package/lib/atlaspack-v3/index.js +19 -0
- package/lib/atlaspack-v3/jsCallable.js +15 -0
- package/lib/atlaspack-v3/plugins/Resolver.js +12 -0
- package/lib/atlaspack-v3/plugins/index.js +16 -0
- package/lib/atlaspack-v3/worker/index.js +3 -0
- package/lib/atlaspack-v3/worker/worker.js +30 -0
- package/lib/buildCache.js +18 -0
- package/lib/constants.js +21 -0
- package/lib/dumpGraphToGraphViz.js +206 -0
- package/lib/index.js +106 -0
- package/lib/loadAtlaspackPlugin.js +148 -0
- package/lib/loadDotEnv.js +54 -0
- package/lib/projectPath.js +86 -0
- package/lib/public/Asset.js +259 -0
- package/lib/public/Bundle.js +231 -0
- package/lib/public/BundleGraph.js +193 -0
- package/lib/public/BundleGroup.js +44 -0
- package/lib/public/Config.js +202 -0
- package/lib/public/Dependency.js +131 -0
- package/lib/public/Environment.js +244 -0
- package/lib/public/MutableBundleGraph.js +184 -0
- package/lib/public/PluginOptions.js +71 -0
- package/lib/public/Symbols.js +247 -0
- package/lib/public/Target.js +64 -0
- package/lib/registerCoreWithSerializer.js +45 -0
- package/lib/requests/AssetGraphRequest.js +427 -0
- package/lib/requests/AssetGraphRequestRust.js +187 -0
- package/lib/requests/AssetRequest.js +137 -0
- package/lib/requests/AtlaspackBuildRequest.js +78 -0
- package/lib/requests/AtlaspackConfigRequest.js +473 -0
- package/lib/requests/BundleGraphRequest.js +419 -0
- package/lib/requests/ConfigRequest.js +198 -0
- package/lib/requests/DevDepRequest.js +166 -0
- package/lib/requests/EntryRequest.js +295 -0
- package/lib/requests/PackageRequest.js +88 -0
- package/lib/requests/PathRequest.js +349 -0
- package/lib/requests/TargetRequest.js +1177 -0
- package/lib/requests/ValidationRequest.js +66 -0
- package/lib/requests/WriteBundleRequest.js +252 -0
- package/lib/requests/WriteBundlesRequest.js +153 -0
- package/lib/resolveOptions.js +234 -0
- package/lib/serializer.js +216 -0
- package/lib/serializerCore.browser.js +29 -0
- package/lib/serializerCore.js +16 -0
- package/lib/summarizeRequest.js +55 -0
- package/lib/types.js +35 -0
- package/lib/utils.js +160 -0
- package/lib/worker.js +170 -0
- package/package.json +59 -0
- package/src/AssetGraph.js +646 -0
- package/src/Atlaspack.js +632 -0
- package/src/AtlaspackConfig.js +490 -0
- package/src/AtlaspackConfig.schema.js +141 -0
- package/src/BundleGraph.js +2193 -0
- package/src/CommittedAsset.js +143 -0
- package/src/Dependency.js +142 -0
- package/src/Environment.js +151 -0
- package/src/InternalConfig.js +72 -0
- package/src/PackagerRunner.js +790 -0
- package/src/ReporterRunner.js +158 -0
- package/src/RequestTracker.js +1697 -0
- package/src/SymbolPropagation.js +794 -0
- package/src/TargetDescriptor.schema.js +136 -0
- package/src/Transformation.js +752 -0
- package/src/UncommittedAsset.js +426 -0
- package/src/Validation.js +223 -0
- package/src/applyRuntimes.js +341 -0
- package/src/assetUtils.js +254 -0
- package/src/atlaspack-v3/AtlaspackV3.js +73 -0
- package/src/atlaspack-v3/fs.js +36 -0
- package/src/atlaspack-v3/index.js +5 -0
- package/src/atlaspack-v3/jsCallable.js +13 -0
- package/src/atlaspack-v3/plugins/Resolver.js +9 -0
- package/src/atlaspack-v3/plugins/index.js +3 -0
- package/src/atlaspack-v3/worker/index.js +8 -0
- package/src/atlaspack-v3/worker/worker.js +14 -0
- package/src/buildCache.js +15 -0
- package/src/constants.js +22 -0
- package/src/dumpGraphToGraphViz.js +244 -0
- package/src/index.js +22 -0
- package/src/loadAtlaspackPlugin.js +239 -0
- package/src/loadDotEnv.js +56 -0
- package/src/projectPath.js +87 -0
- package/src/public/Asset.js +359 -0
- package/src/public/Bundle.js +337 -0
- package/src/public/BundleGraph.js +335 -0
- package/src/public/BundleGroup.js +55 -0
- package/src/public/Config.js +261 -0
- package/src/public/Dependency.js +176 -0
- package/src/public/Environment.js +316 -0
- package/src/public/MutableBundleGraph.js +320 -0
- package/src/public/PluginOptions.js +99 -0
- package/src/public/Symbols.js +315 -0
- package/src/public/Target.js +71 -0
- package/src/registerCoreWithSerializer.js +34 -0
- package/src/requests/AssetGraphRequest.js +577 -0
- package/src/requests/AssetGraphRequestRust.js +222 -0
- package/src/requests/AssetRequest.js +179 -0
- package/src/requests/AtlaspackBuildRequest.js +109 -0
- package/src/requests/AtlaspackConfigRequest.js +709 -0
- package/src/requests/BundleGraphRequest.js +547 -0
- package/src/requests/ConfigRequest.js +287 -0
- package/src/requests/DevDepRequest.js +246 -0
- package/src/requests/EntryRequest.js +385 -0
- package/src/requests/PackageRequest.js +105 -0
- package/src/requests/PathRequest.js +454 -0
- package/src/requests/TargetRequest.js +1632 -0
- package/src/requests/ValidationRequest.js +79 -0
- package/src/requests/WriteBundleRequest.js +362 -0
- package/src/requests/WriteBundlesRequest.js +209 -0
- package/src/resolveOptions.js +278 -0
- package/src/serializer.js +255 -0
- package/src/serializerCore.browser.js +8 -0
- package/src/serializerCore.js +5 -0
- package/src/summarizeRequest.js +47 -0
- package/src/types.js +581 -0
- package/src/utils.js +211 -0
- package/src/worker.js +189 -0
- package/test/AssetGraph.test.js +679 -0
- package/test/Atlaspack.test.js +142 -0
- package/test/AtlaspackConfig.test.js +405 -0
- package/test/AtlaspackConfigRequest.test.js +993 -0
- package/test/BundleGraph.test.js +121 -0
- package/test/EntryRequest.test.js +215 -0
- package/test/Environment.test.js +99 -0
- package/test/InternalAsset.test.js +76 -0
- package/test/PackagerRunner.test.js +27 -0
- package/test/PublicAsset.test.js +40 -0
- package/test/PublicBundle.test.js +68 -0
- package/test/PublicDependency.test.js +22 -0
- package/test/PublicEnvironment.test.js +27 -0
- package/test/PublicMutableBundleGraph.test.js +192 -0
- package/test/RequestTracker.test.js +448 -0
- package/test/SymbolPropagation.test.js +716 -0
- package/test/TargetRequest.test.js +1715 -0
- package/test/fixtures/application-targets/package.json +3 -0
- package/test/fixtures/atlaspack/index.js +1 -0
- package/test/fixtures/atlaspack/other.js +3 -0
- package/test/fixtures/atlaspack/package.json +1 -0
- package/test/fixtures/atlaspack/yarn.lock +0 -0
- package/test/fixtures/bundle.js +10 -0
- package/test/fixtures/common-targets/package.json +24 -0
- package/test/fixtures/common-targets-ignore/package.json +13 -0
- package/test/fixtures/config/.atlaspackrc +6 -0
- package/test/fixtures/config/subfolder/.atlaspackrc +6 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc +3 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc-json5 +3 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc-multiple +3 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc-node-modules +3 -0
- package/test/fixtures/config-malformed/.atlaspackrc +3 -0
- package/test/fixtures/config-node-pipeline/.atlaspackrc +6 -0
- package/test/fixtures/config-plugin-not-found/.atlaspackrc +6 -0
- package/test/fixtures/context/package.json +8 -0
- package/test/fixtures/custom-format-infer-ext/package.json +6 -0
- package/test/fixtures/custom-format-infer-type/package.json +7 -0
- package/test/fixtures/custom-format-mismatch/package.json +8 -0
- package/test/fixtures/custom-targets/package.json +20 -0
- package/test/fixtures/custom-targets-distdir/package.json +11 -0
- package/test/fixtures/duplicate-targets/package.json +4 -0
- package/test/fixtures/glob-like/[entry].js +0 -0
- package/test/fixtures/invalid-distpath/package.json +11 -0
- package/test/fixtures/invalid-engines/package.json +12 -0
- package/test/fixtures/invalid-source-missing/package.json +5 -0
- package/test/fixtures/invalid-source-not-file/package.json +5 -0
- package/test/fixtures/invalid-source-not-file/src/index.js +1 -0
- package/test/fixtures/invalid-target-source-missing/package.json +9 -0
- package/test/fixtures/invalid-target-source-not-file/package.json +9 -0
- package/test/fixtures/invalid-target-source-not-file/src/index.js +1 -0
- package/test/fixtures/invalid-targets/package.json +19 -0
- package/test/fixtures/library-custom-scopehoist/package.json +9 -0
- package/test/fixtures/library-scopehoist/package.json +8 -0
- package/test/fixtures/local-plugin-config-pkg/.atlaspackrc +3 -0
- package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/index.json +8 -0
- package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/local-plugin.js +7 -0
- package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/package.json +7 -0
- package/test/fixtures/main-format-mismatch/package.json +8 -0
- package/test/fixtures/main-global/package.json +8 -0
- package/test/fixtures/main-mjs/package.json +8 -0
- package/test/fixtures/module-a.js +1 -0
- package/test/fixtures/module-b.js +1 -0
- package/test/fixtures/plugins/local-plugin.js +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/index.js +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/package.json +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/index.js +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/package.json +4 -0
- package/test/fixtures/targets-default-distdir-none/package.json +5 -0
- package/test/fixtures/targets-default-distdir-one/package.json +8 -0
- package/test/fixtures/targets-default-distdir-two/package.json +18 -0
- package/test/requests/ConfigRequest.test.js +254 -0
- package/test/serializer.test.js +302 -0
- package/test/test-utils.js +80 -0
- package/test/utils.test.js +43 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import type {Async, FilePath, PackageJSON, Glob} from '@atlaspack/types';
|
|
4
|
+
import type {StaticRunOpts} from '../RequestTracker';
|
|
5
|
+
import type {Entry, InternalFile, AtlaspackOptions} from '../types';
|
|
6
|
+
import type {FileSystem} from '@atlaspack/fs';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
isDirectoryInside,
|
|
10
|
+
isGlob,
|
|
11
|
+
glob,
|
|
12
|
+
findAlternativeFiles,
|
|
13
|
+
} from '@atlaspack/utils';
|
|
14
|
+
import ThrowableDiagnostic, {
|
|
15
|
+
md,
|
|
16
|
+
generateJSONCodeHighlights,
|
|
17
|
+
getJSONSourceLocation,
|
|
18
|
+
} from '@atlaspack/diagnostic';
|
|
19
|
+
import path from 'path';
|
|
20
|
+
import {parse, type Mapping} from '@mischnic/json-sourcemap';
|
|
21
|
+
import {requestTypes} from '../RequestTracker';
|
|
22
|
+
import {
|
|
23
|
+
type ProjectPath,
|
|
24
|
+
fromProjectPath,
|
|
25
|
+
fromProjectPathRelative,
|
|
26
|
+
toProjectPath,
|
|
27
|
+
} from '../projectPath';
|
|
28
|
+
|
|
29
|
+
type RunOpts<TResult> = {|
|
|
30
|
+
input: ProjectPath,
|
|
31
|
+
...StaticRunOpts<TResult>,
|
|
32
|
+
|};
|
|
33
|
+
|
|
34
|
+
export type EntryRequest = {|
|
|
35
|
+
id: string,
|
|
36
|
+
+type: typeof requestTypes.entry_request,
|
|
37
|
+
run: (RunOpts<EntryRequestResult>) => Async<EntryRequestResult>,
|
|
38
|
+
input: ProjectPath,
|
|
39
|
+
|};
|
|
40
|
+
|
|
41
|
+
export type EntryRequestResult = {|
|
|
42
|
+
entries: Array<Entry>,
|
|
43
|
+
files: Array<InternalFile>,
|
|
44
|
+
globs: Array<Glob>,
|
|
45
|
+
|};
|
|
46
|
+
|
|
47
|
+
const type = 'entry_request';
|
|
48
|
+
|
|
49
|
+
export default function createEntryRequest(input: ProjectPath): EntryRequest {
|
|
50
|
+
return {
|
|
51
|
+
id: `${type}:${fromProjectPathRelative(input)}`,
|
|
52
|
+
type: requestTypes.entry_request,
|
|
53
|
+
run,
|
|
54
|
+
input,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function run({input, api, options}): Promise<EntryRequestResult> {
|
|
59
|
+
let entryResolver = new EntryResolver(options);
|
|
60
|
+
let filePath = fromProjectPath(options.projectRoot, input);
|
|
61
|
+
let result = await entryResolver.resolveEntry(filePath);
|
|
62
|
+
|
|
63
|
+
// Connect files like package.json that affect the entry
|
|
64
|
+
// resolution so we invalidate when they change.
|
|
65
|
+
for (let file of result.files) {
|
|
66
|
+
api.invalidateOnFileUpdate(file.filePath);
|
|
67
|
+
api.invalidateOnFileDelete(file.filePath);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// If the entry specifier is a glob, add a glob node so
|
|
71
|
+
// we invalidate when a new file matches.
|
|
72
|
+
for (let glob of result.globs) {
|
|
73
|
+
api.invalidateOnFileCreate({
|
|
74
|
+
glob: toProjectPath(options.projectRoot, glob),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Invalidate whenever an entry is deleted.
|
|
79
|
+
// If the entry was a glob, we'll re-evaluate it, and otherwise
|
|
80
|
+
// a proper entry error will be thrown.
|
|
81
|
+
for (let entry of result.entries) {
|
|
82
|
+
api.invalidateOnFileDelete(entry.filePath);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function assertFile(
|
|
89
|
+
fs: FileSystem,
|
|
90
|
+
entry: FilePath,
|
|
91
|
+
relativeSource: FilePath,
|
|
92
|
+
pkgFilePath: FilePath,
|
|
93
|
+
keyPath: string,
|
|
94
|
+
options: AtlaspackOptions,
|
|
95
|
+
) {
|
|
96
|
+
let source = path.join(entry, relativeSource);
|
|
97
|
+
let stat;
|
|
98
|
+
try {
|
|
99
|
+
stat = await fs.stat(source);
|
|
100
|
+
} catch (err) {
|
|
101
|
+
let contents = await fs.readFile(pkgFilePath, 'utf8');
|
|
102
|
+
let alternatives = await findAlternativeFiles(
|
|
103
|
+
fs,
|
|
104
|
+
relativeSource,
|
|
105
|
+
entry,
|
|
106
|
+
options.projectRoot,
|
|
107
|
+
false,
|
|
108
|
+
);
|
|
109
|
+
throw new ThrowableDiagnostic({
|
|
110
|
+
diagnostic: {
|
|
111
|
+
origin: '@atlaspack/core',
|
|
112
|
+
message: md`${path.relative(process.cwd(), source)} does not exist.`,
|
|
113
|
+
codeFrames: [
|
|
114
|
+
{
|
|
115
|
+
filePath: pkgFilePath,
|
|
116
|
+
codeHighlights: generateJSONCodeHighlights(contents, [
|
|
117
|
+
{
|
|
118
|
+
key: keyPath,
|
|
119
|
+
type: 'value',
|
|
120
|
+
},
|
|
121
|
+
]),
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
hints: alternatives.map(r => {
|
|
125
|
+
return md`Did you mean '__${r}__'?`;
|
|
126
|
+
}),
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!stat.isFile()) {
|
|
132
|
+
let contents = await fs.readFile(pkgFilePath, 'utf8');
|
|
133
|
+
throw new ThrowableDiagnostic({
|
|
134
|
+
diagnostic: {
|
|
135
|
+
origin: '@atlaspack/core',
|
|
136
|
+
message: md`${path.relative(process.cwd(), source)} is not a file.`,
|
|
137
|
+
codeFrames: [
|
|
138
|
+
{
|
|
139
|
+
filePath: pkgFilePath,
|
|
140
|
+
codeHighlights: generateJSONCodeHighlights(contents, [
|
|
141
|
+
{
|
|
142
|
+
key: keyPath,
|
|
143
|
+
type: 'value',
|
|
144
|
+
},
|
|
145
|
+
]),
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export class EntryResolver {
|
|
154
|
+
options: AtlaspackOptions;
|
|
155
|
+
|
|
156
|
+
constructor(options: AtlaspackOptions) {
|
|
157
|
+
this.options = options;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async resolveEntry(entry: FilePath): Promise<EntryRequestResult> {
|
|
161
|
+
let stat;
|
|
162
|
+
try {
|
|
163
|
+
stat = await this.options.inputFS.stat(entry);
|
|
164
|
+
} catch (err) {
|
|
165
|
+
if (!isGlob(entry)) {
|
|
166
|
+
throw new ThrowableDiagnostic({
|
|
167
|
+
diagnostic: {
|
|
168
|
+
message: md`Entry ${entry} does not exist`,
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
let files = await glob(entry, this.options.inputFS, {
|
|
173
|
+
absolute: true,
|
|
174
|
+
onlyFiles: false,
|
|
175
|
+
});
|
|
176
|
+
let results = await Promise.all(
|
|
177
|
+
files.map(f => this.resolveEntry(path.normalize(f))),
|
|
178
|
+
);
|
|
179
|
+
return results.reduce(
|
|
180
|
+
(p, res) => ({
|
|
181
|
+
entries: p.entries.concat(res.entries),
|
|
182
|
+
files: p.files.concat(res.files),
|
|
183
|
+
globs: p.globs.concat(res.globs),
|
|
184
|
+
}),
|
|
185
|
+
{entries: [], files: [], globs: [entry]},
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (stat.isDirectory()) {
|
|
190
|
+
let pkg = await this.readPackage(entry);
|
|
191
|
+
|
|
192
|
+
if (pkg) {
|
|
193
|
+
let {filePath} = pkg;
|
|
194
|
+
let entries = [];
|
|
195
|
+
let files = [
|
|
196
|
+
{
|
|
197
|
+
filePath: toProjectPath(this.options.projectRoot, filePath),
|
|
198
|
+
},
|
|
199
|
+
];
|
|
200
|
+
let globs = [];
|
|
201
|
+
|
|
202
|
+
let targetsWithSources = 0;
|
|
203
|
+
if (pkg.targets) {
|
|
204
|
+
for (let targetName in pkg.targets) {
|
|
205
|
+
let target = pkg.targets[targetName];
|
|
206
|
+
if (target.source != null) {
|
|
207
|
+
targetsWithSources++;
|
|
208
|
+
let targetSources = Array.isArray(target.source)
|
|
209
|
+
? target.source
|
|
210
|
+
: [target.source];
|
|
211
|
+
let i = 0;
|
|
212
|
+
for (let source of targetSources) {
|
|
213
|
+
let sources;
|
|
214
|
+
if (isGlob(source)) {
|
|
215
|
+
globs.push(source);
|
|
216
|
+
sources = await glob(source, this.options.inputFS, {
|
|
217
|
+
onlyFiles: true,
|
|
218
|
+
cwd: entry,
|
|
219
|
+
});
|
|
220
|
+
} else {
|
|
221
|
+
sources = [source];
|
|
222
|
+
}
|
|
223
|
+
let keyPath = `/targets/${targetName}/source${
|
|
224
|
+
Array.isArray(target.source) ? `/${i}` : ''
|
|
225
|
+
}`;
|
|
226
|
+
for (let relativeSource of sources) {
|
|
227
|
+
let source = path.join(entry, relativeSource);
|
|
228
|
+
await assertFile(
|
|
229
|
+
this.options.inputFS,
|
|
230
|
+
entry,
|
|
231
|
+
relativeSource,
|
|
232
|
+
filePath,
|
|
233
|
+
keyPath,
|
|
234
|
+
this.options,
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
entries.push({
|
|
238
|
+
filePath: toProjectPath(this.options.projectRoot, source),
|
|
239
|
+
packagePath: toProjectPath(this.options.projectRoot, entry),
|
|
240
|
+
target: targetName,
|
|
241
|
+
loc: {
|
|
242
|
+
filePath: toProjectPath(
|
|
243
|
+
this.options.projectRoot,
|
|
244
|
+
pkg.filePath,
|
|
245
|
+
),
|
|
246
|
+
...getJSONSourceLocation(
|
|
247
|
+
pkg.map.pointers[keyPath],
|
|
248
|
+
'value',
|
|
249
|
+
),
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
i++;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
let allTargetsHaveSource =
|
|
260
|
+
targetsWithSources > 0 &&
|
|
261
|
+
pkg != null &&
|
|
262
|
+
pkg.targets != null &&
|
|
263
|
+
Object.keys(pkg.targets).length === targetsWithSources;
|
|
264
|
+
|
|
265
|
+
if (!allTargetsHaveSource && pkg.source != null) {
|
|
266
|
+
let pkgSources = Array.isArray(pkg.source)
|
|
267
|
+
? pkg.source
|
|
268
|
+
: [pkg.source];
|
|
269
|
+
let i = 0;
|
|
270
|
+
for (let pkgSource of pkgSources) {
|
|
271
|
+
let sources;
|
|
272
|
+
if (isGlob(pkgSource)) {
|
|
273
|
+
globs.push(pkgSource);
|
|
274
|
+
sources = await glob(pkgSource, this.options.inputFS, {
|
|
275
|
+
onlyFiles: true,
|
|
276
|
+
cwd: path.dirname(filePath),
|
|
277
|
+
});
|
|
278
|
+
} else {
|
|
279
|
+
sources = [pkgSource];
|
|
280
|
+
}
|
|
281
|
+
let keyPath = `/source${Array.isArray(pkg.source) ? `/${i}` : ''}`;
|
|
282
|
+
for (let relativeSource of sources) {
|
|
283
|
+
let source = path.join(path.dirname(filePath), relativeSource);
|
|
284
|
+
await assertFile(
|
|
285
|
+
this.options.inputFS,
|
|
286
|
+
entry,
|
|
287
|
+
relativeSource,
|
|
288
|
+
filePath,
|
|
289
|
+
keyPath,
|
|
290
|
+
this.options,
|
|
291
|
+
);
|
|
292
|
+
entries.push({
|
|
293
|
+
filePath: toProjectPath(this.options.projectRoot, source),
|
|
294
|
+
packagePath: toProjectPath(this.options.projectRoot, entry),
|
|
295
|
+
loc: {
|
|
296
|
+
filePath: toProjectPath(
|
|
297
|
+
this.options.projectRoot,
|
|
298
|
+
pkg.filePath,
|
|
299
|
+
),
|
|
300
|
+
...getJSONSourceLocation(pkg.map.pointers[keyPath], 'value'),
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
i++;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Only return if we found any valid entries
|
|
309
|
+
if (entries.length && files.length) {
|
|
310
|
+
return {
|
|
311
|
+
entries,
|
|
312
|
+
files,
|
|
313
|
+
globs,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
throw new ThrowableDiagnostic({
|
|
319
|
+
diagnostic: {
|
|
320
|
+
message: md`Could not find entry: ${entry}`,
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
} else if (stat.isFile()) {
|
|
324
|
+
let projectRoot = this.options.projectRoot;
|
|
325
|
+
let packagePath = isDirectoryInside(
|
|
326
|
+
this.options.inputFS.cwd(),
|
|
327
|
+
projectRoot,
|
|
328
|
+
)
|
|
329
|
+
? this.options.inputFS.cwd()
|
|
330
|
+
: projectRoot;
|
|
331
|
+
|
|
332
|
+
return {
|
|
333
|
+
entries: [
|
|
334
|
+
{
|
|
335
|
+
filePath: toProjectPath(this.options.projectRoot, entry),
|
|
336
|
+
packagePath: toProjectPath(this.options.projectRoot, packagePath),
|
|
337
|
+
},
|
|
338
|
+
],
|
|
339
|
+
files: [],
|
|
340
|
+
globs: [],
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
throw new ThrowableDiagnostic({
|
|
345
|
+
diagnostic: {
|
|
346
|
+
message: md`Unknown entry: ${entry}`,
|
|
347
|
+
},
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
async readPackage(entry: FilePath): Promise<?{
|
|
352
|
+
...PackageJSON,
|
|
353
|
+
filePath: FilePath,
|
|
354
|
+
map: {|data: mixed, pointers: {|[string]: Mapping|}|},
|
|
355
|
+
...
|
|
356
|
+
}> {
|
|
357
|
+
let content, pkg;
|
|
358
|
+
let pkgFile = path.join(entry, 'package.json');
|
|
359
|
+
try {
|
|
360
|
+
content = await this.options.inputFS.readFile(pkgFile, 'utf8');
|
|
361
|
+
} catch (err) {
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
try {
|
|
366
|
+
pkg = JSON.parse(content);
|
|
367
|
+
} catch (err) {
|
|
368
|
+
// TODO: code frame?
|
|
369
|
+
throw new ThrowableDiagnostic({
|
|
370
|
+
diagnostic: {
|
|
371
|
+
message: md`Error parsing ${path.relative(
|
|
372
|
+
this.options.inputFS.cwd(),
|
|
373
|
+
pkgFile,
|
|
374
|
+
)}: ${err.message}`,
|
|
375
|
+
},
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return {
|
|
380
|
+
...pkg,
|
|
381
|
+
filePath: pkgFile,
|
|
382
|
+
map: parse(content, undefined, {tabWidth: 1}),
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import type {ContentKey} from '@atlaspack/graph';
|
|
4
|
+
import type {Async} from '@atlaspack/types';
|
|
5
|
+
import type {SharedReference} from '@atlaspack/workers';
|
|
6
|
+
|
|
7
|
+
import type {StaticRunOpts} from '../RequestTracker';
|
|
8
|
+
import {requestTypes} from '../RequestTracker';
|
|
9
|
+
import type {Bundle} from '../types';
|
|
10
|
+
import type BundleGraph from '../BundleGraph';
|
|
11
|
+
import type {BundleInfo, RunPackagerRunnerResult} from '../PackagerRunner';
|
|
12
|
+
import type {ConfigAndCachePath} from './AtlaspackConfigRequest';
|
|
13
|
+
|
|
14
|
+
import nullthrows from 'nullthrows';
|
|
15
|
+
import {runConfigRequest} from './ConfigRequest';
|
|
16
|
+
import {getDevDepRequests, runDevDepRequest} from './DevDepRequest';
|
|
17
|
+
import createAtlaspackConfigRequest from './AtlaspackConfigRequest';
|
|
18
|
+
|
|
19
|
+
type PackageRequestInput = {|
|
|
20
|
+
bundleGraph: BundleGraph,
|
|
21
|
+
bundle: Bundle,
|
|
22
|
+
bundleGraphReference: SharedReference,
|
|
23
|
+
optionsRef: SharedReference,
|
|
24
|
+
useMainThread?: boolean,
|
|
25
|
+
|};
|
|
26
|
+
|
|
27
|
+
export type PackageRequestResult = BundleInfo;
|
|
28
|
+
|
|
29
|
+
type RunInput<TResult> = {|
|
|
30
|
+
input: PackageRequestInput,
|
|
31
|
+
...StaticRunOpts<TResult>,
|
|
32
|
+
|};
|
|
33
|
+
|
|
34
|
+
export type PackageRequest = {|
|
|
35
|
+
id: ContentKey,
|
|
36
|
+
+type: typeof requestTypes.package_request,
|
|
37
|
+
run: (RunInput<BundleInfo>) => Async<BundleInfo>,
|
|
38
|
+
input: PackageRequestInput,
|
|
39
|
+
|};
|
|
40
|
+
|
|
41
|
+
export function createPackageRequest(
|
|
42
|
+
input: PackageRequestInput,
|
|
43
|
+
): PackageRequest {
|
|
44
|
+
return {
|
|
45
|
+
type: requestTypes.package_request,
|
|
46
|
+
id: input.bundleGraph.getHash(input.bundle),
|
|
47
|
+
run,
|
|
48
|
+
input,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function run({input, api, farm}) {
|
|
53
|
+
let {bundleGraphReference, optionsRef, bundle, useMainThread} = input;
|
|
54
|
+
let runPackage = farm.createHandle('runPackage', useMainThread);
|
|
55
|
+
|
|
56
|
+
let start = Date.now();
|
|
57
|
+
let {devDeps, invalidDevDeps} = await getDevDepRequests(api);
|
|
58
|
+
let {cachePath} = nullthrows(
|
|
59
|
+
await api.runRequest<null, ConfigAndCachePath>(
|
|
60
|
+
createAtlaspackConfigRequest(),
|
|
61
|
+
),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
let {devDepRequests, configRequests, bundleInfo, invalidations} =
|
|
65
|
+
(await runPackage({
|
|
66
|
+
bundle,
|
|
67
|
+
bundleGraphReference,
|
|
68
|
+
optionsRef,
|
|
69
|
+
configCachePath: cachePath,
|
|
70
|
+
previousDevDeps: devDeps,
|
|
71
|
+
invalidDevDeps,
|
|
72
|
+
previousInvalidations: api.getInvalidations(),
|
|
73
|
+
}): RunPackagerRunnerResult);
|
|
74
|
+
|
|
75
|
+
for (let devDepRequest of devDepRequests) {
|
|
76
|
+
await runDevDepRequest(api, devDepRequest);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
for (let configRequest of configRequests) {
|
|
80
|
+
await runConfigRequest(api, configRequest);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for (let invalidation of invalidations) {
|
|
84
|
+
switch (invalidation.type) {
|
|
85
|
+
case 'file':
|
|
86
|
+
api.invalidateOnFileUpdate(invalidation.filePath);
|
|
87
|
+
api.invalidateOnFileDelete(invalidation.filePath);
|
|
88
|
+
break;
|
|
89
|
+
case 'env':
|
|
90
|
+
api.invalidateOnEnvChange(invalidation.key);
|
|
91
|
+
break;
|
|
92
|
+
case 'option':
|
|
93
|
+
api.invalidateOnOptionChange(invalidation.key);
|
|
94
|
+
break;
|
|
95
|
+
default:
|
|
96
|
+
throw new Error(`Unknown invalidation type: ${invalidation.type}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// $FlowFixMe[cannot-write] time is marked read-only, but this is the exception
|
|
101
|
+
bundleInfo.time = Date.now() - start;
|
|
102
|
+
|
|
103
|
+
api.storeResult(bundleInfo);
|
|
104
|
+
return bundleInfo;
|
|
105
|
+
}
|