Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// If it's not archive prefixed, strip a single parent directory...
if (/^\.\.\//.test(relFile)) {
relFile = relFile.substr(3);
}
// If it's still got a parent directory, or starts with /, it's not in our archive...
if (!/^\.\.\/|^\//.test(relFile)) {
let f;
try {
const node = _archFs.searchNodeFromDirectory(relFile);
if (node && node.size) {
let encoding;
if (options && typeof options === 'string') {
encoding = options;
}
f = asar.extractFile(_archFs.src, relFile);
if (encoding) { f = f.toString(encoding); }
}
}
catch (err) {}
return f;
}
return undefined;
}
it('should have deleted the forge config from the packaged app', async () => {
const cleanPackageJSON = JSON.parse(asar.extractFile(
path.resolve(dir, 'out', `Test App-${process.platform}-${process.arch}`, resourcesPath, 'app.asar'),
'package.json'
));
expect(cleanPackageJSON).to.not.have.nested.property('config.forge');
});
extractFileToReadStream (archive: string, fileName: string): Readable {
const extractedFile = asar.extractFile(archive, fileName);
return toReadableStream(extractedFile);
}
for (const file of archived_files) {
if(file.startsWith(`${path.sep}node_modules`)) continue;
const f = file.startsWith(path.sep) ? file.substr(1) : file;
switch (extension(f)) {
case 'json':
if (f.toLowerCase().indexOf('package.json') < 0)
continue;
case 'js':
case 'jsx':
case 'ts':
case 'tsx':
case 'htm':
case 'html':
logger.debug(`Extracting file: ${f}`);
const buffer = asar.extractFile(archive, f);
this.load_buffer(buffer, f);
break;
default:
break;
}
}
logger.debug(`Loaded ${this.loaded.size} files`);
return this.loaded;
}
}
loadingGif = loadingGif ? path.resolve(loadingGif) : defaultLoadingGif;
let { certificateFile, certificatePassword, remoteReleases, signWithParams, remoteToken } = options;
const metadata: Metadata = {
description: '',
iconUrl: 'https://raw.githubusercontent.com/atom/electron/master/atom/browser/resources/win/atom.ico'
};
if (options.usePackageJson !== false) {
const appResources = path.join(appDirectory, 'resources');
const asarFile = path.join(appResources, 'app.asar');
let appMetadata;
if (await fs.pathExists(asarFile)) {
appMetadata = JSON.parse(asar.extractFile(asarFile, 'package.json'));
} else {
appMetadata = await fs.readJson(path.join(appResources, 'app', 'package.json'));
}
Object.assign(metadata, {
exe: `${appMetadata.name}.exe`,
title: appMetadata.productName || appMetadata.name
}, appMetadata);
}
Object.assign(metadata, options);
if (!metadata.authors) {
if (typeof (metadata.author) === 'string') {
metadata.authors = metadata.author;
} else {
function readPackage(pkgFile) {
if (Object.prototype.hasOwnProperty.call(packageMainCache, pkgFile)) {
return packageMainCache[pkgFile];
}
const jsonPath = pkgFile;
const json = asar.extractFile(_archFs.src, pkgFile);
if (json === undefined) {
return false;
}
let pkg;
try {
packageMainCache[pkgFile] = JSON.parse(json).main;
pkg = packageMainCache[pkgFile];
}
catch (err) {
err.path = jsonPath;
err.message = `Error parsing ${jsonPath}: ${err.message}`;
throw err;
}
return pkg;