From 9eb2508fac78cc36faefd050e9616bb6d34814c1 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Fri, 23 Jun 2023 13:20:23 -0700 Subject: [PATCH] Clean up configs --- configs/babel-jest.config.json | 10 + babel.config.js => configs/babel.config.js | 0 jest.config.json => configs/jest.config.json | 5 +- rollup.config.js => configs/rollup.config.js | 2 +- .../swc-jest.config.json | 2 +- .../ts-jest.config.json | 2 +- .../tsconfig.base.json | 16 +- .../tsconfig.cjs.json | 9 +- .../tsconfig.esm.json | 5 +- .../tsconfig.test.json | 3 +- .../tsconfig.types.json | 7 +- vitest.config.ts => configs/vitest.config.ts | 2 +- deno/lib/__tests__/language-server.source.ts | 76 ------- deno/lib/__tests__/language-server.test.ts | 209 ------------------ package.json | 19 +- src/__tests__/language-server.test.ts | 2 +- tsconfig.json | 2 +- 17 files changed, 40 insertions(+), 331 deletions(-) create mode 100644 configs/babel-jest.config.json rename babel.config.js => configs/babel.config.js (100%) rename jest.config.json => configs/jest.config.json (76%) rename rollup.config.js => configs/rollup.config.js (91%) rename swc-jest.config.json => configs/swc-jest.config.json (93%) rename ts-jest.config.json => configs/ts-jest.config.json (93%) rename tsconfig.base.json => configs/tsconfig.base.json (73%) rename tsconfig.cjs.json => configs/tsconfig.cjs.json (69%) rename tsconfig.esm.json => configs/tsconfig.esm.json (73%) rename tsconfig.test.json => configs/tsconfig.test.json (83%) rename tsconfig.types.json => configs/tsconfig.types.json (60%) rename vitest.config.ts => configs/vitest.config.ts (84%) delete mode 100644 deno/lib/__tests__/language-server.source.ts delete mode 100644 deno/lib/__tests__/language-server.test.ts diff --git a/configs/babel-jest.config.json b/configs/babel-jest.config.json new file mode 100644 index 000000000..f46b627de --- /dev/null +++ b/configs/babel-jest.config.json @@ -0,0 +1,10 @@ +{ + "rootDir": "..", + "testRegex": "src/.*\\.test\\.ts$", + "transform": { + "^.+\\.tsx?$": ["babel-jest", { "configFile": "./configs/babel.config.js" }] + }, + "modulePathIgnorePatterns": ["language-server", "__vitest__"], + "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"], + "coverageReporters": ["json-summary", "text", "lcov"] +} diff --git a/babel.config.js b/configs/babel.config.js similarity index 100% rename from babel.config.js rename to configs/babel.config.js diff --git a/jest.config.json b/configs/jest.config.json similarity index 76% rename from jest.config.json rename to configs/jest.config.json index 3b0e10956..096278dcf 100644 --- a/jest.config.json +++ b/configs/jest.config.json @@ -1,5 +1,8 @@ { - "rootDir": ".", + "rootDir": "..", + "transform": { + "^.+\\.tsx?$": "ts-jest" + }, "testRegex": "src/.*\\.test\\.ts$", "modulePathIgnorePatterns": ["language-server", "__vitest__"], "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"], diff --git a/rollup.config.js b/configs/rollup.config.js similarity index 91% rename from rollup.config.js rename to configs/rollup.config.js index 1ccb37057..8f2090d33 100644 --- a/rollup.config.js +++ b/configs/rollup.config.js @@ -21,7 +21,7 @@ export default [ ], plugins: [ typescript({ - tsconfig: "tsconfig.esm.json", + tsconfig: "./configs/tsconfig.esm.json", sourceMap: false, }), ], diff --git a/swc-jest.config.json b/configs/swc-jest.config.json similarity index 93% rename from swc-jest.config.json rename to configs/swc-jest.config.json index 516809441..dd44db1f8 100644 --- a/swc-jest.config.json +++ b/configs/swc-jest.config.json @@ -1,5 +1,5 @@ { - "rootDir": ".", + "rootDir": "..", "transform": { "^.+\\.(t|j)sx?$": "@swc/jest" }, diff --git a/ts-jest.config.json b/configs/ts-jest.config.json similarity index 93% rename from ts-jest.config.json rename to configs/ts-jest.config.json index 8051d1085..096278dcf 100644 --- a/ts-jest.config.json +++ b/configs/ts-jest.config.json @@ -1,5 +1,5 @@ { - "rootDir": ".", + "rootDir": "..", "transform": { "^.+\\.tsx?$": "ts-jest" }, diff --git a/tsconfig.base.json b/configs/tsconfig.base.json similarity index 73% rename from tsconfig.base.json rename to configs/tsconfig.base.json index 374e5ad04..073703ed4 100644 --- a/tsconfig.base.json +++ b/configs/tsconfig.base.json @@ -1,12 +1,6 @@ { "compilerOptions": { - "lib": [ - "es5", - "es6", - "es7", - "esnext", - "dom" - ], + "lib": ["es5", "es6", "es7", "esnext", "dom"], "target": "es2018", "removeComments": false, "esModuleInterop": true, @@ -22,9 +16,5 @@ "downlevelIteration": true, "isolatedModules": true }, - "include": [ - "./src/**/*", - "playground.ts", - "./.eslintrc.js" - ] -} \ No newline at end of file + "include": ["../src/**/*", "../playground.ts", "../.eslintrc.js"] +} diff --git a/tsconfig.cjs.json b/configs/tsconfig.cjs.json similarity index 69% rename from tsconfig.cjs.json rename to configs/tsconfig.cjs.json index 9a393fdf8..32729f179 100644 --- a/tsconfig.cjs.json +++ b/configs/tsconfig.cjs.json @@ -2,14 +2,11 @@ "extends": "./tsconfig.base.json", "compilerOptions": { "module": "commonjs", - "outDir": "lib", + "outDir": "../lib", "declaration": true, "declarationMap": false, "sourceMap": false, "removeComments": true }, - "exclude": [ - "./src/**/__tests__", - "playground.ts" - ] -} \ No newline at end of file + "exclude": ["../src/**/__tests__", "../playground.ts"] +} diff --git a/tsconfig.esm.json b/configs/tsconfig.esm.json similarity index 73% rename from tsconfig.esm.json rename to configs/tsconfig.esm.json index 6d2fc8ef1..b5c23f25a 100644 --- a/tsconfig.esm.json +++ b/configs/tsconfig.esm.json @@ -7,8 +7,5 @@ "declarationMap": false, "sourceMap": false }, - "exclude": [ - "./src/**/__tests__", - "./src/playground.ts" - ] + "exclude": ["../src/**/__tests__", "../src/playground.ts"] } diff --git a/tsconfig.test.json b/configs/tsconfig.test.json similarity index 83% rename from tsconfig.test.json rename to configs/tsconfig.test.json index 625604ecc..1a9fe2c6d 100644 --- a/tsconfig.test.json +++ b/configs/tsconfig.test.json @@ -6,7 +6,8 @@ "target": "es5", "declaration": true, "declarationMap": false, - "sourceMap": false + "sourceMap": false, + "noEmit": true }, "exclude": [] } diff --git a/tsconfig.types.json b/configs/tsconfig.types.json similarity index 60% rename from tsconfig.types.json rename to configs/tsconfig.types.json index ff811649d..83aec7b76 100644 --- a/tsconfig.types.json +++ b/configs/tsconfig.types.json @@ -1,13 +1,10 @@ { "extends": "./tsconfig.base.json", "compilerOptions": { - "outDir": "./lib/types", + "outDir": "../lib/types", "declaration": true, "declarationMap": true, "emitDeclarationOnly": true }, - "exclude": [ - "./src/**/__tests__", - "./src/playground.ts" - ] + "exclude": ["../src/**/__tests__", "../src/playground.ts"] } diff --git a/vitest.config.ts b/configs/vitest.config.ts similarity index 84% rename from vitest.config.ts rename to configs/vitest.config.ts index 581e75fb1..a9671f849 100644 --- a/vitest.config.ts +++ b/configs/vitest.config.ts @@ -5,7 +5,7 @@ export default defineConfig({ alias: { "@jest/globals": "vitest", }, - include: ["**/*.test.ts"], + include: ["src/**/*.test.ts"], isolate: false, watch: false, }, diff --git a/deno/lib/__tests__/language-server.source.ts b/deno/lib/__tests__/language-server.source.ts deleted file mode 100644 index b0105556c..000000000 --- a/deno/lib/__tests__/language-server.source.ts +++ /dev/null @@ -1,76 +0,0 @@ -import * as z from "../index.ts"; - -export const filePath = __filename; - -// z.object() - -export const Test = z.object({ - f1: z.number(), -}); - -export type Test = z.infer; - -export const instanceOfTest: Test = { - f1: 1, -}; - -// z.object().merge() - -export const TestMerge = z - .object({ - f2: z.string().optional(), - }) - .merge(Test); - -export type TestMerge = z.infer; - -export const instanceOfTestMerge: TestMerge = { - f1: 1, - f2: "string", -}; - -// z.union() - -export const TestUnion = z.union([ - z.object({ - f2: z.string().optional(), - }), - Test, -]); - -export type TestUnion = z.infer; - -export const instanceOfTestUnion: TestUnion = { - f1: 1, - f2: "string", -}; - -// z.object().partial() - -export const TestPartial = Test.partial(); - -export type TestPartial = z.infer; - -export const instanceOfTestPartial: TestPartial = { - f1: 1, -}; - -// z.object().pick() - -export const TestPick = TestMerge.pick({ f1: true }); - -export type TestPick = z.infer; - -export const instanceOfTestPick: TestPick = { - f1: 1, -}; - -// z.object().omit() - -export const TestOmit = TestMerge.omit({ f2: true }); - -export type TestOmit = z.infer; - -export const instanceOfTestOmit: TestOmit = { - f1: 1, -}; diff --git a/deno/lib/__tests__/language-server.test.ts b/deno/lib/__tests__/language-server.test.ts deleted file mode 100644 index bc35d7370..000000000 --- a/deno/lib/__tests__/language-server.test.ts +++ /dev/null @@ -1,209 +0,0 @@ -// @ts-ignore TS6133 -import { expect } from "https://deno.land/x/expect@v0.2.6/mod.ts"; -const test = Deno.test; -// import path from "path"; -// import { Node, Project, SyntaxKind } from "ts-morph"; - -// import { filePath } from "./language-server.source"; - -// The following tool is helpful for understanding the TypeScript AST associated with these tests: -// https://ts-ast-viewer.com/ (just copy the contents of languageServerFeatures.source into the viewer) - -test("", () => {}); -// describe("Executing Go To Definition (and therefore Find Usages and Rename Refactoring) using an IDE works on inferred object properties", () => { -// // Compile file developmentEnvironment.source -// const project = new Project({ -// tsConfigFilePath: path.join(__dirname, "..", "..", "tsconfig.json"), -// skipAddingFilesFromTsConfig: true, -// }); -// const sourceFile = project.addSourceFileAtPath(filePath); - -// test("works for object properties inferred from z.object()", () => { -// // Find usage of Test.f1 property -// const instanceVariable = -// sourceFile.getVariableDeclarationOrThrow("instanceOfTest"); -// const propertyBeingAssigned = getPropertyBeingAssigned( -// instanceVariable, -// "f1" -// ); - -// // Find definition of Test.f1 property -// const definitionOfProperty = propertyBeingAssigned?.getDefinitionNodes()[0]; -// const parentOfProperty = definitionOfProperty?.getFirstAncestorByKind( -// SyntaxKind.VariableDeclaration -// ); - -// // Assert that find definition returned the Zod definition of Test -// expect(definitionOfProperty?.getText()).toEqual("f1: z.number()"); -// expect(parentOfProperty?.getName()).toEqual("Test"); -// }); - -// // test("works for first object properties inferred from z.object().merge()", () => { -// // // Find usage of TestMerge.f1 property -// // const instanceVariable = sourceFile.getVariableDeclarationOrThrow( -// // "instanceOfTestMerge" -// // ); -// // const propertyBeingAssigned = getPropertyBeingAssigned( -// // instanceVariable, -// // "f1" -// // ); - -// // // Find definition of TestMerge.f1 property -// // const definitionOfProperty = propertyBeingAssigned?.getDefinitionNodes()[0]; -// // const parentOfProperty = definitionOfProperty?.getFirstAncestorByKind( -// // SyntaxKind.VariableDeclaration -// // ); - -// // // Assert that find definition returned the Zod definition of Test -// // expect(definitionOfProperty?.getText()).toEqual("f1: z.number()"); -// // expect(parentOfProperty?.getName()).toEqual("Test"); -// // }); - -// // test("works for second object properties inferred from z.object().merge()", () => { -// // // Find usage of TestMerge.f2 property -// // const instanceVariable = sourceFile.getVariableDeclarationOrThrow( -// // "instanceOfTestMerge" -// // ); -// // const propertyBeingAssigned = getPropertyBeingAssigned( -// // instanceVariable, -// // "f2" -// // ); - -// // // Find definition of TestMerge.f2 property -// // const definitionOfProperty = propertyBeingAssigned?.getDefinitionNodes()[0]; -// // const parentOfProperty = definitionOfProperty?.getFirstAncestorByKind( -// // SyntaxKind.VariableDeclaration -// // ); - -// // // Assert that find definition returned the Zod definition of TestMerge -// // expect(definitionOfProperty?.getText()).toEqual( -// // "f2: z.string().optional()" -// // ); -// // expect(parentOfProperty?.getName()).toEqual("TestMerge"); -// // }); - -// test("works for first object properties inferred from z.union()", () => { -// // Find usage of TestUnion.f1 property -// const instanceVariable = sourceFile.getVariableDeclarationOrThrow( -// "instanceOfTestUnion" -// ); -// const propertyBeingAssigned = getPropertyBeingAssigned( -// instanceVariable, -// "f1" -// ); - -// // Find definition of TestUnion.f1 property -// const definitionOfProperty = propertyBeingAssigned?.getDefinitionNodes()[0]; -// const parentOfProperty = definitionOfProperty?.getFirstAncestorByKind( -// SyntaxKind.VariableDeclaration -// ); - -// // Assert that find definition returned the Zod definition of Test -// expect(definitionOfProperty?.getText()).toEqual("f1: z.number()"); -// expect(parentOfProperty?.getName()).toEqual("Test"); -// }); - -// test("works for second object properties inferred from z.union()", () => { -// // Find usage of TestUnion.f2 property -// const instanceVariable = sourceFile.getVariableDeclarationOrThrow( -// "instanceOfTestUnion" -// ); -// const propertyBeingAssigned = getPropertyBeingAssigned( -// instanceVariable, -// "f2" -// ); - -// // Find definition of TestUnion.f2 property -// const definitionOfProperty = propertyBeingAssigned?.getDefinitionNodes()[0]; -// const parentOfProperty = definitionOfProperty?.getFirstAncestorByKind( -// SyntaxKind.VariableDeclaration -// ); - -// // Assert that find definition returned the Zod definition of TestUnion -// expect(definitionOfProperty?.getText()).toEqual( -// "f2: z.string().optional()" -// ); -// expect(parentOfProperty?.getName()).toEqual("TestUnion"); -// }); - -// test("works for object properties inferred from z.object().partial()", () => { -// // Find usage of TestPartial.f1 property -// const instanceVariable = sourceFile.getVariableDeclarationOrThrow( -// "instanceOfTestPartial" -// ); -// const propertyBeingAssigned = getPropertyBeingAssigned( -// instanceVariable, -// "f1" -// ); - -// // Find definition of TestPartial.f1 property -// const definitionOfProperty = propertyBeingAssigned?.getDefinitionNodes()[0]; -// const parentOfProperty = definitionOfProperty?.getFirstAncestorByKind( -// SyntaxKind.VariableDeclaration -// ); - -// // Assert that find definition returned the Zod definition of Test -// expect(definitionOfProperty?.getText()).toEqual("f1: z.number()"); -// expect(parentOfProperty?.getName()).toEqual("Test"); -// }); - -// test("works for object properties inferred from z.object().pick()", () => { -// // Find usage of TestPick.f1 property -// const instanceVariable = -// sourceFile.getVariableDeclarationOrThrow("instanceOfTestPick"); -// const propertyBeingAssigned = getPropertyBeingAssigned( -// instanceVariable, -// "f1" -// ); - -// // Find definition of TestPick.f1 property -// const definitionOfProperty = propertyBeingAssigned?.getDefinitionNodes()[0]; -// const parentOfProperty = definitionOfProperty?.getFirstAncestorByKind( -// SyntaxKind.VariableDeclaration -// ); - -// // Assert that find definition returned the Zod definition of Test -// expect(definitionOfProperty?.getText()).toEqual("f1: z.number()"); -// expect(parentOfProperty?.getName()).toEqual("Test"); -// }); - -// test("works for object properties inferred from z.object().omit()", () => { -// // Find usage of TestOmit.f1 property -// const instanceVariable = -// sourceFile.getVariableDeclarationOrThrow("instanceOfTestOmit"); -// const propertyBeingAssigned = getPropertyBeingAssigned( -// instanceVariable, -// "f1" -// ); - -// // Find definition of TestOmit.f1 property -// const definitionOfProperty = propertyBeingAssigned?.getDefinitionNodes()[0]; -// const parentOfProperty = definitionOfProperty?.getFirstAncestorByKind( -// SyntaxKind.VariableDeclaration -// ); - -// // Assert that find definition returned the Zod definition of Test -// expect(definitionOfProperty?.getText()).toEqual("f1: z.number()"); -// expect(parentOfProperty?.getName()).toEqual("Test"); -// }); -// }); - -// const getPropertyBeingAssigned = (node: Node, name: string) => { -// const propertyAssignment = node.forEachDescendant((descendent) => -// Node.isPropertyAssignment(descendent) && descendent.getName() == name -// ? descendent -// : undefined -// ); - -// if (propertyAssignment == null) -// fail(`Could not find property assignment with name ${name}`); - -// const propertyLiteral = propertyAssignment.getFirstDescendantByKind( -// SyntaxKind.Identifier -// ); - -// if (propertyLiteral == null) -// fail(`Could not find property literal with name ${name}`); - -// return propertyLiteral; -// }; diff --git a/package.json b/package.json index 7bf7f60d5..19f114de9 100644 --- a/package.json +++ b/package.json @@ -90,18 +90,17 @@ "clean": "rm -rf lib/* deno/lib/*", "build": "yarn run clean && npm run build:cjs && npm run build:esm && npm run build:deno", "build:deno": "node ./deno-build.mjs && cp ./README.md ./deno/lib", - "build:esm": "rollup --config rollup.config.js", - "build:cjs": "tsc -p tsconfig.cjs.json", - "build:types": "tsc -p tsconfig.types.json", - "build:test": "tsc -p tsconfig.test.json", - "rollup": "rollup --config rollup.config.js", - "test:watch": "jest --watch", + "build:esm": "rollup --config ./configs/rollup.config.js", + "build:cjs": "tsc -p ./configs/tsconfig.cjs.json", + "build:types": "tsc -p ./configs/tsconfig.types.json", + "build:test": "tsc -p ./configs/tsconfig.test.json", + "test:watch": "yarn test:ts-jest --watch", "test": "yarn test:ts-jest", - "test:babel": "jest --coverage", + "test:babel": "jest --coverage --config ./configs/babel-jest.config.json", "test:bun": "bun test", - "test:vitest": "npx vitest --no-isolate", - "test:ts-jest": "npx jest --config ./ts-jest.config.json", - "test:swc": "npx jest --config ./swc-jest.config.json", + "test:vitest": "npx vitest --config ./configs/vitest.config.ts", + "test:ts-jest": "npx jest --config ./configs/ts-jest.config.json", + "test:swc": "npx jest --config ./configs/swc-jest.config.json", "test:deno": "cd deno && deno test", "prepublishOnly": "npm run test && npm run build && npm run build:deno", "play": "nodemon -e ts -w . -x tsx playground.ts", diff --git a/src/__tests__/language-server.test.ts b/src/__tests__/language-server.test.ts index 88767b4ab..fb5c647e5 100644 --- a/src/__tests__/language-server.test.ts +++ b/src/__tests__/language-server.test.ts @@ -1,5 +1,5 @@ // @ts-ignore TS6133 -import { expect, test, describe } from "@jest/globals"; +import { describe, expect, test } from "@jest/globals"; // import path from "path"; // import { Node, Project, SyntaxKind } from "ts-morph"; diff --git a/tsconfig.json b/tsconfig.json index ffcbb9477..a1b3dc7e4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,3 +1,3 @@ { - "extends": "./tsconfig.base.json" + "extends": "./configs/tsconfig.base.json" }