Skip to content

Commit e436c23

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 5130593 commit e436c23

File tree

14 files changed

+61
-36
lines changed

14 files changed

+61
-36
lines changed

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'
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'
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'
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
src/**/*.js
1+
cjs/
2+
esm/

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",
6+
"browser": "esm/index.js",
77
"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'",
8+
"build": "yarn build:cjs && yarn build:esm",
9+
"build-prod": "yarn build",
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

packages/scaffold-config/src/ct-detect-third-party.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export async function detectThirdPartyCTFrameworks (
9999

100100
// Start at the project root and check each directory above it until we see
101101
// an indication that the current directory is the root of the repository.
102-
await findUp(async (directory: string) => {
102+
await findUp(async (directory: string): Promise<findUp.Match> => {
103103
fullPathGlobs = [
104104
path.join(directory, CT_FRAMEWORK_GLOBAL_GLOB),
105105
path.join(directory, CT_FRAMEWORK_NAMESPACED_GLOB),

packages/scaffold-config/src/frameworks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs-extra'
22
import * as dependencies from './dependencies'
3-
import componentIndexHtmlGenerator from './component-index-template'
3+
import { componentIndexHtmlGenerator } from './component-index-template'
44
import debugLib from 'debug'
55
import semver from 'semver'
66
import { isThirdPartyDefinition } from './ct-detect-third-party'

0 commit comments

Comments
 (0)