@prisma/cli 2.20.1 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/LICENSE +158 -0
  2. package/README.md +29 -28
  3. package/dist/adapters/config.js +74 -0
  4. package/dist/adapters/local-state.js +98 -0
  5. package/dist/adapters/mock-api.js +57 -0
  6. package/dist/adapters/token-storage.js +43 -0
  7. package/dist/cli.js +9 -0
  8. package/dist/cli2.js +59 -0
  9. package/dist/commands/app/index.js +216 -0
  10. package/dist/commands/auth/index.js +42 -0
  11. package/dist/commands/branch/index.js +51 -0
  12. package/dist/commands/project/index.js +45 -0
  13. package/dist/controllers/app.js +834 -0
  14. package/dist/controllers/auth.js +107 -0
  15. package/dist/controllers/branch.js +73 -0
  16. package/dist/controllers/project.js +214 -0
  17. package/dist/controllers/select-prompt-port.js +12 -0
  18. package/dist/lib/app/bun-project.js +39 -0
  19. package/dist/lib/app/env-vars.js +24 -0
  20. package/dist/lib/app/local-dev.js +150 -0
  21. package/dist/lib/app/preview-build.js +142 -0
  22. package/dist/lib/app/preview-interaction.js +38 -0
  23. package/dist/lib/app/preview-progress.js +139 -0
  24. package/dist/lib/app/preview-provider.js +232 -0
  25. package/dist/lib/auth/auth-ops.js +57 -0
  26. package/dist/lib/auth/client.js +22 -0
  27. package/dist/lib/auth/guard.js +34 -0
  28. package/dist/lib/auth/login.js +117 -0
  29. package/dist/output/patterns.js +93 -0
  30. package/dist/presenters/app.js +405 -0
  31. package/dist/presenters/auth.js +73 -0
  32. package/dist/presenters/branch.js +111 -0
  33. package/dist/presenters/project.js +84 -0
  34. package/dist/shell/command-meta.js +329 -0
  35. package/dist/shell/command-runner.js +33 -0
  36. package/dist/shell/errors.js +66 -0
  37. package/dist/shell/global-flags.js +25 -0
  38. package/dist/shell/help.js +78 -0
  39. package/dist/shell/output.js +54 -0
  40. package/dist/shell/prompt.js +31 -0
  41. package/dist/shell/runtime.js +51 -0
  42. package/dist/shell/ui.js +59 -0
  43. package/dist/use-cases/auth.js +70 -0
  44. package/dist/use-cases/branch.js +95 -0
  45. package/dist/use-cases/create-cli-gateways.js +93 -0
  46. package/dist/use-cases/project.js +75 -0
  47. package/package.json +49 -137
  48. package/build/child.js +0 -4110
  49. package/build/index.js +0 -104447
  50. package/build/public/.DS_Store +0 -0
  51. package/build/public/assets/alert.60ea9f84.svg +0 -5
  52. package/build/public/assets/array.1a36c222.svg +0 -4
  53. package/build/public/assets/boolean.9188b434.svg +0 -4
  54. package/build/public/assets/browser.21a575be.js +0 -1
  55. package/build/public/assets/browser.38b7fdb1.js +0 -1
  56. package/build/public/assets/browser.cdd2249a.js +0 -1
  57. package/build/public/assets/chevron-down.24f76e3c.svg +0 -3
  58. package/build/public/assets/cross.c2610cf5.svg +0 -11
  59. package/build/public/assets/datetime.a3bf710a.svg +0 -4
  60. package/build/public/assets/download.8d34b65a.svg +0 -4
  61. package/build/public/assets/ellipsis.a8c5a34a.svg +0 -10
  62. package/build/public/assets/enum.7ec0b64c.svg +0 -6
  63. package/build/public/assets/folder.d77b8eaf.svg +0 -6
  64. package/build/public/assets/hamburger.5fdadeac.svg +0 -4
  65. package/build/public/assets/logotype.a960b169.svg +0 -4
  66. package/build/public/assets/number.85ddf96b.svg +0 -7
  67. package/build/public/assets/object.0ba944a6.svg +0 -5
  68. package/build/public/assets/play.8811691e.svg +0 -6
  69. package/build/public/assets/plus.8fbf7ad3.svg +0 -4
  70. package/build/public/assets/read.79154521.svg +0 -1
  71. package/build/public/assets/refresh.d5448ccc.svg +0 -4
  72. package/build/public/assets/search.2ed766ce.svg +0 -7
  73. package/build/public/assets/settings.5ad25af2.svg +0 -8
  74. package/build/public/assets/string.ea615a24.svg +0 -4
  75. package/build/public/assets/tick-indeterminate.aec8a44d.svg +0 -3
  76. package/build/public/assets/tick.8cbb6a93.svg +0 -4
  77. package/build/public/assets/vendor.c4d0f081.js +0 -354
  78. package/build/public/demo.html +0 -17
  79. package/build/public/demoChunk.js +0 -2
  80. package/build/public/electron-darwin.html +0 -19
  81. package/build/public/electron-linux.html +0 -18
  82. package/build/public/electron-mac.html +0 -18
  83. package/build/public/electron-win.html +0 -17
  84. package/build/public/electron-win32.html +0 -18
  85. package/build/public/electron.html +0 -17
  86. package/build/public/electronBus.js +0 -2
  87. package/build/public/electronChunk.js +0 -2
  88. package/build/public/favicon/apple-touch-icon.png +0 -0
  89. package/build/public/favicon/favicon-16x16.png +0 -0
  90. package/build/public/favicon/favicon-32x32.png +0 -0
  91. package/build/public/favicon/prisma.png +0 -0
  92. package/build/public/favicon.svg +0 -5
  93. package/build/public/fonts/.DS_Store +0 -0
  94. package/build/public/fonts/Inter.ttf +0 -0
  95. package/build/public/fonts/RobotoMono.ttf +0 -0
  96. package/build/public/icons/.DS_Store +0 -0
  97. package/build/public/icons/alert.svg +0 -5
  98. package/build/public/icons/array.svg +0 -4
  99. package/build/public/icons/bin.svg +0 -37
  100. package/build/public/icons/boolean.svg +0 -4
  101. package/build/public/icons/check.svg +0 -3
  102. package/build/public/icons/chevron-down.svg +0 -3
  103. package/build/public/icons/code.svg +0 -4
  104. package/build/public/icons/cross.svg +0 -11
  105. package/build/public/icons/data-tool.svg +0 -5
  106. package/build/public/icons/database.svg +0 -4
  107. package/build/public/icons/datetime.svg +0 -4
  108. package/build/public/icons/double-arrow-right.svg +0 -4
  109. package/build/public/icons/download.svg +0 -4
  110. package/build/public/icons/ellipsis.svg +0 -10
  111. package/build/public/icons/enum.svg +0 -6
  112. package/build/public/icons/expand.svg +0 -4
  113. package/build/public/icons/eye.svg +0 -20
  114. package/build/public/icons/filters.svg +0 -5
  115. package/build/public/icons/folder.svg +0 -6
  116. package/build/public/icons/hamburger.svg +0 -4
  117. package/build/public/icons/icon.svg +0 -199
  118. package/build/public/icons/logo.svg +0 -199
  119. package/build/public/icons/logotype.svg +0 -4
  120. package/build/public/icons/number.svg +0 -7
  121. package/build/public/icons/object.svg +0 -5
  122. package/build/public/icons/play.svg +0 -6
  123. package/build/public/icons/plus.svg +0 -4
  124. package/build/public/icons/refresh.svg +0 -4
  125. package/build/public/icons/search.svg +0 -7
  126. package/build/public/icons/settings.svg +0 -8
  127. package/build/public/icons/string.svg +0 -4
  128. package/build/public/icons/tick-indeterminate.svg +0 -3
  129. package/build/public/icons/tick.svg +0 -4
  130. package/build/public/illustrations/.DS_Store +0 -0
  131. package/build/public/illustrations/empty.svg +0 -1
  132. package/build/public/illustrations/read.svg +0 -1
  133. package/build/public/illustrations/searching.svg +0 -1
  134. package/build/public/images/.DS_Store +0 -0
  135. package/build/public/images/icon-1024.png +0 -0
  136. package/build/public/index.css +0 -1
  137. package/build/public/index.html +0 -49
  138. package/build/public/index.js +0 -1
  139. package/build/public/main.31f688a6254e294d9128.css +0 -118
  140. package/build/public/main.31f688a6254e294d9128.css.map +0 -1
  141. package/build/public/main.364c712f32662ff0e43d.css +0 -116
  142. package/build/public/main.364c712f32662ff0e43d.css.map +0 -1
  143. package/build/public/main.42ef3fe7e97347765c91.css +0 -118
  144. package/build/public/main.42ef3fe7e97347765c91.css.map +0 -1
  145. package/build/public/main.503446defafe7aeca2f3.css +0 -116
  146. package/build/public/main.503446defafe7aeca2f3.css.map +0 -1
  147. package/build/public/main.c50a3b5980fe26f78b65.css +0 -118
  148. package/build/public/main.c50a3b5980fe26f78b65.css.map +0 -1
  149. package/build/public/main.cda25e5813776c2af295.css +0 -116
  150. package/build/public/main.cda25e5813776c2af295.css.map +0 -1
  151. package/build/public/main.dbac3b290f78404ff579.css +0 -116
  152. package/build/public/main.dbac3b290f78404ff579.css.map +0 -1
  153. package/build/public/main.f8ce44e122e5e2b8f778.css +0 -118
  154. package/build/public/main.f8ce44e122e5e2b8f778.css.map +0 -1
  155. package/build/public/main.fc9ea7521a4aecce1a77.css +0 -118
  156. package/build/public/main.fc9ea7521a4aecce1a77.css.map +0 -1
  157. package/build/public/main.js +0 -403
  158. package/build/public/main.js.map +0 -1
  159. package/build/public/mainChunk.0a84f3ba4d2ab481e877.css +0 -116
  160. package/build/public/mainChunk.1b327d58afbddc917bce.css +0 -118
  161. package/build/public/mainChunk.2cdf583b2bd51aa67587.css +0 -118
  162. package/build/public/mainChunk.544af00f7e9ffcbe782c.css +0 -118
  163. package/build/public/mainChunk.56f96a13868b2b4a53be.css +0 -118
  164. package/build/public/mainChunk.5cee429bfbf06e7ecb39.css +0 -118
  165. package/build/public/mainChunk.a862474ed4cdb421ffa2.css +0 -118
  166. package/build/public/mainChunk.ada34153c4911b5ac22b.css +0 -118
  167. package/build/public/mainChunk.c16a8d01b2c49b2f2751.css +0 -118
  168. package/build/public/mainChunk.ca4a878d5478b9320be8.css +0 -116
  169. package/build/public/mainChunk.e3adc8758b4395546cef.css +0 -116
  170. package/build/public/mainChunk.f2c59fcbfc455d8b9de5.css +0 -118
  171. package/build/public/mainChunk.js +0 -396
  172. package/build/public/manifest.json +0 -34
  173. package/build/public/preview.html +0 -16
  174. package/build/public/previewBus.js +0 -2
  175. package/build/public/previewChunk.js +0 -2
  176. package/build/public/projects.html +0 -86
  177. package/build/public/server.html +0 -16
  178. package/build/public/serverBus.js +0 -2
  179. package/build/public/serverChunk.js +0 -2
  180. package/build/public/splash.html +0 -17
  181. package/build/public/studioBundle.828f34b1781061528841.css +0 -118
  182. package/build/public/studioBundle.bfe9138b2e0293fcb7da.css +0 -118
  183. package/build/public/studioBundle.c5b256eede880e502aac.css +0 -118
  184. package/build/public/studioBundle.e43df511c8e2e368900a.css +0 -118
  185. package/build/public/studioBundle.e69382554c2a2942ae32.css +0 -118
  186. package/build/public/studioBundle.ee21aa56a3999a2b380b.css +0 -118
  187. package/build/public/studioBundle.js +0 -396
  188. package/build/public/vercel.html +0 -16
  189. package/build/public/vercelChunk.js +0 -2
  190. package/build/public/views/index.pug +0 -89
  191. package/build/xdg-open +0 -1066
  192. package/install/index.js +0 -5
  193. package/preinstall/index.js +0 -46
  194. package/prisma-client/README.md +0 -27
  195. package/prisma-client/generator-build/.DS_Store +0 -0
  196. package/prisma-client/generator-build/index.js +0 -79697
  197. package/prisma-client/index-browser.js +0 -3
  198. package/prisma-client/index.d.ts +0 -1
  199. package/prisma-client/index.js +0 -11
  200. package/prisma-client/package.json +0 -138
  201. package/prisma-client/runtime/index-browser.d.ts +0 -267
  202. package/prisma-client/runtime/index-browser.js +0 -2273
  203. package/prisma-client/runtime/index.d.ts +0 -1018
  204. package/prisma-client/runtime/index.js +0 -35028
  205. package/prisma-client/scripts/backup-index-browser.js +0 -3
  206. package/prisma-client/scripts/backup-index.d.ts +0 -1
  207. package/prisma-client/scripts/backup-index.js +0 -11
  208. package/prisma-client/scripts/colors.js +0 -180
  209. package/prisma-client/scripts/default-index-browser.js +0 -12
  210. package/prisma-client/scripts/default-index.d.ts +0 -47
  211. package/prisma-client/scripts/default-index.js +0 -12
  212. package/prisma-client/scripts/get-packed-client.js +0 -12
  213. package/prisma-client/scripts/mock-fs.js +0 -14
  214. package/prisma-client/scripts/postinstall.d.ts +0 -5
  215. package/prisma-client/scripts/postinstall.js +0 -398
  216. package/scripts/install-entry.js +0 -8
  217. package/scripts/preinstall-entry.js +0 -9
@@ -1,398 +0,0 @@
1
- // @ts-check
2
- const childProcess = require('child_process')
3
- const { promisify } = require('util')
4
- const fs = require('fs')
5
- const path = require('path')
6
- const c = require('./colors')
7
-
8
- const exec = promisify(childProcess.exec)
9
- const copyFile = promisify(fs.copyFile)
10
- const mkdir = promisify(fs.mkdir)
11
- const stat = promisify(fs.stat)
12
-
13
- function debug(message, ...optionalParams) {
14
- if (process.env.DEBUG && process.env.DEBUG === 'prisma:postinstall') {
15
- console.log(message, ...optionalParams)
16
- }
17
- }
18
- /**
19
- * Adds `package.json` to the end of a path if it doesn't already exist'
20
- * @param {string} pth
21
- */
22
- function addPackageJSON(pth) {
23
- if (pth.endsWith('package.json')) return pth
24
- return path.join(pth, 'package.json')
25
- }
26
-
27
- /**
28
- * Looks up for a `package.json` which is not `@prisma/cli` or `prisma` and returns the directory of the package
29
- * @param {string} startPath - Path to Start At
30
- * @param {number} limit - Find Up limit
31
- * @returns {string | null}
32
- */
33
- function findPackageRoot(startPath, limit = 10) {
34
- if (!startPath || !fs.existsSync(startPath)) return null
35
- let currentPath = startPath
36
- // Limit traversal
37
- for (let i = 0; i < limit; i++) {
38
- const pkgPath = addPackageJSON(currentPath)
39
- if (fs.existsSync(pkgPath)) {
40
- try {
41
- const pkg = require(pkgPath)
42
- if (pkg.name && !['@prisma/cli', 'prisma'].includes(pkg.name)) {
43
- return pkgPath.replace('package.json', '')
44
- }
45
- } catch {}
46
- }
47
- currentPath = path.join(currentPath, '../')
48
- }
49
- return null
50
- }
51
-
52
- async function main() {
53
- if (process.env.INIT_CWD) {
54
- process.chdir(process.env.INIT_CWD) // necessary, because npm chooses __dirname as process.cwd()
55
- // in the postinstall hook
56
- }
57
- await ensureEmptyDotPrisma()
58
-
59
- const localPath = getLocalPackagePath()
60
- // Only execute if !localpath
61
- const installedGlobally = localPath ? undefined : await isInstalledGlobally()
62
-
63
- // this is needed, so that the Generate command does not fail in postinstall
64
-
65
- process.env.PRISMA_GENERATE_IN_POSTINSTALL = 'true'
66
-
67
- // this is needed, so we can find the correct schemas in yarn workspace projects
68
- const root = findPackageRoot(localPath)
69
-
70
- process.env.PRISMA_GENERATE_IN_POSTINSTALL = root ? root : 'true'
71
-
72
- debug({
73
- localPath,
74
- installedGlobally,
75
- init_cwd: process.env.INIT_CWD,
76
- PRISMA_GENERATE_IN_POSTINSTALL: process.env.PRISMA_GENERATE_IN_POSTINSTALL,
77
- })
78
- try {
79
- if (localPath) {
80
- await run('node', [
81
- localPath,
82
- 'generate',
83
- '--postinstall',
84
- doubleQuote(getPostInstallTrigger()),
85
- ])
86
- return
87
- }
88
- if (installedGlobally) {
89
- await run('prisma', [
90
- 'generate',
91
- '--postinstall',
92
- doubleQuote(getPostInstallTrigger()),
93
- ])
94
- return
95
- }
96
- } catch (e) {
97
- // if exit code = 1 do not print
98
- if (e && e !== 1) {
99
- console.error(e)
100
- }
101
- debug(e)
102
- }
103
-
104
- if (!localPath && !installedGlobally) {
105
- console.error(
106
- `${c.yellow(
107
- 'warning',
108
- )} In order to use "@prisma/client", please install Prisma CLI. You can install it with "npm add -D prisma".`,
109
- )
110
- }
111
- }
112
-
113
- function getLocalPackagePath() {
114
- try {
115
- const packagePath = require.resolve('prisma/package.json')
116
- if (packagePath) {
117
- return require.resolve('prisma')
118
- }
119
- } catch (e) {
120
- //
121
- }
122
-
123
- try {
124
- const packagePath = require.resolve('@prisma/cli/package.json')
125
- if (packagePath) {
126
- return require.resolve('@prisma/cli')
127
- }
128
- } catch (e) {}
129
-
130
- return null
131
- }
132
-
133
- async function isInstalledGlobally() {
134
- try {
135
- const result = await exec('prisma -v')
136
- if (result.stdout.includes('@prisma/client')) {
137
- return true
138
- } else {
139
- console.error(`${c.yellow('warning')} You still have the ${c.bold(
140
- 'prisma',
141
- )} cli (Prisma 1) installed globally.
142
- Please uninstall it with either ${c.green('npm remove -g prisma')} or ${c.green(
143
- 'yarn global remove prisma',
144
- )}.`)
145
- }
146
- } catch (e) {
147
- return false
148
- }
149
- }
150
-
151
- if (!process.env.PRISMA_SKIP_POSTINSTALL_GENERATE) {
152
- main()
153
- .catch((e) => {
154
- if (e.stderr) {
155
- if (e.stderr.includes(`Can't find schema.prisma`)) {
156
- console.error(
157
- `${c.yellow('warning')} @prisma/client needs a ${c.bold(
158
- 'schema.prisma',
159
- )} to function, but couldn't find it.
160
- Please either create one manually or use ${c.bold('prisma init')}.
161
- Once you created it, run ${c.bold('prisma generate')}.
162
- To keep Prisma related things separate, we recommend creating it in a subfolder called ${c.underline(
163
- './prisma',
164
- )} like so: ${c.underline('./prisma/schema.prisma')}\n`,
165
- )
166
- } else {
167
- console.error(e.stderr)
168
- }
169
- } else {
170
- console.error(e)
171
- }
172
- process.exit(0)
173
- })
174
- .finally(() => {
175
- debug(`postinstall trigger: ${getPostInstallTrigger()}`)
176
- })
177
- }
178
-
179
- function run(cmd, params, cwd = process.cwd()) {
180
- const child = childProcess.spawn(cmd, params, {
181
- stdio: ['pipe', 'inherit', 'inherit'],
182
- cwd,
183
- })
184
-
185
- return new Promise((resolve, reject) => {
186
- child.on('close', () => {
187
- resolve()
188
- })
189
- child.on('exit', (code) => {
190
- if (code === 0) {
191
- resolve()
192
- } else {
193
- reject(code)
194
- }
195
- })
196
- child.on('error', () => {
197
- reject()
198
- })
199
- })
200
- }
201
-
202
- async function ensureEmptyDotPrisma() {
203
- try {
204
- const dotPrismaClientDir = path.join(__dirname, '../../../.prisma/client')
205
- await makeDir(dotPrismaClientDir)
206
- const defaultIndexJsPath = path.join(dotPrismaClientDir, 'index.js')
207
- const defaultIndexBrowserJSPath = path.join(
208
- dotPrismaClientDir,
209
- 'index-browser.js',
210
- )
211
- const defaultIndexDTSPath = path.join(dotPrismaClientDir, 'index.d.ts')
212
-
213
- if (!fs.existsSync(defaultIndexJsPath)) {
214
- await copyFile(
215
- path.join(__dirname, 'default-index.js'),
216
- defaultIndexJsPath,
217
- )
218
- }
219
- if (!fs.existsSync(defaultIndexBrowserJSPath)) {
220
- await copyFile(
221
- path.join(__dirname, 'default-index-browser.js'),
222
- defaultIndexBrowserJSPath,
223
- )
224
- }
225
-
226
- if (!fs.existsSync(defaultIndexDTSPath)) {
227
- await copyFile(
228
- path.join(__dirname, 'default-index.d.ts'),
229
- defaultIndexDTSPath,
230
- )
231
- }
232
- } catch (e) {
233
- console.error(e)
234
- }
235
- }
236
-
237
- async function makeDir(input) {
238
- const make = async (pth) => {
239
- try {
240
- await mkdir(pth)
241
-
242
- return pth
243
- } catch (error) {
244
- if (error.code === 'EPERM') {
245
- throw error
246
- }
247
-
248
- if (error.code === 'ENOENT') {
249
- if (path.dirname(pth) === pth) {
250
- throw new Error(`operation not permitted, mkdir '${pth}'`)
251
- }
252
-
253
- if (error.message.includes('null bytes')) {
254
- throw error
255
- }
256
-
257
- await make(path.dirname(pth))
258
-
259
- return make(pth)
260
- }
261
-
262
- try {
263
- const stats = await stat(pth)
264
- if (!stats.isDirectory()) {
265
- throw new Error('The path is not a directory')
266
- }
267
- } catch (_) {
268
- throw error
269
- }
270
-
271
- return pth
272
- }
273
- }
274
-
275
- return make(path.resolve(input))
276
- }
277
-
278
- /**
279
- * Get the command that triggered this postinstall script being run. If there is
280
- * an error while attempting to get this value then the string constant
281
- * 'ERROR_WHILE_FINDING_POSTINSTALL_TRIGGER' is returned.
282
- * This information is just necessary for telemetry.
283
- * This get's passed in to Generate, which then automatically get's propagated to telemetry.
284
- */
285
- function getPostInstallTrigger() {
286
- /*
287
- npm_config_argv` is not officially documented so here are our research notes
288
-
289
- `npm_config_argv` is available to the postinstall script when the containing package has been installed by npm into some project.
290
-
291
- An example of its value:
292
-
293
- ```
294
- npm_config_argv: '{"remain":["../test"],"cooked":["add","../test"],"original":["add","../test"]}',
295
- ```
296
-
297
- We are interesting in the data contained in the "original" field.
298
-
299
- Trivia/Note: `npm_config_argv` is not available when running e.g. `npm install` on the containing package itself (e.g. when working on it)
300
-
301
- Yarn mimics this data and environment variable. Here is an example following `yarn add` for the same package:
302
-
303
- ```
304
- npm_config_argv: '{"remain":[],"cooked":["add"],"original":["add","../test"]}'
305
- ```
306
-
307
- Other package managers like `pnpm` have not been tested.
308
- */
309
-
310
- const maybe_npm_config_argv_string = process.env.npm_config_argv
311
-
312
- if (maybe_npm_config_argv_string === undefined) {
313
- return UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING
314
- }
315
-
316
- let npm_config_argv
317
- try {
318
- npm_config_argv = JSON.parse(maybe_npm_config_argv_string)
319
- } catch (e) {
320
- return `${UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR}: ${maybe_npm_config_argv_string}`
321
- }
322
-
323
- if (typeof npm_config_argv !== 'object' || npm_config_argv === null) {
324
- return `${UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR}: ${maybe_npm_config_argv_string}`
325
- }
326
-
327
- const npm_config_arv_original_arr = npm_config_argv.original
328
-
329
- if (!Array.isArray(npm_config_arv_original_arr)) {
330
- return `${UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR}: ${maybe_npm_config_argv_string}`
331
- }
332
-
333
- const npm_config_arv_original = npm_config_arv_original_arr
334
- .filter((arg) => arg !== '')
335
- .join(' ')
336
-
337
- const command =
338
- npm_config_arv_original === ''
339
- ? getPackageManagerName()
340
- : [getPackageManagerName(), npm_config_arv_original].join(' ')
341
-
342
- return command
343
- }
344
-
345
- /**
346
- * Wrap double quotes around the given string.
347
- */
348
- function doubleQuote(x) {
349
- return `"${x}"`
350
- }
351
-
352
- /**
353
- * Get the package manager name currently being used. If parsing fails, then the following pattern is returned:
354
- * UNKNOWN_NPM_CONFIG_USER_AGENT(<string received>).
355
- */
356
- function getPackageManagerName() {
357
- const userAgent = process.env.npm_config_user_agent
358
- if (!userAgent) return 'MISSING_NPM_CONFIG_USER_AGENT'
359
-
360
- const name = parsePackageManagerName(userAgent)
361
- if (!name) return `UNKNOWN_NPM_CONFIG_USER_AGENT(${userAgent})`
362
-
363
- return name
364
- }
365
-
366
- /**
367
- * Parse package manager name from useragent. If parsing fails, `null` is returned.
368
- */
369
- function parsePackageManagerName(userAgent) {
370
- let packageManager = null
371
-
372
- // example: 'yarn/1.22.4 npm/? node/v13.11.0 darwin x64'
373
- // References:
374
- // - https://pnpm.js.org/en/3.6/only-allow-pnpm
375
- // - https://github.com/cameronhunter/npm-config-user-agent-parser
376
- if (userAgent) {
377
- const matchResult = userAgent.match(/^([^\/]+)\/.+/)
378
- if (matchResult) {
379
- packageManager = matchResult[1].trim()
380
- }
381
- }
382
-
383
- return packageManager
384
- }
385
-
386
- // prettier-ignore
387
- const UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING = 'UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING'
388
- // prettier-ignore
389
- const UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR = 'UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR'
390
- // prettier-ignore
391
- const UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR = 'UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR'
392
-
393
- // expose for testing
394
-
395
- exports.UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING = UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING
396
- exports.UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR = UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR
397
- exports.UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR = UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR
398
- exports.getPostInstallTrigger = getPostInstallTrigger
@@ -1,8 +0,0 @@
1
- try {
2
- const preinstall = require('../install/index.js')
3
- preinstall.catch(() => {
4
- //
5
- })
6
- } catch (e) {
7
- //
8
- }
@@ -1,9 +0,0 @@
1
- let preinstall
2
- try {
3
- preinstall = require('../preinstall/index.js')
4
- } catch (e) {
5
- //
6
- }
7
- if (preinstall) {
8
- preinstall.main()
9
- }