Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
});
});
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;
}
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]`));
}
const babelTransform = (format, file) => {
if (format === SRC_MODULES) {
// no transform, just return source
return fs.readFileSync(file)
}
const { code } = babel.transformFileSync(file, {})
return code
}
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.');
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));
};
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');
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));
}
}
}
}
function babelBuild(srcPath, envName) {
return babel.transformFileSync(srcPath, { envName }).code + '\n';
}
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,