-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RSC: vite externalConditions (#9333)
- Loading branch information
Showing
87 changed files
with
2,573 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: Set up RSA test project from fixture | ||
description: Sets up an RSA project for smoke-tests | ||
|
||
runs: | ||
using: node20 | ||
main: 'setUpRsaProjectGitHub.mjs' | ||
|
||
outputs: | ||
test-project-path: | ||
description: Path to the test project |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ions/set-up-rsc-from-fixture/package.json → ...b/actions/set-up-rsa-project/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
.github/actions/set-up-rsa-project/setUpRsaProjectGitHub.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-env node */ | ||
// @ts-check | ||
|
||
import path from 'node:path' | ||
|
||
import core from '@actions/core' | ||
|
||
import { createExecWithEnvInCwd, setUpRscTestProject } from '../actionsLib.mjs' | ||
|
||
const testProjectAndFixtureName = 'test-project-rsa' | ||
const testProjectPath = path.join( | ||
path.dirname(process.cwd()), | ||
testProjectAndFixtureName | ||
) | ||
const execInProject = createExecWithEnvInCwd(testProjectPath) | ||
|
||
setUpRscTestProject( | ||
testProjectPath, | ||
testProjectAndFixtureName, | ||
core, | ||
execInProject | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
.github/actions/set-up-rsc-external-packages-project/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# GitHub action to copy a template RSC project to use for testing | ||
|
||
This action copies a RW project with Streaming SSR and RSC support already set | ||
up. It's used for RSC smoke tests. | ||
|
||
It copies the `__fixtures__/test-project-rsc-external-packages` project, runs | ||
`yarn install` and `project:copy`. Finally it builds the rw app. | ||
|
||
## Testing/running locally | ||
|
||
Go into the github actions folder | ||
`cd .github/actions` | ||
|
||
Then run the following command to execute the action | ||
`node set-up-rsc-external-packages-project/setUpRscExternalPackagesProjectLocally.mjs` | ||
|
||
## Design | ||
|
||
The main logic of the action is in the `../actionsLib.mjs` file. To be able to | ||
run that code both on GitHub and locally it uses dependency injection. The | ||
injection is done by `setupRscExternalPackagesProjectLocally.mjs` for when you | ||
want to run the action on your own machine and by | ||
`setupRscExternalPackagesProjectGitHib.mjs` when it's triggered by GitHub CI. | ||
|
||
When doing further changes to the code here it's very important to keep the | ||
DI scripts as light on logic as possible. Ideally all logic is kept to | ||
`../actionsLib.mjs` so that the same logic is used both locally and on GitHub. | ||
Do note though that more actions share that code, so make sure not to break | ||
the other actions when making changes there. |
10 changes: 10 additions & 0 deletions
10
.github/actions/set-up-rsc-external-packages-project/action.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: Set up RSC test project with external packages from fixture | ||
description: Sets up an RSC project that imports external packages for smoke-tests | ||
|
||
runs: | ||
using: node20 | ||
main: 'setUpRscExternalPackagesProjectGitHub.mjs' | ||
|
||
outputs: | ||
test-project-path: | ||
description: Path to the test project |
11 changes: 11 additions & 0 deletions
11
.github/actions/set-up-rsc-external-packages-project/jsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"target": "esnext", | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"skipLibCheck": false, | ||
"jsx": "react-jsx" | ||
}, | ||
} |
6 changes: 6 additions & 0 deletions
6
.github/actions/set-up-rsc-external-packages-project/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "set-up-rsc-external-packages-project", | ||
"version": "0.0.0", | ||
"private": true, | ||
"type": "module" | ||
} |
22 changes: 22 additions & 0 deletions
22
...ub/actions/set-up-rsc-external-packages-project/setUpRscExternalPackagesProjectGitHub.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-env node */ | ||
// @ts-check | ||
|
||
import path from 'node:path' | ||
|
||
import core from '@actions/core' | ||
|
||
import { createExecWithEnvInCwd, setUpRscTestProject } from '../actionsLib.mjs' | ||
|
||
const testProjectAndFixtureName = 'test-project-rsc-external-packages' | ||
const testProjectPath = path.join( | ||
path.dirname(process.cwd()), | ||
testProjectAndFixtureName | ||
) | ||
const execInProject = createExecWithEnvInCwd(testProjectPath) | ||
|
||
setUpRscTestProject( | ||
testProjectPath, | ||
testProjectAndFixtureName, | ||
core, | ||
execInProject | ||
) |
111 changes: 111 additions & 0 deletions
111
...b/actions/set-up-rsc-external-packages-project/setUpRscExternalPackagesProjectLocally.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* eslint-env node */ | ||
// @ts-check | ||
|
||
import os from 'node:os' | ||
import path from 'node:path' | ||
|
||
import execa from 'execa' | ||
|
||
import { setUpRscTestProject } from '../actionsLib.mjs' | ||
|
||
class ExecaError extends Error { | ||
stdout | ||
stderr | ||
exitCode | ||
|
||
constructor({ stdout, stderr, exitCode }) { | ||
super(`execa failed with exit code ${exitCode}`) | ||
this.stdout = stdout | ||
this.stderr = stderr | ||
this.exitCode = exitCode | ||
} | ||
} | ||
|
||
/** | ||
* @template [EncodingType=string] | ||
* @typedef {import('execa').Options<EncodingType>} ExecaOptions<T> | ||
*/ | ||
|
||
/** | ||
* @typedef {{ | ||
* env?: Record<string, string> | ||
* }} ExecOptions | ||
*/ | ||
|
||
/** | ||
* @param {string} commandLine command to execute (can include additional args). Must be correctly escaped. | ||
* @param {string[]=} args arguments for tool. Escaping is handled by the lib. | ||
* @param {ExecOptions=} options exec options. See ExecOptions | ||
*/ | ||
async function exec(commandLine, args, options) { | ||
return execa(commandLine, args, options) | ||
.then(({ stdout, stderr, exitCode }) => { | ||
if (exitCode !== 0) { | ||
throw new ExecaError({ stdout, stderr, exitCode }) | ||
} | ||
}) | ||
.catch((error) => { | ||
if (error instanceof ExecaError) { | ||
// Rethrow ExecaError | ||
throw error | ||
} else { | ||
const { stdout, stderr, exitCode } = error | ||
console.log('error', error) | ||
throw new ExecaError({ stdout, stderr, exitCode }) | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* @param {string} cwd | ||
* @param {Record<string, string>=} env | ||
* @returns {ExecaOptions<string>} | ||
*/ | ||
function getExecaOptions(cwd, env = {}) { | ||
return { | ||
shell: true, | ||
stdio: 'inherit', | ||
cleanup: true, | ||
cwd, | ||
env, | ||
} | ||
} | ||
|
||
const testProjectAndFixtureName = 'test-project-rsc-external-packages' | ||
|
||
const testProjectPath = path.join( | ||
os.tmpdir(), | ||
'redwood', | ||
testProjectAndFixtureName, | ||
// ":" is problematic with paths | ||
new Date().toISOString().split(':').join('-') | ||
) | ||
|
||
// Mock for @actions/core | ||
const core = { | ||
setOutput: () => {}, | ||
} | ||
|
||
/** | ||
* Exec a command. | ||
* Output will be streamed to the live console. | ||
* Returns promise with return code | ||
* | ||
* @param {string} commandLine command to execute (can include additional args). Must be correctly escaped. | ||
* @param {ExecOptions=} options exec options. See ExecOptions | ||
* @returns {Promise<unknown>} exit code | ||
*/ | ||
function execInProject(commandLine, options) { | ||
return exec( | ||
commandLine, | ||
undefined, | ||
getExecaOptions(testProjectPath, options?.env) | ||
) | ||
} | ||
|
||
setUpRscTestProject( | ||
testProjectPath, | ||
testProjectAndFixtureName, | ||
core, | ||
execInProject | ||
) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.