Skip to content

Commit

Permalink
feat(esm): Convert to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
ff6347 committed Apr 6, 2023
1 parent d3166db commit 7c86b98
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 214 deletions.
3 changes: 1 addition & 2 deletions __tests__/files/write-out-test.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
foo
===
# foo
4 changes: 2 additions & 2 deletions __tests__/parse-flags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("testing parse flags function", () => {
inPath: "__tests__/files/index.html",
};
parseFlags(options);
expect(mockOut.mock.calls[0][0]).toBe("foo\n===\n");
expect(mockOut.mock.calls[0][0]).toBe("# foo\n");
mockOut.mockRestore();
});

Expand Down Expand Up @@ -58,7 +58,7 @@ describe("testing parse flags function", () => {
};
parseFlags(options);
expect(mockClippy).toHaveBeenCalled();
expect(clipboardy.readSync()).toBe("foo\n===\n");
expect(clipboardy.readSync()).toBe("# foo\n");
process.stdin.isTTY = orig;
});
});
2 changes: 0 additions & 2 deletions dist/html2md.d.ts

This file was deleted.

81 changes: 0 additions & 81 deletions dist/html2md.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/html2md.js.map

This file was deleted.

8 changes: 0 additions & 8 deletions dist/lib/parse-flags.d.ts

This file was deleted.

24 changes: 0 additions & 24 deletions dist/lib/parse-flags.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/lib/parse-flags.js.map

This file was deleted.

12 changes: 0 additions & 12 deletions dist/lib/write-out.d.ts

This file was deleted.

47 changes: 0 additions & 47 deletions dist/lib/write-out.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/lib/write-out.js.map

This file was deleted.

30 changes: 8 additions & 22 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
module.exports = {
transform: {
"\\.[jt]sx?$": "ts-jest",
},
globals: {
"ts-jest": {
tsconfig: "./tsconfig.jest.json",
diagnostics: false,
useESM: true,
},
},
transform: {
"^.+\\.ts?$": "ts-jest",
},
testEnvironment: "node",
// setupFilesAfterEnv: ['<rootDir>/__tests__/jest.setup.after-env.ts'],
testRegex: "/__tests__/.*\\.(test|spec)?\\.(ts|tsx)$",
// globalSetup: '<rootDir>/__tests__/jest.setup.ts',
// globalTeardown: '<rootDir>/__tests__/jest.teardown.ts',
moduleFileExtensions: ["js", "json", "jsx", "node", "ts", "tsx"],
collectCoverage: true,
coverageReporters: ["lcov", "text"],
collectCoverageFrom: ["src/**/*.{ts,tsx}", "!src/html2md.ts"],
coverageThreshold: {
global: {
branches: 65,
functions: 75,
lines: 75,
statements: 75,
},
moduleNameMapper: {
"(.+)\\.js": "$1",
},
preset: "ts-jest",
testMatch: null,
testEnvironment: "node",
extensionsToTreatAsEsm: [".ts"],
};
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "to-markdown-cli",
"version": "0.4.5",
"description": "a little cli to turn html to markdown",
"engines": {
"node": ">=14.16"
},
"type": "module",
"main": "dist/html2md.js",
"engines": {
"node": ">=14.16"
},
"type": "module",
"main": "dist/html2md.js",
"scripts": {
"test": "jest",
"test:watch": "jest --watch",
Expand Down
3 changes: 3 additions & 0 deletions src/html2md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import fs from "fs";
import path from "path";
import program from "commander";
import { parseFlags } from "./lib/parse-flags.js";
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const pkg: { version: "string"; [key: string]: any } = JSON.parse(
fs.readFileSync(path.resolve(__dirname, "../package.json"), "utf8"),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/parse-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from "fs";
// const turndownService = new TurndownService();
// const gfm = turndownPluginGfm.gfm;
import clipboardy from "clipboardy";
import { writeOut } from "./write-out";
import { writeOut } from "./write-out.js";
export interface IParseFlagsOptions {
data: string;
inPath?: string;
Expand Down
5 changes: 2 additions & 3 deletions src/lib/write-out.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fs from "fs";
import TurndownService from "turndown";
const turndownPluginGfm = require("turndown-plugin-gfm");
const turndownService = new TurndownService();
const gfm = turndownPluginGfm.gfm;
import {gfm} from "turndown-plugin-gfm";
const turndownService = new TurndownService({ headingStyle: "atx"});
import clipboardy from "clipboardy";

/**
Expand Down
39 changes: 39 additions & 0 deletions src/turndown-plugin-gfm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
declare module 'turndown-plugin-gfm' {
import TurndownService from 'turndown';

type Filter = string | string[] | ((node: HTMLElement) => boolean);
type ReplacementFunction = (
content: string,
node: HTMLElement,
options: { fence: string }
) => string;

interface Rule {
filter: Filter;
replacement?: (
content: string,
node: HTMLElement,
options: TurndownService.Options,
captureGroups: string[]
) => string | void | null;
options?: TurndownService.Options;
}

function highlightedCodeBlock(turndownService: any): void;
function strikethrough(turndownService: any): void;
function tables(turndownService: any): void;
function taskListItems(turndownService: any): void;
function gfm(turndownService: any): void;

export {
highlightedCodeBlock,
strikethrough,
tables,
taskListItems,
gfm,
Rule,
Filter,
ReplacementFunction,
};
}

11 changes: 9 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
"examples",
"__mocks__"
],
"include": [
"src/**/*",
"jest.config.ts",
"__tests__/**/*"
],
"compilerOptions": {

"resolveJsonModule": true,
/* Basic Options */
"target": "ES2018" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "ESNext"/* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": [
"es5",
Expand Down Expand Up @@ -61,7 +67,8 @@
"./node_modules/@types"
] /* List of folders to include type definitions from. */,
"types": [
"node"
"node",
"jest"
] /* Type declaration files to be included in compilation. */,
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
Expand Down

0 comments on commit 7c86b98

Please sign in to comment.