@expo/config-plugins
Advanced tools
Comparing version
import { ConfigPlugin, StaticPlugin } from '../Plugin.types'; | ||
export declare const pluginFileName = "app.plugin.js"; | ||
export declare function resolvePluginForModule(projectRoot: string, modulePath: string): { | ||
export declare function resolvePluginForModule(projectRoot: string, pluginReference: string): { | ||
filePath: string; | ||
isPluginFile: boolean; | ||
filePath: string; | ||
}; | ||
export declare function moduleNameIsDirectFileReference(name: string): boolean; | ||
export declare function moduleNameIsPackageReference(name: string): boolean; | ||
export declare function normalizeStaticPlugin(plugin: StaticPlugin | ConfigPlugin | string): StaticPlugin; | ||
@@ -9,0 +10,0 @@ export declare function assertInternalProjectRoot(projectRoot?: string): asserts projectRoot; |
@@ -8,2 +8,3 @@ "use strict"; | ||
exports.moduleNameIsDirectFileReference = moduleNameIsDirectFileReference; | ||
exports.moduleNameIsPackageReference = moduleNameIsPackageReference; | ||
exports.normalizeStaticPlugin = normalizeStaticPlugin; | ||
@@ -22,9 +23,2 @@ exports.pluginFileName = void 0; | ||
} | ||
function _findUp() { | ||
const data = _interopRequireDefault(require("find-up")); | ||
_findUp = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function path() { | ||
@@ -63,23 +57,25 @@ const data = _interopRequireWildcard(require("path")); | ||
const pluginFileName = exports.pluginFileName = 'app.plugin.js'; | ||
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; | ||
} | ||
function resolvePluginForModule(projectRoot, modulePath) { | ||
const resolved = _resolveFrom().default.silent(projectRoot, modulePath); | ||
if (!resolved) { | ||
throw new (_errors().PluginError)(`Failed to resolve plugin for module "${modulePath}" relative to "${projectRoot}"`, 'PLUGIN_NOT_FOUND'); | ||
// pluginReference is a node module or a file path, as user entered it in app.config.js | ||
function resolvePluginForModule(projectRoot, pluginReference) { | ||
if (moduleNameIsDirectFileReference(pluginReference)) { | ||
// Only resolve `./file.js`, `package/file.js`, `@org/package/file.js` | ||
const pluginScriptFile = _resolveFrom().default.silent(projectRoot, pluginReference); | ||
if (pluginScriptFile) { | ||
return { | ||
isPluginFile: false, | ||
filePath: pluginScriptFile | ||
}; | ||
} | ||
} else if (moduleNameIsPackageReference(pluginReference)) { | ||
// Only resolve `package -> package/app.plugin.js`, `@org/package -> @org/package/app.plugin.js` | ||
const pluginPackageFile = _resolveFrom().default.silent(projectRoot, `${pluginReference}/${pluginFileName}`); | ||
if (pluginPackageFile && (0, _modules().fileExists)(pluginPackageFile)) { | ||
return { | ||
isPluginFile: true, | ||
filePath: pluginPackageFile | ||
}; | ||
} | ||
} | ||
// If the modulePath is something like `@bacon/package/index.js` or `expo-foo/build/app` | ||
// then skip resolving the module `app.plugin.js` | ||
if (moduleNameIsDirectFileReference(modulePath)) { | ||
return { | ||
isPluginFile: false, | ||
filePath: resolved | ||
}; | ||
} | ||
return findUpPlugin(resolved); | ||
throw new (_errors().PluginError)(`Failed to resolve plugin for module "${pluginReference}" relative to "${projectRoot}"`, 'PLUGIN_NOT_FOUND'); | ||
} | ||
@@ -105,26 +101,6 @@ | ||
} | ||
function resolveExpoPluginFile(root) { | ||
// Find the expo plugin root file | ||
const pluginModuleFile = _resolveFrom().default.silent(root, | ||
// use ./ so it isn't resolved as a node module | ||
`./${pluginFileName}`); | ||
// If the default expo plugin file exists use it. | ||
if (pluginModuleFile && (0, _modules().fileExists)(pluginModuleFile)) { | ||
return pluginModuleFile; | ||
} | ||
return null; | ||
function moduleNameIsPackageReference(name) { | ||
const slashCount = name.split('/')?.length; | ||
return name.startsWith('@') ? slashCount === 2 : slashCount === 1; | ||
} | ||
function findUpPlugin(root) { | ||
// Get the closest package.json to the node module | ||
const packageJson = findUpPackageJson(root); | ||
// resolve the root folder for the node module | ||
const moduleRoot = path().dirname(packageJson); | ||
// use whatever the initial resolved file was ex: `node_modules/my-package/index.js` or `./something.js` | ||
const pluginFile = resolveExpoPluginFile(moduleRoot); | ||
return { | ||
filePath: pluginFile ?? root, | ||
isPluginFile: !!pluginFile | ||
}; | ||
} | ||
function normalizeStaticPlugin(plugin) { | ||
@@ -131,0 +107,0 @@ if (Array.isArray(plugin)) { |
{ | ||
"name": "@expo/config-plugins", | ||
"version": "8.1.0-canary-20240927-ab8a962", | ||
"version": "8.1.0-canary-20241008-90b13ad", | ||
"description": "A library for Expo config plugins", | ||
@@ -36,9 +36,8 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"@expo/config-types": "52.0.0-canary-20240927-ab8a962", | ||
"@expo/json-file": "8.4.0-canary-20240927-ab8a962", | ||
"@expo/plist": "0.1.4-canary-20240927-ab8a962", | ||
"@expo/config-types": "52.0.0-canary-20241008-90b13ad", | ||
"@expo/json-file": "8.4.0-canary-20241008-90b13ad", | ||
"@expo/plist": "0.1.4-canary-20241008-90b13ad", | ||
"@expo/sdk-runtime-versions": "^1.0.0", | ||
"chalk": "^4.1.2", | ||
"debug": "^4.3.1", | ||
"find-up": "~5.0.0", | ||
"debug": "^4.3.5", | ||
"getenv": "^1.0.0", | ||
@@ -57,3 +56,3 @@ "glob": "^10.4.2", | ||
"@types/xml2js": "~0.4.11", | ||
"expo-module-scripts": "3.6.0-canary-20240927-ab8a962" | ||
"expo-module-scripts": "3.6.0-canary-20241008-90b13ad" | ||
}, | ||
@@ -63,3 +62,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "ab8a962d2c3dddbda124a6bd88d24475831dae00" | ||
"gitHead": "90b13ad9d0dd3469556ac776d8b74643375b1d97" | ||
} |
Sorry, the diff of this file is not supported yet
14
-6.67%1123658
-0.13%13113
-0.18%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated