Skip to content

Commit

Permalink
Merge pull request #43 from euberdeveloper/esm
Browse files Browse the repository at this point in the history
Esm
  • Loading branch information
euberdeveloper authored Jun 12, 2024
2 parents 0685e55 + 6cab951 commit b181d7b
Show file tree
Hide file tree
Showing 102 changed files with 869 additions and 1,870 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use pnpm ${{ matrix.pnpm-version }}
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: ${{ matrix.pnpm-version }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: main

Expand All @@ -20,7 +20,7 @@ jobs:
config: './docs/tree/dree.config.json'

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "docs: inject dree (automated commit)"
branch: main
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use pnpm ${{ matrix.pnpm-version }}
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: ${{ matrix.pnpm-version }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -29,20 +29,20 @@ jobs:
run: pnpm run transpile

- name: Run tests and generate coverage report
run: pnpm run nyc
run: pnpm run test:cover

- name: Send coverage report to Coveralls
uses: coverallsapp/github-action@master
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Send coverage report to Codecov
uses: Atrox/codecov-action@v0.1.3
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Send coverage report to Code Climate
uses: paambaati/codeclimate-action@v2.7.5
uses: paambaati/codeclimate-action@v8
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}

62 changes: 62 additions & 0 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import fs from 'node:fs';
import { build } from 'esbuild';
import * as importMap from "esbuild-plugin-import-map";

import packageJson from './package.json' assert { type: 'json' };

importMap.load({
imports: {
'../lib/index.js': '../lib/esm/index.esm.js'
}
});

function getExternalDependencies(allow = []) {
const deps = packageJson.dependencies ? Object.keys(packageJson.dependencies).filter(dep => !allow.includes(dep)) : [];
const peerDeps = packageJson.peerDependencies ? Object.keys(packageJson.peerDependencies).filter(dep => !allow.includes(dep)) : [];
return [...deps, ...peerDeps];
}

async function buildModule() {
const shared = {
platform: 'node',
entryPoints: ['source/lib/index.ts'],
bundle: true,
minify: true,
treeShaking: true,
sourcemap: true
};

await build({
...shared,
outfile: 'bundled/lib/commonjs/index.js',
format: 'cjs',
external: getExternalDependencies()
});

await build({
...shared,
outfile: 'bundled/lib/esm/index.esm.js',
format: 'esm',
external: getExternalDependencies()
});

await build({
...shared,
entryPoints: ['source/bin/index.ts'],
outfile: 'bundled/bin/index.js',
format: 'esm',
external: getExternalDependencies(),
plugins: [importMap.plugin()],
define: {
'__VERSION__': `"${packageJson.version}"`
}
});
}

function generateCommonjsPackageJson() {
const packageJsonCommonJs = JSON.stringify({ ...packageJson, type: undefined }, null, 2);
fs.writeFileSync('./bundled/lib/commonjs/package.json', packageJsonCommonJs);
}

await buildModule();
generateCommonjsPackageJson();
52 changes: 33 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,53 @@
"name": "dree",
"version": "4.8.6",
"description": "A nodejs module wich helps you handle a directory tree providing you its abstraction through tested functions and a custom configuration.",
"main": "bundled/lib/index.js",
"types": "bundled/lib/index.d.ts",
"main": "bundled/lib/commonjs/index.js",
"types": "bundled/lib/commonjs/index.d.ts",
"module": "./bundled/lib/esm/index.esm.js",
"bin": {
"dree": "bundled/bin/index.js"
},
"exports": {
".": {
"require": {
"default": "./bundled/lib/commonjs/index.js",
"types": "./bundled/lib/commonjs/index.d.ts"
},
"import": {
"default": "./bundled/lib/esm/index.esm.js",
"types": "./bundled/lib/esm/index.d.ts"
}
}
},
"files": [
"package.json",
"bundled",
"README.md",
"CHANGELOG.md",
"LICENSE"
],
"type": "module",
"scripts": {
"pretranspile": "shx rm -rf dist",
"transpile": "tsc -p source",
"prebundle": "shx rm -rf dist bundled",
"bundle": "webpack",
"bundle:esm": "node build.mjs",
"bundle:dts": "dts-bundle-generator -o bundled/lib/commonjs/index.d.ts --project source/tsconfig.json source/lib/index.ts",
"bundle": "pnpm bundle:esm && pnpm bundle:dts",
"postbundle:dts": "cp bundled/lib/commonjs/index.d.ts bundled/lib/esm/index.d.ts",
"script:getr:linux": "node scripts/generate-expected-tests-results linux",
"script:getr:mac": "node scripts/generate-expected-tests-results mac",
"script:getr:windows": "node scripts/generate-expected-tests-results windows",
"test": "mocha --reporter spec test/test.mjs",
"nyc": "nyc --extension=ts --reporter=html --reporter=text --reporter=lcov npm run test",
"cover:coveralls": "nyc report --extension=ts --reporter=text-lcov | coveralls",
"cover:codecov": "nyc report --extension=ts --reporter=text-lcov > coverage.lcov && codecov",
"cover": "npm run cover:coveralls && npm run cover:codecov",
"test": "mocha --reporter spec test/test.js",
"test:cover": "c8 --reporter=html --reporter=text --reporter=lcov pnpm test",
"cover:coveralls": "c8 report --reporter=text-lcov | coveralls",
"cover:codecov": "c8 report --reporter=text-lcov > coverage.lcov && codecov",
"cover": "pnpm cover:coveralls && pnpm cover:codecov",
"docs:html": "typedoc",
"docs:html-dev": "typedoc --options typedoc.dev.js",
"docs:html-dev": "typedoc --options typedoc.dev.cjs",
"predocs": "shx rm -rf docs/documentation",
"docs": "npm run docs:html && npm run docs:html-dev",
"prepublishOnly": "npm run bundle",
"docs": "pnpm docs:html && pnpm docs:html-dev",
"prepublishOnly": "pnpm bundle",
"release": "dotenv release-it"
},
"repository": {
Expand Down Expand Up @@ -68,22 +85,19 @@
"@release-it/conventional-changelog": "^8.0.1",
"@types/node": "^20.14.2",
"@types/yargs": "^17.0.32",
"bundle-declarations-webpack-plugin": "^5.1.1",
"c8": "^10.1.1",
"chai": "^5.1.1",
"chai-as-promised": "^8.0.0",
"codecov": "^3.8.3",
"coveralls": "^3.1.1",
"dotenv-cli": "^7.4.2",
"dts-bundle-generator": "^9.5.1",
"esbuild": "^0.21.5",
"esbuild-plugin-import-map": "^2.1.0",
"mocha": "^10.4.0",
"nyc": "^17.0.0",
"release-it": "^17.3.0",
"shebang-loader": "^0.0.1",
"shx": "^0.3.4",
"ts-loader": "^9.5.1",
"typedoc": "^0.25.13",
"typescript": "^5.4.5",
"webpack": "^5.92.0",
"webpack-cli": "^5.1.4",
"webpack-node-externals": "^3.0.0"
"typescript": "^5.4.5"
}
}
Loading

0 comments on commit b181d7b

Please sign in to comment.