piral-cli 0.15.0-beta.4472 → 0.15.0-beta.4549
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/apps/new-piral.js +1 -2
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/common/emulator.js +7 -0
- package/lib/common/emulator.js.map +1 -1
- package/lib/common/importmap.d.ts +1 -1
- package/lib/common/importmap.js +17 -2
- package/lib/common/importmap.js.map +1 -1
- package/lib/common/package.d.ts +7 -2
- package/lib/common/package.js +85 -48
- package/lib/common/package.js.map +1 -1
- package/lib/injectors/pilet-injector.d.ts +8 -6
- package/lib/injectors/pilet-injector.js +46 -25
- package/lib/injectors/pilet-injector.js.map +1 -1
- package/package.json +2 -2
- package/src/apps/new-piral.ts +3 -11
- package/src/common/emulator.ts +8 -0
- package/src/common/importmap.ts +20 -2
- package/src/common/package.test.ts +38 -5
- package/src/common/package.ts +71 -23
- package/src/injectors/pilet-injector.test.ts +3 -9
- package/src/injectors/pilet-injector.ts +59 -38
|
@@ -16,8 +16,7 @@ const log_1 = require("../common/log");
|
|
|
16
16
|
const spec_1 = require("../common/spec");
|
|
17
17
|
const config_1 = require("../common/config");
|
|
18
18
|
const external_1 = require("../external");
|
|
19
|
-
|
|
20
|
-
function fillPiletMeta(pilet, basePath, metaFile) {
|
|
19
|
+
function fillPiletMeta(pilet, metaFile, subPath) {
|
|
21
20
|
const { root, bundler } = pilet;
|
|
22
21
|
const metaPath = (0, path_1.join)(root, metaFile);
|
|
23
22
|
const packagePath = (0, path_1.join)(root, 'package.json');
|
|
@@ -25,10 +24,11 @@ function fillPiletMeta(pilet, basePath, metaFile) {
|
|
|
25
24
|
const metaOverride = (0, fs_1.existsSync)(metaPath) ? external_1.jju.parse((0, fs_1.readFileSync)(metaPath, 'utf8')) : undefined;
|
|
26
25
|
const file = bundler.bundle.name.replace(/^[\/\\]/, '');
|
|
27
26
|
const target = (0, path_1.join)(bundler.bundle.dir, file);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
pilet.getMeta = (parentPath) => {
|
|
28
|
+
const basePath = `${parentPath}${subPath}`;
|
|
29
|
+
const url = new url_1.URL(file, basePath);
|
|
30
|
+
return Object.assign(Object.assign(Object.assign({ custom: def.custom, config: def.piletConfig }, metaOverride), { name: def.name, version: def.version, link: `${url.href}?updated=${Date.now()}` }), (0, spec_1.getPiletSpecMeta)(target, basePath));
|
|
31
|
+
};
|
|
32
32
|
}
|
|
33
33
|
function loadFeed(feed) {
|
|
34
34
|
var _a;
|
|
@@ -51,29 +51,30 @@ function loadFeed(feed) {
|
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
class PiletInjector {
|
|
54
|
-
constructor(
|
|
55
|
-
this.config =
|
|
54
|
+
constructor(config, serverConfig, core) {
|
|
55
|
+
this.config = config;
|
|
56
|
+
this.serverConfig = serverConfig;
|
|
56
57
|
if (this.config.active) {
|
|
57
|
-
|
|
58
|
-
this.piletApi = /^https?:/.test(options.api)
|
|
59
|
-
? options.api
|
|
60
|
-
: `${config.ssl ? 'https' : 'http'}://${host}:${config.port}${options.api}`;
|
|
61
|
-
const { pilets, api, publicUrl } = options;
|
|
58
|
+
const { pilets, api, publicUrl } = config;
|
|
62
59
|
this.indexPath = `${publicUrl}index.html`;
|
|
63
60
|
const cbs = {};
|
|
64
61
|
core.on('user-connected', (e) => {
|
|
65
62
|
if (e.target === '*' && e.url === api.substring(1)) {
|
|
66
|
-
cbs[e.id] =
|
|
63
|
+
cbs[e.id] = {
|
|
64
|
+
baseUrl: e.req.headers.origin,
|
|
65
|
+
notify: (msg) => e.ws.send(msg),
|
|
66
|
+
};
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
core.on('user-disconnected', (e) => {
|
|
70
70
|
delete cbs[e.id];
|
|
71
71
|
});
|
|
72
72
|
pilets.forEach((p, i) => p.bundler.on(() => {
|
|
73
|
-
|
|
74
|
-
const meta = fillPiletMeta(p, basePath, options.meta);
|
|
73
|
+
fillPiletMeta(p, config.meta, `/${i}/`);
|
|
75
74
|
for (const id of Object.keys(cbs)) {
|
|
76
|
-
cbs[id]
|
|
75
|
+
const { baseUrl, notify } = cbs[id];
|
|
76
|
+
const meta = this.getPiletMeta(baseUrl, p);
|
|
77
|
+
notify(meta);
|
|
77
78
|
}
|
|
78
79
|
}));
|
|
79
80
|
}
|
|
@@ -91,10 +92,29 @@ class PiletInjector {
|
|
|
91
92
|
return {};
|
|
92
93
|
}
|
|
93
94
|
setOptions() { }
|
|
94
|
-
|
|
95
|
+
getPiletApi(baseUrl) {
|
|
96
|
+
const { api } = this.config;
|
|
97
|
+
if (/^https?:/.test(api)) {
|
|
98
|
+
return api;
|
|
99
|
+
}
|
|
100
|
+
else if (baseUrl) {
|
|
101
|
+
return `${baseUrl}${api}`;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const { ssl, port } = this.serverConfig;
|
|
105
|
+
const { host } = config_1.config;
|
|
106
|
+
return `${ssl ? 'https' : 'http'}://${host}:${port}${api}`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
getPiletMeta(baseUrl, pilet) {
|
|
110
|
+
const basePath = this.getPiletApi(baseUrl);
|
|
111
|
+
return JSON.stringify(pilet.getMeta(basePath));
|
|
112
|
+
}
|
|
113
|
+
getIndexMeta(baseUrl) {
|
|
95
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
115
|
const { pilets, feed } = this.config;
|
|
97
|
-
const
|
|
116
|
+
const basePath = this.getPiletApi(baseUrl);
|
|
117
|
+
const localPilets = pilets.map((pilet) => { var _a; return (_a = pilet.getMeta) === null || _a === void 0 ? void 0 : _a.call(pilet, basePath); }).filter(Boolean);
|
|
98
118
|
const mergedPilets = this.mergePilets(localPilets, yield this.loadRemoteFeed(feed));
|
|
99
119
|
return JSON.stringify(mergedPilets);
|
|
100
120
|
});
|
|
@@ -136,7 +156,7 @@ class PiletInjector {
|
|
|
136
156
|
const type = (_a = external_1.mime.getType(target)) !== null && _a !== void 0 ? _a : 'application/octet-stream';
|
|
137
157
|
return this.sendContent(content, type, url);
|
|
138
158
|
}
|
|
139
|
-
sendResponse(path, url) {
|
|
159
|
+
sendResponse(path, url, baseUrl) {
|
|
140
160
|
return __awaiter(this, void 0, void 0, function* () {
|
|
141
161
|
const { pilets } = this.config;
|
|
142
162
|
const [index, ...rest] = path.split('/');
|
|
@@ -144,7 +164,7 @@ class PiletInjector {
|
|
|
144
164
|
const bundler = pilet === null || pilet === void 0 ? void 0 : pilet.bundler;
|
|
145
165
|
if (!path) {
|
|
146
166
|
yield (bundler === null || bundler === void 0 ? void 0 : bundler.ready());
|
|
147
|
-
const content = yield this.
|
|
167
|
+
const content = yield this.getIndexMeta(baseUrl);
|
|
148
168
|
return this.sendContent(content, 'application/json', url);
|
|
149
169
|
}
|
|
150
170
|
else {
|
|
@@ -157,10 +177,10 @@ class PiletInjector {
|
|
|
157
177
|
}
|
|
158
178
|
});
|
|
159
179
|
}
|
|
160
|
-
sendIndexFile(target, url) {
|
|
180
|
+
sendIndexFile(target, url, baseUrl) {
|
|
161
181
|
const indexHtml = (0, fs_1.readFileSync)(target, 'utf8');
|
|
162
182
|
// mechanism to inject server side debug piletApi config into piral emulator
|
|
163
|
-
const windowInjectionScript = `window['dbg:pilet-api'] = '${this.
|
|
183
|
+
const windowInjectionScript = `window['dbg:pilet-api'] = '${this.getPiletApi(baseUrl)}';`;
|
|
164
184
|
const findStr = `<script`;
|
|
165
185
|
const replaceStr = `<script>/* Pilet Debugging Emulator Config Injection */${windowInjectionScript}</script><script`;
|
|
166
186
|
const content = indexHtml.replace(`${findStr}`, `${replaceStr}`);
|
|
@@ -168,13 +188,14 @@ class PiletInjector {
|
|
|
168
188
|
}
|
|
169
189
|
handle(req) {
|
|
170
190
|
const { app, api, publicUrl } = this.config;
|
|
191
|
+
const baseUrl = req.headers.host ? `${req.encrypted ? 'https' : 'http'}://${req.headers.host}` : undefined;
|
|
171
192
|
if (!req.target) {
|
|
172
193
|
if (req.url.startsWith(publicUrl)) {
|
|
173
194
|
const path = req.url.substring(publicUrl.length).split('?')[0];
|
|
174
195
|
const target = (0, path_1.join)(app, path);
|
|
175
196
|
if ((0, fs_1.existsSync)(target) && (0, fs_1.statSync)(target).isFile()) {
|
|
176
197
|
if (req.url === this.indexPath) {
|
|
177
|
-
return this.sendIndexFile(target, req.url);
|
|
198
|
+
return this.sendIndexFile(target, req.url, baseUrl);
|
|
178
199
|
}
|
|
179
200
|
else {
|
|
180
201
|
return this.sendFile(target, req.url);
|
|
@@ -188,7 +209,7 @@ class PiletInjector {
|
|
|
188
209
|
}
|
|
189
210
|
else if (req.target === api) {
|
|
190
211
|
const path = req.url.substring(1).split('?')[0];
|
|
191
|
-
return this.sendResponse(path, req.url);
|
|
212
|
+
return this.sendResponse(path, req.url, baseUrl);
|
|
192
213
|
}
|
|
193
214
|
}
|
|
194
215
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pilet-injector.js","sourceRoot":"","sources":["../../src/injectors/pilet-injector.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6BAA0B;AAC1B,+BAA4B;AAE5B,2BAAwD;AAExD,uCAAoC;AACpC,yCAAkD;AAClD,
|
|
1
|
+
{"version":3,"file":"pilet-injector.js","sourceRoot":"","sources":["../../src/injectors/pilet-injector.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6BAA0B;AAC1B,+BAA4B;AAE5B,2BAAwD;AAExD,uCAAoC;AACpC,yCAAkD;AAClD,6CAA0D;AAC1D,0CAA+C;AAwB/C,SAAS,aAAa,CAAC,KAAY,EAAE,QAAgB,EAAE,OAAe;IACpE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAChC,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACtC,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,IAAI,EAAE,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AAM,EAAE,EAAE;oBACnD,IAAI,GAAG,CAAC,GAAG,KAAK,IAAI,CAAC,SAAS,EAAE;wBAC9B,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;qBACrD;yBAAM;wBACL,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;qBACvC;iBACF;qBAAM,IAAI,GAAG,CAAC,GAAG,KAAK,IAAI,CAAC,SAAS,EAAE;oBACrC,OAAO,IAAI,CAAC,MAAM,iCACb,GAAG,KACN,GAAG,EAAE,IAAI,CAAC,SAAS,IACnB,CAAC;iBACJ;aACF;YAED,OAAO,SAAS,CAAC;SAClB;aAAM,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE;YAC7B,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAChD,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;SAClD;IACH,CAAC;CACF;AApMD,gCAoMC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-cli",
|
|
3
|
-
"version": "0.15.0-beta.
|
|
3
|
+
"version": "0.15.0-beta.4549",
|
|
4
4
|
"description": "The standard CLI for creating and building a Piral instance or a Pilet.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portal",
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"typescript": "^4.7.3",
|
|
79
79
|
"yargs": "^15.4.1"
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "ca7224ab671fd632fe9e5cfe9b7f573d9a105ce8"
|
|
82
82
|
}
|
package/src/apps/new-piral.ts
CHANGED
|
@@ -4,8 +4,7 @@ import { SourceLanguage, LogLevels, Framework, NpmClientType } from '../types';
|
|
|
4
4
|
import {
|
|
5
5
|
ForceOverwrite,
|
|
6
6
|
installNpmPackage,
|
|
7
|
-
|
|
8
|
-
getPiralPackage,
|
|
7
|
+
patchPiralPackage,
|
|
9
8
|
scaffoldPiralSourceFiles,
|
|
10
9
|
createDirectory,
|
|
11
10
|
createFileIfNotExists,
|
|
@@ -20,8 +19,6 @@ import {
|
|
|
20
19
|
getPiralScaffoldData,
|
|
21
20
|
config,
|
|
22
21
|
initNpmProject,
|
|
23
|
-
logInfo,
|
|
24
|
-
getPiletsInfo,
|
|
25
22
|
} from '../common';
|
|
26
23
|
|
|
27
24
|
export interface NewPiralOptions {
|
|
@@ -173,11 +170,7 @@ always-auth=true`,
|
|
|
173
170
|
);
|
|
174
171
|
}
|
|
175
172
|
|
|
176
|
-
await createFileIfNotExists(
|
|
177
|
-
root,
|
|
178
|
-
'piral.json',
|
|
179
|
-
JSON.stringify({}),
|
|
180
|
-
);
|
|
173
|
+
await createFileIfNotExists(root, 'piral.json', JSON.stringify({}));
|
|
181
174
|
|
|
182
175
|
progress(`Installing npm package ${packageRef} ...`);
|
|
183
176
|
|
|
@@ -187,8 +180,7 @@ always-auth=true`,
|
|
|
187
180
|
|
|
188
181
|
const data = getPiralScaffoldData(language, root, app, framework, variables);
|
|
189
182
|
|
|
190
|
-
await
|
|
191
|
-
await updateExistingJson(root, 'piral.json', { pilets: getPiletsInfo({}) });
|
|
183
|
+
await patchPiralPackage(root, app, data, version, bundlerName);
|
|
192
184
|
|
|
193
185
|
await scaffoldPiralSourceFiles(template, registry, data, forceOverwrite);
|
|
194
186
|
|
package/src/common/emulator.ts
CHANGED
|
@@ -44,6 +44,11 @@ export async function createEmulatorSources(
|
|
|
44
44
|
return deps;
|
|
45
45
|
}, {} as Record<string, string>);
|
|
46
46
|
|
|
47
|
+
const importmapEntries = externalPackages.reduce((deps, dep) => {
|
|
48
|
+
deps[dep.name] = dep.name;
|
|
49
|
+
return deps;
|
|
50
|
+
}, {} as Record<string, string>);
|
|
51
|
+
|
|
47
52
|
const rootDir = resolve(targetDir, '..');
|
|
48
53
|
const appDir = relative(rootDir, targetDir);
|
|
49
54
|
const filesDir = resolve(rootDir, filesTar);
|
|
@@ -70,6 +75,9 @@ export async function createEmulatorSources(
|
|
|
70
75
|
license: piralPkg.license,
|
|
71
76
|
homepage: piralPkg.homepage,
|
|
72
77
|
keywords: piralPkg.keywords,
|
|
78
|
+
importmap: {
|
|
79
|
+
imports: importmapEntries,
|
|
80
|
+
},
|
|
73
81
|
pilets: {
|
|
74
82
|
...piralPkg.pilets,
|
|
75
83
|
files: filesMap,
|
package/src/common/importmap.ts
CHANGED
|
@@ -152,7 +152,7 @@ async function resolveImportmap(dir: string, importmap: Importmap) {
|
|
|
152
152
|
if (packageJson) {
|
|
153
153
|
const packageDir = dirname(packageJson);
|
|
154
154
|
const packageDetails = require(packageJson);
|
|
155
|
-
const otherDependencies = await readImportmap(packageDir, packageDetails);
|
|
155
|
+
const otherDependencies = await readImportmap(packageDir, packageDetails, true);
|
|
156
156
|
|
|
157
157
|
for (const dependency of otherDependencies) {
|
|
158
158
|
const entry = dependencies.find((dep) => dep.name === dependency.name);
|
|
@@ -173,7 +173,11 @@ async function resolveImportmap(dir: string, importmap: Importmap) {
|
|
|
173
173
|
return dependencies;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
export async function readImportmap(
|
|
176
|
+
export async function readImportmap(
|
|
177
|
+
dir: string,
|
|
178
|
+
packageDetails: any,
|
|
179
|
+
inherited = false,
|
|
180
|
+
): Promise<Array<SharedDependency>> {
|
|
177
181
|
const importmap = packageDetails.importmap;
|
|
178
182
|
|
|
179
183
|
if (typeof importmap === 'string') {
|
|
@@ -186,6 +190,20 @@ export async function readImportmap(dir: string, packageDetails: any) {
|
|
|
186
190
|
|
|
187
191
|
const baseDir = dirname(resolve(dir, importmap));
|
|
188
192
|
return resolveImportmap(baseDir, content);
|
|
193
|
+
} else if (typeof importmap === 'undefined' && inherited) {
|
|
194
|
+
// Fall back to sharedDependencies or pilets.external if available
|
|
195
|
+
const shared: Array<string> = packageDetails.sharedDependencies ?? packageDetails.pilets?.externals;
|
|
196
|
+
|
|
197
|
+
if (Array.isArray(shared)) {
|
|
198
|
+
return shared.map((dep) => ({
|
|
199
|
+
id: dep,
|
|
200
|
+
name: dep,
|
|
201
|
+
entry: dep,
|
|
202
|
+
type: 'local',
|
|
203
|
+
ref: undefined,
|
|
204
|
+
requireId: dep,
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
189
207
|
}
|
|
190
208
|
|
|
191
209
|
return resolveImportmap(dir, importmap);
|
|
@@ -46,15 +46,48 @@ describe('CLI package module', () => {
|
|
|
46
46
|
expect(result).toStrictEqual(piralInfo.pilets);
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
it('getPiralPackage returns piral package', () => {
|
|
50
|
-
|
|
49
|
+
it('getPiralPackage returns piral package with webpack in latest version',async () => {
|
|
50
|
+
const result = await getPiralPackage(
|
|
51
51
|
'app',
|
|
52
52
|
{ language: 'ts', packageName: 'piral-base', reactRouterVersion: 5, reactVersion: 17 },
|
|
53
|
-
'
|
|
53
|
+
'10.0.0',
|
|
54
54
|
'webpack',
|
|
55
55
|
);
|
|
56
|
-
expect(result.devDependencies['piral-cli-webpack']).toEqual('
|
|
57
|
-
|
|
56
|
+
expect(result.devDependencies['piral-cli-webpack']).toEqual('latest');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('getPiralPackage returns piral package with webpack in beta version',async () => {
|
|
60
|
+
const result = await getPiralPackage(
|
|
61
|
+
'app',
|
|
62
|
+
{ language: 'ts', packageName: 'piral-base', reactRouterVersion: 5, reactVersion: 17 },
|
|
63
|
+
'0.15.0-beta.1',
|
|
64
|
+
'webpack',
|
|
65
|
+
);
|
|
66
|
+
expect(result.devDependencies['piral-cli-webpack']).toEqual('next');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('getPiralPackage returns piral package with webpack in alpha version',async () => {
|
|
70
|
+
const result = await getPiralPackage(
|
|
71
|
+
'app',
|
|
72
|
+
{ language: 'ts', packageName: 'piral-base', reactRouterVersion: 5, reactVersion: 17 },
|
|
73
|
+
'0.15.0-alpha.1',
|
|
74
|
+
'webpack',
|
|
75
|
+
);
|
|
76
|
+
expect(result.devDependencies['piral-cli-webpack']).toEqual('canary');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('getPiralPackage returns piral package with webpack in existing version',async () => {
|
|
80
|
+
const result = await getPiralPackage(
|
|
81
|
+
'app',
|
|
82
|
+
{ language: 'ts', packageName: 'piral-base', reactRouterVersion: 5, reactVersion: 17 },
|
|
83
|
+
'0.14.0',
|
|
84
|
+
'webpack',
|
|
85
|
+
);
|
|
86
|
+
expect(result.devDependencies['piral-cli-webpack']).toEqual('0.14.0');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('getPiralPackage returns piral package without bundler',async () => {
|
|
90
|
+
const result = await getPiralPackage(
|
|
58
91
|
'app',
|
|
59
92
|
{ language: 'ts', packageName: 'piral-base', reactRouterVersion: 5, reactVersion: 17 },
|
|
60
93
|
'1.0.0',
|
package/src/common/package.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { filesTar, filesOnceTar, declarationEntryExtensions, bundlerNames } from
|
|
|
11
11
|
import { getHash, checkIsDirectory, matchFiles } from './io';
|
|
12
12
|
import { readJson, copy, updateExistingJson, findFile, checkExists } from './io';
|
|
13
13
|
import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath } from './npm';
|
|
14
|
-
import { makePiletExternals, makeExternals, findPackageRoot } from './npm';
|
|
14
|
+
import { makePiletExternals, makeExternals, findPackageRoot, findSpecificVersion } from './npm';
|
|
15
15
|
import {
|
|
16
16
|
SourceLanguage,
|
|
17
17
|
Framework,
|
|
@@ -22,18 +22,37 @@ import {
|
|
|
22
22
|
SharedDependency,
|
|
23
23
|
} from '../types';
|
|
24
24
|
|
|
25
|
-
function appendBundler(devDependencies: Record<string, string>, bundler: string,
|
|
25
|
+
async function appendBundler(devDependencies: Record<string, string>, bundler: string, proposedVersion: string) {
|
|
26
26
|
if (bundler && bundler !== 'none') {
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
if (isValidDependency(bundler)) {
|
|
28
|
+
const sep = bundler.indexOf('@', 1);
|
|
29
|
+
const hasVersion = sep !== -1;
|
|
30
|
+
const proposedName = bundler.substring(0, hasVersion ? sep : bundler.length);
|
|
31
|
+
const givenVersion = hasVersion ? bundler.substring(sep + 1) : proposedVersion;
|
|
32
|
+
const name = bundlerNames.includes(proposedName as any) ? `piral-cli-${bundler}` : proposedName;
|
|
33
|
+
const versions = new Set([
|
|
34
|
+
givenVersion,
|
|
35
|
+
givenVersion.includes('-beta.') && 'next',
|
|
36
|
+
givenVersion.includes('-alpha.') && 'canary',
|
|
37
|
+
'latest',
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
for (const version of versions) {
|
|
41
|
+
if (version) {
|
|
42
|
+
const isAvailable = await findSpecificVersion(name, version);
|
|
43
|
+
|
|
44
|
+
// only if something was returned we know that the version exists; so we can take it.
|
|
45
|
+
if (isAvailable) {
|
|
46
|
+
devDependencies[name] = version;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
log('generalWarning_0001', `Could not find a valid version for the provided bundler "${bundler}".'`);
|
|
53
|
+
} else {
|
|
30
54
|
//Error case - print warning and ignore
|
|
31
55
|
log('generalWarning_0001', `The provided bundler name "${bundler}" does not refer to a valid package name.'`);
|
|
32
|
-
} else {
|
|
33
|
-
const sep = bundler.indexOf('@', 1);
|
|
34
|
-
const name = bundler.substring(0, sep !== -1 ? sep : bundler.length);
|
|
35
|
-
const version = sep !== -1 ? bundler.substring(sep + 1) : 'latest';
|
|
36
|
-
devDependencies[name] = version;
|
|
37
56
|
}
|
|
38
57
|
}
|
|
39
58
|
}
|
|
@@ -160,7 +179,24 @@ export interface PiralPackageData {
|
|
|
160
179
|
reactRouterVersion: number;
|
|
161
180
|
}
|
|
162
181
|
|
|
163
|
-
export function
|
|
182
|
+
export async function patchPiralPackage(
|
|
183
|
+
root: string,
|
|
184
|
+
app: string,
|
|
185
|
+
data: PiralPackageData,
|
|
186
|
+
version: string,
|
|
187
|
+
bundler?: string,
|
|
188
|
+
) {
|
|
189
|
+
log('generalDebug_0003', `Patching the package.json in "${root}" ...`);
|
|
190
|
+
const pkg = await getPiralPackage(app, data, version, bundler);
|
|
191
|
+
|
|
192
|
+
await updateExistingJson(root, 'package.json', pkg);
|
|
193
|
+
log('generalDebug_0003', `Succesfully patched the package.json.`);
|
|
194
|
+
|
|
195
|
+
await updateExistingJson(root, 'piral.json', { pilets: getPiletsInfo({}) });
|
|
196
|
+
log('generalDebug_0003', `Succesfully patched the pilet.json.`);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export async function getPiralPackage(app: string, data: PiralPackageData, version: string, bundler?: string) {
|
|
164
200
|
const framework = data.packageName;
|
|
165
201
|
const devDependencies = {
|
|
166
202
|
...getDevDependencies(
|
|
@@ -173,7 +209,7 @@ export function getPiralPackage(app: string, data: PiralPackageData, version: st
|
|
|
173
209
|
...getDependencies(data.language, getDependencyPackages(framework, data.reactVersion, data.reactRouterVersion)),
|
|
174
210
|
};
|
|
175
211
|
|
|
176
|
-
appendBundler(devDependencies, bundler, version);
|
|
212
|
+
await appendBundler(devDependencies, bundler, version);
|
|
177
213
|
|
|
178
214
|
return {
|
|
179
215
|
app,
|
|
@@ -507,6 +543,27 @@ export async function patchPiletPackage(
|
|
|
507
543
|
newInfo?: { language: SourceLanguage; bundler: string },
|
|
508
544
|
) {
|
|
509
545
|
log('generalDebug_0003', `Patching the package.json in "${root}" ...`);
|
|
546
|
+
const pkg = await getPiletPackage(root, name, version, piralInfo, fromEmulator, newInfo);
|
|
547
|
+
|
|
548
|
+
await updateExistingJson(root, 'package.json', pkg);
|
|
549
|
+
log('generalDebug_0003', `Succesfully patched the package.json.`);
|
|
550
|
+
|
|
551
|
+
await updateExistingJson(root, 'pilet.json', {
|
|
552
|
+
piralInstances: {
|
|
553
|
+
[name]: {},
|
|
554
|
+
},
|
|
555
|
+
});
|
|
556
|
+
log('generalDebug_0003', `Succesfully patched the pilet.json.`);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
export async function getPiletPackage(
|
|
560
|
+
root: string,
|
|
561
|
+
name: string,
|
|
562
|
+
version: string,
|
|
563
|
+
piralInfo: PackageData,
|
|
564
|
+
fromEmulator: boolean,
|
|
565
|
+
newInfo?: { language: SourceLanguage; bundler: string },
|
|
566
|
+
) {
|
|
510
567
|
const { externals, packageOverrides, ...info } = getPiletsInfo(piralInfo);
|
|
511
568
|
const piralDependencies = {
|
|
512
569
|
...piralInfo.devDependencies,
|
|
@@ -548,10 +605,10 @@ export async function patchPiletPackage(
|
|
|
548
605
|
const bundler = newInfo.bundler;
|
|
549
606
|
const version = `^${cliVersion}`;
|
|
550
607
|
devDependencies['piral-cli'] = version;
|
|
551
|
-
appendBundler(devDependencies, bundler, version);
|
|
608
|
+
await appendBundler(devDependencies, bundler, version);
|
|
552
609
|
}
|
|
553
610
|
|
|
554
|
-
|
|
611
|
+
return deepMerge(packageOverrides, {
|
|
555
612
|
importmap: {
|
|
556
613
|
imports: {},
|
|
557
614
|
inherit: [name],
|
|
@@ -561,16 +618,7 @@ export async function patchPiletPackage(
|
|
|
561
618
|
[name]: undefined,
|
|
562
619
|
},
|
|
563
620
|
scripts,
|
|
564
|
-
}));
|
|
565
|
-
|
|
566
|
-
log('generalDebug_0003', `Succesfully patched the package.json.`);
|
|
567
|
-
|
|
568
|
-
await updateExistingJson(root, 'pilet.json', {
|
|
569
|
-
piralInstances: {
|
|
570
|
-
[name]: {},
|
|
571
|
-
},
|
|
572
621
|
});
|
|
573
|
-
log('generalDebug_0003', `Succesfully patched the pilet.json.`);
|
|
574
622
|
}
|
|
575
623
|
|
|
576
624
|
/**
|
|
@@ -5,11 +5,9 @@ import PiletInjector from './pilet-injector';
|
|
|
5
5
|
const optionsMock = {
|
|
6
6
|
pilets: [],
|
|
7
7
|
publicUrl: '/',
|
|
8
|
-
meta: 'debug-meta.json',
|
|
9
8
|
api: '',
|
|
10
9
|
app: '',
|
|
11
10
|
active: true,
|
|
12
|
-
publicUrl: '/',
|
|
13
11
|
meta: '',
|
|
14
12
|
headers: {},
|
|
15
13
|
};
|
|
@@ -18,7 +16,7 @@ const configMock: any = {
|
|
|
18
16
|
port: 1234,
|
|
19
17
|
};
|
|
20
18
|
|
|
21
|
-
describe('Piral-CLI
|
|
19
|
+
describe('Piral-CLI pilet injector', () => {
|
|
22
20
|
it('PiletInjector is active when configured', () => {
|
|
23
21
|
const core = new EventEmitter();
|
|
24
22
|
const injector = new PiletInjector(optionsMock, configMock, core);
|
|
@@ -35,7 +33,7 @@ describe('Piral-CLI piral injector', () => {
|
|
|
35
33
|
injector.name;
|
|
36
34
|
injector.getOptions();
|
|
37
35
|
//injector.getMetaOf(0);
|
|
38
|
-
injector.
|
|
36
|
+
injector.getIndexMeta('http://localhost:9000');
|
|
39
37
|
|
|
40
38
|
// Assert
|
|
41
39
|
expect(injector.active).toBeFalsy();
|
|
@@ -78,7 +76,7 @@ describe('Piral-CLI piral injector', () => {
|
|
|
78
76
|
const injector = new PiletInjector(optionsMock, configMock, core);
|
|
79
77
|
|
|
80
78
|
// Act
|
|
81
|
-
const res = await injector.sendResponse('some/nice/invalid/path', 'localhost:1234');
|
|
79
|
+
const res = await injector.sendResponse('some/nice/invalid/path', 'localhost:1234', 'http://localhost:9000');
|
|
82
80
|
|
|
83
81
|
// Assert
|
|
84
82
|
expect(res).toBeUndefined();
|
|
@@ -88,8 +86,6 @@ describe('Piral-CLI piral injector', () => {
|
|
|
88
86
|
// Arrange
|
|
89
87
|
const optionsMock = {
|
|
90
88
|
pilets: [],
|
|
91
|
-
meta: 'debug-meta.json',
|
|
92
|
-
publicUrl: '/',
|
|
93
89
|
api: 'http://someFakeApi:1234',
|
|
94
90
|
app: '',
|
|
95
91
|
publicUrl: '/',
|
|
@@ -120,8 +116,6 @@ describe('Piral-CLI piral injector', () => {
|
|
|
120
116
|
// Arrange
|
|
121
117
|
const optionsMock = {
|
|
122
118
|
pilets: [],
|
|
123
|
-
meta: 'debug-meta.json',
|
|
124
|
-
publicUrl: '/',
|
|
125
119
|
api: 'http://someFakeApi:1234',
|
|
126
120
|
app: '',
|
|
127
121
|
publicUrl: '/',
|