From 58e0ab91604618ea6f75932622f7e66e419270e6 Mon Sep 17 00:00:00 2001 From: Zachary Williams Date: Mon, 31 Oct 2022 17:25:30 -0500 Subject: [PATCH] fix: remove dependence on @cypress/ types (#24415) * fix: remove dependence on @cypress/ types * I added a patch but didn't wire up patch-package * address comments * remove patch, use updated @vue-test-utils --- npm/mount-utils/create-rollup-entry.mjs | 8 ++- npm/mount-utils/package.json | 1 + npm/vue/inline-types.ts | 69 ------------------------- npm/vue/package.json | 2 +- npm/vue2/package.json | 4 +- scripts/sync-exported-npm-with-cli.js | 3 ++ yarn.lock | 53 +++++++++++-------- 7 files changed, 44 insertions(+), 96 deletions(-) delete mode 100644 npm/vue/inline-types.ts diff --git a/npm/mount-utils/create-rollup-entry.mjs b/npm/mount-utils/create-rollup-entry.mjs index 2db5e4781262..3b230760b69a 100644 --- a/npm/mount-utils/create-rollup-entry.mjs +++ b/npm/mount-utils/create-rollup-entry.mjs @@ -4,6 +4,7 @@ import resolve from '@rollup/plugin-node-resolve' import commonjs from '@rollup/plugin-commonjs' import _ from 'lodash' import { readFileSync } from 'fs' +import dts from 'rollup-plugin-dts' const pkg = JSON.parse(readFileSync('./package.json')) @@ -33,7 +34,7 @@ export function createEntries (options) { check: format === 'es', tsconfigOverride: { compilerOptions: { - declaration: format === 'es', + declaration: false, target: 'es6', module: format === 'cjs' ? 'es2015' : 'esnext', }, @@ -67,5 +68,10 @@ export function createEntries (options) { console.log(`Building ${format}: ${finalConfig.output.file}`) return finalConfig + }).concat({ + input, + output: [{ file: 'dist/index.d.ts', format: 'es' }], + plugins: [dts({ respectExternal: true })], + external: config.external || [], }) } diff --git a/npm/mount-utils/package.json b/npm/mount-utils/package.json index b171f80da79c..8ab99841eecb 100644 --- a/npm/mount-utils/package.json +++ b/npm/mount-utils/package.json @@ -15,6 +15,7 @@ "@rollup/plugin-commonjs": "^17.1.0", "@rollup/plugin-node-resolve": "^11.1.1", "rollup": "^2.38.5", + "rollup-plugin-dts": "^4.2.3", "rollup-plugin-typescript2": "^0.29.0", "typescript": "^4.7.4" }, diff --git a/npm/vue/inline-types.ts b/npm/vue/inline-types.ts deleted file mode 100644 index f7ddbd0c6155..000000000000 --- a/npm/vue/inline-types.ts +++ /dev/null @@ -1,69 +0,0 @@ -import fs from 'fs-extra' -import globby from 'globby' -import path from 'path' - -// We depend on @vue/test-utils and inline this library in the -// @cypress/vue bundle. -// Unfortunately, although rollup can inline libraries like this, -// TypeScript doesn't do the same for d.ts files - it mains imports -// to the original library, which we do not actually ship in the binary. - -// This script copies the `d.ts` files into the `dist` directory -// then modifies the `index.d.ts` to reference the copied type definitions -// instead of the ones from the local node_modules directory that we don't -// actually bundle in the binary. - -function rewriteSourceForInlineTypes (src: string) { - return src - // Need to modify these lines: - // import type { MountingOptions, VueWrapper } from '@vue/test-utils'; - // import * as _VueTestUtils from '@vue/test-utils'; - // to - // import type { MountingOptions, VueWrapper } from './@vue/test-utils'; - // import * as _VueTestUtils from './@vue/test-utils'; - .replaceAll(`'@vue/test-utils';`, `'./@vue/test-utils';`) - - // Need to modify this line: - // config: import("@vue/test-utils/config).GlobalConfigOptions; - // to - // config: import("./@vue/test-utils/config").GlobalConfigOptions; - .replaceAll(`@vue/test-utils/dist/config`, `./@vue/test-utils/config`) -} - -async function inlineTestUtilsTypes () { - console.log('[npm/vue] Inline type definitions for @vue/test-utils and rewriting source') // eslint-disable-line no-console - - // get the directory with the type definitions we want to inline - const vtuDir = path.dirname(require.resolve('@vue/test-utils')) - - // grab the type definitions - const typeDefs = await globby('**/*.d.ts', { cwd: vtuDir }) - - // make a directory for them in npm/vue/dist - const typeDefDir = path.join(__dirname, 'dist', '@vue', 'test-utils') - - await fs.mkdir(typeDefDir, { recursive: true }) - - // copy the type definitions - await Promise.all( - typeDefs.map((tds) => { - const from = path.join(vtuDir, tds) - const to = path.join(typeDefDir, tds) - - return fs.copy(from, to, { recursive: true }) - }), - ) - - const cypressVueMainTypeDef = path.join(__dirname, 'dist', 'index.d.ts') - - // modify index.d.ts to reference relative type definitions instead of ones from - // node_modules - const updateWithRelativeImports = rewriteSourceForInlineTypes( - await fs.readFile(cypressVueMainTypeDef, 'utf-8'), - ) - - // rewrite index.d.ts, now modified to point at local type definitions. - await fs.writeFile(cypressVueMainTypeDef, updateWithRelativeImports) -} - -inlineTestUtilsTypes() diff --git a/npm/vue/package.json b/npm/vue/package.json index 67ce209c999f..85cc3b8d68fd 100644 --- a/npm/vue/package.json +++ b/npm/vue/package.json @@ -8,7 +8,7 @@ "cy:open": "node ../../scripts/cypress.js open --component --project ${PWD}", "cy:run": "node ../../scripts/cypress.js run --component --project ${PWD}", "build": "rimraf dist && rollup -c rollup.config.mjs", - "postbuild": "node --require @packages/ts/register ./inline-types.ts && node ../../scripts/sync-exported-npm-with-cli.js", + "postbuild": "node ../../scripts/sync-exported-npm-with-cli.js", "typecheck": "yarn tsd && vue-tsc --noEmit", "test": "yarn cy:run", "tsd": "yarn build && yarn tsc -p test-tsd/tsconfig.tsd.json", diff --git a/npm/vue2/package.json b/npm/vue2/package.json index e5e39d390aa6..3193201e89af 100644 --- a/npm/vue2/package.json +++ b/npm/vue2/package.json @@ -11,13 +11,11 @@ "test": "echo \"Tests for @cypress/vue2 are run from system-tests\"", "watch": "yarn build --watch --watch.exclude ./dist/**/*" }, - "dependencies": { - "@vue/test-utils": "^1.1.3" - }, "devDependencies": { "@cypress/mount-utils": "0.0.0-development", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-replace": "^2.3.1", + "@vue/test-utils": "^1.3.1", "tslib": "^2.1.0", "typescript": "^4.7.4", "vue": "2.6.12" diff --git a/scripts/sync-exported-npm-with-cli.js b/scripts/sync-exported-npm-with-cli.js index 133db71ed65e..8a894317a5dd 100644 --- a/scripts/sync-exported-npm-with-cli.js +++ b/scripts/sync-exported-npm-with-cli.js @@ -29,6 +29,9 @@ packlist({ path: currentPackageDir }) 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) + // 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) => { diff --git a/yarn.lock b/yarn.lock index 573440bfb887..e6362d169fb3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -824,12 +824,12 @@ dependencies: "@babel/highlight" "^7.8.3" -"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.14.5", "@babel/code-frame@^7.16.7", "@babel/code-frame@^7.5.5", "@babel/code-frame@^7.8.3": - version "7.16.7" - resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.16.7.tgz#44416b6bd7624b998f5b1af5d470856c40138789" - integrity sha512-iAXqUn8IIeBTNd72xsFlgaXHkMBMt6y4HJp1tIaK465CWLT/fG1aqB7ykr95gHHmlBdGbFeWWfyB4NJJ0nmeIg== +"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.14.5", "@babel/code-frame@^7.16.7", "@babel/code-frame@^7.18.6", "@babel/code-frame@^7.5.5", "@babel/code-frame@^7.8.3": + version "7.18.6" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.18.6.tgz#3b25d38c89600baa2dcc219edfa88a74eb2c427a" + integrity sha512-TDCmlK5eOvH+eH7cdAFlNXeVJqWIQ7gW9tY1GJIpUtFb6CmjVyq2VM3u71bOyR8CRihcCgMUYoDNyLXao3+70Q== dependencies: - "@babel/highlight" "^7.16.7" + "@babel/highlight" "^7.18.6" "@babel/compat-data@^7.13.0", "@babel/compat-data@^7.13.11", "@babel/compat-data@^7.13.5", "@babel/compat-data@^7.16.4", "@babel/compat-data@^7.16.8", "@babel/compat-data@^7.17.7", "@babel/compat-data@^7.9.0": version "7.17.7" @@ -1101,10 +1101,10 @@ dependencies: "@babel/types" "^7.16.7" -"@babel/helper-validator-identifier@^7.14.9", "@babel/helper-validator-identifier@^7.16.7": - version "7.16.7" - resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.16.7.tgz#e8c602438c4a8195751243da9031d1607d247cad" - integrity sha512-hsEnFemeiW4D08A5gUAZxLBTXpZ39P+a+DGDsHw1yxqyQ/jzFEnxf5uTEGp+3bzAbNOxU1paTgYS4ECU/IgfDw== +"@babel/helper-validator-identifier@^7.14.9", "@babel/helper-validator-identifier@^7.16.7", "@babel/helper-validator-identifier@^7.18.6": + version "7.19.1" + resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz#7eea834cf32901ffdc1a7ee555e2f9c27e249ca2" + integrity sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w== "@babel/helper-validator-option@^7.12.17", "@babel/helper-validator-option@^7.16.7": version "7.16.7" @@ -1130,12 +1130,12 @@ "@babel/traverse" "^7.17.9" "@babel/types" "^7.17.0" -"@babel/highlight@^7.0.0", "@babel/highlight@^7.10.4", "@babel/highlight@^7.16.7", "@babel/highlight@^7.8.3": - version "7.16.10" - resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.16.10.tgz#744f2eb81579d6eea753c227b0f570ad785aba88" - integrity sha512-5FnTQLSLswEj6IkgVw5KusNUUFY9ZGqe/TRFnP/BKYHYgfh7tc+C7mwiy95/yNP7Dh9x580Vv8r7u7ZfTBFxdw== +"@babel/highlight@^7.0.0", "@babel/highlight@^7.10.4", "@babel/highlight@^7.18.6", "@babel/highlight@^7.8.3": + version "7.18.6" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.18.6.tgz#81158601e93e2563795adcbfbdf5d64be3f2ecdf" + integrity sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g== dependencies: - "@babel/helper-validator-identifier" "^7.16.7" + "@babel/helper-validator-identifier" "^7.18.6" chalk "^2.0.0" js-tokens "^4.0.0" @@ -7658,10 +7658,10 @@ resolved "https://registry.yarnpkg.com/@vue/test-utils/-/test-utils-2.0.2.tgz#0b5edd683366153d5bc5a91edc62f292118710eb" integrity sha512-E2P4oXSaWDqTZNbmKZFVLrNN/siVN78YkEqs7pHryWerrlZR9bBFLWdJwRoguX45Ru6HxIflzKl4vQvwRMwm5g== -"@vue/test-utils@^1.1.3": - version "1.3.0" - resolved "https://registry.yarnpkg.com/@vue/test-utils/-/test-utils-1.3.0.tgz#d563decdcd9c68a7bca151d4179a2bfd6d5c3e15" - integrity sha512-Xk2Xiyj2k5dFb8eYUKkcN9PzqZSppTlx7LaQWBbdA8tqh3jHr/KHX2/YLhNFc/xwDrgeLybqd+4ZCPJSGPIqeA== +"@vue/test-utils@^1.3.1": + version "1.3.1" + resolved "https://registry.yarnpkg.com/@vue/test-utils/-/test-utils-1.3.1.tgz#be181387f4dc19f17c2bbd451b0f97ed48329642" + integrity sha512-99MBPPGBx/Dfe1kHE8eqjDmFjKSC1LZiNbHcece/sm56NppNEm4qk13vFAqHdXJp9snrR5CVQaBeBj9eYNNhjQ== dependencies: dom-event-types "^1.0.0" lodash "^4.17.15" @@ -22937,10 +22937,10 @@ magic-string@^0.25.5, magic-string@^0.25.7: dependencies: sourcemap-codec "^1.4.4" -magic-string@^0.26.1, magic-string@^0.26.2: - version "0.26.3" - resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.26.3.tgz#25840b875140f7b4785ab06bddc384270b7dd452" - integrity sha512-u1Po0NDyFcwdg2nzHT88wSK0+Rih0N1M+Ph1Sp08k8yvFFU3KR72wryS7e1qMPJypt99WB7fIFVCA92mQrMjrg== +magic-string@^0.26.1, magic-string@^0.26.2, magic-string@^0.26.6: + version "0.26.7" + resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.26.7.tgz#caf7daf61b34e9982f8228c4527474dac8981d6f" + integrity sha512-hX9XH3ziStPoPhJxLq1syWuZMxbDvGNbVchfrdCtanC7D13888bMFow61x8axrx+GfHLtVeAx2kxL7tTGRl+Ow== dependencies: sourcemap-codec "^1.4.8" @@ -29606,6 +29606,15 @@ rollup-plugin-copy@3.4.0: globby "10.0.1" is-plain-object "^3.0.0" +rollup-plugin-dts@^4.2.3: + version "4.2.3" + resolved "https://registry.yarnpkg.com/rollup-plugin-dts/-/rollup-plugin-dts-4.2.3.tgz#04c3615df1ffab4228aa9d540697eaca61e01f47" + integrity sha512-jlcpItqM2efqfIiKzDB/IKOS9E9fDvbkJSGw5GtK/PqPGS9eC3R3JKyw2VvpTktZA+TNgJRMu1NTv244aTUzzQ== + dependencies: + magic-string "^0.26.6" + optionalDependencies: + "@babel/code-frame" "^7.18.6" + rollup-plugin-node-builtins@^2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/rollup-plugin-node-builtins/-/rollup-plugin-node-builtins-2.1.2.tgz#24a1fed4a43257b6b64371d8abc6ce1ab14597e9"