Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async collectDependencies() {
// Read deps file
let contents = await fs.readFile(this.depsPath, 'utf8');
let dir = path.dirname(this.name);
let deps = contents
.split('\n')
.filter(Boolean)
.slice(1);
for (let dep of deps) {
dep = path.resolve(dir, dep.slice(0, dep.indexOf(': ')));
if (dep !== this.name) {
this.addDependency(dep, {includedInParent: true});
}
}
}
async readPackage(dir) {
let file = path.join(dir, 'package.json');
if (this.packageCache.has(file)) {
return this.packageCache.get(file);
}
let json = await fs.readFile(file, 'utf8');
let pkg = JSON.parse(json);
pkg.pkgfile = file;
pkg.pkgdir = dir;
// If the package has a `source` field, check if it is behind a symlink.
// If so, we treat the module as source code rather than a pre-compiled module.
if (pkg.source) {
let realpath = await fs.realpath(file);
if (realpath === file) {
delete pkg.source;
}
}
this.packageCache.set(file, pkg);
return pkg;
.slice(3);
let dir = path.join(os.tmpdir(), id);
let filename = path.join(dir, id + '.js');
await fs.mkdirp(dir);
await kotlinCompiler.compile({
output: filename,
sources: [this.name],
moduleKind: 'commonjs',
noStdlib: false,
metaInfo: true,
sourceMaps: this.options.sourceMaps,
});
let source = await fs.readFile(filename, 'utf8');
let sourceMap;
if (this.options.sourceMaps) {
sourceMap = await fs.readFile(filename + '.map', 'utf8');
sourceMap = JSON.parse(sourceMap);
sourceMap.sources = [this.relativeName];
sourceMap.sourcesContent = [this.contents];
// remove source map url
source = source.substring(0, source.lastIndexOf('//# sourceMappingURL'));
}
// delete temp directory
await fs.rimraf(dir);
return [
async readPackage(dir) {
let file = path.join(dir, 'package.json');
if (this.packageCache.has(file)) {
return this.packageCache.get(file);
}
let json = await fs.readFile(file, 'utf8');
let pkg = JSON.parse(json);
pkg.pkgfile = file;
pkg.pkgdir = dir;
// If the package has a `source` field, check if it is behind a symlink.
// If so, we treat the module as source code rather than a pre-compiled module.
if (pkg.source) {
let realpath = await fs.realpath(file);
if (realpath === file) {
delete pkg.source;
}
}
this.packageCache.set(file, pkg);
return pkg;
async function getIgnoreConfig(asset) {
let ignoreFile = await asset.getConfig(['.babelignore'], {
load: false,
});
if (!ignoreFile) {
return null;
}
let data = await fs.readFile(ignoreFile, 'utf8');
let patterns = data
.split('\n')
.map(line => line.replace(/#.*$/, '').trim())
.filter(Boolean);
return {ignore: patterns};
}
async load() {
return fs.readFile(this.name, this.encoding);
}