From 9b41a626cf661a9967b20a5290515c4690d493b7 Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Thu, 11 Jul 2024 17:14:34 +0200 Subject: [PATCH] feat: support ESM config for bob --- .../react-native-builder-bob/package.json | 2 +- .../react-native-builder-bob/src/index.ts | 16 +++++-- yarn.lock | 48 ++++++++----------- 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/packages/react-native-builder-bob/package.json b/packages/react-native-builder-bob/package.json index 02f4c15a3..4d313fe8e 100644 --- a/packages/react-native-builder-bob/package.json +++ b/packages/react-native-builder-bob/package.json @@ -50,7 +50,7 @@ "@babel/preset-react": "^7.17.12", "@babel/preset-typescript": "^7.17.12", "browserslist": "^4.20.4", - "cosmiconfig": "^7.0.1", + "cosmiconfig": "^9.0.0", "cross-spawn": "^7.0.3", "dedent": "^0.7.0", "del": "^6.1.1", diff --git a/packages/react-native-builder-bob/src/index.ts b/packages/react-native-builder-bob/src/index.ts index 5a4fddfee..19a68e198 100644 --- a/packages/react-native-builder-bob/src/index.ts +++ b/packages/react-native-builder-bob/src/index.ts @@ -3,7 +3,7 @@ import fs from 'fs-extra'; import kleur from 'kleur'; import dedent from 'dedent'; import yargs from 'yargs'; -import { cosmiconfigSync } from 'cosmiconfig'; +import { cosmiconfig } from 'cosmiconfig'; import isGitDirty from 'is-git-dirty'; import prompts, { type PromptObject } from './utils/prompts'; import * as logger from './utils/logger'; @@ -16,8 +16,14 @@ import type { Options } from './types'; const { name, version } = require('../package.json'); const root = process.cwd(); -const explorer = cosmiconfigSync(name, { - searchPlaces: ['package.json', `bob.config.js`, 'bob.config.cjs'], +const explorer = cosmiconfig(name, { + stopDir: root, + searchPlaces: [ + 'package.json', + 'bob.config.mjs', + 'bob.config.cjs', + 'bob.config.js', + ], }); const FLOW_PRGAMA_REGEX = /\*?\s*@(flow)\b/m; @@ -46,7 +52,7 @@ yargs } const pkg = JSON.parse(await fs.readFile(pak, 'utf-8')); - const result = explorer.search(); + const result = await explorer.search(); if (result?.config && pkg.devDependencies && name in pkg.devDependencies) { const { shouldContinue } = await prompts({ @@ -413,7 +419,7 @@ yargs ); }) .command('build', 'build files for publishing', {}, async (argv) => { - const result = explorer.search(); + const result = await explorer.search(); if (!result?.config) { logger.exit( diff --git a/yarn.lock b/yarn.lock index 82050cc93..50cca88d6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3876,13 +3876,6 @@ __metadata: languageName: node linkType: hard -"@types/parse-json@npm:^4.0.0": - version: 4.0.0 - resolution: "@types/parse-json@npm:4.0.0" - checksum: fd6bce2b674b6efc3db4c7c3d336bd70c90838e8439de639b909ce22f3720d21344f52427f1d9e57b265fcb7f6c018699b99e5e0c208a1a4823014269a6bf35b - languageName: node - linkType: hard - "@types/prompts@npm:^2.0.14": version: 2.4.4 resolution: "@types/prompts@npm:2.4.4" @@ -5621,19 +5614,6 @@ __metadata: languageName: node linkType: hard -"cosmiconfig@npm:^7.0.1": - version: 7.1.0 - resolution: "cosmiconfig@npm:7.1.0" - dependencies: - "@types/parse-json": ^4.0.0 - import-fresh: ^3.2.1 - parse-json: ^5.0.0 - path-type: ^4.0.0 - yaml: ^1.10.0 - checksum: c53bf7befc1591b2651a22414a5e786cd5f2eeaa87f3678a3d49d6069835a9d8d1aef223728e98aa8fec9a95bf831120d245096db12abe019fecb51f5696c96f - languageName: node - linkType: hard - "cosmiconfig@npm:^8.0.0": version: 8.3.6 resolution: "cosmiconfig@npm:8.3.6" @@ -5651,6 +5631,23 @@ __metadata: languageName: node linkType: hard +"cosmiconfig@npm:^9.0.0": + version: 9.0.0 + resolution: "cosmiconfig@npm:9.0.0" + dependencies: + env-paths: ^2.2.1 + import-fresh: ^3.3.0 + js-yaml: ^4.1.0 + parse-json: ^5.2.0 + peerDependencies: + typescript: ">=4.9.5" + peerDependenciesMeta: + typescript: + optional: true + checksum: a30c424b53d442ea0bdd24cb1b3d0d8687c8dda4a17ab6afcdc439f8964438801619cdb66e8e79f63b9caa3e6586b60d8bab9ce203e72df6c5e80179b971fe8f + languageName: node + linkType: hard + "create-jest@npm:^29.7.0": version: 29.7.0 resolution: "create-jest@npm:29.7.0" @@ -6589,7 +6586,7 @@ __metadata: languageName: node linkType: hard -"env-paths@npm:^2.2.0": +"env-paths@npm:^2.2.0, env-paths@npm:^2.2.1": version: 2.2.1 resolution: "env-paths@npm:2.2.1" checksum: 65b5df55a8bab92229ab2b40dad3b387fad24613263d103a97f91c9fe43ceb21965cd3392b1ccb5d77088021e525c4e0481adb309625d0cb94ade1d1fb8dc17e @@ -12849,7 +12846,7 @@ __metadata: "@types/yargs": ^17.0.10 browserslist: ^4.20.4 concurrently: ^7.2.2 - cosmiconfig: ^7.0.1 + cosmiconfig: ^9.0.0 cross-spawn: ^7.0.3 dedent: ^0.7.0 del: ^6.1.1 @@ -15438,13 +15435,6 @@ __metadata: languageName: node linkType: hard -"yaml@npm:^1.10.0": - version: 1.10.2 - resolution: "yaml@npm:1.10.2" - checksum: ce4ada136e8a78a0b08dc10b4b900936912d15de59905b2bf415b4d33c63df1d555d23acb2a41b23cf9fb5da41c256441afca3d6509de7247daa062fd2c5ea5f - languageName: node - linkType: hard - "yargs-parser@npm:^20.2.2, yargs-parser@npm:^20.2.3": version: 20.2.9 resolution: "yargs-parser@npm:20.2.9"