How to use the typescript.ModuleKind function in typescript

To help you get started, we’ve selected a few typescript examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github frankwallis / plugin-typescript / src / resolve-options.ts View on Github external
function validateOptions(options: CombinedOptions) {
   /* The only time you don't want to output in 'm format is when you are using rollup or babel
      downstream to compile es6 output (e.g. for async/await support) */
	if ((options.module !== ts.ModuleKind.System) && (options.module !== ts.ModuleKind.ES2015) && (options.module !== ts.ModuleKind.ESNext)) {
		logger.warn(`transpiling to ${ts.ModuleKind[options.module]}, consider setting module: "system" in typescriptOptions to transpile directly to System.register format`)
	}

	if (options['supportHtmlImports']) {
		logger.warn("The 'supportHtmlImports' option is no longer supported")
	}

	if (options['resolveAmbientRefs']) {
		logger.warn("The 'resolveAmbientRefs' option is no longer supported")
	}

	if (options['targetLib']) {
		logger.warn("The 'targetLib' option is no longer supported")
	}

	if (options['typeCheck']) {
github meteor / babel / index.js View on Github external
function precompileTypeScript(result, options) {
  const fileName = options.filename || options.sourceFileName;
  if (fileName && ! fileName.endsWith(".ts") && ! fileName.endsWith(".tsx")) {
    return;
  }

  const ts = require("typescript");
  let tsResult;
  try {
    tsResult = ts.transpileModule(result.code, {
      fileName,
      compilerOptions: {
        target: ts.ScriptTarget.ESNext,
        // Leave module syntax intact so that Babel/Reify can handle it.
        module: ts.ModuleKind.ESNext,
        // This used to be false by default, but appears to have become
        // true by default around the release of typescript@3.7. It's
        // important to disable this option because enabling it allows
        // TypeScript to use helpers like __importDefault, which are much
        // better handled by Babel/Reify later in the pipeline.
        esModuleInterop: false,
        sourceMap: true,
        inlineSources: true,
      }
    });
  } catch (e) {
    e.message = "While compiling " + fileName + ": " + e.message;
    throw e;
  }

  result.code = tsResult.outputText.replace(
github BenjaminDobler / ngtron / builders / build / index.ts View on Github external
serverOptions = await context.getTargetOptions(browserTarget);
    const buildOptions = await context.getTargetOptions({
      project: context.target.project,
      configuration: context.target.configuration,
      target: "build"
    });
    buildOptions.browserTarget = context.target.project + ":build";
    buildOptions.port = options.port ? options.port : 4200;
    buildOptions.watch = true;
    buildOptions.baseHref = "./";

    compile([options.electronMain as string], {
      noEmitOnError: true,
      noImplicitAny: true,
      target: ts.ScriptTarget.ES2015,
      module: ts.ModuleKind.CommonJS,
      outDir: buildOptions.outputPath as string
    });

    const outputPath = buildOptions.outputPath as string;


    const electronBuildTarget = targetFromTargetString(context.target.project + ":package-electron");
    buildElectronOptions = await context.getTargetOptions(electronBuildTarget);

    const fromMain = join(context.workspaceRoot, options.electronMain as string);
    const toMain = join(outputPath, basename(options.electronMain as string));
    copyFileSync(fromMain, toMain);

    // write electron package to dist
    writeFileSync(join(outputPath, "package.json"), JSON.stringify(buildElectronOptions.electronPackage), {encoding: "utf-8"});
github frankwallis / plugin-typescript / test / resolve-options-spec.ts View on Github external
? Promise.resolve(JSON.stringify({
							compilerOptions: {
								downlevelIteration: true
							}
						}))
						: Promise.resolve(JSON.stringify({
							extends: 'tsconfig.extended.json',
							compilerOptions: {
								module: 'esnext'
							}
						}))

			const finalOptions = await resolveOptions(undefined, fileConfig, 'file1.ts', fetchJson)
			finalOptions.downlevelIteration.should.be.true
			finalOptions.target.should.equal(ts.ScriptTarget.ES2017)
			finalOptions.module.should.equal(ts.ModuleKind.ESNext)
		})
github seagull-js / seagull / src / tools / util / transpile.ts View on Github external
export function translateCode(sourceText: string, opts?: any): string {
  const module = ts.ModuleKind.CommonJS
  const target = ts.ScriptTarget.ES2015
  const compilerOptions = opts || { module, target }
  compilerOptions.jsx = ts.JsxEmit.React
  const { outputText } = ts.transpileModule(sourceText, { compilerOptions })
  return outputText
}
github xinglie / magix-table / gulpfile.js View on Github external
compileJSStart(content) {
        var str = ts.transpileModule(content, {
            compilerOptions: {
                lib: ['es7'],
                target: 'es6',
                module: ts.ModuleKind.None
            }
        });
        str = str.outputText;
        return str;
    }
});
github Bearer / bearer-js / packages / openapi-generator / src / index.ts View on Github external
export function functionTypesToSchemaConverter(
  functionPath: string,
  options: ts.CompilerOptions = { target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS }
): TOutput {
  const program = ts.createProgram([functionPath], options)
  const sourceFile = program.getSourceFile(functionPath)
  const checker = program.getTypeChecker()

  const output: TOutput = {
    requestBody: {},
    response: {}
  }

  if (sourceFile) {
    ts.forEachChild(sourceFile, visit)
  }

  return output
github neo-one-suite / neo-one / packages / neo-one-editor / src / monaco / language.ts View on Github external
skipLibCheck: true,
        noUnusedLocals: true,
        noImplicitReturns: true,
        allowUnusedLabels: false,
        noUnusedParameters: false,
        allowUnreachableCode: false,
        noFallthroughCasesInSwitch: true,
        forceConsistentCasingInFileNames: true,
      },
      false,
      (file) => getFileType(file) === 'typescript',
    ),
    createMonacoWorkerManager(
      {
        target: ts.ScriptTarget.ESNext,
        module: ts.ModuleKind.ESNext,
        moduleResolution: ts.ModuleResolutionKind.NodeJs,

        noLib: true,
        typeRoots: [],

        pretty: true,

        noEmit: true,
        declaration: false,

        allowSyntheticDefaultImports: true,
        resolveJsonModule: false,
        experimentalDecorators: true,

        alwaysStrict: true,
        strict: true,
github k-maru / grunt-typescript / src / modules / compiler.ts View on Github external
let config = {
		compilerOptions: {
			removeComments: tsOpts.removeComments,
            sourceMap: tsOpts.sourceMap,
            declaration: tsOpts.declaration,
            out: tsOpts.out,
            outDir: tsOpts.outDir,
            noLib: tsOpts.noLib,
            noImplicitAny: tsOpts.noImplicitAny,
            noResolve: tsOpts.noResolve,
            target: tsOpts.target === ts.ScriptTarget.ES3 ? "ES3" :
					tsOpts.target === ts.ScriptTarget.ES5 ? "ES5" :
					tsOpts.target === ts.ScriptTarget.ES6 ? "ES6" : undefined,
            rootDir: tsOpts.rootDir,
            module: tsOpts.module === ts.ModuleKind.AMD ? "amd" :
					tsOpts.module === ts.ModuleKind.CommonJS ? "commonjs" : undefined ,
            preserveConstEnums: tsOpts.preserveConstEnums,
            noEmitOnError: tsOpts.noEmitOnError,
            suppressImplicitAnyIndexErrors: tsOpts.suppressImplicitAnyIndexErrors,
            emitDecoratorMetadata: tsOpts.emitDecoratorMetadata
		},
		files: targetFiles.map(targetFile => util.normalizePath(util.relativePath(outputDir, targetFile)))
	};
	
	util.createDirectoryRecurse(outputDir);
	util.writeFile(outputFile, JSON.stringify(config, null, "    "));
	
	util.writeInfo(`tsconfig.json generated: ${outputFile}`);
}