Skip to content

Document module aliasing#16468

Merged
irvinebroque merged 4 commits intoproductionfrom
bib/module-aliasing
Aug 27, 2024
Merged

Document module aliasing#16468
irvinebroque merged 4 commits intoproductionfrom
bib/module-aliasing

Conversation

@irvinebroque
Copy link
Copy Markdown
Contributor

@irvinebroque irvinebroque commented Aug 26, 2024

  • Documents how to configure module aliasing
  • Documents --alias flag
  • Provides two examples for how to use module aliasing

closes cloudflare/workers-sdk#6184, refs cloudflare/workers-sdk#6167, cloudflare/workers-sdk#6448

Wrangler docs need work and are too long, but for now just need this content to exist somewhere. Better structure should come in a different PR.

Open to feedback on other places in the docs that should link to this or reference it.

Comment thread src/content/docs/workers/wrangler/configuration.mdx Outdated
Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Aug 26, 2024

Deploying cloudflare-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4f3b1ac
Status: ✅  Deploy successful!
Preview URL: https://84975a1a.cloudflare-docs-7ou.pages.dev
Branch Preview URL: https://bib-module-aliasing.cloudflare-docs-7ou.pages.dev

View logs

Copy link
Copy Markdown
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small nit, but otherwise perfect. Thank you so much for this @irvinebroque!

Comment thread src/content/docs/workers/wrangler/configuration.mdx Outdated
Co-authored-by: Sunil Pai <spai@cloudflare.com>
Comment thread src/content/docs/workers/wrangler/configuration.mdx

For example, some NPM packages depend on [`node-fetch`](https://www.npmjs.com/package/node-fetch), a package that provided a polyfill of the [`fetch()` API](/workers/runtime-apis/fetch/), before it was built into Node.js.

`node-fetch` isn't needed in Workers, because the `fetch()` API is provided by the Workers runtime. And `node-fetch` doesn't work on Workers, because it relies on currently unsupported Node.js APIs from the `http`/`https` modules.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issues:

  • Style Guide - (Spelling-error) Did you really mean 'APIs'?

Fix Explanation:

The term 'APIs' is correctly used in this context to refer to multiple application programming interfaces. It is a standard term in the tech industry, and there is no spelling error. If the style guide does not recognize 'APIs' as a valid plural form, it may need to be updated to reflect common industry usage. No change is needed to the text.

export default fetch;
```

### Example: Aliasing Node.js APIs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issues:

  • Style Guide - (Spelling-error) Did you really mean 'APIs'?

Fix Explanation:

The term 'APIs' is correct and widely used in technical documentation. It is not a spelling error. If the style guide suggests otherwise, it may need to be updated to reflect common industry terminology. No change is necessary to the existing text.


### Example: Aliasing Node.js APIs

You can use module aliasing to provide your own polyfill implementation of a Node.js API that is not yet available in the Workers runtime.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issues:

  • Style Guide - (Spelling-error) Did you really mean 'polyfill'?

Fix Explanation:

The term 'polyfill' is correct in this context and is a standard term in the tech industry. It is not a spelling error. If the style guide does not recognize 'polyfill,' it may need to be updated to include this term, as it is widely used in software development documentation.


You can use module aliasing to provide your own polyfill implementation of a Node.js API that is not yet available in the Workers runtime.

For example, let’s say the NPM package you rely on calls [`fs.readFile`](https://nodejs.org/api/fs.html#fsreadfilepath-options-callback). You can alias the fs module by adding the following to your Worker’s wrangler.toml:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issues:

  • Style Guide - (Spelling-error) Did you really mean 'fs'?

Fix Explanation:

The term 'fs' is a standard Node.js module and is correctly used in this context. It is not a spelling error. The style guide may need to be updated to recognize 'fs' as a valid term in technical documentation related to Node.js. No change is necessary to the text.

}
```

In many cases, this allows you to work provide just enough of an API to make a dependency work. You can learn more about Cloudflare Workers' support for Node.js APIs on the [Cloudflare Workers Node.js API documentation page](/workers/runtime-apis/nodejs/).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issues:

  • Style Guide - (Spelling-error) Did you really mean 'APIs'?

Fix Explanation:

The term 'APIs' is correctly used in the context of referring to multiple Application Programming Interfaces. It is a standard term in technical documentation, and there is no spelling error. No change is needed. If the style guide suggests otherwise, it may need to be updated to align with common industry usage.

Comment thread src/content/docs/workers/wrangler/configuration.mdx Outdated
Co-authored-by: Sunil Pai <spai@cloudflare.com>
@irvinebroque irvinebroque merged commit 7af769a into production Aug 27, 2024
@irvinebroque irvinebroque deleted the bib/module-aliasing branch August 27, 2024 15:51
elithrar pushed a commit that referenced this pull request Oct 15, 2024
* Document module aliasing

* Update src/content/docs/workers/wrangler/configuration.mdx

Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com>

* Update src/content/docs/workers/wrangler/configuration.mdx

Co-authored-by: Sunil Pai <spai@cloudflare.com>

* Update src/content/docs/workers/wrangler/configuration.mdx

Co-authored-by: Sunil Pai <spai@cloudflare.com>

---------

Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com>
Co-authored-by: Sunil Pai <spai@cloudflare.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: write docs for module aliasing

7 participants