esbuild-plugin-tsc
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "esbuild-plugin-tsc", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "An esbuild plugin which uses tsc to compile typescript files.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
const fs = require('fs').promises; | ||
const path = require('path'); | ||
const typescript = require('typescript'); | ||
@@ -36,36 +37,36 @@ const stripComments = require('strip-comments'); | ||
module.exports = ( | ||
options = { tsconfigPath: './tsconfig.json', force: false, tsx: true } | ||
) => ({ | ||
module.exports = (options = {}) => ({ | ||
name: 'tsc', | ||
setup(build) { | ||
const tsconfigPath = | ||
options.tsconfigPath ?? path.join(process.cwd(), './tsconfig.json'); | ||
const forceTsc = options.force ?? false; | ||
const tsx = options.tsx ?? true; | ||
let tsconfigRaw = null; | ||
build.onLoad( | ||
{ filter: options.tsx ? /\.tsx?$/ : /\.ts$/ }, | ||
async (args) => { | ||
if (!tsconfigRaw) { | ||
tsconfigRaw = JSON.parse( | ||
stripComments(await fs.readFile(tsconfigPath, 'utf8')) || null | ||
); | ||
if (tsconfigRaw.sourcemap) { | ||
tsconfigRaw.sourcemap = false; | ||
tsconfigRaw.inlineSources = true; | ||
tsconfigRaw.inlineSourceMap = true; | ||
} | ||
build.onLoad({ filter: tsx ? /\.tsx?$/ : /\.ts$/ }, async (args) => { | ||
if (!tsconfigRaw) { | ||
tsconfigRaw = JSON.parse( | ||
stripComments(await fs.readFile(tsconfigPath, 'utf8')) || null | ||
); | ||
if (tsconfigRaw.sourcemap) { | ||
tsconfigRaw.sourcemap = false; | ||
tsconfigRaw.inlineSources = true; | ||
tsconfigRaw.inlineSourceMap = true; | ||
} | ||
} | ||
const ts = await fs.readFile(args.path, 'utf8'); | ||
if ( | ||
options.force || | ||
(tsconfigRaw.compilerOptions && | ||
tsconfigRaw.compilerOptions.emitDecoratorMetadata && | ||
hasDecorator(ts)) | ||
) { | ||
const program = typescript.transpileModule(ts, tsconfigRaw); | ||
return { contents: program.outputText }; | ||
} | ||
const ts = await fs.readFile(args.path, 'utf8'); | ||
if ( | ||
forceTsc || | ||
(tsconfigRaw.compilerOptions && | ||
tsconfigRaw.compilerOptions.emitDecoratorMetadata && | ||
hasDecorator(ts)) | ||
) { | ||
const program = typescript.transpileModule(ts, tsconfigRaw); | ||
return { contents: program.outputText }; | ||
} | ||
); | ||
}); | ||
}, | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5015