config.js
11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getConfig = getConfig;
exports.doMergeConfigs = doMergeConfigs;
exports.validateConfig = validateConfig;
exports.computeDefaultAppDirectory = computeDefaultAppDirectory;
function _builderUtil() {
const data = require("builder-util");
_builderUtil = function () {
return data;
};
return data;
}
function _fs() {
const data = require("builder-util/out/fs");
_fs = function () {
return data;
};
return data;
}
function _fsExtra() {
const data = require("fs-extra");
_fsExtra = function () {
return data;
};
return data;
}
function _lazyVal() {
const data = require("lazy-val");
_lazyVal = function () {
return data;
};
return data;
}
var path = _interopRequireWildcard(require("path"));
function _readConfigFile() {
const data = require("read-config-file");
_readConfigFile = function () {
return data;
};
return data;
}
function _rectCra() {
const data = require("../presets/rectCra");
_rectCra = function () {
return data;
};
return data;
}
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
// eslint-disable-next-line @typescript-eslint/no-var-requires
const validateSchema = require("@develar/schema-utils"); // https://github.com/electron-userland/electron-builder/issues/1847
function mergePublish(config, configFromOptions) {
// if config from disk doesn't have publish (or object), no need to handle, it will be simply merged by deepAssign
const publish = Array.isArray(config.publish) ? configFromOptions.publish : null;
if (publish != null) {
delete configFromOptions.publish;
}
(0, _builderUtil().deepAssign)(config, configFromOptions);
if (publish == null) {
return;
}
const listOnDisk = config.publish;
if (listOnDisk.length === 0) {
config.publish = publish;
} else {
// apply to first
Object.assign(listOnDisk[0], publish);
}
}
async function getConfig(projectDir, configPath, configFromOptions, packageMetadata = new (_lazyVal().Lazy)(() => (0, _readConfigFile().orNullIfFileNotExist)((0, _fsExtra().readJson)(path.join(projectDir, "package.json"))))) {
const configRequest = {
packageKey: "build",
configFilename: "electron-builder",
projectDir,
packageMetadata
};
const configAndEffectiveFile = await (0, _readConfigFile().getConfig)(configRequest, configPath);
const config = configAndEffectiveFile == null ? {} : configAndEffectiveFile.result;
if (configFromOptions != null) {
mergePublish(config, configFromOptions);
}
if (configAndEffectiveFile != null) {
_builderUtil().log.info({
file: configAndEffectiveFile.configFile == null ? 'package.json ("build" field)' : configAndEffectiveFile.configFile
}, "loaded configuration");
}
if (config.extends == null && config.extends !== null) {
const metadata = (await packageMetadata.value) || {};
const devDependencies = metadata.devDependencies;
const dependencies = metadata.dependencies;
if (dependencies != null && "react-scripts" in dependencies || devDependencies != null && "react-scripts" in devDependencies) {
config.extends = "react-cra";
} else if (devDependencies != null && "electron-webpack" in devDependencies) {
let file = "electron-webpack/out/electron-builder.js";
try {
file = require.resolve(file);
} catch (ignore) {
file = require.resolve("electron-webpack/electron-builder.yml");
}
config.extends = `file:${file}`;
}
}
let parentConfig;
if (config.extends === "react-cra") {
parentConfig = await (0, _rectCra().reactCra)(projectDir);
_builderUtil().log.info({
preset: config.extends
}, "loaded parent configuration");
} else if (config.extends != null) {
const parentConfigAndEffectiveFile = await (0, _readConfigFile().loadParentConfig)(configRequest, config.extends);
_builderUtil().log.info({
file: parentConfigAndEffectiveFile.configFile
}, "loaded parent configuration");
parentConfig = parentConfigAndEffectiveFile.result;
} else {
parentConfig = null;
}
return doMergeConfigs(config, parentConfig);
} // normalize for easy merge
function normalizeFiles(configuration, name) {
let value = configuration[name];
if (value == null) {
return;
}
if (!Array.isArray(value)) {
value = [value];
}
itemLoop: for (let i = 0; i < value.length; i++) {
let item = value[i];
if (typeof item === "string") {
// merge with previous if possible
if (i !== 0) {
let prevItemIndex = i - 1;
let prevItem;
do {
prevItem = value[prevItemIndex--];
} while (prevItem == null);
if (prevItem.from == null && prevItem.to == null) {
if (prevItem.filter == null) {
prevItem.filter = [item];
} else {
prevItem.filter.push(item);
}
value[i] = null;
continue itemLoop;
}
}
item = {
filter: [item]
};
value[i] = item;
} else if (Array.isArray(item)) {
throw new Error(`${name} configuration is invalid, nested array not expected for index ${i}: ` + item);
} // make sure that merge logic is not complex - unify different presentations
if (item.from === ".") {
item.from = undefined;
}
if (item.to === ".") {
item.to = undefined;
}
if (item.filter != null && typeof item.filter === "string") {
item.filter = [item.filter];
}
}
configuration[name] = value.filter(it => it != null);
}
function mergeFiles(configuration, parentConfiguration, mergedConfiguration, name) {
const list = configuration[name];
const parentList = parentConfiguration[name];
if (list == null || parentList == null) {
return;
}
const result = list.slice();
mergedConfiguration[name] = result;
itemLoop: for (const item of parentConfiguration.files) {
for (const existingItem of list) {
if (existingItem.from === item.from && existingItem.to === item.to) {
if (item.filter != null) {
if (existingItem.filter == null) {
existingItem.filter = item.filter.slice();
} else {
existingItem.filter = item.filter.concat(existingItem.filter);
}
}
continue itemLoop;
}
} // existing item not found, simply add
result.push(item);
}
}
function doMergeConfigs(configuration, parentConfiguration) {
normalizeFiles(configuration, "files");
normalizeFiles(configuration, "extraFiles");
normalizeFiles(configuration, "extraResources");
if (parentConfiguration == null) {
return (0, _builderUtil().deepAssign)(getDefaultConfig(), configuration);
}
normalizeFiles(parentConfiguration, "files");
normalizeFiles(parentConfiguration, "extraFiles");
normalizeFiles(parentConfiguration, "extraResources");
const result = (0, _builderUtil().deepAssign)(getDefaultConfig(), parentConfiguration, configuration);
mergeFiles(configuration, parentConfiguration, result, "files");
return result;
}
function getDefaultConfig() {
return {
directories: {
output: "dist",
buildResources: "build"
}
};
}
const schemeDataPromise = new (_lazyVal().Lazy)(() => (0, _fsExtra().readJson)(path.join(__dirname, "..", "..", "scheme.json")));
async function validateConfig(config, debugLogger) {
const extraMetadata = config.extraMetadata;
if (extraMetadata != null) {
if (extraMetadata.build != null) {
throw new (_builderUtil().InvalidConfigurationError)(`--em.build is deprecated, please specify as -c"`);
}
if (extraMetadata.directories != null) {
throw new (_builderUtil().InvalidConfigurationError)(`--em.directories is deprecated, please specify as -c.directories"`);
}
}
const oldConfig = config;
if (oldConfig.npmSkipBuildFromSource === false) {
throw new (_builderUtil().InvalidConfigurationError)(`npmSkipBuildFromSource is deprecated, please use buildDependenciesFromSource"`);
}
if (oldConfig.appImage != null && oldConfig.appImage.systemIntegration != null) {
throw new (_builderUtil().InvalidConfigurationError)(`appImage.systemIntegration is deprecated, https://github.com/TheAssassin/AppImageLauncher is used for desktop integration"`);
} // noinspection JSUnusedGlobalSymbols
validateSchema(await schemeDataPromise.value, config, {
name: `electron-builder ${"22.10.5"}`,
postFormatter: (formattedError, error) => {
if (debugLogger.isEnabled) {
debugLogger.add("invalidConfig", (0, _builderUtil().safeStringifyJson)(error));
}
const site = "https://www.electron.build";
let url = `${site}/configuration/configuration`;
const targets = new Set(["mac", "dmg", "pkg", "mas", "win", "nsis", "appx", "linux", "appimage", "snap"]);
const dataPath = error.dataPath == null ? null : error.dataPath;
const targetPath = dataPath.startsWith(".") ? dataPath.substr(1).toLowerCase() : null;
if (targetPath != null && targets.has(targetPath)) {
url = `${site}/configuration/${targetPath}`;
}
return `${formattedError}\n How to fix:
1. Open ${url}
2. Search the option name on the page (or type in into Search to find across the docs).
* Not found? The option was deprecated or not exists (check spelling).
* Found? Check that the option in the appropriate place. e.g. "title" only in the "dmg", not in the root.
`;
}
});
}
const DEFAULT_APP_DIR_NAMES = ["app", "www"];
async function computeDefaultAppDirectory(projectDir, userAppDir) {
if (userAppDir != null) {
const absolutePath = path.resolve(projectDir, userAppDir);
const stat = await (0, _fs().statOrNull)(absolutePath);
if (stat == null) {
throw new (_builderUtil().InvalidConfigurationError)(`Application directory ${userAppDir} doesn't exist`);
} else if (!stat.isDirectory()) {
throw new (_builderUtil().InvalidConfigurationError)(`Application directory ${userAppDir} is not a directory`);
} else if (projectDir === absolutePath) {
_builderUtil().log.warn({
appDirectory: userAppDir
}, `Specified application directory equals to project dir — superfluous or wrong configuration`);
}
return absolutePath;
}
for (const dir of DEFAULT_APP_DIR_NAMES) {
const absolutePath = path.join(projectDir, dir);
const packageJson = path.join(absolutePath, "package.json");
const stat = await (0, _fs().statOrNull)(packageJson);
if (stat != null && stat.isFile()) {
return absolutePath;
}
}
return projectDir;
}
// __ts-babel@6.0.4
//# sourceMappingURL=config.js.map