Skip to content

Commit d1e2d10

Browse files
mistermoefrankhinek
authored andcommitted
scaffold common package
1 parent e1c4700 commit d1e2d10

17 files changed

Lines changed: 7556 additions & 2350 deletions

File tree

package-lock.json

Lines changed: 7192 additions & 2342 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"workspaces": [
3-
"packages/web5-agent",
4-
"packages/credentials",
3+
"packages/common",
54
"packages/crypto",
5+
"packages/web5-agent",
66
"packages/dids",
7-
"packages/web5",
7+
"packages/credentials",
8+
"packages/web5-user-agent",
89
"packages/web5-proxy-agent",
9-
"packages/web5-user-agent"
10+
"packages/web5"
1011
],
1112
"scripts": {
1213
"clean": "npx npkill -d $(pwd) -t node_modules && npx npkill -d $(pwd) -t dist",

packages/common/.c8rc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"all": true,
3+
"cache": false,
4+
"extension": [
5+
".js"
6+
],
7+
"include": [
8+
"__tests__/src/**"
9+
],
10+
"exclude": [
11+
"__tests__/src/main.js",
12+
"__tests__/types/**"
13+
],
14+
"reporter": [
15+
"cobertura",
16+
"text"
17+
]
18+
}

packages/common/.mocharc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"enable-source-maps": true,
3+
"exit": true,
4+
"spec": ["__tests__/**/*.spec.js"]
5+
}

packages/common/build/bundles.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import esbuild from 'esbuild';
2+
import browserConfig from './esbuild-browser-config.cjs';
3+
4+
// cjs bundle for Electron apps. external dependencies bundled except LevelDB
5+
// Remove if/when the following PR is merged and this bundle is no longer needed by Electron apps
6+
// https://github.com/electron/electron/pull/37535
7+
esbuild.buildSync({
8+
platform : 'node',
9+
bundle : true,
10+
format : 'cjs',
11+
// packages: 'external',
12+
external : ['level'],
13+
sourcemap : true,
14+
entryPoints : ['./src/main.ts'],
15+
outfile : './dist/electron/main.cjs',
16+
allowOverwrite : true,
17+
});
18+
19+
// cjs bundle. external dependencies **not** bundled
20+
esbuild.buildSync({
21+
platform : 'node',
22+
bundle : true,
23+
format : 'cjs',
24+
packages : 'external',
25+
sourcemap : true,
26+
entryPoints : ['./src/main.ts'],
27+
outfile : './dist/cjs/main.cjs',
28+
allowOverwrite : true,
29+
});
30+
31+
// esm bundle. external dependencies **not** bundled
32+
esbuild.buildSync({
33+
platform : 'node',
34+
bundle : true,
35+
format : 'esm',
36+
packages : 'external',
37+
sourcemap : true,
38+
entryPoints : ['./src/main.ts'],
39+
outfile : './dist/esm/main.mjs',
40+
allowOverwrite : true,
41+
});
42+
43+
// esm polyfilled bundle for browser
44+
esbuild.build({
45+
...browserConfig,
46+
outfile: 'dist/browser.mjs',
47+
});
48+
49+
// iife polyfilled bundle for browser
50+
esbuild.build({
51+
...browserConfig,
52+
format : 'iife',
53+
globalName : 'Web5',
54+
outfile : 'dist/browser.js',
55+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin');
3+
const stdLibBrowser = require('node-stdlib-browser');
4+
5+
/** @type {import('esbuild').BuildOptions} */
6+
module.exports = {
7+
entryPoints : ['./src/main.ts'],
8+
bundle : true,
9+
format : 'esm',
10+
sourcemap : true,
11+
minify : true,
12+
platform : 'browser',
13+
target : ['chrome101', 'firefox108', 'safari16'],
14+
inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')],
15+
plugins : [polyfillProviderPlugin(stdLibBrowser)],
16+
define : {
17+
'global': 'globalThis',
18+
},
19+
};

packages/common/karma.conf.cjs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
// Karma is what we're using to run our tests in browser environments
3+
// Karma does not support .mjs
4+
5+
// playwright acts as a safari executable on windows and mac
6+
const playwright = require('@playwright/test');
7+
const esbuildBrowserConfig = require('./build/esbuild-browser-config.cjs');
8+
9+
// use playwright chrome exec path as run target for chromium tests
10+
process.env.CHROME_BIN = playwright.chromium.executablePath();
11+
12+
// use playwright webkit exec path as run target for safari tests
13+
process.env.WEBKIT_HEADLESS_BIN = playwright.webkit.executablePath();
14+
15+
// use playwright firefox exec path as run target for firefox tests
16+
process.env.FIREFOX_BIN = playwright.firefox.executablePath();
17+
18+
module.exports = function (config) {
19+
config.set({
20+
plugins: [
21+
'karma-chrome-launcher',
22+
'karma-firefox-launcher',
23+
'karma-webkit-launcher',
24+
'karma-esbuild',
25+
'karma-mocha',
26+
'karma-mocha-reporter',
27+
],
28+
29+
// frameworks to use
30+
// available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter
31+
frameworks: ['mocha'],
32+
33+
// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
34+
client: {
35+
mocha: {
36+
timeout: 10000 // 10 seconds
37+
}
38+
},
39+
40+
41+
// list of files / patterns to load in the browser
42+
files: [
43+
{ pattern: 'tests/**/*.spec.ts', watched: false },
44+
],
45+
46+
// preprocess matching files before serving them to the browser
47+
// available preprocessors: https://www.npmjs.com/search?q=keywords:karma-preprocessor
48+
preprocessors: {
49+
'tests/**/*.spec.ts': ['esbuild'],
50+
},
51+
52+
esbuild: esbuildBrowserConfig,
53+
54+
// list of files / patterns to exclude
55+
exclude: [],
56+
57+
// test results reporter to use
58+
// available reporters: https://www.npmjs.com/search?q=keywords:karma-reporter
59+
reporters: ['mocha'],
60+
61+
// web server port
62+
port: 9876,
63+
64+
// enable / disable colors in the output (reporters and logs)
65+
colors: true,
66+
67+
// level of logging
68+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN ||
69+
// config.LOG_INFO || config.LOG_DEBUG
70+
logLevel: config.LOG_INFO,
71+
72+
concurrency: 1,
73+
74+
// start these browsers
75+
// available browser launchers: https://www.npmjs.com/search?q=keywords:karma-launcher
76+
browsers: ['ChromeHeadless', 'FirefoxHeadless', 'WebkitHeadless'],
77+
78+
// Continuous Integration mode
79+
// if true, Karma captures browsers, runs the tests and exits
80+
singleRun: true,
81+
82+
// Increase browser timeouts to avoid DISCONNECTED messages during GitHub CI runs.
83+
browserDisconnectTimeout : 10000, // default 2000
84+
browserDisconnectTolerance : 1, // default 0
85+
});
86+
};

packages/common/package.json

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{
2+
"name": "@tbd54566975/common",
3+
"version": "0.1.0",
4+
"type": "module",
5+
"main": "./dist/cjs/main.cjs",
6+
"module": "./dist/esm/main.mjs",
7+
"types": "./dist/types/main.d.ts",
8+
"scripts": {
9+
"build": "rimraf dist && node build/bundles.js && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json && tsc",
10+
"lint": "eslint . --ext .ts --max-warnings 0",
11+
"lint:fix": "eslint . --ext .ts --fix",
12+
"test:node": "rimraf __tests__ && tsc -p tsconfig.test.json && c8 mocha",
13+
"test:browser": "karma start karma.conf.cjs"
14+
},
15+
"homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/common#readme",
16+
"bugs": "https://github.com/TBD54566975/web5-js/issues",
17+
"repository": {
18+
"type": "git",
19+
"url": "git+https://github.com/TBD54566975/web5-js",
20+
"directory": "packages/common"
21+
},
22+
"license": "Apache-2.0",
23+
"contributors": [
24+
{
25+
"name": "Daniel Buchner",
26+
"url": "https://github.com/csuwildcat"
27+
},
28+
{
29+
"name": "Frank Hinek",
30+
"url": "https://github.com/frankhinek"
31+
},
32+
{
33+
"name": "Moe Jangda",
34+
"url": "https://github.com/mistermoe"
35+
}
36+
],
37+
"files": [
38+
"dist",
39+
"src"
40+
],
41+
"exports": {
42+
".": {
43+
"import": "./dist/esm/main.mjs",
44+
"require": "./dist/cjs/main.cjs",
45+
"types": "./dist/types/main.d.ts"
46+
},
47+
"./browser": {
48+
"import": "./dist/browser.mjs",
49+
"require": "./dist/browser.js",
50+
"types": "./dist/types/main.d.ts"
51+
},
52+
"./electron": {
53+
"import": "./dist/esm/main.mjs",
54+
"require": "./dist/electron/main.cjs",
55+
"types": "./dist/types/main.d.ts"
56+
}
57+
},
58+
"browser": {
59+
"./dist/esm/main.mjs": "./dist/browser.mjs",
60+
"./dist/cjs/main.cjs": "./dist/browser.js",
61+
"types": "./dist/types/main.d.ts"
62+
},
63+
"keywords": [
64+
"decentralized",
65+
"decentralized-applications",
66+
"decentralized-identity",
67+
"decentralized-web",
68+
"vcs",
69+
"verifiable credentials",
70+
"web5"
71+
],
72+
"publishConfig": {
73+
"access": "public"
74+
},
75+
"engines": {
76+
"node": ">=18.0.0"
77+
},
78+
"dependencies": {},
79+
"devDependencies": {
80+
"@types/chai": "4.3.0",
81+
"@types/eslint": "8.37.0",
82+
"@types/mocha": "10.0.1",
83+
"@typescript-eslint/eslint-plugin": "5.59.0",
84+
"@typescript-eslint/parser": "5.59.0",
85+
"c8": "7.14.0",
86+
"chai": "4.3.7",
87+
"esbuild": "0.16.7",
88+
"eslint": "8.39.0",
89+
"eslint-plugin-mocha": "10.1.0",
90+
"karma": "6.4.1",
91+
"karma-chai": "0.1.0",
92+
"karma-chrome-launcher": "3.1.1",
93+
"karma-esbuild": "2.2.5",
94+
"karma-firefox-launcher": "2.1.2",
95+
"karma-mocha": "2.0.1",
96+
"karma-mocha-reporter": "2.2.5",
97+
"karma-webkit-launcher": "2.1.0",
98+
"mocha": "10.2.0",
99+
"node-stdlib-browser": "1.2.0",
100+
"playwright": "1.31.2",
101+
"rimraf": "4.4.0",
102+
"typescript": "5.0.4"
103+
},
104+
"overrides": {
105+
"socket.io-parser@>4.0.4 <4.2.3": "4.2.3"
106+
}
107+
}

packages/common/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './types.js';
File renamed without changes.

0 commit comments

Comments
 (0)