Browse Source

Webpack -> Rollup

pr/1
Tony Garnock-Jones 1 year ago
parent
commit
fa2c184545
  1. 2
      .gitignore
  2. 11039
      package-lock.json
  3. 7
      package.json
  4. 3
      packages/core/src/crypto_stub.js
  5. 2
      packages/core/src/dataspace.js
  6. 2
      packages/core/src/skeleton.js
  7. 3
      packages/core/src/util_stub.js
  8. 4
      packages/core/src/worker.js
  9. 3
      packages/core/src/worker_stub.js
  10. 4
      packages/default.do
  11. 30
      packages/default.js.do
  12. 2
      packages/flappy-bird-demo/index.html
  13. 4
      packages/flappy-bird-demo/main.dist.json
  14. 7
      packages/flappy-bird-demo/main.webpack.config.js
  15. 4
      packages/flappy-bird-demo/package.json
  16. 8
      packages/flappy-bird-demo/src/index.js
  17. 3
      packages/server/chat.dist.json
  18. 7
      packages/server/chat.webpack.config.js
  19. 1
      packages/server/monitor.dist.json
  20. 7
      packages/server/monitor.webpack.config.js
  21. 2
      packages/server/src/chat.js
  22. 8
      packages/server/src/index.js
  23. 2
      packages/server/src/monitor.js
  24. 4
      packages/syntax-playground/main.dist.json
  25. 7
      packages/syntax-playground/main.webpack.config.js
  26. 2
      packages/syntax-playground/src/index.js
  27. 2
      packages/syntax/src/plugin.js
  28. 106
      rollup-redo

2
.gitignore

@ -6,8 +6,6 @@ lib/
node_modules/
scratch/
package-lock.json
*.did
.do_built
.do_built.dir/

11039
package-lock.json

File diff suppressed because it is too large

7
package.json

@ -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",

3
packages/core/src/crypto_stub.js

@ -0,0 +1,3 @@
module.exports = {
randomBytes: void 0,
};

2
packages/core/src/dataspace.js

@ -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('');
};

2
packages/core/src/skeleton.js

@ -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);

3
packages/core/src/util_stub.js

@ -0,0 +1,3 @@
module.exports = {
inspect: void 0,
};

4
packages/core/src/worker.js

@ -37,9 +37,7 @@ const worker_threads = (function () {
try {
return require('worker_threads');
} catch (_e) {
return {
__isDummyStub: true
};
return require('./worker_stub.js');
}
})();

3
packages/core/src/worker_stub.js

@ -0,0 +1,3 @@
module.exports = {
__isDummyStub: true,
};

4
packages/default.do

@ -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
;;

30
packages/default.js.do

@ -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

2
packages/flappy-bird-demo/index.html

@ -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>

4
packages/flappy-bird-demo/main.dist.json

@ -0,0 +1,4 @@
{
"input": "lib/index.js",
"format": "iife"
}

7
packages/flappy-bird-demo/main.webpack.config.js

@ -1,7 +0,0 @@
module.exports = {
entry: "./lib/index.js",
mode: "development",
externals: {
crypto: 'null'
},
};

4
packages/flappy-bird-demo/package.json

@ -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"
}
}

8
packages/flappy-bird-demo/src/index.js

@ -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);

3
packages/server/chat.dist.json

@ -0,0 +1,3 @@
{
"format": "iife"
}

7
packages/server/chat.webpack.config.js

@ -1,7 +0,0 @@
module.exports = {
entry: "./lib/chat.js",
mode: "development",
externals: {
crypto: 'null'
},
};

1
packages/server/monitor.dist.json

@ -0,0 +1 @@
{}

7
packages/server/monitor.webpack.config.js

@ -1,7 +0,0 @@
module.exports = {
entry: "./lib/monitor.js",
mode: "development",
externals: {
crypto: 'null'
},
};

2
packages/server/src/chat.js

@ -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);

8
packages/server/src/index.js

@ -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'], _, _)

2
packages/server/src/monitor.js

@ -112,3 +112,5 @@ spawn {
}
}
}
require('@syndicate-lang/core').bootModule(module);

4
packages/syntax-playground/main.dist.json

@ -0,0 +1,4 @@
{
"input": "lib/index.js",
"format": "iife"
}

7
packages/syntax-playground/main.webpack.config.js

@ -1,7 +0,0 @@
module.exports = {
entry: "./lib/index.js",
mode: "development",
externals: {
crypto: 'null'
},
};

2
packages/syntax-playground/src/index.js

@ -68,3 +68,5 @@ spawn named 'alerter' {
alert("Hello!");
}
}
require('@syndicate-lang/core').bootModule(module);

2
packages/syntax/src/plugin.js

@ -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,

106
rollup-redo

@ -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…
Cancel
Save