diff --git a/README.md b/README.md index 07a2e056..d216b3ad 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,24 @@ We highly recommend the usage of the following tools: - Document This - ESLint - Prettier - Code formatter +- [Volta](https://volta.sh/) — manages Node.js and npm versions for this project + +#### Node.js and npm (Volta) + +This project pins Node.js and npm versions in `package.json`. Install [Volta](https://volta.sh/) once and the correct versions are applied automatically when you work in this repository. + +**Install Volta:** follow the official [Getting Started guide](https://docs.volta.sh/guide/getting-started) (macOS, Windows, and Linux). + +**Verify Volta is active:** + +```bash +volta --version # Volta is installed +volta which node # pinned Node version for this project +volta which npm # pinned npm version for this project +node -v +npm -v +``` + ### How to use change this code? diff --git a/gulp/Tasks/TsTranspile.js b/gulp/Tasks/TsTranspile.js index 10d925a4..b7c1ceb1 100644 --- a/gulp/Tasks/TsTranspile.js +++ b/gulp/Tasks/TsTranspile.js @@ -1,8 +1,7 @@ -const gulp = require('gulp'); const { series } = require('gulp'); const fs = require('fs'); -const sourcemaps = require('gulp-sourcemaps'); -const ts = require('gulp-typescript'); +const path = require('node:path'); +const ts = require('typescript'); const distFolder = './dist'; const project = require('../DefaultSpecs'); @@ -88,34 +87,54 @@ function tsTranspile(cb, envMode, platformType) { // Method that will trigger the transpile of Ts according if it's development or production mode and platform type (O11 or ODC) async function tsTranspileBasedOnPlatform(cb, envMode, platformType, shouldCreateAll) { - let tsProject = ts.createProject('tsconfig.json', { + const compilerOptions = { outDir: distFolder, declaration: envMode === project.globalConsts.envType.production ? true : false, - outFile: `${envMode === project.globalConsts.envType.production ? '' : envMode + '.'}${ - platformType !== '' ? platformType + '.' : '' - }${project.globalConsts.fileName}.js`, - }); + outFile: path.join( + distFolder, + `${envMode === project.globalConsts.envType.production ? '' : envMode + '.'}${ + platformType !== '' ? platformType + '.' : '' + }${project.globalConsts.fileName}.js` + ), + }; if (envMode === project.globalConsts.envType.development) { - tsProject - .src() - .pipe(sourcemaps.init()) - .pipe(tsProject()) - .js.pipe(sourcemaps.write('.')) - .pipe(gulp.dest(distFolder)) - .on('finish', () => { - onTsCompileFinish(platformType, cb, shouldCreateAll); - }); - } else { - tsProject - .src() - .pipe(tsProject()) - .pipe(gulp.dest(distFolder)) - .on('finish', () => { - onTsCompileFinish(platformType, cb, shouldCreateAll); - }); + compilerOptions.sourceMap = true; + } + + const configFile = ts.readConfigFile('tsconfig.json', ts.sys.readFile); + const parsedConfig = ts.parseJsonConfigFileContent( + configFile.config, + ts.sys, + path.dirname(path.resolve('tsconfig.json')), + compilerOptions, + path.resolve('tsconfig.json') + ); + + const program = ts.createProgram({ + rootNames: parsedConfig.fileNames, + options: parsedConfig.options, + }); + + const emitResult = program.emit(); + const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); + + if (diagnostics.length > 0) { + console.error( + ts.formatDiagnosticsWithColorAndContext(diagnostics, { + getCurrentDirectory: () => ts.sys.getCurrentDirectory(), + getCanonicalFileName: (fileName) => fileName, + getNewLine: () => ts.sys.newLine, + }) + ); } + if (emitResult.emitSkipped) { + throw new Error('TypeScript compilation failed'); + } + + onTsCompileFinish(platformType, cb, shouldCreateAll); + // Rollback tsconfig file to the default state if (defaultTsConfigText !== '') { rollBackTsConfigFile(); diff --git a/package.json b/package.json index 179763d2..716d3a3e 100644 --- a/package.json +++ b/package.json @@ -36,12 +36,11 @@ "eslint": "^8.57.1", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.0.0", - "gulp": "^4.0.2", + "gulp": "^5.0.0", "gulp-autoprefixer": "^8.0.0", "gulp-clean": "^0.4.0", "gulp-remove-empty-lines": "^0.1.0", "gulp-sourcemaps": "^3.0.0", - "gulp-typescript": "^6.0.0-alpha.1", "postcss": "^8.5.6", "postcss-discard-comments": "^5.1.2", "postcss-discard-duplicates": "^5.1.0", @@ -59,6 +58,6 @@ }, "volta": { "node": "24.13.1", - "npm": "11.10.1" + "npm": "11.18.0" } -} +} \ No newline at end of file