├── support-by-exports ├── dist │ ├── index.d.ts │ ├── sub │ │ ├── index.d.ts │ │ ├── index.js │ │ ├── index.mjs │ │ └── index.esm.js │ ├── index.mjs │ ├── index.esm.js │ └── index.js └── package.json ├── exports-but-extension ├── dist │ ├── index.d.mts │ ├── sub │ │ ├── index.d.mts │ │ ├── index.cjs │ │ └── index.mjs │ ├── index.cjs │ └── index.mjs └── package.json ├── only-directory-structure ├── index.d.ts ├── sub │ ├── index.d.ts │ ├── index.mjs │ ├── index.esm.js │ └── index.js ├── index.mjs ├── index.esm.js ├── index.js └── package.json ├── tests └── marked-highlight │ ├── index.ts │ ├── tsconfig.json │ └── package.json ├── support-by-typesversions ├── dist │ ├── index.d.ts │ ├── sub │ │ ├── index.d.ts │ │ ├── index.mjs │ │ ├── index.esm.js │ │ └── index.js │ ├── index.mjs │ ├── index.esm.js │ └── index.js └── package.json ├── support-by-typesversions-and-exports ├── dist │ ├── index.d.ts │ ├── sub │ │ ├── index.d.ts │ │ ├── index.esm.js │ │ ├── index.js │ │ └── index.mjs │ ├── index.esm.js │ ├── index.js │ └── index.mjs └── package.json ├── What is exports.zh-Hans.md ├── exports-no-type-support-type-by-typesversions ├── dist │ ├── index.d.ts │ ├── sub │ │ ├── index.d.ts │ │ ├── index.mjs │ │ ├── index.esm.js │ │ └── index.js │ ├── index.esm.js │ ├── index.js │ └── index.mjs └── package.json ├── ts49 ├── tsconfig.json ├── module:esnext │ ├── tsconfig.json │ ├── resolution:node │ │ ├── tsconfig.json │ │ ├── test.support-by-exports.ts │ │ ├── test.exports-but-extension.ts │ │ ├── test.only-directory-structure.ts │ │ ├── test.support-by-typesversions.ts │ │ ├── test.support-by-typesversions-and-exports.ts │ │ └── test.exports-no-type-support-type-by-typesversions.ts │ └── resolution:nodenext │ │ ├── tsconfig.json │ │ ├── test.support-by-exports.ts │ │ ├── test.exports-but-extension.ts │ │ ├── test.only-directory-structure.ts │ │ ├── test.support-by-typesversions.ts │ │ ├── test.support-by-typesversions-and-exports.ts │ │ └── test.exports-no-type-support-type-by-typesversions.ts ├── module:commonjs │ ├── tsconfig.json │ ├── test.support-by-exports.ts │ ├── test.exports-but-extension.ts │ ├── test.only-directory-structure.ts │ ├── test.support-by-typesversions.ts │ ├── test.support-by-typesversions-and-exports.ts │ └── test.exports-no-type-support-type-by-typesversions.ts ├── module:nodenext │ ├── tsconfig.json │ ├── test.support-by-exports.ts │ ├── test.exports-but-extension.ts │ ├── test.only-directory-structure.ts │ ├── test.support-by-typesversions.ts │ ├── test.support-by-typesversions-and-exports.ts │ └── test.exports-no-type-support-type-by-typesversions.ts ├── package.json └── package-lock.json ├── ts5x ├── tsconfig.json ├── module:esnext │ ├── tsconfig.json │ └── resolution:bundler │ │ ├── tsconfig.json │ │ ├── test.support-by-exports.ts │ │ ├── test.exports-but-extension.ts │ │ ├── test.only-directory-structure.ts │ │ ├── test.support-by-typesversions.ts │ │ ├── test.support-by-typesversions-and-exports.ts │ │ └── test.exports-no-type-support-type-by-typesversions.ts ├── module:nodenext │ ├── tsconfig.json │ └── resolution:nodenext │ │ ├── tsconfig.json │ │ ├── test.support-by-exports.ts │ │ ├── test.exports-but-extension.ts │ │ ├── test.only-directory-structure.ts │ │ ├── test.support-by-typesversions.ts │ │ ├── test.support-by-typesversions-and-exports.ts │ │ └── test.exports-no-type-support-type-by-typesversions.ts ├── package.json └── package-lock.json ├── test.sh ├── .gitignore ├── README.zh-Hans.md └── README.md /support-by-exports/dist/index.d.ts: -------------------------------------------------------------------------------- 1 | export function foo(): 'foo'; 2 | -------------------------------------------------------------------------------- /exports-but-extension/dist/index.d.mts: -------------------------------------------------------------------------------- 1 | export function foo(): 'foo'; 2 | -------------------------------------------------------------------------------- /only-directory-structure/index.d.ts: -------------------------------------------------------------------------------- 1 | export function foo(): 'foo'; 2 | -------------------------------------------------------------------------------- /only-directory-structure/sub/index.d.ts: -------------------------------------------------------------------------------- 1 | export function bar(): 'bar'; 2 | -------------------------------------------------------------------------------- /support-by-exports/dist/sub/index.d.ts: -------------------------------------------------------------------------------- 1 | export function bar(): 'bar'; 2 | -------------------------------------------------------------------------------- /tests/marked-highlight/index.ts: -------------------------------------------------------------------------------- 1 | import {} from 'marked-highlight' 2 | -------------------------------------------------------------------------------- /exports-but-extension/dist/sub/index.d.mts: -------------------------------------------------------------------------------- 1 | export function bar(): 'bar'; 2 | -------------------------------------------------------------------------------- /support-by-typesversions/dist/index.d.ts: -------------------------------------------------------------------------------- 1 | export function foo(): 'foo'; 2 | -------------------------------------------------------------------------------- /support-by-typesversions/dist/sub/index.d.ts: -------------------------------------------------------------------------------- 1 | export function bar(): 'bar'; 2 | -------------------------------------------------------------------------------- /only-directory-structure/index.mjs: -------------------------------------------------------------------------------- 1 | export function foo() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-exports/dist/index.mjs: -------------------------------------------------------------------------------- 1 | export function foo() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-typesversions-and-exports/dist/index.d.ts: -------------------------------------------------------------------------------- 1 | export function foo(): 'foo'; 2 | -------------------------------------------------------------------------------- /exports-but-extension/dist/index.cjs: -------------------------------------------------------------------------------- 1 | exports.foo = function() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /exports-but-extension/dist/index.mjs: -------------------------------------------------------------------------------- 1 | export function foo() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /only-directory-structure/index.esm.js: -------------------------------------------------------------------------------- 1 | export function foo() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /only-directory-structure/index.js: -------------------------------------------------------------------------------- 1 | exports.foo = function() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /only-directory-structure/sub/index.mjs: -------------------------------------------------------------------------------- 1 | export function bar() { 2 | return "bar"; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-exports/dist/index.esm.js: -------------------------------------------------------------------------------- 1 | export function foo() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-exports/dist/index.js: -------------------------------------------------------------------------------- 1 | exports.foo = function() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-exports/dist/sub/index.js: -------------------------------------------------------------------------------- 1 | exports.bar = function() { 2 | return 'bar'; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-exports/dist/sub/index.mjs: -------------------------------------------------------------------------------- 1 | export function bar() { 2 | return "bar"; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-typesversions-and-exports/dist/sub/index.d.ts: -------------------------------------------------------------------------------- 1 | export function bar(): 'bar'; 2 | -------------------------------------------------------------------------------- /support-by-typesversions/dist/index.mjs: -------------------------------------------------------------------------------- 1 | export function foo() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /What is exports.zh-Hans.md: -------------------------------------------------------------------------------- 1 | # 什么是 `exports` 2 | 3 | 为了适配 Node.js 下的文件导出形式,TypeScript 在 4.x 的版本 4 | -------------------------------------------------------------------------------- /exports-but-extension/dist/sub/index.cjs: -------------------------------------------------------------------------------- 1 | exports.bar = function() { 2 | return 'bar'; 3 | } 4 | -------------------------------------------------------------------------------- /exports-but-extension/dist/sub/index.mjs: -------------------------------------------------------------------------------- 1 | export function bar() { 2 | return "bar"; 3 | } 4 | -------------------------------------------------------------------------------- /exports-no-type-support-type-by-typesversions/dist/index.d.ts: -------------------------------------------------------------------------------- 1 | export function foo(): 'foo'; 2 | -------------------------------------------------------------------------------- /only-directory-structure/sub/index.esm.js: -------------------------------------------------------------------------------- 1 | export function bar() { 2 | return "bar"; 3 | } 4 | -------------------------------------------------------------------------------- /only-directory-structure/sub/index.js: -------------------------------------------------------------------------------- 1 | exports.bar = function() { 2 | return 'bar'; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-exports/dist/sub/index.esm.js: -------------------------------------------------------------------------------- 1 | export function bar() { 2 | return "bar"; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-typesversions/dist/index.esm.js: -------------------------------------------------------------------------------- 1 | export function foo() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-typesversions/dist/index.js: -------------------------------------------------------------------------------- 1 | exports.foo = function() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-typesversions/dist/sub/index.mjs: -------------------------------------------------------------------------------- 1 | export function bar() { 2 | return "bar"; 3 | } 4 | -------------------------------------------------------------------------------- /ts49/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "noImplicitAny": true 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /ts5x/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "noImplicitAny": true 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /exports-no-type-support-type-by-typesversions/dist/sub/index.d.ts: -------------------------------------------------------------------------------- 1 | export function bar(): 'bar'; 2 | -------------------------------------------------------------------------------- /support-by-typesversions/dist/sub/index.esm.js: -------------------------------------------------------------------------------- 1 | export function bar() { 2 | return "bar"; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-typesversions/dist/sub/index.js: -------------------------------------------------------------------------------- 1 | exports.bar = function() { 2 | return 'bar'; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-typesversions-and-exports/dist/index.esm.js: -------------------------------------------------------------------------------- 1 | export function foo() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-typesversions-and-exports/dist/index.js: -------------------------------------------------------------------------------- 1 | exports.foo = function() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-typesversions-and-exports/dist/index.mjs: -------------------------------------------------------------------------------- 1 | export function foo() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-typesversions-and-exports/dist/sub/index.esm.js: -------------------------------------------------------------------------------- 1 | export function bar() { 2 | return "bar"; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-typesversions-and-exports/dist/sub/index.js: -------------------------------------------------------------------------------- 1 | exports.bar = function() { 2 | return 'bar'; 3 | } 4 | -------------------------------------------------------------------------------- /support-by-typesversions-and-exports/dist/sub/index.mjs: -------------------------------------------------------------------------------- 1 | export function bar() { 2 | return "bar"; 3 | } 4 | -------------------------------------------------------------------------------- /exports-no-type-support-type-by-typesversions/dist/index.esm.js: -------------------------------------------------------------------------------- 1 | export function foo() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /exports-no-type-support-type-by-typesversions/dist/index.js: -------------------------------------------------------------------------------- 1 | exports.foo = function() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /exports-no-type-support-type-by-typesversions/dist/index.mjs: -------------------------------------------------------------------------------- 1 | export function foo() { 2 | return 'foo'; 3 | } 4 | -------------------------------------------------------------------------------- /exports-no-type-support-type-by-typesversions/dist/sub/index.mjs: -------------------------------------------------------------------------------- 1 | export function bar() { 2 | return "bar"; 3 | } 4 | -------------------------------------------------------------------------------- /exports-no-type-support-type-by-typesversions/dist/sub/index.esm.js: -------------------------------------------------------------------------------- 1 | export function bar() { 2 | return "bar"; 3 | } 4 | -------------------------------------------------------------------------------- /exports-no-type-support-type-by-typesversions/dist/sub/index.js: -------------------------------------------------------------------------------- 1 | exports.bar = function() { 2 | return 'bar'; 3 | } 4 | -------------------------------------------------------------------------------- /ts49/module:esnext/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "module": "ESNext" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /ts5x/module:esnext/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "module": "ESNext" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /ts49/module:commonjs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "module": "CommonJS" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /ts49/module:nodenext/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "module": "NodeNext" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /ts5x/module:nodenext/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "module": "NodeNext" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /ts49/module:esnext/resolution:node/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "moduleResolution": "node" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /ts5x/module:esnext/resolution:bundler/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "moduleResolution": "bundler" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /ts49/module:esnext/resolution:nodenext/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "moduleResolution": "nodenext" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /ts5x/module:nodenext/resolution:nodenext/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "moduleResolution": "nodenext" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/marked-highlight/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "ESNext", 4 | "moduleResolution": "nodenext", 5 | "noImplicitAny": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/marked-highlight/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test.marked-highlight", 3 | "version": "1.0.0", 4 | "dependencies": { 5 | "marked-highlight": "^2.0.8", 6 | "typescript": "^4.9.5" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /only-directory-structure/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@yje/how-to-publish-a-typescript-package.only-directory-structure", 3 | "version": "0.1.0", 4 | "main": "index.js", 5 | "module": "index.mjs", 6 | "types": "index.d.ts" 7 | } 8 | -------------------------------------------------------------------------------- /ts49/module:commonjs/test.support-by-exports.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-exports' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-exports/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:nodenext/test.support-by-exports.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-exports' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-exports/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:commonjs/test.exports-but-extension.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.exports-but-extension' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.exports-but-extension/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:nodenext/test.exports-but-extension.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.exports-but-extension' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.exports-but-extension/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:esnext/resolution:node/test.support-by-exports.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-exports' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-exports/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts5x/module:esnext/resolution:bundler/test.support-by-exports.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-exports' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-exports/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:commonjs/test.only-directory-structure.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.only-directory-structure' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.only-directory-structure/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:commonjs/test.support-by-typesversions.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:esnext/resolution:nodenext/test.support-by-exports.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-exports' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-exports/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:nodenext/test.only-directory-structure.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.only-directory-structure' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.only-directory-structure/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:nodenext/test.support-by-typesversions.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts5x/module:nodenext/resolution:nodenext/test.support-by-exports.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-exports' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-exports/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:esnext/resolution:node/test.exports-but-extension.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.exports-but-extension' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.exports-but-extension/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:esnext/resolution:nodenext/test.exports-but-extension.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.exports-but-extension' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.exports-but-extension/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts5x/module:esnext/resolution:bundler/test.exports-but-extension.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.exports-but-extension' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.exports-but-extension/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:esnext/resolution:node/test.only-directory-structure.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.only-directory-structure' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.only-directory-structure/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:esnext/resolution:node/test.support-by-typesversions.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts5x/module:nodenext/resolution:nodenext/test.exports-but-extension.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.exports-but-extension' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.exports-but-extension/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:esnext/resolution:nodenext/test.only-directory-structure.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.only-directory-structure' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.only-directory-structure/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:esnext/resolution:nodenext/test.support-by-typesversions.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts5x/module:esnext/resolution:bundler/test.only-directory-structure.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.only-directory-structure' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.only-directory-structure/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts5x/module:esnext/resolution:bundler/test.support-by-typesversions.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts5x/module:nodenext/resolution:nodenext/test.only-directory-structure.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.only-directory-structure' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.only-directory-structure/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts5x/module:nodenext/resolution:nodenext/test.support-by-typesversions.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:commonjs/test.support-by-typesversions-and-exports.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:nodenext/test.support-by-typesversions-and-exports.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:esnext/resolution:node/test.support-by-typesversions-and-exports.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:esnext/resolution:nodenext/test.support-by-typesversions-and-exports.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts5x/module:esnext/resolution:bundler/test.support-by-typesversions-and-exports.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts5x/module:nodenext/resolution:nodenext/test.support-by-typesversions-and-exports.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:commonjs/test.exports-no-type-support-type-by-typesversions.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:nodenext/test.exports-no-type-support-type-by-typesversions.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:esnext/resolution:node/test.exports-no-type-support-type-by-typesversions.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts49/module:esnext/resolution:nodenext/test.exports-no-type-support-type-by-typesversions.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts5x/module:esnext/resolution:bundler/test.exports-no-type-support-type-by-typesversions.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /ts5x/module:nodenext/resolution:nodenext/test.exports-no-type-support-type-by-typesversions.ts: -------------------------------------------------------------------------------- 1 | import { foo } from '@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions' 2 | import { bar } from '@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions/sub' 3 | 4 | const t0 = foo() 5 | // ^? 6 | 7 | const t1 = bar() 8 | // ^? 9 | -------------------------------------------------------------------------------- /support-by-typesversions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@yje/how-to-publish-a-typescript-package.support-by-typesversions", 3 | "version": "0.1.0", 4 | "main": "dist/index.js", 5 | "module": "dist/index.mjs", 6 | "types": "dist/index.d.ts", 7 | "typesVersions": { 8 | "*": { 9 | ".": ["dist/index.d.ts"], 10 | "sub": ["dist/sub/index.d.ts"] 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /exports-but-extension/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions", 3 | "version": "0.1.0", 4 | "main": "dist/index.js", 5 | "module": "dist/index.mjs", 6 | "types": "dist/index.d.ts", 7 | "exports": { 8 | "./package.json": "./package.json", 9 | ".": { 10 | "import": "./dist/index.mjs", 11 | "require": "./dist/index.cjs" 12 | }, 13 | "./sub": { 14 | "import": "./dist/sub/index.mjs", 15 | "require": "./dist/sub/index.cjs" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | echo TypeScript 4.9 2 | cd ts49 3 | if [ ! -d "node_modules" ]; then 4 | npm install 5 | fi 6 | npx tsc --noEmit -p module:commonjs/tsconfig.json 7 | npx tsc --noEmit -p module:esnext/resolution:node/tsconfig.json 8 | npx tsc --noEmit -p module:esnext/resolution:nodenext/tsconfig.json 9 | npx tsc --noEmit -p module:nodenext/tsconfig.json 10 | 11 | echo TypeScript 5.x 12 | cd ../ts5x 13 | if [ ! -d "node_modules" ]; then 14 | npm install 15 | fi 16 | npx tsc --noEmit -p module:esnext/resolution:bundler/tsconfig.json 17 | npx tsc --noEmit -p module:nodenext/resolution:nodenext/tsconfig.json 18 | -------------------------------------------------------------------------------- /exports-no-type-support-type-by-typesversions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions", 3 | "version": "0.1.0", 4 | "main": "dist/index.js", 5 | "module": "dist/index.mjs", 6 | "types": "dist/index.d.ts", 7 | "typesVersions": { 8 | "*": { 9 | ".": ["dist/index.d.ts"], 10 | "sub": ["dist/sub/index.d.ts"] 11 | } 12 | }, 13 | "exports": { 14 | "./package.json": "./package.json", 15 | ".": { 16 | "import": "./dist/index.esm.js", 17 | "module": "./dist/index.mjs", 18 | "require": "./dist/index.js" 19 | }, 20 | "./sub": { 21 | "import": "./dist/sub/index.esm.js", 22 | "module": "./dist/sub/index.mjs", 23 | "require": "./dist/sub/index.js" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ts5x/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "name": "ts5x", 4 | "version": "1.0.0", 5 | "dependencies": { 6 | "@yje/how-to-publish-a-typescript-package.exports-but-extension": "file:../exports-but-extension", 7 | "@yje/how-to-publish-a-typescript-package.only-directory-structure": "file:../only-directory-structure", 8 | "@yje/how-to-publish-a-typescript-package.support-by-exports": "file:../support-by-exports", 9 | "@yje/how-to-publish-a-typescript-package.support-by-typesversions": "file:../support-by-typesversions", 10 | "@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports": "file:../support-by-typesversions-and-exports", 11 | "@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions": "file:../exports-no-type-support-type-by-typesversions", 12 | "typescript": "^5.3.2" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ts49/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "name": "ts49+module:commonjs", 4 | "version": "1.0.0", 5 | "dependencies": { 6 | "@yje/how-to-publish-a-typescript-package.exports-but-extension": "file:../exports-but-extension", 7 | "@yje/how-to-publish-a-typescript-package.only-directory-structure": "file:../only-directory-structure", 8 | "@yje/how-to-publish-a-typescript-package.support-by-exports": "file:../support-by-exports", 9 | "@yje/how-to-publish-a-typescript-package.support-by-typesversions": "file:../support-by-typesversions", 10 | "@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports": "file:../support-by-typesversions-and-exports", 11 | "@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions": "file:../exports-no-type-support-type-by-typesversions", 12 | "typescript": "^4.9.5" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /support-by-exports/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@yje/how-to-publish-a-typescript-package.support-by-exports", 3 | "version": "0.1.0", 4 | "main": "dist/index.js", 5 | "module": "dist/index.mjs", 6 | "types": "dist/index.d.ts", 7 | "exports": { 8 | "./package.json": "./package.json", 9 | ".": { 10 | "import": { 11 | "types": "./dist/index.d.ts", 12 | "default": "./dist/index.esm.js" 13 | }, 14 | "module": { 15 | "types": "./dist/index.d.ts", 16 | "default": "./dist/index.mjs" 17 | }, 18 | "require": { 19 | "types": "./dist/index.d.ts", 20 | "default": "./dist/index.js" 21 | } 22 | }, 23 | "./sub": { 24 | "import": { 25 | "types": "./dist/sub/index.d.ts", 26 | "default": "./dist/sub/index.esm.js" 27 | }, 28 | "module": { 29 | "types": "./dist/sub/index.d.ts", 30 | "default": "./dist/sub/index.mjs" 31 | }, 32 | "require": { 33 | "types": "./dist/sub/index.d.ts", 34 | "default": "./dist/sub/index.js" 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /support-by-typesversions-and-exports/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@yje/how-to-publish-a-typescript-package.support-by-typesversions", 3 | "version": "0.1.0", 4 | "main": "dist/index.js", 5 | "module": "dist/index.mjs", 6 | "types": "dist/index.d.ts", 7 | "typesVersions": { 8 | "<5.0": { 9 | "*": ["*", "dist/*", "dist/*/index.d.ts"] 10 | } 11 | }, 12 | "exports": { 13 | "./package.json": "./package.json", 14 | ".": { 15 | "import": { 16 | "types": "./dist/index.d.ts", 17 | "default": "./dist/index.esm.js" 18 | }, 19 | "module": { 20 | "types": "./dist/index.d.ts", 21 | "default": "./dist/index.mjs" 22 | }, 23 | "require": { 24 | "types": "./dist/index.d.ts", 25 | "default": "./dist/index.js" 26 | } 27 | }, 28 | "./sub": { 29 | "import": { 30 | "types": "./dist/sub/index.d.ts", 31 | "default": "./dist/sub/index.esm.js" 32 | }, 33 | "module": { 34 | "types": "./dist/sub/index.d.ts", 35 | "default": "./dist/sub/index.mjs" 36 | }, 37 | "require": { 38 | "types": "./dist/sub/index.d.ts", 39 | "default": "./dist/sub/index.js" 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | 3 | ### Node template 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | lerna-debug.log* 11 | .pnpm-debug.log* 12 | 13 | # Diagnostic reports (https://nodejs.org/api/report.html) 14 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 15 | 16 | # Runtime data 17 | pids 18 | *.pid 19 | *.seed 20 | *.pid.lock 21 | 22 | # Directory for instrumented libs generated by jscoverage/JSCover 23 | lib-cov 24 | 25 | # Coverage directory used by tools like istanbul 26 | coverage 27 | *.lcov 28 | 29 | # nyc test coverage 30 | .nyc_output 31 | 32 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 33 | .grunt 34 | 35 | # Bower dependency directory (https://bower.io/) 36 | bower_components 37 | 38 | # node-waf configuration 39 | .lock-wscript 40 | 41 | # Compiled binary addons (https://nodejs.org/api/addons.html) 42 | build/Release 43 | 44 | # Dependency directories 45 | node_modules/ 46 | jspm_packages/ 47 | 48 | # Snowpack dependency directory (https://snowpack.dev/) 49 | web_modules/ 50 | 51 | # TypeScript cache 52 | *.tsbuildinfo 53 | 54 | # Optional npm cache directory 55 | .npm 56 | 57 | # Optional eslint cache 58 | .eslintcache 59 | 60 | # Optional stylelint cache 61 | .stylelintcache 62 | 63 | # Microbundle cache 64 | .rpt2_cache/ 65 | .rts2_cache_cjs/ 66 | .rts2_cache_es/ 67 | .rts2_cache_umd/ 68 | 69 | # Optional REPL history 70 | .node_repl_history 71 | 72 | # Output of 'npm pack' 73 | *.tgz 74 | 75 | # Yarn Integrity file 76 | .yarn-integrity 77 | 78 | # dotenv environment variable files 79 | .env 80 | .env.development.local 81 | .env.test.local 82 | .env.production.local 83 | .env.local 84 | 85 | # parcel-bundler cache (https://parceljs.org/) 86 | .cache 87 | .parcel-cache 88 | 89 | # Next.js build output 90 | .next 91 | out 92 | 93 | # Nuxt.js build / generate output 94 | .nuxt 95 | 96 | # Gatsby files 97 | .cache/ 98 | # Comment in the public line in if your project uses Gatsby and not Next.js 99 | # https://nextjs.org/blog/next-9-1#public-directory-support 100 | # public 101 | 102 | # vuepress build output 103 | .vuepress/dist 104 | 105 | # vuepress v2.x temp and cache directory 106 | .temp 107 | .cache 108 | 109 | # Docusaurus cache and generated files 110 | .docusaurus 111 | 112 | # Serverless directories 113 | .serverless/ 114 | 115 | # FuseBox cache 116 | .fusebox/ 117 | 118 | # DynamoDB Local files 119 | .dynamodb/ 120 | 121 | # TernJS port file 122 | .tern-port 123 | 124 | # Stores VSCode versions used for testing VSCode extensions.vscode-test 125 | 126 | # yarn v2 127 | .yarn/cache 128 | .yarn/unplugged 129 | .yarn/build-state.yml 130 | .yarn/install-state.gz 131 | .pnp.* 132 | 133 | -------------------------------------------------------------------------------- /ts5x/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ts5x", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "ts5x", 9 | "version": "1.0.0", 10 | "dependencies": { 11 | "@yje/how-to-publish-a-typescript-package.exports-but-extension": "file:../exports-but-extension", 12 | "@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions": "file:../exports-no-type-support-type-by-typesversions", 13 | "@yje/how-to-publish-a-typescript-package.only-directory-structure": "file:../only-directory-structure", 14 | "@yje/how-to-publish-a-typescript-package.support-by-exports": "file:../support-by-exports", 15 | "@yje/how-to-publish-a-typescript-package.support-by-typesversions": "file:../support-by-typesversions", 16 | "@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports": "file:../support-by-typesversions-and-exports", 17 | "typescript": "^5.3.2" 18 | } 19 | }, 20 | "../exports-but-extension": { 21 | "name": "@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions", 22 | "version": "0.1.0" 23 | }, 24 | "../exports-no-type-support-type-by-typesversions": { 25 | "name": "@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions", 26 | "version": "0.1.0" 27 | }, 28 | "../only-directory-structure": { 29 | "name": "@yje/how-to-publish-a-typescript-package.only-directory-structure", 30 | "version": "0.1.0" 31 | }, 32 | "../support-by-exports": { 33 | "name": "@yje/how-to-publish-a-typescript-package.support-by-exports", 34 | "version": "0.1.0" 35 | }, 36 | "../support-by-typesversions": { 37 | "name": "@yje/how-to-publish-a-typescript-package.support-by-typesversions", 38 | "version": "0.1.0" 39 | }, 40 | "../support-by-typesversions-and-exports": { 41 | "name": "@yje/how-to-publish-a-typescript-package.support-by-typesversions", 42 | "version": "0.1.0" 43 | }, 44 | "node_modules/@yje/how-to-publish-a-typescript-package.exports-but-extension": { 45 | "resolved": "../exports-but-extension", 46 | "link": true 47 | }, 48 | "node_modules/@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions": { 49 | "resolved": "../exports-no-type-support-type-by-typesversions", 50 | "link": true 51 | }, 52 | "node_modules/@yje/how-to-publish-a-typescript-package.only-directory-structure": { 53 | "resolved": "../only-directory-structure", 54 | "link": true 55 | }, 56 | "node_modules/@yje/how-to-publish-a-typescript-package.support-by-exports": { 57 | "resolved": "../support-by-exports", 58 | "link": true 59 | }, 60 | "node_modules/@yje/how-to-publish-a-typescript-package.support-by-typesversions": { 61 | "resolved": "../support-by-typesversions", 62 | "link": true 63 | }, 64 | "node_modules/@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports": { 65 | "resolved": "../support-by-typesversions-and-exports", 66 | "link": true 67 | }, 68 | "node_modules/typescript": { 69 | "version": "5.3.2", 70 | "resolved": "https://mirrors.tencent.com/npm/typescript/-/typescript-5.3.2.tgz", 71 | "integrity": "sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==", 72 | "bin": { 73 | "tsc": "bin/tsc", 74 | "tsserver": "bin/tsserver" 75 | }, 76 | "engines": { 77 | "node": ">=14.17" 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /ts49/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ts49+module:commonjs", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "ts49+module:commonjs", 9 | "version": "1.0.0", 10 | "dependencies": { 11 | "@yje/how-to-publish-a-typescript-package.exports-but-extension": "file:../exports-but-extension", 12 | "@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions": "file:../exports-no-type-support-type-by-typesversions", 13 | "@yje/how-to-publish-a-typescript-package.only-directory-structure": "file:../only-directory-structure", 14 | "@yje/how-to-publish-a-typescript-package.support-by-exports": "file:../support-by-exports", 15 | "@yje/how-to-publish-a-typescript-package.support-by-typesversions": "file:../support-by-typesversions", 16 | "@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports": "file:../support-by-typesversions-and-exports", 17 | "typescript": "^4.9.5" 18 | } 19 | }, 20 | "../exports-but-extension": { 21 | "name": "@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions", 22 | "version": "0.1.0" 23 | }, 24 | "../exports-no-type-support-type-by-typesversions": { 25 | "name": "@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions", 26 | "version": "0.1.0" 27 | }, 28 | "../only-directory-structure": { 29 | "name": "@yje/how-to-publish-a-typescript-package.only-directory-structure", 30 | "version": "0.1.0" 31 | }, 32 | "../suport-by-exports": { 33 | "extraneous": true 34 | }, 35 | "../suport-by-typesversions": { 36 | "extraneous": true 37 | }, 38 | "../support-by-exports": { 39 | "name": "@yje/how-to-publish-a-typescript-package.support-by-exports", 40 | "version": "0.1.0" 41 | }, 42 | "../support-by-typesversions": { 43 | "name": "@yje/how-to-publish-a-typescript-package.support-by-typesversions", 44 | "version": "0.1.0" 45 | }, 46 | "../support-by-typesversions-and-exports": { 47 | "name": "@yje/how-to-publish-a-typescript-package.support-by-typesversions", 48 | "version": "0.1.0" 49 | }, 50 | "node_modules/@yje/how-to-publish-a-typescript-package.exports-but-extension": { 51 | "resolved": "../exports-but-extension", 52 | "link": true 53 | }, 54 | "node_modules/@yje/how-to-publish-a-typescript-package.exports-no-type-support-type-by-typesversions": { 55 | "resolved": "../exports-no-type-support-type-by-typesversions", 56 | "link": true 57 | }, 58 | "node_modules/@yje/how-to-publish-a-typescript-package.only-directory-structure": { 59 | "resolved": "../only-directory-structure", 60 | "link": true 61 | }, 62 | "node_modules/@yje/how-to-publish-a-typescript-package.support-by-exports": { 63 | "resolved": "../support-by-exports", 64 | "link": true 65 | }, 66 | "node_modules/@yje/how-to-publish-a-typescript-package.support-by-typesversions": { 67 | "resolved": "../support-by-typesversions", 68 | "link": true 69 | }, 70 | "node_modules/@yje/how-to-publish-a-typescript-package.support-by-typesversions-and-exports": { 71 | "resolved": "../support-by-typesversions-and-exports", 72 | "link": true 73 | }, 74 | "node_modules/typescript": { 75 | "version": "4.9.5", 76 | "resolved": "https://mirrors.tencent.com/npm/typescript/-/typescript-4.9.5.tgz", 77 | "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", 78 | "bin": { 79 | "tsc": "bin/tsc", 80 | "tsserver": "bin/tsserver" 81 | }, 82 | "engines": { 83 | "node": ">=4.2.0" 84 | } 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /README.zh-Hans.md: -------------------------------------------------------------------------------- 1 | # 如何发布一个 npm 包? 2 | 3 | |zh-Hans|[en-US](./README.md) 4 | 5 | 这是什么傻逼问题?也许你会觉得这个问题在 2025 都到了的时候看起来简直蠢到不能再蠢了,但是你知道吗?我到现在为止我都无法通过 exports 发布一个带有类型的包,这简直是太难以置信了。 6 | 7 | ## 为谁发? 8 | 9 | 首先,我们要搞清楚目标用户到底是谁?直接看表格: 10 | 11 | | TypeScript | module | resolution | how to support | supported | 12 | |------------|----------|------------|-------------------------------------|-----------| 13 | | 4.9 | commonjs | --- | exports no type, only typesVersions | ✔︎ | 14 | | 4.9 | commonjs | --- | directory | ✔︎ | 15 | | 4.9 | commonjs | --- | exports | ✖︎ | 16 | | 4.9 | commonjs | --- | typesVersions | ✔︎ | 17 | | 4.9 | esnext | node | exports no type, only typesVersions | ✔︎ | 18 | | 4.9 | esnext | node | directory | ✔︎ | 19 | | 4.9 | esnext | node | exports | ✖︎ | 20 | | 4.9 | esnext | node | typesVersions | ✔︎ | 21 | | 4.9 | esnext | nodenext | exports no type, only typesVersions | ✔︎ | 22 | | 4.9 | esnext | nodenext | directory | ✔︎ | 23 | | 4.9 | esnext | nodenext | exports | ✖︎ | 24 | | 4.9 | esnext | nodenext | typesVersions | ✔︎ | 25 | | 4.9 | nodenext | --- | exports no type, only typesVersions | ✔︎ | 26 | | 4.9 | nodenext | --- | directory | ✔︎ | 27 | | 4.9 | nodenext | --- | exports | ✖︎ | 28 | | 4.9 | nodenext | --- | typesVersions | ✔︎ | 29 | | 5.x | esnext | bundler | exports no type, only typesVersions | ✖︎ | 30 | | 5.x | esnext | bundler | directory | ✔︎ | 31 | | 5.x | esnext | bundler | exports | ✔︎ | 32 | | 5.x | esnext | bundler | typesVersions | ✔︎ | 33 | | 5.x | nodenext | nodenext | exports no type, only typesVersions | ✔︎ | 34 | | 5.x | nodenext | nodenext | directory | ✔︎ | 35 | | 5.x | nodenext | nodenext | exports | ✔︎ | 36 | | 5.x | nodenext | nodenext | typesVersions | ✔︎ | 37 | 38 | 对表格中对一些名词进行解释: 39 | 40 | - `module`:在这里指的是在用户的 tsconfig 中声明的[模块类型](https://www.typescriptlang.org/tsconfig#module),比如 `commonjs`、`nodenext`、`esnext` 等等。 41 | - `resolution`:在这里指的是在用户的 tsconfig 中声明的[模块解析策略](https://www.typescriptlang.org/tsconfig#moduleResolution),比如 `node`、`classic`、`bundler` 等等。 42 | - 类型提供方式:在这里指的是在发布包中通过 package.json 向用户提供的类型映射规则。\ 43 | 在这里我们可以通过多种方式向用户提供各种类型映射规则,比如 `exports`、`typesVersions`、`types` 等等。 44 | - `exports`:在这里指的是在 package.json 中声明的[导出规则](https://nodejs.org/api/packages.html#exports-sugar)。\ 45 | 在 Node.js 文档中并没有过多的涉及到类型相关的信息,我们可以在 TypeScript 的 4.7 版本的 ChangeLog 中阅读到[相关信息](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html)。\ 46 | - `typesVersions`:在这里指的是在 package.json 中声明的[类型映射规则](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#version-selection)。\ 47 | 唉,不能用 `*` 不然 ts 就会死给用户看,局限性很大。也无法处理 condition。 48 | - `types`:在这里指的是在 package.json 中声明的[类型文件](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#including-declarations-in-your-npm-package)。\ 49 | 这个是最简单的,但是也是最不灵活的,因为你只能提供一个类型文件,而且你无法通过这个方式提供多个版本的类型文件。 50 | 51 | 以开发者导出方式来看待的话 52 | - `directory` 兼容性满分,不管在哪种用户使用情况下都是绝对可以的。\ 53 | 但是相对的来说,如果你不想用户用代码的时候还要加一个 dist 在路径里面的话,你就没办法在本地很方便的构建并输出产物了。 54 | - `exports no type, only typesVersions` 在 4.9 下可以无脑使用,但是在 5.x 下 `resolution: bundler` 情况下无法正确为用户提供类型。\ 55 | 在不需要考虑高版本的情况下似乎是一个不错的选择,但是如果你想要支持高版本的话,你就必须要考虑到这个问题,毕竟世界并不总是一成不变。 56 | - `exports` 的类型导出无法在 ts4.9 下使用,在 ts 5.x 上兼容性满分,在不考虑低版本 ts 用户时可以无脑使用。\ 57 | 很好,相对于上面的来说,这个好像看起来是一个互补的选项,或许我们能想点别的法子出来? 58 | - `typesVersions` 也是兼容性满分,就是不支持 `conditional export`,没办法区分导出 esm 和 cjs 包的类型,在没有 node 环境需要区分时可以无脑使用。 59 | 60 | 结合具体的使用,我们可以使用 `exports` + `typesVersions`进行发布。\ 61 | 在这种情况下,我们可以通过 `exports` 来支持高版本的 ts 的识别机制,使用 `typesVersions` 来支持低版本的 ts 的识别机制。\ 62 | 但是我们需要有一个分界点,到底是从哪个版本开始使用 `exports` 呢?这个比较关键,这里我们可以以 4.7 和 5.0 分别作为分界点来进行判断,看看哪个的场景覆盖的范围更多一些。 63 | 64 | ## 其他 65 | 66 | * 如果你采取了 `exports`,不要忘记导出 `package.json`,你的用户可能需要通过的你包来获取到对应的依赖数据。如果不这么做,他可能需要去计算路径,这对他来说十分的麻烦。 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # How to publish a npm package? 2 | 3 | |en-US|[zh-Hans](./README.zh-Hans.md) 4 | 5 | What the fuck is this question? Maybe you think the question is so foolish when 2025 has arrived, but you know what? I can't publish a package with type when I use the exports, it's so incredible. 6 | ## Who is it for? 7 | 8 | First, we need to figure out who the target users are. Let's look at the table directly: 9 | 10 | | TypeScript | module | resolution | how to support | supported | 11 | |------------|----------|------------|-------------------------------------|-----------| 12 | | 4.9 | commonjs | --- | exports no type, only typesVersions | ✔︎ | 13 | | 4.9 | commonjs | --- | directory | ✔︎ | 14 | | 4.9 | commonjs | --- | exports | ✖︎ | 15 | | 4.9 | commonjs | --- | typesVersions | ✔︎ | 16 | | 4.9 | esnext | node | exports no type, only typesVersions | ✔︎ | 17 | | 4.9 | esnext | node | directory | ✔︎ | 18 | | 4.9 | esnext | node | exports | ✖︎ | 19 | | 4.9 | esnext | node | typesVersions | ✔︎ | 20 | | 4.9 | esnext | nodenext | exports no type, only typesVersions | ✔︎ | 21 | | 4.9 | esnext | nodenext | directory | ✔︎ | 22 | | 4.9 | esnext | nodenext | exports | ✖︎ | 23 | | 4.9 | esnext | nodenext | typesVersions | ✔︎ | 24 | | 4.9 | nodenext | --- | exports no type, only typesVersions | ✔︎ | 25 | | 4.9 | nodenext | --- | directory | ✔︎ | 26 | | 4.9 | nodenext | --- | exports | ✖︎ | 27 | | 4.9 | nodenext | --- | typesVersions | ✔︎ | 28 | | 5.x | esnext | bundler | exports no type, only typesVersions | ✖︎ | 29 | | 5.x | esnext | bundler | directory | ✔︎ | 30 | | 5.x | esnext | bundler | exports | ✔︎ | 31 | | 5.x | esnext | bundler | typesVersions | ✔︎ | 32 | | 5.x | nodenext | nodenext | exports no type, only typesVersions | ✔︎ | 33 | | 5.x | nodenext | nodenext | directory | ✔︎ | 34 | | 5.x | nodenext | nodenext | exports | ✔︎ | 35 | | 5.x | nodenext | nodenext | typesVersions | ✔︎ | 36 | 37 | Let's explain some of the terms in the table: 38 | 39 | - `module`: Here refers to the [module type](https://www.typescriptlang.org/tsconfig#module) declared in the user's tsconfig, such as `commonjs`, `nodenext`, `esnext`, etc. 40 | - `resolution`: Here refers to the [module resolution strategy](https://www.typescriptlang.org/tsconfig#moduleResolution) declared in the user's tsconfig, such as `node`, `classic`, `bundler`, etc. 41 | - Type provision method: Here refers to the type mapping rules provided to users through package.json in the published package.\ 42 | Here we can provide various type mapping rules to users in multiple ways, such as `exports`, `typesVersions`, `types`, etc. 43 | - `exports`: Here refers to the [export rules](https://nodejs.org/api/packages.html#exports-sugar) declared in package.json.\ 44 | The Node.js documentation does not involve too much type-related information, we can read [related information](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html) in the TypeScript 4.7 version ChangeLog. 45 | - `typesVersions`: Here refers to the [type mapping rules](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#version-selection) declared in package.json.\ 46 | Alas, you can't use `*` otherwise ts will die for users to see, the limitations are great. It also cannot handle conditions. 47 | - `types`: Here refers to the [type file](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#including-declarations-in-your-npm-package) declared in package.json.\ 48 | This is the simplest, but also the least flexible, because you can only provide one type file, and you cannot provide multiple versions of type files through this method. 49 | 50 | From the perspective of the developer's export method: 51 | - `directory` is fully compatible, it is absolutely possible in any user usage scenario.\ 52 | But relatively speaking, if you don't want users to add a dist in the path when using the code, you can't build and output the product very conveniently locally. 53 | - `exports no type, only typesVersions` can be used without thinking under 4.9, but under 5.x `resolution: bundler` cannot correctly provide types for users.\ 54 | It seems to be a good choice when you don't need to consider higher versions, but if you want to support higher versions, you must consider this problem, after all, the world is not always the same. 55 | - The type export of `exports` cannot be used under ts4.9, and it is fully compatible on ts 5.x. It can be used without considering lower version ts users.\ 56 | Great, compared to the above, this seems to be a complementary option, maybe we can think of other ways? 57 | - `typesVersions` is also fully compatible, but it does not support `conditional export`, and it is impossible to distinguish the types of esm and cjs packages. It can be used without thinking when there is no need to distinguish the node environment. 58 | 59 | Combining specific use, we can use `exports` + `typesVersions` for publishing.\ 60 | In this case, we can use `exports` to support the recognition mechanism of higher versions of ts, and use `typesVersions` to support the recognition mechanism of lower versions of ts.\ 61 | But we need a dividing line, from which version do we start using `exports`? This is critical, here we can use 4.7 and 5.0 as the dividing points for judgment, to see which scenario covers a wider range. 62 | 63 | ## Other 64 | 65 | * If you choose to use `exports`, don't forget to export `package.json`. Your users might need to access the dependency data through your package. If you don't do this, they might have to calculate the path, which could be very inconvenient for them. 66 | --------------------------------------------------------------------------------