Skip to content

Commit

Permalink
Merge pull request #13 from hapijs/chore/hybrid-module
Browse files Browse the repository at this point in the history
chore: convert to hybrid module
  • Loading branch information
Marsup authored Oct 23, 2024
2 parents c6dc393 + de8e8c9 commit bcd79cb
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 60 deletions.
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

20 changes: 0 additions & 20 deletions .eslintrc.js

This file was deleted.

5 changes: 3 additions & 2 deletions .github/scripts/update-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Wreck from '@hapi/wreck';

const ianaUri = 'https://data.iana.org/TLD/tlds-alpha-by-domain.txt';

async function fetchTLDs() {
const fetchTLDs = async () => {
const request = await Wreck.get(ianaUri);
const rl = createInterface({
input: Wreck.toReadableStream(request.payload as string),
Expand All @@ -24,6 +24,7 @@ async function fetchTLDs() {
if (!/^# Version \d{10}, Last Updated .+ UTC$/.test(line)) {
throw new Error('Unexpected version line');
}

data.version = line;
} else if (line.length > 0) {
data.domains.push(line);
Expand Down Expand Up @@ -61,6 +62,6 @@ ${data.domains.map((d) => ` '${d}',`).join('\n')}
// An error means the file is probably different
await writeFile('./src/tlds.ts', formattedFile);
}
}
};

fetchTLDs();
2 changes: 1 addition & 1 deletion .github/workflows/ci-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ on:

jobs:
test:
uses: hapijs/.github/.github/workflows/ci-module.yml@master
uses: hapijs/.github/.github/workflows/ci-module.yml@min-node-18-hapi-21
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
**/node_modules
**/package-lock.json
**/pnpm-lock.yaml
**/yarn.lock

coverage.*

Expand All @@ -12,5 +14,6 @@ coverage.*
**/.vscode
**/.idea

.tshy
dist
esm
2 changes: 1 addition & 1 deletion .labrc.js → .labrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
typescript: true,
assert: '@hapi/code'
assert: '@hapi/code',
};
33 changes: 33 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Globals from 'globals';
import HapiPlugin from '@hapi/eslint-plugin';
import prettierPluginRecommended from 'eslint-plugin-prettier/recommended';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{
ignores: ['node_modules/**', 'dist/**', '.tshy/**'],
},
{
files: ['**/*.ts', '**/*.cjs'],
},
...HapiPlugin.configs.module,
...tseslint.configs.recommended,
prettierPluginRecommended,
{
languageOptions: {
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module',
},
globals: {
...Globals.browser,
...Globals.es2021,
},
},
rules: {
'@hapi/scope-start': 0,
'@typescript-eslint/no-explicit-any': 0,
'prettier/prettier': 'error',
},
},
);
59 changes: 39 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,32 @@
"description": "TLDS list for domain validation",
"version": "1.0.7",
"repository": "git://github.com/hapijs/tlds",
"main": "./dist/index.js",
"module": "./esm/index.js",
"typings": "./dist/index.d.ts",
"type": "module",
"tshy": {
"main": true,
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
}
},
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
},
"main": "./dist/commonjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/commonjs/index.d.ts",
"files": [
"dist",
"esm",
"src"
"dist"
],
"keywords": [
"domain",
Expand All @@ -18,26 +37,26 @@
"engines": {
"node": ">=14.0.0"
},
"dependencies": {},
"devDependencies": {
"@hapi/code": "^9.0.3",
"@hapi/lab": "^25.1.3",
"@hapi/wreck": "^18.0.1",
"@types/node": "^20.11.30",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"prettier": "^3.0.3",
"@hapi/eslint-plugin": "^7.0.0",
"@hapi/lab": "^26.0.0",
"@hapi/wreck": "^18.1.0",
"@types/node": "^18.19.59",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"globals": "^15.11.0",
"prettier": "^3.3.3",
"ts-node": "^10.9.2",
"typescript": "^5.2.2"
"tshy": "^2.0.1",
"typescript": "^5.6.3",
"typescript-eslint": "^8.11.0"
},
"scripts": {
"test": "lab -t 100 -L",
"prepare": "tshy",
"test": "lab -t 100 -L --typescript",
"test-cov-html": "lab -t 100 -L -r html -o coverage.html",
"dist": "rm -rf dist esm && tsc --module commonjs --outdir dist && tsc --module es6 --outdir esm",
"prepublishOnly": "npm run dist",
"format": "prettier --write '**/*.ts'",
"format": "prettier --write '**/*.{cjs,ts,md}'",
"update-list": "ts-node .github/scripts/update-list.ts"
},
"license": "BSD-3-Clause"
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { TLDS } from './tlds';
import { TLDS } from './tlds.js';

export const tlds = new Set(TLDS.map((tld) => tld.toLowerCase()));
2 changes: 1 addition & 1 deletion test/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@hapi/code';
import * as Lab from '@hapi/lab';

import { tlds } from '../src';
import { tlds } from '../src/index.js';

const { describe, it } = (exports.lab = Lab.script());

Expand Down
21 changes: 10 additions & 11 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
{
"compilerOptions": {
"target": "es2021",
"module": "es6",
"moduleResolution": "node",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"rootDir": "src",
"outDir": "esm",
"strict": true,
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true,
"exactOptionalPropertyTypes": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"experimentalDecorators": true
},
"include": [
"*.ts",
"**/*.ts"
],
"exclude": [
"node_modules",
"dist",
"esm",
"test/*"
"src/**/*.ts",
"test/**/*.ts"
],
"ts-node": {
"compilerOptions": {
Expand Down

0 comments on commit bcd79cb

Please sign in to comment.