function generateBazelWorkspace(pkg, workspace) {
        let bzlFile = `# Generated by the yarn_install/npm_install rule
load("@build_bazel_rules_nodejs//internal/copy_repository:copy_repository.bzl", "copy_repository")

def _maybe(repo_rule, name, **kwargs):
    if name not in native.existing_rules():
        repo_rule(name = name, **kwargs)
`;
        const rootPath = pkg.bazelWorkspaces[workspace].rootPath;
        if (!rootPath) {
            console.error(`Malformed bazelWorkspaces attribute in ${pkg._dir}@${pkg.version}. ` +
                `Missing rootPath for workspace ${workspace}.`);
            process.exit(1);
        }
        // Copy all files for this workspace to a folder under _workspaces
        // to restore the Bazel files which have be renamed from the npm package
        const workspaceSourcePath = path.posix.join('_workspaces', workspace);
        mkdirp(workspaceSourcePath);
        pkg._files.forEach(file => {
            if (/^node_modules[/\\]/.test(file)) {
                // don't copy over nested node_modules
                return;
            }
            let destFile = path.relative(rootPath, file);
            if (destFile.startsWith('..')) {
                // this file is not under the rootPath
                return;
            }
            const basename = path.basename(file);
            const basenameUc = basename.toUpperCase();
            // Bazel BUILD files from npm distribution would have been renamed earlier with a _ prefix so
            // we restore the name on the copy
            if (basenameUc === '_BUILD' || basenameUc === '_BUILD.BAZEL') {
                destFile = path.posix.join(path.dirname(destFile), basename.substr(1));
            }
            const src = path.posix.join('node_modules', pkg._dir, file);
            const dest = path.posix.join(workspaceSourcePath, destFile);
            mkdirp(path.dirname(dest));
            fs.copyFileSync(src, dest);
        });
        // We create _bazel_workspace_marker that is used by the custom copy_repository
        // rule to resolve the path to the repository source root. A root BUILD file
        // is required to reference _bazel_workspace_marker as a target so we also create
        // an empty one if one does not exist.
        if (!hasRootBuildFile(pkg, rootPath)) {
            writeFileSync(path.posix.join(workspaceSourcePath, 'BUILD.bazel'), '# Marker file that this directory is a bazel package');
        }
        const sha256sum = crypto.createHash('sha256');
        sha256sum.update(fs.readFileSync(LOCK_FILE_PATH, { encoding: 'utf8' }));
        writeFileSync(path.posix.join(workspaceSourcePath, '_bazel_workspace_marker'), `# Marker file to used by custom copy_repository rule\n${sha256sum.digest('hex')}`);
        bzlFile += `def install_${workspace}():
    _maybe(
        copy_repository,
        name = "${workspace}",
        marker_file = "@${WORKSPACE}//_workspaces/${workspace}:_bazel_workspace_marker",
    )
`;
        writeFileSync(`install_${workspace}.bzl`, bzlFile);
    }
/**
     * Generate install_<workspace>.bzl file with function to install the workspace.
     */
Generate install_.bzl file with function to install the workspace.
Generate install_ . bzl file with function to install the workspace .
function generateBazelWorkspace(pkg, workspace) {
        let bzlFile = `# Generated by the yarn_install/npm_install rule
load("@build_bazel_rules_nodejs//internal/copy_repository:copy_repository.bzl", "copy_repository")
def _maybe(repo_rule, name, **kwargs):
    if name not in native.existing_rules():
        repo_rule(name = name, **kwargs)
`;
        const rootPath = pkg.bazelWorkspaces[workspace].rootPath;
        if (!rootPath) {
            console.error(`Malformed bazelWorkspaces attribute in ${pkg._dir}@${pkg.version}. ` +
                `Missing rootPath for workspace ${workspace}.`);
            process.exit(1);
        }
        const workspaceSourcePath = path.posix.join('_workspaces', workspace);
        mkdirp(workspaceSourcePath);
        pkg._files.forEach(file => {
            if (/^node_modules[/\\]/.test(file)) {
                return;
            }
            let destFile = path.relative(rootPath, file);
            if (destFile.startsWith('..')) {
                return;
            }
            const basename = path.basename(file);
            const basenameUc = basename.toUpperCase();
            if (basenameUc === '_BUILD' || basenameUc === '_BUILD.BAZEL') {
                destFile = path.posix.join(path.dirname(destFile), basename.substr(1));
            }
            const src = path.posix.join('node_modules', pkg._dir, file);
            const dest = path.posix.join(workspaceSourcePath, destFile);
            mkdirp(path.dirname(dest));
            fs.copyFileSync(src, dest);
        });
        if (!hasRootBuildFile(pkg, rootPath)) {
            writeFileSync(path.posix.join(workspaceSourcePath, 'BUILD.bazel'), '# Marker file that this directory is a bazel package');
        }
        const sha256sum = crypto.createHash('sha256');
        sha256sum.update(fs.readFileSync(LOCK_FILE_PATH, { encoding: 'utf8' }));
        writeFileSync(path.posix.join(workspaceSourcePath, '_bazel_workspace_marker'), `# Marker file to used by custom copy_repository rule\n${sha256sum.digest('hex')}`);
        bzlFile += `def install_${workspace}():
    _maybe(
        copy_repository,
        name = "${workspace}",
        marker_file = "@${WORKSPACE}//_workspaces/${workspace}:_bazel_workspace_marker",
    )
`;
        writeFileSync(`install_${workspace}.bzl`, bzlFile);
    }
function generateBazelWorkspace ( pkg , workspace ) { let bzlFile = ` ` ; const rootPath = pkg . bazelWorkspaces [ workspace ] . rootPath ; if ( ! rootPath ) { console . error ( ` ${ pkg . _dir } ${ pkg . version } ` + ` ${ workspace } ` ) ; process . exit ( 1 ) ; } const workspaceSourcePath = path . posix . join ( '_workspaces' , workspace ) ; mkdirp ( workspaceSourcePath ) ; pkg . _files . forEach ( file => { if ( / ^node_modules[/\\] / . test ( file ) ) { return ; } let destFile = path . relative ( rootPath , file ) ; if ( destFile . startsWith ( '..' ) ) { return ; } const basename = path . basename ( file ) ; const basenameUc = basename . toUpperCase ( ) ; if ( basenameUc === '_BUILD' || basenameUc === '_BUILD.BAZEL' ) { destFile = path . posix . join ( path . dirname ( destFile ) , basename . substr ( 1 ) ) ; } const src = path . posix . join ( 'node_modules' , pkg . _dir , file ) ; const dest = path . posix . join ( workspaceSourcePath , destFile ) ; mkdirp ( path . dirname ( dest ) ) ; fs . copyFileSync ( src , dest ) ; } ) ; if ( ! hasRootBuildFile ( pkg , rootPath ) ) { writeFileSync ( path . posix . join ( workspaceSourcePath , 'BUILD.bazel' ) , '# Marker file that this directory is a bazel package' ) ; } const sha256sum = crypto . createHash ( 'sha256' ) ; sha256sum . update ( fs . readFileSync ( LOCK_FILE_PATH , { encoding : 'utf8' } ) ) ; writeFileSync ( path . posix . join ( workspaceSourcePath , '_bazel_workspace_marker' ) , ` \n ${ sha256sum . digest ( 'hex' ) } ` ) ; bzlFile += ` ${ workspace } ${ workspace } ${ WORKSPACE } ${ workspace } ` ; writeFileSync ( ` ${ workspace } ` , bzlFile ) ; }
Generate install_<workspace>.bzl file with function to install the workspace.
Generate install_<workspace > . bzl file with function to install the workspace .
// Copy all files for this workspace to a folder under _workspaces // to restore the Bazel files which have be renamed from the npm package // don't copy over nested node_modules // this file is not under the rootPath // Bazel BUILD files from npm distribution would have been renamed earlier with a _ prefix so // we restore the name on the copy // We create _bazel_workspace_marker that is used by the custom copy_repository // rule to resolve the path to the repository source root. A root BUILD file // is required to reference _bazel_workspace_marker as a target so we also create // an empty one if one does not exist.