From 78966d351f398b04769b4236467c12721b83bdd8 Mon Sep 17 00:00:00 2001 From: wancat Date: Tue, 30 Jan 2024 09:06:41 +0800 Subject: [PATCH] change to use esm --- package.json | 2 +- packages/constants/package.json | 2 +- packages/file-graph/package.json | 2 +- packages/file-graph/src/file.ts | 2 +- packages/file-graph/src/fileNode.js | 4 +-- packages/file-graph/src/index.js | 2 +- packages/models/package.json | 2 +- packages/utils/package.json | 2 +- server/package.json | 2 +- tsconfig.json | 44 ++++++++++++++++++++++++----- 10 files changed, 47 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 8a58ee5..4b6a856 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "app": "yarn workspace app dev", "app:local": "yarn workspace app dev:local", "build": "yarn workspace app build", - "build:watch": "concurrently -n app,server,file-graph,utils -c blue,green,yellow,cyan \"tsc -w -p app\" \"tsc -w -p server\", \"tsc -w -p packages/file-graph\", \"tsc -w -p packages/utils\"", + "build:watch": "concurrently -n server,file-graph,utils,models,constants -c blue,green,yellow,cyan,red \"tsc -w -p server\" \"tsc -w -p packages/file-graph\" \"tsc -w -p packages/utils\" \"tsc -w -p packages/models\" \"tsc -w -p packages/constants\"", "server": "yarn workspace server dev", "cli": "yarn workspace client start", "lint": "eslint .", diff --git a/packages/constants/package.json b/packages/constants/package.json index 3203b7c..7f6dcf0 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -1,6 +1,6 @@ { "name": "@linux-odyssey/constants", - "type": "commonjs", + "type": "module", "version": "1.0.0", "private": true, "main": "dist/index.js", diff --git a/packages/file-graph/package.json b/packages/file-graph/package.json index 689a183..8c6c812 100644 --- a/packages/file-graph/package.json +++ b/packages/file-graph/package.json @@ -1,7 +1,7 @@ { "name": "@linux-odyssey/file-graph", "version": "1.0.0", - "type": "commonjs", + "type": "module", "main": "dist/index.js", "types": "dist/index.d.ts", "exports": "./dist/index.js", diff --git a/packages/file-graph/src/file.ts b/packages/file-graph/src/file.ts index e416bf2..1656e41 100644 --- a/packages/file-graph/src/file.ts +++ b/packages/file-graph/src/file.ts @@ -1,5 +1,5 @@ /* eslint-disable lines-between-class-members */ -import { basename } from './utils' +import { basename } from './utils.js' interface FileObject { path: string diff --git a/packages/file-graph/src/fileNode.js b/packages/file-graph/src/fileNode.js index 716cadf..cf8f089 100644 --- a/packages/file-graph/src/fileNode.js +++ b/packages/file-graph/src/fileNode.js @@ -1,9 +1,9 @@ -import File from './file' +import File from './file.js' import { DuplicateItemError, ParentNotExistsError, FileNotExistsError, -} from './errors' +} from './errors.js' import { basename, dirname } from './utils.js' export default class FileNode extends File { diff --git a/packages/file-graph/src/index.js b/packages/file-graph/src/index.js index de0c671..4b1fcda 100644 --- a/packages/file-graph/src/index.js +++ b/packages/file-graph/src/index.js @@ -1,3 +1,3 @@ -export { default as File } from './file' +export { default as File } from './file.js' export { default as FileNode } from './fileNode.js' export { default as FileGraph } from './fileGraph.js' diff --git a/packages/models/package.json b/packages/models/package.json index 18b96d2..cb5deab 100644 --- a/packages/models/package.json +++ b/packages/models/package.json @@ -1,6 +1,6 @@ { "name": "@linux-odyssey/models", - "type": "commonjs", + "type": "module", "version": "1.0.0", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/utils/package.json b/packages/utils/package.json index d329e9b..cb2e8f2 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -2,7 +2,7 @@ "name": "@linux-odyssey/utils", "version": "1.0.0", "main": "dist/index.js", - "type": "commonjs", + "type": "module", "exports": "./dist/index.js", "types": "./dist/index.d.ts", "license": "MIT", diff --git a/server/package.json b/server/package.json index c360346..af479b2 100644 --- a/server/package.json +++ b/server/package.json @@ -2,7 +2,7 @@ "name": "server", "version": "0.0.0", "description": "Linux Odyssey Server", - "type": "commonjs", + "type": "module", "scripts": { "start": "node dist/index.js", "dev": "nodemon", diff --git a/tsconfig.json b/tsconfig.json index a448336..cf2d1ac 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,42 @@ { + // "compilerOptions": { + // "target": "ESNext", + // "module": "ESNext", + // "moduleResolution": "Bundler", + // "strict": true, + // "moduleDetection": "force", + // "skipLibCheck": true, + // "esModuleInterop": true, + // "declaration": true, + // "sourceMap": true, + // "allowJs": true, + // "resolveJsonModule": true, + // "isolatedModules": true, + // "lib": ["ESNext"] + // } + // "compilerOptions": { + // "esModuleInterop": true, + // "skipLibCheck": true, + // "target": "ESNext", + // "resolveJsonModule": true, + // "isolatedModules": true, + // "moduleDetection": "force", + // "strict": false, + // "noUncheckedIndexedAccess": true, + // "moduleResolution": "NodeNext", + // "module": "NodeNext", + // "noEmit": true, + // "lib": ["es2022", "dom", "dom.iterable"] + // } "compilerOptions": { - "target": "ES2020", - "module": "CommonJS", - "moduleResolution": "node", + "target": "ESNext", // 要編譯成的 JS 目標版本 + "module": "NodeNext", // 要編譯成的 module + "moduleResolution": "NodeNext", // module 解析方式, default "classic" + "esModuleInterop": true, // module 兼容, 會影響 build 方式 + "allowJs": true, + "forceConsistentCasingInFileNames": true, "strict": true, - "esModuleInterop": true, - "declaration": true, - "sourceMap": true, - "allowJs": true + "skipLibCheck": true, + "outDir": "dist" } }