Files
js-sha1/rollup.config.mjs
T
Yi-Cyuan ChenandClaude Opus 5.5 3e1a92f2a4 ### Added
- ESM builds and package `exports`.

### Fixed
- Incorrect hash for strings with unpaired UTF-16 surrogates; they are now encoded as U+FFFD, the same as `TextEncoder`.
- Detect browsers with a `process` polyfill (e.g. BrowserFS) and Electron renderers as non-Node.js environments.

### Changed
- Replace Travis CI with GitHub Actions.
- Update dev dependencies and fix security issues.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 13:58:54 +08:00

49 lines
1.0 KiB
JavaScript

import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
const disableNodeJs = {
name: 'disable-node-js',
transform(code, id) {
if (id.endsWith('/src/sha1.js')) {
const nodeJsDeclaration = /^\s*var NODE_JS = .*;$/m;
if (!nodeJsDeclaration.test(code)) {
this.error('Could not find the NODE_JS declaration');
}
return code.replace(nodeJsDeclaration, ' var NODE_JS = false;');
}
}
};
export default [
{
input: 'src/sha1.mjs',
external: ['crypto', 'buffer'],
output: {
file: 'build/sha1.node.mjs',
format: 'es'
},
plugins: [commonjs({
strictRequires: false
})]
},
{
input: 'src/sha1.mjs',
output: {
file: 'build/sha1.mjs',
format: 'es'
},
plugins: [disableNodeJs, commonjs({
strictRequires: false,
ignore: ['crypto', 'buffer']
})]
},
{
input: 'build/sha1.mjs',
output: {
file: 'build/sha1.min.mjs',
format: 'es'
},
plugins: [terser()]
}
];