piral-cli 0.15.0-alpha.4041 → 0.15.0-alpha.4231
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/build-pilet.js.map +1 -1
- package/lib/apps/build-piral.js.map +1 -1
- package/lib/apps/debug-pilet.js.map +1 -1
- package/lib/apps/debug-piral.js.map +1 -1
- package/lib/apps/index.js +5 -1
- package/lib/apps/index.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 +5 -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/build/bundler-calls.d.ts +1 -1
- package/lib/build/run-build-pilet.js.map +1 -1
- package/lib/build/run-build-piral.js.map +1 -1
- package/lib/build/run-debug-mono-piral.js +1 -1
- package/lib/build/run-debug-mono-piral.js.map +1 -1
- package/lib/build/run-debug-pilet.js.map +1 -1
- package/lib/build/run-debug-piral.js.map +1 -1
- package/lib/bundler.js +1 -1
- package/lib/bundler.js.map +1 -1
- package/lib/commands.js +8 -0
- 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 +36 -9
- package/lib/common/clients/npm.js.map +1 -1
- package/lib/common/clients/pnpm.d.ts +4 -0
- package/lib/common/clients/pnpm.js +41 -1
- 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 +44 -4
- package/lib/common/clients/yarn.js.map +1 -1
- package/lib/common/config.js.map +1 -1
- package/lib/common/constants.d.ts +1 -1
- package/lib/common/constants.js +1 -1
- package/lib/common/constants.js.map +1 -1
- package/lib/common/declaration.js +14 -10
- 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 +1 -1
- package/lib/common/http.js +12 -7
- package/lib/common/http.js.map +1 -1
- package/lib/common/importmap.js +7 -16
- package/lib/common/importmap.js.map +1 -1
- package/lib/common/index.js +5 -1
- package/lib/common/index.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/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 +31 -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/npm.d.ts +11 -16
- package/lib/common/npm.js +165 -158
- 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 -7
- package/lib/common/package.js +26 -28
- package/lib/common/package.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 +2380 -470
- package/lib/helpers.d.ts +1 -1
- package/lib/helpers.js +1 -1
- package/lib/helpers.js.map +1 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/injectors/pilet.d.ts +1 -0
- package/lib/injectors/pilet.js +7 -7
- package/lib/injectors/pilet.js.map +1 -1
- package/lib/messages.d.ts +1 -1
- package/lib/messages.js +5 -1
- 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 +7 -2
- package/lib/release.js.map +1 -1
- package/lib/types/common.d.ts +1 -1
- package/lib/types/index.js +5 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/internal.d.ts +9 -1
- package/lib/types/public.d.ts +2 -2
- package/package.json +5 -3
- package/src/apps/new-pilet.ts +9 -14
- package/src/apps/new-piral.ts +9 -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/build/bundler-calls.ts +1 -1
- package/src/build/run-build-pilet.ts +1 -1
- package/src/build/run-build-piral.ts +1 -1
- package/src/build/run-debug-mono-piral.ts +2 -2
- package/src/build/run-debug-pilet.ts +1 -1
- package/src/build/run-debug-piral.ts +1 -1
- package/src/bundler.test.ts +1 -1
- package/src/bundler.ts +2 -2
- package/src/commands.ts +8 -0
- 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 +31 -6
- package/src/common/clients/pnpm.ts +37 -0
- package/src/common/clients/rush.ts +111 -0
- package/src/common/clients/yarn.ts +40 -3
- package/src/common/config.ts +3 -3
- package/src/common/constants.ts +1 -1
- package/src/common/declaration.ts +17 -10
- package/src/common/emulator.ts +3 -3
- package/src/common/http.ts +20 -6
- package/src/common/importmap.ts +7 -15
- package/src/common/info.ts +6 -1
- package/src/common/inspect.ts +2 -1
- package/src/common/interactive.test.ts +3 -0
- package/src/common/interactive.ts +48 -1
- package/src/common/io.ts +1 -1
- package/src/common/npm.test.ts +122 -76
- package/src/common/npm.ts +177 -152
- package/src/common/pack.test.ts +1 -1
- package/src/common/pack.ts +2 -2
- package/src/common/package.test.ts +1 -14
- package/src/common/package.ts +31 -29
- package/src/common/scaffold.ts +7 -2
- package/src/common/version.ts +4 -4
- package/src/external/index.ts +2 -1
- package/src/helpers.ts +2 -2
- package/src/injectors/pilet.ts +9 -8
- package/src/messages.ts +6 -2
- package/src/plugin.ts +34 -5
- package/src/release.ts +10 -2
- package/src/types/common.ts +1 -1
- package/src/types/internal.ts +6 -1
- package/src/types/public.ts +2 -2
package/src/common/npm.ts
CHANGED
|
@@ -1,65 +1,60 @@
|
|
|
1
|
-
import { resolve, relative, dirname } from 'path';
|
|
2
|
-
import { createReadStream, existsSync
|
|
1
|
+
import { resolve, relative, dirname, isAbsolute, sep } from 'path';
|
|
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) {
|
|
@@ -354,12 +319,63 @@ export async function getCurrentPackageDetails(
|
|
|
354
319
|
return [combinePackageRef(sourceName, desired, 'registry'), desired];
|
|
355
320
|
}
|
|
356
321
|
|
|
322
|
+
function tryResolve(...args: Parameters<typeof require.resolve>) {
|
|
323
|
+
try {
|
|
324
|
+
return require.resolve(...args);
|
|
325
|
+
} catch {
|
|
326
|
+
return undefined;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export function tryResolvePackage(name: string, baseDir: string = undefined) {
|
|
331
|
+
let path = baseDir ? tryResolve(name, { paths: [baseDir] }) : tryResolve(name);
|
|
332
|
+
const root = baseDir || process.cwd();
|
|
333
|
+
|
|
334
|
+
if (!path) {
|
|
335
|
+
if (name.startsWith('.')) {
|
|
336
|
+
path = resolve(root, name);
|
|
337
|
+
} else if (isAbsolute(name)) {
|
|
338
|
+
path = name;
|
|
339
|
+
} else if (name.includes('/', name.startsWith('@') ? name.indexOf('/') + 1 : 0)) {
|
|
340
|
+
const parts = name.split('/');
|
|
341
|
+
const mainPart = name.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
|
|
342
|
+
const mainPath = baseDir ? tryResolve(mainPart, { paths: [baseDir] }) : tryResolve(mainPart);
|
|
343
|
+
const searchStr = `${sep}${mainPart.replace('/', sep)}${sep}`;
|
|
344
|
+
|
|
345
|
+
if (mainPath?.includes(searchStr)) {
|
|
346
|
+
const rest = name.startsWith('@') ? parts.slice(2) : parts.slice(1);
|
|
347
|
+
path = mainPath.substring(0, mainPath.indexOf(searchStr) + searchStr.length) + rest.join(sep);
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
path = resolve(root, 'node_modules', name);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (!existsSync(path)) {
|
|
354
|
+
path = `${path}.js`;
|
|
355
|
+
|
|
356
|
+
if (!existsSync(path)) {
|
|
357
|
+
path = undefined;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (!path) {
|
|
363
|
+
log('generalDebug_0003', `Could not resolve the package "${name}" in "${root}".`);
|
|
364
|
+
} else {
|
|
365
|
+
log('generalVerbose_0004', `Resolved the package "${name}" (from "${root}") to be "${path}".`);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return path;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export function findPackageRoot(pck: string, baseDir: string = undefined) {
|
|
372
|
+
return tryResolvePackage(`${pck}/package.json`, baseDir);
|
|
373
|
+
}
|
|
374
|
+
|
|
357
375
|
export function isLinkedPackage(name: string, type: PackageType, hadVersion: boolean) {
|
|
358
376
|
if (type === 'registry' && !hadVersion) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
return true;
|
|
362
|
-
} catch {}
|
|
377
|
+
const root = findPackageRoot(name);
|
|
378
|
+
return typeof root === 'string';
|
|
363
379
|
}
|
|
364
380
|
|
|
365
381
|
return false;
|
|
@@ -367,7 +383,8 @@ export function isLinkedPackage(name: string, type: PackageType, hadVersion: boo
|
|
|
367
383
|
|
|
368
384
|
export function combinePackageRef(name: string, version: string, type: PackageType) {
|
|
369
385
|
if (type === 'registry') {
|
|
370
|
-
|
|
386
|
+
const tag = version || 'latest';
|
|
387
|
+
return `${name}@${tag}`;
|
|
371
388
|
}
|
|
372
389
|
|
|
373
390
|
return name;
|
|
@@ -421,18 +438,22 @@ export function getPackageVersion(
|
|
|
421
438
|
}
|
|
422
439
|
}
|
|
423
440
|
|
|
424
|
-
function getExternalsFrom(packageName: string): Array<string> | undefined {
|
|
441
|
+
function getExternalsFrom(root: string, packageName: string): Array<string> | undefined {
|
|
425
442
|
try {
|
|
426
|
-
|
|
427
|
-
|
|
443
|
+
const target = require.resolve(`${packageName}/package.json`, {
|
|
444
|
+
paths: [root],
|
|
445
|
+
});
|
|
446
|
+
return require(target).sharedDependencies;
|
|
447
|
+
} catch (err) {
|
|
448
|
+
log('generalError_0002', `Could not get externals from "${packageName}": "${err}`);
|
|
428
449
|
return undefined;
|
|
429
450
|
}
|
|
430
451
|
}
|
|
431
452
|
|
|
432
|
-
function getCoreExternals(dependencies: Record<string, string>): Array<string> {
|
|
453
|
+
function getCoreExternals(root: string, dependencies: Record<string, string>): Array<string> {
|
|
433
454
|
for (const frameworkLib of frameworkLibs) {
|
|
434
455
|
if (dependencies[frameworkLib]) {
|
|
435
|
-
const deps = getExternalsFrom(frameworkLib);
|
|
456
|
+
const deps = getExternalsFrom(root, frameworkLib);
|
|
436
457
|
|
|
437
458
|
if (deps) {
|
|
438
459
|
return deps;
|
|
@@ -445,24 +466,23 @@ function getCoreExternals(dependencies: Record<string, string>): Array<string> {
|
|
|
445
466
|
}
|
|
446
467
|
|
|
447
468
|
export function makePiletExternals(
|
|
469
|
+
root: string,
|
|
448
470
|
dependencies: Record<string, string>,
|
|
449
471
|
externals: Array<string>,
|
|
450
472
|
fromEmulator: boolean,
|
|
451
473
|
piralInfo: any,
|
|
452
|
-
) {
|
|
474
|
+
): Array<string> {
|
|
453
475
|
if (fromEmulator) {
|
|
454
|
-
const { sharedDependencies =
|
|
476
|
+
const { sharedDependencies = mergeExternals(externals, legacyCoreExternals) } = piralInfo;
|
|
455
477
|
return sharedDependencies;
|
|
456
478
|
} else {
|
|
457
|
-
return makeExternals(dependencies, externals);
|
|
479
|
+
return makeExternals(root, dependencies, externals);
|
|
458
480
|
}
|
|
459
481
|
}
|
|
460
482
|
|
|
461
|
-
export function
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
if (externals && Array.isArray(externals)) {
|
|
465
|
-
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>]>(
|
|
466
486
|
(prev, curr) => {
|
|
467
487
|
if (typeof curr === 'string') {
|
|
468
488
|
if (curr.startsWith('!')) {
|
|
@@ -482,3 +502,8 @@ export function makeExternals(dependencies: Record<string, string>, externals?:
|
|
|
482
502
|
|
|
483
503
|
return coreExternals;
|
|
484
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}".`);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { findPackageVersion, findPackageRoot, getPiralPackage, getPiletsInfo, retrievePiletData } from './package';
|
|
1
|
+
import { findPackageVersion, getPiralPackage, getPiletsInfo, retrievePiletData } from './package';
|
|
3
2
|
import { cliVersion } from './info';
|
|
4
3
|
import { SourceLanguage } from './enums';
|
|
5
4
|
|
|
@@ -14,18 +13,6 @@ describe('CLI package module', () => {
|
|
|
14
13
|
expect(version).toBe('latest');
|
|
15
14
|
});
|
|
16
15
|
|
|
17
|
-
it('findPackageRoot correctly resolves the package root of parcel-bundler', () => {
|
|
18
|
-
const dir = process.cwd();
|
|
19
|
-
const version = findPackageRoot('webpack', dir);
|
|
20
|
-
expect(version).toBe(resolve(dir, 'node_modules', 'webpack', 'package.json'));
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('findPackageRoot returns undefined for invalid package', () => {
|
|
24
|
-
const dir = process.cwd();
|
|
25
|
-
const version = findPackageRoot('foo-bar-not-exist', dir);
|
|
26
|
-
expect(version).toBeUndefined();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
16
|
it('getPiletsInfo returns pilets information about provided piralInfo', () => {
|
|
30
17
|
const emptyPiletsInfo = {
|
|
31
18
|
files: [],
|