piral-cli 0.15.0-beta.4696 → 0.15.0-beta.4708
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.d.ts +4 -0
- package/lib/apps/new-piral.js +3 -2
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/bundler.js +16 -4
- package/lib/bundler.js.map +1 -1
- package/lib/commands.js +5 -1
- package/lib/commands.js.map +1 -1
- package/lib/common/constants.d.ts +1 -1
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +2 -0
- package/lib/common/index.js.map +1 -1
- package/lib/common/injectors.js +4 -4
- package/lib/common/injectors.js.map +1 -1
- package/lib/common/log.d.ts +2 -2
- package/lib/common/log.js +18 -47
- package/lib/common/log.js.map +1 -1
- package/lib/external/index.js +59509 -61418
- package/lib/messages.d.ts +26 -0
- package/lib/messages.js +34 -1
- package/lib/messages.js.map +1 -1
- package/package.json +9 -7
- package/src/apps/new-pilet.test.ts +1 -1
- package/src/apps/new-piral.test.ts +21 -2
- package/src/apps/new-piral.ts +8 -1
- package/src/bundler.test.ts +4 -1
- package/src/bundler.ts +20 -5
- package/src/commands.ts +5 -1
- package/src/common/archive.test.ts +51 -45
- package/src/common/browser.test.ts +17 -7
- package/src/common/http.test.ts +69 -57
- package/src/common/index.ts +2 -0
- package/src/common/injectors.ts +1 -1
- package/src/common/interactive.test.ts +3 -0
- package/src/common/log.ts +23 -55
- package/src/common/npm.test.ts +2 -7
- package/src/common/port.test.ts +4 -1
- package/src/common/rules.test.ts +3 -3
- package/src/external/index.test.ts +2 -2
- package/src/external/index.ts +6 -3
- package/src/external/resolve.ts +28 -0
- package/src/messages.ts +33 -0
- package/lib/external/child.js +0 -144
- package/lib/external/classes.trie +0 -0
- package/lib/external/xdg-open +0 -1066
package/src/common/index.ts
CHANGED
|
@@ -13,6 +13,8 @@ export * from './http';
|
|
|
13
13
|
export * from './importmap';
|
|
14
14
|
export * from './info';
|
|
15
15
|
export * from './injectors';
|
|
16
|
+
export * from './inspect';
|
|
17
|
+
export * from './interactive';
|
|
16
18
|
export * from './io';
|
|
17
19
|
export * from './language';
|
|
18
20
|
export * from './log';
|
package/src/common/injectors.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
1
|
import { resolve } from 'path';
|
|
3
2
|
import { liveIcon, settingsIcon } from './emoji';
|
|
4
3
|
import { logInfo, log, logReset } from './log';
|
|
4
|
+
import { chalk } from '../external';
|
|
5
5
|
import { Bundler } from '../types';
|
|
6
6
|
|
|
7
7
|
export function notifyServerOnline(bundlers: Array<Bundler>, path: string, api: string | false) {
|
package/src/common/log.ts
CHANGED
|
@@ -1,111 +1,79 @@
|
|
|
1
1
|
import * as messages from '../messages';
|
|
2
|
-
import { join } from 'path';
|
|
3
2
|
import { format } from 'util';
|
|
4
|
-
import {
|
|
5
|
-
import { isWindows } from './info';
|
|
6
|
-
import { stripAnsi } from '../external';
|
|
3
|
+
import { ora } from '../external';
|
|
7
4
|
import { LogLevels, QuickMessage } from '../types';
|
|
8
5
|
|
|
9
6
|
type Messages = typeof messages;
|
|
10
7
|
type MessageTypes = keyof Messages;
|
|
11
8
|
let currentProgress: string = undefined;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
const logger = require('@parcel/logger');
|
|
16
|
-
|
|
17
|
-
// check to see if this is really right
|
|
18
|
-
if (typeof logger.verbose === 'function') {
|
|
19
|
-
return logger;
|
|
20
|
-
}
|
|
21
|
-
} catch {}
|
|
22
|
-
|
|
23
|
-
return require('../external').logger;
|
|
24
|
-
})();
|
|
25
|
-
|
|
26
|
-
// unfortunately, Parcel's support for verbose logging on Windows is broken
|
|
27
|
-
if (isWindows) {
|
|
28
|
-
logger.verbose = function (message: string) {
|
|
29
|
-
if (this.logLevel < 4) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const currDate = new Date();
|
|
34
|
-
message = `[${currDate.toLocaleTimeString()}]: ${message}`;
|
|
35
|
-
|
|
36
|
-
if (this.logLevel > 4) {
|
|
37
|
-
if (!this.logFile) {
|
|
38
|
-
// the critical line is the filename; it must not contain colons!
|
|
39
|
-
const timestamp = currDate.toISOString().replace(/:/g, '');
|
|
40
|
-
const fileName = `parcel-debug-${timestamp}.log`;
|
|
41
|
-
this.logFile = createWriteStream(join(process.cwd(), fileName));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
this.logFile.write(stripAnsi.default(message) + '\n');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
this._log(message);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
9
|
+
let logLevel = LogLevels.info;
|
|
10
|
+
let instance = ora();
|
|
50
11
|
|
|
51
12
|
export function getLogLevel(): LogLevels {
|
|
52
|
-
return
|
|
13
|
+
return logLevel;
|
|
53
14
|
}
|
|
54
15
|
|
|
55
|
-
export function setLogLevel(
|
|
56
|
-
|
|
16
|
+
export function setLogLevel(value: LogLevels) {
|
|
17
|
+
logLevel = value;
|
|
57
18
|
}
|
|
58
19
|
|
|
59
20
|
export function logInfo(message: string, ...args: Array<string | number | boolean>) {
|
|
60
21
|
const msg = format(message, ...args);
|
|
61
|
-
|
|
22
|
+
instance.info(msg);
|
|
62
23
|
return msg;
|
|
63
24
|
}
|
|
64
25
|
|
|
65
26
|
export function logDebug(message: string, ...args: Array<string | number | boolean>) {
|
|
66
27
|
const msg = format(message, ...args);
|
|
67
|
-
|
|
28
|
+
|
|
29
|
+
if (logLevel >= LogLevels.debug) {
|
|
30
|
+
instance.info(msg);
|
|
31
|
+
}
|
|
32
|
+
|
|
68
33
|
return msg;
|
|
69
34
|
}
|
|
70
35
|
|
|
71
36
|
export function logVerbose(message: string, ...args: Array<string | number | boolean>) {
|
|
72
37
|
const msg = format(message, ...args);
|
|
73
|
-
|
|
38
|
+
|
|
39
|
+
if (logLevel >= LogLevels.verbose) {
|
|
40
|
+
instance.info(msg);
|
|
41
|
+
}
|
|
42
|
+
|
|
74
43
|
return msg;
|
|
75
44
|
}
|
|
76
45
|
|
|
77
46
|
export function logDone(message: string, ...args: Array<string | number | boolean>) {
|
|
78
47
|
const msg = format(message, ...args);
|
|
79
|
-
|
|
48
|
+
instance.succeed(msg);
|
|
80
49
|
return msg;
|
|
81
50
|
}
|
|
82
51
|
|
|
83
52
|
export function logWarn(message: string, ...args: Array<string | number | boolean>) {
|
|
84
53
|
const msg = format(message, ...args);
|
|
85
|
-
|
|
54
|
+
instance.warn(msg);
|
|
86
55
|
return msg;
|
|
87
56
|
}
|
|
88
57
|
|
|
89
58
|
export function logFail(message: string, ...args: Array<string | number | boolean>) {
|
|
90
59
|
const msg = format(message, ...args);
|
|
91
|
-
|
|
60
|
+
instance.fail(msg);
|
|
92
61
|
return msg;
|
|
93
62
|
}
|
|
94
63
|
|
|
95
64
|
export function progress(message: string, ...args: Array<string | number | boolean>) {
|
|
96
65
|
currentProgress = format(message, ...args)
|
|
97
|
-
|
|
66
|
+
instance.start(message);
|
|
98
67
|
}
|
|
99
68
|
|
|
100
69
|
export function logReset() {
|
|
101
|
-
|
|
102
|
-
logger.stopSpinner();
|
|
70
|
+
instance.stop();
|
|
103
71
|
}
|
|
104
72
|
|
|
105
73
|
export function logSuspend() {
|
|
106
74
|
logReset();
|
|
107
75
|
|
|
108
|
-
return () =>
|
|
76
|
+
return () => instance.start(currentProgress);
|
|
109
77
|
}
|
|
110
78
|
|
|
111
79
|
export function fail<T extends MessageTypes>(type: T, ...args: Parameters<Messages[T]>): never {
|
package/src/common/npm.test.ts
CHANGED
package/src/common/port.test.ts
CHANGED
|
@@ -4,7 +4,10 @@ const defaultPort = 12345;
|
|
|
4
4
|
const error = Error('RangeError: Port should be >= 0 and < 65536.');
|
|
5
5
|
|
|
6
6
|
jest.mock('../external', () => ({
|
|
7
|
-
|
|
7
|
+
ora() {
|
|
8
|
+
return {};
|
|
9
|
+
},
|
|
10
|
+
getPort(options: any) {
|
|
8
11
|
if (options == undefined) {
|
|
9
12
|
return Promise.resolve(defaultPort);
|
|
10
13
|
} else if (options && options.port && options.port > 65536) {
|
package/src/common/rules.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ruleSummary, runRules } from './rules';
|
|
2
|
-
import chalk from '
|
|
2
|
+
import { chalk } from '../external';
|
|
3
3
|
|
|
4
4
|
const rule = {
|
|
5
5
|
run: jest.fn(),
|
|
@@ -13,9 +13,9 @@ describe('Rules Module', () => {
|
|
|
13
13
|
};
|
|
14
14
|
expect(runException).toThrow(Error('[0080] Validation failed. Found 1 error(s).'));
|
|
15
15
|
|
|
16
|
-
let consoleSpy = jest.spyOn(
|
|
16
|
+
let consoleSpy = jest.spyOn(process.stderr, 'write');
|
|
17
17
|
ruleSummary([], []);
|
|
18
|
-
expect(consoleSpy).
|
|
18
|
+
expect(consoleSpy).toHaveBeenLastCalledWith(`${chalk.green('✔')} Validation successful. No errors or warnings.\n`);
|
|
19
19
|
|
|
20
20
|
jest.clearAllMocks();
|
|
21
21
|
ruleSummary([], ['Warning!']);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as externals from '
|
|
1
|
+
import * as externals from '../external';
|
|
2
2
|
|
|
3
3
|
describe('Externals module', () => {
|
|
4
4
|
it('exports the FormData class', () => {
|
|
@@ -27,7 +27,7 @@ describe('Externals module', () => {
|
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
it('exports the logger module', () => {
|
|
30
|
-
const logger = externals.
|
|
30
|
+
const logger = externals.ora;
|
|
31
31
|
expect(logger).not.toBeUndefined();
|
|
32
32
|
});
|
|
33
33
|
|
package/src/external/index.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import logger = require('@parcel/logger');
|
|
2
|
-
import stripAnsi = require('strip-ansi');
|
|
3
1
|
import inquirer = require('inquirer');
|
|
4
2
|
import jju = require('jju');
|
|
5
3
|
import glob = require('glob');
|
|
@@ -10,5 +8,10 @@ import axios = require('axios');
|
|
|
10
8
|
import mime = require('mime');
|
|
11
9
|
import getPort = require('get-port');
|
|
12
10
|
import open = require('open');
|
|
11
|
+
import chalk = require('chalk');
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
import isInteractive from 'is-interactive';
|
|
14
|
+
import ora from 'ora';
|
|
15
|
+
import { getModulePath } from './resolve';
|
|
16
|
+
|
|
17
|
+
export { chalk, inquirer, isInteractive, ora, glob, tar, FormData, rc, axios, mime, getPort, open, jju, getModulePath };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as fs from 'graceful-fs';
|
|
2
|
+
import { ResolverFactory, CachedInputFileSystem } from 'enhanced-resolve';
|
|
3
|
+
|
|
4
|
+
const nodeFileSystem = new CachedInputFileSystem(fs, 4000);
|
|
5
|
+
|
|
6
|
+
const nodeContext = {
|
|
7
|
+
environments: ['node+es3+es5+process+native'],
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const enhancedResolve = ResolverFactory.createResolver({
|
|
11
|
+
aliasFields: ['browser'],
|
|
12
|
+
conditionNames: ['import', 'module', 'webpack', 'development', 'browser'],
|
|
13
|
+
extensions: ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.json'],
|
|
14
|
+
exportsFields: ['exports'],
|
|
15
|
+
importsFields: ['imports'],
|
|
16
|
+
mainFields: ['browser', 'module', 'main'],
|
|
17
|
+
fileSystem: nodeFileSystem,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export function getModulePath(root: string, moduleName: string) {
|
|
21
|
+
const res = enhancedResolve.resolveSync(nodeContext, root, moduleName);
|
|
22
|
+
|
|
23
|
+
if (!res) {
|
|
24
|
+
throw new Error(`Could not find module "${moduleName}".`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return res;
|
|
28
|
+
}
|
package/src/messages.ts
CHANGED
|
@@ -2598,6 +2598,39 @@ export function bundlerUnspecified_0175(available: Array<string>): QuickMessage
|
|
|
2598
2598
|
];
|
|
2599
2599
|
}
|
|
2600
2600
|
|
|
2601
|
+
/**
|
|
2602
|
+
* @kind Warning
|
|
2603
|
+
*
|
|
2604
|
+
* @summary
|
|
2605
|
+
* No bundler has been installed yet.
|
|
2606
|
+
*
|
|
2607
|
+
* @abstract
|
|
2608
|
+
* Piral allows you to set up your own tooling for building and debugging. This
|
|
2609
|
+
* is a powerful concept. By default, the Webpack v5 bundler is used.
|
|
2610
|
+
* Alternatives include Parcel and Rollup.
|
|
2611
|
+
*
|
|
2612
|
+
* In case no bundler is yet installed the Piral CLI will automatically install
|
|
2613
|
+
* the default bundler. However, you should consider installing a bundler of your
|
|
2614
|
+
* choice (even if this could also be the default bundler) explicitly.
|
|
2615
|
+
*
|
|
2616
|
+
* @see
|
|
2617
|
+
* - [Pluggable bundlers](https://docs.piral.io/reference/documentation/bundlers)
|
|
2618
|
+
*
|
|
2619
|
+
* @example
|
|
2620
|
+
* Use the following command to install esbuild as a bundler with the npm client:
|
|
2621
|
+
*
|
|
2622
|
+
* ```sh
|
|
2623
|
+
* npm i piral-cli-esbuild --save-dev
|
|
2624
|
+
* ```
|
|
2625
|
+
*/
|
|
2626
|
+
export function bundlerNotInstalled_0176(): QuickMessage {
|
|
2627
|
+
return [
|
|
2628
|
+
LogLevels.warning,
|
|
2629
|
+
'0176',
|
|
2630
|
+
`Installing default bundler since no bundler has been found.`,
|
|
2631
|
+
];
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2601
2634
|
/**
|
|
2602
2635
|
* @kind Warning
|
|
2603
2636
|
*
|
package/lib/external/child.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
const {errorUtils} = require('@parcel/utils');
|
|
2
|
-
|
|
3
|
-
class Child {
|
|
4
|
-
constructor() {
|
|
5
|
-
if (!process.send) {
|
|
6
|
-
throw new Error('Only create Child instances in a worker!');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
this.module = undefined;
|
|
10
|
-
this.childId = undefined;
|
|
11
|
-
|
|
12
|
-
this.callQueue = [];
|
|
13
|
-
this.responseQueue = new Map();
|
|
14
|
-
this.responseId = 0;
|
|
15
|
-
this.maxConcurrentCalls = 10;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
messageListener(data) {
|
|
19
|
-
if (data === 'die') {
|
|
20
|
-
return this.end();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let type = data.type;
|
|
24
|
-
if (type === 'response') {
|
|
25
|
-
return this.handleResponse(data);
|
|
26
|
-
} else if (type === 'request') {
|
|
27
|
-
return this.handleRequest(data);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async send(data) {
|
|
32
|
-
process.send(data, err => {
|
|
33
|
-
if (err && err instanceof Error) {
|
|
34
|
-
if (err.code === 'ERR_IPC_CHANNEL_CLOSED') {
|
|
35
|
-
// IPC connection closed
|
|
36
|
-
// no need to keep the worker running if it can't send or receive data
|
|
37
|
-
return this.end();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
childInit(module, childId) {
|
|
44
|
-
this.module = require(module);
|
|
45
|
-
this.childId = childId;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async handleRequest(data) {
|
|
49
|
-
let idx = data.idx;
|
|
50
|
-
let child = data.child;
|
|
51
|
-
let method = data.method;
|
|
52
|
-
let args = data.args;
|
|
53
|
-
|
|
54
|
-
let result = {idx, child, type: 'response'};
|
|
55
|
-
try {
|
|
56
|
-
result.contentType = 'data';
|
|
57
|
-
if (method === 'childInit') {
|
|
58
|
-
result.content = this.childInit(...args, child);
|
|
59
|
-
} else {
|
|
60
|
-
result.content = await this.module[method](...args);
|
|
61
|
-
}
|
|
62
|
-
} catch (e) {
|
|
63
|
-
result.contentType = 'error';
|
|
64
|
-
result.content = errorUtils.errorToJson(e);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
this.send(result);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async handleResponse(data) {
|
|
71
|
-
let idx = data.idx;
|
|
72
|
-
let contentType = data.contentType;
|
|
73
|
-
let content = data.content;
|
|
74
|
-
let call = this.responseQueue.get(idx);
|
|
75
|
-
|
|
76
|
-
if (contentType === 'error') {
|
|
77
|
-
call.reject(errorUtils.jsonToError(content));
|
|
78
|
-
} else {
|
|
79
|
-
call.resolve(content);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
this.responseQueue.delete(idx);
|
|
83
|
-
|
|
84
|
-
// Process the next call
|
|
85
|
-
this.processQueue();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Keep in mind to make sure responses to these calls are JSON.Stringify safe
|
|
89
|
-
async addCall(request, awaitResponse = true) {
|
|
90
|
-
let call = request;
|
|
91
|
-
call.type = 'request';
|
|
92
|
-
call.child = this.childId;
|
|
93
|
-
call.awaitResponse = awaitResponse;
|
|
94
|
-
|
|
95
|
-
let promise;
|
|
96
|
-
if (awaitResponse) {
|
|
97
|
-
promise = new Promise((resolve, reject) => {
|
|
98
|
-
call.resolve = resolve;
|
|
99
|
-
call.reject = reject;
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
this.callQueue.push(call);
|
|
104
|
-
this.processQueue();
|
|
105
|
-
|
|
106
|
-
return promise;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
async sendRequest(call) {
|
|
110
|
-
let idx;
|
|
111
|
-
if (call.awaitResponse) {
|
|
112
|
-
idx = this.responseId++;
|
|
113
|
-
this.responseQueue.set(idx, call);
|
|
114
|
-
}
|
|
115
|
-
this.send({
|
|
116
|
-
idx: idx,
|
|
117
|
-
child: call.child,
|
|
118
|
-
type: call.type,
|
|
119
|
-
location: call.location,
|
|
120
|
-
method: call.method,
|
|
121
|
-
args: call.args,
|
|
122
|
-
awaitResponse: call.awaitResponse
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async processQueue() {
|
|
127
|
-
if (!this.callQueue.length) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (this.responseQueue.size < this.maxConcurrentCalls) {
|
|
132
|
-
this.sendRequest(this.callQueue.shift());
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
end() {
|
|
137
|
-
process.exit();
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
let child = new Child();
|
|
142
|
-
process.on('message', child.messageListener.bind(child));
|
|
143
|
-
|
|
144
|
-
module.exports = child;
|
|
Binary file
|