|
1 | | -#!/usr/bin/env node |
2 | | - |
3 | | -const { includeTypes } = require('./utils') |
4 | | -const shell = require('shelljs') |
5 | | -const { join } = require('path') |
6 | | -const resolvePkg = require('resolve-pkg') |
7 | | - |
8 | | -shell.set('-v') // verbose |
9 | | -shell.set('-e') // any error is fatal |
10 | | - |
11 | | -// We include the TypeScript definitions for the bundled 3rd party tools |
12 | | -// thus we need to copy them from "dev" dependencies into our types folder |
13 | | -// and we need to sometimes tweak these types files to use relative paths |
14 | | -// This ensures that globals like Cypress.$, Cypress._ etc are property typed |
15 | | -// yet we do not install "@types/.." packages with "npm install cypress" |
16 | | -// because they can conflict with user's own libraries |
17 | | - |
18 | | -includeTypes.forEach((folder) => { |
19 | | - const source = resolvePkg(`@types/${folder}`, { cwd: join(__dirname, '..', '..') }) |
20 | | - |
21 | | - shell.cp('-R', source, 'types') |
| 1 | +const fs = require('../lib/fs') |
| 2 | +const path = require('path') |
| 3 | + |
| 4 | +/** |
| 5 | + * https://github.com/cypress-io/cypress/pull/5780 |
| 6 | + * Folder names in "node_modules/@types" that were copied to cli/types to generate index.d.ts. |
| 7 | + * They cause type errors in type checker. So, they should be removed. |
| 8 | + */ |
| 9 | +const includeTypes = [ |
| 10 | + 'blob-util', |
| 11 | + 'bluebird', |
| 12 | + 'lodash', |
| 13 | + 'mocha', |
| 14 | + 'minimatch', |
| 15 | + 'sinon', |
| 16 | + 'sinon-chai', |
| 17 | + 'chai', |
| 18 | + 'chai-jquery', |
| 19 | + 'jquery', |
| 20 | +] |
| 21 | + |
| 22 | +includeTypes.forEach((t) => { |
| 23 | + const dir = path.join(__dirname, '../types', t) |
| 24 | + |
| 25 | + if (fs.existsSync(dir)) { |
| 26 | + fs.removeSync(dir) |
| 27 | + } |
22 | 28 | }) |
23 | | - |
24 | | -// jQuery v3.3.x includes "dist" folder that just references back to itself |
25 | | -// causing dtslint to think there are double definitions. Remove that folder. |
26 | | -const typesJqueryDistFolder = join('types', 'jquery', 'dist') |
27 | | - |
28 | | -shell.rm('-rf', typesJqueryDistFolder) |
29 | | - |
30 | | -// fix paths to Chai, jQuery and other types to be relative |
31 | | -shell.sed( |
32 | | - '-i', |
33 | | - '<reference types="chai" />', |
34 | | - '<reference path="../chai/index.d.ts" />', |
35 | | - join('types', 'chai-jquery', 'index.d.ts'), |
36 | | -) |
37 | | - |
38 | | -shell.sed( |
39 | | - '-i', |
40 | | - '<reference types="jquery" />', |
41 | | - '<reference path="../jquery/index.d.ts" />', |
42 | | - join('types', 'chai-jquery', 'index.d.ts'), |
43 | | -) |
44 | | - |
45 | | -const sinonChaiFilename = join('types', 'sinon-chai', 'index.d.ts') |
46 | | - |
47 | | -shell.sed( |
48 | | - '-i', |
49 | | - '<reference types="chai" />', |
50 | | - '<reference path="../chai/index.d.ts" />', |
51 | | - sinonChaiFilename, |
52 | | -) |
53 | | - |
54 | | -// also use relative import via path for sinon-chai |
55 | | -// there is reference comment line we need to fix to be relative |
56 | | -shell.sed( |
57 | | - '-i', |
58 | | - '<reference types="sinon" />', |
59 | | - '<reference path="../sinon/index.d.ts" />', |
60 | | - sinonChaiFilename, |
61 | | -) |
62 | | - |
63 | | -// and an import sinon line to be changed to relative path |
64 | | -shell.sed('-i', 'from \'sinon\';', 'from \'../sinon\';', sinonChaiFilename) |
0 commit comments