Skip to content

Commit

Permalink
Build Atom with Parcel
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Aug 18, 2021
1 parent e8296e4 commit 31af14a
Show file tree
Hide file tree
Showing 6 changed files with 9,424 additions and 2,269 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ spec/fixtures/evil-files/
!spec/fixtures/packages/package-with-incompatible-native-module-loaded-conditionally/node_modules/
out/
/electron/
.parcel-cache
105 changes: 105 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,111 @@
"preinstall": "node -e 'process.exit(0)'",
"test": "node script/test"
},
"engines": {
"electron": "9.4.4"
},
"main-target": "./out/app/src/main-process/main.bundle.js",
"start-target": "./out/app/src/main-process/start.bundle.js",
"application-target": "./out/app/src/main-process/atom-application.bundle.js",
"initialize-target": "./out/app/src/initialize-application-window.bundle.js",
"targets": {
"main-target": {
"source": "./out/app/src/main-process/main.js",
"context": "electron-main",
"includeNodeModules": {
"electron": false,
"y18n": false
}
},
"start-target": {
"source": "./out/app/src/main-process/start.js",
"context": "electron-main",
"includeNodeModules": {
"electron": false,
"nslog": false,
"y18n": false,
"coffee-script": false
}
},
"application-target": {
"source": "./out/app/src/main-process/atom-application.js",
"context": "electron-renderer",
"includeNodeModules": {
"electron": false,
"atom": false,
"pathwatcher": false,
"@atom/nsfw": false,
"@atom/watcher": false,
"fs-admin": false,
"git-utils": false,
"oniguruma": false,
"superstring": false,
"coffee-script": false
}
},
"initialize-target": {
"source": "./out/app/src/initialize-application-window.js",
"context": "electron-renderer",
"includeNodeModules": {
"electron": false,
"atom": false,
"pathwatcher": false,
"@atom/nsfw": false,
"@atom/watcher": false,
"fs-admin": false,
"git-utils": false,
"oniguruma": false,
"superstring": false,
"keybinding-resolver": false,
"keytar": false,
"loophole": false,
"pegjs": false,
"@atom/fuzzy-native": false,
"scrollbar-style": false,
"spellchecker": false,
"ctags": false,
"keyboard-layout": false,
"open-on-github": false,
"babel-core": false,
"natural": false,
"xregexp": false,
"dugite": false,
"yaml-front-matter": false,
"cheerio": false,
"marked": false,
"typescript-simple": false,
"typescript": false,
"coffee-script": false,
"fs-extra": false,
"graceful-fs": false,
"htmlparser2": false,
"minimatch": false,
"request": false,
"temp": false,
"parse5": false,
"atom-keymap": false,
"debug": false,
"glob": false,
"iconv-lite": false,
"less": false,
"less-node": false,
"lodash.isequal": false,
"node-fetch": false,
"resolve": false,
"tar": false,
"tmp": false,
"tree_sitter": false,
"yauzl": false,
"util-deprecate": false,
"winreg": false,
"scandal": false,
"vscode-ripgrep": false
}
}
},
"alias": {
"react-dom": "react-dom/cjs/react-dom.production.min.js"
},
"standard-engine": "./script/node_modules/standard",
"standard": {
"env": {
Expand Down
41 changes: 41 additions & 0 deletions script/lib/generate-startup-snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,46 @@ const terser = require('terser');
const CONFIG = require('../config');

module.exports = function(packagedAppPath) {
console.log('Bundling with Parcel');
const parcel = childProcess.spawnSync(
process.execPath,
[
path.join(
CONFIG.repositoryRootPath,
'script',
'node_modules',
'parcel',
'lib',
'bin.js'
),
'build',
CONFIG.repositoryRootPath,
'--detailed-report'
],
{ stdio: 'inherit' }
);
if (parcel.stderr) {
console.error(parcel.stderr);
}
// replace bundles with the source
[
path.join(CONFIG.intermediateAppPath, 'src/main-process/main.bundle.js'),
path.join(CONFIG.intermediateAppPath, 'src/main-process/start.bundle.js'),
path.join(
CONFIG.intermediateAppPath,
'src/main-process/atom-application.bundle.js'
),
path.join(
CONFIG.intermediateAppPath,
'src/initialize-application-window.bundle.js'
)
].map(bundleFile => {
const sourceFile = bundleFile.replace('.bundle.js', '.js');
fs.unlinkSync(sourceFile);
fs.renameSync(bundleFile, sourceFile);
fs.renameSync(bundleFile + '.map', sourceFile + '.map');
});

const snapshotScriptPath = path.join(CONFIG.buildOutputPath, 'startup.js');
const coreModules = new Set([
'electron',
Expand Down Expand Up @@ -47,6 +87,7 @@ module.exports = function(packagedAppPath) {
return (
requiredModulePath.endsWith('.node') ||
coreModules.has(requiredModulePath) ||
requiringModuleRelativePath.includes('node_modules') || // exclude node_modules
requiringModuleRelativePath.endsWith(
path.join('node_modules/xregexp/xregexp-all.js')
) ||
Expand Down
Loading

0 comments on commit 31af14a

Please sign in to comment.