Skip to content

Commit

Permalink
Remove node_runfiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
Globegitter authored and alexeagle committed Jun 4, 2019
1 parent 5454dd4 commit 8f8558c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 80 deletions.
79 changes: 0 additions & 79 deletions internal/node/generate_build_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const path = require('path');

const IS_WINDOWS = TEMPLATED_is_windows;
const NODE_DIR = 'TEMPLATED_node_dir';
const YARN_DIR = 'TEMPLATED_yarn_dir';
const NODE_ACTUAL = 'TEMPLATED_node_actual';
const NODE_BIN_ACTUAL = 'TEMPLATED_node_bin_actual';
const NPM_ACTUAL = 'TEMPLATED_npm_actual';
Expand Down Expand Up @@ -65,13 +64,6 @@ function main() {
module.exports = { main };

function generateBuildFile() {
// *.pyc files are generated during node-gyp compilation and include
// absolute paths, making them non-hermetic.
// See https://github.com/bazelbuild/rules_nodejs/issues/347
const excludedFiles = ['.md', '.html', '.pyc'];
const nodejsSrcFiles = filterFilesForFilegroup(listFiles(NODE_DIR), [], excludedFiles)
const yarnSrcFiles = filterFilesForFilegroup(listFiles(YARN_DIR), [], excludedFiles)

const binaryExt = IS_WINDOWS ? '.cmd' : '';
const buildFile = `# Generated by node_repositories.bzl
package(default_visibility = ["//visibility:public"])
Expand All @@ -89,77 +81,6 @@ alias(name = "node_bin", actual = "${NODE_BIN_ACTUAL}")
alias(name = "node", actual = "${NODE_ACTUAL}")
alias(name = "npm", actual = "${NPM_ACTUAL}")
alias(name = "yarn", actual = "${YARN_ACTUAL}")
filegroup(
name = "node_runfiles",
srcs = [
${nodejsSrcFiles.map(f => `"${NODE_DIR}/${f}",`).join('\n ')}
${yarnSrcFiles.map(f => `"${YARN_DIR}/${f}",`).join('\n ')}
],
)
`
writeFileSync('BUILD.bazel', buildFile);
}

/**
* Returns an array of all the files under a directory as relative
* paths to the directory.
*/
function listFiles(rootDir, subDir = '') {
const dir = path.posix.join(rootDir, subDir);
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
return [];
}
return fs
.readdirSync(dir)
.reduce((files, file) => {
const fullPath = path.posix.join(dir, file);
const relPath = path.posix.join(subDir, file);
let stat;
try {
stat = fs.statSync(fullPath);
} catch (e) {
throw e;
}
return stat.isDirectory() ? files.concat(listFiles(rootDir, relPath)) :
files.concat(relPath);
}, []);
}

/**
* A filter function for a bazel filegroup.
* @param files array of files to filter
* @param allowedExts list of white listed extensions; if empty, no filter is done on extensions;
* '' empty string denotes to allow files with no extensions, other extensions
* are listed with '.ext' notation such as '.d.ts'.
*/
function filterFilesForFilegroup(files, allowedExts = [], excludedExts = []) {
// Files with spaces (\x20) or unicode characters (<\x20 && >\x7E) are not allowed in
// Bazel runfiles. See https://github.com/bazelbuild/bazel/issues/4327
files = files.filter(f => !/[^\x21-\x7E]/.test(f));
if (allowedExts.length) {
const allowNoExts = allowedExts.includes('');
files = files.filter(f => {
// include files with no extensions if noExt is true
if (allowNoExts && !path.extname(f)) return true;
// filter files in allowedExts
for (const e of allowedExts) {
if (e && f.endsWith(e)) {
return true;
}
}
return false;
})
}
if (excludedExts.length) {
files = files.filter(f => {
// filter out files in excludedExts
for (const e of excludedExts) {
if (e && f.endsWith(e)) {
return false;
}
}
return true;
})
}
return files;
}
1 change: 0 additions & 1 deletion internal/node/node_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ if %errorlevel% neq 0 exit /b %errorlevel%
"TEMPLATED_node_dir": NODE_DIR,
"TEMPLATED_npm_actual": npm_node_repositories_entry,
"TEMPLATED_yarn_actual": yarn_node_repositories_entry,
"TEMPLATED_yarn_dir": YARN_DIR,
},
)
result = repository_ctx.execute([node_entry, "generate_build_file.js"])
Expand Down

0 comments on commit 8f8558c

Please sign in to comment.