Skip to content

Commit

Permalink
hotfix(js-setup): Await all transformTSToJS functions (#10930)
Browse files Browse the repository at this point in the history
This PR waits all calls to `transformTSToJS` which became async due to
the prettier upgrade explained here:
#10762

Closes #10762
Closes #10929

---------

Co-authored-by: GitHub Actions <>
Co-authored-by: Josh GM Walker <[email protected]>
  • Loading branch information
dac09 and Josh-Walker-GM committed Jul 10, 2024
1 parent dfb9b83 commit 04eb4f3
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 154 deletions.
4 changes: 0 additions & 4 deletions .github/actions/detect-changes/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ description: Determines what areas of the framework have been changed
outputs:
docs:
description: If *only* docs have changed
rsc:
description: If RSC-related changes have been made
ssr:
description: If SSR-related changes have been made

runs:
using: node20
Expand Down
10 changes: 0 additions & 10 deletions .github/actions/detect-changes/detectChanges.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// @ts-check

// @ts-expect-error types
import fs from 'node:fs'

// @ts-expect-error types
import core from '@actions/core'
import { codeChanges } from './cases/code_changes.mjs'

Expand Down Expand Up @@ -225,8 +223,6 @@ async function main() {
// If there's no branch, we're not in a pull request.
if (!branch) {
core.setOutput('code', true)
core.setOutput('rsc', false)
core.setOutput('ssr', false)
return
}

Expand Down Expand Up @@ -270,22 +266,16 @@ async function main() {
'to running all tests.',
)
core.setOutput('code', true)
core.setOutput('rsc', true)
core.setOutput('ssr', true)
return
}

if (!codeChanges(changedFiles)) {
console.log('Only docs and/or changesets changes detected')
core.setOutput('code', false)
core.setOutput('rsc', false)
core.setOutput('ssr', false)
return
}

core.setOutput('code', true)
core.setOutput('rsc', rscChanged(changedFiles))
core.setOutput('ssr', ssrChanged(changedFiles))
}

main()
2 changes: 0 additions & 2 deletions .github/workflows/check-test-project-fixture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ jobs:

outputs:
code: ${{ steps.detect-changes.outputs.code }}
rsc: ${{ steps.detect-changes.outputs.rsc }}
ssr: ${{ steps.detect-changes.outputs.ssr }}

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ jobs:

outputs:
code: ${{ steps.detect-changes.outputs.code }}
rsc: ${{ steps.detect-changes.outputs.rsc }}
ssr: ${{ steps.detect-changes.outputs.ssr }}

steps:
- uses: actions/checkout@v4
Expand Down
32 changes: 16 additions & 16 deletions packages/cli/src/commands/experimental/setupOpentelemetryHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export const handler = async ({ force, verbose }) => {
const opentelemetryTasks = [
{
title: `Adding OpenTelemetry setup files...`,
task: () => {
task: async () => {
const setupTemplateContent = fs.readFileSync(
path.resolve(__dirname, 'templates', 'opentelemetry.ts.template'),
'utf-8'
'utf-8',
)
const setupScriptContent = ts
? setupTemplateContent
: transformTSToJS(opentelemetryScriptPath, setupTemplateContent)
: await transformTSToJS(opentelemetryScriptPath, setupTemplateContent)

return [
writeFile(opentelemetryScriptPath, setupScriptContent, {
Expand All @@ -69,15 +69,15 @@ export const handler = async ({ force, verbose }) => {
writeFile(
redwoodTomlPath,
configContent.concat(
`\n[experimental.opentelemetry]\n\tenabled = true\n\twrapApi = true`
`\n[experimental.opentelemetry]\n\tenabled = true\n\twrapApi = true`,
),
{
overwriteExisting: true, // redwood.toml always exists
}
},
)
} else {
task.skip(
`The [experimental.opentelemetry] config block already exists in your 'redwood.toml' file.`
`The [experimental.opentelemetry] config block already exists in your 'redwood.toml' file.`,
)
}
},
Expand All @@ -86,7 +86,7 @@ export const handler = async ({ force, verbose }) => {
title: 'Notice: GraphQL function update...',
enabled: () => {
return fs.existsSync(
resolveFile(path.join(getPaths().api.functions, 'graphql'))
resolveFile(path.join(getPaths().api.functions, 'graphql')),
)
},
task: (_ctx, task) => {
Expand All @@ -99,7 +99,7 @@ export const handler = async ({ force, verbose }) => {
'}',
'',
`Which can found at ${c.info(
path.join(getPaths().api.functions, 'graphql')
path.join(getPaths().api.functions, 'graphql'),
)}`,
].join('\n')
},
Expand All @@ -109,7 +109,7 @@ export const handler = async ({ force, verbose }) => {
title: 'Notice: GraphQL function update (server file)...',
enabled: () => {
return fs.existsSync(
resolveFile(path.join(getPaths().api.src, 'server'))
resolveFile(path.join(getPaths().api.src, 'server')),
)
},
task: (_ctx, task) => {
Expand All @@ -122,7 +122,7 @@ export const handler = async ({ force, verbose }) => {
'}',
'',
`Which can found at ${c.info(
path.join(getPaths().api.src, 'server')
path.join(getPaths().api.src, 'server'),
)}`,
].join('\n')
},
Expand All @@ -147,27 +147,27 @@ export const handler = async ({ force, verbose }) => {
'generator client'.length,
schemaContent.indexOf(
'}',
schemaContent.indexOf('generator client')
) + 1
schemaContent.indexOf('generator client'),
) + 1,
)
.trim()

const previewLineExists = clientConfig.includes('previewFeatures')
let newSchemaContents = schemaContent
if (previewLineExists) {
task.skip(
'Please add "tracing" to your previewFeatures in prisma.schema'
'Please add "tracing" to your previewFeatures in prisma.schema',
)
} else {
const newClientConfig = clientConfig.trim().split('\n')
newClientConfig.splice(
newClientConfig.length - 1,
0,
'previewFeatures = ["tracing"]'
'previewFeatures = ["tracing"]',
)
newSchemaContents = newSchemaContents.replace(
clientConfig,
newClientConfig.join('\n')
newClientConfig.join('\n'),
)
}

Expand Down Expand Up @@ -214,7 +214,7 @@ export const handler = async ({ force, verbose }) => {
{
rendererOptions: { collapseSubtasks: false, persistentOutput: true },
renderer: verbose ? 'verbose' : 'default',
}
},
)

try {
Expand Down
52 changes: 28 additions & 24 deletions packages/cli/src/commands/generate/realtime/realtimeHandler.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
import path from 'path'

import camelcase from 'camelcase'
Expand Down Expand Up @@ -82,25 +83,25 @@ export async function handler({ name, type, force, verbose }) {
{
title: `Adding ${name} example subscription ...`,
enabled: () => functionType === 'subscription',
task: () => {
task: async () => {
// sdl

const exampleSdlTemplateContent = path.resolve(
__dirname,
'templates',
'subscriptions',
'blank',
`blank.sdl.ts.template`
`blank.sdl.ts.template`,
)

const sdlFile = path.join(
redwoodPaths.api.graphql,
`${name}.sdl.${isTypeScriptProject() ? 'ts' : 'js'}`
`${name}.sdl.${isTypeScriptProject() ? 'ts' : 'js'}`,
)

const sdlContent = ts
? exampleSdlTemplateContent
: transformTSToJS(sdlFile, exampleSdlTemplateContent)
: await transformTSToJS(sdlFile, exampleSdlTemplateContent)

// service

Expand All @@ -109,17 +110,17 @@ export async function handler({ name, type, force, verbose }) {
'templates',
'subscriptions',
'blank',
`blank.service.ts.template`
`blank.service.ts.template`,
)
const serviceFile = path.join(
redwoodPaths.api.services,
`${name}`,
`${name}.${isTypeScriptProject() ? 'ts' : 'js'}`
`${name}.${isTypeScriptProject() ? 'ts' : 'js'}`,
)

const serviceContent = ts
? exampleServiceTemplateContent
: transformTSToJS(serviceFile, exampleServiceTemplateContent)
: await transformTSToJS(serviceFile, exampleServiceTemplateContent)

// subscription

Expand All @@ -128,18 +129,21 @@ export async function handler({ name, type, force, verbose }) {
'templates',
'subscriptions',
'blank',
`blank.ts.template`
`blank.ts.template`,
)

const exampleFile = path.join(
redwoodPaths.api.subscriptions,
`${name}`,
`${name}.${isTypeScriptProject() ? 'ts' : 'js'}`
`${name}.${isTypeScriptProject() ? 'ts' : 'js'}`,
)

const setupScriptContent = ts
? exampleSubscriptionTemplateContent
: transformTSToJS(exampleFile, exampleSubscriptionTemplateContent)
: await transformTSToJS(
exampleFile,
exampleSubscriptionTemplateContent,
)

// write all files
return [
Expand All @@ -148,62 +152,62 @@ export async function handler({ name, type, force, verbose }) {
generateTemplate(sdlContent, templateVariables(name)),
{
overwriteExisting: force,
}
},
),
writeFile(
serviceFile,
generateTemplate(serviceContent, templateVariables(name)),
{
overwriteExisting: force,
}
},
),
writeFile(
exampleFile,
generateTemplate(setupScriptContent, templateVariables(name)),
{
overwriteExisting: force,
}
},
),
]
},
},
{
title: `Adding ${name} example live query ...`,
enabled: () => functionType === 'liveQuery',
task: () => {
task: async () => {
// sdl
const exampleSdlTemplateContent = path.resolve(
__dirname,
'templates',
'liveQueries',
'blank',
`blank.sdl.ts.template`
`blank.sdl.ts.template`,
)
const sdlFile = path.join(
redwoodPaths.api.graphql,
`${name}.sdl.${isTypeScriptProject() ? 'ts' : 'js'}`
`${name}.sdl.${isTypeScriptProject() ? 'ts' : 'js'}`,
)
const sdlContent = ts
? exampleSdlTemplateContent
: transformTSToJS(sdlFile, exampleSdlTemplateContent)
: await transformTSToJS(sdlFile, exampleSdlTemplateContent)

// service
const exampleServiceTemplateContent = path.resolve(
__dirname,
'templates',
'liveQueries',
'blank',
'blank.service.ts.template'
'blank.service.ts.template',
)

const serviceFile = path.join(
redwoodPaths.api.services,
`${name}`,
`${name}.${isTypeScriptProject() ? 'ts' : 'js'}`
`${name}.${isTypeScriptProject() ? 'ts' : 'js'}`,
)
const serviceContent = ts
? exampleServiceTemplateContent
: transformTSToJS(serviceFile, exampleServiceTemplateContent)
: await transformTSToJS(serviceFile, exampleServiceTemplateContent)

// write all files
return [
Expand All @@ -212,14 +216,14 @@ export async function handler({ name, type, force, verbose }) {
generateTemplate(sdlContent, templateVariables(name)),
{
overwriteExisting: force,
}
},
),
writeFile(
serviceFile,
generateTemplate(serviceContent, templateVariables(name)),
{
overwriteExisting: force,
}
},
),
]
},
Expand All @@ -229,15 +233,15 @@ export async function handler({ name, type, force, verbose }) {
task: async () => {
await generateTypes()
console.log(
'Note: You may need to manually restart GraphQL in VSCode to see the new types take effect.\n\n'
'Note: You may need to manually restart GraphQL in VSCode to see the new types take effect.\n\n',
)
},
},
],
{
rendererOptions: { collapseSubtasks: false, persistentOutput: true },
renderer: verbose ? 'verbose' : 'default',
}
},
)

try {
Expand Down
Loading

0 comments on commit 04eb4f3

Please sign in to comment.