piral-cli 0.15.0-beta.4466 → 0.15.0-beta.4544
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/apps/build-pilet.js +43 -19
- package/lib/apps/build-pilet.js.map +1 -1
- 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 +7 -6
- package/lib/injectors/pilet-injector.js +42 -25
- package/lib/injectors/pilet-injector.js.map +1 -1
- package/package.json +3 -3
- package/src/apps/build-pilet.ts +51 -24
- 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 +2 -8
- package/src/injectors/pilet-injector.ts +54 -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,31 @@ 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 basePath = this.getPiletApi(baseUrl);
|
|
77
|
+
const meta = JSON.stringify(p.getMeta(basePath));
|
|
78
|
+
notify(meta);
|
|
77
79
|
}
|
|
78
80
|
}));
|
|
79
81
|
}
|
|
@@ -91,10 +93,24 @@ class PiletInjector {
|
|
|
91
93
|
return {};
|
|
92
94
|
}
|
|
93
95
|
setOptions() { }
|
|
94
|
-
|
|
96
|
+
getPiletApi(baseUrl) {
|
|
97
|
+
const { api } = this.config;
|
|
98
|
+
if (/^https?:/.test(api)) {
|
|
99
|
+
return api;
|
|
100
|
+
}
|
|
101
|
+
else if (baseUrl) {
|
|
102
|
+
return `${baseUrl}${api}`;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
const { ssl, port } = this.serverConfig;
|
|
106
|
+
const { host } = config_1.config;
|
|
107
|
+
return `${ssl ? 'https' : 'http'}://${host}:${port}${api}`;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
getMeta(baseUrl) {
|
|
95
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
112
|
const { pilets, feed } = this.config;
|
|
97
|
-
const localPilets = pilets.map((pilet) => pilet.
|
|
113
|
+
const localPilets = pilets.map((pilet) => { var _a; return (_a = pilet.getMeta) === null || _a === void 0 ? void 0 : _a.call(pilet, baseUrl); }).filter(Boolean);
|
|
98
114
|
const mergedPilets = this.mergePilets(localPilets, yield this.loadRemoteFeed(feed));
|
|
99
115
|
return JSON.stringify(mergedPilets);
|
|
100
116
|
});
|
|
@@ -136,7 +152,7 @@ class PiletInjector {
|
|
|
136
152
|
const type = (_a = external_1.mime.getType(target)) !== null && _a !== void 0 ? _a : 'application/octet-stream';
|
|
137
153
|
return this.sendContent(content, type, url);
|
|
138
154
|
}
|
|
139
|
-
sendResponse(path, url) {
|
|
155
|
+
sendResponse(path, url, baseUrl) {
|
|
140
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
141
157
|
const { pilets } = this.config;
|
|
142
158
|
const [index, ...rest] = path.split('/');
|
|
@@ -144,7 +160,7 @@ class PiletInjector {
|
|
|
144
160
|
const bundler = pilet === null || pilet === void 0 ? void 0 : pilet.bundler;
|
|
145
161
|
if (!path) {
|
|
146
162
|
yield (bundler === null || bundler === void 0 ? void 0 : bundler.ready());
|
|
147
|
-
const content = yield this.getMeta();
|
|
163
|
+
const content = yield this.getMeta(baseUrl);
|
|
148
164
|
return this.sendContent(content, 'application/json', url);
|
|
149
165
|
}
|
|
150
166
|
else {
|
|
@@ -157,10 +173,10 @@ class PiletInjector {
|
|
|
157
173
|
}
|
|
158
174
|
});
|
|
159
175
|
}
|
|
160
|
-
sendIndexFile(target, url) {
|
|
176
|
+
sendIndexFile(target, url, baseUrl) {
|
|
161
177
|
const indexHtml = (0, fs_1.readFileSync)(target, 'utf8');
|
|
162
178
|
// mechanism to inject server side debug piletApi config into piral emulator
|
|
163
|
-
const windowInjectionScript = `window['dbg:pilet-api'] = '${this.
|
|
179
|
+
const windowInjectionScript = `window['dbg:pilet-api'] = '${this.getPiletApi(baseUrl)}';`;
|
|
164
180
|
const findStr = `<script`;
|
|
165
181
|
const replaceStr = `<script>/* Pilet Debugging Emulator Config Injection */${windowInjectionScript}</script><script`;
|
|
166
182
|
const content = indexHtml.replace(`${findStr}`, `${replaceStr}`);
|
|
@@ -168,13 +184,14 @@ class PiletInjector {
|
|
|
168
184
|
}
|
|
169
185
|
handle(req) {
|
|
170
186
|
const { app, api, publicUrl } = this.config;
|
|
187
|
+
const baseUrl = req.headers.host ? `${req.encrypted ? 'https' : 'http'}://${req.headers.host}` : undefined;
|
|
171
188
|
if (!req.target) {
|
|
172
189
|
if (req.url.startsWith(publicUrl)) {
|
|
173
190
|
const path = req.url.substring(publicUrl.length).split('?')[0];
|
|
174
191
|
const target = (0, path_1.join)(app, path);
|
|
175
192
|
if ((0, fs_1.existsSync)(target) && (0, fs_1.statSync)(target).isFile()) {
|
|
176
193
|
if (req.url === this.indexPath) {
|
|
177
|
-
return this.sendIndexFile(target, req.url);
|
|
194
|
+
return this.sendIndexFile(target, req.url, baseUrl);
|
|
178
195
|
}
|
|
179
196
|
else {
|
|
180
197
|
return this.sendFile(target, req.url);
|
|
@@ -188,7 +205,7 @@ class PiletInjector {
|
|
|
188
205
|
}
|
|
189
206
|
else if (req.target === api) {
|
|
190
207
|
const path = req.url.substring(1).split('?')[0];
|
|
191
|
-
return this.sendResponse(path, req.url);
|
|
208
|
+
return this.sendResponse(path, req.url, baseUrl);
|
|
192
209
|
}
|
|
193
210
|
}
|
|
194
211
|
}
|
|
@@ -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,cAAc,CAAC,CAAC;I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AI,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;AA/LD,gCA+LC"}
|
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.4544",
|
|
4
4
|
"description": "The standard CLI for creating and building a Piral instance or a Pilet.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portal",
|
|
@@ -72,11 +72,11 @@
|
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"chalk": "^2.4.2",
|
|
75
|
-
"dets": "^0.
|
|
75
|
+
"dets": "^0.12.0",
|
|
76
76
|
"kras": "^0.14.1",
|
|
77
77
|
"rimraf": "^3.0.0",
|
|
78
78
|
"typescript": "^4.7.3",
|
|
79
79
|
"yargs": "^15.4.1"
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "d128ed2e80430bbedcc16644455dd47c958addfc"
|
|
82
82
|
}
|
package/src/apps/build-pilet.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
concurrentWorkers,
|
|
24
24
|
normalizePublicUrl,
|
|
25
25
|
combinePiletExternals,
|
|
26
|
+
retrievePiletsInfo,
|
|
26
27
|
} from '../common';
|
|
27
28
|
|
|
28
29
|
interface PiletData {
|
|
@@ -296,32 +297,58 @@ export async function buildPilet(baseDir = process.cwd(), options: BuildPiletOpt
|
|
|
296
297
|
// in case of an emulator assets are not "seen" by the bundler, so we
|
|
297
298
|
// just copy overthing over - this should work in most cases.
|
|
298
299
|
await copy(dirname(appFile), outDir, ForceOverwrite.yes);
|
|
300
|
+
progress('Optimizing app shell ...');
|
|
301
|
+
|
|
302
|
+
// we don't need to care about externals or other things that are already
|
|
303
|
+
// part of the emulator
|
|
304
|
+
await callPiralBuild(
|
|
305
|
+
{
|
|
306
|
+
root,
|
|
307
|
+
piral: appPackage.name,
|
|
308
|
+
emulator: false,
|
|
309
|
+
standalone: true,
|
|
310
|
+
optimizeModules: false,
|
|
311
|
+
sourceMaps,
|
|
312
|
+
contentHash,
|
|
313
|
+
minify,
|
|
314
|
+
externals: [],
|
|
315
|
+
publicUrl,
|
|
316
|
+
outFile: 'index.html',
|
|
317
|
+
outDir,
|
|
318
|
+
entryFiles: appFile,
|
|
319
|
+
logLevel,
|
|
320
|
+
ignored: [],
|
|
321
|
+
_,
|
|
322
|
+
},
|
|
323
|
+
bundlerName,
|
|
324
|
+
);
|
|
325
|
+
} else {
|
|
326
|
+
// in this case we can just do the same steps as if
|
|
327
|
+
const { ignored, externals } = await retrievePiletsInfo(appFile);
|
|
328
|
+
|
|
329
|
+
await callPiralBuild(
|
|
330
|
+
{
|
|
331
|
+
root,
|
|
332
|
+
piral: appPackage.name,
|
|
333
|
+
emulator: false,
|
|
334
|
+
standalone: true,
|
|
335
|
+
optimizeModules: false,
|
|
336
|
+
sourceMaps,
|
|
337
|
+
contentHash,
|
|
338
|
+
minify,
|
|
339
|
+
externals,
|
|
340
|
+
publicUrl,
|
|
341
|
+
outFile: 'index.html',
|
|
342
|
+
outDir,
|
|
343
|
+
entryFiles: appFile,
|
|
344
|
+
logLevel,
|
|
345
|
+
ignored,
|
|
346
|
+
_,
|
|
347
|
+
},
|
|
348
|
+
bundlerName,
|
|
349
|
+
);
|
|
299
350
|
}
|
|
300
351
|
|
|
301
|
-
progress('Optimizing app shell ...');
|
|
302
|
-
|
|
303
|
-
await callPiralBuild(
|
|
304
|
-
{
|
|
305
|
-
root,
|
|
306
|
-
piral: appPackage.name,
|
|
307
|
-
emulator: false,
|
|
308
|
-
standalone: true,
|
|
309
|
-
optimizeModules: false,
|
|
310
|
-
sourceMaps,
|
|
311
|
-
contentHash,
|
|
312
|
-
minify,
|
|
313
|
-
externals: [],
|
|
314
|
-
publicUrl,
|
|
315
|
-
outFile: 'index.html',
|
|
316
|
-
outDir,
|
|
317
|
-
entryFiles: appFile,
|
|
318
|
-
logLevel,
|
|
319
|
-
ignored: [],
|
|
320
|
-
_,
|
|
321
|
-
},
|
|
322
|
-
bundlerName,
|
|
323
|
-
);
|
|
324
|
-
|
|
325
352
|
logDone(`Standalone app available at "${outDir}"!`);
|
|
326
353
|
} else if (type === 'manifest') {
|
|
327
354
|
const manifest = 'pilets.json';
|
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
|
};
|
|
@@ -35,7 +33,7 @@ describe('Piral-CLI piral injector', () => {
|
|
|
35
33
|
injector.name;
|
|
36
34
|
injector.getOptions();
|
|
37
35
|
//injector.getMetaOf(0);
|
|
38
|
-
injector.getMeta();
|
|
36
|
+
injector.getMeta('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: '/',
|