just-task 1.12.0 → 1.14.0

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.
Files changed (42) hide show
  1. package/lib/cache.d.ts +4 -3
  2. package/lib/cache.d.ts.map +1 -1
  3. package/lib/cache.js +6 -128
  4. package/lib/cli.js +2 -2
  5. package/lib/config.js +6 -6
  6. package/lib/enableTypeScript.js +2 -2
  7. package/lib/interfaces.d.ts +1 -0
  8. package/lib/interfaces.d.ts.map +1 -1
  9. package/lib/logger.d.ts +16 -1
  10. package/lib/logger.d.ts.map +1 -1
  11. package/lib/logger.js +52 -11
  12. package/lib/task.d.ts.map +1 -1
  13. package/lib/task.js +0 -10
  14. package/lib/undertaker.d.ts.map +1 -1
  15. package/lib/undertaker.js +0 -2
  16. package/package.json +1 -3
  17. package/src/cache.ts +5 -168
  18. package/src/cli.ts +1 -1
  19. package/src/config.ts +1 -1
  20. package/src/enableTypeScript.ts +1 -1
  21. package/src/interfaces.ts +1 -0
  22. package/src/logger.ts +85 -1
  23. package/src/task.ts +0 -10
  24. package/src/undertaker.ts +0 -3
  25. package/CHANGELOG.json +0 -1314
  26. package/CHANGELOG.md +0 -629
  27. package/lib/package/findDependents.d.ts +0 -7
  28. package/lib/package/findDependents.d.ts.map +0 -1
  29. package/lib/package/findDependents.js +0 -56
  30. package/lib/package/findGitRoot.d.ts +0 -2
  31. package/lib/package/findGitRoot.d.ts.map +0 -1
  32. package/lib/package/findGitRoot.js +0 -26
  33. package/lib/package/findPackageRoot.d.ts +0 -2
  34. package/lib/package/findPackageRoot.d.ts.map +0 -1
  35. package/lib/package/findPackageRoot.js +0 -11
  36. package/lib/paths.d.ts +0 -2
  37. package/lib/paths.d.ts.map +0 -1
  38. package/lib/paths.js +0 -9
  39. package/src/package/findDependents.ts +0 -68
  40. package/src/package/findGitRoot.ts +0 -28
  41. package/src/package/findPackageRoot.ts +0 -8
  42. package/src/paths.ts +0 -6
package/lib/cache.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export declare function registerCachedTask(taskName: string): void;
1
+ /**
2
+ * Clears the task cache.
3
+ * @deprecated Task caching has been removed. This function is a no-op.
4
+ */
2
5
  export declare function clearCache(): void;
3
- export declare function isCached(taskName: string): boolean;
4
- export declare function saveCache(taskName: string): void;
5
6
  //# sourceMappingURL=cache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAaA,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAEzD;AAED,wBAAgB,UAAU,IAAI,IAAI,CAOjC;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAyBlD;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAgBhD"}
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAEjC"}
package/lib/cache.js CHANGED
@@ -1,133 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.saveCache = exports.isCached = exports.clearCache = exports.registerCachedTask = void 0;
4
- const package_deps_hash_1 = require("@rushstack/package-deps-hash");
5
- const option_1 = require("./option");
6
- const resolve_1 = require("./resolve");
7
- const fs = require("fs-extra");
8
- const path = require("path");
9
- const just_task_logger_1 = require("just-task-logger");
10
- const findDependents_1 = require("./package/findDependents");
11
- const findGitRoot_1 = require("./package/findGitRoot");
12
- const child_process_1 = require("child_process");
13
- const cachedTask = [];
14
- const CacheFileName = 'package-deps.json';
15
- function registerCachedTask(taskName) {
16
- cachedTask.push(taskName);
17
- }
18
- exports.registerCachedTask = registerCachedTask;
3
+ exports.clearCache = void 0;
4
+ /**
5
+ * Clears the task cache.
6
+ * @deprecated Task caching has been removed. This function is a no-op.
7
+ */
19
8
  function clearCache() {
20
- const cachePath = getCachePath();
21
- const cacheFile = path.join(cachePath, CacheFileName);
22
- if (fs.existsSync(cacheFile)) {
23
- fs.removeSync(cacheFile);
24
- }
9
+ // no-op
25
10
  }
26
11
  exports.clearCache = clearCache;
27
- function isCached(taskName) {
28
- if (cachedTask.indexOf(taskName) < 0) {
29
- return false;
30
- }
31
- const currentHash = getHash(taskName);
32
- const cachePath = getCachePath();
33
- const cacheFile = path.join(cachePath, CacheFileName);
34
- if (!fs.existsSync(cacheFile)) {
35
- return false;
36
- }
37
- let shouldCache = false;
38
- try {
39
- const cachedHash = JSON.parse(fs.readFileSync(path.join(cachePath, CacheFileName)).toString());
40
- // TODO: make a more robust comparison
41
- shouldCache = JSON.stringify(currentHash) === JSON.stringify(cachedHash);
42
- }
43
- catch (e) {
44
- just_task_logger_1.logger.warn('Invalid package-deps.json detected');
45
- }
46
- return shouldCache;
47
- }
48
- exports.isCached = isCached;
49
- function saveCache(taskName) {
50
- if (cachedTask.indexOf(taskName) < 0) {
51
- return;
52
- }
53
- const cachePath = getCachePath();
54
- if (!fs.pathExistsSync(cachePath)) {
55
- fs.mkdirpSync(cachePath);
56
- }
57
- const cacheHash = getHash(taskName);
58
- if (cacheHash) {
59
- fs.writeFileSync(path.join(cachePath, 'package-deps.json'), JSON.stringify(cacheHash, null, 2));
60
- }
61
- }
62
- exports.saveCache = saveCache;
63
- function getPackageRootPath() {
64
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
65
- const packageJsonFilePath = (0, resolve_1.resolveCwd)('package.json');
66
- return path.dirname(packageJsonFilePath);
67
- }
68
- function getCachePath() {
69
- const rootPath = getPackageRootPath();
70
- return path.join(rootPath, 'node_modules/.just');
71
- }
72
- function getLockFileHashes() {
73
- const results = {};
74
- const lockFiles = ['shrinkwrap.yml', 'package-lock.json', 'yarn.lock', 'pnpmfile.js'];
75
- const gitRoot = (0, findGitRoot_1.findGitRoot)();
76
- const lsFileResults = (0, child_process_1.spawnSync)('git', ['ls-files', ...lockFiles], { cwd: gitRoot });
77
- if (lsFileResults.status !== 0) {
78
- return {};
79
- }
80
- const foundLockFiles = lsFileResults.stdout
81
- .toString()
82
- .split(/\n/)
83
- .map(l => l.trim());
84
- const hashResults = (0, child_process_1.spawnSync)('git', ['hash-object', ...foundLockFiles], { cwd: gitRoot });
85
- if (hashResults.status !== 0) {
86
- return {};
87
- }
88
- const hashes = hashResults.stdout
89
- .toString()
90
- .split(/\n/)
91
- .map(l => l.trim());
92
- foundLockFiles.forEach((foundLockFile, index) => {
93
- results[foundLockFile] = hashes[index];
94
- });
95
- return results;
96
- }
97
- function getHash(taskName) {
98
- (0, just_task_logger_1.mark)('cache:getHash');
99
- const { ...args } = (0, option_1.argv)();
100
- const packageRootPath = getPackageRootPath();
101
- const packageDeps = {
102
- ...Object.fromEntries((0, package_deps_hash_1.getPackageDeps)(packageRootPath)),
103
- ...getLockFileHashes(),
104
- };
105
- const hash = {
106
- args,
107
- taskName,
108
- hash: packageDeps,
109
- dependentHashTimestamps: getDependentHashTimestamps(),
110
- };
111
- just_task_logger_1.logger.perf('cache:getHash');
112
- return hash;
113
- }
114
- function getDependentHashTimestamps() {
115
- (0, just_task_logger_1.mark)('cache:getDependentHashTimestamps');
116
- const dependentPkgPaths = (0, findDependents_1.findDependents)();
117
- const timestampsByPackage = {};
118
- for (const pkgDepInfo of dependentPkgPaths) {
119
- const pkgPath = pkgDepInfo.path;
120
- const depHashFile = path.join(pkgPath, 'node_modules/.just', CacheFileName);
121
- const depPackageJson = JSON.parse(fs.readFileSync(path.join(pkgPath, 'package.json'), 'utf-8'));
122
- if (fs.existsSync(depHashFile)) {
123
- const stat = fs.statSync(depHashFile);
124
- timestampsByPackage[pkgDepInfo.name] = stat.mtimeMs;
125
- }
126
- else if (depPackageJson.scripts) {
127
- // always updated if no hash file is found for dependants
128
- timestampsByPackage[pkgDepInfo.name] = new Date().getTime();
129
- }
130
- }
131
- just_task_logger_1.logger.perf('cache:getDependentHashTimestamps');
132
- return timestampsByPackage;
133
- }
package/lib/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const undertaker_1 = require("./undertaker");
4
4
  const option_1 = require("./option");
5
- const just_task_logger_1 = require("just-task-logger");
5
+ const logger_1 = require("./logger");
6
6
  const config_1 = require("./config");
7
7
  const task_1 = require("./task");
8
8
  const originalEmitWarning = process.emitWarning;
@@ -55,7 +55,7 @@ if (command) {
55
55
  undertaker_1.undertaker.series(registry.get(command))(() => undefined);
56
56
  }
57
57
  else {
58
- just_task_logger_1.logger.error(`Command not defined: ${command}`);
58
+ logger_1.logger.error(`Command not defined: ${command}`);
59
59
  process.exitCode = 1;
60
60
  }
61
61
  }
package/lib/config.js CHANGED
@@ -5,7 +5,7 @@ const fs = require("fs");
5
5
  const path = require("path");
6
6
  const option_1 = require("./option");
7
7
  const resolve_1 = require("./resolve");
8
- const just_task_logger_1 = require("just-task-logger");
8
+ const logger_1 = require("./logger");
9
9
  const enableTypeScript_1 = require("./enableTypeScript");
10
10
  function resolveConfigFile(args) {
11
11
  for (const entry of [
@@ -37,21 +37,21 @@ function readConfig() {
37
37
  }
38
38
  try {
39
39
  const configModule = require(configFile);
40
- (0, just_task_logger_1.mark)('registry:configModule');
40
+ (0, logger_1.mark)('registry:configModule');
41
41
  if (typeof configModule === 'function') {
42
42
  configModule();
43
43
  }
44
- just_task_logger_1.logger.perf('registry:configModule');
44
+ logger_1.logger.perf('registry:configModule');
45
45
  return configModule;
46
46
  }
47
47
  catch (e) {
48
- just_task_logger_1.logger.error(`Invalid configuration file: ${configFile}`);
49
- just_task_logger_1.logger.error(`Error: ${e.stack || e.message || e}`);
48
+ logger_1.logger.error(`Invalid configuration file: ${configFile}`);
49
+ logger_1.logger.error(`Error: ${e.stack || e.message || e}`);
50
50
  process.exit(1);
51
51
  }
52
52
  }
53
53
  else {
54
- just_task_logger_1.logger.error(`Cannot find config file "${configFile}".`, `Please create a file called "just.config.js" in the root of the project next to "package.json".`);
54
+ logger_1.logger.error(`Cannot find config file "${configFile}".`, `Please create a file called "just.config.js" in the root of the project next to "package.json".`);
55
55
  }
56
56
  }
57
57
  exports.readConfig = readConfig;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.enableTypeScript = void 0;
4
4
  const resolve_1 = require("./resolve");
5
- const just_task_logger_1 = require("just-task-logger");
5
+ const logger_1 = require("./logger");
6
6
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
7
7
  function enableTypeScript({ transpileOnly = true, esm = false }) {
8
8
  const tsNodeModule = (0, resolve_1.resolve)('ts-node');
@@ -25,7 +25,7 @@ function enableTypeScript({ transpileOnly = true, esm = false }) {
25
25
  });
26
26
  }
27
27
  else {
28
- just_task_logger_1.logger.error(`In order to use TypeScript with just.config.ts, you need to install "ts-node" module:
28
+ logger_1.logger.error(`In order to use TypeScript with just.config.ts, you need to install "ts-node" module:
29
29
 
30
30
  npm install -D ts-node
31
31
 
@@ -10,6 +10,7 @@ export interface TaskContext {
10
10
  }
11
11
  export interface TaskFunction extends TaskFunctionParams {
12
12
  (this: TaskContext, done: (error?: any) => void): void | Duplex | NodeJS.Process | Promise<never> | any;
13
+ /** @deprecated Task caching has been removed. This property is a no-op. */
13
14
  cached?: () => void;
14
15
  description?: string;
15
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,oBAAY,IAAI,GAAG,MAAM,GAAG,YAAY,CAAC;AAEzC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAa,SAAQ,kBAAkB;IACtD,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;IACxG,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,oBAAY,IAAI,GAAG,MAAM,GAAG,YAAY,CAAC;AAEzC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAa,SAAQ,kBAAkB;IACtD,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;IACxG,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
package/lib/logger.d.ts CHANGED
@@ -1,2 +1,17 @@
1
- export * from 'just-task-logger';
1
+ export declare function mark(marker: string): void;
2
+ export interface Logger {
3
+ /** Whether verbose logging is enabled. Default false unless --verbose arg is given. */
4
+ enableVerbose: boolean;
5
+ /** Log to `console.info` with a timestamp, but only if verbose logging is enabled. */
6
+ verbose(...args: any[]): void;
7
+ /** Log to `console.info` with a timestamp. */
8
+ info(...args: any[]): void;
9
+ /** Log to `console.warn` with a timestamp. */
10
+ warn(...args: any[]): void;
11
+ /** Log to `console.error` with a timestamp. */
12
+ error(...args: any[]): void;
13
+ /** Log perf marker data to `consold.info` with timestamp, only if verbose is enabled */
14
+ perf(marker: string, ...args: any[]): void;
15
+ }
16
+ export declare const logger: Logger;
2
17
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAcA,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAEzC;AAYD,MAAM,WAAW,MAAM;IACrB,uFAAuF;IACvF,aAAa,EAAE,OAAO,CAAC;IACvB,sFAAsF;IACtF,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC9B,8CAA8C;IAC9C,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3B,8CAA8C;IAC9C,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3B,+CAA+C;IAC/C,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC5B,wFAAwF;IACxF,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CAC5C;AAMD,eAAO,MAAM,MAAM,EAAE,MAqCpB,CAAC"}
package/lib/logger.js CHANGED
@@ -1,13 +1,54 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
2
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("just-task-logger"), exports);
3
+ exports.logger = exports.mark = void 0;
4
+ const chalk = require("chalk");
5
+ const parser = require("yargs-parser");
6
+ const argv = parser(process.argv.slice(2));
7
+ function logInternal(method, symbol, ...args) {
8
+ const now = new Date();
9
+ const timestamp = chalk.gray(`[${now.toLocaleTimeString()}]`);
10
+ console[method](timestamp, symbol, ...args);
11
+ }
12
+ const markers = {};
13
+ function mark(marker) {
14
+ markers[marker] = process.hrtime();
15
+ }
16
+ exports.mark = mark;
17
+ function getDeltaAndClearMark(marker) {
18
+ if (markers[marker]) {
19
+ const delta = process.hrtime(markers[marker]);
20
+ delete markers[marker];
21
+ return delta;
22
+ }
23
+ return null;
24
+ }
25
+ const emptySquare = '\u25a1';
26
+ const square = '\u25a0';
27
+ const triangle = '\u25b2';
28
+ exports.logger = {
29
+ enableVerbose: !!argv.verbose,
30
+ verbose(...args) {
31
+ if (exports.logger.enableVerbose) {
32
+ logInternal('info', chalk.gray(emptySquare), ...args);
33
+ }
34
+ },
35
+ info(...args) {
36
+ logInternal('info', chalk.green(square), ...args);
37
+ },
38
+ warn(...args) {
39
+ logInternal('warn', chalk.yellow(triangle), ...args);
40
+ },
41
+ error(...args) {
42
+ logInternal('error', chalk.redBright('x'), ...args);
43
+ },
44
+ perf(marker, ...args) {
45
+ if (exports.logger.enableVerbose) {
46
+ const delta = getDeltaAndClearMark(marker);
47
+ if (delta) {
48
+ const ns = delta[0] * 1e9 + delta[1];
49
+ const deltaMsg = `${ns / 1e9}s`;
50
+ logInternal('info', chalk.cyan(square), `mark(${chalk.cyanBright(marker)}): took ${chalk.cyanBright(deltaMsg)}`, ...args);
51
+ }
52
+ }
53
+ },
54
+ };
package/lib/task.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../src/task.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,wBAAgB,IAAI,CAClB,UAAU,EAAE,MAAM,GAAG,YAAY,EACjC,WAAW,CAAC,EAAE,MAAM,GAAG,YAAY,EACnC,UAAU,CAAC,EAAE,YAAY,GACxB,YAAY,CA0Cd"}
1
+ {"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../src/task.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,wBAAgB,IAAI,CAClB,UAAU,EAAE,MAAM,GAAG,YAAY,EACjC,WAAW,CAAC,EAAE,MAAM,GAAG,YAAY,EACnC,UAAU,CAAC,EAAE,YAAY,GACxB,YAAY,CAiCd"}
package/lib/task.js CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.task = void 0;
4
4
  const undertaker_1 = require("./undertaker");
5
5
  const wrapTask_1 = require("./wrapTask");
6
- const cache_1 = require("./cache");
7
6
  function task(firstParam, secondParam, thirdParam) {
8
7
  const argCount = arguments.length;
9
8
  if (argCount === 1 && typeof firstParam === 'string') {
@@ -12,9 +11,6 @@ function task(firstParam, secondParam, thirdParam) {
12
11
  else if (argCount === 2 && isString(firstParam) && isString(secondParam)) {
13
12
  // task('default', 'build');
14
13
  const wrapped = (0, wrapTask_1.wrapTask)(undertaker_1.undertaker.series(secondParam));
15
- wrapped.cached = () => {
16
- (0, cache_1.registerCachedTask)(firstParam);
17
- };
18
14
  undertaker_1.undertaker.task(firstParam, wrapped);
19
15
  return wrapped;
20
16
  }
@@ -22,18 +18,12 @@ function task(firstParam, secondParam, thirdParam) {
22
18
  // task('pretter', prettierTask());
23
19
  // task('custom', () => { ... });
24
20
  const wrapped = (0, wrapTask_1.wrapTask)(secondParam);
25
- wrapped.cached = () => {
26
- (0, cache_1.registerCachedTask)(firstParam);
27
- };
28
21
  undertaker_1.undertaker.task(firstParam, wrapped);
29
22
  return wrapped;
30
23
  }
31
24
  else if (argCount === 3 && isString(firstParam) && isString(secondParam) && isTaskFunction(thirdParam)) {
32
25
  // task('custom', 'describes this thing', () => { ... })
33
26
  const wrapped = (0, wrapTask_1.wrapTask)(thirdParam);
34
- wrapped.cached = () => {
35
- (0, cache_1.registerCachedTask)(firstParam);
36
- };
37
27
  wrapped.description = secondParam;
38
28
  undertaker_1.undertaker.task(firstParam, wrapped);
39
29
  return wrapped;
@@ -1 +1 @@
1
- {"version":3,"file":"undertaker.d.ts","sourceRoot":"","sources":["../src/undertaker.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,OAAO,UAAU,GAAG,QAAQ,YAAY,CAAC,CAAC;AAE1C,QAAA,MAAM,UAAU,YAAmB,CAAC;AAgHpC,wBAAgB,QAAQ,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,YAAY,CAUlE;AAED,wBAAgB,MAAM,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,YAAY,CAUhE;AAID,OAAO,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"undertaker.d.ts","sourceRoot":"","sources":["../src/undertaker.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,UAAU,GAAG,QAAQ,YAAY,CAAC,CAAC;AAE1C,QAAA,MAAM,UAAU,YAAmB,CAAC;AA8GpC,wBAAgB,QAAQ,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,YAAY,CAUlE;AAED,wBAAgB,MAAM,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,YAAY,CAUhE;AAID,OAAO,EAAE,UAAU,EAAE,CAAC"}
package/lib/undertaker.js CHANGED
@@ -4,7 +4,6 @@ exports.undertaker = exports.series = exports.parallel = void 0;
4
4
  const logger_1 = require("./logger");
5
5
  const chalk = require("chalk");
6
6
  const wrapTask_1 = require("./wrapTask");
7
- const cache_1 = require("./cache");
8
7
  const Undertaker = require("undertaker");
9
8
  const undertaker = new Undertaker();
10
9
  exports.undertaker = undertaker;
@@ -65,7 +64,6 @@ undertaker.on('error', function (args) {
65
64
  logger_1.logger.error(args.error.stderr);
66
65
  }
67
66
  logger_1.logger.error(chalk.yellow('------------------------------------'));
68
- (0, cache_1.clearCache)();
69
67
  process.exitCode = 1;
70
68
  }
71
69
  else if (shouldLog(args)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-task",
3
- "version": "1.12.0",
3
+ "version": "1.14.0",
4
4
  "description": "Build task definition library",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -26,7 +26,6 @@
26
26
  "node": ">=14"
27
27
  },
28
28
  "dependencies": {
29
- "@rushstack/package-deps-hash": "^4.0.0",
30
29
  "@types/chokidar": "^2.1.3",
31
30
  "@types/undertaker": "^1.2.8",
32
31
  "@types/yargs-parser": "^20.2.2",
@@ -34,7 +33,6 @@
34
33
  "chalk": "^4.0.0",
35
34
  "chokidar": "^3.5.2",
36
35
  "fs-extra": "^11.0.0",
37
- "just-task-logger": ">=1.3.0 <2.0.0",
38
36
  "resolve": "^1.19.0",
39
37
  "undertaker": "^2.0.0",
40
38
  "undertaker-registry": "^2.0.0",
package/src/cache.ts CHANGED
@@ -1,170 +1,7 @@
1
- import { getPackageDeps } from '@rushstack/package-deps-hash';
2
- import { argv } from './option';
3
- import { resolveCwd } from './resolve';
4
- import * as fs from 'fs-extra';
5
- import * as path from 'path';
6
- import { logger, mark } from 'just-task-logger';
7
- import { findDependents } from './package/findDependents';
8
- import { findGitRoot } from './package/findGitRoot';
9
- import { spawnSync } from 'child_process';
10
-
11
- const cachedTask: string[] = [];
12
- const CacheFileName = 'package-deps.json';
13
-
14
- export function registerCachedTask(taskName: string): void {
15
- cachedTask.push(taskName);
16
- }
17
-
1
+ /**
2
+ * Clears the task cache.
3
+ * @deprecated Task caching has been removed. This function is a no-op.
4
+ */
18
5
  export function clearCache(): void {
19
- const cachePath = getCachePath();
20
- const cacheFile = path.join(cachePath, CacheFileName);
21
-
22
- if (fs.existsSync(cacheFile)) {
23
- fs.removeSync(cacheFile);
24
- }
25
- }
26
-
27
- export function isCached(taskName: string): boolean {
28
- if (cachedTask.indexOf(taskName) < 0) {
29
- return false;
30
- }
31
-
32
- const currentHash = getHash(taskName);
33
- const cachePath = getCachePath();
34
- const cacheFile = path.join(cachePath, CacheFileName);
35
-
36
- if (!fs.existsSync(cacheFile)) {
37
- return false;
38
- }
39
-
40
- let shouldCache = false;
41
-
42
- try {
43
- const cachedHash = JSON.parse(fs.readFileSync(path.join(cachePath, CacheFileName)).toString());
44
-
45
- // TODO: make a more robust comparison
46
- shouldCache = JSON.stringify(currentHash) === JSON.stringify(cachedHash);
47
- } catch (e) {
48
- logger.warn('Invalid package-deps.json detected');
49
- }
50
-
51
- return shouldCache;
52
- }
53
-
54
- export function saveCache(taskName: string): void {
55
- if (cachedTask.indexOf(taskName) < 0) {
56
- return;
57
- }
58
-
59
- const cachePath = getCachePath();
60
-
61
- if (!fs.pathExistsSync(cachePath)) {
62
- fs.mkdirpSync(cachePath);
63
- }
64
-
65
- const cacheHash = getHash(taskName);
66
-
67
- if (cacheHash) {
68
- fs.writeFileSync(path.join(cachePath, 'package-deps.json'), JSON.stringify(cacheHash, null, 2));
69
- }
70
- }
71
-
72
- function getPackageRootPath() {
73
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
74
- const packageJsonFilePath = resolveCwd('package.json')!;
75
- return path.dirname(packageJsonFilePath);
76
- }
77
-
78
- function getCachePath() {
79
- const rootPath = getPackageRootPath();
80
- return path.join(rootPath, 'node_modules/.just');
81
- }
82
-
83
- interface CacheHash {
84
- args: { [arg: string]: string };
85
- taskName: string;
86
- hash: Record<string, string>;
87
- dependentHashTimestamps: { [pkgName: string]: number };
88
- }
89
-
90
- function getLockFileHashes(): { [file: string]: string } {
91
- const results: { [file: string]: string } = {};
92
-
93
- const lockFiles = ['shrinkwrap.yml', 'package-lock.json', 'yarn.lock', 'pnpmfile.js'];
94
- const gitRoot = findGitRoot();
95
- const lsFileResults = spawnSync('git', ['ls-files', ...lockFiles], { cwd: gitRoot });
96
- if (lsFileResults.status !== 0) {
97
- return {};
98
- }
99
-
100
- const foundLockFiles = lsFileResults.stdout
101
- .toString()
102
- .split(/\n/)
103
- .map(l => l.trim());
104
-
105
- const hashResults = spawnSync('git', ['hash-object', ...foundLockFiles], { cwd: gitRoot });
106
-
107
- if (hashResults.status !== 0) {
108
- return {};
109
- }
110
-
111
- const hashes = hashResults.stdout
112
- .toString()
113
- .split(/\n/)
114
- .map(l => l.trim());
115
-
116
- foundLockFiles.forEach((foundLockFile, index) => {
117
- results[foundLockFile] = hashes[index];
118
- });
119
-
120
- return results;
121
- }
122
-
123
- function getHash(taskName: string): CacheHash | null {
124
- mark('cache:getHash');
125
-
126
- const { ...args } = argv();
127
-
128
- const packageRootPath = getPackageRootPath();
129
-
130
- const packageDeps = {
131
- ...Object.fromEntries(getPackageDeps(packageRootPath)),
132
- ...getLockFileHashes(),
133
- };
134
-
135
- const hash = {
136
- args,
137
- taskName,
138
- hash: packageDeps,
139
- dependentHashTimestamps: getDependentHashTimestamps(),
140
- };
141
-
142
- logger.perf('cache:getHash');
143
-
144
- return hash;
145
- }
146
-
147
- function getDependentHashTimestamps() {
148
- mark('cache:getDependentHashTimestamps');
149
- const dependentPkgPaths = findDependents();
150
-
151
- const timestampsByPackage: { [pkgName: string]: number } = {};
152
-
153
- for (const pkgDepInfo of dependentPkgPaths) {
154
- const pkgPath = pkgDepInfo.path;
155
- const depHashFile = path.join(pkgPath, 'node_modules/.just', CacheFileName);
156
- const depPackageJson = JSON.parse(fs.readFileSync(path.join(pkgPath, 'package.json'), 'utf-8'));
157
-
158
- if (fs.existsSync(depHashFile)) {
159
- const stat = fs.statSync(depHashFile);
160
- timestampsByPackage[pkgDepInfo.name] = stat.mtimeMs;
161
- } else if (depPackageJson.scripts) {
162
- // always updated if no hash file is found for dependants
163
- timestampsByPackage[pkgDepInfo.name] = new Date().getTime();
164
- }
165
- }
166
-
167
- logger.perf('cache:getDependentHashTimestamps');
168
-
169
- return timestampsByPackage;
6
+ // no-op
170
7
  }
package/src/cli.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { undertaker } from './undertaker';
2
2
  import { option, parseCommand } from './option';
3
- import { logger } from 'just-task-logger';
3
+ import { logger } from './logger';
4
4
  import { TaskFunction } from './interfaces';
5
5
  import { readConfig } from './config';
6
6
  import { task } from './task';
package/src/config.ts CHANGED
@@ -3,7 +3,7 @@ import * as path from 'path';
3
3
 
4
4
  import { argv } from './option';
5
5
  import { resolve } from './resolve';
6
- import { mark, logger } from 'just-task-logger';
6
+ import { mark, logger } from './logger';
7
7
  import { enableTypeScript } from './enableTypeScript';
8
8
  import yargsParser = require('yargs-parser');
9
9
  import { TaskFunction } from './interfaces';
@@ -1,5 +1,5 @@
1
1
  import { resolve } from './resolve';
2
- import { logger } from 'just-task-logger';
2
+ import { logger } from './logger';
3
3
 
4
4
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
5
5
  export function enableTypeScript({ transpileOnly = true, esm = false }): void {
package/src/interfaces.ts CHANGED
@@ -12,6 +12,7 @@ export interface TaskContext {
12
12
 
13
13
  export interface TaskFunction extends TaskFunctionParams {
14
14
  (this: TaskContext, done: (error?: any) => void): void | Duplex | NodeJS.Process | Promise<never> | any;
15
+ /** @deprecated Task caching has been removed. This property is a no-op. */
15
16
  cached?: () => void;
16
17
  description?: string;
17
18
  }