From 41bb7c76d648d37d21f63c0998ad7c70742a8f44 Mon Sep 17 00:00:00 2001 From: uid11 Date: Tue, 23 Jan 2024 08:00:15 +0300 Subject: [PATCH] FI-1136 fix: use `E2ED_DOCKER_IMAGE` instead of `dockerImage` pack option feat: support dotenv file `./autotests/.env` fix: use `E2ED_PATH_TO_TS_CONFIG_OF_PROJECT_FROM_ROOT` environment variables --- .prettierrc.yaml | 8 ++- README.md | 14 ++++- autotests/.env | 10 +++ autotests/bin/runDocker.sh | 17 ++--- autotests/packs/allTests.ts | 2 - autotests/packs/local.example.ts | 1 - src/README.md | 46 ++++++++------ src/constants/internal.ts | 1 + src/constants/paths.ts | 8 ++- src/types/config/ownE2edConfig.ts | 13 ---- src/types/environment.ts | 1 + src/utils/clone/cloneWithoutLogEvents.ts | 10 +-- .../environment/getDotEnvValuesObject.ts | 52 +++++++++++++++ src/utils/environment/index.ts | 2 + .../setDotEnvValuesToEnvironment.ts | 29 +++++++++ src/utils/events/registerStartE2edRunEvent.ts | 24 ++++++- src/utils/pack/index.ts | 2 - src/utils/pack/packTimeout.ts | 2 +- .../{pack => packCompiler}/compilePack.ts | 39 +++--------- src/utils/packCompiler/getCompilerOptions.ts | 63 +++++++++++++++++++ src/utils/packCompiler/index.ts | 2 + tsconfig.json | 8 +-- 22 files changed, 258 insertions(+), 96 deletions(-) create mode 100644 autotests/.env create mode 100644 src/utils/environment/getDotEnvValuesObject.ts create mode 100644 src/utils/environment/setDotEnvValuesToEnvironment.ts rename src/utils/{pack => packCompiler}/compilePack.ts (55%) create mode 100644 src/utils/packCompiler/getCompilerOptions.ts create mode 100644 src/utils/packCompiler/index.ts diff --git a/.prettierrc.yaml b/.prettierrc.yaml index 7b6d9bc9..1356d410 100644 --- a/.prettierrc.yaml +++ b/.prettierrc.yaml @@ -1,6 +1,8 @@ -trailingComma: all arrowParens: always -singleQuote: true +bracketSpacing: false jsxSingleQuote: false +overrides: + - {files: ./tsconfig.json, options: {parser: json}} printWidth: 100 -bracketSpacing: false +singleQuote: true +trailingComma: all diff --git a/README.md b/README.md index b2972b69..0af3d4be 100644 --- a/README.md +++ b/README.md @@ -268,9 +268,6 @@ The functions accept a start info object, and can return new full pack config, which in this case will be included in the start info object, and will be used for running pack. Each function can thus access the results of the previous function. -`dockerImage: string`: the name of the docker image where the tests will run. -The image must be based on the e2ed base image. - `enableChromeDevToolsProtocol: boolean`: enables [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) for browser control in tests (instead of `testcafe-hammerhead`). @@ -405,6 +402,17 @@ If the wait is longer than this timeout, then the promise returned by the `waitF ### Environment variables +Required environment variables are defined in the `./autotests/.env` file (they cannot be deleted): + +`E2ED_DOCKER_IMAGE`: the name of the docker image where the tests will run. +The image must be based on the e2ed base image. + +`E2ED_PATH_TO_TS_CONFIG_OF_PROJECT_FROM_ROOT`: the path to TypeScript config file of the project +from the root directory of the project. The project should have one common TypeScript config +for both the application code and the autotest code. + +You can pass the following optional environment variables to the `e2ed` process in any standard way: + `E2ED_ORIGIN`: origin-part of the url (`protocol` + `host`) on which the tests will be run. For example, `https://google.com`. `E2ED_DEBUG`: run e2ed in `nodejs` debug mode (`--inspect-brk=0.0.0.0`) if this variable is not empty. diff --git a/autotests/.env b/autotests/.env new file mode 100644 index 00000000..58301734 --- /dev/null +++ b/autotests/.env @@ -0,0 +1,10 @@ +# This required file in standard dotenv format defines the environment variables +# with which all packs will be run. +# {@link https://www.npmjs.com/package/dotenv} + +# Required variable: the name of the docker image where the tests will run. +E2ED_DOCKER_IMAGE='e2edhub/e2ed' + +# Required variable: the path to TypeScript config file of the project +# from the root directory of the project. +E2ED_PATH_TO_TS_CONFIG_OF_PROJECT_FROM_ROOT='./tsconfig.json' diff --git a/autotests/bin/runDocker.sh b/autotests/bin/runDocker.sh index 62b459e8..44cf5422 100755 --- a/autotests/bin/runDocker.sh +++ b/autotests/bin/runDocker.sh @@ -5,15 +5,16 @@ set +u CONTAINER_LABEL="e2ed" DEBUG_PORT="${E2ED_DOCKER_DEBUG_PORT:-9229}" DIR="${E2ED_WORKDIR:-$PWD}" -DOCKER_IMAGE=$(grep -m1 dockerImage $DIR/$1 | sed -e "s/^[^'\"\`]*['\"\`]//" -e "s/['\"\`][^'\"\`]*$//") MOUNTDIR="${E2ED_MOUNTDIR:-$DIR}" WITH_DEBUG=$([[ -z $E2ED_DEBUG ]] && echo "" || echo "--env E2ED_DEBUG=$DEBUG_PORT --publish $DEBUG_PORT:$DEBUG_PORT --publish $((DEBUG_PORT + 1)):$((DEBUG_PORT + 1))") VERSION=$(grep -m1 \"e2ed\": $DIR/package.json | cut -d '"' -f 4) -if [[ -z $DOCKER_IMAGE ]] +source ./autotests/.env + +if [[ -z $E2ED_DOCKER_IMAGE ]] then - echo "Error: The pack config does not contain an explicit line with \"dockerImage\"." - echo "Add it so that the bash script can read the docker image." + echo "Error: The \"autotests/.env\" file does not contain E2ED_DOCKER_IMAGE variable." + echo "Add it so that \"runDocker.sh\" script can run the docker image." echo "Exit with code 9" exit 9 fi @@ -23,16 +24,16 @@ onExit() { if [[ -z $CONTAINER_ID ]] then - echo "Docker container from image $DOCKER_IMAGE:$VERSION already stopped" + echo "Docker container from image $E2ED_DOCKER_IMAGE:$VERSION already stopped" else - echo "Stop docker container from image $DOCKER_IMAGE:$VERSION" + echo "Stop docker container from image $E2ED_DOCKER_IMAGE:$VERSION" docker stop --time=60 $CONTAINER_ID fi exit } -echo "Run docker image $DOCKER_IMAGE:$VERSION" +echo "Run docker image $E2ED_DOCKER_IMAGE:$VERSION" trap "onExit" EXIT @@ -45,7 +46,7 @@ docker run \ --volume $MOUNTDIR:$MOUNTDIR \ --workdir $DIR \ $WITH_DEBUG \ - $DOCKER_IMAGE:$VERSION \ + $E2ED_DOCKER_IMAGE:$VERSION \ & PID=$! wait $PID diff --git a/autotests/packs/allTests.ts b/autotests/packs/allTests.ts index 45d6b55f..e0abef43 100644 --- a/autotests/packs/allTests.ts +++ b/autotests/packs/allTests.ts @@ -48,7 +48,6 @@ export const pack: Pack = { customPackProperties: {internalPackRunId: 0, name: 'allTests'}, doAfterPack, doBeforePack, - dockerImage: 'e2edhub/e2ed', enableChromeDevToolsProtocol: true, enableHeadlessMode: true, enableLiveMode: false, @@ -68,7 +67,6 @@ export const pack: Pack = { pageRequestTimeout: 30_000, pageStabilizationInterval: 500, pathToScreenshotsDirectoryForReport: './screenshots', - pathToTsConfigOfProjectFromRoot: './tsconfig.json', port1: 1337, port2: 1338, reportFileName: 'report.html', diff --git a/autotests/packs/local.example.ts b/autotests/packs/local.example.ts index 0a686743..ddf28138 100644 --- a/autotests/packs/local.example.ts +++ b/autotests/packs/local.example.ts @@ -8,5 +8,4 @@ import type {Pack} from 'autotests/types/pack'; export const pack: Pack = { ...allTestsPack, browserInitTimeout: 40_000, - dockerImage: 'e2edhub/e2ed', }; diff --git a/src/README.md b/src/README.md index 6c0c17b4..a12732c1 100644 --- a/src/README.md +++ b/src/README.md @@ -19,23 +19,29 @@ Modules in the dependency graph should only import the modules above them: 12. `utils/valueToString` 13. `utils/error` 14. `utils/asserts` -15. `utils/userland` -16. `utils/fn` -17. `utils/environment` -18. `testcaferc` -19. `utils/config` -20. `utils/runLabel` -21. `utils/generalLog` -22. `utils/fs` -23. `selectors` -24. `Route` -25. `ApiRoute` -26. `PageRoute` -27. `testController` -28. `useContext` -29. `context` -30. `utils/log` -31. `utils/waitForEvents` -32. `utils/expect` -33. `expect` -34. ... +15. `utils/clone` +16. `utils/notIncludedInPackTests` +17. `utils/userland` +18. `utils/fn` +19. `utils/environment` +20. `utils/packCompiler` +21. `testcaferc` +22. `utils/config` +23. `utils/runLabel` +24. `utils/generalLog` +25. `utils/fs` +26. `utils/tests` +27. `utils/end` +28. `utils/pack` +29. `selectors` +30. `Route` +31. `ApiRoute` +32. `PageRoute` +33. `testController` +34. `useContext` +35. `context` +36. `utils/log` +37. `utils/waitForEvents` +38. `utils/expect` +39. `expect` +40. ... diff --git a/src/constants/internal.ts b/src/constants/internal.ts index e30f7cf7..5b6ad95a 100644 --- a/src/constants/internal.ts +++ b/src/constants/internal.ts @@ -33,6 +33,7 @@ export { ABSOLUTE_PATH_TO_PROJECT_ROOT_DIRECTORY, AUTOTESTS_DIRECTORY_PATH, COMPILED_USERLAND_CONFIG_DIRECTORY, + DOT_ENV_PATH, EVENTS_DIRECTORY_PATH, INSTALLED_E2ED_DIRECTORY_PATH, REPORTS_DIRECTORY_PATH, diff --git a/src/constants/paths.ts b/src/constants/paths.ts index 979debb1..39fe8b0c 100644 --- a/src/constants/paths.ts +++ b/src/constants/paths.ts @@ -36,6 +36,12 @@ export const INSTALLED_E2ED_DIRECTORY_PATH = relative( */ export const AUTOTESTS_DIRECTORY_PATH = 'autotests' as DirectoryPathFromRoot; +/** + * Relative (from root) path to `.env` file in directory with autotests. + * @internal + */ +export const DOT_ENV_PATH = join(AUTOTESTS_DIRECTORY_PATH, '.env') as FilePathFromRoot; + /** * Relative (from root) path to reports directory. * @internal @@ -82,7 +88,7 @@ export const SCREENSHOTS_DIRECTORY_PATH = join( export const START_INFO_PATH = join(TMP_DIRECTORY_PATH, 'startInfo.json') as FilePathFromRoot; /** - * Relative (from root) path to testcaferc file, + * Relative (from root) path to `testcaferc` file, * that plays the role of the internal TestCafe config. * @internal */ diff --git a/src/types/config/ownE2edConfig.ts b/src/types/config/ownE2edConfig.ts index fc96ca2e..d2cfc847 100644 --- a/src/types/config/ownE2edConfig.ts +++ b/src/types/config/ownE2edConfig.ts @@ -45,12 +45,6 @@ export type OwnE2edConfig< liteReport: LiteReport, ) => MaybePromise)[]; - /** - * The name of the docker image where the tests will run. - * The image must be based on the e2ed base image. - */ - dockerImage: string; - /** * Enables Chrome DevTools Protocol for browser control in tests (instead of `testcafe-hammerhead`). * {@link https://chromedevtools.github.io/devtools-protocol/} @@ -180,13 +174,6 @@ export type OwnE2edConfig< */ pathToScreenshotsDirectoryForReport: string | null; - /** - * Path to TypeScript config file of the project from the root directory of the project. - * The project should have one common TypeScript config for both - * the application code and the autotest code. - */ - pathToTsConfigOfProjectFromRoot: string; - /** * The name of the file under which, after running the tests, * the HTML report will be saved in the `autotests/reports` directory, for example, `report.html`. diff --git a/src/types/environment.ts b/src/types/environment.ts index e1a3e6b5..348972cc 100644 --- a/src/types/environment.ts +++ b/src/types/environment.ts @@ -16,6 +16,7 @@ export type E2edEnvironment = { [key: string]: string | undefined; ['E2ED_DEBUG']?: string; ['E2ED_ORIGIN']?: string; + ['E2ED_PATH_TO_TS_CONFIG_OF_PROJECT_FROM_ROOT']?: string; [PATH_TO_PACK_VARIABLE_NAME]?: string; ['PWD']?: string; [RUN_ENVIRONMENT_VARIABLE_NAME]?: RunEnvironment; diff --git a/src/utils/clone/cloneWithoutLogEvents.ts b/src/utils/clone/cloneWithoutLogEvents.ts index 51c5d911..a0125041 100644 --- a/src/utils/clone/cloneWithoutLogEvents.ts +++ b/src/utils/clone/cloneWithoutLogEvents.ts @@ -1,12 +1,12 @@ -type WithLogEvents = {logEvents: unknown}; +type WithLogEvents = Readonly<{logEvents: unknown}>; /** - * Clone test run object without logEvents property (to reduce logs). + * Clone test run object without `logEvents` property (to reduce logs). * @internal */ -export const cloneWithoutLogEvents = ( - withLogEvents: T, -): Omit => { +export const cloneWithoutLogEvents = ( + withLogEvents: Type, +): Omit => { const {logEvents, ...withoutLogEvents} = withLogEvents ?? {}; void logEvents; diff --git a/src/utils/environment/getDotEnvValuesObject.ts b/src/utils/environment/getDotEnvValuesObject.ts new file mode 100644 index 00000000..4e81e78a --- /dev/null +++ b/src/utils/environment/getDotEnvValuesObject.ts @@ -0,0 +1,52 @@ +import {readFile} from 'node:fs/promises'; + +import {DOT_ENV_PATH, READ_FILE_OPTIONS} from '../../constants/internal'; + +import {E2edError} from '../error'; + +/** + * Get object with values from `.env` file in directory with autotests. + * {@link https://www.npmjs.com/package/dotenv} + * @internal + */ +export const getDotEnvValuesObject = async (): Promise>> => { + const dotEnvText = await readFile(DOT_ENV_PATH, READ_FILE_OPTIONS); + + const lines = dotEnvText.split('\n'); + const result = Object.create(null) as Record; + + for (const line of lines) { + const trimmedLine = line.trim(); + + if (line === '' || line[0] === '#') { + continue; + } + + const indexOfEqualSign = trimmedLine.indexOf('='); + + if (indexOfEqualSign < 1) { + throw new E2edError('Incorrect name of environment variable in `.env`', {line}); + } + + const name = trimmedLine.slice(0, indexOfEqualSign).trim(); + + if (name in result) { + throw new E2edError(`Duplicate name "${name}" in \`.env\` file`, { + firstValue: result[name], + line, + }); + } + + const valueMaybeWithQuotes = trimmedLine.slice(indexOfEqualSign + 1).trim(); + const firstCharacter = valueMaybeWithQuotes[0]; + const isQuoted = + firstCharacter === valueMaybeWithQuotes.at(-1) && + (firstCharacter === '"' || firstCharacter === "'" || firstCharacter === '`'); + + const value = isQuoted ? valueMaybeWithQuotes.slice(1, -1) : valueMaybeWithQuotes; + + result[name] = value; + } + + return result; +}; diff --git a/src/utils/environment/index.ts b/src/utils/environment/index.ts index 0d55fcf4..c7ddf9da 100644 --- a/src/utils/environment/index.ts +++ b/src/utils/environment/index.ts @@ -2,3 +2,5 @@ export {getPathToPack, setPathToPack} from './pathToPack'; /** @internal */ export {getRunLabel, setRunLabel} from './runLabel'; +/** @internal */ +export {setDotEnvValuesToEnvironment} from './setDotEnvValuesToEnvironment'; diff --git a/src/utils/environment/setDotEnvValuesToEnvironment.ts b/src/utils/environment/setDotEnvValuesToEnvironment.ts new file mode 100644 index 00000000..f3369631 --- /dev/null +++ b/src/utils/environment/setDotEnvValuesToEnvironment.ts @@ -0,0 +1,29 @@ +import {e2edEnvironment} from '../../constants/internal'; + +import {E2edError} from '../error'; + +import {getDotEnvValuesObject} from './getDotEnvValuesObject'; + +/** + * Set values from `.env` file in directory with autotests to environment (to `process.env`). + * @internal + */ +export const setDotEnvValuesToEnvironment = async (): Promise => { + // eslint-disable-next-line @typescript-eslint/unbound-method + const {hasOwnProperty} = Object.prototype; + const values = await getDotEnvValuesObject(); + + for (const [name, value] of Object.entries(values)) { + if (hasOwnProperty.call(e2edEnvironment, name) && e2edEnvironment[name] !== value) { + throw new E2edError( + `Environment variable "${name}" from \`.env\` already defined in \`process.env\` with other value`, + { + valueFromDotEnv: value, + valueFromProccessEnv: e2edEnvironment[name], + }, + ); + } + + e2edEnvironment[name] = value; + } +}; diff --git a/src/utils/events/registerStartE2edRunEvent.ts b/src/utils/events/registerStartE2edRunEvent.ts index bddd9821..43d2ee10 100644 --- a/src/utils/events/registerStartE2edRunEvent.ts +++ b/src/utils/events/registerStartE2edRunEvent.ts @@ -2,11 +2,13 @@ import {RunEnvironment} from '../../configurator'; import {EVENTS_DIRECTORY_PATH, ExitCode, TMP_DIRECTORY_PATH} from '../../constants/internal'; import {getFullPackConfig, updateConfig} from '../config'; +import {getPathToPack, setDotEnvValuesToEnvironment} from '../environment'; import {E2edError} from '../error'; import {setGlobalExitCode} from '../exit'; import {createDirectory, removeDirectory, writeStartInfo} from '../fs'; import {generalLog, writeLogsToFile} from '../generalLog'; -import {compilePack, setPackTimeout} from '../pack'; +import {setPackTimeout} from '../pack'; +import {compilePack} from '../packCompiler'; import {getStartInfo} from '../startInfo'; import {runBeforePackFunctions} from './runBeforePackFunctions'; @@ -19,7 +21,13 @@ export const registerStartE2edRunEvent = async (): Promise => { await removeDirectory(TMP_DIRECTORY_PATH); await createDirectory(EVENTS_DIRECTORY_PATH); - compilePack(); + let errorSettingDotEnv: unknown; + + await setDotEnvValuesToEnvironment().catch((error: unknown) => { + errorSettingDotEnv = error; + }); + + const compileErrors = compilePack(); const startInfo = getStartInfo(); @@ -35,6 +43,18 @@ export const registerStartE2edRunEvent = async (): Promise => { updateConfig(fullPackConfig, startInfo); + if (errorSettingDotEnv) { + generalLog('Caught an error on setting environment variables from `.env` file', { + errorSettingDotEnv, + }); + } + + if (compileErrors.length !== 0) { + const pathToPack = getPathToPack(); + + generalLog(`Caught errors on compiling pack ${pathToPack}`, {compileErrors}); + } + const {e2ed, runEnvironment} = startInfo; const isDockerRun = runEnvironment === RunEnvironment.Docker; const startMessage = `Run tests ${isDockerRun ? 'in docker' : 'local'} with e2ed@${e2ed.version}`; diff --git a/src/utils/pack/index.ts b/src/utils/pack/index.ts index 2b7b2e6f..5fc42787 100644 --- a/src/utils/pack/index.ts +++ b/src/utils/pack/index.ts @@ -1,6 +1,4 @@ /** @internal */ -export {compilePack} from './compilePack'; -/** @internal */ export {setPackTimeout} from './packTimeout'; /** @internal */ export {runPackWithArgs} from './runPackWithArgs'; diff --git a/src/utils/pack/packTimeout.ts b/src/utils/pack/packTimeout.ts index f08c4e36..f162acd9 100644 --- a/src/utils/pack/packTimeout.ts +++ b/src/utils/pack/packTimeout.ts @@ -20,7 +20,7 @@ export const getPackTimeoutPromise = (): Promise => }); /** - * Set pack timeout from pack config field "packTimeout". + * Set pack timeout from pack config field `packTimeout`. * @internal */ export const setPackTimeout = (): void => { diff --git a/src/utils/pack/compilePack.ts b/src/utils/packCompiler/compilePack.ts similarity index 55% rename from src/utils/pack/compilePack.ts rename to src/utils/packCompiler/compilePack.ts index fd1a9c2b..f2868582 100644 --- a/src/utils/pack/compilePack.ts +++ b/src/utils/packCompiler/compilePack.ts @@ -1,41 +1,13 @@ import { - type CompilerOptions, createProgram, flattenDiagnosticMessageText, getLineAndCharacterOfPosition, getPreEmitDiagnostics, - JsxEmit, - ModuleKind, - ScriptTarget, } from 'typescript'; -import { - AUTOTESTS_DIRECTORY_PATH, - COMPILED_USERLAND_CONFIG_DIRECTORY, -} from '../../constants/internal'; - import {getPathToPack} from '../environment'; -import {generalLog} from '../generalLog'; - -// jsx, lib, paths, target, types -const compilerOptions: CompilerOptions = { - allowSyntheticDefaultImports: true, - declaration: false, - esModuleInterop: true, - jsx: JsxEmit.React, - module: ModuleKind.CommonJS, - outDir: COMPILED_USERLAND_CONFIG_DIRECTORY, - paths: { - [AUTOTESTS_DIRECTORY_PATH]: [`./${AUTOTESTS_DIRECTORY_PATH}/index.ts`], - [`${AUTOTESTS_DIRECTORY_PATH}/*`]: [`./${AUTOTESTS_DIRECTORY_PATH}/*`], - }, - resolveJsonModule: true, - rootDir: '.', - skipLibCheck: true, - target: ScriptTarget.ESNext, - types: ['node'], -}; +import {getCompilerOptions} from './getCompilerOptions'; const unusedTsExceptErrorMessage = "Unused '@ts-expect-error' directive."; @@ -43,7 +15,8 @@ const unusedTsExceptErrorMessage = "Unused '@ts-expect-error' directive."; * Compiles pack file before running tests (or tasks). * @internal */ -export const compilePack = (): void => { +export const compilePack = (): readonly Readonly>[] => { + const compilerOptions = getCompilerOptions(); const pathToPack = getPathToPack(); const program = createProgram([pathToPack], compilerOptions); @@ -51,6 +24,8 @@ export const compilePack = (): void => { const allDiagnostics = getPreEmitDiagnostics(program).concat(diagnostics); + const errors: Readonly>[] = []; + allDiagnostics.forEach((diagnostic) => { const message = flattenDiagnosticMessageText(diagnostic.messageText, '\n'); @@ -69,6 +44,8 @@ export const compilePack = (): void => { logData.file = `${diagnostic.file.fileName} (${line + 1},${character + 1})`; } - generalLog(`Error on compiling pack ${pathToPack}`, logData); + errors.push(logData); }); + + return errors; }; diff --git a/src/utils/packCompiler/getCompilerOptions.ts b/src/utils/packCompiler/getCompilerOptions.ts new file mode 100644 index 00000000..bbc8c56d --- /dev/null +++ b/src/utils/packCompiler/getCompilerOptions.ts @@ -0,0 +1,63 @@ +import {join} from 'node:path'; + +import {type CompilerOptions, ModuleKind, ScriptTarget} from 'typescript'; + +import { + ABSOLUTE_PATH_TO_PROJECT_ROOT_DIRECTORY, + AUTOTESTS_DIRECTORY_PATH, + COMPILED_USERLAND_CONFIG_DIRECTORY, + e2edEnvironment, +} from '../../constants/internal'; + +import {assertValueIsDefined} from '../asserts'; +import {cloneWithoutUndefinedProperties} from '../clone'; + +const frozenCompilerOptions: CompilerOptions = { + allowSyntheticDefaultImports: true, + declaration: false, + esModuleInterop: true, + module: ModuleKind.CommonJS, + outDir: COMPILED_USERLAND_CONFIG_DIRECTORY, + paths: { + [AUTOTESTS_DIRECTORY_PATH]: [`./${AUTOTESTS_DIRECTORY_PATH}/index.ts`], + [`${AUTOTESTS_DIRECTORY_PATH}/*`]: [`./${AUTOTESTS_DIRECTORY_PATH}/*`], + }, + resolveJsonModule: true, + rootDir: '.', + skipLibCheck: true, + target: ScriptTarget.ESNext, + types: ['node'], +}; + +/** + * Get TypeScript compiler options for pack config compilation. + * @internal + */ +export const getCompilerOptions = (): CompilerOptions => { + let tsConfigOfProject: Readonly<{compilerOptions: CompilerOptions}> = {compilerOptions: {}}; + + const pathToTsConfigOfProjectFromRoot = + e2edEnvironment.E2ED_PATH_TO_TS_CONFIG_OF_PROJECT_FROM_ROOT; + + try { + assertValueIsDefined( + pathToTsConfigOfProjectFromRoot, + 'pathToTsConfigOfProjectFromRoot is defined', + ); + + const absoluteTsConfigPath = join( + ABSOLUTE_PATH_TO_PROJECT_ROOT_DIRECTORY, + pathToTsConfigOfProjectFromRoot, + ); + + // eslint-disable-next-line global-require, import/no-dynamic-require + tsConfigOfProject = require(absoluteTsConfigPath); + } catch {} + + const compilerOptions: CompilerOptions = {...frozenCompilerOptions}; + const {jsx, lib, paths, target} = tsConfigOfProject.compilerOptions; + + Object.assign(compilerOptions, cloneWithoutUndefinedProperties({jsx, lib, paths, target})); + + return compilerOptions; +}; diff --git a/src/utils/packCompiler/index.ts b/src/utils/packCompiler/index.ts new file mode 100644 index 00000000..c2102ce6 --- /dev/null +++ b/src/utils/packCompiler/index.ts @@ -0,0 +1,2 @@ +/** @internal */ +export {compilePack} from './compilePack'; diff --git a/tsconfig.json b/tsconfig.json index 0c1bf874..257d646a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,7 @@ "outDir": "build", "paths": { "autotests": ["./autotests/index.ts"], - "autotests/*": ["./autotests/*"], + "autotests/*": ["./autotests/*"] }, "preserveConstEnums": true, "resolveJsonModule": true, @@ -27,12 +27,12 @@ "stripInternal": true, "target": "ES2016", "types": ["node"], - "useDefineForClassFields": true, + "useDefineForClassFields": true }, "include": [ "./autotests/**/*.ts", "./node_modules/e2ed/**/*.ts", "./scripts/**/*.ts", - "./src/**/*.ts", - ], + "./src/**/*.ts" + ] }