Skip to content

Commit 7c51219

Browse files
authored
Add CommonJS module (#11)
* add CommonJS module * add copy plugin
1 parent 29e7188 commit 7c51219

File tree

8 files changed

+152
-8
lines changed

8 files changed

+152
-8
lines changed

cjs-package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

examples/node/.eslintrc.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"plugins": [
4+
"@typescript-eslint",
5+
"prettier"
6+
],
7+
"extends": [
8+
"eslint:recommended",
9+
"prettier"
10+
],
11+
"rules": {
12+
"no-console": 0,
13+
"prettier/prettier": 1,
14+
"@typescript-eslint/no-explicit-any": 0,
15+
"no-empty-function": 0,
16+
"@typescript-eslint/no-empty-function": 0,
17+
"@typescript-eslint/no-var-requires": 0
18+
},
19+
"env": {
20+
"node": true
21+
}
22+
}

examples/node/main.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import { Client } from '@blyss/sdk';
1+
import type { Client } from '@blyss/sdk';
2+
const blyss = require('@blyss/sdk/node');
3+
4+
process.removeAllListeners('warning');
5+
if (typeof crypto === 'undefined') {
6+
throw 'Requires Node 19+';
7+
}
28

39
async function main() {
4-
const client = new Client('<YOUR API KEY HERE>');
10+
const client: Client = new blyss.Client('<YOUR API KEY HERE>');
511

612
// Create the bucket
713
const bucketName = 'state-capitals';

examples/node/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"type": "module",
32
"dependencies": {
43
"@blyss/sdk": "latest"
54
},

examples/node/tsconfig.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{
22
"compilerOptions": {
3-
"module": "ES6",
43
"target": "ES6",
54
"moduleResolution": "node",
6-
},
7-
"ts-node": {
8-
"esm": true,
95
}
106
}

package-lock.json

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

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
"type": "module",
77
"main": "./dist/index.js",
88
"types": "./dist/index.d.ts",
9+
"exports": {
10+
".": "./dist/index.js",
11+
"./cjs": "./dist/cjs/index.cjs",
12+
"./node": "./dist/cjs/index.cjs"
13+
},
914
"sideEffects": true,
1015
"homepage": "https://github.com/blyssprivacy/sdk#readme",
1116
"repository": {
@@ -39,6 +44,7 @@
3944
"@typescript-eslint/eslint-plugin": "^5.42.0",
4045
"@typescript-eslint/parser": "^5.42.0",
4146
"@wasm-tool/wasm-pack-plugin": "^1.6.0",
47+
"copy-webpack-plugin": "^11.0.0",
4248
"eslint": "^8.26.0",
4349
"eslint-config-prettier": "^8.5.0",
4450
"eslint-plugin-prettier": "^4.2.1",

webpack.config.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import WasmPackPlugin from '@wasm-tool/wasm-pack-plugin';
22
import path from 'path';
33
import { fileURLToPath } from 'url';
4+
import CopyPlugin from 'copy-webpack-plugin';
45

56
const __filename = fileURLToPath(import.meta.url);
67
const __dirname = path.dirname(__filename);
78

89
const dist = path.resolve(__dirname, 'dist');
910
const distLib = path.resolve(dist, 'lib');
11+
const distCjs = path.resolve(dist, 'cjs');
1012

1113
const config = {
1214
name: 'web',
@@ -81,4 +83,25 @@ const webSingleFileTarget = {
8183
}
8284
};
8385

84-
export default [webTarget, webSingleFileTarget];
86+
const nodeTarget = {
87+
...config,
88+
name: 'node',
89+
dependencies: ['web'],
90+
output: {
91+
path: dist + '/cjs',
92+
filename: 'index.cjs',
93+
library: {
94+
type: 'commonjs'
95+
}
96+
},
97+
experiments: {
98+
asyncWebAssembly: true
99+
},
100+
target: 'node',
101+
plugins: [
102+
new CopyPlugin({
103+
patterns: [{ from: '../cjs-package.json', to: distCjs + '/package.json' }]
104+
})
105+
]
106+
};
107+
export default [webTarget, webSingleFileTarget, nodeTarget];

0 commit comments

Comments
 (0)