@atolis-hq/wake 0.2.16 → 0.2.17
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/src/cli/sandbox-command.js +5 -2
- package/dist/src/version.js +127 -1
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ import { createRunnerCliAdapter } from '../adapters/runner/runner-cli-adapter.js
|
|
|
4
4
|
import { runSandboxResumeCommand } from './sandbox-resume.js';
|
|
5
5
|
import { runSelfUpdateCommand, runSelfUpdateLoop } from './self-update-command.js';
|
|
6
6
|
import { runStopCommand } from './stop-command.js';
|
|
7
|
-
import { wakeVersion } from '../version.js';
|
|
7
|
+
import { resolveWakeVersion, wakeVersion } from '../version.js';
|
|
8
8
|
async function ensureDockerfile(input) {
|
|
9
9
|
const targetPath = resolve(input.wakeRoot, 'docker', 'Dockerfile');
|
|
10
10
|
try {
|
|
@@ -89,6 +89,7 @@ export async function runSandboxCommand(input) {
|
|
|
89
89
|
throw new Error('Sandbox build requires config.dev.repoRoot');
|
|
90
90
|
}
|
|
91
91
|
const effectiveDevMode = input.config.dev?.mode ?? 'packaged';
|
|
92
|
+
const buildVersion = effectiveDevMode === 'source' ? resolveWakeVersion({ repoRoot }) : wakeVersion;
|
|
92
93
|
await ensureDockerfile({
|
|
93
94
|
wakeRoot: input.wakeRoot,
|
|
94
95
|
devMode: effectiveDevMode,
|
|
@@ -98,7 +99,9 @@ export async function runSandboxCommand(input) {
|
|
|
98
99
|
image: input.config.sandbox.image,
|
|
99
100
|
dockerfile: resolve(input.wakeRoot, 'docker', 'Dockerfile'),
|
|
100
101
|
contextDir: repoRoot,
|
|
101
|
-
|
|
102
|
+
buildArgs: effectiveDevMode === 'packaged'
|
|
103
|
+
? { WAKE_VERSION: buildVersion }
|
|
104
|
+
: { WAKE_BUILD_TAG: buildVersion },
|
|
102
105
|
});
|
|
103
106
|
return;
|
|
104
107
|
}
|
package/dist/src/version.js
CHANGED
|
@@ -1 +1,127 @@
|
|
|
1
|
-
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
const defaultRepoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
6
|
+
function gitOutputFromRoot(repoRoot, args) {
|
|
7
|
+
try {
|
|
8
|
+
return execFileSync('git', args, {
|
|
9
|
+
cwd: repoRoot,
|
|
10
|
+
encoding: 'utf8',
|
|
11
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
12
|
+
}).trim();
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function defaultReadTextFile(path) {
|
|
19
|
+
try {
|
|
20
|
+
return readFileSync(path, 'utf8');
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function defaultListTextFiles(path) {
|
|
27
|
+
if (!existsSync(path)) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const files = [];
|
|
31
|
+
for (const entry of readdirSync(path, { withFileTypes: true })) {
|
|
32
|
+
const entryPath = resolve(path, entry.name);
|
|
33
|
+
if (entry.isDirectory()) {
|
|
34
|
+
files.push(...defaultListTextFiles(entryPath));
|
|
35
|
+
}
|
|
36
|
+
else if (entry.isFile()) {
|
|
37
|
+
const content = defaultReadTextFile(entryPath);
|
|
38
|
+
if (content !== undefined) {
|
|
39
|
+
files.push({ path: entryPath, content });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return files;
|
|
44
|
+
}
|
|
45
|
+
function currentHeadHash(repoRoot, readTextFile) {
|
|
46
|
+
const head = readTextFile(resolve(repoRoot, '.git', 'HEAD'))?.trim();
|
|
47
|
+
if (head === undefined || head.length === 0) {
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
if (!head.startsWith('ref: ')) {
|
|
51
|
+
return head;
|
|
52
|
+
}
|
|
53
|
+
const refPath = head.slice('ref: '.length).trim();
|
|
54
|
+
return readTextFile(resolve(repoRoot, '.git', ...refPath.split('/')))?.trim() ?? '';
|
|
55
|
+
}
|
|
56
|
+
function looseTagRefs(repoRoot, listTextFiles) {
|
|
57
|
+
const tagsRoot = resolve(repoRoot, '.git', 'refs', 'tags');
|
|
58
|
+
return listTextFiles(tagsRoot).map((file) => ({
|
|
59
|
+
name: file.path.replaceAll('\\', '/').slice(tagsRoot.replaceAll('\\', '/').length + 1),
|
|
60
|
+
hash: file.content.trim(),
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
function packedTagRefs(repoRoot, readTextFile) {
|
|
64
|
+
const packedRefs = readTextFile(resolve(repoRoot, '.git', 'packed-refs'));
|
|
65
|
+
if (packedRefs === undefined) {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
const refs = [];
|
|
69
|
+
let previousTag;
|
|
70
|
+
for (const line of packedRefs.split(/\r?\n/)) {
|
|
71
|
+
if (line.length === 0 || line.startsWith('#')) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (line.startsWith('^')) {
|
|
75
|
+
if (previousTag !== undefined) {
|
|
76
|
+
previousTag.hash = line.slice(1).trim();
|
|
77
|
+
}
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
previousTag = undefined;
|
|
81
|
+
const [hash, ref] = line.split(' ');
|
|
82
|
+
if (hash !== undefined && ref?.startsWith('refs/tags/') === true) {
|
|
83
|
+
previousTag = { name: ref.slice('refs/tags/'.length), hash };
|
|
84
|
+
refs.push(previousTag);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return refs;
|
|
88
|
+
}
|
|
89
|
+
function exactTagFromGitFiles(repoRoot, readTextFile, listTextFiles) {
|
|
90
|
+
const headHash = currentHeadHash(repoRoot, readTextFile);
|
|
91
|
+
if (headHash.length === 0) {
|
|
92
|
+
return '';
|
|
93
|
+
}
|
|
94
|
+
const matchingTag = [
|
|
95
|
+
...looseTagRefs(repoRoot, listTextFiles),
|
|
96
|
+
...packedTagRefs(repoRoot, readTextFile),
|
|
97
|
+
].find((tag) => tag.hash === headHash);
|
|
98
|
+
return matchingTag?.name ?? '';
|
|
99
|
+
}
|
|
100
|
+
export function resolveWakeVersion(options = {}) {
|
|
101
|
+
const repoRoot = options.repoRoot ?? defaultRepoRoot;
|
|
102
|
+
const gitOutput = options.gitOutput ?? ((args) => gitOutputFromRoot(repoRoot, args));
|
|
103
|
+
const readTextFile = options.readTextFile ?? defaultReadTextFile;
|
|
104
|
+
const listTextFiles = options.listTextFiles ?? defaultListTextFiles;
|
|
105
|
+
const exactTag = gitOutput(['describe', '--tags', '--exact-match', 'HEAD']);
|
|
106
|
+
if (exactTag.length > 0) {
|
|
107
|
+
return exactTag;
|
|
108
|
+
}
|
|
109
|
+
const exactFileTag = exactTagFromGitFiles(repoRoot, readTextFile, listTextFiles);
|
|
110
|
+
if (exactFileTag.length > 0) {
|
|
111
|
+
return exactFileTag;
|
|
112
|
+
}
|
|
113
|
+
const latestTag = gitOutput(['describe', '--tags', '--abbrev=0']);
|
|
114
|
+
const shortHash = gitOutput(['rev-parse', '--short', 'HEAD']);
|
|
115
|
+
if (latestTag.length > 0 && shortHash.length > 0) {
|
|
116
|
+
return `${latestTag}+g${shortHash}`;
|
|
117
|
+
}
|
|
118
|
+
if (shortHash.length > 0) {
|
|
119
|
+
return `g${shortHash}`;
|
|
120
|
+
}
|
|
121
|
+
const headHash = currentHeadHash(repoRoot, readTextFile);
|
|
122
|
+
if (headHash.length > 0) {
|
|
123
|
+
return `g${headHash.slice(0, 7)}`;
|
|
124
|
+
}
|
|
125
|
+
return '0.1.0-dev';
|
|
126
|
+
}
|
|
127
|
+
export const wakeVersion = "g743a5ea";
|