Skip to content

Commit

Permalink
Update distribution method for better browser support
Browse files Browse the repository at this point in the history
See fluture-js/fluture-sanctuary-types#73

The main problem was the `.cjs` extensions, which confused content
delivery networks. Simply changing the extension to `.js` won't work,
because that'd confuse Node 12 and up.

So besides changing the extension, the file has also been moved into a
sub-directory containing a package.json file that tells newer Node
versions that the files here are CommonJS (without the need for a file
extension).

This commit also adds documentation for the different ways that the
module can now be obtained.
  • Loading branch information
Avaq committed Mar 30, 2021
1 parent 377e84a commit b4d93a7
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 9 deletions.
7 changes: 5 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ This pull request adds everything the project needs to be at its first release.
- [ ] Name the project:
- Change `repo-name` in `.config` and ensure the tests pass.
- Change the header of the documentation in `index.js`.
- Change the module name in `rollup.config.js`.
- Replace occurrences of `fluture-project` in `index.js`.
- Change the value of `output.name` in `rollup.config.js`.
- Replace occurrences of `flutureProject` in `index.js` to follow the value of `output.name` from the previous step.

- [ ] Describe the project:
- Change `description` in `package.json`.
- Update the GitHub repo description.
- Add the description to the documentation in `index.js`.
- Update the description to the documentation in `index.js`.
- Add additional `tags` in `package.json`.

- [ ] If this is a node-only module, remove browser support:
- Remove browser usage instructions from the README.
- Change `umd` to `cjs` in `rollup.config.js` and remove `output.name`.
- Change `eslint-es3` to `eslint-es6` in `.eslintrc.json`.
- Change `shared-node-browser` to `node` in `.eslintrc.json`.
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/coverage/
/index.cjs
/dist/*
/node_modules/

!/dist/package.json
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
When adding a dependency, first consider whether to add it as
a *regular* or as a *peer* dependency.

Make sure to update `rollup.config.js` after installing a new dependency.
Make sure to update `rollup.config.js` and the usage instructions in `index.js`
after installing a new dependency . Peer dependencies need to be included in the
`npm install` example, and all dependencies need to be mentioned in the UMD
scripting instructions.

### Regular Dependency

Expand Down
3 changes: 3 additions & 0 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
35 changes: 35 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
//. # Fluture Project
//.
//. Hopefully something related to Fluture.
//.
//. ## Usage
//.
//. ### Node
//.
//. ```console
//. $ npm install --save fluture-project
//. ```
//.
//. On Node 12 and up, this module can be loaded directly with `import` or
//. `require`. On Node versions below 12, `require` or the [esm][]-loader can
//. be used.
//.
//. ### Deno and Modern Browsers
//.
//. You can load the EcmaScript module from various content delivery networks:
//.
//. - [Skypack](https://cdn.skypack.dev/[email protected])
//. - [JSPM](https://jspm.dev/[email protected])
//. - [jsDelivr](https://cdn.jsdelivr.net/npm/[email protected]/+esm)
//.
//. ### Old Browsers and Code Pens
//.
//. There's a [UMD][] file included in the NPM package, also available via
//. jsDelivr: https://cdn.jsdelivr.net/npm/[email protected]/dist/umd.js
//.
//. This file adds `flutureProject` to the global scope, or use CommonJS/AMD
//. when available.

export default void 0;

//. [esm]: https://github.com/standard-things/esm
//. [UMD]: https://github.com/umdjs/umd
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"fluture"
],
"type": "module",
"main": "index.cjs",
"main": "./dist/umd.js",
"module": "index.js",
"exports": {
".": {
"import": "./index.js",
"require": "./index.cjs"
"require": "./dist/umd.js"
},
"./index.js": "./index.js"
},
Expand All @@ -28,7 +28,7 @@
"url": "git://github.com/fluture-js/fluture-project.git"
},
"files": [
"/index.cjs",
"/dist",
"/index.js",
"/LICENSE",
"/package.json",
Expand Down
13 changes: 11 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import pkg from './package.json';

const dependencyNames = Array.prototype.concat.call (
Object.keys (pkg.dependencies),
Object.keys (pkg.peerDependencies)
);

export default {
input: 'index.js',
external: dependencyNames,
output: {
format: 'umd',
file: 'index.cjs',
file: 'dist/umd.js',
name: 'flutureProject',
interop: false
exports: 'named',
globals: {}
}
};

0 comments on commit b4d93a7

Please sign in to comment.