Skip to content

Commit

Permalink
Merge branch 'main' into tobbe-rsc-remove-worker
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Sep 6, 2024
2 parents ae9801f + 1cc6d0a commit a22337e
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .changesets/11458.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- fix(linting): Re-enable babel presets during linting of javascript projects (#11458) by @Josh-Walker-GM

The `yarn rw lint` command was failing for JavaScript projects. This change re-enables certain babel plugins to correct this issue and allow this command to succeed again.
3 changes: 3 additions & 0 deletions .changesets/11459.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- fix(jobs): Make deleteSuccessfulJobs configurable (#11459) by @Tobbe

Make the jobs Executor respect the `deleteSuccessfulJobs` config option
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"test": "nx run-many -t test -- --minWorkers=1 --maxWorkers=4",
"test-ci": "nx run-many -t test",
"test:k6": "tsx ./tasks/k6-test/run-k6-tests.mts",
"test:types": "tstyche"
"test:types": "nx run-many -t test:types"
},
"resolutions": {
"@storybook/react-dom-shim@npm:7.6.17": "https://verdaccio.tobbe.dev/@storybook/react-dom-shim/-/react-dom-shim-8.0.8.tgz",
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-config/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Flags {
forJest?: boolean // will change the alias for module-resolver plugin
forPrerender?: boolean // changes what babel-plugin-redwood-routes-auto-loader does
forRsc?: boolean
forJavaScriptLinting?: boolean // will enable presets to supporting linting in the absence of typescript related presets/plugins/parsers
}

export const getWebSideBabelPlugins = (
Expand Down Expand Up @@ -166,7 +167,7 @@ export const getWebSideOverrides = (
export const getWebSideBabelPresets = (options: Flags) => {
// When we perform prerendering we don't use vite, so we need to add the
// appropriate presets for react, env, and typescript, etc.
if (options.forPrerender || options.forJest) {
if (options.forPrerender || options.forJest || options.forJavaScriptLinting) {
let reactPresetConfig: babel.PluginItem = { runtime: 'automatic' }

// This is a special case, where @babel/preset-react needs config
Expand Down
7 changes: 5 additions & 2 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
getApiSideDefaultBabelConfig,
getWebSideDefaultBabelConfig,
} = require('@redwoodjs/babel-config')
const { getConfig } = require('@redwoodjs/project-config')
const { getConfig, isTypeScriptProject } = require('@redwoodjs/project-config')

const config = getConfig()

Expand All @@ -16,7 +16,10 @@ const getProjectBabelOptions = () => {
// So we just take it out and put it as a separate item
// Ignoring overrides, as I don't think it has any impact on linting
const { overrides: _webOverrides, ...otherWebConfig } =
getWebSideDefaultBabelConfig()
getWebSideDefaultBabelConfig({
// We have to enable certain presets like `@babel/preset-react` for JavaScript projects
forJavaScriptLinting: !isTypeScriptProject(),
})

const { overrides: _apiOverrides, ...otherApiConfig } =
getApiSideDefaultBabelConfig()
Expand Down
18 changes: 9 additions & 9 deletions packages/jobs/src/core/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { AdapterRequiredError, JobRequiredError } from '../errors.js'
import { loadJob } from '../loaders.js'
import type { BaseJob, BasicLogger } from '../types.js'

interface Options {
export interface ExecutorOptions {
adapter: BaseAdapter
job: BaseJob
logger?: BasicLogger
Expand All @@ -28,15 +28,15 @@ export const DEFAULTS = {
}

export class Executor {
options: Required<Options>
adapter: Options['adapter']
logger: NonNullable<Options['logger']>
options: Required<ExecutorOptions>
adapter: ExecutorOptions['adapter']
logger: NonNullable<ExecutorOptions['logger']>
job: BaseJob
maxAttempts: NonNullable<Options['maxAttempts']>
deleteFailedJobs: NonNullable<Options['deleteFailedJobs']>
deleteSuccessfulJobs: NonNullable<Options['deleteSuccessfulJobs']>
maxAttempts: NonNullable<ExecutorOptions['maxAttempts']>
deleteFailedJobs: NonNullable<ExecutorOptions['deleteFailedJobs']>
deleteSuccessfulJobs: NonNullable<ExecutorOptions['deleteSuccessfulJobs']>

constructor(options: Options) {
constructor(options: ExecutorOptions) {
this.options = { ...DEFAULTS, ...options }

// validate that everything we need is available
Expand Down Expand Up @@ -68,7 +68,7 @@ export class Executor {

await this.adapter.success({
job: this.job,
deleteJob: DEFAULT_DELETE_SUCCESSFUL_JOBS,
deleteJob: this.deleteSuccessfulJobs,
})
} catch (error: any) {
this.logger.error(
Expand Down
33 changes: 33 additions & 0 deletions packages/jobs/src/core/__tests__/Executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DEFAULT_LOGGER } from '../../consts.js'
import * as errors from '../../errors.js'
import type { BaseJob } from '../../types.js'
import { Executor } from '../Executor.js'
import type { ExecutorOptions } from '../Executor.js'

import { MockAdapter, mockLogger } from './mocks.js'

Expand Down Expand Up @@ -146,6 +147,38 @@ describe('perform', () => {
})
})

it('keeps the job around after successful job if instructed to do so', async () => {
const mockAdapter = new MockAdapter()
const mockJob = {
id: 1,
name: 'TestJob',
path: 'TestJob/TestJob',
args: ['foo'],
attempts: 0,

perform: vi.fn(),
}
const options: ExecutorOptions = {
adapter: mockAdapter,
logger: mockLogger,
job: mockJob,
deleteSuccessfulJobs: false,
}
const executor = new Executor(options)

// spy on the success function of the adapter
const adapterSpy = vi.spyOn(mockAdapter, 'success')
// mock the `loadJob` loader to return the job mock
mocks.loadJob.mockImplementation(() => mockJob)

await executor.perform()

expect(adapterSpy).toHaveBeenCalledWith({
job: options.job,
deleteJob: false,
})
})

it('invokes the `failure` method on the adapter when job fails', async () => {
const mockAdapter = new MockAdapter()
const mockError = new Error('mock error in the job perform method')
Expand Down
8 changes: 8 additions & 0 deletions packages/project-config/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,11 @@ export function projectIsEsm() {

return true
}

export const isTypeScriptProject = () => {
const paths = getPaths()
return (
fs.existsSync(path.join(paths.web.base, 'tsconfig.json')) ||
fs.existsSync(path.join(paths.api.base, 'tsconfig.json'))
)
}

0 comments on commit a22337e

Please sign in to comment.