Skip to content

Commit

Permalink
Introduce rollup for producing compliant ESM distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Oct 2, 2024
1 parent 03e48ce commit d04289d
Show file tree
Hide file tree
Showing 5 changed files with 545 additions and 11 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/deno_dist/
/.eslintrc.js
/CHANGELOG.md
/rollup.config.js
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"scripts": {
"build": "yarn build:cjs && yarn build:esm && yarn build:deno",
"build:cjs": "tsc",
"build:esm": "rm -rf dist/esm && tsc -p tsconfig.esm.json && js2mjs dist/esm",
"build:esm": "rm -rf dist/esm && npx rollup -c",
"build:deno": "denoify",
"test": "yarn test:node && yarn test:deno",
"test:deno": "deno run --reload --unstable --no-check deno_dist/mod.ts",
"test:node": "ts-node test/index.ts",
"lint:check": "eslint . --ext .ts,.tsx",
"lint": "npm run lint:check -- --fix",
"_format": "prettier '**/*.{ts,tsx,json,md}'",
"_format": "prettier '**/*.{ts,tsx,json,md,js}'",
"format": "npm run _format -- --write",
"format:check": "npm run _format -- --list-different"
},
Expand Down Expand Up @@ -68,19 +68,24 @@
"keywords": [],
"homepage": "https://github.com/garronej/tsafe",
"devDependencies": {
"@rollup/plugin-commonjs": "^28.0.0",
"@rollup/plugin-node-resolve": "^15.3.0",
"@types/node": "^18.11.18",
"@typescript-eslint/eslint-plugin": "^4.15.1",
"@typescript-eslint/parser": "^4.15.1",
"denoify": "^1.6.13",
"eslint": "^7.20.0",
"eslint-config-prettier": "^7.2.0",
"evt": "^2.4.18",
"glob": "^11.0.0",
"husky": "^4.3.0",
"improved-garbanzo-easy": "^0.0.1",
"lint-staged": "^10.5.4",
"prettier": "^3.3.1",
"typescript": "^5.0.4",
"rollup": "^4.23.0",
"rollup-plugin-typescript2": "^0.36.0",
"ts-node": "^10.9.1",
"js2mjs": "^1.0.1"
"tslib": "^2.7.0",
"typescript": "^5.0.4"
}
}
23 changes: 23 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const typescript = require("rollup-plugin-typescript2");
const glob = require("glob");

module.exports = {
input: glob.sync("src/**/*.ts"), // Use glob pattern to include all .ts files
output: {
dir: "dist/esm",
format: "esm",
sourcemap: true,
entryFileNames: "[name].mjs",
preserveModules: true,
preserveModulesRoot: "src",
sourcemapPathTransform: relativeSourcePath =>
relativeSourcePath.replace(/^..\//, "")
},
plugins: [
typescript({
tsconfig: "./tsconfig.esm.json",
sourceMap: true,
}),
],
};

4 changes: 2 additions & 2 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ES2015",
"outDir": "./dist/esm"
"target": "ES2019",
"module": "ES2015"
}
}
Loading

0 comments on commit d04289d

Please sign in to comment.