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

Migrate util lib to util Monorepo #1

Open
wants to merge 2 commits into
base: main
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
35 changes: 35 additions & 0 deletions .eslintrc.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nx"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": [
{
"sourceTag": "*",
"onlyDependOnLibsWithTags": ["*"]
}
]
}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nx/typescript"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nx/javascript"],
"rules": {}
}
]
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ config.json
config.*.json

dist/

.nx/cache
.nx/workspace-data
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
V20.0.0
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Add files here to ignore them from prettier formatting
/dist
/coverage
/.nx/cache
/.nx/workspace-data
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
18 changes: 18 additions & 0 deletions libs/chunk-by/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.js"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions libs/chunk-by/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# chunk-by

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test chunk-by` to execute the unit tests via [Vitest](https://vitest.dev/).
16 changes: 16 additions & 0 deletions libs/chunk-by/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "chunk-by",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/chunk-by/src",
"projectType": "library",
"tags": [],
"targets": {
"test": {
"executor": "@nx/vite:test",
"outputs": ["{options.reportsDirectory}"],
"options": {
"reportsDirectory": "../../coverage/libs/chunk-by"
}
}
}
}
1 change: 1 addition & 0 deletions libs/chunk-by/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/chunk-by';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chunkBy from './chunkBy';
import chunkBy from './chunk-by';

describe('chunkBy', () => {
it('should split up an array into sub-arrays of a certain size', () => {
Expand Down
6 changes: 2 additions & 4 deletions src/chunkBy/chunkBy.ts → libs/chunk-by/src/lib/chunk-by.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* chunkBy([1, 2, 3, 4, 5, 6, 7], 2) // [[1, 2], [3, 4], [5, 6], [7]]
* ```
*/
function chunkBy<ArrayItem>(source: ArrayItem[], chunkSize: number) {
export function chunkBy<ArrayItem>(source: ArrayItem[], chunkSize: number) {
if (chunkSize <= 0) {
throw new Error(`Cannot create chunks of size ${chunkSize} (0 or less)`);
}
Expand All @@ -16,6 +16,4 @@ function chunkBy<ArrayItem>(source: ArrayItem[], chunkSize: number) {
return Array.from(new Array(numberOfChunks), (_, i) => {
return source.slice(i * chunkSize, (i + 1) * chunkSize);
});
}

export default chunkBy;
}
22 changes: 22 additions & 0 deletions libs/chunk-by/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "Node16",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
10 changes: 10 additions & 0 deletions libs/chunk-by/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["vite.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
26 changes: 26 additions & 0 deletions libs/chunk-by/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": [
"vitest/globals",
"vitest/importMeta",
"vite/client",
"node",
"vitest"
]
},
"include": [
"vite.config.ts",
"vitest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
]
}
26 changes: 26 additions & 0 deletions libs/chunk-by/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';

export default {
root: __dirname,
cacheDir: '../../node_modules/.vite/libs/chunk-by',

plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])],

// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
// },

test: {
watch: false,
globals: true,
environment: 'node',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
reporters: ['default'],
coverage: {
reportsDirectory: '../../coverage/libs/chunk-by',
provider: 'v8',
},
},
};
18 changes: 18 additions & 0 deletions libs/fetch-ssm-params/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.base.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions libs/fetch-ssm-params/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# fetch-ssm-params

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test fetch-ssm-params` to execute the unit tests via [Vitest](https://vitest.dev/).
16 changes: 16 additions & 0 deletions libs/fetch-ssm-params/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "fetch-ssm-params",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/fetch-ssm-params/src",
"projectType": "library",
"tags": [],
"targets": {
"test": {
"executor": "@nx/vite:test",
"outputs": ["{options.reportsDirectory}"],
"options": {
"reportsDirectory": "../../coverage/libs/fetch-ssm-params"
}
}
}
}
1 change: 1 addition & 0 deletions libs/fetch-ssm-params/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/fetch-ssm-params';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fetchSsmParams from './fetchSsmParams';
import fetchSsmParams from './fetch-ssm-params';
import { mockClient } from 'aws-sdk-client-mock';
import {
GetParameterCommand,
Expand All @@ -15,29 +15,29 @@ describe('fetchSsmParams', () => {
ssmMock.reset();
});

it('should error when no params are passed', async () => {
test('should error when no params are passed', async () => {
try {
await fetchSsmParams();
} catch (ex) {
expect(ex).toBeTruthy();
}
});

it('should fetch a single parameter if only one is supplied', async () => {
test('should fetch a single parameter if only one is supplied', async () => {
try {
await fetchSsmParams('');
// eslint-disable-next-line no-empty
} catch {}
// eslint-disable-next-line no-empty
} catch { }
expect(ssmMock).toHaveReceivedCommandTimes(GetParameterCommand, 1);
expect(ssmMock).toHaveReceivedCommandTimes(GetParametersCommand, 0);
});

it('should fetch a multiple parameters if more than one is supplied',
test('should fetch a multiple parameters if more than one is supplied',
async () => {
try {
await fetchSsmParams('', '', '');
// eslint-disable-next-line no-empty
} catch {}
// eslint-disable-next-line no-empty
} catch { }
expect(ssmMock).toHaveReceivedCommandTimes(GetParameterCommand, 0);
expect(ssmMock).toHaveReceivedCommandTimes(GetParametersCommand, 1);
});
Expand Down
22 changes: 22 additions & 0 deletions libs/fetch-ssm-params/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "Node16",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
10 changes: 10 additions & 0 deletions libs/fetch-ssm-params/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["vite.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
26 changes: 26 additions & 0 deletions libs/fetch-ssm-params/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": [
"vitest/globals",
"vitest/importMeta",
"vite/client",
"node",
"vitest"
]
},
"include": [
"vite.config.ts",
"vitest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
]
}
27 changes: 27 additions & 0 deletions libs/fetch-ssm-params/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';

export default {
root: __dirname,
cacheDir: '../../node_modules/.vite/libs/fetch-ssm-params',

plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])],

// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
// },

test: {
watch: false,
globals: true,
environment: 'node',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
reporters: ['default'],
coverage: {
reportsDirectory: '../../coverage/libs/fetch-ssm-params',
provider: 'v8',
},
},
};
Loading