Skip to content

Commit

Permalink
feat: init standalone library (#222)
Browse files Browse the repository at this point in the history
* feat: init standalone library

* build: standalone size

* build: review size
  • Loading branch information
peterpeterparker authored Dec 7, 2024
1 parent 9db7246 commit 188c6c4
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ target/

packages/core-peer/declarations
packages/core-peer/src
packages/core-standalone/declarations
packages/core-standalone/src

packages/**/LICENSE
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ JavaScript libraries for interfacing with [Juno].
## Libraries

- [core](/packages/core): core client library
- [core-standalone](/packages/core-standalone): a synchronized copy of [core](/packages/core) with all dependencies bundled — no peer dependencies
- [analytics](/packages/analytics): tracker for analytics
- [admin](/packages/admin): interfacing with admin features
- [config](/packages/config): configuration options for the CLI
- [utils](/packages/utils): various utilities used across Juno's JS code base
- [cli-tools](/packages/cli-tools): few tools used in Juno's CLIs and Plugins
- [did-tools](/packages/cli-tools): tools for generating APIs from DID files
- [config-loader](/packages/config-loader): utilities for reading configuration settings
- [core-peer](/packages/core-peer): a synchronized copy of [core](/packages/core) for the bundlers that requires polyfilling DFINITY `agent-js` themselves
- [console](/packages/console): interfacing with Junos' Console
- [storage](/packages/storage): interfacing with Junos' Storage features

Expand Down
33 changes: 32 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"packages/admin",
"packages/analytics",
"packages/core-peer",
"packages/core-standalone",
"packages/cli-tools",
"packages/did-tools",
"packages/config-loader",
Expand Down Expand Up @@ -80,6 +81,11 @@
"@dfinity/auth-client"
]
},
{
"name": "@junobuild/core-standalone",
"path": "./packages/core-standalone/dist/index.js",
"limit": "85 kB"
},
{
"name": "@junobuild/utils",
"path": "./packages/utils/dist/index.js",
Expand Down
17 changes: 17 additions & 0 deletions packages/core-standalone/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[![npm][npm-badge]][npm-badge-url]
[![license][npm-license]][npm-license-url]

[npm-badge]: https://img.shields.io/npm/v/@junobuild/core-standalone
[npm-badge-url]: https://www.npmjs.com/package/@junobuild/core-standalone
[npm-license]: https://img.shields.io/npm/l/@junobuild/core-standalone
[npm-license-url]: https://github.com/junobuild/juno-js/blob/main/LICENSE

# Juno JavaScript core SDK

JavaScript [core](../core/README.md) client for Juno with all dependencies bundled — no peer dependencies.

## License

MIT © [David Dal Busco](mailto:[email protected])

[juno]: https://juno.build
35 changes: 35 additions & 0 deletions packages/core-standalone/esbuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env node

import esbuild from 'esbuild';
import {readdirSync, statSync} from 'fs';
import {join} from 'path';
import {build} from '../../scripts/esbuild.mjs';

build();

// Build web workers

const buildWebWorkers = () => {
const entryPoints = readdirSync(join(process.cwd(), 'src', 'workers'))
.filter(
(file) =>
!file.includes('test') &&
!file.includes('spec') &&
!file.endsWith('.swp') &&
statSync(join(process.cwd(), 'src', 'workers', file)).isFile()
)
.map((file) => `src/workers/${file}`);

esbuild
.build({
entryPoints,
outdir: 'dist/workers',
bundle: true,
sourcemap: 'external',
minify: true,
target: ['node18']
})
.catch(() => process.exit(1));
};

buildWebWorkers();
64 changes: 64 additions & 0 deletions packages/core-standalone/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "@junobuild/core-standalone",
"version": "0.0.1",
"description": "JavaScript core client for Juno with all dependencies bundled — no peer dependencies",
"author": "David Dal Busco (https://daviddalbusco.com)",
"license": "MIT",
"type": "module",
"main": "./dist/node/index.mjs",
"module": "./dist/browser/index.js",
"types": "./dist/types/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/types/index.d.ts",
"default": "./dist/browser/index.js"
},
"require": {
"types": "./dist/types/index.d.ts",
"default": "./dist/node/index.mjs"
}
}
},
"files": [
"dist",
"README.md",
"LICENSE"
],
"scripts": {
"rmdir": "node ../../scripts/rmdir.mjs",
"ts-declaration": "tsc --emitDeclarationOnly --outDir dist/types",
"copy-src": "rm -rf src && cp -R ../core/src .",
"copy-declarations": "rm -rf declarations && cp -R ../core/declarations .",
"copy": "npm run copy-src && npm run copy-declarations",
"build": "npm run rmdir && mkdir -p dist && npm run copy && cp -R declarations dist && node esbuild.mjs && npm run ts-declaration",
"prepack": "npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/junobuild/juno-js.git",
"directory": "packages/core-standanlone"
},
"bugs": {
"url": "https://github.com/junobuild/juno-js"
},
"keywords": [
"blockchain-as-a-service",
"baas",
"dapps",
"dapps-development",
"internet computer",
"smart-contracts",
"web3"
],
"homepage": "https://juno.build",
"dependencies": {
"@dfinity/agent": "^2.1.3",
"@dfinity/auth-client": "^2.1.3",
"@dfinity/candid": "^2.1.3",
"@dfinity/identity": "^2.1.3",
"@dfinity/principal": "^2.1.3",
"@junobuild/storage": "*",
"@junobuild/utils": "*"
}
}
4 changes: 4 additions & 0 deletions packages/core-standalone/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*", "candid/**/*"]
}
1 change: 1 addition & 0 deletions scripts/build-next
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ node ./scripts/update-version.mjs admin
node ./scripts/update-version.mjs analytics
node ./scripts/update-version.mjs console
node ./scripts/update-version.mjs core-peer
node ./scripts/update-version.mjs core-standalone

: Now we can build
npm run build --workspaces
2 changes: 1 addition & 1 deletion scripts/license.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function copy_license() {
cp LICENSE packages/"$lib"
}

LIBS=utils,config,storage,core,admin,console,analytics,core-peer,cli-tools,did-tools,config-loader
LIBS=utils,config,storage,core,admin,console,analytics,core-peer,core-standalone,cli-tools,did-tools,config-loader

for lib in $(echo $LIBS | sed "s/,/ /g"); do
copy_license "$lib"
Expand Down
2 changes: 1 addition & 1 deletion scripts/publish-npm-next.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function publish_npm() {
}

# Tips: libs use by other libs first
LIBS=utils,config,config-loader,cli-tools,did-tools,storage,core,admin,console,analytics,core-peer
LIBS=utils,config,config-loader,cli-tools,did-tools,storage,core,admin,console,analytics,core-peer,core-standalone

for lib in $(echo $LIBS | sed "s/,/ /g"); do
publish_npm "$lib"
Expand Down
2 changes: 1 addition & 1 deletion scripts/publish-npm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function publish_npm() {
}

# Tips: libs use by other libs first
LIBS=utils,config,config-loader,cli-tools,did-tools,storage,core,admin,console,analytics,core-peer
LIBS=utils,config,config-loader,cli-tools,did-tools,storage,core,admin,console,analytics,core-peer,core-standalone

for lib in $(echo $LIBS | sed "s/,/ /g"); do
publish_npm "$lib"
Expand Down
2 changes: 1 addition & 1 deletion scripts/update-agent
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function install_principal_peer() {
npm i @dfinity/principal@latest --workspace=packages/"$package" --save-peer
}

PACKAGES=core
PACKAGES=core,core-standalone
PACKAGES_PEER=admin,console,storage,core-peer
PACKAGES_AUTH_CLIENT_PEER=core-peer
PACKAGES_PEER_UTILS=utils
Expand Down

0 comments on commit 188c6c4

Please sign in to comment.