@ardentcode/tsc
Advanced tools
+147
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.ProgramATSC = void 0; | ||
| const getConfig_1 = __importDefault(require("./utils/getConfig")); | ||
| const path_1 = require("path"); | ||
| const typescript_1 = __importDefault(require("typescript")); | ||
| const fs_1 = __importDefault(require("fs")); | ||
| const getOutputFilename_1 = require("./utils/getOutputFilename"); | ||
| const createFile_1 = __importDefault(require("./utils/createFile")); | ||
| const buildCache_1 = require("../../build-cache/dist/buildCache"); | ||
| const logger_1 = require("./logger/logger"); | ||
| class ProgramATSC { | ||
| constructor(argsParser) { | ||
| this.argsParser = argsParser; | ||
| this.config = (0, getConfig_1.default)(argsParser.options); | ||
| this.tsMetadata = this.getTSMetadata(); | ||
| this.cache = this.createCache(); | ||
| this.program = this.getTSProgram(); | ||
| } | ||
| compile() { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| yield this.cache.validateCache(this.tsMetadata); | ||
| let cacheFilesUsed = 0; | ||
| let compiledFiles = 0; | ||
| const fileNames = this.config.fileNames; | ||
| for (const filePath of fileNames) { | ||
| const takenFromCache = yield this.compileFile(filePath); | ||
| logger_1.logger.debug(`${filePath} ${takenFromCache ? "taken from cache" : "compiled"}.`); | ||
| takenFromCache ? cacheFilesUsed++ : compiledFiles++; | ||
| } | ||
| yield this.cache.saveMetadata(this.tsMetadata); | ||
| return { | ||
| cacheFilesUsed, | ||
| compiledFiles, | ||
| }; | ||
| }); | ||
| } | ||
| purgeCache() { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| yield this.cache.purge(); | ||
| logger_1.logger.info(`Cache purged`); | ||
| }); | ||
| } | ||
| createCache() { | ||
| const cacheSeed = this.getCacheSeed(); | ||
| logger_1.logger.debug(`Cache mounted on ${process.cwd()} with seed: ${cacheSeed}`); | ||
| return new buildCache_1.BuildCache(cacheSeed, process.cwd(), this.argsParser.hasFlag("verbose")); | ||
| } | ||
| getTSProgram() { | ||
| const cliFileNames = this.argsParser.fileNames; | ||
| const { fileNames, compilerOptions } = this.config; | ||
| const program = typescript_1.default.createProgram(cliFileNames.length === 0 ? fileNames : cliFileNames, Object.assign(Object.assign({}, compilerOptions), { emitDeclarationOnly: true })); | ||
| return program; | ||
| } | ||
| getTSMetadata() { | ||
| const { options } = this.argsParser; | ||
| const tsConfigOptions = this.config.tsConfigOptions; | ||
| return { | ||
| cliOptions: options, | ||
| tsVersion: typescript_1.default.version, | ||
| compilerOptions: tsConfigOptions, | ||
| }; | ||
| } | ||
| transpileModule(filePath) { | ||
| const code = this.getSourceCode(filePath); | ||
| const options = this.config.compilerOptions; | ||
| try { | ||
| return typescript_1.default.transpileModule(code, { | ||
| compilerOptions: options, | ||
| fileName: (0, path_1.basename)(filePath), | ||
| }); | ||
| } | ||
| catch (e) { | ||
| logger_1.logger.error(`Compilation failed for ${filePath}`); | ||
| throw e; | ||
| } | ||
| } | ||
| compileFile(filePath) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const sourceCodeHash = this.getSourceCodeHash(filePath); | ||
| const cacheEntry = yield this.getCacheEntry(filePath, sourceCodeHash); | ||
| if (cacheEntry) { | ||
| this.createFilesFromCacheEntry(cacheEntry.files); | ||
| return true; | ||
| } | ||
| const cacheEntryFiles = this.createFileCacheEntry(filePath); | ||
| this.createFilesFromCacheEntry(cacheEntryFiles); | ||
| yield this.cache.set(filePath, sourceCodeHash, cacheEntryFiles); | ||
| return false; | ||
| }); | ||
| } | ||
| getCacheEntry(filePath, sourceCodeHash) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| return yield this.cache.get(filePath, sourceCodeHash); | ||
| }); | ||
| } | ||
| createFilesFromCacheEntry(cacheEntryFiles) { | ||
| cacheEntryFiles.forEach(({ filepath, content }) => { | ||
| (0, createFile_1.default)(filepath, content); | ||
| }); | ||
| } | ||
| createFileCacheEntry(filePath) { | ||
| const options = this.config.compilerOptions; | ||
| const transpiled = this.transpileModule(filePath); | ||
| const newFilePath = (0, getOutputFilename_1.getOutputFilename)(options.outDir || "dist", filePath); | ||
| const cacheEntryFiles = [ | ||
| { filepath: newFilePath, content: transpiled.outputText }, | ||
| ]; | ||
| if (options.declaration) { | ||
| this.program.emit(this.program.getSourceFile(filePath), (fileName, content) => cacheEntryFiles.push({ | ||
| filepath: fileName.replace(".js", ".d.ts"), | ||
| content, | ||
| })); | ||
| } | ||
| if (transpiled.sourceMapText) { | ||
| cacheEntryFiles.push({ | ||
| filepath: newFilePath + ".map", | ||
| content: transpiled.sourceMapText, | ||
| }); | ||
| } | ||
| return cacheEntryFiles; | ||
| } | ||
| getCacheSeed() { | ||
| return JSON.stringify(this.tsMetadata.cliOptions); | ||
| } | ||
| getSourceCodeHash(filePath) { | ||
| const code = this.getSourceCode(filePath); | ||
| return this.cache.hashEntry(code); | ||
| } | ||
| getSourceCode(filePath) { | ||
| return fs_1.default.readFileSync(filePath, "utf8"); | ||
| } | ||
| } | ||
| exports.ProgramATSC = ProgramATSC; | ||
| //# sourceMappingURL=atsc.js.map |
+4
-4
@@ -13,3 +13,3 @@ #!/usr/bin/env node | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const magic_1 = require("./magic"); | ||
| const atsc_1 = require("./atsc"); | ||
| const processExit_1 = require("./utils/processExit"); | ||
@@ -21,6 +21,6 @@ const argumentParser_1 = require("./utils/argumentParser"); | ||
| const argParser = new argumentParser_1.ArgumentParser(argv); | ||
| const magic = new magic_1.Magic(argParser); | ||
| const atsc = new atsc_1.ProgramATSC(argParser); | ||
| logger_1.logger.setVerbose(argParser.hasFlag("verbose")); | ||
| if (argParser.hasFlag("purge")) { | ||
| yield magic.purgeCache(); | ||
| yield atsc.purgeCache(); | ||
| return; | ||
@@ -35,3 +35,3 @@ } | ||
| try { | ||
| const { cacheFilesUsed, compiledFiles } = yield magic.compile(); | ||
| const { cacheFilesUsed, compiledFiles } = yield atsc.compile(); | ||
| logger_1.logger.info(`Done. ${cacheFilesUsed} files taken from cache, ${compiledFiles} files compiled.`); | ||
@@ -38,0 +38,0 @@ process.exit(processExit_1.ProcessExit.Success); |
+2
-2
| { | ||
| "name": "@ardentcode/tsc", | ||
| "version": "0.1.1", | ||
| "version": "0.2.1", | ||
| "description": "", | ||
| "main": "index.js", | ||
| "bin": { | ||
| "actsc": "dist/cli.js" | ||
| "atsc": "dist/cli.js" | ||
| }, | ||
@@ -9,0 +9,0 @@ "files": [ |
-147
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Magic = void 0; | ||
| const getConfig_1 = __importDefault(require("./utils/getConfig")); | ||
| const path_1 = require("path"); | ||
| const typescript_1 = __importDefault(require("typescript")); | ||
| const fs_1 = __importDefault(require("fs")); | ||
| const getOutputFilename_1 = require("./utils/getOutputFilename"); | ||
| const createFile_1 = __importDefault(require("./utils/createFile")); | ||
| const buildCache_1 = require("../../build-cache/dist/buildCache"); | ||
| const logger_1 = require("./logger/logger"); | ||
| class Magic { | ||
| constructor(argsParser) { | ||
| this.argsParser = argsParser; | ||
| this.config = (0, getConfig_1.default)(argsParser.options); | ||
| this.tsMetadata = this.getTSMetadata(); | ||
| this.cache = this.createCache(); | ||
| this.program = this.getTSProgram(); | ||
| } | ||
| compile() { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| yield this.cache.validateCache(this.tsMetadata); | ||
| let cacheFilesUsed = 0; | ||
| let compiledFiles = 0; | ||
| const fileNames = this.config.fileNames; | ||
| for (const filePath of fileNames) { | ||
| const takenFromCache = yield this.compileFile(filePath); | ||
| logger_1.logger.debug(`${filePath} ${takenFromCache ? "taken from cache" : "compiled"}.`); | ||
| takenFromCache ? cacheFilesUsed++ : compiledFiles++; | ||
| } | ||
| yield this.cache.saveMetadata(this.tsMetadata); | ||
| return { | ||
| cacheFilesUsed, | ||
| compiledFiles, | ||
| }; | ||
| }); | ||
| } | ||
| purgeCache() { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| yield this.cache.purge(); | ||
| logger_1.logger.info(`Cache purged`); | ||
| }); | ||
| } | ||
| createCache() { | ||
| const cacheSeed = this.getCacheSeed(); | ||
| logger_1.logger.debug(`Cache mounted on ${process.cwd()} with seed: ${cacheSeed}`); | ||
| return new buildCache_1.BuildCache(cacheSeed, process.cwd(), this.argsParser.hasFlag("verbose")); | ||
| } | ||
| getTSProgram() { | ||
| const cliFileNames = this.argsParser.fileNames; | ||
| const { fileNames, compilerOptions } = this.config; | ||
| const program = typescript_1.default.createProgram(cliFileNames.length === 0 ? fileNames : cliFileNames, Object.assign(Object.assign({}, compilerOptions), { emitDeclarationOnly: true })); | ||
| return program; | ||
| } | ||
| getTSMetadata() { | ||
| const { options } = this.argsParser; | ||
| const tsConfigOptions = this.config.tsConfigOptions; | ||
| return { | ||
| cliOptions: options, | ||
| tsVersion: typescript_1.default.version, | ||
| compilerOptions: tsConfigOptions, | ||
| }; | ||
| } | ||
| transpileModule(filePath) { | ||
| const code = this.getSourceCode(filePath); | ||
| const options = this.config.compilerOptions; | ||
| try { | ||
| return typescript_1.default.transpileModule(code, { | ||
| compilerOptions: options, | ||
| fileName: (0, path_1.basename)(filePath), | ||
| }); | ||
| } | ||
| catch (e) { | ||
| logger_1.logger.error(`Compilation failed for ${filePath}`); | ||
| throw e; | ||
| } | ||
| } | ||
| compileFile(filePath) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const sourceCodeHash = this.getSourceCodeHash(filePath); | ||
| const cacheEntry = yield this.getCacheEntry(filePath, sourceCodeHash); | ||
| if (cacheEntry) { | ||
| this.createFilesFromCacheEntry(cacheEntry.files); | ||
| return true; | ||
| } | ||
| const cacheEntryFiles = this.createFileCacheEntry(filePath); | ||
| this.createFilesFromCacheEntry(cacheEntryFiles); | ||
| yield this.cache.set(filePath, sourceCodeHash, cacheEntryFiles); | ||
| return false; | ||
| }); | ||
| } | ||
| getCacheEntry(filePath, sourceCodeHash) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| return yield this.cache.get(filePath, sourceCodeHash); | ||
| }); | ||
| } | ||
| createFilesFromCacheEntry(cacheEntryFiles) { | ||
| cacheEntryFiles.forEach(({ filepath, content }) => { | ||
| (0, createFile_1.default)(filepath, content); | ||
| }); | ||
| } | ||
| createFileCacheEntry(filePath) { | ||
| const options = this.config.compilerOptions; | ||
| const transpiled = this.transpileModule(filePath); | ||
| const newFilePath = (0, getOutputFilename_1.getOutputFilename)(options.outDir || "dist", filePath); | ||
| const cacheEntryFiles = [ | ||
| { filepath: newFilePath, content: transpiled.outputText }, | ||
| ]; | ||
| if (options.declaration) { | ||
| this.program.emit(this.program.getSourceFile(filePath), (fileName, content) => cacheEntryFiles.push({ | ||
| filepath: fileName.replace(".js", ".d.ts"), | ||
| content, | ||
| })); | ||
| } | ||
| if (transpiled.sourceMapText) { | ||
| cacheEntryFiles.push({ | ||
| filepath: newFilePath + ".map", | ||
| content: transpiled.sourceMapText, | ||
| }); | ||
| } | ||
| return cacheEntryFiles; | ||
| } | ||
| getCacheSeed() { | ||
| return JSON.stringify(this.tsMetadata.cliOptions); | ||
| } | ||
| getSourceCodeHash(filePath) { | ||
| const code = this.getSourceCode(filePath); | ||
| return this.cache.hashEntry(code); | ||
| } | ||
| getSourceCode(filePath) { | ||
| return fs_1.default.readFileSync(filePath, "utf8"); | ||
| } | ||
| } | ||
| exports.Magic = Magic; | ||
| //# sourceMappingURL=magic.js.map |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
14124
-1.97%2
100%