From a6d4d8c630a195054f0548561ad9626d21a85a3d Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Sun, 8 Sep 2024 17:33:18 +0200 Subject: [PATCH] Move things around a bit --- openrewrite/jest.config.js | 9 +++------ openrewrite/package-lock.json | 24 +++++++++++++++++++++++- openrewrite/package.json | 6 ++++-- openrewrite/src/core/index.ts | 1 + openrewrite/src/core/tree.ts | 18 ++++++++++++++++++ openrewrite/src/utils/math.ts | 3 --- openrewrite/test/core/tree.test.ts | 7 +++++++ openrewrite/test/utils/math.test.ts | 15 --------------- 8 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 openrewrite/src/core/index.ts create mode 100644 openrewrite/src/core/tree.ts delete mode 100644 openrewrite/src/utils/math.ts create mode 100644 openrewrite/test/core/tree.test.ts delete mode 100644 openrewrite/test/utils/math.test.ts diff --git a/openrewrite/jest.config.js b/openrewrite/jest.config.js index 100fbb65..c1f20c92 100644 --- a/openrewrite/jest.config.js +++ b/openrewrite/jest.config.js @@ -2,14 +2,11 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', testPathIgnorePatterns: ['/node_modules/', '/dist/'], - globals: { - 'ts-jest': { - tsconfig: 'tsconfig.json', // Adjust if your tsconfig file is named or located differently - }, - }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], transform: { - '^.+\\.tsx?$': 'ts-jest', + '^.+\\.tsx?$': ['ts-jest', { + tsconfig: 'tsconfig.json', // Adjust if your tsconfig file is named or located differently + }], }, testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'], collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.d.ts'], diff --git a/openrewrite/package-lock.json b/openrewrite/package-lock.json index adb48f56..0a507c84 100644 --- a/openrewrite/package-lock.json +++ b/openrewrite/package-lock.json @@ -8,10 +8,12 @@ "name": "openrewrite", "version": "1.0.0", "dependencies": { - "@types/node": "^22.5.4" + "@types/node": "^22.5.4", + "uuid": "^10.0.0" }, "devDependencies": { "@types/jest": "^29.5.12", + "@types/uuid": "^10.0.0", "jest": "^29.7.0", "ts-jest": "^29.2.5", "ts-node": "^10.9.2", @@ -1241,6 +1243,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/uuid": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/yargs": { "version": "17.0.33", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.33.tgz", @@ -4021,6 +4030,19 @@ "browserslist": ">= 4.21.0" } }, + "node_modules/uuid": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/v8-compile-cache-lib": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", diff --git a/openrewrite/package.json b/openrewrite/package.json index a2991b66..951fa949 100644 --- a/openrewrite/package.json +++ b/openrewrite/package.json @@ -1,5 +1,5 @@ { - "name": "openrewrite", + "name": "@openrewrite/rewrite", "version": "1.0.0", "description": "", "main": "dist/index.js", @@ -9,10 +9,12 @@ "test": "jest" }, "dependencies": { - "@types/node": "^22.5.4" + "@types/node": "^22.5.4", + "uuid": "^10.0.0" }, "devDependencies": { "@types/jest": "^29.5.12", + "@types/uuid": "^10.0.0", "jest": "^29.7.0", "ts-jest": "^29.2.5", "ts-node": "^10.9.2", diff --git a/openrewrite/src/core/index.ts b/openrewrite/src/core/index.ts new file mode 100644 index 00000000..50842b59 --- /dev/null +++ b/openrewrite/src/core/index.ts @@ -0,0 +1 @@ +export * from './tree'; diff --git a/openrewrite/src/core/tree.ts b/openrewrite/src/core/tree.ts new file mode 100644 index 00000000..d339fbde --- /dev/null +++ b/openrewrite/src/core/tree.ts @@ -0,0 +1,18 @@ +import { v4 as uuidv4 } from 'uuid'; + +type UUID = string; + +export const random_id = (): UUID => { + return uuidv4(); +} + +class CompilationUnit { + constructor( + public readonly id: UUID + ) { + } + + withId(newId: UUID): CompilationUnit { + return newId == this.id ? this : new CompilationUnit(newId); + } +} diff --git a/openrewrite/src/utils/math.ts b/openrewrite/src/utils/math.ts deleted file mode 100644 index 946a4b82..00000000 --- a/openrewrite/src/utils/math.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function add(a: number, b: number): number { - return a + b; -} \ No newline at end of file diff --git a/openrewrite/test/core/tree.test.ts b/openrewrite/test/core/tree.test.ts new file mode 100644 index 00000000..96ae5631 --- /dev/null +++ b/openrewrite/test/core/tree.test.ts @@ -0,0 +1,7 @@ +import { random_id } from '../../src/core'; + +describe('tree utils', () => { + test('new random ID', () => { + expect(random_id()).toBeDefined(); + }); +}); \ No newline at end of file diff --git a/openrewrite/test/utils/math.test.ts b/openrewrite/test/utils/math.test.ts deleted file mode 100644 index 70e46c0b..00000000 --- a/openrewrite/test/utils/math.test.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { add } from '../../src/utils/math'; - -describe('math utils', () => { - test('adds 1 + 2 to equal 3', () => { - expect(add(1, 2)).toBe(3); - }); - - test('adds -1 + -1 to equal -2', () => { - expect(add(-1, -1)).toBe(-2); - }); - - test('adds 1 + 0 to equal 1', () => { - expect(add(1, 0)).toBe(1); - }); -}); \ No newline at end of file