expo-modules-autolinking
Advanced tools
Comparing version
@@ -13,2 +13,3 @@ "use strict"; | ||
const mergeLinkingOptions_1 = require("./mergeLinkingOptions"); | ||
const utils_1 = require("./utils"); | ||
const ExpoModuleConfig_1 = require("../ExpoModuleConfig"); | ||
@@ -38,14 +39,4 @@ // Names of the config files. From lowest to highest priority. | ||
}); | ||
// Check if the project is using isolated modules, by checking | ||
// if the parent dir of `packagePath` is a `node_modules` folder. | ||
// Isolated modules installs dependencies in small groups such as: | ||
// - /.pnpm/expo@50.x.x(...)/node_modules/@expo/cli | ||
// - /.pnpm/expo@50.x.x(...)/node_modules/expo | ||
// - /.pnpm/expo@50.x.x(...)/node_modules/expo-application | ||
// When isolated modules are detected, expand the `searchPaths` | ||
// to include possible nested dependencies. | ||
const maybeIsolatedModulesPath = path_1.default.join(packagePath, name.startsWith('@') && name.includes('/') ? '../..' : '..' // scoped packages are nested deeper | ||
); | ||
const isIsolatedModulesPath = path_1.default.basename(maybeIsolatedModulesPath) === 'node_modules'; | ||
if (isIsolatedModulesPath && !searchPaths.has(maybeIsolatedModulesPath)) { | ||
const maybeIsolatedModulesPath = (0, utils_1.getIsolatedModulesPath)(packagePath, name); | ||
if (maybeIsolatedModulesPath) { | ||
searchPaths.add(maybeIsolatedModulesPath); | ||
@@ -52,0 +43,0 @@ } |
import { findModulesAsync } from './findModules'; | ||
import { mergeLinkingOptionsAsync, resolveSearchPathsAsync } from './mergeLinkingOptions'; | ||
import { getProjectPackageJsonPathAsync, mergeLinkingOptionsAsync, resolveSearchPathsAsync } from './mergeLinkingOptions'; | ||
import { resolveExtraBuildDependenciesAsync, resolveModulesAsync } from './resolveModules'; | ||
import type { ModuleDescriptor, SearchOptions } from '../types'; | ||
export { findModulesAsync, mergeLinkingOptionsAsync, resolveExtraBuildDependenciesAsync, resolveModulesAsync, resolveSearchPathsAsync, }; | ||
export { findModulesAsync, getProjectPackageJsonPathAsync, mergeLinkingOptionsAsync, resolveExtraBuildDependenciesAsync, resolveModulesAsync, resolveSearchPathsAsync, }; | ||
export { generatePackageListAsync } from './generatePackageList'; | ||
@@ -7,0 +7,0 @@ export { verifySearchResults } from './verifySearchResults'; |
@@ -17,6 +17,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.queryAutolinkingModulesFromProjectAsync = exports.verifySearchResults = exports.generatePackageListAsync = exports.resolveSearchPathsAsync = exports.resolveModulesAsync = exports.resolveExtraBuildDependenciesAsync = exports.mergeLinkingOptionsAsync = exports.findModulesAsync = void 0; | ||
exports.queryAutolinkingModulesFromProjectAsync = exports.verifySearchResults = exports.generatePackageListAsync = exports.resolveSearchPathsAsync = exports.resolveModulesAsync = exports.resolveExtraBuildDependenciesAsync = exports.mergeLinkingOptionsAsync = exports.getProjectPackageJsonPathAsync = exports.findModulesAsync = void 0; | ||
const findModules_1 = require("./findModules"); | ||
Object.defineProperty(exports, "findModulesAsync", { enumerable: true, get: function () { return findModules_1.findModulesAsync; } }); | ||
const mergeLinkingOptions_1 = require("./mergeLinkingOptions"); | ||
Object.defineProperty(exports, "getProjectPackageJsonPathAsync", { enumerable: true, get: function () { return mergeLinkingOptions_1.getProjectPackageJsonPathAsync; } }); | ||
Object.defineProperty(exports, "mergeLinkingOptionsAsync", { enumerable: true, get: function () { return mergeLinkingOptions_1.mergeLinkingOptionsAsync; } }); | ||
@@ -23,0 +24,0 @@ Object.defineProperty(exports, "resolveSearchPathsAsync", { enumerable: true, get: function () { return mergeLinkingOptions_1.resolveSearchPathsAsync; } }); |
import { SupportedPlatform } from '../types'; | ||
export declare function getLinkingImplementationForPlatform(platform: SupportedPlatform): any; | ||
/** | ||
* Get the possible path to the pnpm isolated modules folder. | ||
*/ | ||
export declare function getIsolatedModulesPath(packagePath: string, packageName: string): string | null; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getLinkingImplementationForPlatform = void 0; | ||
exports.getIsolatedModulesPath = exports.getLinkingImplementationForPlatform = void 0; | ||
const path_1 = __importDefault(require("path")); | ||
function getLinkingImplementationForPlatform(platform) { | ||
@@ -18,2 +22,20 @@ switch (platform) { | ||
exports.getLinkingImplementationForPlatform = getLinkingImplementationForPlatform; | ||
/** | ||
* Get the possible path to the pnpm isolated modules folder. | ||
*/ | ||
function getIsolatedModulesPath(packagePath, packageName) { | ||
// Check if the project is using isolated modules, by checking | ||
// if the parent dir of `packagePath` is a `node_modules` folder. | ||
// Isolated modules installs dependencies in small groups such as: | ||
// - /.pnpm/expo@50.x.x(...)/node_modules/@expo/cli | ||
// - /.pnpm/expo@50.x.x(...)/node_modules/expo | ||
// - /.pnpm/expo@50.x.x(...)/node_modules/expo-application | ||
// When isolated modules are detected, expand the `searchPaths` | ||
// to include possible nested dependencies. | ||
const maybeIsolatedModulesPath = path_1.default.join(packagePath, packageName.startsWith('@') && packageName.includes('/') ? '../..' : '..' // scoped packages are nested deeper | ||
); | ||
const isIsolatedModulesPath = path_1.default.basename(maybeIsolatedModulesPath) === 'node_modules'; | ||
return isIsolatedModulesPath ? maybeIsolatedModulesPath : null; | ||
} | ||
exports.getIsolatedModulesPath = getIsolatedModulesPath; | ||
//# sourceMappingURL=utils.js.map |
@@ -7,4 +7,6 @@ "use strict"; | ||
const commander_1 = __importDefault(require("commander")); | ||
const path_1 = __importDefault(require("path")); | ||
const ReactImportsPatcher_1 = require("./ReactImportsPatcher"); | ||
const autolinking_1 = require("./autolinking"); | ||
const reactNativeConfig_1 = require("./reactNativeConfig"); | ||
/** | ||
@@ -46,2 +48,31 @@ * Registers a command that only searches for available expo modules. | ||
} | ||
/** | ||
* Registry the `react-native-config` command. | ||
*/ | ||
function registerReactNativeConfigCommand() { | ||
return commander_1.default | ||
.command('react-native-config [paths...]') | ||
.option('-p, --platform [platform]', 'The platform that the resulting modules must support. Available options: "android", "ios"', 'ios') | ||
.addOption(new commander_1.default.Option('--project-root <projectRoot>', 'The path to the root of the project').default(process.cwd(), 'process.cwd()')) | ||
.option('-j, --json', 'Output results in the plain JSON format.', () => true, false) | ||
.action(async (paths, options) => { | ||
if (!['android', 'ios'].includes(options.platform)) { | ||
throw new Error(`Unsupported platform: ${options.platform}`); | ||
} | ||
const projectRoot = path_1.default.dirname(await (0, autolinking_1.getProjectPackageJsonPathAsync)(options.projectRoot)); | ||
const searchPaths = await (0, autolinking_1.resolveSearchPathsAsync)(paths, projectRoot); | ||
const providedOptions = { | ||
platform: options.platform, | ||
projectRoot, | ||
searchPaths, | ||
}; | ||
const results = await (0, reactNativeConfig_1.createReactNativeConfigAsync)(providedOptions); | ||
if (options.json) { | ||
console.log(JSON.stringify(results)); | ||
} | ||
else { | ||
console.log(require('util').inspect(results, false, null, true)); | ||
} | ||
}); | ||
} | ||
module.exports = async function (args) { | ||
@@ -94,2 +125,3 @@ // Searches for available expo modules. | ||
registerPatchReactImportsCommand(); | ||
registerReactNativeConfigCommand(); | ||
await commander_1.default | ||
@@ -96,0 +128,0 @@ .version(require('expo-modules-autolinking/package.json').version) |
@@ -9,2 +9,4 @@ # Changelog | ||
- Added `react-native-config` command to support core autolinking for react-native. ([#29818](https://github.com/expo/expo/pull/29818) by [@kudo](https://github.com/kudo)) | ||
### 🐛 Bug fixes | ||
@@ -11,0 +13,0 @@ |
const sharedPreset = require('expo-module-scripts/jest-preset-plugin'); | ||
module.exports = { | ||
...sharedPreset, | ||
roots: ['src', 'e2e'], | ||
roots: ['__mocks__', 'src', 'e2e'], | ||
}; |
{ | ||
"name": "expo-modules-autolinking", | ||
"version": "1.11.1", | ||
"version": "1.12.0-canary-20240625-2333e70", | ||
"description": "Scripts that autolink Expo modules.", | ||
@@ -39,3 +39,3 @@ "main": "build/index.js", | ||
"@types/fs-extra": "^9.0.11", | ||
"expo-module-scripts": "~3.5.0", | ||
"expo-module-scripts": "3.6.0-canary-20240625-2333e70", | ||
"minimatch": "^3.0.4", | ||
@@ -49,5 +49,7 @@ "tempy": "^0.7.1" | ||
"find-up": "^5.0.0", | ||
"fs-extra": "^9.1.0" | ||
"fs-extra": "^9.1.0", | ||
"resolve-from": "^5.0.0", | ||
"require-from-string": "^2.0.2" | ||
}, | ||
"gitHead": "ee4f30ef3b5fa567ad1bf94794197f7683fdd481" | ||
"gitHead": "2333e70a4bd3ac91895402dac77ae8ae0ed25995" | ||
} |
@@ -8,2 +8,3 @@ import chalk from 'chalk'; | ||
import { getProjectPackageJsonPathAsync, mergeLinkingOptionsAsync } from './mergeLinkingOptions'; | ||
import { getIsolatedModulesPath } from './utils'; | ||
import { requireAndResolveExpoModuleConfig } from '../ExpoModuleConfig'; | ||
@@ -47,16 +48,4 @@ import { PackageRevision, SearchOptions, SearchResults } from '../types'; | ||
// Check if the project is using isolated modules, by checking | ||
// if the parent dir of `packagePath` is a `node_modules` folder. | ||
// Isolated modules installs dependencies in small groups such as: | ||
// - /.pnpm/expo@50.x.x(...)/node_modules/@expo/cli | ||
// - /.pnpm/expo@50.x.x(...)/node_modules/expo | ||
// - /.pnpm/expo@50.x.x(...)/node_modules/expo-application | ||
// When isolated modules are detected, expand the `searchPaths` | ||
// to include possible nested dependencies. | ||
const maybeIsolatedModulesPath = path.join( | ||
packagePath, | ||
name.startsWith('@') && name.includes('/') ? '../..' : '..' // scoped packages are nested deeper | ||
); | ||
const isIsolatedModulesPath = path.basename(maybeIsolatedModulesPath) === 'node_modules'; | ||
if (isIsolatedModulesPath && !searchPaths.has(maybeIsolatedModulesPath)) { | ||
const maybeIsolatedModulesPath = getIsolatedModulesPath(packagePath, name); | ||
if (maybeIsolatedModulesPath) { | ||
searchPaths.add(maybeIsolatedModulesPath); | ||
@@ -63,0 +52,0 @@ } |
import { findModulesAsync } from './findModules'; | ||
import { mergeLinkingOptionsAsync, resolveSearchPathsAsync } from './mergeLinkingOptions'; | ||
import { | ||
getProjectPackageJsonPathAsync, | ||
mergeLinkingOptionsAsync, | ||
resolveSearchPathsAsync, | ||
} from './mergeLinkingOptions'; | ||
import { resolveExtraBuildDependenciesAsync, resolveModulesAsync } from './resolveModules'; | ||
@@ -8,2 +12,3 @@ import type { ModuleDescriptor, SearchOptions } from '../types'; | ||
findModulesAsync, | ||
getProjectPackageJsonPathAsync, | ||
mergeLinkingOptionsAsync, | ||
@@ -10,0 +15,0 @@ resolveExtraBuildDependenciesAsync, |
@@ -0,1 +1,3 @@ | ||
import path from 'path'; | ||
import { SupportedPlatform } from '../types'; | ||
@@ -16,1 +18,21 @@ | ||
} | ||
/** | ||
* Get the possible path to the pnpm isolated modules folder. | ||
*/ | ||
export function getIsolatedModulesPath(packagePath: string, packageName: string): string | null { | ||
// Check if the project is using isolated modules, by checking | ||
// if the parent dir of `packagePath` is a `node_modules` folder. | ||
// Isolated modules installs dependencies in small groups such as: | ||
// - /.pnpm/expo@50.x.x(...)/node_modules/@expo/cli | ||
// - /.pnpm/expo@50.x.x(...)/node_modules/expo | ||
// - /.pnpm/expo@50.x.x(...)/node_modules/expo-application | ||
// When isolated modules are detected, expand the `searchPaths` | ||
// to include possible nested dependencies. | ||
const maybeIsolatedModulesPath = path.join( | ||
packagePath, | ||
packageName.startsWith('@') && packageName.includes('/') ? '../..' : '..' // scoped packages are nested deeper | ||
); | ||
const isIsolatedModulesPath = path.basename(maybeIsolatedModulesPath) === 'node_modules'; | ||
return isIsolatedModulesPath ? maybeIsolatedModulesPath : null; | ||
} |
import commander from 'commander'; | ||
import path from 'path'; | ||
@@ -6,9 +7,12 @@ import { patchReactImportsAsync } from './ReactImportsPatcher'; | ||
findModulesAsync, | ||
generatePackageListAsync, | ||
getProjectPackageJsonPathAsync, | ||
mergeLinkingOptionsAsync, | ||
resolveExtraBuildDependenciesAsync, | ||
resolveModulesAsync, | ||
resolveSearchPathsAsync, | ||
verifySearchResults, | ||
generatePackageListAsync, | ||
mergeLinkingOptionsAsync, | ||
} from './autolinking'; | ||
import { | ||
import { type RNConfigCommandOptions, createReactNativeConfigAsync } from './reactNativeConfig'; | ||
import type { | ||
GenerateModulesProviderOptions, | ||
@@ -87,2 +91,40 @@ GenerateOptions, | ||
/** | ||
* Registry the `react-native-config` command. | ||
*/ | ||
function registerReactNativeConfigCommand() { | ||
return commander | ||
.command('react-native-config [paths...]') | ||
.option( | ||
'-p, --platform [platform]', | ||
'The platform that the resulting modules must support. Available options: "android", "ios"', | ||
'ios' | ||
) | ||
.addOption( | ||
new commander.Option( | ||
'--project-root <projectRoot>', | ||
'The path to the root of the project' | ||
).default(process.cwd(), 'process.cwd()') | ||
) | ||
.option<boolean>('-j, --json', 'Output results in the plain JSON format.', () => true, false) | ||
.action(async (paths, options) => { | ||
if (!['android', 'ios'].includes(options.platform)) { | ||
throw new Error(`Unsupported platform: ${options.platform}`); | ||
} | ||
const projectRoot = path.dirname(await getProjectPackageJsonPathAsync(options.projectRoot)); | ||
const searchPaths = await resolveSearchPathsAsync(paths, projectRoot); | ||
const providedOptions: RNConfigCommandOptions = { | ||
platform: options.platform, | ||
projectRoot, | ||
searchPaths, | ||
}; | ||
const results = await createReactNativeConfigAsync(providedOptions); | ||
if (options.json) { | ||
console.log(JSON.stringify(results)); | ||
} else { | ||
console.log(require('util').inspect(results, false, null, true)); | ||
} | ||
}); | ||
} | ||
module.exports = async function (args: string[]) { | ||
@@ -159,2 +201,3 @@ // Searches for available expo modules. | ||
registerPatchReactImportsCommand(); | ||
registerReactNativeConfigCommand(); | ||
@@ -161,0 +204,0 @@ await commander |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
370816
30.07%106
35.9%5189
31.77%7
40%1
Infinity%19
58.33%1
Infinity%+ Added
+ Added
+ Added
+ Added