File tree Expand file tree Collapse file tree 11 files changed +53
-42
lines changed
Expand file tree Collapse file tree 11 files changed +53
-42
lines changed Original file line number Diff line number Diff line change 66 },
77 "parser" : " @typescript-eslint/parser" ,
88 "parserOptions" : {
9- "project" : " ./tsconfig.lint. json"
9+ "project" : " ./tsconfig.json"
1010 },
1111 "plugins" : [" import" , " @typescript-eslint" ],
1212 "ignorePatterns" : [" scripts/*" ],
Original file line number Diff line number Diff line change @@ -34,15 +34,15 @@ Typescript Library Starter relies on [volta](https://volta.sh/) to ensure node v
3434### Typescript
3535
3636Leverages [ esbuild] ( https://github.com/evanw/esbuild ) for blazing fast builds, but keeps ` tsc ` to generate ` .d.ts ` files.
37- Generates two builds to support both ESM and CJS .
37+ Generates a single ESM build .
3838
3939Commands:
4040
41- - ` build ` : runs typechecking then generates CJS, ESM and ` d.ts ` files in the ` build/ ` directory
41+ - ` build ` : runs typechecking then ESM and ` d.ts ` files in the ` build/ ` directory
4242- ` clean ` : removes the ` build/ ` directory
4343- ` type:dts ` : only generates ` d.ts `
4444- ` type:check ` : only run typechecking
45- - ` type:build ` : only generates CJS and ESM
45+ - ` type:build ` : only generates ESM
4646
4747### Tests
4848
Original file line number Diff line number Diff line change 1212 "bugs" : " https://github.com/gjuchault/typescript-library-starter/issues" ,
1313 "author" :
" Gabriel Juchault <[email protected] >" ,
1414 "repository" : " gjuchault/typescript-library-starter" ,
15- "main " : " ./build/cjs/index.js " ,
16- "module " : " ./build/esm /index.js" ,
15+ "type " : " module " ,
16+ "exports " : " ./build/index.js" ,
1717 "types" : " ./build/src/index.d.ts" ,
1818 "license" : " MIT" ,
1919 "engines" : {
3232 "build" : " npm run clean && npm run type:dts && npm run build:main" ,
3333 "build:main" : " tsx ./scripts/build" ,
3434 "clean" : " tsx ./scripts/clean" ,
35- "type:dts" : " tsc --emitDeclarationOnly" ,
35+ "type:dts" : " tsc --emitDeclarationOnly --project tsconfig.build.json " ,
3636 "type:check" : " tsc --noEmit" ,
3737 "format" : " prettier \" src/**/*.ts\" --write" ,
3838 "format:check" : " prettier \" src/**/*.ts\" --check" ,
Original file line number Diff line number Diff line change 1- import path from "path" ;
1+ import path from "node:path" ;
2+ import url from "node:url" ;
23import { build as esbuild , BuildOptions } from "esbuild" ;
34
5+ const __dirname = url . fileURLToPath ( new URL ( "." , import . meta. url ) ) ;
6+
47const baseConfig : BuildOptions = {
58 platform : "node" ,
6- target : "esnext " ,
7- format : "cjs " ,
9+ target : "node18 " ,
10+ format : "esm " ,
811 nodePaths : [ path . join ( __dirname , "../src" ) ] ,
912 sourcemap : true ,
1013 external : [ ] ,
@@ -14,18 +17,13 @@ const baseConfig: BuildOptions = {
1417async function main ( ) {
1518 await esbuild ( {
1619 ...baseConfig ,
17- outdir : path . join ( __dirname , "../build/cjs" ) ,
18- entryPoints : [ path . join ( __dirname , "../src/index.ts" ) ] ,
19- } ) ;
20-
21- await esbuild ( {
22- ...baseConfig ,
23- format : "esm" ,
24- outdir : path . join ( __dirname , "../build/esm" ) ,
20+ outdir : path . join ( __dirname , "../build" ) ,
2521 entryPoints : [ path . join ( __dirname , "../src/index.ts" ) ] ,
2622 } ) ;
2723}
2824
29- if ( require . main === module ) {
30- main ( ) ;
25+ if ( import . meta. url . startsWith ( "file:" ) ) {
26+ if ( process . argv [ 1 ] === url . fileURLToPath ( import . meta. url ) ) {
27+ await main ( ) ;
28+ }
3129}
Original file line number Diff line number Diff line change 1- import fs from "fs/promises" ;
2- import path from "path" ;
1+ import fs from "node:fs/promises" ;
2+ import url from "node:url" ;
3+ import path from "node:path" ;
4+
5+ const __dirname = url . fileURLToPath ( new URL ( "." , import . meta. url ) ) ;
36
47async function main ( ) {
58 await Promise . all ( [ rmrf ( "build" ) , rmrf ( "coverage" ) , rmrf ( ".nyc_output" ) ] ) ;
@@ -12,6 +15,8 @@ async function rmrf(pathFromRoot: string): Promise<void> {
1215 } ) ;
1316}
1417
15- if ( require . main === module ) {
16- main ( ) ;
18+ if ( import . meta. url . startsWith ( "file:" ) ) {
19+ if ( process . argv [ 1 ] === url . fileURLToPath ( import . meta. url ) ) {
20+ await main ( ) ;
21+ }
1722}
Original file line number Diff line number Diff line change 1- import path from "path" ;
1+ import path from "node:path" ;
2+ import fs from "node:fs/promises" ;
3+ import childProcess from "node:child_process" ;
4+ import { promisify } from "node:util" ;
5+ import url from "node:url" ;
26import slugify from "slugify" ;
3- import fs from "fs/promises" ;
4- import childProcess from "child_process" ;
5- import { promisify } from "util" ;
67import prompts from "prompts" ;
78
89const exec = promisify ( childProcess . exec ) ;
10+ const __filename = url . fileURLToPath ( import . meta. url ) ;
11+ const __dirname = url . fileURLToPath ( new URL ( "." , import . meta. url ) ) ;
912
1013const rootPath = path . join ( __dirname , ".." ) ;
1114const releaseRcPath = path . join ( rootPath , ".releaserc.json" ) ;
@@ -231,6 +234,8 @@ async function logAsyncTask<TResolve>(
231234 return output ;
232235}
233236
234- if ( require . main === module ) {
235- main ( ) ;
237+ if ( import . meta. url . startsWith ( "file:" ) ) {
238+ if ( process . argv [ 1 ] === url . fileURLToPath ( import . meta. url ) ) {
239+ await main ( ) ;
240+ }
236241}
Original file line number Diff line number Diff line change 1- import childProcess from "child_process" ;
2- import { promisify } from "util" ;
1+ import childProcess from "node:child_process" ;
2+ import { promisify } from "node:util" ;
3+ import url from "node:url" ;
34import { run } from "./setup" ;
45
56const exec = promisify ( childProcess . exec ) ;
@@ -60,6 +61,8 @@ async function testNoGrep(pattern: string) {
6061 }
6162}
6263
63- if ( require . main === module ) {
64- main ( ) ;
64+ if ( import . meta. url . startsWith ( "file:" ) ) {
65+ if ( process . argv [ 1 ] === url . fileURLToPath ( import . meta. url ) ) {
66+ await main ( ) ;
67+ }
6568}
Original file line number Diff line number Diff line change 11import { describe , expect , it } from "vitest" ;
2- import { foobar } from "../index" ;
2+ import { foobar } from "../index.js " ;
33
44describe ( "foobar()" , ( ) => {
55 describe ( "given two positive integers" , ( ) => {
Original file line number Diff line number Diff line change 1- import { bar } from "./bar" ;
2- import { foo } from "./foo" ;
1+ import { bar } from "./bar.js " ;
2+ import { foo } from "./foo.js " ;
33
44export function foobar ( a : number , b : number ) {
55 return foo ( ) . repeat ( a ) . length + bar ( ) . repeat ( b ) . length ;
Original file line number Diff line number Diff line change 11{
22 "extends" : " ./tsconfig.json" ,
3- "exclude" : []
3+ "exclude" : [" ./src/**/__tests__ " ]
44}
You can’t perform that action at this time.
0 commit comments