vitecompose 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +180 -2
- package/dist/core/index.d.mts +4 -0
- package/dist/core/index.mjs +3 -0
- package/dist/duration-BRZrZK6s.mjs +13 -0
- package/dist/index.d.mts +62 -0
- package/dist/index.mjs +144 -0
- package/dist/node.d.mts +108 -0
- package/dist/node.mjs +587 -0
- package/dist/provided-CnoC64M0.d.mts +8 -0
- package/dist/scope-B1yisv2y.d.mts +292 -0
- package/dist/scope-BT1dmBGo.mjs +670 -0
- package/dist/state-B-aMt5sE.mjs +152 -0
- package/package.json +51 -4
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
// src/stack/state.ts
|
|
5
|
+
const emptyEnvironment = () => ({
|
|
6
|
+
images: {},
|
|
7
|
+
stages: {}
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Persists lock, lifecycle, unusable flag and stage fingerprints atomically in a JSON file
|
|
11
|
+
* under the project's private state directory.
|
|
12
|
+
*/
|
|
13
|
+
const createStackStateStore = (stateDir) => {
|
|
14
|
+
const statePath = join(stateDir, "state.json");
|
|
15
|
+
const read = async () => {
|
|
16
|
+
try {
|
|
17
|
+
const raw = await readFile(statePath, "utf8");
|
|
18
|
+
const parsed = JSON.parse(raw);
|
|
19
|
+
return parsed && typeof parsed === "object" ? parsed : null;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (error.code === "ENOENT") return null;
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const writeAtomic = async (state) => {
|
|
26
|
+
await mkdir(stateDir, {
|
|
27
|
+
recursive: true,
|
|
28
|
+
mode: 448
|
|
29
|
+
});
|
|
30
|
+
const tmpPath = join(stateDir, `state.${randomUUID()}.tmp`);
|
|
31
|
+
await writeFile(tmpPath, JSON.stringify(state, null, 2), { mode: 384 });
|
|
32
|
+
try {
|
|
33
|
+
await rename(tmpPath, statePath);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
await rm(tmpPath, { force: true }).catch(() => {});
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const update = async (mutate) => {
|
|
40
|
+
const next = mutate(await read() ?? {});
|
|
41
|
+
await writeAtomic(next);
|
|
42
|
+
return next;
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
statePath,
|
|
46
|
+
initialize: async (marker, lifecycle) => {
|
|
47
|
+
await update((current) => ({
|
|
48
|
+
...current,
|
|
49
|
+
marker: current.marker ?? marker,
|
|
50
|
+
lifecycle: lifecycle ?? current.lifecycle,
|
|
51
|
+
environment: current.environment ?? emptyEnvironment()
|
|
52
|
+
}));
|
|
53
|
+
},
|
|
54
|
+
read,
|
|
55
|
+
acquireLock: async (lock, isLive) => {
|
|
56
|
+
const current = await read() ?? {};
|
|
57
|
+
if (current.lock && isLive(current.lock) && current.lock.holder !== lock.holder) return current.lock;
|
|
58
|
+
await writeAtomic({
|
|
59
|
+
...current,
|
|
60
|
+
lock
|
|
61
|
+
});
|
|
62
|
+
return null;
|
|
63
|
+
},
|
|
64
|
+
renewLock: async (holder, expiresAt) => {
|
|
65
|
+
await update((current) => {
|
|
66
|
+
if (current.lock?.holder !== holder) return current;
|
|
67
|
+
return {
|
|
68
|
+
...current,
|
|
69
|
+
lock: {
|
|
70
|
+
...current.lock,
|
|
71
|
+
expiresAt
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
releaseLock: async (holder) => {
|
|
77
|
+
await update((current) => {
|
|
78
|
+
if (current.lock?.holder !== holder) return current;
|
|
79
|
+
const { lock: _removed, ...rest } = current;
|
|
80
|
+
return rest;
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
markUnusable: async (reason) => {
|
|
84
|
+
await update((current) => ({
|
|
85
|
+
...current,
|
|
86
|
+
unusable: current.unusable ?? reason
|
|
87
|
+
}));
|
|
88
|
+
},
|
|
89
|
+
clearUnusable: async () => {
|
|
90
|
+
await update((current) => {
|
|
91
|
+
const { unusable: _removed, ...rest } = current;
|
|
92
|
+
return rest;
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
markFailed: async () => {
|
|
96
|
+
await update((current) => ({
|
|
97
|
+
...current,
|
|
98
|
+
hadFailure: true
|
|
99
|
+
}));
|
|
100
|
+
},
|
|
101
|
+
clearFailed: async () => {
|
|
102
|
+
await update((current) => {
|
|
103
|
+
const { hadFailure: _removed, ...rest } = current;
|
|
104
|
+
return rest;
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
readEnvironment: async () => {
|
|
108
|
+
const state = await read();
|
|
109
|
+
return {
|
|
110
|
+
images: { ...state?.environment?.images },
|
|
111
|
+
stages: { ...state?.environment?.stages }
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
recordImage: async (name, id) => {
|
|
115
|
+
await update((current) => {
|
|
116
|
+
const environment = current.environment ?? emptyEnvironment();
|
|
117
|
+
return {
|
|
118
|
+
...current,
|
|
119
|
+
environment: {
|
|
120
|
+
...environment,
|
|
121
|
+
images: {
|
|
122
|
+
...environment.images,
|
|
123
|
+
[name]: id
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
recordStage: async (name, fingerprint) => {
|
|
130
|
+
await update((current) => {
|
|
131
|
+
const environment = current.environment ?? emptyEnvironment();
|
|
132
|
+
const stages = { ...environment.stages };
|
|
133
|
+
if (fingerprint === void 0) delete stages[name];
|
|
134
|
+
else stages[name] = fingerprint;
|
|
135
|
+
return {
|
|
136
|
+
...current,
|
|
137
|
+
environment: {
|
|
138
|
+
...environment,
|
|
139
|
+
stages
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
clearEnvironment: async () => {
|
|
145
|
+
await update((current) => ({
|
|
146
|
+
...current,
|
|
147
|
+
environment: emptyEnvironment()
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
export { createStackStateStore as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitecompose",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vitest on real Docker Compose stacks. Write integration tests that feel like unit tests.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"docker",
|
|
7
|
+
"docker-compose",
|
|
8
|
+
"e2e",
|
|
9
|
+
"integration-testing",
|
|
10
|
+
"testing",
|
|
11
|
+
"vitest"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/vitekube/vitecompose",
|
|
14
|
+
"bugs": "https://github.com/vitekube/vitecompose/issues",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Dragan Bajcic",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/vitekube/vitecompose.git"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": "./dist/index.mjs",
|
|
27
|
+
"./core": "./dist/core/index.mjs",
|
|
28
|
+
"./node": "./dist/node.mjs",
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"prepare": "vp config --no-agent && vp pack",
|
|
33
|
+
"e2e": "vp test run --config e2e/vitest.config.ts",
|
|
34
|
+
"e2e:smoke": "pnpm --dir examples/quick-start run e2e",
|
|
35
|
+
"e2e:environment": "pnpm --dir examples/environment run e2e",
|
|
36
|
+
"e2e:all": "sh scripts/e2e-all.sh",
|
|
37
|
+
"e2e:clean": "sh scripts/e2e-clean.sh",
|
|
38
|
+
"e2e:tarball": "sh scripts/e2e-tarball.sh"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^24.0.0",
|
|
42
|
+
"typescript": "^7.0.2",
|
|
43
|
+
"vite-plus": "1.5.0",
|
|
44
|
+
"vitest": "5.1.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"vitest": "^5.0.0"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": "^22.18.0 || ^24.11.0 || >=26.0.0"
|
|
51
|
+
},
|
|
52
|
+
"packageManager": "pnpm@12.4.1"
|
|
53
|
+
}
|