Webpack -> Rollup
This commit is contained in:
parent
718f175b63
commit
fa2c184545
|
@ -6,8 +6,6 @@ lib/
|
|||
node_modules/
|
||||
scratch/
|
||||
|
||||
package-lock.json
|
||||
|
||||
*.did
|
||||
.do_built
|
||||
.do_built.dir/
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -6,11 +6,14 @@
|
|||
"@babel/plugin-syntax-jsx": "^7.10.1",
|
||||
"@babel/plugin-transform-react-jsx": "^7.10.1",
|
||||
"@babel/preset-env": "^7.10.2",
|
||||
"@rollup/plugin-commonjs": "^14.0.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^8.4.0",
|
||||
"esm": "^3.2.25",
|
||||
"lerna": "^3.22.1",
|
||||
"mocha": "^7.2.0",
|
||||
"nyc": "^14.1.1",
|
||||
"webpack": "^4.43.0",
|
||||
"webpack-cli": "^3.3.11"
|
||||
"rollup": "^2.23.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@syndicate-lang/core": "file:packages/core",
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
randomBytes: void 0,
|
||||
};
|
|
@ -391,7 +391,7 @@ Dataspace.prototype._dotGraph = function () {
|
|||
|
||||
pieces.push('\n}');
|
||||
|
||||
require('fs').writeFileSync('d.json', 'var dataspaceContents = ' + JSON.stringify({nodes, edges}, null, 2));
|
||||
// require('fs').writeFileSync('d.json', 'var dataspaceContents = ' + JSON.stringify({nodes, edges}, null, 2));
|
||||
|
||||
return pieces.join('');
|
||||
};
|
||||
|
|
|
@ -378,7 +378,7 @@ Index.prototype.sendMessage = function(v, leafCallback) {
|
|||
|
||||
Node.prototype._debugString = function (outerIndent) {
|
||||
const pieces = [];
|
||||
const inspect = require('util').inspect;
|
||||
const inspect = require('util').inspect || JSON.stringify;
|
||||
function line(indent, content) {
|
||||
pieces.push(indent);
|
||||
pieces.push(content);
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
inspect: void 0,
|
||||
};
|
|
@ -37,9 +37,7 @@ const worker_threads = (function () {
|
|||
try {
|
||||
return require('worker_threads');
|
||||
} catch (_e) {
|
||||
return {
|
||||
__isDummyStub: true
|
||||
};
|
||||
return require('./worker_stub.js');
|
||||
}
|
||||
})();
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
__isDummyStub: true,
|
||||
};
|
|
@ -2,9 +2,9 @@ cd "$(dirname "$1")"
|
|||
case "$1" in
|
||||
*/all)
|
||||
for d in src/*.js; do [ -f "$d" ] && echo lib/$(basename "$d"); done | xargs redo-ifchange
|
||||
for d in *.webpack.config.js
|
||||
for d in *.dist.json
|
||||
do
|
||||
[ -f "$d" ] && echo dist/$(basename "$d" .webpack.config.js).js
|
||||
[ -f "$d" ] && echo dist/$(basename "$d" .dist.json).js
|
||||
done | xargs redo-ifchange
|
||||
[ -f _all.do ] && redo-ifchange _all || true
|
||||
;;
|
||||
|
|
|
@ -40,35 +40,13 @@ case "$1" in
|
|||
fi
|
||||
;;
|
||||
*/dist/*)
|
||||
# Conservatively assume the distribution depends on ALL the
|
||||
# local source files PLUS the lib/*.js of dependent syndicate
|
||||
# packages, other than core which has src/*.js files instead.
|
||||
#
|
||||
for d in src/*.js; do echo lib/$(basename $d); done | xargs redo-ifchange
|
||||
for dep in $(cat package.json | \
|
||||
jq -r '.dependencies | to_entries[].key' | \
|
||||
fgrep '@syndicate-lang/' | \
|
||||
sed -e 's:^@syndicate-lang/::')
|
||||
do
|
||||
for srcfile in ../$dep/src/*.js
|
||||
do
|
||||
if [ -f $srcfile ]
|
||||
then
|
||||
if [ "$dep" = "core" ]
|
||||
then
|
||||
echo $srcfile
|
||||
else
|
||||
libfile=$(echo $srcfile | sed -e 's:/src/:/lib/:')
|
||||
echo $libfile
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done | xargs redo-ifchange
|
||||
configfile=$(basename "$1" .js).webpack.config.js
|
||||
configfile=$(basename "$1" .js).dist.json
|
||||
redo-ifchange $configfile
|
||||
for maybedep in $(../../node_modules/.bin/webpack --config "$configfile" --json -o "$targettempfile" | jq -r '.modules[].identifier')
|
||||
redo-ifchange ../../rollup-redo
|
||||
for maybedep in $(../../rollup-redo deps "$configfile" "$targettempfile")
|
||||
do
|
||||
[ -f "$maybedep" ] && echo "$maybedep"
|
||||
done | xargs redo-ifchange
|
||||
../../rollup-redo generate "$configfile" "$targettempfile"
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -10,6 +10,6 @@
|
|||
<div id="board-area" class="board">
|
||||
</div>
|
||||
</div>
|
||||
<script src="dist/main.js" type="text/javascript"></script>
|
||||
<script src="dist/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"input": "lib/index.js",
|
||||
"format": "iife"
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
module.exports = {
|
||||
entry: "./lib/index.js",
|
||||
mode: "development",
|
||||
externals: {
|
||||
crypto: 'null'
|
||||
},
|
||||
};
|
|
@ -12,8 +12,6 @@
|
|||
"dependencies": {
|
||||
"@syndicate-lang/core": "file:../core",
|
||||
"@syndicate-lang/driver-browser-ui": "file:../driver-browser-ui",
|
||||
"@syndicate-lang/driver-timer": "file:../driver-timer",
|
||||
"webpack": "^4.27.1",
|
||||
"webpack-cli": "^3.1.2"
|
||||
"@syndicate-lang/driver-timer": "file:../driver-timer"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
import { $QuitDataspace, Inbound, Outbound, Dataspace, Double } from "@syndicate-lang/core";
|
||||
import { bootModule, $QuitDataspace, Inbound, Outbound, Dataspace, Double } from "@syndicate-lang/core";
|
||||
|
||||
let UI = activate require("@syndicate-lang/driver-browser-ui");
|
||||
// @jsx UI.html
|
||||
|
@ -170,3 +170,9 @@ function spawnGame() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Running Syndicate programs in node.js doesn't require this -- it
|
||||
// automatically detects the "main" module -- but in the browser, when
|
||||
// using rollup, the mechanism doesn't work properly so we explicitly
|
||||
// activate *ourselves* here.
|
||||
bootModule(module);
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"format": "iife"
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
module.exports = {
|
||||
entry: "./lib/chat.js",
|
||||
mode: "development",
|
||||
externals: {
|
||||
crypto: 'null'
|
||||
},
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -1,7 +0,0 @@
|
|||
module.exports = {
|
||||
entry: "./lib/monitor.js",
|
||||
mode: "development",
|
||||
externals: {
|
||||
crypto: 'null'
|
||||
},
|
||||
};
|
|
@ -82,3 +82,5 @@ function randomName() {
|
|||
return names[Math.floor(Math.random() * names.length)] +
|
||||
'_' + Math.floor(Math.random() * 990 + 10);
|
||||
}
|
||||
|
||||
require('@syndicate-lang/core').bootModule(module);
|
||||
|
|
|
@ -144,12 +144,16 @@ function spawnMonitorAppServer(port) {
|
|||
'<!DOCTYPE html>' + UI.htmlToString(
|
||||
<html>
|
||||
<head><meta charset="utf-8"></meta></head>
|
||||
<body><script src="dist/monitor.js"></script></body>
|
||||
<body><script type="module" src="dist/monitor.js"></script></body>
|
||||
</html>));
|
||||
}
|
||||
|
||||
function assertFileResponse(reqId, path) {
|
||||
assert :snapshot Http.Response(reqId, 200, "OK", {}, fs.readFileSync(path));
|
||||
let type = 'application/octet-stream';
|
||||
if (path.endsWith('.js')) {
|
||||
type = 'text/javascript';
|
||||
}
|
||||
assert :snapshot Http.Response(reqId, 200, "OK", {"Content-type": type}, fs.readFileSync(path));
|
||||
}
|
||||
|
||||
during Http.Request($reqId, server, 'get', ['chat.html'], _, _)
|
||||
|
|
|
@ -112,3 +112,5 @@ spawn {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
require('@syndicate-lang/core').bootModule(module);
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"input": "lib/index.js",
|
||||
"format": "iife"
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
module.exports = {
|
||||
entry: "./lib/index.js",
|
||||
mode: "development",
|
||||
externals: {
|
||||
crypto: 'null'
|
||||
},
|
||||
};
|
|
@ -68,3 +68,5 @@ spawn named 'alerter' {
|
|||
alert("Hello!");
|
||||
}
|
||||
}
|
||||
|
||||
require('@syndicate-lang/core').bootModule(module);
|
||||
|
|
|
@ -345,7 +345,7 @@ export default declare((api, options) => {
|
|||
};
|
||||
DATASPACE._currentFacet = SAVEDGLOBALFACET;
|
||||
SAVEDGLOBALFACET = null;
|
||||
if (require.main === module) {
|
||||
if ((typeof require === 'undefined' ? {main: void 0} : require).main === module) {
|
||||
SYNDICATE.bootModule(module);
|
||||
}`)({
|
||||
DATASPACE: state.DataspaceID,
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
#!/usr/bin/env -S node -r esm
|
||||
|
||||
import * as rollup from 'rollup';
|
||||
import resolve from '@rollup/plugin-node-resolve';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
import json from '@rollup/plugin-json';
|
||||
import * as path from 'path';
|
||||
|
||||
function computeBasename(f) {
|
||||
const m = /^(.*).dist.json$/.exec(f);
|
||||
if (!m) throw new Error(`Config filename ${f} does not match pattern`);
|
||||
return m[1];
|
||||
}
|
||||
|
||||
const [_node, _rollup_redo, mode, configJsonFilename, targetFilename] = process.argv;
|
||||
|
||||
const basename = computeBasename(configJsonFilename);
|
||||
const config = require(`${process.cwd()}/${configJsonFilename}`);
|
||||
const inputFile = ('input' in config)
|
||||
? path.resolve(process.cwd(), config.input)
|
||||
: `${process.cwd()}/lib/${basename}.js`;
|
||||
|
||||
async function build() {
|
||||
const bundle = await rollup.rollup({
|
||||
input: inputFile,
|
||||
external: ['crypto'],
|
||||
plugins: [
|
||||
{
|
||||
resolveId(toResolve, referencingModule) {
|
||||
{
|
||||
const m = /^@syndicate-lang\/(.*)$/.exec(toResolve);
|
||||
if (m) {
|
||||
if (mode === 'deps') {
|
||||
console.log(`../${m[1]}/all`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (/^\0?util(\?commonjs.*)?$/.test(toResolve)) {
|
||||
return '../core/src/util_stub.js';
|
||||
}
|
||||
if (/^\0?crypto(\?commonjs.*)?$/.test(toResolve)) {
|
||||
return '../core/src/crypto_stub.js';
|
||||
}
|
||||
if (/^\0?worker_threads(\?commonjs.*)?$/.test(toResolve)) {
|
||||
return '../core/src/worker_stub.js';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
},
|
||||
resolve({
|
||||
browser: true,
|
||||
}),
|
||||
commonjs(),
|
||||
json(),
|
||||
],
|
||||
onwarn(w, defaultHandler) {
|
||||
if (((w.code === 'UNRESOLVED_IMPORT') ||
|
||||
(w.code === 'MISSING_GLOBAL_NAME')) &&
|
||||
(w.source.startsWith('@syndicate-lang/')))
|
||||
{
|
||||
return;
|
||||
}
|
||||
defaultHandler(w);
|
||||
},
|
||||
treeshake: {
|
||||
moduleSideEffects: "no-external",
|
||||
},
|
||||
});
|
||||
|
||||
switch (mode) {
|
||||
case 'deps': {
|
||||
const deps = {};
|
||||
for (const m of bundle.cache.modules) {
|
||||
deps[m.id] = m.dependencies;
|
||||
}
|
||||
const seen = {};
|
||||
function visit(id) {
|
||||
if (id in seen) return;
|
||||
if (!id.startsWith('/')) return;
|
||||
seen[id] = true;
|
||||
console.log(id);
|
||||
for (const dep of (deps[id] || [])) {
|
||||
visit(dep);
|
||||
}
|
||||
}
|
||||
visit(inputFile);
|
||||
}
|
||||
|
||||
case 'generate': {
|
||||
await bundle.write({
|
||||
output: {
|
||||
file: targetFilename,
|
||||
format: config.format || 'es',
|
||||
name: config.name || 'Syndicate_' + basename,
|
||||
},
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
console.error('Unknown mode', mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
build().then(null, console.error);
|
Loading…
Reference in New Issue