Skip to content

Commit 5a36e81

Browse files
committed
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.
1 parent cf1f220 commit 5a36e81

File tree

17 files changed

+88
-37
lines changed

17 files changed

+88
-37
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
@@ -58,7 +62,7 @@
5862
- [ ] packages/rewriter **PARTIAL** - entry point is JS
5963
- [ ] packages/root
6064
- [x] packages/runner ✅ **COMPLETED**
61-
- [ ] packages/scaffold-config **PARTIAL** - entry point is JS
65+
- [x] packages/scaffold-config **COMPLETED**
6266
- [ ] packages/server **PARTIAL** - many source/test files in JS. highest priority
6367
- [ ] packages/socket **PARTIAL** - entry point is JS. Tests are JS
6468
- [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 '@packages/graphql/src/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 & 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ The process for adding a new library/framework/bundler is as follows:
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/config/browser/dependencies` is NOT used in the production binary and therefore doesn't need to be included when the package bundles.

packages/scaffold-config/index.js

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

packages/scaffold-config/package.json

Lines changed: 13 additions & 7 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",
1114
"clean-deps": "rimraf node_modules",
1215
"lint": "eslint --ext .js,.jsx,.ts,.tsx,.json, .",
1316
"test": "yarn test-unit",
@@ -29,11 +32,14 @@
2932
"@packages/ts": "0.0.0-development",
3033
"@packages/types": "0.0.0-development",
3134
"chai": "4.2.0",
32-
"mocha": "7.0.1"
35+
"mocha": "7.0.1",
36+
"rimraf": "^6.0.1"
3337
},
3438
"files": [
35-
"src"
39+
"cjs/*",
40+
"esm/*"
3641
],
3742
"types": "src/index.ts",
43+
"module": "esm/index.js",
3844
"nx": {}
3945
}

packages/scaffold-config/src/component-index-template.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import dedent from 'dedent'
22

3-
const componentIndexHtmlGenerator = (headModifier: string = '') => {
3+
export const componentIndexHtmlGenerator = (headModifier: string = '') => {
44
return () => {
55
const template = dedent`
66
<!DOCTYPE html>
@@ -23,5 +23,3 @@ const componentIndexHtmlGenerator = (headModifier: string = '') => {
2323
return template.replace(/\n {4}\n/g, '\n')
2424
}
2525
}
26-
27-
export default componentIndexHtmlGenerator

0 commit comments

Comments
 (0)