Skip to content

Commit

Permalink
Add exports field to package.json in order to support moduleResolutio…
Browse files Browse the repository at this point in the history
…n node12/nodenext, closes #1726
  • Loading branch information
gcanti committed Sep 8, 2022
1 parent 449e670 commit 87455b8
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 46 deletions.
31 changes: 27 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,32 @@
"name": "fp-ts",
"version": "2.12.3",
"description": "Functional programming in TypeScript",
"main": "lib/index.js",
"module": "es6/index.js",
"typings": "lib/index.d.ts",
"main": "./lib/index.js",
"module": "./es6/index.js",
"exports": {
".": {
"require": "./lib/index.js",
"import": "./es6/index.js"
},
"./*": {
"require": "./lib/*.js",
"import": "./es6/*.js"
},
"./es6/*": {
"import": "./es6/*.js"
},
"./lib/*": {
"require": "./lib/*.js"
}
},
"types": "index.d.ts",
"typesVersions": {
"*": {
"*": [
"./types/*"
]
}
},
"sideEffects": false,
"scripts": {
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\"",
Expand All @@ -15,7 +38,7 @@
"test": "npm run lint && npm run prettier && npm run dtslint && npm run jest-clear-cache && npm run jest && npm run docs",
"clean": "rimraf ./dist",
"prebuild": "npm run clean",
"build": "tsc -p ./tsconfig.build.json && tsc -p ./tsconfig.build-es6.json && ts-node scripts/build",
"build": "tsc -p ./tsconfig.build-lib.json && tsc -p ./tsconfig.build-es6.json && tsc -p ./tsconfig.build-types.json && ts-node scripts/build",
"postbuild": "prettier --loglevel=silent --write \"./dist/**/*.ts\"",
"prepublishOnly": "ts-node scripts/pre-publish",
"mocha": "mocha -r ts-node/register test/*.ts",
Expand Down
29 changes: 2 additions & 27 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function makePkgJson(module: string): TE.TaskEither<Error, string> {
{
main: `../lib/${module}.js`,
module: `../es6/${module}.js`,
typings: module === 'HKT' ? `../HKT.d.ts` : `../lib/${module}.d.ts`,
types: `../types/${module}.d.ts`,
sideEffects: false
},
null,
Expand All @@ -75,35 +75,10 @@ function makePkgJson(module: string): TE.TaskEither<Error, string> {
)
}

const fixHKT = (folder: string): Build<void> =>
pipe(
(C: FileSystem) => C.mkdir(path.join(OUTPUT_FOLDER, folder, 'HKT')),
RTE.chain(() => (C) =>
C.writeFile(
path.join(OUTPUT_FOLDER, folder, 'HKT', 'package.json'),
JSON.stringify(
{
typings: '../../HKT.d.ts'
},
null,
2
)
)
),
RTE.chain(() => (C) =>
C.moveFile(path.join(OUTPUT_FOLDER, folder, 'HKT.js'), path.join(OUTPUT_FOLDER, folder, 'HKT', 'index.js'))
),
RTE.chain(() => (C) =>
C.moveFile(path.join(OUTPUT_FOLDER, folder, 'HKT.d.ts'), path.join(OUTPUT_FOLDER, 'HKT.d.ts'))
)
)

const main: Build<void> = pipe(
copyPackageJson,
RTE.chain(() => copyFiles),
RTE.chain(() => makeModules),
RTE.chain(() => fixHKT('es6')),
RTE.chain(() => fixHKT('lib'))
RTE.chain(() => makeModules)
)

run(
Expand Down
7 changes: 5 additions & 2 deletions tsconfig.build-es6.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"extends": "./tsconfig.build.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false,
"outDir": "./dist/es6",
"target": "es5",
"module": "es6"
}
},
"include": ["./src"]
}
10 changes: 10 additions & 0 deletions tsconfig.build-lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false,
"outDir": "./dist/lib",
"target": "es5",
"module": "commonjs"
},
"include": ["./src"]
}
9 changes: 9 additions & 0 deletions tsconfig.build-types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.build-es6.json",
"compilerOptions": {
"declaration": true,
"declarationDir": "./dist/types",
"emitDeclarationOnly": true
},
"include": ["./src"]
}
7 changes: 0 additions & 7 deletions tsconfig.build.json

This file was deleted.

9 changes: 3 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
{
"compilerOptions": {
"noEmit": true,
"outDir": "./dist/lib",
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"esModuleInterop": true,
"lib": [],
"sourceMap": false,
"declaration": true,
"declaration": false,
"strict": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true,
"stripInternal": true
"stripInternal": true,
"noUncheckedIndexedAccess": false
},
"include": ["./src", "./test", "./scripts", "./perf"]
}

0 comments on commit 87455b8

Please sign in to comment.