Skip to content

Commit

Permalink
Merge pull request #105 from bugsnag/release/v45.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
yousif-bugsnag committed Mar 2, 2023
2 parents b74a059 + 3552aa0 commit 7272f86
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 30 deletions.
1 change: 1 addition & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ steps:
queue: "opensource-arm-mac-cocoa-12"
env:
EXPO_RELEASE_CHANNEL: ${BUILDKITE_BUILD_ID}
DEVELOPER_DIR: "/Applications/Xcode13.4.app"
artifact_paths: build/output.ipa
commands:
- test/scripts/build-ios.sh
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## v45.1.3 (2022-03-02)

### Fixed

- (bugsnag-expo-cli) Fix issue with automated installation when using app.config.js [#72](https://github.com/bugsnag/bugsnag-expo/pull/72)
- (expo) Add promise v8 as a peer dependency [#77](https://github.com/bugsnag/bugsnag-expo/pull/77)
- (plugin-expo-eas-sourcemaps) Restrict Bugsnag Android Gradle Plugin dependency to v7 [#101](https://github.com/bugsnag/bugsnag-expo/pull/101)

## v45.1.2 (2022-08-21)

### Fixed
Expand Down
35 changes: 23 additions & 12 deletions packages/expo-cli/lib/configure-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,37 @@ function usingWorkspaces (projectRoot, usingYarnClassic) {
}

module.exports = async (projectRoot) => {
const appJsonPath = join(projectRoot, 'app.json')
let conf

// read in existing app.json
try {
const appJsonPath = join(projectRoot, 'app.json')
const conf = JSON.parse(await promisify(readFile)(appJsonPath, 'utf8'))
conf.expo.plugins = conf.expo.plugins || []
if (conf.expo.plugins.includes(plugin)) {
return plugin + ' is already installed'
}
conf.expo.plugins.push(plugin)
await promisify(writeFile)(appJsonPath, JSON.stringify(conf, null, 2), 'utf8')
conf = JSON.parse(await promisify(readFile)(appJsonPath, 'utf8'))
} catch (e) {
// swallow and rethrow for errors that we can produce better messaging for
if (e.code === 'ENOENT') {
throw new Error(`Couldn’t find app.json in "${projectRoot}". Is this the root of your Expo project?`)
}
if (e.name === 'SyntaxError') {
conf = {
expo: {
plugins: []
}
}
} else if (e.name === 'SyntaxError') {
throw new Error(`Couldn’t parse app.json because it wasn’t valid JSON: "${e.message}"`)
} else {
throw e
}
throw e
}

// update config
conf.expo = conf.expo || {}
conf.expo.plugins = conf.expo.plugins || []
if (conf.expo.plugins.includes(plugin)) {
return plugin + ' is already installed'
}
conf.expo.plugins.push(plugin)

await promisify(writeFile)(appJsonPath, JSON.stringify(conf, null, 2), 'utf8')

// do we need to add monorepo configuration?
const withYarnClassic = await usingYarnClassic(projectRoot)
const addMonorepoConfig = await usingWorkspaces(projectRoot, withYarnClassic)
Expand Down
33 changes: 23 additions & 10 deletions packages/expo-cli/lib/set-api-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,34 @@ const { readFile, writeFile } = require('fs')
const { promisify } = require('util')

module.exports = async (apiKey, projectRoot) => {
const appJsonPath = join(projectRoot, 'app.json')
let conf

try {
const appJsonPath = join(projectRoot, 'app.json')
const conf = JSON.parse(await promisify(readFile)(appJsonPath, 'utf8'))
conf.expo.extra = conf.expo.extra || {}
conf.expo.extra.bugsnag = conf.expo.extra.bugsnag || {}
conf.expo.extra.bugsnag.apiKey = apiKey
await promisify(writeFile)(appJsonPath, JSON.stringify(conf, null, 2), 'utf8')
conf = JSON.parse(await promisify(readFile)(appJsonPath, 'utf8'))
} catch (e) {
// swallow and rethrow for errors that we can produce better messaging for
if (e.code === 'ENOENT') {
throw new Error(`Couldn’t find app.json in "${projectRoot}". Is this the root of your Expo project?`)
}
if (e.name === 'SyntaxError') {
conf = {
expo: {
extra: {
bugsnag: {
}
}
}
}
// throw new Error(`Couldn’t find app.json in "${projectRoot}". Is this the root of your Expo project?`)
} else if (e.name === 'SyntaxError') {
throw new Error(`Couldn’t parse app.json because it wasn’t valid JSON: "${e.message}"`)
} else {
throw e
}
throw e
}

conf.expo = conf.expo || {}
conf.expo.extra = conf.expo.extra || {}
conf.expo.extra.bugsnag = conf.expo.extra.bugsnag || {}
conf.expo.extra.bugsnag.apiKey = apiKey

await promisify(writeFile)(appJsonPath, JSON.stringify(conf, null, 2), 'utf8')
}
9 changes: 7 additions & 2 deletions packages/expo-cli/lib/test/configure-plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ describe('expo-cli: upload sourcemaps configure-plugin', () => {
})
})

it('should provide a reasonable error when there is no app.json', async () => {
it('should create a basic file when there is no app.json', async () => {
await withFixture('empty-00', async (projectRoot) => {
await expect(configurePlugin(projectRoot)).rejects.toThrow(/^Couldn’t find app\.json in/)
const msg = await configurePlugin(projectRoot)
expect(msg).toBe(undefined)

const appJsonRaw = await readFile(`${projectRoot}/app.json`, 'utf8')
const appJson = JSON.parse(appJsonRaw)
expect(appJson.expo.plugins).toStrictEqual(['@bugsnag/plugin-expo-eas-sourcemaps'])
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "bugsnag-test-fixture-05",
"name": "already-installed-01",
"private": "true",
"version": "0.0.0",
"dependencies": {
Expand Down
11 changes: 8 additions & 3 deletions packages/expo-cli/lib/test/set-api-key.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('expo-cli: set-api-key', () => {
})
})

it('shouldn’t replaces an existing API key', async () => {
it('shouldn’t replace an existing API key', async () => {
await withFixture('already-configured-00', async (projectRoot) => {
const msg = await setApiKey('AABBCCDD', projectRoot)
expect(msg).toBe(undefined)
Expand All @@ -25,9 +25,14 @@ describe('expo-cli: set-api-key', () => {
})
})

it('should provide a reasonable error when there is no app.json', async () => {
it('should create a basic file with apiKey when there is no app.json', async () => {
await withFixture('empty-00', async (projectRoot) => {
await expect(setApiKey('AABBCCDD', projectRoot)).rejects.toThrow(/^Couldn’t find app\.json in/)
const msg = await setApiKey('AABBCCDD', projectRoot)
expect(msg).toBe(undefined)

const appJsonRaw = await readFile(`${projectRoot}/app.json`, 'utf8')
const appJson = JSON.parse(appJsonRaw)
expect(appJson.expo.extra.bugsnag.apiKey).toBe('AABBCCDD')
})
})

Expand Down
1 change: 1 addition & 0 deletions packages/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"peerDependencies": {
"expo": ">=33.0.0",
"expo-constants": "~13.1.1",
"promise": "^8",
"react": "*"
}
}
2 changes: 1 addition & 1 deletion packages/plugin-expo-eas-sourcemaps/src/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function injectDependencies (script) {
mavenCentral()
}
dependencies {
classpath 'com.bugsnag:bugsnag-android-gradle-plugin:[7.3.0,)'
classpath 'com.bugsnag:bugsnag-android-gradle-plugin:7.+'
}
}
Expand Down
7 changes: 6 additions & 1 deletion test/features/fixtures/test-app/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
},
"plugins": [
["./config-plugins/withRemoveiOSNotificationEntitlement"]
]
],
"extra": {
"eas": {
"projectId": "EXPO_EAS_PROJECT_ID"
}
}
}
}
3 changes: 3 additions & 0 deletions test/scripts/build-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ npm install bugsnag-expo-cli*.tgz
# set bugsnag-js override versions if this build was triggered from the bugsnag-js repo
./set-bugsnag-js-overrides $BUGSNAG_JS_BRANCH $BUGSNAG_JS_COMMIT

# Set EAS Project ID
sed -i '' "s/EXPO_EAS_PROJECT_ID/$EXPO_EAS_PROJECT_ID/g" app.json

# install the remaining packages, this also re-installs the correct @bugsnag/expo version
npm install *.tgz
npm install
Expand Down

0 comments on commit 7272f86

Please sign in to comment.