Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exports field to package.json in order to support moduleResolutio… #1765

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
}