@effected/bundler 0.0.0-stage → 0.1.0
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/Bundler.js +450 -0
- package/BundlerError.js +39 -0
- package/LICENSE +21 -0
- package/README.md +84 -2
- package/action/ActionBuilder.js +108 -0
- package/action/ActionBundle.js +261 -0
- package/action/ActionErrors.js +83 -0
- package/action/ActionValidation.js +195 -0
- package/action/ActionYml.js +366 -0
- package/action/PersistLocal.js +186 -0
- package/action/entries.js +23 -0
- package/action/ignore-stub-plugin.js +25 -0
- package/action/import-check.js +134 -0
- package/assets/Inter-SemiBold.ttf +0 -0
- package/assets/LICENSE-Inter.txt +92 -0
- package/catalog/resolve-catalogs.js +32 -0
- package/changesets/next-versions.js +50 -0
- package/config/ActionConfig.js +102 -0
- package/config/BuildConfig.js +427 -0
- package/config/EffectedConfigFile.js +160 -0
- package/config/merge.js +20 -0
- package/config/plugins.js +84 -0
- package/config-validation/ConfigValidator.js +67 -0
- package/dts/bundled-siblings.js +108 -0
- package/dts/parse.js +28 -0
- package/dts/reexport-stub.js +94 -0
- package/dts/relative-imports.js +33 -0
- package/dts/resolved-tsconfig.js +238 -0
- package/entries/ambient-dts.js +108 -0
- package/entries/export-paths.js +16 -0
- package/entries/extract.js +79 -0
- package/entries/package-json-entries.js +19 -0
- package/errors.js +37 -0
- package/exe/build.js +55 -0
- package/exe/config.js +54 -0
- package/exe/filename.js +13 -0
- package/index.d.ts +3919 -0
- package/index.js +58 -0
- package/internal/causeMessage.js +57 -0
- package/journal/BuildJournal.js +108 -0
- package/jsx/config.js +51 -0
- package/manifest/emit-manifest.js +88 -0
- package/manifest/export-patterns.js +58 -0
- package/manifest/transform.js +323 -0
- package/meta/BundleManifest.js +208 -0
- package/meta/ManifestSource.js +37 -0
- package/meta/api-extractor.js +241 -0
- package/meta/config.js +24 -0
- package/meta/generate.js +246 -0
- package/meta/merge-models.js +43 -0
- package/meta/message-suppressor.js +43 -0
- package/meta/og-image.js +137 -0
- package/meta/og-satori.js +140 -0
- package/meta/optimistic.js +32 -0
- package/meta/run-pass.js +117 -0
- package/meta/scrub-declaration-maps.js +63 -0
- package/meta/tsconfig-resolver.js +55 -0
- package/meta/tsdoc-config.js +47 -0
- package/meta/tsdoctor-config.js +22 -0
- package/meta/tsdoctor-manifest.js +134 -0
- package/meta/tsdoctor-source.js +94 -0
- package/package.json +85 -5
- package/passes/build-target-groups.js +346 -0
- package/passes/cjs-default-interop.js +98 -0
- package/passes/loose-files.js +57 -0
- package/passes/node-builtin-default-interop.js +79 -0
- package/passes/strip-maps.js +39 -0
- package/passes/sync-public.js +100 -0
- package/passes/target-groups.js +112 -0
- package/report/ci-annotations.js +36 -0
- package/report/collector.js +140 -0
- package/report/issues-artifact.js +155 -0
- package/report/metrics-plugin.js +76 -0
- package/report/schema.js +77 -0
- package/report/timer.js +19 -0
- package/report/tsdown-logger.js +58 -0
- package/targets/binding.js +18 -0
- package/targets/config.js +21 -0
- package/targets/resolve-targets.js +165 -0
- package/tsconfig/sync-options.js +20 -0
- package/tsdoc-metadata.json +11 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { ActionBundle, BuildResult } from "./ActionBundle.js";
|
|
2
|
+
import { ActionValidation, ValidationResult } from "./ActionValidation.js";
|
|
3
|
+
import { PersistLocal } from "./PersistLocal.js";
|
|
4
|
+
import { Effect, Schema } from "effect";
|
|
5
|
+
|
|
6
|
+
// src/action/ActionBuilder.ts
|
|
7
|
+
/**
|
|
8
|
+
* Validation stopped an action build, before bundling or on a bundle's size afterwards.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
var ValidationFailed = class extends Schema.TaggedError()("ValidationFailed", {
|
|
13
|
+
/** How many errors it found. */
|
|
14
|
+
errorCount: Schema.Number,
|
|
15
|
+
/** How many warnings it found. */
|
|
16
|
+
warningCount: Schema.Number,
|
|
17
|
+
/** A summary. */
|
|
18
|
+
message: Schema.String,
|
|
19
|
+
/** Everything it found. */
|
|
20
|
+
validation: ValidationResult,
|
|
21
|
+
/** How bundling went, when validation stopped the build after it. */
|
|
22
|
+
build: Schema.optionalKey(BuildResult)
|
|
23
|
+
}) {};
|
|
24
|
+
/**
|
|
25
|
+
* An entry of an action failed to bundle or does not load.
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
var BuildFailed = class extends Schema.TaggedError()("BuildFailed", {
|
|
30
|
+
/** A summary. */
|
|
31
|
+
message: Schema.String,
|
|
32
|
+
/** How many entries failed. */
|
|
33
|
+
failedEntries: Schema.Number,
|
|
34
|
+
/** Every entry's result. */
|
|
35
|
+
build: BuildResult,
|
|
36
|
+
/** What validation found before bundling. */
|
|
37
|
+
validation: ValidationResult
|
|
38
|
+
}) {};
|
|
39
|
+
/**
|
|
40
|
+
* What a whole action build did.
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
var ActionBuildResult = class extends Schema.Class("ActionBuildResult")({
|
|
45
|
+
/** What validation found, including any bundle over its size limit. Empty and valid when validation was skipped. */
|
|
46
|
+
validation: ValidationResult,
|
|
47
|
+
/** How bundling went. */
|
|
48
|
+
build: BuildResult,
|
|
49
|
+
/** Whether the build was copied to the local action directory. */
|
|
50
|
+
persisted: Schema.Boolean
|
|
51
|
+
}) {};
|
|
52
|
+
const failValidation = (validation, build) => new ValidationFailed({
|
|
53
|
+
errorCount: validation.errors.length,
|
|
54
|
+
warningCount: validation.warnings.length,
|
|
55
|
+
message: validation.errors.length > 0 ? "Validation failed" : "Warnings treated as errors in strict mode",
|
|
56
|
+
validation,
|
|
57
|
+
...build !== void 0 ? { build } : {}
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Builds a GitHub Action.
|
|
61
|
+
*
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
var ActionBuilder = class {
|
|
65
|
+
constructor() {}
|
|
66
|
+
/**
|
|
67
|
+
* Validates the action, bundles it, checks the bundles' sizes and copies the build locally.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* It writes nothing to stdout; rendering belongs to the caller. A step that fails stops the ones after it, so an
|
|
71
|
+
* invalid action leaves `dist` as it was, and a failed build or size check persists nothing. In strict mode, set
|
|
72
|
+
* by `validation.strict` or else by running under CI, a warning fails like an error. With `validate` false, neither
|
|
73
|
+
* validation nor the size check runs. `build.importCheck` alone decides whether each bundle is imported to prove it
|
|
74
|
+
* loads, per {@link ActionBundle.build}.
|
|
75
|
+
*
|
|
76
|
+
* Validation and persisting go through the provided `FileSystem`, while bundling always works on the real disk,
|
|
77
|
+
* because rolldown does. A memory filesystem therefore suits {@link ActionValidation} and {@link PersistLocal} tests,
|
|
78
|
+
* not this method.
|
|
79
|
+
*/
|
|
80
|
+
static build = Effect.fn("ActionBuilder.build")(function* (options) {
|
|
81
|
+
const { config, cwd } = options;
|
|
82
|
+
const strict = ActionValidation.isStrict(config, options);
|
|
83
|
+
const before = options.validate ? yield* ActionValidation.validate(config, cwd, options) : ActionValidation.resultOf([], [], false);
|
|
84
|
+
if (!before.valid) return yield* failValidation(before);
|
|
85
|
+
const build = yield* ActionBundle.build(config, {
|
|
86
|
+
cwd,
|
|
87
|
+
clean: true
|
|
88
|
+
});
|
|
89
|
+
if (!build.success) return yield* new BuildFailed({
|
|
90
|
+
message: build.error ?? "One or more entries failed to build",
|
|
91
|
+
failedEntries: build.entries.filter((entry) => !entry.success).length,
|
|
92
|
+
build,
|
|
93
|
+
validation: before
|
|
94
|
+
});
|
|
95
|
+
const oversized = options.validate ? ActionValidation.checkBundleSizes(config, build.entries.flatMap((entry) => entry.stats !== void 0 ? [entry.stats] : [])) : [];
|
|
96
|
+
const validation = ActionValidation.resultOf(before.errors, [...before.warnings, ...oversized], strict && options.validate);
|
|
97
|
+
if (!validation.valid) return yield* failValidation(validation, build);
|
|
98
|
+
const persisted = options.persist && config.persistLocal.enabled;
|
|
99
|
+
if (persisted) yield* PersistLocal.persist(config, { cwd });
|
|
100
|
+
return ActionBuildResult.make({
|
|
101
|
+
validation,
|
|
102
|
+
build,
|
|
103
|
+
persisted
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export { ActionBuildResult, ActionBuilder, BuildFailed, ValidationFailed };
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { causeMessage } from "../internal/causeMessage.js";
|
|
2
|
+
import { BundleFailed, CleanError, WriteError } from "./ActionErrors.js";
|
|
3
|
+
import { DEFAULT_LIFECYCLE_ENTRIES, invalidWorkerName } from "./entries.js";
|
|
4
|
+
import { ignoreStubPlugin } from "./ignore-stub-plugin.js";
|
|
5
|
+
import { checkImport } from "./import-check.js";
|
|
6
|
+
import { Effect, Result, Schema } from "effect";
|
|
7
|
+
import { existsSync, mkdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { join, resolve } from "node:path";
|
|
9
|
+
import { stripVTControlCharacters } from "node:util";
|
|
10
|
+
import { rolldown } from "rolldown";
|
|
11
|
+
|
|
12
|
+
// src/action/ActionBundle.ts
|
|
13
|
+
/**
|
|
14
|
+
* What one bundle came to.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
var BundleStats = class extends Schema.Class("BundleStats")({
|
|
19
|
+
/** The entry: `main`, `pre`, `post` or a worker's name. */
|
|
20
|
+
entry: Schema.String,
|
|
21
|
+
/** The bundle's size in bytes. */
|
|
22
|
+
size: Schema.Number,
|
|
23
|
+
/** How long the entry took to bundle and check, in milliseconds. */
|
|
24
|
+
duration: Schema.Number,
|
|
25
|
+
/** The output path, relative to the action. */
|
|
26
|
+
outputPath: Schema.String
|
|
27
|
+
}) {};
|
|
28
|
+
/**
|
|
29
|
+
* How one entry's bundling went.
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
var BundleResult = class extends Schema.Class("BundleResult")({
|
|
34
|
+
/** Whether the entry bundled and its bundle loaded. */
|
|
35
|
+
success: Schema.Boolean,
|
|
36
|
+
/** The bundle's statistics, on success. */
|
|
37
|
+
stats: Schema.optionalKey(BundleStats),
|
|
38
|
+
/** What went wrong, on failure. */
|
|
39
|
+
error: Schema.optionalKey(Schema.String),
|
|
40
|
+
/** The warnings rolldown logged for this entry, when it logged any. */
|
|
41
|
+
warnings: Schema.optionalKey(Schema.Array(Schema.String))
|
|
42
|
+
}) {};
|
|
43
|
+
/**
|
|
44
|
+
* How a whole action bundle went.
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
var BuildResult = class extends Schema.Class("BuildResult")({
|
|
49
|
+
/** Whether every entry succeeded. */
|
|
50
|
+
success: Schema.Boolean,
|
|
51
|
+
/** Each entry's result: `main`, `pre`, `post`, then the workers. */
|
|
52
|
+
entries: Schema.Array(BundleResult),
|
|
53
|
+
/** How long the build took, in milliseconds. */
|
|
54
|
+
duration: Schema.Number,
|
|
55
|
+
/** A summary of what went wrong, on failure. */
|
|
56
|
+
error: Schema.optionalKey(Schema.String)
|
|
57
|
+
}) {};
|
|
58
|
+
/**
|
|
59
|
+
* The entries to build. A `pre` or `post` the config names must exist, and the conventional `src/pre.ts` and
|
|
60
|
+
* `src/post.ts` are built when they do.
|
|
61
|
+
*/
|
|
62
|
+
const entriesToBuild = (config, cwd) => {
|
|
63
|
+
const { main, pre, post, workers } = config.entries;
|
|
64
|
+
const mainSource = resolve(cwd, main);
|
|
65
|
+
if (!existsSync(mainSource)) return Result.fail(new BundleFailed({
|
|
66
|
+
entry: main,
|
|
67
|
+
cause: /* @__PURE__ */ new Error("Main entry point not found")
|
|
68
|
+
}));
|
|
69
|
+
const entries = [{
|
|
70
|
+
name: "main",
|
|
71
|
+
source: mainSource
|
|
72
|
+
}];
|
|
73
|
+
for (const [name, explicit, fallback] of [[
|
|
74
|
+
"pre",
|
|
75
|
+
pre,
|
|
76
|
+
DEFAULT_LIFECYCLE_ENTRIES.pre
|
|
77
|
+
], [
|
|
78
|
+
"post",
|
|
79
|
+
post,
|
|
80
|
+
DEFAULT_LIFECYCLE_ENTRIES.post
|
|
81
|
+
]]) {
|
|
82
|
+
const source = resolve(cwd, explicit ?? fallback);
|
|
83
|
+
if (existsSync(source)) entries.push({
|
|
84
|
+
name,
|
|
85
|
+
source
|
|
86
|
+
});
|
|
87
|
+
else if (explicit !== void 0) return Result.fail(new BundleFailed({
|
|
88
|
+
entry: name,
|
|
89
|
+
cause: /* @__PURE__ */ new Error(`Entry point not found: ${explicit}`)
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
for (const [name, source] of Object.entries(workers)) {
|
|
93
|
+
const reason = invalidWorkerName(name);
|
|
94
|
+
if (reason !== void 0) return Result.fail(new BundleFailed({
|
|
95
|
+
entry: name,
|
|
96
|
+
cause: new Error(reason)
|
|
97
|
+
}));
|
|
98
|
+
const workerSource = resolve(cwd, source);
|
|
99
|
+
if (!existsSync(workerSource)) return Result.fail(new BundleFailed({
|
|
100
|
+
entry: name,
|
|
101
|
+
cause: /* @__PURE__ */ new Error(`Worker entry point not found: ${source}`)
|
|
102
|
+
}));
|
|
103
|
+
entries.push({
|
|
104
|
+
name,
|
|
105
|
+
source: workerSource
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return Result.succeed(entries);
|
|
109
|
+
};
|
|
110
|
+
/** Bundles one entry and, unless the config turns it off, proves the bundle loads. A failure comes back as a result. */
|
|
111
|
+
const bundleEntry = async (entry, config, cwd, signal) => {
|
|
112
|
+
const started = Date.now();
|
|
113
|
+
const { minify, sourceMap, externals, ignore, importCheck } = config.build;
|
|
114
|
+
const warnings = [];
|
|
115
|
+
const logged = () => warnings.length > 0 ? { warnings } : {};
|
|
116
|
+
try {
|
|
117
|
+
const build = await rolldown({
|
|
118
|
+
input: { [entry.name]: entry.source },
|
|
119
|
+
cwd,
|
|
120
|
+
platform: "node",
|
|
121
|
+
treeshake: true,
|
|
122
|
+
external: [/^node:/, ...externals.filter((name) => !ignore.includes(name))],
|
|
123
|
+
resolve: { mainFields: ["module", "main"] },
|
|
124
|
+
transform: { define: {
|
|
125
|
+
__dirname: "import.meta.dirname",
|
|
126
|
+
__filename: "import.meta.filename",
|
|
127
|
+
"process.env.NODE_ENV": "\"production\""
|
|
128
|
+
} },
|
|
129
|
+
plugins: [ignoreStubPlugin(ignore)],
|
|
130
|
+
onLog(level, log) {
|
|
131
|
+
if (level === "warn") warnings.push(stripVTControlCharacters(log.message));
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
try {
|
|
135
|
+
await build.write({
|
|
136
|
+
dir: join(cwd, "dist"),
|
|
137
|
+
format: "esm",
|
|
138
|
+
entryFileNames: "[name].js",
|
|
139
|
+
minify,
|
|
140
|
+
sourcemap: sourceMap,
|
|
141
|
+
codeSplitting: false,
|
|
142
|
+
comments: {
|
|
143
|
+
legal: true,
|
|
144
|
+
annotation: false,
|
|
145
|
+
jsdoc: false
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
} finally {
|
|
149
|
+
await build.close();
|
|
150
|
+
}
|
|
151
|
+
const file = join(cwd, "dist", `${entry.name}.js`);
|
|
152
|
+
if (importCheck) {
|
|
153
|
+
const verdict = await checkImport(file, {
|
|
154
|
+
externals,
|
|
155
|
+
signal
|
|
156
|
+
});
|
|
157
|
+
if (verdict.kind === "failed") return BundleResult.make({
|
|
158
|
+
success: false,
|
|
159
|
+
error: `${entry.name} does not load: ${verdict.message}`,
|
|
160
|
+
...logged()
|
|
161
|
+
});
|
|
162
|
+
if (verdict.kind === "external-missing") warnings.push(`${verdict.packageName} is in build.externals and is not installed, so the load check stopped there`);
|
|
163
|
+
}
|
|
164
|
+
return BundleResult.make({
|
|
165
|
+
success: true,
|
|
166
|
+
stats: BundleStats.make({
|
|
167
|
+
entry: entry.name,
|
|
168
|
+
size: statSync(file).size,
|
|
169
|
+
duration: Date.now() - started,
|
|
170
|
+
outputPath: `dist/${entry.name}.js`
|
|
171
|
+
}),
|
|
172
|
+
...logged()
|
|
173
|
+
});
|
|
174
|
+
} catch (cause) {
|
|
175
|
+
return BundleResult.make({
|
|
176
|
+
success: false,
|
|
177
|
+
error: `${entry.name} failed to bundle: ${causeMessage(cause) ?? String(cause)}`,
|
|
178
|
+
...logged()
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Bundles a GitHub Action with rolldown.
|
|
184
|
+
*
|
|
185
|
+
* @public
|
|
186
|
+
*/
|
|
187
|
+
var ActionBundle = class {
|
|
188
|
+
constructor() {}
|
|
189
|
+
/**
|
|
190
|
+
* Bundles every entry of the action at `options.cwd` into its own `dist/<entry>.js`, and writes `dist/package.json`
|
|
191
|
+
* so Node reads them as ESM.
|
|
192
|
+
*
|
|
193
|
+
* @remarks
|
|
194
|
+
* Each bundle is self-contained apart from `node:` builtins and `build.externals`, and the output does not depend
|
|
195
|
+
* on when or where it is built.
|
|
196
|
+
*
|
|
197
|
+
* Each bundle is then imported in a fresh Node, because a bundle can build cleanly and not load. Set
|
|
198
|
+
* `build.importCheck = false` to skip that. The child has no `GITHUB_*` variable, token or `PATH`, and runs in a
|
|
199
|
+
* temporary directory, for at most a minute. An action's `GITHUB_ACTIONS` guard stays closed, but an action with no
|
|
200
|
+
* guard runs for real there. A failure asking for an input passes. A package listed in `build.externals` that is not
|
|
201
|
+
* installed passes with a warning on the entry, and the check learns nothing about the bundle past that import.
|
|
202
|
+
*
|
|
203
|
+
* An entry that fails to bundle or load is reported in the result with the others still built, and leaves no bundle
|
|
204
|
+
* in `dist`. A missing `main`, a `pre`, `post` or worker the config names with no file, and a bad worker name fail
|
|
205
|
+
* {@link BundleFailed} before `dist` is touched. Interrupting the build kills a running load check.
|
|
206
|
+
*
|
|
207
|
+
* @param options - `cwd` is the action's directory; `clean` removes `dist` first.
|
|
208
|
+
*/
|
|
209
|
+
static build = Effect.fn("ActionBundle.build")(function* (config, options) {
|
|
210
|
+
const started = Date.now();
|
|
211
|
+
const requested = resolve(options.cwd);
|
|
212
|
+
const cwd = existsSync(requested) ? realpathSync(requested) : requested;
|
|
213
|
+
const dist = join(cwd, "dist");
|
|
214
|
+
const entries = yield* Effect.fromResult(entriesToBuild(config, cwd));
|
|
215
|
+
if (options.clean) yield* Effect.try({
|
|
216
|
+
try: () => rmSync(dist, {
|
|
217
|
+
recursive: true,
|
|
218
|
+
force: true
|
|
219
|
+
}),
|
|
220
|
+
catch: (cause) => new CleanError({
|
|
221
|
+
directory: dist,
|
|
222
|
+
cause
|
|
223
|
+
})
|
|
224
|
+
});
|
|
225
|
+
const manifest = join(dist, "package.json");
|
|
226
|
+
yield* Effect.try({
|
|
227
|
+
try: () => {
|
|
228
|
+
mkdirSync(dist, { recursive: true });
|
|
229
|
+
writeFileSync(manifest, "{ \"type\": \"module\" }", "utf8");
|
|
230
|
+
},
|
|
231
|
+
catch: (cause) => new WriteError({
|
|
232
|
+
path: manifest,
|
|
233
|
+
cause
|
|
234
|
+
})
|
|
235
|
+
});
|
|
236
|
+
const results = [];
|
|
237
|
+
for (const entry of entries) {
|
|
238
|
+
const result = yield* Effect.promise((signal) => bundleEntry(entry, config, cwd, signal));
|
|
239
|
+
if (!result.success) yield* Effect.try({
|
|
240
|
+
try: () => {
|
|
241
|
+
rmSync(join(dist, `${entry.name}.js`), { force: true });
|
|
242
|
+
rmSync(join(dist, `${entry.name}.js.map`), { force: true });
|
|
243
|
+
},
|
|
244
|
+
catch: (cause) => new CleanError({
|
|
245
|
+
directory: dist,
|
|
246
|
+
cause
|
|
247
|
+
})
|
|
248
|
+
});
|
|
249
|
+
results.push(result);
|
|
250
|
+
}
|
|
251
|
+
const failed = results.filter((result) => !result.success).length;
|
|
252
|
+
return BuildResult.make({
|
|
253
|
+
success: failed === 0,
|
|
254
|
+
entries: results,
|
|
255
|
+
duration: Date.now() - started,
|
|
256
|
+
...failed > 0 ? { error: `${failed} of ${results.length} entries failed to build` } : {}
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
export { ActionBundle, BuildResult, BundleResult, BundleStats };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { causeMessage } from "../internal/causeMessage.js";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
// src/action/ActionErrors.ts
|
|
5
|
+
/**
|
|
6
|
+
* An entry could not go through the bundler, or could not be bundled at all.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
var BundleFailed = class extends Schema.TaggedError()("BundleFailed", {
|
|
11
|
+
/** The entry at fault, as its bundle name or source path. */
|
|
12
|
+
entry: Schema.String,
|
|
13
|
+
/** What went wrong. */
|
|
14
|
+
cause: Schema.Defect()
|
|
15
|
+
}) {
|
|
16
|
+
get message() {
|
|
17
|
+
return `Could not bundle ${this.entry}: ${causeMessage(this.cause) ?? String(this.cause)}`;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The output directory could not be cleaned.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
var CleanError = class extends Schema.TaggedError()("CleanError", {
|
|
26
|
+
/** The directory. */
|
|
27
|
+
directory: Schema.String,
|
|
28
|
+
/** What went wrong. */
|
|
29
|
+
cause: Schema.Defect()
|
|
30
|
+
}) {
|
|
31
|
+
get message() {
|
|
32
|
+
return `Could not clean ${this.directory}: ${causeMessage(this.cause) ?? String(this.cause)}`;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* An output file could not be written.
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
var WriteError = class extends Schema.TaggedError()("WriteError", {
|
|
41
|
+
/** The file. */
|
|
42
|
+
path: Schema.String,
|
|
43
|
+
/** What went wrong. */
|
|
44
|
+
cause: Schema.Defect()
|
|
45
|
+
}) {
|
|
46
|
+
get message() {
|
|
47
|
+
return `Could not write ${this.path}: ${causeMessage(this.cause) ?? String(this.cause)}`;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* A file could not be copied to the local action directory.
|
|
52
|
+
*
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
var PersistLocalError = class extends Schema.TaggedError()("PersistLocalError", {
|
|
56
|
+
/** The path involved. */
|
|
57
|
+
path: Schema.String,
|
|
58
|
+
/** What went wrong. */
|
|
59
|
+
cause: Schema.Defect()
|
|
60
|
+
}) {
|
|
61
|
+
get message() {
|
|
62
|
+
return `Could not persist ${this.path}: ${causeMessage(this.cause) ?? String(this.cause)}`;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* A `runs` path in `action.yml` names no file in the local action directory.
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
var ActionYmlPathError = class extends Schema.TaggedError()("ActionYmlPathError", {
|
|
71
|
+
/** The `runs` key: `main`, `pre` or `post`. */
|
|
72
|
+
entryType: Schema.String,
|
|
73
|
+
/** The path as `action.yml` writes it. */
|
|
74
|
+
specifiedPath: Schema.String,
|
|
75
|
+
/** Where that path resolves to. */
|
|
76
|
+
expectedPath: Schema.String
|
|
77
|
+
}) {
|
|
78
|
+
get message() {
|
|
79
|
+
return `action.yml runs.${this.entryType} is ${this.specifiedPath}, and ${this.expectedPath} does not exist`;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export { ActionYmlPathError, BundleFailed, CleanError, PersistLocalError, WriteError };
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { ActionYml } from "./ActionYml.js";
|
|
2
|
+
import { invalidWorkerName } from "./entries.js";
|
|
3
|
+
import { Effect, FileSystem, Option, Path, Result, Schema } from "effect";
|
|
4
|
+
import { RuntimeEnv } from "@effected/env";
|
|
5
|
+
import { Yaml } from "@effected/yaml";
|
|
6
|
+
|
|
7
|
+
// src/action/ActionValidation.ts
|
|
8
|
+
/**
|
|
9
|
+
* One problem a validation found.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
var ValidationIssue = class extends Schema.Class("ValidationIssue")({
|
|
14
|
+
/** What kind of problem it is, such as `MAIN_ENTRY_MISSING`. */
|
|
15
|
+
code: Schema.String,
|
|
16
|
+
/** What went wrong. */
|
|
17
|
+
message: Schema.String,
|
|
18
|
+
/** The file at fault. */
|
|
19
|
+
file: Schema.optionalKey(Schema.String),
|
|
20
|
+
/** How to fix it. */
|
|
21
|
+
suggestion: Schema.optionalKey(Schema.String)
|
|
22
|
+
}) {};
|
|
23
|
+
/**
|
|
24
|
+
* What a validation found.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
var ValidationResult = class extends Schema.Class("ValidationResult")({
|
|
29
|
+
/** Whether the build may go ahead: no errors, and in strict mode no warnings either. */
|
|
30
|
+
valid: Schema.Boolean,
|
|
31
|
+
/** Problems that always stop a build. */
|
|
32
|
+
errors: Schema.Array(ValidationIssue),
|
|
33
|
+
/** Problems that stop a build only in strict mode. */
|
|
34
|
+
warnings: Schema.Array(ValidationIssue)
|
|
35
|
+
}) {};
|
|
36
|
+
const UNIT_BYTES = {
|
|
37
|
+
b: 1,
|
|
38
|
+
kb: 1024,
|
|
39
|
+
mb: 1024 ** 2,
|
|
40
|
+
gb: 1024 ** 3
|
|
41
|
+
};
|
|
42
|
+
/** A size such as `"5mb"` in bytes, counting 1024 to the next unit, or `undefined` when it does not read as one. */
|
|
43
|
+
const parseSize = (size) => {
|
|
44
|
+
const match = /^(\d+(?:\.\d+)?)\s*(b|kb|mb|gb)$/i.exec(size.trim());
|
|
45
|
+
const unit = match?.[2]?.toLowerCase();
|
|
46
|
+
return match?.[1] === void 0 || unit === void 0 ? void 0 : Number(match[1]) * (UNIT_BYTES[unit] ?? 1);
|
|
47
|
+
};
|
|
48
|
+
const formatBytes = (bytes) => {
|
|
49
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
50
|
+
return bytes < 1048576 ? `${(bytes / 1024).toFixed(1)} KB` : `${(bytes / 1048576).toFixed(1)} MB`;
|
|
51
|
+
};
|
|
52
|
+
const issue = (code, message, file, suggestion) => ValidationIssue.make({
|
|
53
|
+
code,
|
|
54
|
+
message,
|
|
55
|
+
...file !== void 0 ? { file } : {},
|
|
56
|
+
...suggestion !== void 0 ? { suggestion } : {}
|
|
57
|
+
});
|
|
58
|
+
/** Recommended fields a valid `action.yml` still leaves out. */
|
|
59
|
+
const recommendations = (content, file) => {
|
|
60
|
+
const warnings = [];
|
|
61
|
+
if (!content.branding) warnings.push(issue("ACTION_YML_NO_BRANDING", "No branding configuration found", file, "Add branding.icon and branding.color for better marketplace visibility"));
|
|
62
|
+
else {
|
|
63
|
+
const branding = content.branding;
|
|
64
|
+
if (!branding.icon) warnings.push(issue("ACTION_YML_NO_BRANDING_ICON", "Branding icon not specified", file, "Add branding.icon for better marketplace visibility"));
|
|
65
|
+
if (!branding.color) warnings.push(issue("ACTION_YML_NO_BRANDING_COLOR", "Branding color not specified", file, "Add branding.color for better marketplace visibility"));
|
|
66
|
+
}
|
|
67
|
+
const described = (key) => Object.entries(content[key] ?? {});
|
|
68
|
+
for (const [name, input] of described("inputs")) if (!input.description) warnings.push(issue("ACTION_YML_INPUT_NO_DESCRIPTION", `Input '${name}' has no description`, file, `Add a description for the '${name}' input`));
|
|
69
|
+
for (const [name, output] of described("outputs")) if (!output.description) warnings.push(issue("ACTION_YML_OUTPUT_NO_DESCRIPTION", `Output '${name}' has no description`, file, `Add a description for the '${name}' output`));
|
|
70
|
+
return warnings;
|
|
71
|
+
};
|
|
72
|
+
const checkActionYml = Effect.fnUntraced(function* (config, cwd) {
|
|
73
|
+
const errors = [];
|
|
74
|
+
const warnings = [];
|
|
75
|
+
if (!config.validation.requireActionYml) return {
|
|
76
|
+
errors,
|
|
77
|
+
warnings
|
|
78
|
+
};
|
|
79
|
+
const fs = yield* FileSystem.FileSystem;
|
|
80
|
+
const file = (yield* Path.Path).resolve(cwd, "action.yml");
|
|
81
|
+
if (!(yield* fs.exists(file))) {
|
|
82
|
+
warnings.push(issue("ACTION_YML_MISSING", "action.yml not found", file, "Create action.yml to define your action metadata"));
|
|
83
|
+
return {
|
|
84
|
+
errors,
|
|
85
|
+
warnings
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const parsed = Yaml.parseResult(yield* fs.readFileString(file));
|
|
89
|
+
if (Result.isFailure(parsed)) {
|
|
90
|
+
errors.push(issue("ACTION_YML_SYNTAX_ERROR", parsed.failure.message, file));
|
|
91
|
+
return {
|
|
92
|
+
errors,
|
|
93
|
+
warnings
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const content = parsed.success;
|
|
97
|
+
if (!content || typeof content !== "object") {
|
|
98
|
+
errors.push(issue("ACTION_YML_SYNTAX_ERROR", "action.yml must be an object", file));
|
|
99
|
+
return {
|
|
100
|
+
errors,
|
|
101
|
+
warnings
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const decoded = yield* Effect.result(Schema.decodeUnknownEffect(ActionYml)(content));
|
|
105
|
+
if (Result.isFailure(decoded)) {
|
|
106
|
+
errors.push(issue("ACTION_YML_SCHEMA_ERROR", decoded.failure.message, file));
|
|
107
|
+
return {
|
|
108
|
+
errors,
|
|
109
|
+
warnings
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
warnings.push(...recommendations(content, file));
|
|
113
|
+
return {
|
|
114
|
+
errors,
|
|
115
|
+
warnings
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
const checkEntries = Effect.fnUntraced(function* (config, cwd) {
|
|
119
|
+
const fs = yield* FileSystem.FileSystem;
|
|
120
|
+
const path = yield* Path.Path;
|
|
121
|
+
const errors = [];
|
|
122
|
+
const { main, pre, post, workers } = config.entries;
|
|
123
|
+
if (!(yield* fs.exists(path.resolve(cwd, main)))) errors.push(issue("MAIN_ENTRY_MISSING", `Main entry point not found: ${main}`, main, "Create src/main.ts or specify a different path in config"));
|
|
124
|
+
for (const [name, source] of [["pre", pre], ["post", post]]) if (source !== void 0 && !(yield* fs.exists(path.resolve(cwd, source)))) errors.push(issue("ENTRY_FILE_MISSING", `The ${name} entry point was not found: ${source}`, source, `Create ${source} or remove entries.${name} from the config`));
|
|
125
|
+
for (const [name, source] of Object.entries(workers)) {
|
|
126
|
+
const reason = invalidWorkerName(name);
|
|
127
|
+
if (reason !== void 0) errors.push(issue("WORKER_ENTRY_INVALID_NAME", `Invalid worker name "${name}": ${reason}`));
|
|
128
|
+
else if (!(yield* fs.exists(path.resolve(cwd, source)))) errors.push(issue("WORKER_ENTRY_MISSING", `Worker entry point not found: ${source}`, source, `Create ${source} or specify a different path for the '${name}' worker`));
|
|
129
|
+
}
|
|
130
|
+
return errors;
|
|
131
|
+
});
|
|
132
|
+
/**
|
|
133
|
+
* Checks an action's config, entry points and `action.yml`, and the size of what it built.
|
|
134
|
+
*
|
|
135
|
+
* @public
|
|
136
|
+
*/
|
|
137
|
+
var ActionValidation = class ActionValidation {
|
|
138
|
+
constructor() {}
|
|
139
|
+
/**
|
|
140
|
+
* Whether `env` describes a CI run, by `@effected/env`'s one rule: a known provider's marker, or a truthy `CI` or
|
|
141
|
+
* `CONTINUOUS_INTEGRATION`.
|
|
142
|
+
*/
|
|
143
|
+
static isCI(env) {
|
|
144
|
+
return Option.isSome(RuntimeEnv.fromRecord(env).ci);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Whether warnings stop this build: `validation.strict` when it is set, otherwise whether this is a CI run.
|
|
148
|
+
*/
|
|
149
|
+
static isStrict(config, options) {
|
|
150
|
+
return config.validation.strict ?? options.ci;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Validates the action at `cwd` before a build.
|
|
154
|
+
*
|
|
155
|
+
* @remarks
|
|
156
|
+
* Every finding comes back in the result, whatever its severity: the effect fails only when a file cannot be
|
|
157
|
+
* read. A missing `main`, a `pre`, `post` or worker the config names with no file, a bad worker name, an unreadable `maxBundleSize` and a broken
|
|
158
|
+
* `action.yml` are errors. A missing `action.yml` and missing recommended fields are warnings, and `valid` turns
|
|
159
|
+
* false on them in strict mode.
|
|
160
|
+
*
|
|
161
|
+
* @param cwd - The action's directory.
|
|
162
|
+
* @param options - `ci` says whether this run is under CI. Answer it once at `main`, with {@link ActionValidation.isCI}.
|
|
163
|
+
*/
|
|
164
|
+
static validate = Effect.fn("ActionValidation.validate")(function* (config, cwd, options) {
|
|
165
|
+
const entryErrors = yield* checkEntries(config, cwd);
|
|
166
|
+
const { maxBundleSize } = config.validation;
|
|
167
|
+
const sizeErrors = maxBundleSize !== void 0 && parseSize(maxBundleSize) === void 0 ? [issue("MAX_BUNDLE_SIZE_INVALID", `Cannot read maxBundleSize: ${maxBundleSize}`, void 0, "Write a size such as \"5mb\" or \"500kb\"")] : [];
|
|
168
|
+
const actionYml = yield* checkActionYml(config, cwd);
|
|
169
|
+
const errors = [
|
|
170
|
+
...entryErrors,
|
|
171
|
+
...sizeErrors,
|
|
172
|
+
...actionYml.errors
|
|
173
|
+
];
|
|
174
|
+
return ActionValidation.resultOf(errors, actionYml.warnings, ActionValidation.isStrict(config, options));
|
|
175
|
+
});
|
|
176
|
+
/**
|
|
177
|
+
* The bundles past `validation.maxBundleSize`, one warning each. Nothing when no limit is set or it cannot be read.
|
|
178
|
+
*/
|
|
179
|
+
static checkBundleSizes(config, bundles) {
|
|
180
|
+
const { maxBundleSize } = config.validation;
|
|
181
|
+
const limit = maxBundleSize === void 0 ? void 0 : parseSize(maxBundleSize);
|
|
182
|
+
if (maxBundleSize === void 0 || limit === void 0) return [];
|
|
183
|
+
return bundles.filter((bundle) => bundle.size > limit).map((bundle) => issue("MAX_BUNDLE_SIZE_EXCEEDED", `Bundle '${bundle.entry}' is ${formatBytes(bundle.size)}, past the ${maxBundleSize} limit`, bundle.outputPath, "Raise validation.maxBundleSize, or move a dependency to build.externals or build.ignore"));
|
|
184
|
+
}
|
|
185
|
+
/** A result from its findings: valid with no errors, and in strict mode no warnings either. */
|
|
186
|
+
static resultOf(errors, warnings, strict) {
|
|
187
|
+
return ValidationResult.make({
|
|
188
|
+
valid: errors.length === 0 && (!strict || warnings.length === 0),
|
|
189
|
+
errors,
|
|
190
|
+
warnings
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export { ActionValidation, ValidationIssue, ValidationResult };
|