piral-cli 0.15.0-alpha.4122 → 0.15.0-alpha.4284
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/README.md +7 -5
- package/lib/apps/debug-pilet.js +28 -42
- package/lib/apps/debug-pilet.js.map +1 -1
- package/lib/apps/debug-piral.js +20 -34
- package/lib/apps/debug-piral.js.map +1 -1
- package/lib/apps/new-pilet.js +5 -9
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/new-piral.js +9 -3
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/apps/publish-pilet.d.ts +4 -0
- package/lib/apps/publish-pilet.js +4 -3
- package/lib/apps/publish-pilet.js.map +1 -1
- package/lib/apps/publish-piral.d.ts +4 -0
- package/lib/apps/publish-piral.js +9 -7
- 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/commands.js +14 -6
- package/lib/commands.js.map +1 -1
- package/lib/common/browser.d.ts +1 -0
- package/lib/common/browser.js +16 -10
- package/lib/common/browser.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 +6 -1
- package/lib/common/clients/lerna.js +67 -3
- package/lib/common/clients/lerna.js.map +1 -1
- package/lib/common/clients/npm.d.ts +4 -1
- package/lib/common/clients/npm.js +37 -16
- package/lib/common/clients/npm.js.map +1 -1
- package/lib/common/clients/pnpm.d.ts +4 -0
- package/lib/common/clients/pnpm.js +43 -9
- package/lib/common/clients/pnpm.js.map +1 -1
- package/lib/common/clients/rush.d.ts +6 -0
- package/lib/common/clients/rush.js +118 -0
- package/lib/common/clients/rush.js.map +1 -0
- package/lib/common/clients/yarn.d.ts +4 -0
- package/lib/common/clients/yarn.js +45 -11
- package/lib/common/clients/yarn.js.map +1 -1
- package/lib/common/declaration.js +12 -9
- package/lib/common/declaration.js.map +1 -1
- package/lib/common/emulator.js +2 -2
- package/lib/common/emulator.js.map +1 -1
- package/lib/common/http.d.ts +4 -2
- package/lib/common/http.js +35 -16
- package/lib/common/http.js.map +1 -1
- package/lib/common/info.d.ts +4 -0
- package/lib/common/info.js +6 -1
- package/lib/common/info.js.map +1 -1
- package/lib/common/injectors.d.ts +36 -7
- package/lib/common/injectors.js +39 -11
- package/lib/common/injectors.js.map +1 -1
- package/lib/common/inspect.js +2 -1
- package/lib/common/inspect.js.map +1 -1
- package/lib/common/interactive.d.ts +9 -0
- package/lib/common/interactive.js +33 -1
- package/lib/common/interactive.js.map +1 -1
- package/lib/common/io.js +1 -1
- package/lib/common/io.js.map +1 -1
- package/lib/common/log.d.ts +1 -0
- package/lib/common/log.js +9 -2
- package/lib/common/log.js.map +1 -1
- package/lib/common/npm.d.ts +9 -16
- package/lib/common/npm.js +110 -152
- 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 +13 -4
- package/lib/common/package.js.map +1 -1
- package/lib/common/port.d.ts +1 -0
- package/lib/common/port.js +11 -1
- package/lib/common/port.js.map +1 -1
- package/lib/common/scaffold.js +5 -2
- package/lib/common/scaffold.js.map +1 -1
- package/lib/common/version.js +4 -4
- package/lib/common/version.js.map +1 -1
- package/lib/external/index.js +1982 -92
- package/lib/helpers.d.ts +3 -3
- package/lib/helpers.js +10 -10
- package/lib/helpers.js.map +1 -1
- package/lib/injectors/{pilet.d.ts → pilet-injector.d.ts} +1 -0
- package/lib/injectors/{pilet.js → pilet-injector.js} +29 -31
- package/lib/injectors/pilet-injector.js.map +1 -0
- package/lib/injectors/{piral.d.ts → piral-injector.d.ts} +1 -0
- package/lib/injectors/{piral.js → piral-injector.js} +20 -22
- package/lib/injectors/piral-injector.js.map +1 -0
- package/lib/messages.d.ts +79 -1
- package/lib/messages.js +89 -2
- package/lib/messages.js.map +1 -1
- package/lib/plugin.js +27 -2
- package/lib/plugin.js.map +1 -1
- package/lib/release.d.ts +1 -1
- package/lib/release.js +35 -3
- package/lib/release.js.map +1 -1
- package/lib/types/common.d.ts +1 -1
- package/lib/types/internal.d.ts +9 -1
- package/lib/types/public.d.ts +1 -1
- package/package.json +6 -4
- package/src/apps/debug-pilet.ts +28 -48
- package/src/apps/debug-piral.ts +22 -37
- package/src/apps/new-pilet.ts +9 -14
- package/src/apps/new-piral.ts +16 -5
- package/src/apps/publish-pilet.ts +10 -3
- package/src/apps/publish-piral.ts +21 -6
- 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/commands.ts +17 -9
- package/src/common/browser.ts +12 -8
- package/src/common/clients/index.ts +33 -0
- package/src/common/clients/lerna.ts +61 -1
- package/src/common/clients/npm.ts +32 -15
- package/src/common/clients/pnpm.ts +39 -10
- package/src/common/clients/rush.ts +111 -0
- package/src/common/clients/yarn.ts +41 -12
- package/src/common/declaration.ts +15 -9
- package/src/common/emulator.ts +3 -3
- package/src/common/http.ts +56 -19
- package/src/common/info.ts +6 -1
- package/src/common/injectors.ts +46 -17
- package/src/common/inspect.ts +2 -1
- package/src/common/interactive.test.ts +3 -0
- package/src/common/interactive.ts +49 -1
- package/src/common/io.ts +1 -1
- package/src/common/log.ts +9 -1
- package/src/common/npm.test.ts +109 -76
- package/src/common/npm.ts +119 -146
- package/src/common/pack.test.ts +1 -1
- package/src/common/pack.ts +2 -2
- package/src/common/package.ts +19 -10
- package/src/common/port.ts +10 -0
- package/src/common/scaffold.ts +6 -2
- package/src/common/version.ts +4 -4
- package/src/external/index.ts +2 -1
- package/src/helpers.test.ts +5 -5
- package/src/helpers.ts +7 -7
- package/src/injectors/{pilet.test.ts → pilet-injector.test.ts} +10 -1
- package/src/injectors/{pilet.ts → pilet-injector.ts} +36 -28
- package/src/injectors/{piral.test.ts → piral-injector.test.ts} +5 -1
- package/src/injectors/{piral.ts → piral-injector.ts} +24 -17
- package/src/messages.ts +88 -1
- package/src/plugin.ts +34 -5
- package/src/release.ts +47 -5
- package/src/types/common.ts +1 -1
- package/src/types/internal.ts +6 -1
- package/src/types/public.ts +1 -1
- package/lib/injectors/pilet.js.map +0 -1
- package/lib/injectors/piral.js.map +0 -1
package/src/common/npm.ts
CHANGED
|
@@ -1,65 +1,60 @@
|
|
|
1
1
|
import { resolve, relative, dirname, isAbsolute, sep } 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';
|
|
7
|
-
import { readJson, checkExists
|
|
8
|
+
import { readJson, checkExists } from './io';
|
|
8
9
|
import { clientTypeKeys } from '../helpers';
|
|
9
10
|
import { PackageType, NpmClientType } from '../types';
|
|
10
11
|
|
|
11
12
|
const gitPrefix = 'git+';
|
|
12
13
|
const filePrefix = 'file:';
|
|
14
|
+
const pathPrefixes = ['/', './', '../', '.\\', '..\\', '~/', '~\\', filePrefix];
|
|
13
15
|
|
|
14
16
|
function isProjectReference(name: string) {
|
|
15
17
|
const target = resolve(name, 'package.json');
|
|
16
18
|
return checkExists(target);
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
});
|
|
21
|
+
function resolveAbsPath(basePath: string, fullName: string) {
|
|
22
|
+
const prefixed = fullName.startsWith(filePrefix);
|
|
23
|
+
const relPath = !prefixed ? fullName : fullName.replace(filePrefix, '');
|
|
24
|
+
return resolve(basePath, relPath);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
access(resolve(root, 'package-lock.json'), constants.F_OK, (noPackageLock) => {
|
|
30
|
-
res(!noPackageLock);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
27
|
+
async function detectMonorepoRoot(root: string): Promise<[] | [string, NpmClientType]> {
|
|
28
|
+
let previous = root;
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
do {
|
|
31
|
+
if (await checkExists(resolve(root, 'lerna.json'))) {
|
|
32
|
+
return [root, 'lerna'];
|
|
33
|
+
}
|
|
38
34
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
if (await checkExists(resolve(root, 'rush.json'))) {
|
|
36
|
+
return [root, 'rush'];
|
|
37
|
+
}
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
39
|
+
if (await checkExists(resolve(root, 'pnpm-workspace.yaml'))) {
|
|
40
|
+
return [root, 'pnpm'];
|
|
41
|
+
}
|
|
47
42
|
|
|
48
|
-
|
|
49
|
-
}
|
|
43
|
+
const packageJson = await readJson(root, 'package.json');
|
|
50
44
|
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
if (Array.isArray(packageJson?.workspaces)) {
|
|
46
|
+
if (await checkExists(resolve(root, 'yarn.lock'))) {
|
|
47
|
+
return [root, 'yarn'];
|
|
48
|
+
}
|
|
53
49
|
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
return require(file).npmClient;
|
|
57
|
-
} catch (err) {
|
|
58
|
-
log('generalError_0002', `Could not read lerna.json: ${err}.`);
|
|
50
|
+
return [root, 'npm'];
|
|
59
51
|
}
|
|
60
|
-
}
|
|
61
52
|
|
|
62
|
-
|
|
53
|
+
previous = root;
|
|
54
|
+
root = dirname(root);
|
|
55
|
+
} while (root !== previous);
|
|
56
|
+
|
|
57
|
+
return [];
|
|
63
58
|
}
|
|
64
59
|
|
|
65
60
|
/**
|
|
@@ -69,36 +64,45 @@ export async function getLernaNpmClient(root: string): Promise<NpmClientType> {
|
|
|
69
64
|
*/
|
|
70
65
|
export async function determineNpmClient(root: string, selected?: NpmClientType): Promise<NpmClientType> {
|
|
71
66
|
if (!selected || !clientTypeKeys.includes(selected)) {
|
|
72
|
-
log('generalDebug_0003', 'No npm client selected. Checking for lock files ...');
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
67
|
+
log('generalDebug_0003', 'No npm client selected. Checking for lock or config files ...');
|
|
68
|
+
|
|
69
|
+
const searchedClients = await detectClients(root);
|
|
70
|
+
const foundClients = searchedClients.filter((m) => m.result);
|
|
71
|
+
|
|
72
|
+
log(
|
|
73
|
+
'generalDebug_0003',
|
|
74
|
+
`Results of the lock file check: ${searchedClients.map((m) => `${m.client}=${m.result}`).join(', ')}`,
|
|
75
|
+
);
|
|
76
|
+
|
|
76
77
|
const defaultClient = config.npmClient;
|
|
77
78
|
|
|
78
|
-
if (
|
|
79
|
-
const
|
|
79
|
+
if (foundClients.length > 1) {
|
|
80
|
+
const wrapperClient = foundClients.find((m) => isWrapperClient(m.client));
|
|
80
81
|
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
if (wrapperClient) {
|
|
83
|
+
const { client } = wrapperClient;
|
|
84
|
+
log('generalDebug_0003', `Found valid wrapper client via lock or config file: "${client}".`);
|
|
84
85
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (foundClients.length > 0) {
|
|
89
|
+
const { client } = foundClients[0];
|
|
90
|
+
|
|
91
|
+
if (foundClients.length > 1) {
|
|
92
|
+
const clientStr = `"${foundClients.map((m) => m.client).join('", "')}"`;
|
|
93
|
+
log('generalWarning_0001', `Found multiple clients via their lock or config files: ${clientStr}.`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
log('generalDebug_0003', `Found valid direct client via lock or config file: "${client}".`);
|
|
97
|
+
return client;
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
if (clientTypeKeys.includes(defaultClient)) {
|
|
97
|
-
log('generalDebug_0003', `
|
|
101
|
+
log('generalDebug_0003', `Using the default client: "${defaultClient}".`);
|
|
98
102
|
return defaultClient;
|
|
99
103
|
}
|
|
100
104
|
|
|
101
|
-
log('generalDebug_0003', 'Using the default npm client.');
|
|
105
|
+
log('generalDebug_0003', 'Using the default "npm" client.');
|
|
102
106
|
return 'npm';
|
|
103
107
|
}
|
|
104
108
|
|
|
@@ -106,103 +110,66 @@ export async function determineNpmClient(root: string, selected?: NpmClientType)
|
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
export async function isMonorepoPackageRef(refName: string, root: string): Promise<boolean> {
|
|
109
|
-
const
|
|
110
|
-
const newRoot = await detectMonorepoRoot(root);
|
|
113
|
+
const [monorepoRoot, client] = await detectMonorepoRoot(root);
|
|
111
114
|
|
|
112
|
-
if (
|
|
113
|
-
const
|
|
114
|
-
return
|
|
115
|
+
if (monorepoRoot) {
|
|
116
|
+
const c = clients[client];
|
|
117
|
+
return await c.isProject(monorepoRoot, refName);
|
|
115
118
|
}
|
|
116
119
|
|
|
117
120
|
return false;
|
|
118
121
|
}
|
|
119
122
|
|
|
120
|
-
export
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
if (file !== undefined) {
|
|
124
|
-
return dirname(file);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
let previous = root;
|
|
128
|
-
|
|
129
|
-
do {
|
|
130
|
-
const packageJson = await readJson(root, 'package.json');
|
|
131
|
-
|
|
132
|
-
if (Array.isArray(packageJson?.workspaces)) {
|
|
133
|
-
return root;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
previous = root;
|
|
137
|
-
root = dirname(root);
|
|
138
|
-
} while (root !== previous);
|
|
139
|
-
|
|
140
|
-
return undefined;
|
|
123
|
+
export function installNpmDependencies(client: NpmClientType, target = '.'): Promise<string> {
|
|
124
|
+
const { installDependencies } = clients[client];
|
|
125
|
+
return installDependencies(target);
|
|
141
126
|
}
|
|
142
127
|
|
|
143
|
-
export
|
|
144
|
-
|
|
145
|
-
export async function detectMonorepo(root: string): Promise<MonorepoKind> {
|
|
146
|
-
const newRoot = await detectMonorepoRoot(root);
|
|
147
|
-
|
|
148
|
-
if (newRoot) {
|
|
149
|
-
const file = await getLernaConfigPath(newRoot);
|
|
150
|
-
|
|
151
|
-
if (file !== undefined) {
|
|
152
|
-
return 'lerna';
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const packageJson = await readJson(newRoot, 'package.json');
|
|
156
|
-
|
|
157
|
-
if (Array.isArray(packageJson?.workspaces)) {
|
|
158
|
-
return 'yarn';
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return 'none';
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export function bootstrapMonorepo(target = '.') {
|
|
166
|
-
const c = require(`./clients/lerna`);
|
|
167
|
-
return c.bootstrap(target);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export function installDependencies(client: NpmClientType, target = '.'): Promise<string> {
|
|
171
|
-
const c = require(`./clients/${client}`);
|
|
172
|
-
return c.installDependencies(target);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export function installPackage(
|
|
128
|
+
export async function installNpmPackage(
|
|
176
129
|
client: NpmClientType,
|
|
177
130
|
packageRef: string,
|
|
178
131
|
target = '.',
|
|
179
132
|
...flags: Array<string>
|
|
180
133
|
): Promise<string> {
|
|
181
|
-
|
|
182
|
-
|
|
134
|
+
try {
|
|
135
|
+
const { installPackage } = clients[client];
|
|
136
|
+
return await installPackage(packageRef, target, ...flags);
|
|
137
|
+
} catch (ex) {
|
|
138
|
+
log(
|
|
139
|
+
'generalError_0002',
|
|
140
|
+
`Could not install the package "${packageRef}" using ${client}. Make sure ${client} is correctly installed and accessible: ${ex}`,
|
|
141
|
+
);
|
|
142
|
+
throw ex;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function initNpmProject(client: NpmClientType, projectName: string, target: string) {
|
|
147
|
+
const { initProject } = clients[client];
|
|
148
|
+
return initProject(projectName, target);
|
|
183
149
|
}
|
|
184
150
|
|
|
185
|
-
export function
|
|
186
|
-
const
|
|
187
|
-
return
|
|
151
|
+
export function publishNpmPackage(target = '.', file = '*.tgz', flags: Array<string> = []): Promise<string> {
|
|
152
|
+
const { publishPackage } = clients.npm;
|
|
153
|
+
return publishPackage(target, file, ...flags);
|
|
188
154
|
}
|
|
189
155
|
|
|
190
|
-
export function
|
|
191
|
-
const
|
|
192
|
-
return
|
|
156
|
+
export function createNpmPackage(target = '.'): Promise<string> {
|
|
157
|
+
const { createPackage } = clients.npm;
|
|
158
|
+
return createPackage(target);
|
|
193
159
|
}
|
|
194
160
|
|
|
195
|
-
export function
|
|
196
|
-
const
|
|
197
|
-
return
|
|
161
|
+
export function findNpmTarball(packageRef: string): Promise<string> {
|
|
162
|
+
const { findTarball } = clients.npm;
|
|
163
|
+
return findTarball(packageRef);
|
|
198
164
|
}
|
|
199
165
|
|
|
200
166
|
export function findSpecificVersion(packageName: string, version: string): Promise<string> {
|
|
201
|
-
const
|
|
202
|
-
return
|
|
167
|
+
const { findSpecificVersion } = clients.npm;
|
|
168
|
+
return findSpecificVersion(packageName, version);
|
|
203
169
|
}
|
|
204
170
|
|
|
205
171
|
export function findLatestVersion(packageName: string) {
|
|
172
|
+
const { findSpecificVersion } = clients.npm;
|
|
206
173
|
return findSpecificVersion(packageName, 'latest');
|
|
207
174
|
}
|
|
208
175
|
|
|
@@ -210,7 +177,7 @@ export function isLocalPackage(baseDir: string, fullName: string) {
|
|
|
210
177
|
log('generalDebug_0003', 'Checking if its a local package ...');
|
|
211
178
|
|
|
212
179
|
if (fullName) {
|
|
213
|
-
if (
|
|
180
|
+
if (pathPrefixes.some((prefix) => fullName.startsWith(prefix))) {
|
|
214
181
|
log('generalDebug_0003', 'Found a local package by name.');
|
|
215
182
|
return true;
|
|
216
183
|
} else if (fullName.endsWith('.tgz')) {
|
|
@@ -249,9 +216,7 @@ export function makeGitUrl(fullName: string) {
|
|
|
249
216
|
}
|
|
250
217
|
|
|
251
218
|
export function makeFilePath(basePath: string, fullName: string) {
|
|
252
|
-
const
|
|
253
|
-
const relPath = !prefixed ? fullName : fullName.replace(filePrefix, '');
|
|
254
|
-
const absPath = resolve(basePath, relPath);
|
|
219
|
+
const absPath = resolveAbsPath(basePath, fullName);
|
|
255
220
|
return `${filePrefix}${absPath}`;
|
|
256
221
|
}
|
|
257
222
|
|
|
@@ -275,7 +240,7 @@ export async function dissectPackageName(
|
|
|
275
240
|
const gitUrl = makeGitUrl(fullName);
|
|
276
241
|
return [gitUrl, 'latest', false, 'git'];
|
|
277
242
|
} else if (isLocalPackage(baseDir, fullName)) {
|
|
278
|
-
const fullPath =
|
|
243
|
+
const fullPath = resolveAbsPath(baseDir, fullName);
|
|
279
244
|
const exists = await checkExists(fullPath);
|
|
280
245
|
|
|
281
246
|
if (!exists) {
|
|
@@ -418,7 +383,8 @@ export function isLinkedPackage(name: string, type: PackageType, hadVersion: boo
|
|
|
418
383
|
|
|
419
384
|
export function combinePackageRef(name: string, version: string, type: PackageType) {
|
|
420
385
|
if (type === 'registry') {
|
|
421
|
-
|
|
386
|
+
const tag = version || 'latest';
|
|
387
|
+
return `${name}@${tag}`;
|
|
422
388
|
}
|
|
423
389
|
|
|
424
390
|
return name;
|
|
@@ -472,19 +438,22 @@ export function getPackageVersion(
|
|
|
472
438
|
}
|
|
473
439
|
}
|
|
474
440
|
|
|
475
|
-
function getExternalsFrom(packageName: string): Array<string> | undefined {
|
|
441
|
+
function getExternalsFrom(root: string, packageName: string): Array<string> | undefined {
|
|
476
442
|
try {
|
|
477
|
-
|
|
443
|
+
const target = require.resolve(`${packageName}/package.json`, {
|
|
444
|
+
paths: [root],
|
|
445
|
+
});
|
|
446
|
+
return require(target).sharedDependencies;
|
|
478
447
|
} catch (err) {
|
|
479
448
|
log('generalError_0002', `Could not get externals from "${packageName}": "${err}`);
|
|
480
449
|
return undefined;
|
|
481
450
|
}
|
|
482
451
|
}
|
|
483
452
|
|
|
484
|
-
function getCoreExternals(dependencies: Record<string, string>): Array<string> {
|
|
453
|
+
function getCoreExternals(root: string, dependencies: Record<string, string>): Array<string> {
|
|
485
454
|
for (const frameworkLib of frameworkLibs) {
|
|
486
455
|
if (dependencies[frameworkLib]) {
|
|
487
|
-
const deps = getExternalsFrom(frameworkLib);
|
|
456
|
+
const deps = getExternalsFrom(root, frameworkLib);
|
|
488
457
|
|
|
489
458
|
if (deps) {
|
|
490
459
|
return deps;
|
|
@@ -497,24 +466,23 @@ function getCoreExternals(dependencies: Record<string, string>): Array<string> {
|
|
|
497
466
|
}
|
|
498
467
|
|
|
499
468
|
export function makePiletExternals(
|
|
469
|
+
root: string,
|
|
500
470
|
dependencies: Record<string, string>,
|
|
501
471
|
externals: Array<string>,
|
|
502
472
|
fromEmulator: boolean,
|
|
503
473
|
piralInfo: any,
|
|
504
|
-
) {
|
|
474
|
+
): Array<string> {
|
|
505
475
|
if (fromEmulator) {
|
|
506
|
-
const { sharedDependencies =
|
|
476
|
+
const { sharedDependencies = mergeExternals(externals, legacyCoreExternals) } = piralInfo;
|
|
507
477
|
return sharedDependencies;
|
|
508
478
|
} else {
|
|
509
|
-
return makeExternals(dependencies, externals);
|
|
479
|
+
return makeExternals(root, dependencies, externals);
|
|
510
480
|
}
|
|
511
481
|
}
|
|
512
482
|
|
|
513
|
-
export function
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
if (externals && Array.isArray(externals)) {
|
|
517
|
-
const [include, exclude] = externals.reduce<[Array<string>, Array<string>]>(
|
|
483
|
+
export function mergeExternals(customExternals?: Array<string>, coreExternals: Array<string> = []) {
|
|
484
|
+
if (customExternals && Array.isArray(customExternals)) {
|
|
485
|
+
const [include, exclude] = customExternals.reduce<[Array<string>, Array<string>]>(
|
|
518
486
|
(prev, curr) => {
|
|
519
487
|
if (typeof curr === 'string') {
|
|
520
488
|
if (curr.startsWith('!')) {
|
|
@@ -534,3 +502,8 @@ export function makeExternals(dependencies: Record<string, string>, externals?:
|
|
|
534
502
|
|
|
535
503
|
return coreExternals;
|
|
536
504
|
}
|
|
505
|
+
|
|
506
|
+
export function makeExternals(root: string, dependencies: Record<string, string>, externals?: Array<string>) {
|
|
507
|
+
const coreExternals = getCoreExternals(root, dependencies);
|
|
508
|
+
return mergeExternals(externals, coreExternals);
|
|
509
|
+
}
|
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
|
@@ -13,7 +13,7 @@ import { getHash, checkIsDirectory, matchFiles } from './io';
|
|
|
13
13
|
import { readJson, copy, updateExistingJson, findFile, checkExists } from './io';
|
|
14
14
|
import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath } from './npm';
|
|
15
15
|
import { makePiletExternals, makeExternals, findPackageRoot } from './npm';
|
|
16
|
-
import { Framework, FileInfo, PiletsInfo, TemplateFileLocation } from '../types';
|
|
16
|
+
import { Framework, FileInfo, PiletsInfo, TemplateFileLocation, PackageData } from '../types';
|
|
17
17
|
|
|
18
18
|
function appendBundler(devDependencies: Record<string, string>, bundler: string, version: string) {
|
|
19
19
|
if (bundler && bundler !== 'none') {
|
|
@@ -149,7 +149,7 @@ function findPackage(pck: string | Array<string>, baseDir: string) {
|
|
|
149
149
|
return undefined;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
export function readPiralPackage(root: string, name: string) {
|
|
152
|
+
export function readPiralPackage(root: string, name: string): Promise<PackageData> {
|
|
153
153
|
log('generalDebug_0003', `Reading the piral package in "${root}" ...`);
|
|
154
154
|
const path = getPiralPath(root, name);
|
|
155
155
|
return readJson(path, 'package.json');
|
|
@@ -318,10 +318,19 @@ function isTemplateFileLocation(item: string | TemplateFileLocation): item is Te
|
|
|
318
318
|
return typeof item === 'object';
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
+
function tryFindPackageVersion(packageName: string): string {
|
|
322
|
+
try {
|
|
323
|
+
const { version } = require(`${packageName}/package.json`);
|
|
324
|
+
return version;
|
|
325
|
+
} catch {
|
|
326
|
+
return undefined;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
321
330
|
export async function copyPiralFiles(
|
|
322
331
|
root: string,
|
|
323
332
|
name: string,
|
|
324
|
-
piralInfo:
|
|
333
|
+
piralInfo: PackageData,
|
|
325
334
|
forceOverwrite: ForceOverwrite,
|
|
326
335
|
variables: Record<string, string>,
|
|
327
336
|
originalFiles?: Array<FileInfo>,
|
|
@@ -341,7 +350,7 @@ export async function copyPiralFiles(
|
|
|
341
350
|
await copyFiles(files, forceOverwrite, originalFiles, variables);
|
|
342
351
|
}
|
|
343
352
|
|
|
344
|
-
export function getPiletsInfo(piralInfo:
|
|
353
|
+
export function getPiletsInfo(piralInfo: Partial<PackageData>): PiletsInfo {
|
|
345
354
|
const {
|
|
346
355
|
files = [],
|
|
347
356
|
scripts = {},
|
|
@@ -450,7 +459,7 @@ export async function retrieveExternals(root: string, packageInfo: any) {
|
|
|
450
459
|
...packageInfo.dependencies,
|
|
451
460
|
};
|
|
452
461
|
const deps = packageInfo.pilets?.externals;
|
|
453
|
-
return makeExternals(allDeps, deps);
|
|
462
|
+
return makeExternals(root, allDeps, deps);
|
|
454
463
|
}
|
|
455
464
|
|
|
456
465
|
return sharedDependencies.map((m) => m.name);
|
|
@@ -469,9 +478,9 @@ export async function retrievePiletsInfo(entryFile: string) {
|
|
|
469
478
|
fail('packageJsonMissing_0074');
|
|
470
479
|
}
|
|
471
480
|
|
|
481
|
+
const root = dirname(packageJson);
|
|
472
482
|
const packageInfo = require(packageJson);
|
|
473
483
|
const info = getPiletsInfo(packageInfo);
|
|
474
|
-
const root = dirname(packageJson);
|
|
475
484
|
const externals = await retrieveExternals(root, packageInfo);
|
|
476
485
|
|
|
477
486
|
return {
|
|
@@ -500,7 +509,7 @@ export async function patchPiletPackage(
|
|
|
500
509
|
root: string,
|
|
501
510
|
name: string,
|
|
502
511
|
version: string,
|
|
503
|
-
piralInfo:
|
|
512
|
+
piralInfo: PackageData,
|
|
504
513
|
fromEmulator: boolean,
|
|
505
514
|
newInfo?: { language: SourceLanguage; bundler: string },
|
|
506
515
|
) {
|
|
@@ -524,7 +533,7 @@ export async function patchPiletPackage(
|
|
|
524
533
|
}
|
|
525
534
|
: info.scripts;
|
|
526
535
|
const peerModules = [];
|
|
527
|
-
const allExternals = makePiletExternals(piralDependencies, externals, fromEmulator, piralInfo);
|
|
536
|
+
const allExternals = makePiletExternals(root, piralDependencies, externals, fromEmulator, piralInfo);
|
|
528
537
|
const peerDependencies = {
|
|
529
538
|
...allExternals.reduce((deps, name) => {
|
|
530
539
|
const valid = isValidDependency(name);
|
|
@@ -548,7 +557,7 @@ export async function patchPiletPackage(
|
|
|
548
557
|
return deps;
|
|
549
558
|
}, {}),
|
|
550
559
|
...allExternals.filter(isValidDependency).reduce((deps, name) => {
|
|
551
|
-
const version = piralDependencies[name];
|
|
560
|
+
const version = piralDependencies[name] || tryFindPackageVersion(name);
|
|
552
561
|
|
|
553
562
|
if (version || newInfo) {
|
|
554
563
|
// set only if we have an explicit version or we are in the scaffolding case
|
|
@@ -585,7 +594,7 @@ export async function patchPiletPackage(
|
|
|
585
594
|
/**
|
|
586
595
|
* Returns true if its an emulator package, otherwise it has to be a "raw" app shell.
|
|
587
596
|
*/
|
|
588
|
-
export function checkAppShellPackage(appPackage:
|
|
597
|
+
export function checkAppShellPackage(appPackage: PackageData) {
|
|
589
598
|
const { piralCLI = { generated: false, version: cliVersion } } = appPackage;
|
|
590
599
|
|
|
591
600
|
if (piralCLI.generated) {
|
package/src/common/port.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { log } from './log';
|
|
2
2
|
import { getPort } from '../external';
|
|
3
3
|
|
|
4
|
+
export async function getAvailablePort(defaultPort: number) {
|
|
5
|
+
const selectedPort = await getFreePort(defaultPort);
|
|
6
|
+
|
|
7
|
+
if (selectedPort !== defaultPort) {
|
|
8
|
+
log('portNotFree_0047', selectedPort, defaultPort);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return selectedPort;
|
|
12
|
+
}
|
|
13
|
+
|
|
4
14
|
export async function getFreePort(preferred?: number) {
|
|
5
15
|
log('generalDebug_0003', `Looking for a free port. Preferred port: ${preferred}`);
|
|
6
16
|
const port = await getPort(preferred && { port: preferred });
|
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 { cliVersion, isWindows } from './info';
|
|
@@ -37,7 +37,11 @@ async function getTemplateFiles(
|
|
|
37
37
|
if (templatePackageName.startsWith('.')) {
|
|
38
38
|
templatePackageName = resolve(process.cwd(), templatePackageName);
|
|
39
39
|
} else {
|
|
40
|
-
|
|
40
|
+
if (templatePackageName.indexOf('@', 1) === -1) {
|
|
41
|
+
templatePackageName = `${templatePackageName}@latest`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
await installNpmPackage('npm', templatePackageName, __dirname, '--registry', registry);
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
const templateRunner = getTemplatePackage(templatePackageName);
|
package/src/common/version.ts
CHANGED
|
@@ -16,15 +16,15 @@ function indexOrEnd(str: string, q: string) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
function splitVersion(v: string) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const c = v.replace(/^v/, '').replace(/\+.*$/, '');
|
|
20
|
+
const patchIndex = indexOrEnd(c, '-');
|
|
21
|
+
const arr = c.substring(0, patchIndex).split('.');
|
|
22
22
|
arr.push(c.substring(patchIndex + 1));
|
|
23
23
|
return arr;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
function parseSegment(v: string) {
|
|
27
|
-
|
|
27
|
+
const n = parseInt(v, 10);
|
|
28
28
|
return isNaN(n) ? v : n;
|
|
29
29
|
}
|
|
30
30
|
|
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.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { keyOfForceOverwrite,
|
|
1
|
+
import { keyOfForceOverwrite, keyOfSourceLanguage, valueOfForceOverwrite, valueOfSourceLanguage } from './helpers';
|
|
2
2
|
import { ForceOverwrite, SourceLanguage } from './common/enums';
|
|
3
3
|
|
|
4
4
|
describe('Piral CLI Command Helpers Module', () => {
|
|
@@ -13,12 +13,12 @@ describe('Piral CLI Command Helpers Module', () => {
|
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
it('correct value of keyOfPiletLanguage results in same key', () => {
|
|
16
|
-
const result =
|
|
16
|
+
const result = keyOfSourceLanguage(SourceLanguage.ts);
|
|
17
17
|
expect(result).toBe('ts');
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
it('incorrect value of keyOfPiletLanguage results in key for TS', () => {
|
|
21
|
-
const result =
|
|
21
|
+
const result = keyOfSourceLanguage(5);
|
|
22
22
|
expect(result).toBe('ts');
|
|
23
23
|
});
|
|
24
24
|
|
|
@@ -33,12 +33,12 @@ describe('Piral CLI Command Helpers Module', () => {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
it('correct key of valueOfPiletLanguage results in same value', () => {
|
|
36
|
-
const result =
|
|
36
|
+
const result = valueOfSourceLanguage('ts');
|
|
37
37
|
expect(result).toBe(SourceLanguage.ts);
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
it('incorrect key of valueOfPiletLanguage results in value for TS', () => {
|
|
41
|
-
const result =
|
|
41
|
+
const result = valueOfSourceLanguage('foo');
|
|
42
42
|
expect(result).toBe(SourceLanguage.ts);
|
|
43
43
|
});
|
|
44
44
|
});
|