just-task 1.13.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.
- package/lib/cache.d.ts +4 -3
- package/lib/cache.d.ts.map +1 -1
- package/lib/cache.js +6 -128
- package/lib/interfaces.d.ts +1 -0
- package/lib/interfaces.d.ts.map +1 -1
- package/lib/task.d.ts.map +1 -1
- package/lib/task.js +0 -10
- package/lib/undertaker.d.ts.map +1 -1
- package/lib/undertaker.js +0 -2
- package/package.json +1 -2
- package/src/cache.ts +5 -168
- package/src/interfaces.ts +1 -0
- package/src/task.ts +0 -10
- package/src/undertaker.ts +0 -3
- package/CHANGELOG.json +0 -1329
- package/CHANGELOG.md +0 -637
- package/lib/package/findDependents.d.ts +0 -7
- package/lib/package/findDependents.d.ts.map +0 -1
- package/lib/package/findDependents.js +0 -56
- package/lib/package/findGitRoot.d.ts +0 -2
- package/lib/package/findGitRoot.d.ts.map +0 -1
- package/lib/package/findGitRoot.js +0 -26
- package/lib/package/findPackageRoot.d.ts +0 -2
- package/lib/package/findPackageRoot.d.ts.map +0 -1
- package/lib/package/findPackageRoot.js +0 -11
- package/lib/paths.d.ts +0 -2
- package/lib/paths.d.ts.map +0 -1
- package/lib/paths.js +0 -9
- package/src/package/findDependents.ts +0 -68
- package/src/package/findGitRoot.ts +0 -28
- package/src/package/findPackageRoot.ts +0 -8
- package/src/paths.ts +0 -6
package/lib/cache.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
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
|
package/lib/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"
|
|
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.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const path = require("path");
|
|
9
|
-
const logger_1 = require("./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
|
-
|
|
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
|
-
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, 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
|
-
logger_1.logger.perf('cache:getHash');
|
|
112
|
-
return hash;
|
|
113
|
-
}
|
|
114
|
-
function getDependentHashTimestamps() {
|
|
115
|
-
(0, 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
|
-
logger_1.logger.perf('cache:getDependentHashTimestamps');
|
|
132
|
-
return timestampsByPackage;
|
|
133
|
-
}
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -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
|
}
|
package/lib/interfaces.d.ts.map
CHANGED
|
@@ -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/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;
|
|
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;
|
package/lib/undertaker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undertaker.d.ts","sourceRoot":"","sources":["../src/undertaker.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,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.
|
|
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",
|
package/src/cache.ts
CHANGED
|
@@ -1,170 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import * as path from 'path';
|
|
6
|
-
import { logger, mark } from './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
|
-
|
|
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/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
|
}
|
package/src/task.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { undertaker } from './undertaker';
|
|
2
2
|
import { wrapTask } from './wrapTask';
|
|
3
3
|
import { TaskFunction } from './interfaces';
|
|
4
|
-
import { registerCachedTask } from './cache';
|
|
5
4
|
|
|
6
5
|
export function task(
|
|
7
6
|
firstParam: string | TaskFunction,
|
|
@@ -16,9 +15,6 @@ export function task(
|
|
|
16
15
|
// task('default', 'build');
|
|
17
16
|
|
|
18
17
|
const wrapped = wrapTask(undertaker.series(secondParam));
|
|
19
|
-
wrapped.cached = () => {
|
|
20
|
-
registerCachedTask(firstParam);
|
|
21
|
-
};
|
|
22
18
|
|
|
23
19
|
undertaker.task(firstParam, wrapped);
|
|
24
20
|
|
|
@@ -27,9 +23,6 @@ export function task(
|
|
|
27
23
|
// task('pretter', prettierTask());
|
|
28
24
|
// task('custom', () => { ... });
|
|
29
25
|
const wrapped = wrapTask(secondParam as TaskFunction) as TaskFunction;
|
|
30
|
-
wrapped.cached = () => {
|
|
31
|
-
registerCachedTask(firstParam);
|
|
32
|
-
};
|
|
33
26
|
|
|
34
27
|
undertaker.task(firstParam, wrapped);
|
|
35
28
|
|
|
@@ -37,9 +30,6 @@ export function task(
|
|
|
37
30
|
} else if (argCount === 3 && isString(firstParam) && isString(secondParam) && isTaskFunction(thirdParam)) {
|
|
38
31
|
// task('custom', 'describes this thing', () => { ... })
|
|
39
32
|
const wrapped = wrapTask(thirdParam);
|
|
40
|
-
wrapped.cached = () => {
|
|
41
|
-
registerCachedTask(firstParam);
|
|
42
|
-
};
|
|
43
33
|
|
|
44
34
|
wrapped.description = secondParam;
|
|
45
35
|
|
package/src/undertaker.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { logger } from './logger';
|
|
|
2
2
|
import chalk = require('chalk');
|
|
3
3
|
import { wrapTask } from './wrapTask';
|
|
4
4
|
import { Task } from './interfaces';
|
|
5
|
-
import { clearCache } from './cache';
|
|
6
5
|
import Undertaker = require('undertaker');
|
|
7
6
|
|
|
8
7
|
const undertaker = new Undertaker();
|
|
@@ -84,8 +83,6 @@ undertaker.on('error', function (args: any) {
|
|
|
84
83
|
|
|
85
84
|
logger.error(chalk.yellow('------------------------------------'));
|
|
86
85
|
|
|
87
|
-
clearCache();
|
|
88
|
-
|
|
89
86
|
process.exitCode = 1;
|
|
90
87
|
} else if (shouldLog(args)) {
|
|
91
88
|
const duration = args.duration;
|