Skip to content

Commit

Permalink
update build script and refactor code for ES module compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwolf committed Jan 7, 2025
1 parent 55c330d commit ab67c0a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"build": "rm -rf dist/* && tsc",
"start": "node dist/index.js",
"dev": "ts-node src/index.ts",
"lint": "eslint .",
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { greet } from './lib/greeter'
import { Person } from './types'
import { Person } from './types.js';

Check warning on line 1 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

Delete `;`
import { greet } from './lib/greeter.js';

Check warning on line 2 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

Delete `;`

const person: Person = {
firstName: 'Jane',
lastName: 'Doe',
}
firstName: 'John',
lastName: 'Doe'

Check warning on line 6 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

Insert `,`
};

Check warning on line 7 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

Delete `;`

console.log(greet(`${person.firstName} ${person.lastName}`))
console.log(greet(person));

Check warning on line 9 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

Delete `;`
6 changes: 4 additions & 2 deletions src/lib/greeter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export function greet(name: string): string {
return `Hello, ${name}!`
import { Person } from '../types.js';

Check warning on line 1 in src/lib/greeter.ts

View workflow job for this annotation

GitHub Actions / build

Delete `;`

export function greet(person: Person): string {
return `Hello ${person.firstName} ${person.lastName}!`;

Check warning on line 4 in src/lib/greeter.ts

View workflow job for this annotation

GitHub Actions / build

Delete `;`
}
9 changes: 5 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */

/* Modules */
"module": "commonjs" /* Specify what module code is generated. */,
"module": "NodeNext" /* Specify what module code is generated. */,
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
"rootDir": "./src", /* Specify the root folder within your source files. */
"moduleResolution": "NodeNext", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
Expand Down Expand Up @@ -108,5 +108,6 @@
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
},
"include": ["src/**/*"]
}

0 comments on commit ab67c0a

Please sign in to comment.