Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('Protractor Target', () => {
const devkitRoot = (global as any)._DevKitRoot; // tslint:disable-line:no-any
const root = resolve(devkitRoot, 'tests/@angular_devkit/build_webpack/hello-world-app/');
const builderPath = resolve(devkitRoot, 'packages/angular_devkit/build_webpack');
const relativeBuilderPath = relative(root, builderPath);
const host = new NodeJsSyncHost();
const getWorkspace = (): Workspace => {
const workspace = getDevServerWorkspace();
workspace.projects.app.defaultTarget = 'protractor';
workspace.projects.app.targets['protractor'] = {
builder: `${relativeBuilderPath}:protractor`,
options: {
protractorConfig: '../protractor.conf.js',
devServerTarget: 'app:devServer',
},
};
return workspace;
};
it('runs', (done) => {
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).
return (context) => {
// Resolve all file:///a/b/c/d from the schematic's own path, and not the current
// path.
const root = core_1.normalize(path_1.resolve(context.schematic.description.path, url.path || ''));
return new src_1.HostCreateTree(new core_1.virtualFs.ScopedHost(new node_1.NodeJsSyncHost(), root));
};
}
export function serveWebpackBrowser(
options: DevServerBuilderOptions,
context: BuilderContext,
transforms: {
webpackConfiguration?: ExecutionTransformer;
logging?: WebpackLoggingCallback;
indexHtml?: IndexHtmlTransform;
} = {},
): Observable {
// Check Angular version.
assertCompatibleAngularVersion(context.workspaceRoot, context.logger);
const browserTarget = targetFromTargetString(options.browserTarget);
const root = context.workspaceRoot;
let first = true;
const host = new NodeJsSyncHost();
const loggingFn =
transforms.logging || createBrowserLoggingCallback(!!options.verbose, context.logger);
async function setup(): Promise<{
browserOptions: json.JsonObject & BrowserBuilderSchema;
webpackConfig: webpack.Configuration;
webpackDevServerConfig: WebpackDevServer.Configuration;
port: number;
projectRoot: string;
}> {
// Get the browser configuration from the target name.
const rawBrowserOptions = await context.getTargetOptions(browserTarget);
// Override options we need to override, if defined.
const overrides = (Object.keys(options) as (keyof DevServerBuilderOptions)[])
constructor(dir: string) {
super(new NodeJsSyncHost(), normalize(dir));
}
}
export async function generateBrowserWebpackConfigFromContext(
options: BrowserBuilderSchema,
context: BuilderContext,
webpackPartialGenerator: (wco: BrowserWebpackConfigOptions) => webpack.Configuration[],
host: virtualFs.Host = new NodeJsSyncHost(),
): Promise<{ config: webpack.Configuration; projectRoot: string; projectSourceRoot?: string }> {
const projectName = context.target && context.target.project;
if (!projectName) {
throw new Error('The builder requires a target.');
}
const workspaceRoot = normalize(context.workspaceRoot);
const projectMetadata = await context.getProjectMetadata(projectName);
const projectRoot = resolve(workspaceRoot, normalize((projectMetadata.root as string) || ''));
const projectSourceRoot = projectMetadata.sourceRoot as string | undefined;
const sourceRoot = projectSourceRoot
? resolve(workspaceRoot, normalize(projectSourceRoot))
: undefined;
const normalizedOptions = normalizeBrowserSchema(
host,
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)
});
}
export async function validateWorkspace(json: JsonObject) {
const workspace = new experimental.workspace.Workspace(
normalize('.'),
new NodeJsSyncHost(),
);
await workspace.loadWorkspaceFromJson(json).toPromise();
return true;
}
constructor(host, force = false) {
super(typeof host == 'string'
? new core_1.virtualFs.ScopedHost(new node_1.NodeJsSyncHost(), core_1.normalize(host))
: host, force);
this._subject = new rxjs_1.Subject();
this._fileDoesNotExistExceptionSet = new Set();
this._fileAlreadyExistExceptionSet = new Set();
this.reporter = this._subject.asObservable();
}
_fileAlreadyExistException(path) {
export function getWorkspaceRaw(
level: 'local' | 'global' = 'local',
): [JsonAstObject | null, string | null] {
let configPath = level === 'local' ? projectFilePath() : globalFilePath();
if (!configPath) {
if (level === 'global') {
configPath = createGlobalSettings();
} else {
return [null, null];
}
}
let content = '';
new NodeJsSyncHost().read(normalize(configPath))
.subscribe(data => content = virtualFs.fileBufferToString(data));
const ast = parseJsonAst(content, JsonParseMode.Loose);
if (ast.kind != 'object') {
throw new Error(`Invalid JSON file: ${configPath}`);
}
return [ast, configPath];
}