Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function buildJsonNode(p: PortablePath, accesses: Array) {
const content = await xfs.readFilePromise(p, `utf8`);
// Just to be sure that it's valid JSON
JSON.parse(content);
const sourceFile = await ts.createSourceFile(
npath.fromPortablePath(p),
`(${content})`,
ts.ScriptTarget.ES2015,
/*setParentNodes */ true,
);
// @ts-ignore
let node: ts.Node = sourceFile.statements[0].expression;
if (!node)
throw new Error(`Invalid source tree`);
const cb = (error: any) => {
if (error) {
rejectFn(error);
} else {
resolveFn();
}
};
if (stat.isFile()) {
let content: Buffer;
// The root package.json supports replacement fields in publishConfig
if (file === `package.json`)
content = Buffer.from(JSON.stringify(await genPackageManifest(workspace), null, 2));
else
content = await xfs.readFilePromise(source);
pack.entry({...opts, type: `file`}, content, cb);
} else if (stat.isSymbolicLink()) {
pack.entry({...opts, type: `symlink`, linkname: await xfs.readlinkPromise(source)}, cb);
}
await awaitTarget;
}
pack.finalize();
});
private async setupResolutions() {
this.storedResolutions = new Map();
this.storedDescriptors = new Map();
this.storedPackages = new Map();
const lockfilePath = ppath.join(this.cwd, this.configuration.get(`lockfileFilename`));
const defaultLanguageName = this.configuration.get(`defaultLanguageName`);
if (xfs.existsSync(lockfilePath)) {
const content = await xfs.readFilePromise(lockfilePath, `utf8`);
const parsed: any = parseSyml(content);
// Protects against v1 lockfiles
if (parsed.__metadata) {
const lockfileVersion = parsed.__metadata.version;
for (const key of Object.keys(parsed)) {
if (key === `__metadata`)
continue;
const data = parsed[key];
const locator = structUtils.parseLocator(data.resolution, true);
const manifest = new Manifest();
manifest.load(data);
export async function makeUpdater(filename: PortablePath) {
let indent = ` `;
let obj;
if (xfs.existsSync(filename)) {
const content = await xfs.readFilePromise(filename, `utf8`);
const indentMatch = content.match(/^[ \t]+/m);
if (indentMatch)
indent = indentMatch[0];
obj = JSON.parse(content || `{}`);
}
if (!obj)
obj = {};
const tracker = makeTracker(obj);
const initial = tracker.immutable;
return {
open(cb: (value: Object) => void) {
static async findRcFiles(startingCwd: PortablePath) {
const rcFilename = getRcFilename();
const rcFiles = [];
let nextCwd = startingCwd;
let currentCwd = null;
while (nextCwd !== currentCwd) {
currentCwd = nextCwd;
const rcPath = ppath.join(currentCwd, rcFilename as PortablePath);
if (xfs.existsSync(rcPath)) {
const content = await xfs.readFilePromise(rcPath, `utf8`);
let data;
try {
data = parseSyml(content) as any;
} catch (error) {
let tip = ``;
if (content.match(/^\s+(?!-)[^:]+\s+\S+/m))
tip = ` (in particular, make sure you list the colons after each key name)`;
throw new UsageError(`Parse error when loading ${rcPath}; please check it's proper Yaml${tip}`);
}
rcFiles.push({path: rcPath, cwd: currentCwd, data});
}
async cloneFromRemote(locator: Locator, opts: FetchOptions) {
const cloneTarget = await gitUtils.clone(locator.reference, opts.project.configuration);
const packagePath = ppath.join(cloneTarget, `package.tgz` as PortablePath);
await scriptUtils.prepareExternalProject(cloneTarget, packagePath, {
configuration: opts.project.configuration,
report: opts.report,
});
const sourceBuffer = await xfs.readFilePromise(packagePath);
return await miscUtils.releaseAfterUseAsync(async () => {
return await tgzUtils.convertToZip(sourceBuffer, {
stripComponents: 1,
prefixPath: structUtils.getIdentVendorPath(locator),
});
});
}
}
async function parseFile(p: PortablePath) {
const content = await xfs.readFilePromise(p, `utf8`);
if (probablyMinified(content))
return null;
return await ts.createSourceFile(
npath.fromPortablePath(p),
content,
ts.ScriptTarget.ES2015,
/*setParentNodes */ true,
);
}
onAbsolute: async () => {
return await xfs.readFilePromise(patchPath, `utf8`);
},