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

fix: Don't detect Redwood App as multiple workspaces #5271

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions packages/build-info/src/frameworks/qwik.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ beforeEach((ctx) => {
ctx.fs = new NodeFS()
})

test('should detect quick with npm', async ({ fs }) => {
test('should detect qwik with npm', async ({ fs }) => {
const cwd = mockFileSystem({
'package.json': JSON.stringify({ dependencies: { '@builder.io/qwik': '*' } }),
})
Expand All @@ -19,7 +19,7 @@ test('should detect quick with npm', async ({ fs }) => {
expect(detected?.[0].dev?.command).toBe('vite')
})

test('should detect quick with yarn', async ({ fs }) => {
test('should detect qwik with yarn', async ({ fs }) => {
const cwd = mockFileSystem({
'package.json': JSON.stringify({ packageManager: '[email protected]', dependencies: { '@builder.io/qwik': '*' } }),
})
Expand All @@ -29,7 +29,7 @@ test('should detect quick with yarn', async ({ fs }) => {
expect(detected?.[0].build.directory).toBe('dist')
})

test('should detect quick', async ({ fs }) => {
test('should detect qwik', async ({ fs }) => {
const cwd = mockFileSystem({
'pnpm-lock.yaml': '',
'package.json': JSON.stringify({ dependencies: { '@builder.io/qwik': '*' } }),
Expand Down
102 changes: 102 additions & 0 deletions packages/build-info/src/frameworks/redwood.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { beforeEach, expect, test } from 'vitest'

import { mockFileSystem } from '../../tests/mock-file-system.js'
import { NodeFS } from '../node/file-system.js'
import { Project } from '../project.js'

beforeEach((ctx) => {
ctx.fs = new NodeFS()
})

const redwoodToml = `
# This file contains the configuration settings for your Redwood app.
# This file is also what makes your Redwood app a Redwood app.
# If you remove it and try to run "yarn rw dev", you'll get an error.
#
# For the full list of options, see the "App Configuration: redwood.toml" doc:
# https://redwoodjs.com/docs/app-configuration-redwood-toml

[web]
title = "Redwood App"
port = 8910
apiUrl = "/.netlify/functions"
includeEnvironmentVariables = [
# Add any ENV vars that should be available to the web side to this array
# See https://redwoodjs.com/docs/environment-variables#web
]
[api]
port = 8911
[browser]
open = true
[notifications]
versionUpdates = ["latest"]
`

test('should detect redwood', async ({ fs }) => {
const cwd = mockFileSystem({
'redwood.toml': redwoodToml,
'package.json': JSON.stringify({
private: true,
workspaces: {
packages: ['api', 'web'],
},
devDependencies: {
'@redwoodjs/core': '6.1.0',
},
eslintConfig: {
extends: '@redwoodjs/eslint-config',
root: true,
},
engines: {
node: '=18.x',
yarn: '>=1.15',
},
prisma: {
seed: 'yarn rw exec seed',
},
packageManager: '[email protected]',
}),
'web/package.json': JSON.stringify({
name: 'web',
version: '0.0.0',
private: true,
browserslist: {
development: ['last 1 version'],
production: ['defaults'],
},
dependencies: {
'@redwoodjs/forms': '6.1.0',
'@redwoodjs/router': '6.1.0',
'@redwoodjs/web': '6.1.0',
'humanize-string': '2.1.0',
'prop-types': '15.8.1',
react: '18.2.0',
'react-dom': '18.2.0',
},
devDependencies: {
'@redwoodjs/vite': '6.1.0',
},
}),
'api/package.json': JSON.stringify({
name: 'api',
version: '0.0.0',
private: true,
dependencies: {
'@redwoodjs/api': '6.1.0',
'@redwoodjs/graphql-server': '6.1.0',
},
}),
})

const project = new Project(fs, cwd, cwd)

expect(await project.detectWorkspaces()).toBeNull()
const detected = await project.detectFrameworks()

expect(detected).toHaveLength(1)
expect(detected?.[0].id).toBe('redwoodjs')
expect(detected?.[0].name).toBe('RedwoodJS')
expect(detected?.[0].build.command).toBe('rw deploy netlify')
expect(detected?.[0].build.directory).toBe('web/dist')
expect(detected?.[0].dev?.command).toBe('yarn rw dev')
})
4 changes: 4 additions & 0 deletions packages/build-info/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ export class Project {
return null
}

async isRedwoodProject(): Promise<boolean> {
return await this.fs.fileExists(this.fs.resolve(this.fs.cwd, 'redwood.toml'))
}

constructor(public fs: FileSystem, baseDirectory?: string, root?: string) {
this.baseDirectory = fs.resolve(root || '', baseDirectory !== undefined ? baseDirectory : fs.cwd)
this.root = root ? fs.resolve(fs.cwd, root) : undefined
Expand Down
4 changes: 4 additions & 0 deletions packages/build-info/src/workspaces/detect-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export async function detectWorkspaces(project: Project): Promise<WorkspaceInfo
return null
}

if (await project.isRedwoodProject()) {
return null
}

const pkgJSON = await project.getRootPackageJSON()
const workspaceGlobs =
project.packageManager.name === PkgManager.PNPM
Expand Down
Loading