piral-cli 1.4.0-beta.6250 → 1.4.0-beta.6252
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/api.js +8 -17
- package/lib/api.js.map +1 -1
- package/lib/apps/add-piral-instance-pilet.js +20 -31
- package/lib/apps/add-piral-instance-pilet.js.map +1 -1
- package/lib/apps/build-pilet.js +139 -147
- package/lib/apps/build-pilet.js.map +1 -1
- package/lib/apps/build-piral.js +130 -144
- package/lib/apps/build-piral.js.map +1 -1
- package/lib/apps/debug-pilet.js +107 -119
- package/lib/apps/debug-pilet.js.map +1 -1
- package/lib/apps/debug-piral.js +62 -70
- package/lib/apps/debug-piral.js.map +1 -1
- package/lib/apps/declaration-piral.js +6 -17
- package/lib/apps/declaration-piral.js.map +1 -1
- package/lib/apps/new-pilet.js +71 -82
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/new-piral.js +42 -53
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/apps/pack-pilet.js +7 -18
- package/lib/apps/pack-pilet.js.map +1 -1
- package/lib/apps/publish-pilet.js +127 -141
- package/lib/apps/publish-pilet.js.map +1 -1
- package/lib/apps/publish-piral.js +48 -63
- package/lib/apps/publish-piral.js.map +1 -1
- package/lib/apps/remove-piral-instance-pilet.js +30 -35
- package/lib/apps/remove-piral-instance-pilet.js.map +1 -1
- package/lib/apps/run-emulator-piral.js +49 -61
- package/lib/apps/run-emulator-piral.js.map +1 -1
- package/lib/apps/upgrade-pilet.js +64 -76
- package/lib/apps/upgrade-pilet.js.map +1 -1
- package/lib/apps/upgrade-piral.js +31 -43
- package/lib/apps/upgrade-piral.js.map +1 -1
- package/lib/apps/validate-pilet.js +34 -45
- package/lib/apps/validate-pilet.js.map +1 -1
- package/lib/apps/validate-piral.js +29 -51
- package/lib/apps/validate-piral.js.map +1 -1
- package/lib/build/bundler-calls.js +12 -3
- package/lib/build/bundler-calls.js.map +1 -1
- package/lib/build/run-build-pilet.js +5 -14
- package/lib/build/run-build-pilet.js.map +1 -1
- package/lib/build/run-build-piral.js +5 -14
- package/lib/build/run-build-piral.js.map +1 -1
- package/lib/build/run-debug-mono-piral.js +5 -14
- package/lib/build/run-debug-mono-piral.js.map +1 -1
- package/lib/build/run-debug-pilet.js +5 -14
- package/lib/build/run-debug-pilet.js.map +1 -1
- package/lib/build/run-debug-piral.js +5 -14
- package/lib/build/run-debug-piral.js.map +1 -1
- package/lib/bundler.js +100 -127
- package/lib/bundler.js.map +1 -1
- package/lib/commands.js +5 -1
- package/lib/commands.js.map +1 -1
- package/lib/common/browser.js +13 -26
- package/lib/common/browser.js.map +1 -1
- package/lib/common/compatibility.js +10 -21
- package/lib/common/compatibility.js.map +1 -1
- package/lib/common/declaration.js +80 -101
- package/lib/common/declaration.js.map +1 -1
- package/lib/common/emulator.js +186 -182
- package/lib/common/emulator.js.map +1 -1
- package/lib/common/http.js +7 -4
- package/lib/common/http.js.map +1 -1
- package/lib/common/importmap.js +172 -187
- package/lib/common/importmap.js.map +1 -1
- package/lib/common/injectors.js +4 -1
- package/lib/common/injectors.js.map +1 -1
- package/lib/common/inspect.js +5 -2
- package/lib/common/inspect.js.map +1 -1
- package/lib/common/interactive.js +9 -15
- package/lib/common/interactive.js.map +1 -1
- package/lib/common/io.js +256 -299
- package/lib/common/io.js.map +1 -1
- package/lib/common/language.js +21 -5
- package/lib/common/language.js.map +1 -1
- package/lib/common/npm.js +193 -228
- package/lib/common/npm.js.map +1 -1
- package/lib/common/pack.js +71 -86
- package/lib/common/pack.js.map +1 -1
- package/lib/common/package.js +426 -448
- package/lib/common/package.js.map +1 -1
- package/lib/common/parallel.js +12 -23
- package/lib/common/parallel.js.map +1 -1
- package/lib/common/patcher.js +54 -71
- package/lib/common/patcher.js.map +1 -1
- package/lib/common/platform.js +1 -12
- package/lib/common/platform.js.map +1 -1
- package/lib/common/port.js +11 -24
- package/lib/common/port.js.map +1 -1
- package/lib/common/rules.js +6 -17
- package/lib/common/rules.js.map +1 -1
- package/lib/common/scaffold.js +52 -59
- package/lib/common/scaffold.js.map +1 -1
- package/lib/common/shell.js +49 -58
- package/lib/common/shell.js.map +1 -1
- package/lib/common/spec.js +1 -1
- package/lib/common/spec.js.map +1 -1
- package/lib/common/template.js +3 -14
- package/lib/common/template.js.map +1 -1
- package/lib/common/watcher.js +7 -16
- package/lib/common/watcher.js.map +1 -1
- package/lib/common/website.d.ts +1 -0
- package/lib/common/website.js +67 -57
- package/lib/common/website.js.map +1 -1
- package/lib/injectors/pilet-injector.js +138 -145
- package/lib/injectors/pilet-injector.js.map +1 -1
- package/lib/injectors/piral-injector.js +55 -67
- package/lib/injectors/piral-injector.js.map +1 -1
- package/lib/messages.d.ts +81 -0
- package/lib/messages.js +94 -1
- package/lib/messages.js.map +1 -1
- package/lib/npm-clients/bun.js +36 -60
- package/lib/npm-clients/bun.js.map +1 -1
- package/lib/npm-clients/index.js +10 -21
- package/lib/npm-clients/index.js.map +1 -1
- package/lib/npm-clients/lerna.js +48 -72
- package/lib/npm-clients/lerna.js.map +1 -1
- package/lib/npm-clients/npm.js +69 -105
- package/lib/npm-clients/npm.js.map +1 -1
- package/lib/npm-clients/pnp.js +35 -59
- package/lib/npm-clients/pnp.js.map +1 -1
- package/lib/npm-clients/pnpm.js +35 -59
- package/lib/npm-clients/pnpm.js.map +1 -1
- package/lib/npm-clients/rush.js +53 -77
- package/lib/npm-clients/rush.js.map +1 -1
- package/lib/npm-clients/yarn.js +35 -59
- package/lib/npm-clients/yarn.js.map +1 -1
- package/lib/platforms/node.js +4 -17
- package/lib/platforms/node.js.map +1 -1
- package/lib/platforms/web.js +81 -96
- package/lib/platforms/web.js.map +1 -1
- package/lib/plugin.js +56 -75
- package/lib/plugin.js.map +1 -1
- package/lib/questionnaire.js +46 -12
- package/lib/questionnaire.js.map +1 -1
- package/lib/release.js +32 -47
- package/lib/release.js.map +1 -1
- package/lib/rules/index.js +10 -23
- package/lib/rules/index.js.map +1 -1
- package/lib/rules/pilet-has-externals-as-peers.js +34 -45
- package/lib/rules/pilet-has-externals-as-peers.js.map +1 -1
- package/lib/rules/pilet-has-no-self-reference.js +16 -27
- package/lib/rules/pilet-has-no-self-reference.js.map +1 -1
- package/lib/rules/pilet-has-non-conflicting-css.js +27 -42
- package/lib/rules/pilet-has-non-conflicting-css.js.map +1 -1
- package/lib/rules/pilet-stays-small.js +20 -33
- package/lib/rules/pilet-stays-small.js.map +1 -1
- package/lib/rules/pilet-uses-latest-piral.js +17 -28
- package/lib/rules/pilet-uses-latest-piral.js.map +1 -1
- package/lib/rules/piral-has-valid-devDependencies.js +4 -1
- package/lib/rules/piral-has-valid-devDependencies.js.map +1 -1
- package/lib/runner.js +3 -12
- package/lib/runner.js.map +1 -1
- package/lib/select.js +21 -32
- package/lib/select.js.map +1 -1
- package/lib/start.js +6 -17
- package/lib/start.js.map +1 -1
- package/package.json +2 -2
- package/src/apps/build-piral.test.ts +1 -1
- package/src/common/package.ts +9 -2
- package/src/common/website.ts +43 -15
- package/src/injectors/pilet-injector.ts +12 -2
- package/src/messages.ts +93 -0
package/lib/common/package.js
CHANGED
|
@@ -1,24 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
3
|
exports.retrievePiletData = exports.findPiletRoot = exports.combinePiletExternals = exports.checkAppShellPackage = exports.patchPiletPackage = exports.isValidDependency = exports.validateSharedDependencies = exports.retrievePiletsInfo = exports.retrieveExternals = exports.flattenExternals = exports.findPackageVersion = exports.findDependencyVersion = exports.retrievePiralRoot = exports.getPiletsInfo = exports.copyPiralFiles = exports.copyScaffoldingFiles = exports.getFileStats = exports.getPiralPackage = exports.patchPiralPackage = exports.readPiralPackage = exports.findPiralInstances = exports.findPiralInstance = exports.getPiralPath = void 0;
|
|
24
4
|
const path_1 = require("path");
|
|
@@ -40,40 +20,38 @@ const language_2 = require("./language");
|
|
|
40
20
|
const constants_1 = require("./constants");
|
|
41
21
|
const constants_2 = require("./constants");
|
|
42
22
|
const external_1 = require("../external");
|
|
43
|
-
function appendBundler(devDependencies, bundler, proposedVersion) {
|
|
44
|
-
|
|
45
|
-
if (bundler
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
23
|
+
async function appendBundler(devDependencies, bundler, proposedVersion) {
|
|
24
|
+
if (bundler && bundler !== 'none') {
|
|
25
|
+
if (isValidDependency(bundler)) {
|
|
26
|
+
const sep = bundler.indexOf('@', 1);
|
|
27
|
+
const hasVersion = sep !== -1;
|
|
28
|
+
const proposedName = bundler.substring(0, hasVersion ? sep : bundler.length);
|
|
29
|
+
const givenVersion = hasVersion ? bundler.substring(sep + 1) : proposedVersion;
|
|
30
|
+
const name = constants_1.bundlerNames.includes(proposedName) ? `piral-cli-${bundler}` : proposedName;
|
|
31
|
+
const versions = new Set([
|
|
32
|
+
givenVersion,
|
|
33
|
+
givenVersion.includes('-beta.') && 'next',
|
|
34
|
+
givenVersion.includes('-alpha.') && 'canary',
|
|
35
|
+
givenVersion.includes('.') && givenVersion.split('.').slice(0, 2).join('.'),
|
|
36
|
+
'latest',
|
|
37
|
+
]);
|
|
38
|
+
for (const version of versions) {
|
|
39
|
+
if (version) {
|
|
40
|
+
const isAvailable = await (0, npm_2.findSpecificVersion)(name, version);
|
|
41
|
+
// only if something was returned we know that the version exists; so we can take it.
|
|
42
|
+
if (isAvailable) {
|
|
43
|
+
devDependencies[name] = version;
|
|
44
|
+
return;
|
|
67
45
|
}
|
|
68
46
|
}
|
|
69
|
-
(0, log_1.log)('generalWarning_0001', `Could not find a valid version for the provided bundler "${bundler}".'`);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
//Error case - print warning and ignore
|
|
73
|
-
(0, log_1.log)('generalWarning_0001', `The provided bundler name "${bundler}" does not refer to a valid package name.'`);
|
|
74
47
|
}
|
|
48
|
+
(0, log_1.log)('generalWarning_0001', `Could not find a valid version for the provided bundler "${bundler}".'`);
|
|
75
49
|
}
|
|
76
|
-
|
|
50
|
+
else {
|
|
51
|
+
//Error case - print warning and ignore
|
|
52
|
+
(0, log_1.log)('generalWarning_0001', `The provided bundler name "${bundler}" does not refer to a valid package name.'`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
77
55
|
}
|
|
78
56
|
function getDependencyVersion(name, devDependencies, allDependencies) {
|
|
79
57
|
const version = devDependencies[name];
|
|
@@ -84,47 +62,45 @@ function getDependencyVersion(name, devDependencies, allDependencies) {
|
|
|
84
62
|
return selected || 'latest';
|
|
85
63
|
}
|
|
86
64
|
const globPatternStartIndicators = ['*', '?', '[', '!(', '?(', '+(', '@('];
|
|
87
|
-
function getMatchingFiles(source, target, file) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
65
|
+
async function getMatchingFiles(source, target, file) {
|
|
66
|
+
const { from, to, deep = true } = typeof file === 'string' ? { from: file, to: file, deep: true } : file;
|
|
67
|
+
const sourcePath = (0, path_1.resolve)(source, from);
|
|
68
|
+
const targetPath = (0, path_1.resolve)(target, to);
|
|
69
|
+
const isDirectory = await (0, io_1.checkIsDirectory)(sourcePath);
|
|
70
|
+
if (isDirectory) {
|
|
71
|
+
(0, log_1.log)('generalDebug_0003', `Matching in directory "${sourcePath}".`);
|
|
72
|
+
const pattern = deep ? '**/*' : '*';
|
|
73
|
+
const files = await (0, io_1.matchFiles)(sourcePath, pattern);
|
|
74
|
+
return files.map((file) => ({
|
|
75
|
+
sourcePath: file,
|
|
76
|
+
targetPath: (0, path_1.resolve)(targetPath, (0, path_1.relative)(sourcePath, file)),
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
else if (globPatternStartIndicators.some((m) => from.indexOf(m) !== -1)) {
|
|
80
|
+
(0, log_1.log)('generalDebug_0003', `Matching using glob "${sourcePath}".`);
|
|
81
|
+
const files = await (0, io_1.matchFiles)(source, from);
|
|
82
|
+
const parts = sourcePath.split('/');
|
|
83
|
+
for (let i = 0; i < parts.length; i++) {
|
|
84
|
+
const part = parts[i];
|
|
85
|
+
if (globPatternStartIndicators.some((m) => part.indexOf(m) !== -1)) {
|
|
86
|
+
parts.splice(i, parts.length - i);
|
|
87
|
+
break;
|
|
112
88
|
}
|
|
113
|
-
const relRoot = parts.join('/');
|
|
114
|
-
const tarRoot = (0, path_1.resolve)(target, to);
|
|
115
|
-
return files.map((file) => ({
|
|
116
|
-
sourcePath: file,
|
|
117
|
-
targetPath: (0, path_1.resolve)(tarRoot, (0, path_1.relative)(relRoot, file)),
|
|
118
|
-
}));
|
|
119
89
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
});
|
|
90
|
+
const relRoot = parts.join('/');
|
|
91
|
+
const tarRoot = (0, path_1.resolve)(target, to);
|
|
92
|
+
return files.map((file) => ({
|
|
93
|
+
sourcePath: file,
|
|
94
|
+
targetPath: (0, path_1.resolve)(tarRoot, (0, path_1.relative)(relRoot, file)),
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
(0, log_1.log)('generalDebug_0003', `Assume direct path source "${sourcePath}".`);
|
|
98
|
+
return [
|
|
99
|
+
{
|
|
100
|
+
sourcePath,
|
|
101
|
+
targetPath,
|
|
102
|
+
},
|
|
103
|
+
];
|
|
128
104
|
}
|
|
129
105
|
function getPiralPath(root, name) {
|
|
130
106
|
const path = (0, npm_2.findPackageRoot)(name, root);
|
|
@@ -134,50 +110,50 @@ function getPiralPath(root, name) {
|
|
|
134
110
|
return (0, path_1.dirname)(path);
|
|
135
111
|
}
|
|
136
112
|
exports.getPiralPath = getPiralPath;
|
|
137
|
-
function findPiralInstance(proposedApp, rootDir, details) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const { url } = details, rest = __rest(details, ["url"]);
|
|
152
|
-
(0, log_1.log)('generalDebug_0003', `Piral instance not installed yet - trying from remote "${url}" ...`);
|
|
153
|
-
yield (0, website_1.scaffoldFromEmulatorWebsite)(rootDir, url);
|
|
154
|
-
return yield findPiralInstance(proposedApp, rootDir, rest);
|
|
113
|
+
async function findPiralInstance(proposedApp, rootDir, details) {
|
|
114
|
+
const path = (0, npm_2.findPackageRoot)(proposedApp, rootDir);
|
|
115
|
+
if (path) {
|
|
116
|
+
(0, log_1.log)('generalDebug_0003', `Following the app package in "${path}" ...`);
|
|
117
|
+
const url = details?.url;
|
|
118
|
+
const root = (0, path_1.dirname)(path);
|
|
119
|
+
const appPackage = await (0, io_2.readJson)(root, (0, path_1.basename)(path));
|
|
120
|
+
const relPath = appPackage.app;
|
|
121
|
+
appPackage.app = relPath && (0, path_1.resolve)(root, relPath);
|
|
122
|
+
appPackage.root = root;
|
|
123
|
+
appPackage.port = details?.port || 0;
|
|
124
|
+
if (url) {
|
|
125
|
+
(0, log_1.log)('generalDebug_0003', `Updating the emulator from remote "${url}" ...`);
|
|
126
|
+
await (0, website_1.updateFromEmulatorWebsite)(root, url);
|
|
155
127
|
}
|
|
156
|
-
|
|
157
|
-
}
|
|
128
|
+
return appPackage;
|
|
129
|
+
}
|
|
130
|
+
else if (details?.url) {
|
|
131
|
+
const { url, ...rest } = details;
|
|
132
|
+
(0, log_1.log)('generalDebug_0003', `Piral instance not installed yet - trying from remote "${url}" ...`);
|
|
133
|
+
await (0, website_1.scaffoldFromEmulatorWebsite)(rootDir, url);
|
|
134
|
+
return await findPiralInstance(proposedApp, rootDir, rest);
|
|
135
|
+
}
|
|
136
|
+
(0, log_1.fail)('appInstanceNotFound_0010', proposedApp);
|
|
158
137
|
}
|
|
159
138
|
exports.findPiralInstance = findPiralInstance;
|
|
160
|
-
function findPiralInstances(proposedApps, piletPackage, piletDefinition, rootDir) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
proposedApps = availableApps.
|
|
169
|
-
if (proposedApps.length === 0) {
|
|
170
|
-
proposedApps = availableApps.slice(0, 1);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
proposedApps = [(_a = piletPackage.piral) === null || _a === void 0 ? void 0 : _a.name].filter(Boolean);
|
|
175
|
-
}
|
|
176
|
-
if (proposedApps.length > 0) {
|
|
177
|
-
return Promise.all(proposedApps.map((proposedApp) => { var _a; return findPiralInstance(proposedApp, rootDir, (_a = piletDefinition === null || piletDefinition === void 0 ? void 0 : piletDefinition.piralInstances) === null || _a === void 0 ? void 0 : _a[proposedApp]); }));
|
|
139
|
+
async function findPiralInstances(proposedApps, piletPackage, piletDefinition, rootDir) {
|
|
140
|
+
if (proposedApps) {
|
|
141
|
+
// do nothing
|
|
142
|
+
}
|
|
143
|
+
else if (piletDefinition) {
|
|
144
|
+
const availableApps = Object.keys(piletDefinition.piralInstances || {});
|
|
145
|
+
proposedApps = availableApps.filter((m) => piletDefinition.piralInstances[m].selected);
|
|
146
|
+
if (proposedApps.length === 0) {
|
|
147
|
+
proposedApps = availableApps.slice(0, 1);
|
|
178
148
|
}
|
|
179
|
-
|
|
180
|
-
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
proposedApps = [piletPackage.piral?.name].filter(Boolean);
|
|
152
|
+
}
|
|
153
|
+
if (proposedApps.length > 0) {
|
|
154
|
+
return Promise.all(proposedApps.map((proposedApp) => findPiralInstance(proposedApp, rootDir, piletDefinition?.piralInstances?.[proposedApp])));
|
|
155
|
+
}
|
|
156
|
+
return [];
|
|
181
157
|
}
|
|
182
158
|
exports.findPiralInstances = findPiralInstances;
|
|
183
159
|
function readPiralPackage(root, name) {
|
|
@@ -186,133 +162,128 @@ function readPiralPackage(root, name) {
|
|
|
186
162
|
return (0, io_2.readJson)(path, constants_1.packageJson);
|
|
187
163
|
}
|
|
188
164
|
exports.readPiralPackage = readPiralPackage;
|
|
189
|
-
function patchPiralPackage(root, app, data, version, bundler) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
pilets: getPiletsInfo({}),
|
|
198
|
-
});
|
|
199
|
-
(0, log_1.log)('generalDebug_0003', `Succesfully patched the pilet.json.`);
|
|
165
|
+
async function patchPiralPackage(root, app, data, version, bundler) {
|
|
166
|
+
(0, log_1.log)('generalDebug_0003', `Patching the ${constants_1.packageJson} in "${root}" ...`);
|
|
167
|
+
const pkg = await getPiralPackage(app, data, version, bundler);
|
|
168
|
+
await (0, io_2.updateExistingJson)(root, constants_1.packageJson, pkg);
|
|
169
|
+
(0, log_1.log)('generalDebug_0003', `Succesfully patched the ${constants_1.packageJson}.`);
|
|
170
|
+
await (0, io_2.updateExistingJson)(root, constants_2.piralJson, {
|
|
171
|
+
$schema: constants_1.piralJsonSchemaUrl,
|
|
172
|
+
pilets: getPiletsInfo({}),
|
|
200
173
|
});
|
|
174
|
+
(0, log_1.log)('generalDebug_0003', `Succesfully patched the pilet.json.`);
|
|
201
175
|
}
|
|
202
176
|
exports.patchPiralPackage = patchPiralPackage;
|
|
203
|
-
function getPiralPackage(app, data, version, bundler) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
177
|
+
async function getPiralPackage(app, data, version, bundler) {
|
|
178
|
+
const framework = data.packageName;
|
|
179
|
+
const devDependencies = {
|
|
180
|
+
...(0, language_1.getDevDependencies)(data.language, (0, language_2.getDevDependencyPackages)(framework, data.reactVersion, data.reactRouterVersion)),
|
|
181
|
+
'piral-cli': `${version}`,
|
|
182
|
+
};
|
|
183
|
+
const dependencies = {
|
|
184
|
+
...(0, language_2.getFrameworkDependencies)(framework, version),
|
|
185
|
+
...(0, language_1.getDependencies)(data.language, (0, language_1.getDependencyPackages)(framework, data.reactVersion, data.reactRouterVersion)),
|
|
186
|
+
};
|
|
187
|
+
await appendBundler(devDependencies, bundler, version);
|
|
188
|
+
return {
|
|
189
|
+
app,
|
|
190
|
+
scripts: {
|
|
191
|
+
start: 'piral debug',
|
|
192
|
+
build: 'piral build',
|
|
193
|
+
postinstall: 'piral declaration',
|
|
194
|
+
},
|
|
195
|
+
types: 'dist/index.d.ts',
|
|
196
|
+
importmap: {
|
|
197
|
+
imports: {},
|
|
198
|
+
inherit: [
|
|
199
|
+
'piral-base',
|
|
200
|
+
framework !== 'piral-base' && 'piral-core',
|
|
201
|
+
framework === 'piral' && 'piral', // this we take only if we selected piral
|
|
202
|
+
].filter(Boolean),
|
|
203
|
+
},
|
|
204
|
+
dependencies,
|
|
205
|
+
devDependencies,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
exports.getPiralPackage = getPiralPackage;
|
|
209
|
+
async function getAvailableFiles(root, name, dirName, fileMap) {
|
|
210
|
+
const source = getPiralPath(root, name);
|
|
211
|
+
const tgz = `${dirName}.tar`;
|
|
212
|
+
(0, log_1.log)('generalDebug_0003', `Checking if "${tgz}" exists in "${source}" ...`);
|
|
213
|
+
const exists = await (0, io_2.checkExists)((0, path_1.resolve)(source, tgz));
|
|
214
|
+
if (exists) {
|
|
215
|
+
await (0, archive_1.unpackTarball)(source, tgz);
|
|
216
|
+
}
|
|
217
|
+
(0, log_1.log)('generalDebug_0003', `Get matching files from "${source}".`);
|
|
218
|
+
const base = (0, path_1.resolve)(source, dirName);
|
|
219
|
+
const files = await (0, io_1.matchFiles)(base, '**/*');
|
|
220
|
+
return files.map((file) => ({
|
|
221
|
+
sourcePath: file,
|
|
222
|
+
targetPath: (0, path_1.resolve)(root, (0, path_1.relative)(base, file)),
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
async function getFileStats(root, name, fileMap = []) {
|
|
226
|
+
const files = await getAvailableFiles(root, name, constants_1.filesTar, fileMap);
|
|
227
|
+
return await Promise.all(files.map(async (file) => {
|
|
228
|
+
const { sourcePath, targetPath } = file;
|
|
229
|
+
const sourceHash = await (0, io_1.getHash)(sourcePath);
|
|
230
|
+
(0, log_1.log)('generalDebug_0003', `Obtained hash from "${sourcePath}": ${sourceHash}`);
|
|
231
|
+
const targetHash = await (0, io_1.getHash)(targetPath);
|
|
232
|
+
(0, log_1.log)('generalDebug_0003', `Obtained hash from "${targetPath}": ${targetHash}`);
|
|
209
233
|
return {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
build: 'piral build',
|
|
214
|
-
postinstall: 'piral declaration',
|
|
215
|
-
},
|
|
216
|
-
types: 'dist/index.d.ts',
|
|
217
|
-
importmap: {
|
|
218
|
-
imports: {},
|
|
219
|
-
inherit: [
|
|
220
|
-
'piral-base',
|
|
221
|
-
framework !== 'piral-base' && 'piral-core',
|
|
222
|
-
framework === 'piral' && 'piral', // this we take only if we selected piral
|
|
223
|
-
].filter(Boolean),
|
|
224
|
-
},
|
|
225
|
-
dependencies,
|
|
226
|
-
devDependencies,
|
|
234
|
+
path: targetPath,
|
|
235
|
+
hash: targetHash,
|
|
236
|
+
changed: sourceHash !== targetHash,
|
|
227
237
|
};
|
|
228
|
-
});
|
|
238
|
+
}));
|
|
229
239
|
}
|
|
230
|
-
exports.
|
|
231
|
-
function
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
const
|
|
235
|
-
(0, log_1.log)('generalDebug_0003', `Checking if "${tgz}" exists in "${source}" ...`);
|
|
236
|
-
const exists = yield (0, io_2.checkExists)((0, path_1.resolve)(source, tgz));
|
|
240
|
+
exports.getFileStats = getFileStats;
|
|
241
|
+
async function copyFiles(subfiles, forceOverwrite, originalFiles, variables) {
|
|
242
|
+
for (const subfile of subfiles) {
|
|
243
|
+
const { sourcePath, targetPath } = subfile;
|
|
244
|
+
const exists = await (0, io_2.checkExists)(sourcePath);
|
|
237
245
|
if (exists) {
|
|
238
|
-
|
|
246
|
+
const overwrite = originalFiles.some((m) => m.path === targetPath && !m.changed);
|
|
247
|
+
const force = overwrite ? enums_1.ForceOverwrite.yes : forceOverwrite;
|
|
248
|
+
await (0, io_2.copy)(sourcePath, targetPath, force);
|
|
239
249
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const files = yield (0, io_1.matchFiles)(base, '**/*');
|
|
243
|
-
return files.map((file) => ({
|
|
244
|
-
sourcePath: file,
|
|
245
|
-
targetPath: (0, path_1.resolve)(root, (0, path_1.relative)(base, file)),
|
|
246
|
-
}));
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
function getFileStats(root, name, fileMap = []) {
|
|
250
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
251
|
-
const files = yield getAvailableFiles(root, name, constants_1.filesTar, fileMap);
|
|
252
|
-
return yield Promise.all(files.map((file) => __awaiter(this, void 0, void 0, function* () {
|
|
253
|
-
const { sourcePath, targetPath } = file;
|
|
254
|
-
const sourceHash = yield (0, io_1.getHash)(sourcePath);
|
|
255
|
-
(0, log_1.log)('generalDebug_0003', `Obtained hash from "${sourcePath}": ${sourceHash}`);
|
|
256
|
-
const targetHash = yield (0, io_1.getHash)(targetPath);
|
|
257
|
-
(0, log_1.log)('generalDebug_0003', `Obtained hash from "${targetPath}": ${targetHash}`);
|
|
258
|
-
return {
|
|
259
|
-
path: targetPath,
|
|
260
|
-
hash: targetHash,
|
|
261
|
-
changed: sourceHash !== targetHash,
|
|
262
|
-
};
|
|
263
|
-
})));
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
exports.getFileStats = getFileStats;
|
|
267
|
-
function copyFiles(subfiles, forceOverwrite, originalFiles, variables) {
|
|
268
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
269
|
-
for (const subfile of subfiles) {
|
|
270
|
-
const { sourcePath, targetPath } = subfile;
|
|
271
|
-
const exists = yield (0, io_2.checkExists)(sourcePath);
|
|
272
|
-
if (exists) {
|
|
273
|
-
const overwrite = originalFiles.some((m) => m.path === targetPath && !m.changed);
|
|
274
|
-
const force = overwrite ? enums_1.ForceOverwrite.yes : forceOverwrite;
|
|
275
|
-
yield (0, io_2.copy)(sourcePath, targetPath, force);
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
(0, log_1.fail)('cannotFindFile_0046', sourcePath);
|
|
279
|
-
}
|
|
250
|
+
else {
|
|
251
|
+
(0, log_1.fail)('cannotFindFile_0046', sourcePath);
|
|
280
252
|
}
|
|
281
|
-
}
|
|
253
|
+
}
|
|
282
254
|
}
|
|
283
|
-
function copyScaffoldingFiles(source, target, files, piralInfo, variables) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
yield copyFiles(allFiles, enums_1.ForceOverwrite.yes, [], variables);
|
|
295
|
-
});
|
|
255
|
+
async function copyScaffoldingFiles(source, target, files, piralInfo, variables) {
|
|
256
|
+
(0, log_1.log)('generalDebug_0003', `Copying the scaffolding files ...`);
|
|
257
|
+
const allFiles = [];
|
|
258
|
+
for (const file of files) {
|
|
259
|
+
const subfiles = await getMatchingFiles(source, target, file);
|
|
260
|
+
allFiles.push(...subfiles);
|
|
261
|
+
}
|
|
262
|
+
if (piralInfo) {
|
|
263
|
+
await extendPackageOverridesFromTemplateFragment(target, piralInfo, allFiles);
|
|
264
|
+
}
|
|
265
|
+
await copyFiles(allFiles, enums_1.ForceOverwrite.yes, [], variables);
|
|
296
266
|
}
|
|
297
267
|
exports.copyScaffoldingFiles = copyScaffoldingFiles;
|
|
298
|
-
function extendPackageOverridesFromTemplateFragment(root, piralInfo, files) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
piralInfo.pilets = {};
|
|
308
|
-
}
|
|
309
|
-
if (!piralInfo.pilets.packageOverrides) {
|
|
310
|
-
piralInfo.pilets.packageOverrides = {};
|
|
311
|
-
}
|
|
312
|
-
piralInfo.pilets.packageOverrides = Object.assign(Object.assign({}, piralInfo.pilets.packageOverrides), fragment);
|
|
268
|
+
async function extendPackageOverridesFromTemplateFragment(root, piralInfo, files) {
|
|
269
|
+
const packageTarget = (0, path_1.resolve)(root, constants_1.packageJson);
|
|
270
|
+
for (let i = files.length; i--;) {
|
|
271
|
+
const file = files[i];
|
|
272
|
+
if (file.targetPath === packageTarget) {
|
|
273
|
+
const fragment = await (0, io_2.readJson)((0, path_1.dirname)(file.sourcePath), (0, path_1.basename)(file.sourcePath));
|
|
274
|
+
files.splice(i, 1);
|
|
275
|
+
if (!piralInfo.pilets) {
|
|
276
|
+
piralInfo.pilets = {};
|
|
313
277
|
}
|
|
278
|
+
if (!piralInfo.pilets.packageOverrides) {
|
|
279
|
+
piralInfo.pilets.packageOverrides = {};
|
|
280
|
+
}
|
|
281
|
+
piralInfo.pilets.packageOverrides = {
|
|
282
|
+
...piralInfo.pilets.packageOverrides,
|
|
283
|
+
...fragment,
|
|
284
|
+
};
|
|
314
285
|
}
|
|
315
|
-
}
|
|
286
|
+
}
|
|
316
287
|
}
|
|
317
288
|
function isTemplateFileLocation(item) {
|
|
318
289
|
return typeof item === 'object';
|
|
@@ -322,24 +293,22 @@ function tryFindPackageVersion(packageName) {
|
|
|
322
293
|
const { version } = require(`${packageName}/${constants_1.packageJson}`);
|
|
323
294
|
return version;
|
|
324
295
|
}
|
|
325
|
-
catch
|
|
296
|
+
catch {
|
|
326
297
|
return undefined;
|
|
327
298
|
}
|
|
328
299
|
}
|
|
329
|
-
function copyPiralFiles(root, name, piralInfo, forceOverwrite, variables, originalFiles) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
yield copyFiles(files, forceOverwrite, originalFiles, variables);
|
|
342
|
-
});
|
|
300
|
+
async function copyPiralFiles(root, name, piralInfo, forceOverwrite, variables, originalFiles) {
|
|
301
|
+
(0, log_1.log)('generalDebug_0003', `Copying the Piral files ...`);
|
|
302
|
+
const { files: _files } = getPiletsInfo(piralInfo);
|
|
303
|
+
const fileMap = _files.filter(isTemplateFileLocation);
|
|
304
|
+
const files = await getAvailableFiles(root, name, constants_1.filesTar, fileMap);
|
|
305
|
+
if (originalFiles === undefined) {
|
|
306
|
+
const initialFiles = await getAvailableFiles(root, name, constants_1.filesOnceTar, fileMap);
|
|
307
|
+
files.push(...initialFiles);
|
|
308
|
+
originalFiles = [];
|
|
309
|
+
}
|
|
310
|
+
await extendPackageOverridesFromTemplateFragment(root, piralInfo, files);
|
|
311
|
+
await copyFiles(files, forceOverwrite, originalFiles, variables);
|
|
343
312
|
}
|
|
344
313
|
exports.copyPiralFiles = copyPiralFiles;
|
|
345
314
|
function getPiletsInfo(piralInfo) {
|
|
@@ -358,27 +327,25 @@ function getPiletsInfo(piralInfo) {
|
|
|
358
327
|
};
|
|
359
328
|
}
|
|
360
329
|
exports.getPiletsInfo = getPiletsInfo;
|
|
361
|
-
function retrievePiralRoot(baseDir, entry) {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
(0, log_1.fail)('entryPointMissing_0070', rootDir);
|
|
371
|
-
}
|
|
372
|
-
const { app } = require(packageName);
|
|
373
|
-
if (!app) {
|
|
374
|
-
(0, log_1.fail)('entryPointMissing_0071');
|
|
375
|
-
}
|
|
376
|
-
(0, log_1.log)('generalDebug_0003', `Found app entry point in "${app}".`);
|
|
377
|
-
return (0, path_1.join)((0, path_1.dirname)(packageName), app);
|
|
330
|
+
async function retrievePiralRoot(baseDir, entry) {
|
|
331
|
+
const rootDir = (0, path_1.join)(baseDir, entry);
|
|
332
|
+
(0, log_1.log)('generalDebug_0003', `Retrieving Piral root from "${rootDir}" ...`);
|
|
333
|
+
if (!constants_2.declarationEntryExtensions.includes((0, path_1.extname)(rootDir).toLowerCase())) {
|
|
334
|
+
const packageName = (0, path_1.basename)(rootDir) === constants_1.packageJson ? rootDir : (0, path_1.join)(rootDir, constants_1.packageJson);
|
|
335
|
+
(0, log_1.log)('generalDebug_0003', `Trying to get entry point from "${packageName}".`);
|
|
336
|
+
const exists = await (0, io_2.checkExists)(packageName);
|
|
337
|
+
if (!exists) {
|
|
338
|
+
(0, log_1.fail)('entryPointMissing_0070', rootDir);
|
|
378
339
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
340
|
+
const { app } = require(packageName);
|
|
341
|
+
if (!app) {
|
|
342
|
+
(0, log_1.fail)('entryPointMissing_0071');
|
|
343
|
+
}
|
|
344
|
+
(0, log_1.log)('generalDebug_0003', `Found app entry point in "${app}".`);
|
|
345
|
+
return (0, path_1.join)((0, path_1.dirname)(packageName), app);
|
|
346
|
+
}
|
|
347
|
+
(0, log_1.log)('generalDebug_0003', `Found app entry point in "${rootDir}".`);
|
|
348
|
+
return rootDir;
|
|
382
349
|
}
|
|
383
350
|
exports.retrievePiralRoot = retrievePiralRoot;
|
|
384
351
|
function checkArrayOrUndefined(obj, key) {
|
|
@@ -391,57 +358,52 @@ function checkArrayOrUndefined(obj, key) {
|
|
|
391
358
|
}
|
|
392
359
|
return undefined;
|
|
393
360
|
}
|
|
394
|
-
function findDependencyVersion(pckg, rootPath, dependency) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
if ((0, npm_1.isNpmPackage)(desiredVersion)) {
|
|
403
|
-
return desiredVersion;
|
|
404
|
-
}
|
|
405
|
-
else if ((0, npm_1.isGitPackage)(desiredVersion)) {
|
|
406
|
-
return (0, npm_1.makeGitUrl)(desiredVersion);
|
|
407
|
-
}
|
|
408
|
-
else if ((0, npm_1.isLocalPackage)(rootPath, desiredVersion)) {
|
|
409
|
-
return (0, npm_1.makeFilePath)(rootPath, desiredVersion);
|
|
410
|
-
}
|
|
361
|
+
async function findDependencyVersion(pckg, rootPath, dependency) {
|
|
362
|
+
const { devDependencies = {}, dependencies = {} } = pckg;
|
|
363
|
+
const packageName = dependency.name;
|
|
364
|
+
const desiredVersion = dependencies[packageName] ?? devDependencies[packageName];
|
|
365
|
+
const [parent] = dependency.parents || [];
|
|
366
|
+
if (desiredVersion) {
|
|
367
|
+
if ((0, npm_1.isNpmPackage)(desiredVersion)) {
|
|
368
|
+
return desiredVersion;
|
|
411
369
|
}
|
|
412
|
-
if (
|
|
413
|
-
|
|
414
|
-
// we should start the lookup in its directory (pnpm issue)
|
|
415
|
-
const parentPath = (0, npm_1.tryResolvePackage)(parent, rootPath);
|
|
416
|
-
if (parentPath) {
|
|
417
|
-
rootPath = (0, path_1.dirname)(parentPath);
|
|
418
|
-
}
|
|
370
|
+
else if ((0, npm_1.isGitPackage)(desiredVersion)) {
|
|
371
|
+
return (0, npm_1.makeGitUrl)(desiredVersion);
|
|
419
372
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return (0, npm_2.makeNpmAlias)(dependency.alias, version);
|
|
373
|
+
else if ((0, npm_1.isLocalPackage)(rootPath, desiredVersion)) {
|
|
374
|
+
return (0, npm_1.makeFilePath)(rootPath, desiredVersion);
|
|
423
375
|
}
|
|
424
|
-
|
|
425
|
-
|
|
376
|
+
}
|
|
377
|
+
if (parent) {
|
|
378
|
+
// in case the dependency came from another package (= parent)
|
|
379
|
+
// we should start the lookup in its directory (pnpm issue)
|
|
380
|
+
const parentPath = (0, npm_1.tryResolvePackage)(parent, rootPath);
|
|
381
|
+
if (parentPath) {
|
|
382
|
+
rootPath = (0, path_1.dirname)(parentPath);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const version = await findPackageVersion(rootPath, packageName);
|
|
386
|
+
if (dependency.alias) {
|
|
387
|
+
return (0, npm_2.makeNpmAlias)(dependency.alias, version);
|
|
388
|
+
}
|
|
389
|
+
return version;
|
|
426
390
|
}
|
|
427
391
|
exports.findDependencyVersion = findDependencyVersion;
|
|
428
|
-
function findPackageVersion(rootPath, packageName) {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
return version;
|
|
439
|
-
}
|
|
440
|
-
catch (_a) { }
|
|
392
|
+
async function findPackageVersion(rootPath, packageName) {
|
|
393
|
+
const packages = Array.isArray(packageName) ? packageName : [packageName];
|
|
394
|
+
for (const pckg of packages) {
|
|
395
|
+
try {
|
|
396
|
+
(0, log_1.log)('generalDebug_0003', `Finding the version of "${packageName}" in "${rootPath}".`);
|
|
397
|
+
const moduleName = (0, external_1.getModulePath)(rootPath, pckg);
|
|
398
|
+
const packageJsonPath = await (0, io_2.findFile)(moduleName, constants_1.packageJson);
|
|
399
|
+
const root = (0, path_1.dirname)(packageJsonPath);
|
|
400
|
+
const { version } = await (0, io_2.readJson)(root, constants_1.packageJson);
|
|
401
|
+
return version;
|
|
441
402
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
403
|
+
catch { }
|
|
404
|
+
}
|
|
405
|
+
(0, log_1.log)('cannotResolveDependency_0053', packages, rootPath);
|
|
406
|
+
return 'latest';
|
|
445
407
|
}
|
|
446
408
|
exports.findPackageVersion = findPackageVersion;
|
|
447
409
|
function flattenExternals(dependencies, disableAsync = false) {
|
|
@@ -449,51 +411,61 @@ function flattenExternals(dependencies, disableAsync = false) {
|
|
|
449
411
|
return dependencies.map(getName).filter(utils_1.onlyUnique);
|
|
450
412
|
}
|
|
451
413
|
exports.flattenExternals = flattenExternals;
|
|
452
|
-
function retrieveExternals(root, packageInfo) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
|
|
414
|
+
async function retrieveExternals(root, packageInfo) {
|
|
415
|
+
const importmap = await (0, importmap_1.readImportmap)(root, packageInfo, 'exact', 'host');
|
|
416
|
+
if (importmap.length === 0) {
|
|
417
|
+
const allDeps = {
|
|
418
|
+
...packageInfo.devDependencies,
|
|
419
|
+
...packageInfo.dependencies,
|
|
420
|
+
};
|
|
421
|
+
const deps = packageInfo.pilets?.externals;
|
|
422
|
+
const externals = await (0, npm_2.makeExternals)(root, allDeps, deps);
|
|
423
|
+
return externals.map((ext) => ({
|
|
424
|
+
id: ext,
|
|
425
|
+
name: ext,
|
|
426
|
+
entry: ext,
|
|
427
|
+
type: 'local',
|
|
428
|
+
ref: undefined,
|
|
429
|
+
requireId: ext,
|
|
430
|
+
}));
|
|
431
|
+
}
|
|
432
|
+
return importmap;
|
|
471
433
|
}
|
|
472
434
|
exports.retrieveExternals = retrieveExternals;
|
|
473
|
-
function retrievePiletsInfo(entryFile) {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
435
|
+
async function retrievePiletsInfo(entryFile) {
|
|
436
|
+
const exists = await (0, io_2.checkExists)(entryFile);
|
|
437
|
+
if (!exists) {
|
|
438
|
+
(0, log_1.fail)('entryPointDoesNotExist_0073', entryFile);
|
|
439
|
+
}
|
|
440
|
+
const packageJsonPath = await (0, io_2.findFile)(entryFile, constants_1.packageJson);
|
|
441
|
+
if (!packageJsonPath) {
|
|
442
|
+
(0, log_1.fail)('packageJsonMissing_0074');
|
|
443
|
+
}
|
|
444
|
+
const root = (0, path_1.dirname)(packageJsonPath);
|
|
445
|
+
const packageInfo = await (0, io_2.readJson)(root, constants_1.packageJson);
|
|
446
|
+
const piralJsonPkg = await (0, io_2.readJson)(root, constants_2.piralJson);
|
|
447
|
+
const pilets = {
|
|
448
|
+
...getPiletsInfo(packageInfo),
|
|
449
|
+
...piralJsonPkg.pilets,
|
|
450
|
+
};
|
|
451
|
+
const externals = await retrieveExternals(root, packageInfo);
|
|
452
|
+
const dependencies = {
|
|
453
|
+
std: packageInfo.dependencies || {},
|
|
454
|
+
dev: packageInfo.devDependencies || {},
|
|
455
|
+
peer: packageInfo.peerDependencies || {},
|
|
456
|
+
};
|
|
457
|
+
const framework = constants_2.frameworkLibs.find((lib) => lib in dependencies.std || lib in dependencies.dev);
|
|
458
|
+
return {
|
|
459
|
+
...pilets,
|
|
460
|
+
externals,
|
|
461
|
+
name: packageInfo.name,
|
|
462
|
+
version: packageInfo.version,
|
|
463
|
+
framework,
|
|
464
|
+
dependencies,
|
|
465
|
+
scripts: packageInfo.scripts,
|
|
466
|
+
ignored: checkArrayOrUndefined(packageInfo, 'preservedDependencies'),
|
|
467
|
+
root,
|
|
468
|
+
};
|
|
497
469
|
}
|
|
498
470
|
exports.retrievePiletsInfo = retrievePiletsInfo;
|
|
499
471
|
// This is an ugly workaround for having *some* packages that
|
|
@@ -518,55 +490,65 @@ function isValidDependency(name) {
|
|
|
518
490
|
return name.indexOf('/') === -1 || (name.indexOf('@') === 0 && name.split('/').length < 3);
|
|
519
491
|
}
|
|
520
492
|
exports.isValidDependency = isValidDependency;
|
|
521
|
-
function patchPiletPackage(root, piralInfo, fromEmulator, newInfo) {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
(0, log_1.log)('generalDebug_0003', `Succesfully patched the ${constants_1.packageJson}.`);
|
|
527
|
-
});
|
|
493
|
+
async function patchPiletPackage(root, piralInfo, fromEmulator, newInfo) {
|
|
494
|
+
(0, log_1.log)('generalDebug_0003', `Patching the ${constants_1.packageJson} in "${root}" ...`);
|
|
495
|
+
const pkg = await getPiletPackage(root, piralInfo, fromEmulator, newInfo);
|
|
496
|
+
await (0, io_2.updateExistingJson)(root, constants_1.packageJson, pkg);
|
|
497
|
+
(0, log_1.log)('generalDebug_0003', `Succesfully patched the ${constants_1.packageJson}.`);
|
|
528
498
|
}
|
|
529
499
|
exports.patchPiletPackage = patchPiletPackage;
|
|
530
|
-
function getPiletPackage(root, piralInfo, fromEmulator, newInfo) {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
500
|
+
async function getPiletPackage(root, piralInfo, fromEmulator, newInfo) {
|
|
501
|
+
const { piralCLI = { version: info_1.cliVersion } } = piralInfo;
|
|
502
|
+
const { packageOverrides, ...info } = getPiletsInfo(piralInfo);
|
|
503
|
+
const existingData = newInfo ? {} : await (0, io_2.readJson)(root, constants_1.packageJson);
|
|
504
|
+
const piralDependencies = {
|
|
505
|
+
...piralInfo.devDependencies,
|
|
506
|
+
...piralInfo.dependencies,
|
|
507
|
+
};
|
|
508
|
+
const toolVersion = piralCLI.version;
|
|
509
|
+
const typeDependencies = newInfo ? (0, language_1.getDevDependencies)(newInfo.language) : {};
|
|
510
|
+
const scripts = newInfo
|
|
511
|
+
? {
|
|
512
|
+
start: 'pilet debug',
|
|
513
|
+
build: 'pilet build',
|
|
514
|
+
upgrade: 'pilet upgrade',
|
|
515
|
+
...info.scripts,
|
|
516
|
+
}
|
|
517
|
+
: info.scripts;
|
|
518
|
+
const allExternals = await (0, npm_2.makePiletExternals)(root, piralDependencies, fromEmulator, piralInfo);
|
|
519
|
+
const devDependencies = {
|
|
520
|
+
...Object.keys(typeDependencies).reduce((deps, name) => {
|
|
542
521
|
deps[name] = piralDependencies[name] || typeDependencies[name];
|
|
543
522
|
return deps;
|
|
544
|
-
}, {})
|
|
523
|
+
}, {}),
|
|
524
|
+
...Object.keys(info.devDependencies).reduce((deps, name) => {
|
|
545
525
|
deps[name] = getDependencyVersion(name, info.devDependencies, piralDependencies);
|
|
546
526
|
return deps;
|
|
547
|
-
}, {})
|
|
527
|
+
}, {}),
|
|
528
|
+
...allExternals.filter(isValidDependency).reduce((deps, name) => {
|
|
548
529
|
const existingDeps = existingData.devDependencies;
|
|
549
530
|
const shouldSpecify = newInfo || (existingDeps && name in existingDeps);
|
|
550
531
|
if (shouldSpecify) {
|
|
551
532
|
deps[name] = piralDependencies[name] || tryFindPackageVersion(name) || 'latest';
|
|
552
533
|
}
|
|
553
534
|
return deps;
|
|
554
|
-
}, {})
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
},
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
535
|
+
}, {}),
|
|
536
|
+
['piral-cli']: toolVersion,
|
|
537
|
+
};
|
|
538
|
+
const dependencies = {
|
|
539
|
+
['piral-cli']: undefined,
|
|
540
|
+
};
|
|
541
|
+
if (newInfo) {
|
|
542
|
+
await appendBundler(devDependencies, newInfo.bundler, toolVersion);
|
|
543
|
+
}
|
|
544
|
+
return (0, merge_1.deepMerge)(packageOverrides, {
|
|
545
|
+
importmap: {
|
|
546
|
+
imports: {},
|
|
547
|
+
inherit: [],
|
|
548
|
+
},
|
|
549
|
+
devDependencies,
|
|
550
|
+
dependencies,
|
|
551
|
+
scripts,
|
|
570
552
|
});
|
|
571
553
|
}
|
|
572
554
|
/**
|
|
@@ -602,55 +584,51 @@ function combinePiletExternals(appShells, peerDependencies, peerModules, importm
|
|
|
602
584
|
return externals;
|
|
603
585
|
}
|
|
604
586
|
exports.combinePiletExternals = combinePiletExternals;
|
|
605
|
-
function findPiletRoot(proposedRoot) {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
return (0, path_1.dirname)(packageJsonPath);
|
|
612
|
-
});
|
|
587
|
+
async function findPiletRoot(proposedRoot) {
|
|
588
|
+
const packageJsonPath = await (0, io_2.findFile)(proposedRoot, constants_1.packageJson);
|
|
589
|
+
if (!packageJsonPath) {
|
|
590
|
+
(0, log_1.fail)('packageJsonMissing_0075');
|
|
591
|
+
}
|
|
592
|
+
return (0, path_1.dirname)(packageJsonPath);
|
|
613
593
|
}
|
|
614
594
|
exports.findPiletRoot = findPiletRoot;
|
|
615
|
-
function retrievePiletData(target, app) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
(0, log_1.fail)('appInstanceInvalid_0011');
|
|
630
|
-
}
|
|
631
|
-
const emulator = checkAppShellPackage(appPackage);
|
|
632
|
-
apps.push({
|
|
633
|
-
appPackage,
|
|
634
|
-
appFile,
|
|
635
|
-
appRoot,
|
|
636
|
-
emulator,
|
|
637
|
-
appPort,
|
|
638
|
-
});
|
|
595
|
+
async function retrievePiletData(target, app) {
|
|
596
|
+
const piletJsonPath = await (0, io_2.findFile)(target, constants_2.piletJson);
|
|
597
|
+
const proposedRoot = piletJsonPath ? (0, path_1.dirname)(piletJsonPath) : target;
|
|
598
|
+
const root = await findPiletRoot(proposedRoot);
|
|
599
|
+
const piletPackage = await (0, io_2.readJson)(root, constants_1.packageJson);
|
|
600
|
+
const piletDefinition = piletJsonPath && (await (0, io_2.readJson)(proposedRoot, constants_2.piletJson));
|
|
601
|
+
const appPackages = await findPiralInstances(app && [app], piletPackage, piletDefinition, root);
|
|
602
|
+
const apps = [];
|
|
603
|
+
for (const appPackage of appPackages) {
|
|
604
|
+
const appFile = appPackage?.app;
|
|
605
|
+
const appRoot = appPackage?.root;
|
|
606
|
+
const appPort = appPackage?.port;
|
|
607
|
+
if (!appFile || !appRoot) {
|
|
608
|
+
(0, log_1.fail)('appInstanceInvalid_0011');
|
|
639
609
|
}
|
|
640
|
-
const
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
}
|
|
653
|
-
|
|
610
|
+
const emulator = checkAppShellPackage(appPackage);
|
|
611
|
+
apps.push({
|
|
612
|
+
appPackage,
|
|
613
|
+
appFile,
|
|
614
|
+
appRoot,
|
|
615
|
+
emulator,
|
|
616
|
+
appPort,
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
const importmap = await (0, importmap_1.readImportmap)(root, piletPackage, piletDefinition?.importmapVersions, 'remote');
|
|
620
|
+
return {
|
|
621
|
+
dependencies: piletPackage.dependencies || {},
|
|
622
|
+
devDependencies: piletPackage.devDependencies || {},
|
|
623
|
+
peerDependencies: piletPackage.peerDependencies || {},
|
|
624
|
+
peerModules: piletPackage.peerModules || [],
|
|
625
|
+
ignored: checkArrayOrUndefined(piletPackage, 'preservedDependencies'),
|
|
626
|
+
schema: piletDefinition?.schemaVersion,
|
|
627
|
+
importmap,
|
|
628
|
+
apps,
|
|
629
|
+
piletPackage,
|
|
630
|
+
root,
|
|
631
|
+
};
|
|
654
632
|
}
|
|
655
633
|
exports.retrievePiletData = retrievePiletData;
|
|
656
634
|
//# sourceMappingURL=package.js.map
|