piral-cli 1.4.0-beta.6250 → 1.4.0-beta.6253
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 +428 -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 +50 -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 +5 -1
- package/lib/common/website.js +71 -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 +23 -17
- package/src/common/shell.ts +2 -1
- package/src/common/website.ts +47 -16
- 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,52 @@ function getPiralPath(root, name) {
|
|
|
134
110
|
return (0, path_1.dirname)(path);
|
|
135
111
|
}
|
|
136
112
|
exports.getPiralPath = getPiralPath;
|
|
137
|
-
function
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
(0, log_1.log)('generalDebug_0003', `
|
|
153
|
-
|
|
154
|
-
return yield findPiralInstance(proposedApp, rootDir, rest);
|
|
113
|
+
async function loadPiralInstance(root, details) {
|
|
114
|
+
(0, log_1.log)('generalDebug_0003', `Following the app package in "${root}" ...`);
|
|
115
|
+
const appPackage = await (0, io_2.readJson)(root, constants_1.packageJson);
|
|
116
|
+
const relPath = appPackage.app;
|
|
117
|
+
appPackage.app = relPath && (0, path_1.resolve)(root, relPath);
|
|
118
|
+
appPackage.root = root;
|
|
119
|
+
appPackage.port = details?.port || 0;
|
|
120
|
+
return appPackage;
|
|
121
|
+
}
|
|
122
|
+
async function findPiralInstance(proposedApp, rootDir, details) {
|
|
123
|
+
const path = (0, npm_2.findPackageRoot)(proposedApp, rootDir);
|
|
124
|
+
const url = details?.url;
|
|
125
|
+
if (path) {
|
|
126
|
+
const root = (0, path_1.dirname)(path);
|
|
127
|
+
if (url) {
|
|
128
|
+
(0, log_1.log)('generalDebug_0003', `Updating the emulator from remote "${url}" ...`);
|
|
129
|
+
await (0, website_1.updateFromEmulatorWebsite)(root, url);
|
|
155
130
|
}
|
|
156
|
-
|
|
157
|
-
}
|
|
131
|
+
return await loadPiralInstance(root, details);
|
|
132
|
+
}
|
|
133
|
+
else if (url) {
|
|
134
|
+
(0, log_1.log)('generalDebug_0003', `Piral instance not installed yet - trying from remote "${url}" ...`);
|
|
135
|
+
const emulator = await (0, website_1.scaffoldFromEmulatorWebsite)(rootDir, url);
|
|
136
|
+
return await loadPiralInstance(emulator.path, details);
|
|
137
|
+
}
|
|
138
|
+
(0, log_1.fail)('appInstanceNotFound_0010', proposedApp);
|
|
158
139
|
}
|
|
159
140
|
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]); }));
|
|
141
|
+
async function findPiralInstances(proposedApps, piletPackage, piletDefinition, rootDir) {
|
|
142
|
+
if (proposedApps) {
|
|
143
|
+
// do nothing
|
|
144
|
+
}
|
|
145
|
+
else if (piletDefinition) {
|
|
146
|
+
const availableApps = Object.keys(piletDefinition.piralInstances || {});
|
|
147
|
+
proposedApps = availableApps.filter((m) => piletDefinition.piralInstances[m].selected);
|
|
148
|
+
if (proposedApps.length === 0) {
|
|
149
|
+
proposedApps = availableApps.slice(0, 1);
|
|
178
150
|
}
|
|
179
|
-
|
|
180
|
-
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
proposedApps = [piletPackage.piral?.name].filter(Boolean);
|
|
154
|
+
}
|
|
155
|
+
if (proposedApps.length > 0) {
|
|
156
|
+
return Promise.all(proposedApps.map((proposedApp) => findPiralInstance(proposedApp, rootDir, piletDefinition?.piralInstances?.[proposedApp])));
|
|
157
|
+
}
|
|
158
|
+
return [];
|
|
181
159
|
}
|
|
182
160
|
exports.findPiralInstances = findPiralInstances;
|
|
183
161
|
function readPiralPackage(root, name) {
|
|
@@ -186,133 +164,128 @@ function readPiralPackage(root, name) {
|
|
|
186
164
|
return (0, io_2.readJson)(path, constants_1.packageJson);
|
|
187
165
|
}
|
|
188
166
|
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.`);
|
|
167
|
+
async function patchPiralPackage(root, app, data, version, bundler) {
|
|
168
|
+
(0, log_1.log)('generalDebug_0003', `Patching the ${constants_1.packageJson} in "${root}" ...`);
|
|
169
|
+
const pkg = await getPiralPackage(app, data, version, bundler);
|
|
170
|
+
await (0, io_2.updateExistingJson)(root, constants_1.packageJson, pkg);
|
|
171
|
+
(0, log_1.log)('generalDebug_0003', `Succesfully patched the ${constants_1.packageJson}.`);
|
|
172
|
+
await (0, io_2.updateExistingJson)(root, constants_2.piralJson, {
|
|
173
|
+
$schema: constants_1.piralJsonSchemaUrl,
|
|
174
|
+
pilets: getPiletsInfo({}),
|
|
200
175
|
});
|
|
176
|
+
(0, log_1.log)('generalDebug_0003', `Succesfully patched the pilet.json.`);
|
|
201
177
|
}
|
|
202
178
|
exports.patchPiralPackage = patchPiralPackage;
|
|
203
|
-
function getPiralPackage(app, data, version, bundler) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
179
|
+
async function getPiralPackage(app, data, version, bundler) {
|
|
180
|
+
const framework = data.packageName;
|
|
181
|
+
const devDependencies = {
|
|
182
|
+
...(0, language_1.getDevDependencies)(data.language, (0, language_2.getDevDependencyPackages)(framework, data.reactVersion, data.reactRouterVersion)),
|
|
183
|
+
'piral-cli': `${version}`,
|
|
184
|
+
};
|
|
185
|
+
const dependencies = {
|
|
186
|
+
...(0, language_2.getFrameworkDependencies)(framework, version),
|
|
187
|
+
...(0, language_1.getDependencies)(data.language, (0, language_1.getDependencyPackages)(framework, data.reactVersion, data.reactRouterVersion)),
|
|
188
|
+
};
|
|
189
|
+
await appendBundler(devDependencies, bundler, version);
|
|
190
|
+
return {
|
|
191
|
+
app,
|
|
192
|
+
scripts: {
|
|
193
|
+
start: 'piral debug',
|
|
194
|
+
build: 'piral build',
|
|
195
|
+
postinstall: 'piral declaration',
|
|
196
|
+
},
|
|
197
|
+
types: 'dist/index.d.ts',
|
|
198
|
+
importmap: {
|
|
199
|
+
imports: {},
|
|
200
|
+
inherit: [
|
|
201
|
+
'piral-base',
|
|
202
|
+
framework !== 'piral-base' && 'piral-core',
|
|
203
|
+
framework === 'piral' && 'piral', // this we take only if we selected piral
|
|
204
|
+
].filter(Boolean),
|
|
205
|
+
},
|
|
206
|
+
dependencies,
|
|
207
|
+
devDependencies,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
exports.getPiralPackage = getPiralPackage;
|
|
211
|
+
async function getAvailableFiles(root, name, dirName, fileMap) {
|
|
212
|
+
const source = getPiralPath(root, name);
|
|
213
|
+
const tgz = `${dirName}.tar`;
|
|
214
|
+
(0, log_1.log)('generalDebug_0003', `Checking if "${tgz}" exists in "${source}" ...`);
|
|
215
|
+
const exists = await (0, io_2.checkExists)((0, path_1.resolve)(source, tgz));
|
|
216
|
+
if (exists) {
|
|
217
|
+
await (0, archive_1.unpackTarball)(source, tgz);
|
|
218
|
+
}
|
|
219
|
+
(0, log_1.log)('generalDebug_0003', `Get matching files from "${source}".`);
|
|
220
|
+
const base = (0, path_1.resolve)(source, dirName);
|
|
221
|
+
const files = await (0, io_1.matchFiles)(base, '**/*');
|
|
222
|
+
return files.map((file) => ({
|
|
223
|
+
sourcePath: file,
|
|
224
|
+
targetPath: (0, path_1.resolve)(root, (0, path_1.relative)(base, file)),
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
async function getFileStats(root, name, fileMap = []) {
|
|
228
|
+
const files = await getAvailableFiles(root, name, constants_1.filesTar, fileMap);
|
|
229
|
+
return await Promise.all(files.map(async (file) => {
|
|
230
|
+
const { sourcePath, targetPath } = file;
|
|
231
|
+
const sourceHash = await (0, io_1.getHash)(sourcePath);
|
|
232
|
+
(0, log_1.log)('generalDebug_0003', `Obtained hash from "${sourcePath}": ${sourceHash}`);
|
|
233
|
+
const targetHash = await (0, io_1.getHash)(targetPath);
|
|
234
|
+
(0, log_1.log)('generalDebug_0003', `Obtained hash from "${targetPath}": ${targetHash}`);
|
|
209
235
|
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,
|
|
236
|
+
path: targetPath,
|
|
237
|
+
hash: targetHash,
|
|
238
|
+
changed: sourceHash !== targetHash,
|
|
227
239
|
};
|
|
228
|
-
});
|
|
240
|
+
}));
|
|
229
241
|
}
|
|
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));
|
|
242
|
+
exports.getFileStats = getFileStats;
|
|
243
|
+
async function copyFiles(subfiles, forceOverwrite, originalFiles, variables) {
|
|
244
|
+
for (const subfile of subfiles) {
|
|
245
|
+
const { sourcePath, targetPath } = subfile;
|
|
246
|
+
const exists = await (0, io_2.checkExists)(sourcePath);
|
|
237
247
|
if (exists) {
|
|
238
|
-
|
|
248
|
+
const overwrite = originalFiles.some((m) => m.path === targetPath && !m.changed);
|
|
249
|
+
const force = overwrite ? enums_1.ForceOverwrite.yes : forceOverwrite;
|
|
250
|
+
await (0, io_2.copy)(sourcePath, targetPath, force);
|
|
239
251
|
}
|
|
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
|
-
}
|
|
252
|
+
else {
|
|
253
|
+
(0, log_1.fail)('cannotFindFile_0046', sourcePath);
|
|
280
254
|
}
|
|
281
|
-
}
|
|
255
|
+
}
|
|
282
256
|
}
|
|
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
|
-
});
|
|
257
|
+
async function copyScaffoldingFiles(source, target, files, piralInfo, variables) {
|
|
258
|
+
(0, log_1.log)('generalDebug_0003', `Copying the scaffolding files ...`);
|
|
259
|
+
const allFiles = [];
|
|
260
|
+
for (const file of files) {
|
|
261
|
+
const subfiles = await getMatchingFiles(source, target, file);
|
|
262
|
+
allFiles.push(...subfiles);
|
|
263
|
+
}
|
|
264
|
+
if (piralInfo) {
|
|
265
|
+
await extendPackageOverridesFromTemplateFragment(target, piralInfo, allFiles);
|
|
266
|
+
}
|
|
267
|
+
await copyFiles(allFiles, enums_1.ForceOverwrite.yes, [], variables);
|
|
296
268
|
}
|
|
297
269
|
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);
|
|
270
|
+
async function extendPackageOverridesFromTemplateFragment(root, piralInfo, files) {
|
|
271
|
+
const packageTarget = (0, path_1.resolve)(root, constants_1.packageJson);
|
|
272
|
+
for (let i = files.length; i--;) {
|
|
273
|
+
const file = files[i];
|
|
274
|
+
if (file.targetPath === packageTarget) {
|
|
275
|
+
const fragment = await (0, io_2.readJson)((0, path_1.dirname)(file.sourcePath), (0, path_1.basename)(file.sourcePath));
|
|
276
|
+
files.splice(i, 1);
|
|
277
|
+
if (!piralInfo.pilets) {
|
|
278
|
+
piralInfo.pilets = {};
|
|
313
279
|
}
|
|
280
|
+
if (!piralInfo.pilets.packageOverrides) {
|
|
281
|
+
piralInfo.pilets.packageOverrides = {};
|
|
282
|
+
}
|
|
283
|
+
piralInfo.pilets.packageOverrides = {
|
|
284
|
+
...piralInfo.pilets.packageOverrides,
|
|
285
|
+
...fragment,
|
|
286
|
+
};
|
|
314
287
|
}
|
|
315
|
-
}
|
|
288
|
+
}
|
|
316
289
|
}
|
|
317
290
|
function isTemplateFileLocation(item) {
|
|
318
291
|
return typeof item === 'object';
|
|
@@ -322,24 +295,22 @@ function tryFindPackageVersion(packageName) {
|
|
|
322
295
|
const { version } = require(`${packageName}/${constants_1.packageJson}`);
|
|
323
296
|
return version;
|
|
324
297
|
}
|
|
325
|
-
catch
|
|
298
|
+
catch {
|
|
326
299
|
return undefined;
|
|
327
300
|
}
|
|
328
301
|
}
|
|
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
|
-
});
|
|
302
|
+
async function copyPiralFiles(root, name, piralInfo, forceOverwrite, variables, originalFiles) {
|
|
303
|
+
(0, log_1.log)('generalDebug_0003', `Copying the Piral files ...`);
|
|
304
|
+
const { files: _files } = getPiletsInfo(piralInfo);
|
|
305
|
+
const fileMap = _files.filter(isTemplateFileLocation);
|
|
306
|
+
const files = await getAvailableFiles(root, name, constants_1.filesTar, fileMap);
|
|
307
|
+
if (originalFiles === undefined) {
|
|
308
|
+
const initialFiles = await getAvailableFiles(root, name, constants_1.filesOnceTar, fileMap);
|
|
309
|
+
files.push(...initialFiles);
|
|
310
|
+
originalFiles = [];
|
|
311
|
+
}
|
|
312
|
+
await extendPackageOverridesFromTemplateFragment(root, piralInfo, files);
|
|
313
|
+
await copyFiles(files, forceOverwrite, originalFiles, variables);
|
|
343
314
|
}
|
|
344
315
|
exports.copyPiralFiles = copyPiralFiles;
|
|
345
316
|
function getPiletsInfo(piralInfo) {
|
|
@@ -358,27 +329,25 @@ function getPiletsInfo(piralInfo) {
|
|
|
358
329
|
};
|
|
359
330
|
}
|
|
360
331
|
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);
|
|
332
|
+
async function retrievePiralRoot(baseDir, entry) {
|
|
333
|
+
const rootDir = (0, path_1.join)(baseDir, entry);
|
|
334
|
+
(0, log_1.log)('generalDebug_0003', `Retrieving Piral root from "${rootDir}" ...`);
|
|
335
|
+
if (!constants_2.declarationEntryExtensions.includes((0, path_1.extname)(rootDir).toLowerCase())) {
|
|
336
|
+
const packageName = (0, path_1.basename)(rootDir) === constants_1.packageJson ? rootDir : (0, path_1.join)(rootDir, constants_1.packageJson);
|
|
337
|
+
(0, log_1.log)('generalDebug_0003', `Trying to get entry point from "${packageName}".`);
|
|
338
|
+
const exists = await (0, io_2.checkExists)(packageName);
|
|
339
|
+
if (!exists) {
|
|
340
|
+
(0, log_1.fail)('entryPointMissing_0070', rootDir);
|
|
378
341
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
342
|
+
const { app } = require(packageName);
|
|
343
|
+
if (!app) {
|
|
344
|
+
(0, log_1.fail)('entryPointMissing_0071');
|
|
345
|
+
}
|
|
346
|
+
(0, log_1.log)('generalDebug_0003', `Found app entry point in "${app}".`);
|
|
347
|
+
return (0, path_1.join)((0, path_1.dirname)(packageName), app);
|
|
348
|
+
}
|
|
349
|
+
(0, log_1.log)('generalDebug_0003', `Found app entry point in "${rootDir}".`);
|
|
350
|
+
return rootDir;
|
|
382
351
|
}
|
|
383
352
|
exports.retrievePiralRoot = retrievePiralRoot;
|
|
384
353
|
function checkArrayOrUndefined(obj, key) {
|
|
@@ -391,57 +360,52 @@ function checkArrayOrUndefined(obj, key) {
|
|
|
391
360
|
}
|
|
392
361
|
return undefined;
|
|
393
362
|
}
|
|
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
|
-
}
|
|
363
|
+
async function findDependencyVersion(pckg, rootPath, dependency) {
|
|
364
|
+
const { devDependencies = {}, dependencies = {} } = pckg;
|
|
365
|
+
const packageName = dependency.name;
|
|
366
|
+
const desiredVersion = dependencies[packageName] ?? devDependencies[packageName];
|
|
367
|
+
const [parent] = dependency.parents || [];
|
|
368
|
+
if (desiredVersion) {
|
|
369
|
+
if ((0, npm_1.isNpmPackage)(desiredVersion)) {
|
|
370
|
+
return desiredVersion;
|
|
411
371
|
}
|
|
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
|
-
}
|
|
372
|
+
else if ((0, npm_1.isGitPackage)(desiredVersion)) {
|
|
373
|
+
return (0, npm_1.makeGitUrl)(desiredVersion);
|
|
419
374
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return (0, npm_2.makeNpmAlias)(dependency.alias, version);
|
|
375
|
+
else if ((0, npm_1.isLocalPackage)(rootPath, desiredVersion)) {
|
|
376
|
+
return (0, npm_1.makeFilePath)(rootPath, desiredVersion);
|
|
423
377
|
}
|
|
424
|
-
|
|
425
|
-
|
|
378
|
+
}
|
|
379
|
+
if (parent) {
|
|
380
|
+
// in case the dependency came from another package (= parent)
|
|
381
|
+
// we should start the lookup in its directory (pnpm issue)
|
|
382
|
+
const parentPath = (0, npm_1.tryResolvePackage)(parent, rootPath);
|
|
383
|
+
if (parentPath) {
|
|
384
|
+
rootPath = (0, path_1.dirname)(parentPath);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
const version = await findPackageVersion(rootPath, packageName);
|
|
388
|
+
if (dependency.alias) {
|
|
389
|
+
return (0, npm_2.makeNpmAlias)(dependency.alias, version);
|
|
390
|
+
}
|
|
391
|
+
return version;
|
|
426
392
|
}
|
|
427
393
|
exports.findDependencyVersion = findDependencyVersion;
|
|
428
|
-
function findPackageVersion(rootPath, packageName) {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
return version;
|
|
439
|
-
}
|
|
440
|
-
catch (_a) { }
|
|
394
|
+
async function findPackageVersion(rootPath, packageName) {
|
|
395
|
+
const packages = Array.isArray(packageName) ? packageName : [packageName];
|
|
396
|
+
for (const pckg of packages) {
|
|
397
|
+
try {
|
|
398
|
+
(0, log_1.log)('generalDebug_0003', `Finding the version of "${packageName}" in "${rootPath}".`);
|
|
399
|
+
const moduleName = (0, external_1.getModulePath)(rootPath, pckg);
|
|
400
|
+
const packageJsonPath = await (0, io_2.findFile)(moduleName, constants_1.packageJson);
|
|
401
|
+
const root = (0, path_1.dirname)(packageJsonPath);
|
|
402
|
+
const { version } = await (0, io_2.readJson)(root, constants_1.packageJson);
|
|
403
|
+
return version;
|
|
441
404
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
405
|
+
catch { }
|
|
406
|
+
}
|
|
407
|
+
(0, log_1.log)('cannotResolveDependency_0053', packages, rootPath);
|
|
408
|
+
return 'latest';
|
|
445
409
|
}
|
|
446
410
|
exports.findPackageVersion = findPackageVersion;
|
|
447
411
|
function flattenExternals(dependencies, disableAsync = false) {
|
|
@@ -449,51 +413,61 @@ function flattenExternals(dependencies, disableAsync = false) {
|
|
|
449
413
|
return dependencies.map(getName).filter(utils_1.onlyUnique);
|
|
450
414
|
}
|
|
451
415
|
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
|
-
|
|
416
|
+
async function retrieveExternals(root, packageInfo) {
|
|
417
|
+
const importmap = await (0, importmap_1.readImportmap)(root, packageInfo, 'exact', 'host');
|
|
418
|
+
if (importmap.length === 0) {
|
|
419
|
+
const allDeps = {
|
|
420
|
+
...packageInfo.devDependencies,
|
|
421
|
+
...packageInfo.dependencies,
|
|
422
|
+
};
|
|
423
|
+
const deps = packageInfo.pilets?.externals;
|
|
424
|
+
const externals = await (0, npm_2.makeExternals)(root, allDeps, deps);
|
|
425
|
+
return externals.map((ext) => ({
|
|
426
|
+
id: ext,
|
|
427
|
+
name: ext,
|
|
428
|
+
entry: ext,
|
|
429
|
+
type: 'local',
|
|
430
|
+
ref: undefined,
|
|
431
|
+
requireId: ext,
|
|
432
|
+
}));
|
|
433
|
+
}
|
|
434
|
+
return importmap;
|
|
471
435
|
}
|
|
472
436
|
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
|
-
|
|
437
|
+
async function retrievePiletsInfo(entryFile) {
|
|
438
|
+
const exists = await (0, io_2.checkExists)(entryFile);
|
|
439
|
+
if (!exists) {
|
|
440
|
+
(0, log_1.fail)('entryPointDoesNotExist_0073', entryFile);
|
|
441
|
+
}
|
|
442
|
+
const packageJsonPath = await (0, io_2.findFile)(entryFile, constants_1.packageJson);
|
|
443
|
+
if (!packageJsonPath) {
|
|
444
|
+
(0, log_1.fail)('packageJsonMissing_0074');
|
|
445
|
+
}
|
|
446
|
+
const root = (0, path_1.dirname)(packageJsonPath);
|
|
447
|
+
const packageInfo = await (0, io_2.readJson)(root, constants_1.packageJson);
|
|
448
|
+
const piralJsonPkg = await (0, io_2.readJson)(root, constants_2.piralJson);
|
|
449
|
+
const pilets = {
|
|
450
|
+
...getPiletsInfo(packageInfo),
|
|
451
|
+
...piralJsonPkg.pilets,
|
|
452
|
+
};
|
|
453
|
+
const externals = await retrieveExternals(root, packageInfo);
|
|
454
|
+
const dependencies = {
|
|
455
|
+
std: packageInfo.dependencies || {},
|
|
456
|
+
dev: packageInfo.devDependencies || {},
|
|
457
|
+
peer: packageInfo.peerDependencies || {},
|
|
458
|
+
};
|
|
459
|
+
const framework = constants_2.frameworkLibs.find((lib) => lib in dependencies.std || lib in dependencies.dev);
|
|
460
|
+
return {
|
|
461
|
+
...pilets,
|
|
462
|
+
externals,
|
|
463
|
+
name: packageInfo.name,
|
|
464
|
+
version: packageInfo.version,
|
|
465
|
+
framework,
|
|
466
|
+
dependencies,
|
|
467
|
+
scripts: packageInfo.scripts,
|
|
468
|
+
ignored: checkArrayOrUndefined(packageInfo, 'preservedDependencies'),
|
|
469
|
+
root,
|
|
470
|
+
};
|
|
497
471
|
}
|
|
498
472
|
exports.retrievePiletsInfo = retrievePiletsInfo;
|
|
499
473
|
// This is an ugly workaround for having *some* packages that
|
|
@@ -518,55 +492,65 @@ function isValidDependency(name) {
|
|
|
518
492
|
return name.indexOf('/') === -1 || (name.indexOf('@') === 0 && name.split('/').length < 3);
|
|
519
493
|
}
|
|
520
494
|
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
|
-
});
|
|
495
|
+
async function patchPiletPackage(root, piralInfo, fromEmulator, newInfo) {
|
|
496
|
+
(0, log_1.log)('generalDebug_0003', `Patching the ${constants_1.packageJson} in "${root}" ...`);
|
|
497
|
+
const pkg = await getPiletPackage(root, piralInfo, fromEmulator, newInfo);
|
|
498
|
+
await (0, io_2.updateExistingJson)(root, constants_1.packageJson, pkg);
|
|
499
|
+
(0, log_1.log)('generalDebug_0003', `Succesfully patched the ${constants_1.packageJson}.`);
|
|
528
500
|
}
|
|
529
501
|
exports.patchPiletPackage = patchPiletPackage;
|
|
530
|
-
function getPiletPackage(root, piralInfo, fromEmulator, newInfo) {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
502
|
+
async function getPiletPackage(root, piralInfo, fromEmulator, newInfo) {
|
|
503
|
+
const { piralCLI = { version: info_1.cliVersion } } = piralInfo;
|
|
504
|
+
const { packageOverrides, ...info } = getPiletsInfo(piralInfo);
|
|
505
|
+
const existingData = newInfo ? {} : await (0, io_2.readJson)(root, constants_1.packageJson);
|
|
506
|
+
const piralDependencies = {
|
|
507
|
+
...piralInfo.devDependencies,
|
|
508
|
+
...piralInfo.dependencies,
|
|
509
|
+
};
|
|
510
|
+
const toolVersion = piralCLI.version;
|
|
511
|
+
const typeDependencies = newInfo ? (0, language_1.getDevDependencies)(newInfo.language) : {};
|
|
512
|
+
const scripts = newInfo
|
|
513
|
+
? {
|
|
514
|
+
start: 'pilet debug',
|
|
515
|
+
build: 'pilet build',
|
|
516
|
+
upgrade: 'pilet upgrade',
|
|
517
|
+
...info.scripts,
|
|
518
|
+
}
|
|
519
|
+
: info.scripts;
|
|
520
|
+
const allExternals = await (0, npm_2.makePiletExternals)(root, piralDependencies, fromEmulator, piralInfo);
|
|
521
|
+
const devDependencies = {
|
|
522
|
+
...Object.keys(typeDependencies).reduce((deps, name) => {
|
|
542
523
|
deps[name] = piralDependencies[name] || typeDependencies[name];
|
|
543
524
|
return deps;
|
|
544
|
-
}, {})
|
|
525
|
+
}, {}),
|
|
526
|
+
...Object.keys(info.devDependencies).reduce((deps, name) => {
|
|
545
527
|
deps[name] = getDependencyVersion(name, info.devDependencies, piralDependencies);
|
|
546
528
|
return deps;
|
|
547
|
-
}, {})
|
|
529
|
+
}, {}),
|
|
530
|
+
...allExternals.filter(isValidDependency).reduce((deps, name) => {
|
|
548
531
|
const existingDeps = existingData.devDependencies;
|
|
549
532
|
const shouldSpecify = newInfo || (existingDeps && name in existingDeps);
|
|
550
533
|
if (shouldSpecify) {
|
|
551
534
|
deps[name] = piralDependencies[name] || tryFindPackageVersion(name) || 'latest';
|
|
552
535
|
}
|
|
553
536
|
return deps;
|
|
554
|
-
}, {})
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
},
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
537
|
+
}, {}),
|
|
538
|
+
['piral-cli']: toolVersion,
|
|
539
|
+
};
|
|
540
|
+
const dependencies = {
|
|
541
|
+
['piral-cli']: undefined,
|
|
542
|
+
};
|
|
543
|
+
if (newInfo) {
|
|
544
|
+
await appendBundler(devDependencies, newInfo.bundler, toolVersion);
|
|
545
|
+
}
|
|
546
|
+
return (0, merge_1.deepMerge)(packageOverrides, {
|
|
547
|
+
importmap: {
|
|
548
|
+
imports: {},
|
|
549
|
+
inherit: [],
|
|
550
|
+
},
|
|
551
|
+
devDependencies,
|
|
552
|
+
dependencies,
|
|
553
|
+
scripts,
|
|
570
554
|
});
|
|
571
555
|
}
|
|
572
556
|
/**
|
|
@@ -602,55 +586,51 @@ function combinePiletExternals(appShells, peerDependencies, peerModules, importm
|
|
|
602
586
|
return externals;
|
|
603
587
|
}
|
|
604
588
|
exports.combinePiletExternals = combinePiletExternals;
|
|
605
|
-
function findPiletRoot(proposedRoot) {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
return (0, path_1.dirname)(packageJsonPath);
|
|
612
|
-
});
|
|
589
|
+
async function findPiletRoot(proposedRoot) {
|
|
590
|
+
const packageJsonPath = await (0, io_2.findFile)(proposedRoot, constants_1.packageJson);
|
|
591
|
+
if (!packageJsonPath) {
|
|
592
|
+
(0, log_1.fail)('packageJsonMissing_0075');
|
|
593
|
+
}
|
|
594
|
+
return (0, path_1.dirname)(packageJsonPath);
|
|
613
595
|
}
|
|
614
596
|
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
|
-
});
|
|
597
|
+
async function retrievePiletData(target, app) {
|
|
598
|
+
const piletJsonPath = await (0, io_2.findFile)(target, constants_2.piletJson);
|
|
599
|
+
const proposedRoot = piletJsonPath ? (0, path_1.dirname)(piletJsonPath) : target;
|
|
600
|
+
const root = await findPiletRoot(proposedRoot);
|
|
601
|
+
const piletPackage = await (0, io_2.readJson)(root, constants_1.packageJson);
|
|
602
|
+
const piletDefinition = piletJsonPath && (await (0, io_2.readJson)(proposedRoot, constants_2.piletJson));
|
|
603
|
+
const appPackages = await findPiralInstances(app && [app], piletPackage, piletDefinition, root);
|
|
604
|
+
const apps = [];
|
|
605
|
+
for (const appPackage of appPackages) {
|
|
606
|
+
const appFile = appPackage?.app;
|
|
607
|
+
const appRoot = appPackage?.root;
|
|
608
|
+
const appPort = appPackage?.port;
|
|
609
|
+
if (!appFile || !appRoot) {
|
|
610
|
+
(0, log_1.fail)('appInstanceInvalid_0011');
|
|
639
611
|
}
|
|
640
|
-
const
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
}
|
|
653
|
-
|
|
612
|
+
const emulator = checkAppShellPackage(appPackage);
|
|
613
|
+
apps.push({
|
|
614
|
+
appPackage,
|
|
615
|
+
appFile,
|
|
616
|
+
appRoot,
|
|
617
|
+
emulator,
|
|
618
|
+
appPort,
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
const importmap = await (0, importmap_1.readImportmap)(root, piletPackage, piletDefinition?.importmapVersions, 'remote');
|
|
622
|
+
return {
|
|
623
|
+
dependencies: piletPackage.dependencies || {},
|
|
624
|
+
devDependencies: piletPackage.devDependencies || {},
|
|
625
|
+
peerDependencies: piletPackage.peerDependencies || {},
|
|
626
|
+
peerModules: piletPackage.peerModules || [],
|
|
627
|
+
ignored: checkArrayOrUndefined(piletPackage, 'preservedDependencies'),
|
|
628
|
+
schema: piletDefinition?.schemaVersion,
|
|
629
|
+
importmap,
|
|
630
|
+
apps,
|
|
631
|
+
piletPackage,
|
|
632
|
+
root,
|
|
633
|
+
};
|
|
654
634
|
}
|
|
655
635
|
exports.retrievePiletData = retrievePiletData;
|
|
656
636
|
//# sourceMappingURL=package.js.map
|