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

refactor: build synchronizer using webpack #486

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/stupid-clouds-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@monokle/synchronizer": minor
---

Build library using webpack
4,071 changes: 2,849 additions & 1,222 deletions package-lock.json

Large diffs are not rendered by default.

25 changes: 16 additions & 9 deletions packages/synchronizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
"description": "Monokle Cloud synchronizer",
"author": "Kubeshop",
"license": "MIT",
"type": "module",
"sideEffects": false,
"main": "lib/index.js",
"source": "src/index.ts",
"module": "lib/index.js",
"types": "lib/index.d.ts",
"typings": "lib/index.d.ts",
"exports": "./lib/index.js",
Expand All @@ -20,7 +16,8 @@
"test": "npm run build && mocha",
"test:cc": "npm run build && c8 mocha",
"test:snapshot": "vitest --update",
"build": "rimraf lib && tsc --build tsconfig.build.json",
"build": "webpack --mode production && tsc -p tsconfig.build.json",
"build_old": "rimraf lib && tsc --build tsconfig.build.json",
"format:all": "prettier --write \"{src,test}/**/*.{js,jsx,ts,tsx}\""
},
"repository": {
Expand All @@ -40,21 +37,31 @@
"homepage": "https://github.com/kubeshop/monokle-core/tree/main/packages/synchronizer",
"dependencies": {
"@monokle/validation": "*",
"env-paths": "^3.0.0",
"mkdirp": "^3.0.1",
"node-fetch": "^3.3.2",
"env-paths": "2.2.1",
"mkdirp": "2.1.6",
"node-fetch": "2.6.13",
"normalize-url": "^8.0.0",
"openid-client": "^5.4.3",
"simple-git": "^3.19.1",
"yaml": "^2.3.1"
},
"devDependencies": {
"@babel/core": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"@babel/preset-typescript": "^7.22.5",
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.1",
"@types/sinon": "^10.0.16",
"babel-loader": "8.3.0",
"c8": "^8.0.1",
"chai": "^4.3.7",
"clean-webpack-plugin": "4.0.0",
"fork-ts-checker-webpack-plugin": "6.5.3",
"mocha": "^10.2.0",
"sinon": "^15.2.0"
"sinon": "^15.2.0",
"ts-loader": "8.4.0",
"webpack": "4.46.0",
"webpack-cli": "4.10.0",
"webpack-node-externals": "^3.0.0"
}
}
10 changes: 5 additions & 5 deletions packages/synchronizer/src/__tests__/authenticator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {fileURLToPath} from 'url';
import {rm, mkdir, cp} from 'fs/promises';
import sinon from 'sinon';
import {assert} from 'chai';
import {createDefaultMonokleAuthenticator} from '../createDefaultMonokleAuthenticator.js';
import {StorageHandlerAuth} from '../handlers/storageHandlerAuth.js';
import {ApiHandler} from '../handlers/apiHandler.js';
import {DeviceFlowHandler} from '../handlers/deviceFlowHandler.js';
import type {AuthenticatorLoginEvent} from '../utils/authenticator.js';
import {createDefaultMonokleAuthenticator} from '../createDefaultMonokleAuthenticator';
import {StorageHandlerAuth} from '../handlers/storageHandlerAuth';
import {ApiHandler} from '../handlers/apiHandler';
import {DeviceFlowHandler} from '../handlers/deviceFlowHandler';
import type {AuthenticatorLoginEvent} from '../utils/authenticator';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand Down
4 changes: 2 additions & 2 deletions packages/synchronizer/src/__tests__/synchronizer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {fileURLToPath} from 'url';
import {rm, mkdir, cp} from 'fs/promises';
import sinon from 'sinon';
import {assert} from 'chai';
import {createDefaultMonokleSynchronizer} from '../createDefaultMonokleSynchronizer.js';
import {StorageHandlerPolicy} from '../handlers/storageHandlerPolicy.js';
import {createDefaultMonokleSynchronizer} from '../createDefaultMonokleSynchronizer';
import {StorageHandlerPolicy} from '../handlers/storageHandlerPolicy';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ApiHandler} from './handlers/apiHandler.js';
import {DeviceFlowHandler} from './handlers/deviceFlowHandler.js';
import {StorageHandlerAuth} from './handlers/storageHandlerAuth.js';
import {Authenticator} from './utils/authenticator.js';
import {ApiHandler} from './handlers/apiHandler';
import {DeviceFlowHandler} from './handlers/deviceFlowHandler';
import {StorageHandlerAuth} from './handlers/storageHandlerAuth';
import {Authenticator} from './utils/authenticator';

export function createDefaultMonokleAuthenticator(
storageHandler: StorageHandlerAuth = new StorageHandlerAuth(),
Expand Down
8 changes: 4 additions & 4 deletions packages/synchronizer/src/createDefaultMonokleSynchronizer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ApiHandler} from './handlers/apiHandler.js';
import {GitHandler} from './handlers/gitHandler.js';
import {StorageHandlerPolicy} from './handlers/storageHandlerPolicy.js';
import {Synchronizer} from './utils/synchronizer.js';
import {ApiHandler} from './handlers/apiHandler';
import {GitHandler} from './handlers/gitHandler';
import {StorageHandlerPolicy} from './handlers/storageHandlerPolicy';
import {Synchronizer} from './utils/synchronizer';

export function createDefaultMonokleSynchronizer(
storageHandler: StorageHandlerPolicy = new StorageHandlerPolicy(),
Expand Down
2 changes: 1 addition & 1 deletion packages/synchronizer/src/handlers/apiHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import normalizeUrl from 'normalize-url';
import fetch from 'node-fetch';
import {DEFAULT_API_URL} from '../constants.js';
import {DEFAULT_API_URL} from '../constants';

const getUserQuery = `
query getUser {
Expand Down
2 changes: 1 addition & 1 deletion packages/synchronizer/src/handlers/deviceFlowHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
DEFAULT_DEVICE_FLOW_CLIENT_SECRET,
DEFAULT_DEVICE_FLOW_ALG,
DEFAULT_DEVICE_FLOW_CLIENT_SCOPE,
} from '../constants.js';
} from '../constants';
import type {
BaseClient,
ClientMetadata,
Expand Down
6 changes: 3 additions & 3 deletions packages/synchronizer/src/handlers/storageHandlerAuth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import envPaths from 'env-paths';
import {StorageHandler} from './storageHandler.js';
import {DEFAULT_STORAGE_CONFIG_FILE_AUTH, DEFAULT_STORAGE_CONFIG_FOLDER} from '../constants.js';
import type {TokenSet} from './deviceFlowHandler.js';
import {StorageHandler} from './storageHandler';
import {DEFAULT_STORAGE_CONFIG_FILE_AUTH, DEFAULT_STORAGE_CONFIG_FOLDER} from '../constants';
import type {TokenSet} from './deviceFlowHandler';

export type AccessToken = {
access_token: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/synchronizer/src/handlers/storageHandlerPolicy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import envPaths from 'env-paths';
import {Document} from 'yaml';
import {StorageHandler} from './storageHandler.js';
import {DEFAULT_STORAGE_CONFIG_FOLDER} from '../constants.js';
import {StorageHandler} from './storageHandler';
import {DEFAULT_STORAGE_CONFIG_FOLDER} from '../constants';
import type {Config} from '@monokle/validation';

export type StoragePolicyFormat = Config;
Expand Down
24 changes: 12 additions & 12 deletions packages/synchronizer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export * from './handlers/apiHandler.js';
export * from './handlers/deviceFlowHandler.js';
export * from './handlers/gitHandler.js';
export * from './handlers/storageHandler.js';
export * from './handlers/storageHandlerAuth.js';
export * from './handlers/storageHandlerPolicy.js';
export * from './handlers/apiHandler';
export * from './handlers/deviceFlowHandler';
export * from './handlers/gitHandler';
export * from './handlers/storageHandler';
export * from './handlers/storageHandlerAuth';
export * from './handlers/storageHandlerPolicy';

export * from './models/user.js';
export * from './models/user';

export * from './utils/authenticator.js';
export * from './utils/synchronizer.js';
export * from './utils/authenticator';
export * from './utils/synchronizer';

export * from './constants.js';
export * from './constants';

export * from './createDefaultMonokleAuthenticator.js';
export * from './createDefaultMonokleSynchronizer.js';
export * from './createDefaultMonokleAuthenticator';
export * from './createDefaultMonokleSynchronizer';
2 changes: 1 addition & 1 deletion packages/synchronizer/src/models/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {StorageAuthFormat} from '../handlers/storageHandlerAuth.js';
import type {StorageAuthFormat} from '../handlers/storageHandlerAuth';

export class User {
private _email: string | null = null;
Expand Down
12 changes: 6 additions & 6 deletions packages/synchronizer/src/utils/authenticator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {EventEmitter} from 'events';
import {User} from '../models/user.js';
import {StorageHandlerAuth} from '../handlers/storageHandlerAuth.js';
import {ApiHandler} from '../handlers/apiHandler.js';
import {DeviceFlowHandler} from '../handlers/deviceFlowHandler.js';
import type {Token} from '../handlers/storageHandlerAuth.js';
import type {DeviceFlowHandle} from '../handlers/deviceFlowHandler.js';
import {User} from '../models/user';
import {StorageHandlerAuth} from '../handlers/storageHandlerAuth';
import {ApiHandler} from '../handlers/apiHandler';
import {DeviceFlowHandler} from '../handlers/deviceFlowHandler';
import type {Token} from '../handlers/storageHandlerAuth';
import type {DeviceFlowHandle} from '../handlers/deviceFlowHandler';

export type AuthMethod = 'device code' | 'token';

Expand Down
10 changes: 5 additions & 5 deletions packages/synchronizer/src/utils/synchronizer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {EventEmitter} from 'events';
import {StorageHandlerPolicy} from '../handlers/storageHandlerPolicy.js';
import {ApiHandler} from '../handlers/apiHandler.js';
import {GitHandler} from '../handlers/gitHandler.js';
import type {StoragePolicyFormat} from '../handlers/storageHandlerPolicy.js';
import type {RepoRemoteData} from '../handlers/gitHandler.js';
import {StorageHandlerPolicy} from '../handlers/storageHandlerPolicy';
import {ApiHandler} from '../handlers/apiHandler';
import {GitHandler} from '../handlers/gitHandler';
import type {StoragePolicyFormat} from '../handlers/storageHandlerPolicy';
import type {RepoRemoteData} from '../handlers/gitHandler';

export type RepoRemoteInputData = {
provider: string;
Expand Down
1 change: 1 addition & 0 deletions packages/synchronizer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"skipLibCheck": true,
"removeComments": false,
"strict": true,
"emitDeclarationOnly": true
},
"exclude": ["node_modules", "lib"],
"include": ["src"]
Expand Down
40 changes: 40 additions & 0 deletions packages/synchronizer/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const path = require('path');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const nodeExternals = require('webpack-node-externals');

module.exports = {
entry: './src/index.ts',
target: 'node',
externals: [nodeExternals()],
output: {
path: path.resolve(__dirname, 'lib'),
filename: 'index.js',
libraryTarget: 'commonjs2',
},
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules: [
{
test: /\.ts$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-typescript'],
},
},
},
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
],
},
plugins: [new CleanWebpackPlugin()],
};
Loading