You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.1 KiB
112 lines
3.1 KiB
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.isModuleSymlinked = isModuleSymlinked;
|
|
function _assert() {
|
|
const data = _interopRequireDefault(require("assert"));
|
|
_assert = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _findUp() {
|
|
const data = _interopRequireDefault(require("find-up"));
|
|
_findUp = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _path() {
|
|
const data = _interopRequireDefault(require("path"));
|
|
_path = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _resolveFrom() {
|
|
const data = _interopRequireDefault(require("resolve-from"));
|
|
_resolveFrom = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
/**
|
|
* Find the closest `package.json`.
|
|
*
|
|
* @example findUpPackageJson('./foo/expo/build/index.js') -> './foo/expo/package.json'
|
|
*/
|
|
function findUpPackageJson(root) {
|
|
const packageJson = _findUp().default.sync('package.json', {
|
|
cwd: root
|
|
});
|
|
(0, _assert().default)(packageJson, `No package.json found for module "${root}"`);
|
|
return packageJson;
|
|
}
|
|
|
|
/**
|
|
* Return the root folder for a node module file.
|
|
*
|
|
* @example getModuleRootPathForFile('./foo/expo/build/index.js') -> './foo/expo'
|
|
*/
|
|
function getModuleRootPathForFile(moduleFile) {
|
|
// Get the closest package.json to the node module
|
|
const packageJson = findUpPackageJson(moduleFile);
|
|
const moduleRoot = _path().default.dirname(packageJson);
|
|
return moduleRoot;
|
|
}
|
|
|
|
/**
|
|
* Return true if the parent folder for a given file path is named "node_modules".
|
|
*
|
|
* @example
|
|
* isModuleRootPathInNodeModulesFolder('./foo/expo') -> false
|
|
* isModuleRootPathInNodeModulesFolder('./node_modules/expo') -> true
|
|
*/
|
|
function isModuleRootPathInNodeModulesFolder(moduleRootPath) {
|
|
const parentFolderName = _path().default.basename(_path().default.dirname(moduleRootPath));
|
|
return parentFolderName === 'node_modules';
|
|
}
|
|
|
|
/**
|
|
* Given a node module name, and a project path, this method will:
|
|
*
|
|
* 1. Resolve the module path.
|
|
* 2. Find the module root folder.
|
|
* 3. Return true if the module root folder is in a folder named `node_modules`
|
|
*
|
|
* @param projectRoot
|
|
* @param moduleId
|
|
*
|
|
* @example
|
|
* isModuleSymlinked({
|
|
* projectRoot: './expo/apps/native-component-list',
|
|
* moduleId: 'react-native'
|
|
* })
|
|
*/
|
|
function isModuleSymlinked({
|
|
projectRoot,
|
|
moduleId,
|
|
isSilent
|
|
}) {
|
|
try {
|
|
const modulePath = (0, _resolveFrom().default)(projectRoot, moduleId);
|
|
if (!modulePath) {
|
|
// module cannot be resolved (probably not installed), cannot be symlinked.
|
|
return false;
|
|
}
|
|
// resolve the root folder for the node module
|
|
const moduleRootPath = getModuleRootPathForFile(modulePath);
|
|
return !isModuleRootPathInNodeModulesFolder(moduleRootPath);
|
|
} catch (error) {
|
|
if (!isSilent) {
|
|
throw error;
|
|
}
|
|
// Failed to resolve the package.json relative to the project, not sure what to do here.
|
|
// This is probably not possible due to node module resolution.
|
|
return false;
|
|
}
|
|
}
|
|
//# sourceMappingURL=isModuleSymlinked.js.map
|