create-expo-module
Advanced tools
Comparing version
@@ -12,3 +12,3 @@ "use strict"; | ||
const find_up_1 = __importDefault(require("find-up")); | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const getenv_1 = require("getenv"); | ||
@@ -70,3 +70,3 @@ const path_1 = __importDefault(require("path")); | ||
} | ||
await fs_extra_1.default.ensureDir(targetDir); | ||
await fs_1.default.promises.mkdir(targetDir, { recursive: true }); | ||
await confirmTargetDirAsync(targetDir); | ||
@@ -102,10 +102,10 @@ options.target = targetDir; | ||
// We should remove it after all. | ||
await fs_extra_1.default.remove(packagePath); | ||
await fs_1.default.promises.rm(packagePath, { recursive: true, force: true }); | ||
} | ||
if (!options.local && data.type !== 'local') { | ||
if (!options.withReadme) { | ||
await fs_extra_1.default.remove(path_1.default.join(targetDir, 'README.md')); | ||
await fs_1.default.promises.rm(path_1.default.join(targetDir, 'README.md'), { force: true }); | ||
} | ||
if (!options.withChangelog) { | ||
await fs_extra_1.default.remove(path_1.default.join(targetDir, 'CHANGELOG.md')); | ||
await fs_1.default.promises.rm(path_1.default.join(targetDir, 'CHANGELOG.md'), { force: true }); | ||
} | ||
@@ -150,3 +150,3 @@ if (options.example) { | ||
const baseDir = dir ? path_1.default.join(root, dir) : root; | ||
for (const file of await fs_extra_1.default.readdir(baseDir)) { | ||
for (const file of await fs_1.default.promises.readdir(baseDir)) { | ||
const relativePath = dir ? path_1.default.join(dir, file) : file; | ||
@@ -157,3 +157,3 @@ if (IGNORES_PATHS.includes(relativePath) || IGNORES_PATHS.includes(file)) { | ||
const fullPath = path_1.default.join(baseDir, file); | ||
const stat = await fs_extra_1.default.lstat(fullPath); | ||
const stat = await fs_1.default.promises.lstat(fullPath); | ||
if (stat.isDirectory()) { | ||
@@ -250,5 +250,8 @@ files.push(...(await getFilesAsync(root, relativePath))); | ||
const toPath = path_1.default.join(targetPath, renderedRelativePath); | ||
const template = await fs_extra_1.default.readFile(fromPath, { encoding: 'utf8' }); | ||
const template = await fs_1.default.promises.readFile(fromPath, 'utf8'); | ||
const renderedContent = ejs_1.default.render(template, data); | ||
await fs_extra_1.default.outputFile(toPath, renderedContent, { encoding: 'utf8' }); | ||
if (!fs_1.default.existsSync(path_1.default.dirname(toPath))) { | ||
await fs_1.default.promises.mkdir(path_1.default.dirname(toPath), { recursive: true }); | ||
} | ||
await fs_1.default.promises.writeFile(toPath, renderedContent, 'utf8'); | ||
} | ||
@@ -335,3 +338,3 @@ } | ||
async function confirmTargetDirAsync(targetDir) { | ||
const files = await fs_extra_1.default.readdir(targetDir); | ||
const files = await fs_1.default.promises.readdir(targetDir); | ||
if (files.length === 0) { | ||
@@ -338,0 +341,0 @@ return; |
@@ -8,3 +8,3 @@ "use strict"; | ||
const spawn_async_1 = __importDefault(require("@expo/spawn-async")); | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const getenv_1 = __importDefault(require("getenv")); | ||
@@ -29,3 +29,3 @@ const os_1 = __importDefault(require("os")); | ||
const appTargetPath = path_1.default.join(targetDir, 'example'); | ||
if (!(await fs_extra_1.default.pathExists(appTargetPath))) { | ||
if (!fs_1.default.existsSync(appTargetPath)) { | ||
// The template doesn't include the example app, so just skip this phase | ||
@@ -54,8 +54,8 @@ return; | ||
// Cleanup the "example" dir | ||
await fs_extra_1.default.rmdir(appTargetPath); | ||
await fs_1.default.promises.rm(appTargetPath, { recursive: true, force: true }); | ||
// Clean up the ".git" from example app | ||
// note, this directory has contents, rmdir will throw | ||
await fs_extra_1.default.remove(path_1.default.join(appTmpPath, '.git')); | ||
await fs_1.default.promises.rm(path_1.default.join(appTmpPath, '.git'), { recursive: true, force: true }); | ||
// Move the temporary example app to "example" dir | ||
await fs_extra_1.default.rename(appTmpPath, appTargetPath); | ||
await fs_1.default.promises.rename(appTmpPath, appTargetPath); | ||
await addMissingAppConfigFields(appTargetPath, data); | ||
@@ -86,9 +86,24 @@ step.succeed('Configured the example app'); | ||
/** | ||
* Copies files from one directory to another. | ||
* Moves files from one directory to another. | ||
*/ | ||
async function moveFiles(fromPath, toPath) { | ||
for (const file of await fs_extra_1.default.readdir(fromPath)) { | ||
await fs_extra_1.default.move(path_1.default.join(fromPath, file), path_1.default.join(toPath, file), { | ||
overwrite: true, | ||
}); | ||
// Make sure that the target directory exists | ||
await fs_1.default.promises.mkdir(toPath, { recursive: true }); | ||
for (const file of await fs_1.default.promises.readdir(fromPath)) { | ||
// First, remove target, so there are no conflicts (explicit overwrite) | ||
await fs_1.default.promises.rm(path_1.default.join(toPath, file), { force: true, recursive: true }); | ||
try { | ||
// Then, rename the file to move it to the destination | ||
await fs_1.default.promises.rename(path_1.default.join(fromPath, file), path_1.default.join(toPath, file)); | ||
} | ||
catch (error) { | ||
if (error.code === 'EXDEV') { | ||
// If the file is on a different device/disk, copy it instead and delete the original | ||
await fs_1.default.promises.cp(fromPath, toPath, { errorOnExist: true, recursive: true }); | ||
await fs_1.default.promises.rm(fromPath, { recursive: true, force: true }); | ||
} | ||
else { | ||
throw error; | ||
} | ||
} | ||
} | ||
@@ -101,3 +116,4 @@ } | ||
const appConfigPath = path_1.default.join(appPath, 'app.json'); | ||
const appConfig = await fs_extra_1.default.readJson(appConfigPath); | ||
const appConfigContent = await fs_1.default.promises.readFile(appConfigPath, 'utf8'); | ||
const appConfig = JSON.parse(appConfigContent); | ||
const appId = `${data.project.package}.example`; | ||
@@ -114,5 +130,3 @@ // Android package name needs to be added to app.json | ||
appConfig.expo.ios.bundleIdentifier = appId; | ||
await fs_extra_1.default.writeJson(appConfigPath, appConfig, { | ||
spaces: 2, | ||
}); | ||
await fs_1.default.promises.writeFile(appConfigPath, JSON.stringify(appConfig, null, 2), 'utf8'); | ||
} | ||
@@ -125,3 +139,4 @@ /** | ||
const packageJsonPath = path_1.default.join(appPath, 'package.json'); | ||
const packageJson = await fs_extra_1.default.readJson(packageJsonPath); | ||
const packageJsonContent = await fs_1.default.promises.readFile(packageJsonPath, 'utf8'); | ||
const packageJson = JSON.parse(packageJsonContent); | ||
if (!packageJson.expo) { | ||
@@ -139,5 +154,3 @@ packageJson.expo = {}; | ||
} | ||
await fs_extra_1.default.writeJson(packageJsonPath, packageJson, { | ||
spaces: 2, | ||
}); | ||
await fs_1.default.promises.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8'); | ||
} | ||
@@ -144,0 +157,0 @@ /** |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -7,3 +30,2 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
exports.eventCreateExpoModule = exports.logEventAsync = exports.getTelemetryClient = void 0; | ||
const getUserState_1 = require("@expo/config/build/getUserState"); | ||
const json_file_1 = __importDefault(require("@expo/json-file")); | ||
@@ -13,3 +35,4 @@ const rudder_sdk_node_1 = __importDefault(require("@expo/rudder-sdk-node")); | ||
const getenv_1 = require("getenv"); | ||
const os_1 = __importDefault(require("os")); | ||
const os_1 = __importStar(require("os")); | ||
const path = __importStar(require("path")); | ||
const packageJson = require('../package.json'); | ||
@@ -37,5 +60,23 @@ /** If telemetry is disabled by the user */ | ||
exports.getTelemetryClient = getTelemetryClient; | ||
// The ~/.expo directory is used to store authentication sessions, | ||
// which are shared between EAS CLI and Expo CLI. | ||
function getExpoHomeDirectory() { | ||
const home = (0, os_1.homedir)(); | ||
if (process.env.__UNSAFE_EXPO_HOME_DIRECTORY) { | ||
return process.env.__UNSAFE_EXPO_HOME_DIRECTORY; | ||
} | ||
else if ((0, getenv_1.boolish)('EXPO_STAGING', false)) { | ||
return path.join(home, '.expo-staging'); | ||
} | ||
else if ((0, getenv_1.boolish)('EXPO_LOCAL', false)) { | ||
return path.join(home, '.expo-local'); | ||
} | ||
return path.join(home, '.expo'); | ||
} | ||
function getUserStatePath() { | ||
return path.join(getExpoHomeDirectory(), 'state.json'); | ||
} | ||
/** Get the randomly generated anonymous ID from the persistent storage, see @expo/cli */ | ||
async function getTelemetryIdAsync() { | ||
const settings = new json_file_1.default((0, getUserState_1.getUserStatePath)(), { | ||
const settings = new json_file_1.default(getUserStatePath(), { | ||
ensureDir: true, | ||
@@ -42,0 +83,0 @@ jsonParseErrorDefault: {}, |
{ | ||
"name": "create-expo-module", | ||
"version": "0.8.11", | ||
"version": "0.8.12-canary-20250331-817737a", | ||
"description": "The script to create the Expo module", | ||
@@ -36,4 +36,4 @@ "main": "build/create-expo-module.js", | ||
"dependencies": { | ||
"@expo/config": "~10.0.11", | ||
"@expo/json-file": "^9.0.2", | ||
"@expo/config": "11.0.0-canary-20250331-817737a", | ||
"@expo/json-file": "9.0.3-canary-20250331-817737a", | ||
"@expo/rudder-sdk-node": "^1.1.1", | ||
@@ -48,3 +48,2 @@ "@expo/spawn-async": "^1.7.2", | ||
"find-up": "^5.0.0", | ||
"fs-extra": "^11.2.0", | ||
"getenv": "^1.0.0", | ||
@@ -60,5 +59,4 @@ "ora": "^5.4.1", | ||
"@types/prompts": "^2.4.9", | ||
"expo-module-scripts": "^4.0.4" | ||
}, | ||
"gitHead": "efc676ef6dbe6c2eaed19c1a31abb79a935f583a" | ||
"expo-module-scripts": "4.0.5-canary-20250331-817737a" | ||
} | ||
} |
@@ -7,3 +7,3 @@ import spawnAsync from '@expo/spawn-async'; | ||
import findUp from 'find-up'; | ||
import fs from 'fs-extra'; | ||
import fs from 'fs'; | ||
import { boolish } from 'getenv'; | ||
@@ -99,3 +99,3 @@ import path from 'path'; | ||
} | ||
await fs.ensureDir(targetDir); | ||
await fs.promises.mkdir(targetDir, { recursive: true }); | ||
await confirmTargetDirAsync(targetDir); | ||
@@ -138,10 +138,10 @@ | ||
// We should remove it after all. | ||
await fs.remove(packagePath); | ||
await fs.promises.rm(packagePath, { recursive: true, force: true }); | ||
} | ||
if (!options.local && data.type !== 'local') { | ||
if (!options.withReadme) { | ||
await fs.remove(path.join(targetDir, 'README.md')); | ||
await fs.promises.rm(path.join(targetDir, 'README.md'), { force: true }); | ||
} | ||
if (!options.withChangelog) { | ||
await fs.remove(path.join(targetDir, 'CHANGELOG.md')); | ||
await fs.promises.rm(path.join(targetDir, 'CHANGELOG.md'), { force: true }); | ||
} | ||
@@ -188,3 +188,3 @@ if (options.example) { | ||
for (const file of await fs.readdir(baseDir)) { | ||
for (const file of await fs.promises.readdir(baseDir)) { | ||
const relativePath = dir ? path.join(dir, file) : file; | ||
@@ -197,4 +197,3 @@ | ||
const fullPath = path.join(baseDir, file); | ||
const stat = await fs.lstat(fullPath); | ||
const stat = await fs.promises.lstat(fullPath); | ||
if (stat.isDirectory()) { | ||
@@ -316,6 +315,9 @@ files.push(...(await getFilesAsync(root, relativePath))); | ||
const toPath = path.join(targetPath, renderedRelativePath); | ||
const template = await fs.readFile(fromPath, { encoding: 'utf8' }); | ||
const template = await fs.promises.readFile(fromPath, 'utf8'); | ||
const renderedContent = ejs.render(template, data); | ||
await fs.outputFile(toPath, renderedContent, { encoding: 'utf8' }); | ||
if (!fs.existsSync(path.dirname(toPath))) { | ||
await fs.promises.mkdir(path.dirname(toPath), { recursive: true }); | ||
} | ||
await fs.promises.writeFile(toPath, renderedContent, 'utf8'); | ||
} | ||
@@ -428,4 +430,3 @@ } | ||
async function confirmTargetDirAsync(targetDir: string): Promise<void> { | ||
const files = await fs.readdir(targetDir); | ||
const files = await fs.promises.readdir(targetDir); | ||
if (files.length === 0) { | ||
@@ -432,0 +433,0 @@ return; |
import spawnAsync from '@expo/spawn-async'; | ||
import fs from 'fs-extra'; | ||
import fs from 'fs'; | ||
import getenv from 'getenv'; | ||
@@ -35,3 +35,3 @@ import os from 'os'; | ||
if (!(await fs.pathExists(appTargetPath))) { | ||
if (!fs.existsSync(appTargetPath)) { | ||
// The template doesn't include the example app, so just skip this phase | ||
@@ -65,10 +65,10 @@ return; | ||
// Cleanup the "example" dir | ||
await fs.rmdir(appTargetPath); | ||
await fs.promises.rm(appTargetPath, { recursive: true, force: true }); | ||
// Clean up the ".git" from example app | ||
// note, this directory has contents, rmdir will throw | ||
await fs.remove(path.join(appTmpPath, '.git')); | ||
await fs.promises.rm(path.join(appTmpPath, '.git'), { recursive: true, force: true }); | ||
// Move the temporary example app to "example" dir | ||
await fs.rename(appTmpPath, appTargetPath); | ||
await fs.promises.rename(appTmpPath, appTargetPath); | ||
@@ -108,9 +108,22 @@ await addMissingAppConfigFields(appTargetPath, data); | ||
/** | ||
* Copies files from one directory to another. | ||
* Moves files from one directory to another. | ||
*/ | ||
async function moveFiles(fromPath: string, toPath: string): Promise<void> { | ||
for (const file of await fs.readdir(fromPath)) { | ||
await fs.move(path.join(fromPath, file), path.join(toPath, file), { | ||
overwrite: true, | ||
}); | ||
// Make sure that the target directory exists | ||
await fs.promises.mkdir(toPath, { recursive: true }); | ||
for (const file of await fs.promises.readdir(fromPath)) { | ||
// First, remove target, so there are no conflicts (explicit overwrite) | ||
await fs.promises.rm(path.join(toPath, file), { force: true, recursive: true }); | ||
try { | ||
// Then, rename the file to move it to the destination | ||
await fs.promises.rename(path.join(fromPath, file), path.join(toPath, file)); | ||
} catch (error: any) { | ||
if (error.code === 'EXDEV') { | ||
// If the file is on a different device/disk, copy it instead and delete the original | ||
await fs.promises.cp(fromPath, toPath, { errorOnExist: true, recursive: true }); | ||
await fs.promises.rm(fromPath, { recursive: true, force: true }); | ||
} else { | ||
throw error; | ||
} | ||
} | ||
} | ||
@@ -124,3 +137,4 @@ } | ||
const appConfigPath = path.join(appPath, 'app.json'); | ||
const appConfig = await fs.readJson(appConfigPath); | ||
const appConfigContent = await fs.promises.readFile(appConfigPath, 'utf8'); | ||
const appConfig = JSON.parse(appConfigContent); | ||
const appId = `${data.project.package}.example`; | ||
@@ -140,5 +154,3 @@ | ||
await fs.writeJson(appConfigPath, appConfig, { | ||
spaces: 2, | ||
}); | ||
await fs.promises.writeFile(appConfigPath, JSON.stringify(appConfig, null, 2), 'utf8'); | ||
} | ||
@@ -152,3 +164,4 @@ | ||
const packageJsonPath = path.join(appPath, 'package.json'); | ||
const packageJson = await fs.readJson(packageJsonPath); | ||
const packageJsonContent = await fs.promises.readFile(packageJsonPath, 'utf8'); | ||
const packageJson = JSON.parse(packageJsonContent); | ||
@@ -170,5 +183,3 @@ if (!packageJson.expo) { | ||
await fs.writeJson(packageJsonPath, packageJson, { | ||
spaces: 2, | ||
}); | ||
await fs.promises.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8'); | ||
} | ||
@@ -175,0 +186,0 @@ |
@@ -1,2 +0,1 @@ | ||
import { getUserStatePath } from '@expo/config/build/getUserState'; | ||
import JsonFile from '@expo/json-file'; | ||
@@ -6,3 +5,4 @@ import TelemetryClient from '@expo/rudder-sdk-node'; | ||
import { boolish } from 'getenv'; | ||
import os from 'os'; | ||
import os, { homedir } from 'os'; | ||
import * as path from 'path'; | ||
@@ -41,2 +41,20 @@ import { CommandOptions } from './types'; | ||
// The ~/.expo directory is used to store authentication sessions, | ||
// which are shared between EAS CLI and Expo CLI. | ||
function getExpoHomeDirectory() { | ||
const home = homedir(); | ||
if (process.env.__UNSAFE_EXPO_HOME_DIRECTORY) { | ||
return process.env.__UNSAFE_EXPO_HOME_DIRECTORY; | ||
} else if (boolish('EXPO_STAGING', false)) { | ||
return path.join(home, '.expo-staging'); | ||
} else if (boolish('EXPO_LOCAL', false)) { | ||
return path.join(home, '.expo-local'); | ||
} | ||
return path.join(home, '.expo'); | ||
} | ||
function getUserStatePath() { | ||
return path.join(getExpoHomeDirectory(), 'state.json'); | ||
} | ||
/** Get the randomly generated anonymous ID from the persistent storage, see @expo/cli */ | ||
@@ -43,0 +61,0 @@ async function getTelemetryIdAsync() { |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
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
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
156379
5.67%15
-6.25%2245
4.03%10
25%+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed