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 loadModule(dir: string) {
const ts = new reflect.TypeSystem();
await ts.load(dir, { validate: false }); // Don't validate to save 66% of execution time (20s vs 1min).
// We run 'awslint' during build time, assemblies are guaranteed to be ok.
if (ts.roots.length !== 1) {
throw new Error(`Expecting only a single root assembly`);
}
return ts.roots[0];
}
async function loadFromFilesystem(name: string, options: LoadOptions) {
const stat = await fs.stat(name);
const ts = new reflect.TypeSystem();
if (stat.isDirectory()) {
return ts.loadModule(name, options);
}
return ts.loadFile(name, options);
}
import { Scratch, shell } from './util';
import * as logging from '../lib/logging';
import * as reflect from 'jsii-reflect';
import * as os from 'os';
import * as path from 'path';
const SHARED_TS = new reflect.TypeSystem();
export interface JsiiModuleOptions {
/**
* Name of the module
*/
name: string;
/**
* The module directory
*/
moduleDirectory: string;
/**
* Identifier of the targets to build
*/
availableTargets: string[];
export async function loadTypeSystem(validate = true) {
const typeSystem = new jsiiReflect.TypeSystem();
const packageJson = require('../package.json');
for (const depName of Object.keys(packageJson.dependencies || {})) {
const jsiiModuleDir = path.dirname(require.resolve(`${depName}/package.json`));
if (!fs.existsSync(path.resolve(jsiiModuleDir, '.jsii'))) {
continue;
}
await typeSystem.load(jsiiModuleDir, { validate });
}
return typeSystem;
}