@alexaegis/turbowatch 0.9.1 → 0.9.3
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/index.cjs +3 -114
- package/index.js +3 -114
- package/local-node-modules.cjs +2 -7
- package/local-node-modules.js +2 -7
- package/package.json +13 -13
- package/watch-local-node-modules-3uJuYV7q.cjs +115 -0
- package/watch-local-node-modules-4nEURxpr.js +116 -0
package/index.cjs
CHANGED
|
@@ -1,116 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const node_path = require("node:path");
|
|
7
|
-
const fs = require("@alexaegis/fs");
|
|
8
|
-
const normalizeTurbowatchLocalNodeModulesOptions = (options) => {
|
|
9
|
-
return {
|
|
10
|
-
...fs.normalizeCwdOption(options),
|
|
11
|
-
deep: options?.deep ?? true,
|
|
12
|
-
useGitIgnore: options?.useGitIgnore ?? false,
|
|
13
|
-
logChangedFiles: options?.logChangedFiles ?? false,
|
|
14
|
-
buildDependenciesScript: options?.buildDependenciesScript ?? "build:dependencies",
|
|
15
|
-
packageManagerCommand: options?.packageManagerCommand ?? "pnpm",
|
|
16
|
-
onFirstBuild: options?.onFirstBuild,
|
|
17
|
-
devScript: options?.devScript ?? "dev_"
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
const turbowatchLocalNodeModules = async (rawOptions) => {
|
|
21
|
-
const options = normalizeTurbowatchLocalNodeModulesOptions(rawOptions);
|
|
22
|
-
console.log("turbowatch started in", options.cwd);
|
|
23
|
-
const currentPackagePath = workspaceTools.getCurrentPackageRoot(options.cwd);
|
|
24
|
-
if (!currentPackagePath) {
|
|
25
|
-
throw new Error("Not in a package!");
|
|
26
|
-
}
|
|
27
|
-
const currentPackagesNodeModulesPath = node_path.join(currentPackagePath, workspaceTools.NODE_MODULES_DIRECTORY_NAME);
|
|
28
|
-
const workspacePackages = await workspaceTools.collectWorkspacePackages({
|
|
29
|
-
...options,
|
|
30
|
-
skipWorkspaceRoot: true
|
|
31
|
-
});
|
|
32
|
-
const doNotMatchPackageJson = ["not", ["match", "package.json", "basename"]];
|
|
33
|
-
const matchInLocalPackageDirectories = [
|
|
34
|
-
"anyof",
|
|
35
|
-
...workspacePackages.map((workspacePackage) => workspacePackage.packageJson.name).filter(common.isNotNullish).map((packageName) => ["dirname", packageName])
|
|
36
|
-
];
|
|
37
|
-
const commonIgnoredDirs = [
|
|
38
|
-
["dirname", "dist"],
|
|
39
|
-
["dirname", "out"],
|
|
40
|
-
["dirname", "build"],
|
|
41
|
-
["dirname", "coverage"],
|
|
42
|
-
["dirname", ".turbo"],
|
|
43
|
-
["dirname", ".vercel"],
|
|
44
|
-
["dirname", ".cache"],
|
|
45
|
-
["dirname", ".svelte-kit"],
|
|
46
|
-
["dirname", ".next"],
|
|
47
|
-
["match", "vite(st)?.config.*"]
|
|
48
|
-
];
|
|
49
|
-
if (!options.deep) {
|
|
50
|
-
commonIgnoredDirs.push(["dirname", "node_modules"]);
|
|
51
|
-
}
|
|
52
|
-
const doNotMatchCommonOutputs = ["not", ["anyof", ...commonIgnoredDirs]];
|
|
53
|
-
const watchExpression = [
|
|
54
|
-
"allof",
|
|
55
|
-
matchInLocalPackageDirectories,
|
|
56
|
-
doNotMatchCommonOutputs,
|
|
57
|
-
doNotMatchPackageJson
|
|
58
|
-
];
|
|
59
|
-
if (options.useGitIgnore) {
|
|
60
|
-
let ignoreEntries = await workspaceTools.collectIgnoreEntries(options);
|
|
61
|
-
if (options.deep) {
|
|
62
|
-
ignoreEntries = ignoreEntries.filter(
|
|
63
|
-
(entry) => !entry.includes(workspaceTools.NODE_MODULES_DIRECTORY_NAME)
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
const ignoreMatchEntries = ignoreEntries.map((ignoreEntry) => [
|
|
67
|
-
"match",
|
|
68
|
-
ignoreEntry
|
|
69
|
-
]);
|
|
70
|
-
const doNotMatchIgnored = ["not", ["anyof", ...ignoreMatchEntries]];
|
|
71
|
-
watchExpression.push(doNotMatchIgnored);
|
|
72
|
-
}
|
|
73
|
-
let changeCount = 0;
|
|
74
|
-
const startCommand = () => {
|
|
75
|
-
return node_child_process.spawn(options.packageManagerCommand, ["run", options.devScript], {
|
|
76
|
-
stdio: "inherit"
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
let spawnedOnFirstBuild;
|
|
80
|
-
const abortController = new AbortController();
|
|
81
|
-
return {
|
|
82
|
-
project: currentPackagesNodeModulesPath,
|
|
83
|
-
debounce: { wait: 50 },
|
|
84
|
-
abortController,
|
|
85
|
-
triggers: [
|
|
86
|
-
{
|
|
87
|
-
expression: watchExpression,
|
|
88
|
-
name: "build",
|
|
89
|
-
retry: { retries: 0 },
|
|
90
|
-
onChange: async ({ spawn: spawn2, files }) => {
|
|
91
|
-
if (options.logChangedFiles) {
|
|
92
|
-
console.log("changed files:", files);
|
|
93
|
-
}
|
|
94
|
-
await spawn2`${options.packageManagerCommand} run ${options.buildDependenciesScript}`;
|
|
95
|
-
if (changeCount < 1) {
|
|
96
|
-
spawnedOnFirstBuild = options.onFirstBuild ? options.onFirstBuild() : startCommand();
|
|
97
|
-
if (spawnedOnFirstBuild) {
|
|
98
|
-
spawnedOnFirstBuild.on("exit", () => {
|
|
99
|
-
abortController.abort("onFirstBuild command exited!");
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
changeCount++;
|
|
104
|
-
},
|
|
105
|
-
onTeardown: async () => {
|
|
106
|
-
if (spawnedOnFirstBuild) {
|
|
107
|
-
spawnedOnFirstBuild.kill();
|
|
108
|
-
}
|
|
109
|
-
await common.noopAsync();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
]
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
exports.normalizeTurbowatchLocalNodeModulesOptions = normalizeTurbowatchLocalNodeModulesOptions;
|
|
116
|
-
exports.turbowatchLocalNodeModules = turbowatchLocalNodeModules;
|
|
3
|
+
const watchLocalNodeModules = require("./watch-local-node-modules-3uJuYV7q.cjs");
|
|
4
|
+
exports.normalizeTurbowatchLocalNodeModulesOptions = watchLocalNodeModules.normalizeTurbowatchLocalNodeModulesOptions;
|
|
5
|
+
exports.turbowatchLocalNodeModules = watchLocalNodeModules.turbowatchLocalNodeModules;
|
package/index.js
CHANGED
|
@@ -1,116 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getCurrentPackageRoot, NODE_MODULES_DIRECTORY_NAME, collectWorkspacePackages, collectIgnoreEntries } from "@alexaegis/workspace-tools";
|
|
3
|
-
import { spawn } from "node:child_process";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { normalizeCwdOption } from "@alexaegis/fs";
|
|
6
|
-
const normalizeTurbowatchLocalNodeModulesOptions = (options) => {
|
|
7
|
-
return {
|
|
8
|
-
...normalizeCwdOption(options),
|
|
9
|
-
deep: options?.deep ?? true,
|
|
10
|
-
useGitIgnore: options?.useGitIgnore ?? false,
|
|
11
|
-
logChangedFiles: options?.logChangedFiles ?? false,
|
|
12
|
-
buildDependenciesScript: options?.buildDependenciesScript ?? "build:dependencies",
|
|
13
|
-
packageManagerCommand: options?.packageManagerCommand ?? "pnpm",
|
|
14
|
-
onFirstBuild: options?.onFirstBuild,
|
|
15
|
-
devScript: options?.devScript ?? "dev_"
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
const turbowatchLocalNodeModules = async (rawOptions) => {
|
|
19
|
-
const options = normalizeTurbowatchLocalNodeModulesOptions(rawOptions);
|
|
20
|
-
console.log("turbowatch started in", options.cwd);
|
|
21
|
-
const currentPackagePath = getCurrentPackageRoot(options.cwd);
|
|
22
|
-
if (!currentPackagePath) {
|
|
23
|
-
throw new Error("Not in a package!");
|
|
24
|
-
}
|
|
25
|
-
const currentPackagesNodeModulesPath = join(currentPackagePath, NODE_MODULES_DIRECTORY_NAME);
|
|
26
|
-
const workspacePackages = await collectWorkspacePackages({
|
|
27
|
-
...options,
|
|
28
|
-
skipWorkspaceRoot: true
|
|
29
|
-
});
|
|
30
|
-
const doNotMatchPackageJson = ["not", ["match", "package.json", "basename"]];
|
|
31
|
-
const matchInLocalPackageDirectories = [
|
|
32
|
-
"anyof",
|
|
33
|
-
...workspacePackages.map((workspacePackage) => workspacePackage.packageJson.name).filter(isNotNullish).map((packageName) => ["dirname", packageName])
|
|
34
|
-
];
|
|
35
|
-
const commonIgnoredDirs = [
|
|
36
|
-
["dirname", "dist"],
|
|
37
|
-
["dirname", "out"],
|
|
38
|
-
["dirname", "build"],
|
|
39
|
-
["dirname", "coverage"],
|
|
40
|
-
["dirname", ".turbo"],
|
|
41
|
-
["dirname", ".vercel"],
|
|
42
|
-
["dirname", ".cache"],
|
|
43
|
-
["dirname", ".svelte-kit"],
|
|
44
|
-
["dirname", ".next"],
|
|
45
|
-
["match", "vite(st)?.config.*"]
|
|
46
|
-
];
|
|
47
|
-
if (!options.deep) {
|
|
48
|
-
commonIgnoredDirs.push(["dirname", "node_modules"]);
|
|
49
|
-
}
|
|
50
|
-
const doNotMatchCommonOutputs = ["not", ["anyof", ...commonIgnoredDirs]];
|
|
51
|
-
const watchExpression = [
|
|
52
|
-
"allof",
|
|
53
|
-
matchInLocalPackageDirectories,
|
|
54
|
-
doNotMatchCommonOutputs,
|
|
55
|
-
doNotMatchPackageJson
|
|
56
|
-
];
|
|
57
|
-
if (options.useGitIgnore) {
|
|
58
|
-
let ignoreEntries = await collectIgnoreEntries(options);
|
|
59
|
-
if (options.deep) {
|
|
60
|
-
ignoreEntries = ignoreEntries.filter(
|
|
61
|
-
(entry) => !entry.includes(NODE_MODULES_DIRECTORY_NAME)
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
const ignoreMatchEntries = ignoreEntries.map((ignoreEntry) => [
|
|
65
|
-
"match",
|
|
66
|
-
ignoreEntry
|
|
67
|
-
]);
|
|
68
|
-
const doNotMatchIgnored = ["not", ["anyof", ...ignoreMatchEntries]];
|
|
69
|
-
watchExpression.push(doNotMatchIgnored);
|
|
70
|
-
}
|
|
71
|
-
let changeCount = 0;
|
|
72
|
-
const startCommand = () => {
|
|
73
|
-
return spawn(options.packageManagerCommand, ["run", options.devScript], {
|
|
74
|
-
stdio: "inherit"
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
let spawnedOnFirstBuild;
|
|
78
|
-
const abortController = new AbortController();
|
|
79
|
-
return {
|
|
80
|
-
project: currentPackagesNodeModulesPath,
|
|
81
|
-
debounce: { wait: 50 },
|
|
82
|
-
abortController,
|
|
83
|
-
triggers: [
|
|
84
|
-
{
|
|
85
|
-
expression: watchExpression,
|
|
86
|
-
name: "build",
|
|
87
|
-
retry: { retries: 0 },
|
|
88
|
-
onChange: async ({ spawn: spawn2, files }) => {
|
|
89
|
-
if (options.logChangedFiles) {
|
|
90
|
-
console.log("changed files:", files);
|
|
91
|
-
}
|
|
92
|
-
await spawn2`${options.packageManagerCommand} run ${options.buildDependenciesScript}`;
|
|
93
|
-
if (changeCount < 1) {
|
|
94
|
-
spawnedOnFirstBuild = options.onFirstBuild ? options.onFirstBuild() : startCommand();
|
|
95
|
-
if (spawnedOnFirstBuild) {
|
|
96
|
-
spawnedOnFirstBuild.on("exit", () => {
|
|
97
|
-
abortController.abort("onFirstBuild command exited!");
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
changeCount++;
|
|
102
|
-
},
|
|
103
|
-
onTeardown: async () => {
|
|
104
|
-
if (spawnedOnFirstBuild) {
|
|
105
|
-
spawnedOnFirstBuild.kill();
|
|
106
|
-
}
|
|
107
|
-
await noopAsync();
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
]
|
|
111
|
-
};
|
|
112
|
-
};
|
|
1
|
+
import { n, t } from "./watch-local-node-modules-4nEURxpr.js";
|
|
113
2
|
export {
|
|
114
|
-
normalizeTurbowatchLocalNodeModulesOptions,
|
|
115
|
-
turbowatchLocalNodeModules
|
|
3
|
+
n as normalizeTurbowatchLocalNodeModulesOptions,
|
|
4
|
+
t as turbowatchLocalNodeModules
|
|
116
5
|
};
|
package/local-node-modules.cjs
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
require("@alexaegis/workspace-tools");
|
|
6
|
-
require("node:child_process");
|
|
7
|
-
require("node:path");
|
|
8
|
-
require("@alexaegis/fs");
|
|
9
|
-
exports.turbowatchLocalNodeModules = index.turbowatchLocalNodeModules;
|
|
3
|
+
const watchLocalNodeModules = require("./watch-local-node-modules-3uJuYV7q.cjs");
|
|
4
|
+
exports.turbowatchLocalNodeModules = watchLocalNodeModules.turbowatchLocalNodeModules;
|
package/local-node-modules.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "@alexaegis/common";
|
|
3
|
-
import "@alexaegis/workspace-tools";
|
|
4
|
-
import "node:child_process";
|
|
5
|
-
import "node:path";
|
|
6
|
-
import "@alexaegis/fs";
|
|
1
|
+
import { t } from "./watch-local-node-modules-4nEURxpr.js";
|
|
7
2
|
export {
|
|
8
|
-
turbowatchLocalNodeModules
|
|
3
|
+
t as turbowatchLocalNodeModules
|
|
9
4
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexaegis/turbowatch",
|
|
3
3
|
"description": "A turbowatch configuration to watch local dependencies through node_modules",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
7
|
"archetype": {
|
|
@@ -55,21 +55,21 @@
|
|
|
55
55
|
"./readme": "./readme.md"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@alexaegis/common": "^0.8.
|
|
59
|
-
"@alexaegis/fs": "^0.8.
|
|
60
|
-
"@alexaegis/workspace-tools": "^0.8.
|
|
58
|
+
"@alexaegis/common": "^0.8.2",
|
|
59
|
+
"@alexaegis/fs": "^0.8.2",
|
|
60
|
+
"@alexaegis/workspace-tools": "^0.8.2"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@alexaegis/eslint-config-vitest": "^0.9.
|
|
64
|
-
"@alexaegis/ts": "^0.9.
|
|
65
|
-
"@alexaegis/vite": "^0.9.
|
|
66
|
-
"@alexaegis/vitest": "^0.9.
|
|
67
|
-
"@types/node": "^20.
|
|
68
|
-
"publint": "^0.2.
|
|
63
|
+
"@alexaegis/eslint-config-vitest": "^0.9.3",
|
|
64
|
+
"@alexaegis/ts": "^0.9.3",
|
|
65
|
+
"@alexaegis/vite": "^0.9.3",
|
|
66
|
+
"@alexaegis/vitest": "^0.9.3",
|
|
67
|
+
"@types/node": "^20.11.17",
|
|
68
|
+
"publint": "^0.2.7",
|
|
69
69
|
"turbowatch": "^2.29.4",
|
|
70
|
-
"typescript": "^5.3.
|
|
71
|
-
"vite": "^5.0
|
|
72
|
-
"vitest": "^
|
|
70
|
+
"typescript": "^5.3.3",
|
|
71
|
+
"vite": "^5.1.0",
|
|
72
|
+
"vitest": "^1.2.2"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
75
|
"lint:depcheck": "turbo run lint:depcheck_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/turbowatch",
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const common = require("@alexaegis/common");
|
|
3
|
+
const workspaceTools = require("@alexaegis/workspace-tools");
|
|
4
|
+
const node_child_process = require("node:child_process");
|
|
5
|
+
const node_path = require("node:path");
|
|
6
|
+
const fs = require("@alexaegis/fs");
|
|
7
|
+
const normalizeTurbowatchLocalNodeModulesOptions = (options) => {
|
|
8
|
+
return {
|
|
9
|
+
...fs.normalizeCwdOption(options),
|
|
10
|
+
deep: options?.deep ?? true,
|
|
11
|
+
useGitIgnore: options?.useGitIgnore ?? false,
|
|
12
|
+
logChangedFiles: options?.logChangedFiles ?? false,
|
|
13
|
+
buildDependenciesScript: options?.buildDependenciesScript ?? "build:dependencies",
|
|
14
|
+
packageManagerCommand: options?.packageManagerCommand ?? "pnpm",
|
|
15
|
+
onFirstBuild: options?.onFirstBuild,
|
|
16
|
+
devScript: options?.devScript ?? "dev_"
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
const turbowatchLocalNodeModules = async (rawOptions) => {
|
|
20
|
+
const options = normalizeTurbowatchLocalNodeModulesOptions(rawOptions);
|
|
21
|
+
console.log("turbowatch started in", options.cwd);
|
|
22
|
+
const currentPackagePath = workspaceTools.getCurrentPackageRoot(options.cwd);
|
|
23
|
+
if (!currentPackagePath) {
|
|
24
|
+
throw new Error("Not in a package!");
|
|
25
|
+
}
|
|
26
|
+
const currentPackagesNodeModulesPath = node_path.join(currentPackagePath, workspaceTools.NODE_MODULES_DIRECTORY_NAME);
|
|
27
|
+
const workspacePackages = await workspaceTools.collectWorkspacePackages({
|
|
28
|
+
...options,
|
|
29
|
+
skipWorkspaceRoot: true
|
|
30
|
+
});
|
|
31
|
+
const doNotMatchPackageJson = ["not", ["match", "package.json", "basename"]];
|
|
32
|
+
const matchInLocalPackageDirectories = [
|
|
33
|
+
"anyof",
|
|
34
|
+
...workspacePackages.map((workspacePackage) => workspacePackage.packageJson.name).filter(common.isNotNullish).map((packageName) => ["dirname", packageName])
|
|
35
|
+
];
|
|
36
|
+
const commonIgnoredDirs = [
|
|
37
|
+
["dirname", "dist"],
|
|
38
|
+
["dirname", "out"],
|
|
39
|
+
["dirname", "build"],
|
|
40
|
+
["dirname", "coverage"],
|
|
41
|
+
["dirname", ".turbo"],
|
|
42
|
+
["dirname", ".vercel"],
|
|
43
|
+
["dirname", ".cache"],
|
|
44
|
+
["dirname", ".svelte-kit"],
|
|
45
|
+
["dirname", ".next"],
|
|
46
|
+
["match", "vite(st)?.config.*"]
|
|
47
|
+
];
|
|
48
|
+
if (!options.deep) {
|
|
49
|
+
commonIgnoredDirs.push(["dirname", "node_modules"]);
|
|
50
|
+
}
|
|
51
|
+
const doNotMatchCommonOutputs = ["not", ["anyof", ...commonIgnoredDirs]];
|
|
52
|
+
const watchExpression = [
|
|
53
|
+
"allof",
|
|
54
|
+
matchInLocalPackageDirectories,
|
|
55
|
+
doNotMatchCommonOutputs,
|
|
56
|
+
doNotMatchPackageJson
|
|
57
|
+
];
|
|
58
|
+
if (options.useGitIgnore) {
|
|
59
|
+
let ignoreEntries = await workspaceTools.collectIgnoreEntries(options);
|
|
60
|
+
if (options.deep) {
|
|
61
|
+
ignoreEntries = ignoreEntries.filter(
|
|
62
|
+
(entry) => !entry.includes(workspaceTools.NODE_MODULES_DIRECTORY_NAME)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
const ignoreMatchEntries = ignoreEntries.map((ignoreEntry) => [
|
|
66
|
+
"match",
|
|
67
|
+
ignoreEntry
|
|
68
|
+
]);
|
|
69
|
+
const doNotMatchIgnored = ["not", ["anyof", ...ignoreMatchEntries]];
|
|
70
|
+
watchExpression.push(doNotMatchIgnored);
|
|
71
|
+
}
|
|
72
|
+
let changeCount = 0;
|
|
73
|
+
const startCommand = () => {
|
|
74
|
+
return node_child_process.spawn(options.packageManagerCommand, ["run", options.devScript], {
|
|
75
|
+
stdio: "inherit"
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
let spawnedOnFirstBuild;
|
|
79
|
+
const abortController = new AbortController();
|
|
80
|
+
return {
|
|
81
|
+
project: currentPackagesNodeModulesPath,
|
|
82
|
+
debounce: { wait: 50 },
|
|
83
|
+
abortController,
|
|
84
|
+
triggers: [
|
|
85
|
+
{
|
|
86
|
+
expression: watchExpression,
|
|
87
|
+
name: "build",
|
|
88
|
+
retry: { retries: 0 },
|
|
89
|
+
onChange: async ({ spawn: spawn2, files }) => {
|
|
90
|
+
if (options.logChangedFiles) {
|
|
91
|
+
console.log("changed files:", files);
|
|
92
|
+
}
|
|
93
|
+
await spawn2`${options.packageManagerCommand} run ${options.buildDependenciesScript}`;
|
|
94
|
+
if (changeCount < 1) {
|
|
95
|
+
spawnedOnFirstBuild = options.onFirstBuild ? options.onFirstBuild() : startCommand();
|
|
96
|
+
if (spawnedOnFirstBuild) {
|
|
97
|
+
spawnedOnFirstBuild.on("exit", () => {
|
|
98
|
+
abortController.abort("onFirstBuild command exited!");
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
changeCount++;
|
|
103
|
+
},
|
|
104
|
+
onTeardown: async () => {
|
|
105
|
+
if (spawnedOnFirstBuild) {
|
|
106
|
+
spawnedOnFirstBuild.kill();
|
|
107
|
+
}
|
|
108
|
+
await common.noopAsync();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
exports.normalizeTurbowatchLocalNodeModulesOptions = normalizeTurbowatchLocalNodeModulesOptions;
|
|
115
|
+
exports.turbowatchLocalNodeModules = turbowatchLocalNodeModules;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { isNotNullish, noopAsync } from "@alexaegis/common";
|
|
2
|
+
import { getCurrentPackageRoot, NODE_MODULES_DIRECTORY_NAME, collectWorkspacePackages, collectIgnoreEntries } from "@alexaegis/workspace-tools";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { normalizeCwdOption } from "@alexaegis/fs";
|
|
6
|
+
const normalizeTurbowatchLocalNodeModulesOptions = (options) => {
|
|
7
|
+
return {
|
|
8
|
+
...normalizeCwdOption(options),
|
|
9
|
+
deep: options?.deep ?? true,
|
|
10
|
+
useGitIgnore: options?.useGitIgnore ?? false,
|
|
11
|
+
logChangedFiles: options?.logChangedFiles ?? false,
|
|
12
|
+
buildDependenciesScript: options?.buildDependenciesScript ?? "build:dependencies",
|
|
13
|
+
packageManagerCommand: options?.packageManagerCommand ?? "pnpm",
|
|
14
|
+
onFirstBuild: options?.onFirstBuild,
|
|
15
|
+
devScript: options?.devScript ?? "dev_"
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const turbowatchLocalNodeModules = async (rawOptions) => {
|
|
19
|
+
const options = normalizeTurbowatchLocalNodeModulesOptions(rawOptions);
|
|
20
|
+
console.log("turbowatch started in", options.cwd);
|
|
21
|
+
const currentPackagePath = getCurrentPackageRoot(options.cwd);
|
|
22
|
+
if (!currentPackagePath) {
|
|
23
|
+
throw new Error("Not in a package!");
|
|
24
|
+
}
|
|
25
|
+
const currentPackagesNodeModulesPath = join(currentPackagePath, NODE_MODULES_DIRECTORY_NAME);
|
|
26
|
+
const workspacePackages = await collectWorkspacePackages({
|
|
27
|
+
...options,
|
|
28
|
+
skipWorkspaceRoot: true
|
|
29
|
+
});
|
|
30
|
+
const doNotMatchPackageJson = ["not", ["match", "package.json", "basename"]];
|
|
31
|
+
const matchInLocalPackageDirectories = [
|
|
32
|
+
"anyof",
|
|
33
|
+
...workspacePackages.map((workspacePackage) => workspacePackage.packageJson.name).filter(isNotNullish).map((packageName) => ["dirname", packageName])
|
|
34
|
+
];
|
|
35
|
+
const commonIgnoredDirs = [
|
|
36
|
+
["dirname", "dist"],
|
|
37
|
+
["dirname", "out"],
|
|
38
|
+
["dirname", "build"],
|
|
39
|
+
["dirname", "coverage"],
|
|
40
|
+
["dirname", ".turbo"],
|
|
41
|
+
["dirname", ".vercel"],
|
|
42
|
+
["dirname", ".cache"],
|
|
43
|
+
["dirname", ".svelte-kit"],
|
|
44
|
+
["dirname", ".next"],
|
|
45
|
+
["match", "vite(st)?.config.*"]
|
|
46
|
+
];
|
|
47
|
+
if (!options.deep) {
|
|
48
|
+
commonIgnoredDirs.push(["dirname", "node_modules"]);
|
|
49
|
+
}
|
|
50
|
+
const doNotMatchCommonOutputs = ["not", ["anyof", ...commonIgnoredDirs]];
|
|
51
|
+
const watchExpression = [
|
|
52
|
+
"allof",
|
|
53
|
+
matchInLocalPackageDirectories,
|
|
54
|
+
doNotMatchCommonOutputs,
|
|
55
|
+
doNotMatchPackageJson
|
|
56
|
+
];
|
|
57
|
+
if (options.useGitIgnore) {
|
|
58
|
+
let ignoreEntries = await collectIgnoreEntries(options);
|
|
59
|
+
if (options.deep) {
|
|
60
|
+
ignoreEntries = ignoreEntries.filter(
|
|
61
|
+
(entry) => !entry.includes(NODE_MODULES_DIRECTORY_NAME)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
const ignoreMatchEntries = ignoreEntries.map((ignoreEntry) => [
|
|
65
|
+
"match",
|
|
66
|
+
ignoreEntry
|
|
67
|
+
]);
|
|
68
|
+
const doNotMatchIgnored = ["not", ["anyof", ...ignoreMatchEntries]];
|
|
69
|
+
watchExpression.push(doNotMatchIgnored);
|
|
70
|
+
}
|
|
71
|
+
let changeCount = 0;
|
|
72
|
+
const startCommand = () => {
|
|
73
|
+
return spawn(options.packageManagerCommand, ["run", options.devScript], {
|
|
74
|
+
stdio: "inherit"
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
let spawnedOnFirstBuild;
|
|
78
|
+
const abortController = new AbortController();
|
|
79
|
+
return {
|
|
80
|
+
project: currentPackagesNodeModulesPath,
|
|
81
|
+
debounce: { wait: 50 },
|
|
82
|
+
abortController,
|
|
83
|
+
triggers: [
|
|
84
|
+
{
|
|
85
|
+
expression: watchExpression,
|
|
86
|
+
name: "build",
|
|
87
|
+
retry: { retries: 0 },
|
|
88
|
+
onChange: async ({ spawn: spawn2, files }) => {
|
|
89
|
+
if (options.logChangedFiles) {
|
|
90
|
+
console.log("changed files:", files);
|
|
91
|
+
}
|
|
92
|
+
await spawn2`${options.packageManagerCommand} run ${options.buildDependenciesScript}`;
|
|
93
|
+
if (changeCount < 1) {
|
|
94
|
+
spawnedOnFirstBuild = options.onFirstBuild ? options.onFirstBuild() : startCommand();
|
|
95
|
+
if (spawnedOnFirstBuild) {
|
|
96
|
+
spawnedOnFirstBuild.on("exit", () => {
|
|
97
|
+
abortController.abort("onFirstBuild command exited!");
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
changeCount++;
|
|
102
|
+
},
|
|
103
|
+
onTeardown: async () => {
|
|
104
|
+
if (spawnedOnFirstBuild) {
|
|
105
|
+
spawnedOnFirstBuild.kill();
|
|
106
|
+
}
|
|
107
|
+
await noopAsync();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
export {
|
|
114
|
+
normalizeTurbowatchLocalNodeModulesOptions as n,
|
|
115
|
+
turbowatchLocalNodeModules as t
|
|
116
|
+
};
|