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 loadAndValidateAssembly(jsiiFileName: string): Promise {
if (!ASSEMBLY_CACHE.has(jsiiFileName)) {
ASSEMBLY_CACHE.set(jsiiFileName, spec.validateAssembly(await fs.readJson(jsiiFileName)));
}
return ASSEMBLY_CACHE.get(jsiiFileName)!;
}
async function loadPackageNameFromAssembly(options: LoadOptions): Promise {
const JSII_ASSEMBLY_FILE = '.jsii';
if (!await fs.pathExists(JSII_ASSEMBLY_FILE)) {
throw new Error(`No NPM package name given and no ${JSII_ASSEMBLY_FILE} file in the current directory. Please specify a package name.`);
}
const contents = await fs.readJSON(JSII_ASSEMBLY_FILE, { encoding: 'utf-8' });
const module = options.validate ? spec.validateAssembly(contents) : contents as spec.Assembly;
if (!module.name) { throw new Error(`Could not find package in ${JSII_ASSEMBLY_FILE}`); }
return module.name;
}
async function loadAssemblyFromFile(filename: string) {
const contents = await fs.readJSON(filename, { encoding: 'utf-8' });
return spec.validateAssembly(contents);
}
private async loadAssembly(file: string, validate = true) {
const spec = JSON.parse((await readFile(file)).toString());
const ass = validate ? jsii.validateAssembly(spec) : spec as jsii.Assembly;
return new Assembly(this, ass);
}