deslop-js 0.0.13 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -33,10 +33,10 @@ let fast_glob = require("fast-glob");
33
33
  fast_glob = __toESM(fast_glob, 1);
34
34
  let node_fs_promises = require("node:fs/promises");
35
35
  let oxc_parser = require("oxc-parser");
36
- let oxc_resolver = require("oxc-resolver");
37
- let minimatch = require("minimatch");
38
36
  let typescript = require("typescript");
39
37
  typescript = __toESM(typescript, 1);
38
+ let oxc_resolver = require("oxc-resolver");
39
+ let minimatch = require("minimatch");
40
40
 
41
41
  //#region src/constants.ts
42
42
  const DEFAULT_EXTENSIONS = [
@@ -3166,6 +3166,196 @@ const discoverMobileEntryPoints = (directory) => {
3166
3166
  }
3167
3167
  };
3168
3168
 
3169
+ //#endregion
3170
+ //#region src/collect/expo-config-plugin-entries.ts
3171
+ const EXPO_CONFIG_FILE_GLOBS = ["app.config.{ts,mts,cts,js,mjs,cjs}", "app.json"];
3172
+ const NESTED_EXPO_CONFIG_FILE_GLOBS = [
3173
+ ...EXPO_CONFIG_FILE_GLOBS,
3174
+ "**/app.config.{ts,mts,cts,js,mjs,cjs}",
3175
+ "**/app.json"
3176
+ ];
3177
+ const EXPO_REACT_NATIVE_DEPENDENCIES = new Set(["expo", "react-native"]);
3178
+ const EXPO_PLUGIN_RESOLVABLE_EXTENSIONS = SOURCE_EXTENSIONS$3.map((sourceExtension) => `.${sourceExtension}`);
3179
+ const isRecord = (value) => typeof value === "object" && value !== null;
3180
+ const isExpoOrReactNativeWorkspace = (dependencies) => [...EXPO_REACT_NATIVE_DEPENDENCIES].some((dependencyName) => dependencyName in dependencies);
3181
+ const isLocalExpoPluginPath = (value) => (value.startsWith("./") || value.startsWith("../")) && !value.includes("*") && !value.includes("?");
3182
+ const isFile = (filePath) => {
3183
+ try {
3184
+ return (0, node_fs.statSync)(filePath).isFile();
3185
+ } catch {
3186
+ return false;
3187
+ }
3188
+ };
3189
+ const resolveExpoPluginPath = (configDirectory, pluginPath) => {
3190
+ const candidatePath = (0, node_path.resolve)(configDirectory, pluginPath);
3191
+ if (isFile(candidatePath)) return candidatePath;
3192
+ for (const extension of EXPO_PLUGIN_RESOLVABLE_EXTENSIONS) {
3193
+ const candidatePathWithExtension = `${candidatePath}${extension}`;
3194
+ if (isFile(candidatePathWithExtension)) return candidatePathWithExtension;
3195
+ }
3196
+ for (const extension of EXPO_PLUGIN_RESOLVABLE_EXTENSIONS) {
3197
+ const indexCandidatePath = (0, node_path.join)(candidatePath, `index${extension}`);
3198
+ if (isFile(indexCandidatePath)) return indexCandidatePath;
3199
+ }
3200
+ };
3201
+ const addExpoPluginEntry = (entries, rootDirectory, configDirectory, pluginPath) => {
3202
+ if (!isLocalExpoPluginPath(pluginPath)) return;
3203
+ const resolvedPath = resolveExpoPluginPath(configDirectory, pluginPath);
3204
+ if (!resolvedPath) return;
3205
+ const relativePath = (0, node_path.relative)(rootDirectory, resolvedPath);
3206
+ if (relativePath !== "" && (relativePath.startsWith("..") || (0, node_path.isAbsolute)(relativePath))) return;
3207
+ entries.add(resolvedPath);
3208
+ };
3209
+ const getPropertyName = (name) => {
3210
+ if (typescript.default.isIdentifier(name) || typescript.default.isStringLiteral(name) || typescript.default.isNumericLiteral(name)) return name.text;
3211
+ };
3212
+ const unwrapExpression = (expression) => {
3213
+ let currentExpression = expression;
3214
+ while (typescript.default.isParenthesizedExpression(currentExpression)) currentExpression = currentExpression.expression;
3215
+ return currentExpression;
3216
+ };
3217
+ const collectExpoPluginPathsFromArray = (array, entries, rootDirectory, configDirectory) => {
3218
+ for (const element of array.elements) {
3219
+ if (typescript.default.isStringLiteral(element) || typescript.default.isNoSubstitutionTemplateLiteral(element)) {
3220
+ addExpoPluginEntry(entries, rootDirectory, configDirectory, element.text);
3221
+ continue;
3222
+ }
3223
+ if (typescript.default.isArrayLiteralExpression(element)) {
3224
+ const [pluginName] = element.elements;
3225
+ if (pluginName && (typescript.default.isStringLiteral(pluginName) || typescript.default.isNoSubstitutionTemplateLiteral(pluginName))) addExpoPluginEntry(entries, rootDirectory, configDirectory, pluginName.text);
3226
+ }
3227
+ }
3228
+ };
3229
+ const collectExpoPluginPathsFromConfigObject = (objectLiteral, entries, rootDirectory, configDirectory) => {
3230
+ for (const property of objectLiteral.properties) if (typescript.default.isPropertyAssignment(property) && getPropertyName(property.name) === "plugins" && typescript.default.isArrayLiteralExpression(property.initializer)) collectExpoPluginPathsFromArray(property.initializer, entries, rootDirectory, configDirectory);
3231
+ };
3232
+ const collectReturnedExpoConfigPluginPaths = (body, entries, rootDirectory, configDirectory) => {
3233
+ if (!typescript.default.isBlock(body)) {
3234
+ const expression = unwrapExpression(body);
3235
+ if (typescript.default.isObjectLiteralExpression(expression)) collectExpoPluginPathsFromConfigObject(expression, entries, rootDirectory, configDirectory);
3236
+ return;
3237
+ }
3238
+ const visit = (node) => {
3239
+ if (typescript.default.isFunctionDeclaration(node) || typescript.default.isFunctionExpression(node) || typescript.default.isArrowFunction(node)) return;
3240
+ if (typescript.default.isReturnStatement(node) && node.expression) {
3241
+ const expression = unwrapExpression(node.expression);
3242
+ if (typescript.default.isObjectLiteralExpression(expression)) collectExpoPluginPathsFromConfigObject(expression, entries, rootDirectory, configDirectory);
3243
+ return;
3244
+ }
3245
+ typescript.default.forEachChild(node, visit);
3246
+ };
3247
+ visit(body);
3248
+ };
3249
+ const collectExpoPluginPathsFromConfigExpression = (expression, entries, rootDirectory, configDirectory, bindings, seenIdentifiers = /* @__PURE__ */ new Set()) => {
3250
+ const configExpression = unwrapExpression(expression);
3251
+ if (typescript.default.isObjectLiteralExpression(configExpression)) {
3252
+ collectExpoPluginPathsFromConfigObject(configExpression, entries, rootDirectory, configDirectory);
3253
+ return;
3254
+ }
3255
+ if (typescript.default.isIdentifier(configExpression)) {
3256
+ if (seenIdentifiers.has(configExpression.text)) return;
3257
+ seenIdentifiers.add(configExpression.text);
3258
+ const boundExpression = bindings.expressions.get(configExpression.text);
3259
+ if (boundExpression) {
3260
+ collectExpoPluginPathsFromConfigExpression(boundExpression, entries, rootDirectory, configDirectory, bindings, seenIdentifiers);
3261
+ return;
3262
+ }
3263
+ const boundFunction = bindings.functions.get(configExpression.text);
3264
+ if (boundFunction?.body) collectReturnedExpoConfigPluginPaths(boundFunction.body, entries, rootDirectory, configDirectory);
3265
+ return;
3266
+ }
3267
+ if (typescript.default.isArrowFunction(configExpression)) {
3268
+ collectReturnedExpoConfigPluginPaths(configExpression.body, entries, rootDirectory, configDirectory);
3269
+ return;
3270
+ }
3271
+ if (typescript.default.isFunctionExpression(configExpression) && configExpression.body) collectReturnedExpoConfigPluginPaths(configExpression.body, entries, rootDirectory, configDirectory);
3272
+ };
3273
+ const hasDefaultExportModifier = (node) => Boolean(typescript.default.canHaveModifiers(node) && typescript.default.getModifiers(node)?.some((modifier) => modifier.kind === typescript.default.SyntaxKind.DefaultKeyword));
3274
+ const isModuleExportsAssignmentTarget = (node) => typescript.default.isPropertyAccessExpression(node) && typescript.default.isIdentifier(node.expression) && node.expression.text === "module" && node.name.text === "exports";
3275
+ const collectStaticConfigBindings = (sourceFile) => {
3276
+ const expressions = /* @__PURE__ */ new Map();
3277
+ const functions = /* @__PURE__ */ new Map();
3278
+ for (const statement of sourceFile.statements) {
3279
+ if (typescript.default.isVariableStatement(statement)) {
3280
+ for (const declaration of statement.declarationList.declarations) if (typescript.default.isIdentifier(declaration.name) && declaration.initializer) expressions.set(declaration.name.text, declaration.initializer);
3281
+ continue;
3282
+ }
3283
+ if (typescript.default.isFunctionDeclaration(statement) && statement.name) functions.set(statement.name.text, statement);
3284
+ }
3285
+ return {
3286
+ expressions,
3287
+ functions
3288
+ };
3289
+ };
3290
+ const collectExpoPluginPathsFromAppConfig = (configPath, entries, rootDirectory) => {
3291
+ const extension = (0, node_path.extname)(configPath);
3292
+ const sourceFile = typescript.default.createSourceFile(configPath, (0, node_fs.readFileSync)(configPath, "utf8"), typescript.default.ScriptTarget.Latest, true, extension === ".ts" || extension === ".mts" || extension === ".cts" ? typescript.default.ScriptKind.TS : typescript.default.ScriptKind.JS);
3293
+ const configDirectory = (0, node_path.dirname)(configPath);
3294
+ const bindings = collectStaticConfigBindings(sourceFile);
3295
+ const visit = (node) => {
3296
+ if (typescript.default.isExportAssignment(node)) {
3297
+ collectExpoPluginPathsFromConfigExpression(node.expression, entries, rootDirectory, configDirectory, bindings);
3298
+ return;
3299
+ }
3300
+ if (typescript.default.isFunctionDeclaration(node) && hasDefaultExportModifier(node) && node.body) {
3301
+ collectReturnedExpoConfigPluginPaths(node.body, entries, rootDirectory, configDirectory);
3302
+ return;
3303
+ }
3304
+ if (typescript.default.isBinaryExpression(node) && node.operatorToken.kind === typescript.default.SyntaxKind.EqualsToken && isModuleExportsAssignmentTarget(node.left)) {
3305
+ collectExpoPluginPathsFromConfigExpression(node.right, entries, rootDirectory, configDirectory, bindings);
3306
+ return;
3307
+ }
3308
+ typescript.default.forEachChild(node, visit);
3309
+ };
3310
+ visit(sourceFile);
3311
+ };
3312
+ const collectPluginPathsFromJsonValue = (value) => {
3313
+ if (!Array.isArray(value)) return [];
3314
+ const pluginPaths = [];
3315
+ for (const plugin of value) {
3316
+ if (typeof plugin === "string") {
3317
+ pluginPaths.push(plugin);
3318
+ continue;
3319
+ }
3320
+ if (Array.isArray(plugin) && typeof plugin[0] === "string") pluginPaths.push(plugin[0]);
3321
+ }
3322
+ return pluginPaths;
3323
+ };
3324
+ const collectExpoPluginPathsFromAppJson = (configPath, entries, rootDirectory) => {
3325
+ const parsedJson = JSON.parse((0, node_fs.readFileSync)(configPath, "utf8"));
3326
+ const configDirectory = (0, node_path.dirname)(configPath);
3327
+ if (!isRecord(parsedJson)) return;
3328
+ const expoConfig = parsedJson.expo;
3329
+ const expoPluginPaths = isRecord(expoConfig) ? collectPluginPathsFromJsonValue(expoConfig.plugins) : [];
3330
+ for (const pluginPath of [...expoPluginPaths, ...collectPluginPathsFromJsonValue(parsedJson.plugins)]) addExpoPluginEntry(entries, rootDirectory, configDirectory, pluginPath);
3331
+ };
3332
+ const collectExpoPluginPathsFromConfig = (configPath, entries, rootDirectory) => {
3333
+ try {
3334
+ if ((0, node_path.basename)(configPath) === "app.json") {
3335
+ collectExpoPluginPathsFromAppJson(configPath, entries, rootDirectory);
3336
+ return;
3337
+ }
3338
+ collectExpoPluginPathsFromAppConfig(configPath, entries, rootDirectory);
3339
+ } catch {}
3340
+ };
3341
+ const extractExpoConfigPluginEntries = (directory, dependencies, rootDirectory = directory, includeNestedConfigs = true) => {
3342
+ if (!isExpoOrReactNativeWorkspace(dependencies)) return [];
3343
+ const entries = /* @__PURE__ */ new Set();
3344
+ const configPaths = fast_glob.default.sync(includeNestedConfigs ? NESTED_EXPO_CONFIG_FILE_GLOBS : EXPO_CONFIG_FILE_GLOBS, {
3345
+ cwd: directory,
3346
+ absolute: true,
3347
+ onlyFiles: true,
3348
+ ignore: [
3349
+ "**/node_modules/**",
3350
+ "**/dist/**",
3351
+ "**/build/**"
3352
+ ],
3353
+ deep: 6
3354
+ });
3355
+ for (const configPath of configPaths) collectExpoPluginPathsFromConfig(configPath, entries, rootDirectory);
3356
+ return [...entries];
3357
+ };
3358
+
3169
3359
  //#endregion
3170
3360
  //#region src/resolver/source-path.ts
3171
3361
  const SOURCE_EXTENSIONS$1 = [
@@ -3589,6 +3779,11 @@ const resolveEntries = async (config) => {
3589
3779
  for (const workspacePackage of entryEligiblePackages) tsConfigIncludeEntries.push(...extractTsConfigIncludeFilesEntries(workspacePackage.directory));
3590
3780
  const configStringEntries = extractConfigStringReferencedEntries(absoluteRoot);
3591
3781
  for (const workspacePackage of entryEligiblePackages) configStringEntries.push(...extractConfigStringReferencedEntries(workspacePackage.directory));
3782
+ const expoConfigPluginEntries = extractExpoConfigPluginEntries(absoluteRoot, readPackageJsonDependencies((0, node_path.join)(absoluteRoot, "package.json")), absoluteRoot, false);
3783
+ for (const workspacePackage of entryEligiblePackages) {
3784
+ const workspacePackageDependencies = readPackageJsonDependencies((0, node_path.join)(workspacePackage.directory, "package.json"));
3785
+ expoConfigPluginEntries.push(...extractExpoConfigPluginEntries(workspacePackage.directory, workspacePackageDependencies, absoluteRoot));
3786
+ }
3592
3787
  const sectionsModuleEntries = extractSectionsModuleEntries(absoluteRoot);
3593
3788
  const wranglerEntries = extractWranglerEntries(absoluteRoot);
3594
3789
  for (const workspacePackage of entryEligiblePackages) wranglerEntries.push(...extractWranglerEntries(workspacePackage.directory));
@@ -3617,6 +3812,7 @@ const resolveEntries = async (config) => {
3617
3812
  ...webWorkerEntries,
3618
3813
  ...tsConfigIncludeEntries,
3619
3814
  ...configStringEntries,
3815
+ ...expoConfigPluginEntries,
3620
3816
  ...sectionsModuleEntries,
3621
3817
  ...wranglerEntries,
3622
3818
  ...pluginFileEntries,
@@ -5492,7 +5688,7 @@ const FRAMEWORK_PATTERNS = [
5492
5688
  "app/_layout.{ts,tsx,js,jsx}",
5493
5689
  "app/index.{ts,tsx,js,jsx}"
5494
5690
  ],
5495
- alwaysUsed: ["app.json", "app.config.{ts,js}"]
5691
+ alwaysUsed: ["app.json", "app.config.{ts,mts,cts,js,mjs,cjs}"]
5496
5692
  },
5497
5693
  {
5498
5694
  enablers: ["wrangler"],
package/dist/index.mjs CHANGED
@@ -3,9 +3,9 @@ import { existsSync, readFileSync, statSync } from "node:fs";
3
3
  import fg from "fast-glob";
4
4
  import { readFile } from "node:fs/promises";
5
5
  import { parseSync } from "oxc-parser";
6
+ import ts from "typescript";
6
7
  import { ResolverFactory } from "oxc-resolver";
7
8
  import { minimatch } from "minimatch";
8
- import ts from "typescript";
9
9
 
10
10
  //#region src/constants.ts
11
11
  const DEFAULT_EXTENSIONS = [
@@ -3135,6 +3135,196 @@ const discoverMobileEntryPoints = (directory) => {
3135
3135
  }
3136
3136
  };
3137
3137
 
3138
+ //#endregion
3139
+ //#region src/collect/expo-config-plugin-entries.ts
3140
+ const EXPO_CONFIG_FILE_GLOBS = ["app.config.{ts,mts,cts,js,mjs,cjs}", "app.json"];
3141
+ const NESTED_EXPO_CONFIG_FILE_GLOBS = [
3142
+ ...EXPO_CONFIG_FILE_GLOBS,
3143
+ "**/app.config.{ts,mts,cts,js,mjs,cjs}",
3144
+ "**/app.json"
3145
+ ];
3146
+ const EXPO_REACT_NATIVE_DEPENDENCIES = new Set(["expo", "react-native"]);
3147
+ const EXPO_PLUGIN_RESOLVABLE_EXTENSIONS = SOURCE_EXTENSIONS$3.map((sourceExtension) => `.${sourceExtension}`);
3148
+ const isRecord = (value) => typeof value === "object" && value !== null;
3149
+ const isExpoOrReactNativeWorkspace = (dependencies) => [...EXPO_REACT_NATIVE_DEPENDENCIES].some((dependencyName) => dependencyName in dependencies);
3150
+ const isLocalExpoPluginPath = (value) => (value.startsWith("./") || value.startsWith("../")) && !value.includes("*") && !value.includes("?");
3151
+ const isFile = (filePath) => {
3152
+ try {
3153
+ return statSync(filePath).isFile();
3154
+ } catch {
3155
+ return false;
3156
+ }
3157
+ };
3158
+ const resolveExpoPluginPath = (configDirectory, pluginPath) => {
3159
+ const candidatePath = resolve(configDirectory, pluginPath);
3160
+ if (isFile(candidatePath)) return candidatePath;
3161
+ for (const extension of EXPO_PLUGIN_RESOLVABLE_EXTENSIONS) {
3162
+ const candidatePathWithExtension = `${candidatePath}${extension}`;
3163
+ if (isFile(candidatePathWithExtension)) return candidatePathWithExtension;
3164
+ }
3165
+ for (const extension of EXPO_PLUGIN_RESOLVABLE_EXTENSIONS) {
3166
+ const indexCandidatePath = join(candidatePath, `index${extension}`);
3167
+ if (isFile(indexCandidatePath)) return indexCandidatePath;
3168
+ }
3169
+ };
3170
+ const addExpoPluginEntry = (entries, rootDirectory, configDirectory, pluginPath) => {
3171
+ if (!isLocalExpoPluginPath(pluginPath)) return;
3172
+ const resolvedPath = resolveExpoPluginPath(configDirectory, pluginPath);
3173
+ if (!resolvedPath) return;
3174
+ const relativePath = relative(rootDirectory, resolvedPath);
3175
+ if (relativePath !== "" && (relativePath.startsWith("..") || isAbsolute(relativePath))) return;
3176
+ entries.add(resolvedPath);
3177
+ };
3178
+ const getPropertyName = (name) => {
3179
+ if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name)) return name.text;
3180
+ };
3181
+ const unwrapExpression = (expression) => {
3182
+ let currentExpression = expression;
3183
+ while (ts.isParenthesizedExpression(currentExpression)) currentExpression = currentExpression.expression;
3184
+ return currentExpression;
3185
+ };
3186
+ const collectExpoPluginPathsFromArray = (array, entries, rootDirectory, configDirectory) => {
3187
+ for (const element of array.elements) {
3188
+ if (ts.isStringLiteral(element) || ts.isNoSubstitutionTemplateLiteral(element)) {
3189
+ addExpoPluginEntry(entries, rootDirectory, configDirectory, element.text);
3190
+ continue;
3191
+ }
3192
+ if (ts.isArrayLiteralExpression(element)) {
3193
+ const [pluginName] = element.elements;
3194
+ if (pluginName && (ts.isStringLiteral(pluginName) || ts.isNoSubstitutionTemplateLiteral(pluginName))) addExpoPluginEntry(entries, rootDirectory, configDirectory, pluginName.text);
3195
+ }
3196
+ }
3197
+ };
3198
+ const collectExpoPluginPathsFromConfigObject = (objectLiteral, entries, rootDirectory, configDirectory) => {
3199
+ for (const property of objectLiteral.properties) if (ts.isPropertyAssignment(property) && getPropertyName(property.name) === "plugins" && ts.isArrayLiteralExpression(property.initializer)) collectExpoPluginPathsFromArray(property.initializer, entries, rootDirectory, configDirectory);
3200
+ };
3201
+ const collectReturnedExpoConfigPluginPaths = (body, entries, rootDirectory, configDirectory) => {
3202
+ if (!ts.isBlock(body)) {
3203
+ const expression = unwrapExpression(body);
3204
+ if (ts.isObjectLiteralExpression(expression)) collectExpoPluginPathsFromConfigObject(expression, entries, rootDirectory, configDirectory);
3205
+ return;
3206
+ }
3207
+ const visit = (node) => {
3208
+ if (ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node)) return;
3209
+ if (ts.isReturnStatement(node) && node.expression) {
3210
+ const expression = unwrapExpression(node.expression);
3211
+ if (ts.isObjectLiteralExpression(expression)) collectExpoPluginPathsFromConfigObject(expression, entries, rootDirectory, configDirectory);
3212
+ return;
3213
+ }
3214
+ ts.forEachChild(node, visit);
3215
+ };
3216
+ visit(body);
3217
+ };
3218
+ const collectExpoPluginPathsFromConfigExpression = (expression, entries, rootDirectory, configDirectory, bindings, seenIdentifiers = /* @__PURE__ */ new Set()) => {
3219
+ const configExpression = unwrapExpression(expression);
3220
+ if (ts.isObjectLiteralExpression(configExpression)) {
3221
+ collectExpoPluginPathsFromConfigObject(configExpression, entries, rootDirectory, configDirectory);
3222
+ return;
3223
+ }
3224
+ if (ts.isIdentifier(configExpression)) {
3225
+ if (seenIdentifiers.has(configExpression.text)) return;
3226
+ seenIdentifiers.add(configExpression.text);
3227
+ const boundExpression = bindings.expressions.get(configExpression.text);
3228
+ if (boundExpression) {
3229
+ collectExpoPluginPathsFromConfigExpression(boundExpression, entries, rootDirectory, configDirectory, bindings, seenIdentifiers);
3230
+ return;
3231
+ }
3232
+ const boundFunction = bindings.functions.get(configExpression.text);
3233
+ if (boundFunction?.body) collectReturnedExpoConfigPluginPaths(boundFunction.body, entries, rootDirectory, configDirectory);
3234
+ return;
3235
+ }
3236
+ if (ts.isArrowFunction(configExpression)) {
3237
+ collectReturnedExpoConfigPluginPaths(configExpression.body, entries, rootDirectory, configDirectory);
3238
+ return;
3239
+ }
3240
+ if (ts.isFunctionExpression(configExpression) && configExpression.body) collectReturnedExpoConfigPluginPaths(configExpression.body, entries, rootDirectory, configDirectory);
3241
+ };
3242
+ const hasDefaultExportModifier = (node) => Boolean(ts.canHaveModifiers(node) && ts.getModifiers(node)?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword));
3243
+ const isModuleExportsAssignmentTarget = (node) => ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "module" && node.name.text === "exports";
3244
+ const collectStaticConfigBindings = (sourceFile) => {
3245
+ const expressions = /* @__PURE__ */ new Map();
3246
+ const functions = /* @__PURE__ */ new Map();
3247
+ for (const statement of sourceFile.statements) {
3248
+ if (ts.isVariableStatement(statement)) {
3249
+ for (const declaration of statement.declarationList.declarations) if (ts.isIdentifier(declaration.name) && declaration.initializer) expressions.set(declaration.name.text, declaration.initializer);
3250
+ continue;
3251
+ }
3252
+ if (ts.isFunctionDeclaration(statement) && statement.name) functions.set(statement.name.text, statement);
3253
+ }
3254
+ return {
3255
+ expressions,
3256
+ functions
3257
+ };
3258
+ };
3259
+ const collectExpoPluginPathsFromAppConfig = (configPath, entries, rootDirectory) => {
3260
+ const extension = extname(configPath);
3261
+ const sourceFile = ts.createSourceFile(configPath, readFileSync(configPath, "utf8"), ts.ScriptTarget.Latest, true, extension === ".ts" || extension === ".mts" || extension === ".cts" ? ts.ScriptKind.TS : ts.ScriptKind.JS);
3262
+ const configDirectory = dirname(configPath);
3263
+ const bindings = collectStaticConfigBindings(sourceFile);
3264
+ const visit = (node) => {
3265
+ if (ts.isExportAssignment(node)) {
3266
+ collectExpoPluginPathsFromConfigExpression(node.expression, entries, rootDirectory, configDirectory, bindings);
3267
+ return;
3268
+ }
3269
+ if (ts.isFunctionDeclaration(node) && hasDefaultExportModifier(node) && node.body) {
3270
+ collectReturnedExpoConfigPluginPaths(node.body, entries, rootDirectory, configDirectory);
3271
+ return;
3272
+ }
3273
+ if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken && isModuleExportsAssignmentTarget(node.left)) {
3274
+ collectExpoPluginPathsFromConfigExpression(node.right, entries, rootDirectory, configDirectory, bindings);
3275
+ return;
3276
+ }
3277
+ ts.forEachChild(node, visit);
3278
+ };
3279
+ visit(sourceFile);
3280
+ };
3281
+ const collectPluginPathsFromJsonValue = (value) => {
3282
+ if (!Array.isArray(value)) return [];
3283
+ const pluginPaths = [];
3284
+ for (const plugin of value) {
3285
+ if (typeof plugin === "string") {
3286
+ pluginPaths.push(plugin);
3287
+ continue;
3288
+ }
3289
+ if (Array.isArray(plugin) && typeof plugin[0] === "string") pluginPaths.push(plugin[0]);
3290
+ }
3291
+ return pluginPaths;
3292
+ };
3293
+ const collectExpoPluginPathsFromAppJson = (configPath, entries, rootDirectory) => {
3294
+ const parsedJson = JSON.parse(readFileSync(configPath, "utf8"));
3295
+ const configDirectory = dirname(configPath);
3296
+ if (!isRecord(parsedJson)) return;
3297
+ const expoConfig = parsedJson.expo;
3298
+ const expoPluginPaths = isRecord(expoConfig) ? collectPluginPathsFromJsonValue(expoConfig.plugins) : [];
3299
+ for (const pluginPath of [...expoPluginPaths, ...collectPluginPathsFromJsonValue(parsedJson.plugins)]) addExpoPluginEntry(entries, rootDirectory, configDirectory, pluginPath);
3300
+ };
3301
+ const collectExpoPluginPathsFromConfig = (configPath, entries, rootDirectory) => {
3302
+ try {
3303
+ if (basename(configPath) === "app.json") {
3304
+ collectExpoPluginPathsFromAppJson(configPath, entries, rootDirectory);
3305
+ return;
3306
+ }
3307
+ collectExpoPluginPathsFromAppConfig(configPath, entries, rootDirectory);
3308
+ } catch {}
3309
+ };
3310
+ const extractExpoConfigPluginEntries = (directory, dependencies, rootDirectory = directory, includeNestedConfigs = true) => {
3311
+ if (!isExpoOrReactNativeWorkspace(dependencies)) return [];
3312
+ const entries = /* @__PURE__ */ new Set();
3313
+ const configPaths = fg.sync(includeNestedConfigs ? NESTED_EXPO_CONFIG_FILE_GLOBS : EXPO_CONFIG_FILE_GLOBS, {
3314
+ cwd: directory,
3315
+ absolute: true,
3316
+ onlyFiles: true,
3317
+ ignore: [
3318
+ "**/node_modules/**",
3319
+ "**/dist/**",
3320
+ "**/build/**"
3321
+ ],
3322
+ deep: 6
3323
+ });
3324
+ for (const configPath of configPaths) collectExpoPluginPathsFromConfig(configPath, entries, rootDirectory);
3325
+ return [...entries];
3326
+ };
3327
+
3138
3328
  //#endregion
3139
3329
  //#region src/resolver/source-path.ts
3140
3330
  const SOURCE_EXTENSIONS$1 = [
@@ -3558,6 +3748,11 @@ const resolveEntries = async (config) => {
3558
3748
  for (const workspacePackage of entryEligiblePackages) tsConfigIncludeEntries.push(...extractTsConfigIncludeFilesEntries(workspacePackage.directory));
3559
3749
  const configStringEntries = extractConfigStringReferencedEntries(absoluteRoot);
3560
3750
  for (const workspacePackage of entryEligiblePackages) configStringEntries.push(...extractConfigStringReferencedEntries(workspacePackage.directory));
3751
+ const expoConfigPluginEntries = extractExpoConfigPluginEntries(absoluteRoot, readPackageJsonDependencies(join(absoluteRoot, "package.json")), absoluteRoot, false);
3752
+ for (const workspacePackage of entryEligiblePackages) {
3753
+ const workspacePackageDependencies = readPackageJsonDependencies(join(workspacePackage.directory, "package.json"));
3754
+ expoConfigPluginEntries.push(...extractExpoConfigPluginEntries(workspacePackage.directory, workspacePackageDependencies, absoluteRoot));
3755
+ }
3561
3756
  const sectionsModuleEntries = extractSectionsModuleEntries(absoluteRoot);
3562
3757
  const wranglerEntries = extractWranglerEntries(absoluteRoot);
3563
3758
  for (const workspacePackage of entryEligiblePackages) wranglerEntries.push(...extractWranglerEntries(workspacePackage.directory));
@@ -3586,6 +3781,7 @@ const resolveEntries = async (config) => {
3586
3781
  ...webWorkerEntries,
3587
3782
  ...tsConfigIncludeEntries,
3588
3783
  ...configStringEntries,
3784
+ ...expoConfigPluginEntries,
3589
3785
  ...sectionsModuleEntries,
3590
3786
  ...wranglerEntries,
3591
3787
  ...pluginFileEntries,
@@ -5461,7 +5657,7 @@ const FRAMEWORK_PATTERNS = [
5461
5657
  "app/_layout.{ts,tsx,js,jsx}",
5462
5658
  "app/index.{ts,tsx,js,jsx}"
5463
5659
  ],
5464
- alwaysUsed: ["app.json", "app.config.{ts,js}"]
5660
+ alwaysUsed: ["app.json", "app.config.{ts,mts,cts,js,mjs,cjs}"]
5465
5661
  },
5466
5662
  {
5467
5663
  enablers: ["wrangler"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deslop-js",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "Deslop JavaScript code",
5
5
  "keywords": [
6
6
  "dead-code",