Skip to content

Commit

Permalink
Merge branch 'main' into feat/dbauth-fetch-handler
Browse files Browse the repository at this point in the history
  • Loading branch information
dac09 authored Jan 22, 2024
2 parents 61d4664 + 74a9b0a commit 8fdbec0
Show file tree
Hide file tree
Showing 23 changed files with 105 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/actions/telemetry_check/check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ try {
switch (mode) {
case 'crwa':
exitCode = await exec(
`yarn node ./packages/create-redwood-app/dist/create-redwood-app.js ../project-for-telemetry --typescript true --git false`
`yarn node ./packages/create-redwood-app/dist/create-redwood-app.js ../project-for-telemetry --typescript true --git false --no-yarn-install`
)
if (exitCode) {
process.exit(1)
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/studioHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const handler = async (options) => {
console.log(
'The studio package is not installed, installing it for you, this may take a moment...'
)
await installModule('@redwoodjs/studio', '11.0.0')
await installModule('@redwoodjs/studio', '11.0.1')
console.log('Studio package installed successfully.')

console.log('Adding config to redwood.toml...')
Expand All @@ -18,7 +18,7 @@ export const handler = async (options) => {

// Import studio and start it
const { serve } = await import('@redwoodjs/studio')
await serve({ open: options.open })
await serve({ open: options.open, enableWeb: true })
} catch (e) {
console.log('Cannot start the development studio')
console.log(e)
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/commands/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ function updatePackageJsonVersion(pkgPath, version, { dryRun, verbose }) {
)

if (pkg.dependencies) {
for (const depName of Object.keys(pkg.dependencies).filter((x) =>
x.startsWith('@redwoodjs/')
for (const depName of Object.keys(pkg.dependencies).filter(
(x) => x.startsWith('@redwoodjs/') && x !== '@redwoodjs/studio'
)) {
if (verbose || dryRun) {
console.log(` - ${depName}: ${pkg.dependencies[depName]} => ${version}`)
Expand All @@ -234,8 +234,8 @@ function updatePackageJsonVersion(pkgPath, version, { dryRun, verbose }) {
}
}
if (pkg.devDependencies) {
for (const depName of Object.keys(pkg.devDependencies).filter((x) =>
x.startsWith('@redwoodjs/')
for (const depName of Object.keys(pkg.devDependencies).filter(
(x) => x.startsWith('@redwoodjs/') && x !== '@redwoodjs/studio'
)) {
if (verbose || dryRun) {
console.log(
Expand Down
2 changes: 1 addition & 1 deletion packages/create-redwood-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"scripts": {
"build": "node ./scripts/build.js",
"build:pack": "yarn pack -o create-redwood-app.tgz",
"build:pack": "node ./scripts/buildPack.js",
"build:watch": "nodemon --watch src --ignore dist,template --exec \"yarn build\"",
"prepublishOnly": "NODE_ENV=production yarn build",
"set-up-test-project": "node ./scripts/setUpTestProject.js",
Expand Down
31 changes: 31 additions & 0 deletions packages/create-redwood-app/scripts/buildPack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-env node */

import { fileURLToPath } from 'node:url'

import { cd, path, within, $ } from 'zx'

const tsTemplatePath = fileURLToPath(
new URL('../templates/ts', import.meta.url)
)
const jsTemplatePath = fileURLToPath(
new URL('../templates/js', import.meta.url)
)

await within(async () => {
cd(tsTemplatePath)

await $`touch yarn.lock`
await $`yarn`
})

await within(async () => {
cd(jsTemplatePath)

await $`touch yarn.lock`
await $`yarn`
})

await $`yarn pack -o create-redwood-app.tgz`

await $`rm ${path.join(tsTemplatePath, 'yarn.lock')}`
await $`rm ${path.join(jsTemplatePath, 'yarn.lock')}`
57 changes: 20 additions & 37 deletions packages/create-redwood-app/src/create-redwood-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,6 @@ const { telemetry } = Parser(hideBin(process.argv), {

const tui = new RedwoodTUI()

// Credit to esbuild: https://github.com/rtsao/esbuild/blob/c35a4cebf037237559213abc684504658966f9d6/lib/install.ts#L190-L199
function isYarnBerryOrNewer() {
const { npm_config_user_agent: npmConfigUserAgent } = process.env

if (npmConfigUserAgent) {
const match = npmConfigUserAgent.match(/yarn\/(\d+)/)

if (match && match[1]) {
return parseInt(match[1], 10) >= 2
}
}

return false
}

const USE_GITPOD_TEXT = [
` As an alternative solution, you can launch a Redwood project using GitPod instead. GitPod is a an online IDE.`,
` See: ${terminalLink(
Expand Down Expand Up @@ -250,7 +235,10 @@ async function installNodeModules(newAppDir) {
})
tui.startReactive(tuiContent)

const yarnInstallSubprocess = execa('yarn install', {
const oldCwd = process.cwd()
process.chdir(newAppDir)

const yarnInstallSubprocess = execa(`yarn install`, {
shell: true,
cwd: newAppDir,
})
Expand All @@ -271,9 +259,12 @@ async function installNodeModules(newAppDir) {
)
recordErrorViaTelemetry(error)
await shutdownTelemetry()
process.chdir(oldCwd)
process.exit(1)
}

process.chdir(oldCwd)

tuiContent.update({
header: '',
content: `${RedwoodStyling.green('✔')} Installed node modules`,
Expand Down Expand Up @@ -611,6 +602,11 @@ async function handleCommitMessagePreference(commitMessageFlag) {
async function handleYarnInstallPreference(yarnInstallFlag) {
// Handle case where flag is set
if (yarnInstallFlag !== null) {
tui.drawText(
`${RedwoodStyling.green('✔')} ${
yarnInstallFlag ? 'Will' : 'Will not'
} run yarn install based on command line flag`
)
return yarnInstallFlag
}

Expand Down Expand Up @@ -673,6 +669,11 @@ async function createRedwoodApp() {
type: 'string',
describe: 'Commit message for the initial commit',
})
.option('yarn-install', {
default: null,
type: 'boolean',
describe: 'Install node modules. Skip via --no-yarn-install.',
})
.option('telemetry', {
default: true,
type: 'boolean',
Expand All @@ -692,22 +693,10 @@ async function createRedwoodApp() {
].join('\n')
)

const _isYarnBerryOrNewer = isYarnBerryOrNewer()

// Only permit the yarn install flag on yarn 1.
if (!_isYarnBerryOrNewer) {
cli.option('yarn-install', {
default: null,
type: 'boolean',
describe: 'Install node modules. Skip via --no-yarn-install.',
})
}

// Extract the args as provided by the user in the command line
// TODO: Make all flags have the 'flag' suffix
const args = parsedFlags._
const yarnInstallFlag =
parsedFlags['yarn-install'] ?? !_isYarnBerryOrNewer ? parsedFlags.yes : null
const yarnInstallFlag = parsedFlags['yarn-install'] ?? parsedFlags.yes
const typescriptFlag = parsedFlags.typescript ?? parsedFlags.yes
const overwrite = parsedFlags.overwrite
const gitInitFlag = parsedFlags['git-init'] ?? parsedFlags.yes
Expand Down Expand Up @@ -745,11 +734,7 @@ async function createRedwoodApp() {
commitMessage = await handleCommitMessagePreference(commitMessageFlag)
}

let yarnInstall = false

if (!_isYarnBerryOrNewer) {
yarnInstall = await handleYarnInstallPreference(yarnInstallFlag)
}
const yarnInstall = await handleYarnInstallPreference(yarnInstallFlag)

let newAppDir = path.resolve(process.cwd(), targetDir)

Expand All @@ -765,9 +750,7 @@ async function createRedwoodApp() {
.getActiveSpan()
?.setAttribute('yarn-install-time', Date.now() - yarnInstallStart)
} else {
if (!_isYarnBerryOrNewer) {
tui.drawText(`${RedwoodStyling.info('ℹ')} Skipped yarn install step`)
}
tui.drawText(`${RedwoodStyling.info('ℹ')} Skipped yarn install step`)
}

// Generate types
Expand Down
4 changes: 2 additions & 2 deletions packages/create-redwood-app/templates/js/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"react-dom": "0.0.0-experimental-e5205658f-20230913"
},
"devDependencies": {
"@redwoodjs/vite": "6.0.7",
"@types/react": "18.2.37",
"@types/react-dom": "18.2.15",
"@redwoodjs/vite": "6.0.7"
"@types/react-dom": "18.2.15"
}
}
4 changes: 2 additions & 2 deletions packages/create-redwood-app/templates/ts/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"react-dom": "0.0.0-experimental-e5205658f-20230913"
},
"devDependencies": {
"@redwoodjs/vite": "6.0.7",
"@types/react": "18.2.37",
"@types/react-dom": "18.2.15",
"@redwoodjs/vite": "6.0.7"
"@types/react-dom": "18.2.15"
}
}
12 changes: 10 additions & 2 deletions packages/create-redwood-app/tests/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ describe('create-redwood-app', () => {
--git-init, --git Initialize a git repository [boolean] [default: null]
-m, --commit-message Commit message for the initial commit
[string] [default: null]
--yarn-install Install node modules. Skip via --no-yarn-install.
[boolean] [default: null]
--telemetry Enables sending telemetry events for this create
command and all Redwood CLI commands
https://telemetry.redwoodjs.com
Expand All @@ -52,7 +54,11 @@ describe('create-redwood-app', () => {
})

test('--yes, -y', async () => {
const p = await $`yarn create-redwood-app ./redwood-app --yes`
// Running `yarn install` in Jest test times out and the subsequent step,
// generating types, is also flakey since `yarn pack` seems to skip `.yarnrc.yml`
// which is necessary for configuring a proper install.
const p =
await $`yarn create-redwood-app ./redwood-app --no-yarn-install --yes`

expect(p.exitCode).toEqual(0)
expect(p.stdout).toMatchInlineSnapshot(`
Expand All @@ -64,9 +70,11 @@ describe('create-redwood-app', () => {
[?25h✔ Creating your Redwood app in ./redwood-app based on command line argument
✔ Using TypeScript based on command line flag
✔ Will initialize a git repo based on command line flag
✔ Will not run yarn install based on command line flag
[?25l⠋ Creating project files
[?25h[?25l✔ Project files created
[?25h[?25l⠋ Initializing a git repo
[?25hℹ Skipped yarn install step
[?25l⠋ Initializing a git repo
[?25h[?25l✔ Initialized a git repo with commit message "Initial commit"
[?25h
Thanks for trying out Redwood!
Expand Down
2 changes: 1 addition & 1 deletion packages/create-redwood-app/tests/e2e_prompts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cd $projectPath

set projectDirectory "redwood-app-prompt-test"

spawn yarn create-redwood-app
spawn yarn create-redwood-app --no-yarn-install

expect "Where would you like to create your Redwood app?"
send "$projectDirectory\n"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-redwood-app/tests/e2e_prompts_git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cd $projectPath

set projectDirectory "redwood-app-prompt-git-test"

spawn yarn create-redwood-app --git
spawn yarn create-redwood-app --no-yarn-install --git

expect "Where would you like to create your Redwood app?"
send "$projectDirectory\n"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-redwood-app/tests/e2e_prompts_m.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cd $projectPath

set projectDirectory "redwood-app-prompt-m-test"

spawn yarn create-redwood-app -m "first"
spawn yarn create-redwood-app --no-yarn-install -m "first"

expect "Where would you like to create your Redwood app?"
send "$projectDirectory\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cd $projectPath

set projectDirectory "redwood-app-prompt-node-greater-test"

spawn yarn create-redwood-app
spawn yarn create-redwood-app --no-yarn-install

expect "How would you like to proceed?"
# ❯ Override error and continue install
Expand Down
2 changes: 1 addition & 1 deletion packages/create-redwood-app/tests/e2e_prompts_node_less.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cd $projectPath

set projectDirectory "redwood-app-prompt-node-less-test"

spawn yarn create-redwood-app
spawn yarn create-redwood-app --no-yarn-install

expect eof
catch wait result
Expand Down
2 changes: 1 addition & 1 deletion packages/create-redwood-app/tests/e2e_prompts_overwrite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set projectDirectory "redwood-app-prompt-overwrite-test"
exec mkdir $projectDirectory
exec touch $projectDirectory/README.md

spawn yarn create-redwood-app
spawn yarn create-redwood-app --no-yarn-install

expect "Where would you like to create your Redwood app?"
send "$projectDirectory\n"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-redwood-app/tests/e2e_prompts_ts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cd $projectPath

set projectDirectory "redwood-app-prompt-ts-test"

spawn yarn create-redwood-app --ts
spawn yarn create-redwood-app --no-yarn-install --ts

expect "Where would you like to create your Redwood app?"
send "$projectDirectory\n"
Expand Down
1 change: 0 additions & 1 deletion packages/project-config/.babelrc.js

This file was deleted.

8 changes: 0 additions & 8 deletions packages/project-config/jest.config.js

This file was deleted.

8 changes: 4 additions & 4 deletions packages/project-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"build:types": "tsc --build --verbose",
"build:watch": "nodemon --watch src --ext \"js,ts,tsx\" --ignore dist --exec \"yarn build\"",
"prepublishOnly": "NODE_ENV=production yarn build",
"test": "jest src",
"test:watch": "run test --watch"
"test": "vitest run src",
"test:watch": "vitest watch src"
},
"dependencies": {
"@iarna/toml": "2.2.5",
Expand All @@ -31,9 +31,9 @@
},
"devDependencies": {
"esbuild": "0.19.9",
"jest": "29.7.0",
"rimraf": "5.0.5",
"typescript": "5.3.3"
"typescript": "5.3.3",
"vitest": "1.2.1"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
}
2 changes: 2 additions & 0 deletions packages/project-config/src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import path from 'path'

import { describe, it, expect } from 'vitest'

import { getConfig, getRawConfig } from '../config'

describe('getRawConfig', () => {
Expand Down
Loading

0 comments on commit 8fdbec0

Please sign in to comment.