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(build): Avoid prebuilding api side, instead use an esbuild plugin #9767

Merged
merged 60 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
096674f
Use async build
dac09 Feb 22, 2023
cd49f30
Fix tests
dac09 Feb 22, 2023
b3ece67
Remove graphql-tag plugin because it doesnt work anyway
dac09 Feb 22, 2023
7f1c721
Explain use of prebuildApiFiles
dac09 Feb 22, 2023
bd2c985
Rename prebuild function
dac09 Feb 22, 2023
9c8fbde
Remove redundant code
dac09 Feb 22, 2023
00a4a85
Revert "Remove graphql-tag plugin because it doesnt work anyway"
dac09 Feb 22, 2023
8932833
Fix failing nftPack test
dac09 Feb 23, 2023
480a257
Fix sourcemaps/debugging with breakpoints
dac09 Feb 23, 2023
3f84ed2
Fix api build test
dac09 Feb 23, 2023
d86822e
Try disabling telemetry on CLI tests
dac09 Feb 24, 2023
ccebbeb
Merge branch 'main' of github.com:redwoodjs/redwood into feat/api-ski…
dac09 Feb 24, 2023
f2ebf21
Try mocking telemetry
dac09 Feb 24, 2023
113ce60
Add "." to esbuild filter
dac09 Feb 24, 2023
dc03ee1
Remove prebuild
dac09 Feb 24, 2023
0f8f8b2
Remove unused import
dac09 Feb 24, 2023
4863387
Increase test timeout
dac09 Feb 24, 2023
c862986
Merge branch 'main' into feat/api-skip-prebuild
dac09 Mar 1, 2023
5d6557e
Mock FS in tests
Tobbe Mar 31, 2023
3308408
Merge branch 'main' into feat/api-skip-prebuild
Tobbe Mar 31, 2023
5b8fdd2
Fix test after merge
Tobbe Mar 31, 2023
fd575ba
Fix merge conflicts
Tobbe Mar 31, 2023
de923ae
Fix merge conflicts
Tobbe Mar 31, 2023
3010ad9
fix tests on windows
Tobbe Mar 31, 2023
18db1cd
Merge branch 'main' into feat/api-skip-prebuild
Tobbe Apr 1, 2023
4c1928b
Merge branch 'main' into feat/api-skip-prebuild
Tobbe Apr 2, 2023
333cac8
Undo jest config change
dac09 Apr 3, 2023
9bac85b
Undo telemetry change
dac09 Apr 3, 2023
7db85c9
Merge branch 'main' of github.com:redwoodjs/redwood into feat/api-ski…
dac09 Dec 28, 2023
4aa171c
Fix tests
dac09 Dec 28, 2023
4ced18a
Try using esbuild's watcher instead
dac09 Dec 28, 2023
47822bf
Hacky poc
dac09 Dec 28, 2023
b5acbd0
Merge branch 'main' into feat/api-skip-prebuild-try-2
dac09 Dec 28, 2023
213fbf7
Remove incorrect comment
dac09 Dec 28, 2023
20370a0
Merge branch 'feat/api-skip-prebuild-try-2' of github.com:dac09/redwo…
dac09 Dec 28, 2023
cc1d7df
Try esbuild rebuild with chokidar
dac09 Dec 29, 2023
2c9b608
Try removing second level nodemon
dac09 Dec 29, 2023
ef5ddb1
Merge branch 'main' into feat/api-skip-prebuild-try-2
dac09 Dec 29, 2023
4812763
Restore nodemon for now
dac09 Dec 29, 2023
2377778
Differenciate rebuild and build
dac09 Dec 29, 2023
fa52105
Merge branch 'feat/api-skip-prebuild-try-2' of github.com:dac09/redwo…
dac09 Dec 29, 2023
655b8f6
Add additional await statements
dac09 Dec 29, 2023
f7a05d6
Merge branch 'main' into feat/api-skip-prebuild-try-2
dac09 Jan 2, 2024
5252042
Merge branch 'main' into feat/api-skip-prebuild-try-2
dac09 Jan 4, 2024
248eac8
Merge branch 'main' of github.com:redwoodjs/redwood into feat/api-ski…
dac09 Jan 5, 2024
7095ceb
Merge branch 'feat/api-skip-prebuild-try-2' of github.com:dac09/redwo…
dac09 Jan 5, 2024
66e1aff
TEMP: try removing clean
dac09 Jan 5, 2024
fd72ccc
Increase timeout on logger
dac09 Jan 5, 2024
04a02cf
add dev server logs, fail fast, bump delay restart
jtoar Jan 6, 2024
4fb918a
Try making api transform async
dac09 Jan 8, 2024
ee9b04d
Merge branch 'main' of github.com:redwoodjs/redwood into feat/api-ski…
dac09 Jan 8, 2024
00c8370
Explain LRU comment
dac09 Jan 8, 2024
8ad4753
Bit more cleanup
dac09 Jan 8, 2024
2fd6b9a
Merge branch 'main' of github.com:redwoodjs/redwood into feat/api-ski…
dac09 Jan 8, 2024
2e82513
Merge branch 'main' of github.com:redwoodjs/redwood into feat/api-ski…
dac09 Jan 15, 2024
a41233b
Increase runMode retries to 3
dac09 Jan 15, 2024
5760000
PR comments and type fixes
dac09 Jan 15, 2024
3a44001
Merge branch 'main' into feat/api-skip-prebuild-try-2
dac09 Jan 15, 2024
14db454
Mroe type tweaks
dac09 Jan 15, 2024
25047fb
Ignore dist paths from jestconfig
dac09 Jan 15, 2024
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
59 changes: 30 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,54 +179,55 @@ jobs:
env:
GITHUB_TOKEN: ${{ github.token }}

- name: 📁 Create a temporary directory
id: createpath
run: |
project_path=$(mktemp -d -t redwood.XXXXXX)
echo "::set-output name=project_path::$project_path"
framework_path=$(pwd)
echo "::set-output name=framework_path::$framework_path"
- name: 🔨 Build
run: yarn build

- name: 🌲 Install Cypress
run: yarn cypress install

- name: 🌲 Create a Redwood App
run: |
./tasks/run-e2e ${{ steps.createpath.outputs.project_path }} \
--no-start \
--bundler ${{ matrix.bundler }}
id: crwa
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false

- name: 🐙 Git init in the Redwood App directory
run: |
project_path=$(mktemp -d -t redwood.XXXXXX)
echo "project-path=$project_path" >> $GITHUB_OUTPUT

git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git init --initial-branch main && git add .
git commit -a --message=init
working-directory: ${{ steps.createpath.outputs.project_path }}

- name: Start server in background
run: yarn rw dev --no-generate --fwd="--no-open" &
working-directory: ${{ steps.createpath.outputs.project_path }}
./tasks/run-e2e "$project_path" \
--bundler ${{ matrix.bundler }} \
--no-build-framework \
--no-start

- name: 🌲 Install Cypress
run: yarn run cypress install
- name: Start the dev server in the background
run: |
yarn rw dev --no-generate --fwd="--no-open" 2>&1 | tee dev_server.log &
working-directory: ${{ steps.crwa.outputs.project-path }}

- name: 🌲 Run cypress
uses: cypress-io/github-action@v5
- name: 🌲 Run Cypress
uses: cypress-io/github-action@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CYPRESS_RW_PATH: "${{ steps.createpath.outputs.project_path }}"
CYPRESS_RW_PATH: ${{ steps.crwa.outputs.project-path }}
with:
# We've already installed dependencies.
install: false
env: true
browser: chrome
record: false
env: true
install: false
wait-on: 'http://[::1]:8910'
working-directory: ./tasks/e2e
spec: |
cypress/e2e/01-tutorial/*.cy.js
cypress/e2e/04-logger/*.cy.js

- uses: actions/upload-artifact@v4
if: always()
with:
name: ${{ matrix.bundler }}-logs
path: |
${{ steps.crwa.outputs.project-path }}/dev_server.log
${{ steps.crwa.outputs.project-path }}/e2e.log

tutorial-e2e-skip:
needs: detect-changes
if: needs.detect-changes.outputs.onlydocs == 'true'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"boxen": "5.1.2",
"core-js": "3.34.0",
"cypress": "13.6.1",
"cypress-fail-fast": "7.1.0",
"cypress-wait-until": "3.0.1",
"dependency-cruiser": "15.5.0",
"dotenv": "16.3.1",
Expand Down
81 changes: 58 additions & 23 deletions packages/api-server/src/watch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

import { fork } from 'child_process'
import type { ChildProcess } from 'child_process'
import { fork } from 'child_process'
import fs from 'fs'
import path from 'path'

Expand All @@ -13,12 +13,16 @@ import { debounce } from 'lodash'
import { hideBin } from 'yargs/helpers'
import yargs from 'yargs/yargs'

import { buildApi } from '@redwoodjs/internal/dist/build/api'
import {
buildApi,
cleanApiBuild,
rebuildApi,
} from '@redwoodjs/internal/dist/build/api'
import { loadAndValidateSdls } from '@redwoodjs/internal/dist/validateSchema'
import {
getPaths,
ensurePosixPath,
getConfig,
getPaths,
resolveFile,
} from '@redwoodjs/project-config'

Expand All @@ -43,9 +47,6 @@ dotenv.config({
path: rwjsPaths.base,
})

// TODO:
// 1. Move this file out of the HTTP server, and place it in the CLI?

let httpServerProcess: ChildProcess

const killApiServer = () => {
Expand All @@ -63,19 +64,32 @@ const validate = async () => {
console.error(c.red(e?.message))
console.log(c.redBright('-'.repeat(40)))

delayRestartServer.cancel()
debouncedBuild.cancel()
debouncedRebuild.cancel()
return false
}
}

const rebuildApiServer = () => {
const buildAndRestart = async ({
rebuild = false,
clean = false,
}: { rebuild?: boolean; clean?: boolean } = {}) => {
try {
// Shutdown API server
killApiServer()

const buildTs = Date.now()
process.stdout.write(c.dim(c.italic('Building... ')))
buildApi()

if (clean) {
await cleanApiBuild()
}

if (rebuild) {
await rebuildApi()
} else {
await buildApi()
}
console.log(c.dim(c.italic('Took ' + (Date.now() - buildTs) + ' ms')))

const forkOpts = {
Expand Down Expand Up @@ -148,11 +162,18 @@ const rebuildApiServer = () => {
// this usually happens when running RedwoodJS generator commands.
// Local writes are very fast, but writes in e2e environments are not,
// so allow the default to be adjust with a env-var.
const delayRestartServer = debounce(
rebuildApiServer,
const debouncedRebuild = debounce(
() => buildAndRestart({ rebuild: true }),
process.env.RWJS_DELAY_RESTART
? parseInt(process.env.RWJS_DELAY_RESTART, 10)
: 5
: 500
)

const debouncedBuild = debounce(
() => buildAndRestart({ rebuild: false }),
process.env.RWJS_DELAY_RESTART
? parseInt(process.env.RWJS_DELAY_RESTART, 10)
: 500
)

// NOTE: the file comes through as a unix path, even on windows
Expand All @@ -165,7 +186,7 @@ const IGNORED_API_PATHS = [
].map((path) => ensurePosixPath(path))

chokidar
.watch(rwjsPaths.api.base, {
.watch([rwjsPaths.api.src], {
persistent: true,
ignoreInitial: true,
ignored: (file: string) => {
Expand All @@ -188,7 +209,11 @@ chokidar
},
})
.on('ready', async () => {
rebuildApiServer()
// First time
await buildAndRestart({
clean: true,
rebuild: false,
})
await validate()
})
.on('all', async (eventName, filePath) => {
Expand All @@ -199,20 +224,30 @@ chokidar
return
}

// We validate here, so that developers will see the error
// As they're running the dev server
if (filePath.includes('.sdl')) {
const isValid = await validate()
if (eventName) {
if (filePath.includes('.sdl')) {
// We validate here, so that developers will see the error
// As they're running the dev server
const isValid = await validate()

// Exit early if not valid
if (!isValid) {
return
// Exit early if not valid
if (!isValid) {
return
}
}
}

console.log(
c.dim(`[${eventName}] ${filePath.replace(rwjsPaths.api.base, '')}`)
)
delayRestartServer.cancel()
delayRestartServer()

if (eventName === 'add' || eventName === 'unlink') {
debouncedBuild.cancel()
debouncedRebuild.cancel()
debouncedBuild()
} else {
// If files have just changed, then rebuild
debouncedRebuild.cancel()
debouncedRebuild()
}
})
2 changes: 1 addition & 1 deletion packages/babel-config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
testPathIgnorePatterns: ['fixtures'],
testPathIgnorePatterns: ['fixtures', 'dist/*'],
}
1 change: 1 addition & 0 deletions packages/babel-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"devDependencies": {
"@types/babel-plugin-tester": "9.0.9",
"@types/babel__core": "7.20.4",
"@types/node": "20.10.4",
"babel-plugin-tester": "11.0.4",
"esbuild": "0.19.9",
"jest": "29.7.0"
Expand Down
19 changes: 14 additions & 5 deletions packages/babel-config/src/__tests__/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { vol } from 'memfs'

import { getPaths, ensurePosixPath } from '@redwoodjs/project-config'
import { ensurePosixPath, getPaths } from '@redwoodjs/project-config'

import type { PluginList } from '../api'
import {
getApiSideBabelConfigPath,
getApiSideBabelPlugins,
Expand Down Expand Up @@ -87,7 +88,7 @@ describe('api', () => {
)

const apiSideBabelConfigPath = getApiSideBabelConfigPath()
expect(ensurePosixPath(apiSideBabelConfigPath)).toMatch(
expect(ensurePosixPath(apiSideBabelConfigPath || '')).toMatch(
'/redwood-app/api/babel.config.js'
)
})
Expand Down Expand Up @@ -185,9 +186,17 @@ describe('api', () => {
},
])

type ModuleResolverConfig = {
root: string[]
alias: Record<string, string>
cwd: string
loglevel: string
}

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const [_, babelPluginModuleResolverConfig] = apiSideBabelPlugins.find(
(plugin) => plugin[0] === 'babel-plugin-module-resolver'
)
)! as [any, ModuleResolverConfig, any]

expect(babelPluginModuleResolverConfig).toMatchObject({
alias: {
Expand Down Expand Up @@ -238,12 +247,12 @@ describe('api', () => {
})
})

function getPluginAliases(plugins) {
function getPluginAliases(plugins: PluginList) {
return plugins.reduce((pluginAliases, plugin) => {
if (plugin.length !== 3) {
return pluginAliases
}

return [...pluginAliases, plugin[2]]
}, [])
}, [] as any)
}
Loading
Loading