diff --git a/.gitignore b/.gitignore index 152b238714..9e9dd6c88d 100644 --- a/.gitignore +++ b/.gitignore @@ -278,6 +278,7 @@ ref/ # Typescript & Rollup tsconfig.build.tsbuildinfo +types/ # MSAL Node Cache Files temp-cache.json diff --git a/api-extractor-base.json b/api-extractor-base.json index 4f171e99e7..fc086eff1e 100644 --- a/api-extractor-base.json +++ b/api-extractor-base.json @@ -1,6 +1,6 @@ { "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", - "mainEntryPointFilePath": "/dist/index.d.ts", + "mainEntryPointFilePath": "/types/index.d.ts", "newlineKind": "lf", "apiReport": { "enabled": true, @@ -16,8 +16,8 @@ "messages": { "compilerMessageReporting": { "default": { - "logLevel": "warning", - "addToApiReportFile": true + "logLevel": "warning", + "addToApiReportFile": true } }, "extractorMessageReporting": { @@ -40,8 +40,8 @@ "tsdocMessageReporting": { "default": { "logLevel": "warning", - "addToApiReportFile":true + "addToApiReportFile": true } } } -} +} \ No newline at end of file diff --git a/change/@azure-msal-browser-3119ffe4-b5d0-4de3-87fd-4f8b9dbbdb25.json b/change/@azure-msal-browser-3119ffe4-b5d0-4de3-87fd-4f8b9dbbdb25.json new file mode 100644 index 0000000000..09bd9814ab --- /dev/null +++ b/change/@azure-msal-browser-3119ffe4-b5d0-4de3-87fd-4f8b9dbbdb25.json @@ -0,0 +1,7 @@ +{ + "type": "minor", + "comment": "Remove duplicate typings in the build output [#8557](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8557)", + "packageName": "@azure/msal-browser", + "email": "thomas.norling@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/change/@azure-msal-common-e4e43f22-87e9-466d-8f27-dd830275df22.json b/change/@azure-msal-common-e4e43f22-87e9-466d-8f27-dd830275df22.json new file mode 100644 index 0000000000..c54da83a43 --- /dev/null +++ b/change/@azure-msal-common-e4e43f22-87e9-466d-8f27-dd830275df22.json @@ -0,0 +1,7 @@ +{ + "type": "minor", + "comment": "Remove duplicate typings in the build output [#8557](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8557)", + "packageName": "@azure/msal-common", + "email": "thomas.norling@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/change/@azure-msal-node-977b757e-ee8b-45b6-b013-dc213ab43e0c.json b/change/@azure-msal-node-977b757e-ee8b-45b6-b013-dc213ab43e0c.json new file mode 100644 index 0000000000..eb79587da6 --- /dev/null +++ b/change/@azure-msal-node-977b757e-ee8b-45b6-b013-dc213ab43e0c.json @@ -0,0 +1,7 @@ +{ + "type": "minor", + "comment": "Remove duplicate typings in the build output [#8557](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8557)", + "packageName": "@azure/msal-node", + "email": "thomas.norling@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/change/@azure-msal-node-extensions-dac0fe19-b6cd-4d14-bf45-1855c1dce4f4.json b/change/@azure-msal-node-extensions-dac0fe19-b6cd-4d14-bf45-1855c1dce4f4.json new file mode 100644 index 0000000000..d5a2753bc4 --- /dev/null +++ b/change/@azure-msal-node-extensions-dac0fe19-b6cd-4d14-bf45-1855c1dce4f4.json @@ -0,0 +1,7 @@ +{ + "type": "minor", + "comment": "Remove duplicate typings in the build output [#8557](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8557)", + "packageName": "@azure/msal-node-extensions", + "email": "thomas.norling@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/change/@azure-msal-react-cc1eae69-e881-4eb2-a8be-1788387ac3cd.json b/change/@azure-msal-react-cc1eae69-e881-4eb2-a8be-1788387ac3cd.json new file mode 100644 index 0000000000..1595731236 --- /dev/null +++ b/change/@azure-msal-react-cc1eae69-e881-4eb2-a8be-1788387ac3cd.json @@ -0,0 +1,7 @@ +{ + "type": "minor", + "comment": "Remove duplicate typings in the build output [#8557](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8557)", + "packageName": "@azure/msal-react", + "email": "thomas.norling@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/extensions/msal-node-extensions/package.json b/extensions/msal-node-extensions/package.json index 9440b03ccd..44168b1868 100644 --- a/extensions/msal-node-extensions/package.json +++ b/extensions/msal-node-extensions/package.json @@ -8,16 +8,16 @@ "license": "MIT", "type": "module", "module": "dist/index.mjs", - "types": "dist/index.d.ts", + "types": "types/index.d.ts", "main": "lib/msal-node-extensions.cjs", "exports": { ".": { "import": { - "types": "./dist/index.d.ts", + "types": "./types/index.d.ts", "default": "./dist/index.mjs" }, "require": { - "types": "./lib/types/index.d.ts", + "types": "./types/index.d.cts", "default": "./lib/msal-node-extensions.cjs" } }, @@ -33,6 +33,7 @@ ], "files": [ "dist", + "types", "bin", "lib" ], @@ -42,9 +43,10 @@ "scripts": { "compile": "node-gyp rebuild", "install": "exit 0", - "clean": "shx rm -rf dist bin lib", - "build": "npm run clean && npm run build:js && npm run build:binaries", + "clean": "shx rm -rf dist types bin lib", + "build": "npm run clean && npm run build:js && npm run build:types && npm run build:binaries", "build:js": "rollup -c --strictDeprecations --bundleConfigAsCjs", + "build:types": "tsc -p tsconfig.build.types.json", "build:binaries": "node ./scripts/buildBinaries.cjs", "build:all": "cd ../.. && npm run build --workspace=@azure/msal-common --workspace=@azure/msal-node-extensions", "test": "jest", @@ -88,4 +90,4 @@ "tslib": "^2.0.0", "typescript": "^4.9.5" } -} +} \ No newline at end of file diff --git a/extensions/msal-node-extensions/rollup.config.js b/extensions/msal-node-extensions/rollup.config.js index 28c6414892..399a54b85b 100644 --- a/extensions/msal-node-extensions/rollup.config.js +++ b/extensions/msal-node-extensions/rollup.config.js @@ -6,7 +6,8 @@ import { nodeResolve } from "@rollup/plugin-node-resolve"; import typescript from "@rollup/plugin-typescript"; import pkg from "./package.json"; -import { createPackageJson } from "rollup-msal"; +import { createCjsTypeShims, createPackageJson } from "rollup-msal"; +import path from "path"; const libraryHeader = `/*! ${pkg.name} v${pkg.version} ${new Date().toISOString().split("T")[0]} */`; const useStrictHeader = "'use strict';"; @@ -36,7 +37,9 @@ export default [ typescript({ typescript: require("typescript"), tsconfig: "tsconfig.build.json", - compilerOptions: { outDir: "lib/types" } + compilerOptions: { + outDir: "./lib" + } }), nodeResolve({ preferBuiltins: true @@ -69,6 +72,15 @@ export default [ typescript: require("typescript"), tsconfig: "tsconfig.build.json" }), + createCjsTypeShims({ + packageRoot: __dirname, + shims: [ + { + filePath: path.join("types", "index.d.cts"), + target: "./index.js" + } + ] + }), nodeResolve({ preferBuiltins: true }) diff --git a/extensions/msal-node-extensions/tsconfig.build.json b/extensions/msal-node-extensions/tsconfig.build.json index afd75c74d7..8f154885e2 100644 --- a/extensions/msal-node-extensions/tsconfig.build.json +++ b/extensions/msal-node-extensions/tsconfig.build.json @@ -1,7 +1,9 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "rootDir": "./src" + "rootDir": "./src", + "declaration": false, + "declarationMap": false }, "include": [ "src" diff --git a/extensions/msal-node-extensions/tsconfig.build.types.json b/extensions/msal-node-extensions/tsconfig.build.types.json new file mode 100644 index 0000000000..dc370fe1a0 --- /dev/null +++ b/extensions/msal-node-extensions/tsconfig.build.types.json @@ -0,0 +1,13 @@ +{ + "extends": "./tsconfig.build.json", + "compilerOptions": { + "outDir": "./types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "noEmit": false + }, + "include": [ + "src" + ] +} \ No newline at end of file diff --git a/lib/msal-browser/package.json b/lib/msal-browser/package.json index ca0a810ab9..050436bc99 100644 --- a/lib/msal-browser/package.json +++ b/lib/msal-browser/package.json @@ -25,35 +25,35 @@ "sideEffects": false, "main": "./lib/msal-browser.cjs", "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", + "types": "./types/index.d.ts", "exports": { "./custom-auth": { "import": { - "types": "./dist/custom-auth-path/custom_auth/index.d.ts", - "default": "./dist/custom-auth-path/custom_auth/index.mjs" + "types": "./types/custom_auth/index.d.ts", + "default": "./dist/custom_auth/index.mjs" }, "require": { - "types": "./lib/custom-auth-path/types/custom_auth/index.d.ts", + "types": "./types/custom_auth/index.d.cts", "default": "./lib/custom-auth-path/msal-custom-auth.cjs" } }, "./redirect-bridge": { "import": { - "types": "./dist/redirect-bridge/redirect_bridge/index.d.ts", - "default": "./dist/redirect-bridge/redirect_bridge/index.mjs" + "types": "./types/redirect_bridge/index.d.ts", + "default": "./dist/redirect_bridge/index.mjs" }, "require": { - "types": "./lib/redirect-bridge/types/redirect_bridge/index.d.ts", + "types": "./types/redirect_bridge/index.d.cts", "default": "./lib/redirect-bridge/msal-redirect-bridge.cjs" } }, ".": { "import": { - "types": "./dist/index.d.ts", + "types": "./types/index.d.ts", "default": "./dist/index.mjs" }, "require": { - "types": "./lib/types/index.d.ts", + "types": "./types/index.d.cts", "default": "./lib/msal-browser.cjs" } }, @@ -72,11 +72,12 @@ }, "files": [ "dist", + "types", "lib", "src" ], "scripts": { - "clean": "shx rm -rf dist lib", + "clean": "shx rm -rf dist types lib", "clean:coverage": "rimraf ../../.nyc_output/*", "lint": "eslint src --ext .ts", "lint:fix": "npm run lint -- --fix", @@ -85,7 +86,8 @@ "test:coverage:only": "npm run clean:coverage && npm run test:coverage", "build:all": "cd ../.. && npm run build --workspace=@azure/msal-common --workspace=@azure/msal-browser", "build:all:debug": "cd ../.. && cross-env MSAL_MINIFY_LOGS=false npm run build --workspace=@azure/msal-common --workspace=@azure/msal-browser", - "build:modules": "rollup -c --strictDeprecations --bundleConfigAsCjs", + "build:modules": "rollup -c --strictDeprecations --bundleConfigAsCjs && npm run build:types", + "build:types": "tsc -p tsconfig.build.types.json", "build:modules:watch": "rollup -cw --bundleConfigAsCjs", "build": "npm run clean && npm run build:modules", "build:debug": "npm run clean && cross-env MSAL_MINIFY_LOGS=false npm run build:modules", @@ -130,4 +132,4 @@ "dependencies": { "@azure/msal-common": "16.5.2" } -} +} \ No newline at end of file diff --git a/lib/msal-browser/rollup.config.js b/lib/msal-browser/rollup.config.js index 022103b4b7..a2ada7bc85 100644 --- a/lib/msal-browser/rollup.config.js +++ b/lib/msal-browser/rollup.config.js @@ -7,7 +7,7 @@ import { nodeResolve } from "@rollup/plugin-node-resolve"; import typescript from "@rollup/plugin-typescript"; import terser from "@rollup/plugin-terser"; import pkg from "./package.json"; -import { createPackageJson, loggerMinifyPlugin } from "rollup-msal"; +import { createCjsTypeShims, createPackageJson, loggerMinifyPlugin } from "rollup-msal"; import path from "path"; const libraryHeader = `/*! ${pkg.name} v${pkg.version} ${ @@ -19,8 +19,12 @@ const minifyLogs = process.env.MSAL_MINIFY_LOGS !== 'false'; export default [ { - // Main SDK - ES build - input: "src/index.ts", + // Main SDK + subpath exports - ES build + input: [ + "src/index.ts", + "src/custom_auth/index.ts", + "src/redirect_bridge/index.ts", + ], output: { dir: "dist", preserveModules: true, @@ -40,6 +44,23 @@ export default [ typescript: require("typescript"), tsconfig: "tsconfig.build.json", }), + createCjsTypeShims({ + packageRoot: __dirname, + shims: [ + { + filePath: path.join("types", "index.d.cts"), + target: "./index.js", + }, + { + filePath: path.join("types", "custom_auth", "index.d.cts"), + target: "./index.js", + }, + { + filePath: path.join("types", "redirect_bridge", "index.d.cts"), + target: "./index.js", + }, + ], + }), ...(minifyLogs === true ? [loggerMinifyPlugin({ verbose: true, outputFile: path.resolve(__dirname, "./dist/log-strings-mapping.json"), @@ -69,7 +90,9 @@ export default [ typescript: require("typescript"), tsconfig: "tsconfig.build.json", sourceMap: true, - compilerOptions: { outDir: "lib/types" }, + compilerOptions: { + outDir: "lib/types", + }, }), createPackageJson({ libPath: __dirname }), ...(minifyLogs === true ? [loggerMinifyPlugin({ @@ -104,8 +127,6 @@ export default [ sourceMap: true, compilerOptions: { outDir: "lib/types", - declaration: false, - declarationMap: false, }, }), ...(minifyLogs === true ? [loggerMinifyPlugin({ @@ -138,8 +159,6 @@ export default [ sourceMap: false, compilerOptions: { outDir: "lib/types", - declaration: false, - declarationMap: false, }, }), loggerMinifyPlugin({ @@ -153,35 +172,6 @@ export default [ }), ], }, - { - // Custom Auth - ES module build - input: "src/custom_auth/index.ts", - output: { - dir: "dist/custom-auth-path", - preserveModules: true, - preserveModulesRoot: "src", - format: "es", - entryFileNames: "[name].mjs", - banner: fileHeader, - sourcemap: true, - }, - treeshake: { - moduleSideEffects: false, - propertyReadSideEffects: false, - }, - external: ["@azure/msal-common/browser"], - plugins: [ - typescript({ - typescript: require("typescript"), - tsconfig: "tsconfig.custom-auth.build.json", - }), - ...(minifyLogs === true ? [loggerMinifyPlugin({ - verbose: true, - outputFile: path.resolve(__dirname, "./dist/custom-auth-path/log-strings-mapping.json"), - packageJsonPath: path.resolve(__dirname, "./package.json"), - })] : []), - ], - }, { // Custom Auth - CommonJS build input: "src/custom_auth/index.ts", @@ -211,30 +201,6 @@ export default [ })] : []), ], }, - { - // Redirect Bridge - ES module build - input: "src/redirect_bridge/index.ts", - output: { - dir: "dist/redirect-bridge", - preserveModules: true, - preserveModulesRoot: "src", - format: "es", - entryFileNames: "[name].mjs", - banner: fileHeader, - sourcemap: true, - }, - treeshake: { - moduleSideEffects: false, - propertyReadSideEffects: false, - }, - external: ["@azure/msal-common/browser"], - plugins: [ - typescript({ - typescript: require("typescript"), - tsconfig: "tsconfig.redirect-bridge.build.json", - }), - ], - }, { // Redirect Bridge - CommonJS build input: "src/redirect_bridge/index.ts", @@ -284,8 +250,6 @@ export default [ sourceMap: true, compilerOptions: { outDir: "lib/redirect-bridge/types", - declaration: false, - declarationMap: false, }, }), ], @@ -315,8 +279,6 @@ export default [ sourceMap: false, compilerOptions: { outDir: "lib/redirect-bridge/types", - declaration: false, - declarationMap: false, }, }), terser({ diff --git a/lib/msal-browser/test/custom_auth/get_account/interaction_client/CustomAuthSilentCacheClient.spec.ts b/lib/msal-browser/test/custom_auth/get_account/interaction_client/CustomAuthSilentCacheClient.spec.ts index 644d1df5f6..3002ee95b2 100644 --- a/lib/msal-browser/test/custom_auth/get_account/interaction_client/CustomAuthSilentCacheClient.spec.ts +++ b/lib/msal-browser/test/custom_auth/get_account/interaction_client/CustomAuthSilentCacheClient.spec.ts @@ -7,6 +7,7 @@ import { AccountEntityUtils, CacheHelpers, CommonSilentFlowRequest, + Constants, createInteractionRequiredAuthError, ICrypto, INetworkModule, @@ -36,7 +37,6 @@ import { getDefaultEventHandler, getDefaultPerformanceClient, } from "../../test_resources/TestModules.js"; -import { AuthenticationScheme } from "../../../../../msal-common/lib/types/utils/Constants.js"; import { mock } from "node:test"; describe("CustomAuthSilentCacheClient", () => { @@ -444,7 +444,7 @@ function createAccessTokenEntity(browserCrypto: ICrypto): AccessTokenEntity { expiresOn + 0, browserCrypto.base64Decode, undefined, - TestServerTokenResponse.token_type as AuthenticationScheme + TestServerTokenResponse.token_type as Constants.AuthenticationScheme ); } diff --git a/lib/msal-browser/tsconfig.build.json b/lib/msal-browser/tsconfig.build.json index 0f946f3dc8..8f154885e2 100644 --- a/lib/msal-browser/tsconfig.build.json +++ b/lib/msal-browser/tsconfig.build.json @@ -1,7 +1,11 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "rootDir": "./src" + "rootDir": "./src", + "declaration": false, + "declarationMap": false }, - "include": ["src"] + "include": [ + "src" + ] } \ No newline at end of file diff --git a/lib/msal-browser/tsconfig.build.types.json b/lib/msal-browser/tsconfig.build.types.json new file mode 100644 index 0000000000..dc370fe1a0 --- /dev/null +++ b/lib/msal-browser/tsconfig.build.types.json @@ -0,0 +1,13 @@ +{ + "extends": "./tsconfig.build.json", + "compilerOptions": { + "outDir": "./types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "noEmit": false + }, + "include": [ + "src" + ] +} \ No newline at end of file diff --git a/lib/msal-browser/tsconfig.custom-auth.build.json b/lib/msal-browser/tsconfig.custom-auth.build.json index 3177289d6b..76c52bc5f1 100644 --- a/lib/msal-browser/tsconfig.custom-auth.build.json +++ b/lib/msal-browser/tsconfig.custom-auth.build.json @@ -3,6 +3,10 @@ "compilerOptions": { "rootDir": "./src", "outDir": "./dist/custom-auth-path", + "declaration": false, + "declarationMap": false, }, - "include": ["src"] -} + "include": [ + "src" + ] +} \ No newline at end of file diff --git a/lib/msal-browser/tsconfig.redirect-bridge.build.json b/lib/msal-browser/tsconfig.redirect-bridge.build.json index 43d902c2ea..786a367fb1 100644 --- a/lib/msal-browser/tsconfig.redirect-bridge.build.json +++ b/lib/msal-browser/tsconfig.redirect-bridge.build.json @@ -3,6 +3,10 @@ "compilerOptions": { "rootDir": "./src", "outDir": "./dist/redirect-bridge", + "declaration": false, + "declarationMap": false, }, - "include": ["src"] -} + "include": [ + "src" + ] +} \ No newline at end of file diff --git a/lib/msal-common/browser/package.json b/lib/msal-common/browser/package.json index b403b13026..a2ca54365a 100644 --- a/lib/msal-common/browser/package.json +++ b/lib/msal-common/browser/package.json @@ -1,5 +1,5 @@ { "main": "../lib/index-browser.cjs", "module": "../dist/index-browser.mjs", - "types": "../lib/types/index-browser.d.ts" + "types": "../types/index-browser.d.ts" } \ No newline at end of file diff --git a/lib/msal-common/node/package.json b/lib/msal-common/node/package.json index bcc1f1009e..20f267c327 100644 --- a/lib/msal-common/node/package.json +++ b/lib/msal-common/node/package.json @@ -1,5 +1,5 @@ { "main": "../lib/index-node.cjs", "module": "../dist/index-node.mjs", - "types": "../lib/types/index-node.d.ts" + "types": "../types/index-node.d.ts" } \ No newline at end of file diff --git a/lib/msal-common/package.json b/lib/msal-common/package.json index 692dba3fde..6dcdcc2fc1 100644 --- a/lib/msal-common/package.json +++ b/lib/msal-common/package.json @@ -25,35 +25,35 @@ "type": "module", "main": "./lib/index.cjs", "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", + "types": "./types/index.d.ts", "exports": { "./browser": { "import": { - "types": "./dist-browser/index-browser.d.ts", + "types": "./types/index-browser.d.ts", "default": "./dist-browser/index-browser.mjs" }, "require": { - "types": "./lib/types/index-browser.d.ts", + "types": "./types/index-browser.d.cts", "default": "./lib/index-browser.cjs" } }, "./node": { "import": { - "types": "./dist/index-node.d.ts", + "types": "./types/index-node.d.ts", "default": "./dist/index-node.mjs" }, "require": { - "types": "./lib/types/index-node.d.ts", + "types": "./types/index-node.d.cts", "default": "./lib/index-node.cjs" } }, ".": { "import": { - "types": "./dist/index.d.ts", + "types": "./types/index.d.ts", "default": "./dist/index.mjs" }, "require": { - "types": "./lib/types/index.d.ts", + "types": "./types/index.d.cts", "default": "./lib/index.cjs" } }, @@ -68,20 +68,22 @@ "files": [ "dist", "dist-browser", + "types", "lib", "src", "node", "browser" ], "scripts": { - "clean": "shx rm -rf dist dist-browser lib", + "clean": "shx rm -rf dist dist-browser types lib", "clean:coverage": "rimraf ../../.nyc_output/*", "lint": "eslint src --ext .ts", "lint:fix": "npm run lint -- --fix", "test": "jest", "test:coverage": "jest --coverage", "test:coverage:only": "npm run clean:coverage && npm run test:coverage", - "build:modules": "rollup -c --strictDeprecations --bundleConfigAsCjs", + "build:modules": "rollup -c --strictDeprecations --bundleConfigAsCjs && npm run build:types", + "build:types": "tsc -p tsconfig.build.types.json", "build:modules:watch": "rollup -cw --bundleConfigAsCjs", "build": "npm run clean && npm run build:modules", "build:debug": "npm run clean && cross-env MSAL_MINIFY_LOGS=false npm run build:modules", @@ -128,4 +130,4 @@ "typescript": "^4.9.5", "yargs": "^17.5.1" } -} +} \ No newline at end of file diff --git a/lib/msal-common/rollup.config.js b/lib/msal-common/rollup.config.js index c9b2893dc6..6744da5b60 100644 --- a/lib/msal-common/rollup.config.js +++ b/lib/msal-common/rollup.config.js @@ -5,7 +5,7 @@ import typescript from "@rollup/plugin-typescript"; import pkg from "./package.json"; -import { createPackageJson, loggerMinifyPlugin } from "rollup-msal"; +import { createCjsTypeShims, createPackageJson, loggerMinifyPlugin } from "rollup-msal"; import path from "path"; const libraryHeader = `/*! ${pkg.name} v${pkg.version} ${new Date().toISOString().split("T")[0]} */`; @@ -38,7 +38,24 @@ export default [ typescript({ typescript: require("typescript"), tsconfig: "tsconfig.build.json" - }) + }), + createCjsTypeShims({ + packageRoot: __dirname, + shims: [ + { + filePath: path.join("types", "index.d.cts"), + target: "./index.js", + }, + { + filePath: path.join("types", "index-node.d.cts"), + target: "./index-node.js", + }, + { + filePath: path.join("types", "index-browser.d.cts"), + target: "./index-browser.js", + }, + ], + }), ] }, { @@ -93,7 +110,9 @@ export default [ typescript: require("typescript"), tsconfig: "tsconfig.build.json", sourceMap: true, - compilerOptions: { outDir: "lib/types"} + compilerOptions: { + outDir: "lib/types" + } }), createPackageJson({libPath: __dirname}) ] diff --git a/lib/msal-common/tsconfig.build.browser.json b/lib/msal-common/tsconfig.build.browser.json index 4c7433f764..a333c5f84f 100644 --- a/lib/msal-common/tsconfig.build.browser.json +++ b/lib/msal-common/tsconfig.build.browser.json @@ -2,7 +2,11 @@ "extends": "./tsconfig.json", "compilerOptions": { "rootDir": "./src", - "outDir": "./dist-browser" + "outDir": "./dist-browser", + "declaration": false, + "declarationMap": false }, - "include": ["src"] -} + "include": [ + "src" + ] +} \ No newline at end of file diff --git a/lib/msal-common/tsconfig.build.json b/lib/msal-common/tsconfig.build.json index 0f946f3dc8..8f154885e2 100644 --- a/lib/msal-common/tsconfig.build.json +++ b/lib/msal-common/tsconfig.build.json @@ -1,7 +1,11 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "rootDir": "./src" + "rootDir": "./src", + "declaration": false, + "declarationMap": false }, - "include": ["src"] + "include": [ + "src" + ] } \ No newline at end of file diff --git a/lib/msal-common/tsconfig.build.types.json b/lib/msal-common/tsconfig.build.types.json new file mode 100644 index 0000000000..dc370fe1a0 --- /dev/null +++ b/lib/msal-common/tsconfig.build.types.json @@ -0,0 +1,13 @@ +{ + "extends": "./tsconfig.build.json", + "compilerOptions": { + "outDir": "./types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "noEmit": false + }, + "include": [ + "src" + ] +} \ No newline at end of file diff --git a/lib/msal-node/package.json b/lib/msal-node/package.json index 8f280c4eb3..2ac5096b77 100644 --- a/lib/msal-node/package.json +++ b/lib/msal-node/package.json @@ -24,15 +24,15 @@ "type": "module", "main": "lib/msal-node.cjs", "module": "dist/index.mjs", - "types": "dist/index.d.ts", + "types": "types/index.d.ts", "exports": { ".": { "import": { - "types": "./dist/index.d.ts", + "types": "./types/index.d.ts", "default": "./dist/index.mjs" }, "require": { - "types": "./lib/types/index.d.ts", + "types": "./types/index.d.cts", "default": "./lib/msal-node.cjs" } }, @@ -40,13 +40,15 @@ }, "files": [ "dist", + "types", "lib", "src" ], "scripts": { - "build": "npm run clean && rollup -c --strictDeprecations --bundleConfigAsCjs", + "build": "npm run clean && rollup -c --strictDeprecations --bundleConfigAsCjs && npm run build:types", + "build:types": "tsc -p tsconfig.build.types.json", "build:watch": "rollup -c --watch --strictDeprecations --bundleConfigAsCjs", - "clean": "shx rm -rf dist lib", + "clean": "shx rm -rf dist types lib", "test": "jest", "test:watch": "jest --watch", "test:coverage": "jest --coverage", @@ -88,4 +90,4 @@ "engines": { "node": ">=20" } -} +} \ No newline at end of file diff --git a/lib/msal-node/rollup.config.js b/lib/msal-node/rollup.config.js index 0b54301826..850cf99b16 100644 --- a/lib/msal-node/rollup.config.js +++ b/lib/msal-node/rollup.config.js @@ -6,7 +6,7 @@ import { nodeResolve } from "@rollup/plugin-node-resolve"; import typescript from "@rollup/plugin-typescript"; import pkg from "./package.json"; -import { createPackageJson } from "rollup-msal" +import { createCjsTypeShims, createPackageJson } from "rollup-msal" const libraryHeader = `/*! ${pkg.name} v${pkg.version} ${ new Date().toISOString().split("T")[0] @@ -36,7 +36,16 @@ export default [{ ], plugins: [ typescript({ - tsconfig: "tsconfig.build.json", + tsconfig: "tsconfig.build.json" + }), + createCjsTypeShims({ + packageRoot: __dirname, + shims: [ + { + filePath: "types/index.d.cts", + target: "./index.js", + }, + ], }), nodeResolve({ preferBuiltins: true @@ -63,7 +72,9 @@ export default [{ plugins: [ typescript({ tsconfig: "tsconfig.build.json", - compilerOptions: { outDir: "lib/types" } + compilerOptions: { + outDir: "lib/types" + } }), nodeResolve({ preferBuiltins: true }), createPackageJson({libPath: __dirname}) diff --git a/lib/msal-node/test/client/ConfidentialClientApplication.spec.ts b/lib/msal-node/test/client/ConfidentialClientApplication.spec.ts index bdf4def2ee..e4bc204e82 100644 --- a/lib/msal-node/test/client/ConfidentialClientApplication.spec.ts +++ b/lib/msal-node/test/client/ConfidentialClientApplication.spec.ts @@ -14,6 +14,7 @@ import { InteractionRequiredAuthErrorCodes, ClientAssertion, AccountEntityUtils, + INetworkModule, } from "@azure/msal-common"; import { DEFAULT_OPENID_CONFIG_RESPONSE, @@ -45,7 +46,6 @@ import { buildAccountFromIdTokenClaims } from "msal-test-utils"; import { Constants, MSAL_FORCE_REGION } from "../../src/utils/Constants.js"; import jwt from "jsonwebtoken"; import { NodeAuthError } from "../../src/error/NodeAuthError.js"; -import { INetworkModule } from "../../../msal-common/lib/types/exports-common.js"; import { CommonClientCredentialRequest } from "../../src/request/CommonClientCredentialRequest.js"; import * as NodeClientAuthErrorCodes from "../../src/error/ClientAuthErrorCodes.js"; import { ClientApplication } from "../../src/client/ClientApplication.js"; diff --git a/lib/msal-node/tsconfig.build.json b/lib/msal-node/tsconfig.build.json index 0f946f3dc8..8f154885e2 100644 --- a/lib/msal-node/tsconfig.build.json +++ b/lib/msal-node/tsconfig.build.json @@ -1,7 +1,11 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "rootDir": "./src" + "rootDir": "./src", + "declaration": false, + "declarationMap": false }, - "include": ["src"] + "include": [ + "src" + ] } \ No newline at end of file diff --git a/lib/msal-node/tsconfig.build.types.json b/lib/msal-node/tsconfig.build.types.json new file mode 100644 index 0000000000..dc370fe1a0 --- /dev/null +++ b/lib/msal-node/tsconfig.build.types.json @@ -0,0 +1,13 @@ +{ + "extends": "./tsconfig.build.json", + "compilerOptions": { + "outDir": "./types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "noEmit": false + }, + "include": [ + "src" + ] +} \ No newline at end of file diff --git a/lib/msal-react/apiReview/msal-react.api.md b/lib/msal-react/apiReview/msal-react.api.md index e4ac0f6e9d..b0a0784884 100644 --- a/lib/msal-react/apiReview/msal-react.api.md +++ b/lib/msal-react/apiReview/msal-react.api.md @@ -170,7 +170,7 @@ export type WithMsalProps = { // Warnings were encountered during analysis: // -// dist/index.d.ts:3:12 - (tsdoc-characters-after-block-tag) The token "@azure" looks like a TSDoc tag but contains an invalid character "/"; if it is not a tag, use a backslash to escape the "@" -// dist/index.d.ts:3:4 - (tsdoc-undefined-tag) The TSDoc tag "@module" is not defined in this configuration +// src/index.ts:8:12 - (tsdoc-characters-after-block-tag) The token "@azure" looks like a TSDoc tag but contains an invalid character "/"; if it is not a tag, use a backslash to escape the "@" +// src/index.ts:8:4 - (tsdoc-undefined-tag) The TSDoc tag "@module" is not defined in this configuration ``` diff --git a/lib/msal-react/package.json b/lib/msal-react/package.json index 334cefe54a..a5ac98b7e7 100644 --- a/lib/msal-react/package.json +++ b/lib/msal-react/package.json @@ -14,16 +14,16 @@ "description": "Microsoft Authentication Library for React", "type": "module", "module": "dist/index.js", - "types": "dist/index.d.ts", + "types": "types/index.d.ts", "main": "lib/msal-react.cjs", "exports": { ".": { "import": { - "types": "./dist/index.d.ts", + "types": "./types/index.d.ts", "default": "./dist/index.js" }, "require": { - "types": "./lib/types/index.d.ts", + "types": "./types/index.d.cts", "default": "./lib/msal-react.cjs" } }, @@ -31,6 +31,7 @@ }, "files": [ "dist", + "types", "lib", "src" ], @@ -43,7 +44,9 @@ ] }, "scripts": { - "build": "rollup -c --strictDeprecations --bundleConfigAsCjs", + "clean": "shx rm -rf dist types lib", + "build": "npm run clean && rollup -c --strictDeprecations --bundleConfigAsCjs && npm run build:types", + "build:types": "tsc -p tsconfig.build.types.json", "build:modules:watch": "rollup -cw --bundleConfigAsCjs", "test": "jest --forceExit", "test:coverage": "jest --coverage", @@ -83,4 +86,4 @@ "tslib": "^2.0.0", "typescript": "^4.9.5" } -} +} \ No newline at end of file diff --git a/lib/msal-react/rollup.config.js b/lib/msal-react/rollup.config.js index 2aa1dd0ded..4306dec12c 100644 --- a/lib/msal-react/rollup.config.js +++ b/lib/msal-react/rollup.config.js @@ -5,7 +5,8 @@ import typescript from "@rollup/plugin-typescript"; import pkg from "./package.json"; -import { createPackageJson } from "rollup-msal"; +import { createCjsTypeShims, createPackageJson } from "rollup-msal"; +import path from "path"; const libraryHeader = `/*! ${pkg.name} v${pkg.version} ${new Date().toISOString().split("T")[0]} */`; const useStrictHeader = "'use strict';"; @@ -35,7 +36,16 @@ export default [ typescript({ typescript: require("typescript"), tsconfig: "tsconfig.build.json" - }) + }), + createCjsTypeShims({ + packageRoot: __dirname, + shims: [ + { + filePath: path.join("types", "index.d.cts"), + target: "./index.js", + }, + ], + }), ] }, { @@ -59,7 +69,9 @@ export default [ typescript({ typescript: require("typescript"), tsconfig: "tsconfig.build.json", - compilerOptions: { outDir: "lib/types" } + compilerOptions: { + outDir: "lib/types" + } }), createPackageJson({ libPath: __dirname}) ] diff --git a/lib/msal-react/tsconfig.build.json b/lib/msal-react/tsconfig.build.json index 4b2f60926a..3acf4a042b 100644 --- a/lib/msal-react/tsconfig.build.json +++ b/lib/msal-react/tsconfig.build.json @@ -2,6 +2,8 @@ "extends": "./tsconfig.json", "compilerOptions": { "rootDir": "./src", + "declaration": false, + "declarationMap": false, "types": [ "react" ] diff --git a/lib/msal-react/tsconfig.build.types.json b/lib/msal-react/tsconfig.build.types.json new file mode 100644 index 0000000000..dc370fe1a0 --- /dev/null +++ b/lib/msal-react/tsconfig.build.types.json @@ -0,0 +1,13 @@ +{ + "extends": "./tsconfig.build.json", + "compilerOptions": { + "outDir": "./types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "noEmit": false + }, + "include": [ + "src" + ] +} \ No newline at end of file diff --git a/lib/msal-react/tsconfig.json b/lib/msal-react/tsconfig.json index 86665991d2..95d380f34a 100644 --- a/lib/msal-react/tsconfig.json +++ b/lib/msal-react/tsconfig.json @@ -1,7 +1,6 @@ { "include": [ "src", - "types", "test" ], "compilerOptions": { diff --git a/shared-configs/rollup-msal/index.js b/shared-configs/rollup-msal/index.js index 9e2831db32..8ba74e7b1e 100644 --- a/shared-configs/rollup-msal/index.js +++ b/shared-configs/rollup-msal/index.js @@ -24,7 +24,28 @@ const createPackageJson = ({libPath}) => { } } +/** + * Creates CommonJS declaration shims that point to ESM declaration entrypoints. + */ +const createCjsTypeShims = ({ packageRoot, shims }) => { + return { + name: "createCjsTypeShims", + writeBundle: () => { + for (const shim of shims) { + const absolutePath = path.resolve(packageRoot, shim.filePath); + fs.mkdirSync(path.dirname(absolutePath), { recursive: true }); + fs.writeFileSync( + absolutePath, + `export * from "${shim.target}";\n`, + "utf8" + ); + } + } + } +} + module.exports = { createPackageJson, + createCjsTypeShims, loggerMinifyPlugin }