def _build_node_module(ctx, compilation_dir, node_module):
    """Copy the given node_module into the specified compilation dir"""
    
    outputs = []
    for src in node_module.sources:
        relpath = node_module.sourcemap[src.path]
        dst = ctx.new_file("%s/node_modules/%s/%s" % (compilation_dir, node_module.name, relpath))
        outputs.append(dst)

        ctx.action(
            mnemonic = "CopyNodeModuleForTs",
            inputs = [src],
            outputs = [dst],
            command = "cp %s %s" % (src.path, dst.path),
        )
    return outputs