Verified Commit c3c2aaab authored by staltz's avatar staltz
Browse files

use esbuild: work in progress

parent e6e64443
......@@ -10364,6 +10364,18 @@
"resolved": "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz",
"integrity": "sha1-wsNYJlYkfDnqEHyx5mUrb58kUjw="
},
"esbuild": {
"version": "0.8.51",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.8.51.tgz",
"integrity": "sha512-MVIom8fgL1+B6iGqWtrG7QJ1gqd64BycxounlsX1kR/IcIITaSlTo7gghKpg4a+bnxkpo0dwcikuvk4MVSA9ww==",
"dev": true
},
"esbuild-plugin-alias": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/esbuild-plugin-alias/-/esbuild-plugin-alias-0.1.2.tgz",
"integrity": "sha512-WsX0OJy8IGOsGZV+4oHEU5B6XQUpxOsZN1iSoYf9COTDbY7WXcOwd1oCLYNWUIWCExyGXSghIGq2k7sXBldxwQ==",
"dev": true
},
"escape-html": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
......
......@@ -67,8 +67,7 @@
},
"devDependencies": {
"license-ls": "~1.4.1",
"noderify": "4.3.0",
"patch-package": "6.2.2",
"terser": "4.3.8"
"esbuild": "0.8.51",
"patch-package": "6.2.2"
}
}
#!/usr/bin/env node
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const path = require('path');
const esbuild = require('esbuild');
const alias = require('esbuild-plugin-alias');
const projectPath = process.cwd();
const nodejsProjectPath = `${projectPath}/desktop/nodejs-project`;
const to = (name, file = 'index.js') =>
path.resolve(nodejsProjectPath, 'node_modules', name, file);
esbuild
.build({
entryPoints: [`${nodejsProjectPath}/index.js`],
outfile: `${nodejsProjectPath}/_esbuilt.js`,
bundle: true,
platform: 'node',
target: ['es2019', 'chrome85', 'node12.16.0'],
// metafile: `${nodejsProjectPath}/meta.json`,
minifySyntax: true,
external: [
'electron', // we want to load its native bindings
'rn-bridge', // not used on desktop, it's specific to mobile
'multiserver-rn-channel', // not used on desktop, it's specific to mobile
'bufferutil', // we want to load its native bindings
'utf-8-validate', // we want to load its native bindings
],
plugins: [
alias({
// we use ssb-keys-neon for better performance in Rust
'ssb-keys': to('ssb-keys-neon', 'lib/index.js'),
// we use ssb-keys-mnemonic-neon for better performance in Rust
'ssb-keys-mnemonic': to('ssb-keys-mnemonic-neon', 'lib/index.js'),
// can't remember why we need to replace it, build seemed to fail
'node-extend': to('xtend', 'immutable.js'),
// we use a "better" fork of this package
'non-private-ip': to('non-private-ip-android'),
// we're fixing a corner case bug with error recovery
'multiserver/plugins/net': to('staltz-multiserver/plugins', 'net.js'),
}),
],
})
.catch((err) => {
console.error(err);
process.exit(1);
});
#!/usr/bin/env node
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const path = require('path');
const esbuild = require('esbuild');
const alias = require('esbuild-plugin-alias');
const projectPath = process.cwd();
const nodejsProjectPath = `${projectPath}/nodejs-assets/nodejs-project`;
const to = (name, file = 'index.js') =>
path.resolve(nodejsProjectPath, 'node_modules', name, file);
esbuild
.build({
entryPoints: [`${nodejsProjectPath}/index.js`],
outfile: `${nodejsProjectPath}/_esbuilt.js`,
bundle: true,
platform: 'node',
target: ['es2019', 'node12.19.0'],
metafile: `${nodejsProjectPath}/meta.json`,
minifySyntax: true,
external: [
'rn-bridge', // not an npm package, it's just a nodejs-mobile shortcut
'bl', // we didn't use this, and bl@0.8.x has security vulnerabilities
'bufferutil', // we want nodejs-mobile to load its native bindings
'supports-color', // optional dependency within package `debug`
'electron', // not used on mobile, it's specific to desktop
'multiserver-electron-ipc', // not used on mobile, it's desktop-specific
'utf-8-validate', // we want nodejs-mobile to load its native bindings
],
plugins: [
alias({
// after esbuild, the paths to .node files might be different, so
// we use a special fork of bindings
bindings: to('bindings-noderify-nodejs-mobile', 'bindings.js'),
// chloride: needs special compilation configs for android, and we'd
// like to remove unused packages such as sodium-browserify etc
chloride: to('sodium-chloride-native-nodejs-mobile'),
// leveldown: newer versions of leveldown are intentionally ignoring
// nodejs-mobile support, so we run an older version
leveldown: to('leveldown-nodejs-mobile', 'leveldown.js'),
// we use ssb-keys-neon for better performance in Rust
'ssb-keys': to('ssb-keys-neon', 'lib/index.js'),
// we use ssb-keys-mnemonic-neon for better performance in Rust
'ssb-keys-mnemonic': to('ssb-keys-mnemonic-neon', 'lib/index.js'),
// we want to compile for nodejs-mobile instead of using prebuilds
'utp-native': to('utp-native-nodejs-mobile'),
// can't remember why we need to replace it, build seemed to fail
'node-extend': to('xtend', 'immutable.js'),
// we use a "better" fork of this package
'non-private-ip': to('non-private-ip-android'),
// we're fixing a corner case bug with error recovery
'multiserver/plugins/net': to('staltz-multiserver/plugins', 'net.js'),
}),
],
})
.catch((err) => {
console.error(err);
process.exit(1);
});
#!/bin/bash
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
set -eEu -o pipefail
shopt -s extdebug
IFS=$'\n\t'
trap 'onFailure $?' ERR
function onFailure() {
echo "Unhandled script error $1 at ${BASH_SOURCE[0]}:${BASH_LINENO[0]}" >&2
exit 1
}
cd ./desktop/nodejs-project;
rm index.js; mv _esbuilt.js index.js;
rm restore.js;
rm ssb.js;
rm -rf plugins;
cd ../..;
\ No newline at end of file
#!/bin/bash
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
set -eEu -o pipefail
shopt -s extdebug
IFS=$'\n\t'
trap 'onFailure $?' ERR
function onFailure() {
echo "Unhandled script error $1 at ${BASH_SOURCE[0]}:${BASH_LINENO[0]}" >&2
exit 1
}
cd ./nodejs-assets/nodejs-project;
rm index.js; mv _esbuilt.js index.js;
rm restore.js;
rm ssb.js;
rm -rf plugins;
cd ../..;
\ No newline at end of file
......@@ -152,12 +152,20 @@ async function runAndReport(label, task) {
if (targetPlatform === 'desktop') {
await runAndReport(
'Bundle and minify backend JS into one file',
exec('./tools/backend/noderify-desktop.sh'),
exec('./tools/backend/esbuild-desktop.sh'),
);
await runAndReport(
'Cleanup after bundling',
exec('./tools/backend/post-esbuild-desktop.sh'),
);
} else {
await runAndReport(
'Bundle and minify backend JS into one file',
exec('./tools/backend/noderify-mobile.sh'),
exec('./tools/backend/esbuild-mobile.js'),
);
await runAndReport(
'Cleanup after bundling',
exec('./tools/backend/post-esbuild-mobile.sh'),
);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment