mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-29 18:06:43 +03:00
npm/api: updating build to use rollup for better distribution
This commit is contained in:
parent
ed157abb19
commit
fa4e4e4f20
11
pkg/npm/api/.babelrc
Normal file
11
pkg/npm/api/.babelrc
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"targets": "> 1%",
|
||||
"useBuiltIns": "usage"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
2
pkg/npm/api/deps.d.ts
vendored
2
pkg/npm/api/deps.d.ts
vendored
@ -1,5 +1,5 @@
|
||||
|
||||
declare module "urbit-ob" {
|
||||
declare module 'urbit-ob' {
|
||||
|
||||
/**
|
||||
* Convert a @p-encoded string to a decimal-encoded string.
|
||||
|
@ -1,5 +1,3 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
import { Enc, Path, Patp, PatpNoSig, Poke, Thread } from '../lib/types';
|
||||
import { Group, GroupPolicy, GroupPolicyDiff, GroupUpdateAddMembers, GroupUpdateAddTag, GroupUpdateChangePolicy, GroupUpdateRemoveGroup, GroupUpdateRemoveMembers, GroupUpdateRemoveTag, Resource, RoleTags, Tag } from './types';
|
||||
import { GroupUpdate } from './update';
|
||||
@ -97,6 +95,10 @@ export const changePolicy = (
|
||||
}
|
||||
});
|
||||
|
||||
export const makeResource = (ship: string, name: string) => {
|
||||
return { ship, name };
|
||||
};
|
||||
|
||||
export const join = (
|
||||
ship: string,
|
||||
name: string
|
||||
@ -174,30 +176,32 @@ export const roleForShip = (
|
||||
const roleShips = group?.tags?.role?.[role];
|
||||
return roleShips && roleShips.has(ship) ? role : currRole;
|
||||
}, undefined as RoleTags | undefined);
|
||||
}
|
||||
};
|
||||
|
||||
export const resourceFromPath = (path: Path): Resource => {
|
||||
const [, , ship, name] = path.split('/');
|
||||
return { ship, name };
|
||||
}
|
||||
|
||||
export const makeResource = (ship: string, name: string) => {
|
||||
return { ship, name };
|
||||
}
|
||||
};
|
||||
|
||||
export const isWriter = (group: Group, resource: string, ship: string) => {
|
||||
const writers: Set<string> | undefined = _.get(
|
||||
group,
|
||||
['tags', 'graph', resource, 'writers'],
|
||||
undefined
|
||||
);
|
||||
const graph = group.tags?.graph;
|
||||
const writers: Set<string> | undefined = graph && (graph[resource] as any)?.writers;
|
||||
const admins = group?.tags?.role?.admin ?? new Set();
|
||||
if (_.isUndefined(writers)) {
|
||||
if (typeof writers === 'undefined') {
|
||||
return true;
|
||||
} else {
|
||||
return writers.has(ship) || admins.has(ship);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const isHost = (
|
||||
resource: string,
|
||||
ship: string
|
||||
): boolean => {
|
||||
const [, , host] = resource.split('/');
|
||||
|
||||
return ship === host;
|
||||
};
|
||||
|
||||
export const isChannelAdmin = (
|
||||
group: Group,
|
||||
@ -211,13 +215,4 @@ export const isChannelAdmin = (
|
||||
role === 'admin' ||
|
||||
role === 'moderator'
|
||||
);
|
||||
}
|
||||
|
||||
export const isHost = (
|
||||
resource: string,
|
||||
ship: string
|
||||
): boolean => {
|
||||
const [, , host] = resource.split('/');
|
||||
|
||||
return ship === host;
|
||||
}
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { PatpNoSig, Path, Jug, ShipRank, Enc } from '../lib';
|
||||
import { PatpNoSig, Path, ShipRank, Enc } from '../lib';
|
||||
import { roleTags } from './index';
|
||||
|
||||
export type RoleTags = typeof roleTags[number];
|
||||
@ -173,5 +173,3 @@ export type GroupUpdate =
|
||||
| GroupUpdateInitialGroup;
|
||||
|
||||
export type GroupAction = Omit<GroupUpdate, 'initialGroup' | 'initial'>;
|
||||
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { Poke, Scry } from '../lib';
|
||||
import { Vats, Vat } from './types';
|
||||
import _ from 'lodash';
|
||||
|
||||
export const getVats: Scry = {
|
||||
app: 'hood',
|
||||
@ -98,13 +97,17 @@ export function getBlockers(vats: Vats): string[] {
|
||||
if(!blockedOn) {
|
||||
return blockers;
|
||||
}
|
||||
_.forEach(_.omit(vats, 'base'), (vat, desk) => {
|
||||
// assuming only %zuse
|
||||
const kelvins = _.map((vat.arak.rail?.next || []), n => n.weft.kelvin);
|
||||
if(!(kelvins.includes(blockedOn))) {
|
||||
blockers.push(desk);
|
||||
}
|
||||
});
|
||||
|
||||
Object.entries(vats)
|
||||
.filter(([desk]) => desk !== 'base')
|
||||
.forEach(([desk, vat]) => {
|
||||
// assuming only %zuse
|
||||
const woofs = vat.arak.rail?.next || [];
|
||||
const kelvins = woofs.map(n => n.weft.kelvin);
|
||||
if(!(kelvins.includes(blockedOn))) {
|
||||
blockers.push(desk);
|
||||
}
|
||||
});
|
||||
|
||||
return blockers;
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
import _ from "lodash";
|
||||
import f from "lodash/fp";
|
||||
import bigInt, { BigInteger } from "big-integer";
|
||||
|
||||
import { Resource } from "../groups/types";
|
||||
@ -9,6 +7,36 @@ const DA_UNIX_EPOCH = bigInt("170141184475152167957503069145530368000"); // `@ud
|
||||
|
||||
const DA_SECOND = bigInt("18446744073709551616"); // `@ud` ~s1
|
||||
|
||||
function chunk<T>(arr: T[], size: number): T[][] {
|
||||
let chunk: T[] = [];
|
||||
let newArray = [chunk];
|
||||
|
||||
for (let i = 0;i < arr.length;i++) {
|
||||
if (chunk.length < size) {
|
||||
chunk.push(arr[i])
|
||||
} else {
|
||||
chunk = [arr[i]]
|
||||
newArray.push(chunk)
|
||||
}
|
||||
}
|
||||
|
||||
return newArray;
|
||||
}
|
||||
|
||||
function dropWhile<T>(arr: T[], pred: (x: T) => boolean): T[] {
|
||||
const newArray = arr.slice();
|
||||
|
||||
for (const item of arr) {
|
||||
if (pred(item)) {
|
||||
newArray.shift();
|
||||
} else {
|
||||
return newArray;
|
||||
}
|
||||
}
|
||||
|
||||
return newArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a bigint representing an urbit date, returns a unix timestamp.
|
||||
*
|
||||
@ -48,17 +76,11 @@ export function udToDec(ud: string): string {
|
||||
}
|
||||
|
||||
export function decToUd(str: string): string {
|
||||
return _.trimStart(
|
||||
f.flow(
|
||||
f.split(""),
|
||||
f.reverse,
|
||||
f.chunk(3),
|
||||
f.map(f.flow(f.reverse, f.join(""))),
|
||||
f.reverse,
|
||||
f.join(".")
|
||||
)(str),
|
||||
"0."
|
||||
);
|
||||
const transform = chunk(str.split('').reverse(), 3)
|
||||
.map(group => group.reverse().join(''))
|
||||
.reverse()
|
||||
.join('.')
|
||||
return transform.replace(/^[0\.]+/g, '');
|
||||
}
|
||||
|
||||
export function resourceAsPath(resource: Resource): string {
|
||||
@ -161,11 +183,10 @@ export function uxToHex(ux: string) {
|
||||
}
|
||||
|
||||
export const hexToUx = (hex: string): string => {
|
||||
const ux = f.flow(
|
||||
f.chunk(4),
|
||||
f.map(x => _.dropWhile(x, (y: unknown) => y === 0).join('')),
|
||||
f.join('.')
|
||||
)(hex.split(''));
|
||||
const ux = chunk(hex.split(''), 4).map(x => {
|
||||
return dropWhile(x, y => y === '0').join('');
|
||||
}).join('.');
|
||||
|
||||
return `0x${ux}`;
|
||||
};
|
||||
|
||||
@ -207,21 +228,6 @@ export function stringToTa(str: string): string {
|
||||
return "~." + out;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Formats a numbers as a `@ud` inserting dot where needed
|
||||
*/
|
||||
export function numToUd(num: number): string {
|
||||
return f.flow(
|
||||
f.split(''),
|
||||
f.reverse,
|
||||
f.chunk(3),
|
||||
f.reverse,
|
||||
f.map(s => s.join('')),
|
||||
f.join('.')
|
||||
)(num.toString())
|
||||
}
|
||||
|
||||
export const buntPost = (): Post => ({
|
||||
author: '',
|
||||
contents: [],
|
||||
|
3597
pkg/npm/api/package-lock.json
generated
3597
pkg/npm/api/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,39 +1,47 @@
|
||||
{
|
||||
"name": "@urbit/api",
|
||||
"version": "2.0.0",
|
||||
"description": "",
|
||||
"description": "A library that provides bindings and types for Urbit's various userspace desks",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "ssh://git@github.com/urbit/urbit.git",
|
||||
"directory": "pkg/npm/api"
|
||||
},
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d",
|
||||
"type": "module",
|
||||
"main": "dist/cjs/index.js",
|
||||
"module": "dist/esm/index.js",
|
||||
"jsdelivr": "dist/urbit-api.min.js",
|
||||
"unpkg": "dist/urbit-api.min.js",
|
||||
"types": "types/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "echo \"No test specified\" && exit 0",
|
||||
"watch": "tsc -p tsconfig.json --watch",
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"clean": "rm -rf dist/*",
|
||||
"prepare": "npm run build"
|
||||
"build": "npm run clean && rollup -c && npx tsc -p tsconfig.json",
|
||||
"prepare": "npm run build",
|
||||
"watch": "rollup -c -w",
|
||||
"clean": "rm -rf dist/* types/*"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@types/lodash": "^4.14.168",
|
||||
"@urbit/eslint-config": "^1.0.3",
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"big-integer": "^1.6.48",
|
||||
"immer": "^9.0.1",
|
||||
"lodash": "^4.17.20",
|
||||
"urbit-ob": "^5.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.16.0",
|
||||
"@rollup/plugin-babel": "^5.3.0",
|
||||
"@rollup/plugin-commonjs": "^21.0.1",
|
||||
"@rollup/plugin-node-resolve": "^13.0.6",
|
||||
"@types/node": "^15.12.5",
|
||||
"@typescript-eslint/eslint-plugin": "^4.28.2",
|
||||
"@typescript-eslint/parser": "^4.28.2",
|
||||
"@urbit/eslint-config": "^1.0.3",
|
||||
"babel-eslint": "^10.1.0",
|
||||
"eslint-plugin-react": "^7.24.0",
|
||||
"onchange": "^7.1.0",
|
||||
"rollup-plugin-analyzer": "^4.0.0",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"rollup-plugin-typescript2": "^0.30.0",
|
||||
"typescript": "^4.3.2"
|
||||
}
|
||||
}
|
||||
|
76
pkg/npm/api/rollup.config.ts
Normal file
76
pkg/npm/api/rollup.config.ts
Normal file
@ -0,0 +1,76 @@
|
||||
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
||||
import commonJS from '@rollup/plugin-commonjs';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
import babel from '@rollup/plugin-babel';
|
||||
import typescript from 'rollup-plugin-typescript2';
|
||||
import analyze from 'rollup-plugin-analyzer'
|
||||
|
||||
const input = ['./index.ts'];
|
||||
|
||||
// Skip certain warnings
|
||||
function onwarn(warning) {
|
||||
if (warning.code === 'THIS_IS_UNDEFINED') {
|
||||
return;
|
||||
}
|
||||
|
||||
console.warn(warning.message);
|
||||
}
|
||||
|
||||
export default [
|
||||
{
|
||||
input,
|
||||
onwarn,
|
||||
plugins: [
|
||||
nodeResolve({
|
||||
extensions: ['.js', '.jsx', '.ts', '.tsx']
|
||||
}),
|
||||
commonJS(),
|
||||
typescript(),
|
||||
babel({
|
||||
babelHelpers: 'bundled',
|
||||
exclude: ['node_modules/**']
|
||||
}),
|
||||
terser({
|
||||
ecma: 2017,
|
||||
compress: true,
|
||||
mangle: true
|
||||
})
|
||||
],
|
||||
output: {
|
||||
file: 'dist/urbit-api.min.js',
|
||||
format: 'umd',
|
||||
name: 'UrbitAPI', // this is the name of the global object
|
||||
esModule: false,
|
||||
exports: 'named',
|
||||
sourcemap: true
|
||||
}
|
||||
},
|
||||
{
|
||||
input,
|
||||
onwarn,
|
||||
plugins: [
|
||||
nodeResolve({
|
||||
extensions: ['.js', '.jsx', '.ts', '.tsx']
|
||||
}),
|
||||
commonJS(),
|
||||
typescript(),
|
||||
analyze({
|
||||
limit: 10
|
||||
})
|
||||
],
|
||||
output: [
|
||||
{
|
||||
dir: 'dist/esm',
|
||||
format: 'esm',
|
||||
exports: 'named',
|
||||
sourcemap: true
|
||||
},
|
||||
{
|
||||
dir: 'dist/cjs',
|
||||
format: 'cjs',
|
||||
exports: 'named',
|
||||
sourcemap: true
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
@ -2,9 +2,9 @@
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"outDir": "./dist",
|
||||
"module": "ES2020",
|
||||
"module": "ESNext",
|
||||
"noImplicitAny": true,
|
||||
"target": "ES2017",
|
||||
"target": "ESNext",
|
||||
"pretty": true,
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
@ -14,6 +14,6 @@
|
||||
"strict": false,
|
||||
"noErrorTruncation": true
|
||||
},
|
||||
"exclude": ["node_modules", "./dist/**/*", "@types"],
|
||||
"exclude": ["node_modules", "./dist/**/*", "@types", "rollup.config.ts"],
|
||||
"include": ["./*.ts"]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user