Skip to content

Commit 34d80aa

Browse files
committed
build: build Atom with Parcel
1 parent 76bd67d commit 34d80aa

File tree

6 files changed

+2178
-19
lines changed

6 files changed

+2178
-19
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ spec/fixtures/evil-files/
1919
!spec/fixtures/packages/package-with-incompatible-native-module-loaded-conditionally/node_modules/
2020
out/
2121
/electron/
22+
.parcel-cache

package.json

+105
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,111 @@
273273
"preinstall": "node -e 'process.exit(0)'",
274274
"test": "node script/test"
275275
},
276+
"engines": {
277+
"electron": "9.4.4"
278+
},
279+
"main-target": "./out/app/src/main-process/main.bundle.js",
280+
"start-target": "./out/app/src/main-process/start.bundle.js",
281+
"application-target": "./out/app/src/main-process/atom-application.bundle.js",
282+
"initialize-target": "./out/app/src/initialize-application-window.bundle.js",
283+
"targets": {
284+
"main-target": {
285+
"source": "./out/app/src/main-process/main.js",
286+
"context": "electron-main",
287+
"includeNodeModules": {
288+
"electron": false,
289+
"y18n": false
290+
}
291+
},
292+
"start-target": {
293+
"source": "./out/app/src/main-process/start.js",
294+
"context": "electron-main",
295+
"includeNodeModules": {
296+
"electron": false,
297+
"nslog": false,
298+
"y18n": false,
299+
"coffee-script": false
300+
}
301+
},
302+
"application-target": {
303+
"source": "./out/app/src/main-process/atom-application.js",
304+
"context": "electron-renderer",
305+
"includeNodeModules": {
306+
"electron": false,
307+
"atom": false,
308+
"pathwatcher": false,
309+
"@atom/nsfw": false,
310+
"@atom/watcher": false,
311+
"fs-admin": false,
312+
"git-utils": false,
313+
"oniguruma": false,
314+
"superstring": false,
315+
"coffee-script": false
316+
}
317+
},
318+
"initialize-target": {
319+
"source": "./out/app/src/initialize-application-window.js",
320+
"context": "electron-renderer",
321+
"includeNodeModules": {
322+
"electron": false,
323+
"atom": false,
324+
"pathwatcher": false,
325+
"@atom/nsfw": false,
326+
"@atom/watcher": false,
327+
"fs-admin": false,
328+
"git-utils": false,
329+
"oniguruma": false,
330+
"superstring": false,
331+
"keybinding-resolver": false,
332+
"keytar": false,
333+
"loophole": false,
334+
"pegjs": false,
335+
"@atom/fuzzy-native": false,
336+
"scrollbar-style": false,
337+
"spellchecker": false,
338+
"ctags": false,
339+
"keyboard-layout": false,
340+
"open-on-github": false,
341+
"babel-core": false,
342+
"natural": false,
343+
"xregexp": false,
344+
"dugite": false,
345+
"yaml-front-matter": false,
346+
"cheerio": false,
347+
"marked": false,
348+
"typescript-simple": false,
349+
"typescript": false,
350+
"coffee-script": false,
351+
"fs-extra": false,
352+
"graceful-fs": false,
353+
"htmlparser2": false,
354+
"minimatch": false,
355+
"request": false,
356+
"temp": false,
357+
"parse5": false,
358+
"atom-keymap": false,
359+
"debug": false,
360+
"glob": false,
361+
"iconv-lite": false,
362+
"less": false,
363+
"less-node": false,
364+
"lodash.isequal": false,
365+
"node-fetch": false,
366+
"resolve": false,
367+
"tar": false,
368+
"tmp": false,
369+
"tree_sitter": false,
370+
"yauzl": false,
371+
"util-deprecate": false,
372+
"winreg": false,
373+
"scandal": false,
374+
"vscode-ripgrep": false
375+
}
376+
}
377+
},
378+
"alias": {
379+
"react-dom": "react-dom/cjs/react-dom.production.min.js"
380+
},
276381
"standard-engine": "./script/node_modules/standard",
277382
"standard": {
278383
"env": {

script/lib/generate-startup-snapshot.js

+41
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,46 @@ const terser = require('terser');
66
const CONFIG = require('../config');
77

88
module.exports = function(packagedAppPath) {
9+
console.log('Bundling with Parcel');
10+
const parcel = childProcess.spawnSync(
11+
process.execPath,
12+
[
13+
path.join(
14+
CONFIG.repositoryRootPath,
15+
'script',
16+
'node_modules',
17+
'parcel',
18+
'lib',
19+
'bin.js'
20+
),
21+
'build',
22+
CONFIG.repositoryRootPath,
23+
'--detailed-report'
24+
],
25+
{ stdio: 'inherit' }
26+
);
27+
if (parcel.stderr) {
28+
console.error(parcel.stderr);
29+
}
30+
// replace bundles with the source
31+
[
32+
path.join(CONFIG.intermediateAppPath, 'src/main-process/main.bundle.js'),
33+
path.join(CONFIG.intermediateAppPath, 'src/main-process/start.bundle.js'),
34+
path.join(
35+
CONFIG.intermediateAppPath,
36+
'src/main-process/atom-application.bundle.js'
37+
),
38+
path.join(
39+
CONFIG.intermediateAppPath,
40+
'src/initialize-application-window.bundle.js'
41+
)
42+
].map(bundleFile => {
43+
const sourceFile = bundleFile.replace('.bundle.js', '.js');
44+
fs.unlinkSync(sourceFile);
45+
fs.renameSync(bundleFile, sourceFile);
46+
fs.renameSync(bundleFile + '.map', sourceFile + '.map');
47+
});
48+
949
const snapshotScriptPath = path.join(CONFIG.buildOutputPath, 'startup.js');
1050
const coreModules = new Set([
1151
'electron',
@@ -47,6 +87,7 @@ module.exports = function(packagedAppPath) {
4787
return (
4888
requiredModulePath.endsWith('.node') ||
4989
coreModules.has(requiredModulePath) ||
90+
requiringModuleRelativePath.includes('node_modules') || // exclude node_modules
5091
requiringModuleRelativePath.endsWith(
5192
path.join('node_modules/xregexp/xregexp-all.js')
5293
) ||

0 commit comments

Comments
 (0)