Skip to content

Commit

Permalink
fix sync script with updateds npm-packlist
Browse files Browse the repository at this point in the history
  • Loading branch information
AtofStryker committed Oct 21, 2024
1 parent e0177ff commit a61cee0
Show file tree
Hide file tree
Showing 4 changed files with 668 additions and 53 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"@graphql-tools/delegate": "8.2.1",
"@graphql-tools/utils": "8.2.3",
"@graphql-tools/wrap": "8.1.1",
"@npmcli/arborist": "8.0.0",
"@nrwl/nx-cloud": "19.0.0",
"@octokit/auth-app": "6.0.3",
"@octokit/core": "5.0.2",
Expand Down Expand Up @@ -180,6 +181,7 @@
"mocha-junit-reporter": "2.2.0",
"mocha-multi-reporters": "1.1.7",
"mock-fs": "5.2.0",
"npm-packlist": "9.0.0",
"p-defer": "^3.0.0",
"patch-package": "6.4.7",
"playwright-webkit": "1.24.2",
Expand Down
1 change: 1 addition & 0 deletions packages/graphql/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,7 @@ enum ErrorTypeEnum {
EXPERIMENTAL_STUDIO_REMOVED
EXPERIMENTAL_USE_DEFAULT_DOCUMENT_DOMAIN_E2E_ONLY
EXTENSION_NOT_LOADED
FIREFOX_CDP_FAILED_TO_CONNECT
FIREFOX_COULD_NOT_CONNECT
FIREFOX_GC_INTERVAL_REMOVED
FIREFOX_GECKODRIVER_FAILURE
Expand Down
91 changes: 49 additions & 42 deletions scripts/sync-exported-npm-with-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -16,66 +17,72 @@ 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
console.log(currentPackageDir)

const arborist = new Arborist({ path: currentPackageDir })

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')
const cliPath = path.join(__dirname, '..', 'cli')

// 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)
// 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)

// Remove output directory to clean up old files before building
fs.removeSync(outDir)
// Remove output directory to clean up old files before building
fs.removeSync(outDir)

// 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) => {
// 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)
const { dir } = path.parse(f)

if (dir) {
fs.mkdirSync(path.join(outDir, dir), { recursive: true })
}
if (dir) {
fs.mkdirSync(path.join(outDir, dir), { recursive: true })
}

fs.cpSync(path.join(currentPackageDir, f), path.join(outDir, f))
})
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
// 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 cliPackageConfig = require(path.join(cliPath, 'package.json'))

const subPackageExports = cliPackageConfig.exports[`./${exportName}`] = {}
const esmEntry = isModule ? currentPackageConfig.main : currentPackageConfig.module
const subPackageExports = cliPackageConfig.exports[`./${exportName}`] = {}
const esmEntry = isModule ? currentPackageConfig.main : currentPackageConfig.module

if (types) {
if (types) {
// ./react/dist/cypress-react-cjs.js, etc
subPackageExports.types = `./${exportName}/${types}`
}
subPackageExports.types = `./${exportName}/${types}`
}

if (esmEntry) {
if (esmEntry) {
// ./react/dist/cypress-react-esm.js, etc
subPackageExports.import = `./${exportName}/${esmEntry}`
}
subPackageExports.import = `./${exportName}/${esmEntry}`
}

if (!isModule) {
if (!isModule) {
// ./react/dist/cypress-react-cjs.js, etc
subPackageExports.require = `./${exportName}/${currentPackageConfig.main}`
}
subPackageExports.require = `./${exportName}/${currentPackageConfig.main}`
}

if (!cliPackageConfig.files.includes(exportName)) {
cliPackageConfig.files.push(exportName)
}
if (!cliPackageConfig.files.includes(exportName)) {
cliPackageConfig.files.push(exportName)
}

const output = `${JSON.stringify(cliPackageConfig, null, 2) }\n`
const output = `${JSON.stringify(cliPackageConfig, null, 2) }\n`

console.log('Writing to CLI package.json for', exportName)
console.log('Writing to CLI package.json for', exportName)

fs.writeFileSync(path.join(cliPath, 'package.json'), output, 'utf-8')
fs.writeFileSync(path.join(cliPath, 'package.json'), output, 'utf-8')
})
})
Loading

0 comments on commit a61cee0

Please sign in to comment.