Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function getRoots(
context: BuilderContext
): Promise<{ workspaceRoot: Path; projectRoot: Path }> {
const host = new NodeJsSyncHost();
const registry = new schema.CoreSchemaRegistry();
registry.addPostTransform(schema.transforms.addUndefinedDefaults);
const workspace = await experimental.workspace.Workspace.fromPath(
host,
normalize(context.workspaceRoot),
registry
);
const projectName = context.target ? context.target.project : workspace.getDefaultProjectName();
if (!projectName) {
throw new Error('Must either have a target from the context or a default project.');
}
// const projectRoot = resolve(
// workspace.root,
// normalize(workspace.getProject(projectName).root),
// );
protected async createWorkflow(options: BaseSchematicSchema): Promise {
if (this._workflow) {
return this._workflow;
}
const { force, dryRun } = options;
const fsHost = new virtualFs.ScopedHost(new NodeJsSyncHost(), normalize(this.workspace.root));
const workflow = new NodeWorkflow(fsHost, {
force,
dryRun,
packageManager: await getPackageManager(this.workspace.root),
root: normalize(this.workspace.root),
registry: new schema.CoreSchemaRegistry(formats.standardFormats),
resolvePaths: !!this.workspace.configFile
// Workspace
? [process.cwd(), this.workspace.root]
// Global
: [__dirname, process.cwd()],
});
workflow.engineHost.registerContextTransform(context => {
// This is run by ALL schematics, so if someone uses `externalSchematics(...)` which
// is safelisted, it would move to the right analytics (even if their own isn't).
const collectionName: string = context.schematic.collection.description.name;
if (isPackageNameSafeForAnalytics(collectionName)) {
return {
...context,
analytics: this.analytics,
};
} else {
export async function getTestArchitect() {
const tmpDir = getTempDir();
const architectHost = new TestingArchitectHost(tmpDir, tmpDir);
const registry = new schema.CoreSchemaRegistry();
registry.addPostTransform(schema.transforms.addUndefinedDefaults);
const architect = new Architect(architectHost, registry);
await architectHost.addBuilderFromPackage(join(__dirname, '../..'));
return [architect, architectHost] as [Architect, TestingArchitectHost];
}
constructor(private _collectionName: string, collectionPath: string) {
this._engineHost.registerCollection(_collectionName, collectionPath);
this._logger = new logging.Logger('test');
const registry = new schema.CoreSchemaRegistry(formats.standardFormats);
registry.addPostTransform(schema.transforms.addUndefinedDefaults);
this._engineHost.registerOptionsTransform(validateOptionsWithSchema(registry));
this._engineHost.registerTaskExecutor(BuiltinTaskExecutor.NodePackage);
this._engineHost.registerTaskExecutor(BuiltinTaskExecutor.RepositoryInitializer);
this._engineHost.registerTaskExecutor(BuiltinTaskExecutor.RunSchematic);
this._engineHost.registerTaskExecutor(BuiltinTaskExecutor.TslintFix);
this._collection = this._engine.createCollection(this._collectionName);
}
export async function getTestArchitect() {
const architectHost = new TestingArchitectHost('/root', '/root');
const registry = new schema.CoreSchemaRegistry();
registry.addPostTransform(schema.transforms.addUndefinedDefaults);
const architect = new Architect(architectHost, registry);
await architectHost.addBuilderFromPackage(join(__dirname, '../..'));
return [architect, architectHost] as [Architect, TestingArchitectHost];
}
constructor(options: BaseWorkflowOptions) {
this._host = options.host;
this._engineHost = options.engineHost;
if (options.registry) {
this._registry = options.registry;
} else {
this._registry = new schema.CoreSchemaRegistry(standardFormats);
this._registry.addPostTransform(schema.transforms.addUndefinedDefaults);
}
this._engine = new SchematicEngine(this._engineHost, this);
this._context = [];
this._force = options.force || false;
this._dryRun = options.dryRun || false;
}
export function formatValidator(
data: JsonValue,
dataSchema: JsonObject,
formats: schema.SchemaFormat[],
): Observable {
const registry = new schema.CoreSchemaRegistry();
for (const format of formats) {
registry.addFormat(format);
}
return registry
.compile(dataSchema)
.pipe(mergeMap(validator => validator(data)));
}
function createWorkflow(dryRun: boolean) {
const root = normalize(rootDirectory);
const host = new virtualFs.ScopedHost(new NodeJsSyncHost(), root);
return new NodeWorkflow(host, {
packageManager: detectPackageManager(),
root,
dryRun,
registry: new schema.CoreSchemaRegistry(formats.standardFormats)
});
}
beforeEach(async () => {
const registry = new schema.CoreSchemaRegistry();
registry.addPostTransform(schema.transforms.addUndefinedDefaults);
const testArchitectHost = new TestingArchitectHost('/root', '/root');
architect = new Architect(testArchitectHost, registry);
await testArchitectHost.addBuilderFromPackage(join(__dirname, '../../..'));
});