Skip to content

chore: update dependencies and configs #240

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

Open
wants to merge 9 commits into
base: next
Choose a base branch
from
Open
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
28 changes: 25 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,30 @@
]
],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/proposal-class-properties", { "loose": true }],
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"@babel/proposal-class-properties",
{
"loose": true
}
],
[
"@babel/plugin-transform-private-property-in-object",
{
"loose": true
}
],
[
"@babel/plugin-transform-private-methods",
{
"loose": true
}
],
"@babel/proposal-object-rest-spread"
]
}
}
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version: 2
jobs:
test-job:
docker:
- image: circleci/node:10
- image: cimg/node:21.6.1
working_directory: ~/repo
steps:
- checkout
Expand All @@ -29,7 +29,7 @@ jobs:

test-docs:
docker:
- image: circleci/node:10
- image: cimg/node:21.6.1
working_directory: ~/repo
steps:
- checkout
Expand All @@ -43,7 +43,7 @@ jobs:

deploy-docs:
docker:
- image: circleci/node:10
- image: cimg/node:21.6.1
working_directory: ~/repo
steps:
- checkout
Expand All @@ -59,7 +59,7 @@ jobs:

publish-job:
docker:
- image: circleci/node:10
- image: cimg/node:21.6.1
working_directory: ~/repo
steps:
- checkout
Expand Down
59 changes: 29 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,43 +54,42 @@
"js",
"javascript"
],
"dependencies": {},
"devDependencies": {
"@babel/core": "7.8.7",
"@babel/core": "7.23.9",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-decorators": "^7.8.3",
"@babel/plugin-proposal-decorators": "^7.23.9",
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
"@babel/preset-env": "7.8.7",
"@babel/preset-typescript": "^7.8.3",
"@babel/preset-env": "7.23.9",
"@babel/preset-typescript": "^7.23.3",
"@hapi/joi": "^16.1.7",
"@types/hapi__joi": "^16.0.1",
"@types/jest": "25.1.4",
"@types/node": "^13.1.0",
"@types/validator": "^10.11.3",
"@types/webpack": "^4.4.27",
"@types/webpack-bundle-analyzer": "^2.13.3",
"babel-loader": "^8.0.5",
"fork-ts-checker-webpack-plugin": "^4.0.1",
"jest": "24.7.1",
"lint-staged": "^10.0.3",
"nodemon": "^2.0.0",
"nodemon-webpack-plugin": "^4.2.2",
"@types/hapi__joi": "^17.1.14",
"@types/jest": "29.5.11",
"@types/node": "^20.11.10",
"@types/validator": "^13.11.8",
"@types/webpack": "^5.28.5",
"@types/webpack-bundle-analyzer": "^4.6.3",
"babel-loader": "^9.1.3",
"fork-ts-checker-webpack-plugin": "^9.0.2",
"jest": "^29.7.0",
"lint-staged": "^15.2.0",
"nodemon": "^3.0.3",
"nodemon-webpack-plugin": "^4.8.2",
"now": "^17.0.0",
"npm-run-all": "^4.1.5",
"prettier": "1.19.1",
"semantic-release": "^17.0.0",
"source-map-loader": "^0.2.4",
"ts-node": "^8.0.3",
"tslint": "^5.15.0",
"prettier": "3.2.4",
"semantic-release": "^23.0.0",
"source-map-loader": "^5.0.0",
"ts-node": "^10.9.2",
"tslint": "^5.20.1",
"tslint-loader": "^3.6.0",
"typedoc": "^0.16.0",
"typedoc-plugin-external-module-name": "^3.0.0",
"typedoc-plugin-internal-external": "^2.0.1",
"typescript": "^3.7.2",
"validator": "^11.1.0",
"webpack": "4.42.0",
"webpack-bundle-analyzer": "^3.5.2",
"webpack-cli": "^3.3.0"
"typedoc": "^0.25.7",
"typedoc-plugin-external-module-name": "^2.1.0",
"typedoc-plugin-internal-external": "^2.2.0",
"typescript": "^5.3.3",
"validator": "^13.11.0",
"webpack": "5.90.0",
"webpack-bundle-analyzer": "^4.10.1",
"webpack-cli": "^5.1.4"
},
"eslintConfig": {
"extends": "xo-space",
Expand Down
4 changes: 2 additions & 2 deletions src/MorphismDecorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Mapper } from './types';
import { Mapper, Schema, StrictSchema } from './types';
import { isPromise } from './helpers';

export function decorator<Target>(mapper: Mapper<Target>) {
export function decorator<Target extends Schema<any, any> | StrictSchema<any, any>>(mapper: Mapper<Target>) {
return (_target: any, _name: string, descriptor: PropertyDescriptor) => {
const fn = descriptor.value;
if (typeof fn === 'function') {
Expand Down
2 changes: 1 addition & 1 deletion src/MorphismRegistry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Mappers Registry', function() {
Morphism.register(User);
});
it('should throw an exception when using Registration function without parameters', function() {
expect(() => Morphism.register(null as any, null)).toThrow();
expect(() => Morphism.register(null as any, undefined)).toThrow();
});

it('should throw an exception when trying to register a mapper type more than once', function() {
Expand Down
4 changes: 2 additions & 2 deletions src/MorphismRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Constructable, Schema, Mapper } from './types';
import { morphism } from './morphism';
import { StrictSchema, morphism } from './morphism';

export interface IMorphismRegistry {
/**
Expand All @@ -10,7 +10,7 @@ export interface IMorphismRegistry {
*
*/
register<Target>(type: Constructable<Target>): Mapper<Schema<Target>, Target>;
register<Target, TSchema>(type: Constructable<Target>, schema?: TSchema): Mapper<TSchema, Target>;
register<Target, TSchema extends Schema<any, any> | StrictSchema<any, any>>(type: Constructable<Target>, schema?: TSchema): Mapper<TSchema, Target>;

/**
* Transform any input in the specified Class
Expand Down
2 changes: 1 addition & 1 deletion src/MorphismTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class MorphismSchemaTree<Target, Source> {
if (action.fn) {
try {
targetValue = action.fn.call(undefined, targetValue, object, items, objectToCompute);
} catch (e) {
} catch (e: any) {
e.message = `Unable to set target property [${targetProperty}].
\n An error occured when applying [${action.fn.name}] on property [${action.path}]
\n Internal error: ${e.message}`;
Expand Down
8 changes: 4 additions & 4 deletions src/morphism.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,24 +229,24 @@ describe('Morphism', () => {
const mapUser = Morphism.register(User, schema);
const results = mapUser(input);
results.forEach((res, index) => {
expect(res).toEqual(jasmine.objectContaining(output[index]));
expect(res).toEqual(expect.objectContaining(output[index]));
});

const mapUser2 = Morphism(schema, null, User);
const results2 = mapUser2(input);

results2.forEach((res, index) => {
expect(res).toEqual(jasmine.objectContaining(output[index]));
expect(res).toEqual(expect.objectContaining(output[index]));
});

const results3 = Morphism.map(User, input);
results3.forEach((res, index) => {
expect(res).toEqual(jasmine.objectContaining(output[index]));
expect(res).toEqual(expect.objectContaining(output[index]));
});

const results4 = input.map(userInput => Morphism.map(User, userInput));
results4.forEach((res, index) => {
expect(res).toEqual(jasmine.objectContaining(output[index]));
expect(res).toEqual(expect.objectContaining(output[index]));
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/morphism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function transformItems<T, TSchema extends Schema<T | {}>>(schema: TSchema, type
}

function getSchemaForClass<T>(type: Constructable<T>, baseSchema: Schema<T>): Schema<T> {
let typeFields = Object.keys(new type());
let typeFields = Object.keys(new type() as any);
let defaultSchema = zipObject(typeFields, typeFields);
let finalSchema = Object.assign(defaultSchema, baseSchema);
return finalSchema;
Expand Down Expand Up @@ -167,7 +167,7 @@ function morphism<
Source extends SourceFromSchema<TSchema> = SourceFromSchema<TSchema>
>(schema: TSchema, data: Source): DestinationFromSchema<TSchema>;

function morphism<TSchema = Schema<DestinationFromSchema<Schema>, SourceFromSchema<Schema>>>(schema: TSchema): Mapper<TSchema>; // morphism({}) => mapper(S) => T
function morphism<TSchema extends Schema<any, any> | StrictSchema<any, any> = Schema<DestinationFromSchema<Schema>, SourceFromSchema<Schema>>>(schema: TSchema): Mapper<TSchema>; // morphism({}) => mapper(S) => T

function morphism<TSchema extends Schema, TDestination>(
schema: TSchema,
Expand Down
4 changes: 1 addition & 3 deletions typedoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ module.exports = {
name: 'Morphism API',
out: './docs/typedoc',

entryPoints: ["./src/morphism.ts"],
// readme: 'none',
exclude: ['/**/*.spec.ts'],

mode: 'modules',
externalPattern: '**/helpers.ts',
excludeExternals: true,
excludeNotExported: true,
excludePrivate: true,
excludeProtected: true,
includeDeclarations: true
};
83 changes: 75 additions & 8 deletions webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,68 @@
// import path from 'path';
// import webpack from 'webpack';
// import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
// import NodemonPlugin from 'nodemon-webpack-plugin';
// import ModuleDependencyWarning from 'webpack/lib/ModuleDependencyWarning';
// import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';

// const nodeEnv = process.env.NODE_ENV || 'development';
// const isProd = nodeEnv === 'production';
// const shouldAnalyzeBundle = process.env.WEBPACK_ANALYZE;
// class IgnoreNotFoundExportPlugin {
// apply(compiler) {
// const messageRegExp = /export '.*'( \(reexported as '.*'\))? was not found in/;
// function doneHook(stats) {
// stats.compilation.warnings = stats.compilation.warnings.filter(function(warn) {
// if (warn instanceof ModuleDependencyWarning && messageRegExp.test(warn.message)) {
// return false;
// }
// return true;
// });
// }
// if (compiler.hooks) {
// compiler.hooks.done.tap('IgnoreNotFoundExportPlugin', doneHook);
// } else {
// compiler.plugin('done', doneHook);
// }
// }
// }

// const webpackconfiguration: webpack.Configuration = {
// mode: 'development',
// entry: path.resolve(__dirname, 'src', 'morphism.ts'),
// devtool: isProd ? 'hidden-source-map' : 'source-map',
// output: {
// filename: 'morphism.js',
// hashFunction: 'sha256',
// path: path.resolve(__dirname, 'dist'),
// libraryTarget: 'umd',
// globalObject: 'this',
// sourceMapFilename: 'morphism.map',
// library: 'Morphism',
// },
// resolve: {
// extensions: ['.ts', '.tsx', '.js', '.json'],
// },
// module: {
// rules: [{ test: /\.(ts|js)x?$/, use: ['babel-loader', 'source-map-loader'], exclude: /node_modules/ }],
// },
// plugins: [
// new ForkTsCheckerWebpackPlugin({
// async: false,
// typescript: {
// configFile: './tsconfig.json'
// }
// // checkSyntacticErrors: true,
// // reportFiles: ['**', '!**/*.json', '!**/__tests__/**', '!**/?(*.)(spec|test).*'],
// // silent: true,
// }),
// new NodemonPlugin(),
// new IgnoreNotFoundExportPlugin(),
// shouldAnalyzeBundle ? new BundleAnalyzerPlugin({ generateStatsFile: true }) : null,
// ].filter(plugin => plugin),
// };

// export default webpackconfiguration;
import path from 'path';
import webpack from 'webpack';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
Expand All @@ -8,11 +73,12 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
const nodeEnv = process.env.NODE_ENV || 'development';
const isProd = nodeEnv === 'production';
const shouldAnalyzeBundle = process.env.WEBPACK_ANALYZE;

class IgnoreNotFoundExportPlugin {
apply(compiler) {
const messageRegExp = /export '.*'( \(reexported as '.*'\))? was not found in/;
function doneHook(stats) {
stats.compilation.warnings = stats.compilation.warnings.filter(function(warn) {
stats.compilation.warnings = stats.compilation.warnings.filter(function (warn) {
if (warn instanceof ModuleDependencyWarning && messageRegExp.test(warn.message)) {
return false;
}
Expand All @@ -27,12 +93,13 @@ class IgnoreNotFoundExportPlugin {
}
}

const webpackconfiguration: webpack.Configuration = {
const webpackConfiguration: webpack.Configuration = {
mode: 'development',
entry: path.resolve(__dirname, 'src', 'morphism.ts'),
devtool: isProd ? 'hidden-source-map' : 'source-map',
output: {
filename: 'morphism.js',
hashFunction: 'sha256',
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'umd',
globalObject: 'this',
Expand All @@ -48,14 +115,14 @@ const webpackconfiguration: webpack.Configuration = {
plugins: [
new ForkTsCheckerWebpackPlugin({
async: false,
checkSyntacticErrors: true,
reportFiles: ['**', '!**/*.json', '!**/__tests__/**', '!**/?(*.)(spec|test).*'],
silent: true,
typescript: {
configFile: './tsconfig.json',
},
}),
new NodemonPlugin(),
new IgnoreNotFoundExportPlugin(),
shouldAnalyzeBundle ? new BundleAnalyzerPlugin({ generateStatsFile: true }) : null,
].filter(plugin => plugin),
shouldAnalyzeBundle ? new BundleAnalyzerPlugin({ generateStatsFile: true }) : undefined,
].filter((plugin) => plugin),
};

export default webpackconfiguration;
export default webpackConfiguration;
Loading