From 59411e3be16a4627c3921ae837bdef3f2ad12cab Mon Sep 17 00:00:00 2001 From: nganhkhoa Date: Thu, 30 Mar 2023 12:05:40 +0700 Subject: [PATCH] use es2022 modules --- .gitignore | 1 + dist/index.js | 38 ------------------------------------- dist/src/moduleA/feature.js | 4 ---- dist/src/moduleA/index.js | 5 ----- dist/src/moduleB/feature.js | 4 ---- index.ts | 7 ++----- package.json | 4 ++-- src/moduleA/index.ts | 2 +- src/moduleB/index.ts | 1 + tsconfig.json | 9 +++++---- 10 files changed, 12 insertions(+), 63 deletions(-) delete mode 100644 dist/index.js delete mode 100644 dist/src/moduleA/feature.js delete mode 100644 dist/src/moduleA/index.js delete mode 100644 dist/src/moduleB/feature.js create mode 100644 src/moduleB/index.ts diff --git a/.gitignore b/.gitignore index 809f1c5..7c2a5bd 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ #.pnp.* node_modules/ +dist/ diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c0e8615..0000000 --- a/dist/index.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const feature_1 = require("./src/moduleA/feature"); -const feature_2 = require("./src/moduleB/feature"); -const _a_1 = require("./src/moduleA"); -const path = __importStar(require("path")); -const moment_1 = __importDefault(require("moment")); -console.log("from A module", feature_1.A); -console.log("from A module", _a_1.A); -console.log("from B module", feature_2.B); -console.log("testing std node modules", path.delimiter); -console.log("testing installed node_modules", (0, moment_1.default)().format()); diff --git a/dist/src/moduleA/feature.js b/dist/src/moduleA/feature.js deleted file mode 100644 index 535e04e..0000000 --- a/dist/src/moduleA/feature.js +++ /dev/null @@ -1,4 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.A = void 0; -exports.A = 1; diff --git a/dist/src/moduleA/index.js b/dist/src/moduleA/index.js deleted file mode 100644 index 306a1fc..0000000 --- a/dist/src/moduleA/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.A = void 0; -var feature_1 = require("./feature"); -Object.defineProperty(exports, "A", { enumerable: true, get: function () { return feature_1.A; } }); diff --git a/dist/src/moduleB/feature.js b/dist/src/moduleB/feature.js deleted file mode 100644 index 7af6076..0000000 --- a/dist/src/moduleB/feature.js +++ /dev/null @@ -1,4 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.B = void 0; -exports.B = 2; diff --git a/index.ts b/index.ts index 9af577e..10d206b 100644 --- a/index.ts +++ b/index.ts @@ -1,14 +1,11 @@ -import { A } from "@a/feature"; -import { B } from "@b/feature"; - -import { A as AA } from "@a"; +import { A } from "@a"; +import { B } from "@b"; import * as path from "path"; import moment from "moment"; console.log("from A module", A) -console.log("from A module", AA) console.log("from B module", B) console.log("testing std node modules", path.delimiter) diff --git a/package.json b/package.json index 41fe70c..fd290e6 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "a", "packageManager": "yarn@3.4.1", - "type": "commonjs", + "type": "module", "scripts": { - "start": "node dist/index.js", + "start": "node --experimental-specifier-resolution=node dist/index.js", "build": "tsc && tsc-alias", "build:watch": "tsc && (concurrently \"tsc -w\" \"tsc-alias -w\")" }, diff --git a/src/moduleA/index.ts b/src/moduleA/index.ts index 00872f5..b99f09b 100644 --- a/src/moduleA/index.ts +++ b/src/moduleA/index.ts @@ -1 +1 @@ -export { A } from './feature'; +export { A } from "./feature"; diff --git a/src/moduleB/index.ts b/src/moduleB/index.ts new file mode 100644 index 0000000..6634635 --- /dev/null +++ b/src/moduleB/index.ts @@ -0,0 +1 @@ +export { B } from "./feature"; diff --git a/tsconfig.json b/tsconfig.json index d17bad2..a2aeab2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,15 +26,13 @@ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ - "module": "commonjs", /* Specify what module code is generated. */ + "module": "es2022", /* Specify what module code is generated. */ // "rootDir": "./", /* Specify the root folder within your source files. */ "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ "baseUrl": ".", /* Specify the base directory to resolve non-relative module names. */ "paths": { "@a": ["src/moduleA"], - "@b": ["src/moduleB"], - "@a/*": ["src/moduleA/*"], - "@b/*": ["src/moduleB/*"], + "@b": ["src/moduleB"] }, /* 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. */ // "typeRoots": [ @@ -115,5 +113,8 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ + }, + "tsc-alias": { + "resolveFullPaths": true } }