@spica/cli 0.19.7 → 0.19.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/index.js +80 -54
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -3460,42 +3460,48 @@ var silentReporter = {
|
|
|
3460
3460
|
};
|
|
3461
3461
|
|
|
3462
3462
|
// packages/sync/dist/src/fs-utils.js
|
|
3463
|
-
import
|
|
3463
|
+
import fs10 from "fs";
|
|
3464
3464
|
import path9 from "path";
|
|
3465
3465
|
import yaml from "yaml";
|
|
3466
|
+
import cloneDeep from "lodash/cloneDeep.js";
|
|
3467
|
+
|
|
3468
|
+
// packages/sync/dist/src/source.js
|
|
3469
|
+
import fs9 from "node:fs";
|
|
3470
|
+
var diskSource = {
|
|
3471
|
+
listFolders(dir) {
|
|
3472
|
+
if (!fs9.existsSync(dir))
|
|
3473
|
+
return [];
|
|
3474
|
+
return fs9.readdirSync(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
3475
|
+
},
|
|
3476
|
+
readText(filePath) {
|
|
3477
|
+
if (!fs9.existsSync(filePath))
|
|
3478
|
+
return null;
|
|
3479
|
+
return fs9.readFileSync(filePath, "utf-8");
|
|
3480
|
+
}
|
|
3481
|
+
};
|
|
3482
|
+
|
|
3483
|
+
// packages/sync/dist/src/fs-utils.js
|
|
3466
3484
|
function ensureDir(dir) {
|
|
3467
|
-
|
|
3468
|
-
}
|
|
3469
|
-
function listFolders(dir) {
|
|
3470
|
-
if (!fs9.existsSync(dir))
|
|
3471
|
-
return [];
|
|
3472
|
-
return fs9.readdirSync(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
3485
|
+
fs10.mkdirSync(dir, { recursive: true });
|
|
3473
3486
|
}
|
|
3474
3487
|
function readYaml(filePath) {
|
|
3475
|
-
|
|
3476
|
-
return null;
|
|
3477
|
-
return yaml.parse(fs9.readFileSync(filePath, "utf-8"));
|
|
3488
|
+
return readSourceYaml(diskSource, filePath);
|
|
3478
3489
|
}
|
|
3479
3490
|
function writeYaml(filePath, data) {
|
|
3480
3491
|
ensureDir(path9.dirname(filePath));
|
|
3481
|
-
|
|
3482
|
-
}
|
|
3483
|
-
function readText(filePath) {
|
|
3484
|
-
if (!fs9.existsSync(filePath))
|
|
3485
|
-
return null;
|
|
3486
|
-
return fs9.readFileSync(filePath, "utf-8");
|
|
3492
|
+
fs10.writeFileSync(filePath, yaml.stringify(data), "utf-8");
|
|
3487
3493
|
}
|
|
3488
3494
|
function writeText(filePath, content) {
|
|
3489
3495
|
ensureDir(path9.dirname(filePath));
|
|
3490
|
-
|
|
3496
|
+
fs10.writeFileSync(filePath, content, "utf-8");
|
|
3491
3497
|
}
|
|
3492
3498
|
function removeDir(dir) {
|
|
3493
|
-
if (
|
|
3494
|
-
|
|
3499
|
+
if (fs10.existsSync(dir)) {
|
|
3500
|
+
fs10.rmSync(dir, { recursive: true, force: true });
|
|
3495
3501
|
}
|
|
3496
3502
|
}
|
|
3497
3503
|
function omit(obj, fields) {
|
|
3498
|
-
const clone =
|
|
3504
|
+
const clone = cloneDeep(obj);
|
|
3499
3505
|
for (const f of fields)
|
|
3500
3506
|
delete clone[f];
|
|
3501
3507
|
return clone;
|
|
@@ -3513,17 +3519,21 @@ function unwrapList(res) {
|
|
|
3513
3519
|
const got = typeof body === "string" ? `${body.slice(0, 80).replace(/\s+/g, " ")}\u2026` : typeof body;
|
|
3514
3520
|
throw new Error(`Expected a list response but got: ${got}. Check that your context URL points at the Spica API (e.g. ".../api"), not the panel.`);
|
|
3515
3521
|
}
|
|
3516
|
-
async function readLocalSchemas(rootDir, moduleName) {
|
|
3522
|
+
async function readLocalSchemas(rootDir, moduleName, source = diskSource) {
|
|
3517
3523
|
const dir = path9.join(rootDir, moduleName);
|
|
3518
|
-
const slugs = listFolders(dir);
|
|
3524
|
+
const slugs = source.listFolders(dir);
|
|
3519
3525
|
const results = [];
|
|
3520
3526
|
for (const slug of slugs) {
|
|
3521
|
-
const data =
|
|
3527
|
+
const data = readSourceYaml(source, path9.join(dir, slug, "schema.yaml"));
|
|
3522
3528
|
if (data)
|
|
3523
3529
|
results.push({ slug, data });
|
|
3524
3530
|
}
|
|
3525
3531
|
return results;
|
|
3526
3532
|
}
|
|
3533
|
+
function readSourceYaml(source, filePath) {
|
|
3534
|
+
const text = source.readText(filePath);
|
|
3535
|
+
return text === null ? null : yaml.parse(text);
|
|
3536
|
+
}
|
|
3527
3537
|
function writeLocalSchema(rootDir, moduleName, remote) {
|
|
3528
3538
|
const dir = path9.join(rootDir, moduleName, remote.slug);
|
|
3529
3539
|
writeYaml(path9.join(dir, "schema.yaml"), remote.data);
|
|
@@ -3538,11 +3548,11 @@ import isEqual2 from "lodash/isEqual.js";
|
|
|
3538
3548
|
import { createTwoFilesPatch } from "diff";
|
|
3539
3549
|
import yaml2 from "yaml";
|
|
3540
3550
|
async function buildPlan(modules, http2, rootDir, options = {}) {
|
|
3541
|
-
const { detailed = false, detectRenames = true, reporter = silentReporter, concurrency = DEFAULT_CONCURRENCY } = options;
|
|
3551
|
+
const { detailed = false, detectRenames = true, reporter = silentReporter, concurrency = DEFAULT_CONCURRENCY, source } = options;
|
|
3542
3552
|
const modulePlans = [];
|
|
3543
3553
|
for (const mod of modules) {
|
|
3544
3554
|
const [locals, remotes] = await Promise.all([
|
|
3545
|
-
reporter.task(`Reading local ${mod.displayName} files`, () => mod.readLocal(rootDir)),
|
|
3555
|
+
reporter.task(`Reading local ${mod.displayName} files`, () => mod.readLocal(rootDir, source)),
|
|
3546
3556
|
reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http2, { concurrency }))
|
|
3547
3557
|
]);
|
|
3548
3558
|
const localBySlug = new Map(locals.map((l) => [l.slug, l]));
|
|
@@ -3867,8 +3877,8 @@ var bucketModule = {
|
|
|
3867
3877
|
displayName: "Bucket",
|
|
3868
3878
|
identityField: "title",
|
|
3869
3879
|
ignoredFields: IGNORED_FIELDS,
|
|
3870
|
-
readLocal(rootDir) {
|
|
3871
|
-
return readLocalSchemas(rootDir, "bucket");
|
|
3880
|
+
readLocal(rootDir, source) {
|
|
3881
|
+
return readLocalSchemas(rootDir, "bucket", source);
|
|
3872
3882
|
},
|
|
3873
3883
|
async readRemote(http2) {
|
|
3874
3884
|
const res = await http2.get("bucket");
|
|
@@ -3916,8 +3926,8 @@ var envVarModule = {
|
|
|
3916
3926
|
displayName: "Environment Variable",
|
|
3917
3927
|
identityField: "key",
|
|
3918
3928
|
ignoredFields: IGNORED_FIELDS2,
|
|
3919
|
-
readLocal(rootDir) {
|
|
3920
|
-
return readLocalSchemas(rootDir, "env-var");
|
|
3929
|
+
readLocal(rootDir, source) {
|
|
3930
|
+
return readLocalSchemas(rootDir, "env-var", source);
|
|
3921
3931
|
},
|
|
3922
3932
|
async readRemote(http2) {
|
|
3923
3933
|
const res = await http2.get("env-var");
|
|
@@ -3961,6 +3971,7 @@ var envVarModule = {
|
|
|
3961
3971
|
import path10 from "path";
|
|
3962
3972
|
import yaml3 from "yaml";
|
|
3963
3973
|
import isEqual3 from "lodash/isEqual.js";
|
|
3974
|
+
import semver2 from "semver";
|
|
3964
3975
|
import { bold as bold5, cyan as cyan2, green as green5, yellow as yellow3 } from "colorette";
|
|
3965
3976
|
var SCHEMA_IGNORED = ["_id", "env_vars", "secrets"];
|
|
3966
3977
|
function indexFilename(language) {
|
|
@@ -3972,13 +3983,18 @@ function extractId(v) {
|
|
|
3972
3983
|
}
|
|
3973
3984
|
return String(v);
|
|
3974
3985
|
}
|
|
3986
|
+
function byCodeUnit(a, b) {
|
|
3987
|
+
if (a === b)
|
|
3988
|
+
return 0;
|
|
3989
|
+
return a < b ? -1 : 1;
|
|
3990
|
+
}
|
|
3975
3991
|
function normalizeSchema(schema) {
|
|
3976
3992
|
const normalized = { ...schema };
|
|
3977
3993
|
if (Array.isArray(schema.env_vars)) {
|
|
3978
|
-
normalized.env_vars = schema.env_vars.map(extractId);
|
|
3994
|
+
normalized.env_vars = schema.env_vars.map(extractId).sort(byCodeUnit);
|
|
3979
3995
|
}
|
|
3980
3996
|
if (Array.isArray(schema.secrets)) {
|
|
3981
|
-
normalized.secrets = schema.secrets.map(extractId);
|
|
3997
|
+
normalized.secrets = schema.secrets.map(extractId).sort(byCodeUnit);
|
|
3982
3998
|
}
|
|
3983
3999
|
return normalized;
|
|
3984
4000
|
}
|
|
@@ -3996,6 +4012,19 @@ function isNotFoundError(error) {
|
|
|
3996
4012
|
const c = error;
|
|
3997
4013
|
return c.status === 404 || c.statusCode === 404 || c.response?.status === 404 || c.response?.statusCode === 404;
|
|
3998
4014
|
}
|
|
4015
|
+
function dependencySatisfied(localSpec, remoteSpec) {
|
|
4016
|
+
if (remoteSpec === void 0)
|
|
4017
|
+
return false;
|
|
4018
|
+
if (localSpec === remoteSpec)
|
|
4019
|
+
return true;
|
|
4020
|
+
const installed = remoteSpec.startsWith("^") ? semver2.valid(remoteSpec.slice(1)) : null;
|
|
4021
|
+
const rewrittenByNpm = !!semver2.valid(localSpec) || localSpec.startsWith("^") && !!semver2.validRange(localSpec);
|
|
4022
|
+
return !!installed && rewrittenByNpm && semver2.satisfies(installed, localSpec);
|
|
4023
|
+
}
|
|
4024
|
+
function dependenciesMatch(local, remote) {
|
|
4025
|
+
const names = /* @__PURE__ */ new Set([...Object.keys(local), ...Object.keys(remote)]);
|
|
4026
|
+
return [...names].every((name) => name in local && dependencySatisfied(local[name], remote[name]));
|
|
4027
|
+
}
|
|
3999
4028
|
var emptyIfMissing = (empty) => (error) => {
|
|
4000
4029
|
if (isNotFoundError(error))
|
|
4001
4030
|
return empty;
|
|
@@ -4006,14 +4035,14 @@ var functionModule = {
|
|
|
4006
4035
|
displayName: "Function",
|
|
4007
4036
|
identityField: "name",
|
|
4008
4037
|
ignoredFields: SCHEMA_IGNORED,
|
|
4009
|
-
readSchema(rootDir, slug) {
|
|
4010
|
-
return
|
|
4038
|
+
readSchema(rootDir, slug, source = diskSource) {
|
|
4039
|
+
return readSourceYaml(source, path10.join(rootDir, "function", slug, "schema.yaml"));
|
|
4011
4040
|
},
|
|
4012
|
-
readIndex(rootDir, slug, language) {
|
|
4013
|
-
return readText(path10.join(rootDir, "function", slug, indexFilename(language))) ?? "";
|
|
4041
|
+
readIndex(rootDir, slug, language, source = diskSource) {
|
|
4042
|
+
return source.readText(path10.join(rootDir, "function", slug, indexFilename(language))) ?? "";
|
|
4014
4043
|
},
|
|
4015
|
-
readDependencies(rootDir, slug) {
|
|
4016
|
-
const pkgText = readText(path10.join(rootDir, "function", slug, "package.json"));
|
|
4044
|
+
readDependencies(rootDir, slug, source = diskSource) {
|
|
4045
|
+
const pkgText = source.readText(path10.join(rootDir, "function", slug, "package.json"));
|
|
4017
4046
|
if (!pkgText)
|
|
4018
4047
|
return {};
|
|
4019
4048
|
try {
|
|
@@ -4022,16 +4051,16 @@ var functionModule = {
|
|
|
4022
4051
|
return {};
|
|
4023
4052
|
}
|
|
4024
4053
|
},
|
|
4025
|
-
async readLocal(rootDir) {
|
|
4054
|
+
async readLocal(rootDir, source = diskSource) {
|
|
4026
4055
|
const dir = path10.join(rootDir, "function");
|
|
4027
|
-
const slugs = listFolders(dir);
|
|
4056
|
+
const slugs = source.listFolders(dir);
|
|
4028
4057
|
const results = [];
|
|
4029
4058
|
for (const slug of slugs) {
|
|
4030
|
-
const schema = this.readSchema(rootDir, slug);
|
|
4059
|
+
const schema = this.readSchema(rootDir, slug, source);
|
|
4031
4060
|
if (!schema)
|
|
4032
4061
|
continue;
|
|
4033
|
-
const index = this.readIndex(rootDir, slug, schema.language);
|
|
4034
|
-
const dependencies = this.readDependencies(rootDir, slug);
|
|
4062
|
+
const index = this.readIndex(rootDir, slug, schema.language, source);
|
|
4063
|
+
const dependencies = this.readDependencies(rootDir, slug, source);
|
|
4035
4064
|
results.push({ slug, data: { schema, index, dependencies } });
|
|
4036
4065
|
}
|
|
4037
4066
|
return results;
|
|
@@ -4113,10 +4142,7 @@ var functionModule = {
|
|
|
4113
4142
|
return;
|
|
4114
4143
|
throw error;
|
|
4115
4144
|
})));
|
|
4116
|
-
const toAdd = Object.entries(localDeps).filter(([n, v]) => {
|
|
4117
|
-
const cur = currentByName.get(n);
|
|
4118
|
-
return !cur || cur !== v;
|
|
4119
|
-
}).map(([n, v]) => `${n}@${v}`);
|
|
4145
|
+
const toAdd = Object.entries(localDeps).filter(([n, v]) => !dependencySatisfied(v, currentByName.get(n))).map(([n, v]) => `${n}@${v}`);
|
|
4120
4146
|
if (toAdd.length) {
|
|
4121
4147
|
await http2.post(`function/${remoteId}/dependencies`, { name: toAdd });
|
|
4122
4148
|
}
|
|
@@ -4147,7 +4173,7 @@ var functionModule = {
|
|
|
4147
4173
|
changed.push("schema");
|
|
4148
4174
|
if (local.index !== remote.index)
|
|
4149
4175
|
changed.push("index");
|
|
4150
|
-
if (!
|
|
4176
|
+
if (!dependenciesMatch(local.dependencies, remote.dependencies))
|
|
4151
4177
|
changed.push("dependencies");
|
|
4152
4178
|
const localEnvVars = local.schema.env_vars ?? [];
|
|
4153
4179
|
const remoteEnvVars = remote.schema.env_vars ?? [];
|
|
@@ -4170,9 +4196,9 @@ var functionModule = {
|
|
|
4170
4196
|
result["index"] = buildUnifiedDiff(remote.data.index, local.data.index, indexFilename(local.data.schema.language));
|
|
4171
4197
|
}
|
|
4172
4198
|
const sortKeys = (obj) => Object.fromEntries(Object.entries(obj).sort(([a], [b]) => a.localeCompare(b)));
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4199
|
+
if (!dependenciesMatch(local.data.dependencies, remote.data.dependencies)) {
|
|
4200
|
+
const localDepsYaml = yaml3.stringify(sortKeys(local.data.dependencies));
|
|
4201
|
+
const remoteDepsYaml = yaml3.stringify(sortKeys(remote.data.dependencies));
|
|
4176
4202
|
result["dependencies"] = buildUnifiedDiff(remoteDepsYaml, localDepsYaml, "package.json");
|
|
4177
4203
|
}
|
|
4178
4204
|
return result;
|
|
@@ -4272,8 +4298,8 @@ var policyModule = {
|
|
|
4272
4298
|
displayName: "Policy",
|
|
4273
4299
|
identityField: "name",
|
|
4274
4300
|
ignoredFields: IGNORED_FIELDS3,
|
|
4275
|
-
readLocal(rootDir) {
|
|
4276
|
-
return readLocalSchemas(rootDir, "policy");
|
|
4301
|
+
readLocal(rootDir, source) {
|
|
4302
|
+
return readLocalSchemas(rootDir, "policy", source);
|
|
4277
4303
|
},
|
|
4278
4304
|
async readRemote(http2) {
|
|
4279
4305
|
const res = await http2.get("passport/policy");
|
|
@@ -4323,8 +4349,8 @@ var secretModule = {
|
|
|
4323
4349
|
displayName: "Secret",
|
|
4324
4350
|
identityField: "key",
|
|
4325
4351
|
ignoredFields: IGNORED_FIELDS4,
|
|
4326
|
-
readLocal(rootDir) {
|
|
4327
|
-
return readLocalSchemas(rootDir, "secret");
|
|
4352
|
+
readLocal(rootDir, source) {
|
|
4353
|
+
return readLocalSchemas(rootDir, "secret", source);
|
|
4328
4354
|
},
|
|
4329
4355
|
async readRemote(http2) {
|
|
4330
4356
|
const res = await http2.get("secret");
|