Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only add browser script tag instructions for browser modules #1124

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 24 additions & 11 deletions src/check-project/readme/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,37 @@
* @param {*} pkg
*/
export const INSTALL = (pkg) => {
return `
## Install
const nodeInstall = `
## Install

\`\`\`console
$ npm i ${pkg.name}
\`\`\`
\`\`\`console
$ npm i ${pkg.name}
\`\`\`
`
const browserInstall = `### Browser \`<script>\` tag

### Browser \`<script>\` tag
Loading this module through a script tag will make it's exports available as \`${nameToGlobalSymbol(pkg.name)}\` in the global namespace.

Loading this module through a script tag will make it's exports available as \`${nameToGlobalSymbol(pkg.name)}\` in the global namespace.
\`\`\`html
<script src="https://unpkg.com/${pkg.name}/dist/index.min.js"></script>
\`\`\`
`
const scripts = pkg.scripts ?? {}

\`\`\`html
<script src="https://unpkg.com/${pkg.name}/dist/index.min.js"></script>
\`\`\`
`
// if the module tests on browsers include browser install instructions
if (scripts['test:chrome'] != null || scripts['test:firefox'] != null || scripts['test:browser'] != null) {
return nodeInstall + browserInstall
}

// otherwise just include node install instructions
return nodeInstall
}

/**
* Esbuild uses the module name to determine the symbol that's added to
* the global scope by the minified build so replicate how it determines
* the name in order to add it to the docs.
*
* @param {string} name
* @returns {string}
*/
Expand Down