-
-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Separate ESM and UMD type definitions
- Loading branch information
Showing
8 changed files
with
45 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules/ | ||
npm-debug.* | ||
umd/index.js | ||
umd/types.d.ts |
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,26 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import { fileURLToPath } from "url"; | ||
import esm2umd from "esm2umd"; | ||
import prettier from "prettier"; | ||
|
||
const basePath = path.join(path.dirname(fileURLToPath(import.meta.url)), ".."); | ||
const esmPath = path.join(basePath, "index.js"); | ||
const umdPath = path.join(basePath, "umd", "index.js"); | ||
|
||
const esmSource = fs.readFileSync(esmPath, "utf8"); | ||
const umdSource = esm2umd("Long", esmSource); | ||
|
||
async function formatWithPrettier(source, filepath) { | ||
const options = await prettier.resolveConfig(filepath); | ||
return await prettier.format(source, { ...options, filepath }); | ||
} | ||
|
||
const prettierUmdSource = await formatWithPrettier(umdSource, umdPath); | ||
|
||
fs.writeFileSync(umdPath, prettierUmdSource); | ||
|
||
fs.copyFileSync( | ||
path.join(basePath, "types.d.ts"), | ||
path.join(basePath, "umd", "types.d.ts"), | ||
); |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
/// <reference path="../../umd/index.d.ts" /> | ||
|
||
Long.fromValue(1); | ||
|
||
var long = new Long(0, 0); | ||
long.toNumber(); | ||
|
||
function test(long: Long) {} |
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import Long from "../../index.js"; | ||
|
||
Long.fromValue(1); | ||
|
||
var long = new Long(0, 0); | ||
long.toNumber(); | ||
|
||
function test(long: Long) {} | ||
|
||
export default Long; |
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import Long = require("../../umd/index.js"); | ||
|
||
Long.fromValue(1); | ||
|
||
var long = new Long(0, 0); | ||
long.toNumber(); | ||
|
||
export default Long; | ||
function test(long: Long) {} | ||
|
||
export = Long; |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { Long } from "../types.js"; | ||
import { Long } from "./types.js"; | ||
export = Long; | ||
export as namespace Long; |