@netlify/content-engine
Version:
96 lines • 2.48 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNodeInternalModulePath = void 0;
exports.joinPath = joinPath;
exports.slash = slash;
const path_1 = __importDefault(require("path"));
const os_1 = __importDefault(require("os"));
/**
* Joins all given path segments and converts
* @param paths A sequence of path segments
*/
function joinPath(...paths) {
const joinedPath = path_1.default.join(...paths);
if (os_1.default.platform() === `win32`) {
return joinedPath.replace(/\\/g, `\\\\`);
}
return joinedPath;
}
// copied from https://runpkg.com/?pretty-error@2.1.1/lib/nodePaths.js
// and added `^internal/` test
const nodePaths = [
/^_debugger.js$/,
/^_http_agent.js$/,
/^_http_client.js$/,
/^_http_common.js$/,
/^_http_incoming.js$/,
/^_http_outgoing.js$/,
/^_http_server.js$/,
/^_linklist.js$/,
/^_stream_duplex.js$/,
/^_stream_passthrough.js$/,
/^_stream_readable.js$/,
/^_stream_transform.js$/,
/^_stream_writable.js$/,
/^_tls_legacy.js$/,
/^_tls_wrap.js$/,
/^assert.js$/,
/^buffer.js$/,
/^child_process.js$/,
/^cluster.js$/,
/^console.js$/,
/^constants.js$/,
/^crypto.js$/,
/^dgram.js$/,
/^dns.js$/,
/^domain.js$/,
/^events.js$/,
/^freelist.js$/,
/^fs.js$/,
/^http.js$/,
/^https.js$/,
/^module.js$/,
/^net.js$/,
/^os.js$/,
/^path.js$/,
/^punycode.js$/,
/^querystring.js$/,
/^readline.js$/,
/^repl.js$/,
/^smalloc.js$/,
/^stream.js$/,
/^string_decoder.js$/,
/^sys.js$/,
/^timers.js$/,
/^tls.js$/,
/^tty.js$/,
/^url.js$/,
/^util.js$/,
/^vm.js$/,
/^zlib.js$/,
/^node.js$/,
/^internal[/\\]/,
];
/**
* Checks if the file name matches a node path
* @param fileName File name
*/
const isNodeInternalModulePath = (fileName) => nodePaths.some((regTest) => regTest.test(fileName));
exports.isNodeInternalModulePath = isNodeInternalModulePath;
/**
* Convert Windows backslash paths to slash paths: foo\\bar ➔ foo/bar
*
* @param path
* @return slashed path
*/
function slash(path) {
const isExtendedLengthPath = /^\\\\\?\\/.test(path);
if (isExtendedLengthPath) {
return path;
}
return path.replace(/\\/g, `/`);
}
//# sourceMappingURL=path.js.map
;