chore: fix build [fixes DXJ-482] (#352)

* Remove additional node targeted build

* Fix test errors

* Typo fix

* Remove headless

* Prevent JSON error

* Cache json parsing

* Remove resource test as it's not working in new nox

* Fix test output

* enable smoke tests

* add puppeteer to deps

* Remove headless option
This commit is contained in:
Akim 2023-09-29 16:23:06 +07:00 committed by GitHub
parent 63e4ce3f84
commit 15a2c91917
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 414 additions and 706 deletions

View File

@ -6,7 +6,7 @@ on:
nox-image: nox-image:
description: "nox image tag" description: "nox image tag"
type: string type: string
default: "fluencelabs/nox:minimal_0.2.5" default: "fluencelabs/nox:minimal_0.2.9"
avm-version: avm-version:
description: "@fluencelabs/avm version" description: "@fluencelabs/avm version"
type: string type: string

View File

@ -53,15 +53,6 @@ export const runTest = async (): Promise<TestResult> => {
console.log('my peer id: ', client.getPeerId()); console.log('my peer id: ', client.getPeerId());
console.log('my sk id: ', fromByteArray(client.getPeerSecretKey())); console.log('my sk id: ', fromByteArray(client.getPeerSecretKey()));
console.log('running resource test...');
const [res, errors] = await resourceTest('my_resource');
if (res === null) {
console.log('resource test failed, errors', errors);
return { type: 'failure', error: errors.join(', ') };
} else {
console.log('resource test finished, result', res);
}
console.log('running hello test...'); console.log('running hello test...');
const hello = await helloTest(); const hello = await helloTest();
console.log('hello test finished, result: ', hello); console.log('hello test finished, result: ', hello);
@ -75,9 +66,8 @@ export const runTest = async (): Promise<TestResult> => {
console.log('marine test finished, result: ', marine); console.log('marine test finished, result: ', marine);
const returnVal = { const returnVal = {
res,
hello, hello,
// marine, marine,
}; };
return { type: 'success', data: JSON.stringify(returnVal) }; return { type: 'success', data: JSON.stringify(returnVal) };
} finally { } finally {

View File

@ -11,7 +11,7 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"test_commented_out": "node --loader ts-node/esm ./src/index.ts" "test": "node --loader ts-node/esm ./src/index.ts"
}, },
"repository": "https://github.com/fluencelabs/fluence-js", "repository": "https://github.com/fluencelabs/fluence-js",
"author": "Fluence Labs", "author": "Fluence Labs",

View File

@ -19,10 +19,11 @@
"web-vitals": "2.1.4" "web-vitals": "2.1.4"
}, },
"devDependencies": { "devDependencies": {
"@test/test-utils": "workspace:^" "@test/test-utils": "workspace:^",
"puppeteer": "19.7.2"
}, },
"scripts": { "scripts": {
"test_commented_out": "node --loader ts-node/esm ./test/index.ts", "test": "node --loader ts-node/esm ./test/index.ts",
"simulate-cdn": "http-server -p 8766 ../../../client/js-client.web.standalone/dist", "simulate-cdn": "http-server -p 8766 ../../../client/js-client.web.standalone/dist",
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",

View File

@ -19,7 +19,7 @@ const test = async () => {
} }
console.log('starting puppeteer...'); console.log('starting puppeteer...');
const browser = await puppeteer.launch({ headless: false }); const browser = await puppeteer.launch();
const page = (await browser.pages())[0]; const page = (await browser.pages())[0];
// uncomment to debug what's happening inside the browser // uncomment to debug what's happening inside the browser

View File

@ -12,7 +12,7 @@
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"simulate-cdn": "http-server -p 8765 ../../../client/js-client.web.standalone/dist", "simulate-cdn": "http-server -p 8765 ../../../client/js-client.web.standalone/dist",
"test_commented_out": "node --loader ts-node/esm ./src/index.ts", "test": "node --loader ts-node/esm ./src/index.ts",
"serve": "http-server public" "serve": "http-server public"
}, },
"repository": "https://github.com/fluencelabs/fluence-js", "repository": "https://github.com/fluencelabs/fluence-js",
@ -22,5 +22,7 @@
"@fluencelabs/js-client": "workspace:^", "@fluencelabs/js-client": "workspace:^",
"@test/test-utils": "workspace:../../test-utils" "@test/test-utils": "workspace:../../test-utils"
}, },
"devDependencies": {} "devDependencies": {
"puppeteer": "19.7.2"
}
} }

View File

@ -1,102 +0,0 @@
import path, { dirname } from 'path';
import type { InlineConfig, PluginOption } from 'vite';
import { build } from 'vite';
import { builtinModules, createRequire } from 'module';
import tsconfigPaths from 'vite-tsconfig-paths';
import inject from '@rollup/plugin-inject';
import stdLibBrowser from 'node-stdlib-browser';
import { fileURLToPath } from 'url';
import { rm, rename } from 'fs/promises';
import { replaceCodePlugin } from 'vite-plugin-replace';
import pkg from './package.json' assert { type: 'json' };
import libAssetsPlugin from '@laynezh/vite-plugin-lib-assets';
const require = createRequire(import.meta.url);
const commonConfig = (isNode: boolean): InlineConfig & Required<Pick<InlineConfig, 'build'>> => {
const esbuildShim = require.resolve('node-stdlib-browser/helpers/esbuild/shim');
return {
build: {
target: 'modules',
minify: 'esbuild',
lib: {
entry: './src/index.ts',
name: 'js-client',
fileName: `${isNode ? 'node' : 'browser'}/index`,
},
outDir: './dist',
emptyOutDir: false,
...(isNode ? {
rollupOptions: {
external: [...builtinModules, ...builtinModules.map(bm => `node:${bm}`)],
plugins: [
// @ts-ignore
inject({
self: 'global',
'WorkerScope': ['worker_threads', '*'],
'Worker': ['worker_threads', 'Worker'],
'isMainThread': ['worker_threads', 'isMainThread'],
})
]
}
} : {
rollupOptions: {
plugins: [
{
// @ts-ignore
...inject({
global: [esbuildShim, 'global'],
process: [esbuildShim, 'process'],
Buffer: [esbuildShim, 'Buffer']
}), enforce: 'post'
}
],
}
})
},
plugins: [tsconfigPaths(), libAssetsPlugin({
include: ['**/*.wasm*', '**/marine-worker.umd.cjs*'],
publicUrl: '/',
}), ...(isNode ? [replaceCodePlugin({
replacements: [
// After 'threads' package is built, it produces wrong output, which throws runtime errors.
// This code aims to fix such places.
// Should remove this after we move from threads to other package.
{ from: 'eval("require")("worker_threads")', to: 'WorkerScope' },
{ from: 'eval("require")("worker_threads")', to: 'WorkerScope' },
]
})] : [])] as PluginOption[],
optimizeDeps: {
esbuildOptions: {
define: {
global: 'globalThis',
},
},
},
resolve: {
browserField: !isNode,
conditions: isNode ? ['node'] : ['browser']
},
// Used only by browser
define: {
__JS_CLIENT_VERSION__: pkg.version,
__ENV__: isNode ? 'node' : 'browser'
},
};
};
const buildClient = async () => {
const nodeConfig = commonConfig(true);
const browserConfig = commonConfig(false);
try {
await rm('./dist', { recursive: true });
} catch {}
await build(nodeConfig);
await build(browserConfig);
};
buildClient()
.then(() => console.log('Built successfully'))
.catch((err) => console.error('failed', err));

View File

@ -9,17 +9,17 @@
"files": [ "files": [
"dist" "dist"
], ],
"main": "./dist/browser/index.js", "main": "./dist/index.js",
"unpkg": "./dist/browser/index.js", "unpkg": "./dist/browser/index.umd.js",
"types": "./dist/types/index.d.ts", "types": "./dist/index.d.ts",
"exports": { "exports": {
"types": "./dist/types/index.d.ts", "types": "./dist/index.d.ts",
"node": "./dist/node/index.js", "node": "./dist/index.js",
"default": "./dist/browser/index.js" "default": "./dist/browser/index.js"
}, },
"type": "module", "type": "module",
"scripts": { "scripts": {
"build": "node --loader ts-node/esm build.ts && tsc --emitDeclarationOnly", "build": "tsc && vite build",
"test": "vitest --threads false run" "test": "vitest --threads false run"
}, },
"repository": "https://github.com/fluencelabs/fluence-js", "repository": "https://github.com/fluencelabs/fluence-js",
@ -29,6 +29,7 @@
"@chainsafe/libp2p-noise": "13.0.0", "@chainsafe/libp2p-noise": "13.0.0",
"@chainsafe/libp2p-yamux": "5.0.0", "@chainsafe/libp2p-yamux": "5.0.0",
"@fluencelabs/interfaces": "workspace:*", "@fluencelabs/interfaces": "workspace:*",
"@fluencelabs/marine-worker": "0.3.3",
"@libp2p/crypto": "2.0.3", "@libp2p/crypto": "2.0.3",
"@libp2p/interface": "0.1.2", "@libp2p/interface": "0.1.2",
"@libp2p/peer-id": "3.0.2", "@libp2p/peer-id": "3.0.2",
@ -55,15 +56,12 @@
"@fluencelabs/aqua-api": "0.9.3", "@fluencelabs/aqua-api": "0.9.3",
"@fluencelabs/avm": "0.48.0", "@fluencelabs/avm": "0.48.0",
"@fluencelabs/marine-js": "0.7.2", "@fluencelabs/marine-js": "0.7.2",
"@fluencelabs/marine-worker": "workspace:*",
"@laynezh/vite-plugin-lib-assets": "0.5.2",
"@rollup/plugin-inject": "5.0.3", "@rollup/plugin-inject": "5.0.3",
"@types/bs58": "4.0.1", "@types/bs58": "4.0.1",
"@types/debug": "4.1.7", "@types/debug": "4.1.7",
"@types/node": "20.7.0",
"@types/uuid": "8.3.2", "@types/uuid": "8.3.2",
"node-stdlib-browser": "1.2.0",
"vite": "4.0.4", "vite": "4.0.4",
"vite-plugin-replace": "0.1.1",
"vite-tsconfig-paths": "4.0.3", "vite-tsconfig-paths": "4.0.3",
"vitest": "0.29.7" "vitest": "0.29.7"
} }

View File

@ -14,6 +14,27 @@
* limitations under the License. * limitations under the License.
*/ */
export async function fetchResource(assetPath: string, version: string) { interface PackageJsonContent {
return fetch(new globalThis.URL(`@fluencelabs/js-client@${version}/dist` + assetPath, `https://unpkg.com/`)); dependencies: Record<string, string | undefined>;
devDependencies: Record<string, string | undefined>;
}
// This will be substituted in build phase
const packageJsonContentString = `__PACKAGE_JSON_CONTENT__`;
let parsedPackageJsonContent: PackageJsonContent;
const PRIMARY_CDN = "https://unpkg.com/";
export async function fetchResource(pkg: string, assetPath: string) {
const packageJsonContent = parsedPackageJsonContent || (parsedPackageJsonContent = JSON.parse(packageJsonContentString));
const version = packageJsonContent.dependencies[pkg] || packageJsonContent.devDependencies[pkg];
if (version === undefined) {
const availableDeps = [...Object.keys(packageJsonContent.dependencies), ...Object.keys(packageJsonContent.devDependencies)];
throw new Error(`Cannot find version of ${pkg} in package.json. Available versions: ${availableDeps.join(',')}`);
}
const refinedAssetPath = assetPath.startsWith('/') ? assetPath.slice(1) : assetPath;
return fetch(new globalThis.URL(`${pkg}@${version}/` + refinedAssetPath, PRIMARY_CDN));
} }

View File

@ -20,11 +20,11 @@ import process from 'process';
const isNode = typeof process !== 'undefined' && process?.release?.name === 'node'; const isNode = typeof process !== 'undefined' && process?.release?.name === 'node';
export async function fetchResource(assetPath: string, version: string) { export async function fetchResource(pkg: string, path: string) {
switch (true) { switch (true) {
case isNode: case isNode:
return fetchResourceNode(assetPath, version); return fetchResourceNode(pkg, path);
default: default:
return fetchResourceBrowser(assetPath, version); return fetchResourceBrowser(pkg, path);
} }
} }

View File

@ -15,22 +15,37 @@
*/ */
import fs from 'fs'; import fs from 'fs';
import url from 'url';
import path from 'path'; import path from 'path';
import module from 'module';
export async function fetchResource(assetPath: string, version: string) { export async function fetchResource(pkg: string, assetPath: string) {
const require = module.createRequire(import.meta.url);
const packagePathIndex = require.resolve(pkg);
// Ensure that windows path is converted to posix path. So we can find a package
const posixPath = packagePathIndex.split(path.sep).join(path.posix.sep);
const matches = new RegExp(`(.+${pkg})`).exec(posixPath);
const packagePath = matches?.[0];
if (!packagePath) {
throw new Error(`Cannot find dependency ${pkg} in path ${posixPath}`);
}
const pathToResource = path.join(packagePath, assetPath);
const file = await new Promise<ArrayBuffer>((resolve, reject) => { const file = await new Promise<ArrayBuffer>((resolve, reject) => {
// Cannot use 'fs/promises' with current vite config. This module is not polyfilled by default. // Cannot use 'fs/promises' with current vite config. This module is not polyfilled by default.
const root = path.dirname(url.fileURLToPath(import.meta.url)); fs.readFile(pathToResource, (err, data) => {
const workerFilePath = path.join(root, '..', assetPath);
fs.readFile(workerFilePath, (err, data) => {
if (err) { if (err) {
reject(err); reject(err);
return; return;
} }
resolve(data); resolve(data);
}); });
}); });
return new Response(file, { return new Response(file, {
headers: { headers: {
'Content-type': 'Content-type':

View File

@ -23,28 +23,32 @@ import { BlobWorker, Worker } from 'threads';
import { doRegisterNodeUtils } from './services/NodeUtils.js'; import { doRegisterNodeUtils } from './services/NodeUtils.js';
import { fetchResource } from './fetchers/index.js'; import { fetchResource } from './fetchers/index.js';
import process from 'process'; import process from 'process';
import path from 'path';
import avmWasmUrl from '../node_modules/@fluencelabs/avm/dist/avm.wasm?url'; import url from 'url';
import marineJsWasmUrl from '../node_modules/@fluencelabs/marine-js/dist/marine-js.wasm?url'; import module from 'module';
import workerCodeUrl from '../node_modules/@fluencelabs/marine-worker/dist/__ENV__/marine-worker.umd.cjs?url';
const JS_CLIENT_VERSION = '__JS_CLIENT_VERSION__';
const isNode = typeof process !== 'undefined' && process?.release?.name === 'node'; const isNode = typeof process !== 'undefined' && process?.release?.name === 'node';
const fetchWorkerCode = () => fetchResource(workerCodeUrl, JS_CLIENT_VERSION).then(res => res.text()); const fetchWorkerCode = () => fetchResource('@fluencelabs/marine-worker', '/dist/browser/marine-worker.umd.cjs').then(res => res.text());
const fetchMarineJsWasm = () => fetchResource(marineJsWasmUrl, JS_CLIENT_VERSION).then(res => res.arrayBuffer()); const fetchMarineJsWasm = () => fetchResource('@fluencelabs/marine-js', '/dist/marine-js.wasm').then(res => res.arrayBuffer());
const fetchAvmWasm = () => fetchResource(avmWasmUrl, JS_CLIENT_VERSION).then(res => res.arrayBuffer()); const fetchAvmWasm = () => fetchResource('@fluencelabs/avm', '/dist/avm.wasm').then(res => res.arrayBuffer());
const createClient = async (relay: RelayOptions, config: ClientConfig): Promise<IFluenceClient> => { const createClient = async (relay: RelayOptions, config: ClientConfig): Promise<IFluenceClient> => {
const workerCode = await fetchWorkerCode();
const marineJsWasm = await fetchMarineJsWasm(); const marineJsWasm = await fetchMarineJsWasm();
const avmWasm = await fetchAvmWasm(); const avmWasm = await fetchAvmWasm();
const marine = new MarineBackgroundRunner({ const marine = new MarineBackgroundRunner({
getValue() { async getValue() {
return BlobWorker.fromText(workerCode) if (isNode) {
const require = module.createRequire(import.meta.url);
const pathToThisFile = path.dirname(url.fileURLToPath(import.meta.url));
const pathToWorker = require.resolve('@fluencelabs/marine-worker');
const relativePathToWorker = path.relative(pathToThisFile, pathToWorker);
return new Worker(relativePathToWorker);
} else {
const workerCode = await fetchWorkerCode();
return BlobWorker.fromText(workerCode)
}
}, },
start() { start() {
return Promise.resolve(undefined); return Promise.resolve(undefined);

View File

@ -21,6 +21,6 @@ import { LazyLoader } from '../interfaces.js';
export class WorkerLoader extends LazyLoader<WorkerImplementation> { export class WorkerLoader extends LazyLoader<WorkerImplementation> {
constructor() { constructor() {
super(() => new Worker('../../../node_modules/@fluencelabs/marine-worker/dist/node/marine-worker.umd.cjs')); super(() => new Worker('../../../node_modules/@fluencelabs/marine-worker/dist/index.js'));
} }
} }

View File

@ -57,7 +57,7 @@ export class MarineBackgroundRunner implements IMarineHost {
await this.avmWasmLoader.start(); await this.avmWasmLoader.start();
await this.workerLoader.start(); await this.workerLoader.start();
const worker = this.workerLoader.getValue(); const worker = await this.workerLoader.getValue();
const workerThread = await spawn<MarineBackgroundInterface>(worker); const workerThread = await spawn<MarineBackgroundInterface>(worker);
const logfn: LogFunction = (message) => { const logfn: LogFunction = (message) => {

View File

@ -1,8 +1,8 @@
{ {
"extends": "../../../tsconfig.json", "extends": "../../../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"types": ["vite/client"], "types": ["vite/client", "node"],
"outDir": "dist/types", "outDir": "./dist",
"esModuleInterop": true, "esModuleInterop": true,
"resolveJsonModule": true "resolveJsonModule": true
}, },

View File

@ -0,0 +1,59 @@
/*
* Copyright 2023 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import inject from '@rollup/plugin-inject';
import tsconfigPaths from 'vite-tsconfig-paths';
import { createRequire } from 'module';
import { readFileSync } from 'fs';
const require = createRequire(import.meta.url);
const esbuildShim = require.resolve('node-stdlib-browser/helpers/esbuild/shim');
export default {
build: {
target: 'modules',
minify: 'esbuild',
lib: {
entry: './src/index.ts',
name: 'js-client',
fileName: 'index',
},
outDir: './dist/browser',
rollupOptions: {
plugins: [
{
// @ts-ignore
...inject({
global: [esbuildShim, 'global'],
process: [esbuildShim, 'process'],
Buffer: [esbuildShim, 'Buffer']
}), enforce: 'post'
}
],
}
},
plugins: [tsconfigPaths()],
optimizeDeps: {
esbuildOptions: {
define: {
global: 'globalThis',
},
},
},
define: {
__PACKAGE_JSON_CONTENT__: readFileSync('./package.json', 'utf-8')
},
}

View File

@ -1,68 +0,0 @@
import { build, defineConfig, InlineConfig, PluginOption, UserConfig, UserConfigExport } from 'vite'
import { dirname, resolve } from 'path';
import { builtinModules, createRequire } from 'module';
import inject from '@rollup/plugin-inject';
// @ts-ignore
import merge from 'deepmerge';
import { fileURLToPath } from 'url';
import { replaceCodePlugin } from 'vite-plugin-replace';
const require = createRequire(import.meta.url);
const esbuildShim = require.resolve('node-stdlib-browser/helpers/esbuild/shim');
const commonConfig = defineConfig({
build: {
lib: {
entry: resolve(dirname(fileURLToPath(import.meta.url)), 'src/index.ts'),
name: 'MarineWorker'
},
}
}) as UserConfig;
const browserConfig: InlineConfig = await merge(commonConfig, defineConfig({
build: {
outDir: 'dist/browser',
},
plugins: [{
// @ts-ignore
...inject({
global: [esbuildShim, 'global'],
process: [esbuildShim, 'process'],
Buffer: [esbuildShim, 'Buffer']
}), enforce: 'post'
} as PluginOption],
}) as UserConfig);
const nodeConfig: InlineConfig = await merge(commonConfig, defineConfig({
build: {
target: 'es2022',
outDir: 'dist/node',
rollupOptions: {
external: [...builtinModules],
plugins: [
// @ts-ignore
inject({
self: 'global',
'WorkerScope': ['worker_threads', '*'],
'Worker': ['worker_threads', 'Worker'],
'isMainThread': ['worker_threads', 'isMainThread'],
})
]
}
},
plugins: [
replaceCodePlugin({
replacements: [
{ from: 'eval("require")("worker_threads")', to: 'WorkerScope' },
{ from: 'eval("require")("worker_threads")', to: 'WorkerScope' },
]
})
],
resolve: {
browserField: false,
}
}) as UserConfig);
await build(browserConfig!);
await build(nodeConfig!);

View File

@ -1,31 +1,16 @@
{ {
"type": "module",
"name": "@fluencelabs/marine-worker", "name": "@fluencelabs/marine-worker",
"version": "0.3.3", "version": "0.3.3",
"description": "Marine worker", "description": "Marine worker",
"files": [ "files": [
"dist" "dist"
], ],
"main": "./dist/node/marine-worker.umd.cjs", "main": "./dist/index.js",
"unpkg": "./dist/browser/marine-worker.umd.cjs", "unpkg": "./dist/browser/marine-worker.umd.cjs",
"types": "./dist/types/index.d.ts", "types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"node": "./dist/node/marine-worker.umd.cjs",
"default": "./dist/browser/marine-worker.umd.cjs"
},
"./dist/marine-worker.js": {
"node": "./dist/node/marine-worker.js",
"default": "./dist/browser/marine-worker.js"
},
"./dist/marine-worker.umd.cjs": {
"node": "./dist/node/marine-worker.umd.cjs",
"default": "./dist/browser/marine-worker.umd.cjs"
}
},
"type": "module",
"scripts": { "scripts": {
"build": "tsc --emitDeclarationOnly && node --loader ts-node/esm build.ts" "build": "tsc && vite build"
}, },
"repository": "https://github.com/fluencelabs/fluence-js", "repository": "https://github.com/fluencelabs/fluence-js",
"author": "Fluence Labs", "author": "Fluence Labs",
@ -34,12 +19,9 @@
"devDependencies": { "devDependencies": {
"@rollup/plugin-inject": "5.0.3", "@rollup/plugin-inject": "5.0.3",
"@types/node": "20.4.5", "@types/node": "20.4.5",
"deepmerge": "4.3.1",
"node-stdlib-browser": "1.2.0", "node-stdlib-browser": "1.2.0",
"typescript": "5.1.6", "typescript": "5.1.6",
"vite": "4.0.4", "vite": "4.0.4",
"vite-plugin-dts": "3.4.0",
"vite-plugin-replace": "0.1.1",
"vitest": "0.29.7" "vitest": "0.29.7"
}, },
"dependencies": { "dependencies": {

View File

@ -19,7 +19,7 @@ import type { Env, MarineModuleConfig, MarineServiceConfig, ModuleDescriptor } f
import type { JSONArray, JSONObject, LogMessage, CallParameters } from '@fluencelabs/marine-js/dist/types'; import type { JSONArray, JSONObject, LogMessage, CallParameters } from '@fluencelabs/marine-js/dist/types';
import { Observable, Subject } from 'observable-fns'; import { Observable, Subject } from 'observable-fns';
// @ts-ignore no types provided for package // @ts-ignore no types provided for package
import { expose } from 'threads'; import { expose } from 'threads/worker';
const createSimpleModuleDescriptor = (name: string, envs?: Env): ModuleDescriptor => { const createSimpleModuleDescriptor = (name: string, envs?: Env): ModuleDescriptor => {
return { return {

View File

@ -1,7 +1,7 @@
{ {
"extends": "../../../tsconfig.json", "extends": "../../../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "./dist/types" "outDir": "./dist"
}, },
"include": ["src/**/*"], "include": ["src/**/*"],
"exclude": ["node_modules", "dist"] "exclude": ["node_modules", "dist"]

View File

@ -0,0 +1,42 @@
/*
* Copyright 2023 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { PluginOption } from 'vite'
import { dirname, resolve } from 'path';
import { createRequire } from 'module';
import inject from '@rollup/plugin-inject';
import { fileURLToPath } from 'url';
const require = createRequire(import.meta.url);
const esbuildShim = require.resolve('node-stdlib-browser/helpers/esbuild/shim');
export default {
build: {
lib: {
entry: resolve(dirname(fileURLToPath(import.meta.url)), 'src/index.ts'),
name: 'MarineWorker'
},
outDir: 'dist/browser',
},
plugins: [{
// @ts-ignore
...inject({
global: [esbuildShim, 'global'],
process: [esbuildShim, 'process'],
Buffer: [esbuildShim, 'Buffer']
}), enforce: 'post'
} as PluginOption],
};

676
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff