Repository navigation
oj build: a package section in oj.config builds a published npm package in tsdown's words - #827
Open
raphamorim wants to merge 2 commits into
Open
raphamorim wants to merge 2 commits into
raphamorim wants to merge 2 commits into
Conversation
…kage in tsdown's words with tsdown's defaults, beside Vite's `build.lib` A published package is built with tsdown today: `tsdown.config.ts` names the entries, the formats, `fixedExtension: false`, `dts` and `target: false`, and relies on tsdown's defaults for the rest (platform node, dependencies and peers external with their subpaths, devDependencies bundled, no minify, entries named by their path from the common directory). oj's library build could already write a dual es+cjs package from an `oj.config.json` with `build.lib`, but with Vite's decisions: array entries named by stem (two `index.ts` came out `index` and `index2`), `external` matched exactly (`jose` external, `jose/sub` bundled), the bundle minified and lowered, and a vite.config beside the package adopted as the package's. The `package` section takes tsdown's option names so a config ports key for key, and resolves (oj_config::package_builds) to the library build's own config plus what tsdown decides differently: `entry` as a file, a list named from the entries' lowest common directory, or an object; `format` (`esm` default); `platform` (`node`, and `node` for the cjs file whatever it says); `target` from `engines.node` or none; `minify` off; `clean`; `fixedExtension` on under node; a hash in chunk names; `define`, `sourcemap`, `copy`, `globalName`, `tsconfig`, `treeshake`, `outputOptions.entryFileNames`; and `deps.alwaysBundle` / `deps.neverBundle` / `deps.onlyBundle` / `deps.skipNodeModulesBundle` (plus the older `external` / `noExternal`) over the manifest's production dependencies, as rolldown's `external` function. A list of sections builds a package twice, each with its own `clean`. A package build defines nothing of Vite's `import.meta.env`, copies no `public/`, and reads no vite.config of its own accord: `oj.plugins.mjs` carries plugins, `--config` names a config on purpose. `dts` is read and warned about; declarations are the next change. Checked against two of the monorepo's packages (authorization-js and lovable-vite-tanstack): the same file set as tsdown writes, with the peers and the builtins kept as imports and the shared chunk hashed.
…es into the outDir it wrote to, and leaves no disallowed bundle behind Review round. The package dispatch was gated on no `--config`, so `oj build --config plugins.mjs` in a package root ran the app build and dropped the section; the section now decides, and a `--config` file lends the build its plugins as the docs said. A `mode` the config names is read as load_build_config reads it (the config and `.env.<mode>` again under it) when the command line names none. `copy` entries are kept as written and resolved when the files are copied, against the outDir the build wrote to, so `--outDir build` takes the copies along (an explicit `to` stays put); a glob is detected on the entry as written and the root is escaped in the pattern, glob read errors fail the copy instead of thinning it, and `rename` applies to a glob's files too. A `deps.onlyBundle` failure removes the chunks this build wrote, as tsdown fails before writing. `PackageSection` is read by hand from the JSON's shape, so a wrong value inside a section fails with serde's message for that key rather than "did not match any variant". A RegExp string with JS's escaped slash is tested, and a lone `/plain` string stays a name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A
packagesection inoj.config.{json,ts,mjs,js}builds a published npm package the way tsdown builds it, so atsdown.config.tsports key for key and the package needs no vite.config. First of the changes that let oj replace tsdown for the monorepo's packages;build.libstays Vite's.{ "package": { "entry": ["src/index.ts", "src/model.ts"], "format": ["cjs", "esm"], "fixedExtension": false } }What the section resolves to (
oj_config::package_builds), and what differs from the library build today:src/index.tsandsrc/protocols/mcp/index.tsareindexandprotocols/mcp/index), or by the keys of an object; defaultsrc/index.ts. The library build named array entries by stem, so twoindex.tscame outindexandindex2.externalfunction:dependencies,peerDependenciesandoptionalDependenciesstay imports with every subpath, devDependencies are bundled,deps.alwaysBundle/deps.neverBundle/deps.onlyBundle/deps.skipNodeModulesBundle(and the olderexternal/noExternal) adjust that; a string names a package or a subpath under it, a/regex/string or a RegExp marker is tested as written. The library build matchedexternalexactly (joseexternal,jose/subbundled).onlyBundlefails the build over a node_modules package it does not name.esm,dist, platformnode(the cjs file alwaysnode), no minify, no lowering unlessengines.nodenames a floor,clean, a hash in chunk names,fixedExtensionon under node (.mjs/.cjs; off gives.js/.cjsfor atype: modulepackage).define,sourcemap,copy(files, directories, globs;{ from, to, flatten, rename }),globalName,tsconfig,treeshake,outputOptions.entryFileNames,nameas a label, and a list of sections for a package that builds twice, each with its ownclean.import.meta.env, copies nopublic/, and reads no vite.config beside it (that one configures the app); plugins come fromoj.plugins.mjsor a config named with--config.dtsis read and warned about. Declarations are the next change.Tests
oj_configunit tests: entry naming from the common directory, format normalization, the dependency rule, package names of specifiers, the extension table,engines.nodeas a target, and a section resolving to the library config with tsdown's defaults (mergeddefine, no public dir, copy destinations, a list withclean: false).ojbuild tests over a package fixture (atype: modulemanifest with an installed dependency and devDependency, a nested entry, a throwing vite.config beside it): the dual build's file set and contents (builtin and dependency subpath kept, devDependency inlined, names unminified,defineapplied);alwaysBundle/neverBundle/onlyBundle; a list that builds in order withcopy, a browser-platform second build underclean: false, the TS config form, and an iife withglobalName,minifyandentryFileNames.Verification
cargo test -p oj_config(86 pass) and the library and package build tests inoj; clippy-D warningson both crates and rustfmt clean.indexandmodel, es+cjs, a shared chunk hashed) and lovable-vite-tanstack (three named entries;viteand the Node builtins kept as imports). Same file set tsdown writes, minus declarations.Review round
Two review passes (the code-review skill and a read of the diff), fixes in the second commit:
oj build --config xin a package root ran the app build and dropped the section. The section now decides; a--configfile lends its plugins.copydestinations were fixed at config time, so--outDir buildput the bundle inbuild/and the copies indist/. Entries are resolved when copied, against the outDir written to; an explicittostays put. Globs are detected on the entry as written with the root escaped, glob read errors fail the copy,renameapplies to globbed files.modeis honoured when the command line names none.deps.onlyBundlefailure removes what the build wrote, as tsdown fails before writing.oj.config.tson a non-package build (one QuickJS pass, to see whether apackagesection is there).