lib/docker.js
function getBindPath(serverless, servicePath) {
  // Determine bind path
  if (process.platform !== 'win32' && !isWsl) {
    return servicePath;
  }

  // test docker is available
  dockerCommand(['version']);

  // find good bind path for Windows
  let bindPaths = [];
  let baseBindPath = servicePath.replace(/\\([^\s])/g, '/$1');
  let drive;
  let path;

  bindPaths.push(baseBindPath);
  if (baseBindPath.startsWith('/mnt/')) {
    // cygwin "/mnt/C/users/..."
    baseBindPath = baseBindPath.replace(/^\/mnt\//, '/');
  }
  if (baseBindPath[1] == ':') {
    // normal windows "c:/users/..."
    drive = baseBindPath[0];
    path = baseBindPath.substring(3);
  } else if (baseBindPath[0] == '/' && baseBindPath[2] == '/') {
    // gitbash "/c/users/..."
    drive = baseBindPath[1];
    path = baseBindPath.substring(3);
  } else {
    throw new Error(`Unknown path format ${baseBindPath.substr(10)}...`);
  }

  bindPaths.push(`/${drive.toLowerCase()}/${path}`); // Docker Toolbox (seems like Docker for Windows can support this too)
  bindPaths.push(`${drive.toLowerCase()}:/${path}`); // Docker for Windows
  // other options just in case
  bindPaths.push(`/${drive.toUpperCase()}/${path}`);
  bindPaths.push(`/mnt/${drive.toLowerCase()}/${path}`);
  bindPaths.push(`/mnt/${drive.toUpperCase()}/${path}`);
  bindPaths.push(`${drive.toUpperCase()}:/${path}`);

  const testFile = findTestFile(servicePath);

  for (let i = 0; i < bindPaths.length; i++) {
    const bindPath = bindPaths[i];
    if (tryBindPath(serverless, bindPath, testFile)) {
      return bindPath;
    }
  }

  throw new Error('Unable to find good bind path format');
}
function getBindPath(serverless, servicePath) {
  // Determine bind path
  if (process.platform !== 'win32' && !isWsl) {
    return servicePath;
  }

  // test docker is available
  dockerCommand(['version']);

  // find good bind path for Windows
  let bindPaths = [];
  let baseBindPath = servicePath.replace(/\\([^\s])/g, '/$1');
  let drive;
  let path;

  bindPaths.push(baseBindPath);
  if (baseBindPath.startsWith('/mnt/')) {
    // cygwin "/mnt/C/users/..."
    baseBindPath = baseBindPath.replace(/^\/mnt\//, '/');
  }
  if (baseBindPath[1] == ':') {
    // normal windows "c:/users/..."
    drive = baseBindPath[0];
    path = baseBindPath.substring(3);
  } else if (baseBindPath[0] == '/' && baseBindPath[2] == '/') {
    // gitbash "/c/users/..."
    drive = baseBindPath[1];
    path = baseBindPath.substring(3);
  } else {
    throw new Error(`Unknown path format ${baseBindPath.substr(10)}...`);
  }

  bindPaths.push(`/${drive.toLowerCase()}/${path}`); // Docker Toolbox (seems like Docker for Windows can support this too)
  bindPaths.push(`${drive.toLowerCase()}:/${path}`); // Docker for Windows
  // other options just in case
  bindPaths.push(`/${drive.toUpperCase()}/${path}`);
  bindPaths.push(`/mnt/${drive.toLowerCase()}/${path}`);
  bindPaths.push(`/mnt/${drive.toUpperCase()}/${path}`);
  bindPaths.push(`${drive.toUpperCase()}:/${path}`);

  const testFile = findTestFile(servicePath);

  for (let i = 0; i < bindPaths.length; i++) {
    const bindPath = bindPaths[i];
    if (tryBindPath(serverless, bindPath, testFile)) {
      return bindPath;
    }
  }

  throw new Error('Unable to find good bind path format');
}
function getBindPath ( serverless , servicePath ) { // Determine bind path if ( process . platform !== 'win32' && ! isWsl ) { return servicePath ; } // test docker is available dockerCommand ( [ 'version' ] ) ; // find good bind path for Windows let bindPaths = [ ] ; let baseBindPath = servicePath . replace ( / \\([^\s]) / g , '/$1' ) ; let drive ; let path ; bindPaths . push ( baseBindPath ) ; if ( baseBindPath . startsWith ( '/mnt/' ) ) { // cygwin "/mnt/C/users/..." baseBindPath = baseBindPath . replace ( / ^\/mnt\/ / , '/' ) ; } if ( baseBindPath [ 1 ] == ':' ) { // normal windows "c:/users/..." drive = baseBindPath [ 0 ] ; path = baseBindPath . substring ( 3 ) ; } else if ( baseBindPath [ 0 ] == '/' && baseBindPath [ 2 ] == '/' ) { // gitbash "/c/users/..." drive = baseBindPath [ 1 ] ; path = baseBindPath . substring ( 3 ) ; } else { throw new Error ( ` ${ baseBindPath . substr ( 10 ) } ` ) ; } bindPaths . push ( ` ${ drive . toLowerCase ( ) } ${ path } ` ) ; // Docker Toolbox (seems like Docker for Windows can support this too) bindPaths . push ( ` ${ drive . toLowerCase ( ) } ${ path } ` ) ; // Docker for Windows // other options just in case bindPaths . push ( ` ${ drive . toUpperCase ( ) } ${ path } ` ) ; bindPaths . push ( ` ${ drive . toLowerCase ( ) } ${ path } ` ) ; bindPaths . push ( ` ${ drive . toUpperCase ( ) } ${ path } ` ) ; bindPaths . push ( ` ${ drive . toUpperCase ( ) } ${ path } ` ) ; const testFile = findTestFile ( servicePath ) ; for ( let i = 0 ; i < bindPaths . length ; i ++ ) { const bindPath = bindPaths [ i ] ; if ( tryBindPath ( serverless , bindPath , testFile ) ) { return bindPath ; } } throw new Error ( 'Unable to find good bind path format' ) ; }
Get bind path depending on os platform
@param {object} serverless
@param {string} servicePath
@return {string} The bind path.
Get bind path depending on os platform