piral-cli 0.15.3 → 0.15.4-beta.5013
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.d.ts +4 -0
- package/lib/apps/build-pilet.js +5 -1
- package/lib/apps/build-pilet.js.map +1 -1
- package/lib/apps/build-piral.d.ts +4 -0
- package/lib/apps/build-piral.js +4 -1
- package/lib/apps/build-piral.js.map +1 -1
- package/lib/apps/debug-piral.js +15 -5
- package/lib/apps/debug-piral.js.map +1 -1
- package/lib/apps/publish-pilet.js +1 -0
- package/lib/apps/publish-pilet.js.map +1 -1
- package/lib/apps/run-emulator-piral.js +1 -1
- package/lib/apps/run-emulator-piral.js.map +1 -1
- package/lib/build/run-build-pilet.js +3 -3
- package/lib/build/run-build-pilet.js.map +1 -1
- package/lib/build/run-build-piral.js +3 -3
- package/lib/build/run-build-piral.js.map +1 -1
- package/lib/commands.js +8 -0
- package/lib/commands.js.map +1 -1
- package/lib/common/envs.js +2 -1
- package/lib/common/envs.js.map +1 -1
- package/lib/common/importmap.js +33 -27
- package/lib/common/importmap.js.map +1 -1
- package/lib/common/npm.d.ts +2 -2
- package/lib/common/npm.js +44 -28
- package/lib/common/npm.js.map +1 -1
- package/lib/common/package.d.ts +2 -2
- package/lib/common/package.js +41 -35
- package/lib/common/package.js.map +1 -1
- package/lib/common/watcher.d.ts +9 -1
- package/lib/common/watcher.js +69 -12
- package/lib/common/watcher.js.map +1 -1
- package/lib/types/public.d.ts +2 -0
- package/package.json +2 -2
- package/src/apps/build-pilet.ts +10 -0
- package/src/apps/build-piral.ts +9 -0
- package/src/apps/debug-piral.ts +20 -4
- package/src/apps/publish-pilet.ts +1 -0
- package/src/apps/run-emulator-piral.ts +1 -1
- package/src/build/run-build-pilet.ts +3 -1
- package/src/build/run-build-piral.ts +3 -1
- package/src/commands.ts +8 -0
- package/src/common/envs.ts +2 -1
- package/src/common/importmap.ts +14 -12
- package/src/common/npm.test.ts +48 -29
- package/src/common/npm.ts +20 -12
- package/src/common/package.ts +20 -12
- package/src/common/watcher.ts +82 -17
- package/src/types/public.ts +2 -0
package/src/common/npm.ts
CHANGED
|
@@ -419,9 +419,15 @@ export async function getPackageName(root: string, name: string, type: PackageTy
|
|
|
419
419
|
|
|
420
420
|
if (!originalPackageJson.name) {
|
|
421
421
|
const p = resolve(process.cwd(), name);
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
422
|
+
|
|
423
|
+
try {
|
|
424
|
+
const s = createReadStream(p);
|
|
425
|
+
const i = await inspectPackage(s);
|
|
426
|
+
return i.name;
|
|
427
|
+
} catch (err) {
|
|
428
|
+
log('generalError_0002', `Could not open package tarball at "${p}": "${err}`);
|
|
429
|
+
return undefined;
|
|
430
|
+
}
|
|
425
431
|
}
|
|
426
432
|
|
|
427
433
|
return originalPackageJson.name;
|
|
@@ -460,20 +466,22 @@ export function getPackageVersion(
|
|
|
460
466
|
}
|
|
461
467
|
}
|
|
462
468
|
|
|
463
|
-
function getExternalsFrom(root: string, packageName: string): Array<string> | undefined {
|
|
469
|
+
async function getExternalsFrom(root: string, packageName: string): Promise<Array<string> | undefined> {
|
|
464
470
|
try {
|
|
465
471
|
const target = getModulePath(root, `${packageName}/package.json`);
|
|
466
|
-
|
|
472
|
+
const dir = dirname(target);
|
|
473
|
+
const { sharedDependencies } = await readJson(dir, 'package.json');
|
|
474
|
+
return sharedDependencies;
|
|
467
475
|
} catch (err) {
|
|
468
476
|
log('generalError_0002', `Could not get externals from "${packageName}": "${err}`);
|
|
469
477
|
return undefined;
|
|
470
478
|
}
|
|
471
479
|
}
|
|
472
480
|
|
|
473
|
-
function getCoreExternals(root: string, dependencies: Record<string, string>): Array<string
|
|
481
|
+
async function getCoreExternals(root: string, dependencies: Record<string, string>): Promise<Array<string>> {
|
|
474
482
|
for (const frameworkLib of frameworkLibs) {
|
|
475
483
|
if (dependencies[frameworkLib]) {
|
|
476
|
-
const deps = getExternalsFrom(root, frameworkLib);
|
|
484
|
+
const deps = await getExternalsFrom(root, frameworkLib);
|
|
477
485
|
|
|
478
486
|
if (deps) {
|
|
479
487
|
return deps;
|
|
@@ -485,17 +493,17 @@ function getCoreExternals(root: string, dependencies: Record<string, string>): A
|
|
|
485
493
|
return [];
|
|
486
494
|
}
|
|
487
495
|
|
|
488
|
-
export function makePiletExternals(
|
|
496
|
+
export async function makePiletExternals(
|
|
489
497
|
root: string,
|
|
490
498
|
dependencies: Record<string, string>,
|
|
491
499
|
fromEmulator: boolean,
|
|
492
500
|
piralInfo: any,
|
|
493
|
-
): Array<string
|
|
501
|
+
): Promise<Array<string>> {
|
|
494
502
|
if (fromEmulator) {
|
|
495
503
|
const { sharedDependencies = legacyCoreExternals } = piralInfo;
|
|
496
504
|
return sharedDependencies;
|
|
497
505
|
} else {
|
|
498
|
-
return getCoreExternals(root, dependencies);
|
|
506
|
+
return await getCoreExternals(root, dependencies);
|
|
499
507
|
}
|
|
500
508
|
}
|
|
501
509
|
|
|
@@ -522,7 +530,7 @@ export function mergeExternals(customExternals?: Array<string>, coreExternals: A
|
|
|
522
530
|
return coreExternals;
|
|
523
531
|
}
|
|
524
532
|
|
|
525
|
-
export function makeExternals(root: string, dependencies: Record<string, string>, externals: Array<string>) {
|
|
526
|
-
const coreExternals = getCoreExternals(root, dependencies);
|
|
533
|
+
export async function makeExternals(root: string, dependencies: Record<string, string>, externals: Array<string>) {
|
|
534
|
+
const coreExternals = await getCoreExternals(root, dependencies);
|
|
527
535
|
return mergeExternals(externals, coreExternals);
|
|
528
536
|
}
|
package/src/common/package.ts
CHANGED
|
@@ -167,13 +167,17 @@ export function getPiralPath(root: string, name: string) {
|
|
|
167
167
|
return dirname(path);
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
export function findPiralInstance(
|
|
170
|
+
export async function findPiralInstance(
|
|
171
|
+
proposedApp: string,
|
|
172
|
+
baseDir: string,
|
|
173
|
+
port: number,
|
|
174
|
+
): Promise<PiralInstancePackageData> {
|
|
171
175
|
const path = findPackageRoot(proposedApp, baseDir);
|
|
172
176
|
|
|
173
177
|
if (path) {
|
|
174
178
|
log('generalDebug_0003', `Following the app package in "${path}" ...`);
|
|
175
|
-
const appPackage = require(path);
|
|
176
179
|
const root = dirname(path);
|
|
180
|
+
const appPackage = await readJson(root, basename(path));
|
|
177
181
|
const relPath = appPackage && appPackage.app;
|
|
178
182
|
appPackage.app = relPath && resolve(root, relPath);
|
|
179
183
|
appPackage.root = root;
|
|
@@ -184,7 +188,7 @@ export function findPiralInstance(proposedApp: string, baseDir: string, port: nu
|
|
|
184
188
|
fail('appInstanceNotFound_0010', proposedApp);
|
|
185
189
|
}
|
|
186
190
|
|
|
187
|
-
export function findPiralInstances(
|
|
191
|
+
export async function findPiralInstances(
|
|
188
192
|
proposedApps: Array<string>,
|
|
189
193
|
piletPackage: PiletPackageData,
|
|
190
194
|
piletDefinition: undefined | PiletDefinition,
|
|
@@ -204,8 +208,10 @@ export function findPiralInstances(
|
|
|
204
208
|
}
|
|
205
209
|
|
|
206
210
|
if (proposedApps.length > 0) {
|
|
207
|
-
return
|
|
208
|
-
|
|
211
|
+
return Promise.all(
|
|
212
|
+
proposedApps.map((proposedApp) =>
|
|
213
|
+
findPiralInstance(proposedApp, baseDir, piletDefinition?.piralInstances?.[proposedApp]?.port ?? 0),
|
|
214
|
+
),
|
|
209
215
|
);
|
|
210
216
|
}
|
|
211
217
|
|
|
@@ -530,7 +536,9 @@ export async function findPackageVersion(rootPath: string, packageName: string |
|
|
|
530
536
|
log('generalDebug_0003', `Finding the version of "${packageName}" in "${rootPath}".`);
|
|
531
537
|
const moduleName = getModulePath(rootPath, pckg);
|
|
532
538
|
const packageJson = await findFile(moduleName, 'package.json');
|
|
533
|
-
|
|
539
|
+
const root = dirname(packageJson);
|
|
540
|
+
const { version } = await readJson(root, 'package.json');
|
|
541
|
+
return version;
|
|
534
542
|
} catch {}
|
|
535
543
|
}
|
|
536
544
|
|
|
@@ -555,7 +563,7 @@ export async function retrieveExternals(root: string, packageInfo: any): Promise
|
|
|
555
563
|
...packageInfo.dependencies,
|
|
556
564
|
};
|
|
557
565
|
const deps = packageInfo.pilets?.externals;
|
|
558
|
-
const externals = makeExternals(root, allDeps, deps);
|
|
566
|
+
const externals = await makeExternals(root, allDeps, deps);
|
|
559
567
|
return externals.map((ext) => ({
|
|
560
568
|
id: ext,
|
|
561
569
|
name: ext,
|
|
@@ -583,7 +591,7 @@ export async function retrievePiletsInfo(entryFile: string) {
|
|
|
583
591
|
}
|
|
584
592
|
|
|
585
593
|
const root = dirname(packageJson);
|
|
586
|
-
const packageInfo =
|
|
594
|
+
const packageInfo = await readJson(root, 'package.json');
|
|
587
595
|
const info = getPiletsInfo(packageInfo);
|
|
588
596
|
const externals = await retrieveExternals(root, packageInfo);
|
|
589
597
|
const dependencies = {
|
|
@@ -659,7 +667,7 @@ async function getPiletPackage(
|
|
|
659
667
|
...info.scripts,
|
|
660
668
|
}
|
|
661
669
|
: info.scripts;
|
|
662
|
-
const allExternals = makePiletExternals(root, piralDependencies, fromEmulator, piralInfo);
|
|
670
|
+
const allExternals = await makePiletExternals(root, piralDependencies, fromEmulator, piralInfo);
|
|
663
671
|
const devDependencies: Record<string, string> = {
|
|
664
672
|
...Object.keys(typeDependencies).reduce((deps, name) => {
|
|
665
673
|
deps[name] = piralDependencies[name] || typeDependencies[name];
|
|
@@ -757,9 +765,9 @@ export async function retrievePiletData(target: string, app?: string) {
|
|
|
757
765
|
const piletJson = await findFile(target, 'pilet.json');
|
|
758
766
|
const proposedRoot = piletJson ? dirname(piletJson) : target;
|
|
759
767
|
const root = await findPiletRoot(proposedRoot);
|
|
760
|
-
const piletPackage =
|
|
761
|
-
const piletDefinition = piletJson &&
|
|
762
|
-
const appPackages = findPiralInstances(app && [app], piletPackage, piletDefinition, target);
|
|
768
|
+
const piletPackage = await readJson(root, 'package.json');
|
|
769
|
+
const piletDefinition = piletJson && await readJson(proposedRoot, 'pilet.json');
|
|
770
|
+
const appPackages = await findPiralInstances(app && [app], piletPackage, piletDefinition, target);
|
|
763
771
|
const apps: Array<AppDefinition> = [];
|
|
764
772
|
|
|
765
773
|
if (appPackages.length === 0) {
|
package/src/common/watcher.ts
CHANGED
|
@@ -1,24 +1,89 @@
|
|
|
1
|
+
import { watch, existsSync } from 'fs';
|
|
2
|
+
|
|
3
|
+
export interface WatcherRef<T> {
|
|
4
|
+
end: Promise<void>;
|
|
5
|
+
data: T;
|
|
6
|
+
onTrigger(cb: () => void): void;
|
|
7
|
+
}
|
|
8
|
+
|
|
1
9
|
export interface WatcherContext {
|
|
2
10
|
onClean(dispose: () => void): void;
|
|
3
11
|
watch(file: string): void;
|
|
12
|
+
dependOn<T>(ref: WatcherRef<T>): void;
|
|
13
|
+
close(): void;
|
|
14
|
+
status: 'initial' | 'reoccuring';
|
|
4
15
|
}
|
|
5
16
|
|
|
6
|
-
export function watcherTask(cb: (watcherContext: WatcherContext) => Promise<
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
export function watcherTask<T = void>(cb: (watcherContext: WatcherContext) => Promise<T>) {
|
|
18
|
+
let running = Promise.resolve();
|
|
19
|
+
let pending = false;
|
|
20
|
+
let notify = () => {};
|
|
21
|
+
|
|
22
|
+
const disposers: Array<() => void> = [];
|
|
23
|
+
const triggers: Array<() => void> = [];
|
|
24
|
+
const end = new Promise<void>(resolve => {
|
|
25
|
+
notify = resolve;
|
|
26
|
+
});
|
|
27
|
+
const ref: WatcherRef<T> = {
|
|
28
|
+
data: undefined,
|
|
29
|
+
onTrigger(cb) {
|
|
30
|
+
triggers.push(cb);
|
|
31
|
+
},
|
|
32
|
+
end,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const reRun = async () => {
|
|
36
|
+
if (!pending) {
|
|
37
|
+
pending = true;
|
|
38
|
+
await running;
|
|
39
|
+
disposers.splice(0, disposers.length).forEach((dispose) => {
|
|
40
|
+
dispose();
|
|
41
|
+
});
|
|
42
|
+
pending = false;
|
|
43
|
+
context.status = 'reoccuring';
|
|
44
|
+
await run();
|
|
45
|
+
|
|
46
|
+
triggers.splice(0, triggers.length).forEach((trigger) => {
|
|
47
|
+
trigger();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const context: WatcherContext = {
|
|
53
|
+
onClean(dispose) {
|
|
54
|
+
disposers.push(dispose);
|
|
55
|
+
},
|
|
56
|
+
watch(file) {
|
|
57
|
+
if (existsSync(file)) {
|
|
58
|
+
const watcher = watch(
|
|
59
|
+
file,
|
|
60
|
+
{
|
|
61
|
+
persistent: false,
|
|
62
|
+
},
|
|
63
|
+
reRun,
|
|
64
|
+
);
|
|
65
|
+
disposers.push(() => watcher.close());
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
dependOn(anotherRef) {
|
|
69
|
+
anotherRef.onTrigger(reRun);
|
|
70
|
+
},
|
|
71
|
+
close() {
|
|
72
|
+
cb = () => Promise.resolve(undefined);
|
|
73
|
+
reRun().then(notify);
|
|
74
|
+
},
|
|
75
|
+
status: 'initial',
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const run = async () => {
|
|
79
|
+
running = cb(context).then((data) => {
|
|
80
|
+
ref.data = data;
|
|
81
|
+
});
|
|
82
|
+
await running;
|
|
83
|
+
return ref;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return new Promise<WatcherRef<T>>((resolve, reject) => {
|
|
87
|
+
run().then(resolve, reject);
|
|
23
88
|
});
|
|
24
89
|
}
|
package/src/types/public.ts
CHANGED
|
@@ -90,6 +90,7 @@ export interface BuildPiralParameters extends BaseBundleParameters {
|
|
|
90
90
|
emulator: boolean;
|
|
91
91
|
standalone: boolean;
|
|
92
92
|
sourceMaps: boolean;
|
|
93
|
+
watch: boolean;
|
|
93
94
|
contentHash: boolean;
|
|
94
95
|
minify: boolean;
|
|
95
96
|
externals: Array<string>;
|
|
@@ -116,6 +117,7 @@ export interface DebugPiletParameters extends BaseBundleParameters {
|
|
|
116
117
|
export interface BuildPiletParameters extends BaseBundleParameters {
|
|
117
118
|
piralInstances: Array<string>;
|
|
118
119
|
sourceMaps: boolean;
|
|
120
|
+
watch: boolean;
|
|
119
121
|
contentHash: boolean;
|
|
120
122
|
minify: boolean;
|
|
121
123
|
externals: Array<string>;
|