forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook-require.js
43 lines (35 loc) · 1.34 KB
/
hook-require.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const path = require('path')
const env = process.env.CYPRESS_INTERNAL_ENV === 'production' ? 'prod' : 'dev'
process.env.PROJECT_BASE_DIR = process.env.PROJECT_BASE_DIR ?? path.join(__dirname, '..', '..')
const isDev = env === 'dev'
function runWithSnapshot (forceTypeScript) {
const { snapshotRequire } = require('@packages/v8-snapshot-require')
const projectBaseDir = process.env.PROJECT_BASE_DIR
const supportTS = forceTypeScript || typeof global.getSnapshotResult === 'undefined' || global.supportTypeScript
snapshotRequire(projectBaseDir, {
diagnosticsEnabled: isDev,
useCache: true,
transpileOpts: {
supportTS,
initTranspileCache: supportTS
? () => require('dirt-simple-file-cache').DirtSimpleFileCache.initSync(projectBaseDir, { cacheDir: path.join(projectBaseDir, 'node_modules', '.dsfc'), keepInMemoryCache: true })
: undefined,
tsconfig: {
compilerOptions: {
useDefineForClassFields: false, // default
importsNotUsedAsValues: 'remove', // default
},
},
},
})
}
const hookRequire = ({ forceTypeScript }) => {
if (['1', 'true'].includes(process.env.DISABLE_SNAPSHOT_REQUIRE) || typeof getSnapshotResult === 'undefined') {
require('@packages/ts/register')
} else {
runWithSnapshot(forceTypeScript)
}
}
module.exports = {
hookRequire,
}