Repository navigation
feat: add zile.transform hook for emitted javascript - #52
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
zile.define replacements for emitted javascriptzile.transform hook for emitted javascript
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a6fbdb895b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 80f96177a1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const sourceDir = getSourceDir({ cwd, sources }) | ||
|
|
||
| if (!link) { | ||
| const transform = await readTransform({ cwd, pkgJson }) |
There was a problem hiding this comment.
Load the transform after transpilation
When a relative transform such as ./dist/transform.js is itself emitted by the package—or the transform imports another generated file—a clean build fails during module loading because readTransform runs before transpile creates those files. Resolve and import the transform after transpilation, immediately before applying it to the emitted JavaScript.
Useful? React with 👍 / 👎.
| for await (const file of fs.glob('**/*.{js,mjs,cjs}', { cwd: outDir })) { | ||
| const filePath = path.resolve(outDir, file) | ||
| const code = await fs.readFile(filePath, 'utf-8') | ||
| await fs.writeFile(filePath, await transform(code, path.relative(cwd, filePath))) |
There was a problem hiding this comment.
Normalize callback paths across platforms
On Windows, path.relative returns a path such as dist\index.js, while the documented callback contract shows package-relative paths such as dist/index.js. Transforms that select files using the documented slash-separated value therefore silently skip their replacements on Windows; normalize the callback path to forward slashes before invoking the transform.
Useful? React with 👍 / 👎.
Adds
package.json#zile.transform, a module whose default export rewrites each emitted JavaScript file aftertsc. Lets libraries replace build flag reads with literals before publishing, without zile knowing about the flag library.