@prisma/cli 2.20.0 → 3.0.0-alpha.0
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.
- package/LICENSE +158 -0
- package/README.md +29 -28
- package/dist/adapters/config.js +74 -0
- package/dist/adapters/local-state.js +98 -0
- package/dist/adapters/mock-api.js +57 -0
- package/dist/adapters/token-storage.js +43 -0
- package/dist/cli.js +9 -0
- package/dist/cli2.js +59 -0
- package/dist/commands/app/index.js +223 -0
- package/dist/commands/auth/index.js +42 -0
- package/dist/commands/branch/index.js +51 -0
- package/dist/commands/project/index.js +45 -0
- package/dist/controllers/app.js +813 -0
- package/dist/controllers/auth.js +107 -0
- package/dist/controllers/branch.js +73 -0
- package/dist/controllers/project.js +214 -0
- package/dist/controllers/select-prompt-port.js +12 -0
- package/dist/lib/app/bun-project.js +39 -0
- package/dist/lib/app/env-vars.js +24 -0
- package/dist/lib/app/local-dev.js +149 -0
- package/dist/lib/app/preview-build.js +283 -0
- package/dist/lib/app/preview-interaction.js +38 -0
- package/dist/lib/app/preview-progress.js +139 -0
- package/dist/lib/app/preview-provider.js +232 -0
- package/dist/lib/auth/auth-ops.js +57 -0
- package/dist/lib/auth/client.js +22 -0
- package/dist/lib/auth/guard.js +34 -0
- package/dist/lib/auth/login.js +117 -0
- package/dist/output/patterns.js +93 -0
- package/dist/presenters/app.js +405 -0
- package/dist/presenters/auth.js +73 -0
- package/dist/presenters/branch.js +111 -0
- package/dist/presenters/project.js +84 -0
- package/dist/shell/command-meta.js +320 -0
- package/dist/shell/command-runner.js +33 -0
- package/dist/shell/errors.js +66 -0
- package/dist/shell/global-flags.js +25 -0
- package/dist/shell/help.js +78 -0
- package/dist/shell/output.js +54 -0
- package/dist/shell/prompt.js +31 -0
- package/dist/shell/runtime.js +51 -0
- package/dist/shell/ui.js +59 -0
- package/dist/use-cases/auth.js +70 -0
- package/dist/use-cases/branch.js +95 -0
- package/dist/use-cases/create-cli-gateways.js +93 -0
- package/dist/use-cases/project.js +75 -0
- package/package.json +49 -137
- package/build/child.js +0 -4110
- package/build/index.js +0 -104447
- package/build/public/demo.html +0 -17
- package/build/public/demoChunk.js +0 -2
- package/build/public/electron-darwin.html +0 -19
- package/build/public/electron-linux.html +0 -18
- package/build/public/electron-mac.html +0 -18
- package/build/public/electron-win.html +0 -17
- package/build/public/electron-win32.html +0 -18
- package/build/public/electron.html +0 -17
- package/build/public/electronBus.js +0 -2
- package/build/public/electronChunk.js +0 -2
- package/build/public/favicon/apple-touch-icon.png +0 -0
- package/build/public/favicon/favicon-16x16.png +0 -0
- package/build/public/favicon/favicon-32x32.png +0 -0
- package/build/public/favicon/prisma.png +0 -0
- package/build/public/fonts/Inter.ttf +0 -0
- package/build/public/fonts/RobotoMono.ttf +0 -0
- package/build/public/icons/.DS_Store +0 -0
- package/build/public/icons/alert.svg +0 -5
- package/build/public/icons/array.svg +0 -4
- package/build/public/icons/bin.svg +0 -37
- package/build/public/icons/boolean.svg +0 -4
- package/build/public/icons/check.svg +0 -3
- package/build/public/icons/chevron-down.svg +0 -3
- package/build/public/icons/code.svg +0 -4
- package/build/public/icons/cross.svg +0 -11
- package/build/public/icons/data-tool.svg +0 -5
- package/build/public/icons/database.svg +0 -4
- package/build/public/icons/datetime.svg +0 -4
- package/build/public/icons/double-arrow-right.svg +0 -4
- package/build/public/icons/download.svg +0 -4
- package/build/public/icons/ellipsis.svg +0 -10
- package/build/public/icons/enum.svg +0 -6
- package/build/public/icons/expand.svg +0 -4
- package/build/public/icons/eye.svg +0 -20
- package/build/public/icons/filters.svg +0 -5
- package/build/public/icons/folder.svg +0 -6
- package/build/public/icons/hamburger.svg +0 -4
- package/build/public/icons/icon.svg +0 -199
- package/build/public/icons/logo.svg +0 -199
- package/build/public/icons/logotype.svg +0 -4
- package/build/public/icons/number.svg +0 -7
- package/build/public/icons/object.svg +0 -5
- package/build/public/icons/play.svg +0 -6
- package/build/public/icons/plus.svg +0 -4
- package/build/public/icons/refresh.svg +0 -4
- package/build/public/icons/search.svg +0 -7
- package/build/public/icons/settings.svg +0 -8
- package/build/public/icons/string.svg +0 -4
- package/build/public/icons/tick-indeterminate.svg +0 -3
- package/build/public/icons/tick.svg +0 -4
- package/build/public/illustrations/.DS_Store +0 -0
- package/build/public/illustrations/empty.svg +0 -1
- package/build/public/illustrations/read.svg +0 -1
- package/build/public/illustrations/searching.svg +0 -1
- package/build/public/images/.DS_Store +0 -0
- package/build/public/images/icon-1024.png +0 -0
- package/build/public/index.html +0 -49
- package/build/public/main.31f688a6254e294d9128.css +0 -118
- package/build/public/main.31f688a6254e294d9128.css.map +0 -1
- package/build/public/main.364c712f32662ff0e43d.css +0 -116
- package/build/public/main.364c712f32662ff0e43d.css.map +0 -1
- package/build/public/main.42ef3fe7e97347765c91.css +0 -118
- package/build/public/main.42ef3fe7e97347765c91.css.map +0 -1
- package/build/public/main.503446defafe7aeca2f3.css +0 -116
- package/build/public/main.503446defafe7aeca2f3.css.map +0 -1
- package/build/public/main.c50a3b5980fe26f78b65.css +0 -118
- package/build/public/main.c50a3b5980fe26f78b65.css.map +0 -1
- package/build/public/main.cda25e5813776c2af295.css +0 -116
- package/build/public/main.cda25e5813776c2af295.css.map +0 -1
- package/build/public/main.dbac3b290f78404ff579.css +0 -116
- package/build/public/main.dbac3b290f78404ff579.css.map +0 -1
- package/build/public/main.f8ce44e122e5e2b8f778.css +0 -118
- package/build/public/main.f8ce44e122e5e2b8f778.css.map +0 -1
- package/build/public/main.fc9ea7521a4aecce1a77.css +0 -118
- package/build/public/main.fc9ea7521a4aecce1a77.css.map +0 -1
- package/build/public/main.js +0 -403
- package/build/public/main.js.map +0 -1
- package/build/public/mainChunk.0a84f3ba4d2ab481e877.css +0 -116
- package/build/public/mainChunk.1b327d58afbddc917bce.css +0 -118
- package/build/public/mainChunk.2cdf583b2bd51aa67587.css +0 -118
- package/build/public/mainChunk.544af00f7e9ffcbe782c.css +0 -118
- package/build/public/mainChunk.56f96a13868b2b4a53be.css +0 -118
- package/build/public/mainChunk.5cee429bfbf06e7ecb39.css +0 -118
- package/build/public/mainChunk.a862474ed4cdb421ffa2.css +0 -118
- package/build/public/mainChunk.ada34153c4911b5ac22b.css +0 -118
- package/build/public/mainChunk.c16a8d01b2c49b2f2751.css +0 -118
- package/build/public/mainChunk.ca4a878d5478b9320be8.css +0 -116
- package/build/public/mainChunk.e3adc8758b4395546cef.css +0 -116
- package/build/public/mainChunk.f2c59fcbfc455d8b9de5.css +0 -118
- package/build/public/mainChunk.js +0 -396
- package/build/public/preview.html +0 -16
- package/build/public/previewBus.js +0 -2
- package/build/public/previewChunk.js +0 -2
- package/build/public/projects.html +0 -86
- package/build/public/server.html +0 -16
- package/build/public/serverBus.js +0 -2
- package/build/public/serverChunk.js +0 -2
- package/build/public/splash.html +0 -17
- package/build/public/studioBundle.828f34b1781061528841.css +0 -118
- package/build/public/studioBundle.bfe9138b2e0293fcb7da.css +0 -118
- package/build/public/studioBundle.c5b256eede880e502aac.css +0 -118
- package/build/public/studioBundle.e43df511c8e2e368900a.css +0 -118
- package/build/public/studioBundle.e69382554c2a2942ae32.css +0 -118
- package/build/public/studioBundle.ee21aa56a3999a2b380b.css +0 -118
- package/build/public/studioBundle.js +0 -396
- package/build/public/vercel.html +0 -16
- package/build/public/vercelChunk.js +0 -2
- package/build/xdg-open +0 -1066
- package/install/index.js +0 -5
- package/preinstall/index.js +0 -71
- package/prisma-client/README.md +0 -27
- package/prisma-client/generator-build/.DS_Store +0 -0
- package/prisma-client/generator-build/index.js +0 -79697
- package/prisma-client/index-browser.js +0 -3
- package/prisma-client/index.d.ts +0 -1
- package/prisma-client/index.js +0 -11
- package/prisma-client/package.json +0 -138
- package/prisma-client/runtime/index-browser.d.ts +0 -267
- package/prisma-client/runtime/index-browser.js +0 -2273
- package/prisma-client/runtime/index.d.ts +0 -1018
- package/prisma-client/runtime/index.js +0 -35028
- package/prisma-client/scripts/backup-index-browser.js +0 -3
- package/prisma-client/scripts/backup-index.d.ts +0 -1
- package/prisma-client/scripts/backup-index.js +0 -11
- package/prisma-client/scripts/colors.js +0 -180
- package/prisma-client/scripts/default-index-browser.js +0 -12
- package/prisma-client/scripts/default-index.d.ts +0 -47
- package/prisma-client/scripts/default-index.js +0 -12
- package/prisma-client/scripts/get-packed-client.js +0 -12
- package/prisma-client/scripts/mock-fs.js +0 -14
- package/prisma-client/scripts/postinstall.d.ts +0 -5
- package/prisma-client/scripts/postinstall.js +0 -398
- package/scripts/install-entry.js +0 -8
- 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
|
package/scripts/install-entry.js
DELETED