Skip to content

Commit

Permalink
Merge pull request #114 from samchon/features/esm
Browse files Browse the repository at this point in the history
Publish both CJS and ESM
  • Loading branch information
samchon committed Mar 27, 2024
2 parents c643412 + 8863122 commit b620c76
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 141 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ jobs:
Ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 12.x
node-version: 20.x
- run: npm install
- run: npm run module
- run: npm run compile
- run: npm run build
- run: npm run test
12 changes: 2 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@
assets/benchmarks/
node_modules/
lib/
dist/

package-lock.json
*.log

#----
# COMPILED FILES
#----
*.js
*.js.map
*.d.ts
*.d.ts.map
pnpm-lock.yaml
*.log
4 changes: 0 additions & 4 deletions .npmignore

This file was deleted.

102 changes: 0 additions & 102 deletions build/dist.ts

This file was deleted.

48 changes: 30 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,38 @@
"email": "samchon.github@gmail.com",
"url": "https://github.com/samchon"
},
"version": "2.5.16",
"typings": "./index.d.ts",
"main": "./index.js",
"version": "3.0.0",
"main": "./lib/index.js",
"typings": "./lib/index.d.ts",
"exports": {
".": {
"types": "./lib/index.d.ts",
"require": "./lib/index.js",
"import": "./lib/index.mjs"
}
},
"scripts": {
"api": "typedoc src --exclude \"**/+(test|benchmark)/**\" --excludeNotDocumented --plugin typedoc-plugin-external-module-name --plugin typedoc-plugin-exclude-references --out ../tstl@gh-pages/api",
"migration": "ts-node build/migration",
"benchmark": "node benchmark",
"build": "npm run clean && npm run module && npm run compile && npm run test",
"clean": "rimraf dist",
"compile": "tsc",
"dev": "tsc --watch",
"dev:ts": "tsc --watch --noEmit --module esnext",
"dist": "ts-node build/dist",
"module": "tsc --noEmit --module amd && tsc --noEmit --module system && tsc --noEmit --module umd && tsc --noEmit --module esnext",
"package": "npm run test:ts && npm run dist && cd dist && npm publish",
"package:next": "npm run package -- --tag next",
"prettier": "prettier --write ./**/*.ts",
"test": "node dist/test",
"test:ts": "ts-node src/test"
"build": "rimraf lib && tsc && rollup -c",
"dev": "rimraf lib && tsc --watch",
"prettier": "prettier --write ./src",
"test": "node lib/test"
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@types/cli": "^0.11.19",
"@types/node": "^14.6.3",
"cli": "^1.0.1",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"rollup": "^4.13.1",
"source-map-support": "^0.5.21",
"ts-node": "^10.7.0",
"typedoc": "^0.22.13",
"typescript": "^4.6.2"
"tslib": "^2.6.2",
"typedoc": "^0.25.12",
"typescript": "^5.4.3"
},
"homepage": "https://github.com/samchon/tstl",
"repository": {
Expand Down Expand Up @@ -97,5 +99,15 @@
"SharedLock",
"UniqueLock",
"Singleton"
],
"files": [
"LICENSE",
"README.md",
"lib/",
"src/",
"!lib/benchmark",
"!lib/test",
"!src/benchmark",
"!src/test"
]
}
29 changes: 29 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const typescript = require('@rollup/plugin-typescript');
const terser = require('@rollup/plugin-terser');

module.exports = {
input: './src/index.ts',
output: {
dir: 'lib',
format: 'esm',
entryFileNames: '[name].mjs',
sourcemap: true,
},
plugins: [
typescript({
tsconfig: "tsconfig.json",
module: "ES2020",
target: "ES2020",
}),
terser({
format: {
comments: 'some',
beautify: true,
ecma: '2020',
},
compress: false,
mangle: false,
module: true,
}),
]
};
2 changes: 1 addition & 1 deletion src/test/numeric/test_special_maths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as std from "../../index";
const PATH =
__filename.substr(-2) === "ts"
? `${__dirname}/special_math`
: `${__dirname}/special_math`.replace("dist", "src");
: `${__dirname}/special_math`.replace("lib", "src");

export function similar(x: number, y: number, precision = 0.05): boolean {
const diff: number = _Difference(x, y);
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"outDir": "./lib", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
Expand Down

0 comments on commit b620c76

Please sign in to comment.