@decohere/core 0.0.1-dev.118 → 0.0.1-dev.120

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/commonjs/src/caching/cache-manager.js +3 -3
  2. package/commonjs/src/caching/index.js +1 -1
  3. package/commonjs/src/caching/map-cache.js +39 -0
  4. package/commonjs/src/io/io.js +0 -3
  5. package/es6/src/caching/cache-manager.js +3 -3
  6. package/es6/src/caching/index.js +1 -1
  7. package/es6/src/caching/map-cache.js +35 -0
  8. package/es6/src/caching/memoize.decorator.js +1 -1
  9. package/es6/src/io/io.js +0 -3
  10. package/package.json +6 -40
  11. package/types/src/caching/index.d.ts +1 -1
  12. package/types/src/caching/map-cache.d.ts +23 -0
  13. package/types/src/caching/memoize.decorator.d.ts +1 -1
  14. package/types/src/io/io.d.ts +0 -3
  15. package/commonjs/src/caching/node-cache-memoize.adapter.js +0 -49
  16. package/commonjs/src/cli/action.js +0 -65
  17. package/commonjs/src/cli/command.js +0 -127
  18. package/commonjs/src/cli/index.js +0 -61
  19. package/commonjs/src/cli/module.type.js +0 -18
  20. package/commonjs/src/cli/options.js +0 -115
  21. package/commonjs/src/diagnostics/index.js +0 -22
  22. package/commonjs/src/diagnostics/trace.js +0 -86
  23. package/commonjs/src/interop/docker/docker.js +0 -54
  24. package/commonjs/src/interop/errors/interop.error.js +0 -12
  25. package/commonjs/src/interop/git/git.js +0 -134
  26. package/commonjs/src/interop/git/git.types.js +0 -4
  27. package/commonjs/src/interop/index.js +0 -97
  28. package/commonjs/src/interop/node/index.js +0 -18
  29. package/commonjs/src/interop/node/node.js +0 -45
  30. package/commonjs/src/interop/npm/npm.js +0 -231
  31. package/commonjs/src/interop/npm/npm.types.js +0 -16
  32. package/commonjs/src/interop/pnpm/pnpm.js +0 -34
  33. package/commonjs/src/interop/pnpm/pnpm.types.js +0 -4
  34. package/commonjs/src/interop/shell/shell.argv.js +0 -45
  35. package/commonjs/src/interop/shell/shell.js +0 -105
  36. package/commonjs/src/interop/shell/shell.types.js +0 -4
  37. package/commonjs/src/interop/types/detect-package-manager.js +0 -71
  38. package/commonjs/src/interop/types/package-manager.js +0 -4
  39. package/commonjs/src/interop/yarn/yarn.js +0 -34
  40. package/commonjs/src/interop/yarn/yarn.types.js +0 -4
  41. package/commonjs/src/io/find-directories.js +0 -21
  42. package/commonjs/src/io/find-file.js +0 -45
  43. package/commonjs/src/io/watch.js +0 -261
  44. package/commonjs/src/semver/index.js +0 -18
  45. package/commonjs/src/semver/semver.js +0 -92
  46. package/commonjs/src/testing/flush-promises.js +0 -16
  47. package/commonjs/src/testing/glob-with-memfs.js +0 -22
  48. package/commonjs/src/testing/index.js +0 -22
  49. package/commonjs/src/testing/memfs.js +0 -52
  50. package/commonjs/src/testing/mock-logger.js +0 -36
  51. package/commonjs/src/testing/spy-on-constructor.js +0 -27
  52. package/es6/src/caching/node-cache-memoize.adapter.js +0 -37
  53. package/es6/src/cli/action.js +0 -47
  54. package/es6/src/cli/command.js +0 -106
  55. package/es6/src/cli/index.js +0 -4
  56. package/es6/src/cli/module.type.js +0 -11
  57. package/es6/src/cli/options.js +0 -76
  58. package/es6/src/diagnostics/index.js +0 -1
  59. package/es6/src/diagnostics/trace.js +0 -68
  60. package/es6/src/interop/docker/docker.js +0 -44
  61. package/es6/src/interop/errors/interop.error.js +0 -2
  62. package/es6/src/interop/git/git.js +0 -124
  63. package/es6/src/interop/git/git.types.js +0 -1
  64. package/es6/src/interop/index.js +0 -21
  65. package/es6/src/interop/node/index.js +0 -1
  66. package/es6/src/interop/node/node.js +0 -35
  67. package/es6/src/interop/npm/npm.js +0 -180
  68. package/es6/src/interop/npm/npm.types.js +0 -6
  69. package/es6/src/interop/pnpm/pnpm.js +0 -24
  70. package/es6/src/interop/pnpm/pnpm.types.js +0 -1
  71. package/es6/src/interop/shell/shell.argv.js +0 -35
  72. package/es6/src/interop/shell/shell.js +0 -95
  73. package/es6/src/interop/shell/shell.types.js +0 -1
  74. package/es6/src/interop/types/detect-package-manager.js +0 -50
  75. package/es6/src/interop/types/package-manager.js +0 -1
  76. package/es6/src/interop/yarn/yarn.js +0 -24
  77. package/es6/src/interop/yarn/yarn.types.js +0 -1
  78. package/es6/src/io/find-directories.js +0 -11
  79. package/es6/src/io/find-file.js +0 -27
  80. package/es6/src/io/watch.js +0 -238
  81. package/es6/src/semver/index.js +0 -1
  82. package/es6/src/semver/semver.js +0 -71
  83. package/es6/src/testing/flush-promises.js +0 -6
  84. package/es6/src/testing/glob-with-memfs.js +0 -20
  85. package/es6/src/testing/index.js +0 -5
  86. package/es6/src/testing/memfs.js +0 -25
  87. package/es6/src/testing/mock-logger.js +0 -26
  88. package/es6/src/testing/spy-on-constructor.js +0 -31
  89. package/types/src/caching/node-cache-memoize.adapter.d.ts +0 -22
  90. package/types/src/cli/action.d.ts +0 -36
  91. package/types/src/cli/command.d.ts +0 -34
  92. package/types/src/cli/index.d.ts +0 -7
  93. package/types/src/cli/module.type.d.ts +0 -36
  94. package/types/src/cli/options.d.ts +0 -28
  95. package/types/src/diagnostics/index.d.ts +0 -1
  96. package/types/src/diagnostics/trace.d.ts +0 -10
  97. package/types/src/interop/docker/docker.d.ts +0 -19
  98. package/types/src/interop/errors/interop.error.d.ts +0 -2
  99. package/types/src/interop/git/git.d.ts +0 -16
  100. package/types/src/interop/git/git.types.d.ts +0 -14
  101. package/types/src/interop/index.d.ts +0 -14
  102. package/types/src/interop/node/index.d.ts +0 -1
  103. package/types/src/interop/node/node.d.ts +0 -5
  104. package/types/src/interop/npm/npm.d.ts +0 -29
  105. package/types/src/interop/npm/npm.types.d.ts +0 -24
  106. package/types/src/interop/pnpm/pnpm.d.ts +0 -9
  107. package/types/src/interop/pnpm/pnpm.types.d.ts +0 -3
  108. package/types/src/interop/shell/shell.argv.d.ts +0 -5
  109. package/types/src/interop/shell/shell.d.ts +0 -6
  110. package/types/src/interop/shell/shell.types.d.ts +0 -9
  111. package/types/src/interop/types/detect-package-manager.d.ts +0 -4
  112. package/types/src/interop/types/package-manager.d.ts +0 -10
  113. package/types/src/interop/yarn/yarn.d.ts +0 -9
  114. package/types/src/interop/yarn/yarn.types.d.ts +0 -3
  115. package/types/src/io/find-directories.d.ts +0 -2
  116. package/types/src/io/find-file.d.ts +0 -9
  117. package/types/src/io/watch.d.ts +0 -16
  118. package/types/src/semver/index.d.ts +0 -1
  119. package/types/src/semver/semver.d.ts +0 -18
  120. package/types/src/testing/flush-promises.d.ts +0 -1
  121. package/types/src/testing/glob-with-memfs.d.ts +0 -3
  122. package/types/src/testing/index.d.ts +0 -5
  123. package/types/src/testing/memfs.d.ts +0 -5
  124. package/types/src/testing/mock-logger.d.ts +0 -13
  125. package/types/src/testing/spy-on-constructor.d.ts +0 -21
@@ -1,6 +0,0 @@
1
- export const VersionTypes = {
2
- major: "major",
3
- minor: "minor",
4
- patch: "patch",
5
- prerelease: "prerelease"
6
- };
@@ -1,24 +0,0 @@
1
- import { Shell } from "../shell/shell.js";
2
- const Commands = {
3
- install: "install"
4
- };
5
- export class Pnpm extends Shell {
6
- name = "pnpm";
7
- program = "pnpm";
8
- async install(options = {
9
- cwd: "./"
10
- }) {
11
- const { cwd } = options;
12
- return this.run({
13
- cwd
14
- }, Commands.install);
15
- }
16
- async syncLockFile(options = {
17
- cwd: "./"
18
- }) {
19
- const { cwd } = options;
20
- return this.run({
21
- cwd
22
- }, Commands.install, "--lockfile-only", "--ignore-scripts");
23
- }
24
- }
@@ -1 +0,0 @@
1
- export { };
@@ -1,35 +0,0 @@
1
- function fields(args) {
2
- const positional = [];
3
- const flags = {};
4
- for(let i = 0; i < args.length; i++){
5
- const arg = args[i];
6
- if (arg === "--") {
7
- positional.push(...args.slice(i + 1));
8
- break;
9
- }
10
- if (arg.startsWith("--")) {
11
- const body = arg.slice(2);
12
- const eq = body.indexOf("=");
13
- if (eq !== -1) {
14
- flags[body.slice(0, eq)] = body.slice(eq + 1);
15
- continue;
16
- }
17
- const next = args[i + 1];
18
- if (next != null && !next.startsWith("-")) {
19
- flags[body] = next;
20
- i += 1;
21
- } else {
22
- flags[body] = true;
23
- }
24
- continue;
25
- }
26
- positional.push(arg);
27
- }
28
- return {
29
- _: positional,
30
- ...flags
31
- };
32
- }
33
- export const shellArgv = {
34
- fields
35
- };
@@ -1,95 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { scribe } from "@decohere/scribe";
3
- import { InteropError } from "../errors/interop.error.js";
4
- import { shellArgv } from "./shell.argv.js";
5
- export class Shell {
6
- async run(options, ...args) {
7
- const logger = scribe.logger(Shell.name);
8
- const argv = args ?? [];
9
- const argvFields = shellArgv.fields(argv);
10
- const positionals = Array.isArray(argvFields._) ? argvFields._ : [];
11
- const commandName = [
12
- this.program,
13
- ...positionals
14
- ].join(" ").trim();
15
- logger.info("Running", {
16
- program: this.program,
17
- args: argvFields
18
- });
19
- return new Promise((resolve, reject)=>{
20
- let settled = false;
21
- const resolveOnce = (response)=>{
22
- if (settled) {
23
- return;
24
- }
25
- settled = true;
26
- resolve(response);
27
- };
28
- const rejectOnce = (error)=>{
29
- if (settled) {
30
- return;
31
- }
32
- settled = true;
33
- reject(error);
34
- };
35
- const { cwd, env } = options;
36
- const spawnOpt = {
37
- cwd: cwd ?? ".",
38
- stdio: [
39
- "inherit",
40
- "pipe",
41
- "pipe"
42
- ],
43
- env: env ?? {
44
- ...process.env
45
- }
46
- };
47
- const proc = spawn(this.program, argv, spawnOpt);
48
- const responseData = [];
49
- const errorData = [];
50
- proc.on("close", (code, signal)=>{
51
- if (code === 0) {
52
- resolveOnce({
53
- message: `${commandName} completed`,
54
- data: responseData
55
- });
56
- return;
57
- }
58
- const stderr = errorData.join("\n").trim();
59
- const stdout = responseData.join("\n").trim();
60
- const exitCodeText = code == null ? "unknown" : String(code);
61
- const signalText = signal ? ` signal ${signal}` : "";
62
- const base = `Running '${commandName}' failed with code ${exitCodeText}${signalText}`;
63
- const details = [
64
- stderr ? `stderr:\n${stderr}` : "",
65
- !stderr && stdout ? `stdout:\n${stdout}` : ""
66
- ].filter(Boolean).join("\n");
67
- rejectOnce(new InteropError(details ? `${base}\n${details}` : base));
68
- });
69
- proc.on("error", (err)=>{
70
- rejectOnce(err);
71
- });
72
- proc.stdout.on("error", (err)=>{
73
- rejectOnce(err);
74
- });
75
- proc.stdout.on("data", (data)=>{
76
- const lines = this.parseStream(data);
77
- console.log(data.toString());
78
- responseData.push(...lines);
79
- });
80
- proc.stderr?.on("error", (err)=>{
81
- rejectOnce(err);
82
- });
83
- proc.stderr?.on("data", (data)=>{
84
- const lines = this.parseStream(data);
85
- console.error(data.toString());
86
- errorData.push(...lines);
87
- });
88
- });
89
- }
90
- parseStream(data) {
91
- const dataStr = data.toString();
92
- const lines = dataStr.split("\n").filter((l)=>l !== "");
93
- return lines;
94
- }
95
- }
@@ -1 +0,0 @@
1
- export { };
@@ -1,50 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { createInterface } from "node:readline/promises";
4
- import { Npm } from "../npm/npm.js";
5
- import { Pnpm } from "../pnpm/pnpm.js";
6
- import { Yarn } from "../yarn/yarn.js";
7
- const LOCKFILES = [
8
- [
9
- "pnpm-lock.yaml",
10
- ()=>new Pnpm()
11
- ],
12
- [
13
- "yarn.lock",
14
- ()=>new Yarn()
15
- ],
16
- [
17
- "package-lock.json",
18
- ()=>new Npm()
19
- ]
20
- ];
21
- function fromLockfile(cwd) {
22
- for (const [file, factory] of LOCKFILES){
23
- if (existsSync(join(cwd, file))) return factory();
24
- }
25
- return undefined;
26
- }
27
- function fromUserAgent() {
28
- const agent = process.env.npm_config_user_agent ?? "";
29
- if (agent.startsWith("pnpm")) return new Pnpm();
30
- if (agent.startsWith("yarn")) return new Yarn();
31
- if (agent.startsWith("npm")) return new Npm();
32
- return undefined;
33
- }
34
- export function detectPackageManager(cwd) {
35
- return fromLockfile(cwd) ?? fromUserAgent();
36
- }
37
- export function packageManagerFromString(name) {
38
- if (name === "yarn") return new Yarn();
39
- if (name === "npm") return new Npm();
40
- return new Pnpm();
41
- }
42
- export async function promptForPackageManager() {
43
- const rl = createInterface({
44
- input: process.stdin,
45
- output: process.stdout
46
- });
47
- const answer = await rl.question("Package manager? [pnpm/yarn/npm] (default: pnpm): ");
48
- rl.close();
49
- return packageManagerFromString(answer.trim().toLowerCase());
50
- }
@@ -1 +0,0 @@
1
- export { };
@@ -1,24 +0,0 @@
1
- import { Shell } from "../shell/shell.js";
2
- const Commands = {
3
- install: "install"
4
- };
5
- export class Yarn extends Shell {
6
- name = "yarn";
7
- program = "yarn";
8
- async install(options = {
9
- cwd: "./"
10
- }) {
11
- const { cwd } = options;
12
- return this.run({
13
- cwd
14
- }, Commands.install);
15
- }
16
- async syncLockFile(options = {
17
- cwd: "./"
18
- }) {
19
- const { cwd } = options;
20
- return this.run({
21
- cwd
22
- }, Commands.install, "--mode", "update-lockfile", "--ignore-scripts");
23
- }
24
- }
@@ -1 +0,0 @@
1
- export { };
@@ -1,11 +0,0 @@
1
- import { glob } from "glob";
2
- export async function findDirectories(...pattern) {
3
- const paths = await glob(pattern, {
4
- withFileTypes: true
5
- });
6
- const dirs = paths.filter((p)=>p.isDirectory()).map((p)=>({
7
- name: p.name,
8
- parentPath: p.parentPath
9
- }));
10
- return dirs;
11
- }
@@ -1,27 +0,0 @@
1
- import { glob } from "glob";
2
- import { FileEx } from "./types/file.js";
3
- export async function findFile(pattern) {
4
- const files = await glob(pattern, {
5
- includeChildMatches: false
6
- });
7
- if (files.length === 0) {
8
- return;
9
- }
10
- const file = {
11
- relativePath: files.at(0)
12
- };
13
- return file;
14
- }
15
- export async function findFiles(patterns, options) {
16
- const paths = await glob(patterns, {
17
- ...options,
18
- withFileTypes: true
19
- });
20
- const files = paths.filter((p)=>p.isFile()).map((p)=>{
21
- return new FileEx({
22
- relativePath: p.relative(),
23
- fullPath: p.fullpath()
24
- });
25
- });
26
- return files;
27
- }
@@ -1,238 +0,0 @@
1
- import { watch as nativeWatch, readdirSync, statSync } from "node:fs";
2
- import path from "node:path";
3
- import picomatch from "picomatch";
4
- import { FileEx } from "./types/file.js";
5
- export const WatchEvents = {
6
- add: "add",
7
- change: "change",
8
- addDir: "addDir",
9
- unlink: "unlink",
10
- unlinkDir: "unlinkDir"
11
- };
12
- export function watch(directory, options = {
13
- cwd: "."
14
- }) {
15
- const { include, ignore, ignoreInitial = false } = options;
16
- const changeCoalesceMs = 25;
17
- const handlers = {
18
- ready: new Set(),
19
- add: new Set(),
20
- change: new Set(),
21
- addDir: new Set(),
22
- unlink: new Set(),
23
- unlinkDir: new Set()
24
- };
25
- let resolveReady;
26
- const ready = new Promise((resolve)=>{
27
- resolveReady = resolve;
28
- });
29
- const snapshot = buildSnapshot(directory);
30
- const isFiltered = (relativePath)=>{
31
- const posixRelativePath = toPosixPath(relativePath);
32
- const posixFullPath = toPosixPath(path.resolve(directory, relativePath));
33
- const matchesEitherPath = (patterns)=>picomatch.isMatch(posixRelativePath, patterns) || picomatch.isMatch(posixFullPath, patterns);
34
- if (include && include.length > 0) {
35
- return !matchesEitherPath(include);
36
- }
37
- if (ignore && ignore.length > 0) {
38
- return matchesEitherPath(ignore);
39
- }
40
- return false;
41
- };
42
- const emit = (event, relativePath)=>{
43
- if (isFiltered(relativePath)) {
44
- return;
45
- }
46
- const fullPath = path.resolve(directory, relativePath);
47
- for (const handler of handlers[event]){
48
- handler(new FileEx({
49
- fullPath,
50
- relativePath
51
- }));
52
- }
53
- };
54
- const pendingChangeTimers = new Map();
55
- const emitChange = (relativePath)=>{
56
- const existing = pendingChangeTimers.get(relativePath);
57
- if (existing != null) {
58
- clearTimeout(existing);
59
- }
60
- const timer = setTimeout(()=>{
61
- pendingChangeTimers.delete(relativePath);
62
- emit("change", relativePath);
63
- }, changeCoalesceMs);
64
- pendingChangeTimers.set(relativePath, timer);
65
- };
66
- const emitReady = ()=>{
67
- for (const handler of handlers.ready){
68
- handler();
69
- }
70
- };
71
- queueMicrotask(()=>{
72
- if (!ignoreInitial) {
73
- for (const [relativePath, entry] of snapshot){
74
- emit(entry.isDirectory ? "addDir" : "add", relativePath);
75
- }
76
- }
77
- emitReady();
78
- resolveReady?.();
79
- resolveReady = undefined;
80
- });
81
- // One non-recursive watcher per directory. Node's recursive mode on Linux tracks files
82
- // individually and goes silent for a file once an editor replaces it with an atomic save
83
- // (write temp file, rename over the original); directory watchers keep seeing it (#505).
84
- const directoryWatchers = new Map();
85
- const watchDirectory = (relativeDir)=>{
86
- if (directoryWatchers.has(relativeDir)) {
87
- return;
88
- }
89
- try {
90
- const watcher = nativeWatch(path.resolve(directory, relativeDir), (_eventType, fileName)=>{
91
- if (fileName != null) {
92
- onFsEvent(path.posix.join(relativeDir, toPosixPath(fileName.toString())));
93
- }
94
- });
95
- watcher.on("error", ()=>unwatchDirectory(relativeDir));
96
- directoryWatchers.set(relativeDir, watcher);
97
- } catch {
98
- // The directory vanished before we could watch it; its unlink event covers it.
99
- }
100
- };
101
- const unwatchDirectory = (relativeDir)=>{
102
- for (const [watchedDir, watcher] of directoryWatchers){
103
- if (watchedDir === relativeDir || watchedDir.startsWith(`${relativeDir}/`)) {
104
- watcher.close();
105
- directoryWatchers.delete(watchedDir);
106
- }
107
- }
108
- };
109
- /** A directory appeared: watch it, and report what was created in it before we were watching. */ const addDirectory = (relativeDir)=>{
110
- watchDirectory(relativeDir);
111
- const found = new Map();
112
- try {
113
- collectSnapshotEntries(directory, path.resolve(directory, relativeDir), found);
114
- } catch {
115
- return;
116
- }
117
- for (const [relativePath, entry] of found){
118
- if (snapshot.has(relativePath)) continue;
119
- snapshot.set(relativePath, entry);
120
- if (entry.isDirectory) watchDirectory(relativePath);
121
- emit(entry.isDirectory ? "addDir" : "add", relativePath);
122
- }
123
- };
124
- /** A directory went away: stop watching it and forget everything that was under it. */ const removeDirectoryContents = (relativeDir)=>{
125
- unwatchDirectory(relativeDir);
126
- // oxlint-disable-next-line unicorn/no-useless-spread -- iterate a copy: the loop deletes from the snapshot
127
- for (const [relativePath, entry] of [
128
- ...snapshot
129
- ]){
130
- if (relativePath.startsWith(`${relativeDir}/`)) {
131
- snapshot.delete(relativePath);
132
- emit(entry.isDirectory ? "unlinkDir" : "unlink", relativePath);
133
- }
134
- }
135
- };
136
- const onFsEvent = (eventPath)=>{
137
- const relativePath = eventPath === "." ? "" : eventPath;
138
- if (relativePath.length === 0) {
139
- return;
140
- }
141
- const fullPath = path.resolve(directory, relativePath);
142
- const previous = snapshot.get(relativePath);
143
- try {
144
- const stat = statSync(fullPath);
145
- const current = toSnapshotEntry(stat);
146
- snapshot.set(relativePath, current);
147
- if (previous == null) {
148
- emit(current.isDirectory ? "addDir" : "add", relativePath);
149
- if (current.isDirectory) addDirectory(relativePath);
150
- return;
151
- }
152
- if (previous.isDirectory !== current.isDirectory) {
153
- if (previous.isDirectory) removeDirectoryContents(relativePath);
154
- emit(previous.isDirectory ? "unlinkDir" : "unlink", relativePath);
155
- emit(current.isDirectory ? "addDir" : "add", relativePath);
156
- return;
157
- }
158
- if (!current.isDirectory && previous.fingerprint !== current.fingerprint) {
159
- emitChange(relativePath);
160
- }
161
- } catch {
162
- if (previous == null) {
163
- return;
164
- }
165
- snapshot.delete(relativePath);
166
- const pending = pendingChangeTimers.get(relativePath);
167
- if (pending != null) {
168
- clearTimeout(pending);
169
- pendingChangeTimers.delete(relativePath);
170
- }
171
- emit(previous.isDirectory ? "unlinkDir" : "unlink", relativePath);
172
- }
173
- };
174
- watchDirectory("");
175
- for (const [relativePath, entry] of snapshot){
176
- if (entry.isDirectory) watchDirectory(relativePath);
177
- }
178
- const watchApi = {
179
- ready,
180
- on (event, handler) {
181
- if (event === "ready") {
182
- handlers.ready.add(handler);
183
- return watchApi;
184
- }
185
- handlers[event].add(handler);
186
- return watchApi;
187
- },
188
- close: ()=>{
189
- for (const pending of pendingChangeTimers.values()){
190
- clearTimeout(pending);
191
- }
192
- pendingChangeTimers.clear();
193
- for (const watcher of directoryWatchers.values()){
194
- watcher.close();
195
- }
196
- directoryWatchers.clear();
197
- }
198
- };
199
- return watchApi;
200
- }
201
- function buildSnapshot(directoryPath) {
202
- const snapshot = new Map();
203
- collectSnapshotEntries(directoryPath, directoryPath, snapshot);
204
- return snapshot;
205
- }
206
- /** Never source, and huge: watching every folder inside them could exhaust OS watch limits. */ const UNWATCHED_DIRECTORIES = new Set([
207
- "node_modules",
208
- ".git"
209
- ]);
210
- function collectSnapshotEntries(rootDirectoryPath, currentDirectoryPath, snapshot) {
211
- for (const entry of readdirSync(currentDirectoryPath, {
212
- encoding: "utf8"
213
- })){
214
- const name = typeof entry === "string" ? entry : String(entry);
215
- const fullPath = path.join(currentDirectoryPath, name);
216
- if (UNWATCHED_DIRECTORIES.has(name)) {
217
- continue;
218
- }
219
- const relativePath = toPosixPath(path.relative(rootDirectoryPath, fullPath));
220
- const stat = statSync(fullPath);
221
- const snapshotEntry = toSnapshotEntry(stat);
222
- snapshot.set(relativePath, snapshotEntry);
223
- if (!snapshotEntry.isDirectory) {
224
- continue;
225
- }
226
- collectSnapshotEntries(rootDirectoryPath, fullPath, snapshot);
227
- }
228
- }
229
- function toSnapshotEntry(stat) {
230
- const isDirectory = stat.isDirectory();
231
- return {
232
- isDirectory,
233
- fingerprint: isDirectory ? `dir:${stat.mtimeMs}` : `file:${stat.mtimeMs}:${stat.size}`
234
- };
235
- }
236
- function toPosixPath(filePath) {
237
- return filePath.split(path.sep).join(path.posix.sep);
238
- }
@@ -1 +0,0 @@
1
- export * from "./semver.js";
@@ -1,71 +0,0 @@
1
- export const VersionTypes = {
2
- major: "major",
3
- minor: "minor",
4
- patch: "patch",
5
- prerelease: "prerelease"
6
- };
7
- export class SemverError extends Error {
8
- constructor(message){
9
- super(message);
10
- this.name = SemverError.name;
11
- }
12
- }
13
- const SEMVER_REGEX = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
14
- export class Semver {
15
- version;
16
- constructor(version){
17
- this.ensureValid(version);
18
- this.version = version;
19
- }
20
- increment(versionType, preid = "pre") {
21
- const { major, minor, patch, prerelease } = this.parse(this.version);
22
- if (versionType === "major") {
23
- this.version = `${major + 1}.0.0`;
24
- return this;
25
- }
26
- if (versionType === "minor") {
27
- this.version = `${major}.${minor + 1}.0`;
28
- return this;
29
- }
30
- if (versionType === "patch") {
31
- this.version = `${major}.${minor}.${patch + 1}`;
32
- return this;
33
- }
34
- if (prerelease == null) {
35
- this.version = `${major}.${minor}.${patch + 1}-${preid}.0`;
36
- return this;
37
- }
38
- const [identifier, ...rest] = prerelease.split(".");
39
- const maybeCounter = rest.at(-1);
40
- const counter = maybeCounter != null ? Number.parseInt(maybeCounter, 10) : Number.NaN;
41
- if (identifier === preid && Number.isFinite(counter)) {
42
- const nextCounter = counter + 1;
43
- const prefix = rest.length > 1 ? `${rest.slice(0, -1).join(".")}.` : "";
44
- this.version = `${major}.${minor}.${patch}-${preid}.${prefix}${nextCounter}`;
45
- return this;
46
- }
47
- this.version = `${major}.${minor}.${patch}-${preid}.0`;
48
- return this;
49
- }
50
- toString() {
51
- return this.version;
52
- }
53
- ensureValid(version) {
54
- if (SEMVER_REGEX.test(version)) {
55
- return;
56
- }
57
- throw new SemverError(`Invalid semantic version: ${version}`);
58
- }
59
- parse(version) {
60
- const match = version.match(SEMVER_REGEX);
61
- if (match == null) {
62
- throw new SemverError(`Invalid semantic version: ${version}`);
63
- }
64
- return {
65
- major: Number.parseInt(match[1], 10),
66
- minor: Number.parseInt(match[2], 10),
67
- patch: Number.parseInt(match[3], 10),
68
- prerelease: match[4]
69
- };
70
- }
71
- }
@@ -1,6 +0,0 @@
1
- var scheduler = typeof setImmediate === "function" ? setImmediate : setTimeout;
2
- export function flushPromises() {
3
- return new Promise((resolve)=>{
4
- scheduler(resolve);
5
- });
6
- }
@@ -1,20 +0,0 @@
1
- import { fs } from "memfs";
2
- // Wraps a real `glob` module so all file-system access is routed through memfs.
3
- //
4
- // Why this exists:
5
- // - Integration tests often need real glob matching semantics.
6
- // - Vitest `vi.mock` factories are hoisted, so directly importing and patching
7
- // `glob` inside helper modules can trigger initialization-order issues.
8
- // - Passing the already-loaded `actual` module keeps the helper pure and
9
- // hoist-safe while still allowing us to inject memfs.
10
- export function withMemfsFsForGlob(actual) {
11
- // Preserve all module exports, overriding only `glob` to force `{ fs: memfs }`.
12
- const glob = (pattern, options)=>actual.glob(pattern, {
13
- ...options,
14
- fs
15
- });
16
- return {
17
- ...actual,
18
- glob
19
- };
20
- }
@@ -1,5 +0,0 @@
1
- export * from "./flush-promises.js";
2
- export * from "./glob-with-memfs.js";
3
- export * from "./memfs.js";
4
- export * from "./mock-logger.js";
5
- export * from "./spy-on-constructor.js";
@@ -1,25 +0,0 @@
1
- import { fs, vol } from "memfs";
2
- export function resetMemfs() {
3
- vol.reset();
4
- }
5
- export function seedMemfs(files) {
6
- vol.fromJSON(files);
7
- }
8
- export function createTestFile(filePath, content) {
9
- fs.mkdirSync(filePath.substring(0, filePath.lastIndexOf("/")), {
10
- recursive: true
11
- });
12
- fs.writeFileSync(filePath, content);
13
- }
14
- export async function readFile(filePath) {
15
- const response = await fs.promises.readFile(filePath, "utf8");
16
- return response;
17
- }
18
- export function fileExists(filePath) {
19
- try {
20
- vol.statSync(filePath);
21
- return true;
22
- } catch {
23
- return false;
24
- }
25
- }