Merge branch 'develop' into release/14.0.0

This commit is contained in:
Jennifer Shehane
2024-10-22 15:19:08 -04:00
committed by GitHub
44 changed files with 1305 additions and 1172 deletions

View File

@@ -4,5 +4,6 @@
"private": true,
"scripts": {
"lint": "eslint --ext .js,.ts,.json, ."
}
},
"nx": {}
}

View File

@@ -6,6 +6,7 @@
* with this version of the binary
*/
const path = require('path')
const Arborist = require('@npmcli/arborist')
const packlist = require('npm-packlist')
const fs = require('fs-extra')
@@ -16,66 +17,70 @@ const currentPackageDir = process.cwd()
// 1. We'll run npm's own "packlist" against the npm package to be published (@cypress/react, etc)
// to make sure we don't miss any files when we copy them over to the CLI package
// The files that will be returned here are the ones from @cypress/react's package.json['files'] key.
packlist({ path: currentPackageDir })
.then((files) => {
// 2. Move all of the files that would be published under @cypress/react
// to be copied under cli/react (drop the @cypress namespace)
const cliPath = path.join(__dirname, '..', 'cli')
const arborist = new Arborist({ path: currentPackageDir })
// Typically, these packages are independently published as @cypress/package-name
// e.g. @cypress/vue => import whatever from 'cypress/vue'
// The files will wind up at cypress/cli/vue/*
const currentPackageConfig = require(path.join(process.cwd(), 'package.json'))
const exportName = currentPackageConfig.name.replace('@cypress/', '')
const outDir = path.join(cliPath, exportName)
arborist.loadActual().then((tree) => {
packlist(tree)
.then((files) => {
// 2. Move all of the files that would be published under @cypress/react
// to be copied under cli/react (drop the @cypress namespace)
const cliPath = path.join(__dirname, '..', 'cli')
// Remove output directory to clean up old files before building
fs.removeSync(outDir)
// Typically, these packages are independently published as @cypress/package-name
// e.g. @cypress/vue => import whatever from 'cypress/vue'
// The files will wind up at cypress/cli/vue/*
const currentPackageConfig = require(path.join(process.cwd(), 'package.json'))
const exportName = currentPackageConfig.name.replace('@cypress/', '')
const outDir = path.join(cliPath, exportName)
// 3. For each file, mkdir if not exists, and then copy the dist'd assets over
// to write to the `cliPackageConfig` at the end
files.forEach((f) => {
// mkdir if not exists
const { dir } = path.parse(f)
// Remove output directory to clean up old files before building
fs.removeSync(outDir)
if (dir) {
fs.mkdirSync(path.join(outDir, dir), { recursive: true })
// 3. For each file, mkdir if not exists, and then copy the dist'd assets over
// to write to the `cliPackageConfig` at the end
files.forEach((f) => {
// mkdir if not exists
const { dir } = path.parse(f)
if (dir) {
fs.mkdirSync(path.join(outDir, dir), { recursive: true })
}
fs.cpSync(path.join(currentPackageDir, f), path.join(outDir, f))
})
// After everything is copied, let's update the Cypress cli package.json['exports'] map.
const isModule = currentPackageConfig.type === 'module'
const types = currentPackageConfig.types
const cliPackageConfig = require(path.join(cliPath, 'package.json'))
const subPackageExports = cliPackageConfig.exports[`./${exportName}`] = {}
const esmEntry = isModule ? currentPackageConfig.main : currentPackageConfig.module
if (types) {
// ./react/dist/cypress-react-cjs.js, etc
subPackageExports.types = `./${exportName}/${types}`
}
fs.cpSync(path.join(currentPackageDir, f), path.join(outDir, f))
if (esmEntry) {
// ./react/dist/cypress-react-esm.js, etc
subPackageExports.import = `./${exportName}/${esmEntry}`
}
if (!isModule) {
// ./react/dist/cypress-react-cjs.js, etc
subPackageExports.require = `./${exportName}/${currentPackageConfig.main}`
}
if (!cliPackageConfig.files.includes(exportName)) {
cliPackageConfig.files.push(exportName)
}
const output = `${JSON.stringify(cliPackageConfig, null, 2) }\n`
console.log('Writing to CLI package.json for', exportName)
fs.writeFileSync(path.join(cliPath, 'package.json'), output, 'utf-8')
})
// After everything is copied, let's update the Cypress cli package.json['exports'] map.
const isModule = currentPackageConfig.type === 'module'
const types = currentPackageConfig.types
const cliPackageConfig = require(path.join(cliPath, 'package.json'))
const subPackageExports = cliPackageConfig.exports[`./${exportName}`] = {}
const esmEntry = isModule ? currentPackageConfig.main : currentPackageConfig.module
if (types) {
// ./react/dist/cypress-react-cjs.js, etc
subPackageExports.types = `./${exportName}/${types}`
}
if (esmEntry) {
// ./react/dist/cypress-react-esm.js, etc
subPackageExports.import = `./${exportName}/${esmEntry}`
}
if (!isModule) {
// ./react/dist/cypress-react-cjs.js, etc
subPackageExports.require = `./${exportName}/${currentPackageConfig.main}`
}
if (!cliPackageConfig.files.includes(exportName)) {
cliPackageConfig.files.push(exportName)
}
const output = `${JSON.stringify(cliPackageConfig, null, 2) }\n`
console.log('Writing to CLI package.json for', exportName)
fs.writeFileSync(path.join(cliPath, 'package.json'), output, 'utf-8')
})