-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#83, test importing ts-morph-structures in another project.
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import driver from "./driver.js"; | ||
driver(process.argv[process.argv.length - 1]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { | ||
ModuleKind, | ||
ModuleResolutionKind, | ||
Project, | ||
ScriptTarget, | ||
} from "ts-morph"; | ||
|
||
import { | ||
getTypeAugmentedStructure, | ||
VoidTypeNodeToTypeStructureConsole, | ||
} from "ts-morph-structures"; | ||
|
||
const TSC_CONFIG = { | ||
"compilerOptions": { | ||
"lib": ["es2022"], | ||
"module": ModuleKind.ESNext, | ||
"target": ScriptTarget.ESNext, | ||
"moduleResolution": ModuleResolutionKind.NodeNext, | ||
}, | ||
skipAddingFilesFromTsConfig: true, | ||
}; | ||
const project = new Project(TSC_CONFIG); | ||
|
||
export default function driver(pathToFile) { | ||
const sourceFile = project.addSourceFileAtPath(pathToFile); | ||
const structure = getTypeAugmentedStructure( | ||
sourceFile, VoidTypeNodeToTypeStructureConsole, true | ||
).rootStructure; | ||
process.stdout.write(JSON.stringify(structure) + "\n\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "ts-morph-structures_import-test", | ||
"version": "0.1.0", | ||
"description": "Structure classes for ts-morph, including type structure classes.", | ||
"type": "module", | ||
"engines": { | ||
"node": ">=18.19" | ||
}, | ||
"scripts": { | ||
"start": "node ./cmdLine.js" | ||
}, | ||
"author": "Alexander J. Vincent <[email protected]>", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"mixin-decorators": "^1.0.1", | ||
"ts-morph": "^22.0.0", | ||
"ts-morph-structures": "__TSM_STRUCTURES__", | ||
"ts-node": "^10.9.2", | ||
"tslib": "^2.6.2", | ||
"type-fest": "^4.12.0", | ||
"typescript": "^5.4.2" | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
stage_2_snapshot/spec-snapshot/build-checks/import-dist.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import fs from "fs/promises"; | ||
import path from "path"; | ||
import which from "which"; | ||
import { exec } from "child_process"; | ||
import { promisify } from "util"; | ||
|
||
import tempDirWithCleanup from "#utilities/source/tempDirWithCleanup.js"; | ||
|
||
import { | ||
ModuleSourceDirectory, | ||
pathToModule, | ||
projectDir | ||
} from "#utilities/source/AsyncSpecModules.js"; | ||
|
||
import getTS_SourceFile from "#utilities/source/getTS_SourceFile.js"; | ||
|
||
import { | ||
getTypeAugmentedStructure, | ||
VoidTypeNodeToTypeStructureConsole, | ||
} from "#stage_two/snapshot/source/exports.js"; | ||
|
||
const execPromise = promisify(exec); | ||
|
||
const stageDir: ModuleSourceDirectory = { | ||
importMeta: import.meta, | ||
pathToDirectory: "../../.." | ||
}; | ||
|
||
const sourceDir = pathToModule(stageDir, "fixtures/import-dist"); | ||
const cleanup = await tempDirWithCleanup(); | ||
const targetDir = cleanup.tempDir; | ||
|
||
// copy package files | ||
{ | ||
await fs.cp(sourceDir, targetDir, { recursive: true }); | ||
await fs.cp(path.join(projectDir, "node_modules"), path.join(targetDir, "node_modules"), { recursive: true }); | ||
} | ||
|
||
const npm = await which("npm"); | ||
|
||
it("Driver generates a valid set of classes", async () => { | ||
const DefaultMapModule = pathToModule(stageDir, "fixtures/stage_utilities/DefaultMap.ts"); | ||
const DefaultMapStructure = getTypeAugmentedStructure( | ||
getTS_SourceFile(stageDir, "fixtures/stage_utilities/DefaultMap.ts"), VoidTypeNodeToTypeStructureConsole, true | ||
).rootStructure; | ||
|
||
try { | ||
await execPromise( | ||
npm + " install " + projectDir, | ||
{ cwd: targetDir } | ||
); | ||
|
||
const {stdout} = await execPromise( | ||
npm + " start " + DefaultMapModule, | ||
{ cwd: targetDir } | ||
); | ||
|
||
expect( | ||
JSON.parse(stdout.substring(stdout.indexOf("{"))) | ||
).toEqual(JSON.parse(JSON.stringify(DefaultMapStructure))); | ||
} | ||
finally { | ||
cleanup.resolve(null); | ||
await cleanup.promise; | ||
} | ||
}, 1000 * 30); |