Skip to content

Commit

Permalink
improve esm/cjs export using @beforesemicolon/builder
Browse files Browse the repository at this point in the history
  • Loading branch information
ECorreia45 committed Oct 28, 2024
1 parent cb727f0 commit 725230e
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 45 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ npm install @beforesemicolon/html-parser
<head>

<!-- Grab the latest version -->
<script src="https://unpkg.com/@beforesemicolon/html-parser/dist/parser-client.min.js"></script>
<script src="https://unpkg.com/@beforesemicolon/html-parser/dist/client.js"></script>

<!-- Or a specific version -->
<script src="https://unpkg.com/@beforesemicolon/[email protected]/dist/parser-client.min.js"></script>
<script src="https://unpkg.com/@beforesemicolon/[email protected]/dist/client.js"></script>

</head>
<body></body>
Expand Down
9 changes: 9 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
transform: {
'^.+\\.ts$': 'ts-jest',
},
testEnvironment: 'jsdom',
testRegex: './src/.*\\.(test|spec)?\\.(js|ts)$',
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
roots: ['<rootDir>/src'],
}
9 changes: 0 additions & 9 deletions jest.config.js

This file was deleted.

30 changes: 19 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
{
"name": "@beforesemicolon/html-parser",
"version": "0.5.0",
"version": "0.6.0",
"description": "HTML parser for any Javascript runtime environment",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"types": "./dist/types/index.d.ts",
"exports": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"default": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts"
},
"scripts": {
"test": "jest",
"test:coverage": "jest --coverage",
"build:min": "esbuild `find src \\( -name '*.ts' ! -name '*.spec.ts' \\)` --outdir=dist --platform=node --format=cjs --keep-names --minify --target=esnext\n",
"build:browser": "esbuild src/client.ts --bundle --minify --keep-names --sourcemap --target=esnext --outfile=dist/parser-client.min.js",
"build": "npm test && rm -rf dist && tsc && npm run build:min && npm run build:browser",
"build:browser": "node node_modules/@beforesemicolon/builder/dist/build-browser.js",
"build:modules": "node node_modules/@beforesemicolon/builder/dist/build-modules.js",
"build": "rm -rf dist && npm-run-all lint test && tsc --emitDeclarationOnly && npm-run-all build:modules build:browser",
"lint": "eslint ./src && prettier --check ./src",
"format": "eslint ./src --fix && prettier --write ./src"
},
Expand All @@ -27,24 +33,26 @@
"type": "git"
},
"devDependencies": {
"@beforesemicolon/builder": "^1.1.1",
"@types/jest": "^29.5.1",
"@types/jsdom": "^21.1.1",
"@types/node": "^20.1.0",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"core-js": "^3.31.0",
"esbuild": "^0.17.18",
"eslint": "^8.50.0",
"eslint-config-prettier": "^9.0.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-n": "^16.1.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.5.0",
"eslint-plugin-prettier": "^5.1.2",
"eslint-plugin-promise": "^6.1.1",
"htmlparser-benchmark": "^1.1.3",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jsdom": "^22.1.0",
"npm-run-all": "^4.1.5",
"prettier": "3.0.3",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
Expand Down
2 changes: 1 addition & 1 deletion src/Doc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { selfClosingTags } from './self-closing-tags'
import { selfClosingTags } from './self-closing-tags.ts'

export interface NodeLike {
readonly nodeType: number
Expand Down
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parse } from './parse'
import { Doc } from './Doc'
import { parse } from './parse.ts'
import { Doc } from './Doc.ts'

if (window) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './parse'
export * from './Doc'
export * from './parse.ts'
export * from './Doc.ts'
3 changes: 1 addition & 2 deletions src/parse.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {parse} from './parse';
import {CommentLike} from "./Doc";
import {parse} from './parse.ts';

function stringifyNode(node: any): string {
if (node) {
Expand Down
4 changes: 2 additions & 2 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
ElementLike,
NodeLike,
DocumentFragmentLike,
} from './Doc'
import { selfClosingTags } from './self-closing-tags'
} from './Doc.ts'
import { selfClosingTags } from './self-closing-tags.ts'

export type NodeHandlerCallback = (node: ElementLike | NodeLike) => void

Expand Down
24 changes: 10 additions & 14 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
{
"compilerOptions": {
"target": "ESNEXT",
"module": "es6",
"lib": [
"dom",
"es2015.proxy"
],
"module": "nodenext",
"lib": ["dom", "es2015.proxy", "es2021.weakref"],
"declaration": true,
"declarationMap": false,
"sourceMap": false,
"outDir": "./dist",
"sourceMap": true,
"outDir": "./dist/types",
"removeComments": true,
"downlevelIteration": true,
"strict": true,
"alwaysStrict": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"moduleResolution": "nodenext",
"esModuleInterop": true,
"skipLibCheck": true,
"allowImportingTsExtensions": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true
},
"include": [
"./src/**/*"
],
"exclude": [
"src/**/*.spec.ts"
]
"include": ["./src/**/*"],
"exclude": ["src/**/*.spec.ts"]
}

0 comments on commit 725230e

Please sign in to comment.