Skip to content

Commit

Permalink
Reorganize the wasm node by moving files around (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka authored May 5, 2023
1 parent f3c0753 commit 8135dba
Show file tree
Hide file tree
Showing 16 changed files with 20 additions and 20 deletions.
10 changes: 5 additions & 5 deletions wasm-node/javascript/prepare.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ child_process.execSync(
{ 'stdio': 'inherit', 'env': { 'RUSTFLAGS': '-C target-feature=+bulk-memory,+sign-ext,+simd128', ...process.env } }
);

// The code below will write a variable number of files to the `src/module/autogen` directory.
// The code below will write a variable number of files to the `src/internals/module` directory.
// Start by clearing all existing files from this directory in case there are some left from past
// builds.
const filesToRemove = fs.readdirSync('./src/module/autogen');
const filesToRemove = fs.readdirSync('./src/internals/module');
for (const file of filesToRemove) {
if (!file.startsWith('.')) // Don't want to remove the `.gitignore` or `.npmignore` or similar
fs.unlinkSync(path.join("./src/module/autogen", file));
fs.unlinkSync(path.join("./src/internals/module", file));
}

// We then do an optimization pass on the Wasm file, using `wasm-opt`.
Expand Down Expand Up @@ -124,14 +124,14 @@ try {
const chunk = base64Data.slice(0, 1024 * 1024);
// We could simply export the chunk instead of a function that returns the chunk, but that
// would cause TypeScript to generate a definitions file containing a copy of the entire chunk.
fs.writeFileSync('./src/module/autogen/wasm' + fileNum + '.ts', 'export default function(): string { return "' + chunk + '"; }');
fs.writeFileSync('./src/internals/module/wasm' + fileNum + '.ts', 'export default function(): string { return "' + chunk + '"; }');
imports += 'import { default as wasm' + fileNum + ' } from \'./wasm' + fileNum + '.js\';\n';
chunksSum += ' + wasm' + fileNum + '()';
fileNum += 1;
base64Data = base64Data.slice(1024 * 1024);
}
fs.writeFileSync(
'./src/module/autogen/wasm.ts',
'./src/internals/module/wasm.ts',
imports +
'export default ' + chunksSum
);
Expand Down
4 changes: 2 additions & 2 deletions wasm-node/javascript/src/index-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
/// <reference lib="dom" />

import { Client, ClientOptions } from './public-types.js'
import { start as innerStart, Connection, ConnectionConfig } from './client.js'
import { multibaseBase64Decode } from './base64.js'
import { start as innerStart, Connection, ConnectionConfig } from './internals/client.js'
import { multibaseBase64Decode } from './internals/base64.js'
import { compileModule } from './module-browser.js'

export {
Expand Down
2 changes: 1 addition & 1 deletion wasm-node/javascript/src/index-deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { Client, ClientOptions } from './public-types.js'
import { start as innerStart, Connection, ConnectionConfig } from './client.js'
import { start as innerStart, Connection, ConnectionConfig } from './internals/client.js'
import { compileModule } from './module-deno.js'

export {
Expand Down
2 changes: 1 addition & 1 deletion wasm-node/javascript/src/index-nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// with both at the same time.

import { Client, ClientOptions } from './public-types.js'
import { start as innerStart, Connection, ConnectionConfig } from './client.js'
import { start as innerStart, Connection, ConnectionConfig } from './internals/client.js'
import { compileModule } from './module-nodejs.js'

import { WebSocket } from 'ws';
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { Client, ClientOptions, QueueFullError, AlreadyDestroyedError, AddChainError, AddChainOptions, Chain, JsonRpcDisabledError, MalformedJsonRpcError, CrashError } from './public-types.js';
import * as instance from './instance/local.js';
import * as remote from './instance/remote.js';
import { Client, ClientOptions, QueueFullError, AlreadyDestroyedError, AddChainError, AddChainOptions, Chain, JsonRpcDisabledError, MalformedJsonRpcError, CrashError } from '../public-types.js';
import * as instance from './local-instance.js';
import * as remote from './remote-instance.js';

/**
* Contains functions that the client will use when it needs to leverage the platform.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// is ready to accept more JSON-RPC responses, after which the server can send responses at any
// time and the client queues them locally.

import * as instance from './local.js';
import * as instance from './local-instance.js';

export interface ConnectConfig {
wasmModule: Promise<WebAssembly.Module>,
Expand Down
4 changes: 2 additions & 2 deletions wasm-node/javascript/src/module-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { default as wasmBase64 } from './module/autogen/wasm.js';
import { classicDecode } from './base64.js'
import { default as wasmBase64 } from './internals/module/wasm.js';
import { classicDecode } from './internals/base64.js'
import { inflate } from 'pako';

/**
Expand Down
2 changes: 1 addition & 1 deletion wasm-node/javascript/src/module-deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { default as wasmBase64 } from './module/autogen/wasm.js';
import { default as wasmBase64 } from './internals/module/wasm.js';

/**
* Compiles and returns the smoldot WebAssembly binary.
Expand Down
2 changes: 1 addition & 1 deletion wasm-node/javascript/src/module-nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { default as wasmBase64 } from './module/autogen/wasm.js';
import { default as wasmBase64 } from './internals/module/wasm.js';
import { inflate } from 'pako';

/**
Expand Down
2 changes: 1 addition & 1 deletion wasm-node/javascript/src/worker-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import * as instance from './instance/remote.js'
import * as instance from './internals/remote-instance.js'

/**
* Runs the CPU-heavy parts of smoldot. Must be passed a port whose other end is passed to
Expand Down
2 changes: 1 addition & 1 deletion wasm-node/javascript/src/worker-deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import * as instance from './instance/remote.js'
import * as instance from './internals/remote-instance.js'

/**
* Runs the CPU-heavy parts of smoldot. Must be passed a port whose other end is passed to
Expand Down
2 changes: 1 addition & 1 deletion wasm-node/javascript/src/worker-nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import * as instance from './instance/remote.js'
import * as instance from './internals/remote-instance.js'
import { performance } from 'node:perf_hooks';
import { randomFillSync } from 'node:crypto';

Expand Down

0 comments on commit 8135dba

Please sign in to comment.