From e2fbf6957ab8524f9984e0a51c75ac03932ce32b Mon Sep 17 00:00:00 2001 From: chenhaoli Date: Thu, 14 Sep 2023 18:57:07 +0800 Subject: [PATCH] chore: make node.js can run out code --- .gitignore | 1 - README.md | 1 + esm/a.js | 4 ++-- esm/b.js | 2 +- esm/c.js | 2 +- package.json | 2 ++ src/a.ts | 4 ++-- src/b.ts | 2 +- src/c.ts | 2 +- tsconfig.json | 2 +- 10 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index b533b3d..f5da326 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ node_modules lib -dist build .DS_Store \ No newline at end of file diff --git a/README.md b/README.md index 25925dc..1bcf1be 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,5 @@ ```bash pnpm i pnpm build +pnpm execute ``` \ No newline at end of file diff --git a/esm/a.js b/esm/a.js index 99afc2d..e1c2568 100644 --- a/esm/a.js +++ b/esm/a.js @@ -1,3 +1,3 @@ -import { B } from "./b"; -import { C } from "./c"; +import { B } from "./b.js"; +import { C } from "./c.js"; console.log("Hello", B, C); diff --git a/esm/b.js b/esm/b.js index 771db8c..96a9189 100644 --- a/esm/b.js +++ b/esm/b.js @@ -1,3 +1,3 @@ -import { sleep } from "./d"; +import { sleep } from "./d.js"; await sleep(1000); export const B = 'TLA (b)'; diff --git a/esm/c.js b/esm/c.js index bc53836..6c19b2c 100644 --- a/esm/c.js +++ b/esm/c.js @@ -1,3 +1,3 @@ -import { sleep } from "./d"; +import { sleep } from "./d.js"; await sleep(500); export const C = 'TLA (c)'; diff --git a/package.json b/package.json index 1d9f1e3..02ab341 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,10 @@ "version": "1.0.0", "description": "", "main": "index.js", + "type": "module", "scripts": { "build": "tsc", + "execute": "node esm/a.js", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], diff --git a/src/a.ts b/src/a.ts index 06e01ca..77d4e10 100644 --- a/src/a.ts +++ b/src/a.ts @@ -1,4 +1,4 @@ -import { B } from "./b"; -import { C } from "./c"; +import { B } from "./b.js"; +import { C } from "./c.js"; console.log("Hello", B, C); diff --git a/src/b.ts b/src/b.ts index 7e17b9d..181f2cb 100644 --- a/src/b.ts +++ b/src/b.ts @@ -1,4 +1,4 @@ -import { sleep } from "./d"; +import { sleep } from "./d.js"; await sleep(1000); export const B = 'TLA (b)'; diff --git a/src/c.ts b/src/c.ts index 510ddb6..85a16fc 100644 --- a/src/c.ts +++ b/src/c.ts @@ -1,4 +1,4 @@ -import { sleep } from "./d"; +import { sleep } from "./d.js"; await sleep(500); export const C = 'TLA (c)'; diff --git a/tsconfig.json b/tsconfig.json index d4567db..40cd674 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "ES2017", - "module": "esnext", + "module": "NodeNext", "outDir": "./esm" }, "include": [