feat(js-client)!: Adding strictes eslint and ts config to all packages [fixes DXJ-464] (#355)

* introduce eslint

* Fix all eslint errors

* Eslint fix and some touches

* Fix tests

* Fix misc errors

* change semver

* change semver #2

* Fix path

* Fix path #2

* freeze lock file in CI

* fix package install

* Fix formatting of surrounding files

* Add empty prettier config

* Fix formatting

* Fix build errors

* Remove unused deps

* remove changelog from formatting

* deps cleanup

* make resource importers async

* Refactor

* Fix error message

* remove comment

* more refactoring

* Update packages/core/js-client/src/compilerSupport/registerService.ts

Co-authored-by: shamsartem <shamsartem@gmail.com>

* refactoring

* refactoring fix

* optimize import

* Update packages/@tests/smoke/node/src/index.ts

Co-authored-by: shamsartem <shamsartem@gmail.com>

* Revert package

* Fix pnpm lock

* Lint-fix

* Fix CI

* Update tests

* Fix build

* Fix import

* Use forked threads dep

* Use fixed version

* Update threads

* Fix lint

* Fix test

* Fix test

* Add polyfill for assert

* Add subpath import

* Fix tests

* Fix deps

---------

Co-authored-by: shamsartem <shamsartem@gmail.com>
This commit is contained in:
Akim
2023-10-17 22:14:08 +07:00
committed by GitHub
parent b46933252a
commit 919c7d6ea1
135 changed files with 10529 additions and 9167 deletions

View File

@ -1,48 +1,82 @@
import handler from 'serve-handler';
import { createServer } from 'http';
import type { Server } from 'http';
/**
* 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 { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { createServer } from "http";
import type { Server } from "http";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
import handler from "serve-handler";
const __dirname = dirname(fileURLToPath(import.meta.url));
export const CDN_PUBLIC_PATH = join(__dirname, '../../../core/js-client/dist/browser');
export const CDN_PUBLIC_PATH = join(
__dirname,
"../../../core/js-client/dist/browser",
);
export const startCdn = (port: number) => startContentServer(port, CDN_PUBLIC_PATH);
export const startCdn = (port: number) => {
return startContentServer(port, CDN_PUBLIC_PATH);
};
export const startContentServer = (port: number, publicDir: string): Promise<Server> => {
const server = createServer((request, response) => {
return handler(request, response, {
public: publicDir,
rewrites: [{
source: '/js-client.min.js',
destination: '/source/index.umd.cjs'
}],
headers: [{
source: '**/*',
headers: [
{ key: 'Cross-Origin-Opener-Policy', value: 'same-origin' },
{ key: 'Cross-Origin-Embedder-Policy', value: 'require-corp' }
]
}]
});
export const startContentServer = (
port: number,
publicDir: string,
): Promise<Server> => {
const server = createServer((request, response) => {
void handler(request, response, {
public: publicDir,
rewrites: [
{
source: "/js-client.min.js",
destination: "/source/index.umd.cjs",
},
],
headers: [
{
source: "**/*",
headers: [
{
key: "Cross-Origin-Opener-Policy",
value: "same-origin",
},
{
key: "Cross-Origin-Embedder-Policy",
value: "require-corp",
},
],
},
],
});
});
return new Promise<Server>((resolve) => {
const result = server.listen(port, () => {
console.log(`server started on port ${port}`);
console.log(`public dir ${publicDir}`);
resolve(result);
});
return new Promise<Server>((resolve) => {
const result = server.listen(port, () => {
console.log(`server started on port ${port}`);
console.log(`public dir ${publicDir}`);
resolve(result);
});
});
};
export const stopServer = (app: Server): Promise<void> => {
return new Promise<void>((resolve) => {
app.close(() => {
console.log('server stopped');
resolve();
});
return new Promise<void>((resolve) => {
app.close(() => {
console.log("server stopped");
resolve();
});
});
};