Skip to content

Commit

Permalink
feat(esm): simplify build step with tsc and remove esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
tduyng committed Apr 13, 2023
1 parent 04ceed2 commit b8c9218
Show file tree
Hide file tree
Showing 19 changed files with 47 additions and 692 deletions.
2 changes: 1 addition & 1 deletion examples/cjs/example1.cjs → examples/cjs/example1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const logger = require('../../lib/cjs/index.cjs')
const logger = require('../../lib/cjs/index.js')

logger.setNamespaces('root:*')
logger.setLevel('debug')
Expand Down
2 changes: 1 addition & 1 deletion examples/cjs/example2.cjs → examples/cjs/example2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const logger = require('../../lib/cjs/index.cjs')
const logger = require('../../lib/cjs/index.js')

logger.setNamespaces('root:*')
logger.setLevel('debug')
Expand Down
2 changes: 1 addition & 1 deletion examples/cjs/example3.cjs → examples/cjs/example3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const logger = require('../../lib/cjs/index.cjs')
const logger = require('../../lib/cjs/index.js')

logger.setNamespaces('namespace:*')
logger.setLevel('debug')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const logger = require('../../lib/cjs/index.cjs')
const logger = require('../../lib/cjs/index.js')

logger.setOutput(logger.outputs.pretty)
logger.setNamespaces('*')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const logger = require('../../lib/cjs/index.cjs')
const logger = require('../../lib/cjs/index.js')

logger.setOutput(logger.outputs.pretty)
logger.setNamespaces('namespace:*')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const logger = require('../../lib/cjs/index.cjs')
const logger = require('../../lib/cjs/index.js')

logger.setOutput(logger.outputs.pretty)
logger.setNamespaces('*')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const logger = require('../../lib/cjs/index.cjs')
const logger = require('../../lib/cjs/index.js')

logger.setNamespaces('namespace:*')
logger.setLevel('debug')
Expand Down
1 change: 1 addition & 0 deletions examples/cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "commonjs"}
1 change: 1 addition & 0 deletions examples/esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "module"}
5 changes: 4 additions & 1 deletion examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ console.log(chalk.green('RUN ESM EXAMPLES:'))
await $`for file in examples/esm/*.js; do node "$file"; done`

console.log(chalk.green('RUN CJS EXAMPLES:'))
await $`for file in examples/cjs/*.cjs; do node "$file"; done`
await $`for file in examples/cjs/*.js; do node "$file"; done`

// console.log(chalk.green('RUN TYPESCRIPTS EXAMPLES:'))
// await $`bun examples/typescript/index.ts`
10 changes: 0 additions & 10 deletions examples/typescript/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logger from '../../lib/esm/index.js'
import loggerCjs from '../../lib/cjs/index.cjs'
import loggerNpm from '@ekino/logger'
import loggerNpmTest from 'td-logger'

// ESM
logger.setOutput(logger.outputs.pretty)
Expand Down Expand Up @@ -31,12 +30,3 @@ loggerNpm.setLevel('info')
const logNpm = loggerNpm.createLogger('namespace:subNamespace')

logNpm.warn('example of logger npm', { someData: 'someValue of logger npm' })

// NPM Test
loggerNpmTest.setOutput(loggerNpmTest.outputs.pretty)
loggerNpmTest.setNamespaces('namespace:*')
loggerNpmTest.setLevel('info')

const logNpmTest = loggerNpmTest.createLogger('namespace:subNamespace')

logNpmTest.warn('example of logger npm test', { someData: 'someValue of logger npm test' })
5 changes: 2 additions & 3 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "bun index.ts"
},
"keywords": [],
"author": "",
Expand All @@ -14,7 +14,6 @@
"typescript": "5.0.4"
},
"dependencies": {
"@ekino/logger": "2.1.1",
"td-logger": "3.0.0-rc"
"@ekino/logger": "^2.1.1"
}
}
24 changes: 7 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,17 @@
"files": [
"/lib"
],
"main": "lib/esm/index.js",
"types": "lib/esm/index.d.ts",
"exports": {
".": {
"require": {
"types": "./lib/cjs/index.d.ts",
"default": "./lib/cjs/index.cjs"
"default": "./lib/cjs/index.js",
"types": "./lib/cjs/index.d.ts"
},
"import": {
"types": "./lib/esm/index.d.ts",
"default": "./lib/esm/index.js"
}
},
"./*": {
"require": {
"types": "./lib/cjs/*.d.ts",
"default": "./lib/cjs/*.cjs"
},
"import": {
"types": "./lib/esm/*.d.ts",
"default": "./lib/esm/*.js"
"default": "./lib/esm/index.js",
"types": "./lib/esm/index.d.ts"
}
}
},
Expand Down Expand Up @@ -77,9 +69,7 @@
"scripts": {
"fmt": "prettier --color --write \"{*,src/**/*,test/**/*}.{js,ts}\" --cache",
"check-fmt": "prettier --list-different \"{*,test/**/*}.{js,ts}\"",
"build-cjs": "node scripts/esbuild-cjs.js && tsc -p ./tsconfig.lib.json --declarationDir lib/cjs && node scripts/casting.js",
"build-esm": "node scripts/esbuild-esm.js && tsc -p ./tsconfig.lib.json --declarationDir lib/esm",
"build": "yarn build-cjs && yarn build-esm",
"build": "node scripts/build.js",
"prepublishOnly": "rm -rf lib && yarn build",
"test": "ava",
"test-cover": "c8 ava",
Expand Down
8 changes: 8 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env zx
import { $ } from 'zx'

await $`npx tsc --module es2022 --outDir lib/esm`
await $`echo '{"type": "module"}' > lib/esm/package.json`

await $`npx tsc --module commonjs --outDir lib/cjs`
await $`echo '{"type": "commonjs"}' > lib/cjs/package.json`
32 changes: 0 additions & 32 deletions scripts/casting.js

This file was deleted.

19 changes: 0 additions & 19 deletions scripts/esbuild-cjs.js

This file was deleted.

19 changes: 0 additions & 19 deletions scripts/esbuild-esm.js

This file was deleted.

3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"allowJs": true,
"target": "esnext",
"lib": ["esnext","dom"],
"module": "nodenext",
"module": "es2022",
"moduleResolution": "nodenext",
"alwaysStrict": true,
"skipLibCheck": true,
Expand All @@ -19,7 +19,6 @@
"typeRoots": ["./node_modules/@types", "./@types"],
"sourceMap": true,
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "lib"
},
"include": ["src/**/*", "test/**/*.ts"],
Expand Down
Loading

0 comments on commit b8c9218

Please sign in to comment.