-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: diff-sequences export not playing nice with Vite
- Loading branch information
Showing
3 changed files
with
33 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { readFileSync, writeFileSync } from 'fs' | ||
|
||
// The original file contains an export that doesn't play nice with Vite | ||
// This script copies the source code and turns it into regular a ES module | ||
// The original export looks like: | ||
// | ||
// Object.defineProperty(exports, '__esModule', { | ||
// value: true | ||
// }); | ||
// exports.default = diffSequence; | ||
// | ||
// The ESM export looks like: | ||
// | ||
// export default diffSequence; | ||
|
||
const commonjsFile = '../node_modules/diff-sequences/build/index.js' | ||
const esmFile = '../src/lib/generated/diffSequence.js' | ||
const commonjsCode = String(readFileSync(commonjsFile)) | ||
|
||
const commentsStart = commonjsCode.indexOf('/**') | ||
|
||
const esmHeader = `// esm version of diff-sequences | ||
// generated by ./tools/generateDiffSequenceEsm.js | ||
export default diffSequence; | ||
` | ||
|
||
const esmCode = esmHeader + commonjsCode.slice(commentsStart) | ||
|
||
writeFileSync(esmFile, esmCode) |