Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CJS projects #2487

Merged
merged 26 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bee1764
Add support for CJS projects
wirednkod Jul 8, 2022
68ad7dd
Add Changelog entry
wirednkod Jul 8, 2022
644933e
Add Changelog entry
wirednkod Jul 8, 2022
f70a2c4
Merge branch 'main' of github.com:wirednkod/smoldot into nik-add-cjs-…
wirednkod Jul 8, 2022
b8e6f6b
minor fixes to package.json
wirednkod Jul 8, 2022
029884d
replace yarn install v1.22.15
wirednkod Jul 9, 2022
7aa4c29
replace yarn install v1.22.15
wirednkod Jul 9, 2022
9912cf1
replace yarn install v1.22.15
wirednkod Jul 9, 2022
b2c2ce5
Merge branch 'main' into nik-add-cjs-support
wirednkod Jul 9, 2022
096f04c
remove erroneous files
wirednkod Jul 11, 2022
f738271
remove 'extra' demo and fix pacakge.json accordingly
wirednkod Jul 11, 2022
97f994d
Merge branch 'main' into nik-add-cjs-support
wirednkod Jul 11, 2022
4a31e0a
merge
wirednkod Jul 13, 2022
8f5f692
merge
wirednkod Jul 13, 2022
3434146
remove sed
wirednkod Jul 13, 2022
c56c4a2
Merge branch 'main' into nik-add-cjs-support
wirednkod Jul 13, 2022
b7d7d5e
Update bin/wasm-node/javascript/package.json
wirednkod Jul 13, 2022
7147c37
Update bin/wasm-node/javascript/package.json
wirednkod Jul 13, 2022
4e68b6e
Update bin/wasm-node/javascript/tsconfig-cjs.json
wirednkod Jul 13, 2022
8d5637e
Address PR comments
wirednkod Jul 13, 2022
c1d762b
Fix Changelog
wirednkod Jul 13, 2022
4fd9541
Fix Changelog
wirednkod Jul 13, 2022
5679d22
remove from gitignore fix-package-type file
wirednkod Jul 13, 2022
de87cce
Fix tests; add module in package json in order to avoid renaming to m…
wirednkod Jul 13, 2022
42577b8
remove type module and rename files to mjs
wirednkod Jul 13, 2022
1aff5e7
Remove yarn lock
wirednkod Jul 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bin/wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Added

- Add support for CommonJS projects. ([#2487](https://github.com/paritytech/smoldot/pull/2487))

### Changed

- No WebWorker/worker thread is spawned anymore by the JavaScript code. The WebAssembly virtual machine that runs smoldot is now directly instantiated by the `start` function. This should fix compatibility issues with various JavaScript bundlers. ([#2498](https://github.com/paritytech/smoldot/pull/2498))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

// This file launches a WebSocket server that exposes JSON-RPC functions.

import * as smoldot from '../dist/index.js';
import * as smoldot from '../dist/mjs/index.js';
import { default as websocket } from 'websocket';
import * as http from 'node:http';
import * as process from 'node:process';
Expand Down
16 changes: 16 additions & 0 deletions bin/wasm-node/javascript/fix-package-type.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# Adds package.json files to cjs/mjs subtrees with the respective type needed for
# the target environment.
#

cat >dist/cjs/package.json <<!EOF
{
"type": "commonjs"
}
!EOF

cat >dist/mjs/package.json <<!EOF
{
"type": "module"
}
!EOF
2 changes: 2 additions & 0 deletions bin/wasm-node/javascript/package-lock.json

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

24 changes: 16 additions & 8 deletions bin/wasm-node/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@
"url": "https://github.com/paritytech/smoldot/issues"
},
"files": ["dist"],
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.js",
"main": "dist/cjs/index.js",
"types": "dist/mjs/index.d.ts",
"module": "dist/mjs/index.js",
"exports": {
".": {
"import": "./dist/mjs/index.js",
"require": "./dist/cjs/index.js"
}
},
"scripts": {
"prepublishOnly": "node prepare.js --release && rimraf ./dist && tsc",
"build": "node prepare.js --release && rimraf ./dist && tsc",
"start": "node prepare.js --debug && rimraf ./dist && tsc && node demo/demo.js",
"test": "node prepare.js --debug && rimraf ./dist && tsc && ava --timeout=2m --concurrency 2 --no-worker-threads"
"buildModules": "tsc -p tsconfig-mjs.json && tsc -p tsconfig-cjs.json && bash fix-package-type.sh",
"prepublishOnly": "node prepare.mjs --release && rimraf ./dist && npm run buildModules",
"build": "node prepare.mjs --release && rimraf ./dist && npm run buildModules",
"start": "node prepare.mjs --debug && rimraf ./dist && npm run buildModules && node demo/demo.mjs",
"test": "node prepare.mjs --debug && rimraf ./dist && npm run buildModules && ava --timeout=2m --concurrency 2 --no-worker-threads"
},
"browser": {
"./dist/compat/index.js": "./dist/compat/index-browser-overwrite.js"
"./dist/mjs/compat/index.js": "./dist/mjs/compat/index-browser-overwrite.js",
"./dist/cjs/compat/index.js": "./dist/cjs/compat/index-browser-overwrite.js"
},
"dependencies": {
"buffer": "^6.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import test from 'ava';
import * as fs from 'node:fs';
import { start } from "../dist/index.js";
import { start } from "../dist/mjs/index.js";

const westendSpec = fs.readFileSync('./test/westend.json', 'utf8');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import test from 'ava';
import * as fs from 'node:fs';
import { start } from "../dist/index.js";
import { start } from "../dist/mjs/index.js";

const westendSpec = fs.readFileSync('./test/westend.json', 'utf8');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import test from 'ava';
import * as fs from 'node:fs';
import { start } from "../dist/index.js";
import { start } from "../dist/mjs/index.js";

const westendSpec = fs.readFileSync('./test/westend.json', 'utf8');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import test from 'ava';
import * as fs from 'node:fs';
import { start } from "../dist/index.js";
import { start } from "../dist/mjs/index.js";

const westendSpec = fs.readFileSync('./test/westend.json', 'utf8');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import test from 'ava';
import * as fs from 'node:fs';
import { start } from "../dist/index.js";
import { start } from "../dist/mjs/index.js";

const westendSpec = fs.readFileSync('./test/westend.json', 'utf8');

Expand Down
11 changes: 11 additions & 0 deletions bin/wasm-node/javascript/tsconfig-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"lib": [
"es2015"
],
"target": "es2015",
"module": "commonjs",
"outDir": "./dist/cjs",
},
}
11 changes: 11 additions & 0 deletions bin/wasm-node/javascript/tsconfig-mjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"lib": [
"es2020"
],
"target": "es2020",
"module": "es2020",
"outDir": "./dist/mjs",
}
}
8 changes: 1 addition & 7 deletions bin/wasm-node/javascript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
{
"compilerOptions": {
"lib": [
"es2020"
],
"target": "es2020",
"module": "es2020",
"outDir": "./dist",
"declaration": true,
"allowJs": true,
"allowSyntheticDefaultImports": true,

"esModuleInterop": true,
"strict": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
Expand Down