path#isAbsolute JavaScript Examples

The following examples show how to use path#isAbsolute. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: editor.js    From ReactSourceCodeAnalyze with MIT License 6 votes vote down vote up
export function getValidFilePath(
  maybeRelativePath: string,
  absoluteProjectRoots: Array<string>,
): string | null {
  // We use relative paths at Facebook with deterministic builds.
  // This is why our internal tooling calls React DevTools with absoluteProjectRoots.
  // If the filename is absolute then we don't need to care about this.
  if (isAbsolute(maybeRelativePath)) {
    if (existsSync(maybeRelativePath)) {
      return maybeRelativePath;
    }
  } else {
    for (let i = 0; i < absoluteProjectRoots.length; i++) {
      const projectRoot = absoluteProjectRoots[i];
      const joinedPath = join(projectRoot, maybeRelativePath);
      if (existsSync(joinedPath)) {
        return joinedPath;
      }
    }
  }

  return null;
}
Example #2
Source File: parse.js    From uvu with MIT License 6 votes vote down vote up
parse('should rely on defaults', async () => {
	// dirname to avoid node_modules
	let output = await $.parse(__dirname);

	assert.type(output, 'object');
	assert.is(output.dir, __dirname);
	assert.is(output.requires, false);

	assert.instance(output.suites, Array);
	assert.is(output.suites.length, FILES.length);

	output.suites.forEach(suite => {
		assert.is.not(isAbsolute(suite.name));
		assert.is(FILES.includes(suite.name), true, '~> suite.name is relative filename')
		assert.is(isAbsolute(suite.file), true, '~> suite.file is absolute path');
	});
});
Example #3
Source File: parse.js    From uvu with MIT License 6 votes vote down vote up
dir('should accept relative `dir` input', async () => {
	let output = await $.parse('test');

	assert.type(output, 'object');
	assert.is(output.dir, __dirname);
	assert.is(output.requires, false);

	assert.instance(output.suites, Array);
	assert.is(output.suites.length, FILES.length);

	output.suites.forEach(suite => {
		assert.is.not(isAbsolute(suite.name));
		assert.is(FILES.includes(suite.name), true, '~> suite.name is relative filename')
		assert.is(isAbsolute(suite.file), true, '~> suite.file is absolute path');
	});
});
Example #4
Source File: parse.js    From uvu with MIT License 5 votes vote down vote up
cwd('should affect from where `dir` resolves', async () => {
	let foo = await $.parse('.', '', { cwd: __dirname });
	assert.is(foo.suites.length, FILES.length);
	foo.suites.forEach(suite => {
		assert.is(FILES.includes(suite.name), true, '~> suite.name is relative filename')
		assert.is(isAbsolute(suite.file), true, '~> suite.file is absolute path');
	});
});