Repository navigation
Expand file tree
/
Copy pathpackage-scripts.cjs
More file actions
212 lines (193 loc) · 7.99 KB
/
Copy pathpackage-scripts.cjs
File metadata and controls
212 lines (193 loc) · 7.99 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// package-scripts.js is a convention used by the 'nps' utility
// It's like package.json scripts, but more flexible.
const { concurrent, series, runInNewWindow } = require('nps-utils')
const pkg = require('./package.json')
const builtFiles = pkg.files.filter(f => !['cli.js', 'cli.cjs'].includes(f))
const retry = n => cmd => Array(n).fill(`(${cmd})`).join(` || `)
const retry3 = retry(3)
const quote = cmd => cmd.replaceAll("'", "\\'").replaceAll('"', '\\"')
const optional = cmd =>
`(${cmd}) || echo "Optional command '${quote(cmd)}' failed".`
const timeout = n => cmd => `timeout -t ${n}m -- ${cmd}`
// const timeout15 = timeout(15)
const timeout15 = (command) =>
process.platform === 'win32' ? command : `timeout -t 15m -- ${command}`
/**
* Returns the environment variables to configure bundlewatch for the current CI provider.
* @returns {string}
*/
const bundlewatchEnvironmentVariables = () => {
// Interpolating an unset variable yields the literal string 'undefined',
// which bundlewatch then treats as a real value. Skip the option instead.
const options = []
const set = (name, value) => {
if (value !== undefined && value !== '') options.push(`${name}='${value}'`)
}
set('BUNDLEWATCH_GITHUB_TOKEN', process.env.BUNDLEWATCH_GITHUB_TOKEN)
set('CI_REPO_OWNER', 'isomorphic-git')
set('CI_REPO_NAME', 'isomorphic-git')
// Azure DevOps Pipeline is not detected by bundlewatch (which uses ci-env).
if (process.env.SYSTEM_COLLECTIONURI !== undefined) {
// On a pull request build Azure checks out a merge commit, so report the
// head of the source branch, which is the commit the status belongs to.
set(
'CI_COMMIT_SHA',
process.env.SYSTEM_PULLREQUEST_SOURCECOMMITID ??
process.env.BUILD_SOURCEVERSION
)
set('CI_BRANCH', process.env.SYSTEM_PULLREQUEST_SOURCEBRANCH)
set('CI_BRANCH_BASE', process.env.SYSTEM_PULLREQUEST_TARGETBRANCH)
}
// GitHub is not detected well using bundlewatch@0.2.5.
else if (process.env.GITHUB_SHA) {
set('CI_COMMIT_SHA', process.env.GITHUB_SHA)
// Get the current and base branch for pull requests
if (process.env.GITHUB_EVENT_NAME === 'pull_request') {
set('CI_BRANCH', process.env.GITHUB_HEAD_REF)
set('CI_BRANCH_BASE', process.env.GITHUB_BASE_REF)
}
// Otherwise, get the current branch. This handles push and workflow_dispatch events.
// This does not handle tags (refs/tags/<tag_name>).
else if (process.env.GITHUB_REF?.startsWith('refs/heads/')) {
set('CI_BRANCH', process.env.GITHUB_REF.replace('refs/heads/', ''))
}
}
return options.join(' ')
}
const jestEnv =
'NODE_OPTIONS="--experimental-vm-modules --max-old-space-size-percentage=80" TEST_ENV=node'
const jestCommand = 'node --experimental-vm-modules --max-old-space-size-percentage=80 node_modules/jest/bin/jest.js --ci --coverage'
// const jestCommand = 'jest --ci --coverage'
// const jestCommand = 'jest --ci --coverage --runInBand --logHeapUsage'
const jestBrowser = browserName => {
const cmd = `${jestCommand} --config jest-browser.config.js`
if (process.env.CI) {
// On CI we need to set environment variables differently depending on the shell
if (process.platform === 'win32') {
// PowerShell / cmd.exe compatible version using cross-env
return `cross-env ${jestEnv} JEST_BROWSER=${browserName} JEST_PUPPETEER_CONFIG=.config/jest-puppeteer.js ${retry3(cmd)}`
} else {
// Unix-like shells (bash, sh, etc.) – keep the original export style
return `export ${jestEnv}\nexport JEST_BROWSER=${browserName}\nexport JEST_PUPPETEER_CONFIG=.config/jest-puppeteer.js\n${retry3(timeout15(cmd))}`
}
}
// Non-CI case (local development) – already cross-platform via cross-env
return `cross-env ${jestEnv} JEST_BROWSER=${browserName} JEST_PUPPETEER_CONFIG=.config/jest-puppeteer.js ${cmd}`
}
module.exports = {
scripts: {
clean: {
default: `rm -rf ${builtFiles.join(' ')} internal-apis.*`,
},
lint: {
default: 'eslint src __tests__',
fix: optional('eslint --fix src __tests__'),
},
format: {
default: series.nps('lint.fix'),
},
watch: {
default: concurrent.nps('watch.rollup', 'watch.jest'),
rollup: runInNewWindow('rollup -cw'),
jest: runInNewWindow('cross-env DEBUG=* jest --watch'),
},
contributors: {
add: 'node ./__tests__/__helpers__/add-contributor.cjs',
generate: 'all-contributors generate',
check: 'all-contributors check',
},
build: {
default: series.nps(
'build.rollup',
'build.typings',
'build.webpack',
'build.indexjson',
'build.treeshake',
'build.docs',
'build.size',
'build.pack'
),
test: series.nps(
'build.rollup',
'build.typings',
'build.webpack',
'build.indexjson',
'build.treeshake',
'build.size',
'build.pack'
),
rollup: 'rollup -c --no-treeshake',
typings:
'tsc -p declaration.tsconfig.json && cp index.d.ts index.umd.min.d.ts',
webpack: 'webpack --config webpack.config.cjs',
indexjson:
'npx make-index __tests__/__fixtures__ -o __tests__/__fixtures__/index.json -i __tests__/__fixtures__/index.json && node __tests__/__helpers__/make_superblock.cjs',
treeshake: 'agadoo',
docs: 'node ./__tests__/__helpers__/generate-docs.cjs',
size: process.env.CI
? optional(`cross-env ${bundlewatchEnvironmentVariables()} bundlewatch`)
: optional(`cross-env bundlewatch`),
pack: 'npm pack',
},
website: {
default: process.env.CI
? series.nps(
'website.codemirrorify',
'website.cpstatic',
'website.build',
'website.publish'
)
: series.nps(
'website.codemirrorify',
'website.cpstatic',
'website.dev'
),
codemirrorify:
'(cd website/packages/codemirrorify && npm install && npm run build)',
cpstatic:
'cp website/packages/codemirrorify/dist/main.js website/static/js/codemirrorify.js && node __tests__/__helpers__/copy-to-website.cjs',
build: '(cd website && npm install && npm run build)',
dev: '(cd website && npm start)',
publish: '(cd website && node ./scripts/deploy-gh-pages.cjs)',
},
// ATTENTION:
// LIST OF SAFE PORTS FOR SAUCE LABS (Edge and Safari) https://wiki.saucelabs.com/display/DOCS/Sauce+Connect+Proxy+FAQS#SauceConnectProxyFAQS-CanIAccessApplicationsonlocalhost?
// 'proxy' needs to run in the background during tests. I'm too lazy to auto start/stop it from within the browser tests.
proxy: {
default: `cors-proxy run`,
start: `cors-proxy start`,
stop: `cors-proxy stop`,
},
gitserver: {
default: `cross-env GIT_HTTP_MOCK_SERVER_PORT=8888 GIT_HTTP_MOCK_SERVER_ROOT=__tests__/__fixtures__ git-http-mock-server`,
start: `cross-env GIT_HTTP_MOCK_SERVER_PORT=8888 GIT_HTTP_MOCK_SERVER_ROOT=__tests__/__fixtures__ git-http-mock-server start`,
stop: `cross-env GIT_HTTP_MOCK_SERVER_PORT=8888 GIT_HTTP_MOCK_SERVER_ROOT=__tests__/__fixtures__ git-http-mock-server stop`,
},
test: {
default: series.nps(
'lint',
'build.test',
'test.typecheck',
'test.setup',
'test.node',
'test.chrome',
'test.teardown'
),
browsers: series.nps('test.chrome', 'test.firefox'),
typecheck: 'tsc -p tsconfig.json',
setup: series.nps('proxy.start', 'gitserver.start'),
teardown: series.nps('proxy.stop', 'gitserver.stop'),
node: process.env.CI
? (process.platform === 'win32'
? `cross-env ${jestEnv} ${retry3(jestCommand)}`
: `export ${jestEnv}\n${retry3(timeout15(jestCommand))}`)
: `cross-env-shell ${jestEnv} ${jestCommand}`,
chrome: jestBrowser('chrome'),
firefox: jestBrowser('firefox'),
},
prepublish: {
default: series.nps('prepublish.version', 'build'),
version: `node __tests__/__helpers__/fix-version-number.cjs`,
},
},
}