Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove bluebird dependency to packages/config for better Yarn 3 compat #26570

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mainBuildFilters: &mainBuildFilters
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- 'update-v8-snapshot-cache-on-develop'
- 'matth/misc/telemetry'
- 'add-bluebird-config'

# usually we don't build Mac app - it takes a long time
# but sometimes we want to really confirm we are doing the right thing
Expand All @@ -41,6 +42,7 @@ macWorkflowFilters: &darwin-workflow-filters
- equal: [ develop, << pipeline.git.branch >> ]
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'add-bluebird-config', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand Down Expand Up @@ -136,7 +138,7 @@ commands:
- run:
name: Check current branch to persist artifacts
command: |
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "update-v8-snapshot-cache-on-develop" && "$CIRCLE_BRANCH" != "matth/chore/add-circle-ci-detector" ]]; then
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "update-v8-snapshot-cache-on-develop" && "$CIRCLE_BRANCH" != "add-bluebird-config" ]]; then
echo "Not uploading artifacts or posting install comment for this branch."
circleci-agent step halt
fi
Expand Down
85 changes: 48 additions & 37 deletions packages/config/src/project/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Bluebird from 'bluebird'
import Debug from 'debug'
import fs from 'fs-extra'
import _ from 'lodash'
Expand Down Expand Up @@ -276,7 +275,7 @@ export function relativeToProjectRoot (projectRoot: string, file: string) {
// async function
export async function setSupportFileAndFolder (obj: Config, getFilesByGlob: any) {
if (!obj.supportFile) {
return Bluebird.resolve(obj)
return Promise.resolve(obj)
}

obj = _.clone(obj)
Expand All @@ -301,62 +300,74 @@ export async function setSupportFileAndFolder (obj: Config, getFilesByGlob: any)
debug(`setting support file ${sf}`)
debug(`for project root ${obj.projectRoot}`)

return Bluebird
.try(() => {
try {
// resolve full path with extension
obj.supportFile = utils.resolveModule(sf)

return debug('resolved support file %s', obj.supportFile)
}).then(() => {
if (!checkIfResolveChangedRootFolder(obj.supportFile, sf)) {
return
}
debug('resolved support file %s', obj.supportFile)

debug('require.resolve switched support folder from %s to %s', sf, obj.supportFile)
// this means the path was probably symlinked, like
// /tmp/foo -> /private/tmp/foo
// which can confuse the rest of the code
// switch it back to "normal" file
const supportFileName = path.basename(obj.supportFile)
const base = sf?.endsWith(supportFileName) ? path.dirname(sf) : sf
if (checkIfResolveChangedRootFolder(obj.supportFile, sf)) {
debug('require.resolve switched support folder from %s to %s', sf, obj.supportFile)
// this means the path was probably symlinked, like
// /tmp/foo -> /private/tmp/foo
// which can confuse the rest of the code
// switch it back to "normal" file
const supportFileName = path.basename(obj.supportFile)
const base = sf?.endsWith(supportFileName) ? path.dirname(sf) : sf

obj.supportFile = path.join(base || '', supportFileName)
obj.supportFile = path.join(base || '', supportFileName)

const found = await fs.pathExists(obj.supportFile)

return fs.pathExists(obj.supportFile)
.then((found) => {
if (!found) {
errors.throwErr('SUPPORT_FILE_NOT_FOUND', relativeToProjectRoot(obj.projectRoot, obj.supportFile))
}

return debug('switching to found file %s', obj.supportFile)
})
}).catch({ code: 'MODULE_NOT_FOUND' }, () => {
debug('support JS module %s does not load', sf)
debug('switching to found file %s', obj.supportFile)

return utils.discoverModuleFile({
filename: sf,
projectRoot: obj.projectRoot,
})
.then((result) => {
if (result === null) {
return errors.throwErr('SUPPORT_FILE_NOT_FOUND', relativeToProjectRoot(obj.projectRoot, sf))
if (obj.supportFile) {
// set config.supportFolder to its directory
obj.supportFolder = path.dirname(obj.supportFile)
debug(`set support folder ${obj.supportFolder}`)
}

debug('setting support file to %o', { result })
obj.supportFile = result

return obj
})
})
.then(() => {
}

if (obj.supportFile) {
// set config.supportFolder to its directory
obj.supportFolder = path.dirname(obj.supportFile)
debug(`set support folder ${obj.supportFolder}`)
}

return obj
})
} catch (error) {
if (error.code === 'MODULE_NOT_FOUND') {
debug('support JS module %s does not load', sf)

const result = await utils.discoverModuleFile({
filename: sf,
projectRoot: obj.projectRoot,
})

if (result === null) {
errors.throwErr('SUPPORT_FILE_NOT_FOUND', relativeToProjectRoot(obj.projectRoot, sf))
}

debug('setting support file to %o', { result })
obj.supportFile = result

if (obj.supportFile) {
// set config.supportFolder to its directory
obj.supportFolder = path.dirname(obj.supportFile)
debug(`set support folder ${obj.supportFolder}`)
}

return obj
}

throw error
}
}

export function mergeDefaults (
Expand Down