Skip to content

Commit

Permalink
Bundling (#160)
Browse files Browse the repository at this point in the history
* change bundling strategy for `common` pkg

* change bundling strategy for `crypto` pkg

* update export directives in crypto pkg

* change bundling strategy for `credentials` pkg

* change bundling strategy for `dids` pkg

* change bundling strategy of `web5-agent` pkk

* change bundling strategy for `web5-user-agent` pkg

* change bundling strategy for `web5-proxy-agent` pkg

* change bundling strategy for `web5` pkg

* switch tests back to hitting deployed nodes

* bump `dwn-sdk-js`

* bump versions

* version bumps

* alpha versions

* fix `cjs` packages

* (common) fix `cjs`

* bump ion-tools

* remove hardcoded alpha version

* use non-alpha version of `dwn-sdk-js`

* update vscode launch configurations and tasks

* bump `dwn-sdk-js`

* Use the same version of playwright and ion-tools across packages

Signed-off-by: Frank Hinek <[email protected]>

* Remove exclusive test

Signed-off-by: Frank Hinek <[email protected]>

* Fix failing test due to DWN SDK encryption changes

Signed-off-by: Frank Hinek <[email protected]>

* Fix typo in web5 launch.json and workspace test all

Signed-off-by: Frank Hinek <[email protected]>

* Switch from @playwright/test to playwright

Signed-off-by: Frank Hinek <[email protected]>

---------

Signed-off-by: Frank Hinek <[email protected]>
Co-authored-by: Frank Hinek <[email protected]>
  • Loading branch information
mistermoe and frankhinek authored Aug 4, 2023
1 parent d8e2be7 commit 72facd4
Show file tree
Hide file tree
Showing 121 changed files with 1,168 additions and 1,823 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
**/INDEX/
**/MESSAGESTORE/
data
compiled

**/__tests__/
**/__TESTDATA__/
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"npm.packageManager": "npm"
}
481 changes: 206 additions & 275 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/common/.c8rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
".js"
],
"include": [
"__tests__/src/**"
"tests/compiled/**"
],
"exclude": [
"__tests__/src/main.js",
"__tests__/src/types.js",
"__tests__/types/**"
"tests/compiled/src/main.js",
"tests/compiled/src/types.js",
"tests/compiled/types/**"
],
"reporter": [
"cobertura",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"enable-source-maps": true,
"exit": true,
"spec": ["__tests__/**/*.spec.js"]
"spec": ["tests/compiled/**/*.spec.js"]
}
11 changes: 4 additions & 7 deletions packages/common/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
"request": "launch",
"name": "test:node",
"runtimeExecutable": "${workspaceFolder:root}/node_modules/.bin/mocha",
"runtimeArgs": [
"${workspaceFolder:common}/__tests__/**/*.spec.js"
],
"console": "internalConsole",
"preLaunchTask": "tsc: build - tsconfig.test.json",
"outFiles": [
"${workspaceFolder:common}/__tests__/**/*.js"
],
"preLaunchTask": "build tests",
"skipFiles": [
"<node_internals>/**"
]
}
]
}
18 changes: 5 additions & 13 deletions packages/common/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"label": "npm run build",
"type": "npm",
"script": "build",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
Expand All @@ -27,19 +26,12 @@
}
},
{
"label": "tsc: build - tsconfig.test.json",
"type": "typescript",
"tsconfig": "tsconfig.test.json",
"problemMatcher": [
"$tsc"
],
"group": {
"kind": "build",
"isDefault": false
},
"label": "build tests",
"type": "npm",
"script": "build:tests:node",
"options": {
"cwd": "${workspaceFolder:root}"
"cwd": "${workspaceFolder:common}"
}
},
}
]
}
41 changes: 1 addition & 40 deletions packages/common/build/bundles.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,6 @@
import esbuild from 'esbuild';
import browserConfig from './esbuild-browser-config.cjs';

// cjs bundle for Electron apps. external dependencies bundled except LevelDB
// Remove if/when the following PR is merged and this bundle is no longer needed by Electron apps
// https://github.com/electron/electron/pull/37535
esbuild.buildSync({
platform : 'node',
bundle : true,
format : 'cjs',
// packages: 'external',
external : ['level'],
sourcemap : true,
entryPoints : ['./src/main.ts'],
outfile : './dist/electron/main.cjs',
allowOverwrite : true,
});

// cjs bundle. external dependencies **not** bundled
esbuild.buildSync({
platform : 'node',
bundle : true,
format : 'cjs',
packages : 'external',
sourcemap : true,
entryPoints : ['./src/main.ts'],
outfile : './dist/cjs/main.cjs',
allowOverwrite : true,
});

// esm bundle. external dependencies **not** bundled
esbuild.buildSync({
platform : 'node',
bundle : true,
format : 'esm',
packages : 'external',
sourcemap : true,
entryPoints : ['./src/main.ts'],
outfile : './dist/esm/main.mjs',
allowOverwrite : true,
});

// esm polyfilled bundle for browser
esbuild.build({
...browserConfig,
Expand All @@ -50,6 +11,6 @@ esbuild.build({
esbuild.build({
...browserConfig,
format : 'iife',
globalName : 'Web5',
globalName : 'Web5Common',
outfile : 'dist/browser.js',
});
26 changes: 26 additions & 0 deletions packages/common/build/cjs-bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import esbuild from 'esbuild';
import packageJson from '../package.json' assert { type: 'json' };

// list of dependencies that _dont_ ship cjs
const includeList = new Set(['multiformats']);

// create list of dependencies that we _do not_ want to include in our bundle
const excludeList = [];
for (const dependency in packageJson.dependencies) {
if (includeList.has(dependency)) {
continue;
} else {
excludeList.push(dependency);
}
}

esbuild.build({
entryPoints : [ './src/main.ts' ],
bundle : true,
external : excludeList,
format : 'cjs',
sourcemap : true,
platform : 'node',
outfile : 'dist/cjs/main.js',
allowOverwrite : true
});
6 changes: 0 additions & 6 deletions packages/common/build/esbuild-browser-config.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin');
const stdLibBrowser = require('node-stdlib-browser');

/** @type {import('esbuild').BuildOptions} */
module.exports = {
entryPoints : ['./src/main.ts'],
Expand All @@ -11,8 +7,6 @@ module.exports = {
minify : true,
platform : 'browser',
target : ['chrome101', 'firefox108', 'safari16'],
inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')],
plugins : [polyfillProviderPlugin(stdLibBrowser)],
define : {
'global': 'globalThis',
},
Expand Down
45 changes: 15 additions & 30 deletions packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{
"name": "@tbd54566975/common",
"version": "0.1.1",
"version": "0.8.0",
"type": "module",
"main": "./dist/cjs/main.cjs",
"module": "./dist/esm/main.mjs",
"main": "./dist/cjs/main.js",
"module": "./dist/esm/main.js",
"types": "./dist/types/main.d.ts",
"scripts": {
"build": "rimraf dist && node build/bundles.js && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json && tsc",
"clean": "rimraf dist coverage tests/compiled",
"build:esm": "rimraf dist/esm dist/types && npx tsc -p tsconfig.json",
"build:cjs": "rimraf dist/cjs && node build/cjs-bundle.js && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json",
"build:browser": "rimraf dist/browser.mjs dist/browser.js && node build/bundles.js",
"build:tests:node": "rimraf tests/compiled && tsc -p tests/tsconfig.json",
"build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:browser",
"lint": "eslint . --ext .ts --max-warnings 0",
"lint:fix": "eslint . --ext .ts --fix",
"test:node": "rimraf __tests__ && tsc -p tsconfig.test.json && c8 mocha",
"test:node": "npm run build:tests:node && c8 mocha",
"test:browser": "karma start karma.conf.cjs"
},
"homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/common#readme",
Expand Down Expand Up @@ -40,31 +45,12 @@
],
"exports": {
".": {
"import": "./dist/esm/main.mjs",
"require": "./dist/cjs/main.cjs",
"types": "./dist/types/main.d.ts"
},
"./browser": {
"import": "./dist/browser.mjs",
"require": "./dist/browser.js",
"types": "./dist/types/main.d.ts"
},
"./electron": {
"import": "./dist/esm/main.mjs",
"require": "./dist/electron/main.cjs",
"import": "./dist/esm/main.js",
"require": "./dist/cjs/main.js",
"types": "./dist/types/main.d.ts"
}
},
"browser": {
"./dist/esm/main.mjs": "./dist/browser.mjs",
"./dist/cjs/main.cjs": "./dist/browser.js",
"types": "./dist/types/main.d.ts"
},
"react-native": {
"./dist/esm/main.mjs": "./dist/esm/main.mjs",
"./dist/cjs/main.cjs": "./dist/esm/main.mjs",
"types": "./dist/types/main.d.ts"
},
"react-native": "./dist/esm/main.js",
"keywords": [
"decentralized",
"decentralized-applications",
Expand Down Expand Up @@ -103,9 +89,8 @@
"karma-mocha-reporter": "2.2.5",
"karma-webkit-launcher": "2.1.0",
"mocha": "10.2.0",
"node-stdlib-browser": "1.2.0",
"playwright": "1.31.2",
"playwright": "1.36.2",
"rimraf": "4.4.0",
"typescript": "5.0.4"
"typescript": "5.1.6"
}
}
14 changes: 7 additions & 7 deletions packages/common/src/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export class MemoryStore<K, V> implements KeyValueStore<K, V> {
/**
* A private field that contains the Map used as the key-value store.
*/
#store: Map<K, V> = new Map();
private store: Map<K, V> = new Map();

/**
* Clears all entries in the key-value store.
*
* @returns A Promise that resolves when the operation is complete.
*/
async clear(): Promise<void> {
this.#store.clear();
this.store.clear();
}

/**
Expand All @@ -49,7 +49,7 @@ export class MemoryStore<K, V> implements KeyValueStore<K, V> {
* @returns A Promise that resolves to a boolean indicating whether the entry was successfully deleted.
*/
async delete(id: K): Promise<boolean> {
return this.#store.delete(id);
return this.store.delete(id);
}

/**
Expand All @@ -59,7 +59,7 @@ export class MemoryStore<K, V> implements KeyValueStore<K, V> {
* @returns A Promise that resolves to the value of the entry, or `undefined` if the entry does not exist.
*/
async get(id: K): Promise<V | undefined> {
return this.#store.get(id);
return this.store.get(id);
}

/**
Expand All @@ -69,7 +69,7 @@ export class MemoryStore<K, V> implements KeyValueStore<K, V> {
* @returns A Promise that resolves to a boolean indicating whether an element with the specified key exists or not.
*/
async has(id: K): Promise<boolean> {
return this.#store.has(id);
return this.store.has(id);
}

/**
Expand All @@ -78,7 +78,7 @@ export class MemoryStore<K, V> implements KeyValueStore<K, V> {
* @returns A Promise that resolves to an array of all values in the store.
*/
async list(): Promise<V[]> {
return Array.from(this.#store.values());
return Array.from(this.store.values());
}

/**
Expand All @@ -89,6 +89,6 @@ export class MemoryStore<K, V> implements KeyValueStore<K, V> {
* @returns A Promise that resolves when the operation is complete.
*/
async set(id: K, key: V): Promise<void> {
this.#store.set(id, key);
this.store.set(id, key);
}
}
15 changes: 15 additions & 0 deletions packages/common/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "compiled",
"declarationDir": "compiled/types",
"sourceMap": true,
},
"include": [
"../src",
".",
],
"exclude": [
"./compiled"
]
}
18 changes: 18 additions & 0 deletions packages/common/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"lib": [
"DOM",
"ES5",
],
"target": "ES5",
"module": "CommonJS",
"outDir": "dist/cjs",
"declaration": false,
"declarationMap": false,
"declarationDir": null
},
"include": [
"src"
]
}
6 changes: 1 addition & 5 deletions packages/common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"module": "ESNext", // Required for enabling JavaScript import assertion support
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"declarationDir": "dist/types",
"outDir": "dist/esm",
"sourceMap": true,
// `NodeNext` will throw compilation errors if relative import paths are missing file extension
// reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js
Expand All @@ -20,9 +20,5 @@
},
"include": [
"src",
],
"exclude": [
"node_modules",
"dist"
]
}
Loading

0 comments on commit 72facd4

Please sign in to comment.