watchful-cli 1.7.21 → 1.7.22

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.
@@ -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(sourceFilePath, targetFilePath, (success) => {
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
 
@@ -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
- const { FORWARD_SLASH_CHARACTER } = characters,
8
- { isPathName, bottommostNameFromPath } = pathUtilities;
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
+
@@ -7,11 +7,11 @@ const { encodings } = require("necessary");
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
- { sourceFileNameFromSourceFilePathAndTargetFilePath } = require("../utilities/sourceMap"),
11
- { SWC_FAILED_MESSAGE,
12
- BABEL_FAILED_MESSAGE,
13
- SWC_NOT_INSTALLED_MESSAGE,
14
- BABEL_NOT_INSTALLED_MESSAGE } = require("../messages");
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
15
 
16
16
  const { BASE64_ENCODING } = encodings;
17
17
 
@@ -36,9 +36,12 @@ function createBabelTranspileFileFunction(debug) {
36
36
  babel = require(babelCorePath),
37
37
  transpiler = babel; ///
38
38
 
39
- babelTranspileFileFunction = (sourceFilePath, targetFilePath, callback) => {
39
+ babelTranspileFileFunction = (filePath, sourceDirectoryPath, targetDirectoryPath, callback) => {
40
40
  let options;
41
41
 
42
+ const sourceFilePath = sourceFilePathFromFilePathAndSourceDirectoryPath(filePath, sourceDirectoryPath),
43
+ targetFilePath = targetFilePathFromFilePathAndTargetDirectoryPath(filePath, targetDirectoryPath);
44
+
42
45
  if (debug) {
43
46
  const sourceMaps = INLINE, ///
44
47
  sourceFileName = sourceFileNameFromSourceFilePathAndTargetFilePath(sourceFilePath, targetFilePath);
@@ -92,14 +95,16 @@ function createSWCTranspileFileFunction(debug) {
92
95
  swc = require(swcCorePath),
93
96
  transpiler = swc; ///
94
97
 
95
- swcTranspileFileFunction = (sourceFilePath, targetFilePath, callback) => {
96
- const sourceMaps = debug, ///
98
+ swcTranspileFileFunction = (filePath, sourceDirectoryPath, targetDirectoryPath, callback) => {
99
+ const sourceFilePath = sourceFilePathFromFilePathAndSourceDirectoryPath(filePath, sourceDirectoryPath),
100
+ targetFilePath = targetFilePathFromFilePathAndTargetDirectoryPath(filePath, targetDirectoryPath),
97
101
  filename = targetFilePath, ///
102
+ sourceMaps = debug, ///
103
+ sourceFileContent = readFile(sourceFilePath),
98
104
  options = {
99
105
  filename,
100
106
  sourceMaps
101
- },
102
- sourceFileContent = readFile(sourceFilePath);
107
+ };
103
108
 
104
109
  transpiler.transform(sourceFileContent, options)
105
110
  .then((output) => {
@@ -109,20 +114,14 @@ function createSWCTranspileFileFunction(debug) {
109
114
 
110
115
  if (debug) {
111
116
  const { code, map } = output,
112
- mapJSON = JSON.parse(map),
113
- sourceFileName = sourceFileNameFromSourceFilePathAndTargetFilePath(sourceFilePath, targetFilePath),
114
- source = sourceFileName, ///
115
- sources = [
116
- source
117
- ],
118
- sourceContent = sourceFileContent, ///
119
- sourcesContent = [
120
- sourceContent
121
- ];
117
+ mapJSON = JSON.parse(map);
118
+
119
+ let { sources } = mapJSON;
120
+
121
+ sources = sourcesFromSourcesSourceDirectoryPathAndTargetDirectoryPath(sources, sourceDirectoryPath, targetDirectoryPath);
122
122
 
123
123
  Object.assign(mapJSON, {
124
- sources,
125
- sourcesContent
124
+ sources
126
125
  });
127
126
 
128
127
  const mapJSONString = JSON.stringify(mapJSON),
@@ -157,3 +156,4 @@ ${error}`);
157
156
 
158
157
  return swcTranspileFileFunction;
159
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.21",
4
+ "version": "1.7.22",
5
5
  "license": "MIT, Anti-996",
6
6
  "homepage": "https://github.com/djalbat/watchful-cli",
7
7
  "description": "Incremental transpilation with bundling.",
@@ -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
- };