piral-cli 0.14.24-beta.4150 → 0.14.24-beta.4163
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/lib/apps/new-pilet.js +1 -7
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/upgrade-pilet.js +1 -7
- package/lib/apps/upgrade-pilet.js.map +1 -1
- package/lib/common/clients/index.d.ts +19 -0
- package/lib/common/clients/index.js +40 -0
- package/lib/common/clients/index.js.map +1 -0
- package/lib/common/clients/lerna.d.ts +3 -1
- package/lib/common/clients/lerna.js +36 -3
- package/lib/common/clients/lerna.js.map +1 -1
- package/lib/common/clients/npm.d.ts +2 -1
- package/lib/common/clients/npm.js +20 -16
- package/lib/common/clients/npm.js.map +1 -1
- package/lib/common/clients/pnpm.d.ts +1 -0
- package/lib/common/clients/pnpm.js +14 -11
- package/lib/common/clients/pnpm.js.map +1 -1
- package/lib/common/clients/rush.d.ts +3 -0
- package/lib/common/clients/rush.js +64 -0
- package/lib/common/clients/rush.js.map +1 -0
- package/lib/common/clients/yarn.d.ts +1 -0
- package/lib/common/clients/yarn.js +16 -13
- package/lib/common/clients/yarn.js.map +1 -1
- package/lib/common/info.d.ts +1 -0
- package/lib/common/info.js +2 -1
- package/lib/common/info.js.map +1 -1
- package/lib/common/io.js +1 -1
- package/lib/common/io.js.map +1 -1
- package/lib/common/npm.d.ts +0 -9
- package/lib/common/npm.js +58 -121
- package/lib/common/npm.js.map +1 -1
- package/lib/common/scaffold.js +2 -2
- package/lib/common/scaffold.js.map +1 -1
- package/lib/helpers.js +1 -1
- package/lib/helpers.js.map +1 -1
- package/lib/plugin.js +27 -2
- package/lib/plugin.js.map +1 -1
- package/lib/types/public.d.ts +1 -1
- package/package.json +2 -2
- package/src/apps/new-pilet.ts +1 -9
- package/src/apps/upgrade-pilet.ts +1 -9
- package/src/common/clients/index.ts +33 -0
- package/src/common/clients/lerna.ts +33 -1
- package/src/common/clients/npm.ts +18 -15
- package/src/common/clients/pnpm.ts +13 -12
- package/src/common/clients/rush.ts +49 -0
- package/src/common/clients/yarn.ts +15 -14
- package/src/common/info.ts +1 -0
- package/src/common/io.ts +1 -1
- package/src/common/npm.test.ts +25 -38
- package/src/common/npm.ts +72 -123
- package/src/common/scaffold.ts +2 -2
- package/src/helpers.ts +1 -1
- package/src/plugin.ts +33 -4
- package/src/types/public.ts +1 -1
package/src/common/npm.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolve, relative, dirname } from 'path';
|
|
2
|
-
import { createReadStream, existsSync
|
|
2
|
+
import { createReadStream, existsSync } from 'fs';
|
|
3
3
|
import { log, fail } from './log';
|
|
4
|
+
import { clients, detectClients, isWrapperClient } from './clients';
|
|
4
5
|
import { config } from './config';
|
|
5
6
|
import { legacyCoreExternals, frameworkLibs } from './constants';
|
|
6
7
|
import { inspectPackage } from './inspect';
|
|
@@ -23,48 +24,28 @@ function resolveAbsPath(basePath: string, fullName: string) {
|
|
|
23
24
|
return resolve(basePath, relPath);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
access(resolve(root, 'pnpm-lock.yaml'), constants.F_OK, (noPnpmLock) => {
|
|
29
|
-
res(!noPnpmLock);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function detectNpm(root: string) {
|
|
35
|
-
return new Promise((res) => {
|
|
36
|
-
access(resolve(root, 'package-lock.json'), constants.F_OK, (noPackageLock) => {
|
|
37
|
-
res(!noPackageLock);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function detectYarn(root: string) {
|
|
43
|
-
return !!(await findFile(root, 'yarn.lock'));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function getLernaConfigPath(root: string) {
|
|
47
|
-
log('generalDebug_0003', 'Trying to get the configuration file for Lerna ...');
|
|
48
|
-
const file = await findFile(root, 'lerna.json');
|
|
27
|
+
async function detectMonorepoRoot(root: string): Promise<string> {
|
|
28
|
+
let previous = root;
|
|
49
29
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
30
|
+
do {
|
|
31
|
+
const isMonorepo =
|
|
32
|
+
(await checkExists(resolve(root, 'lerna.json'))) ||
|
|
33
|
+
(await checkExists(resolve(root, 'rush.json'))) ||
|
|
34
|
+
(await checkExists(resolve(root, 'pnpm-workspace.yaml')));
|
|
54
35
|
|
|
55
|
-
|
|
56
|
-
|
|
36
|
+
if (isMonorepo) {
|
|
37
|
+
return root;
|
|
38
|
+
}
|
|
57
39
|
|
|
58
|
-
|
|
59
|
-
const file = await getLernaConfigPath(root);
|
|
40
|
+
const packageJson = await readJson(root, 'package.json');
|
|
60
41
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return require(file).npmClient;
|
|
64
|
-
} catch (err) {
|
|
65
|
-
log('generalError_0002', `Could not read lerna.json: ${err}.`);
|
|
42
|
+
if (Array.isArray(packageJson?.workspaces)) {
|
|
43
|
+
return root;
|
|
66
44
|
}
|
|
67
|
-
|
|
45
|
+
|
|
46
|
+
previous = root;
|
|
47
|
+
root = dirname(root);
|
|
48
|
+
} while (root !== previous);
|
|
68
49
|
|
|
69
50
|
return undefined;
|
|
70
51
|
}
|
|
@@ -76,36 +57,45 @@ export async function getLernaNpmClient(root: string): Promise<NpmClientType> {
|
|
|
76
57
|
*/
|
|
77
58
|
export async function determineNpmClient(root: string, selected?: NpmClientType): Promise<NpmClientType> {
|
|
78
59
|
if (!selected || !clientTypeKeys.includes(selected)) {
|
|
79
|
-
log('generalDebug_0003', 'No npm client selected. Checking for lock files ...');
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
60
|
+
log('generalDebug_0003', 'No npm client selected. Checking for lock or config files ...');
|
|
61
|
+
|
|
62
|
+
const searchedClients = await detectClients(root);
|
|
63
|
+
const foundClients = searchedClients.filter((m) => m.result);
|
|
64
|
+
|
|
65
|
+
log(
|
|
66
|
+
'generalDebug_0003',
|
|
67
|
+
`Results of the lock file check: ${searchedClients.map((m) => `${m.client}=${m.result}`).join(', ')}`,
|
|
68
|
+
);
|
|
69
|
+
|
|
83
70
|
const defaultClient = config.npmClient;
|
|
84
71
|
|
|
85
|
-
if (
|
|
86
|
-
const
|
|
72
|
+
if (foundClients.length > 1) {
|
|
73
|
+
const wrapperClient = foundClients.find((m) => isWrapperClient(m.client));
|
|
87
74
|
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
75
|
+
if (wrapperClient) {
|
|
76
|
+
const { client } = wrapperClient;
|
|
77
|
+
log('generalDebug_0003', `Found valid wrapper client via lock or config file: "${client}".`);
|
|
91
78
|
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (foundClients.length > 0) {
|
|
82
|
+
const { client } = foundClients[0];
|
|
83
|
+
|
|
84
|
+
if (foundClients.length > 1) {
|
|
85
|
+
const clientStr = `"${foundClients.map((m) => m.client).join('", "')}"`;
|
|
86
|
+
log('generalWarning_0001', `Found multiple clients via their lock or config files: ${clientStr}.`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
log('generalDebug_0003', `Found valid direct client via lock or config file: "${client}".`);
|
|
90
|
+
return client;
|
|
101
91
|
}
|
|
102
92
|
|
|
103
93
|
if (clientTypeKeys.includes(defaultClient)) {
|
|
104
|
-
log('generalDebug_0003', `
|
|
94
|
+
log('generalDebug_0003', `Using the default client: "${defaultClient}".`);
|
|
105
95
|
return defaultClient;
|
|
106
96
|
}
|
|
107
97
|
|
|
108
|
-
log('generalDebug_0003', 'Using the default npm client.');
|
|
98
|
+
log('generalDebug_0003', 'Using the default "npm" client.');
|
|
109
99
|
return 'npm';
|
|
110
100
|
}
|
|
111
101
|
|
|
@@ -113,103 +103,62 @@ export async function determineNpmClient(root: string, selected?: NpmClientType)
|
|
|
113
103
|
}
|
|
114
104
|
|
|
115
105
|
export async function isMonorepoPackageRef(refName: string, root: string): Promise<boolean> {
|
|
116
|
-
const c = require(`./clients/npm`);
|
|
117
106
|
const newRoot = await detectMonorepoRoot(root);
|
|
118
107
|
|
|
119
108
|
if (newRoot) {
|
|
120
|
-
const
|
|
109
|
+
const { listPackage } = clients.npm;
|
|
110
|
+
const details = await listPackage(refName, newRoot);
|
|
121
111
|
return details?.dependencies?.[refName]?.extraneous ?? false;
|
|
122
112
|
}
|
|
123
113
|
|
|
124
114
|
return false;
|
|
125
115
|
}
|
|
126
116
|
|
|
127
|
-
export async function detectMonorepoRoot(root: string): Promise<string> {
|
|
128
|
-
const file = await getLernaConfigPath(root);
|
|
129
|
-
|
|
130
|
-
if (file !== undefined) {
|
|
131
|
-
return dirname(file);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
let previous = root;
|
|
135
|
-
|
|
136
|
-
do {
|
|
137
|
-
const packageJson = await readJson(root, 'package.json');
|
|
138
|
-
|
|
139
|
-
if (Array.isArray(packageJson?.workspaces)) {
|
|
140
|
-
return root;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
previous = root;
|
|
144
|
-
root = dirname(root);
|
|
145
|
-
} while (root !== previous);
|
|
146
|
-
|
|
147
|
-
return undefined;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export type MonorepoKind = 'none' | 'lerna' | 'yarn';
|
|
151
|
-
|
|
152
|
-
export async function detectMonorepo(root: string): Promise<MonorepoKind> {
|
|
153
|
-
const newRoot = await detectMonorepoRoot(root);
|
|
154
|
-
|
|
155
|
-
if (newRoot) {
|
|
156
|
-
const file = await getLernaConfigPath(newRoot);
|
|
157
|
-
|
|
158
|
-
if (file !== undefined) {
|
|
159
|
-
return 'lerna';
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const packageJson = await readJson(newRoot, 'package.json');
|
|
163
|
-
|
|
164
|
-
if (Array.isArray(packageJson?.workspaces)) {
|
|
165
|
-
return 'yarn';
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return 'none';
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function bootstrapMonorepo(target = '.') {
|
|
173
|
-
const c = require(`./clients/lerna`);
|
|
174
|
-
return c.bootstrap(target);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
117
|
export function installDependencies(client: NpmClientType, target = '.'): Promise<string> {
|
|
178
|
-
const
|
|
179
|
-
return
|
|
118
|
+
const { installDependencies } = clients[client];
|
|
119
|
+
return installDependencies(target);
|
|
180
120
|
}
|
|
181
121
|
|
|
182
|
-
export function installPackage(
|
|
122
|
+
export async function installPackage(
|
|
183
123
|
client: NpmClientType,
|
|
184
124
|
packageRef: string,
|
|
185
125
|
target = '.',
|
|
186
126
|
...flags: Array<string>
|
|
187
127
|
): Promise<string> {
|
|
188
|
-
|
|
189
|
-
|
|
128
|
+
try {
|
|
129
|
+
const { installPackage } = clients[client];
|
|
130
|
+
return await installPackage(packageRef, target, ...flags);
|
|
131
|
+
} catch (ex) {
|
|
132
|
+
log(
|
|
133
|
+
'generalError_0002',
|
|
134
|
+
`Could not install the package "${packageRef}" using ${client}. Make sure ${client} is correctly installed and accessible: ${ex}`,
|
|
135
|
+
);
|
|
136
|
+
throw ex;
|
|
137
|
+
}
|
|
190
138
|
}
|
|
191
139
|
|
|
192
140
|
export function publishPackage(target = '.', file = '*.tgz', flags: Array<string> = []): Promise<string> {
|
|
193
|
-
const
|
|
194
|
-
return
|
|
141
|
+
const { publishPackage } = clients.npm;
|
|
142
|
+
return publishPackage(target, file, ...flags);
|
|
195
143
|
}
|
|
196
144
|
|
|
197
145
|
export function createPackage(target = '.'): Promise<string> {
|
|
198
|
-
const
|
|
199
|
-
return
|
|
146
|
+
const { createPackage } = clients.npm;
|
|
147
|
+
return createPackage(target);
|
|
200
148
|
}
|
|
201
149
|
|
|
202
150
|
export function findTarball(packageRef: string): Promise<string> {
|
|
203
|
-
const
|
|
204
|
-
return
|
|
151
|
+
const { findTarball } = clients.npm;
|
|
152
|
+
return findTarball(packageRef);
|
|
205
153
|
}
|
|
206
154
|
|
|
207
155
|
export function findSpecificVersion(packageName: string, version: string): Promise<string> {
|
|
208
|
-
const
|
|
209
|
-
return
|
|
156
|
+
const { findSpecificVersion } = clients.npm;
|
|
157
|
+
return findSpecificVersion(packageName, version);
|
|
210
158
|
}
|
|
211
159
|
|
|
212
160
|
export function findLatestVersion(packageName: string) {
|
|
161
|
+
const { findSpecificVersion } = clients.npm;
|
|
213
162
|
return findSpecificVersion(packageName, 'latest');
|
|
214
163
|
}
|
|
215
164
|
|
package/src/common/scaffold.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { join, dirname, resolve, basename, isAbsolute } from 'path';
|
|
2
|
-
import { installPackage } from './
|
|
2
|
+
import { installPackage } from './npm';
|
|
3
3
|
import { ForceOverwrite, SourceLanguage } from './enums';
|
|
4
4
|
import { createDirectory, createFileIfNotExists, updateExistingJson } from './io';
|
|
5
5
|
import { log, fail } from './log';
|
|
@@ -36,7 +36,7 @@ async function getTemplateFiles(
|
|
|
36
36
|
if (templatePackageName.startsWith('.')) {
|
|
37
37
|
templatePackageName = resolve(process.cwd(), templatePackageName);
|
|
38
38
|
} else {
|
|
39
|
-
await installPackage(templatePackageName, __dirname, '--registry', registry);
|
|
39
|
+
await installPackage('npm', templatePackageName, __dirname, '--registry', registry);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const templateRunner = getTemplatePackage(templatePackageName);
|
package/src/helpers.ts
CHANGED
|
@@ -15,7 +15,7 @@ export const publishModeKeys: Array<PiletPublishScheme> = ['none', 'basic', 'bea
|
|
|
15
15
|
export const fromKeys: Array<PiletPublishSource> = ['local', 'remote', 'npm'];
|
|
16
16
|
export const piralBuildTypeKeys: Array<PiralBuildType> = ['all', 'release', 'emulator', 'emulator-sources'];
|
|
17
17
|
export const piletBuildTypeKeys: Array<PiletBuildType> = ['default', 'standalone', 'manifest'];
|
|
18
|
-
export const clientTypeKeys: Array<NpmClientType> = ['npm', 'pnpm', 'yarn'];
|
|
18
|
+
export const clientTypeKeys: Array<NpmClientType> = ['npm', 'pnpm', 'yarn', 'lerna', 'rush'];
|
|
19
19
|
export const bundlerKeys: Array<string> = ['none', ...bundlerNames];
|
|
20
20
|
export const availableBundlers: Array<string> = [];
|
|
21
21
|
export const availableReleaseProviders: Array<string> = [];
|
package/src/plugin.ts
CHANGED
|
@@ -1,12 +1,41 @@
|
|
|
1
1
|
import { readdir, stat } from 'fs';
|
|
2
|
-
import { join, resolve } from 'path';
|
|
3
|
-
import { log } from './common';
|
|
2
|
+
import { join, resolve, sep, posix } from 'path';
|
|
3
|
+
import { cliName, cliVersion, log } from './common';
|
|
4
4
|
import { inject } from './inject';
|
|
5
5
|
|
|
6
|
-
function
|
|
6
|
+
function getContainerDir() {
|
|
7
|
+
const currentDir = __dirname.split(sep).join(posix.sep);
|
|
8
|
+
|
|
9
|
+
if (currentDir.includes(`/.pnpm/${cliName}@${cliVersion}/node_modules/${cliName}/`)) {
|
|
10
|
+
return resolve(__dirname, '..', '..', '..', '..', '..');
|
|
11
|
+
}
|
|
12
|
+
|
|
7
13
|
return resolve(__dirname, '..', '..');
|
|
8
14
|
}
|
|
9
15
|
|
|
16
|
+
async function getLocalPackageDir() {
|
|
17
|
+
const proposedDirs = [
|
|
18
|
+
getContainerDir(),
|
|
19
|
+
resolve(process.cwd(), 'node_modules'),
|
|
20
|
+
resolve(process.cwd(), '..', 'node_modules'),
|
|
21
|
+
resolve(process.cwd(), '..', '..', 'node_modules'),
|
|
22
|
+
resolve(process.cwd(), '..', '..', '..', 'node_modules'),
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
// Right now we always take the first one, but in the future this may be different
|
|
26
|
+
// once we come up with more / better criteria to identify if its a good/valid
|
|
27
|
+
// plugin root directory
|
|
28
|
+
for (const dir of proposedDirs) {
|
|
29
|
+
log('generalDebug_0003', `Checking for potential plugin directory "${dir}" ...`);
|
|
30
|
+
|
|
31
|
+
if (await isDirectory(dir)) {
|
|
32
|
+
return dir;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
10
39
|
function isDirectory(dir: string) {
|
|
11
40
|
return new Promise<boolean>((resolve, reject) => {
|
|
12
41
|
stat(dir, (err, stats) => {
|
|
@@ -83,7 +112,7 @@ async function getAllPlugins(rootDir: string): Promise<Array<string>> {
|
|
|
83
112
|
}
|
|
84
113
|
|
|
85
114
|
export async function loadPlugins() {
|
|
86
|
-
const localDir = getLocalPackageDir();
|
|
115
|
+
const localDir = await getLocalPackageDir();
|
|
87
116
|
const allPlugins = await getAllPlugins(localDir);
|
|
88
117
|
|
|
89
118
|
for (const pluginPath of allPlugins) {
|
package/src/types/public.ts
CHANGED
|
@@ -226,7 +226,7 @@ export type PiletBuildType = 'default' | 'standalone' | 'manifest';
|
|
|
226
226
|
|
|
227
227
|
export type PackageType = 'registry' | 'file' | 'git';
|
|
228
228
|
|
|
229
|
-
export type NpmClientType = 'npm' | 'yarn' | 'pnpm';
|
|
229
|
+
export type NpmClientType = 'npm' | 'yarn' | 'pnpm' | 'lerna' | 'rush';
|
|
230
230
|
|
|
231
231
|
export type Framework = 'piral' | 'piral-core' | 'piral-base';
|
|
232
232
|
|