@supersdk/supercli 0.3.3-staging.45 → 0.3.3-staging.48
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/build/artifactIntegrity.js +158 -2
- package/dist/build/artifactIntegrity.js.map +1 -1
- package/dist/build/projectBuild.js +335 -0
- package/dist/build/projectBuild.js.map +1 -0
- package/dist/cli.js +0 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/add.js +35 -29
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/build.js +407 -105
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/init.js +22 -29
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/register.js +62 -217
- package/dist/commands/register.js.map +1 -1
- package/dist/config/appConfig.js +36 -163
- package/dist/config/appConfig.js.map +1 -1
- package/dist/config/superConfig.js +213 -185
- package/dist/config/superConfig.js.map +1 -1
- package/dist/deploy/manifest.js +189 -167
- package/dist/deploy/manifest.js.map +1 -1
- package/dist/deploy/preflight.js +15 -16
- package/dist/deploy/preflight.js.map +1 -1
- package/dist/deploy/runAdapter.js +7 -4
- package/dist/deploy/runAdapter.js.map +1 -1
- package/dist/docker/dockerCli.js +72 -77
- package/dist/docker/dockerCli.js.map +1 -1
- package/dist/template/README.md +26 -94
- package/dist/template/android/gradle/supersdk-config-reader.gradle +13 -62
- package/dist/template/android/scripts/build.sh +11 -0
- package/dist/template/ios/project.yml +1 -1
- package/dist/template/ios/scripts/build.sh +19 -0
- package/dist/template/ios/scripts/render_project.py +60 -0
- package/dist/template/ios/supersdk-default.config.json +6 -0
- package/dist/template/service/scripts/build.sh +11 -0
- package/dist/template/super.json +22 -14
- package/dist/template/template_manifest.json +3 -7
- package/dist/template/web/package.json +8 -0
- package/dist/template/web/scripts/build.sh +8 -0
- package/dist/template/web/scripts/web_package.py +490 -0
- package/dist/template/web/src/js/app.js +2 -2
- package/dist/util/shell.js +3 -3
- package/dist/workspace/config.js +3 -79
- package/dist/workspace/config.js.map +1 -1
- package/dist/workspace/identity.js +6 -15
- package/dist/workspace/identity.js.map +1 -1
- package/dist/workspace/projectIdentity.js +2 -7
- package/dist/workspace/projectIdentity.js.map +1 -1
- package/dist/workspace/template.js +205 -77
- package/dist/workspace/template.js.map +1 -1
- package/package.json +4 -1
- package/dist/commands/config.js +0 -170
- package/dist/commands/config.js.map +0 -1
- package/dist/template/scripts/android_snapshot_canary.py +0 -145
- package/dist/template/scripts/build_android.sh +0 -382
- package/dist/template/scripts/build_ios.sh +0 -331
- package/dist/template/scripts/build_service.sh +0 -89
- package/dist/template/scripts/build_site.sh +0 -57
- package/dist/template/scripts/lib/workspace.sh +0 -43
- package/dist/template/scripts/serve_web.py +0 -78
- package/dist/template/scripts/super_build_orchestrator.py +0 -344
- package/dist/template/scripts/supersdk_template.py +0 -1394
- package/dist/template/scripts/web_host_validator.py +0 -103
- package/dist/template/scripts/web_package.py +0 -296
- package/dist/template/scripts/ws03_shared_schema_merge_guard.py +0 -73
- package/dist/template/super_build.sh +0 -70
- package/dist/workspace/inspect.js +0 -275
- package/dist/workspace/inspect.js.map +0 -1
|
@@ -40,7 +40,7 @@ exports.canonicalConfigDigest = canonicalConfigDigest;
|
|
|
40
40
|
exports.parseSuperConfig = parseSuperConfig;
|
|
41
41
|
exports.findSuperConfig = findSuperConfig;
|
|
42
42
|
exports.configProblem = configProblem;
|
|
43
|
-
/** Strict schema-
|
|
43
|
+
/** Strict schema-v5 parser and workspace discovery. */
|
|
44
44
|
const crypto = __importStar(require("node:crypto"));
|
|
45
45
|
const fs = __importStar(require("node:fs"));
|
|
46
46
|
const node_net_1 = require("node:net");
|
|
@@ -49,36 +49,71 @@ const appConfig_1 = require("./appConfig");
|
|
|
49
49
|
exports.CONFIG_FILENAME = appConfig_1.APP_CONFIG_FILENAME;
|
|
50
50
|
exports.CONFIG_SCHEMA_VERSION = appConfig_1.APP_CONFIG_SCHEMA_VERSION;
|
|
51
51
|
const MAX_SEARCH_DEPTH = 64;
|
|
52
|
-
const rootKeys = new Set(['schemaVersion', 'spid', 'orgId', 'name', 'version', '
|
|
53
|
-
const commonProjectKeys = new Set(['projectId', 'type', 'dir', 'name', '
|
|
52
|
+
const rootKeys = new Set(['schemaVersion', 'spid', 'orgId', 'name', 'version', 'projects']);
|
|
53
|
+
const commonProjectKeys = new Set(['projectId', 'type', 'dir', 'name', 'build', 'version']);
|
|
54
54
|
const typeProjectKeys = {
|
|
55
|
-
android: new Set(['package']),
|
|
56
|
-
|
|
55
|
+
android: new Set(['package']),
|
|
56
|
+
ios: new Set(['bundleId', 'spmMode']),
|
|
57
|
+
site: new Set(['deploy', 'offline']),
|
|
58
|
+
service: new Set(['deploy']),
|
|
57
59
|
};
|
|
58
60
|
const versionKeys = new Set(['name', 'code']);
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const serviceBuildKeys = new Set(['context', 'dockerfile', 'platform', 'argsFromEnv']);
|
|
61
|
+
const buildKeys = new Set(['entry', 'args', 'artifacts']);
|
|
62
|
+
const artifactKeys = new Set(['id', 'kind', 'path']);
|
|
62
63
|
const deployCommonKeys = new Set(['envTarget', 'slug', 'name', 'env']);
|
|
63
|
-
const serviceDeployKeys = new Set([
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return
|
|
64
|
+
const serviceDeployKeys = new Set([
|
|
65
|
+
...deployCommonKeys,
|
|
66
|
+
'port',
|
|
67
|
+
'cpuMilli',
|
|
68
|
+
'memoryMiB',
|
|
69
|
+
'maxScale',
|
|
70
|
+
'databaseConnection',
|
|
71
|
+
'runtimeEnvFromEnv',
|
|
72
|
+
'secretsFromEnv',
|
|
73
|
+
]);
|
|
74
|
+
function plain(value) {
|
|
75
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
76
|
+
}
|
|
77
|
+
function fail(filePath, reason) {
|
|
78
|
+
return { kind: 'invalid', path: filePath, reason };
|
|
79
|
+
}
|
|
80
|
+
function exactKeys(object, allowed, label) {
|
|
81
|
+
const unknown = Object.keys(object).filter((key) => !allowed.has(key));
|
|
82
|
+
return unknown.length ? `${label} contains unknown field(s): ${unknown.join(', ')}` : undefined;
|
|
83
|
+
}
|
|
84
|
+
function nonEmptyString(value) {
|
|
85
|
+
return typeof value === 'string' && value.trim() !== '';
|
|
86
|
+
}
|
|
87
|
+
function integer(value) {
|
|
88
|
+
return typeof value === 'number' && Number.isInteger(value);
|
|
89
|
+
}
|
|
90
|
+
function envName(value) {
|
|
91
|
+
return typeof value === 'string' && /^[A-Za-z_][A-Za-z0-9_]*$/.test(value);
|
|
92
|
+
}
|
|
93
|
+
function validProjectId(value) {
|
|
94
|
+
return typeof value === 'string' && /^[a-z][a-z0-9-]{0,63}$/.test(value);
|
|
95
|
+
}
|
|
96
|
+
function validEnvTarget(value) {
|
|
97
|
+
return typeof value === 'string' && /^[a-z][a-z0-9-]{0,31}$/.test(value);
|
|
98
|
+
}
|
|
99
|
+
function normalizeProjectDir(raw) {
|
|
100
|
+
if (raw.trim() !== raw || raw.length === 0 || raw.includes('\0') || raw.startsWith('/') || raw.includes('\\') || /^[A-Za-z]:/.test(raw))
|
|
101
|
+
return undefined;
|
|
102
|
+
const parts = raw.split('/');
|
|
103
|
+
if (parts.some((part) => part === '' || part === '.' || part === '..'))
|
|
104
|
+
return undefined;
|
|
105
|
+
return parts.join('/');
|
|
106
|
+
}
|
|
107
|
+
function normalizedRelative(raw) {
|
|
108
|
+
if (!nonEmptyString(raw) || raw.trim() !== raw || raw.includes('\0') || raw.includes('\\') || raw.startsWith('/') || /^[A-Za-z]:/.test(raw))
|
|
109
|
+
return undefined;
|
|
110
|
+
const parts = raw.split('/');
|
|
111
|
+
return parts.length > 0 && !parts.some((part) => part === '' || part === '.' || part === '..') ? parts.join('/') : undefined;
|
|
112
|
+
}
|
|
78
113
|
function isAncestor(a, b) { return a !== b && b.startsWith(`${a}/`); }
|
|
79
114
|
function validateVersion(value, label, complete) {
|
|
80
115
|
if (value === undefined)
|
|
81
|
-
return
|
|
116
|
+
return undefined;
|
|
82
117
|
if (!plain(value))
|
|
83
118
|
return `${label} must be a JSON object`;
|
|
84
119
|
const unknown = exactKeys(value, versionKeys, label);
|
|
@@ -86,73 +121,27 @@ function validateVersion(value, label, complete) {
|
|
|
86
121
|
return unknown;
|
|
87
122
|
if (complete && (!Object.hasOwn(value, 'name') || !Object.hasOwn(value, 'code')))
|
|
88
123
|
return `${label} must contain name and code`;
|
|
89
|
-
if (value.name !== undefined && !
|
|
124
|
+
if (value.name !== undefined && !nonEmptyString(value.name))
|
|
90
125
|
return `${label}.name must be a non-empty string`;
|
|
91
126
|
if (value.code !== undefined && (!integer(value.code) || value.code < 1 || value.code > 2147483647))
|
|
92
127
|
return `${label}.code must be a positive 32-bit integer`;
|
|
93
128
|
return undefined;
|
|
94
129
|
}
|
|
95
|
-
function
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return false;
|
|
104
|
-
let parsed;
|
|
105
|
-
try {
|
|
106
|
-
parsed = new URL(value);
|
|
107
|
-
}
|
|
108
|
-
catch {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
if (parsed.protocol !== 'https:' || !parsed.hostname)
|
|
112
|
-
return false;
|
|
113
|
-
const host = parsed.hostname.toLowerCase().replace(/^\[|\]$/g, '');
|
|
114
|
-
if (host === 'localhost' || host === 'example.com' || host === 'example.org'
|
|
115
|
-
|| host.endsWith('.localhost') || host.endsWith('.local') || host.endsWith('.example.com')
|
|
116
|
-
|| host.endsWith('.example.org') || host.includes('example.invalid'))
|
|
117
|
-
return false;
|
|
118
|
-
if ((0, node_net_1.isIP)(host) === 4) {
|
|
119
|
-
const octets = host.split('.').map(Number);
|
|
120
|
-
if (octets[0] === 10 || octets[0] === 127 || octets[0] === 0
|
|
121
|
-
|| (octets[0] === 169 && octets[1] === 254) || (octets[0] === 172 && octets[1] >= 16 && octets[1] <= 31)
|
|
122
|
-
|| (octets[0] === 192 && octets[1] === 168))
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
if ((0, node_net_1.isIP)(host) === 6 && (host === '::' || host === '::1' || /^f[cd]/.test(host) || /^fe[89ab]/.test(host)))
|
|
126
|
-
return false;
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
function validateProjectSdk(type, mode, sdk, label) {
|
|
130
|
-
if (type === 'android') {
|
|
131
|
-
if (typeof sdk.androidVersion !== 'string' || !/^[0-9]+\.[0-9]+\.[0-9]+(?:[-.][A-Za-z0-9]+)*$/.test(sdk.androidVersion.trim()))
|
|
132
|
-
return `${label}.sdk.androidVersion must be a valid Android SDK version`;
|
|
133
|
-
}
|
|
134
|
-
if (type === 'ios') {
|
|
135
|
-
const spmMode = mode ?? 'mock';
|
|
136
|
-
if (spmMode === 'mock' && (Object.hasOwn(sdk, 'iosPackageUrl') || Object.hasOwn(sdk, 'iosVersion')))
|
|
137
|
-
return `${label}.sdk iosPackageUrl/iosVersion are not allowed when spmMode is mock`;
|
|
138
|
-
if (spmMode === 'real') {
|
|
139
|
-
if (!validIosPackageUrl(sdk.iosPackageUrl))
|
|
140
|
-
return `${label}.sdk.iosPackageUrl must be a non-local HTTPS URL when spmMode is real`;
|
|
141
|
-
if (typeof sdk.iosVersion !== 'string' || !/^[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?$/.test(sdk.iosVersion))
|
|
142
|
-
return `${label}.sdk.iosVersion must be a semantic version when spmMode is real`;
|
|
130
|
+
function validateRefs(value, label) {
|
|
131
|
+
if (!Array.isArray(value))
|
|
132
|
+
return `${label} must be an array`;
|
|
133
|
+
const seen = new Set();
|
|
134
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
135
|
+
const item = value[i];
|
|
136
|
+
if (!plain(item) || Object.keys(item).some((key) => key !== 'name' && key !== 'sourceEnv') || !envName(item.name) || !envName(item.sourceEnv)) {
|
|
137
|
+
return `${label}[${i}] must contain valid name/sourceEnv`;
|
|
143
138
|
}
|
|
139
|
+
if (seen.has(item.name))
|
|
140
|
+
return `${label}[${i}].name duplicates a platform environment variable name`;
|
|
141
|
+
seen.add(item.name);
|
|
144
142
|
}
|
|
145
143
|
return undefined;
|
|
146
144
|
}
|
|
147
|
-
function validateRefs(value, label) { if (!Array.isArray(value))
|
|
148
|
-
return `${label} must be an array`; const seen = new Set(); for (let i = 0; i < value.length; i += 1) {
|
|
149
|
-
const item = value[i];
|
|
150
|
-
if (!plain(item) || Object.keys(item).some((key) => key !== 'name' && key !== 'sourceEnv') || !envName(item.name) || !envName(item.sourceEnv))
|
|
151
|
-
return `${label}[${i}] must contain valid name/sourceEnv`;
|
|
152
|
-
if (seen.has(item.name))
|
|
153
|
-
return `${label}[${i}].name duplicates a platform environment variable name`;
|
|
154
|
-
seen.add(item.name);
|
|
155
|
-
} return undefined; }
|
|
156
145
|
function validateDeploy(value, type, label) {
|
|
157
146
|
if (value === undefined)
|
|
158
147
|
return [];
|
|
@@ -168,20 +157,20 @@ function validateDeploy(value, type, label) {
|
|
|
168
157
|
const unknown = exactKeys(item, type === 'service' ? serviceDeployKeys : deployCommonKeys, where);
|
|
169
158
|
if (unknown)
|
|
170
159
|
return unknown;
|
|
171
|
-
if (!validEnvTarget(item.envTarget) || typeof item.slug !== 'string' || !/^[a-z0-9]{1,32}$/.test(item.slug) || item.slug === 'stg' || item.slug === 'site' || typeof item.env !== 'string' || !/^[a-z0-9]{1,10}$/.test(item.env))
|
|
160
|
+
if (!validEnvTarget(item.envTarget) || typeof item.slug !== 'string' || !/^[a-z0-9]{1,32}$/.test(item.slug) || item.slug === 'stg' || item.slug === 'site' || typeof item.env !== 'string' || !/^[a-z0-9]{1,10}$/.test(item.env)) {
|
|
172
161
|
return `${where} requires valid envTarget, slug and env`;
|
|
162
|
+
}
|
|
173
163
|
if (targets.has(item.envTarget))
|
|
174
164
|
return `${where}.envTarget must be unique within the project`;
|
|
175
165
|
targets.add(item.envTarget);
|
|
176
|
-
if (item.name !== undefined && (!
|
|
166
|
+
if (item.name !== undefined && (!nonEmptyString(item.name) || item.name !== item.name.trim() || item.name.length > 50))
|
|
177
167
|
return `${where}.name must be 1..50 characters without surrounding whitespace`;
|
|
178
|
-
if (type !== 'service' && Object.keys(item).some((key) => !deployCommonKeys.has(key)))
|
|
179
|
-
return `${where} has service-only fields`;
|
|
180
168
|
if (type === 'service') {
|
|
181
|
-
for (const [key, max] of [['port', 65535], ['cpuMilli', 4000], ['memoryMiB', 8192], ['maxScale', 10]])
|
|
169
|
+
for (const [key, max] of [['port', 65535], ['cpuMilli', 4000], ['memoryMiB', 8192], ['maxScale', 10]]) {
|
|
182
170
|
if (item[key] !== undefined && (!integer(item[key]) || item[key] < 1 || item[key] > max))
|
|
183
171
|
return `${where}.${key} must be an integer from 1 to ${max}`;
|
|
184
|
-
|
|
172
|
+
}
|
|
173
|
+
if (item.databaseConnection !== undefined && item.databaseConnection !== null && !nonEmptyString(item.databaseConnection))
|
|
185
174
|
return `${where}.databaseConnection must be a string or null`;
|
|
186
175
|
const runtime = item.runtimeEnvFromEnv === undefined ? undefined : validateRefs(item.runtimeEnvFromEnv, `${where}.runtimeEnvFromEnv`);
|
|
187
176
|
if (runtime)
|
|
@@ -229,24 +218,79 @@ function validOfflineHost(value) {
|
|
|
229
218
|
return labels.length >= 2 && !/^\d+$/.test(labels[labels.length - 1])
|
|
230
219
|
&& labels.every((part) => part.length <= 63 && /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(part));
|
|
231
220
|
}
|
|
232
|
-
function
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
221
|
+
function containsBuildVariable(value) { return value.includes('${'); }
|
|
222
|
+
function validateBuildArg(value, label) {
|
|
223
|
+
if (value.includes('\0'))
|
|
224
|
+
return `${label} must not contain NUL`;
|
|
225
|
+
let cursor = 0;
|
|
226
|
+
while (cursor < value.length) {
|
|
227
|
+
const start = value.indexOf('${', cursor);
|
|
228
|
+
if (start < 0)
|
|
229
|
+
return undefined;
|
|
230
|
+
if (!value.startsWith('${spid}', start))
|
|
231
|
+
return `${label} only supports the exact \${spid} placeholder`;
|
|
232
|
+
cursor = start + '${spid}'.length;
|
|
233
|
+
}
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
function validateBuild(value, type, label) {
|
|
237
|
+
if (!plain(value))
|
|
238
|
+
return `${label} is required and must be a JSON object`;
|
|
239
|
+
const keys = Object.keys(value);
|
|
240
|
+
if (keys.length === 0)
|
|
241
|
+
return {};
|
|
242
|
+
const unknown = exactKeys(value, buildKeys, label);
|
|
243
|
+
if (unknown)
|
|
244
|
+
return unknown;
|
|
245
|
+
if (keys.length !== buildKeys.size || !Object.hasOwn(value, 'entry') || !Object.hasOwn(value, 'args') || !Object.hasOwn(value, 'artifacts')) {
|
|
246
|
+
return `${label} must be {} or contain exactly entry, args and artifacts`;
|
|
247
|
+
}
|
|
248
|
+
const entry = normalizedRelative(value.entry);
|
|
249
|
+
if (entry === undefined || (typeof value.entry === 'string' && containsBuildVariable(value.entry)))
|
|
250
|
+
return `${label}.entry must be a project-relative POSIX path without variables`;
|
|
251
|
+
if (!Array.isArray(value.args) || value.args.some((arg) => typeof arg !== 'string'))
|
|
252
|
+
return `${label}.args must be an array of strings`;
|
|
253
|
+
for (let i = 0; i < value.args.length; i += 1) {
|
|
254
|
+
const problem = validateBuildArg(value.args[i], `${label}.args[${i}]`);
|
|
255
|
+
if (problem)
|
|
256
|
+
return problem;
|
|
257
|
+
}
|
|
258
|
+
if (!Array.isArray(value.artifacts) || value.artifacts.length === 0)
|
|
259
|
+
return `${label}.artifacts must be a non-empty array`;
|
|
260
|
+
const artifacts = [];
|
|
261
|
+
const ids = new Set();
|
|
262
|
+
for (let i = 0; i < value.artifacts.length; i += 1) {
|
|
263
|
+
const artifact = value.artifacts[i];
|
|
264
|
+
const where = `${label}.artifacts[${i}]`;
|
|
265
|
+
if (!plain(artifact))
|
|
266
|
+
return `${where} must be an object`;
|
|
267
|
+
const extra = exactKeys(artifact, artifactKeys, where);
|
|
268
|
+
if (extra)
|
|
269
|
+
return extra;
|
|
270
|
+
if (Object.keys(artifact).length !== artifactKeys.size)
|
|
271
|
+
return `${where} must contain exactly id, kind and path`;
|
|
272
|
+
if (typeof artifact.id !== 'string' || !/^[a-z][a-z0-9._-]{0,63}$/.test(artifact.id))
|
|
273
|
+
return `${where}.id must match ^[a-z][a-z0-9._-]{0,63}$`;
|
|
274
|
+
if (ids.has(artifact.id))
|
|
275
|
+
return `${where}.id duplicates artifact id ${artifact.id}`;
|
|
276
|
+
ids.add(artifact.id);
|
|
277
|
+
if (artifact.kind !== 'file' && artifact.kind !== 'directory' && artifact.kind !== 'docker-image-archive')
|
|
278
|
+
return `${where}.kind must be file, directory or docker-image-archive`;
|
|
279
|
+
const artifactPath = normalizedRelative(artifact.path);
|
|
280
|
+
if (artifactPath === undefined || (typeof artifact.path === 'string' && containsBuildVariable(artifact.path)))
|
|
281
|
+
return `${where}.path must be a project-relative POSIX path without variables`;
|
|
282
|
+
artifacts.push({ id: artifact.id, kind: artifact.kind, path: artifactPath });
|
|
283
|
+
}
|
|
284
|
+
if (type === 'site' && !artifacts.some((artifact) => artifact.id === 'site-dist' && artifact.kind === 'directory'))
|
|
285
|
+
return `${label} for a site must declare site-dist as a directory`;
|
|
286
|
+
if (type === 'service' && !artifacts.some((artifact) => artifact.id === 'service-image' && artifact.kind === 'docker-image-archive'))
|
|
287
|
+
return `${label} for a service must declare service-image as a docker-image-archive`;
|
|
288
|
+
return { entry, args: [...value.args], artifacts };
|
|
289
|
+
}
|
|
248
290
|
function canonicalConfigJson(document) { return (0, appConfig_1.serializeAppConfig)(document); }
|
|
249
|
-
function canonicalConfigDigest(document) {
|
|
291
|
+
function canonicalConfigDigest(document) {
|
|
292
|
+
return crypto.createHash('sha256').update(canonicalConfigJson(document), 'utf8').digest('hex');
|
|
293
|
+
}
|
|
250
294
|
function parseSuperConfig(raw, filePath) {
|
|
251
295
|
const duplicate = (0, appConfig_1.findDuplicateKey)(raw);
|
|
252
296
|
if (duplicate)
|
|
@@ -263,20 +307,17 @@ function parseSuperConfig(raw, filePath) {
|
|
|
263
307
|
const rootUnknown = exactKeys(document, rootKeys, 'root');
|
|
264
308
|
if (rootUnknown)
|
|
265
309
|
return fail(filePath, rootUnknown);
|
|
266
|
-
if (document.schemaVersion !==
|
|
267
|
-
return fail(filePath, 'schemaVersion
|
|
310
|
+
if (document.schemaVersion !== appConfig_1.APP_CONFIG_SCHEMA_VERSION)
|
|
311
|
+
return fail(filePath, 'only schemaVersion 5 is supported; update super.json manually');
|
|
268
312
|
if (typeof document.spid !== 'string' || !/^[a-z0-9]{8}$/.test(document.spid))
|
|
269
313
|
return fail(filePath, 'spid must be 8 lowercase letters or digits');
|
|
270
314
|
if (document.orgId !== undefined && (typeof document.orgId !== 'string' || !/^[1-9][0-9]*$/.test(document.orgId)))
|
|
271
315
|
return fail(filePath, 'orgId must be a positive decimal string');
|
|
272
|
-
if (document.name !== undefined && (!
|
|
316
|
+
if (document.name !== undefined && (!nonEmptyString(document.name) || document.name !== document.name.trim() || document.name.length > 100))
|
|
273
317
|
return fail(filePath, 'name must be 1..100 characters without surrounding whitespace');
|
|
274
318
|
const rootVersion = validateVersion(document.version, 'version', false);
|
|
275
319
|
if (rootVersion)
|
|
276
320
|
return fail(filePath, rootVersion);
|
|
277
|
-
const rootSdk = validateSdk(document.sdk, 'sdk');
|
|
278
|
-
if (rootSdk)
|
|
279
|
-
return fail(filePath, rootSdk);
|
|
280
321
|
if (!Array.isArray(document.projects))
|
|
281
322
|
return fail(filePath, 'projects must be an array');
|
|
282
323
|
const projects = [];
|
|
@@ -291,8 +332,7 @@ function parseSuperConfig(raw, filePath) {
|
|
|
291
332
|
const type = item.type;
|
|
292
333
|
if (type !== 'android' && type !== 'ios' && type !== 'site' && type !== 'service')
|
|
293
334
|
return fail(filePath, `${label}.type must be android, ios, site or service`);
|
|
294
|
-
const
|
|
295
|
-
const unknown = exactKeys(item, allowed, label);
|
|
335
|
+
const unknown = exactKeys(item, new Set([...commonProjectKeys, ...typeProjectKeys[type]]), label);
|
|
296
336
|
if (unknown)
|
|
297
337
|
return fail(filePath, unknown);
|
|
298
338
|
if (!validProjectId(item.projectId))
|
|
@@ -300,7 +340,7 @@ function parseSuperConfig(raw, filePath) {
|
|
|
300
340
|
if (ids.has(item.projectId))
|
|
301
341
|
return fail(filePath, `duplicate projectId ${item.projectId}`);
|
|
302
342
|
ids.add(item.projectId);
|
|
303
|
-
if (typeof item.dir !== 'string' ||
|
|
343
|
+
if (typeof item.dir !== 'string' || normalizeProjectDir(item.dir) === undefined)
|
|
304
344
|
return fail(filePath, `${label}.dir must be a workspace-relative POSIX path`);
|
|
305
345
|
const dir = normalizeProjectDir(item.dir);
|
|
306
346
|
if (dirs.some((existing) => existing === dir || isAncestor(existing, dir) || isAncestor(dir, existing)))
|
|
@@ -309,26 +349,29 @@ function parseSuperConfig(raw, filePath) {
|
|
|
309
349
|
const version = validateVersion(item.version, `${label}.version`, item.version !== undefined);
|
|
310
350
|
if (version)
|
|
311
351
|
return fail(filePath, version);
|
|
312
|
-
|
|
313
|
-
if (sdk)
|
|
314
|
-
return fail(filePath, sdk);
|
|
315
|
-
if (item.name !== undefined && (!string(item.name) || item.name !== item.name.trim() || item.name.length > (type === 'site' || type === 'service' ? 50 : 100)))
|
|
352
|
+
if (item.name !== undefined && (!nonEmptyString(item.name) || item.name !== item.name.trim() || item.name.length > (type === 'site' || type === 'service' ? 50 : 100)))
|
|
316
353
|
return fail(filePath, `${label}.name must be 1..${type === 'site' || type === 'service' ? 50 : 100} characters without surrounding whitespace`);
|
|
317
|
-
if ((type === 'android' || type === 'ios') && (!
|
|
354
|
+
if ((type === 'android' || type === 'ios') && (!nonEmptyString(item.name) || item.name !== item.name.trim() || /[\x00-\x1f]/.test(item.name)))
|
|
318
355
|
return fail(filePath, `${label}.name is required for ${type}`);
|
|
319
|
-
if (type === 'android' && (!
|
|
356
|
+
if (type === 'android' && (!nonEmptyString(item.package) || !/^[A-Za-z][A-Za-z0-9_]*(\.[A-Za-z][A-Za-z0-9_]*)+$/.test(item.package) || item.package === 'com.supersdk.simple'))
|
|
320
357
|
return fail(filePath, `${label}.package is required for android`);
|
|
321
|
-
if (type === 'ios' && (!
|
|
358
|
+
if (type === 'ios' && (!nonEmptyString(item.bundleId) || !/^[A-Za-z0-9][A-Za-z0-9-]*(\.[A-Za-z0-9][A-Za-z0-9-]*)+$/.test(item.bundleId)))
|
|
322
359
|
return fail(filePath, `${label}.bundleId is required for ios`);
|
|
323
360
|
if (type === 'ios' && item.spmMode !== undefined && item.spmMode !== 'mock' && item.spmMode !== 'real')
|
|
324
361
|
return fail(filePath, `${label}.spmMode must be mock or real`);
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
362
|
+
const build = validateBuild(item.build, type, `${label}.build`);
|
|
363
|
+
if (typeof build === 'string')
|
|
364
|
+
return fail(filePath, build);
|
|
365
|
+
if (type === 'site') {
|
|
366
|
+
const offline = item.offline === undefined ? {} : item.offline;
|
|
367
|
+
if (!plain(offline))
|
|
368
|
+
return fail(filePath, `${label}.offline must be a JSON object`);
|
|
369
|
+
const unknownOffline = exactKeys(offline, new Set(['host']), `${label}.offline`);
|
|
370
|
+
if (unknownOffline)
|
|
371
|
+
return fail(filePath, unknownOffline);
|
|
372
|
+
if (offline.host !== undefined && !validOfflineHost(offline.host))
|
|
373
|
+
return fail(filePath, `${label}.offline.host must be a deployable domain or HTTP(S) URL`);
|
|
374
|
+
}
|
|
332
375
|
const deploy = validateDeploy(item.deploy, type, `${label}.deploy`);
|
|
333
376
|
if (typeof deploy === 'string')
|
|
334
377
|
return fail(filePath, deploy);
|
|
@@ -338,92 +381,77 @@ function parseSuperConfig(raw, filePath) {
|
|
|
338
381
|
return fail(filePath, `duplicate deploy target ${key}`);
|
|
339
382
|
targets.add(key);
|
|
340
383
|
}
|
|
341
|
-
projects.push({ ...item, projectId: item.projectId, type, dir, ...(item.deploy !== undefined ? { deploy } : {}) });
|
|
384
|
+
projects.push({ ...item, projectId: item.projectId, type, dir, build, ...(item.deploy !== undefined ? { deploy } : {}) });
|
|
342
385
|
}
|
|
343
386
|
const resolved = path.resolve(filePath);
|
|
344
|
-
return {
|
|
387
|
+
return {
|
|
388
|
+
kind: 'valid',
|
|
389
|
+
config: {
|
|
390
|
+
path: resolved,
|
|
391
|
+
root: path.dirname(resolved),
|
|
392
|
+
document,
|
|
393
|
+
schemaVersion: appConfig_1.APP_CONFIG_SCHEMA_VERSION,
|
|
394
|
+
spid: document.spid,
|
|
395
|
+
...(typeof document.orgId === 'string' ? { orgId: document.orgId } : {}),
|
|
396
|
+
...(typeof document.name === 'string' ? { name: document.name } : {}),
|
|
397
|
+
projects,
|
|
398
|
+
digest: canonicalConfigDigest(document),
|
|
399
|
+
},
|
|
400
|
+
};
|
|
345
401
|
}
|
|
346
|
-
function read(pathname) {
|
|
347
|
-
|
|
402
|
+
function read(pathname) {
|
|
403
|
+
try {
|
|
404
|
+
return parseSuperConfig(fs.readFileSync(pathname, 'utf8'), pathname);
|
|
405
|
+
}
|
|
406
|
+
catch (error) {
|
|
407
|
+
return fail(pathname, `cannot read config: ${error.message}`);
|
|
408
|
+
}
|
|
348
409
|
}
|
|
349
|
-
|
|
350
|
-
return
|
|
351
|
-
} }
|
|
352
|
-
function boundary(current) { return fs.existsSync(path.join(current, '.git')) || current === path.parse(current).root || current === path.resolve(process.env.HOME ?? '~'); }
|
|
353
|
-
function legacyAt(root) { return appConfig_1.LEGACY_APP_CONFIG_FILENAMES.map((name) => path.join(root, name)).filter((candidate) => fs.existsSync(candidate)); }
|
|
354
|
-
function scan(startDir) { let current = path.resolve(startDir); const dirs = []; const candidates = []; const legacy = []; for (let level = 0; level < MAX_SEARCH_DEPTH; level += 1) {
|
|
355
|
-
dirs.push(current);
|
|
356
|
-
const candidate = path.join(current, exports.CONFIG_FILENAME);
|
|
357
|
-
if (fs.existsSync(candidate))
|
|
358
|
-
candidates.push(candidate);
|
|
359
|
-
legacy.push(...legacyAt(current));
|
|
360
|
-
if (boundary(current))
|
|
361
|
-
break;
|
|
362
|
-
const parent = path.dirname(current);
|
|
363
|
-
if (parent === current)
|
|
364
|
-
break;
|
|
365
|
-
current = parent;
|
|
366
|
-
} return { dirs, candidates, legacy }; }
|
|
367
|
-
function isWithin(root, candidate) {
|
|
368
|
-
const relative = path.relative(path.resolve(root), path.resolve(candidate));
|
|
369
|
-
return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative));
|
|
410
|
+
function boundary(current) {
|
|
411
|
+
return fs.existsSync(path.join(current, '.git')) || current === path.parse(current).root || current === path.resolve(process.env.HOME ?? '~');
|
|
370
412
|
}
|
|
371
|
-
|
|
372
|
-
function scanToRoot(startDir, root) {
|
|
373
|
-
const selectedRoot = path.resolve(root);
|
|
413
|
+
function scan(startDir) {
|
|
374
414
|
let current = path.resolve(startDir);
|
|
375
|
-
if (!isWithin(selectedRoot, current))
|
|
376
|
-
return { dirs: [], candidates: [], legacy: [] };
|
|
377
415
|
const dirs = [];
|
|
378
416
|
const candidates = [];
|
|
379
|
-
const legacy = [];
|
|
380
417
|
for (let level = 0; level < MAX_SEARCH_DEPTH; level += 1) {
|
|
381
418
|
dirs.push(current);
|
|
382
419
|
const candidate = path.join(current, exports.CONFIG_FILENAME);
|
|
383
420
|
if (fs.existsSync(candidate))
|
|
384
421
|
candidates.push(candidate);
|
|
385
|
-
|
|
386
|
-
if (current === selectedRoot)
|
|
422
|
+
if (boundary(current))
|
|
387
423
|
break;
|
|
388
424
|
const parent = path.dirname(current);
|
|
389
|
-
if (parent === current
|
|
425
|
+
if (parent === current)
|
|
390
426
|
break;
|
|
391
427
|
current = parent;
|
|
392
428
|
}
|
|
393
|
-
return { dirs, candidates
|
|
429
|
+
return { dirs, candidates };
|
|
394
430
|
}
|
|
395
431
|
function findSuperConfig(startDir, explicitPath) {
|
|
396
432
|
if (explicitPath !== undefined) {
|
|
397
433
|
const selected = path.resolve(explicitPath);
|
|
398
434
|
if (!fs.existsSync(selected))
|
|
399
435
|
return { kind: 'absent', searched: [selected], explicit: true };
|
|
400
|
-
// The selected file defines the workspace root. An unrelated cwd is only
|
|
401
|
-
// a process-launch detail and must never contribute config/legacy state.
|
|
402
|
-
// When cwd is inside the selected workspace, scan cwd -> selected root so
|
|
403
|
-
// nested authorities still fail closed. A same-directory alternate and
|
|
404
|
-
// super.json may coexist because --config chose the alternate explicitly.
|
|
405
|
-
const selectedRoot = path.dirname(selected);
|
|
406
|
-
const selectedChain = scanToRoot(startDir, selectedRoot);
|
|
407
|
-
const conflicts = [...new Set(selectedChain.candidates)]
|
|
408
|
-
.filter((candidate) => candidate !== selected && path.dirname(candidate) !== selectedRoot);
|
|
409
|
-
if (conflicts.length)
|
|
410
|
-
return { kind: 'ambiguous', paths: [selected, ...conflicts] };
|
|
411
|
-
const rootLegacy = legacyAt(selectedRoot);
|
|
412
|
-
const legacy = [...new Set([...rootLegacy, ...selectedChain.legacy])];
|
|
413
|
-
if (legacy.length)
|
|
414
|
-
return fail(selected, `${legacy[0]} coexists on the discovery chain; migrate/remove the retired configuration`);
|
|
415
436
|
return read(selected);
|
|
416
437
|
}
|
|
417
438
|
const scanned = scan(startDir);
|
|
418
|
-
if (scanned.legacy.length)
|
|
419
|
-
return fail(scanned.legacy[0], `retired configuration found; migrate with \`supercli config migrate --from ${scanned.legacy[0]} --to ${path.join(path.dirname(scanned.legacy[0]), exports.CONFIG_FILENAME)}\``);
|
|
420
439
|
if (scanned.candidates.length !== 1)
|
|
421
|
-
return scanned.candidates.length
|
|
440
|
+
return scanned.candidates.length
|
|
441
|
+
? { kind: 'ambiguous', paths: scanned.candidates }
|
|
442
|
+
: { kind: 'absent', searched: scanned.dirs, explicit: false };
|
|
422
443
|
return read(scanned.candidates[0]);
|
|
423
444
|
}
|
|
424
445
|
exports.resolveSuperConfig = findSuperConfig;
|
|
425
|
-
function configProblem(result) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
446
|
+
function configProblem(result) {
|
|
447
|
+
if (result.kind === 'valid')
|
|
448
|
+
return undefined;
|
|
449
|
+
if (result.kind === 'absent')
|
|
450
|
+
return result.explicit
|
|
451
|
+
? `explicit config not found: ${result.searched[0]}`
|
|
452
|
+
: `no ${exports.CONFIG_FILENAME} found; run interactive \`supercli init\` to create one`;
|
|
453
|
+
if (result.kind === 'ambiguous')
|
|
454
|
+
return `CONFIG_AMBIGUOUS: multiple ${exports.CONFIG_FILENAME} candidates found: ${result.paths.join(', ')}`;
|
|
455
|
+
return `CONFIG_INVALID: ${result.path}: ${result.reason}`;
|
|
456
|
+
}
|
|
429
457
|
//# sourceMappingURL=superConfig.js.map
|