Comparing version 1.5.1 to 1.6.0
# Changelog | ||
## 1.6.0 | ||
- feat: parallel jetifier - speedup x cpu count, @m4tt72 making your installs fast :muscle: | ||
- test: exercise macOS in CI alongside linux | ||
## 1.5.1 | ||
@@ -4,0 +9,0 @@ |
26
index.js
@@ -1,21 +0,19 @@ | ||
const { readFileSync, writeFileSync } = require('fs'); | ||
const { loadCSV, readDir } = require('./src/utils'); | ||
const { fork } = require('child_process'); | ||
const { join } = require('path'); | ||
const { getClassesMapping, readDir, chunk } = require('./src/utils'); | ||
const cpus = require('os').cpus().length; | ||
const arg = process.argv.slice(2)[0]; | ||
const mode = arg && ((arg === 'reverse') || (arg === '-r')) ? 'reverse' : 'forward'; | ||
const SEARCH_DIR = 'node_modules'; | ||
const csv = loadCSV(); | ||
const classesMapping = getClassesMapping(); | ||
const files = readDir(SEARCH_DIR); | ||
for (const file of files) { | ||
let data = readFileSync(file, { encoding: 'utf8' }); | ||
for (const c in csv) { | ||
if (data.includes(mode === 'forward' ? c : csv[c])) { | ||
console.log(`${mode}-jetifying: ${file}`); | ||
data = mode === 'forward' ? data.replace(new RegExp(c, 'g'), csv[c]) : data.replace(new RegExp(csv[c], 'g'), c); | ||
writeFileSync(file, data, { encoding: 'utf8' }); | ||
} | ||
} | ||
} | ||
console.log(`Jetifier found ${files.length} file(s) to ${mode}-jetify. Using ${cpus} workers...`); | ||
for (const filesChunk of chunk(files, cpus)) { | ||
const worker = fork(join(__dirname, 'src', 'worker.js')); | ||
worker.send({ filesChunk, classesMapping, mode }); | ||
} |
{ | ||
"name": "jetifier", | ||
"version": "1.5.1", | ||
"version": "1.6.0", | ||
"description": "jetifier from Android Studio, in npm package format", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
const { readFileSync, readdirSync, statSync } = require('fs'); | ||
const { join } = require('path'); | ||
const chunk = (array, chunkSize) => { | ||
const size = Math.ceil(array.length / chunkSize); | ||
const result = []; | ||
while (array.length) { | ||
result.push(array.splice(0, size)); | ||
} | ||
return result; | ||
}; | ||
const readDir = (dir, filesList = []) => { | ||
@@ -19,27 +28,36 @@ const files = readdirSync(dir); | ||
const loadCSV = () => { | ||
const csvFilePath = join(__dirname, 'androidx-class-mapping.csv'); | ||
const loadCSVFile = () => { | ||
const csvFilePath = join(__dirname, '..', 'mapping', 'androidx-class-mapping.csv'); | ||
const lines = readFileSync(csvFilePath, { encoding: 'utf8' }).split(/\r?\n/); | ||
// Remove redundant "Support Library class,Android X class" from array | ||
lines.shift(); | ||
// last element will always be an empty line so removing it from the array | ||
if(lines[lines.length - 1] === "") { | ||
lines.pop(); | ||
if (lines[lines.length - 1] === "") { | ||
lines.pop(); | ||
} | ||
const result = {}; | ||
for (let line of lines) { | ||
return lines; | ||
}; | ||
const getClassesMapping = () => { | ||
const csv = loadCSVFile(); | ||
const result = []; | ||
for (let line of csv) { | ||
const oldValue = line.split(',')[0]; | ||
const newValue = line.split(',')[1]; | ||
result[oldValue] = newValue; | ||
result.push([oldValue, newValue]); | ||
} | ||
// renderscript must be added to the canonical androidx-class-mapping.csv - it is not upstream | ||
result['android.support.v8.renderscript'] = 'android.renderscript'; | ||
result.push(['android.support.v8.renderscript', 'android.renderscript']); | ||
return result; | ||
} | ||
}; | ||
module.exports = { | ||
loadCSV, | ||
readDir | ||
} | ||
getClassesMapping, | ||
readDir, | ||
chunk | ||
}; |
Sorry, the diff of this file is not supported yet
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
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
2738586
27
81
1