@tegami/dart 0.0.0-tegami-trusted-publish-setup → 1.1.1
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/dist/index.d.ts +72 -0
- package/dist/index.js +630 -0
- package/package.json +46 -3
- package/README.md +0 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fuma Nama
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Document } from "yaml";
|
|
2
|
+
import { BumpType, TegamiPlugin, WorkspacePackage } from "tegami";
|
|
3
|
+
|
|
4
|
+
//#region src/schema.d.ts
|
|
5
|
+
type DartDependency = string | {
|
|
6
|
+
version?: string;
|
|
7
|
+
hosted?: string | {
|
|
8
|
+
name?: string;
|
|
9
|
+
url: string;
|
|
10
|
+
};
|
|
11
|
+
path?: string;
|
|
12
|
+
git?: unknown;
|
|
13
|
+
sdk?: string;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
interface Pubspec {
|
|
17
|
+
name?: string;
|
|
18
|
+
version?: string;
|
|
19
|
+
publish_to?: string;
|
|
20
|
+
resolution?: string;
|
|
21
|
+
workspace?: string[];
|
|
22
|
+
dependencies?: Record<string, DartDependency>;
|
|
23
|
+
dev_dependencies?: Record<string, DartDependency>;
|
|
24
|
+
dependency_overrides?: Record<string, DartDependency>;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/index.d.ts
|
|
28
|
+
declare const DEP_FIELDS: readonly ["dependencies", "dev_dependencies", "dependency_overrides"];
|
|
29
|
+
interface PubspecFile {
|
|
30
|
+
path: string;
|
|
31
|
+
doc: Document;
|
|
32
|
+
data: Pubspec;
|
|
33
|
+
}
|
|
34
|
+
declare class DartPackage extends WorkspacePackage {
|
|
35
|
+
readonly path: string;
|
|
36
|
+
readonly file: PubspecFile;
|
|
37
|
+
readonly manager = "dart";
|
|
38
|
+
constructor(path: string, file: PubspecFile);
|
|
39
|
+
get name(): string;
|
|
40
|
+
get version(): string | undefined;
|
|
41
|
+
get publishTo(): string | undefined;
|
|
42
|
+
setVersion(version: string): void;
|
|
43
|
+
write(): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
interface DependentRef {
|
|
46
|
+
dependent: DartPackage;
|
|
47
|
+
kind: (typeof DEP_FIELDS)[number];
|
|
48
|
+
name: string;
|
|
49
|
+
spec: DartDependency;
|
|
50
|
+
table: Record<string, DartDependency>;
|
|
51
|
+
linked: DartPackage;
|
|
52
|
+
}
|
|
53
|
+
interface DartPluginOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Update the pub workspace resolution after versioning.
|
|
56
|
+
*
|
|
57
|
+
* @default true
|
|
58
|
+
*/
|
|
59
|
+
updateLockFile?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Decide how to bump the dependents of a bumped package.
|
|
62
|
+
*/
|
|
63
|
+
bumpDep?: (opts: DependentRef) => BumpType | false;
|
|
64
|
+
}
|
|
65
|
+
declare function dart({
|
|
66
|
+
updateLockFile,
|
|
67
|
+
bumpDep: getBumpDepType
|
|
68
|
+
}?: DartPluginOptions): TegamiPlugin;
|
|
69
|
+
declare function updateConstraintRange(range: string, version: string): string;
|
|
70
|
+
declare function isPackagePublished(name: string, version: string, hostedUrl: string): Promise<boolean>;
|
|
71
|
+
//#endregion
|
|
72
|
+
export { DartPackage, DartPluginOptions, dart, isPackagePublished, updateConstraintRange };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import * as semver from "semver";
|
|
4
|
+
import { glob } from "tinyglobby";
|
|
5
|
+
import { x } from "tinyexec";
|
|
6
|
+
import { parseDocument } from "yaml";
|
|
7
|
+
import { WorkspacePackage } from "tegami";
|
|
8
|
+
import { execFailure, isCI, joinPath } from "tegami/utils";
|
|
9
|
+
//#region ../../node_modules/.pnpm/typia@12.1.1_@types+node@26.0.1_typescript@6.0.3/node_modules/typia/lib/TypeGuardError.mjs
|
|
10
|
+
/**
|
|
11
|
+
* Error thrown when type assertion fails.
|
|
12
|
+
*
|
|
13
|
+
* Thrown by {@link assert}, {@link assertGuard}, and other assert-family
|
|
14
|
+
* functions when input doesn't match expected type `T`. Contains detailed
|
|
15
|
+
* information about the first assertion failure:
|
|
16
|
+
*
|
|
17
|
+
* - `method`: Which typia function threw (e.g., `"typia.assert"`)
|
|
18
|
+
* - `path`: Property path where error occurred (e.g., `"input.user.age"`)
|
|
19
|
+
* - `expected`: Expected type string (e.g., `"number & ExclusiveMinimum<19>"`)
|
|
20
|
+
* - `value`: Actual value that failed validation
|
|
21
|
+
*
|
|
22
|
+
* @template T Expected type (for type safety)
|
|
23
|
+
*/
|
|
24
|
+
var TypeGuardError = class extends Error {
|
|
25
|
+
/**
|
|
26
|
+
* Name of the typia method that threw this error.
|
|
27
|
+
*
|
|
28
|
+
* E.g., `"typia.assert"`, `"typia.assertEquals"`, `"typia.assertGuard"`.
|
|
29
|
+
*/
|
|
30
|
+
method;
|
|
31
|
+
/**
|
|
32
|
+
* Property path where assertion failed.
|
|
33
|
+
*
|
|
34
|
+
* Uses dot notation for nested properties. `undefined` if error occurred at
|
|
35
|
+
* root level.
|
|
36
|
+
*
|
|
37
|
+
* E.g., `"input.age"`, `"input.profile.email"`, `"input[0].name"`.
|
|
38
|
+
*/
|
|
39
|
+
path;
|
|
40
|
+
/**
|
|
41
|
+
* String representation of expected type.
|
|
42
|
+
*
|
|
43
|
+
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`, `"{ name: string; age:
|
|
44
|
+
* number }"`.
|
|
45
|
+
*/
|
|
46
|
+
expected;
|
|
47
|
+
/**
|
|
48
|
+
* Actual value that failed assertion.
|
|
49
|
+
*
|
|
50
|
+
* The raw value at the error path, useful for debugging.
|
|
51
|
+
*/
|
|
52
|
+
value;
|
|
53
|
+
/**
|
|
54
|
+
* Optional human-readable error description.
|
|
55
|
+
*
|
|
56
|
+
* Primarily for AI agent libraries or custom validation scenarios needing
|
|
57
|
+
* additional context. Standard assertions rely on `path`, `expected`, and
|
|
58
|
+
* `value` for error reporting.
|
|
59
|
+
*/
|
|
60
|
+
description;
|
|
61
|
+
/**
|
|
62
|
+
* Phantom property for TypeScript type safety.
|
|
63
|
+
*
|
|
64
|
+
* Not used at runtime—exists only to preserve generic type `T` in the type
|
|
65
|
+
* system. Always `undefined`.
|
|
66
|
+
*
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
fake_expected_typed_value_;
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new TypeGuardError instance.
|
|
72
|
+
*
|
|
73
|
+
* @param props Error properties
|
|
74
|
+
*/
|
|
75
|
+
constructor(props) {
|
|
76
|
+
super(props.message || `Error on ${props.method}(): invalid type${props.path ? ` on ${props.path}` : ""}, expect to be ${props.expected}`);
|
|
77
|
+
const proto = new.target.prototype;
|
|
78
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
79
|
+
else this.__proto__ = proto;
|
|
80
|
+
this.method = props.method;
|
|
81
|
+
this.path = props.path;
|
|
82
|
+
this.expected = props.expected;
|
|
83
|
+
this.value = props.value;
|
|
84
|
+
if (props.description || props.value === void 0) this.description = props.description ?? [
|
|
85
|
+
"The value at this path is `undefined`.",
|
|
86
|
+
"",
|
|
87
|
+
`Please fill the \`${props.expected}\` typed value next time.`
|
|
88
|
+
].join("\n");
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region ../../node_modules/.pnpm/typia@12.1.1_@types+node@26.0.1_typescript@6.0.3/node_modules/typia/lib/internal/_assertGuard.mjs
|
|
93
|
+
const _assertGuard = (exceptionable, props, factory) => {
|
|
94
|
+
if (exceptionable === true) if (factory) throw factory(props);
|
|
95
|
+
else throw new TypeGuardError(props);
|
|
96
|
+
return false;
|
|
97
|
+
};
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region ../../node_modules/.pnpm/typia@12.1.1_@types+node@26.0.1_typescript@6.0.3/node_modules/typia/lib/internal/_accessExpressionAsString.mjs
|
|
100
|
+
const _accessExpressionAsString = (str) => variable(str) ? `.${str}` : `[${JSON.stringify(str)}]`;
|
|
101
|
+
const variable = (str) => reserved(str) === false && /^[a-zA-Z_$][a-zA-Z_$0-9]*$/g.test(str);
|
|
102
|
+
const reserved = (str) => RESERVED.has(str);
|
|
103
|
+
const RESERVED = /* @__PURE__ */ new Set([
|
|
104
|
+
"break",
|
|
105
|
+
"case",
|
|
106
|
+
"catch",
|
|
107
|
+
"class",
|
|
108
|
+
"const",
|
|
109
|
+
"continue",
|
|
110
|
+
"debugger",
|
|
111
|
+
"default",
|
|
112
|
+
"delete",
|
|
113
|
+
"do",
|
|
114
|
+
"else",
|
|
115
|
+
"enum",
|
|
116
|
+
"export",
|
|
117
|
+
"extends",
|
|
118
|
+
"false",
|
|
119
|
+
"finally",
|
|
120
|
+
"for",
|
|
121
|
+
"function",
|
|
122
|
+
"if",
|
|
123
|
+
"import",
|
|
124
|
+
"in",
|
|
125
|
+
"instanceof",
|
|
126
|
+
"new",
|
|
127
|
+
"null",
|
|
128
|
+
"return",
|
|
129
|
+
"super",
|
|
130
|
+
"switch",
|
|
131
|
+
"this",
|
|
132
|
+
"throw",
|
|
133
|
+
"true",
|
|
134
|
+
"try",
|
|
135
|
+
"typeof",
|
|
136
|
+
"var",
|
|
137
|
+
"void",
|
|
138
|
+
"while",
|
|
139
|
+
"with"
|
|
140
|
+
]);
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/schema.ts
|
|
143
|
+
const assertPubspec = (() => {
|
|
144
|
+
const _io0 = (input) => (void 0 === input.name || "string" === typeof input.name) && (void 0 === input.version || "string" === typeof input.version) && (void 0 === input.publish_to || "string" === typeof input.publish_to) && (void 0 === input.resolution || "string" === typeof input.resolution) && (void 0 === input.workspace || Array.isArray(input.workspace) && input.workspace.every((elem) => "string" === typeof elem)) && (void 0 === input.dependencies || "object" === typeof input.dependencies && null !== input.dependencies && false === Array.isArray(input.dependencies) && _io1(input.dependencies)) && (void 0 === input.dev_dependencies || "object" === typeof input.dev_dependencies && null !== input.dev_dependencies && false === Array.isArray(input.dev_dependencies) && _io1(input.dev_dependencies)) && (void 0 === input.dependency_overrides || "object" === typeof input.dependency_overrides && null !== input.dependency_overrides && false === Array.isArray(input.dependency_overrides) && _io1(input.dependency_overrides));
|
|
145
|
+
const _io1 = (input) => Object.keys(input).every((key) => {
|
|
146
|
+
const value = input[key];
|
|
147
|
+
if (void 0 === value) return true;
|
|
148
|
+
return null !== value && void 0 !== value && ("string" === typeof value || "object" === typeof value && null !== value && false === Array.isArray(value) && _io2(value));
|
|
149
|
+
});
|
|
150
|
+
const _io2 = (input) => (void 0 === input.version || "string" === typeof input.version) && null !== input.hosted && (void 0 === input.hosted || "string" === typeof input.hosted || "object" === typeof input.hosted && null !== input.hosted && _io3(input.hosted)) && (void 0 === input.path || "string" === typeof input.path) && (void 0 === input.sdk || "string" === typeof input.sdk) && Object.keys(input).every((key) => {
|
|
151
|
+
if ([
|
|
152
|
+
"version",
|
|
153
|
+
"hosted",
|
|
154
|
+
"path",
|
|
155
|
+
"git",
|
|
156
|
+
"sdk"
|
|
157
|
+
].some((prop) => key === prop)) return true;
|
|
158
|
+
if (void 0 === input[key]) return true;
|
|
159
|
+
return true;
|
|
160
|
+
});
|
|
161
|
+
const _io3 = (input) => (void 0 === input.name || "string" === typeof input.name) && "string" === typeof input.url;
|
|
162
|
+
const _ao0 = (input, _path, _exceptionable = true) => (void 0 === input.name || "string" === typeof input.name || _assertGuard(_exceptionable, {
|
|
163
|
+
method: "typia.createAssert",
|
|
164
|
+
path: _path + ".name",
|
|
165
|
+
expected: "(string | undefined)",
|
|
166
|
+
value: input.name
|
|
167
|
+
}, _errorFactory)) && (void 0 === input.version || "string" === typeof input.version || _assertGuard(_exceptionable, {
|
|
168
|
+
method: "typia.createAssert",
|
|
169
|
+
path: _path + ".version",
|
|
170
|
+
expected: "(string | undefined)",
|
|
171
|
+
value: input.version
|
|
172
|
+
}, _errorFactory)) && (void 0 === input.publish_to || "string" === typeof input.publish_to || _assertGuard(_exceptionable, {
|
|
173
|
+
method: "typia.createAssert",
|
|
174
|
+
path: _path + ".publish_to",
|
|
175
|
+
expected: "(string | undefined)",
|
|
176
|
+
value: input.publish_to
|
|
177
|
+
}, _errorFactory)) && (void 0 === input.resolution || "string" === typeof input.resolution || _assertGuard(_exceptionable, {
|
|
178
|
+
method: "typia.createAssert",
|
|
179
|
+
path: _path + ".resolution",
|
|
180
|
+
expected: "(string | undefined)",
|
|
181
|
+
value: input.resolution
|
|
182
|
+
}, _errorFactory)) && (void 0 === input.workspace || (Array.isArray(input.workspace) || _assertGuard(_exceptionable, {
|
|
183
|
+
method: "typia.createAssert",
|
|
184
|
+
path: _path + ".workspace",
|
|
185
|
+
expected: "(Array<string> | undefined)",
|
|
186
|
+
value: input.workspace
|
|
187
|
+
}, _errorFactory)) && input.workspace.every((elem, _index2) => "string" === typeof elem || _assertGuard(_exceptionable, {
|
|
188
|
+
method: "typia.createAssert",
|
|
189
|
+
path: _path + ".workspace[" + _index2 + "]",
|
|
190
|
+
expected: "string",
|
|
191
|
+
value: elem
|
|
192
|
+
}, _errorFactory)) || _assertGuard(_exceptionable, {
|
|
193
|
+
method: "typia.createAssert",
|
|
194
|
+
path: _path + ".workspace",
|
|
195
|
+
expected: "(Array<string> | undefined)",
|
|
196
|
+
value: input.workspace
|
|
197
|
+
}, _errorFactory)) && (void 0 === input.dependencies || ("object" === typeof input.dependencies && null !== input.dependencies && false === Array.isArray(input.dependencies) || _assertGuard(_exceptionable, {
|
|
198
|
+
method: "typia.createAssert",
|
|
199
|
+
path: _path + ".dependencies",
|
|
200
|
+
expected: "(Record<string, DartDependency> | undefined)",
|
|
201
|
+
value: input.dependencies
|
|
202
|
+
}, _errorFactory)) && _ao1(input.dependencies, _path + ".dependencies", _exceptionable) || _assertGuard(_exceptionable, {
|
|
203
|
+
method: "typia.createAssert",
|
|
204
|
+
path: _path + ".dependencies",
|
|
205
|
+
expected: "(Record<string, DartDependency> | undefined)",
|
|
206
|
+
value: input.dependencies
|
|
207
|
+
}, _errorFactory)) && (void 0 === input.dev_dependencies || ("object" === typeof input.dev_dependencies && null !== input.dev_dependencies && false === Array.isArray(input.dev_dependencies) || _assertGuard(_exceptionable, {
|
|
208
|
+
method: "typia.createAssert",
|
|
209
|
+
path: _path + ".dev_dependencies",
|
|
210
|
+
expected: "(Record<string, DartDependency> | undefined)",
|
|
211
|
+
value: input.dev_dependencies
|
|
212
|
+
}, _errorFactory)) && _ao1(input.dev_dependencies, _path + ".dev_dependencies", _exceptionable) || _assertGuard(_exceptionable, {
|
|
213
|
+
method: "typia.createAssert",
|
|
214
|
+
path: _path + ".dev_dependencies",
|
|
215
|
+
expected: "(Record<string, DartDependency> | undefined)",
|
|
216
|
+
value: input.dev_dependencies
|
|
217
|
+
}, _errorFactory)) && (void 0 === input.dependency_overrides || ("object" === typeof input.dependency_overrides && null !== input.dependency_overrides && false === Array.isArray(input.dependency_overrides) || _assertGuard(_exceptionable, {
|
|
218
|
+
method: "typia.createAssert",
|
|
219
|
+
path: _path + ".dependency_overrides",
|
|
220
|
+
expected: "(Record<string, DartDependency> | undefined)",
|
|
221
|
+
value: input.dependency_overrides
|
|
222
|
+
}, _errorFactory)) && _ao1(input.dependency_overrides, _path + ".dependency_overrides", _exceptionable) || _assertGuard(_exceptionable, {
|
|
223
|
+
method: "typia.createAssert",
|
|
224
|
+
path: _path + ".dependency_overrides",
|
|
225
|
+
expected: "(Record<string, DartDependency> | undefined)",
|
|
226
|
+
value: input.dependency_overrides
|
|
227
|
+
}, _errorFactory));
|
|
228
|
+
const _ao1 = (input, _path, _exceptionable = true) => false === _exceptionable || Object.keys(input).every((key) => {
|
|
229
|
+
const value = input[key];
|
|
230
|
+
if (void 0 === value) return true;
|
|
231
|
+
return (null !== value || _assertGuard(_exceptionable, {
|
|
232
|
+
method: "typia.createAssert",
|
|
233
|
+
path: _path + _accessExpressionAsString(key),
|
|
234
|
+
expected: "(__type | string)",
|
|
235
|
+
value
|
|
236
|
+
}, _errorFactory)) && (void 0 !== value || _assertGuard(_exceptionable, {
|
|
237
|
+
method: "typia.createAssert",
|
|
238
|
+
path: _path + _accessExpressionAsString(key),
|
|
239
|
+
expected: "(__type | string)",
|
|
240
|
+
value
|
|
241
|
+
}, _errorFactory)) && ("string" === typeof value || ("object" === typeof value && null !== value && false === Array.isArray(value) || _assertGuard(_exceptionable, {
|
|
242
|
+
method: "typia.createAssert",
|
|
243
|
+
path: _path + _accessExpressionAsString(key),
|
|
244
|
+
expected: "(__type | string)",
|
|
245
|
+
value
|
|
246
|
+
}, _errorFactory)) && _ao2(value, _path + _accessExpressionAsString(key), _exceptionable) || _assertGuard(_exceptionable, {
|
|
247
|
+
method: "typia.createAssert",
|
|
248
|
+
path: _path + _accessExpressionAsString(key),
|
|
249
|
+
expected: "(__type | string)",
|
|
250
|
+
value
|
|
251
|
+
}, _errorFactory));
|
|
252
|
+
});
|
|
253
|
+
const _ao2 = (input, _path, _exceptionable = true) => (void 0 === input.version || "string" === typeof input.version || _assertGuard(_exceptionable, {
|
|
254
|
+
method: "typia.createAssert",
|
|
255
|
+
path: _path + ".version",
|
|
256
|
+
expected: "(string | undefined)",
|
|
257
|
+
value: input.version
|
|
258
|
+
}, _errorFactory)) && (null !== input.hosted || _assertGuard(_exceptionable, {
|
|
259
|
+
method: "typia.createAssert",
|
|
260
|
+
path: _path + ".hosted",
|
|
261
|
+
expected: "(__type.o1 | string | undefined)",
|
|
262
|
+
value: input.hosted
|
|
263
|
+
}, _errorFactory)) && (void 0 === input.hosted || "string" === typeof input.hosted || ("object" === typeof input.hosted && null !== input.hosted || _assertGuard(_exceptionable, {
|
|
264
|
+
method: "typia.createAssert",
|
|
265
|
+
path: _path + ".hosted",
|
|
266
|
+
expected: "(__type.o1 | string | undefined)",
|
|
267
|
+
value: input.hosted
|
|
268
|
+
}, _errorFactory)) && _ao3(input.hosted, _path + ".hosted", _exceptionable) || _assertGuard(_exceptionable, {
|
|
269
|
+
method: "typia.createAssert",
|
|
270
|
+
path: _path + ".hosted",
|
|
271
|
+
expected: "(__type.o1 | string | undefined)",
|
|
272
|
+
value: input.hosted
|
|
273
|
+
}, _errorFactory)) && (void 0 === input.path || "string" === typeof input.path || _assertGuard(_exceptionable, {
|
|
274
|
+
method: "typia.createAssert",
|
|
275
|
+
path: _path + ".path",
|
|
276
|
+
expected: "(string | undefined)",
|
|
277
|
+
value: input.path
|
|
278
|
+
}, _errorFactory)) && (void 0 === input.sdk || "string" === typeof input.sdk || _assertGuard(_exceptionable, {
|
|
279
|
+
method: "typia.createAssert",
|
|
280
|
+
path: _path + ".sdk",
|
|
281
|
+
expected: "(string | undefined)",
|
|
282
|
+
value: input.sdk
|
|
283
|
+
}, _errorFactory)) && (false === _exceptionable || Object.keys(input).every((key) => {
|
|
284
|
+
if ([
|
|
285
|
+
"version",
|
|
286
|
+
"hosted",
|
|
287
|
+
"path",
|
|
288
|
+
"git",
|
|
289
|
+
"sdk"
|
|
290
|
+
].some((prop) => key === prop)) return true;
|
|
291
|
+
if (void 0 === input[key]) return true;
|
|
292
|
+
return true;
|
|
293
|
+
}));
|
|
294
|
+
const _ao3 = (input, _path, _exceptionable = true) => (void 0 === input.name || "string" === typeof input.name || _assertGuard(_exceptionable, {
|
|
295
|
+
method: "typia.createAssert",
|
|
296
|
+
path: _path + ".name",
|
|
297
|
+
expected: "(string | undefined)",
|
|
298
|
+
value: input.name
|
|
299
|
+
}, _errorFactory)) && ("string" === typeof input.url || _assertGuard(_exceptionable, {
|
|
300
|
+
method: "typia.createAssert",
|
|
301
|
+
path: _path + ".url",
|
|
302
|
+
expected: "string",
|
|
303
|
+
value: input.url
|
|
304
|
+
}, _errorFactory));
|
|
305
|
+
const __is = (input) => "object" === typeof input && null !== input && false === Array.isArray(input) && _io0(input);
|
|
306
|
+
let _errorFactory;
|
|
307
|
+
return (input, errorFactory) => {
|
|
308
|
+
if (false === __is(input)) {
|
|
309
|
+
_errorFactory = errorFactory;
|
|
310
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input && false === Array.isArray(input) || _assertGuard(true, {
|
|
311
|
+
method: "typia.createAssert",
|
|
312
|
+
path: _path + "",
|
|
313
|
+
expected: "Pubspec",
|
|
314
|
+
value: input
|
|
315
|
+
}, _errorFactory)) && _ao0(input, _path + "", true) || _assertGuard(true, {
|
|
316
|
+
method: "typia.createAssert",
|
|
317
|
+
path: _path + "",
|
|
318
|
+
expected: "Pubspec",
|
|
319
|
+
value: input
|
|
320
|
+
}, _errorFactory))(input, "$input", true);
|
|
321
|
+
}
|
|
322
|
+
return input;
|
|
323
|
+
};
|
|
324
|
+
})();
|
|
325
|
+
const assertHostedPackage = (() => {
|
|
326
|
+
const _io0 = (input) => void 0 === input.versions || Array.isArray(input.versions) && input.versions.every((elem) => "object" === typeof elem && null !== elem && _io1(elem));
|
|
327
|
+
const _io1 = (input) => "string" === typeof input.version;
|
|
328
|
+
const _ao0 = (input, _path, _exceptionable = true) => void 0 === input.versions || (Array.isArray(input.versions) || _assertGuard(_exceptionable, {
|
|
329
|
+
method: "typia.createAssert",
|
|
330
|
+
path: _path + ".versions",
|
|
331
|
+
expected: "(Array<__type> | undefined)",
|
|
332
|
+
value: input.versions
|
|
333
|
+
}, _errorFactory)) && input.versions.every((elem, _index2) => ("object" === typeof elem && null !== elem || _assertGuard(_exceptionable, {
|
|
334
|
+
method: "typia.createAssert",
|
|
335
|
+
path: _path + ".versions[" + _index2 + "]",
|
|
336
|
+
expected: "__type",
|
|
337
|
+
value: elem
|
|
338
|
+
}, _errorFactory)) && _ao1(elem, _path + ".versions[" + _index2 + "]", _exceptionable) || _assertGuard(_exceptionable, {
|
|
339
|
+
method: "typia.createAssert",
|
|
340
|
+
path: _path + ".versions[" + _index2 + "]",
|
|
341
|
+
expected: "__type",
|
|
342
|
+
value: elem
|
|
343
|
+
}, _errorFactory)) || _assertGuard(_exceptionable, {
|
|
344
|
+
method: "typia.createAssert",
|
|
345
|
+
path: _path + ".versions",
|
|
346
|
+
expected: "(Array<__type> | undefined)",
|
|
347
|
+
value: input.versions
|
|
348
|
+
}, _errorFactory);
|
|
349
|
+
const _ao1 = (input, _path, _exceptionable = true) => "string" === typeof input.version || _assertGuard(_exceptionable, {
|
|
350
|
+
method: "typia.createAssert",
|
|
351
|
+
path: _path + ".version",
|
|
352
|
+
expected: "string",
|
|
353
|
+
value: input.version
|
|
354
|
+
}, _errorFactory);
|
|
355
|
+
const __is = (input) => "object" === typeof input && null !== input && false === Array.isArray(input) && _io0(input);
|
|
356
|
+
let _errorFactory;
|
|
357
|
+
return (input, errorFactory) => {
|
|
358
|
+
if (false === __is(input)) {
|
|
359
|
+
_errorFactory = errorFactory;
|
|
360
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input && false === Array.isArray(input) || _assertGuard(true, {
|
|
361
|
+
method: "typia.createAssert",
|
|
362
|
+
path: _path + "",
|
|
363
|
+
expected: "HostedPackage",
|
|
364
|
+
value: input
|
|
365
|
+
}, _errorFactory)) && _ao0(input, _path + "", true) || _assertGuard(true, {
|
|
366
|
+
method: "typia.createAssert",
|
|
367
|
+
path: _path + "",
|
|
368
|
+
expected: "HostedPackage",
|
|
369
|
+
value: input
|
|
370
|
+
}, _errorFactory))(input, "$input", true);
|
|
371
|
+
}
|
|
372
|
+
return input;
|
|
373
|
+
};
|
|
374
|
+
})();
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/index.ts
|
|
377
|
+
const DEP_FIELDS = [
|
|
378
|
+
"dependencies",
|
|
379
|
+
"dev_dependencies",
|
|
380
|
+
"dependency_overrides"
|
|
381
|
+
];
|
|
382
|
+
const DEFAULT_HOSTED_URL = "https://pub.dev";
|
|
383
|
+
var DartPackage = class extends WorkspacePackage {
|
|
384
|
+
path;
|
|
385
|
+
file;
|
|
386
|
+
manager = "dart";
|
|
387
|
+
constructor(path, file) {
|
|
388
|
+
super();
|
|
389
|
+
this.path = path;
|
|
390
|
+
this.file = file;
|
|
391
|
+
}
|
|
392
|
+
get name() {
|
|
393
|
+
return this.file.data.name;
|
|
394
|
+
}
|
|
395
|
+
get version() {
|
|
396
|
+
return this.file.data.version;
|
|
397
|
+
}
|
|
398
|
+
get publishTo() {
|
|
399
|
+
return this.file.data.publish_to;
|
|
400
|
+
}
|
|
401
|
+
setVersion(version) {
|
|
402
|
+
this.file.data.version = version;
|
|
403
|
+
this.file.doc.setIn(["version"], version);
|
|
404
|
+
}
|
|
405
|
+
async write() {
|
|
406
|
+
await writeFile(path.join(this.path, "pubspec.yaml"), this.file.doc.toString({ lineWidth: 0 }));
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
function dart({ updateLockFile = true, bumpDep: getBumpDepType } = {}) {
|
|
410
|
+
let active = false;
|
|
411
|
+
return {
|
|
412
|
+
name: "dart",
|
|
413
|
+
enforce: "post",
|
|
414
|
+
async resolve() {
|
|
415
|
+
const packages = await discoverDartPackages(this.cwd);
|
|
416
|
+
for (const pkg of packages) this.graph.add(pkg);
|
|
417
|
+
active = packages.length > 0;
|
|
418
|
+
},
|
|
419
|
+
initDraft(draft) {
|
|
420
|
+
if (!active) return;
|
|
421
|
+
draft.addPolicy(depsPolicy(this, getBumpDepType));
|
|
422
|
+
},
|
|
423
|
+
publishPreflight({ pkg }) {
|
|
424
|
+
if (!(pkg instanceof DartPackage)) return;
|
|
425
|
+
const wait = dependencyRefs(this.graph, pkg).filter((ref) => ref.kind === "dependencies").map((ref) => ref.linked.id);
|
|
426
|
+
return {
|
|
427
|
+
shouldPublish: pkg.version !== void 0 && pkg.publishTo !== "none",
|
|
428
|
+
wait
|
|
429
|
+
};
|
|
430
|
+
},
|
|
431
|
+
resolvePlanStatus({ plan }) {
|
|
432
|
+
return Array.from(plan.packages, async ([id, { preflight }]) => {
|
|
433
|
+
if (!preflight.shouldPublish) return;
|
|
434
|
+
const pkg = this.graph.get(id);
|
|
435
|
+
if (!(pkg instanceof DartPackage) || !pkg.version) return;
|
|
436
|
+
if (!await isPackagePublished(pkg.name, pkg.version, pkg.publishTo ?? DEFAULT_HOSTED_URL)) return "pending";
|
|
437
|
+
});
|
|
438
|
+
},
|
|
439
|
+
async publish({ pkg }) {
|
|
440
|
+
if (!(pkg instanceof DartPackage)) return;
|
|
441
|
+
const result = await x("dart", [
|
|
442
|
+
"pub",
|
|
443
|
+
"publish",
|
|
444
|
+
...isCI() ? ["--force"] : []
|
|
445
|
+
], { nodeOptions: { cwd: pkg.path } });
|
|
446
|
+
if (result.exitCode !== 0) {
|
|
447
|
+
if (/already exists|already published|version already exists/i.test(`${result.stdout}\n${result.stderr}`)) return { type: "skipped" };
|
|
448
|
+
return {
|
|
449
|
+
type: "failed",
|
|
450
|
+
error: execFailure(`Failed to publish ${pkg.name}@${pkg.version}.`, result).message
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
return { type: "published" };
|
|
454
|
+
},
|
|
455
|
+
async applyDraft(draft) {
|
|
456
|
+
if (!active) return;
|
|
457
|
+
for (const pkg of this.graph.getPackages()) {
|
|
458
|
+
if (!(pkg instanceof DartPackage)) continue;
|
|
459
|
+
const bumped = draft.getPackageDraft(pkg.id)?.bumpVersion(pkg);
|
|
460
|
+
if (bumped) pkg.setVersion(bumped);
|
|
461
|
+
}
|
|
462
|
+
const writes = [];
|
|
463
|
+
for (const pkg of this.graph.getPackages()) {
|
|
464
|
+
if (!(pkg instanceof DartPackage)) continue;
|
|
465
|
+
for (const ref of dependencyRefs(this.graph, pkg)) {
|
|
466
|
+
if (!ref.linked.version) continue;
|
|
467
|
+
const range = getDependencyRange(ref.spec);
|
|
468
|
+
if (!range || satisfiesDartRange(ref.linked.version, range)) continue;
|
|
469
|
+
const nextRange = updateConstraintRange(range, ref.linked.version);
|
|
470
|
+
ref.table[ref.name] = setDependencyRange(ref.spec, nextRange);
|
|
471
|
+
ref.dependent.file.doc.setIn(typeof ref.spec === "object" && ref.spec !== null ? [
|
|
472
|
+
ref.kind,
|
|
473
|
+
ref.name,
|
|
474
|
+
"version"
|
|
475
|
+
] : [ref.kind, ref.name], nextRange);
|
|
476
|
+
}
|
|
477
|
+
writes.push(pkg.write());
|
|
478
|
+
}
|
|
479
|
+
await Promise.all(writes);
|
|
480
|
+
},
|
|
481
|
+
async applyCliDraft() {
|
|
482
|
+
if (!active || !updateLockFile) return;
|
|
483
|
+
const result = await x("dart", ["pub", "get"], { nodeOptions: { cwd: this.cwd } });
|
|
484
|
+
if (result.exitCode !== 0) throw execFailure("Failed to update Dart pub resolution.", result);
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
function depsPolicy({ graph }, getBumpDepType = ({ kind }) => {
|
|
489
|
+
switch (kind) {
|
|
490
|
+
case "dependencies":
|
|
491
|
+
case "dependency_overrides": return "patch";
|
|
492
|
+
case "dev_dependencies": return false;
|
|
493
|
+
}
|
|
494
|
+
}) {
|
|
495
|
+
const dependentMap = /* @__PURE__ */ new Map();
|
|
496
|
+
for (const pkg of graph.getPackages()) {
|
|
497
|
+
if (!(pkg instanceof DartPackage)) continue;
|
|
498
|
+
for (const ref of dependencyRefs(graph, pkg)) {
|
|
499
|
+
const refs = dependentMap.get(ref.linked.id);
|
|
500
|
+
if (refs) refs.push(ref);
|
|
501
|
+
else dependentMap.set(ref.linked.id, [ref]);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return {
|
|
505
|
+
id: "dart:deps",
|
|
506
|
+
onUpdate({ pkg, packageDraft: plan }) {
|
|
507
|
+
if (!(pkg instanceof DartPackage)) return;
|
|
508
|
+
const deps = dependentMap.get(pkg.id);
|
|
509
|
+
if (!deps) return;
|
|
510
|
+
const group = graph.getPackageGroup(pkg.id);
|
|
511
|
+
if (!plan.bumpVersion(pkg)) return;
|
|
512
|
+
for (const dep of deps) {
|
|
513
|
+
if (group?.options.syncBump && graph.getPackageGroup(dep.dependent.id) === group) continue;
|
|
514
|
+
const bumpType = getBumpDepType(dep);
|
|
515
|
+
if (bumpType === false) continue;
|
|
516
|
+
this.bumpPackage(dep.dependent, {
|
|
517
|
+
type: bumpType,
|
|
518
|
+
reason: `update dependency "${dep.name}"`
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
function dependencyRefs(graph, pkg) {
|
|
525
|
+
const refs = [];
|
|
526
|
+
for (const { kind, table } of dependencyTables(pkg.file.data)) for (const [name, spec] of Object.entries(table)) {
|
|
527
|
+
const linked = resolveLinkedPackage(graph, name);
|
|
528
|
+
if (!linked || linked === pkg) continue;
|
|
529
|
+
refs.push({
|
|
530
|
+
dependent: pkg,
|
|
531
|
+
kind,
|
|
532
|
+
name,
|
|
533
|
+
spec,
|
|
534
|
+
table,
|
|
535
|
+
linked
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
return refs;
|
|
539
|
+
}
|
|
540
|
+
function resolveLinkedPackage(graph, name) {
|
|
541
|
+
return graph.getPackages().find((candidate) => candidate instanceof DartPackage && candidate.name === name);
|
|
542
|
+
}
|
|
543
|
+
function dependencyTables(manifest) {
|
|
544
|
+
const tables = [];
|
|
545
|
+
for (const kind of DEP_FIELDS) {
|
|
546
|
+
const table = manifest[kind];
|
|
547
|
+
if (table) tables.push({
|
|
548
|
+
kind,
|
|
549
|
+
table
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
return tables;
|
|
553
|
+
}
|
|
554
|
+
function getDependencyRange(spec) {
|
|
555
|
+
if (typeof spec === "string") return spec;
|
|
556
|
+
return spec.version;
|
|
557
|
+
}
|
|
558
|
+
function setDependencyRange(spec, range) {
|
|
559
|
+
if (typeof spec !== "object" || spec === null) return range;
|
|
560
|
+
spec.version = range;
|
|
561
|
+
return spec;
|
|
562
|
+
}
|
|
563
|
+
function updateConstraintRange(range, version) {
|
|
564
|
+
const trimmed = range.trim();
|
|
565
|
+
if (trimmed.startsWith("^")) return `^${version}`;
|
|
566
|
+
if (trimmed.startsWith("~")) return `~${version}`;
|
|
567
|
+
const lowerBound = /^(>=|>)\s*([0-9A-Za-z.+-]+)/.exec(trimmed);
|
|
568
|
+
if (lowerBound) return trimmed.replace(lowerBound[0], `${lowerBound[1]}${version}`);
|
|
569
|
+
return version;
|
|
570
|
+
}
|
|
571
|
+
function satisfiesDartRange(version, range) {
|
|
572
|
+
const trimmed = range.trim();
|
|
573
|
+
if (trimmed === "any") return true;
|
|
574
|
+
if (!semver.validRange(trimmed, { loose: true })) return false;
|
|
575
|
+
return semver.satisfies(version, trimmed, {
|
|
576
|
+
includePrerelease: true,
|
|
577
|
+
loose: true
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
async function discoverDartPackages(cwd) {
|
|
581
|
+
const root = await readPubspec(cwd);
|
|
582
|
+
if (!root?.data.workspace?.length) return [];
|
|
583
|
+
const files = /* @__PURE__ */ new Map();
|
|
584
|
+
files.set(root.path, root);
|
|
585
|
+
await collectWorkspaceFiles(root, files);
|
|
586
|
+
return Array.from(files.values()).filter((file) => Boolean(file.data.name)).map((file) => new DartPackage(path.dirname(file.path), file));
|
|
587
|
+
}
|
|
588
|
+
async function collectWorkspaceFiles(root, files) {
|
|
589
|
+
const rootDir = path.dirname(root.path);
|
|
590
|
+
const members = root.data.workspace;
|
|
591
|
+
if (!members?.length) return;
|
|
592
|
+
const paths = await glob(members, {
|
|
593
|
+
absolute: true,
|
|
594
|
+
cwd: rootDir,
|
|
595
|
+
onlyDirectories: true,
|
|
596
|
+
onlyFiles: false,
|
|
597
|
+
ignore: ["**/.dart_tool/**", "**/build/**"]
|
|
598
|
+
});
|
|
599
|
+
await Promise.all(paths.map(async (dir) => {
|
|
600
|
+
const file = await readPubspec(dir);
|
|
601
|
+
if (!file || files.has(file.path)) return;
|
|
602
|
+
files.set(file.path, file);
|
|
603
|
+
await collectWorkspaceFiles(file, files);
|
|
604
|
+
}));
|
|
605
|
+
}
|
|
606
|
+
async function readPubspec(dir) {
|
|
607
|
+
const filePath = path.join(dir, "pubspec.yaml");
|
|
608
|
+
try {
|
|
609
|
+
const doc = parseDocument(await readFile(filePath, "utf8"));
|
|
610
|
+
return {
|
|
611
|
+
path: filePath,
|
|
612
|
+
doc,
|
|
613
|
+
data: assertPubspec(doc.toJS())
|
|
614
|
+
};
|
|
615
|
+
} catch {
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
async function isPackagePublished(name, version, hostedUrl) {
|
|
620
|
+
const url = joinPath(hostedUrl, "api/packages", encodeURIComponent(name));
|
|
621
|
+
const response = await fetch(url, { headers: {
|
|
622
|
+
Accept: "application/vnd.pub.v2+json",
|
|
623
|
+
"User-Agent": "tegami-dart"
|
|
624
|
+
} });
|
|
625
|
+
if (response.status === 404) return false;
|
|
626
|
+
if (!response.ok) return false;
|
|
627
|
+
return assertHostedPackage(await response.json()).versions?.some((entry) => entry.version === version) ?? false;
|
|
628
|
+
}
|
|
629
|
+
//#endregion
|
|
630
|
+
export { DartPackage, dart, isPackagePublished, updateConstraintRange };
|
package/package.json
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tegami/dart",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Dart pub workspace support and pub.dev publishing for Tegami",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Fuma Nama",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "github:fuma-nama/tegami"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": "./dist/index.js",
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"semver": "^7.8.5",
|
|
24
|
+
"tinyexec": "^1.2.4",
|
|
25
|
+
"tinyglobby": "^0.2.17",
|
|
26
|
+
"yaml": "^2.9.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^26.0.1",
|
|
30
|
+
"@types/semver": "^7.7.1",
|
|
31
|
+
"tsdown": "^0.22.3",
|
|
32
|
+
"typescript": "6.0.3",
|
|
33
|
+
"typia": "^12.1.1",
|
|
34
|
+
"@repo/typescript-config": "0.0.0",
|
|
35
|
+
"tegami": "1.1.1"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"tegami": "1.1.1"
|
|
39
|
+
},
|
|
40
|
+
"inlinedDependencies": {
|
|
41
|
+
"typia": "12.1.1"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"types:check": "tsc --noEmit",
|
|
45
|
+
"build": "tsdown",
|
|
46
|
+
"dev": "tsdown --watch"
|
|
47
|
+
}
|
|
48
|
+
}
|