Skip to content

Commit 7062573

Browse files
authored
chore: make the @packages/scaffold-config an independent bundle without needed ts-node to register entrypoint. Both ESM and CJS distributions are built and types are used as source to be compatible with older styles of commonjs bundling. Types are not shipped with the package. (#32614)
1 parent d0c4dd9 commit 7062573

File tree

18 files changed

+104
-50
lines changed

18 files changed

+104
-50
lines changed

guides/esm-migration.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
- Unit tests in package are written in TypeScript
1111
- Does not include scripts or system test migrations
1212

13+
#### Notes
14+
15+
When migrating some of these projects away from the `ts-node` entry [see `@packages/scaffold-config` example](https://github.com/cypress-io/cypress/blob/v15.2.0/packages/scaffold-config/index.js), it is somewhat difficult to make separate browser/node entries as the v8-snapshot [tsconfig.json](https://github.com/cypress-io/cypress/blob/v15.2.0/tooling/v8-snapshot/tsconfig.json) is using an older style of module resolution where the `exports` key inside a package's `package.json` is not well supported. Because of this, we need to find ways to bundle code that is needed internally in the browser vs in node without them being a part of the same bundle. This is a temporary work around until we are able to get every package being able to build as an ES Module, which as that point we can re assess how the Cypress binary is being built as well as v8-snapshots, and will allow us to reconfigure this packages to export content in a more proper fashion.
16+
1317
#### Status
1418

1519
##### NPM Packages
@@ -57,7 +61,7 @@
5761
- [ ] packages/rewriter **PARTIAL** - entry point is JS
5862
- [x] packages/root ✅ **COMPLETED**
5963
- [x] packages/runner ✅ **COMPLETED**
60-
- [ ] packages/scaffold-config **PARTIAL** - entry point is JS
64+
- [x] packages/scaffold-config **COMPLETED**
6165
- [ ] packages/server **PARTIAL** - many source/test files in JS. highest priority
6266
- [ ] packages/socket **PARTIAL** - entry point is JS. Tests are JS
6367
- [x] packages/stderr-filtering ✅ **COMPLETED**

packages/data-context/src/actions/WizardActions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NexusGenObjects } from '../gen/nxs.gen'
2-
import { detectFramework, commandsFileBody, supportFileComponent, supportFileE2E, getBundler, CT_FRAMEWORKS, resolveComponentFrameworkDefinition, detectThirdPartyCTFrameworks } from '@packages/scaffold-config'
2+
import { detectFramework, commandsFileBody, supportFileComponent, supportFileE2E, getBundler, CT_FRAMEWORKS, resolveComponentFrameworkDefinition, detectThirdPartyCTFrameworks, componentIndexHtmlGenerator } from '@packages/scaffold-config'
33
import assert from 'assert'
44
import path from 'path'
55
import Debug from 'debug'
@@ -9,7 +9,6 @@ const debug = Debug('cypress:data-context:wizard-actions')
99

1010
import type { DataContext } from '..'
1111
import { addTestingTypeToCypressConfig, AddTestingTypeToCypressConfigOptions } from '@packages/config'
12-
import componentIndexHtmlGenerator from '@packages/scaffold-config/src/component-index-template'
1312

1413
export class WizardActions {
1514
constructor (private ctx: DataContext) {}

packages/frontend-shared/cypress/support/mock-graphql/stubgql-Wizard.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Wizard, WizardBundler } from '../generated/test-graphql-types.gen'
2-
import * as wizardDeps from '@packages/scaffold-config/src/dependencies'
32
import type { MaybeResolver } from './clientTestUtils'
43
import { testNodeId } from './clientTestUtils'
4+
import { WIZARD_DEPENDENCY_REACT, WIZARD_DEPENDENCY_REACT_DOM, WIZARD_DEPENDENCY_TYPESCRIPT } from '@packages/scaffold-config/browser/dependencies'
55

66
const testBundlerVite = {
77
type: 'vite',
@@ -34,28 +34,28 @@ const testFrameworks = [
3434

3535
export const stubWizard: MaybeResolver<Wizard> = {
3636
__typename: 'Wizard',
37-
installDependenciesCommand: `npm install -D ${wizardDeps.WIZARD_DEPENDENCY_REACT.package} ${wizardDeps.WIZARD_DEPENDENCY_REACT_DOM.package} ${wizardDeps.WIZARD_DEPENDENCY_TYPESCRIPT.package}`,
37+
installDependenciesCommand: `npm install -D ${WIZARD_DEPENDENCY_REACT.package} ${WIZARD_DEPENDENCY_REACT_DOM.package} ${WIZARD_DEPENDENCY_TYPESCRIPT.package}`,
3838
packagesToInstall: [
3939
{
4040
__typename: 'WizardNpmPackage',
4141
id: 'react',
4242
satisfied: true,
4343
detectedVersion: '18.3.1',
44-
...wizardDeps.WIZARD_DEPENDENCY_REACT,
44+
...WIZARD_DEPENDENCY_REACT,
4545
},
4646
{
4747
__typename: 'WizardNpmPackage',
4848
id: 'react-dom',
4949
satisfied: true,
5050
detectedVersion: '18.3.1',
51-
...wizardDeps.WIZARD_DEPENDENCY_REACT_DOM,
51+
...WIZARD_DEPENDENCY_REACT_DOM,
5252
},
5353
{
5454
__typename: 'WizardNpmPackage',
5555
id: 'typescript',
5656
satisfied: false,
5757
detectedVersion: '3.9.4',
58-
...wizardDeps.WIZARD_DEPENDENCY_TYPESCRIPT,
58+
...WIZARD_DEPENDENCY_TYPESCRIPT,
5959
},
6060
],
6161
allBundlers,

packages/launchpad/src/setup/InstallDependencies.cy.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { defaultMessages } from '@cy/i18n'
33
import InstallDependencies from './InstallDependencies.vue'
44
import { InstallDependenciesFragmentDoc } from '../generated/graphql-test'
5-
import * as wizardDeps from '@packages/scaffold-config/src/dependencies'
5+
import { WIZARD_DEPENDENCY_REACT, WIZARD_DEPENDENCY_REACT_DOM, WIZARD_DEPENDENCY_TYPESCRIPT } from '@packages/scaffold-config/browser/dependencies'
66

77
describe('<InstallDependencies />', () => {
88
beforeEach(function () {
@@ -73,21 +73,21 @@ describe('<InstallDependencies />', () => {
7373
id: 'react',
7474
satisfied: true,
7575
detectedVersion: '18.3.1',
76-
...wizardDeps.WIZARD_DEPENDENCY_REACT,
76+
...WIZARD_DEPENDENCY_REACT,
7777
},
7878
{
7979
__typename: 'WizardNpmPackage',
8080
id: 'react-dom',
8181
satisfied: true,
8282
detectedVersion: '18.3.1',
83-
...wizardDeps.WIZARD_DEPENDENCY_REACT_DOM,
83+
...WIZARD_DEPENDENCY_REACT_DOM,
8484
},
8585
{
8686
__typename: 'WizardNpmPackage',
8787
id: 'typescript',
8888
satisfied: true,
8989
detectedVersion: '2.0.1',
90-
...wizardDeps.WIZARD_DEPENDENCY_TYPESCRIPT,
90+
...WIZARD_DEPENDENCY_TYPESCRIPT,
9191
},
9292
]
9393

packages/launchpad/src/setup/ManualInstall.cy.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import sinon from 'sinon'
22
import { ManualInstallFragmentDoc } from '../generated/graphql-test'
33
import ManualInstall from './ManualInstall.vue'
4-
import * as deps from '@packages/scaffold-config/src/dependencies'
54
// tslint:disable-next-line: no-implicit-dependencies - need to handle this
65
import { defaultMessages } from '@cy/i18n'
76
import { Clipboard_CopyToClipboardDocument } from '../generated/graphql'
7+
import { WIZARD_DEPENDENCY_REACT, WIZARD_DEPENDENCY_TYPESCRIPT } from '@packages/scaffold-config/browser/dependencies'
88

99
describe('<ManualInstall />', () => {
1010
it('playground', () => {
@@ -18,8 +18,8 @@ describe('<ManualInstall />', () => {
1818
})
1919

2020
it('lists packages and can copy install command to clipboard', { viewportWidth: 800, viewportHeight: 600 }, () => {
21-
const framework = deps.WIZARD_DEPENDENCY_REACT
22-
const language = deps.WIZARD_DEPENDENCY_TYPESCRIPT
21+
const framework = WIZARD_DEPENDENCY_REACT
22+
const language = WIZARD_DEPENDENCY_TYPESCRIPT
2323

2424
const stubCopy = sinon.stub()
2525

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
**/tsconfig.json
2+
cjs/
3+
esm/
4+
browser/
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
src/**/*.js
1+
cjs/
2+
esm/
3+
browser/

packages/scaffold-config/README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,30 @@ We will also attempt to scaffold a configuration file for projects using React a
99
### Supported Frameworks and Libraries
1010

1111
| Name | Version| Dev Server | Version | Library | Component Adaptor | Example Project |
12-
| ---------------- | -------| ---------- | ------- | ------------------ | -------------------------- | ------------------------------------------------------------------- |
13-
| React | - | Vite | 4, 5 | React 18, 19 | `@cypress/react@latest` | [Link](../../system-tests/projects/react-vite-ts-configured) |
14-
| React | - | Webpack | 4, 5 | React 18, 19 | `@cypress/vue@latest` | [Link](../../system-tests/projects/react18) |
15-
| Vue | - | Vite | 4, 5, 6 | Vue 3 | `@cypress/react@latest` | [Link](../../system-tests/projects/vue3-vite-ts-configured) |
16-
| Vue | - | Webpack | 4, 5 | Vue 3 | `@cypress/vue@latest` | [Link](../../system-tests/projects/vue3-webpack-ts-configured) |
17-
| Angular | - | Webpack | 5 | Angular 17, 18, 19 | `@cypress/angular@latest` | [Link](../../system-tests/projects/angular-cli-configured) |
18-
| Svelte | - | Vite | 4, 5, 6 | Svelte 5 | `@cypress/svelte@latest` | [Link](../../system-tests/projects/svelte-vite-configured) |
19-
| Svelte | - | Webpack | 4, 5 | Svelte 5 | `@cypress/svelte@latest` | [Link](../../system-tests/projects/svelte-webpack-configured) |
20-
| Next.js | 14, 15 | Webpack | 4, 5 | React 18, 19 | `@cypress/react@latest` | [Link](../../system-tests/projects/nextjs-configured) |
12+
| ---------------- | -------| ---------- | ---------- | ------------------ | -------------------------- | ------------------------------------------------------------------- |
13+
| React | - | Vite | 5, 6, 7 | React 18, 19 | `@cypress/react@latest` | [Link](../../system-tests/projects/react-vite-ts-configured) |
14+
| React | - | Webpack | 5 | React 18, 19 | `@cypress/vue@latest` | [Link](../../system-tests/projects/react18) |
15+
| Vue | - | Vite | 5, 6, 7 | Vue 3 | `@cypress/react@latest` | [Link](../../system-tests/projects/vue3-vite-ts-configured) |
16+
| Vue | - | Webpack | 5 | Vue 3 | `@cypress/vue@latest` | [Link](../../system-tests/projects/vue3-webpack-ts-configured) |
17+
| Angular | - | Webpack | 5 | Angular 17, 18, 19 | `@cypress/angular@latest` | [Link](../../system-tests/projects/angular-cli-configured) |
18+
| Svelte | - | Vite | 5, 6, 7 | Svelte 5 | `@cypress/svelte@latest` | [Link](../../system-tests/projects/svelte-vite-configured) |
19+
| Svelte | - | Webpack | 5 | Svelte 5 | `@cypress/svelte@latest` | [Link](../../system-tests/projects/svelte-webpack-configured) |
20+
| Next.js | 14, 15 | Webpack | 5 | React 18, 19 | `@cypress/react@latest` | [Link](../../system-tests/projects/nextjs-configured) |
2121

2222
### Adding More Projects
2323

2424
The process for adding a new library/framework/bundler is as follows:
2525

2626
1. Add your framework in [`src/frameworks.ts`](./src/frameworks.ts).
2727
2. Any new dependencies are declared in [`src/constants.ts`](./src/constants.ts). Don't forget to add a description.
28-
3. Ensure your project has the correct library and bundler detected with a test in [`test/unit/detect.spec.ts`](./test/unit/detect.spec.ts).
28+
3. Ensure your project has the correct library and bundler detected with a test in [`test/unit/detect.spec.ts`](./test/detect.spec.ts).
2929
3. Add a new project with the correct `cypress.config.js` and `package.json` to [system-tests/projects](../../system-tests/projects). It should be `<name>-configured`, which is a working example with some specs. Ensure it will run on CI by adding it to [`component_testing_spec.ts`](../../system-tests/test/component_testing_spec.ts).
3030
4. Add another project called `<name>-unconfigured`, which represents the project prior to having Cypress added. This will be used in step 5.
3131
5. Add a test to [`scaffold-component-testing.cy.ts`](../launchpad/cypress/e2e/scaffold-component-testing.cy.ts) to ensure your project has the correct `cypress.config.js` generated. Use an existing test as a template.
32+
33+
### Internal testing
34+
35+
`@packages/scaffold-config/browser/dependencies` is NOT used in the production binary and therefore doesn't need to be included when the package bundles.
36+
37+
We also build an ESM version of `@packages/scaffold-config` but it isn't currently in use as this packages is only used in server-side CommonJS currently.
38+

packages/scaffold-config/index.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/scaffold-config/package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
"name": "@packages/scaffold-config",
33
"version": "0.0.0-development",
44
"description": "Logic related to scaffolding new projects using launchpad",
5-
"main": "index.js",
6-
"browser": "src/index.ts",
5+
"main": "cjs/index.js",
76
"scripts": {
8-
"build-prod": "tsc || echo 'built, with errors'",
9-
"check-ts": "tsc --noEmit && yarn -s tslint",
10-
"clean": "rimraf --glob './src/*.js' './src/**/*.js' './src/**/**/*.js' './test/**/*.js' || echo 'cleaned'",
7+
"build": "yarn build:cjs && yarn build:esm && yarn build:browser",
8+
"build-prod": "yarn build",
9+
"build:browser": "rimraf browser && tsc -p tsconfig.browser.json",
10+
"build:cjs": "rimraf cjs && tsc -p tsconfig.cjs.json",
11+
"build:esm": "rimraf esm && tsc -p tsconfig.esm.json",
12+
"check-ts": "tsc -p tsconfig.cjs.json --noEmit && yarn -s tslint -p tsconfig.cjs.json",
13+
"clean": "rimraf esm cjs browser",
1114
"clean-deps": "rimraf node_modules",
1215
"lint": "eslint --ext .js,.jsx,.ts,.tsx,.json, .",
1316
"test": "vitest run",
@@ -28,11 +31,14 @@
2831
"devDependencies": {
2932
"@packages/ts": "0.0.0-development",
3033
"@packages/types": "0.0.0-development",
34+
"rimraf": "^6.0.1",
3135
"vitest": "^3.2.4"
3236
},
3337
"files": [
34-
"src"
38+
"cjs/*",
39+
"esm/*"
3540
],
3641
"types": "src/index.ts",
42+
"module": "esm/index.js",
3743
"nx": {}
3844
}

0 commit comments

Comments
 (0)