diff --git a/stage_2_snapshot/fixtures/import-dist/cmdLine.js b/stage_2_snapshot/fixtures/import-dist/cmdLine.js new file mode 100644 index 00000000..2058c34a --- /dev/null +++ b/stage_2_snapshot/fixtures/import-dist/cmdLine.js @@ -0,0 +1,2 @@ +import driver from "./driver.js"; +driver(process.argv[process.argv.length - 1]); diff --git a/stage_2_snapshot/fixtures/import-dist/driver.js b/stage_2_snapshot/fixtures/import-dist/driver.js new file mode 100644 index 00000000..8bd2df4e --- /dev/null +++ b/stage_2_snapshot/fixtures/import-dist/driver.js @@ -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"); +} diff --git a/stage_2_snapshot/fixtures/import-dist/package.json b/stage_2_snapshot/fixtures/import-dist/package.json new file mode 100644 index 00000000..d1f0feb0 --- /dev/null +++ b/stage_2_snapshot/fixtures/import-dist/package.json @@ -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 ", + "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" + } +} diff --git a/stage_2_snapshot/spec-snapshot/build-checks/import-dist.ts b/stage_2_snapshot/spec-snapshot/build-checks/import-dist.ts new file mode 100644 index 00000000..64cc96bb --- /dev/null +++ b/stage_2_snapshot/spec-snapshot/build-checks/import-dist.ts @@ -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);