How to use the @babel/core.transformFileSync function in @babel/core

To help you get started, we’ve selected a few @babel/core 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 ttag-org / babel-plugin-ttag / tests / functional / test_sorted_entries_without_reference_line_num.js View on Github external
it('should sort message identifiers and file location comments', () => {
        const inputFile = 'tests/fixtures/sort_by_msgid_input.js';
        const inputFile2 = 'tests/fixtures/sort_by_msgid_input2.js';
        const expectedPath = 'tests/fixtures/expected_sort_by_msgid_withou_reference_line_num.pot';
        // here we use reverse order of files, expected that references will be sorted
        babel.transformFileSync(path.join(process.cwd(), inputFile2), options);
        babel.transformFileSync(path.join(process.cwd(), inputFile), options);
        const result = fs.readFileSync(output).toString();
        const expected = fs.readFileSync(expectedPath).toString();
        expect(result).to.eql(expected);
    });
});
github grubersjoe / reflow / src / cli / runner.ts View on Github external
inputFiles.forEach(inputFile => {
      // Skip all invalid sources (files that match the include glob pattern, but are not JS)
      if (!isValidSource(inputFile)) {
        return;
      }

      console.log(`Transpiling ${inputFile}...`);

      try {
        const out = transformFileSync(inputFile, babelOptions);

        if (out === null || !out.code) {
          logError(`Unable to transpile ${inputFile}`, 4);
        } else {
          const outputFile = process.env.DEBUG
            ? inputFile
            : inputFile.replace(extname(inputFile), FileTypes.get(inputFile) || '.ts');

          const originalCode = String(readFileSync(inputFile));
          const output = formatOutputCode(out.code, originalCode, pluginOptions);

          if (output instanceof Error) {
            logError(`${inputFile} could not be formatted. Skipping.`, 4);
            logError(output.message, 4);
            return;
          }
github Zerthox / BetterDiscord-Plugins / scripts / build.js View on Github external
function compile() {
		try {
			const time = process.hrtime();

			// load plugin config
			const info = JSON.parse(fs.readFileSync(cfg, "utf8"));

			// generate source link
			info.source = "https://github.com/Zerthox/BetterDiscord-Plugins";

			// transform file
			const transformed = babel.transformFileSync(
				file, 
				{
					plugins: [
						["./lib/sass-importer", {
							plugin: info
						}]
					]
				}
			).code;

			// write to output file
			fs.writeFileSync(out, generateMeta(info) + generatePlugin(info, transformed));

			// console output
			console.log(chalk.green(`Compiled "${info.name}.plugin.js" to the BetterDiscord plugins folder [${Math.round(process.hrtime(time)[1] / 1000000)}ms]`));
		}
github Nozbe / WatermelonDB / scripts / make.js View on Github external
const babelTransform = (format, file) => {
  if (format === SRC_MODULES) {
    // no transform, just return source
    return fs.readFileSync(file)
  }

  const { code } = babel.transformFileSync(file, {})
  return code
}
github apache / incubator-echarts / test / build / test-transform.js View on Github external
suite.eachSrcFile(({fileName, filePath}) => {
        let result = babel.transformFileSync(filePath, {
            plugins: [removeDEVPlugin]
        });

        suite.writeToExpectFile(fileName, result.code);

        console.log(`removing dev ${fileName} ...`);
    });
    console.log('All done.');
github asapach / babel-plugin-rewire-exports / test / issues.js View on Github external
const assertIssue = (id, options) => {
    const actual = transformFileSync(`./test/issues/${id}/input.js`, options).code;
    const expected = fs.readFileSync(`./test/issues/${id}/output.js`).toString();

    assert.strictEqual(trim(actual), trim(expected));
  };
github ampproject / amphtml / build-system / tasks / helpers.js View on Github external
files.forEach(file => {
    if (file.startsWith('node_modules/') || file.startsWith('third_party/')) {
      fs.copySync(file, `${SRC_TEMP_DIR}/${file}`);
      return;
    }

    const {code} = babel.transformFileSync(file, {
      plugins: conf.plugins({
        isEsmBuild: options.isEsmBuild,
        isSinglePass: options.isSinglePass,
        isForTesting: options.isForTesting,
        isChecktypes: options.isChecktypes,
      }),
      retainLines: true,
      compact: false,
    });
    const name = `${SRC_TEMP_DIR}/${file}`;
    fs.outputFileSync(name, code);
    process.stdout.write('.');
  });
  console.log('\n');
github ismail-codar / fidan / packages / deprecated-babel-plugin-transform-jsx / src / export-registry.ts View on Github external
const getExportPaths = (fileName: string): t.BaseNode[] => {
	const localExports = [];
	if (fs.existsSync(fileName)) {
		babel.transformFileSync(
			fileName,
			buildBabelConfig(() => {
				return {
					visitor: {
						ExportNamedDeclaration(p) {
							localExports.push.apply(localExports, getDeclationsFromNamedExport(p.node));
						},
						Identifier(path: NodePath, file) {
							const parentNode = path.parent;
							if (path.node.name === 'exports') {
								if (t.isMemberExpression(path.parent)) {
									localExports.push.apply(localExports, getDeclationsFromExports(path));
								}
							}
						}
					}
github graphql / graphql-js / resources / build.js View on Github external
function babelBuild(srcPath, envName) {
  return babel.transformFileSync(srcPath, { envName }).code + '\n';
}
github ampproject / amphtml / build-system / compile / single-pass.js View on Github external
targets.forEach(path => {
      const map = loadSourceMap(path);
      function returnMapFirst(map) {
        let first = true;
        return function(file) {
          if (first) {
            first = false;
            return map;
          }
          return loadSourceMap(file);
        };
      }
      const {code, map: babelMap} = babel.transformFileSync(path, {
        plugins: conf.eliminateIntermediateBundles(),
        retainLines: true,
        sourceMaps: true,
        inputSourceMap: false,
      });
      let remapped = resorcery(
        babelMap,
        returnMapFirst(map),
        !argv.full_sourcemaps
      );

      const {code: compressed, map: terserMap} = terser.minify(code, {
        mangle: false,
        compress: {
          defaults: false,
          unused: true,