Better packaging

This commit is contained in:
Tony Garnock-Jones 2021-01-17 14:14:02 +01:00
parent fc23d1b779
commit 6408493ea3
7 changed files with 76 additions and 72 deletions

View File

@ -1,16 +0,0 @@
import * as fs from 'fs';
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
for (let f of fs.readdirSync('dist')) {
const prefix = `syndicate-${pkg.version}`;
if (f.startsWith(prefix)) {
const linkname = `dist/syndicate${f.substring(prefix.length)}`;
try {
fs.unlinkSync(linkname);
} catch (e) {
if (e.code !== 'ENOENT') throw e;
}
fs.symlinkSync(f, linkname);
}
}

View File

@ -1,4 +1,4 @@
#!/usr/bin/env -S node --es-module-specifier-resolution=node
#!/usr/bin/env node
//---------------------------------------------------------------------------
// @syndicate-lang/core, an implementation of Syndicate dataspaces for JS.
// Copyright (C) 2016-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//---------------------------------------------------------------------------
import { Dataspace, Skeleton, Ground, Record, Discard, Capture, Observe } from '../lib/index';
const { Dataspace, Skeleton, Ground, Record, Discard, Capture, Observe } = require('../dist/syndicate.js');
const __ = Discard._instance;
const _$ = Capture(__);
@ -28,7 +28,7 @@ const N = 100000;
console.time('box-and-client-' + N.toString());
export function boot(thisFacet) {
function boot(thisFacet) {
thisFacet.spawn('box', function (thisFacet) {
thisFacet.declareField(this, 'value', 0);
thisFacet.addEndpoint(() => {
@ -87,4 +87,6 @@ export function boot(thisFacet) {
console.timeEnd('box-and-client-' + N.toString()));
}
module.exports.boot = boot;
new Ground(boot).start();

View File

@ -11,12 +11,12 @@
"scripts": {
"prepare": "npm run compile && npm run rollup",
"compile": "../../node_modules/.bin/tsc --incremental",
"rollup": "../../node_modules/.bin/rollup -c syndicate.dist.js && node ./dist-link.js",
"rollup": "../../node_modules/.bin/rollup -c",
"test": "../../node_modules/.bin/jest",
"cover": "../../node_modules/.bin/nyc --reporter=html ../../node_modules/.bin/jest"
},
"type": "module",
"main": "lib/index.js",
"main": "dist/syndicate.js",
"module": "lib/index.js",
"types": "lib/index.d.ts",
"author": "Tony Garnock-Jones <tonyg@leastfixedpoint.com>",
"dependencies": {

View File

@ -0,0 +1,54 @@
import resolve from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
function distfile(insertion) {
const f = `syndicate${insertion}.js`;
return `dist/${f}`;
}
function umd(insertion, extra) {
return {
file: distfile(insertion),
format: 'umd',
name: 'Syndicate',
globals: {
'crypto': 'crypto',
},
... (extra || {})
};
}
function es6(insertion, extra) {
return {
file: distfile('.es6' + insertion),
format: 'es',
... (extra || {})
};
}
export default [
{
input: 'lib/index.js',
plugins: [
resolve({
preferBuiltins: false,
}),
],
output: [
umd(''),
umd('.min', { plugins: [terser()] }),
],
}, {
input: 'lib/index.js',
plugins: [
resolve({
moduleDirectories: ['stubs', 'node_modules'],
preferBuiltins: false,
}),
],
output: [
es6(''),
es6('.min', { plugins: [terser()] }),
],
}
];

View File

@ -1,4 +1,4 @@
import fs from 'fs';
import * as fs from 'fs';
import * as S from '../syntax/index.js';
import { Substitution } from '../syntax/index.js';
import * as G from './grammar.js';

View File

@ -27,17 +27,22 @@ export function _btoa(s: string): string {
}
}
export function randomId(byteCount: number, hexOutput: boolean = false): string {
let buf: Uint8Array;
if (node_crypto.randomBytes !== void 0) {
buf = node_crypto.randomBytes(byteCount);
} else {
buf = new Uint8Array(byteCount);
crypto.getRandomValues(buf);
}
function _finish(hexOutput: boolean, buf: Uint8Array): string {
if (hexOutput) {
return Bytes.from(buf).toHex();
} else {
return _btoa(String.fromCharCode.apply(null, buf as unknown as number[])).replace(/=/g,'');
}
}
export const randomId =
(typeof crypto !== 'undefined' && 'getRandomValues' in crypto)
? ((byteCount: number, hexOutput: boolean = false): string => {
const buf = new Uint8Array(byteCount);
crypto.getRandomValues(buf);
return _finish(hexOutput, buf);
})
: ((byteCount: number, hexOutput: boolean = false): string => {
let buf = node_crypto.randomBytes(byteCount);
return _finish(hexOutput, buf);
});

View File

@ -1,41 +0,0 @@
import pkg from './package.json';
import resolve from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
function distfile(insertion) {
const f = `syndicate-${pkg.version}${insertion}.js`;
return `dist/${f}`;
}
function umd(insertion, extra) {
return {
file: distfile(insertion),
format: 'umd',
name: 'Syndicate',
... (extra || {})
};
}
function es6(insertion, extra) {
return {
file: distfile('.es6' + insertion),
format: 'es',
... (extra || {})
};
}
export default {
input: 'lib/index.js',
plugins: [
resolve({
moduleDirectories: ['stubs', 'node_modules'],
preferBuiltins: false,
}),
],
output: [
umd(''),
umd('.min', { plugins: [terser()] }),
es6(''),
es6('.min', { plugins: [terser()] }),
],
}