piral-cli 0.15.0-beta.4815 → 0.15.0-beta.4820
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 +46 -56
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/new-piral.js +1 -1
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/common/clients/pnpm.js +1 -1
- package/lib/common/clients/pnpm.js.map +1 -1
- package/lib/common/compatibility.js +2 -1
- package/lib/common/compatibility.js.map +1 -1
- package/lib/common/declaration.js +19 -5
- package/lib/common/declaration.js.map +1 -1
- package/lib/common/importmap.js +27 -15
- package/lib/common/importmap.js.map +1 -1
- package/lib/common/io.d.ts +1 -1
- package/lib/common/io.js +11 -8
- package/lib/common/io.js.map +1 -1
- package/lib/common/log.js +3 -2
- package/lib/common/log.js.map +1 -1
- package/lib/common/npm.js +1 -28
- package/lib/common/npm.js.map +1 -1
- package/lib/common/package.d.ts +2 -1
- package/lib/common/package.js +20 -15
- package/lib/common/package.js.map +1 -1
- package/lib/messages.d.ts +1 -1
- package/lib/messages.js +12 -8
- package/lib/messages.js.map +1 -1
- package/package.json +3 -3
- package/src/apps/new-pilet.ts +64 -69
- package/src/apps/new-piral.ts +1 -1
- package/src/common/clients/pnpm.ts +1 -1
- package/src/common/compatibility.ts +2 -1
- package/src/common/declaration.ts +22 -5
- package/src/common/importmap.ts +33 -19
- package/src/common/io.ts +18 -10
- package/src/common/log.ts +3 -2
- package/src/common/npm.ts +1 -29
- package/src/common/package.ts +23 -15
- package/src/messages.ts +12 -8
package/src/common/importmap.ts
CHANGED
|
@@ -38,7 +38,27 @@ function getLocalDependencyVersion(
|
|
|
38
38
|
return [details.version, details.version];
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
function getInheritedDependencies(inheritedImport: string, dir: string): Promise<Array<SharedDependency>> {
|
|
42
|
+
const packageJson = tryResolvePackage(`${inheritedImport}/package.json`, dir);
|
|
43
|
+
|
|
44
|
+
if (inheritedImport) {
|
|
45
|
+
const packageDir = dirname(packageJson);
|
|
46
|
+
const packageDetails = require(packageJson);
|
|
47
|
+
return readImportmap(packageDir, packageDetails, true);
|
|
48
|
+
} else {
|
|
49
|
+
const directImportmap = tryResolvePackage(inheritedImport, dir);
|
|
50
|
+
|
|
51
|
+
if (directImportmap) {
|
|
52
|
+
const content = require(directImportmap);
|
|
53
|
+
const baseDir = dirname(directImportmap);
|
|
54
|
+
return resolveImportmap(baseDir, content);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return Promise.resolve([]);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function resolveImportmap(dir: string, importmap: Importmap): Promise<Array<SharedDependency>> {
|
|
42
62
|
const dependencies: Array<SharedDependency> = [];
|
|
43
63
|
const sharedImports = importmap?.imports;
|
|
44
64
|
const inheritedImports = importmap?.inherit;
|
|
@@ -142,24 +162,18 @@ async function resolveImportmap(dir: string, importmap: Importmap) {
|
|
|
142
162
|
|
|
143
163
|
if (Array.isArray(inheritedImports)) {
|
|
144
164
|
for (const inheritedImport of inheritedImports) {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
if (packageJson) {
|
|
148
|
-
const packageDir = dirname(packageJson);
|
|
149
|
-
const packageDetails = require(packageJson);
|
|
150
|
-
const otherDependencies = await readImportmap(packageDir, packageDetails, true);
|
|
165
|
+
const otherDependencies = await getInheritedDependencies(inheritedImport, dir);
|
|
151
166
|
|
|
152
|
-
|
|
153
|
-
|
|
167
|
+
for (const dependency of otherDependencies) {
|
|
168
|
+
const entry = dependencies.find((dep) => dep.name === dependency.name);
|
|
154
169
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
170
|
+
if (!entry) {
|
|
171
|
+
dependencies.push({
|
|
172
|
+
...dependency,
|
|
173
|
+
parents: [inheritedImport],
|
|
174
|
+
});
|
|
175
|
+
} else if (Array.isArray(entry.parents)) {
|
|
176
|
+
entry.parents.push(inheritedImport);
|
|
163
177
|
}
|
|
164
178
|
}
|
|
165
179
|
}
|
|
@@ -184,7 +198,7 @@ export async function readImportmap(
|
|
|
184
198
|
}
|
|
185
199
|
|
|
186
200
|
const baseDir = dirname(resolve(dir, importmap));
|
|
187
|
-
return resolveImportmap(baseDir, content);
|
|
201
|
+
return await resolveImportmap(baseDir, content);
|
|
188
202
|
} else if (typeof importmap === 'undefined' && inherited) {
|
|
189
203
|
// Fall back to sharedDependencies or pilets.external if available
|
|
190
204
|
const shared: Array<string> = packageDetails.sharedDependencies ?? packageDetails.pilets?.externals;
|
|
@@ -201,5 +215,5 @@ export async function readImportmap(
|
|
|
201
215
|
}
|
|
202
216
|
}
|
|
203
217
|
|
|
204
|
-
return resolveImportmap(dir, importmap);
|
|
218
|
+
return await resolveImportmap(dir, importmap);
|
|
205
219
|
}
|
package/src/common/io.ts
CHANGED
|
@@ -141,20 +141,28 @@ export function getFileNames(target: string) {
|
|
|
141
141
|
});
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
export async function findFile(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
144
|
+
export async function findFile(
|
|
145
|
+
topDir: string,
|
|
146
|
+
fileName: string | Array<string>,
|
|
147
|
+
stopDir = resolve(topDir, '/'),
|
|
148
|
+
): Promise<string> {
|
|
149
|
+
const fileNames = Array.isArray(fileName) ? fileName : [fileName];
|
|
150
|
+
|
|
151
|
+
for (const fn of fileNames) {
|
|
152
|
+
const path = join(topDir, fn);
|
|
153
|
+
const exists = await checkExists(path);
|
|
154
|
+
|
|
155
|
+
if (exists) {
|
|
156
|
+
return path;
|
|
152
157
|
}
|
|
158
|
+
}
|
|
153
159
|
|
|
154
|
-
|
|
160
|
+
if (topDir !== stopDir) {
|
|
161
|
+
const parentDir = resolve(topDir, '..');
|
|
162
|
+
return await findFile(parentDir, fileNames, stopDir);
|
|
155
163
|
}
|
|
156
164
|
|
|
157
|
-
return
|
|
165
|
+
return undefined;
|
|
158
166
|
}
|
|
159
167
|
|
|
160
168
|
interface AnyPattern {
|
package/src/common/log.ts
CHANGED
|
@@ -62,8 +62,9 @@ export function logFail(message: string, ...args: Array<string | number | boolea
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export function progress(message: string, ...args: Array<string | number | boolean>) {
|
|
65
|
-
|
|
66
|
-
instance.start(
|
|
65
|
+
const msg = format(message, ...args)
|
|
66
|
+
instance.start(msg);
|
|
67
|
+
currentProgress = msg;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
export function logReset() {
|
package/src/common/npm.ts
CHANGED
|
@@ -360,37 +360,9 @@ function tryResolve(packageName: string, baseDir = process.cwd()) {
|
|
|
360
360
|
}
|
|
361
361
|
|
|
362
362
|
export function tryResolvePackage(name: string, baseDir: string = undefined) {
|
|
363
|
-
|
|
363
|
+
const path = baseDir ? tryResolve(name, baseDir) : tryResolve(name);
|
|
364
364
|
const root = baseDir || process.cwd();
|
|
365
365
|
|
|
366
|
-
if (!path) {
|
|
367
|
-
if (name.startsWith('.')) {
|
|
368
|
-
path = resolve(root, name);
|
|
369
|
-
} else if (isAbsolute(name)) {
|
|
370
|
-
path = name;
|
|
371
|
-
} else if (name.includes('/', name.startsWith('@') ? name.indexOf('/') + 1 : 0)) {
|
|
372
|
-
const parts = name.split('/');
|
|
373
|
-
const mainPart = name.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
|
|
374
|
-
const mainPath = baseDir ? tryResolve(mainPart, baseDir) : tryResolve(mainPart);
|
|
375
|
-
const searchStr = `${sep}${mainPart.replace('/', sep)}${sep}`;
|
|
376
|
-
|
|
377
|
-
if (mainPath?.includes(searchStr)) {
|
|
378
|
-
const rest = name.startsWith('@') ? parts.slice(2) : parts.slice(1);
|
|
379
|
-
path = mainPath.substring(0, mainPath.indexOf(searchStr) + searchStr.length) + rest.join(sep);
|
|
380
|
-
}
|
|
381
|
-
} else {
|
|
382
|
-
path = resolve(root, 'node_modules', name);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
if (!existsSync(path)) {
|
|
386
|
-
path = `${path}.js`;
|
|
387
|
-
|
|
388
|
-
if (!existsSync(path)) {
|
|
389
|
-
path = undefined;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
366
|
if (!path) {
|
|
395
367
|
log('generalDebug_0003', `Could not resolve the package "${name}" in "${root}".`);
|
|
396
368
|
} else {
|
package/src/common/package.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { getHash, checkIsDirectory, matchFiles } from './io';
|
|
|
11
11
|
import { readJson, copy, updateExistingJson, findFile, checkExists } from './io';
|
|
12
12
|
import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath } from './npm';
|
|
13
13
|
import { makePiletExternals, makeExternals, findPackageRoot, findSpecificVersion } from './npm';
|
|
14
|
+
import { getModulePath } from '../external';
|
|
14
15
|
import {
|
|
15
16
|
filesTar,
|
|
16
17
|
filesOnceTar,
|
|
@@ -18,8 +19,8 @@ import {
|
|
|
18
19
|
bundlerNames,
|
|
19
20
|
piralJsonSchemaUrl,
|
|
20
21
|
piletJsonSchemaUrl,
|
|
22
|
+
frameworkLibs,
|
|
21
23
|
} from './constants';
|
|
22
|
-
import { getModulePath } from '../external';
|
|
23
24
|
import {
|
|
24
25
|
SourceLanguage,
|
|
25
26
|
Framework,
|
|
@@ -496,16 +497,20 @@ export function findDependencyVersion(
|
|
|
496
497
|
return findPackageVersion(rootPath, packageName);
|
|
497
498
|
}
|
|
498
499
|
|
|
499
|
-
export async function findPackageVersion(rootPath: string, packageName: string): Promise<string> {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
500
|
+
export async function findPackageVersion(rootPath: string, packageName: string | Array<string>): Promise<string> {
|
|
501
|
+
const packages = Array.isArray(packageName) ? packageName : [packageName];
|
|
502
|
+
|
|
503
|
+
for (const pckg of packages) {
|
|
504
|
+
try {
|
|
505
|
+
log('generalDebug_0003', `Finding the version of "${packageName}" in "${rootPath}".`);
|
|
506
|
+
const moduleName = getModulePath(rootPath, pckg);
|
|
507
|
+
const packageJson = await findFile(moduleName, 'package.json');
|
|
508
|
+
return require(packageJson).version;
|
|
509
|
+
} catch {}
|
|
508
510
|
}
|
|
511
|
+
|
|
512
|
+
log('cannotResolveDependency_0053', packages, rootPath);
|
|
513
|
+
return 'latest';
|
|
509
514
|
}
|
|
510
515
|
|
|
511
516
|
export async function retrieveExternals(root: string, packageInfo: any) {
|
|
@@ -540,17 +545,20 @@ export async function retrievePiletsInfo(entryFile: string) {
|
|
|
540
545
|
const packageInfo = require(packageJson);
|
|
541
546
|
const info = getPiletsInfo(packageInfo);
|
|
542
547
|
const externals = await retrieveExternals(root, packageInfo);
|
|
548
|
+
const dependencies = {
|
|
549
|
+
std: packageInfo.dependencies || {},
|
|
550
|
+
dev: packageInfo.devDependencies || {},
|
|
551
|
+
peer: packageInfo.peerDependencies || {},
|
|
552
|
+
};
|
|
553
|
+
const framework = frameworkLibs.find((lib) => lib in dependencies.std || lib in dependencies.dev);
|
|
543
554
|
|
|
544
555
|
return {
|
|
545
556
|
...info,
|
|
546
557
|
externals,
|
|
547
558
|
name: packageInfo.name,
|
|
548
559
|
version: packageInfo.version,
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
dev: packageInfo.devDependencies || {},
|
|
552
|
-
peer: packageInfo.peerDependencies || {},
|
|
553
|
-
},
|
|
560
|
+
framework,
|
|
561
|
+
dependencies,
|
|
554
562
|
scripts: packageInfo.scripts,
|
|
555
563
|
ignored: checkArrayOrUndefined(packageInfo, 'preservedDependencies'),
|
|
556
564
|
root,
|
package/src/messages.ts
CHANGED
|
@@ -1231,8 +1231,12 @@ export function cannotResolveVersion_0052(name: string): QuickMessage {
|
|
|
1231
1231
|
* }
|
|
1232
1232
|
* ```
|
|
1233
1233
|
*/
|
|
1234
|
-
export function cannotResolveDependency_0053(
|
|
1235
|
-
return [
|
|
1234
|
+
export function cannotResolveDependency_0053(names: Array<string>, rootDir: string): QuickMessage {
|
|
1235
|
+
return [
|
|
1236
|
+
LogLevels.warning,
|
|
1237
|
+
'0053',
|
|
1238
|
+
`Could not resolve any package (tried "${names.join('", "')}") from "${rootDir}". Taking "latest" version.`,
|
|
1239
|
+
];
|
|
1236
1240
|
}
|
|
1237
1241
|
|
|
1238
1242
|
/**
|
|
@@ -2387,7 +2391,11 @@ export function publishFeedMissingUrl_0115(): QuickMessage {
|
|
|
2387
2391
|
* ```
|
|
2388
2392
|
*/
|
|
2389
2393
|
export function publishFeedMissingVersion_0116(): QuickMessage {
|
|
2390
|
-
return [
|
|
2394
|
+
return [
|
|
2395
|
+
LogLevels.error,
|
|
2396
|
+
'0116',
|
|
2397
|
+
`The "feed" provider requires either a "--opts.version" argument or a package.json with a version.`,
|
|
2398
|
+
];
|
|
2391
2399
|
}
|
|
2392
2400
|
|
|
2393
2401
|
/**
|
|
@@ -2624,11 +2632,7 @@ export function bundlerUnspecified_0175(available: Array<string>): QuickMessage
|
|
|
2624
2632
|
* ```
|
|
2625
2633
|
*/
|
|
2626
2634
|
export function bundlerNotInstalled_0176(): QuickMessage {
|
|
2627
|
-
return [
|
|
2628
|
-
LogLevels.warning,
|
|
2629
|
-
'0176',
|
|
2630
|
-
`Installing default bundler since no bundler has been found.`,
|
|
2631
|
-
];
|
|
2635
|
+
return [LogLevels.warning, '0176', `Installing default bundler since no bundler has been found.`];
|
|
2632
2636
|
}
|
|
2633
2637
|
|
|
2634
2638
|
/**
|