@@ -24,7 +24,6 @@ const path = require('path');
2424
2525const IS_WINDOWS = TEMPLATED_is_windows ;
2626const NODE_DIR = 'TEMPLATED_node_dir' ;
27- const YARN_DIR = 'TEMPLATED_yarn_dir' ;
2827const NODE_ACTUAL = 'TEMPLATED_node_actual' ;
2928const NODE_BIN_ACTUAL = 'TEMPLATED_node_bin_actual' ;
3029const NPM_ACTUAL = 'TEMPLATED_npm_actual' ;
@@ -65,13 +64,6 @@ function main() {
6564module . exports = { main } ;
6665
6766function generateBuildFile ( ) {
68- // *.pyc files are generated during node-gyp compilation and include
69- // absolute paths, making them non-hermetic.
70- // See https://github.com/bazelbuild/rules_nodejs/issues/347
71- const excludedFiles = [ '.md' , '.html' , '.pyc' ] ;
72- const nodejsSrcFiles = filterFilesForFilegroup ( listFiles ( NODE_DIR ) , [ ] , excludedFiles )
73- const yarnSrcFiles = filterFilesForFilegroup ( listFiles ( YARN_DIR ) , [ ] , excludedFiles )
74-
7567 const binaryExt = IS_WINDOWS ? '.cmd' : '' ;
7668 const buildFile = `# Generated by node_repositories.bzl
7769package(default_visibility = ["//visibility:public"])
@@ -89,77 +81,6 @@ alias(name = "node_bin", actual = "${NODE_BIN_ACTUAL}")
8981alias(name = "node", actual = "${ NODE_ACTUAL } ")
9082alias(name = "npm", actual = "${ NPM_ACTUAL } ")
9183alias(name = "yarn", actual = "${ YARN_ACTUAL } ")
92- filegroup(
93- name = "node_runfiles",
94- srcs = [
95- ${ nodejsSrcFiles . map ( f => `"${ NODE_DIR } /${ f } ",` ) . join ( '\n ' ) }
96- ${ yarnSrcFiles . map ( f => `"${ YARN_DIR } /${ f } ",` ) . join ( '\n ' ) }
97- ],
98- )
9984`
10085 writeFileSync ( 'BUILD.bazel' , buildFile ) ;
10186}
102-
103- /**
104- * Returns an array of all the files under a directory as relative
105- * paths to the directory.
106- */
107- function listFiles ( rootDir , subDir = '' ) {
108- const dir = path . posix . join ( rootDir , subDir ) ;
109- if ( ! fs . existsSync ( dir ) || ! fs . statSync ( dir ) . isDirectory ( ) ) {
110- return [ ] ;
111- }
112- return fs
113- . readdirSync ( dir )
114- . reduce ( ( files , file ) => {
115- const fullPath = path . posix . join ( dir , file ) ;
116- const relPath = path . posix . join ( subDir , file ) ;
117- let stat ;
118- try {
119- stat = fs . statSync ( fullPath ) ;
120- } catch ( e ) {
121- throw e ;
122- }
123- return stat . isDirectory ( ) ? files . concat ( listFiles ( rootDir , relPath ) ) :
124- files . concat ( relPath ) ;
125- } , [ ] ) ;
126- }
127-
128- /**
129- * A filter function for a bazel filegroup.
130- * @param files array of files to filter
131- * @param allowedExts list of white listed extensions; if empty, no filter is done on extensions;
132- * '' empty string denotes to allow files with no extensions, other extensions
133- * are listed with '.ext' notation such as '.d.ts'.
134- */
135- function filterFilesForFilegroup ( files , allowedExts = [ ] , excludedExts = [ ] ) {
136- // Files with spaces (\x20) or unicode characters (<\x20 && >\x7E) are not allowed in
137- // Bazel runfiles. See https://github.com/bazelbuild/bazel/issues/4327
138- files = files . filter ( f => ! / [ ^ \x21 - \x7E ] / . test ( f ) ) ;
139- if ( allowedExts . length ) {
140- const allowNoExts = allowedExts . includes ( '' ) ;
141- files = files . filter ( f => {
142- // include files with no extensions if noExt is true
143- if ( allowNoExts && ! path . extname ( f ) ) return true ;
144- // filter files in allowedExts
145- for ( const e of allowedExts ) {
146- if ( e && f . endsWith ( e ) ) {
147- return true ;
148- }
149- }
150- return false ;
151- } )
152- }
153- if ( excludedExts . length ) {
154- files = files . filter ( f => {
155- // filter out files in excludedExts
156- for ( const e of excludedExts ) {
157- if ( e && f . endsWith ( e ) ) {
158- return false ;
159- }
160- }
161- return true ;
162- } )
163- }
164- return files ;
165- }
0 commit comments