@yunho1017/ts-loader
Advanced tools
+1
-1
| { | ||
| "name": "@yunho1017/ts-loader", | ||
| "version": "0.1.0", | ||
| "version": "0.3.0", | ||
| "author": "Yunho Seo", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
+47
-6
| const ts = require("typescript"); | ||
| const fs = require("fs"); | ||
| const path = require("path"); | ||
| function findConfigFile(requestDirPath, configFile) { | ||
| if (path.isAbsolute(configFile)) { | ||
| return fs.existsSync(configFile) ? configFile : undefined; | ||
| } | ||
| if (/^\.\.?(\/|\\)/.test(configFile)) { | ||
| const resolvedPath = path.resolve(requestDirPath, configFile); | ||
| return fs.existsSync(resolvedPath) ? resolvedPath : undefined; | ||
| } | ||
| while (true) { | ||
| const fileName = path.join(requestDirPath, configFile); | ||
| if (fs.existsSync(fileName)) { | ||
| return fileName; | ||
| } | ||
| const parentPath = path.dirname(requestDirPath); | ||
| if (parentPath === requestDirPath) { | ||
| break; | ||
| } | ||
| requestDirPath = parentPath; | ||
| } | ||
| return undefined; | ||
| } | ||
| function readConfigFile(filePath) { | ||
| try { | ||
| const fileContent = fs.readFileSync(filePath, "utf-8"); | ||
| return JSON.parse(fileContent); | ||
| } catch (error) { | ||
| console.error(`Error reading config file at ${filePath}:`, error); | ||
| return undefined; | ||
| } | ||
| } | ||
| function getConfigFileOptions(requestDirPath, configFile) { | ||
| const configFilePath = findConfigFile(requestDirPath, configFile); | ||
| if (configFilePath) { | ||
| const configFileContent = readConfigFile(configFilePath); | ||
| return configFileContent ? configFileContent.compilerOptions : {}; | ||
| } | ||
| return {}; | ||
| } | ||
| exports.default = async function loader(content, emitError) { | ||
| try { | ||
| return ts.transpileModule(content, { | ||
| compilerOptions: { | ||
| target: ts.ScriptTarget.ES5, | ||
| module: ts.ModuleKind.CommonJS, | ||
| noImplicitUseStrict: true, | ||
| pretty: true, | ||
| }, | ||
| compilerOptions: getConfigFileOptions(process.cwd(), "tsconfig.json"), | ||
| }).outputText; | ||
@@ -13,0 +54,0 @@ } catch (err) { |
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
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
Unpopular package
QualityThis package is not very popular.
Found 1 instance in 1 package
2042
138.55%50
233.33%1
-50%1
Infinity%1
Infinity%