uniwind-pro 1.0.0-beta.3 → 1.0.0-beta.5
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/package.json +1 -1
- package/pre/postinstall/index.js +38 -0
- package/pre/postinstall/install.js +70 -12
package/package.json
CHANGED
package/pre/postinstall/index.js
CHANGED
|
@@ -1,8 +1,46 @@
|
|
|
1
1
|
import { Chalk } from 'chalk'
|
|
2
|
+
import { mkdirSync, symlinkSync, existsSync } from 'node:fs'
|
|
3
|
+
import { dirname, join, resolve } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
2
5
|
import { keyring } from '@zowe/secrets-for-zowe-sdk'
|
|
3
6
|
import { UNIWIND_AUTH_TOKEN, SERVICE, UNIWIND_WEB_URL, HELP_EMAIL } from '../consts.js'
|
|
4
7
|
import { downloadFromCI, downloadFromCLI } from './install.js'
|
|
5
8
|
|
|
9
|
+
// Create bin symlinks for aliased package
|
|
10
|
+
const createBinSymlinks = () => {
|
|
11
|
+
try {
|
|
12
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
13
|
+
const cliPath = resolve(__dirname, '../cli/index.js')
|
|
14
|
+
let current = __dirname
|
|
15
|
+
|
|
16
|
+
while (current !== '/') {
|
|
17
|
+
if (!current.includes('node_modules')) {
|
|
18
|
+
const binDir = join(current, 'node_modules', '.bin')
|
|
19
|
+
const nodeModules = join(current, 'node_modules')
|
|
20
|
+
|
|
21
|
+
if (existsSync(nodeModules)) {
|
|
22
|
+
// Now we're at the actual project root
|
|
23
|
+
mkdirSync(binDir, { recursive: true })
|
|
24
|
+
|
|
25
|
+
for (const name of ['uniwind', 'uniwind-pro']) {
|
|
26
|
+
const linkPath = join(binDir, name)
|
|
27
|
+
|
|
28
|
+
if (!existsSync(linkPath)) {
|
|
29
|
+
symlinkSync(cliPath, linkPath)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
break
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
current = dirname(current)
|
|
38
|
+
}
|
|
39
|
+
} catch {}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
createBinSymlinks()
|
|
43
|
+
|
|
6
44
|
const chalk = new Chalk({ level: 3 })
|
|
7
45
|
|
|
8
46
|
const main = async () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
|
-
import { readFileSync, mkdirSync, readdirSync, cpSync, rmSync } from 'node:fs'
|
|
2
|
+
import { readFileSync, mkdirSync, readdirSync, cpSync, rmSync, existsSync } from 'node:fs'
|
|
3
3
|
import { keyring } from '@zowe/secrets-for-zowe-sdk'
|
|
4
4
|
import { join, dirname } from 'node:path'
|
|
5
5
|
import { fileURLToPath } from 'node:url'
|
|
@@ -10,7 +10,6 @@ import { INSTALLATION_URL, SERVICE } from '../consts.js'
|
|
|
10
10
|
|
|
11
11
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
12
12
|
const pkgPath = join(__dirname, '../../package.json')
|
|
13
|
-
const rootPkgPath = join(__dirname, '../../../../package.json')
|
|
14
13
|
const streamPipeline = promisify(pipeline)
|
|
15
14
|
|
|
16
15
|
const getVersion = () => {
|
|
@@ -25,17 +24,76 @@ const getVersion = () => {
|
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const packageJson = readFileSync(rootPkgPath, 'utf8')
|
|
31
|
-
const parsedPackageJSON = JSON.parse(packageJson)
|
|
27
|
+
const findWorkspacePackages = (rootDir, workspaces) => {
|
|
28
|
+
const packages = []
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
for (const pattern of workspaces) {
|
|
31
|
+
const wsPath = join(rootDir, pattern.replace('/*', ''))
|
|
32
|
+
|
|
33
|
+
if (existsSync(wsPath)) {
|
|
34
|
+
try {
|
|
35
|
+
const dirs = readdirSync(wsPath, { withFileTypes: true })
|
|
36
|
+
|
|
37
|
+
for (const dir of dirs) {
|
|
38
|
+
if (dir.isDirectory()) {
|
|
39
|
+
const pkgPath = join(wsPath, dir.name, 'package.json')
|
|
40
|
+
|
|
41
|
+
if (existsSync(pkgPath)) {
|
|
42
|
+
packages.push(pkgPath)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} catch {}
|
|
47
|
+
}
|
|
38
48
|
}
|
|
49
|
+
|
|
50
|
+
return packages
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const getProjectName = () => {
|
|
54
|
+
let current = __dirname
|
|
55
|
+
|
|
56
|
+
while (current !== '/') {
|
|
57
|
+
if (!current.includes('node_modules')) {
|
|
58
|
+
const pkgPath = join(current, 'package.json')
|
|
59
|
+
|
|
60
|
+
if (existsSync(pkgPath)) {
|
|
61
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
|
|
62
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies }
|
|
63
|
+
|
|
64
|
+
// Direct dependency - return immediately
|
|
65
|
+
if (deps['uniwind'] || deps['uniwind-pro']) {
|
|
66
|
+
return pkg.name
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Monorepo with workspaces - search for package that depends on uniwind
|
|
70
|
+
if (pkg.workspaces) {
|
|
71
|
+
const workspaces = Array.isArray(pkg.workspaces)
|
|
72
|
+
? pkg.workspaces
|
|
73
|
+
: pkg.workspaces.packages || []
|
|
74
|
+
const wsPkgs = findWorkspacePackages(current, workspaces)
|
|
75
|
+
|
|
76
|
+
for (const wsPkgPath of wsPkgs) {
|
|
77
|
+
try {
|
|
78
|
+
const wsPkg = JSON.parse(readFileSync(wsPkgPath, 'utf8'))
|
|
79
|
+
const wsDeps = { ...wsPkg.dependencies, ...wsPkg.devDependencies }
|
|
80
|
+
|
|
81
|
+
if (wsDeps['uniwind'] || wsDeps['uniwind-pro']) {
|
|
82
|
+
return wsPkg.name
|
|
83
|
+
}
|
|
84
|
+
} catch {}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Fallback to root package name
|
|
89
|
+
return pkg.name
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
current = dirname(current)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
throw new Error('Could not find project package.json')
|
|
39
97
|
}
|
|
40
98
|
|
|
41
99
|
export const downloadFromCI = async (licenseUUID) => {
|
|
@@ -56,7 +114,7 @@ export const downloadFromCLI = async ({ account: handle, password: token }) => {
|
|
|
56
114
|
|
|
57
115
|
console.log(chalk.dim(`Fetching v${packageVersion} for project "${projectName}"...\n`))
|
|
58
116
|
|
|
59
|
-
const cdnUrl = `${INSTALLATION_URL}/cli/${handle}/${projectName}/${packageVersion}/${token}`
|
|
117
|
+
const cdnUrl = `${INSTALLATION_URL}/cli/${handle}/${encodeURIComponent(projectName)}/${packageVersion}/${token}`
|
|
60
118
|
const response = await fetch(cdnUrl)
|
|
61
119
|
|
|
62
120
|
if (response.ok) {
|