watchful-cli 1.7.20 → 1.7.23
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/bin/queue.js +1 -1
- package/bin/transpileFile.js +4 -4
- package/bin/utilities/path.js +57 -20
- package/bin/utilities/transpile.js +26 -24
- package/package.json +1 -2
- package/bin/utilities/sourceMap.js +0 -17
package/bin/queue.js
CHANGED
package/bin/transpileFile.js
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
const { combinePaths } = require("./utilities/path");
|
|
4
4
|
|
|
5
5
|
function transpileFile(filePath, context, callback) {
|
|
6
|
-
const { transpileFileFunction, sourceDirectoryPath, targetDirectoryPath } = context
|
|
7
|
-
sourceFilePath = combinePaths(sourceDirectoryPath, filePath), ///
|
|
8
|
-
targetFilePath = combinePaths(targetDirectoryPath, filePath); ///
|
|
6
|
+
const { transpileFileFunction, sourceDirectoryPath, targetDirectoryPath } = context;
|
|
9
7
|
|
|
10
|
-
transpileFileFunction(
|
|
8
|
+
transpileFileFunction(filePath, sourceDirectoryPath, targetDirectoryPath, (success) => {
|
|
11
9
|
const { quietly } = context;
|
|
12
10
|
|
|
13
11
|
if (!quietly) {
|
|
12
|
+
const sourceFilePath = combinePaths(sourceDirectoryPath, filePath);
|
|
13
|
+
|
|
14
14
|
console.log(`Transpiled '${sourceFilePath}'.`);
|
|
15
15
|
}
|
|
16
16
|
|
package/bin/utilities/path.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
const path = require("path");
|
|
4
|
+
|
|
3
5
|
const { characters, pathUtilities } = require("necessary");
|
|
4
6
|
|
|
5
7
|
const { EMPTY_STRING } = require("../constants");
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
{
|
|
9
|
+
const { FORWARD_SLASH_CHARACTER } = characters,
|
|
10
|
+
{ combinePaths, pathWithoutBottommostNameFromPath } = pathUtilities;
|
|
9
11
|
|
|
10
12
|
const currentWorkingDirectoryPath = process.cwd(),
|
|
11
13
|
currentWorkingDirectoryPathLength = currentWorkingDirectoryPath.length;
|
|
@@ -32,22 +34,6 @@ function pathFromOption(option) {
|
|
|
32
34
|
return path;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
function fileNameFromFilePath(filePath) {
|
|
36
|
-
let fileName;
|
|
37
|
-
|
|
38
|
-
const filePathFileName = isPathName(filePath);
|
|
39
|
-
|
|
40
|
-
if (filePathFileName) {
|
|
41
|
-
fileName = filePath; ///
|
|
42
|
-
} else {
|
|
43
|
-
const bottommostFileName = bottommostNameFromPath(filePath);
|
|
44
|
-
|
|
45
|
-
fileName = bottommostFileName; ///
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return fileName;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
37
|
function isPathFullQualifiedPath(path) {
|
|
52
38
|
const pathStartsWithCurrentWorkingDirectoryPath = path.startsWith(currentWorkingDirectoryPath),
|
|
53
39
|
pathFullyQualifiedPath = pathStartsWithCurrentWorkingDirectoryPath; ///
|
|
@@ -69,10 +55,61 @@ function pathWithoutDirectoryPathFromPathAndDirectoryPath(path, directoryPath) {
|
|
|
69
55
|
return pathWithoutDirectoryPath;
|
|
70
56
|
}
|
|
71
57
|
|
|
58
|
+
function sourceFilePathFromFilePathAndSourceDirectoryPath(filePath, sourceDirectoryPath) {
|
|
59
|
+
const sourceFilePath = combinePaths(sourceDirectoryPath, filePath);
|
|
60
|
+
|
|
61
|
+
return sourceFilePath;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function targetFilePathFromFilePathAndTargetDirectoryPath(filePath, targetDirectoryPath) {
|
|
65
|
+
const targetFilePath = combinePaths(targetDirectoryPath, filePath);
|
|
66
|
+
|
|
67
|
+
return targetFilePath;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function sourceFileNameFromSourceFilePathAndTargetFilePath(sourceFilePath, targetFilePath) {
|
|
71
|
+
const relativeSourceFilepath = relativeSourceFilePathFromSourceFilePathAndTargetFilePath(sourceFilePath, targetFilePath),
|
|
72
|
+
sourceFileName = relativeSourceFilepath; ///
|
|
73
|
+
|
|
74
|
+
return sourceFileName;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function sourcesFromSourcesSourceDirectoryPathAndTargetDirectoryPath(sources, sourceDirectoryPath, targetDirectoryPath) {
|
|
78
|
+
sources = sources.map((source) => { ///
|
|
79
|
+
const sourceStartsWithTargetDirectoryPath = source.startsWith(targetDirectoryPath);
|
|
80
|
+
|
|
81
|
+
if (sourceStartsWithTargetDirectoryPath) {
|
|
82
|
+
const targetDirectoryPathLength = targetDirectoryPath.length,
|
|
83
|
+
start = targetDirectoryPathLength + 1,
|
|
84
|
+
filePath = source.substring(start),
|
|
85
|
+
targetFilePath = source, ///
|
|
86
|
+
sourceFilePath = sourceFilePathFromFilePathAndSourceDirectoryPath(filePath, sourceDirectoryPath),
|
|
87
|
+
relativeSourceFilePath = relativeSourceFilePathFromSourceFilePathAndTargetFilePath(sourceFilePath, targetFilePath);
|
|
88
|
+
|
|
89
|
+
source = relativeSourceFilePath; ///
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return source;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return sources;
|
|
96
|
+
}
|
|
97
|
+
|
|
72
98
|
module.exports = Object.assign({}, pathUtilities, {
|
|
73
99
|
pathFromOption,
|
|
74
|
-
fileNameFromFilePath,
|
|
75
100
|
isPathFullQualifiedPath,
|
|
76
101
|
pathFromFullyQualifiedPath,
|
|
77
|
-
pathWithoutDirectoryPathFromPathAndDirectoryPath
|
|
102
|
+
pathWithoutDirectoryPathFromPathAndDirectoryPath,
|
|
103
|
+
sourceFilePathFromFilePathAndSourceDirectoryPath,
|
|
104
|
+
targetFilePathFromFilePathAndTargetDirectoryPath,
|
|
105
|
+
sourceFileNameFromSourceFilePathAndTargetFilePath,
|
|
106
|
+
sourcesFromSourcesSourceDirectoryPathAndTargetDirectoryPath
|
|
78
107
|
});
|
|
108
|
+
|
|
109
|
+
function relativeSourceFilePathFromSourceFilePathAndTargetFilePath(sourceFilePath, targetFilePath) {
|
|
110
|
+
const targetFilePathWithoutBottommostName = pathWithoutBottommostNameFromPath(targetFilePath),
|
|
111
|
+
relativeSourceFilePath = path.relative(targetFilePathWithoutBottommostName, sourceFilePath);
|
|
112
|
+
|
|
113
|
+
return relativeSourceFilePath;
|
|
114
|
+
}
|
|
115
|
+
|
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
const path = require("path");
|
|
4
4
|
|
|
5
|
-
const {
|
|
5
|
+
const { encodings } = require("necessary");
|
|
6
6
|
|
|
7
7
|
const { SWC_CORE_PATH, BABEL_CORE_PATH } = require("../paths"),
|
|
8
8
|
{ readFile, writeFile, createParentDirectory } = require("../utilities/fileSystem"),
|
|
9
9
|
{ BABEL, INLINE, SOURCE_MAP_PREAMBLE } = require("../constants"),
|
|
10
|
-
{
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
{ SWC_FAILED_MESSAGE, BABEL_FAILED_MESSAGE, SWC_NOT_INSTALLED_MESSAGE, BABEL_NOT_INSTALLED_MESSAGE } = require("../messages"),
|
|
11
|
+
{ sourceFilePathFromFilePathAndSourceDirectoryPath,
|
|
12
|
+
targetFilePathFromFilePathAndTargetDirectoryPath,
|
|
13
|
+
sourceFileNameFromSourceFilePathAndTargetFilePath,
|
|
14
|
+
sourcesFromSourcesSourceDirectoryPathAndTargetDirectoryPath } = require("../utilities/path");
|
|
15
|
+
|
|
16
|
+
const { BASE64_ENCODING } = encodings;
|
|
15
17
|
|
|
16
18
|
function createTranspileFileFunction(context) {
|
|
17
19
|
const { debug, transpiler } = context,
|
|
@@ -34,9 +36,12 @@ function createBabelTranspileFileFunction(debug) {
|
|
|
34
36
|
babel = require(babelCorePath),
|
|
35
37
|
transpiler = babel; ///
|
|
36
38
|
|
|
37
|
-
babelTranspileFileFunction = (
|
|
39
|
+
babelTranspileFileFunction = (filePath, sourceDirectoryPath, targetDirectoryPath, callback) => {
|
|
38
40
|
let options;
|
|
39
41
|
|
|
42
|
+
const sourceFilePath = sourceFilePathFromFilePathAndSourceDirectoryPath(filePath, sourceDirectoryPath),
|
|
43
|
+
targetFilePath = targetFilePathFromFilePathAndTargetDirectoryPath(filePath, targetDirectoryPath);
|
|
44
|
+
|
|
40
45
|
if (debug) {
|
|
41
46
|
const sourceMaps = INLINE, ///
|
|
42
47
|
sourceFileName = sourceFileNameFromSourceFilePathAndTargetFilePath(sourceFilePath, targetFilePath);
|
|
@@ -90,14 +95,16 @@ function createSWCTranspileFileFunction(debug) {
|
|
|
90
95
|
swc = require(swcCorePath),
|
|
91
96
|
transpiler = swc; ///
|
|
92
97
|
|
|
93
|
-
swcTranspileFileFunction = (
|
|
94
|
-
const
|
|
98
|
+
swcTranspileFileFunction = (filePath, sourceDirectoryPath, targetDirectoryPath, callback) => {
|
|
99
|
+
const sourceFilePath = sourceFilePathFromFilePathAndSourceDirectoryPath(filePath, sourceDirectoryPath),
|
|
100
|
+
targetFilePath = targetFilePathFromFilePathAndTargetDirectoryPath(filePath, targetDirectoryPath),
|
|
95
101
|
filename = targetFilePath, ///
|
|
102
|
+
sourceMaps = debug, ///
|
|
103
|
+
sourceFileContent = readFile(sourceFilePath),
|
|
96
104
|
options = {
|
|
97
105
|
filename,
|
|
98
106
|
sourceMaps
|
|
99
|
-
}
|
|
100
|
-
sourceFileContent = readFile(sourceFilePath);
|
|
107
|
+
};
|
|
101
108
|
|
|
102
109
|
transpiler.transform(sourceFileContent, options)
|
|
103
110
|
.then((output) => {
|
|
@@ -107,24 +114,18 @@ function createSWCTranspileFileFunction(debug) {
|
|
|
107
114
|
|
|
108
115
|
if (debug) {
|
|
109
116
|
const { code, map } = output,
|
|
110
|
-
mapJSON = JSON.parse(map)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
],
|
|
116
|
-
sourceContent = sourceFileContent, ///
|
|
117
|
-
sourcesContent = [
|
|
118
|
-
sourceContent
|
|
119
|
-
];
|
|
117
|
+
mapJSON = JSON.parse(map);
|
|
118
|
+
|
|
119
|
+
let { sources } = mapJSON;
|
|
120
|
+
|
|
121
|
+
sources = sourcesFromSourcesSourceDirectoryPathAndTargetDirectoryPath(sources, sourceDirectoryPath, targetDirectoryPath);
|
|
120
122
|
|
|
121
123
|
Object.assign(mapJSON, {
|
|
122
|
-
sources
|
|
123
|
-
sourcesContent
|
|
124
|
+
sources
|
|
124
125
|
});
|
|
125
126
|
|
|
126
127
|
const mapJSONString = JSON.stringify(mapJSON),
|
|
127
|
-
base64EncodedMapJSONString =
|
|
128
|
+
base64EncodedMapJSONString = Buffer.from(mapJSONString).toString(BASE64_ENCODING);
|
|
128
129
|
|
|
129
130
|
targetFileContent = `${code}
|
|
130
131
|
${SOURCE_MAP_PREAMBLE}${base64EncodedMapJSONString}`; ///
|
|
@@ -155,3 +156,4 @@ ${error}`);
|
|
|
155
156
|
|
|
156
157
|
return swcTranspileFileFunction;
|
|
157
158
|
}
|
|
159
|
+
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "watchful-cli",
|
|
3
3
|
"author": "James Smith",
|
|
4
|
-
"version": "1.7.
|
|
4
|
+
"version": "1.7.23",
|
|
5
5
|
"license": "MIT, Anti-996",
|
|
6
6
|
"homepage": "https://github.com/djalbat/watchful-cli",
|
|
7
7
|
"description": "Incremental transpilation with bundling.",
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"argumentative": "^2.0.14",
|
|
17
17
|
"chokidar": "^3.3.1",
|
|
18
|
-
"js-base64": "^3.7.2",
|
|
19
18
|
"necessary": "^11.0.25"
|
|
20
19
|
},
|
|
21
20
|
"devDependencies": {},
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const path = require("path");
|
|
4
|
-
|
|
5
|
-
const { pathWithoutBottommostNameFromPath } = require("../utilities/path");
|
|
6
|
-
|
|
7
|
-
function sourceFileNameFromSourceFilePathAndTargetFilePath(sourceFilePath, targetFilePath) {
|
|
8
|
-
const targetFilePathWithoutBottommostName = pathWithoutBottommostNameFromPath(targetFilePath),
|
|
9
|
-
relativeSourceFilePath = path.relative(targetFilePathWithoutBottommostName, sourceFilePath),
|
|
10
|
-
sourceFileName = relativeSourceFilePath; ///
|
|
11
|
-
|
|
12
|
-
return sourceFileName;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = {
|
|
16
|
-
sourceFileNameFromSourceFilePathAndTargetFilePath
|
|
17
|
-
};
|