Skip to content

Commit

Permalink
refactor: remove ts-nameof and ttypescript dev dependencies (#1217)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Nov 13, 2021
1 parent 720380e commit 3ba4f63
Show file tree
Hide file tree
Showing 336 changed files with 2,319 additions and 2,326 deletions.
4 changes: 4 additions & 0 deletions deno/common/ts_morph_common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,10 @@ export declare class IterableUtils {
static find<T>(items: IterableIterator<T>, condition: (item: T) => boolean): T | undefined;
}

export declare function nameof<TObject>(obj: TObject, key: keyof TObject): string;

export declare function nameof<TObject>(key: keyof TObject): string;

export declare class ObjectUtils {
private constructor();
static clone<T>(obj: T): T;
Expand Down
8 changes: 6 additions & 2 deletions deno/common/ts_morph_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ class IterableUtils {
}
}

function nameof(key1, key2) {
return key2 !== null && key2 !== void 0 ? key2 : key1;
}

class ObjectUtils {
constructor() {
}
Expand Down Expand Up @@ -975,7 +979,7 @@ function createHosts(options) {
function getLibFolderPath() {
if (options.libFolderPath != null) {
if (options.skipLoadingLibFiles === true) {
throw new errors.InvalidOperationError(`Cannot set ${"skipLoadingLibFiles"} to true when ${"libFolderPath"} is provided.`);
throw new errors.InvalidOperationError(`Cannot set ${nameof(options, "skipLoadingLibFiles")} to true when ${nameof(options, "libFolderPath")} is provided.`);
}
return options.libFolderPath;
}
Expand Down Expand Up @@ -2561,4 +2565,4 @@ function getCompilerOptionsFromTsConfig(filePath, options = {}) {
};
}

export { ArrayUtils, ComparerToStoredComparer, CompilerOptionsContainer, DocumentRegistry, EventContainer, FileUtils, InMemoryFileSystemHost, IterableUtils, KeyValueCache, LocaleStringComparer, Memoize, ObjectUtils, PropertyComparer, PropertyStoredComparer, RealFileSystemHost, ResolutionHosts, SettingsContainer, SortedKeyValueArray, StringUtils, TransactionalFileSystem, TsConfigResolver, WeakCache, createDocumentCache, createHosts, createModuleResolutionHost, deepClone, errors, getCompilerOptionsFromTsConfig, getEmitModuleResolutionKind, getFileMatcherPatterns, getLibFiles, getSyntaxKindName, libFolderInMemoryPath, matchFiles, matchGlobs, runtime };
export { ArrayUtils, ComparerToStoredComparer, CompilerOptionsContainer, DocumentRegistry, EventContainer, FileUtils, InMemoryFileSystemHost, IterableUtils, KeyValueCache, LocaleStringComparer, Memoize, ObjectUtils, PropertyComparer, PropertyStoredComparer, RealFileSystemHost, ResolutionHosts, SettingsContainer, SortedKeyValueArray, StringUtils, TransactionalFileSystem, TsConfigResolver, WeakCache, createDocumentCache, createHosts, createModuleResolutionHost, deepClone, errors, getCompilerOptionsFromTsConfig, getEmitModuleResolutionKind, getFileMatcherPatterns, getLibFiles, getSyntaxKindName, libFolderInMemoryPath, matchFiles, matchGlobs, nameof, runtime };
1 change: 1 addition & 0 deletions deno/ts_morph.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4606,6 +4606,7 @@ export declare class Decorator extends DecoratorBase<ts.Decorator> {
removeArgument(index: number): this;
/** Removes this decorator. */
remove(): void;
_getInnerExpression(): Expression<ts.Expression>;
/**
* Sets the node from a structure.
* @param structure - Structure to set the node with.
Expand Down
409 changes: 207 additions & 202 deletions deno/ts_morph.js

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions packages/bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"build": "npm run build:declarations && npm run build:node && npm run build:deno",
"build:node": "rimraf dist && npm run rollup",
"build:deno": "rimraf dist-deno && npm run rollup -- --environment BUILD:deno && ts-node scripts/buildDeno.ts",
"build:declarations": "ts-node --compiler ttypescript --project scripts/tsconfig.json --transpile-only scripts/buildDeclarations.ts",
"test": "cross-env TS_NODE_COMPILER=\"ttypescript\" TS_NODE_TRANSPILE_ONLY=\"true\" mocha",
"build:declarations": "ts-node --project scripts/tsconfig.json --transpile-only scripts/buildDeclarations.ts",
"test": "cross-env TS_NODE_TRANSPILE_ONLY=\"true\" mocha",
"test:ci": "npm run test",
"test:debug": "npm run test --inspect-brk",
"test:ts-versions": "ts-node --transpile-only scripts/test/testTypeScriptVersions",
Expand All @@ -25,17 +25,14 @@
"devDependencies": {
"@types/chai": "^4.2.22",
"@types/mocha": "^9.0.0",
"@types/ts-nameof": "^4.2.1",
"@ts-morph/scripts": "~0.2.0",
"chai": "^4.3.4",
"cross-env": "^7.0.3",
"mocha": "^9.1.3",
"rimraf": "^3.0.2",
"rollup": "^2.58.3",
"rollup-plugin-typescript2": "^0.30.0",
"ts-nameof": "^5.0.0",
"ts-node": "^10.4.0",
"ttypescript": "^1.5.12",
"typescript": "~4.4.4"
},
"publishConfig": {
Expand Down
1 change: 0 additions & 1 deletion packages/bootstrap/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default {
},
plugins: [
typescript({
typescript: require("ttypescript"),
tsconfig: "tsconfig.rollup.json",
}),
],
Expand Down
3 changes: 1 addition & 2 deletions packages/bootstrap/scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"outDir": "../dist-scripts",
"rootDir": "../",
"noEmit": true,
"module": "commonjs",
"plugins": [{ "transform": "ts-nameof", "type": "raw" }]
"module": "commonjs"
},
"include": [
"../**/*.ts"
Expand Down
42 changes: 21 additions & 21 deletions packages/bootstrap/src/tests/projectTests.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getLibFiles, InMemoryFileSystemHost, ts } from "@ts-morph/common";
import { getLibFiles, InMemoryFileSystemHost, nameof, ts } from "@ts-morph/common";
import { expect } from "chai";
import { EOL } from "os";
import { createProject, createProjectSync, Project, ProjectOptions } from "../Project";

describe(nameof(Project), () => {
describe("Project", () => {
describe("constructor", () => {
describe("async ctor", () => doTestsForProject(opts => createProject(opts)));
describe("sync ctor", () => doTestsForProject(opts => Promise.resolve(createProjectSync(opts))));
Expand Down Expand Up @@ -222,7 +222,7 @@ describe(nameof(Project), () => {
});
});

describe(nameof<ProjectOptions>(o => o.skipLoadingLibFiles), () => {
describe(nameof<ProjectOptions>("skipLoadingLibFiles"), () => {
it("should not skip loading lib files when empty", async () => {
const project = await create({ useInMemoryFileSystem: true });
const sourceFile = project.createSourceFile("test.ts", "const t: String = '';");
Expand Down Expand Up @@ -258,7 +258,7 @@ describe(nameof(Project), () => {
});
});

describe(nameof<ProjectOptions>(o => o.libFolderPath), () => {
describe(nameof<ProjectOptions>("libFolderPath"), () => {
it("should support specifying a different folder for the lib files", async () => {
const fileSystem = new InMemoryFileSystemHost();
for (const file of getLibFiles())
Expand All @@ -278,7 +278,7 @@ describe(nameof(Project), () => {
}
});

describe(nameof<Project>(p => p.createSourceFile), () => {
describe(nameof<Project>("createSourceFile"), () => {
it("should create the specified source files", () => {
const project = createProjectSync({ useInMemoryFileSystem: true, skipLoadingLibFiles: true });
const sourceFiles = [
Expand All @@ -290,7 +290,7 @@ describe(nameof(Project), () => {
});
});

describe(nameof<Project>(p => p.removeSourceFile), () => {
describe(nameof<Project>("removeSourceFile"), () => {
it("should remove the specified source files by source file object", () => {
const { project } = setup();
const sourceFiles = [
Expand All @@ -313,7 +313,7 @@ describe(nameof(Project), () => {
});
});

describe(nameof<Project>(p => p.updateSourceFile), () => {
describe(nameof<Project>("updateSourceFile"), () => {
it("should update a source file", () => {
const { project } = setup();
project.createSourceFile("/test.ts", "class Test {}");
Expand Down Expand Up @@ -350,7 +350,7 @@ describe(nameof(Project), () => {
});
});

describe(nameof<Project>(p => p.addSourceFileAtPath), () => {
describe(nameof<Project>("addSourceFileAtPath"), () => {
describe("async", () => doTestsForMethod((project, filePath, options) => project.addSourceFileAtPath(filePath, options)));
describe("sync", () => doTestsForMethod((project, filePath, options) => Promise.resolve(project.addSourceFileAtPath(filePath, options))));

Expand Down Expand Up @@ -379,7 +379,7 @@ describe(nameof(Project), () => {
}
});

describe(nameof<Project>(p => p.addSourceFileAtPathIfExists), () => {
describe(nameof<Project>("addSourceFileAtPathIfExists"), () => {
describe("async", () => doTestsForMethod((project, filePath, options) => project.addSourceFileAtPathIfExists(filePath, options)));
describe("sync", () => doTestsForMethod((project, filePath, options) => Promise.resolve(project.addSourceFileAtPathIfExists(filePath, options))));

Expand All @@ -405,7 +405,7 @@ describe(nameof(Project), () => {
}
});

describe(nameof<Project>(project => project.addSourceFilesFromTsConfig), () => {
describe(nameof<Project>("addSourceFilesFromTsConfig"), () => {
describe("async", () => doTestsForMethod((project, filePath) => project.addSourceFilesFromTsConfig(filePath)));
describe("sync", () => doTestsForMethod((project, filePath) => Promise.resolve(project.addSourceFilesFromTsConfigSync(filePath))));

Expand Down Expand Up @@ -441,7 +441,7 @@ describe(nameof(Project), () => {
}
});

describe(nameof<Project>(p => p.addSourceFilesByPaths), () => {
describe(nameof<Project>("addSourceFilesByPaths"), () => {
describe("async", () => doTestsForMethod((project, globs) => project.addSourceFilesByPaths(globs)));
describe("sync", () => doTestsForMethod((project, globs) => Promise.resolve(project.addSourceFilesByPathsSync(globs))));

Expand All @@ -462,7 +462,7 @@ describe(nameof(Project), () => {
}
});

describe(nameof<Project>(p => p.resolveSourceFileDependencies), () => {
describe(nameof<Project>("resolveSourceFileDependencies"), () => {
it("should resolve file dependencies once specified and include those in the node_modules folder", async () => {
const { project, initialFiles, resolvedFiles, nodeModuleFiles } = await fileDependencyResolutionSetup({ skipFileDependencyResolution: true },
createProject);
Expand All @@ -485,8 +485,8 @@ describe(nameof(Project), () => {
`{ "name": "library2", "version": "0.0.1", "main": "index.js", "typings": "index.d.ts", "typescript": { "definition": "index.d.ts" } }`);
fileSystem.writeFileSync("/node_modules/library2/index.js", "export class Library2 {}");
fileSystem.writeFileSync("/node_modules/library2/index.d.ts", "export class Library2 {}");
fileSystem.writeFileSync("/src/main.ts", "/// <reference path='../other/referenced-file.d.ts' />\n\nimport { Test } from 'library'; nameof();");
fileSystem.writeFileSync("/other/referenced-file.d.ts", "declare function nameof(): void;");
fileSystem.writeFileSync("/src/main.ts", "/// <reference path='../other/referenced-file.d.ts' />\n\nimport { Test } from 'library'; something();");
fileSystem.writeFileSync("/other/referenced-file.d.ts", "declare function something(): void;");
fileSystem.writeFileSync("/tsconfig.json", `{ "files": ["src/main.ts"] }`);

const project = await create({ tsConfigFilePath: "tsconfig.json", fileSystem, ...options, skipLoadingLibFiles: true });
Expand All @@ -501,7 +501,7 @@ describe(nameof(Project), () => {
};
}

describe(nameof<Project>(p => p.formatDiagnosticsWithColorAndContext), () => {
describe(nameof<Project>("formatDiagnosticsWithColorAndContext"), () => {
function setup() {
const project = createProjectSync({ useInMemoryFileSystem: true });
project.createSourceFile("test.ts", "const t; const u;");
Expand Down Expand Up @@ -538,7 +538,7 @@ describe(nameof(Project), () => {
});
});

describe(nameof<Project>(p => p.getModuleResolutionHost), () => {
describe(nameof<Project>("getModuleResolutionHost"), () => {
function setup() {
const project = createProjectSync({ useInMemoryFileSystem: true });
const moduleResolutionHost = project.getModuleResolutionHost();
Expand Down Expand Up @@ -637,7 +637,7 @@ describe(nameof(Project), () => {
});
});

describe(nameof<Project>(p => p.createProgram), () => {
describe(nameof<Project>("createProgram"), () => {
it("should create a program and get a type checker", () => {
const { project } = setup();
const sourceFile = project.createSourceFile("./test.ts", "export const t = 5;");
Expand All @@ -649,7 +649,7 @@ describe(nameof(Project), () => {
});
});

describe(nameof<Project>(p => p.getLanguageService), () => {
describe(nameof<Project>("getLanguageService"), () => {
it("should create a language service", () => {
const { project } = setup();
const languageSerivce = project.getLanguageService(); // define it first
Expand All @@ -667,7 +667,7 @@ describe(nameof(Project), () => {
});
});

describe(nameof<Project>(project => project.getSourceFile), () => {
describe(nameof<Project>("getSourceFile"), () => {
it("should get the first match based on the directory structure", () => {
const project = createProjectSync({ useInMemoryFileSystem: true });
project.createSourceFile("dir/file.ts");
Expand Down Expand Up @@ -711,7 +711,7 @@ describe(nameof(Project), () => {
});
});

describe(nameof<Project>(project => project.getSourceFileOrThrow), () => {
describe(nameof<Project>("getSourceFileOrThrow"), () => {
it("should throw when it can't find the source file based on a provided file name", () => {
const project = createProjectSync({ useInMemoryFileSystem: true });
expect(() => project.getSourceFileOrThrow("fileName.ts")).to.throw(
Expand Down Expand Up @@ -748,7 +748,7 @@ describe(nameof(Project), () => {
});
});

describe(nameof<ts.Program>(p => p.getConfigFileParsingDiagnostics), () => {
describe(nameof<ts.Program>("getConfigFileParsingDiagnostics"), () => {
it("should get the diagnostics found when parsing the tsconfig.json", () => {
const fileSystem = new InMemoryFileSystemHost();
fileSystem.writeFileSync("/tsconfig.json", `{ "fies": [] }`);
Expand Down
3 changes: 1 addition & 2 deletions packages/bootstrap/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"compilerOptions": {
"declaration": false,
"rootDir": "./src",
"outDir": "./dist",
"plugins": [{ "transform": "ts-nameof", "type": "raw" }]
"outDir": "./dist"
},
"include": [
"./src"
Expand Down
3 changes: 1 addition & 2 deletions packages/bootstrap/tsconfig.rollup.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"compilerOptions": {
"module": "es2015",
"moduleResolution": "node",
"removeComments": true,
"plugins": [{ "transform": "ts-nameof", "type": "raw" }]
"removeComments": true
},
"exclude": [
"lib",
Expand Down
4 changes: 4 additions & 0 deletions packages/common/lib/ts-morph-common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,10 @@ export declare class IterableUtils {
static find<T>(items: IterableIterator<T>, condition: (item: T) => boolean): T | undefined;
}

export declare function nameof<TObject>(obj: TObject, key: keyof TObject): string;

export declare function nameof<TObject>(key: keyof TObject): string;

export declare class ObjectUtils {
private constructor();
static clone<T>(obj: T): T;
Expand Down
7 changes: 2 additions & 5 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"build": "npm run build:declarations && npm run build:node && npm run build:deno",
"build:node": "rimraf dist && npm run createLibFile && npm run rollup && ts-node scripts/bundleLocalTs.ts",
"build:deno": "rimraf ../../deno/common && rimraf dist-deno && npm run rollup -- --environment BUILD:deno && npm run build:declarations && ts-node scripts/buildDeno.ts",
"build:declarations": "ts-node --compiler ttypescript --project scripts/tsconfig.json --transpile-only scripts/buildDeclarations.ts",
"build:declarations": "ts-node --project scripts/tsconfig.json --transpile-only scripts/buildDeclarations.ts",
"createLibFile": "ts-node scripts/createLibFile.ts",
"test": "cross-env TS_NODE_COMPILER=\"ttypescript\" TS_NODE_TRANSPILE_ONLY=\"true\" mocha",
"test": "cross-env TS_NODE_TRANSPILE_ONLY=\"true\" mocha",
"test:ci": "npm run test",
"test:debug": "npm run test --inspect-brk",
"rollup": "rollup --config"
Expand All @@ -31,17 +31,14 @@
"@types/mocha": "^9.0.0",
"@types/minimatch": "^3.0.5",
"@types/node": "^16.11.6",
"@types/ts-nameof": "^4.2.1",
"chai": "^4.3.4",
"cross-env": "^7.0.3",
"dts-minify": "^0.2.3",
"mocha": "^9.1.3",
"rimraf": "^3.0.2",
"rollup": "^2.58.3",
"rollup-plugin-typescript2": "^0.30.0",
"ts-nameof": "^5.0.0",
"ts-node": "^10.4.0",
"ttypescript": "^1.5.12",
"typescript": "4.4.4"
},
"publishConfig": {
Expand Down
2 changes: 0 additions & 2 deletions packages/common/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default [{
},
plugins: [
typescript({
typescript: require("ttypescript"),
tsconfig: "tsconfig.rollup.json",
}),
],
Expand All @@ -24,7 +23,6 @@ export default [{
},
plugins: [
typescript({
typescript: require("ttypescript"),
tsconfig: "tsconfig.rollup.json",
}),
],
Expand Down
3 changes: 1 addition & 2 deletions packages/common/scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"outDir": "../dist-scripts",
"rootDir": "../",
"noEmit": true,
"module": "commonjs",
"plugins": [{ "transform": "ts-nameof", "type": "raw" }]
"module": "commonjs"
}
}
3 changes: 2 additions & 1 deletion packages/common/src/compiler/createHosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getLibFiles, libFolderInMemoryPath } from "../getLibFiles";
import { CompilerOptionsContainer } from "../options";
import { runtime } from "../runtimes";
import { ScriptTarget, ts } from "../typescript";
import { nameof } from "../utils";
import { ResolutionHost } from "./ResolutionHost";
import { TsSourceFileContainer } from "./TsSourceFileContainer";

Expand Down Expand Up @@ -161,7 +162,7 @@ export function createHosts(options: CreateHostsOptions) {
if (options.libFolderPath != null) {
if (options.skipLoadingLibFiles === true) {
throw new errors.InvalidOperationError(
`Cannot set ${nameof(options.skipLoadingLibFiles)} to true when ${nameof(options.libFolderPath)} is provided.`,
`Cannot set ${nameof(options, "skipLoadingLibFiles")} to true when ${nameof(options, "libFolderPath")} is provided.`,
);
}
return options.libFolderPath;
Expand Down
5 changes: 3 additions & 2 deletions packages/common/src/tests/collections/keyValueCacheTests.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { expect } from "chai";
import { KeyValueCache } from "../../collections";
import { nameof } from "../../utils";

// todo: more tests

describe(nameof(KeyValueCache), () => {
describe(nameof<KeyValueCache<number, number>>(c => c.replaceKey), () => {
describe("KeyValueCache", () => {
describe(nameof<KeyValueCache<number, number>>("replaceKey"), () => {
it("should throw when replacing a key that doesn't exist", () => {
const cache = new KeyValueCache<{}, {}>();
expect(() => cache.replaceKey({}, {})).to.throw(Error, "Key not found.");
Expand Down
Loading

0 comments on commit 3ba4f63

Please sign in to comment.