piral-cli 0.14.24-beta.4157 → 0.14.24-beta.4168
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 +5 -9
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/new-piral.js +2 -2
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/apps/publish-pilet.js +1 -1
- package/lib/apps/publish-pilet.js.map +1 -1
- package/lib/apps/publish-piral.js +1 -1
- package/lib/apps/publish-piral.js.map +1 -1
- package/lib/apps/upgrade-pilet.js +2 -8
- package/lib/apps/upgrade-pilet.js.map +1 -1
- package/lib/apps/upgrade-piral.js +1 -1
- package/lib/apps/upgrade-piral.js.map +1 -1
- package/lib/bundler.js +1 -1
- package/lib/bundler.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 +4 -1
- package/lib/common/clients/lerna.js +40 -3
- package/lib/common/clients/lerna.js.map +1 -1
- package/lib/common/clients/npm.d.ts +3 -1
- package/lib/common/clients/npm.js +24 -16
- package/lib/common/clients/npm.js.map +1 -1
- package/lib/common/clients/pnpm.d.ts +2 -0
- package/lib/common/clients/pnpm.js +18 -11
- package/lib/common/clients/pnpm.js.map +1 -1
- package/lib/common/clients/rush.d.ts +4 -0
- package/lib/common/clients/rush.js +91 -0
- package/lib/common/clients/rush.js.map +1 -0
- package/lib/common/clients/yarn.d.ts +2 -0
- package/lib/common/clients/yarn.js +20 -13
- package/lib/common/clients/yarn.js.map +1 -1
- package/lib/common/emulator.js +1 -1
- package/lib/common/emulator.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/inspect.js +2 -1
- package/lib/common/inspect.js.map +1 -1
- package/lib/common/npm.d.ts +7 -15
- package/lib/common/npm.js +69 -127
- package/lib/common/npm.js.map +1 -1
- package/lib/common/pack.js +1 -1
- package/lib/common/pack.js.map +1 -1
- package/lib/common/package.d.ts +6 -6
- package/lib/common/package.js +10 -1
- package/lib/common/package.js.map +1 -1
- package/lib/common/scaffold.js +2 -2
- package/lib/common/scaffold.js.map +1 -1
- package/lib/external/index.js +1982 -92
- package/lib/helpers.js +1 -1
- package/lib/helpers.js.map +1 -1
- package/lib/injectors/pilet.js +2 -2
- package/lib/injectors/pilet.js.map +1 -1
- package/lib/plugin.js +27 -2
- package/lib/plugin.js.map +1 -1
- package/lib/types/internal.d.ts +9 -1
- package/lib/types/public.d.ts +1 -1
- package/package.json +4 -2
- package/src/apps/new-pilet.ts +9 -13
- package/src/apps/new-piral.ts +4 -4
- package/src/apps/publish-pilet.ts +2 -2
- package/src/apps/publish-piral.ts +2 -2
- package/src/apps/upgrade-pilet.ts +4 -12
- package/src/apps/upgrade-piral.ts +2 -2
- package/src/bundler.test.ts +1 -1
- package/src/bundler.ts +2 -2
- package/src/common/clients/index.ts +33 -0
- package/src/common/clients/lerna.ts +35 -1
- package/src/common/clients/npm.ts +20 -15
- package/src/common/clients/pnpm.ts +15 -12
- package/src/common/clients/rush.ts +85 -0
- package/src/common/clients/yarn.ts +17 -14
- package/src/common/emulator.ts +2 -2
- package/src/common/info.ts +1 -0
- package/src/common/inspect.ts +2 -1
- package/src/common/npm.test.ts +51 -62
- package/src/common/npm.ts +82 -128
- package/src/common/pack.test.ts +1 -1
- package/src/common/pack.ts +2 -2
- package/src/common/package.ts +16 -7
- package/src/common/scaffold.ts +2 -2
- package/src/external/index.ts +2 -1
- package/src/helpers.ts +1 -1
- package/src/injectors/pilet.ts +3 -3
- package/src/plugin.ts +33 -4
- package/src/types/internal.ts +6 -1
- 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));
|
|
74
|
+
|
|
75
|
+
if (wrapperClient) {
|
|
76
|
+
const { client } = wrapperClient;
|
|
77
|
+
log('generalDebug_0003', `Found valid wrapper client via lock or config file: "${client}".`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (foundClients.length > 0) {
|
|
82
|
+
const { client } = foundClients[0];
|
|
87
83
|
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
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}.`);
|
|
91
87
|
}
|
|
92
|
-
|
|
93
|
-
log('generalDebug_0003', `Found valid
|
|
94
|
-
return
|
|
95
|
-
} else if (hasYarn) {
|
|
96
|
-
log('generalDebug_0003', `Found valid Yarn client via lockfile.`);
|
|
97
|
-
return 'yarn';
|
|
98
|
-
} else if (hasPnpm) {
|
|
99
|
-
log('generalDebug_0003', `Found valid pnpm client via lockfile.`);
|
|
100
|
-
return 'pnpm';
|
|
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,67 @@ 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
|
|
128
|
-
const
|
|
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
|
-
export function installDependencies(client: NpmClientType, target = '.'): Promise<string> {
|
|
178
|
-
const c = require(`./clients/${client}`);
|
|
179
|
-
return c.installDependencies(target);
|
|
117
|
+
export function installNpmDependencies(client: NpmClientType, target = '.'): Promise<string> {
|
|
118
|
+
const { installDependencies } = clients[client];
|
|
119
|
+
return installDependencies(target);
|
|
180
120
|
}
|
|
181
121
|
|
|
182
|
-
export function
|
|
122
|
+
export async function installNpmPackage(
|
|
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
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function initNpmProject(client: NpmClientType, projectName: string, target: string) {
|
|
141
|
+
const { initProject } = clients[client];
|
|
142
|
+
return initProject(projectName, target);
|
|
190
143
|
}
|
|
191
144
|
|
|
192
|
-
export function
|
|
193
|
-
const
|
|
194
|
-
return
|
|
145
|
+
export function publishNpmPackage(target = '.', file = '*.tgz', flags: Array<string> = []): Promise<string> {
|
|
146
|
+
const { publishPackage } = clients.npm;
|
|
147
|
+
return publishPackage(target, file, ...flags);
|
|
195
148
|
}
|
|
196
149
|
|
|
197
|
-
export function
|
|
198
|
-
const
|
|
199
|
-
return
|
|
150
|
+
export function createNpmPackage(target = '.'): Promise<string> {
|
|
151
|
+
const { createPackage } = clients.npm;
|
|
152
|
+
return createPackage(target);
|
|
200
153
|
}
|
|
201
154
|
|
|
202
|
-
export function
|
|
203
|
-
const
|
|
204
|
-
return
|
|
155
|
+
export function findNpmTarball(packageRef: string): Promise<string> {
|
|
156
|
+
const { findTarball } = clients.npm;
|
|
157
|
+
return findTarball(packageRef);
|
|
205
158
|
}
|
|
206
159
|
|
|
207
160
|
export function findSpecificVersion(packageName: string, version: string): Promise<string> {
|
|
208
|
-
const
|
|
209
|
-
return
|
|
161
|
+
const { findSpecificVersion } = clients.npm;
|
|
162
|
+
return findSpecificVersion(packageName, version);
|
|
210
163
|
}
|
|
211
164
|
|
|
212
165
|
export function findLatestVersion(packageName: string) {
|
|
166
|
+
const { findSpecificVersion } = clients.npm;
|
|
213
167
|
return findSpecificVersion(packageName, 'latest');
|
|
214
168
|
}
|
|
215
169
|
|
|
@@ -455,7 +409,7 @@ export function makePiletExternals(
|
|
|
455
409
|
externals: Array<string>,
|
|
456
410
|
fromEmulator: boolean,
|
|
457
411
|
piralInfo: any,
|
|
458
|
-
) {
|
|
412
|
+
): Array<string> {
|
|
459
413
|
if (fromEmulator) {
|
|
460
414
|
const { sharedDependencies = makeExternals(dependencies, externals, true) } = piralInfo;
|
|
461
415
|
return sharedDependencies;
|
package/src/common/pack.test.ts
CHANGED
package/src/common/pack.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolve, join } from 'path';
|
|
2
2
|
import { log, progress, fail } from './log';
|
|
3
3
|
import { readJson, move } from './io';
|
|
4
|
-
import {
|
|
4
|
+
import { createNpmPackage } from './npm';
|
|
5
5
|
import { ForceOverwrite } from './enums';
|
|
6
6
|
|
|
7
7
|
async function getFile(root: string, name: string, dest: string) {
|
|
@@ -38,7 +38,7 @@ export async function createPiletPackage(baseDir: string, source: string, target
|
|
|
38
38
|
|
|
39
39
|
progress(`Packing pilet in ${dest} ...`);
|
|
40
40
|
log('generalDebug_0003', 'Creating package ...');
|
|
41
|
-
await
|
|
41
|
+
await createNpmPackage(root);
|
|
42
42
|
log('generalDebug_0003', 'Successfully created package.');
|
|
43
43
|
const name = `${pckg.name}-${pckg.version}.tgz`.replace(/@/g, '').replace(/\//g, '-');
|
|
44
44
|
log('generalDebug_0003', `Assumed package name "${name}".`);
|
package/src/common/package.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath, makePiletExtern
|
|
|
12
12
|
import { filesTar, filesOnceTar, declarationEntryExtensions, bundlerNames } from './constants';
|
|
13
13
|
import { getHash, checkIsDirectory, matchFiles } from './io';
|
|
14
14
|
import { readJson, copy, updateExistingJson, findFile, checkExists } from './io';
|
|
15
|
-
import { Framework, FileInfo, PiletsInfo, TemplateFileLocation, SharedDependency } from '../types';
|
|
15
|
+
import { Framework, FileInfo, PiletsInfo, TemplateFileLocation, SharedDependency, PackageData } from '../types';
|
|
16
16
|
|
|
17
17
|
function appendBundler(devDependencies: Record<string, string>, bundler: string, version: string) {
|
|
18
18
|
if (bundler && bundler !== 'none') {
|
|
@@ -159,7 +159,7 @@ function findPackage(pck: string | Array<string>, baseDir: string) {
|
|
|
159
159
|
return undefined;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
export function readPiralPackage(root: string, name: string) {
|
|
162
|
+
export function readPiralPackage(root: string, name: string): Promise<PackageData> {
|
|
163
163
|
log('generalDebug_0003', `Reading the piral package in "${root}" ...`);
|
|
164
164
|
const path = getPiralPath(root, name);
|
|
165
165
|
return readJson(path, 'package.json');
|
|
@@ -319,10 +319,19 @@ function isTemplateFileLocation(item: string | TemplateFileLocation): item is Te
|
|
|
319
319
|
return typeof item === 'object';
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
+
function tryFindPackageVersion(packageName: string): string {
|
|
323
|
+
try {
|
|
324
|
+
const { version } = require(`${packageName}/package.json`);
|
|
325
|
+
return version;
|
|
326
|
+
} catch {
|
|
327
|
+
return undefined;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
322
331
|
export async function copyPiralFiles(
|
|
323
332
|
root: string,
|
|
324
333
|
name: string,
|
|
325
|
-
piralInfo:
|
|
334
|
+
piralInfo: PackageData,
|
|
326
335
|
forceOverwrite: ForceOverwrite,
|
|
327
336
|
variables: Record<string, string>,
|
|
328
337
|
originalFiles?: Array<FileInfo>,
|
|
@@ -342,7 +351,7 @@ export async function copyPiralFiles(
|
|
|
342
351
|
await copyFiles(files, forceOverwrite, originalFiles, variables);
|
|
343
352
|
}
|
|
344
353
|
|
|
345
|
-
export function getPiletsInfo(piralInfo:
|
|
354
|
+
export function getPiletsInfo(piralInfo: Partial<PackageData>): PiletsInfo {
|
|
346
355
|
const {
|
|
347
356
|
files = [],
|
|
348
357
|
externals = [],
|
|
@@ -491,7 +500,7 @@ export async function patchPiletPackage(
|
|
|
491
500
|
root: string,
|
|
492
501
|
name: string,
|
|
493
502
|
version: string,
|
|
494
|
-
piralInfo:
|
|
503
|
+
piralInfo: PackageData,
|
|
495
504
|
fromEmulator: boolean,
|
|
496
505
|
newInfo?: { language: SourceLanguage; bundler: string },
|
|
497
506
|
) {
|
|
@@ -539,7 +548,7 @@ export async function patchPiletPackage(
|
|
|
539
548
|
return deps;
|
|
540
549
|
}, {}),
|
|
541
550
|
...allExternals.filter(isValidDependency).reduce((deps, name) => {
|
|
542
|
-
const version = piralDependencies[name];
|
|
551
|
+
const version = piralDependencies[name] || tryFindPackageVersion(name);
|
|
543
552
|
|
|
544
553
|
if (version || newInfo) {
|
|
545
554
|
// set only if we have an explicit version or we are in the scaffolding case
|
|
@@ -576,7 +585,7 @@ export async function patchPiletPackage(
|
|
|
576
585
|
/**
|
|
577
586
|
* Returns true if its an emulator package, otherwise it has to be a "raw" app shell.
|
|
578
587
|
*/
|
|
579
|
-
export function checkAppShellPackage(appPackage:
|
|
588
|
+
export function checkAppShellPackage(appPackage: PackageData) {
|
|
580
589
|
const { piralCLI = { generated: false, version: cliVersion } } = appPackage;
|
|
581
590
|
|
|
582
591
|
if (piralCLI.generated) {
|
package/src/common/scaffold.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { join, dirname, resolve, basename, isAbsolute } from 'path';
|
|
2
|
-
import {
|
|
2
|
+
import { installNpmPackage } 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
|
|
39
|
+
await installNpmPackage('npm', templatePackageName, __dirname, '--registry', registry);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const templateRunner = getTemplatePackage(templatePackageName);
|
package/src/external/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import logger = require('@parcel/logger');
|
|
2
2
|
import stripAnsi = require('strip-ansi');
|
|
3
3
|
import inquirer = require('inquirer');
|
|
4
|
+
import jju = require('jju');
|
|
4
5
|
import glob = require('glob');
|
|
5
6
|
import tar = require('tar');
|
|
6
7
|
import FormData = require('form-data');
|
|
@@ -10,4 +11,4 @@ import mime = require('mime');
|
|
|
10
11
|
import getPort = require('get-port');
|
|
11
12
|
import open = require('open');
|
|
12
13
|
|
|
13
|
-
export { logger, inquirer, glob, tar, FormData, rc, axios, mime, stripAnsi, getPort, open };
|
|
14
|
+
export { logger, inquirer, glob, tar, FormData, rc, axios, mime, stripAnsi, getPort, open, jju };
|
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/injectors/pilet.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { KrasInjector, KrasResponse, KrasRequest, KrasInjectorConfig, KrasConfig
|
|
|
6
6
|
import { log } from '../common/log';
|
|
7
7
|
import { getPiletSpecMeta } from '../common/spec';
|
|
8
8
|
import { config } from '../common/config';
|
|
9
|
-
import { axios, mime } from '../external';
|
|
9
|
+
import { axios, mime, jju } from '../external';
|
|
10
10
|
import { Bundler } from '../types';
|
|
11
11
|
|
|
12
12
|
const { host } = config;
|
|
@@ -35,8 +35,8 @@ function fillPiletMeta(pilet: Pilet, basePath: string, metaFile: string) {
|
|
|
35
35
|
const { root, bundler } = pilet;
|
|
36
36
|
const metaPath = join(root, metaFile);
|
|
37
37
|
const packagePath = join(root, 'package.json');
|
|
38
|
-
const def =
|
|
39
|
-
const metaOverride = existsSync(metaPath) ?
|
|
38
|
+
const def = jju.parse(readFileSync(packagePath, 'utf8'));
|
|
39
|
+
const metaOverride = existsSync(metaPath) ? jju.parse(readFileSync(metaPath, 'utf8')) : undefined;
|
|
40
40
|
const file = bundler.bundle.name.replace(/^[\/\\]/, '');
|
|
41
41
|
const target = join(bundler.bundle.dir, file);
|
|
42
42
|
const url = new URL(file, basePath);
|
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/internal.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LogLevels } from './common';
|
|
1
|
+
import type { LogLevels, PiletsInfo } from './common';
|
|
2
2
|
|
|
3
3
|
export interface PackageData {
|
|
4
4
|
name: string;
|
|
@@ -13,6 +13,11 @@ export interface PackageData {
|
|
|
13
13
|
email?: string;
|
|
14
14
|
};
|
|
15
15
|
custom?: any;
|
|
16
|
+
pilets?: PiletsInfo;
|
|
17
|
+
piralCLI?: { generated: boolean; version: string };
|
|
18
|
+
dependencies: Record<string, string>;
|
|
19
|
+
peerDependencies: Record<string, string>;
|
|
20
|
+
devDependencies: Record<string, string>;
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
export interface PackageFiles {
|
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
|
|