LLazyEmail / LLazyEmail/markdown-regex

migration to TS

Open
#325 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
11
Forks
3
Avg merge
4h 51m
Merged PRs (30d)
20

Description

Got it. Here’s a focused, practical plan that matches what you described.

### Recommended Direction for this module

**Goal**: Keep it tiny and focused (regex constants + future custom-tag addons), but make the *tooling & packaging* modern, reliable, and low-maintenance.

#### 1. Language & Source
- Move fully to **TypeScript**.
- Source becomes pure `.ts` files that only export `RegExp` constants (and later custom-tag helpers).
- No runtime logic beyond the regexes themselves → extremely easy to tree-shake and bundle.

#### 2. Bundler choice (replace Rollup)
For a pure constants library the best modern options are:

| Tool | Pros | Cons | Recommendation |
|------------|-------------------------------------------|--------------------------|--------------|
| **tsup** | Zero-config, built on esbuild, excellent dual CJS/ESM + dts | Slightly less flexible than Rollup for exotic cases | **Strongly recommended** |
| unbuild | Very good for libraries, solid dts | A bit more config | Good alternative |
| Vite library mode | Familiar if you already use Vite | Heavier for pure libs | Overkill here |

**Recommendation**: Switch to **tsup**.
It gives you in one command:
- CJS
- ESM
- IIFE / browser
- `.d.ts` (and optionally `.d.mts`)
- minified browser build if you want

Example `tsup.config.ts` that covers everything you listed:

```ts
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm', 'iife'],
dts: true,
splitting: false,
sourcemap: true,
clean: true,
minify: true, // only for iife if you want
globalName: 'MarkdownRegex',
target: 'es2020',
outExtension({ format }) {
return {
js: format === 'cjs' ? '.cjs' : format === 'esm' ? '.mjs' : '.js',
};
},
});
```

This replaces the entire complicated Rollup + polyfills setup.

#### 3. Package.json exports (modern dual package)
```json
{
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"browser": "./dist/index.global.js"
}
},
"sideEffects": false,
"files": ["dist"]
}
```

#### 4. React / Browser
- **Browser**: the IIFE build from tsup is enough.
- **React**: this module has no React dependency and shouldn’t. Just consume the ESM/CJS build from any React project. No special React build is needed (and adding one would only increase maintenance).

#### 5. Future custom tags / addons
Keep the core very clean:

```
src/
index.ts ← re-exports everything
core/ ← current basic tags
addons/ ← future custom tags
index.ts
my-custom-tag.ts
```

or even better later:

```ts
// users can do
import { REGEXP_LINK } from 'markdown-regex';
import { REGEXP_CUSTOM_XYZ } from 'markdown-regex/addons';
```

You can expose subpath exports when the time comes.

#### 6. Keep (and improve) your existing tooling
- **Tests**: keep Jest (or migrate to Vitest — it’s faster and works great with TypeScript + tsup). Your current test structure is already good; just make the fixtures more realistic and test both `\n` and `\r\n`.
- **CI / GitHub Actions**: keep it. Just update the workflow to run `tsup` + tests + type-check.
- **AI helpers**: continue using them. With clean TypeScript + good tests the AI suggestions become much more reliable.
- **Linting**: ESLint + Prettier (or Biome if you want something even simpler).

#### 7. Migration order (low risk)
1. Create a new branch.
2. Convert `src/` to TypeScript (the regexes themselves barely change).
3. Add `tsup` + new `package.json` exports.
4. Fix the newline handling (remove `os` dependency completely — this is still the most important correctness fix).
5. Make sure all existing tests pass + add a few more edge cases.
6. Update README + CHANGELOG.
7. Publish as `2.0.0` (breaking because of the packaging change + better newlines).

---

Would you like me to:

A. Draft the full modern `package.json` + `tsup.config.ts` + folder structure right now?
B. Show the TypeScript version of the current core regexes with proper flexible newlines?
C. Propose the GitHub Actions workflow that runs everything cleanly?

Just tell me which piece you want first and I’ll give you ready-to-use code.

Contributor guide

Open the contributing guide

Research direction

Start by inventorying the current src/ layout, Rollup configuration, package.json, existing Jest tests, and the GitHub Actions workflow. Confirm the migration scope and chosen build tool before changing anything; done means the TypeScript build, package exports, type-check, tests, newline cases, documentation, and release workflow all agree with the final plan.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, javascript, rollup, typescript
Domain
build-system, release, testing, tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.