@meistrari/mise-en-place 2.4.6 → 2.4.8
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/cli/cli.mjs +226 -0
- package/package.json +2 -2
- package/dist/cli.mjs +0 -14
- package/scripts/postinstall.sh +0 -94
- /package/dist/{cli.d.mts → cli/cli.d.mts} +0 -0
- /package/dist/{cli.d.ts → cli/cli.d.ts} +0 -0
package/dist/cli/cli.mjs
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { argv } from 'node:process';
|
|
3
|
+
import { existsSync, writeFileSync, readFileSync, globSync } from 'node:fs';
|
|
4
|
+
import { execSync } from 'node:child_process';
|
|
5
|
+
import { dirname } from 'node:path';
|
|
6
|
+
|
|
7
|
+
function readPackageJson(path) {
|
|
8
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
9
|
+
}
|
|
10
|
+
function writePackageJson(path, content) {
|
|
11
|
+
writeFileSync(path, `${JSON.stringify(content, null, 4)}
|
|
12
|
+
`);
|
|
13
|
+
}
|
|
14
|
+
function findWorkspacePackageJsons(workspaces) {
|
|
15
|
+
const packageJsons = [];
|
|
16
|
+
for (const pattern of workspaces) {
|
|
17
|
+
const matches = globSync(`${pattern}/package.json`);
|
|
18
|
+
packageJsons.push(...matches);
|
|
19
|
+
}
|
|
20
|
+
return packageJsons;
|
|
21
|
+
}
|
|
22
|
+
function getMeistrariLibs(packageJson) {
|
|
23
|
+
const libs = /* @__PURE__ */ new Set();
|
|
24
|
+
const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
|
|
25
|
+
for (const dep of Object.keys(deps)) {
|
|
26
|
+
if (dep.startsWith("@meistrari/")) {
|
|
27
|
+
libs.add(dep);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return Array.from(libs).sort();
|
|
31
|
+
}
|
|
32
|
+
function addCaretToMeistrariDeps(deps) {
|
|
33
|
+
if (!deps)
|
|
34
|
+
return deps;
|
|
35
|
+
const result = {};
|
|
36
|
+
for (const [key, value] of Object.entries(deps)) {
|
|
37
|
+
if (key.startsWith("@meistrari/") && !value.startsWith("^")) {
|
|
38
|
+
result[key] = `^${value}`;
|
|
39
|
+
} else {
|
|
40
|
+
result[key] = value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
function detectPackageManager() {
|
|
46
|
+
const pnpmLockExists = existsSync("pnpm-lock.yaml");
|
|
47
|
+
if (pnpmLockExists) {
|
|
48
|
+
return {
|
|
49
|
+
packageManager: "pnpm",
|
|
50
|
+
file: "pnpm-lock.yaml"
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const bunLockExists = existsSync("bun.lock");
|
|
54
|
+
if (bunLockExists) {
|
|
55
|
+
return {
|
|
56
|
+
packageManager: "bun",
|
|
57
|
+
file: "bun.lock"
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const bunLockbExists = existsSync("bun.lockb");
|
|
61
|
+
if (bunLockbExists) {
|
|
62
|
+
return {
|
|
63
|
+
packageManager: "bun",
|
|
64
|
+
file: "bun.lockb"
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const yarnLockExists = existsSync("yarn.lock");
|
|
68
|
+
if (yarnLockExists) {
|
|
69
|
+
return {
|
|
70
|
+
packageManager: "yarn",
|
|
71
|
+
file: "yarn.lock"
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const npmLockExists = existsSync("package-lock.json");
|
|
75
|
+
if (npmLockExists) {
|
|
76
|
+
return {
|
|
77
|
+
packageManager: "npm",
|
|
78
|
+
file: "package-lock.json"
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
function updateLibraries(packageManager, libs, cwd) {
|
|
84
|
+
const libsStr = libs.join(" ");
|
|
85
|
+
const options = {
|
|
86
|
+
stdio: "inherit",
|
|
87
|
+
cwd
|
|
88
|
+
};
|
|
89
|
+
switch (packageManager) {
|
|
90
|
+
case "pnpm":
|
|
91
|
+
execSync(`pnpm update ${libsStr} --ignore-scripts -r`, options);
|
|
92
|
+
break;
|
|
93
|
+
case "bun":
|
|
94
|
+
execSync(`bun update --silent ${libsStr} --ignore-scripts`, options);
|
|
95
|
+
break;
|
|
96
|
+
case "yarn":
|
|
97
|
+
execSync(`yarn up ${libsStr} --ignore-scripts -r`, options);
|
|
98
|
+
break;
|
|
99
|
+
case "npm":
|
|
100
|
+
execSync(`npm update ${libsStr} --ignore-scripts`, options);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function handleMakefileInitialSetup() {
|
|
105
|
+
if (existsSync("Makefile")) {
|
|
106
|
+
console.log("Makefile already exists. Skipping initial setup");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
console.log("No Makefile found. Generating one that includes mise-en-place Makefile.");
|
|
110
|
+
writeFileSync("Makefile", "-include ./node_modules/@meistrari/mise-en-place/Makefile\n");
|
|
111
|
+
execSync("make mise-en-place", { stdio: "inherit" });
|
|
112
|
+
}
|
|
113
|
+
function updateMeistrariLibraries(packageManagerOverride) {
|
|
114
|
+
if (!existsSync("package.json")) {
|
|
115
|
+
console.log("No package.json found. Skipping @meistrari/* updates.");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const rootPackageJson = readPackageJson("package.json");
|
|
119
|
+
const workspaces = rootPackageJson.workspaces || [];
|
|
120
|
+
const packageJsonPaths = ["./package.json"];
|
|
121
|
+
if (workspaces.length > 0) {
|
|
122
|
+
const workspacePackageJsons = findWorkspacePackageJsons(workspaces);
|
|
123
|
+
packageJsonPaths.push(...workspacePackageJsons);
|
|
124
|
+
console.log(`Found workspace package.json files: ${packageJsonPaths.join(" ")}`);
|
|
125
|
+
}
|
|
126
|
+
const allMeistrariLibs = /* @__PURE__ */ new Set();
|
|
127
|
+
for (const pkgJsonPath of packageJsonPaths) {
|
|
128
|
+
if (!existsSync(pkgJsonPath))
|
|
129
|
+
continue;
|
|
130
|
+
const pkgJson = readPackageJson(pkgJsonPath);
|
|
131
|
+
for (const lib of getMeistrariLibs(pkgJson)) {
|
|
132
|
+
allMeistrariLibs.add(lib);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (allMeistrariLibs.size === 0) {
|
|
136
|
+
console.log("No @meistrari/* libraries found in dependencies. Skipping update.");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
for (const pkgJsonPath of packageJsonPaths) {
|
|
140
|
+
if (!existsSync(pkgJsonPath))
|
|
141
|
+
continue;
|
|
142
|
+
const pkgJson = readPackageJson(pkgJsonPath);
|
|
143
|
+
if (pkgJson.dependencies) {
|
|
144
|
+
const updated = addCaretToMeistrariDeps(pkgJson.dependencies);
|
|
145
|
+
pkgJson.dependencies = updated;
|
|
146
|
+
}
|
|
147
|
+
if (pkgJson.devDependencies) {
|
|
148
|
+
const updated = addCaretToMeistrariDeps(pkgJson.devDependencies);
|
|
149
|
+
pkgJson.devDependencies = updated;
|
|
150
|
+
}
|
|
151
|
+
writePackageJson(pkgJsonPath, pkgJson);
|
|
152
|
+
}
|
|
153
|
+
const libsList = Array.from(allMeistrariLibs).sort();
|
|
154
|
+
console.log(`Found ${libsList.length} @meistrari/* libraries to update:`);
|
|
155
|
+
console.log(libsList.join("\n"));
|
|
156
|
+
const selectPackageManager = () => {
|
|
157
|
+
if (packageManagerOverride) {
|
|
158
|
+
console.log(`Using overridden package manager: ${packageManagerOverride}`);
|
|
159
|
+
return packageManagerOverride;
|
|
160
|
+
}
|
|
161
|
+
const detectedPackageManager = detectPackageManager();
|
|
162
|
+
if (!detectedPackageManager) {
|
|
163
|
+
console.log("No recognized lock file found (pnpm-lock.yaml, yarn.lock, package-lock.json)");
|
|
164
|
+
process.exit(1);
|
|
165
|
+
}
|
|
166
|
+
const { packageManager: packageManager2, file } = detectedPackageManager;
|
|
167
|
+
console.log(`Detected ${packageManager2} due to the presence of the file '${file}'. Updating @meistrari/* libraries...`);
|
|
168
|
+
return packageManager2;
|
|
169
|
+
};
|
|
170
|
+
const packageManager = selectPackageManager();
|
|
171
|
+
if (packageManager === "bun") {
|
|
172
|
+
for (const pkgJsonPath of packageJsonPaths) {
|
|
173
|
+
if (!existsSync(pkgJsonPath))
|
|
174
|
+
continue;
|
|
175
|
+
const pkgJsonDir = dirname(pkgJsonPath);
|
|
176
|
+
const pkgJson = readPackageJson(pkgJsonPath);
|
|
177
|
+
const localLibs = getMeistrariLibs(pkgJson);
|
|
178
|
+
if (localLibs.length === 0) {
|
|
179
|
+
console.log(`No @meistrari/* libraries found in ${pkgJsonDir}. Skipping.`);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
console.log(`Updating ${localLibs.join(" ")} libraries in ${pkgJsonDir}`);
|
|
183
|
+
updateLibraries(packageManager, localLibs, pkgJsonDir === "." ? void 0 : pkgJsonDir);
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
updateLibraries(packageManager, libsList);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function postinstall(args) {
|
|
190
|
+
handleMakefileInitialSetup();
|
|
191
|
+
updateMeistrariLibraries(args.packageManager);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function parseArgs(args2) {
|
|
195
|
+
const result = {};
|
|
196
|
+
for (let i = 0; i < args2.length; i++) {
|
|
197
|
+
const arg = args2[i];
|
|
198
|
+
if (arg?.startsWith("--")) {
|
|
199
|
+
const [key, value] = arg.slice(2).split("=");
|
|
200
|
+
if (key === void 0) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (value !== void 0) {
|
|
204
|
+
result[key] = value;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
const nextIndex = i + 1;
|
|
208
|
+
const nextArg = args2[nextIndex];
|
|
209
|
+
if (nextArg && !nextArg.startsWith("--")) {
|
|
210
|
+
result[key] = nextArg;
|
|
211
|
+
i = nextIndex;
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
result[key] = true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
const [command, ...args] = argv.slice(2);
|
|
220
|
+
const parsedArgs = parseArgs(args);
|
|
221
|
+
console.log(parsedArgs);
|
|
222
|
+
if (command === "postinstall") {
|
|
223
|
+
postinstall(parsedArgs);
|
|
224
|
+
process.exit(0);
|
|
225
|
+
}
|
|
226
|
+
throw new Error(`Unknown command: ${command}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meistrari/mise-en-place",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"build": "unbuild"
|
|
11
11
|
},
|
|
12
12
|
"bin": {
|
|
13
|
-
"mise-en-place": "dist/cli.mjs"
|
|
13
|
+
"mise-en-place": "dist/cli/cli.mjs"
|
|
14
14
|
},
|
|
15
15
|
"exports": {
|
|
16
16
|
"./eslint": {
|
package/dist/cli.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { execSync } from 'node:child_process';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { dirname, join } from 'node:path';
|
|
5
|
-
import { argv } from 'node:process';
|
|
6
|
-
|
|
7
|
-
const [command] = argv.slice(2);
|
|
8
|
-
const __dirname$1 = dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
if (command === "postinstall") {
|
|
10
|
-
const scriptPath = join(__dirname$1, "..", "scripts", "postinstall.sh");
|
|
11
|
-
execSync(scriptPath, { stdio: "inherit" });
|
|
12
|
-
process.exit(0);
|
|
13
|
-
}
|
|
14
|
-
throw new Error(`Unknown command: ${command}`);
|
package/scripts/postinstall.sh
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
|
|
3
|
-
set -eu
|
|
4
|
-
|
|
5
|
-
if test -f Makefile; then
|
|
6
|
-
echo 'Makefile already exists. Skipping initial setup'
|
|
7
|
-
else
|
|
8
|
-
echo 'No Makefile found. Generating one that includes mise-en-place Makefile.'
|
|
9
|
-
echo 'include ./node_modules/@meistrari/mise-en-place/Makefile' > Makefile
|
|
10
|
-
|
|
11
|
-
make mise-en-place
|
|
12
|
-
fi
|
|
13
|
-
|
|
14
|
-
WORKSPACE_PATTERNS=$(jq -r '.workspaces[]? // empty' package.json 2>/dev/null)
|
|
15
|
-
JQ_EXPRESSION='(.dependencies // {}, .devDependencies // {}) | keys[] | select(startswith("@meistrari/"))'
|
|
16
|
-
|
|
17
|
-
PACKAGE_JSONS="./package.json"
|
|
18
|
-
# If workspaces exist, find package.json files matching the patterns, otherwise just use root
|
|
19
|
-
if [ -n "$WORKSPACE_PATTERNS" ]; then
|
|
20
|
-
for pattern in $WORKSPACE_PATTERNS; do
|
|
21
|
-
# Use find with the workspace pattern (e.g., "packages/*" becomes "packages/*/package.json")
|
|
22
|
-
PACKAGE_JSONS="$PACKAGE_JSONS $(find $pattern -maxdepth 1 -name "package.json" 2>/dev/null)"
|
|
23
|
-
done
|
|
24
|
-
echo "Found workspace package.json files: $PACKAGE_JSONS"
|
|
25
|
-
MEISTRARI_LIBS_LIST=$(echo "$PACKAGE_JSONS" | xargs jq -r "$JQ_EXPRESSION" 2>/dev/null | sort -u)
|
|
26
|
-
else
|
|
27
|
-
# No workspaces, just check root package.json
|
|
28
|
-
MEISTRARI_LIBS_LIST=$(jq -r "$JQ_EXPRESSION" package.json 2>/dev/null | sort -u)
|
|
29
|
-
fi
|
|
30
|
-
|
|
31
|
-
# Ensure all @meistrari/* dependencies have caret (^) in all package.json files
|
|
32
|
-
for pkg_json in $PACKAGE_JSONS; do
|
|
33
|
-
PKG_JSON_DIR=$(dirname "$pkg_json")
|
|
34
|
-
cd "$PKG_JSON_DIR"
|
|
35
|
-
|
|
36
|
-
# Add caret (^) to each library that starts with @meistrari/ (if not already present)
|
|
37
|
-
# The line `"@meistrari/logger": "2.1.1"` becomes `"@meistrari/logger": "^2.1.1"`
|
|
38
|
-
# But `"@meistrari/logger": "^2.1.1"` stays as `"^2.1.1"` (no double caret)
|
|
39
|
-
ADD_CARET_JQ='with_entries(if .key | startswith("@meistrari/") then .value |= (if startswith("^") then . else "^" + . end) else . end)'
|
|
40
|
-
jq --indent 4 "if .dependencies then .dependencies |= $ADD_CARET_JQ else . end" package.json > package.json.tmp && mv package.json.tmp package.json
|
|
41
|
-
jq --indent 4 "if .devDependencies then .devDependencies |= $ADD_CARET_JQ else . end" package.json > package.json.tmp && mv package.json.tmp package.json
|
|
42
|
-
cd - > /dev/null
|
|
43
|
-
done
|
|
44
|
-
|
|
45
|
-
log_header () {
|
|
46
|
-
echo "File '$1' present. Updating @meistrari/* libraries..."
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if [ -n "$MEISTRARI_LIBS_LIST" ]; then
|
|
50
|
-
MEISTRARI_LIBS_COUNT=$(echo "$MEISTRARI_LIBS_LIST" | wc -l | tr -d ' ')
|
|
51
|
-
echo "Found $MEISTRARI_LIBS_COUNT @meistrari/* libraries to update:"
|
|
52
|
-
echo "$MEISTRARI_LIBS_LIST"
|
|
53
|
-
|
|
54
|
-
if test -f pnpm-lock.yaml; then
|
|
55
|
-
log_header "pnpm-lock.yaml"
|
|
56
|
-
pnpm update $MEISTRARI_LIBS_LIST --ignore-scripts -r
|
|
57
|
-
|
|
58
|
-
elif test -f bun.lock || test -f bun.lockb; then
|
|
59
|
-
log_header "bun.lock or bun.lockb"
|
|
60
|
-
|
|
61
|
-
for pkg_json in $PACKAGE_JSONS; do
|
|
62
|
-
PKG_JSON_DIR=$(dirname "$pkg_json")
|
|
63
|
-
cd "$PKG_JSON_DIR"
|
|
64
|
-
|
|
65
|
-
MEISTRARI_LIBS_LIST_LOCAL_DIR=$(jq -r "$JQ_EXPRESSION" package.json 2>/dev/null | sort -u)
|
|
66
|
-
|
|
67
|
-
# If no libraries, skip
|
|
68
|
-
if [ -z "$MEISTRARI_LIBS_LIST_LOCAL_DIR" ]; then
|
|
69
|
-
echo "No @meistrari/* libraries found in $PKG_JSON_DIR. Skipping."
|
|
70
|
-
cd - > /dev/null
|
|
71
|
-
continue
|
|
72
|
-
fi
|
|
73
|
-
|
|
74
|
-
echo "Updating $(echo $MEISTRARI_LIBS_LIST_LOCAL_DIR | tr '\n' ' ') libraries in $PKG_JSON_DIR"
|
|
75
|
-
|
|
76
|
-
bun update --silent $MEISTRARI_LIBS_LIST_LOCAL_DIR --ignore-scripts
|
|
77
|
-
cd - > /dev/null
|
|
78
|
-
done
|
|
79
|
-
|
|
80
|
-
elif test -f yarn.lock; then
|
|
81
|
-
log_header "yarn.lock"
|
|
82
|
-
yarn up $MEISTRARI_LIBS_LIST --ignore-scripts -r
|
|
83
|
-
|
|
84
|
-
elif test -f package-lock.json; then
|
|
85
|
-
log_header "package-lock.json"
|
|
86
|
-
npm update $MEISTRARI_LIBS_LIST --ignore-scripts
|
|
87
|
-
|
|
88
|
-
else
|
|
89
|
-
echo "No recognized lock file found (pnpm-lock.yaml, yarn.lock, package-lock.json)"
|
|
90
|
-
exit 1
|
|
91
|
-
fi
|
|
92
|
-
else
|
|
93
|
-
echo "No @meistrari/* libraries found in dependencies. Skipping update."
|
|
94
|
-
fi
|
|
File without changes
|
|
File without changes
|