Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function normalizeFileReplacement(
fileReplacement: FileReplacement,
root?: Path,
): NormalizedFileReplacement {
let replacePath: Path;
let withPath: Path;
if (fileReplacement.src && fileReplacement.replaceWith) {
replacePath = normalize(fileReplacement.src);
withPath = normalize(fileReplacement.replaceWith);
} else if (fileReplacement.replace && fileReplacement.with) {
replacePath = normalize(fileReplacement.replace);
withPath = normalize(fileReplacement.with);
} else {
throw new Error(`Invalid file replacement: ${JSON.stringify(fileReplacement)}`);
}
// TODO: For 7.x should this only happen if not absolute?
if (root) {
replacePath = join(root, replacePath);
}
if (root) {
withPath = join(root, withPath);
}
return { replace: replacePath, with: withPath };
}
appendToFile(path, str) {
const content = core_1.virtualFs.fileBufferToString(this.scopedSync().read(core_1.normalize(path)));
this.scopedSync().write(core_1.normalize(path), core_1.virtualFs.stringToFileBuffer(content.concat(str)));
}
fileMatchExists(dir, regex) {
it('makes every path absolute', () => {
const host = new SyncDelegateHost(new SimpleMemoryHost());
const buffer = stringToFileBuffer('hello');
const buffer2 = stringToFileBuffer('hello 2');
host.write(normalize('file1'), buffer);
host.write(normalize('/sub/file2'), buffer);
host.write(normalize('sub/file2'), buffer2);
expect(host.isFile(normalize('file1'))).toBe(true);
expect(host.isFile(normalize('/file1'))).toBe(true);
expect(host.isFile(normalize('/sub/file2'))).toBe(true);
expect(host.read(normalize('sub/file2'))).toBe(buffer2);
expect(host.isDirectory(normalize('/sub'))).toBe(true);
expect(host.isDirectory(normalize('sub'))).toBe(true);
});
});
stat(path: string, callback: Callback): void {
const p = normalize('/' + path);
const result = this._host.stat(p);
if (result === null) {
const o = this._host.exists(p).pipe(
switchMap(exists => {
if (!exists) {
throw new FileDoesNotExistException(p);
}
return this._host.isDirectory(p).pipe(
mergeMap(isDirectory => {
return (isDirectory ? of(0) : this._host.read(p).pipe(
map(content => content.byteLength),
)).pipe(
map(size => [isDirectory, size]),
);
level: 'local' | 'global' = 'local',
): experimental.workspace.Workspace | null {
const cached = cachedWorkspaces.get(level);
if (cached != undefined) {
return cached;
}
const configPath = level === 'local' ? projectFilePath() : globalFilePath();
if (!configPath) {
cachedWorkspaces.set(level, null);
return null;
}
const root = normalize(path.dirname(configPath));
const file = normalize(path.basename(configPath));
const workspace = new experimental.workspace.Workspace(
root,
new NodeJsSyncHost(),
);
workspace.loadWorkspaceFromHost(file).subscribe();
cachedWorkspaces.set(level, workspace);
return workspace;
}
function setOptionsValue(target, defaultSourceRoot: string) {
target.path =
target.path !== undefined
? join(normalize(defaultSourceRoot), target.path)
: normalize(defaultSourceRoot);
if (target.name) {
const location: Location = new Parser().nameParser(target);
target.name = strings.dasherize(location.name);
target.path = join(strings.dasherize(location.path) as Path, target.name);
}
return target;
}
architect.serve.options = {
...architect.serve.options,
customServerPath: options.server
};
}
architect.export = {
builder: '@nrwl/next:export',
options: {
buildTarget: `${options.projectName}:build`
}
};
architect.lint = generateProjectLint(
normalize(options.appProjectRoot),
join(normalize(options.appProjectRoot), 'tsconfig.json'),
options.linter
);
json.projects[options.projectName] = {
root: options.appProjectRoot,
sourceRoot: options.appProjectRoot,
projectType: 'application',
schematics: {},
architect
};
json.defaultProject = json.defaultProject || options.projectName;
return json;
});
}
if (typeof asset === 'string') {
return core_1.normalize(appRoot + '/' + asset);
}
else {
if (asset.allowOutsideOutDir) {
logger.warn(core_1.tags.oneLine `
Asset with input '${asset.input}' was not migrated because it
uses the 'allowOutsideOutDir' option which is not supported in Angular CLI 6.
`);
return null;
}
else if (asset.output) {
return {
glob: asset.glob,
input: core_1.normalize(appRoot + '/' + asset.input),
output: core_1.normalize('/' + asset.output),
};
}
else {
return {
glob: asset.glob,
input: core_1.normalize(appRoot + '/' + asset.input),
output: '/',
};
}
}
}
function _buildConfigurations() {
protected _normalizePath(path: string): Path {
return normalize('/' + path);
}
protected get tree(): ReadonlyMap { return this._tree; }