@alexaegis/turbowatch 0.14.0 → 0.15.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/dist/index.cjs +4 -0
- package/dist/index.js +2 -0
- package/dist/local-node-modules.cjs +3 -0
- package/dist/local-node-modules.js +2 -0
- package/dist/watch-local-node-modules-0DugEhkt.cjs +120 -0
- package/dist/watch-local-node-modules-0DugEhkt.cjs.map +1 -0
- package/dist/watch-local-node-modules-gDrf144G.js +109 -0
- package/dist/watch-local-node-modules-gDrf144G.js.map +1 -0
- package/package.json +28 -42
- package/index.cjs +0 -5
- package/index.js +0 -5
- package/license +0 -21
- package/local-node-modules.cjs +0 -4
- package/local-node-modules.js +0 -4
- package/watch-local-node-modules-BzPCh3jr.js +0 -116
- package/watch-local-node-modules-CB61jc7h.cjs +0 -115
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.d.ts.map → dist/index.d.ts.map} +0 -0
- /package/{index.spec.d.ts → dist/index.spec.d.ts} +0 -0
- /package/{index.spec.d.ts.map → dist/index.spec.d.ts.map} +0 -0
- /package/{internal → dist/internal}/watch-local-node-modules.d.ts +0 -0
- /package/{internal → dist/internal}/watch-local-node-modules.d.ts.map +0 -0
- /package/{internal → dist/internal}/watch-local-node-modules.options.d.ts +0 -0
- /package/{internal → dist/internal}/watch-local-node-modules.options.d.ts.map +0 -0
- /package/{local-node-modules.d.ts → dist/local-node-modules.d.ts} +0 -0
- /package/{local-node-modules.d.ts.map → dist/local-node-modules.d.ts.map} +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_watch_local_node_modules = require("./watch-local-node-modules-0DugEhkt.cjs");
|
|
3
|
+
exports.normalizeTurbowatchLocalNodeModulesOptions = require_watch_local_node_modules.normalizeTurbowatchLocalNodeModulesOptions;
|
|
4
|
+
exports.turbowatchLocalNodeModules = require_watch_local_node_modules.turbowatchLocalNodeModules;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
let _alexaegis_common = require("@alexaegis/common");
|
|
2
|
+
let _alexaegis_workspace_tools = require("@alexaegis/workspace-tools");
|
|
3
|
+
let node_child_process = require("node:child_process");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
let _alexaegis_fs = require("@alexaegis/fs");
|
|
6
|
+
//#region src/internal/watch-local-node-modules.options.ts
|
|
7
|
+
var normalizeTurbowatchLocalNodeModulesOptions = (options) => {
|
|
8
|
+
return {
|
|
9
|
+
...(0, _alexaegis_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
|
+
//#endregion
|
|
20
|
+
//#region src/internal/watch-local-node-modules.ts
|
|
21
|
+
/**
|
|
22
|
+
* Defines a turbowatch config that runs a build command everytime something
|
|
23
|
+
* changes in `node_modules`, where all the local dependencies expected to be
|
|
24
|
+
* linked.
|
|
25
|
+
*/
|
|
26
|
+
var turbowatchLocalNodeModules = async (rawOptions) => {
|
|
27
|
+
const options = normalizeTurbowatchLocalNodeModulesOptions(rawOptions);
|
|
28
|
+
console.log("turbowatch started in", options.cwd);
|
|
29
|
+
const currentPackagePath = (0, _alexaegis_workspace_tools.getCurrentPackageRoot)(options.cwd);
|
|
30
|
+
if (!currentPackagePath) throw new Error("Not in a package!");
|
|
31
|
+
const currentPackagesNodeModulesPath = (0, node_path.join)(currentPackagePath, _alexaegis_workspace_tools.NODE_MODULES_DIRECTORY_NAME);
|
|
32
|
+
const workspacePackages = await (0, _alexaegis_workspace_tools.collectWorkspacePackages)({
|
|
33
|
+
...options,
|
|
34
|
+
skipWorkspaceRoot: true
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Pakk modifies it on build, as it's not part of the source code, and is
|
|
38
|
+
* actually a result of build, it should be skipped.
|
|
39
|
+
*/
|
|
40
|
+
const doNotMatchPackageJson = ["not", [
|
|
41
|
+
"match",
|
|
42
|
+
"package.json",
|
|
43
|
+
"basename"
|
|
44
|
+
]];
|
|
45
|
+
/**
|
|
46
|
+
* Only trigger changes within local packages in a workspace
|
|
47
|
+
*/
|
|
48
|
+
const matchInLocalPackageDirectories = ["anyof", ...workspacePackages.map((workspacePackage) => workspacePackage.packageJson.name).filter(_alexaegis_common.isNotNullish).map((packageName) => ["dirname", packageName])];
|
|
49
|
+
const commonIgnoredDirs = [
|
|
50
|
+
["dirname", "dist"],
|
|
51
|
+
["dirname", "out"],
|
|
52
|
+
["dirname", "build"],
|
|
53
|
+
["dirname", "coverage"],
|
|
54
|
+
["dirname", ".turbo"],
|
|
55
|
+
["dirname", ".vercel"],
|
|
56
|
+
["dirname", ".cache"],
|
|
57
|
+
["dirname", ".svelte-kit"],
|
|
58
|
+
["dirname", ".next"],
|
|
59
|
+
["match", "vite(st)?.config.*"]
|
|
60
|
+
];
|
|
61
|
+
if (!options.deep) commonIgnoredDirs.push(["dirname", "node_modules"]);
|
|
62
|
+
const watchExpression = [
|
|
63
|
+
"allof",
|
|
64
|
+
matchInLocalPackageDirectories,
|
|
65
|
+
["not", ["anyof", ...commonIgnoredDirs]],
|
|
66
|
+
doNotMatchPackageJson
|
|
67
|
+
];
|
|
68
|
+
if (options.useGitIgnore) {
|
|
69
|
+
let ignoreEntries = await (0, _alexaegis_workspace_tools.collectIgnoreEntries)(options);
|
|
70
|
+
if (options.deep) ignoreEntries = ignoreEntries.filter((entry) => !entry.includes(_alexaegis_workspace_tools.NODE_MODULES_DIRECTORY_NAME));
|
|
71
|
+
const doNotMatchIgnored = ["not", ["anyof", ...ignoreEntries.map((ignoreEntry) => ["match", ignoreEntry])]];
|
|
72
|
+
watchExpression.push(doNotMatchIgnored);
|
|
73
|
+
}
|
|
74
|
+
let changeCount = 0;
|
|
75
|
+
const startCommand = () => {
|
|
76
|
+
return (0, node_child_process.spawn)(options.packageManagerCommand, ["run", options.devScript], { stdio: "inherit" });
|
|
77
|
+
};
|
|
78
|
+
let spawnedOnFirstBuild;
|
|
79
|
+
const abortController = new AbortController();
|
|
80
|
+
return {
|
|
81
|
+
project: currentPackagesNodeModulesPath,
|
|
82
|
+
debounce: { wait: 50 },
|
|
83
|
+
abortController,
|
|
84
|
+
triggers: [{
|
|
85
|
+
expression: watchExpression,
|
|
86
|
+
name: "build",
|
|
87
|
+
retry: { retries: 0 },
|
|
88
|
+
onChange: async ({ spawn, files }) => {
|
|
89
|
+
if (options.logChangedFiles) console.log("changed files:", files);
|
|
90
|
+
await spawn`${options.packageManagerCommand} run ${options.buildDependenciesScript}`;
|
|
91
|
+
if (changeCount < 1) {
|
|
92
|
+
spawnedOnFirstBuild = options.onFirstBuild ? options.onFirstBuild() : startCommand();
|
|
93
|
+
if (spawnedOnFirstBuild) spawnedOnFirstBuild.on("exit", () => {
|
|
94
|
+
abortController.abort("onFirstBuild command exited!");
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
changeCount++;
|
|
98
|
+
},
|
|
99
|
+
onTeardown: async () => {
|
|
100
|
+
if (spawnedOnFirstBuild) spawnedOnFirstBuild.kill();
|
|
101
|
+
await (0, _alexaegis_common.noopAsync)();
|
|
102
|
+
}
|
|
103
|
+
}]
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
//#endregion
|
|
107
|
+
Object.defineProperty(exports, "normalizeTurbowatchLocalNodeModulesOptions", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
get: function() {
|
|
110
|
+
return normalizeTurbowatchLocalNodeModulesOptions;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(exports, "turbowatchLocalNodeModules", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
get: function() {
|
|
116
|
+
return turbowatchLocalNodeModules;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
//# sourceMappingURL=watch-local-node-modules-0DugEhkt.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch-local-node-modules-0DugEhkt.cjs","names":[],"sources":["../src/internal/watch-local-node-modules.options.ts","../src/internal/watch-local-node-modules.ts"],"sourcesContent":["import type { Defined } from '@alexaegis/common';\nimport { normalizeCwdOption, type CwdOption } from '@alexaegis/fs';\nimport type { ChildProcess } from 'node:child_process';\n\nexport interface TurbowatchLocalNodeModulesOptions extends CwdOption {\n\t/**\n\t * If true, it will make sure ignore statements do not contain node_modules\n\t * so the watcher can watch the entire dependency tree.\n\t *\n\t * If false deeper node_modules will be ignored.\n\t *\n\t * @default true\n\t */\n\tdeep?: boolean | undefined;\n\n\t/**\n\t * If the default ignored files like\n\t * - 'dist'\n\t * - '.turbo'\n\t * - '.vercel'\n\t * - '.cache'\n\t * - 'coverage'\n\t * - 'build'\n\t *\n\t * Does not suffice, you can enable this and then it will read all the\n\t * .gitignore files up your project root and include those too in the do\n\t * not watch list. This could potentially ignore more than you actually\n\t * want though!\n\t *\n\t * @default false\n\t */\n\tuseGitIgnore?: boolean | undefined;\n\n\t/**\n\t * Log out changed files on every change. Useful for debugging if you\n\t * notice builds are getting triggered over and over again.\n\t *\n\t * @default false\n\t */\n\tlogChangedFiles?: boolean | undefined;\n\n\t/**\n\t * The command used to build the dependencies of this package.\n\t *\n\t * @default 'build:dependencies'\n\t */\n\tbuildDependenciesScript?: string | undefined;\n\n\t/**\n\t * Which package manager to invoke when running buildDependenciesScript\n\t *\n\t * @default 'pnpm'\n\t */\n\tpackageManagerCommand?: string | undefined;\n\n\t/**\n\t * Called the first time buildDependenciesScript finished\n\t * You can use this to start your app if the way devScript doesn't suffice.\n\t * If this is defined, devScript will not be used!\n\t *\n\t * It can be async but it won't be awaited!\n\t */\n\tonFirstBuild?: (() => ChildProcess | undefined) | undefined;\n\n\t/**\n\t * What package.json script should be started once buildDependenciesScript\n\t * is first finished. By default it's `dev_` with an underscore at the\n\t * end as this turbowatch call should be named `dev`\n\t *\n\t * @default 'dev_'\n\t */\n\tdevScript?: string | undefined;\n}\n\n// type gr= Defined<Omit<TurbowatchLocalNodeModulesOptions, 'onFirstBuild'>>\n// type asd = Pick<TurbowatchLocalNodeModulesOptions, 'onFirstBuild'>\n// type hhrt = gr | asd\n// const a :hhrt ={}\n\nexport type NormalizedTurbowatchLocalNodeModulesOptions = Defined<\n\tOmit<TurbowatchLocalNodeModulesOptions, 'onFirstBuild'>\n> &\n\tPick<TurbowatchLocalNodeModulesOptions, 'onFirstBuild'>;\n\nexport const normalizeTurbowatchLocalNodeModulesOptions = (\n\toptions?: TurbowatchLocalNodeModulesOptions,\n): NormalizedTurbowatchLocalNodeModulesOptions => {\n\treturn {\n\t\t...normalizeCwdOption(options),\n\t\tdeep: options?.deep ?? true,\n\t\tuseGitIgnore: options?.useGitIgnore ?? false,\n\t\tlogChangedFiles: options?.logChangedFiles ?? false,\n\t\tbuildDependenciesScript: options?.buildDependenciesScript ?? 'build:dependencies',\n\t\tpackageManagerCommand: options?.packageManagerCommand ?? 'pnpm',\n\t\tonFirstBuild: options?.onFirstBuild,\n\t\tdevScript: options?.devScript ?? 'dev_',\n\t};\n};\n","import { isNotNullish, noopAsync } from '@alexaegis/common';\nimport {\n\tNODE_MODULES_DIRECTORY_NAME,\n\tcollectIgnoreEntries,\n\tcollectWorkspacePackages,\n\tgetCurrentPackageRoot,\n} from '@alexaegis/workspace-tools';\nimport { ChildProcess, spawn } from 'node:child_process';\nimport { join } from 'node:path';\nimport type { Expression } from 'turbowatch';\nimport {\n\tnormalizeTurbowatchLocalNodeModulesOptions,\n\ttype TurbowatchLocalNodeModulesOptions,\n} from './watch-local-node-modules.options.js';\n\n/**\n * Defines a turbowatch config that runs a build command everytime something\n * changes in `node_modules`, where all the local dependencies expected to be\n * linked.\n */\nexport const turbowatchLocalNodeModules = async (\n\trawOptions?: TurbowatchLocalNodeModulesOptions,\n): Promise<Parameters<typeof import('turbowatch').watch>[0]> => {\n\tconst options = normalizeTurbowatchLocalNodeModulesOptions(rawOptions);\n\tconsole.log('turbowatch started in', options.cwd);\n\tconst currentPackagePath = getCurrentPackageRoot(options.cwd);\n\tif (!currentPackagePath) {\n\t\tthrow new Error('Not in a package!');\n\t}\n\n\tconst currentPackagesNodeModulesPath = join(currentPackagePath, NODE_MODULES_DIRECTORY_NAME);\n\n\tconst workspacePackages = await collectWorkspacePackages({\n\t\t...options,\n\t\tskipWorkspaceRoot: true,\n\t});\n\n\t/**\n\t * Pakk modifies it on build, as it's not part of the source code, and is\n\t * actually a result of build, it should be skipped.\n\t */\n\tconst doNotMatchPackageJson: Expression = ['not', ['match', 'package.json', 'basename']];\n\n\t/**\n\t * Only trigger changes within local packages in a workspace\n\t */\n\tconst matchInLocalPackageDirectories: Expression = [\n\t\t'anyof',\n\t\t...workspacePackages\n\t\t\t.map((workspacePackage) => workspacePackage.packageJson.name)\n\t\t\t.filter(isNotNullish)\n\t\t\t.map<Expression>((packageName) => ['dirname', packageName]),\n\t];\n\n\tconst commonIgnoredDirs: Expression[] = [\n\t\t['dirname', 'dist'],\n\t\t['dirname', 'out'],\n\t\t['dirname', 'build'],\n\t\t['dirname', 'coverage'],\n\t\t['dirname', '.turbo'],\n\t\t['dirname', '.vercel'],\n\t\t['dirname', '.cache'],\n\t\t['dirname', '.svelte-kit'],\n\t\t['dirname', '.next'],\n\t\t['match', 'vite(st)?.config.*'],\n\t];\n\n\tif (!options.deep) {\n\t\tcommonIgnoredDirs.push(['dirname', 'node_modules']); // This prevents deep dependencies from being watched\n\t}\n\n\tconst doNotMatchCommonOutputs: Expression = ['not', ['anyof', ...commonIgnoredDirs]];\n\n\tconst watchExpression: Expression = [\n\t\t'allof',\n\t\tmatchInLocalPackageDirectories,\n\t\tdoNotMatchCommonOutputs,\n\t\tdoNotMatchPackageJson,\n\t];\n\n\tif (options.useGitIgnore) {\n\t\tlet ignoreEntries = await collectIgnoreEntries(options);\n\n\t\tif (options.deep) {\n\t\t\tignoreEntries = ignoreEntries.filter(\n\t\t\t\t(entry) => !entry.includes(NODE_MODULES_DIRECTORY_NAME),\n\t\t\t);\n\t\t}\n\n\t\tconst ignoreMatchEntries = ignoreEntries.map<Expression>((ignoreEntry) => [\n\t\t\t'match',\n\t\t\tignoreEntry,\n\t\t]);\n\n\t\tconst doNotMatchIgnored: Expression = ['not', ['anyof', ...ignoreMatchEntries]];\n\t\twatchExpression.push(doNotMatchIgnored);\n\t}\n\n\tlet changeCount = 0;\n\n\tconst startCommand = (): ChildProcess => {\n\t\treturn spawn(options.packageManagerCommand, ['run', options.devScript], {\n\t\t\tstdio: 'inherit',\n\t\t});\n\t};\n\n\tlet spawnedOnFirstBuild: ChildProcess | undefined;\n\tconst abortController: AbortController = new AbortController();\n\n\treturn {\n\t\tproject: currentPackagesNodeModulesPath,\n\t\tdebounce: { wait: 50 },\n\t\tabortController,\n\t\ttriggers: [\n\t\t\t{\n\t\t\t\texpression: watchExpression,\n\t\t\t\tname: 'build',\n\t\t\t\tretry: { retries: 0 },\n\t\t\t\tonChange: async ({ spawn, files }) => {\n\t\t\t\t\tif (options.logChangedFiles) {\n\t\t\t\t\t\tconsole.log('changed files:', files);\n\t\t\t\t\t}\n\n\t\t\t\t\tawait spawn`${options.packageManagerCommand} run ${options.buildDependenciesScript}`;\n\t\t\t\t\tif (changeCount < 1) {\n\t\t\t\t\t\tspawnedOnFirstBuild = options.onFirstBuild\n\t\t\t\t\t\t\t? options.onFirstBuild()\n\t\t\t\t\t\t\t: startCommand();\n\n\t\t\t\t\t\tif (spawnedOnFirstBuild) {\n\t\t\t\t\t\t\tspawnedOnFirstBuild.on('exit', () => {\n\t\t\t\t\t\t\t\tabortController.abort('onFirstBuild command exited!');\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tchangeCount++;\n\t\t\t\t},\n\t\t\t\tonTeardown: async (): Promise<void> => {\n\t\t\t\t\tif (spawnedOnFirstBuild) {\n\t\t\t\t\t\tspawnedOnFirstBuild.kill();\n\t\t\t\t\t}\n\t\t\t\t\tawait noopAsync();\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t};\n};\n"],"mappings":";;;;;;AAoFA,IAAa,8CACZ,YACiD;AACjD,QAAO;EACN,IAAA,GAAA,cAAA,oBAAsB,QAAQ;EAC9B,MAAM,SAAS,QAAQ;EACvB,cAAc,SAAS,gBAAgB;EACvC,iBAAiB,SAAS,mBAAmB;EAC7C,yBAAyB,SAAS,2BAA2B;EAC7D,uBAAuB,SAAS,yBAAyB;EACzD,cAAc,SAAS;EACvB,WAAW,SAAS,aAAa;EACjC;;;;;;;;;AC5EF,IAAa,6BAA6B,OACzC,eAC+D;CAC/D,MAAM,UAAU,2CAA2C,WAAW;AACtE,SAAQ,IAAI,yBAAyB,QAAQ,IAAI;CACjD,MAAM,sBAAA,GAAA,2BAAA,uBAA2C,QAAQ,IAAI;AAC7D,KAAI,CAAC,mBACJ,OAAM,IAAI,MAAM,oBAAoB;CAGrC,MAAM,kCAAA,GAAA,UAAA,MAAsC,oBAAoB,2BAAA,4BAA4B;CAE5F,MAAM,oBAAoB,OAAA,GAAA,2BAAA,0BAA+B;EACxD,GAAG;EACH,mBAAmB;EACnB,CAAC;;;;;CAMF,MAAM,wBAAoC,CAAC,OAAO;EAAC;EAAS;EAAgB;EAAW,CAAC;;;;CAKxF,MAAM,iCAA6C,CAClD,SACA,GAAG,kBACD,KAAK,qBAAqB,iBAAiB,YAAY,KAAK,CAC5D,OAAO,kBAAA,aAAa,CACpB,KAAiB,gBAAgB,CAAC,WAAW,YAAY,CAAC,CAC5D;CAED,MAAM,oBAAkC;EACvC,CAAC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,QAAQ,cAAc,GACtB,cAAc;AAEjB,SAAI,oBACH,qBAAoB,GAAG,cAAc;AACpC,sBAAgB,MAAM,+BAA+B;OACpD;;AAGJ;;GAED,YAAY,YAA2B;AACtC,QAAI,oBACH,qBAAoB,MAAM;AAE3B,WAAA,GAAA,kBAAA,YAAiB;;GAElB,CACD;EACD"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { isNotNullish, noopAsync } from "@alexaegis/common";
|
|
2
|
+
import { NODE_MODULES_DIRECTORY_NAME, collectIgnoreEntries, collectWorkspacePackages, getCurrentPackageRoot } from "@alexaegis/workspace-tools";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { normalizeCwdOption } from "@alexaegis/fs";
|
|
6
|
+
//#region src/internal/watch-local-node-modules.options.ts
|
|
7
|
+
var normalizeTurbowatchLocalNodeModulesOptions = (options) => {
|
|
8
|
+
return {
|
|
9
|
+
...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
|
+
//#endregion
|
|
20
|
+
//#region src/internal/watch-local-node-modules.ts
|
|
21
|
+
/**
|
|
22
|
+
* Defines a turbowatch config that runs a build command everytime something
|
|
23
|
+
* changes in `node_modules`, where all the local dependencies expected to be
|
|
24
|
+
* linked.
|
|
25
|
+
*/
|
|
26
|
+
var turbowatchLocalNodeModules = async (rawOptions) => {
|
|
27
|
+
const options = normalizeTurbowatchLocalNodeModulesOptions(rawOptions);
|
|
28
|
+
console.log("turbowatch started in", options.cwd);
|
|
29
|
+
const currentPackagePath = getCurrentPackageRoot(options.cwd);
|
|
30
|
+
if (!currentPackagePath) throw new Error("Not in a package!");
|
|
31
|
+
const currentPackagesNodeModulesPath = join(currentPackagePath, NODE_MODULES_DIRECTORY_NAME);
|
|
32
|
+
const workspacePackages = await collectWorkspacePackages({
|
|
33
|
+
...options,
|
|
34
|
+
skipWorkspaceRoot: true
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Pakk modifies it on build, as it's not part of the source code, and is
|
|
38
|
+
* actually a result of build, it should be skipped.
|
|
39
|
+
*/
|
|
40
|
+
const doNotMatchPackageJson = ["not", [
|
|
41
|
+
"match",
|
|
42
|
+
"package.json",
|
|
43
|
+
"basename"
|
|
44
|
+
]];
|
|
45
|
+
/**
|
|
46
|
+
* Only trigger changes within local packages in a workspace
|
|
47
|
+
*/
|
|
48
|
+
const matchInLocalPackageDirectories = ["anyof", ...workspacePackages.map((workspacePackage) => workspacePackage.packageJson.name).filter(isNotNullish).map((packageName) => ["dirname", packageName])];
|
|
49
|
+
const commonIgnoredDirs = [
|
|
50
|
+
["dirname", "dist"],
|
|
51
|
+
["dirname", "out"],
|
|
52
|
+
["dirname", "build"],
|
|
53
|
+
["dirname", "coverage"],
|
|
54
|
+
["dirname", ".turbo"],
|
|
55
|
+
["dirname", ".vercel"],
|
|
56
|
+
["dirname", ".cache"],
|
|
57
|
+
["dirname", ".svelte-kit"],
|
|
58
|
+
["dirname", ".next"],
|
|
59
|
+
["match", "vite(st)?.config.*"]
|
|
60
|
+
];
|
|
61
|
+
if (!options.deep) commonIgnoredDirs.push(["dirname", "node_modules"]);
|
|
62
|
+
const watchExpression = [
|
|
63
|
+
"allof",
|
|
64
|
+
matchInLocalPackageDirectories,
|
|
65
|
+
["not", ["anyof", ...commonIgnoredDirs]],
|
|
66
|
+
doNotMatchPackageJson
|
|
67
|
+
];
|
|
68
|
+
if (options.useGitIgnore) {
|
|
69
|
+
let ignoreEntries = await collectIgnoreEntries(options);
|
|
70
|
+
if (options.deep) ignoreEntries = ignoreEntries.filter((entry) => !entry.includes(NODE_MODULES_DIRECTORY_NAME));
|
|
71
|
+
const doNotMatchIgnored = ["not", ["anyof", ...ignoreEntries.map((ignoreEntry) => ["match", ignoreEntry])]];
|
|
72
|
+
watchExpression.push(doNotMatchIgnored);
|
|
73
|
+
}
|
|
74
|
+
let changeCount = 0;
|
|
75
|
+
const startCommand = () => {
|
|
76
|
+
return spawn(options.packageManagerCommand, ["run", options.devScript], { stdio: "inherit" });
|
|
77
|
+
};
|
|
78
|
+
let spawnedOnFirstBuild;
|
|
79
|
+
const abortController = new AbortController();
|
|
80
|
+
return {
|
|
81
|
+
project: currentPackagesNodeModulesPath,
|
|
82
|
+
debounce: { wait: 50 },
|
|
83
|
+
abortController,
|
|
84
|
+
triggers: [{
|
|
85
|
+
expression: watchExpression,
|
|
86
|
+
name: "build",
|
|
87
|
+
retry: { retries: 0 },
|
|
88
|
+
onChange: async ({ spawn, files }) => {
|
|
89
|
+
if (options.logChangedFiles) console.log("changed files:", files);
|
|
90
|
+
await spawn`${options.packageManagerCommand} run ${options.buildDependenciesScript}`;
|
|
91
|
+
if (changeCount < 1) {
|
|
92
|
+
spawnedOnFirstBuild = options.onFirstBuild ? options.onFirstBuild() : startCommand();
|
|
93
|
+
if (spawnedOnFirstBuild) spawnedOnFirstBuild.on("exit", () => {
|
|
94
|
+
abortController.abort("onFirstBuild command exited!");
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
changeCount++;
|
|
98
|
+
},
|
|
99
|
+
onTeardown: async () => {
|
|
100
|
+
if (spawnedOnFirstBuild) spawnedOnFirstBuild.kill();
|
|
101
|
+
await noopAsync();
|
|
102
|
+
}
|
|
103
|
+
}]
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
//#endregion
|
|
107
|
+
export { normalizeTurbowatchLocalNodeModulesOptions as n, turbowatchLocalNodeModules as t };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=watch-local-node-modules-gDrf144G.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch-local-node-modules-gDrf144G.js","names":[],"sources":["../src/internal/watch-local-node-modules.options.ts","../src/internal/watch-local-node-modules.ts"],"sourcesContent":["import type { Defined } from '@alexaegis/common';\nimport { normalizeCwdOption, type CwdOption } from '@alexaegis/fs';\nimport type { ChildProcess } from 'node:child_process';\n\nexport interface TurbowatchLocalNodeModulesOptions extends CwdOption {\n\t/**\n\t * If true, it will make sure ignore statements do not contain node_modules\n\t * so the watcher can watch the entire dependency tree.\n\t *\n\t * If false deeper node_modules will be ignored.\n\t *\n\t * @default true\n\t */\n\tdeep?: boolean | undefined;\n\n\t/**\n\t * If the default ignored files like\n\t * - 'dist'\n\t * - '.turbo'\n\t * - '.vercel'\n\t * - '.cache'\n\t * - 'coverage'\n\t * - 'build'\n\t *\n\t * Does not suffice, you can enable this and then it will read all the\n\t * .gitignore files up your project root and include those too in the do\n\t * not watch list. This could potentially ignore more than you actually\n\t * want though!\n\t *\n\t * @default false\n\t */\n\tuseGitIgnore?: boolean | undefined;\n\n\t/**\n\t * Log out changed files on every change. Useful for debugging if you\n\t * notice builds are getting triggered over and over again.\n\t *\n\t * @default false\n\t */\n\tlogChangedFiles?: boolean | undefined;\n\n\t/**\n\t * The command used to build the dependencies of this package.\n\t *\n\t * @default 'build:dependencies'\n\t */\n\tbuildDependenciesScript?: string | undefined;\n\n\t/**\n\t * Which package manager to invoke when running buildDependenciesScript\n\t *\n\t * @default 'pnpm'\n\t */\n\tpackageManagerCommand?: string | undefined;\n\n\t/**\n\t * Called the first time buildDependenciesScript finished\n\t * You can use this to start your app if the way devScript doesn't suffice.\n\t * If this is defined, devScript will not be used!\n\t *\n\t * It can be async but it won't be awaited!\n\t */\n\tonFirstBuild?: (() => ChildProcess | undefined) | undefined;\n\n\t/**\n\t * What package.json script should be started once buildDependenciesScript\n\t * is first finished. By default it's `dev_` with an underscore at the\n\t * end as this turbowatch call should be named `dev`\n\t *\n\t * @default 'dev_'\n\t */\n\tdevScript?: string | undefined;\n}\n\n// type gr= Defined<Omit<TurbowatchLocalNodeModulesOptions, 'onFirstBuild'>>\n// type asd = Pick<TurbowatchLocalNodeModulesOptions, 'onFirstBuild'>\n// type hhrt = gr | asd\n// const a :hhrt ={}\n\nexport type NormalizedTurbowatchLocalNodeModulesOptions = Defined<\n\tOmit<TurbowatchLocalNodeModulesOptions, 'onFirstBuild'>\n> &\n\tPick<TurbowatchLocalNodeModulesOptions, 'onFirstBuild'>;\n\nexport const normalizeTurbowatchLocalNodeModulesOptions = (\n\toptions?: TurbowatchLocalNodeModulesOptions,\n): NormalizedTurbowatchLocalNodeModulesOptions => {\n\treturn {\n\t\t...normalizeCwdOption(options),\n\t\tdeep: options?.deep ?? true,\n\t\tuseGitIgnore: options?.useGitIgnore ?? false,\n\t\tlogChangedFiles: options?.logChangedFiles ?? false,\n\t\tbuildDependenciesScript: options?.buildDependenciesScript ?? 'build:dependencies',\n\t\tpackageManagerCommand: options?.packageManagerCommand ?? 'pnpm',\n\t\tonFirstBuild: options?.onFirstBuild,\n\t\tdevScript: options?.devScript ?? 'dev_',\n\t};\n};\n","import { isNotNullish, noopAsync } from '@alexaegis/common';\nimport {\n\tNODE_MODULES_DIRECTORY_NAME,\n\tcollectIgnoreEntries,\n\tcollectWorkspacePackages,\n\tgetCurrentPackageRoot,\n} from '@alexaegis/workspace-tools';\nimport { ChildProcess, spawn } from 'node:child_process';\nimport { join } from 'node:path';\nimport type { Expression } from 'turbowatch';\nimport {\n\tnormalizeTurbowatchLocalNodeModulesOptions,\n\ttype TurbowatchLocalNodeModulesOptions,\n} from './watch-local-node-modules.options.js';\n\n/**\n * Defines a turbowatch config that runs a build command everytime something\n * changes in `node_modules`, where all the local dependencies expected to be\n * linked.\n */\nexport const turbowatchLocalNodeModules = async (\n\trawOptions?: TurbowatchLocalNodeModulesOptions,\n): Promise<Parameters<typeof import('turbowatch').watch>[0]> => {\n\tconst options = normalizeTurbowatchLocalNodeModulesOptions(rawOptions);\n\tconsole.log('turbowatch started in', options.cwd);\n\tconst currentPackagePath = getCurrentPackageRoot(options.cwd);\n\tif (!currentPackagePath) {\n\t\tthrow new Error('Not in a package!');\n\t}\n\n\tconst currentPackagesNodeModulesPath = join(currentPackagePath, NODE_MODULES_DIRECTORY_NAME);\n\n\tconst workspacePackages = await collectWorkspacePackages({\n\t\t...options,\n\t\tskipWorkspaceRoot: true,\n\t});\n\n\t/**\n\t * Pakk modifies it on build, as it's not part of the source code, and is\n\t * actually a result of build, it should be skipped.\n\t */\n\tconst doNotMatchPackageJson: Expression = ['not', ['match', 'package.json', 'basename']];\n\n\t/**\n\t * Only trigger changes within local packages in a workspace\n\t */\n\tconst matchInLocalPackageDirectories: Expression = [\n\t\t'anyof',\n\t\t...workspacePackages\n\t\t\t.map((workspacePackage) => workspacePackage.packageJson.name)\n\t\t\t.filter(isNotNullish)\n\t\t\t.map<Expression>((packageName) => ['dirname', packageName]),\n\t];\n\n\tconst commonIgnoredDirs: Expression[] = [\n\t\t['dirname', 'dist'],\n\t\t['dirname', 'out'],\n\t\t['dirname', 'build'],\n\t\t['dirname', 'coverage'],\n\t\t['dirname', '.turbo'],\n\t\t['dirname', '.vercel'],\n\t\t['dirname', '.cache'],\n\t\t['dirname', '.svelte-kit'],\n\t\t['dirname', '.next'],\n\t\t['match', 'vite(st)?.config.*'],\n\t];\n\n\tif (!options.deep) {\n\t\tcommonIgnoredDirs.push(['dirname', 'node_modules']); // This prevents deep dependencies from being watched\n\t}\n\n\tconst doNotMatchCommonOutputs: Expression = ['not', ['anyof', ...commonIgnoredDirs]];\n\n\tconst watchExpression: Expression = [\n\t\t'allof',\n\t\tmatchInLocalPackageDirectories,\n\t\tdoNotMatchCommonOutputs,\n\t\tdoNotMatchPackageJson,\n\t];\n\n\tif (options.useGitIgnore) {\n\t\tlet ignoreEntries = await collectIgnoreEntries(options);\n\n\t\tif (options.deep) {\n\t\t\tignoreEntries = ignoreEntries.filter(\n\t\t\t\t(entry) => !entry.includes(NODE_MODULES_DIRECTORY_NAME),\n\t\t\t);\n\t\t}\n\n\t\tconst ignoreMatchEntries = ignoreEntries.map<Expression>((ignoreEntry) => [\n\t\t\t'match',\n\t\t\tignoreEntry,\n\t\t]);\n\n\t\tconst doNotMatchIgnored: Expression = ['not', ['anyof', ...ignoreMatchEntries]];\n\t\twatchExpression.push(doNotMatchIgnored);\n\t}\n\n\tlet changeCount = 0;\n\n\tconst startCommand = (): ChildProcess => {\n\t\treturn spawn(options.packageManagerCommand, ['run', options.devScript], {\n\t\t\tstdio: 'inherit',\n\t\t});\n\t};\n\n\tlet spawnedOnFirstBuild: ChildProcess | undefined;\n\tconst abortController: AbortController = new AbortController();\n\n\treturn {\n\t\tproject: currentPackagesNodeModulesPath,\n\t\tdebounce: { wait: 50 },\n\t\tabortController,\n\t\ttriggers: [\n\t\t\t{\n\t\t\t\texpression: watchExpression,\n\t\t\t\tname: 'build',\n\t\t\t\tretry: { retries: 0 },\n\t\t\t\tonChange: async ({ spawn, files }) => {\n\t\t\t\t\tif (options.logChangedFiles) {\n\t\t\t\t\t\tconsole.log('changed files:', files);\n\t\t\t\t\t}\n\n\t\t\t\t\tawait spawn`${options.packageManagerCommand} run ${options.buildDependenciesScript}`;\n\t\t\t\t\tif (changeCount < 1) {\n\t\t\t\t\t\tspawnedOnFirstBuild = options.onFirstBuild\n\t\t\t\t\t\t\t? options.onFirstBuild()\n\t\t\t\t\t\t\t: startCommand();\n\n\t\t\t\t\t\tif (spawnedOnFirstBuild) {\n\t\t\t\t\t\t\tspawnedOnFirstBuild.on('exit', () => {\n\t\t\t\t\t\t\t\tabortController.abort('onFirstBuild command exited!');\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tchangeCount++;\n\t\t\t\t},\n\t\t\t\tonTeardown: async (): Promise<void> => {\n\t\t\t\t\tif (spawnedOnFirstBuild) {\n\t\t\t\t\t\tsp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turbowatch configuration to watch local dependencies through node_modules",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.15.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
7
|
"archetype": {
|
|
@@ -13,64 +13,50 @@
|
|
|
13
13
|
"managed-by-autotool",
|
|
14
14
|
"turbowatch"
|
|
15
15
|
],
|
|
16
|
-
"author": {
|
|
17
|
-
"email": "alexaegis@pm.me",
|
|
18
|
-
"name": "Alex Aegis",
|
|
19
|
-
"url": "https://github.com/AlexAegis"
|
|
20
|
-
},
|
|
21
|
-
"homepage": "https://github.com/AlexAegis/js-tooling",
|
|
22
16
|
"repository": {
|
|
23
17
|
"url": "git+https://github.com/AlexAegis/js-tooling",
|
|
24
|
-
"type": "git"
|
|
25
|
-
"directory": "packages/turbowatch"
|
|
26
|
-
},
|
|
27
|
-
"bugs": {
|
|
28
|
-
"email": "alexaegis@pm.me",
|
|
29
|
-
"url": "https://github.com/AlexAegis/js-tooling/issues"
|
|
18
|
+
"type": "git"
|
|
30
19
|
},
|
|
31
20
|
"type": "module",
|
|
32
|
-
"config": {
|
|
33
|
-
"engine-strict": true
|
|
34
|
-
},
|
|
35
21
|
"publishConfig": {
|
|
36
22
|
"access": "public"
|
|
37
23
|
},
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
42
27
|
"exports": {
|
|
43
28
|
".": {
|
|
44
|
-
"types": "./index.d.ts",
|
|
45
|
-
"import": "./index.js",
|
|
46
|
-
"require": "./index.cjs",
|
|
47
|
-
"default": "./index.js"
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js",
|
|
31
|
+
"require": "./dist/index.cjs",
|
|
32
|
+
"default": "./dist/index.js"
|
|
48
33
|
},
|
|
49
34
|
"./local-node-modules": {
|
|
50
|
-
"types": "./local-node-modules.d.ts",
|
|
51
|
-
"import": "./local-node-modules.js",
|
|
52
|
-
"require": "./local-node-modules.cjs",
|
|
53
|
-
"default": "./local-node-modules.js"
|
|
35
|
+
"types": "./dist/local-node-modules.d.ts",
|
|
36
|
+
"import": "./dist/local-node-modules.js",
|
|
37
|
+
"require": "./dist/local-node-modules.cjs",
|
|
38
|
+
"default": "./dist/local-node-modules.js"
|
|
54
39
|
},
|
|
55
40
|
"./package.json": "./package.json",
|
|
56
41
|
"./readme": "./readme.md"
|
|
57
42
|
},
|
|
58
43
|
"dependencies": {
|
|
59
|
-
"@alexaegis/common": "^0.
|
|
60
|
-
"@alexaegis/fs": "^0.
|
|
61
|
-
"@alexaegis/workspace-tools": "^0.
|
|
44
|
+
"@alexaegis/common": "^0.15.0",
|
|
45
|
+
"@alexaegis/fs": "^0.15.0",
|
|
46
|
+
"@alexaegis/workspace-tools": "^0.15.0"
|
|
62
47
|
},
|
|
63
48
|
"devDependencies": {
|
|
64
|
-
"@
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
49
|
+
"@types/node": "^25.5.0",
|
|
50
|
+
"publint": "^0.3.18",
|
|
51
|
+
"turbowatch": "^2.30.0",
|
|
52
|
+
"typescript": "^5.9.3",
|
|
53
|
+
"vite": "^8.0.1",
|
|
54
|
+
"vite-plugin-dts": "^4.5.4",
|
|
55
|
+
"vitest": "^4.1.0",
|
|
56
|
+
"@alexaegis/eslint-config-vitest": "^0.15.0",
|
|
57
|
+
"@alexaegis/ts": "^0.15.0",
|
|
58
|
+
"@alexaegis/vite": "^0.15.0",
|
|
59
|
+
"@alexaegis/vitest": "^0.15.0"
|
|
74
60
|
},
|
|
75
61
|
"scripts": {
|
|
76
62
|
"lint:depcheck": "turbo run lint:depcheck_ --concurrency 16 --filter @alexaegis/turbowatch",
|
|
@@ -84,7 +70,7 @@
|
|
|
84
70
|
"lint:tsc": "turbo run lint:tsc_ --concurrency 16 --filter @alexaegis/turbowatch",
|
|
85
71
|
"lint:tsc_": "tsc --noEmit",
|
|
86
72
|
"publint": "BUILD_REASON='publish' turbo run publint_ --concurrency 16 --filter @alexaegis/turbowatch",
|
|
87
|
-
"publint_": "publint
|
|
73
|
+
"publint_": "publint",
|
|
88
74
|
"test": "turbo run test_ --concurrency 16 --filter @alexaegis/turbowatch",
|
|
89
75
|
"test_": "vitest --passWithNoTests --coverage --run",
|
|
90
76
|
"test:watch": "vitest --passWithNoTests --coverage",
|
package/index.cjs
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const watchLocalNodeModules = require("./watch-local-node-modules-CB61jc7h.cjs");
|
|
4
|
-
exports.normalizeTurbowatchLocalNodeModulesOptions = watchLocalNodeModules.normalizeTurbowatchLocalNodeModulesOptions;
|
|
5
|
-
exports.turbowatchLocalNodeModules = watchLocalNodeModules.turbowatchLocalNodeModules;
|
package/index.js
DELETED
package/license
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Győri Sándor
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/local-node-modules.cjs
DELETED
package/local-node-modules.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,115 +0,0 @@
|
|
|
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;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|