-
Notifications
You must be signed in to change notification settings - Fork 45
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
Support named exports in the ESM mode #60
Open
prantlf
wants to merge
2
commits into
alexeyraspopov:main
Choose a base branch
from
prantlf:named-exports
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
node_modules | ||
picocolors.mjs | ||
tests/types.mjs |
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,28 @@ | ||
import { readFile, writeFile } from "node:fs/promises" | ||
|
||
let script = await readFile("picocolors.js", "utf8") | ||
|
||
script = script.replace('require != null && require("tty")', '(await import("tty"))') | ||
|
||
let lines = script.split(/\r?\n/) | ||
lines.splice(-3, 3) | ||
script = lines.join("\n") | ||
|
||
script += ` | ||
let colors = createColors() | ||
colors.createColors = createColors | ||
let { | ||
reset, bold, dim, italic, underline, inverse, hidden, strikethrough, | ||
black, red, green, yellow, blue, magenta, cyan, white, gray, | ||
bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite | ||
} = colors | ||
|
||
export { | ||
isColorSupported, reset, bold, dim, italic, underline, inverse, hidden, strikethrough, | ||
black, red, green, yellow, blue, magenta, cyan, white, gray, | ||
bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, createColors | ||
} | ||
export default colors | ||
`; | ||
|
||
await writeFile("picocolors.mjs", script) |
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,5 +1,38 @@ | ||
import { Colors } from "./types" | ||
import { Colors, Formatter } from "./types" | ||
|
||
declare const picocolors: Colors & { createColors: (enabled?: boolean) => Colors } | ||
export { Colors } | ||
|
||
export = picocolors | ||
declare type Generator = (enabled?: boolean) => Colors | ||
|
||
declare const picocolors: Colors & { createColors: Generator } | ||
|
||
export default picocolors | ||
|
||
export let isColorSupported: boolean | ||
export let reset: Formatter | ||
export let bold: Formatter | ||
export let dim: Formatter | ||
export let italic: Formatter | ||
export let underline: Formatter | ||
export let inverse: Formatter | ||
export let hidden: Formatter | ||
export let strikethrough: Formatter | ||
export let black: Formatter | ||
export let red: Formatter | ||
export let green: Formatter | ||
export let yellow: Formatter | ||
export let blue: Formatter | ||
export let magenta: Formatter | ||
export let cyan: Formatter | ||
export let white: Formatter | ||
export let gray: Formatter | ||
export let bgBlack: Formatter | ||
export let bgRed: Formatter | ||
export let bgGreen: Formatter | ||
export let bgYellow: Formatter | ||
export let bgBlue: Formatter | ||
export let bgMagenta: Formatter | ||
export let bgCyan: Formatter | ||
export let bgWhite: Formatter | ||
|
||
export let createColors: Generator |
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,27 @@ | ||
import pc from "../picocolors.mjs" | ||
import { bold, createColors } from "../picocolors.mjs" | ||
import assert from "node:assert" | ||
|
||
test("import all", () => { | ||
assert.equal(typeof pc, "object") | ||
assert.equal(typeof pc.bold, "function") | ||
assert.equal(typeof pc.createColors, "function") | ||
}) | ||
|
||
test("import bold", () => { | ||
assert.equal(typeof bold, "function") | ||
}) | ||
|
||
test("import createColors", () => { | ||
assert.equal(typeof createColors, "function") | ||
}) | ||
|
||
function test(name, fn) { | ||
try { | ||
fn() | ||
console.log(pc.green("✓ " + name)) | ||
} catch (error) { | ||
console.log(pc.red("✗ " + name)) | ||
throw error | ||
} | ||
} |
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,25 @@ | ||
import pc from "../picocolors.mjs" | ||
import { bold, createColors, Colors } from "../picocolors.mjs" | ||
|
||
test("default export", () => { | ||
let _result: string = pc.bold("test") | ||
}) | ||
|
||
test("named exports", () => { | ||
let _result: string = bold("test") | ||
}) | ||
|
||
test("factory function", () => { | ||
let _result1: Colors = pc.createColors() | ||
let _result2: Colors = createColors() | ||
}) | ||
|
||
function test(name: string, fn: () => void) : void { | ||
try { | ||
fn() | ||
console.log(pc.green("✓ " + name)) | ||
} catch (error) { | ||
console.log(pc.red("✗ " + name)) | ||
throw error | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it not be more logical to put the compiling of the types tests during the test script? As it is a way to tests that types are correct.
Also maybe adding
--noEmit
option to not produce any compiled files of the test, no ?