@dual-os/cli 0.12.2 → 0.13.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/dist/openapi/emit.d.ts +1 -1
- package/dist/openapi/emit.d.ts.map +1 -1
- package/dist/openapi/emit.js +20 -19
- package/dist/openapi/emit.js.map +1 -1
- package/dist/openapi/schema.d.ts.map +1 -1
- package/dist/openapi/schema.js +3 -2
- package/dist/openapi/schema.js.map +1 -1
- package/dist/plugin/bundle.d.ts.map +1 -1
- package/dist/plugin/bundle.js +15 -6
- package/dist/plugin/bundle.js.map +1 -1
- package/package.json +4 -4
- package/src/openapi/emit.ts +37 -24
- package/src/openapi/schema.ts +3 -2
- package/src/plugin/bundle.ts +34 -6
package/dist/plugin/bundle.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PackageError } from "./package.js";
|
|
1
|
+
import { PackageError, fromCause } from "./package.js";
|
|
2
2
|
import { createRequire, isBuiltin } from "node:module";
|
|
3
3
|
import { Array, Effect, FileSystem, MutableHashMap, MutableList, Order, Path, Predicate, Record, Schema } from "effect";
|
|
4
4
|
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
@@ -254,16 +254,25 @@ const make = Effect.gen(function* () {
|
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
if (source.startsWith(`${input}${path.sep}`)) continue;
|
|
257
|
+
const segments = source.split(path.sep);
|
|
258
|
+
const modules = segments.lastIndexOf("node_modules");
|
|
259
|
+
const packageRoot = modules === -1 ? void 0 : Array.join(segments.slice(0, modules + (segments[modules + 1]?.startsWith("@") ? 3 : 2)), path.sep);
|
|
257
260
|
const owner = Effect.fnUntraced(function* (directory) {
|
|
258
|
-
|
|
261
|
+
const manifest = path.join(directory, "package.json");
|
|
262
|
+
if (yield* fs.exists(manifest)) {
|
|
263
|
+
if (packageRoot) return directory;
|
|
264
|
+
const candidate = yield* Schema.decodeEffect(Schema.fromJsonString(Schema.JsonObject))(yield* fs.readFileString(manifest)).pipe(Effect.mapError((cause) => fromCause(cause, `Invalid dependency manifest ${manifest} for ${source}`)));
|
|
265
|
+
if (Object.hasOwn(candidate, "name")) return directory;
|
|
266
|
+
}
|
|
259
267
|
const parent = path.dirname(directory);
|
|
260
|
-
if (parent === directory) return yield* PackageError.make({ message: `Dependency has no package manifest: ${source}` });
|
|
268
|
+
if (parent === directory || directory === packageRoot) return yield* PackageError.make({ message: `Dependency has no package manifest: ${source}; searched ${manifest}` });
|
|
261
269
|
return yield* owner(parent);
|
|
262
270
|
});
|
|
263
|
-
const directory = yield* owner(path.dirname(source));
|
|
271
|
+
const directory = yield* owner(packageRoot ?? path.dirname(source));
|
|
264
272
|
if (MutableHashMap.has(packages, directory)) continue;
|
|
265
|
-
const
|
|
266
|
-
|
|
273
|
+
const manifest = path.join(directory, "package.json");
|
|
274
|
+
const pkg = yield* json(manifest).pipe(Effect.mapError((cause) => fromCause(cause, `Invalid dependency manifest ${manifest} for ${source}`)));
|
|
275
|
+
if (!pkg.name || !pkg.license) return yield* PackageError.make({ message: `Dependency lacks name/license metadata: ${manifest} for ${source}` });
|
|
267
276
|
const licenseFiles = (yield* fs.glob("{LICENSE,LICENCE,COPYING,NOTICE}{,.md,.txt}", { root: directory })).sort();
|
|
268
277
|
if (Array.isArrayEmpty(licenseFiles)) return yield* PackageError.make({ message: `Dependency attribution missing: ${pkg.name}@${pkg.version}` });
|
|
269
278
|
const licenses = MutableList.make();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.js","names":[],"sources":["../../src/plugin/bundle.ts"],"sourcesContent":["import { createRequire, isBuiltin } from \"node:module\";\n\nimport type { PlatformError } from \"effect\";\nimport {\n Array,\n Effect,\n FileSystem,\n MutableHashMap,\n MutableList,\n Order,\n Path,\n Predicate,\n Record,\n Schema,\n} from \"effect\";\n\nimport * as acorn from \"acorn\";\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\";\n\nimport { ReleaseManifest } from \"#release/release-manifest\";\n\nimport { PluginPackage } from \"./package.ts\";\n\nconst Import = Schema.Struct({ path: Schema.String, external: Schema.optionalKey(Schema.Boolean) });\nconst Metafile = Schema.Struct({\n inputs: Schema.Record(Schema.String, Schema.Struct({ imports: Schema.Array(Import) })),\n outputs: Schema.Record(\n Schema.String,\n Schema.Struct({\n imports: Schema.Array(Import),\n inputs: Schema.Record(Schema.String, Schema.Struct({ bytesInOutput: Schema.Number })),\n entryPoint: Schema.optionalKey(Schema.String),\n }),\n ),\n});\nconst Metadata = Schema.StructWithRest(\n Schema.Struct({\n name: Schema.optionalKey(Schema.String),\n version: ReleaseManifest.ExactVersion,\n license: Schema.optionalKey(Schema.String),\n exports: Schema.optionalKey(Schema.Json),\n }),\n [Schema.Record(Schema.String, Schema.Json)],\n);\n\nfunction targets(value: Schema.Json): string[] {\n if (typeof value === \"string\") return [value];\n if (value === null) return [];\n if (typeof value !== \"object\")\n throw PluginPackage.PackageError.make({ message: \"Unsupported package exports\" });\n return Array.flatMap(Object.values(value), targets);\n}\n\nfunction pattern(expression: acorn.Expression | acorn.SpreadElement): string {\n if (expression.type === \"Literal\" && typeof expression.value === \"string\")\n return expression.value;\n if (\n expression.type === \"BinaryExpression\" &&\n expression.operator === \"+\" &&\n expression.left.type !== \"PrivateIdentifier\"\n )\n return pattern(expression.left) + pattern(expression.right);\n if (expression.type === \"TemplateLiteral\")\n return Array.join(\n Array.map(expression.quasis, part => part.value.cooked ?? part.value.raw),\n \"*\",\n );\n return \"*\";\n}\n\nfunction isNode(value: unknown): value is acorn.AnyNode {\n return (\n Predicate.isObject(value) &&\n Predicate.isString(value[\"type\"]) &&\n Predicate.isNumber(value[\"start\"]) &&\n Predicate.isNumber(value[\"end\"])\n );\n}\n\n// Acorn owns the node shapes; traversing the AST also handles chained import().then() calls.\nfunction references(code: string) {\n const tree = acorn.parse(code, {\n ecmaVersion: \"latest\",\n sourceType: \"module\",\n allowReturnOutsideFunction: true,\n });\n const found = MutableList.make<{\n kind: \"import\" | \"require\" | \"resolve\" | \"asset\";\n path: string;\n }>();\n const visit = (\n expression: acorn.AnyNode,\n parent?: acorn.AnyNode,\n grandparent?: acorn.AnyNode,\n ): void => {\n if (expression.type === \"ImportExpression\")\n MutableList.append(found, { kind: \"import\" as const, path: pattern(expression.source) });\n if (\n expression.type === \"CallExpression\" &&\n expression.callee.type === \"Identifier\" &&\n Array.contains([\"require\", \"__require\"], expression.callee.name) &&\n expression.arguments[0]\n )\n MutableList.append(found, {\n kind: \"require\" as const,\n path: pattern(expression.arguments[0]),\n });\n if (\n expression.type === \"CallExpression\" &&\n expression.callee.type === \"MemberExpression\" &&\n expression.callee.object.type === \"MetaProperty\" &&\n expression.callee.object.meta.name === \"import\" &&\n expression.callee.property.type === \"Identifier\" &&\n Array.contains([\"resolve\", \"require\"], expression.callee.property.name) &&\n expression.arguments[0]\n )\n MutableList.append(found, {\n kind: \"resolve\" as const,\n path: pattern(expression.arguments[0]),\n });\n if (\n expression.type === \"ImportSpecifier\" &&\n expression.imported.type === \"Identifier\" &&\n expression.imported.name === \"createRequire\" &&\n parent?.type === \"ImportDeclaration\" &&\n Array.contains([\"node:module\", \"module\"], parent.source.value)\n )\n MutableList.append(found, { kind: \"resolve\" as const, path: \"createRequire\" });\n if (\n ((expression.type === \"ImportNamespaceSpecifier\" ||\n expression.type === \"ImportDefaultSpecifier\") &&\n parent?.type === \"ImportDeclaration\" &&\n Array.contains([\"node:module\", \"module\"], parent.source.value)) ||\n (expression.type === \"ImportExpression\" &&\n Array.contains([\"node:module\", \"module\"], pattern(expression.source))) ||\n (expression.type === \"CallExpression\" &&\n expression.callee.type === \"Identifier\" &&\n Array.contains([\"require\", \"__require\"], expression.callee.name) &&\n expression.arguments[0] &&\n Array.contains([\"node:module\", \"module\"], pattern(expression.arguments[0])))\n )\n MutableList.append(found, { kind: \"resolve\" as const, path: \"module namespace\" });\n if (expression.type === \"NewExpression\") {\n const base = expression.arguments[1];\n if (\n expression.callee.type === \"Identifier\" &&\n expression.callee.name === \"URL\" &&\n base?.type === \"MemberExpression\" &&\n base.object.type === \"MetaProperty\" &&\n base.object.meta.name === \"import\" &&\n base.object.property.name === \"meta\" &&\n base.property.type === \"Identifier\" &&\n base.property.name === \"url\" &&\n expression.arguments[0]\n ) {\n const receiver = parent?.type === \"MemberExpression\" ? parent : expression;\n const call = receiver === parent ? grandparent : parent;\n const method = call?.type === \"CallExpression\" ? call.callee : undefined;\n const name =\n method?.type === \"Identifier\"\n ? method.name\n : method?.type === \"MemberExpression\" && method.property.type === \"Identifier\"\n ? method.property.name\n : \"\";\n const writing =\n call?.type === \"CallExpression\" &&\n call.arguments[0] === receiver &&\n Array.contains(\n [\n \"writeFile\",\n \"writeFileSync\",\n \"writeFileString\",\n \"appendFile\",\n \"appendFileSync\",\n \"makeDirectory\",\n \"mkdir\",\n \"mkdirSync\",\n ],\n name,\n );\n if (!writing)\n MutableList.append(found, {\n kind: \"asset\" as const,\n path: pattern(expression.arguments[0]),\n });\n }\n }\n const fields: unknown[] = Object.values(expression);\n for (const field of fields) {\n if (isNode(field)) visit(field, expression, parent);\n else if (Array.isArray(field))\n for (const child of field) if (isNode(child)) visit(child, expression, parent);\n }\n };\n visit(tree);\n return MutableList.toArray(found);\n}\n\nexport const make = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;\n return Effect.fn(\"PluginBundle.build\")(function* (\n root: string,\n prepared: PluginPackage.Prepared,\n ) {\n const json = Effect.fnUntraced(function* (file: string) {\n return yield* Schema.decodeEffect(Schema.fromJsonString(Metadata))(\n yield* fs.readFileString(file),\n );\n });\n const manifest = yield* json(path.join(root, \"package.json\"));\n const require = createRequire(prepared.entrypoint);\n const sdkRoot = path.dirname(require.resolve(\"@dual-os/sdk/package.json\"));\n const sdk = yield* json(path.join(sdkRoot, \"package.json\"));\n const sdkRunner = yield* fs.realPath(require.resolve(\"@dual-os/sdk/Runner\"));\n const input = path.join(root, \".dual/bundle-input\");\n const output = path.join(root, \".dual/bundle-output\");\n for (const directory of [input, output]) {\n if (yield* fs.exists(directory)) yield* fs.remove(directory, { recursive: true });\n yield* fs.makeDirectory(directory, { recursive: true });\n }\n const safe = Effect.fnUntraced(function* (name: string) {\n const relative = path.relative(root, path.resolve(root, name));\n if (\n relative === \"\" ||\n relative.startsWith(\"..\") ||\n path.isAbsolute(relative) ||\n Array.some(\n relative.split(path.sep),\n part =>\n [\"node_modules\", \".dual\", \".env\", \".npmrc\", \".netrc\"].includes(part) ||\n part.startsWith(\".env.\"),\n )\n )\n return yield* PluginPackage.PackageError.make({ message: `Unsafe bundle path: ${name}` });\n const source = path.resolve(root, name);\n const real = yield* fs.realPath(source);\n if (!real.startsWith(`${root}${path.sep}`))\n return yield* PluginPackage.PackageError.make({\n message: `Bundle file escapes the package: ${name}`,\n });\n return { source, relative };\n });\n const copy = Effect.fnUntraced(function* (name: string, destination: string) {\n const file = yield* safe(name);\n if ((yield* fs.stat(file.source)).type !== \"File\")\n return yield* PluginPackage.PackageError.make({\n message: `Bundle export must be a file: ${name}`,\n });\n const bytes = yield* fs.readFile(file.source);\n if (/\\.[cm]?tsx?$/u.test(name) && !/\\.d\\.[cm]?ts$/u.test(name))\n return yield* PluginPackage.PackageError.make({\n message: `Source exports/assets cannot be shipped in a JavaScript bundle: ${name}`,\n });\n const prefix = Buffer.from(bytes.subarray(0, 4));\n if (\n /\\.(?:node|dll|dylib|exe|so(?:\\.[0-9.]+)?)$|(?:^|\\/)binding\\.gyp$/iu.test(name) ||\n (prefix.length === 4 &&\n [\n 0x7f454c46, 0xfeedface, 0xcefaedfe, 0xfeedfacf, 0xcffaedfe, 0xcafebabe, 0xbebafeca,\n ].includes(prefix.readUInt32BE(0))) ||\n (prefix.length >= 2 && prefix.readUInt16BE(0) === 0x4d5a)\n )\n return yield* PluginPackage.PackageError.make({\n message: `Native bundle content is unsupported: ${name}`,\n });\n yield* fs.makeDirectory(path.dirname(path.join(destination, file.relative)), {\n recursive: true,\n });\n yield* fs.copyFile(file.source, path.join(destination, file.relative));\n });\n const publicFiles = MutableList.make<string>();\n for (const target of yield* Effect.try(() => targets(manifest.exports ?? {}))) {\n const matches = yield* fs.glob(target, { root });\n if (Array.isArrayEmpty(matches))\n return yield* PluginPackage.PackageError.make({\n message: `Missing public export: ${target}`,\n });\n MutableList.appendAll(publicFiles, matches);\n }\n const declared = Array.dedupe([\n ...MutableList.toArray(publicFiles),\n path.relative(root, prepared.entrypoint),\n ...Array.map(prepared.assets, file => path.relative(root, file)),\n ]);\n // Static helpers can live above any public entrypoint; only the bundler's reachable graph ships.\n const declarations = MutableList.make<string>();\n for (const file of yield* fs.glob(\"**/*\", {\n root,\n exclude: [\"node_modules/**\", \".dual/**\", \".git/**\"],\n })) {\n const source = path.join(root, file);\n if ((yield* fs.stat(source)).type !== \"File\") continue;\n if (/\\.d\\.[cm]?ts(?:\\.map)?$/u.test(file)) {\n yield* copy(file, output);\n MutableList.append(declarations, file);\n }\n if (\n /\\.(?:[cm]?js|json|map)$/.test(file) &&\n !Array.some(file.split(\"/\"), part => part.startsWith(\".\"))\n )\n yield* copy(path.relative(root, source), input);\n }\n for (const file of declared) {\n yield* copy(file, input);\n if (!/\\.(?:[cm]?js)$/.test(file)) yield* copy(file, output);\n }\n for (const file of [\"README.md\", \"LICENSE\", \"LICENSE.md\", \"LICENSE.txt\"]) {\n if (yield* fs.exists(path.join(root, file))) yield* copy(file, output);\n }\n yield* fs.writeFileString(\n path.join(input, \"package.json\"),\n yield* fs.readFileString(path.join(root, \"package.json\")),\n );\n // Resolve the same installed graph as the source package, including workspace hoisting.\n const modules = Effect.fnUntraced(function* (\n directory: string,\n ): Effect.fn.Return<string, PlatformError.PlatformError | PluginPackage.PackageError> {\n if (yield* fs.exists(path.join(directory, \"node_modules\")))\n return path.join(directory, \"node_modules\");\n const parent = path.dirname(directory);\n if (parent === directory)\n return yield* PluginPackage.PackageError.make({\n message: \"Install build dependencies from a frozen lockfile first\",\n });\n return yield* modules(parent);\n });\n yield* fs.symlink(yield* modules(root), path.join(input, \"node_modules\"));\n const runnerName = Effect.fnUntraced(function* (\n index: number,\n ): Effect.fn.Return<string, PlatformError.PlatformError> {\n const name = index === 0 ? \"Runner.js\" : `Runner-${index}.js`;\n return (yield* fs.exists(path.join(input, name))) ? yield* runnerName(index + 1) : name;\n });\n const runner = yield* runnerName(0);\n yield* fs.writeFileString(\n path.join(input, runner),\n 'export { load } from \"@dual-os/sdk/Runner\";\\n',\n );\n const entries = Array.dedupe([\n ...Array.filter(declared, file => /\\.(?:[cm]?js)$/.test(file)),\n runner,\n ]);\n const metaPath = path.join(root, \".dual/bundle-metafile.json\");\n const code = yield* spawner.exitCode(\n ChildProcess.make(\n \"bun\",\n [\n \"build\",\n \"--no-env-file\",\n \"--target=bun\",\n \"--format=esm\",\n \"--splitting\",\n \"--keep-names\",\n \"--sourcemap=linked\",\n `--metafile=${metaPath}`,\n \"--root\",\n input,\n \"--outdir\",\n output,\n ...Array.map(entries, file => path.resolve(input, file)),\n ],\n { cwd: input, stdin: \"ignore\", stdout: \"ignore\", stderr: \"inherit\" },\n ),\n );\n if (code !== 0)\n return yield* PluginPackage.PackageError.make({\n message: \"Self-contained plugin compilation failed; no installation fallback is available\",\n });\n const meta = yield* Schema.decodeEffect(Schema.fromJsonString(Metafile))(\n yield* fs.readFileString(metaPath),\n );\n const emitted = Record.fromEntries(\n Array.flatMap(Object.entries(meta.outputs), entry =>\n entry[1].entryPoint\n ? [\n [\n path.relative(input, path.resolve(input, entry[1].entryPoint)),\n entry[0].replace(/^\\.\\//u, \"\"),\n ] as const,\n ]\n : [],\n ),\n );\n const rewrite = (value: Schema.Json): Schema.Json => {\n if (typeof value === \"string\")\n return emitted[path.normalize(value)]\n ? `./${emitted[path.normalize(value)]}`\n : value.replace(/\\.[cm]js$/u, \".js\");\n if (value === null || typeof value !== \"object\") return value;\n if (Array.isArray<Schema.Json>(value)) return Array.map(value, rewrite);\n return Record.map(value, rewrite);\n };\n const packages = MutableHashMap.empty<\n string,\n { name: string; version: string; license: string; licenses: string[] }\n >();\n const contributing = Array.dedupe(\n Array.flatMap(Object.values(meta.outputs), result =>\n Array.map(\n Array.filter(Object.entries(result.inputs), entry => entry[1].bytesInOutput > 0),\n entry => entry[0],\n ),\n ),\n );\n for (const file of contributing) {\n const source = yield* fs.realPath(path.resolve(input, file));\n const body = yield* fs.readFileString(source);\n for (const reference of /\\.[cm]?js$/.test(source)\n ? yield* Effect.try(() => references(body))\n : []) {\n if (\n reference.kind === \"resolve\" &&\n Array.contains([\"createRequire\", \"module namespace\"], reference.path)\n )\n continue;\n if (reference.kind === \"import\" && source === sdkRunner) continue;\n if (isBuiltin(reference.path) || reference.path.startsWith(\"bun:\")) continue;\n if (reference.kind === \"asset\" && /^(?!file:)[a-z][a-z\\d+.-]*:/iu.test(reference.path))\n continue;\n if (reference.kind === \"resolve\")\n return yield* PluginPackage.PackageError.make({\n message: `Runtime package resolution cannot be bundled in ${file}: ${reference.path}; use an import instead`,\n });\n if (reference.kind !== \"asset\" && !reference.path.includes(\"*\")) continue;\n if (reference.kind === \"require\")\n return yield* PluginPackage.PackageError.make({\n message: `Unresolved computed require in ${file}; use finite imports and declare dual.plugin.assets`,\n });\n if (!reference.path.startsWith(\".\"))\n return yield* PluginPackage.PackageError.make({\n message: `Unresolved dynamic import/resource in ${file}: ${reference.path}. Declare finite relative files in dual.plugin.assets.`,\n });\n const matches = yield* fs.glob(reference.path, { root: path.dirname(source) });\n if (Array.isArrayEmpty(matches))\n return yield* PluginPackage.PackageError.make({\n message: `Missing dynamic import/resource in ${file}: ${reference.path}`,\n });\n if (reference.path.includes(\"*\"))\n for (const match of matches) {\n const relative = path.relative(input, path.resolve(path.dirname(source), match));\n if (!Array.some(declared, name => path.normalize(name) === relative))\n return yield* PluginPackage.PackageError.make({\n message: `Declare dynamic file in dual.plugin.assets: ${relative}`,\n });\n }\n }\n if (source.startsWith(`${input}${path.sep}`)) continue;\n const owner = Effect.fnUntraced(function* (\n directory: string,\n ): Effect.fn.Return<string, PlatformError.PlatformError | PluginPackage.PackageError> {\n if (yield* fs.exists(path.join(directory, \"package.json\"))) return directory;\n const parent = path.dirname(directory);\n if (parent === directory)\n return yield* PluginPackage.PackageError.make({\n message: `Dependency has no package manifest: ${source}`,\n });\n return yield* owner(parent);\n });\n const directory = yield* owner(path.dirname(source));\n if (MutableHashMap.has(packages, directory)) continue;\n const pkg = yield* json(path.join(directory, \"package.json\"));\n if (!pkg.name || !pkg.license)\n return yield* PluginPackage.PackageError.make({\n message: `Dependency lacks name/license metadata: ${directory}`,\n });\n const licenseFiles = (yield* fs.glob(\"{LICENSE,LICENCE,COPYING,NOTICE}{,.md,.txt}\", {\n root: directory,\n })).sort();\n if (Array.isArrayEmpty(licenseFiles))\n return yield* PluginPackage.PackageError.make({\n message: `Dependency attribution missing: ${pkg.name}@${pkg.version}`,\n });\n const licenses = MutableList.make<string>();\n for (const license of licenseFiles) {\n if ((yield* fs.stat(path.join(directory, license))).size === 0n)\n return yield* PluginPackage.PackageError.make({\n message: `Empty dependency attribution: ${pkg.name}@${pkg.version}: ${license}`,\n });\n const target = `licenses/${pkg.name.replaceAll(\"/\", \"_\")}@${pkg.version}/${license}`;\n yield* fs.makeDirectory(path.dirname(path.join(output, target)), { recursive: true });\n yield* fs.copyFile(path.join(directory, license), path.join(output, target));\n MutableList.append(licenses, target);\n }\n MutableHashMap.set(packages, directory, {\n name: pkg.name,\n version: pkg.version,\n license: pkg.license,\n licenses: MutableList.toArray(licenses),\n });\n }\n for (const [file, metadata] of Object.entries(meta.outputs)) {\n for (const imported of metadata.imports) {\n if (isBuiltin(imported.path) || imported.path.startsWith(\"bun:\")) continue;\n if (\n imported.external ||\n !imported.path.startsWith(\".\") ||\n !(yield* fs.exists(path.resolve(output, imported.path)))\n )\n return yield* PluginPackage.PackageError.make({\n message: `Unbundled dependency in ${file}: ${imported.path}`,\n });\n }\n if (!/\\.[cm]?js$/.test(file)) continue;\n const outputCode = yield* fs.readFileString(path.resolve(output, file));\n for (const reference of yield* Effect.try(() => references(outputCode))) {\n if (\n reference.kind === \"resolve\" &&\n Array.contains([\"createRequire\", \"module namespace\"], reference.path)\n )\n return yield* PluginPackage.PackageError.make({\n message: `Runtime package resolution cannot be bundled in ${file}: ${reference.path}; use static named imports instead`,\n });\n if (\n reference.kind === \"require\" &&\n !isBuiltin(reference.path) &&\n !reference.path.startsWith(\"bun:\")\n )\n return yield* PluginPackage.PackageError.make({\n message: `Unbundled require in ${file}: ${reference.path}; no installation fallback is available`,\n });\n if (\n reference.kind === \"import\" &&\n reference.path.startsWith(\".\") &&\n reference.path.includes(\"*\") &&\n Array.isArrayEmpty(\n yield* fs.glob(reference.path, { root: path.resolve(output, path.dirname(file)) }),\n )\n )\n return yield* PluginPackage.PackageError.make({\n message: `Bundle dynamic import is missing after splitting: ${file}: ${reference.path}`,\n });\n if (reference.kind !== \"asset\") continue;\n if (/^(?!file:)[a-z][a-z\\d+.-]*:/iu.test(reference.path)) continue;\n if (!(yield* fs.exists(path.resolve(output, path.dirname(file), reference.path))))\n return yield* PluginPackage.PackageError.make({\n message: `Bundle resource is missing after splitting: ${file}: ${reference.path}`,\n });\n }\n }\n return {\n output,\n sdkVersion: sdk.version,\n runner: emitted[runner] ?? runner,\n manifest: { ...manifest, exports: rewrite(manifest.exports ?? {}) },\n entrypoint:\n emitted[path.relative(root, prepared.entrypoint)] ??\n path.relative(root, prepared.entrypoint),\n assets: Array.dedupe([\n ...Array.map(prepared.assets, file => {\n const relative = path.relative(root, file);\n return emitted[relative] ?? relative;\n }),\n ...MutableList.toArray(declarations),\n ...Array.filter(MutableList.toArray(publicFiles), file => !/\\.[cm]?js$/u.test(file)),\n ...Array.map(\n Array.filter(Object.keys(meta.outputs), file => !/\\.[cm]?js$/u.test(file)),\n file => file.replace(/^\\.\\//u, \"\"),\n ),\n ]),\n publicJavaScript: Array.map(\n Array.filter(MutableList.toArray(publicFiles), file => /\\.[cm]?js$/u.test(file)),\n source => ({ source, output: emitted[path.normalize(source)] ?? source }),\n ),\n packages: Array.sort(\n Array.fromIterable(MutableHashMap.values(packages)),\n Order.mapInput(\n Order.String,\n (pkg: { name: string; version: string }) => `${pkg.name}@${pkg.version}`,\n ),\n ),\n };\n });\n});\n"],"mappings":";;;;;;;AAuBA,MAAM,SAAS,OAAO,OAAO;CAAE,MAAM,OAAO;CAAQ,UAAU,OAAO,YAAY,OAAO,OAAO;AAAE,CAAC;AAClG,MAAM,WAAW,OAAO,OAAO;CAC7B,QAAQ,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,EAAE,SAAS,OAAO,MAAM,MAAM,EAAE,CAAC,CAAC;CACrF,SAAS,OAAO,OACd,OAAO,QACP,OAAO,OAAO;EACZ,SAAS,OAAO,MAAM,MAAM;EAC5B,QAAQ,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,EAAE,eAAe,OAAO,OAAO,CAAC,CAAC;EACpF,YAAY,OAAO,YAAY,OAAO,MAAM;CAC9C,CAAC,CACH;AACF,CAAC;AACD,MAAM,WAAW,OAAO,eACtB,OAAO,OAAO;CACZ,MAAM,OAAO,YAAY,OAAO,MAAM;CACtC,SAAS,gBAAgB;CACzB,SAAS,OAAO,YAAY,OAAO,MAAM;CACzC,SAAS,OAAO,YAAY,OAAO,IAAI;AACzC,CAAC,GACD,CAAC,OAAO,OAAO,OAAO,QAAQ,OAAO,IAAI,CAAC,CAC5C;AAEA,SAAS,QAAQ,OAA8B;CAC7C,IAAI,OAAO,UAAU,UAAU,OAAO,CAAC,KAAK;CAC5C,IAAI,UAAU,MAAM,OAAO,CAAC;CAC5B,IAAI,OAAO,UAAU,UACnB,MAAA,aAAiC,KAAK,EAAE,SAAS,8BAA8B,CAAC;CAClF,OAAO,MAAM,QAAQ,OAAO,OAAO,KAAK,GAAG,OAAO;AACpD;AAEA,SAAS,QAAQ,YAA4D;CAC3E,IAAI,WAAW,SAAS,aAAa,OAAO,WAAW,UAAU,UAC/D,O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AM,IAAI,SAAS,SAAQ,SAAQ;KACpC,MAAM,WAAW,KAAK,SAAS,MAAM,IAAI;KACzC,OAAO,QAAQ,aAAa;IAC9B,CAAC;IACD,GAAG,YAAY,QAAQ,YAAY;IACnC,GAAG,MAAM,OAAO,YAAY,QAAQ,WAAW,IAAG,SAAQ,CAAC,cAAc,KAAK,IAAI,CAAC;IACnF,GAAG,MAAM,IACP,MAAM,OAAO,OAAO,KAAK,KAAK,OAAO,IAAG,SAAQ,CAAC,cAAc,KAAK,IAAI,CAAC,IACzE,SAAQ,KAAK,QAAQ,UAAU,EAAE,CACnC;GACF,CAAC;GACD,kBAAkB,MAAM,IACtB,MAAM,OAAO,YAAY,QAAQ,WAAW,IAAG,SAAQ,cAAc,KAAK,IAAI,CAAC,IAC/E,YAAW;IAAE;IAAQ,QAAQ,QAAQ,KAAK,UAAU,MAAM,MAAM;GAAO,EACzE;GACA,UAAU,MAAM,KACd,MAAM,aAAa,eAAe,OAAO,QAAQ,CAAC,GAClD,MAAM,SACJ,MAAM,SACL,QAA2C,GAAG,IAAI,KAAK,GAAG,IAAI,SACjE,CACF;EACF;CACF,CAAC;AACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"bundle.js","names":["PluginPackage.fromCause"],"sources":["../../src/plugin/bundle.ts"],"sourcesContent":["import { createRequire, isBuiltin } from \"node:module\";\n\nimport type { PlatformError } from \"effect\";\nimport {\n Array,\n Effect,\n FileSystem,\n MutableHashMap,\n MutableList,\n Order,\n Path,\n Predicate,\n Record,\n Schema,\n} from \"effect\";\n\nimport * as acorn from \"acorn\";\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\";\n\nimport { ReleaseManifest } from \"#release/release-manifest\";\n\nimport { PluginPackage } from \"./package.ts\";\n\nconst Import = Schema.Struct({ path: Schema.String, external: Schema.optionalKey(Schema.Boolean) });\nconst Metafile = Schema.Struct({\n inputs: Schema.Record(Schema.String, Schema.Struct({ imports: Schema.Array(Import) })),\n outputs: Schema.Record(\n Schema.String,\n Schema.Struct({\n imports: Schema.Array(Import),\n inputs: Schema.Record(Schema.String, Schema.Struct({ bytesInOutput: Schema.Number })),\n entryPoint: Schema.optionalKey(Schema.String),\n }),\n ),\n});\nconst Metadata = Schema.StructWithRest(\n Schema.Struct({\n name: Schema.optionalKey(Schema.String),\n version: ReleaseManifest.ExactVersion,\n license: Schema.optionalKey(Schema.String),\n exports: Schema.optionalKey(Schema.Json),\n }),\n [Schema.Record(Schema.String, Schema.Json)],\n);\n\nfunction targets(value: Schema.Json): string[] {\n if (typeof value === \"string\") return [value];\n if (value === null) return [];\n if (typeof value !== \"object\")\n throw PluginPackage.PackageError.make({ message: \"Unsupported package exports\" });\n return Array.flatMap(Object.values(value), targets);\n}\n\nfunction pattern(expression: acorn.Expression | acorn.SpreadElement): string {\n if (expression.type === \"Literal\" && typeof expression.value === \"string\")\n return expression.value;\n if (\n expression.type === \"BinaryExpression\" &&\n expression.operator === \"+\" &&\n expression.left.type !== \"PrivateIdentifier\"\n )\n return pattern(expression.left) + pattern(expression.right);\n if (expression.type === \"TemplateLiteral\")\n return Array.join(\n Array.map(expression.quasis, part => part.value.cooked ?? part.value.raw),\n \"*\",\n );\n return \"*\";\n}\n\nfunction isNode(value: unknown): value is acorn.AnyNode {\n return (\n Predicate.isObject(value) &&\n Predicate.isString(value[\"type\"]) &&\n Predicate.isNumber(value[\"start\"]) &&\n Predicate.isNumber(value[\"end\"])\n );\n}\n\n// Acorn owns the node shapes; traversing the AST also handles chained import().then() calls.\nfunction references(code: string) {\n const tree = acorn.parse(code, {\n ecmaVersion: \"latest\",\n sourceType: \"module\",\n allowReturnOutsideFunction: true,\n });\n const found = MutableList.make<{\n kind: \"import\" | \"require\" | \"resolve\" | \"asset\";\n path: string;\n }>();\n const visit = (\n expression: acorn.AnyNode,\n parent?: acorn.AnyNode,\n grandparent?: acorn.AnyNode,\n ): void => {\n if (expression.type === \"ImportExpression\")\n MutableList.append(found, { kind: \"import\" as const, path: pattern(expression.source) });\n if (\n expression.type === \"CallExpression\" &&\n expression.callee.type === \"Identifier\" &&\n Array.contains([\"require\", \"__require\"], expression.callee.name) &&\n expression.arguments[0]\n )\n MutableList.append(found, {\n kind: \"require\" as const,\n path: pattern(expression.arguments[0]),\n });\n if (\n expression.type === \"CallExpression\" &&\n expression.callee.type === \"MemberExpression\" &&\n expression.callee.object.type === \"MetaProperty\" &&\n expression.callee.object.meta.name === \"import\" &&\n expression.callee.property.type === \"Identifier\" &&\n Array.contains([\"resolve\", \"require\"], expression.callee.property.name) &&\n expression.arguments[0]\n )\n MutableList.append(found, {\n kind: \"resolve\" as const,\n path: pattern(expression.arguments[0]),\n });\n if (\n expression.type === \"ImportSpecifier\" &&\n expression.imported.type === \"Identifier\" &&\n expression.imported.name === \"createRequire\" &&\n parent?.type === \"ImportDeclaration\" &&\n Array.contains([\"node:module\", \"module\"], parent.source.value)\n )\n MutableList.append(found, { kind: \"resolve\" as const, path: \"createRequire\" });\n if (\n ((expression.type === \"ImportNamespaceSpecifier\" ||\n expression.type === \"ImportDefaultSpecifier\") &&\n parent?.type === \"ImportDeclaration\" &&\n Array.contains([\"node:module\", \"module\"], parent.source.value)) ||\n (expression.type === \"ImportExpression\" &&\n Array.contains([\"node:module\", \"module\"], pattern(expression.source))) ||\n (expression.type === \"CallExpression\" &&\n expression.callee.type === \"Identifier\" &&\n Array.contains([\"require\", \"__require\"], expression.callee.name) &&\n expression.arguments[0] &&\n Array.contains([\"node:module\", \"module\"], pattern(expression.arguments[0])))\n )\n MutableList.append(found, { kind: \"resolve\" as const, path: \"module namespace\" });\n if (expression.type === \"NewExpression\") {\n const base = expression.arguments[1];\n if (\n expression.callee.type === \"Identifier\" &&\n expression.callee.name === \"URL\" &&\n base?.type === \"MemberExpression\" &&\n base.object.type === \"MetaProperty\" &&\n base.object.meta.name === \"import\" &&\n base.object.property.name === \"meta\" &&\n base.property.type === \"Identifier\" &&\n base.property.name === \"url\" &&\n expression.arguments[0]\n ) {\n const receiver = parent?.type === \"MemberExpression\" ? parent : expression;\n const call = receiver === parent ? grandparent : parent;\n const method = call?.type === \"CallExpression\" ? call.callee : undefined;\n const name =\n method?.type === \"Identifier\"\n ? method.name\n : method?.type === \"MemberExpression\" && method.property.type === \"Identifier\"\n ? method.property.name\n : \"\";\n const writing =\n call?.type === \"CallExpression\" &&\n call.arguments[0] === receiver &&\n Array.contains(\n [\n \"writeFile\",\n \"writeFileSync\",\n \"writeFileString\",\n \"appendFile\",\n \"appendFileSync\",\n \"makeDirectory\",\n \"mkdir\",\n \"mkdirSync\",\n ],\n name,\n );\n if (!writing)\n MutableList.append(found, {\n kind: \"asset\" as const,\n path: pattern(expression.arguments[0]),\n });\n }\n }\n const fields: unknown[] = Object.values(expression);\n for (const field of fields) {\n if (isNode(field)) visit(field, expression, parent);\n else if (Array.isArray(field))\n for (const child of field) if (isNode(child)) visit(child, expression, parent);\n }\n };\n visit(tree);\n return MutableList.toArray(found);\n}\n\nexport const make = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;\n return Effect.fn(\"PluginBundle.build\")(function* (\n root: string,\n prepared: PluginPackage.Prepared,\n ) {\n const json = Effect.fnUntraced(function* (file: string) {\n return yield* Schema.decodeEffect(Schema.fromJsonString(Metadata))(\n yield* fs.readFileString(file),\n );\n });\n const manifest = yield* json(path.join(root, \"package.json\"));\n const require = createRequire(prepared.entrypoint);\n const sdkRoot = path.dirname(require.resolve(\"@dual-os/sdk/package.json\"));\n const sdk = yield* json(path.join(sdkRoot, \"package.json\"));\n const sdkRunner = yield* fs.realPath(require.resolve(\"@dual-os/sdk/Runner\"));\n const input = path.join(root, \".dual/bundle-input\");\n const output = path.join(root, \".dual/bundle-output\");\n for (const directory of [input, output]) {\n if (yield* fs.exists(directory)) yield* fs.remove(directory, { recursive: true });\n yield* fs.makeDirectory(directory, { recursive: true });\n }\n const safe = Effect.fnUntraced(function* (name: string) {\n const relative = path.relative(root, path.resolve(root, name));\n if (\n relative === \"\" ||\n relative.startsWith(\"..\") ||\n path.isAbsolute(relative) ||\n Array.some(\n relative.split(path.sep),\n part =>\n [\"node_modules\", \".dual\", \".env\", \".npmrc\", \".netrc\"].includes(part) ||\n part.startsWith(\".env.\"),\n )\n )\n return yield* PluginPackage.PackageError.make({ message: `Unsafe bundle path: ${name}` });\n const source = path.resolve(root, name);\n const real = yield* fs.realPath(source);\n if (!real.startsWith(`${root}${path.sep}`))\n return yield* PluginPackage.PackageError.make({\n message: `Bundle file escapes the package: ${name}`,\n });\n return { source, relative };\n });\n const copy = Effect.fnUntraced(function* (name: string, destination: string) {\n const file = yield* safe(name);\n if ((yield* fs.stat(file.source)).type !== \"File\")\n return yield* PluginPackage.PackageError.make({\n message: `Bundle export must be a file: ${name}`,\n });\n const bytes = yield* fs.readFile(file.source);\n if (/\\.[cm]?tsx?$/u.test(name) && !/\\.d\\.[cm]?ts$/u.test(name))\n return yield* PluginPackage.PackageError.make({\n message: `Source exports/assets cannot be shipped in a JavaScript bundle: ${name}`,\n });\n const prefix = Buffer.from(bytes.subarray(0, 4));\n if (\n /\\.(?:node|dll|dylib|exe|so(?:\\.[0-9.]+)?)$|(?:^|\\/)binding\\.gyp$/iu.test(name) ||\n (prefix.length === 4 &&\n [\n 0x7f454c46, 0xfeedface, 0xcefaedfe, 0xfeedfacf, 0xcffaedfe, 0xcafebabe, 0xbebafeca,\n ].includes(prefix.readUInt32BE(0))) ||\n (prefix.length >= 2 && prefix.readUInt16BE(0) === 0x4d5a)\n )\n return yield* PluginPackage.PackageError.make({\n message: `Native bundle content is unsupported: ${name}`,\n });\n yield* fs.makeDirectory(path.dirname(path.join(destination, file.relative)), {\n recursive: true,\n });\n yield* fs.copyFile(file.source, path.join(destination, file.relative));\n });\n const publicFiles = MutableList.make<string>();\n for (const target of yield* Effect.try(() => targets(manifest.exports ?? {}))) {\n const matches = yield* fs.glob(target, { root });\n if (Array.isArrayEmpty(matches))\n return yield* PluginPackage.PackageError.make({\n message: `Missing public export: ${target}`,\n });\n MutableList.appendAll(publicFiles, matches);\n }\n const declared = Array.dedupe([\n ...MutableList.toArray(publicFiles),\n path.relative(root, prepared.entrypoint),\n ...Array.map(prepared.assets, file => path.relative(root, file)),\n ]);\n // Static helpers can live above any public entrypoint; only the bundler's reachable graph ships.\n const declarations = MutableList.make<string>();\n for (const file of yield* fs.glob(\"**/*\", {\n root,\n exclude: [\"node_modules/**\", \".dual/**\", \".git/**\"],\n })) {\n const source = path.join(root, file);\n if ((yield* fs.stat(source)).type !== \"File\") continue;\n if (/\\.d\\.[cm]?ts(?:\\.map)?$/u.test(file)) {\n yield* copy(file, output);\n MutableList.append(declarations, file);\n }\n if (\n /\\.(?:[cm]?js|json|map)$/.test(file) &&\n !Array.some(file.split(\"/\"), part => part.startsWith(\".\"))\n )\n yield* copy(path.relative(root, source), input);\n }\n for (const file of declared) {\n yield* copy(file, input);\n if (!/\\.(?:[cm]?js)$/.test(file)) yield* copy(file, output);\n }\n for (const file of [\"README.md\", \"LICENSE\", \"LICENSE.md\", \"LICENSE.txt\"]) {\n if (yield* fs.exists(path.join(root, file))) yield* copy(file, output);\n }\n yield* fs.writeFileString(\n path.join(input, \"package.json\"),\n yield* fs.readFileString(path.join(root, \"package.json\")),\n );\n // Resolve the same installed graph as the source package, including workspace hoisting.\n const modules = Effect.fnUntraced(function* (\n directory: string,\n ): Effect.fn.Return<string, PlatformError.PlatformError | PluginPackage.PackageError> {\n if (yield* fs.exists(path.join(directory, \"node_modules\")))\n return path.join(directory, \"node_modules\");\n const parent = path.dirname(directory);\n if (parent === directory)\n return yield* PluginPackage.PackageError.make({\n message: \"Install build dependencies from a frozen lockfile first\",\n });\n return yield* modules(parent);\n });\n yield* fs.symlink(yield* modules(root), path.join(input, \"node_modules\"));\n const runnerName = Effect.fnUntraced(function* (\n index: number,\n ): Effect.fn.Return<string, PlatformError.PlatformError> {\n const name = index === 0 ? \"Runner.js\" : `Runner-${index}.js`;\n return (yield* fs.exists(path.join(input, name))) ? yield* runnerName(index + 1) : name;\n });\n const runner = yield* runnerName(0);\n yield* fs.writeFileString(\n path.join(input, runner),\n 'export { load } from \"@dual-os/sdk/Runner\";\\n',\n );\n const entries = Array.dedupe([\n ...Array.filter(declared, file => /\\.(?:[cm]?js)$/.test(file)),\n runner,\n ]);\n const metaPath = path.join(root, \".dual/bundle-metafile.json\");\n const code = yield* spawner.exitCode(\n ChildProcess.make(\n \"bun\",\n [\n \"build\",\n \"--no-env-file\",\n \"--target=bun\",\n \"--format=esm\",\n \"--splitting\",\n \"--keep-names\",\n \"--sourcemap=linked\",\n `--metafile=${metaPath}`,\n \"--root\",\n input,\n \"--outdir\",\n output,\n ...Array.map(entries, file => path.resolve(input, file)),\n ],\n { cwd: input, stdin: \"ignore\", stdout: \"ignore\", stderr: \"inherit\" },\n ),\n );\n if (code !== 0)\n return yield* PluginPackage.PackageError.make({\n message: \"Self-contained plugin compilation failed; no installation fallback is available\",\n });\n const meta = yield* Schema.decodeEffect(Schema.fromJsonString(Metafile))(\n yield* fs.readFileString(metaPath),\n );\n const emitted = Record.fromEntries(\n Array.flatMap(Object.entries(meta.outputs), entry =>\n entry[1].entryPoint\n ? [\n [\n path.relative(input, path.resolve(input, entry[1].entryPoint)),\n entry[0].replace(/^\\.\\//u, \"\"),\n ] as const,\n ]\n : [],\n ),\n );\n const rewrite = (value: Schema.Json): Schema.Json => {\n if (typeof value === \"string\")\n return emitted[path.normalize(value)]\n ? `./${emitted[path.normalize(value)]}`\n : value.replace(/\\.[cm]js$/u, \".js\");\n if (value === null || typeof value !== \"object\") return value;\n if (Array.isArray<Schema.Json>(value)) return Array.map(value, rewrite);\n return Record.map(value, rewrite);\n };\n const packages = MutableHashMap.empty<\n string,\n { name: string; version: string; license: string; licenses: string[] }\n >();\n const contributing = Array.dedupe(\n Array.flatMap(Object.values(meta.outputs), result =>\n Array.map(\n Array.filter(Object.entries(result.inputs), entry => entry[1].bytesInOutput > 0),\n entry => entry[0],\n ),\n ),\n );\n for (const file of contributing) {\n const source = yield* fs.realPath(path.resolve(input, file));\n const body = yield* fs.readFileString(source);\n for (const reference of /\\.[cm]?js$/.test(source)\n ? yield* Effect.try(() => references(body))\n : []) {\n if (\n reference.kind === \"resolve\" &&\n Array.contains([\"createRequire\", \"module namespace\"], reference.path)\n )\n continue;\n if (reference.kind === \"import\" && source === sdkRunner) continue;\n if (isBuiltin(reference.path) || reference.path.startsWith(\"bun:\")) continue;\n if (reference.kind === \"asset\" && /^(?!file:)[a-z][a-z\\d+.-]*:/iu.test(reference.path))\n continue;\n if (reference.kind === \"resolve\")\n return yield* PluginPackage.PackageError.make({\n message: `Runtime package resolution cannot be bundled in ${file}: ${reference.path}; use an import instead`,\n });\n if (reference.kind !== \"asset\" && !reference.path.includes(\"*\")) continue;\n if (reference.kind === \"require\")\n return yield* PluginPackage.PackageError.make({\n message: `Unresolved computed require in ${file}; use finite imports and declare dual.plugin.assets`,\n });\n if (!reference.path.startsWith(\".\"))\n return yield* PluginPackage.PackageError.make({\n message: `Unresolved dynamic import/resource in ${file}: ${reference.path}. Declare finite relative files in dual.plugin.assets.`,\n });\n const matches = yield* fs.glob(reference.path, { root: path.dirname(source) });\n if (Array.isArrayEmpty(matches))\n return yield* PluginPackage.PackageError.make({\n message: `Missing dynamic import/resource in ${file}: ${reference.path}`,\n });\n if (reference.path.includes(\"*\"))\n for (const match of matches) {\n const relative = path.relative(input, path.resolve(path.dirname(source), match));\n if (!Array.some(declared, name => path.normalize(name) === relative))\n return yield* PluginPackage.PackageError.make({\n message: `Declare dynamic file in dual.plugin.assets: ${relative}`,\n });\n }\n }\n if (source.startsWith(`${input}${path.sep}`)) continue;\n const segments = source.split(path.sep);\n const modules = segments.lastIndexOf(\"node_modules\");\n const packageRoot =\n modules === -1\n ? undefined\n : Array.join(\n segments.slice(0, modules + (segments[modules + 1]?.startsWith(\"@\") ? 3 : 2)),\n path.sep,\n );\n const owner = Effect.fnUntraced(function* (\n directory: string,\n ): Effect.fn.Return<string, PlatformError.PlatformError | PluginPackage.PackageError> {\n const manifest = path.join(directory, \"package.json\");\n if (yield* fs.exists(manifest)) {\n if (packageRoot) return directory;\n const candidate = yield* Schema.decodeEffect(Schema.fromJsonString(Schema.JsonObject))(\n yield* fs.readFileString(manifest),\n ).pipe(\n Effect.mapError(cause =>\n PluginPackage.fromCause(\n cause,\n `Invalid dependency manifest ${manifest} for ${source}`,\n ),\n ),\n );\n if (Object.hasOwn(candidate, \"name\")) return directory;\n }\n const parent = path.dirname(directory);\n if (parent === directory || directory === packageRoot)\n return yield* PluginPackage.PackageError.make({\n message: `Dependency has no package manifest: ${source}; searched ${manifest}`,\n });\n return yield* owner(parent);\n });\n const directory = yield* owner(packageRoot ?? path.dirname(source));\n if (MutableHashMap.has(packages, directory)) continue;\n const manifest = path.join(directory, \"package.json\");\n const pkg = yield* json(manifest).pipe(\n Effect.mapError(cause =>\n PluginPackage.fromCause(cause, `Invalid dependency manifest ${manifest} for ${source}`),\n ),\n );\n if (!pkg.name || !pkg.license)\n return yield* PluginPackage.PackageError.make({\n message: `Dependency lacks name/license metadata: ${manifest} for ${source}`,\n });\n const licenseFiles = (yield* fs.glob(\"{LICENSE,LICENCE,COPYING,NOTICE}{,.md,.txt}\", {\n root: directory,\n })).sort();\n if (Array.isArrayEmpty(licenseFiles))\n return yield* PluginPackage.PackageError.make({\n message: `Dependency attribution missing: ${pkg.name}@${pkg.version}`,\n });\n const licenses = MutableList.make<string>();\n for (const license of licenseFiles) {\n if ((yield* fs.stat(path.join(directory, license))).size === 0n)\n return yield* PluginPackage.PackageError.make({\n message: `Empty dependency attribution: ${pkg.name}@${pkg.version}: ${license}`,\n });\n const target = `licenses/${pkg.name.replaceAll(\"/\", \"_\")}@${pkg.version}/${license}`;\n yield* fs.makeDirectory(path.dirname(path.join(output, target)), { recursive: true });\n yield* fs.copyFile(path.join(directory, license), path.join(output, target));\n MutableList.append(licenses, target);\n }\n MutableHashMap.set(packages, directory, {\n name: pkg.name,\n version: pkg.version,\n license: pkg.license,\n licenses: MutableList.toArray(licenses),\n });\n }\n for (const [file, metadata] of Object.entries(meta.outputs)) {\n for (const imported of metadata.imports) {\n if (isBuiltin(imported.path) || imported.path.startsWith(\"bun:\")) continue;\n if (\n imported.external ||\n !imported.path.startsWith(\".\") ||\n !(yield* fs.exists(path.resolve(output, imported.path)))\n )\n return yield* PluginPackage.PackageError.make({\n message: `Unbundled dependency in ${file}: ${imported.path}`,\n });\n }\n if (!/\\.[cm]?js$/.test(file)) continue;\n const outputCode = yield* fs.readFileString(path.resolve(output, file));\n for (const reference of yield* Effect.try(() => references(outputCode))) {\n if (\n reference.kind === \"resolve\" &&\n Array.contains([\"createRequire\", \"module namespace\"], reference.path)\n )\n return yield* PluginPackage.PackageError.make({\n message: `Runtime package resolution cannot be bundled in ${file}: ${reference.path}; use static named imports instead`,\n });\n if (\n reference.kind === \"require\" &&\n !isBuiltin(reference.path) &&\n !reference.path.startsWith(\"bun:\")\n )\n return yield* PluginPackage.PackageError.make({\n message: `Unbundled require in ${file}: ${reference.path}; no installation fallback is available`,\n });\n if (\n reference.kind === \"import\" &&\n reference.path.startsWith(\".\") &&\n reference.path.includes(\"*\") &&\n Array.isArrayEmpty(\n yield* fs.glob(reference.path, { root: path.resolve(output, path.dirname(file)) }),\n )\n )\n return yield* PluginPackage.PackageError.make({\n message: `Bundle dynamic import is missing after splitting: ${file}: ${reference.path}`,\n });\n if (reference.kind !== \"asset\") continue;\n if (/^(?!file:)[a-z][a-z\\d+.-]*:/iu.test(reference.path)) continue;\n if (!(yield* fs.exists(path.resolve(output, path.dirname(file), reference.path))))\n return yield* PluginPackage.PackageError.make({\n message: `Bundle resource is missing after splitting: ${file}: ${reference.path}`,\n });\n }\n }\n return {\n output,\n sdkVersion: sdk.version,\n runner: emitted[runner] ?? runner,\n manifest: { ...manifest, exports: rewrite(manifest.exports ?? {}) },\n entrypoint:\n emitted[path.relative(root, prepared.entrypoint)] ??\n path.relative(root, prepared.entrypoint),\n assets: Array.dedupe([\n ...Array.map(prepared.assets, file => {\n const relative = path.relative(root, file);\n return emitted[relative] ?? relative;\n }),\n ...MutableList.toArray(declarations),\n ...Array.filter(MutableList.toArray(publicFiles), file => !/\\.[cm]?js$/u.test(file)),\n ...Array.map(\n Array.filter(Object.keys(meta.outputs), file => !/\\.[cm]?js$/u.test(file)),\n file => file.replace(/^\\.\\//u, \"\"),\n ),\n ]),\n publicJavaScript: Array.map(\n Array.filter(MutableList.toArray(publicFiles), file => /\\.[cm]?js$/u.test(file)),\n source => ({ source, output: emitted[path.normalize(source)] ?? source }),\n ),\n packages: Array.sort(\n Array.fromIterable(MutableHashMap.values(packages)),\n Order.mapInput(\n Order.String,\n (pkg: { name: string; version: string }) => `${pkg.name}@${pkg.version}`,\n ),\n ),\n };\n });\n});\n"],"mappings":";;;;;;;AAuBA,MAAM,SAAS,OAAO,OAAO;CAAE,MAAM,OAAO;CAAQ,UAAU,OAAO,YAAY,OAAO,OAAO;AAAE,CAAC;AAClG,MAAM,WAAW,OAAO,OAAO;CAC7B,QAAQ,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,EAAE,SAAS,OAAO,MAAM,MAAM,EAAE,CAAC,CAAC;CACrF,SAAS,OAAO,OACd,OAAO,QACP,OAAO,OAAO;EACZ,SAAS,OAAO,MAAM,MAAM;EAC5B,QAAQ,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,EAAE,eAAe,OAAO,OAAO,CAAC,CAAC;EACpF,YAAY,OAAO,YAAY,OAAO,MAAM;CAC9C,CAAC,CACH;AACF,CAAC;AACD,MAAM,WAAW,OAAO,eACtB,OAAO,OAAO;CACZ,MAAM,OAAO,YAAY,OAAO,MAAM;CACtC,SAAS,gBAAgB;CACzB,SAAS,OAAO,YAAY,OAAO,MAAM;CACzC,SAAS,OAAO,YAAY,OAAO,IAAI;AACzC,CAAC,GACD,CAAC,OAAO,OAAO,OAAO,QAAQ,OAAO,IAAI,CAAC,CAC5C;AAEA,SAAS,QAAQ,O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OAAO,KAAK,KAAK,OAAO,IAAG,SAAQ,CAAC,cAAc,KAAK,IAAI,CAAC,IACzE,SAAQ,KAAK,QAAQ,UAAU,EAAE,CACnC;GACF,CAAC;GACD,kBAAkB,MAAM,IACtB,MAAM,OAAO,YAAY,QAAQ,WAAW,IAAG,SAAQ,cAAc,KAAK,IAAI,CAAC,IAC/E,YAAW;IAAE;IAAQ,QAAQ,QAAQ,KAAK,UAAU,MAAM,MAAM;GAAO,EACzE;GACA,UAAU,MAAM,KACd,MAAM,aAAa,eAAe,OAAO,QAAQ,CAAC,GAClD,MAAM,SACJ,MAAM,SACL,QAA2C,GAAG,IAAI,KAAK,GAAG,IAAI,SACjE,CACF;EACF;CACF,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dual-os/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"bin": {
|
|
6
6
|
"dual": "./dist/bin.js"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"typecheck": "tsrs --build tsconfig.json --force --pretty false"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@dual-os/sdk": "0.
|
|
47
|
+
"@dual-os/sdk": "0.10.0",
|
|
48
48
|
"@effect/platform-node": "4.1.2",
|
|
49
49
|
"@effect/platform-node-shared": "4.1.2",
|
|
50
50
|
"acorn": "8.17.0",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"vite-plus": "1.4.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@dual/core": "0.20.
|
|
64
|
-
"@dual/dualspec": "0.5.
|
|
63
|
+
"@dual/core": "0.20.4",
|
|
64
|
+
"@dual/dualspec": "0.5.4",
|
|
65
65
|
"@dual/workspace-opensandbox": "0.4.1",
|
|
66
66
|
"@types/js-yaml": "4.0.9",
|
|
67
67
|
"@types/node": "25.9.5",
|
package/src/openapi/emit.ts
CHANGED
|
@@ -42,13 +42,13 @@ function importLine(names: readonly string[], from: string) {
|
|
|
42
42
|
|
|
43
43
|
const primitives = {
|
|
44
44
|
Boolean: "Schema.Boolean",
|
|
45
|
-
File: "
|
|
45
|
+
File: "Files.File",
|
|
46
46
|
Int: "Schema.Int",
|
|
47
47
|
Never: "Schema.Never",
|
|
48
48
|
Null: "Schema.Null",
|
|
49
49
|
Number: "Schema.Number",
|
|
50
50
|
String: "Schema.String",
|
|
51
|
-
ToolFile: "
|
|
51
|
+
ToolFile: "Files.File",
|
|
52
52
|
Unknown: "Schema.Unknown",
|
|
53
53
|
};
|
|
54
54
|
|
|
@@ -156,7 +156,7 @@ function expression(
|
|
|
156
156
|
],
|
|
157
157
|
", ",
|
|
158
158
|
)}]`;
|
|
159
|
-
return `Schema.StructWithRest(${fields}, [Schema.Record(${keys}, Schema.Union([${Array.join(members, ", ")}]))]).check(Schema.makeFilter(input => Array.every(Record.toEntries(input), entry => Array.contains(${names}, entry[0]) || Schema.is(${additional})(entry[1])), { representation: { id: "dual/openapi/additionalProperties", payload: null, schemas: [${additional}.ast] }, toJsonSchema: context => ({ properties: Record.fromEntries(Array.map(${names}, name => [name, {}])), additionalProperties: Array.getUnsafe(context.schemas, 0) }) }))`;
|
|
159
|
+
return `Schema.StructWithRest(${fields}, [Schema.Record(${keys}, Schema.Union([${Array.join(members, ", ")}]))]).check(Schema.makeFilter(input => Array.every(Record.toEntries(input), entry => Array.contains(${names}, entry[0]) || Schema.is(Schema.toType(${additional}))(entry[1])), { representation: { id: "dual/openapi/additionalProperties", payload: null, schemas: [${additional}.ast] }, toJsonSchema: context => ({ properties: Record.fromEntries(Array.map(${names}, name => [name, {}])), additionalProperties: Array.getUnsafe(context.schemas, 0) }) }))`;
|
|
160
160
|
}
|
|
161
161
|
return struct.rest || preserve
|
|
162
162
|
? `Schema.StructWithRest(${fields}, [Schema.Record(${keys}, Schema.Unknown)])`
|
|
@@ -179,13 +179,13 @@ function expression(
|
|
|
179
179
|
|
|
180
180
|
const typeKeywords = {
|
|
181
181
|
Boolean: "boolean",
|
|
182
|
-
File: "
|
|
182
|
+
File: "Files.File",
|
|
183
183
|
Int: "number",
|
|
184
184
|
Never: "never",
|
|
185
185
|
Null: "null",
|
|
186
186
|
Number: "number",
|
|
187
187
|
String: "string",
|
|
188
|
-
ToolFile: "
|
|
188
|
+
ToolFile: "Files.File",
|
|
189
189
|
Unknown: "unknown",
|
|
190
190
|
};
|
|
191
191
|
|
|
@@ -204,9 +204,9 @@ function typeOf(node: OpenApiSchema.Node, encoded?: HashSet.HashSet<string>): st
|
|
|
204
204
|
Array: array => `readonly ${element(array.item)}[]`,
|
|
205
205
|
Bytes: bytes => {
|
|
206
206
|
if (bytes.direction === "input") {
|
|
207
|
-
return encoded === undefined ? "string" : "
|
|
207
|
+
return encoded === undefined ? "string" : "Files.File";
|
|
208
208
|
}
|
|
209
|
-
return encoded === undefined ? "
|
|
209
|
+
return encoded === undefined ? "Files.File" : "string";
|
|
210
210
|
},
|
|
211
211
|
Instant: instant => {
|
|
212
212
|
const wire = instant.clock === "unix-seconds" ? "number" : "string";
|
|
@@ -343,7 +343,7 @@ function uses(texts: readonly string[], namespace: string) {
|
|
|
343
343
|
function effectImport(texts: readonly string[]) {
|
|
344
344
|
const names = [
|
|
345
345
|
...(uses(texts, "Array") ? ["Array"] : []),
|
|
346
|
-
...(
|
|
346
|
+
...(uses(texts, "Effect") ? ["Effect"] : []),
|
|
347
347
|
...(uses(texts, "Record") ? ["Record"] : []),
|
|
348
348
|
...(uses(texts, "Schema") ? ["Schema"] : []),
|
|
349
349
|
...(Array.some(texts, text => /(?<![\w$.])pipe\(/u.test(text)) ? ["pipe"] : []),
|
|
@@ -445,18 +445,18 @@ function bodyStep(contract: OpenApiSchema.Contract, body: OpenApiOperations.Body
|
|
|
445
445
|
: `HttpClientRequest.bodyText(JSON.stringify(input.payload), ${content})`,
|
|
446
446
|
),
|
|
447
447
|
Match.when("text", () => `HttpClientRequest.bodyText(input.payload, ${content})`),
|
|
448
|
-
Match.when(
|
|
449
|
-
"binary",
|
|
450
|
-
() =>
|
|
451
|
-
`HttpClientRequest.bodyUint8Array(input.payload.contentBase64, input.payload.contentType ?? ${content})`,
|
|
452
|
-
),
|
|
448
|
+
Match.when("binary", () => "Http.withFile(request, input.payload)"),
|
|
453
449
|
Match.when(
|
|
454
450
|
"form",
|
|
455
451
|
() =>
|
|
456
452
|
`HttpClientRequest.bodyUrlParams(Http.params(input.payload${encodings(body.joined ?? [], body.deepObject ?? [])}))`,
|
|
457
453
|
),
|
|
458
|
-
Match.orElse(() => `
|
|
454
|
+
Match.orElse(() => `Http.withForm(request, ${multipartPayload})`),
|
|
459
455
|
);
|
|
456
|
+
const applied =
|
|
457
|
+
body.encoding === "binary" || body.encoding === "multipart"
|
|
458
|
+
? value
|
|
459
|
+
: `Effect.succeed(${value}(request))`;
|
|
460
460
|
const conditions = [
|
|
461
461
|
...(contract.bodies.length > 1
|
|
462
462
|
? [
|
|
@@ -467,9 +467,11 @@ function bodyStep(contract: OpenApiSchema.Contract, body: OpenApiOperations.Body
|
|
|
467
467
|
: []),
|
|
468
468
|
...(body.required ? [] : ["input.payload !== undefined"]),
|
|
469
469
|
];
|
|
470
|
-
return
|
|
471
|
-
|
|
472
|
-
|
|
470
|
+
return `(request: HttpClientRequest.HttpClientRequest) => ${
|
|
471
|
+
Array.isReadonlyArrayEmpty(conditions)
|
|
472
|
+
? applied
|
|
473
|
+
: `${Array.join(conditions, " && ")} ? ${applied} : Effect.succeed(request)`
|
|
474
|
+
}`;
|
|
473
475
|
}
|
|
474
476
|
|
|
475
477
|
function sentBy(contract: OpenApiSchema.Contract, payload: string, call: string) {
|
|
@@ -501,9 +503,6 @@ function operationSource(
|
|
|
501
503
|
...(Array.isReadonlyArrayEmpty(contract.headers)
|
|
502
504
|
? []
|
|
503
505
|
: [`HttpClientRequest.setHeaders(${params(contract.headers, contract.commaSeparated, [])})`]),
|
|
504
|
-
...(contract.googleUpload === undefined
|
|
505
|
-
? Array.map(contract.bodies, body => bodyStep(contract, body))
|
|
506
|
-
: []),
|
|
507
506
|
];
|
|
508
507
|
const built = Array.isReadonlyArrayEmpty(steps)
|
|
509
508
|
? declared
|
|
@@ -511,13 +510,25 @@ function operationSource(
|
|
|
511
510
|
const preauthenticated = `Http.preauthenticated(HttpClientRequest.${method}, input.uploadUrl${Array.isReadonlyArrayEmpty(steps) ? "" : `, ${Array.join(steps, ", ")}`})`;
|
|
512
511
|
const continued =
|
|
513
512
|
contract.nextLink === true ? `Http.continuation(${built}, input.nextLink)` : built;
|
|
514
|
-
const
|
|
513
|
+
const target = contract.preauthenticatedUpload === true ? preauthenticated : continued;
|
|
514
|
+
const bodies = contract.googleUpload === undefined ? contract.bodies : [];
|
|
515
|
+
const request = Array.isReadonlyArrayEmpty(bodies)
|
|
516
|
+
? target
|
|
517
|
+
: `pipe(${target}, ${Array.join(
|
|
518
|
+
[
|
|
519
|
+
...(contract.preauthenticatedUpload === true || contract.nextLink === true
|
|
520
|
+
? []
|
|
521
|
+
: ["Effect.succeed"]),
|
|
522
|
+
...Array.map(bodies, body => `Effect.flatMap(${bodyStep(contract, body)})`),
|
|
523
|
+
],
|
|
524
|
+
", ",
|
|
525
|
+
)})`;
|
|
515
526
|
const context = contract.preauthenticatedUpload === true ? "undefined" : "context";
|
|
516
527
|
const single = Array.getUnsafe(contract.responses, 0);
|
|
517
528
|
const upload = contract.googleUpload;
|
|
518
529
|
const variants = `Http.variants(${context}, output, ${request}, ${JSON.stringify(
|
|
519
530
|
Array.map(contract.responses, response => ({
|
|
520
|
-
body: response.kind,
|
|
531
|
+
body: response.kind === "binary" ? "file" : response.kind,
|
|
521
532
|
contentType: response.contentType,
|
|
522
533
|
...(response.headers === undefined ? {} : { headers: response.headers }),
|
|
523
534
|
...(/^2\d\d$/u.test(response.status) ? { status: Number(response.status) } : {}),
|
|
@@ -525,7 +536,7 @@ function operationSource(
|
|
|
525
536
|
)}${contract.googleDownload === true ? ', input.alt === "media"' : ""})`;
|
|
526
537
|
const plain =
|
|
527
538
|
contract.responses.length === 1 && single.headers === undefined
|
|
528
|
-
? `Http.execute(${context}, output, ${request}, ${JSON.stringify(single.kind)})`
|
|
539
|
+
? `Http.execute(${context}, output, ${request}, ${JSON.stringify(single.kind === "binary" ? "file" : single.kind)})`
|
|
529
540
|
: variants;
|
|
530
541
|
const call =
|
|
531
542
|
upload === undefined
|
|
@@ -573,7 +584,7 @@ export function operationsSource(
|
|
|
573
584
|
...(Array.some(texts, String.includes("HttpClientRequest."))
|
|
574
585
|
? ['import { HttpClientRequest } from "effect/http";']
|
|
575
586
|
: []),
|
|
576
|
-
...(uses(texts, "
|
|
587
|
+
...(uses(texts, "Files") ? [importLine(["Files"], "@dual-os/sdk")] : []),
|
|
577
588
|
'import * as Http from "./http.ts";',
|
|
578
589
|
],
|
|
579
590
|
"\n",
|
|
@@ -714,6 +725,8 @@ export {
|
|
|
714
725
|
continuation,
|
|
715
726
|
decoded,
|
|
716
727
|
form,
|
|
728
|
+
withFile,
|
|
729
|
+
withForm,
|
|
717
730
|
literal,
|
|
718
731
|
params,
|
|
719
732
|
path,
|
package/src/openapi/schema.ts
CHANGED
|
@@ -459,7 +459,7 @@ function object(context: Context, schema: OpenApiSpec.JsonObject, pointer: strin
|
|
|
459
459
|
...(fieldDefault === undefined ? {} : { default: fieldDefault }),
|
|
460
460
|
};
|
|
461
461
|
}),
|
|
462
|
-
rest: additional
|
|
462
|
+
rest: additional === true || Predicate.isObject(additional),
|
|
463
463
|
spreads: [],
|
|
464
464
|
};
|
|
465
465
|
}
|
|
@@ -1231,6 +1231,7 @@ function pascal(value: string) {
|
|
|
1231
1231
|
"Array",
|
|
1232
1232
|
"Auth",
|
|
1233
1233
|
"Effect",
|
|
1234
|
+
"Files",
|
|
1234
1235
|
"Group",
|
|
1235
1236
|
"Http",
|
|
1236
1237
|
"HttpClientRequest",
|
|
@@ -1789,7 +1790,7 @@ export function converts(node: Node): node is Extract<Node, { _tag: "Bytes" | "I
|
|
|
1789
1790
|
|
|
1790
1791
|
const conversionNotes = {
|
|
1791
1792
|
Bytes: {
|
|
1792
|
-
input: "Pass a
|
|
1793
|
+
input: "Pass a File reference; the host reads its bytes for the request.",
|
|
1793
1794
|
output: "Returned as a file.",
|
|
1794
1795
|
},
|
|
1795
1796
|
Instant: {
|
package/src/plugin/bundle.ts
CHANGED
|
@@ -447,23 +447,51 @@ export const make = Effect.gen(function* () {
|
|
|
447
447
|
}
|
|
448
448
|
}
|
|
449
449
|
if (source.startsWith(`${input}${path.sep}`)) continue;
|
|
450
|
+
const segments = source.split(path.sep);
|
|
451
|
+
const modules = segments.lastIndexOf("node_modules");
|
|
452
|
+
const packageRoot =
|
|
453
|
+
modules === -1
|
|
454
|
+
? undefined
|
|
455
|
+
: Array.join(
|
|
456
|
+
segments.slice(0, modules + (segments[modules + 1]?.startsWith("@") ? 3 : 2)),
|
|
457
|
+
path.sep,
|
|
458
|
+
);
|
|
450
459
|
const owner = Effect.fnUntraced(function* (
|
|
451
460
|
directory: string,
|
|
452
461
|
): Effect.fn.Return<string, PlatformError.PlatformError | PluginPackage.PackageError> {
|
|
453
|
-
|
|
462
|
+
const manifest = path.join(directory, "package.json");
|
|
463
|
+
if (yield* fs.exists(manifest)) {
|
|
464
|
+
if (packageRoot) return directory;
|
|
465
|
+
const candidate = yield* Schema.decodeEffect(Schema.fromJsonString(Schema.JsonObject))(
|
|
466
|
+
yield* fs.readFileString(manifest),
|
|
467
|
+
).pipe(
|
|
468
|
+
Effect.mapError(cause =>
|
|
469
|
+
PluginPackage.fromCause(
|
|
470
|
+
cause,
|
|
471
|
+
`Invalid dependency manifest ${manifest} for ${source}`,
|
|
472
|
+
),
|
|
473
|
+
),
|
|
474
|
+
);
|
|
475
|
+
if (Object.hasOwn(candidate, "name")) return directory;
|
|
476
|
+
}
|
|
454
477
|
const parent = path.dirname(directory);
|
|
455
|
-
if (parent === directory)
|
|
478
|
+
if (parent === directory || directory === packageRoot)
|
|
456
479
|
return yield* PluginPackage.PackageError.make({
|
|
457
|
-
message: `Dependency has no package manifest: ${source}`,
|
|
480
|
+
message: `Dependency has no package manifest: ${source}; searched ${manifest}`,
|
|
458
481
|
});
|
|
459
482
|
return yield* owner(parent);
|
|
460
483
|
});
|
|
461
|
-
const directory = yield* owner(path.dirname(source));
|
|
484
|
+
const directory = yield* owner(packageRoot ?? path.dirname(source));
|
|
462
485
|
if (MutableHashMap.has(packages, directory)) continue;
|
|
463
|
-
const
|
|
486
|
+
const manifest = path.join(directory, "package.json");
|
|
487
|
+
const pkg = yield* json(manifest).pipe(
|
|
488
|
+
Effect.mapError(cause =>
|
|
489
|
+
PluginPackage.fromCause(cause, `Invalid dependency manifest ${manifest} for ${source}`),
|
|
490
|
+
),
|
|
491
|
+
);
|
|
464
492
|
if (!pkg.name || !pkg.license)
|
|
465
493
|
return yield* PluginPackage.PackageError.make({
|
|
466
|
-
message: `Dependency lacks name/license metadata: ${
|
|
494
|
+
message: `Dependency lacks name/license metadata: ${manifest} for ${source}`,
|
|
467
495
|
});
|
|
468
496
|
const licenseFiles = (yield* fs.glob("{LICENSE,LICENCE,COPYING,NOTICE}{,.md,.txt}", {
|
|
469
497
|
root: directory,
|